Skip to content

Add Script.declareVersion() and emit Versions type map in generated script contents#1932

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/add-declare-version-method
Draft

Add Script.declareVersion() and emit Versions type map in generated script contents#1932
Copilot wants to merge 5 commits intomainfrom
copilot/add-declare-version-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

Summary

Adds Script.declareVersion(coder, name) to register versioned type output by name/version and extends contents() to emit a Versions type alias representing that nested map. This enables version-aware type declarations to be generated alongside existing script exports.

  • Version registry in Script

    • Added internal versions: Map<string, Map<string, ExportStatement>>.
    • Implemented declareVersion(coder, name) with duplicate protection per (name, version) key.
  • Version declarations included in generation lifecycle

    • Extended isInProgress() / finished() to track version declaration promises.
    • Ensured contents() awaits completion before formatting.
  • Versions type emission

    • Added versionsTypeStatements() and integrated it into contents() output.
    • Emits a type alias shaped as map-of-maps of versioned types.
script.declareVersion(new V1AccountTypeCoder({}), "Account");
script.declareVersion(new V2AccountTypeCoder({}), "Account");

// generated
export type Versions = {
  Account: {
    "1.0.0": { id: string };
    "2.0.0": { id: string; email: string };
  };
};
Original Prompt

Issue: script.declareVersion()

Add a new method to the Script class, declareVersion(coder, name).

It should work like export, adding some code to an internal Map called versions.

The key of the versions Map will be a string corresponding to the name. The value will be another Map with a key of version (taken from the coder) and value of the code generated by the coder.

The contents() method will declare a type named Versions whose value is the map of maps of types.

Manual acceptance tests

  • Declaring two coders with the same name and different coder.version values emits both entries under that name in Versions.
  • Calling contents() after declareVersion(...) includes an export type Versions = ... declaration in generated output.
  • Re-declaring the same (name, version) pair does not create duplicate version entries.
  • Existing import/export statement generation remains unchanged when no versions are declared.

Tasks

  • Added versions state to Script and implemented declareVersion(coder, name).
  • Wired version declaration promises into script completion tracking (isInProgress, finished).
  • Added versionsTypeStatements() and injected Versions emission into contents().
  • Added focused unit tests in test/typescript-generator/script.test.ts for version grouping and contents() output.

Copilot AI linked an issue Apr 18, 2026 that may be closed by this pull request
});

it("declares versioned code grouped by name and coder version", async () => {
const repository = new Repository("/base/path");
});

it("outputs the contents including Versions when versions are declared", async () => {
const repository = new Repository("/base/path");
Copilot AI changed the title [WIP] Add declareVersion method to Script class Add Script.declareVersion() and emit Versions type map in generated script contents Apr 18, 2026
Copilot AI requested a review from pmcelhaney April 18, 2026 21:24
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.

script.declareVersion()

2 participants