Skip to content

Add Script.declareVersion() and emit Versions type map from versioned generated code#1932

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

Add Script.declareVersion() and emit Versions type map from versioned generated code#1932
Copilot wants to merge 8 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.

Follow-up review feedback is incorporated:

  • declareVersion now reads coder.version directly (no optional version cast/check).

  • Versions entries are derived from generated version code only (no typeDeclaration fallback).

  • 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 generated 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

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.
  • Versions values are emitted from the declared version code (not from typeDeclaration).
  • 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.
  • Applied review feedback to use coder.version directly and remove typeDeclaration usage from version declaration 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");
Comment thread test/typescript-generator/script.test.ts Fixed
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
pmcelhaney and others added 2 commits April 21, 2026 21:46
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
version?: string;
}
).version ?? "";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version property is now part of coder so this check can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 080fd02: declareVersion now uses coder.version directly and removes the optional cast/check.

Comment thread src/typescript-generator/script.ts Outdated
isDefault: false,
isType: true,
jsdoc: "",
typeDeclaration: coder.typeDeclaration(this.exports, this),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This typeDeclaration piece doesn't belong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 080fd02: removed the typeDeclaration usage from version declarations, so Versions entries now come from the generated code only.

Copilot AI changed the title Add Script.declareVersion() and emit Versions type map in generated script contents Add Script.declareVersion() and emit Versions type map from versioned generated code Apr 22, 2026
Copilot AI requested a review from pmcelhaney April 22, 2026 02:04
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