Skip to content

sdk/typescript: name identifiers via formatIdentifiers - #14674

Closed
vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5b-typescript-codegen
Closed

vito wants to merge 3 commits into
naming/5a-go-codegenfrom
naming/5b-typescript-codegen

Conversation

@vito

@vito vito commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Part 5b/N of the stack splitting #14501 (identifier casing): the TypeScript SDK. Plan: #14501 (comment)

Refs #13668

Stacked on #14673 (5a, Go codegen + the shared cmd/codegen infra).

What changes for TypeScript

Client codegen (cmd/codegen/generator/typescript). When the schema it generates from has Query.formatIdentifiers, the generator names TypeScript identifiers with the names the engine formats (introspection.LoadFormattedNames, from 5a) instead of guessing with toPascalCase:

identifier format before now
methods CAMEL / UPPERCASE shortSha(), filterUri() shortSHA(), filterURI()
required args (parameters) CAMEL / UPPERCASE withToolResult(callId, …) withToolResult(callID, …)
opts keys CAMEL / UPPERCASE { pushUrl }, { asSdkName } { pushURL }, { asSDKName }
Opts types, enum converter prefixes PASCAL / UPPERCASE ClientHttpOpts, ClientSshfsVolumeOpts ClientHTTPOpts, ClientSSHFSVolumeOpts
enum members PASCAL / CAPITALIZED NetworkProtocol.Tcp NetworkProtocol.Tcp (unchanged)
  • Only TypeScript identifiers change. Field names in select, argument keys, input object fields and enum values go over the wire exactly as the schema has them: required args are keyed by their schema name (callId: callID), and renamed opts keys are mapped back before the call (pushUrl: opts?.pushURL ?? opts?.pushUrl).
  • Type names are left alone. The runtime looks generated classes up by GraphQL type name; in views with formatIdentifiers they're already canonical, which TestCoreTypeNamesAreCanonical checks against the live engine.
  • Deprecated aliases keep every old spelling: methods (shortSha: GitCommit["shortSHA"] = (...args) => this.shortSHA(...args)), Opts type aliases (export type ClientHttpOpts = ClientHTTPOpts) and old opts keys (pushUrl?: string, @deprecated).
  • Fallback: without formatIdentifiers (older engines, pre-v1 views), every name goes through the legacy converters, so older schemas generate byte-identical code.

Runtime (sdk/typescript/src/module/naming.ts, executor, static entrypoint templates). Calls the runtime builds through a module's own interfaces used the TypeScript names of the interface's functions/args and predicted the interface type name (${module}${iface}). From v1.0.0 the engine names module declarations with its rules (#14669), so getUrl(comUrl) on HttpFetcher is PondHTTPFetcher.getURL(comURL:). Both entrypoint paths now ask the engine first, only when the module declares interfaces: resolveSchemaNames formats the names with Query.formatIdentifiers (one batch per casing) and namespaces each interface the way the engine does. The gate is the field being in the runtime's session schema, which is served at the module's engine version; older modules keep the names they always had.

Regenerated sdk/typescript/src/api/client.gen.ts: the renames above, all with deprecated aliases, nothing on the wire.

Breaking changes for TypeScript SDK users

Source compatibility is kept by the deprecated aliases; what's left for maintainers to decide on:

  • Deprecation warnings. Code using shortSha(), parentShas(), filterUri(), withoutUri(), callId(), the pushUrl/asSdkName opts keys or the *HttpOpts/*SshfsVolumeOpts/*UriOpts/*SdkOpts type names now gets @deprecated hints (and lint errors under @typescript-eslint/no-deprecated). How long the aliases live is an open decision (proposed: through 1.0).
  • Renamed parameter names (callId → callID) only matter to code reading them reflectively; they're positional.
  • Subclasses or structural implementations of generated classes that override a renamed method by its old name now override the alias, not the method.
  • Not covered: renamed dependency names. When a dependency module moves to v1 naming (core: name modules with engine/naming from v1.0.0-beta.21 #14669), its schema names change (daggerCli → daggerCLI, MyModHttpclient → MyModHTTPClient). Go has deprecated aliases for those (core: name modules with engine/naming from v1.0.0-beta.21 #14669/codegen: name Go identifiers via formatIdentifiers #14673); TypeScript doesn't, so TS module code calling dag.daggerCli() breaks when the dependency is regenerated. The engine still accepts the old spelling over the wire; only the generated TS binding is missing. Worth deciding whether TS needs the Go-style legacy wrappers before release.

Open decision: TypeScript enum member style

Enum members use PASCAL / CAPITALIZED (Tcp, ObjectKind, GitHubRepo, PerSession), the closest match to what the generator has always written, so no core enum member changes. The alternative, PASCAL / UPPERCASE, would rename every member containing an acronym or term (Tcp → TCP, Ipv6 → IPv6), with deprecated duplicates needed to keep them compatible. Calling it out so it can be confirmed.

Not in it

  • Core renames (callID, pushURL, shortSHA, …, FunctionCachePolicy values) and the TS generator's "old schema names" table (introspection/renamed.go, LegacyFieldName/LegacyArgName): PR 6.
  • Runtime engineVersion bump: not needed for TypeScript. The typescript-sdk runtime module (sdk/typescript/runtime/dagger-module.toml, Go) stays at v0.21.9, as in the final tree of Centralize identifier casing in the engine and SDKs #14501; the name formatting happens in the TS library, inside the user module's own session.
  • Names sidecar (codegen introspect --names-out): TS codegen always runs with an engine connection, so it formats names directly.
  • Module introspection JSON emitter (introspection_json.ts) still predicts names with strcase. It isn't wired in yet; it gets a comment for whoever wires it.

Testing

  • go test ./cmd/codegen/... (naming funcs with internal/testnames, fallback, rendered client with/without engine names, entrypoint SchemaNames wiring, TestCoreTypeNamesAreCanonical against the engine), go vet
  • Checks: typescript-client/lint-typescript, typescript-client/test-nodejs-lts (incl. the new naming.spec.ts), typescript-client/client-library/stale, typescript-client/format/stale, typescript-sdk/generate/stale
  • Integration:
    • new TestModuleNaming/TestTypeScriptInterfaceAcronyms: a v1 TS module calls through its own interface (HttpFetcher.withHttpPrefix(...).getUrl(comUrl)) implemented by another TS module; the trace shows the runtime resolving the names via formatIdentifiers and calling Impl.withHTTPPrefix(httpPrefix:) / Impl.getURL(comURL:). (The legacy-spelling aliases from core: name modules with engine/naming from v1.0.0-beta.21 #14669 would also accept the old names, so this checks correctness rather than catching a hard failure.)
    • regression: TestInterface/TestIface(Basic|Call)/typescript (pre-v1 and latest fixtures)
  • Not run: the full TestTypescript suite and TestCLI.

vito added 3 commits October 14, 2026 03:17
When the schema has Query.formatIdentifiers, TypeScript client codegen
names identifiers with the names the engine formats instead of guessing
with toPascalCase:

- methods, args and opts keys: CAMEL / UPPERCASE (shortSHA, withGPU)
- Opts types and enum converter prefixes: PASCAL / UPPERCASE
  (ClientHTTPOpts)
- enum members: PASCAL / CAPITALIZED, the closest match to what the
  generator has always written (Tcp, ObjectKind)

Only TypeScript identifiers change. Field names in select, arg keys,
input object fields and enum values stay as the schema has them:
required args are keyed by their schema name, and renamed opts keys are
mapped back to it before the call. Type names are left alone, since the
runtime looks generated classes up by GraphQL type name; in views with
formatIdentifiers they are canonical already, which a test checks.

Renamed methods, Opts types and opts keys keep their old names as
deprecated aliases. Without formatIdentifiers, every name falls back to
the legacy converters, so older schemas generate byte-identical code.

Signed-off-by: Alex Suraci <[email protected]>
Methods, args, opts keys and Opts types whose names the engine formats
differently now use those names, with the old ones kept as deprecated
aliases: shortSHA (shortSha), parentSHAs, filterURI, withoutURI, callID,
pushURL and asSDKName opts keys, ClientHTTPOpts (ClientHttpOpts),
ClientSSHFSVolumeOpts, ArtifactURIOpts, WorkspaceWith(out)SDKOpts. Nothing
changes on the wire, and no enum member changes.

Signed-off-by: Alex Suraci <[email protected]>
Calls through a module's own interfaces are built by the runtime, which
used the TypeScript names of the interface's functions and arguments and
predicted the interface's type name. From engine version v1.0.0 the
engine names module declarations with its naming rules, so for names with
acronyms the two disagree (getUrl is getURL) and the call relies on the
legacy-spelling aliases at best.

Both runtime paths now ask the engine before invoking anything, when the
module declares interfaces: resolveSchemaNames formats the names with
Query.formatIdentifiers, in one batch per casing, and namespaces each
interface the way the engine does, comparing words. The static entrypoint
(generated by cmd/codegen) and the Executor of the dynamic entrypoint use
the result for selections, argument keys and node(id:) type names.

The identifier API only exists from v1.0.0, the version the naming rules
start at, and the runtime's session is served at the module's engine
version, so the field being in the session schema is the gate. Older
modules keep the names the runtime always used.

The module introspection JSON emitter still predicts names with strcase.
It isn't wired in and runs without an engine connection, so it only gets a
note for whoever wires it.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Closing: the in-repo SDKs are now legacy. This work will be redone as a PR against github.com/dagger/typescript-sdk (identifier-casing branch) once the engine side (view-gated naming at v1.0.0-beta.20) lands. The branch is kept for reference.

@vito vito closed this Oct 22, 2026
vito added a commit to dagger/typescript-sdk that referenced this pull request Oct 22, 2026
When the schema has Query.formatIdentifiers (views from v1.0.0-beta.21, the
same views whose module declarations the engine names with engine/naming),
methods, args and opts keys are CAMEL/UPPERCASE, Opts types and enum
converters PASCAL/UPPERCASE, and enum members PASCAL/CAPITALIZED. Only TS
identifiers change: selections, argument keys, input object fields, enum
values and type names go over the wire as the schema has them, renamed opts
keys are mapped back before the call, and required args are keyed by their
schema name.

Every renamed identifier keeps its old spelling as a deprecated alias:
methods, top-level module functions, Opts types, opts keys and enum members.
Schemas without the field keep the legacy converters, so they generate
byte-identical code (the existing goldens are unchanged).

Ported from dagger/dagger#14674.

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit to dagger/typescript-sdk that referenced this pull request Oct 22, 2026
From v1.0.0-beta.21 the engine names a module's declarations with its naming
rules, so HttpFetcher.getUrl(comUrl) in module pond is
PondHTTPFetcher.getURL(comURL:). The static entrypoint and the dispatcher
selected the TS names and predicted the type as <Module><Iface>, which no
longer exist in the schema.

The gate is the module's own schema, now passed to `codegen entrypoint`
(--introspection-json-path): it is served at the module's engine version, and
has Query.formatIdentifiers exactly when the engine names the module with
engine/naming. The names are then computed at generation time with the
vendored rules (core.Namer's FieldName and NamespaceObject), rather than asked
of the engine at call time as dagger/dagger#14674 does: the generated file
carries answers, and no runtime query depends on which view the dispatcher's
session is served at. Older modules render byte-identical entrypoints.

Signed-off-by: Alex Suraci <[email protected]>
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