Skip to content

Add @codama/upgrade - #1095

Draft
lorisleiva wants to merge 1 commit into
mainfrom
08-20-add_codama_upgrade
Draft

Add @codama/upgrade#1095
lorisleiva wants to merge 1 commit into
mainfrom
08-20-add_codama_upgrade

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR adds the @codama/upgrade package: an append-only chain of pure, hand-written functions, each upgrading a Codama document exactly one major to the next. upgrade() detects the source major from the document's version, refuses pre-1.0 or unparsable versions with the new CODAMA_ERROR__UNSUPPORTED_VERSION code, refuses future majors with the existing CODAMA_ERROR__VERSION_MISMATCH (whose message now covers both directions), runs the applicable upgrade functions as sequential if (major <= N) blocks, and restamps the result with the latest CODAMA_VERSION. The chain is empty while the latest spec major is 1, so upgrading is identity plus restamp; adding a future major means one new function and one new if block, and because the functions and frozen types are committed source with zero dependencies, every major back to 1.0.0 stays upgradable forever. The frozen v1 node types are generated as part of the default generate orchestrator from a new @codama/spec-v1 aliased exact pin in spec-generators, so the CI freshness check guards the snapshot automatically and it only changes when that pin or the generator code deliberately changes; after the v2 transition, the living pin moves to 2.x while the alias keeps pointing at the last 1.x. The snapshot is committed under src/v1 alongside frozen copies of the hand-written brands/Docs/Version siblings, is compile-time only, and is exposed as the type-only v1 namespace, adding zero runtime bytes. upgradeFromJson covers the JSON path and upgradeToLatestVisitor provides the CLI-friendly preprocessing boundary. Tests cover detection, restamping, content preservation, all error paths, a compile-time guarantee that the frozen v1 types describe current v1 documents, and upgraded fixtures passing @codama/validators as a smoke check. Upgrade functions are pure JSON-tree-in, JSON-tree-out transforms with no environment access, keeping the chain portable to codama-rs. This is Phase 2 of the v2 migration framework plan.

This PR adds the `@codama/upgrade` package: an append-only chain of pure, hand-written functions, each upgrading a Codama document exactly one major to the next. `upgrade()` detects the source major from the document's `version`, refuses pre-1.0 or unparsable versions with the new `CODAMA_ERROR__UNSUPPORTED_VERSION` code, refuses future majors with the existing `CODAMA_ERROR__VERSION_MISMATCH` (whose message now covers both directions), runs the applicable upgrade functions as sequential `if (major <= N)` blocks, and restamps the result with the latest `CODAMA_VERSION`. The chain is empty while the latest spec major is 1, so upgrading is identity plus restamp; adding a future major means one new function and one new `if` block, and because the functions and frozen types are committed source with zero dependencies, every major back to 1.0.0 stays upgradable forever. The frozen v1 node types are generated as part of the default `generate` orchestrator from a new `@codama/spec-v1` aliased exact pin in `spec-generators`, so the CI freshness check guards the snapshot automatically and it only changes when that pin or the generator code deliberately changes; after the v2 transition, the living pin moves to 2.x while the alias keeps pointing at the last 1.x. The snapshot is committed under `src/v1` alongside frozen copies of the hand-written `brands`/`Docs`/`Version` siblings, is compile-time only, and is exposed as the type-only `v1` namespace, adding zero runtime bytes. `upgradeFromJson` covers the JSON path and `upgradeToLatestVisitor` provides the CLI-friendly preprocessing boundary. Tests cover detection, restamping, content preservation, all error paths, a compile-time guarantee that the frozen `v1` types describe current v1 documents, and upgraded fixtures passing `@codama/validators` as a smoke check. Upgrade functions are pure JSON-tree-in, JSON-tree-out transforms with no environment access, keeping the chain portable to `codama-rs`. This is Phase 2 of the v2 migration framework plan.
@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ae200d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@codama/upgrade Major
@codama/errors Minor
@codama/dynamic-address-resolution Patch
@codama/dynamic-client Patch
@codama/dynamic-codecs Patch
@codama/dynamic-instructions Patch
@codama/dynamic-parsers Patch
@codama/fragments Patch
codama Minor
@codama/nodes-from-anchor Patch
@codama/nodes Minor
@codama/renderers-core Patch
@codama/validators Minor
@codama/visitors-core Minor
@codama/visitors Minor
@codama/cli Patch
@codama/node-types Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

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.

1 participant