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.

working types

Tyler ee61dff7 beda016d

+594 -32
+3
packages/site/public/types/index.d.ts
··· 1 + import { GetNullable, GetRequired, Infer } from "./infer.js"; 2 + import { lx } from "./lib.js"; 3 + export { GetNullable, GetRequired, Infer, lx };
+91
packages/site/public/types/infer.d.ts
··· 1 + import { Prettify } from "./type-utils.js"; 2 + 3 + //#region src/infer.d.ts 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; 35 + type InferToken<T> = T extends { 36 + enum: readonly (infer U)[]; 37 + } ? U : string; 38 + type GetRequired<T> = T extends { 39 + required: readonly (infer R)[]; 40 + } ? R : never; 41 + 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 } : {}>; 47 + type InferArray<T> = T extends { 48 + items: infer Items; 49 + } ? InferType<Items>[] : never[]; 50 + type InferUnion<T> = T extends { 51 + refs: readonly (infer R)[]; 52 + } ? R extends string ? { 53 + $type: R; 54 + [key: string]: unknown; 55 + } : never : never; 56 + type InferRef<T> = T extends { 57 + ref: infer R; 58 + } ? R extends string ? { 59 + $type: R; 60 + [key: string]: unknown; 61 + } : unknown : unknown; 62 + type InferParams<T> = InferObject<T>; 63 + 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; 70 + /** 71 + * Recursively replaces stub references in a type with their actual definitions. 72 + * Detects circular references and missing references, returning string literal error messages. 73 + */ 74 + 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; 79 + /** 80 + * Infers the TypeScript type for a lexicon namespace, returning only the 'main' definition 81 + * with all local refs (#user, #post, etc.) resolved to their actual types. 82 + */ 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>; 89 + //#endregion 90 + export { GetNullable, GetRequired, Infer }; 91 + //# sourceMappingURL=infer.d.ts.map
+420
packages/site/public/types/lib.d.ts
··· 1 + import { UnionToTuple } from "./type-utils.js"; 2 + import { Infer } from "./infer.js"; 3 + 4 + //#region src/lib.d.ts 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"; 7 + /** 8 + * Common options available for lexicon items. 9 + * @see https://atproto.com/specs/lexicon#string-formats 10 + */ 11 + 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; 16 + } 17 + /** 18 + * Base interface for all lexicon items. 19 + * @see https://atproto.com/specs/lexicon#overview-of-types 20 + */ 21 + interface LexiconItem extends LexiconItemCommonOptions { 22 + type: LexiconType; 23 + } 24 + /** 25 + * Definition in a lexicon namespace. 26 + * @see https://atproto.com/specs/lexicon#lexicon-document 27 + */ 28 + interface Def { 29 + type: LexiconType; 30 + } 31 + /** 32 + * Lexicon namespace document structure. 33 + * @see https://atproto.com/specs/lexicon#lexicon-document 34 + */ 35 + interface LexiconNamespace { 36 + /** Namespaced identifier (NSID) for this lexicon */ 37 + id: string; 38 + /** Named definitions within this namespace */ 39 + defs: Record<string, Def>; 40 + } 41 + /** 42 + * String type options. 43 + * @see https://atproto.com/specs/lexicon#string 44 + */ 45 + 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; 67 + } 68 + /** 69 + * Boolean type options. 70 + * @see https://atproto.com/specs/lexicon#boolean 71 + */ 72 + interface BooleanOptions extends LexiconItemCommonOptions { 73 + /** Default value if not provided */ 74 + default?: boolean; 75 + /** Fixed, unchangeable value */ 76 + const?: boolean; 77 + } 78 + /** 79 + * Integer type options. 80 + * @see https://atproto.com/specs/lexicon#integer 81 + */ 82 + 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; 93 + } 94 + /** 95 + * Bytes type options for arbitrary byte arrays. 96 + * @see https://atproto.com/specs/lexicon#bytes 97 + */ 98 + interface BytesOptions extends LexiconItemCommonOptions { 99 + /** Minimum byte array length */ 100 + minLength?: number; 101 + /** Maximum byte array length */ 102 + maxLength?: number; 103 + } 104 + /** 105 + * Blob type options for binary data with MIME types. 106 + * @see https://atproto.com/specs/lexicon#blob 107 + */ 108 + 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; 113 + } 114 + /** 115 + * Array type options. 116 + * @see https://atproto.com/specs/lexicon#array 117 + */ 118 + interface ArrayOptions extends LexiconItemCommonOptions { 119 + /** Minimum array length */ 120 + minLength?: number; 121 + /** Maximum array length */ 122 + maxLength?: number; 123 + } 124 + /** 125 + * Record type options for repository records. 126 + * @see https://atproto.com/specs/lexicon#record 127 + */ 128 + 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; 137 + } 138 + /** 139 + * Union type options for multiple possible types. 140 + * @see https://atproto.com/specs/lexicon#union 141 + */ 142 + interface UnionOptions extends LexiconItemCommonOptions { 143 + /** If true, only listed refs are allowed; if false, additional types may be added */ 144 + closed?: boolean; 145 + } 146 + /** 147 + * Map of property names to their lexicon item definitions. 148 + * @see https://atproto.com/specs/lexicon#object 149 + */ 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]; 159 + /** 160 + * Resulting object schema with required and nullable fields extracted. 161 + * @see https://atproto.com/specs/lexicon#object 162 + */ 163 + 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 + }); 174 + /** 175 + * Map of parameter names to their lexicon item definitions. 176 + * @see https://atproto.com/specs/lexicon#params 177 + */ 178 + type ParamsProperties = Record<string, LexiconItem>; 179 + /** 180 + * Resulting params schema with required fields extracted. 181 + * @see https://atproto.com/specs/lexicon#params 182 + */ 183 + 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 + }); 190 + /** 191 + * HTTP request or response body schema. 192 + * @see https://atproto.com/specs/lexicon#http-endpoints 193 + */ 194 + 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>; 201 + } 202 + /** 203 + * Error definition for HTTP endpoints. 204 + * @see https://atproto.com/specs/lexicon#http-endpoints 205 + */ 206 + interface ErrorDef { 207 + /** Error name/code */ 208 + name: string; 209 + /** Human-readable error description */ 210 + description?: string; 211 + } 212 + /** 213 + * Query endpoint options (HTTP GET). 214 + * @see https://atproto.com/specs/lexicon#query 215 + */ 216 + 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[]; 225 + } 226 + /** 227 + * Procedure endpoint options (HTTP POST). 228 + * @see https://atproto.com/specs/lexicon#procedure 229 + */ 230 + 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[]; 241 + } 242 + /** 243 + * WebSocket message schema for subscriptions. 244 + * @see https://atproto.com/specs/lexicon#subscription 245 + */ 246 + 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 + }; 254 + } 255 + /** 256 + * Subscription endpoint options (WebSocket). 257 + * @see https://atproto.com/specs/lexicon#subscription 258 + */ 259 + 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[]; 268 + } 269 + declare class Namespace<T extends LexiconNamespace> { 270 + json: T; 271 + infer: Infer<T>; 272 + constructor(json: T); 273 + } 274 + /** 275 + * Main API for creating lexicon schemas. 276 + * @see https://atproto.com/specs/lexicon 277 + */ 278 + 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 + }>; 417 + }; 418 + //#endregion 419 + export { lx }; 420 + //# sourceMappingURL=lib.d.ts.map
+14
packages/site/public/types/type-utils.d.ts
··· 1 + //#region src/type-utils.d.ts 2 + /** 3 + * Converts a string union type to a tuple type 4 + * @example 5 + * type Colors = "red" | "green" | "blue"; 6 + * type ColorTuple = UnionToTuple<Colors>; // ["red", "green", "blue"] 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] : []; 9 + type Prettify<T> = { [K in keyof T]: T[K] } & {}; 10 + //# sourceMappingURL=type-utils.d.ts.map 11 + 12 + //#endregion 13 + export { Prettify, UnionToTuple }; 14 + //# sourceMappingURL=type-utils.d.ts.map
+34 -31
packages/site/src/components/Editor.tsx
··· 6 6 } 7 7 8 8 export function Editor({ value, onChange }: EditorProps) { 9 - const handleEditorWillMount = (monaco: typeof import("monaco-editor")) => { 9 + const handleEditorWillMount = async ( 10 + monaco: typeof import("monaco-editor"), 11 + ) => { 10 12 monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({ 11 13 noSemanticValidation: false, 12 14 noSyntaxValidation: false, ··· 15 17 monaco.languages.typescript.typescriptDefaults.setCompilerOptions({ 16 18 target: monaco.languages.typescript.ScriptTarget.ES2020, 17 19 allowNonTsExtensions: true, 18 - moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, 20 + moduleResolution: 21 + monaco.languages.typescript.ModuleResolutionKind.NodeJs, 19 22 module: monaco.languages.typescript.ModuleKind.ESNext, 20 23 noEmit: true, 21 24 esModuleInterop: true, 22 25 allowSyntheticDefaultImports: true, 23 26 }); 24 27 25 - monaco.languages.typescript.typescriptDefaults.addExtraLib( 26 - `declare module "prototypekit" { 27 - type Prettify<T> = { [K in keyof T]: T[K] } & {}; 28 - 29 - 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] : []; 28 + try { 29 + const [typeUtilsDts, inferDts, libDts, indexDts] = await Promise.all([ 30 + fetch("/types/type-utils.d.ts").then((r) => r.text()), 31 + fetch("/types/infer.d.ts").then((r) => r.text()), 32 + fetch("/types/lib.d.ts").then((r) => r.text()), 33 + fetch("/types/index.d.ts").then((r) => r.text()), 34 + ]); 35 + 36 + monaco.languages.typescript.typescriptDefaults.addExtraLib( 37 + typeUtilsDts, 38 + "file:///node_modules/prototypekit/type-utils.d.ts", 39 + ); 40 + 41 + monaco.languages.typescript.typescriptDefaults.addExtraLib( 42 + inferDts, 43 + "file:///node_modules/prototypekit/infer.d.ts", 44 + ); 45 + 46 + monaco.languages.typescript.typescriptDefaults.addExtraLib( 47 + libDts, 48 + "file:///node_modules/prototypekit/lib.d.ts", 49 + ); 30 50 31 - export const lx: { 32 - null(options?: { required?: boolean; nullable?: boolean }): { type: "null" } & { required?: boolean; nullable?: boolean }; 33 - boolean<T extends { required?: boolean; nullable?: boolean; default?: boolean; const?: boolean }>(options?: T): T & { type: "boolean" }; 34 - integer<T extends { required?: boolean; nullable?: boolean; minimum?: number; maximum?: number; enum?: number[]; default?: number; const?: number }>(options?: T): T & { type: "integer" }; 35 - string<T extends { required?: boolean; nullable?: boolean; format?: "at-identifier" | "at-uri" | "cid" | "datetime" | "did" | "handle" | "nsid" | "tid" | "record-key" | "uri" | "language"; maxLength?: number; minLength?: number; maxGraphemes?: number; minGraphemes?: number; knownValues?: string[]; enum?: string[]; default?: string; const?: string }>(options?: T): T & { type: "string" }; 36 - unknown(options?: { required?: boolean; nullable?: boolean }): { type: "unknown" } & { required?: boolean; nullable?: boolean }; 37 - bytes<T extends { required?: boolean; nullable?: boolean; minLength?: number; maxLength?: number }>(options?: T): T & { type: "bytes" }; 38 - cidLink<Link extends string>(link: Link): { type: "cid-link"; $link: Link }; 39 - blob<T extends { required?: boolean; nullable?: boolean; accept?: string[]; maxSize?: number }>(options?: T): T & { type: "blob" }; 40 - array<Items extends { type: any }, Options extends { required?: boolean; nullable?: boolean; minLength?: number; maxLength?: number }>(items: Items, options?: Options): Options & { type: "array"; items: Items }; 41 - token<Description extends string>(description: Description): { type: "token"; description: Description }; 42 - ref<Ref extends string>(ref: Ref, options?: { required?: boolean; nullable?: boolean }): { required?: boolean; nullable?: boolean } & { type: "ref"; ref: Ref }; 43 - union<const Refs extends readonly string[], Options extends { required?: boolean; nullable?: boolean; closed?: boolean }>(refs: Refs, options?: Options): Options & { type: "union"; refs: Refs }; 44 - record<T extends { key: "self" | "tid"; record: { type: "object" }; description?: string }>(options: T): T & { type: "record" }; 45 - object<T extends Record<string, { type: any }>>(options: T): any; 46 - params<Properties extends Record<string, any>>(properties: Properties): any; 47 - query<T extends { description?: string; parameters?: any; output?: any; errors?: any[] }>(options?: T): T & { type: "query" }; 48 - procedure<T extends { description?: string; parameters?: any; input?: any; output?: any; errors?: any[] }>(options?: T): T & { type: "procedure" }; 49 - subscription<T extends { description?: string; parameters?: any; message?: any; errors?: any[] }>(options?: T): T & { type: "subscription" }; 50 - namespace<ID extends string, D extends Record<string, { type: any }>>(id: ID, defs: D): { json: { lexicon: 1; id: ID; defs: D }; infer: any }; 51 - }; 52 - }`, 53 - "file:///node_modules/prototypekit/index.d.ts", 54 - ); 51 + monaco.languages.typescript.typescriptDefaults.addExtraLib( 52 + indexDts, 53 + "file:///node_modules/prototypekit/index.d.ts", 54 + ); 55 + } catch (error) { 56 + console.error("Failed to load prototypekit types:", error); 57 + } 55 58 }; 56 59 57 60 return (
+32 -1
packages/site/vite.config.ts
··· 1 1 import { defineConfig } from "vite"; 2 2 import react from "@vitejs/plugin-react"; 3 + import { readFileSync } from "fs"; 4 + import { resolve } from "path"; 5 + 6 + function servePrototypeKitTypes() { 7 + return { 8 + name: "serve-prototypekit-types", 9 + configureServer(server) { 10 + server.middlewares.use((req, res, next) => { 11 + if (req.url?.startsWith("/types/") && req.url.endsWith(".d.ts")) { 12 + const fileName = req.url.slice(7); 13 + try { 14 + const filePath = resolve( 15 + __dirname, 16 + "../prototypekit/lib", 17 + fileName, 18 + ); 19 + const content = readFileSync(filePath, "utf-8"); 20 + res.setHeader("Content-Type", "application/typescript"); 21 + res.end(content); 22 + return; 23 + } catch (e) { 24 + res.statusCode = 404; 25 + res.end("Type file not found"); 26 + return; 27 + } 28 + } 29 + next(); 30 + }); 31 + }, 32 + }; 33 + } 3 34 4 35 export default defineConfig({ 5 - plugins: [react()], 36 + plugins: [react(), servePrototypeKitTypes()], 6 37 });