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