Repository navigation
TML-2886: type SQL enum columns via a baked storage column lookup - #841
Conversation
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ified form (pre-existing main drift) Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…age value-sets (SQL emitter) Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ookup (SQL emitter) Completes the D1 storage lookup so the lanes can read column types from it. Each `StorageColumnTypes[ns][table][column]` entry is now the FULL column type: the parameterized-codec-refined codec output (via the same `renderOutputTypeFor` path the framework uses for `FieldOutputTypes`, so `id` -> `Char<36>`, `embedding` -> `Vector<1536>`), narrowed to the value-set literal union when the column carries one, with nullability applied. Adds the input side as a parallel `StorageColumnInputTypes` map for the insert/update surfaces. Both are wired into the contract type via the `TypeMaps` phantom slot, reachable through new `ExtractStorageColumnTypes` / `ExtractStorageColumnInputTypes` extractors in `sql-contract` (mirroring `ExtractFieldOutputTypes`). `FieldOutputTypes`/`FieldInputTypes` now derive from the same shared column-type helper for plain scalar column-backed fields (the SQL `resolveFieldType` hook returns the full column type, not just the enum union). Composite fields (valueObject/union) and `many`/`dict` fields keep the framework default — their element type comes from the domain field codec, not the storage container codec. The two maps stay byte-identical to before (verified across every emitted fixture); only `StorageColumnTypes` gains the refinements it was missing and the new `StorageColumnInputTypes` map appears. contract.json and all hashes are unchanged (the change is .d.ts-only). The in-memory `defineContract` authoring path also emits the two storage maps (`StorageColumnChannelTypes`) so its contracts stay consistent with emitted ones. The framework emitter keeps zero value-set / storage-column knowledge (A5). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e reach) Points the storage query surfaces at the now-complete storage lookup. Query builder (`selection.ts`): `ExtractOutputType` indexes `StorageColumnTypes[ns][table][column]` with a single O(1) access (unioned across namespaces that declare the table), replacing the `FieldOutputOverride` cross-plane model->field walk. A column with a value-set but no domain field now types correctly because the storage lookup does not require a model field. sql-builder (`table-proxy.ts`): the select-result row reads `StorageColumnTypes[ns][table]`; insert/update read `StorageColumnInputTypes`. This decouples the sql-builder storage surface from the shared `ComputeColumnJsType` (it no longer routes column output through it). The ORM keeps reading `FieldOutputTypes` via `ComputeColumnJsType` — that type now has a single consumer (the ORM) and is unchanged, so the ORM is unaffected. No ref-following and no fallback chains — a single indexed access per column. Parameterized refinements (`Char<N>`, `Vector<N>`) are preserved because they are baked into the storage lookup (verified by the sql-builder `resolved-field-types` type test staying green). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…hanged) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Warning Review limit reached
More reviews will be available in 39 minutes and 38 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughIntroduces ChangesStorageColumnTypes feature end-to-end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
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 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/config-loader
@prisma-next/emitter
@prisma-next/language-server
@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 📦
|
…olumn-lookup Merge commits 088813b (TML-2916: un-namespaced PG models default to public namespace per ADR 223) and a3da203 (TML-2503: reconcile extension-supabase spec/plan) into this branch. Conflict resolution: - examples/**/migration.json (3 files): resolved by taking main's hashes, then regenerating via `pnpm fixtures:emit` (post-build) to get the combined correct hashes. - skills/extension-author/.../instructions.md: kept both TML-2916 and TML-2886 incidental entries as separate HTML comment blocks. - All *.d.ts contract fixtures: auto-merge kept stale __unbound__ entries in StorageColumnTypes; after rebuilding and re-emitting, re-staged the correct emitter output (no __unbound__ for Postgres contracts per ADR 223). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
wmadden
left a comment
There was a problem hiding this comment.
Please try and restrain yourself. Write reasonable length comments
…es only storage column lookups Domain field enum narrowing (`field.valueSet` of `entityKind: 'enum'` -> `contract.domain.enum[name].members[*].value`) is family-agnostic — same algorithm SQL and Mongo both need, same algorithm `contract-ts`'s `FieldChannelType`/`EnumValueUnion` already uses for the no-emit path. Hoist it back to the framework emitter and remove the `EmissionSpi.resolveFieldType` override hook that put it in the SQL family. The framework emitter now reads `contract.domain.namespaces[ns].enum[name]` directly and bakes the literal union into `FieldOutputTypes`/`FieldInputTypes`. `EmissionSpi.resolveFieldTypeParams` stays — parameterized codec rendering IS family-specific (SQL `column.typeRef` -> `storage.types`). The SQL family contributes only `StorageColumnTypes`/`StorageColumnInputTypes` via the renamed `getStorageTypeExports` hook (was `getExtraTypeExports`). That hook still narrows by the *storage* column's `valueSet` (storage-plane knowledge, correctly behind the SPI boundary). `FieldOutputTypes`/`FieldInputTypes` are byte-identical to origin/main across every emitted fixture. `contract.json` and all hashes byte-identical to main. `StorageColumnTypes` keeps its `Char<36>`/`Vector<1536>`/value-set unions. Reframes A5 in the slice spec: "framework holds no STORAGE knowledge"; domain enum narrowing is framework-level. The Phase-1 commit also tracks the SQL emitter `index.ts` god-file extraction as a separate follow-up (TML-2926). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
`StorageColumnMapAt` (single-namespace coordinate lookup) was duplicated across the sql-builder lane and open-coded in the query-builder lane's `ExtractOutputType` (cross-namespace flat-table view). Extract both to `packages/2-sql/1-core/contract/src/column-type-resolution.ts` — the natural home for column-type resolution helpers, alongside the existing `ExtractStorageColumnTypes` extractors. Adds: - `StorageColumnMapAt<SCT, NsId, TableName>` — single-coordinate lookup, resolving to `never` when the map is the empty default a non-emitted contract carries OR when the coordinate is absent in an emitted map. - `StorageColumnTypeAcrossNamespaces<SCT, TableName, ColumnName>` — flat-table lookup, unioning across every namespace that declares the table. `table-proxy.ts` and `selection.ts` now import the helpers. No behavioral change; fixtures unchanged. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Per Will's review on PR #841: aggressively cut every multi-line comment block I added in this slice. Repo rule (CLAUDE.md): no comments if avoidable; comments are a last resort; the WHY is non-obvious only. A type's mechanics are obvious mechanism — they belong in the code, not in prose. No behavioral change. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…SPI-hook branches `80a9744c9` moved enum narrowing into the framework and added SPI plumbing for `getStorageTypeExports`. The new branches lacked direct unit-test coverage, so both files dropped below the 90% branch threshold: - domain-type-generation.ts 87.56% < 90% - generate-contract-dts.ts 88.89% < 90% Adds focused unit tests covering the enum-narrowing edge cases (numeric / boolean members, nullability on the narrowed union, falls-through when the lookup returns undefined / empty / non-scalar members) and every arm of the SPI plumbing (`getStorageTypeExports` hook absent / present-string / present- undefined; `domainEnumLookup` non-enum / missing-ns / missing-enum-block). Post-fix: - domain-type-generation.ts branches 95.33% (was 87.56%) - generate-contract-dts.ts branches 94.44% (was 88.89%) No production code changed; tests only. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/3-extensions/postgis/src/contract.d.ts (1)
63-80:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPopulate the storage-column maps instead of leaving them empty.
TypeMapsTypenow carries the[namespace][table][column]storage map, but both regenerated fixtures still setStorageColumnTypes/StorageColumnInputTypesto{ readonly public: {} }even though the contracts declare real tables. That drops every storage-column key from the emitted types and leaves these fixtures out of sync with the new contract shape.
packages/3-extensions/postgis/src/contract.d.ts#L63-L80: emitcafe,neighborhood, androutestorage columns here.test/integration/test/fixtures/contract.d.ts#L63-L80: emit theuserstorage columns here so the integration fixture matches the new map shape.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-extensions/postgis/src/contract.d.ts` around lines 63 - 80, The StorageColumnTypes and StorageColumnInputTypes fields in the TypeMapsType are currently empty objects but should be populated with the actual storage columns for the declared tables. At packages/3-extensions/postgis/src/contract.d.ts (lines 63-80), populate the storage-column maps with the cafe, neighborhood, and route table columns. At test/integration/test/fixtures/contract.d.ts (lines 63-80), populate the storage-column maps with the user table columns. This will bring both fixtures into sync with the new contract shape that now carries namespace, table, and column storage mappings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts`:
- Around line 1381-1392: The test fixture in the "does not narrow non-scalar
(union) fields even with a valueSet present" test is missing the valueSet
property on the field object, even though the test name explicitly advertises
that valueSet should be present. Add a valueSet property to the ContractField
fixture to align the test setup with its stated purpose and ensure the
regression scenario is actually being tested.
---
Outside diff comments:
In `@packages/3-extensions/postgis/src/contract.d.ts`:
- Around line 63-80: The StorageColumnTypes and StorageColumnInputTypes fields
in the TypeMapsType are currently empty objects but should be populated with the
actual storage columns for the declared tables. At
packages/3-extensions/postgis/src/contract.d.ts (lines 63-80), populate the
storage-column maps with the cafe, neighborhood, and route table columns. At
test/integration/test/fixtures/contract.d.ts (lines 63-80), populate the
storage-column maps with the user table columns. This will bring both fixtures
into sync with the new contract shape that now carries namespace, table, and
column storage mappings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 930ea04f-ca6e-42c2-9bf8-a3987e595717
⛔ Files ignored due to path filters (11)
examples/bundle-size/src/postgres/generated/contract.d.tsis excluded by!**/generated/**packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**projects/enums-as-domain-concept/slices/type-columns-from-valueset-ref/plan.mdis excluded by!projects/**projects/enums-as-domain-concept/slices/type-columns-from-valueset-ref/spec.mdis excluded by!projects/**test/e2e/framework/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/e2e/framework/test/sqlite/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/namespaced-accessors/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/sql-builder/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/sql-orm-client/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/sql-orm-client/fixtures/polymorphism/generated/contract.d.tsis excluded by!**/generated/**
📒 Files selected for processing (49)
apps/telemetry-backend/src/prisma/contract.d.tsexamples/multi-extension-monorepo/app/src/contract.d.tsexamples/multi-extension-monorepo/packages/audit/src/contract.d.tsexamples/multi-extension-monorepo/packages/feature-flags/src/contract.d.tsexamples/paradedb-demo/src/prisma/contract.d.tsexamples/prisma-next-cloudflare-worker/src/prisma/contract.d.tsexamples/prisma-next-demo-sqlite/src/prisma/contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0720_initial/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0742_migration/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0742_migration/start-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0748_migration/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260422T0748_migration/start-contract.d.tsexamples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260605T1145_mti_variant_link_columns/start-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T0000_add_priority_enum/start-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/end-contract.d.tsexamples/prisma-next-demo/migrations/app/20260610T2216_set_priority_default/start-contract.d.tsexamples/prisma-next-demo/src/prisma/contract.d.tsexamples/prisma-next-postgis-demo/migrations/app/20260512T1309_migration/end-contract.d.tsexamples/prisma-next-postgis-demo/src/prisma/contract.d.tsexamples/react-router-demo/src/prisma/contract.d.tsexamples/supabase/src/contract.d.tspackages/1-framework/1-core/framework-components/src/control/emission-types.tspackages/1-framework/1-core/framework-components/src/exports/emission.tspackages/1-framework/3-tooling/emitter/src/domain-type-generation.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.tspackages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tspackages/1-framework/3-tooling/emitter/test/generate-contract-dts.spi-branches.test.tspackages/2-sql/1-core/contract/src/column-type-resolution.tspackages/2-sql/1-core/contract/src/exports/types.tspackages/2-sql/1-core/contract/src/types.tspackages/2-sql/2-authoring/contract-ts/src/contract-types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.storage-column-types.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.typeref-resolver.test.tspackages/2-sql/4-lanes/query-builder/src/selection.tspackages/2-sql/4-lanes/query-builder/test/enum-type.field-output.test-d.tspackages/2-sql/4-lanes/sql-builder/src/types/table-proxy.tspackages/2-sql/4-lanes/sql-builder/test/enum-type.field-output.test-d.tspackages/2-sql/4-lanes/sql-builder/test/types/namespace-unique-fields.types.test-d.tspackages/3-extensions/paradedb/src/contract.d.tspackages/3-extensions/pgvector/src/contract.d.tspackages/3-extensions/postgis/src/contract.d.tspackages/3-extensions/supabase/src/contract/contract.d.tsskills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/instructions.mdskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.mdtest/integration/test/fixtures/contract.d.ts
…e-column-lookup Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Main bumped to 0.14.0; the in-flight transition is now 0.14 → 0.15. This PR's incidental substrate diff (the StorageColumnTypes addition to emitted contract.d.ts files in examples/ and packages/3-extensions/) needs a per-PR declaration in the matching upgrade window, since main's bump PR shipped the 0.14-to-0.15 directories with `changes: []` placeholders. Adds matching TML-2886 (redo, PR #841) declarations to both: - skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md - skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md Same content as the equivalent 0.13-to-0.14 entries (which describe the pre-bump state of this PR). No consumer action required — incidental substrate diff only; observable types unchanged. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…CodeRabbit) The test claimed to cover the "non-scalar field with valueSet present" branch but omitted `valueSet` from the fixture, so it didn't actually exercise the guard. Add a `valueSet` (`entityKind: 'enum'`, pointing at the existing `priorityRef`) AND a `domainEnumLookup` that would narrow if the narrowing code ran — proving the non-scalar-kind guard (the switch's `union` arm bypassing the scalar narrowing block), not a missing-lookup short-circuit, is what keeps the union shape intact. Coverage stays at 95.33% / 94.44% branches (both ≥ 90%). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e-column-lookup Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…e-column-lookup Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
…e-column-lookup Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]> # Conflicts: # 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 # skills/upgrade/prisma-next-upgrade/upgrades/0.14-to-0.15/instructions.md
…ion kind TML-2886 (#841) and TML-2911 (#846) merged in tests that build SQL-storage namespaces in the pre-TML-2891 kind-less form { id, entries }. This branch makes a namespace kind required (every namespace is a target concretion). Inject kind: test-sql-namespace for entries-form namespaces in the emitter fixture normalizeRootSqlStorage, and add it to the three namespace literals in storage-column-many.test.ts. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Decision
Type SQL enum columns using a baked storage column lookup computed in the SQL family emitter. The storage plane now carries its own map of column types — keyed
[namespace][table][column]— so the query builder reads it with a single indexed access and never reaches across into domain-keyed tables.Both maps are flat literal types baked at emit time. No type-level traversal anywhere in the emitted
.d.ts.Vocabulary
FieldOutputTypes/FieldInputTypeskey by[namespace][model][field].StorageColumnTypeskeys by[namespace][table][column].valueSetentry in the SQL namespace and enforced by a CHECK constraint.valueSetref that names the owning value-set entry. The rejected design from PR TML-2886: derive enum column types by following the contract’s references, not a baked lookup table #833 followed this ref at the type level; this PR bakes the resolution into the emitter.Why baked lookup, not ref-following
PR #833 (closed) typed each enum column by following the
valueSetref through the contract at the type level — an expression of the formContractBase['storage']['namespaces'][Ns]['entries']['valueSet'][Ref]['members'][number]['value'], re-evaluated for every column in every selected row type. This was rejected on two grounds:TypeScript evaluation cost is the binding constraint. A ref-following expression compounds type instantiations: one multi-hop traversal per column, nested inside the query result's mapped type, repeated for every selected column. On a contract with many tables this hits TypeScript's "excessively deep" limit and stalls the language server. A baked literal property access —
StorageColumnTypes[Ns][T][C]— pulls nothing else into the type graph and costs exactly one indexed access.The real defect was the cross-plane reach, not the lookup table. The old query builder typed columns via a path that walked storage column → domain model field →
FieldOutputTypes. The lookup table was the correct tool; the bug was reaching into a domain-keyed table from the storage plane. Giving storage its own column-type lookup removes the reach at the root.The baked lookup exists for exactly this reason: derivation happens once in the emitter (generator code), not on every consumer type evaluation.
What changed
SQL family emitter (
packages/2-sql/3-tooling/emitter):StorageColumnTypesmap — codec output narrowed by value-set literals for enum columns, parameterized codec types forChar<N>/Vector<N>columns, plain codec output otherwise.FieldOutputTypes/FieldInputTypesfromStorageColumnTypesat emit time via the field→column mapping each model carries. The derivation is a domain→storage projection, the legal read direction.packages/1-framework/3-tooling/emitter) gains aresolveFieldTypehook that the SQL family answers from its column lookup. No value-set or column knowledge enters the framework layer (A5).Query builder (
packages/2-sql/4-lanes/sql-builder,packages/2-sql/4-lanes/query-builder):ResolvedColumnTypesandExtractOutputTypeindexStorageColumnTypesdirectly. TheFindModelForTable/FindFieldForColumnwalk and theFieldOutputOverridefallback chain are deleted.packages/2-sql/4-lanes/relational-core,packages/3-extensions/sql-orm-client) is unchanged —ComputeColumnJsTypestill readsFieldOutputTypes; its source file is byte-identical to main.No-emit path (
packages/2-sql/2-authoring/contract-ts):StorageColumnChannelTypesadded — a structural projection re-keyed from models to tables, re-usingFieldChannelTypeper entry. No new ref-following. Theenum-surface.types.test-d.tstests keep passing.SQL-only realization: Mongo is unchanged — collections are ~1:1 with model fields, no cross-plane reach to fix.
MongoTypeMapsis untouched.Verification
Self-checks:
grep -rn 'ContractBase\[' examples/prisma-next-demo/src/prisma/contract.d.ts→ empty (A4: no ref-following in emitted output)grep -rnE 'valueSet|ValueSetRef|StorageColumn|EnumValuesResolver' packages/1-framework/3-tooling/emitter/src/→ empty (A5: framework stays target-agnostic)git diff --stat origin/main HEAD -- ':(glob)**/contract.json'→ empty (A7: contract.json/hashes byte-identical)FieldOutputTypesblock in the democontract.d.tsbyte-identical to mainReviewer break-and-revert evidence (rev-2886-v2b, verdict SATISFIED, branch tip
44816fe9e):renderRefinedCodecTypetoif (false && …)collapsed parameterized types in both maps;resolved-field-types.test-d.tsfailed namingChar<36>explicitly.if (column.valueSet)toif (false && …)collapsedPost.prioritytostring; all threeexpectTypeOf().toEqualTypeOf<'low' | 'high' | 'urgent'>()assertions indemo-dx.types.test.tsbit — covering the directFieldOutputTypesindex, the query-builder row type, and the ORM-via-typed-rows path.D3 gate:
pnpm build✓,pnpm typecheck(138 packages) ✓,pnpm fixtures:check✓pnpm lint:deps✓,pnpm lint:casts✓,pnpm check:upgrade-coverage --mode pr✓@prisma-next/sql-contract-emitter,@prisma-next/emitter,@prisma-next/sql-orm-client,@prisma-next/sql-builder,@prisma-next/sql-relational-core) ✓@prisma-next/integration-tests typecheck,prisma-next-demo typecheck✓pnpm test:packages✓Alternatives considered
valueSetref at the type level through the emitted contract. Rejected: TS evaluation cost is unbounded across large contracts; the cross-plane type-level traversal is the violation this work was meant to fix.FieldOutputTypes. Rejected: wrong read direction; breaks enum typing for raw value-set columns with no domain field.Upgrade coverage
The
examples/andpackages/3-extensions/diffs are purely generated artifacts: the newStorageColumnTypesblock appears in every regeneratedcontract.d.ts;FieldOutputTypesis byte-identical to main;contract.jsonand hashes are unchanged. No consumer action required — a re-emit picks upStorageColumnTypesautomatically. Declared incidental inskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.mdandskills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/instructions.md.Context
This is a redo of closed PR #833. The original cut followed the
valueSetref at the type level; this redo bakes the resolution in the emitter. Design pivot recorded inprojects/enums-as-domain-concept/slices/type-columns-from-valueset-ref/spec.md. Commit23e8809b8on this branch is a pre-existing fixture drift fix (migration op-id format from #837), kept here sofixtures:checkstays green.Summary by CodeRabbit
Bug Fixes
Documentation
Tests