/** * Simplified TypeSpec emitter types for Atproto Lexicon * * These types mirror the atproto lexicon structure but use plain TypeScript * instead of Zod schemas. This avoids type conflicts from discriminated unions * while remaining structurally compatible at runtime. */ // Primitives export type LexNull = { type: "null"; description?: string; }; export type LexBoolean = { type: "boolean"; description?: string; default?: boolean; const?: boolean; }; export type LexInteger = { type: "integer"; description?: string; default?: number; minimum?: number; maximum?: number; enum?: number[]; const?: number; }; export type LexString = { type: "string"; format?: string; description?: string; default?: string; minLength?: number; maxLength?: number; minGraphemes?: number; maxGraphemes?: number; enum?: string[]; const?: string; knownValues?: string[]; }; export type LexUnknown = { type: "unknown"; description?: string; }; export type LexPrimitive = LexNull | LexBoolean | LexInteger | LexString | LexUnknown; // IPLD types export type LexBytes = { type: "bytes"; description?: string; maxLength?: number; minLength?: number; }; export type LexCidLink = { type: "cid-link"; description?: string; }; export type LexIpldType = LexBytes | LexCidLink; // References export type LexRef = { type: "ref"; description?: string; ref: string; }; export type LexRefUnion = { type: "union"; description?: string; refs: string[]; closed?: boolean; }; export type LexRefVariant = LexRef | LexRefUnion; // Blobs export type LexBlob = { type: "blob"; description?: string; accept?: string[]; maxSize?: number; }; // Arrays export type LexArrayItem = LexPrimitive | LexIpldType | LexRefVariant | LexBlob; export type LexArray = { type: "array"; description?: string; items: LexArrayItem; minLength?: number; maxLength?: number; }; // Objects - use a looser type for properties to avoid discriminated union issues export type LexObjectProperty = | LexArray | LexPrimitive | LexIpldType | LexRefVariant | LexBlob | LexObject; // Allow nested objects export type LexObject = { type: "object"; description?: string; required?: string[]; nullable?: string[]; properties: Record; }; // Token export type LexToken = { type: "token"; description?: string; }; // XRPC types export type LexPrimitiveArray = { type: "array"; description?: string; items: LexPrimitive; minLength?: number; maxLength?: number; }; export type LexXrpcParameterProperty = LexPrimitive | LexPrimitiveArray; export type LexXrpcParameters = { type: "params"; description?: string; required?: string[]; properties: Record; }; export type LexXrpcBody = { description?: string; encoding: string; schema?: LexRefVariant | LexObject; }; export type LexXrpcSubscriptionMessage = { description?: string; schema?: LexRefVariant | LexObject; }; export type LexXrpcError = { name: string; description?: string; }; export type LexXrpcQuery = { type: "query"; description?: string; parameters?: LexXrpcParameters; output?: LexXrpcBody; errors?: LexXrpcError[]; }; export type LexXrpcProcedure = { type: "procedure"; description?: string; parameters?: LexXrpcParameters; input?: LexXrpcBody; output?: LexXrpcBody; errors?: LexXrpcError[]; }; export type LexXrpcSubscription = { type: "subscription"; description?: string; parameters?: LexXrpcParameters; message?: LexXrpcSubscriptionMessage; errors?: LexXrpcError[]; }; // Records export type LexRecord = { type: "record"; description?: string; key?: string; record: LexObject; }; // Union of all user-definable types export type LexUserType = | LexRecord | LexXrpcQuery | LexXrpcProcedure | LexXrpcSubscription | LexBlob | LexArray | LexToken | LexObject | LexPrimitive | LexIpldType; // Lexicon document export type LexiconDoc = { lexicon: 1; id: string; revision?: number; description?: string; defs: Record; }; // Helper type for objects that can have descriptions export type WithDescription = T & { description?: string };