feat(cloudflare): exportAs patch directive to hoist named union type aliases#381
Open
sam-goodwin wants to merge 1 commit into
Open
feat(cloudflare): exportAs patch directive to hoist named union type aliases#381sam-goodwin wants to merge 1 commit into
sam-goodwin wants to merge 1 commit into
Conversation
…aliases
Well-known inline discriminated unions (e.g. the Workers script-upload
binding union, repeated inline in ~8 request/response structs) can now be
named at their JSON path in a patch file:
"metadata.bindings[]": { "exportAs": "Binding" }
The hoisting pass lifts the union into an exported top-level type alias
with one exported named interface per variant. Structurally identical
module-private defs with upstream-derived names are promoted (not
duplicated); unnamed patch-appended variants get discriminant-derived
names (WorkerLoaderBinding, ArtifactsBinding). Public request/response
interfaces reference the alias by name, so consumers write
workers.Binding instead of Exclude<...["bindings"], undefined>[number].
Applied to workers: putScript request bindings -> Binding,
getScriptScriptAndVersionSetting response bindings -> SettingsBinding.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
Install the packages built from this commit: @distilled.cloud/core bun add @distilled.cloud/core@https://pkg.distilled.cloud/core/0d915a3@distilled.cloud/cloudflare bun add @distilled.cloud/cloudflare@https://pkg.distilled.cloud/cloudflare/0d915a3@distilled.cloud/planetscale bun add @distilled.cloud/planetscale@https://pkg.distilled.cloud/planetscale/0d915a3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an
exportAsproperty-patch directive that hoists a well-known inline union into an exported named type alias, and applies it to the Workers script-upload binding union (previously repeated anonymously inline in ~8 request/response structs).generates
so consumers write
workers.Bindinginstead ofExclude<workers.PutScriptRequest["metadata"]["bindings"], undefined>[number].WorkersBindingKindD1) is promoted toexport interfacerather than duplicated under a new name; suffixes (WorkersBindingKindDurableObjectNamespace2) now appear only where request and response shapes genuinely differ. Patch-appended variants without an upstream name get discriminant-derived names (WorkerLoaderBinding,ArtifactsBinding,RatelimitBinding).exportAsname targeting two structurally different unions, or a name colliding with an existing top-level identifier, throws.putScriptrequestmetadata.bindings[]→Binding,getScriptScriptAndVersionSettingresponsebindings[]→SettingsBinding. Only the workers service was regenerated (−590 lines from collapsing the repeated inline unions).Verified with
bun tsc -bfrom the alchemy workspace root and liveWorkerEnv/WorkerBindingtest suites (deploying real Workers through the regeneratedputScript/settings schemas).🤖 Generated with Claude Code