Repository navigation
Name clashes throw, optional struct fields, toTypeScript fixes - #212
Merged
Merged
Conversation
…ruct layouts - Store/Database create take nameClashes to acknowledge a legacy component/resource clash; unlisted clashes warn per store - struct writers fill absent optional fields (field default or zeros) instead of crashing or writing NaN - getStructLayout memoizes per schema object, so struct read/write compile once per schema Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nces - ToType resolves anyOf as a union, matching toTypeScript. - toTypeScript names a repeated parameter shape after the parameter. - New Schema.typeName emits a named type reference (Response, HTMLElement); ToType resolves global class names to their instance type. - Schema.nullable?: never rejects OpenAPI nullable at compile time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves the two decisions left open in #211, plus
toTypeScript/ToTypefixes.Store.createnow throws in both directions, even when the schemas are identical.Database.Plugin.createalso rejects a clash at compile time, within one plugin or against itsextends/imports. A clash formed throughPlugin.combineis caught at runtime. ThenameClashesoption from the first draft of this PR is removed.{ a: Vec2, b: Vec2 }withdefault: {}used to crash in the generated struct writer (Cannot read properties of undefined), and an absent primitive field silently wroteNaN. Struct eligibility is unchanged. Instead,getStructLayoutgives each object field that isn'trequireda frozenfill: the field's owndefault, otherwise zeros of its shape. The writer falls back to it with one??per optional field and no allocation. Fields listed inrequiredgenerate exactly the same code as before, and an omitted field reads back as its fill.getStructLayoutwas keyed on a fresh{ schema, layout }object (and its throwing path skipped the cache entirely), so it never hit. Every struct column recompiled its read/write functions withnew Function, and those memo maps grew without bound. It is now a per-schemaWeakMapkeyed by layout mode.anyOfagrees betweenToTypeandtoTypeScript.ToTyperesolvedanyOftoany, whiletoTypeScriptrendered a union. Both now give the union (anyOfshares theoneOfbranch, so no extra conditional depth).interface Opts, notShape1.typeNamefor types JSON Schema can't describe.{ typeName: "Response" }renders asResponseintoTypeScript. InToType, a global class name (Response,HTMLElement,ReadableStream) resolves to its instance type, and any other name isany. It's meant for service schemas.nullableis a compile error.Schema.nullable?: neverrejects OpenAPI'snullable, which used to be silently ignored. UseoneOfwith{ type: "null" }.Testing
pnpm run lint,pnpm run typecheck(with build caches cleared),pnpm run check:workspaceandpnpm run buildpass.pnpm run testpasses in every package:data3,611 tests, plus all libraries and samples.extendsand throughPlugin.combine; the type tests reject a clash in one plugin and acrossextends, and keep inference for distinct names (about 1.3% more type instantiations inpackages/data);fillappears only on non-required fields and is frozen;default: {}is created, and a component with absent fields inserts and round-trips throughtoData/fromData;anyOftype and text agree, a repeated parameter shape is named after its parameter,typeNamerenders verbatim and resolves toHTMLElement/Response, andnullablefails to compile.🤖 Generated with Claude Code