Skip to content

feat(codegen): first-class coercedType hint on data type defs#866

Merged
theoephraim merged 2 commits into
mainfrom
datatype-coerced-type-hint
Jul 6, 2026
Merged

feat(codegen): first-class coercedType hint on data type defs#866
theoephraim merged 2 commits into
mainfrom
datatype-coerced-type-hint

Conversation

@theoephraim

@theoephraim theoephraim commented Jul 6, 2026

Copy link
Copy Markdown
Member

Follow-up to #849.

resolveCoercedType hardcoded built-in type names and read private back-channels (_isInt, _rawEnumOptions via _rawDef), so plugin-registered data types always emitted as string in every generated language — silently wrong TS types, and a runtime json.Unmarshal failure in the generated Go loader when the coerced blob value is numeric.

  • Add a first-class coercedType field ('string' | 'int' | 'number' | 'boolean' | 'object' | { enum: [...] }) to data type defs; built-ins declare it, and field resolution consumes it generically (info.dataType?.coercedType ?? 'string'). The _isInt / _rawEnumOptions / _rawDef side channels are gone.
  • Plugin data types get this for free through registerDataType — no API change. Types that declare nothing still fall back to string.
  • New test registers a custom type the way a plugin would and asserts declared hints drive Go/TS emission.
  • Docs: coercedType documented in the code-generation guide's plugin section, plus a pointer on the data-types reference page.

Replace the built-in-name switch and private side channels (_isInt,
_rawEnumOptions via _rawDef) in resolveCoercedType with a coercedType
field on EnvGraphDataTypeDef that each type declares. Plugin-registered
data types can now declare what their coerce() outputs so generated env
modules type their fields correctly instead of always emitting string
(which made the Go loader fail at runtime on numeric blob values).
Types that declare nothing still fall back to string.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

bumpy-frog

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

patch Patch releases

  • varlock 1.9.0 → 1.9.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
varlock-website c333247 Commit Preview URL

Branch Preview URL
Jul 06 2026, 11:25 PM

@pkg-pr-new

pkg-pr-new Bot commented Jul 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/varlock@866

commit: c333247

@theoephraim theoephraim merged commit 7ad0489 into main Jul 6, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant