Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

fix(emitter): emit enum input literals (#788); verify #784/#785 — #783 cut for a proper fix - #797

Merged
wmadden-electric merged 6 commits into
mainfrom
tml-infer-emit-roundtrip
Jun 15, 2026
Merged

wmadden-electric merged 6 commits into
mainfrom
tml-infer-emit-roundtrip

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes the rest of the Supabase brownfield infer → emit cluster — minus #783, which has been cut from this PR (see below).

#788 — enum input types widened to string (fixed)

FieldOutputTypes for an enum resolved to the literal member union, but FieldInputTypes fell back to CodecTypes['pg/enum@1']['input'] (≈string), so create/update weren't exhaustiveness-checked. Added a symmetric input renderer: optional CodecDescriptor.renderInputType + optional CodecLookup.renderInputTypeFor (existing lookups unchanged), wired through the control stack and resolveFieldType. PgEnumDescriptor.renderInputType returns the same literal union as its output renderer. A regenerated example golden shows the input flip from CodecTypes['pg/enum@1']['input'] → 'admin' | 'user'.

#785 — boolean defaults not lowered (already fixed v0.12 → v0.13)

Does not reproduce on v0.13; added a regression test pinning @default(true|false) → { kind: 'literal', value } at the interpreter.

#784 — types{} alias typeParams (already fixed v0.12 → v0.13)

Does not reproduce on v0.13; named-type aliases lower with typeParams on the storage.types entry, referenced via typeRef. Covered by existing interpreter.types.test.ts + the pgvector-named-type parity golden.

#783 — cut from this PR

The first cut of #783 silently dropped the relation navigation field for FKs to un-inferred tables. That's lossy — it deletes a real relationship to an externally-owned entity (e.g. Supabase auth.users) with no trace, trading a loud emit failure for a silent information loss. Per maintainer review, the correct fix is to surface the referenced table as an external-control-policy stub (@@control(external) — "Prisma Next never emits DDL for it") so the relation resolves and is preserved. That is being done as separate, properly-shaped work; the stopgap is reverted here (commit a9a12ca65). #783 stays open.

Tests / checks

Regression test for #785; failing-first + golden coverage for #788. Suites pass: family-sql (375), framework-components, emitter, sql-emitter, target-postgres. Lint, typecheck, lint:deps clean. Independent of #791.

Closes #784
Closes #785
Closes #788

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added per-codec input-type rendering so emitted contract.d.ts write/input types can use codec-specific, parameter-aware literal unions (not the generic codec input type). Enum codecs now align input and output typing for stricter TypeScript safety.
  • Tests

    • Added coverage for parameterized input-type emission and verified correct fallback behavior.
    • Added a test ensuring boolean literal default lowering into the storage contract.
  • Documentation

    • Updated the 0.13 → 0.14 upgrade notes to call out the types-only enum input widening and regenerated contract typing goldens.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 10, 2026 06:39
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7478f0c2-70c0-41fd-b1d4-c957214a2f4d

📥 Commits

Reviewing files that changed from the base of the PR and between f10646e and d41d376.

📒 Files selected for processing (21)
  • examples/prisma-next-cloudflare-worker/src/prisma/contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0742_migration/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0742_migration/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0748_migration/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0748_migration/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.d.ts
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/1-core/framework-components/src/control/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/shared/codec-descriptor.ts
  • packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
  • packages/3-targets/3-targets/postgres/src/core/codecs.ts
  • skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
✅ Files skipped from review due to trivial changes (5)
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0748_migration/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/start-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/end-contract.d.ts
🚧 Files skipped from review as they are similar to previous changes (15)
  • packages/1-framework/1-core/framework-components/src/shared/codec-descriptor.ts
  • examples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/start-contract.d.ts
  • examples/prisma-next-cloudflare-worker/src/prisma/contract.d.ts
  • packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
  • packages/3-targets/3-targets/postgres/src/core/codecs.ts
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/1-core/framework-components/src/control/control-stack.ts
  • examples/prisma-next-demo/migrations/app/20260422T0742_migration/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260422T0748_migration/start-contract.d.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
  • examples/prisma-next-demo/migrations/app/20260422T0742_migration/start-contract.d.ts
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • examples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.d.ts
  • examples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/end-contract.d.ts

📝 Walkthrough

Walkthrough

This PR adds input-type rendering support to codecs, enabling parameter-aware type narrowing in generated contract typings. Enum fields now emit narrowed string-literal unions (e.g., 'admin' | 'user') on the write side, matching output-side rendering. A test for boolean literal defaults is also included.

Changes

Input type rendering and contract type narrowing

Layer / File(s) Summary
Codec input type rendering contracts
packages/1-framework/1-core/framework-components/src/shared/codec-descriptor.ts, packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
CodecDescriptor and CodecDescriptorImpl gain optional renderInputType hook; CodecLookup adds optional renderInputTypeFor(id, params) method to retrieve and render codec-specific input type expressions.
Codec lookup input renderer collection and exposure
packages/1-framework/1-core/framework-components/src/control/control-stack.ts
extractCodecLookup creates an inputRenderersById map, collects codecDescriptor.renderInputType functions, and exposes them via renderInputTypeFor(id, params) method on the returned CodecLookup.
Domain type generation with parameterized input resolution
packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts, packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
resolveFieldType scalar handling now calls codecLookup.renderInputTypeFor?.(...) when type params are available, validates the result, and falls back to the codec's static input type. Tests cover both custom rendering and fallback paths.
PostgreSQL enum input type rendering
packages/3-targets/3-targets/postgres/src/core/codecs.ts
PgEnumDescriptor overrides renderInputType to return the same literal-union expression as renderOutputType, unifying enum write and read type constraints.
Generated contract typings updated
examples/prisma-next-cloudflare-worker/src/prisma/contract.d.ts, examples/prisma-next-demo/src/prisma/contract.d.ts, examples/prisma-next-demo/migrations/app/*/\*-contract.d.ts
Enum field input types across all generated contract snapshots now use explicit string-literal unions ('admin' | 'user') instead of generic codec input types, narrowing write-side field acceptance.
Boolean literal defaults in PSL contracts
packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
New test verifies that PSL @default(true) and @default(false) annotations lower to SQL storage contract { kind: 'literal', value: boolean } entries.
Upgrade documentation
skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
Added note documenting that emitted contract.d.ts enum field input types are narrowed to literal unions on the write side; clarifies contract.json is unchanged and the change is types-only and additive.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • wmadden
  • aqrln

Poem

🐰 From generic codecs to unions precise,
Input types now render with accurate spice!
Enums speak freely of members they hold,
Contract.d.ts tells a TypeScript tale bold. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding enum input literal rendering to the emitter. While it references related issues (#788, #784, #785, #783), the primary focus on 'emit enum input literals' is specific and directly tied to the core changeset modifications across codec descriptors, lookup infrastructure, and generated contract types.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-infer-emit-roundtrip

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@797

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@797

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@797

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@797

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@797

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@797

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@797

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@797

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@797

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@797

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@797

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@797

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@797

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@797

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@797

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@797

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@797

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@797

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@797

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@797

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@797

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@797

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@797

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@797

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@797

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@797

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@797

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@797

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@797

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@797

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@797

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@797

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@797

prisma-next

npm i https://pkg.pr.new/prisma-next@797

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@797

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@797

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@797

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@797

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@797

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@797

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@797

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@797

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@797

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@797

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@797

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@797

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@797

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@797

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@797

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@797

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@797

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@797

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@797

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@797

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@797

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@797

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@797

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@797

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@797

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@797

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@797

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@797

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@797

commit: d41d376

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 155.16 KB (+0.03% 🔺)
postgres / emit 122.45 KB (+0.04% 🔺)
mongo / no-emit 76.92 KB (0%)
mongo / emit 71.01 KB (0%)
cf-worker / no-emit 183.87 KB (+0.03% 🔺)
cf-worker / emit 147.74 KB (+0.03% 🔺)

Comment on lines +45 to +53
// Skip FKs whose referenced table was not inferred (e.g. a Supabase
// `public` → `auth.users` FK with the auth schema excluded). Emitting a
// relation navigation field here would point at a model that does not
// exist in the output, breaking `contract emit`. The scalar FK column is
// preserved by the column walk, so only the navigation field is omitted.
if (!Object.hasOwn(tables, fk.referencedTable)) {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Anything present in the contract already should not be inferred. These should be marked with the external control policy

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.

Agreed — the drop is worse than the failure it replaced. I've reverted #783 out of this PR (commit a9a12ca); it stays open. The proper fix will surface a FK target outside the inferred set as an external-control-policy stub (@@control(external) — Prisma Next never emits DDL for it) so the relation resolves and is preserved instead of deleted. That, plus the "don't re-infer what's already in the contract" half, will be shaped as separate work. This PR now only carries #788 (enum input literals) + the #784/#785 verifications.

@wmadden-electric wmadden-electric changed the title fix(infer/emit): drop dangling cross-schema relations + emit enum input literals (#783, #788; verify #784/#785) fix(emitter): emit enum input literals (#788); verify #784/#785 — #783 cut for a proper fix Jun 11, 2026
wmadden and others added 6 commits June 15, 2026 12:52
…rred tables

`contract infer` emitted a relation navigation field for every foreign key,
even when the referenced table was not part of the inferred schema — e.g. a
Supabase `public` → `auth.users` FK with the `auth` schema excluded. That
produced `users users @relation(...)` with no `model users`, so `contract emit`
failed on the unresolved relation target.

Skip relation inference for any FK whose `referencedTable` is absent from the
inferred tables. The scalar FK column is preserved (it comes from the column
walk); only the dangling navigation field and its back-relation are omitted.

Closes #783

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…for #785)

#785 reported boolean `@default(true/false)` from infer not lowering into
contract.json on v0.12. It no longer reproduces on v0.13: the interpreter
lowers boolean literals to `{ kind: 'literal', value: true|false }` on the
storage contract, the infer side emits the PSL attribute, and the Postgres
planner renders boolean literal defaults. This adds a regression test pinning
the interpreter behavior so it can't silently regress.

Closes #785

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… output

`FieldOutputTypes` for an enum column resolved to the precise literal member
union (via the codec's `renderOutputType`), but `FieldInputTypes` always fell
back to `CodecTypes['pg/enum@1']['input']` (effectively `string`). Create/update
call sites therefore weren't exhaustiveness-checked against enum members.

Add a symmetric input renderer:
- `CodecDescriptor.renderInputType?(params)` (optional) and a matching
  `CodecLookup.renderInputTypeFor?(id, params)` (optional, so existing lookups
  need no change). The control stack builds the input-renderer map alongside the
  output one.
- `domain-type-generation`'s `resolveFieldType` renders the input position via
  `renderInputTypeFor` when present, mirroring the output path; absent renderers
  keep the `CodecTypes[...]['input']` fallback.
- `PgEnumDescriptor.renderInputType` returns the same literal union as its
  output renderer, since enum writes accept the same members as reads.

Only enum opts in; every other codec falls back unchanged.

Closes #788

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The enum input-literal change (#788) now renders pg/enum columns as their
member union on the input side. Regenerate the demo example fixtures so the
committed contract.d.ts files match emitter output.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… un-inferred tables"

This reverts #783's change. Silently dropping the relation navigation field for
a FK to an un-inferred table is lossy: it deletes a real relationship to an
externally-owned entity (e.g. Supabase `auth.users`) with no trace, trading a
loud `contract emit` failure for a silent information loss. The correct fix is
to surface the referenced table as an `external`-control-policy stub so the
relation resolves and is preserved — that is being done as separate, properly
shaped work. Cutting the stopgap rather than shipping a worse-than-nothing
behavior.

This reverts commit 92c9c13.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The enum input-literal change (#788) regenerated the example contract.d.ts
goldens, which touches examples/. The per-PR upgrade-coverage check requires
this PR to record an upgrade declaration for that diff. Add an incidental-diff
declaration matching the existing comment style: the change is types-only,
contract.json is unchanged, and no consumer action is required.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden force-pushed the tml-infer-emit-roundtrip branch from f10646e to d41d376 Compare June 15, 2026 10:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

2 participants