prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

formatting and tsc

Tyler 3f8ba0c9 12b62261

+546 -367
+1 -1
packages/prototypey/src/lib.ts
··· 329 329 330 330 class Namespace<T extends LexiconNamespace> { 331 331 public json: T; 332 - public infer: Infer<T> = null as unknown as Infer<T>; 332 + public infer: Infer<{ json: T }> = null as unknown as Infer<{ json: T }>; 333 333 334 334 constructor(json: T) { 335 335 this.json = json;
+167 -68
packages/site/public/types/infer.d.ts
··· 2 2 3 3 //#region src/infer.d.ts 4 4 type InferType<T> = T extends { 5 - type: "record"; 6 - } ? InferRecord<T> : T extends { 7 - type: "object"; 8 - } ? InferObject<T> : T extends { 9 - type: "array"; 10 - } ? InferArray<T> : T extends { 11 - type: "params"; 12 - } ? InferParams<T> : T extends { 13 - type: "union"; 14 - } ? InferUnion<T> : T extends { 15 - type: "token"; 16 - } ? InferToken<T> : T extends { 17 - type: "ref"; 18 - } ? InferRef<T> : T extends { 19 - type: "unknown"; 20 - } ? unknown : T extends { 21 - type: "null"; 22 - } ? null : T extends { 23 - type: "boolean"; 24 - } ? boolean : T extends { 25 - type: "integer"; 26 - } ? number : T extends { 27 - type: "string"; 28 - } ? string : T extends { 29 - type: "bytes"; 30 - } ? Uint8Array : T extends { 31 - type: "cid-link"; 32 - } ? string : T extends { 33 - type: "blob"; 34 - } ? Blob : never; 5 + type: "record"; 6 + } 7 + ? InferRecord<T> 8 + : T extends { 9 + type: "object"; 10 + } 11 + ? InferObject<T> 12 + : T extends { 13 + type: "array"; 14 + } 15 + ? InferArray<T> 16 + : T extends { 17 + type: "params"; 18 + } 19 + ? InferParams<T> 20 + : T extends { 21 + type: "union"; 22 + } 23 + ? InferUnion<T> 24 + : T extends { 25 + type: "token"; 26 + } 27 + ? InferToken<T> 28 + : T extends { 29 + type: "ref"; 30 + } 31 + ? InferRef<T> 32 + : T extends { 33 + type: "unknown"; 34 + } 35 + ? unknown 36 + : T extends { 37 + type: "null"; 38 + } 39 + ? null 40 + : T extends { 41 + type: "boolean"; 42 + } 43 + ? boolean 44 + : T extends { 45 + type: "integer"; 46 + } 47 + ? number 48 + : T extends { 49 + type: "string"; 50 + } 51 + ? string 52 + : T extends { 53 + type: "bytes"; 54 + } 55 + ? Uint8Array 56 + : T extends { 57 + type: "cid-link"; 58 + } 59 + ? string 60 + : T extends { 61 + type: "blob"; 62 + } 63 + ? Blob 64 + : never; 35 65 type InferToken<T> = T extends { 36 - enum: readonly (infer U)[]; 37 - } ? U : string; 66 + enum: readonly (infer U)[]; 67 + } 68 + ? U 69 + : string; 38 70 type GetRequired<T> = T extends { 39 - required: readonly (infer R)[]; 40 - } ? R : never; 71 + required: readonly (infer R)[]; 72 + } 73 + ? R 74 + : never; 41 75 type GetNullable<T> = T extends { 42 - nullable: readonly (infer N)[]; 43 - } ? N : never; 44 - type InferObject<T, Nullable extends string = GetNullable<T> & string, Required extends string = GetRequired<T> & string, NullableAndRequired extends string = Required & Nullable & string, Normal extends string = ("properties" extends keyof T ? Exclude<keyof T["properties"], Required | Nullable> & string : never)> = Prettify<T extends { 45 - properties: infer P; 46 - } ? { -readonly [K in Normal]?: InferType<P[K & keyof P]> } & { -readonly [K in Exclude<Required, NullableAndRequired>]-?: InferType<P[K & keyof P]> } & { -readonly [K in Exclude<Nullable, NullableAndRequired>]?: InferType<P[K & keyof P]> | null } & { -readonly [K in NullableAndRequired]: InferType<P[K & keyof P]> | null } : {}>; 76 + nullable: readonly (infer N)[]; 77 + } 78 + ? N 79 + : never; 80 + type InferObject< 81 + T, 82 + Nullable extends string = GetNullable<T> & string, 83 + Required extends string = GetRequired<T> & string, 84 + NullableAndRequired extends string = Required & Nullable & string, 85 + Normal extends string = "properties" extends keyof T 86 + ? Exclude<keyof T["properties"], Required | Nullable> & string 87 + : never, 88 + > = Prettify< 89 + T extends { 90 + properties: infer P; 91 + } 92 + ? { -readonly [K in Normal]?: InferType<P[K & keyof P]> } & { 93 + -readonly [K in Exclude<Required, NullableAndRequired>]-?: InferType< 94 + P[K & keyof P] 95 + >; 96 + } & { 97 + -readonly [K in Exclude<Nullable, NullableAndRequired>]?: InferType< 98 + P[K & keyof P] 99 + > | null; 100 + } & { 101 + -readonly [K in NullableAndRequired]: InferType<P[K & keyof P]> | null; 102 + } 103 + : {} 104 + >; 47 105 type InferArray<T> = T extends { 48 - items: infer Items; 49 - } ? InferType<Items>[] : never[]; 106 + items: infer Items; 107 + } 108 + ? InferType<Items>[] 109 + : never[]; 50 110 type InferUnion<T> = T extends { 51 - refs: readonly (infer R)[]; 52 - } ? R extends string ? { 53 - $type: R; 54 - [key: string]: unknown; 55 - } : never : never; 111 + refs: readonly (infer R)[]; 112 + } 113 + ? R extends string 114 + ? { 115 + $type: R; 116 + [key: string]: unknown; 117 + } 118 + : never 119 + : never; 56 120 type InferRef<T> = T extends { 57 - ref: infer R; 58 - } ? R extends string ? { 59 - $type: R; 60 - [key: string]: unknown; 61 - } : unknown : unknown; 121 + ref: infer R; 122 + } 123 + ? R extends string 124 + ? { 125 + $type: R; 126 + [key: string]: unknown; 127 + } 128 + : unknown 129 + : unknown; 62 130 type InferParams<T> = InferObject<T>; 63 131 type InferRecord<T> = T extends { 64 - record: infer R; 65 - } ? R extends { 66 - type: "object"; 67 - } ? InferObject<R> : R extends { 68 - type: "union"; 69 - } ? InferUnion<R> : unknown : unknown; 132 + record: infer R; 133 + } 134 + ? R extends { 135 + type: "object"; 136 + } 137 + ? InferObject<R> 138 + : R extends { 139 + type: "union"; 140 + } 141 + ? InferUnion<R> 142 + : unknown 143 + : unknown; 70 144 /** 71 145 * Recursively replaces stub references in a type with their actual definitions. 72 146 * Detects circular references and missing references, returning string literal error messages. 73 147 */ 74 148 type ReplaceRefsInType<T, Defs, Visited = never> = T extends { 75 - $type: `#${infer DefName}`; 76 - } ? DefName extends keyof Defs ? DefName extends Visited ? `[Circular reference detected: #${DefName}]` : Prettify<ReplaceRefsInType<Defs[DefName], Defs, Visited | DefName> & { 77 - $type: T["$type"]; 78 - }> : `[Reference not found: #${DefName}]` : T extends Uint8Array | Blob ? T : T extends readonly (infer Item)[] ? ReplaceRefsInType<Item, Defs, Visited>[] : T extends object ? T extends ((...args: unknown[]) => unknown) ? T : { [K in keyof T]: ReplaceRefsInType<T[K], Defs, Visited> } : T; 149 + $type: `#${infer DefName}`; 150 + } 151 + ? DefName extends keyof Defs 152 + ? DefName extends Visited 153 + ? `[Circular reference detected: #${DefName}]` 154 + : Prettify< 155 + ReplaceRefsInType<Defs[DefName], Defs, Visited | DefName> & { 156 + $type: T["$type"]; 157 + } 158 + > 159 + : `[Reference not found: #${DefName}]` 160 + : T extends Uint8Array | Blob 161 + ? T 162 + : T extends readonly (infer Item)[] 163 + ? ReplaceRefsInType<Item, Defs, Visited>[] 164 + : T extends object 165 + ? T extends (...args: unknown[]) => unknown 166 + ? T 167 + : { [K in keyof T]: ReplaceRefsInType<T[K], Defs, Visited> } 168 + : T; 79 169 /** 80 170 * Infers the TypeScript type for a lexicon namespace, returning only the 'main' definition 81 171 * with all local refs (#user, #post, etc.) resolved to their actual types. 82 172 */ 83 - type Infer<T extends { 84 - id: string; 85 - defs: Record<string, unknown>; 86 - }> = Prettify<"main" extends keyof T["defs"] ? { 87 - $type: T["id"]; 88 - } & ReplaceRefsInType<InferType<T["defs"]["main"]>, { [K in keyof T["defs"]]: InferType<T["defs"][K]> }> : never>; 173 + type Infer< 174 + T extends { 175 + id: string; 176 + defs: Record<string, unknown>; 177 + }, 178 + > = Prettify< 179 + "main" extends keyof T["defs"] 180 + ? { 181 + $type: T["id"]; 182 + } & ReplaceRefsInType< 183 + InferType<T["defs"]["main"]>, 184 + { [K in keyof T["defs"]]: InferType<T["defs"][K]> } 185 + > 186 + : never 187 + >; 89 188 //#endregion 90 189 export { GetNullable, GetRequired, Infer }; 91 - //# sourceMappingURL=infer.d.ts.map 190 + //# sourceMappingURL=infer.d.ts.map
+368 -278
packages/site/public/types/lib.d.ts
··· 3 3 4 4 //#region src/lib.d.ts 5 5 /** @see https://atproto.com/specs/lexicon#overview-of-types */ 6 - type LexiconType = "null" | "boolean" | "integer" | "string" | "bytes" | "cid-link" | "blob" | "array" | "object" | "params" | "token" | "ref" | "union" | "unknown" | "record" | "query" | "procedure" | "subscription"; 6 + type LexiconType = 7 + | "null" 8 + | "boolean" 9 + | "integer" 10 + | "string" 11 + | "bytes" 12 + | "cid-link" 13 + | "blob" 14 + | "array" 15 + | "object" 16 + | "params" 17 + | "token" 18 + | "ref" 19 + | "union" 20 + | "unknown" 21 + | "record" 22 + | "query" 23 + | "procedure" 24 + | "subscription"; 7 25 /** 8 26 * Common options available for lexicon items. 9 27 * @see https://atproto.com/specs/lexicon#string-formats 10 28 */ 11 29 interface LexiconItemCommonOptions { 12 - /** Indicates this field must be provided */ 13 - required?: boolean; 14 - /** Indicates this field can be explicitly set to null */ 15 - nullable?: boolean; 30 + /** Indicates this field must be provided */ 31 + required?: boolean; 32 + /** Indicates this field can be explicitly set to null */ 33 + nullable?: boolean; 16 34 } 17 35 /** 18 36 * Base interface for all lexicon items. 19 37 * @see https://atproto.com/specs/lexicon#overview-of-types 20 38 */ 21 39 interface LexiconItem extends LexiconItemCommonOptions { 22 - type: LexiconType; 40 + type: LexiconType; 23 41 } 24 42 /** 25 43 * Definition in a lexicon namespace. 26 44 * @see https://atproto.com/specs/lexicon#lexicon-document 27 45 */ 28 46 interface Def { 29 - type: LexiconType; 47 + type: LexiconType; 30 48 } 31 49 /** 32 50 * Lexicon namespace document structure. 33 51 * @see https://atproto.com/specs/lexicon#lexicon-document 34 52 */ 35 53 interface LexiconNamespace { 36 - /** Namespaced identifier (NSID) for this lexicon */ 37 - id: string; 38 - /** Named definitions within this namespace */ 39 - defs: Record<string, Def>; 54 + /** Namespaced identifier (NSID) for this lexicon */ 55 + id: string; 56 + /** Named definitions within this namespace */ 57 + defs: Record<string, Def>; 40 58 } 41 59 /** 42 60 * String type options. 43 61 * @see https://atproto.com/specs/lexicon#string 44 62 */ 45 63 interface StringOptions extends LexiconItemCommonOptions { 46 - /** 47 - * Semantic string format constraint. 48 - * @see https://atproto.com/specs/lexicon#string-formats 49 - */ 50 - format?: "at-identifier" | "at-uri" | "cid" | "datetime" | "did" | "handle" | "nsid" | "tid" | "record-key" | "uri" | "language"; 51 - /** Maximum string length in bytes */ 52 - maxLength?: number; 53 - /** Minimum string length in bytes */ 54 - minLength?: number; 55 - /** Maximum string length in Unicode graphemes */ 56 - maxGraphemes?: number; 57 - /** Minimum string length in Unicode graphemes */ 58 - minGraphemes?: number; 59 - /** Hints at expected values, not enforced */ 60 - knownValues?: string[]; 61 - /** Restricts to an exact set of string values */ 62 - enum?: string[]; 63 - /** Default value if not provided */ 64 - default?: string; 65 - /** Fixed, unchangeable value */ 66 - const?: string; 64 + /** 65 + * Semantic string format constraint. 66 + * @see https://atproto.com/specs/lexicon#string-formats 67 + */ 68 + format?: 69 + | "at-identifier" 70 + | "at-uri" 71 + | "cid" 72 + | "datetime" 73 + | "did" 74 + | "handle" 75 + | "nsid" 76 + | "tid" 77 + | "record-key" 78 + | "uri" 79 + | "language"; 80 + /** Maximum string length in bytes */ 81 + maxLength?: number; 82 + /** Minimum string length in bytes */ 83 + minLength?: number; 84 + /** Maximum string length in Unicode graphemes */ 85 + maxGraphemes?: number; 86 + /** Minimum string length in Unicode graphemes */ 87 + minGraphemes?: number; 88 + /** Hints at expected values, not enforced */ 89 + knownValues?: string[]; 90 + /** Restricts to an exact set of string values */ 91 + enum?: string[]; 92 + /** Default value if not provided */ 93 + default?: string; 94 + /** Fixed, unchangeable value */ 95 + const?: string; 67 96 } 68 97 /** 69 98 * Boolean type options. 70 99 * @see https://atproto.com/specs/lexicon#boolean 71 100 */ 72 101 interface BooleanOptions extends LexiconItemCommonOptions { 73 - /** Default value if not provided */ 74 - default?: boolean; 75 - /** Fixed, unchangeable value */ 76 - const?: boolean; 102 + /** Default value if not provided */ 103 + default?: boolean; 104 + /** Fixed, unchangeable value */ 105 + const?: boolean; 77 106 } 78 107 /** 79 108 * Integer type options. 80 109 * @see https://atproto.com/specs/lexicon#integer 81 110 */ 82 111 interface IntegerOptions extends LexiconItemCommonOptions { 83 - /** Minimum allowed value (inclusive) */ 84 - minimum?: number; 85 - /** Maximum allowed value (inclusive) */ 86 - maximum?: number; 87 - /** Restricts to an exact set of integer values */ 88 - enum?: number[]; 89 - /** Default value if not provided */ 90 - default?: number; 91 - /** Fixed, unchangeable value */ 92 - const?: number; 112 + /** Minimum allowed value (inclusive) */ 113 + minimum?: number; 114 + /** Maximum allowed value (inclusive) */ 115 + maximum?: number; 116 + /** Restricts to an exact set of integer values */ 117 + enum?: number[]; 118 + /** Default value if not provided */ 119 + default?: number; 120 + /** Fixed, unchangeable value */ 121 + const?: number; 93 122 } 94 123 /** 95 124 * Bytes type options for arbitrary byte arrays. 96 125 * @see https://atproto.com/specs/lexicon#bytes 97 126 */ 98 127 interface BytesOptions extends LexiconItemCommonOptions { 99 - /** Minimum byte array length */ 100 - minLength?: number; 101 - /** Maximum byte array length */ 102 - maxLength?: number; 128 + /** Minimum byte array length */ 129 + minLength?: number; 130 + /** Maximum byte array length */ 131 + maxLength?: number; 103 132 } 104 133 /** 105 134 * Blob type options for binary data with MIME types. 106 135 * @see https://atproto.com/specs/lexicon#blob 107 136 */ 108 137 interface BlobOptions extends LexiconItemCommonOptions { 109 - /** Allowed MIME types (e.g., ["image/png", "image/jpeg"]) */ 110 - accept?: string[]; 111 - /** Maximum blob size in bytes */ 112 - maxSize?: number; 138 + /** Allowed MIME types (e.g., ["image/png", "image/jpeg"]) */ 139 + accept?: string[]; 140 + /** Maximum blob size in bytes */ 141 + maxSize?: number; 113 142 } 114 143 /** 115 144 * Array type options. 116 145 * @see https://atproto.com/specs/lexicon#array 117 146 */ 118 147 interface ArrayOptions extends LexiconItemCommonOptions { 119 - /** Minimum array length */ 120 - minLength?: number; 121 - /** Maximum array length */ 122 - maxLength?: number; 148 + /** Minimum array length */ 149 + minLength?: number; 150 + /** Maximum array length */ 151 + maxLength?: number; 123 152 } 124 153 /** 125 154 * Record type options for repository records. 126 155 * @see https://atproto.com/specs/lexicon#record 127 156 */ 128 157 interface RecordOptions { 129 - /** Record key strategy: "self" for self-describing or "tid" for timestamp IDs */ 130 - key: "self" | "tid"; 131 - /** Object schema defining the record structure */ 132 - record: { 133 - type: "object"; 134 - }; 135 - /** Human-readable description */ 136 - description?: string; 158 + /** Record key strategy: "self" for self-describing or "tid" for timestamp IDs */ 159 + key: "self" | "tid"; 160 + /** Object schema defining the record structure */ 161 + record: { 162 + type: "object"; 163 + }; 164 + /** Human-readable description */ 165 + description?: string; 137 166 } 138 167 /** 139 168 * Union type options for multiple possible types. 140 169 * @see https://atproto.com/specs/lexicon#union 141 170 */ 142 171 interface UnionOptions extends LexiconItemCommonOptions { 143 - /** If true, only listed refs are allowed; if false, additional types may be added */ 144 - closed?: boolean; 172 + /** If true, only listed refs are allowed; if false, additional types may be added */ 173 + closed?: boolean; 145 174 } 146 175 /** 147 176 * Map of property names to their lexicon item definitions. 148 177 * @see https://atproto.com/specs/lexicon#object 149 178 */ 150 - type ObjectProperties = Record<string, { 151 - type: LexiconType; 152 - }>; 153 - type RequiredKeys<T> = { [K in keyof T]: T[K] extends { 154 - required: true; 155 - } ? K : never }[keyof T]; 156 - type NullableKeys<T> = { [K in keyof T]: T[K] extends { 157 - nullable: true; 158 - } ? K : never }[keyof T]; 179 + type ObjectProperties = Record< 180 + string, 181 + { 182 + type: LexiconType; 183 + } 184 + >; 185 + type RequiredKeys<T> = { 186 + [K in keyof T]: T[K] extends { 187 + required: true; 188 + } 189 + ? K 190 + : never; 191 + }[keyof T]; 192 + type NullableKeys<T> = { 193 + [K in keyof T]: T[K] extends { 194 + nullable: true; 195 + } 196 + ? K 197 + : never; 198 + }[keyof T]; 159 199 /** 160 200 * Resulting object schema with required and nullable fields extracted. 161 201 * @see https://atproto.com/specs/lexicon#object 162 202 */ 163 203 type ObjectResult<T extends ObjectProperties> = { 164 - type: "object"; 165 - /** Property definitions */ 166 - properties: { [K in keyof T]: T[K] extends { 167 - type: "object"; 168 - } ? T[K] : Omit<T[K], "required" | "nullable"> }; 169 - } & ([RequiredKeys<T>] extends [never] ? {} : { 170 - required: UnionToTuple<RequiredKeys<T>>; 171 - }) & ([NullableKeys<T>] extends [never] ? {} : { 172 - nullable: UnionToTuple<NullableKeys<T>>; 173 - }); 204 + type: "object"; 205 + /** Property definitions */ 206 + properties: { 207 + [K in keyof T]: T[K] extends { 208 + type: "object"; 209 + } 210 + ? T[K] 211 + : Omit<T[K], "required" | "nullable">; 212 + }; 213 + } & ([RequiredKeys<T>] extends [never] 214 + ? {} 215 + : { 216 + required: UnionToTuple<RequiredKeys<T>>; 217 + }) & 218 + ([NullableKeys<T>] extends [never] 219 + ? {} 220 + : { 221 + nullable: UnionToTuple<NullableKeys<T>>; 222 + }); 174 223 /** 175 224 * Map of parameter names to their lexicon item definitions. 176 225 * @see https://atproto.com/specs/lexicon#params ··· 181 230 * @see https://atproto.com/specs/lexicon#params 182 231 */ 183 232 type ParamsResult<T extends ParamsProperties> = { 184 - type: "params"; 185 - /** Parameter definitions */ 186 - properties: { [K in keyof T]: Omit<T[K], "required" | "nullable"> }; 187 - } & ([RequiredKeys<T>] extends [never] ? {} : { 188 - required: UnionToTuple<RequiredKeys<T>>; 189 - }); 233 + type: "params"; 234 + /** Parameter definitions */ 235 + properties: { [K in keyof T]: Omit<T[K], "required" | "nullable"> }; 236 + } & ([RequiredKeys<T>] extends [never] 237 + ? {} 238 + : { 239 + required: UnionToTuple<RequiredKeys<T>>; 240 + }); 190 241 /** 191 242 * HTTP request or response body schema. 192 243 * @see https://atproto.com/specs/lexicon#http-endpoints 193 244 */ 194 245 interface BodySchema { 195 - /** MIME type encoding (typically "application/json") */ 196 - encoding: "application/json" | (string & {}); 197 - /** Human-readable description */ 198 - description?: string; 199 - /** Object schema defining the body structure */ 200 - schema?: ObjectResult<ObjectProperties>; 246 + /** MIME type encoding (typically "application/json") */ 247 + encoding: "application/json" | (string & {}); 248 + /** Human-readable description */ 249 + description?: string; 250 + /** Object schema defining the body structure */ 251 + schema?: ObjectResult<ObjectProperties>; 201 252 } 202 253 /** 203 254 * Error definition for HTTP endpoints. 204 255 * @see https://atproto.com/specs/lexicon#http-endpoints 205 256 */ 206 257 interface ErrorDef { 207 - /** Error name/code */ 208 - name: string; 209 - /** Human-readable error description */ 210 - description?: string; 258 + /** Error name/code */ 259 + name: string; 260 + /** Human-readable error description */ 261 + description?: string; 211 262 } 212 263 /** 213 264 * Query endpoint options (HTTP GET). 214 265 * @see https://atproto.com/specs/lexicon#query 215 266 */ 216 267 interface QueryOptions { 217 - /** Human-readable description */ 218 - description?: string; 219 - /** Query string parameters */ 220 - parameters?: ParamsResult<ParamsProperties>; 221 - /** Response body schema */ 222 - output?: BodySchema; 223 - /** Possible error responses */ 224 - errors?: ErrorDef[]; 268 + /** Human-readable description */ 269 + description?: string; 270 + /** Query string parameters */ 271 + parameters?: ParamsResult<ParamsProperties>; 272 + /** Response body schema */ 273 + output?: BodySchema; 274 + /** Possible error responses */ 275 + errors?: ErrorDef[]; 225 276 } 226 277 /** 227 278 * Procedure endpoint options (HTTP POST). 228 279 * @see https://atproto.com/specs/lexicon#procedure 229 280 */ 230 281 interface ProcedureOptions { 231 - /** Human-readable description */ 232 - description?: string; 233 - /** Query string parameters */ 234 - parameters?: ParamsResult<ParamsProperties>; 235 - /** Request body schema */ 236 - input?: BodySchema; 237 - /** Response body schema */ 238 - output?: BodySchema; 239 - /** Possible error responses */ 240 - errors?: ErrorDef[]; 282 + /** Human-readable description */ 283 + description?: string; 284 + /** Query string parameters */ 285 + parameters?: ParamsResult<ParamsProperties>; 286 + /** Request body schema */ 287 + input?: BodySchema; 288 + /** Response body schema */ 289 + output?: BodySchema; 290 + /** Possible error responses */ 291 + errors?: ErrorDef[]; 241 292 } 242 293 /** 243 294 * WebSocket message schema for subscriptions. 244 295 * @see https://atproto.com/specs/lexicon#subscription 245 296 */ 246 297 interface MessageSchema { 247 - /** Human-readable description */ 248 - description?: string; 249 - /** Union of possible message types */ 250 - schema: { 251 - type: "union"; 252 - refs: readonly string[]; 253 - }; 298 + /** Human-readable description */ 299 + description?: string; 300 + /** Union of possible message types */ 301 + schema: { 302 + type: "union"; 303 + refs: readonly string[]; 304 + }; 254 305 } 255 306 /** 256 307 * Subscription endpoint options (WebSocket). 257 308 * @see https://atproto.com/specs/lexicon#subscription 258 309 */ 259 310 interface SubscriptionOptions { 260 - /** Human-readable description */ 261 - description?: string; 262 - /** Query string parameters */ 263 - parameters?: ParamsResult<ParamsProperties>; 264 - /** Message schema for events */ 265 - message?: MessageSchema; 266 - /** Possible error responses */ 267 - errors?: ErrorDef[]; 311 + /** Human-readable description */ 312 + description?: string; 313 + /** Query string parameters */ 314 + parameters?: ParamsResult<ParamsProperties>; 315 + /** Message schema for events */ 316 + message?: MessageSchema; 317 + /** Possible error responses */ 318 + errors?: ErrorDef[]; 268 319 } 269 320 declare class Namespace<T extends LexiconNamespace> { 270 - json: T; 271 - infer: Infer<T>; 272 - constructor(json: T); 321 + json: T; 322 + infer: Infer<T>; 323 + constructor(json: T); 273 324 } 274 325 /** 275 326 * Main API for creating lexicon schemas. 276 327 * @see https://atproto.com/specs/lexicon 277 328 */ 278 329 declare const lx: { 279 - /** 280 - * Creates a null type. 281 - * @see https://atproto.com/specs/lexicon#null 282 - */ 283 - null(options?: LexiconItemCommonOptions): { 284 - type: "null"; 285 - } & LexiconItemCommonOptions; 286 - /** 287 - * Creates a boolean type with optional constraints. 288 - * @see https://atproto.com/specs/lexicon#boolean 289 - */ 290 - boolean<T extends BooleanOptions>(options?: T): T & { 291 - type: "boolean"; 292 - }; 293 - /** 294 - * Creates an integer type with optional min/max and enum constraints. 295 - * @see https://atproto.com/specs/lexicon#integer 296 - */ 297 - integer<T extends IntegerOptions>(options?: T): T & { 298 - type: "integer"; 299 - }; 300 - /** 301 - * Creates a string type with optional format, length, and value constraints. 302 - * @see https://atproto.com/specs/lexicon#string 303 - */ 304 - string<T extends StringOptions>(options?: T): T & { 305 - type: "string"; 306 - }; 307 - /** 308 - * Creates an unknown type for flexible, unvalidated objects. 309 - * @see https://atproto.com/specs/lexicon#unknown 310 - */ 311 - unknown(options?: LexiconItemCommonOptions): { 312 - type: "unknown"; 313 - } & LexiconItemCommonOptions; 314 - /** 315 - * Creates a bytes type for arbitrary byte arrays. 316 - * @see https://atproto.com/specs/lexicon#bytes 317 - */ 318 - bytes<T extends BytesOptions>(options?: T): T & { 319 - type: "bytes"; 320 - }; 321 - /** 322 - * Creates a CID link reference to content-addressed data. 323 - * @see https://atproto.com/specs/lexicon#cid-link 324 - */ 325 - cidLink<Link extends string>(link: Link): { 326 - type: "cid-link"; 327 - $link: Link; 328 - }; 329 - /** 330 - * Creates a blob type for binary data with MIME type constraints. 331 - * @see https://atproto.com/specs/lexicon#blob 332 - */ 333 - blob<T extends BlobOptions>(options?: T): T & { 334 - type: "blob"; 335 - }; 336 - /** 337 - * Creates an array type with item schema and length constraints. 338 - * @see https://atproto.com/specs/lexicon#array 339 - */ 340 - array<Items extends { 341 - type: LexiconType; 342 - }, Options extends ArrayOptions>(items: Items, options?: Options): Options & { 343 - type: "array"; 344 - items: Items; 345 - }; 346 - /** 347 - * Creates a token type for symbolic values in unions. 348 - * @see https://atproto.com/specs/lexicon#token 349 - */ 350 - token<Description extends string>(description: Description): { 351 - type: "token"; 352 - description: Description; 353 - }; 354 - /** 355 - * Creates a reference to another schema definition. 356 - * @see https://atproto.com/specs/lexicon#ref 357 - */ 358 - ref<Ref extends string>(ref: Ref, options?: LexiconItemCommonOptions): LexiconItemCommonOptions & { 359 - type: "ref"; 360 - ref: Ref; 361 - }; 362 - /** 363 - * Creates a union type for multiple possible type variants. 364 - * @see https://atproto.com/specs/lexicon#union 365 - */ 366 - union<const Refs extends readonly string[], Options extends UnionOptions>(refs: Refs, options?: Options): Options & { 367 - type: "union"; 368 - refs: Refs; 369 - }; 370 - /** 371 - * Creates a record type for repository records. 372 - * @see https://atproto.com/specs/lexicon#record 373 - */ 374 - record<T extends RecordOptions>(options: T): T & { 375 - type: "record"; 376 - }; 377 - /** 378 - * Creates an object type with defined properties. 379 - * @see https://atproto.com/specs/lexicon#object 380 - */ 381 - object<T extends ObjectProperties>(options: T): ObjectResult<T>; 382 - /** 383 - * Creates a params type for query string parameters. 384 - * @see https://atproto.com/specs/lexicon#params 385 - */ 386 - params<Properties extends ParamsProperties>(properties: Properties): ParamsResult<Properties>; 387 - /** 388 - * Creates a query endpoint definition (HTTP GET). 389 - * @see https://atproto.com/specs/lexicon#query 390 - */ 391 - query<T extends QueryOptions>(options?: T): T & { 392 - type: "query"; 393 - }; 394 - /** 395 - * Creates a procedure endpoint definition (HTTP POST). 396 - * @see https://atproto.com/specs/lexicon#procedure 397 - */ 398 - procedure<T extends ProcedureOptions>(options?: T): T & { 399 - type: "procedure"; 400 - }; 401 - /** 402 - * Creates a subscription endpoint definition (WebSocket). 403 - * @see https://atproto.com/specs/lexicon#subscription 404 - */ 405 - subscription<T extends SubscriptionOptions>(options?: T): T & { 406 - type: "subscription"; 407 - }; 408 - /** 409 - * Creates a lexicon namespace document. 410 - * @see https://atproto.com/specs/lexicon#lexicon-document 411 - */ 412 - namespace<ID extends string, D extends LexiconNamespace["defs"]>(id: ID, defs: D): Namespace<{ 413 - lexicon: 1; 414 - id: ID; 415 - defs: D; 416 - }>; 330 + /** 331 + * Creates a null type. 332 + * @see https://atproto.com/specs/lexicon#null 333 + */ 334 + null(options?: LexiconItemCommonOptions): { 335 + type: "null"; 336 + } & LexiconItemCommonOptions; 337 + /** 338 + * Creates a boolean type with optional constraints. 339 + * @see https://atproto.com/specs/lexicon#boolean 340 + */ 341 + boolean<T extends BooleanOptions>( 342 + options?: T, 343 + ): T & { 344 + type: "boolean"; 345 + }; 346 + /** 347 + * Creates an integer type with optional min/max and enum constraints. 348 + * @see https://atproto.com/specs/lexicon#integer 349 + */ 350 + integer<T extends IntegerOptions>( 351 + options?: T, 352 + ): T & { 353 + type: "integer"; 354 + }; 355 + /** 356 + * Creates a string type with optional format, length, and value constraints. 357 + * @see https://atproto.com/specs/lexicon#string 358 + */ 359 + string<T extends StringOptions>( 360 + options?: T, 361 + ): T & { 362 + type: "string"; 363 + }; 364 + /** 365 + * Creates an unknown type for flexible, unvalidated objects. 366 + * @see https://atproto.com/specs/lexicon#unknown 367 + */ 368 + unknown(options?: LexiconItemCommonOptions): { 369 + type: "unknown"; 370 + } & LexiconItemCommonOptions; 371 + /** 372 + * Creates a bytes type for arbitrary byte arrays. 373 + * @see https://atproto.com/specs/lexicon#bytes 374 + */ 375 + bytes<T extends BytesOptions>( 376 + options?: T, 377 + ): T & { 378 + type: "bytes"; 379 + }; 380 + /** 381 + * Creates a CID link reference to content-addressed data. 382 + * @see https://atproto.com/specs/lexicon#cid-link 383 + */ 384 + cidLink<Link extends string>( 385 + link: Link, 386 + ): { 387 + type: "cid-link"; 388 + $link: Link; 389 + }; 390 + /** 391 + * Creates a blob type for binary data with MIME type constraints. 392 + * @see https://atproto.com/specs/lexicon#blob 393 + */ 394 + blob<T extends BlobOptions>( 395 + options?: T, 396 + ): T & { 397 + type: "blob"; 398 + }; 399 + /** 400 + * Creates an array type with item schema and length constraints. 401 + * @see https://atproto.com/specs/lexicon#array 402 + */ 403 + array< 404 + Items extends { 405 + type: LexiconType; 406 + }, 407 + Options extends ArrayOptions, 408 + >( 409 + items: Items, 410 + options?: Options, 411 + ): Options & { 412 + type: "array"; 413 + items: Items; 414 + }; 415 + /** 416 + * Creates a token type for symbolic values in unions. 417 + * @see https://atproto.com/specs/lexicon#token 418 + */ 419 + token<Description extends string>( 420 + description: Description, 421 + ): { 422 + type: "token"; 423 + description: Description; 424 + }; 425 + /** 426 + * Creates a reference to another schema definition. 427 + * @see https://atproto.com/specs/lexicon#ref 428 + */ 429 + ref<Ref extends string>( 430 + ref: Ref, 431 + options?: LexiconItemCommonOptions, 432 + ): LexiconItemCommonOptions & { 433 + type: "ref"; 434 + ref: Ref; 435 + }; 436 + /** 437 + * Creates a union type for multiple possible type variants. 438 + * @see https://atproto.com/specs/lexicon#union 439 + */ 440 + union<const Refs extends readonly string[], Options extends UnionOptions>( 441 + refs: Refs, 442 + options?: Options, 443 + ): Options & { 444 + type: "union"; 445 + refs: Refs; 446 + }; 447 + /** 448 + * Creates a record type for repository records. 449 + * @see https://atproto.com/specs/lexicon#record 450 + */ 451 + record<T extends RecordOptions>( 452 + options: T, 453 + ): T & { 454 + type: "record"; 455 + }; 456 + /** 457 + * Creates an object type with defined properties. 458 + * @see https://atproto.com/specs/lexicon#object 459 + */ 460 + object<T extends ObjectProperties>(options: T): ObjectResult<T>; 461 + /** 462 + * Creates a params type for query string parameters. 463 + * @see https://atproto.com/specs/lexicon#params 464 + */ 465 + params<Properties extends ParamsProperties>( 466 + properties: Properties, 467 + ): ParamsResult<Properties>; 468 + /** 469 + * Creates a query endpoint definition (HTTP GET). 470 + * @see https://atproto.com/specs/lexicon#query 471 + */ 472 + query<T extends QueryOptions>( 473 + options?: T, 474 + ): T & { 475 + type: "query"; 476 + }; 477 + /** 478 + * Creates a procedure endpoint definition (HTTP POST). 479 + * @see https://atproto.com/specs/lexicon#procedure 480 + */ 481 + procedure<T extends ProcedureOptions>( 482 + options?: T, 483 + ): T & { 484 + type: "procedure"; 485 + }; 486 + /** 487 + * Creates a subscription endpoint definition (WebSocket). 488 + * @see https://atproto.com/specs/lexicon#subscription 489 + */ 490 + subscription<T extends SubscriptionOptions>( 491 + options?: T, 492 + ): T & { 493 + type: "subscription"; 494 + }; 495 + /** 496 + * Creates a lexicon namespace document. 497 + * @see https://atproto.com/specs/lexicon#lexicon-document 498 + */ 499 + namespace<ID extends string, D extends LexiconNamespace["defs"]>( 500 + id: ID, 501 + defs: D, 502 + ): Namespace<{ 503 + lexicon: 1; 504 + id: ID; 505 + defs: D; 506 + }>; 417 507 }; 418 508 //#endregion 419 509 export { lx }; 420 - //# sourceMappingURL=lib.d.ts.map 510 + //# sourceMappingURL=lib.d.ts.map
+10 -2
packages/site/public/types/type-utils.d.ts
··· 5 5 * type Colors = "red" | "green" | "blue"; 6 6 * type ColorTuple = UnionToTuple<Colors>; // ["red", "green", "blue"] 7 7 */ 8 - type UnionToTuple<T> = ((T extends unknown ? (x: () => T) => void : never) extends ((x: infer I) => void) ? I : never) extends (() => infer R) ? [...UnionToTuple<Exclude<T, R>>, R] : []; 8 + type UnionToTuple<T> = ( 9 + (T extends unknown ? (x: () => T) => void : never) extends ( 10 + x: infer I, 11 + ) => void 12 + ? I 13 + : never 14 + ) extends () => infer R 15 + ? [...UnionToTuple<Exclude<T, R>>, R] 16 + : []; 9 17 type Prettify<T> = { [K in keyof T]: T[K] } & {}; 10 18 //# sourceMappingURL=type-utils.d.ts.map 11 19 12 20 //#endregion 13 21 export { Prettify, UnionToTuple }; 14 - //# sourceMappingURL=type-utils.d.ts.map 22 + //# sourceMappingURL=type-utils.d.ts.map
-18
pnpm-lock.yaml
··· 49 49 specifier: ^3.2.4 50 50 version: 3.2.4(@types/node@24.0.4)(esbuild@0.25.10)(jiti@2.6.1)(jsdom@25.0.1) 51 51 52 - packages/prototypekit: 53 - devDependencies: 54 - '@ark/attest': 55 - specifier: ^0.49.0 56 - version: 0.49.0(typescript@5.8.3) 57 - '@types/node': 58 - specifier: 24.0.4 59 - version: 24.0.4 60 - tsdown: 61 - specifier: 0.12.7 62 - version: 0.12.7(typescript@5.8.3) 63 - typescript: 64 - specifier: 5.8.3 65 - version: 5.8.3 66 - vitest: 67 - specifier: ^3.2.4 68 - version: 3.2.4(@types/node@24.0.4)(esbuild@0.25.10)(jiti@2.6.1)(jsdom@25.0.1) 69 - 70 52 packages/prototypey: 71 53 devDependencies: 72 54 '@ark/attest':