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

hide infer as ~infer and add main to package.json

Tyler 15d5b7c3 8eebe5c0

+58 -52
+5
.changeset/dark-hounds-smash.md
···
··· 1 + --- 2 + "prototypey": patch 3 + --- 4 + 5 + hide infer as ~infer
+2 -2
packages/prototypey/core/lib.ts
··· 334 */ 335 export interface LexiconSchema<T extends LexiconNamespace> { 336 json: T; 337 - infer: Infer<{ json: T }>; 338 validate( 339 data: unknown, 340 def?: keyof T["defs"], ··· 343 344 class Lexicon<T extends LexiconNamespace> implements LexiconSchema<T> { 345 public json: T; 346 - public infer: Infer<{ json: T }> = null as unknown as Infer<{ json: T }>; 347 private _validator: Lexicons; 348 349 constructor(json: T) {
··· 334 */ 335 export interface LexiconSchema<T extends LexiconNamespace> { 336 json: T; 337 + "~infer": Infer<{ json: T }>; 338 validate( 339 data: unknown, 340 def?: keyof T["defs"], ··· 343 344 class Lexicon<T extends LexiconNamespace> implements LexiconSchema<T> { 345 public json: T; 346 + public "~infer": Infer<{ json: T }> = null as unknown as Infer<{ json: T }>; 347 private _validator: Lexicons; 348 349 constructor(json: T) {
+4 -4
packages/prototypey/core/tests/infer.bench.ts
··· 8 name: lx.string({ required: true }), 9 }), 10 }); 11 - return schema.infer; 12 }).types([741, "instantiations"]); 13 14 bench("infer with complex nested structure", () => { ··· 31 }), 32 }), 33 }); 34 - return schema.infer; 35 }).types([1040, "instantiations"]); 36 37 bench("infer with circular reference", () => { ··· 48 users: lx.array(lx.ref("#user")), 49 }), 50 }); 51 - return ns.infer; 52 }).types([692, "instantiations"]); 53 54 bench("infer with app.bsky.feed.defs lexicon", () => { ··· 115 interactionQuote: lx.token("User quoted the feed item"), 116 interactionShare: lx.token("User shared the feed item"), 117 }); 118 - return schema.infer; 119 }).types([1285, "instantiations"]);
··· 8 name: lx.string({ required: true }), 9 }), 10 }); 11 + return schema["~infer"]; 12 }).types([741, "instantiations"]); 13 14 bench("infer with complex nested structure", () => { ··· 31 }), 32 }), 33 }); 34 + return schema["~infer"]; 35 }).types([1040, "instantiations"]); 36 37 bench("infer with circular reference", () => { ··· 48 users: lx.array(lx.ref("#user")), 49 }), 50 }); 51 + return ns["~infer"]; 52 }).types([692, "instantiations"]); 53 54 bench("infer with app.bsky.feed.defs lexicon", () => { ··· 115 interactionQuote: lx.token("User quoted the feed item"), 116 interactionShare: lx.token("User shared the feed item"), 117 }); 118 + return schema["~infer"]; 119 }).types([1285, "instantiations"]);
+46 -46
packages/prototypey/core/tests/infer.test.ts
··· 16 }); 17 18 // Type snapshot - this captures how types appear on hover 19 - attest(exampleLexicon.infer).type.toString.snap(`{ 20 $type: "com.example.post" 21 tags?: string[] | undefined 22 likes?: number | undefined ··· 33 }), 34 }); 35 36 - attest(schema.infer).type.toString.snap(`{ 37 $type: "test" 38 optional?: string | undefined 39 required: string ··· 47 }), 48 }); 49 50 - attest(schema.infer).type.toString.snap( 51 '{ $type: "test"; nullable: string | null }', 52 ); 53 }); ··· 63 }), 64 }); 65 66 - attest(lexicon.infer).type.toString.snap(`{ 67 $type: "test.string" 68 simpleString?: string | undefined 69 }`); ··· 77 }), 78 }); 79 80 - attest(lexicon.infer).type.toString.snap(`{ 81 $type: "test.integer" 82 count?: number | undefined 83 age?: number | undefined ··· 92 }), 93 }); 94 95 - attest(lexicon.infer).type.toString.snap(`{ 96 $type: "test.boolean" 97 isActive?: boolean | undefined 98 hasAccess: boolean ··· 106 }), 107 }); 108 109 - attest(lexicon.infer).type.toString.snap(`{ 110 $type: "test.null" 111 nullValue?: null | undefined 112 }`); ··· 119 }), 120 }); 121 122 - attest(lexicon.infer).type.toString.snap( 123 '{ $type: "test.unknown"; metadata?: unknown }', 124 ); 125 }); ··· 131 }), 132 }); 133 134 - attest(lexicon.infer).type.toString.snap(`{ 135 $type: "test.bytes" 136 data?: Uint8Array<ArrayBufferLike> | undefined 137 }`); ··· 144 }), 145 }); 146 147 - attest(lexicon.infer).type.toString.snap( 148 '{ $type: "test.blob"; image?: Blob | undefined }', 149 ); 150 }); ··· 160 }), 161 }); 162 163 - attest(lexicon.infer).type.toString.snap(`{ 164 $type: "test.token" 165 symbol?: string | undefined 166 }`); ··· 177 }), 178 }); 179 180 - attest(lexicon.infer).type.toString.snap(`{ 181 $type: "test.array.string" 182 tags?: string[] | undefined 183 }`); ··· 190 }), 191 }); 192 193 - attest(lexicon.infer).type.toString.snap(`{ 194 $type: "test.array.integer" 195 scores?: number[] | undefined 196 }`); ··· 203 }), 204 }); 205 206 - attest(lexicon.infer).type.toString.snap(`{ 207 $type: "test.array.boolean" 208 flags?: boolean[] | undefined 209 }`); ··· 216 }), 217 }); 218 219 - attest(lexicon.infer).type.toString.snap(`{ 220 $type: "test.array.unknown" 221 items?: unknown[] | undefined 222 }`); ··· 236 }), 237 }); 238 239 - attest(lexicon.infer).type.toString.snap(`{ 240 $type: "test.mixed" 241 age?: number | undefined 242 email?: string | undefined ··· 254 }), 255 }); 256 257 - attest(lexicon.infer).type.toString.snap(`{ 258 $type: "test.allOptional" 259 field1?: string | undefined 260 field2?: number | undefined ··· 271 }), 272 }); 273 274 - attest(lexicon.infer).type.toString.snap(`{ 275 $type: "test.allRequired" 276 field1: string 277 field2: number ··· 290 }), 291 }); 292 293 - attest(lexicon.infer).type.toString.snap(`{ 294 $type: "test.nullableOptional" 295 description?: string | null | undefined 296 }`); ··· 305 }), 306 }); 307 308 - attest(lexicon.infer).type.toString.snap(`{ 309 $type: "test.multipleNullable" 310 field1?: string | null | undefined 311 field2?: number | null | undefined ··· 320 }), 321 }); 322 323 - attest(lexicon.infer).type.toString.snap(`{ 324 $type: "test.nullableRequired" 325 value: string | null 326 }`); ··· 336 }), 337 }); 338 339 - attest(lexicon.infer).type.toString.snap(`{ 340 $type: "test.mixedNullable" 341 optional?: string | undefined 342 required: string ··· 356 }), 357 }); 358 359 - attest(lexicon.infer).type.toString.snap(`{ 360 $type: "test.ref" 361 post?: 362 | { [x: string]: unknown; $type: "com.example.post" } ··· 371 }), 372 }); 373 374 - attest(lexicon.infer).type.toString.snap(`{ 375 $type: "test.refRequired" 376 author?: 377 | { [x: string]: unknown; $type: "com.example.user" } ··· 386 }), 387 }); 388 389 - attest(lexicon.infer).type.toString.snap(`{ 390 $type: "test.refNullable" 391 parent?: 392 | { [x: string]: unknown; $type: "com.example.node" } ··· 405 }), 406 }); 407 408 - attest(lexicon.infer).type.toString.snap(`{ 409 $type: "test.union" 410 content?: 411 | { [x: string]: unknown; $type: "com.example.text" } ··· 423 }), 424 }); 425 426 - attest(lexicon.infer).type.toString.snap(`{ 427 $type: "test.unionRequired" 428 media: 429 | { [x: string]: unknown; $type: "com.example.video" } ··· 443 }), 444 }); 445 446 - attest(lexicon.infer).type.toString.snap(`{ 447 $type: "test.unionMultiple" 448 attachment?: 449 | { [x: string]: unknown; $type: "com.example.image" } ··· 469 }), 470 }); 471 472 - attest(lexicon.infer).type.toString.snap(`{ 473 $type: "test.params" 474 limit?: number | undefined 475 offset?: number | undefined ··· 484 }), 485 }); 486 487 - attest(lexicon.infer).type.toString.snap(`{ 488 $type: "test.paramsRequired" 489 limit?: number | undefined 490 query: string ··· 507 }), 508 }); 509 510 - attest(lexicon.infer).type.toString.snap(`{ 511 $type: "test.record" 512 published?: boolean | undefined 513 content: string ··· 529 }), 530 }); 531 532 - attest(lexicon.infer).type.toString.snap(`{ 533 $type: "test.nested" 534 user?: { name: string; email: string } | undefined 535 }`); ··· 548 }), 549 }); 550 551 - attest(lexicon.infer).type.toString.snap(`{ 552 $type: "test.deepNested" 553 data?: 554 | { ··· 576 }), 577 }); 578 579 - attest(lexicon.infer).type.toString.snap(`{ 580 $type: "test.arrayOfObjects" 581 users?: { id: string; name: string }[] | undefined 582 }`); ··· 591 main: schema, 592 }); 593 594 - attest(lexicon.infer).type.toString.snap(`{ 595 $type: "test.nestedArrays" 596 matrix?: number[][] | undefined 597 }`); ··· 604 }), 605 }); 606 607 - attest(lexicon.infer).type.toString.snap(`{ 608 $type: "test.arrayOfRefs" 609 followers?: 610 | { [x: string]: unknown; $type: "com.example.user" }[] ··· 635 }), 636 }); 637 638 - attest(lexicon.infer).type.toString.snap(`{ 639 $type: "test.complex" 640 tags?: string[] | undefined 641 content?: ··· 680 }), 681 }); 682 683 - attest(lexicon.infer).type.toString.snap("never"); 684 }); 685 686 test("InferNS handles namespace with record and object defs", () => { ··· 698 }), 699 }); 700 701 - attest(lexicon.infer).type.toString.snap(`{ 702 $type: "com.example.blog" 703 title: string 704 body: string ··· 721 }), 722 }); 723 724 - attest(ns.infer).type.toString.snap(`{ 725 $type: "test" 726 author?: 727 | { name: string; email: string; $type: "#user" } ··· 740 }), 741 }); 742 743 - attest(ns.infer).type.toString.snap(`{ 744 $type: "test" 745 users?: { name: string; $type: "#user" }[] | undefined 746 }`); ··· 755 }), 756 }); 757 758 - attest(ns.infer).type.toString.snap(`{ 759 $type: "test" 760 embed?: 761 | { content: string; $type: "#text" } ··· 778 }), 779 }); 780 781 - attest(ns.infer).type.toString.snap(`{ 782 $type: "test" 783 author?: 784 | { ··· 804 }), 805 }); 806 807 - attest(ns.infer).type.toString.snap(`{ 808 $type: "test" 809 parent?: 810 | { ··· 834 }), 835 }); 836 837 - attest(ns.infer).type.toString.snap(`{ 838 $type: "test" 839 users?: 840 | { ··· 861 }), 862 }); 863 864 - attest(ns.infer).type.toString.snap(`{ 865 $type: "test" 866 author?: "[Reference not found: #user]" | undefined 867 }`);
··· 16 }); 17 18 // Type snapshot - this captures how types appear on hover 19 + attest(exampleLexicon["~infer"]).type.toString.snap(`{ 20 $type: "com.example.post" 21 tags?: string[] | undefined 22 likes?: number | undefined ··· 33 }), 34 }); 35 36 + attest(schema["~infer"]).type.toString.snap(`{ 37 $type: "test" 38 optional?: string | undefined 39 required: string ··· 47 }), 48 }); 49 50 + attest(schema["~infer"]).type.toString.snap( 51 '{ $type: "test"; nullable: string | null }', 52 ); 53 }); ··· 63 }), 64 }); 65 66 + attest(lexicon["~infer"]).type.toString.snap(`{ 67 $type: "test.string" 68 simpleString?: string | undefined 69 }`); ··· 77 }), 78 }); 79 80 + attest(lexicon["~infer"]).type.toString.snap(`{ 81 $type: "test.integer" 82 count?: number | undefined 83 age?: number | undefined ··· 92 }), 93 }); 94 95 + attest(lexicon["~infer"]).type.toString.snap(`{ 96 $type: "test.boolean" 97 isActive?: boolean | undefined 98 hasAccess: boolean ··· 106 }), 107 }); 108 109 + attest(lexicon["~infer"]).type.toString.snap(`{ 110 $type: "test.null" 111 nullValue?: null | undefined 112 }`); ··· 119 }), 120 }); 121 122 + attest(lexicon["~infer"]).type.toString.snap( 123 '{ $type: "test.unknown"; metadata?: unknown }', 124 ); 125 }); ··· 131 }), 132 }); 133 134 + attest(lexicon["~infer"]).type.toString.snap(`{ 135 $type: "test.bytes" 136 data?: Uint8Array<ArrayBufferLike> | undefined 137 }`); ··· 144 }), 145 }); 146 147 + attest(lexicon["~infer"]).type.toString.snap( 148 '{ $type: "test.blob"; image?: Blob | undefined }', 149 ); 150 }); ··· 160 }), 161 }); 162 163 + attest(lexicon["~infer"]).type.toString.snap(`{ 164 $type: "test.token" 165 symbol?: string | undefined 166 }`); ··· 177 }), 178 }); 179 180 + attest(lexicon["~infer"]).type.toString.snap(`{ 181 $type: "test.array.string" 182 tags?: string[] | undefined 183 }`); ··· 190 }), 191 }); 192 193 + attest(lexicon["~infer"]).type.toString.snap(`{ 194 $type: "test.array.integer" 195 scores?: number[] | undefined 196 }`); ··· 203 }), 204 }); 205 206 + attest(lexicon["~infer"]).type.toString.snap(`{ 207 $type: "test.array.boolean" 208 flags?: boolean[] | undefined 209 }`); ··· 216 }), 217 }); 218 219 + attest(lexicon["~infer"]).type.toString.snap(`{ 220 $type: "test.array.unknown" 221 items?: unknown[] | undefined 222 }`); ··· 236 }), 237 }); 238 239 + attest(lexicon["~infer"]).type.toString.snap(`{ 240 $type: "test.mixed" 241 age?: number | undefined 242 email?: string | undefined ··· 254 }), 255 }); 256 257 + attest(lexicon["~infer"]).type.toString.snap(`{ 258 $type: "test.allOptional" 259 field1?: string | undefined 260 field2?: number | undefined ··· 271 }), 272 }); 273 274 + attest(lexicon["~infer"]).type.toString.snap(`{ 275 $type: "test.allRequired" 276 field1: string 277 field2: number ··· 290 }), 291 }); 292 293 + attest(lexicon["~infer"]).type.toString.snap(`{ 294 $type: "test.nullableOptional" 295 description?: string | null | undefined 296 }`); ··· 305 }), 306 }); 307 308 + attest(lexicon["~infer"]).type.toString.snap(`{ 309 $type: "test.multipleNullable" 310 field1?: string | null | undefined 311 field2?: number | null | undefined ··· 320 }), 321 }); 322 323 + attest(lexicon["~infer"]).type.toString.snap(`{ 324 $type: "test.nullableRequired" 325 value: string | null 326 }`); ··· 336 }), 337 }); 338 339 + attest(lexicon["~infer"]).type.toString.snap(`{ 340 $type: "test.mixedNullable" 341 optional?: string | undefined 342 required: string ··· 356 }), 357 }); 358 359 + attest(lexicon["~infer"]).type.toString.snap(`{ 360 $type: "test.ref" 361 post?: 362 | { [x: string]: unknown; $type: "com.example.post" } ··· 371 }), 372 }); 373 374 + attest(lexicon["~infer"]).type.toString.snap(`{ 375 $type: "test.refRequired" 376 author?: 377 | { [x: string]: unknown; $type: "com.example.user" } ··· 386 }), 387 }); 388 389 + attest(lexicon["~infer"]).type.toString.snap(`{ 390 $type: "test.refNullable" 391 parent?: 392 | { [x: string]: unknown; $type: "com.example.node" } ··· 405 }), 406 }); 407 408 + attest(lexicon["~infer"]).type.toString.snap(`{ 409 $type: "test.union" 410 content?: 411 | { [x: string]: unknown; $type: "com.example.text" } ··· 423 }), 424 }); 425 426 + attest(lexicon["~infer"]).type.toString.snap(`{ 427 $type: "test.unionRequired" 428 media: 429 | { [x: string]: unknown; $type: "com.example.video" } ··· 443 }), 444 }); 445 446 + attest(lexicon["~infer"]).type.toString.snap(`{ 447 $type: "test.unionMultiple" 448 attachment?: 449 | { [x: string]: unknown; $type: "com.example.image" } ··· 469 }), 470 }); 471 472 + attest(lexicon["~infer"]).type.toString.snap(`{ 473 $type: "test.params" 474 limit?: number | undefined 475 offset?: number | undefined ··· 484 }), 485 }); 486 487 + attest(lexicon["~infer"]).type.toString.snap(`{ 488 $type: "test.paramsRequired" 489 limit?: number | undefined 490 query: string ··· 507 }), 508 }); 509 510 + attest(lexicon["~infer"]).type.toString.snap(`{ 511 $type: "test.record" 512 published?: boolean | undefined 513 content: string ··· 529 }), 530 }); 531 532 + attest(lexicon["~infer"]).type.toString.snap(`{ 533 $type: "test.nested" 534 user?: { name: string; email: string } | undefined 535 }`); ··· 548 }), 549 }); 550 551 + attest(lexicon["~infer"]).type.toString.snap(`{ 552 $type: "test.deepNested" 553 data?: 554 | { ··· 576 }), 577 }); 578 579 + attest(lexicon["~infer"]).type.toString.snap(`{ 580 $type: "test.arrayOfObjects" 581 users?: { id: string; name: string }[] | undefined 582 }`); ··· 591 main: schema, 592 }); 593 594 + attest(lexicon["~infer"]).type.toString.snap(`{ 595 $type: "test.nestedArrays" 596 matrix?: number[][] | undefined 597 }`); ··· 604 }), 605 }); 606 607 + attest(lexicon["~infer"]).type.toString.snap(`{ 608 $type: "test.arrayOfRefs" 609 followers?: 610 | { [x: string]: unknown; $type: "com.example.user" }[] ··· 635 }), 636 }); 637 638 + attest(lexicon["~infer"]).type.toString.snap(`{ 639 $type: "test.complex" 640 tags?: string[] | undefined 641 content?: ··· 680 }), 681 }); 682 683 + attest(lexicon["~infer"]).type.toString.snap("never"); 684 }); 685 686 test("InferNS handles namespace with record and object defs", () => { ··· 698 }), 699 }); 700 701 + attest(lexicon["~infer"]).type.toString.snap(`{ 702 $type: "com.example.blog" 703 title: string 704 body: string ··· 721 }), 722 }); 723 724 + attest(ns["~infer"]).type.toString.snap(`{ 725 $type: "test" 726 author?: 727 | { name: string; email: string; $type: "#user" } ··· 740 }), 741 }); 742 743 + attest(ns["~infer"]).type.toString.snap(`{ 744 $type: "test" 745 users?: { name: string; $type: "#user" }[] | undefined 746 }`); ··· 755 }), 756 }); 757 758 + attest(ns["~infer"]).type.toString.snap(`{ 759 $type: "test" 760 embed?: 761 | { content: string; $type: "#text" } ··· 778 }), 779 }); 780 781 + attest(ns["~infer"]).type.toString.snap(`{ 782 $type: "test" 783 author?: 784 | { ··· 804 }), 805 }); 806 807 + attest(ns["~infer"]).type.toString.snap(`{ 808 $type: "test" 809 parent?: 810 | { ··· 834 }), 835 }); 836 837 + attest(ns["~infer"]).type.toString.snap(`{ 838 $type: "test" 839 users?: 840 | { ··· 861 }), 862 }); 863 864 + attest(ns["~infer"]).type.toString.snap(`{ 865 $type: "test" 866 author?: "[Reference not found: #user]" | undefined 867 }`);
+1
packages/prototypey/package.json
··· 9 }, 10 "homepage": "https://prototypey.org", 11 "license": "MIT", 12 "author": { 13 "name": "tylersayshi", 14 "email": "hi@tylur.dev"
··· 9 }, 10 "homepage": "https://prototypey.org", 11 "license": "MIT", 12 + "main": "./lib/core/main.js", 13 "author": { 14 "name": "tylersayshi", 15 "email": "hi@tylur.dev"