Skip to content

Send the version each union variant was added in, and allow new variants in minor versions - #369

Draft
yota88 wants to merge 5 commits into
mainfrom
ytang/union-variant-metadata
Draft

yota88 wants to merge 5 commits into
mainfrom
ytang/union-variant-metadata

Conversation

@yota88

@yota88 yota88 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Why

The server now accepts a new variant on an existing union, but only when the schema says which version added it (variantMetadata on UnionDef, in api-gateway 1.1885.0). type-gen never sent it, so adding a variant to a deployed union always fails.

Changes

  • IR: resolveSchemaChain records the version each union variant first appears in. convertUnionDefToIr writes variantMetadata for the variants added after the union.
  • Sent schema: convertIrToWireSchema passes variantMetadata on, so ir asset, ir update-schema, and ir deploy send it. ir deploy --first-party already copies the whole union.
  • Existing schemas: a union that never gained a variant gets no variantMetadata, so its IR and asset don't change.
  • Minor versions: pack.schema now lets a minor version add union variants. Older apps on the same major read a new variant as unknown and keep it when they save. Removing a variant is still rejected.
  • Write version: the union registry in generated SDKs now lists variantAddedInVersions, and state.core tags a write that uses an added variant with at least that version. Before, writing a variant added in v2 whose record existed in v1 was tagged v1.
  • sdkgen templates: the "./*" export now points at build/esm/public/*.js and build/cjs/public/*.cjs, like the other packages. This was left out of Generate the Pack platform SDK in PACK instead of installing it from npm #342.

Don't merge until api-gateway and backpack copy variantMetadata through to schema validation. Until backpack reads it from first-party assets, an asset with an added variant fails to load. The generated platform SDK already has the field, so it doesn't need to be regenerated.

Flow

schema.mjs    nextSchema(v1, { bump: "minor" }): Shape.addVariant("square", Square) → 1.1
   │ type-gen schema ir
   ▼
IR (1.1)      Shape.variantMetadata: { square: { addedInVersion: 1, addedInMinorVersion: 1 } }
   ├─ ir asset / ir update-schema ─▶ api-gateway UnionDef.variantMetadata ─▶ backpack
   └─ ir deploy --first-party ─────▶ backpack UnionDef.variantMetadata

@yota88 yota88 changed the title Send the version each union variant was added in Send the version each union variant was added in, and allow new variants in minor versions Oct 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants