Repository navigation
fix(emitter): emit enum input literals (#788); verify #784/#785 — #783 cut for a proper fix - #797
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (21)
✅ Files skipped from review due to trivial changes (5)
🚧 Files skipped from review as they are similar to previous changes (15)
📝 WalkthroughWalkthroughThis 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., ChangesInput type rendering and contract type narrowing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
| // 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; | ||
| } | ||
|
|
There was a problem hiding this comment.
Anything present in the contract already should not be inferred. These should be marked with the external control policy
There was a problem hiding this comment.
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.
…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]>
f10646e to
d41d376
Compare
Closes the rest of the Supabase brownfield
infer → emitcluster — minus #783, which has been cut from this PR (see below).#788 — enum input types widened to
string(fixed)FieldOutputTypesfor an enum resolved to the literal member union, butFieldInputTypesfell back toCodecTypes['pg/enum@1']['input'](≈string), so create/update weren't exhaustiveness-checked. Added a symmetric input renderer: optionalCodecDescriptor.renderInputType+ optionalCodecLookup.renderInputTypeFor(existing lookups unchanged), wired through the control stack andresolveFieldType.PgEnumDescriptor.renderInputTypereturns the same literal union as its output renderer. A regenerated example golden shows the input flip fromCodecTypes['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
typeParamson thestorage.typesentry, referenced viatypeRef. Covered by existinginterpreter.types.test.ts+ thepgvector-named-typeparity 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 loudemitfailure for a silent information loss. Per maintainer review, the correct fix is to surface the referenced table as anexternal-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 (commita9a12ca65). #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:depsclean. Independent of #791.Closes #784
Closes #785
Closes #788
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
contract.d.tswrite/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
Documentation