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

TML-2852: enums become first-class in application code — typed I/O, db.enums, declaration-order ORDER BY - #769

Merged
wmadden-electric merged 47 commits into
mainfrom
tml-2852-application-read-surface
Jun 10, 2026
Merged

wmadden-electric merged 47 commits into
mainfrom
tml-2852-application-read-surface

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

At a glance

In the demo's own contract, Post carries a Priority enum — and the column is typed as its value union everywhere you touch it:

const Priority = enumType('Priority', pgText,
  member('Low', 'low'), member('High', 'high'), member('Urgent', 'urgent'));   // declaration order ≠ lexical

// on a real model:  Post { …, priority: field.namedType(Priority) }

// READ — priority is 'low' | 'high' | 'urgent' (not string), sorted by DECLARATION order
getPostsByPriority()   // → rows ordered low, low, high, urgent  (not lexical)

// WRITE — only member values compile; 'nope' is a compile error, and the CHECK constraint rejects it at the DB

// INTROSPECT at runtime
db.enums.public.Priority.values        // ['low', 'high', 'urgent']  (ordered, literal-typed)
db.enums.public.Priority.members.High  // 'high'

This runs end-to-end against PGlite in examples/prisma-next-demo — typed read, db.enums.<ns>, declaration-order ORDER BY, and the slice-2 CHECK rejecting out-of-union writes.

What this decides

An enum becomes a first-class application concept: its value union flows into the static read/write types of both query lanes, db.enums.<ns>.<Name> exposes it at runtime, and ORDER BY on an enum column sorts by declaration order. It works for text and int-backed enums and in both authoring forms (definition and factory defineContract). Built on the merged substrate (slice 1) and check-constraint enforcement (slice 2), and lands additively — PSL enum stays native until the cutover, so only enumType-authored contracts exercise it.

How it builds up

  1. Typed I/O (R4/R5) — narrow the codec type by the field's valueSet to the value union, on both paths: the authored Definition (no-emit) and the emitted contract.d.ts — the emitter resolves a field's valueSet ref to the enum's member-value union, codec-agnostically (text and int). Both lanes inherit it through the field-output typemap; non-enum fields are unchanged.
  2. db.enums.<ns>.<Name> (R6) — a runtime, literal-typed accessor (.values / .members.X / .has / .nameOf / .ordinalOf) built from that namespace's domain enums. Enums are lane-agnostic contract metadata, so db.enums lives on the db facade alongside transaction / prepare / raw / context (decided with the query team) — a namespace-keyed map projected per target exactly like db.sql / db.orm. It matches the IR (domain.namespaces[ns].enum) and lets the same enum name in two namespaces resolve independently. Unbound-namespace targets (sqlite/mongo) get db.enums.<Name> via the existing per-facade projection. Because enums sit on the facade rather than adjacent to models, no reserved-name guard is needed — a model named enums no longer collides.
  3. Declaration-order ORDER BY (R8, Postgres) — renders array_position(ARRAY[…]::text[], col) over the value-set's ordered values.
  4. Factory-form authoring — the new enum is authorable in the demo's real factory-form contract (a top-level enums key threaded through the factory overload, mirroring the definition form), not only the definition form.

Scope

Additive / dark. PSL enum keeps lowering to native (the repoint is the cutover, TML-2853); member defaults are TML-2855; non-Postgres ORDER BY (MySQL FIELD(...) / SQLite CASE) is future. Existing fixtures are byte-identical apart from the demo.

CI note

The repo-wide pnpm typecheck is red on inherited Cannot find module subpath errors (/contract-builder, /migration, /adapter, /aggregate, /constants) that reproduce on clean origin/main — a separate main-health issue, not introduced here.

Alternatives considered

  • Narrow from the emitted contract JSON rather than the authored Definition — rejected: emission widens the value-set to string[], erasing the literals.
  • A bespoke "enum codec" — rejected: every field already carries a codec; the enum is a valueSet restriction layered on top.
  • A dedicated orderByDeclarationOrder() API — rejected: ordering an enum column by declaration order should just work; the renderer handles it implicitly.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Added enum type definitions with first-class support for enum-backed model fields in SQL contracts.
    • Enum fields now narrow to literal value unions (e.g., 'user' | 'admin' instead of generic string) in both read and write operations, with compile-time type checking.
    • Exposed enum metadata and lookup utilities (values list, names, member maps, membership/ordinal checks) on the client facade under db.enums.<namespace>.<EnumName> (lane-agnostic namespace-keyed map).
    • Enum-backed ORDER BY now respects enum declaration order rather than lexical order.
    • Added support for both string and numeric enum values.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 8, 2026 12:26
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Parameterizes enum generics in contract authoring, widens enum member/value typing and encodes values during contract build, exposes typed enum accessors on the ORM client, adds enum-aware ORDER BY lowering in Postgres renderer, and adds type/runtime tests and demo integration across the stack.

Changes

Enum Support Across the Stack

Layer / File(s) Summary
Enum authoring API: value widening & encoding
packages/2-sql/2-authoring/contract-ts/src/enum-type.ts, packages/2-sql/2-authoring/contract-ts/src/build-contract.ts
Enum members accept non-string JSON values tied to codec input types; duplicate-value checks stringify for messages; build-time encodeEnumValue encodes member/value JSON for domain/storage.
Contract builder generics & merge
packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts, packages/2-sql/2-authoring/contract-ts/src/exports/contract-builder.ts
ContractDefinition/ContractScaffold/ContractFactory accept Enums generics; LiteralEnums/MergeEnums combine scaffold+factory enum shapes; buildBoundContract merges runtime enums and emits enums only when non-empty.
Contract types & field channel typing
packages/2-sql/2-authoring/contract-ts/src/contract-types.ts, packages/2-sql/2-authoring/contract-ts/src/exports/contract-builder.ts
Detect EnumTypeHandle type-refs, short-circuit descriptor lookup, add enumAccessors on SqlContractResult, and compute `FieldChannelTypes<Definition, 'output'
Query & SQL builder propagation
packages/2-sql/4-lanes/query-builder/src/selection.ts, packages/2-sql/4-lanes/sql-builder/test/*
ExtractOutputType now prefers field-level enum output overrides (from contract) over codec fallback; sql-builder tests validate non-nullable enum fields narrow to literal unions and nullable include null.
ORM enum accessors
packages/3-extensions/sql-orm-client/src/enum-accessor.ts, packages/3-extensions/sql-orm-client/src/orm.ts, packages/3-extensions/sql-orm-client/test/*
New EnumAccessor interface and createEnumAccessor/buildEnumsMap; orm() exposes lazy, frozen db.enums with per-enum accessors (values, names, members, has, nameOf, ordinalOf); tests and d.ts assertions added.
Postgres extension: defineContract & enum binding
packages/3-extensions/postgres/src/contract/define-contract.ts, packages/3-extensions/postgres/src/contract/enum-type.ts, packages/3-extensions/postgres/src/exports/contract-builder.ts
Adds Enums generics and EnumsConstraint to Postgres defineContract overloads, exposes a Postgres-bound enumType via bindEnumType, and re-exports enum builder types/values.
Postgres schema valueSet support
packages/3-targets/3-targets/postgres/src/core/postgres-schema.ts, packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
Adds optional valueSet entries to PostgresSchema input/entries, constructs StorageValueSet nodes, and serializes/deserializes valueSet when present.
Postgres enum-order SQL rendering
packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts, packages/3-targets/6-adapters/postgres/test/migrations/order-by-enum.integration.test.ts
renderSelect uses renderOrderByExpr; enum-backed string columns lower to array_position(ARRAY[...]::text[], column) for declaration-order sorting; ambiguous unqualified refs and non-string value-sets fall back to plain rendering; integration tests added.
Examples & tests
examples/prisma-next-demo/*, various test/* and *.test-d.ts files across lanes
Demo adds Priority enum, query helper getPostsByPriority, and runtime/type tests validating enum surface, ordering, CHECK constraints, and type narrowing.
Minor test typing adjustments
packages/3-extensions/postgres/test/postgres.test.ts, packages/3-extensions/sqlite/test/transaction.test.ts
Adjusted mock cast patterns (via unknown) for TypeScript compatibility in tests.

Sequence Diagram (high-level flow)

sequenceDiagram
  participant Authoring as ContractAuthoring
  participant Builder as ContractBuilder
  participant Runtime as ORMRuntime
  participant Postgres as PostgresRenderer
  ContractAuthoring->>ContractBuilder: defineContract/enums + enumType
  ContractBuilder->>ContractBuilder: encodeEnumValue, merge scaffold+factory enums
  ContractBuilder->>ORMRuntime: produce SqlContractResult (enumAccessors)
  ORMRuntime->>ORMRuntime: buildEnumsMap/createEnumAccessor (lazy on db.enums)
  ORMRuntime->>PostgresRenderer: query AST with enum-backed columns
  PostgresRenderer->>PostgresRenderer: renderOrderByExpr -> array_position over valueSet
Loading

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • prisma/prisma-next#731: Related changes to buildBoundContract / defineContract wiring; overlaps in contract-builder typing.
  • prisma/prisma-next#750: Related enum/value-set propagation and contract builder work in the SQL authoring lane.
  • prisma/prisma-next#499: Prior work on enum entity modeling that this PR extends with typed enum generics and downstream handling.

"I'm a rabbit, I hop and I write,
Enums in order, values just right.
From builder to DB, helpers parade,
Arrays and accessors neatly made.
🐇🥕"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.95% 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
Title check ✅ Passed The title clearly and specifically describes the primary changes: adding enums as first-class in application code with typed I/O, runtime surface (db.enums), and declaration-order ORDER BY support.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2852-application-read-surface

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 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: d90ea31

@github-actions

github-actions Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 151.62 KB (+0.71% 🔺)
postgres / emit 119.99 KB (+0.57% 🔺)
mongo / no-emit 76.67 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 180.95 KB (+0.54% 🔺)
cf-worker / emit 145.99 KB (+0.35% 🔺)

wmadden and others added 5 commits June 8, 2026 15:20
…ut types (TML-2852 Dispatch 1)

FieldOutputType and FieldInputType in contract-types.ts now resolve to the
literal value union (e.g. 'user' | 'admin') when the field was authored with
field.namedType(enumHandle), instead of falling back to the codec's string
output.  The key fix was replacing the ModelStorageColumn conditional path
(which TypeScript defers because it contains a type-variable extends check)
with a direct ModelFieldState index access for the nullable and codec-id
lookups.

ExtractOutputType in query-builder/selection.ts now consults
ExtractFieldOutputTypes via a FindModelForTable/FindFieldForColumn lookup
before falling back to the codec type, so enum columns propagate the literal
union through TableToSelection as well.

Type-tests added in all four affected packages (contract-ts, sql-orm-client,
sql-builder, query-builder) covering both read output and write input, plus a
negative case that rejects out-of-union literals.

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

Adds `db.enums.<Name>` to the sql-orm-client: a runtime accessor map built
from the contract domain enum entity, plus the type-level connection so
`db.enums.Role.values` resolves to the literal value tuple and
`.members.User` to the value literal.

- enum-accessor.ts: `createEnumAccessor` / `buildEnumsMap` (no bare casts;
  `Object.freeze` already yields `readonly`).
- orm.ts: Proxy `enums` branch + `enums` typed off the contract`s
  `enumAccessors`.
- contract-builder.ts: thread a `const Enums` generic through
  `defineContract` so authored enum handles keep their literal types.
- contract-types.ts: `BuiltEnumAccessors` derives the accessor shape from
  the authored `EnumTypeHandle`; widened (enum-less) contracts stay empty.
- Tests: runtime accessors + Proxy branch; a type-test asserting the
  literal `values` tuple (not `string[]`) and `.members.User === 'user'`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… BY (TML-2852 Dispatch 3)

An ORDER BY on an enum-restricted column now renders
array_position(ARRAY[v1, v2, …]::text[], <col>) over the value-set's
ordered values, so rows sort by declaration order rather than lexically.

The Postgres sql-renderer builds an alias→storage-coordinate map from the
SELECT's FROM and JOIN table sources, resolves an ORDER BY column-ref to
its storage column, and — when that column carries a valueSet — emits the
array_position expression from the value-set's ordered values. Non-enum
columns render unchanged. A PGlite integration test inserts rows out of
declaration order and asserts the declaration-order result, plus a
nullable-column case (array_position returns NULL for NULL rows, which
sort last under the default ASC NULL handling).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric force-pushed the tml-2852-application-read-surface branch from d33e6a2 to c011d3a Compare June 8, 2026 13:34

@wmadden wmadden left a comment

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.

Only a few small comments. Overall looks good.

wmadden and others added 4 commits June 8, 2026 15:48
…solution (TML-2852)

D1 rewrote FieldOutputType/FieldInputType with an inline ResolveFieldDescriptor
path that re-widened non-enum field result types to string (id, createdAt),
regressing the query-builder ResultType inference covered by integration-tests
contract-builder.test.ts and .types.test-d.ts.

Restore mains codec-based resolution verbatim as FieldCodecOutputType and
FieldCodecInputType, and layer the enum value-union narrowing on top via
EnumNarrowedType, which only narrows when the field carries an enum typeRef.

The non-enum widening came from EnumValueUnion structurally matching the default
EnumTypeHandle and inferring Values as string[]. Guard it with a tuple-wrapped
extends check plus a string[] extends Values bail-out so only fields with a
concrete enum handle narrow; everything else falls through to mains codec output.

In query-builder selection.ts, ExtractOutputType consults the field-output
typemap only when it carries a concrete literal override, otherwise falling back
to mains exact ExtractCodecTypes codec output expression.

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

D2 added enums to OrmClient, so the loose () => ({ lane }) mocks no longer
overlap typeof orm and the as typeof ormMock cast failed with TS2352. Route the
mock implementations through unknown so the consumer stubs satisfy the richer
client type without weakening OrmClient.enums.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…rder sort (TML-2852)

The Postgres ORDER BY enum hook only matched qualified column-ref order items.
The sql-builders .orderBy(col) string and callback forms both emit an
identifier-ref (bare column, no table qualifier), so a natural ORDER BY on an
enum column fell through to a plain column reference and sorted lexically.

Resolve identifier-ref order columns against the SELECTs FROM/JOIN sources and
render array_position over the value-sets ordered values when exactly one source
carries that enum column; an ambiguous name across joined tables falls through
to the bare column. Adds a PGlite test for the identifier-ref form.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… end to end (TML-2852)

A focused example app authored with the TypeScript enumType API (not PSL enum)
that demonstrates all three slice surfaces against PGlite:

- Typed I/O: the enum field reads as the value union (not string) and a write
  only accepts the union; an out-of-union literal is a compile error
  (enum-demo.types.test-d.ts).
- db.enums: the runtime accessor exposes values/names/members/has/ordinalOf in
  declaration order (enum-demo.integration.test.ts).
- Declaration-order ORDER BY via array_position, plus the slice-2 CHECK
  constraint rejecting out-of-union values (enum-demo.integration.test.ts).

The runtime passes the TypeScript-authored contract directly so the value-union
types flow from the authored definition. The emitted contract.json / contract.d.ts
are committed and kept current via emit:check.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric wmadden-electric changed the title TML-2852: application read surface — typed enum I/O, db.enums, declaration-order ORDER BY TML-2852: enums become first-class in application code — typed I/O, db.enums, declaration-order ORDER BY Jun 8, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 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/3-targets/6-adapters/postgres/src/core/sql-renderer.ts`:
- Around line 282-297: The current resolution loop over sourcesByRef only treats
ambiguity when multiple enum-backed columns match, allowing a rewrite to
array_position(...) when the same column name exists on multiple sources but
only one is enum; change the logic in sql-renderer.ts so that before setting
resolved (and before performing the array_position rewrite) you first count
matches of the identifier across all sources (use sourcesByRef and
contract.storage.namespaces lookups used in the existing loop), and only proceed
to set resolved/valueSet and perform the enum rewrite when the identifier
matches exactly one source column in total (not just one enum column); apply the
same uniqueness check to the other matching block that leads to the
array_position rewrite (the code around the existing resolved variable usage and
the 317-321 region) so ambiguous column names are not rewritten.
🪄 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: 7c1e650a-68d2-4642-b876-c4cedb51f2f4

📥 Commits

Reviewing files that changed from the base of the PR and between c011d3a and bc85f26.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (19)
  • examples/enum-demo/README.md
  • examples/enum-demo/biome.jsonc
  • examples/enum-demo/package.json
  • examples/enum-demo/prisma-next.config.ts
  • examples/enum-demo/src/contract.d.ts
  • examples/enum-demo/src/contract.json
  • examples/enum-demo/src/contract.ts
  • examples/enum-demo/src/db.ts
  • examples/enum-demo/test/enum-demo.integration.test.ts
  • examples/enum-demo/test/enum-demo.types.test-d.ts
  • examples/enum-demo/test/init-db.ts
  • examples/enum-demo/tsconfig.json
  • examples/enum-demo/vitest.config.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts
  • packages/2-sql/4-lanes/query-builder/src/selection.ts
  • packages/3-extensions/postgres/test/postgres.test.ts
  • packages/3-extensions/sqlite/test/transaction.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/order-by-enum.integration.test.ts
✅ Files skipped from review due to trivial changes (8)
  • examples/enum-demo/tsconfig.json
  • examples/enum-demo/prisma-next.config.ts
  • examples/enum-demo/src/contract.ts
  • packages/3-extensions/sqlite/test/transaction.test.ts
  • examples/enum-demo/src/contract.json
  • examples/enum-demo/biome.jsonc
  • examples/enum-demo/README.md
  • examples/enum-demo/src/contract.d.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/2-sql/4-lanes/query-builder/src/selection.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts

wmadden and others added 3 commits June 8, 2026 16:50
…L-2852)

Reduce the enum value-union narrowing to a shallow, single-pass form and fix a
non-null enum column reading as `union | null`.

Behavior spec (TDD, tests first):
- A non-null enum field reads/writes as exactly its value union (no `| null`).
- A nullable enum field reads/writes as `union | null`.
- A non-text (int-backed) enum narrows to its int value union (e.g. `1 | 10`).
- Non-enum fields keep their codec output unchanged.

Implementation:
- contract-types.ts: compute a field`s non-null base type once (enum value
  union when the field is enum-typed, else the codec channel), apply nullability
  once. Replaces the deeply nested FieldCodecOutputType / EnumNarrowedType pair
  (max conditional depth ~10 -> ~4).
- contract-types.ts: resolve an enum-handle field`s storage descriptor and
  type-ref from the handle, so an enum column is a real StorageColumn with the
  correct `nullable: false` instead of collapsing to `never` (the `never extends
  true` vacuous-truth that injected the spurious `| null` in the select lane).
- query-builder selection.ts: delete FindModelForTable / FindFieldForColumn /
  EnumOutputOverride / FieldOutputTypeFor; read the FieldOutputTypes override in
  one flat mapped-type pass (max depth ~7 -> ~3).
- enum-type.ts + build-contract.ts: enum member values may be string or number
  literals (preserved in the handle for narrowing); encode to strings when
  lowering to the storage value-set / domain enum members.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…enum-demo (TML-2852)

Move the enum read-surface example out of a standalone `examples/enum-demo`
app and into the existing `prisma-next-demo`, and fix the Postgres value-set
materialization gap the move surfaced.

- Postgres value-set materialization: `postgresCreateNamespace` and the
  Postgres contract serializer dropped the `entries.valueSet` slot, so an
  `enumType`-authored enum built through the Postgres builder lost its
  storage value-set. The CHECK constraint and the declaration-order ORDER BY
  both reference that value-set, so `db init` failed ("value-set not found")
  and ORDER BY fell through to a bare column. `PostgresSchema` now carries
  `valueSet`, and the serializer round-trips it.
- postgres `defineContract`: thread an `enums` field through the wrapper so a
  Postgres contract can declare `enumType` enums; re-export `enumType` /
  `member` / `EnumTypeHandle` from `@prisma-next/postgres/contract-builder`.
- prisma-next-demo: add a TS-authored `enumType` enum (`Priority`) on a small
  definition-form contract and demonstrate the three surfaces with tests —
  typed read/write narrowing (`*.types.test-d.ts`), `db.enums` accessors, and
  declaration-order ORDER BY against a dev database. PSL `enum` stays native.
- Delete `examples/enum-demo` entirely (workspace + lockfile).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…any joined source shares the name (TML-2852)

resolveEnumOrderValuesForIdentifier only fell through when two enum-backed
columns matched. A join where the same column name exists on multiple sources
but only one is enum-backed still rewrote to array_position over a bare
identifier — ambiguous SQL. Now count every source column with that name (enum
or not); rewrite only when exactly one source has it and it carries a value-set.

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

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/2-sql/2-authoring/contract-ts/src/enum-type.ts (1)

188-203: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate uniqueness on the lowered storage value.

seenValues now treats 1 and '1' as distinct, but build-contract.ts later normalizes both to "1". That means enumType('E', ..., member('One', 1), member('TextOne', '1')) passes here and then emits duplicate enum/value-set entries downstream. Please compare uniqueness on String(m.value) (or otherwise on the lowered representation) so authored enums stay one-to-one after serialization.

🛠️ Suggested fix
-  const seenValues = new Set<string | number>();
+  const seenLoweredValues = new Set<string>();
   for (const m of members) {
     if (seenNames.has(m.name)) {
       throw new Error(
         `enumType("${name}"): duplicate member name "${m.name}". Member names must be unique.`,
       );
     }
     seenNames.add(m.name);

-    if (seenValues.has(m.value)) {
+    const loweredValue = String(m.value);
+    if (seenLoweredValues.has(loweredValue)) {
       throw new Error(
-        `enumType("${name}"): duplicate member value "${m.value}". Member values must be unique.`,
+        `enumType("${name}"): duplicate member value "${loweredValue}" after storage encoding. Member values must be unique.`,
       );
     }
-    seenValues.add(m.value);
+    seenLoweredValues.add(loweredValue);
   }
🤖 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/2-sql/2-authoring/contract-ts/src/enum-type.ts` around lines 188 -
203, The uniqueness check for enum member values in the members loop treats
numeric 1 and string "1" as distinct; change the logic in enum-type.ts (inside
the members iteration where seenValues is used) to compare and store the
lowered/serialized representation (e.g., String(m.value)) so duplication is
detected after serialization; update seenValues to be a Set<string>, perform
seenValues.has(String(m.value)) for the duplicate check, and then
seenValues.add(String(m.value)) when storing the value.
packages/2-sql/2-authoring/contract-ts/src/contract-types.ts (1)

594-603: ⚠️ Potential issue | 🟠 Major

Fix enumAccessors accessor method parameter types to use the authored enum value union

EnumHandleAccessorType still types has/nameOf/ordinalOf as v: string (even though enum handles are string | number at runtime and carry literal value tuples), so int-backed enums will incorrectly reject db.enums.<Enum>.has(1) / nameOf(10) / ordinalOf(1) at compile time.

🛠️ Suggested fix
 type EnumHandleAccessorType<Handle> =
   Handle extends EnumTypeHandle<infer _Name, infer Values, infer Names, infer MembersMap>
     ? {
         readonly values: Values;
         readonly names: Names;
         readonly members: MembersMap;
-        has(v: string): boolean;
-        nameOf(v: string): string | undefined;
-        ordinalOf(v: string): number;
+        has(v: Values[number]): boolean;
+        nameOf(v: Values[number]): string | undefined;
+        ordinalOf(v: Values[number]): number;
       }
     : never;
🤖 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/2-sql/2-authoring/contract-ts/src/contract-types.ts` around lines
594 - 603, EnumHandleAccessorType currently types the has/nameOf/ordinalOf
parameters as v: string which prevents numeric enum values from compiling;
update the parameter types for has, nameOf, and ordinalOf to accept the authored
enum value union (use the inferred Values tuple to derive the value type, e.g.
Values[number] or the equivalent union) in the EnumHandleAccessorType definition
so these methods accept both string and numeric enum members.
🧹 Nitpick comments (1)
examples/prisma-next-demo/test/utils/enum-control-client.ts (1)

27-29: 💤 Low value

Optional: remove redundant mkdirSync after mkdtempSync.

mkdtempSync at line 27 already creates the directory atomically, so the mkdirSync call at line 29 is redundant. While the recursive: true flag makes this a harmless no-op, removing it would simplify the code.

♻️ Simplify by removing the redundant mkdir
 const migrationsDir = mkdtempSync(join(tmpdir(), 'prisma-next-demo-enum-migrations-'));
 try {
-  mkdirSync(migrationsDir, { recursive: true });
   const initResult = await client.dbInit({
🤖 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 `@examples/prisma-next-demo/test/utils/enum-control-client.ts` around lines 27
- 29, Remove the redundant mkdirSync call: after creating migrationsDir with
mkdtempSync (symbol migrationsDir), delete the subsequent
mkdirSync(migrationsDir, { recursive: true }) invocation since mkdtempSync
already creates the directory atomically; ensure any surrounding try/catch or
error handling still makes sense after removing the mkdirSync line.
🤖 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.

Outside diff comments:
In `@packages/2-sql/2-authoring/contract-ts/src/contract-types.ts`:
- Around line 594-603: EnumHandleAccessorType currently types the
has/nameOf/ordinalOf parameters as v: string which prevents numeric enum values
from compiling; update the parameter types for has, nameOf, and ordinalOf to
accept the authored enum value union (use the inferred Values tuple to derive
the value type, e.g. Values[number] or the equivalent union) in the
EnumHandleAccessorType definition so these methods accept both string and
numeric enum members.

In `@packages/2-sql/2-authoring/contract-ts/src/enum-type.ts`:
- Around line 188-203: The uniqueness check for enum member values in the
members loop treats numeric 1 and string "1" as distinct; change the logic in
enum-type.ts (inside the members iteration where seenValues is used) to compare
and store the lowered/serialized representation (e.g., String(m.value)) so
duplication is detected after serialization; update seenValues to be a
Set<string>, perform seenValues.has(String(m.value)) for the duplicate check,
and then seenValues.add(String(m.value)) when storing the value.

---

Nitpick comments:
In `@examples/prisma-next-demo/test/utils/enum-control-client.ts`:
- Around line 27-29: Remove the redundant mkdirSync call: after creating
migrationsDir with mkdtempSync (symbol migrationsDir), delete the subsequent
mkdirSync(migrationsDir, { recursive: true }) invocation since mkdtempSync
already creates the directory atomically; ensure any surrounding try/catch or
error handling still makes sense after removing the mkdirSync line.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: a209978a-97a7-42f7-9907-30108d7a8de5

📥 Commits

Reviewing files that changed from the base of the PR and between bc85f26 and f642ed8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • examples/prisma-next-demo/prisma/enum-contract.ts
  • examples/prisma-next-demo/prisma/enum-db.ts
  • examples/prisma-next-demo/test/enum-surface.integration.test.ts
  • examples/prisma-next-demo/test/enum-surface.types.test-d.ts
  • examples/prisma-next-demo/test/utils/enum-control-client.ts
  • packages/2-sql/2-authoring/contract-ts/src/build-contract.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/src/enum-type.ts
  • packages/2-sql/2-authoring/contract-ts/test/enum-type.field-output.test.ts
  • packages/2-sql/4-lanes/query-builder/src/selection.ts
  • packages/3-extensions/postgres/src/contract/define-contract.ts
  • packages/3-extensions/postgres/src/exports/contract-builder.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-schema.ts
  • test/integration/test/contract-builder.types.test-d.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/3-extensions/postgres/src/exports/contract-builder.ts

wmadden and others added 3 commits June 8, 2026 17:30
Collapse the enum read/write field-type helpers to the flattest shape the
behavior tests require, without changing non-enum resolution:

- Replace the `IsEnumTypeRef` boolean threaded through three descriptor
  resolvers with a single `EnumFieldHandle<FieldState>` that yields the
  handle (or never). `ResolveFieldDescriptor` and `ResolveFieldColumnTypeRef`
  now short-circuit on it; for non-enum fields both reduce to mains exact
  bodies. `ResolveFieldColumnTypeParams` reverts to byte-identical-to-main
  (it already produced undefined for enum fields via the column-type-ref).
- Merge `FieldOutputType` + `FieldInputType` + `FieldNullable` + `FieldBaseType`
  into one channel-parameterised `FieldChannelType` and one `FieldChannelTypes`
  map; nullability is a flat union member, not an outer conditional.

Net -27 lines; no behavior change (enum field-output type-tests and the
full-lane ResultType spec stay green).

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

The factory form of defineContract dropped a top-level `enums` key returned
from the factory callback: its `Built` generic carried only `types`/`models`
and the impl spread only those, so an enum authored through the factory never
reached `SqlContractResult` -> field narrowing / db.enums.

Mirror the definition form. The factory `Built` type now carries
`readonly enums?: Enums` captured with a `const Enums` generic, the impl spreads
`built.enums`, and the public factory overload merges scaffold-declared and
factory-returned enums into the narrowing `Enums` slot. A parity type-test
asserts the factory form narrows field reads/writes to the value union and
surfaces the same `enumAccessors` shape as the definition form.

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

Thread a factory-returned `enums` key through the Postgres `defineContract`
wrapper so its factory form carries enum handles (previously only the scaffold
arg did), mirroring the base builder. The demo contract (factory form) now
declares a `Priority` enum (declaration order low -> high -> urgent, which
differs from lexical) and references it on `Post.priority` via
`field.namedType`.

The no-emit app code consumes it for real: `getPostsByPriority` reads the
narrowed value union and orders by declaration order, and `getPriorityEnum`
surfaces `db.enums.Priority`. The rewritten enum-surface tests prove the read
narrows to the union (not string), `db.enums` exposes the declaration-ordered
runtime surface, declaration-order ORDER BY sorts low/low/high/urgent, and the
CHECK constraint rejects out-of-union writes.

Removes the side-contract (prisma/enum-contract.ts, prisma/enum-db.ts,
test/utils/enum-control-client.ts) it replaces. The PSL schema is untouched
(PSL enum repoint is a later slice).

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

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/2-sql/2-authoring/contract-ts/src/contract-types.ts (1)

596-605: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Accept numeric enum values in accessor lookups.

Lines 602-604 hard-code string lookup inputs, but this PR also introduces int-backed enums (Priority in the new factory-form test is 1 | 10). That means enumAccessors.Priority.has(1), nameOf(1), and ordinalOf(1) are rejected by the public types even though numeric enum values are now first-class elsewhere in the surface.

Suggested fix
 type EnumHandleAccessorType<Handle> =
   Handle extends EnumTypeHandle<infer _Name, infer Values, infer Names, infer MembersMap>
     ? {
         readonly values: Values;
         readonly names: Names;
         readonly members: MembersMap;
-        has(v: string): boolean;
-        nameOf(v: string): string | undefined;
-        ordinalOf(v: string): number;
+        has(v: string | number): boolean;
+        nameOf(v: string | number): Names[number] | undefined;
+        ordinalOf(v: string | number): number;
       }
     : never;
🤖 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/2-sql/2-authoring/contract-ts/src/contract-types.ts` around lines
596 - 605, The accessor type EnumHandleAccessorType currently restricts lookup
inputs to string, which breaks int-backed enums; update the method signatures on
EnumHandleAccessorType (the has, nameOf, and ordinalOf members) to accept both
string and number (e.g., change parameter type from string to string | number)
so numeric enum values like 1 or 10 are allowed in lookups while keeping return
types the same.
packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts (1)

435-439: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Merge scaffold and factory enums before building the contract.

Lines 435-439 currently overwrite definition.enums with built.enums. That disagrees with the factory-form type on Lines 504-529, which advertises MergeEnums<ScaffoldEnums, FactoryEnums>. In a mixed contract, any scaffold-authored enum disappears from the built contract as soon as the factory returns an enums object, so the runtime enum surface no longer matches the published type.

Suggested fix
     return buildContractFromDsl({
       ...full,
       ...ifDefined('types', built.types),
       ...ifDefined('models', built.models),
-      ...ifDefined('enums', built.enums),
+      ...ifDefined(
+        'enums',
+        built.enums === undefined
+          ? undefined
+          : {
+              ...(definition.enums ?? {}),
+              ...built.enums,
+            },
+      ),
     });
🤖 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/2-sql/2-authoring/contract-ts/src/contract-builder.ts` around lines
435 - 439, The returned contract currently overwrites scaffold enums with
factory enums; change the merge so scaffold and factory enums are combined
before calling buildContractFromDsl by merging full.enums and built.enums into a
single enums object (respecting scaffold keys and letting factory keys override
where intended) instead of using ifDefined('enums', built.enums); update the
return in the function that calls buildContractFromDsl to pass the merged enums
(referencing buildContractFromDsl, ifDefined, definition.enums, built.enums and
the MergeEnums<ScaffoldEnums, FactoryEnums> contract type) so runtime enums
match the published MergeEnums type.
packages/3-extensions/postgres/src/contract/define-contract.ts (1)

24-40: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep the Postgres wrapper's enum generics split between scaffold and factory.

This wrapper collapses both enum sources into one Enums generic. Unlike the core defineContract overload in packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts (Lines 489-530), that means defineContract({ enums: { A } }, () => ({ enums: { B } })) cannot model the combined shape through the Postgres API. The extension surface ends up narrower than the builder it delegates to.

Suggested fix
 export function defineContract<
   const Types extends TypesConstraint = Record<never, never>,
   const Models extends ModelsConstraint = Record<never, never>,
   const ExtensionPacks extends
     | Record<string, ExtensionPackRef<'sql', string>>
     | undefined = undefined,
-  const Enums extends EnumsConstraint = Record<never, never>,
+  const ScaffoldEnums extends EnumsConstraint = Record<never, never>,
+  const FactoryEnums extends EnumsConstraint = Record<never, never>,
 >(
-  scaffold: PostgresScaffold<ExtensionPacks, Enums>,
+  scaffold: PostgresScaffold<ExtensionPacks, ScaffoldEnums>,
   factory: (helpers: ComposedAuthoringHelpers<SqlFamily, PostgresPack, ExtensionPacks>) => {
     readonly types?: Types;
     readonly models?: Models;
-    readonly enums?: Enums;
+    readonly enums?: FactoryEnums;
   },
-): PostgresResult<Types, Models, ExtensionPacks, Enums>;
+): PostgresResult<
+  Types,
+  Models,
+  ExtensionPacks,
+  MergeEnums<ScaffoldEnums, FactoryEnums>
+>;

Also applies to: 84-98

🤖 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/postgres/src/contract/define-contract.ts` around lines
24 - 40, The Postgres wrapper collapses scaffold and factory enums into one
Enums generic; update type PostgresResult to accept two enum generics (e.g.
EnumsScaffold and EnumsFactory) and pass them through to buildBoundContract so
both the scaffold-provided enums and the factory-provided enums are preserved.
Concretely: replace the single Enums generic with separate EnumsScaffold and
EnumsFactory generics, change the scaffold-side shape to use enums?:
EnumsScaffold and ensure the factory-side shape (the buildBoundContract
return/input) is typed to accept enums?: EnumsFactory so the wrapper delegates
both enum sources to buildBoundContract (referencing the PostgresResult type and
buildBoundContract, SqlFamily, and PostgresPack symbols).
🤖 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.

Outside diff comments:
In `@packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts`:
- Around line 435-439: The returned contract currently overwrites scaffold enums
with factory enums; change the merge so scaffold and factory enums are combined
before calling buildContractFromDsl by merging full.enums and built.enums into a
single enums object (respecting scaffold keys and letting factory keys override
where intended) instead of using ifDefined('enums', built.enums); update the
return in the function that calls buildContractFromDsl to pass the merged enums
(referencing buildContractFromDsl, ifDefined, definition.enums, built.enums and
the MergeEnums<ScaffoldEnums, FactoryEnums> contract type) so runtime enums
match the published MergeEnums type.

In `@packages/2-sql/2-authoring/contract-ts/src/contract-types.ts`:
- Around line 596-605: The accessor type EnumHandleAccessorType currently
restricts lookup inputs to string, which breaks int-backed enums; update the
method signatures on EnumHandleAccessorType (the has, nameOf, and ordinalOf
members) to accept both string and number (e.g., change parameter type from
string to string | number) so numeric enum values like 1 or 10 are allowed in
lookups while keeping return types the same.

In `@packages/3-extensions/postgres/src/contract/define-contract.ts`:
- Around line 24-40: The Postgres wrapper collapses scaffold and factory enums
into one Enums generic; update type PostgresResult to accept two enum generics
(e.g. EnumsScaffold and EnumsFactory) and pass them through to
buildBoundContract so both the scaffold-provided enums and the factory-provided
enums are preserved. Concretely: replace the single Enums generic with separate
EnumsScaffold and EnumsFactory generics, change the scaffold-side shape to use
enums?: EnumsScaffold and ensure the factory-side shape (the buildBoundContract
return/input) is typed to accept enums?: EnumsFactory so the wrapper delegates
both enum sources to buildBoundContract (referencing the PostgresResult type and
buildBoundContract, SqlFamily, and PostgresPack symbols).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 62792a6c-5926-4b5e-85c2-4e0ed53c2b8e

📥 Commits

Reviewing files that changed from the base of the PR and between f642ed8 and 6e2afa1.

📒 Files selected for processing (10)
  • examples/prisma-next-demo/prisma/contract.ts
  • examples/prisma-next-demo/src/prisma-no-emit/priority-feed.ts
  • examples/prisma-next-demo/test/enum-surface.integration.test.ts
  • examples/prisma-next-demo/test/enum-surface.types.test-d.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-builder.ts
  • packages/2-sql/2-authoring/contract-ts/src/contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/enum-type.factory-form.test.ts
  • packages/3-extensions/postgres/src/contract/define-contract.ts
  • packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/order-by-enum.integration.test.ts
✅ Files skipped from review due to trivial changes (1)
  • examples/prisma-next-demo/test/enum-surface.types.test-d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/3-targets/6-adapters/postgres/src/core/sql-renderer.ts

wmadden and others added 4 commits June 9, 2026 13:52
…g|number (TML-2852)

member<N, V> stays generic over any literal V; enumType constrains member
values to the codec descriptors input type via CodecInput<C> (falls back to
unknown when the descriptor carries no input phantom). EnumTypeHandle and the
db.enums accessor (has/nameOf/ordinalOf) now accept the value union, so
int-backed enums accept numeric values. Uniqueness now compares the lowered
String(value) form so 1 and "1" collide as build-contract later normalizes them.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
buildBoundContract previously spread built.enums into the DSL input, overwriting
any scaffold-authored definition.enums. The factory-form type advertises
MergeEnums<ScaffoldEnums, FactoryEnums>, so a mixed contract silently lost the
scaffold enums at runtime. Merge both sides instead.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ntract (TML-2852)

The postgres wrapper collapsed scaffold + factory enums into one Enums generic,
so it could not model defineContract({ enums: { A } }, () => ({ enums: { B } }))
— narrower than the core defineContract it delegates to. Split into
ScaffoldEnums / FactoryEnums and return MergeEnums<ScaffoldEnums, FactoryEnums>,
mirroring the core overload. Exposes MergeEnums from the core builder for reuse.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… demo test (TML-2852)

Remove the redundant comment on contract.ts. The enum accessor probe with a
non-member value now annotates the value union, since has() is typed to the
codec value union after making member values codec-driven.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden enabled auto-merge June 10, 2026 13:01
@wmadden
wmadden added this pull request to the merge queue Jun 10, 2026
Mongo enums move from a non-goal to scope. The domain enum is framework-level
and target-agnostic; Mongo realizes the value-set restriction as a $jsonSchema
collection validator (validationLevel: strict) instead of a CHECK constraint,
needing no value-set storage IR or migration-ops parallel. Mongo has no native
enum and no prior PSL enum, so it skips the transitional keyword and the cutover
entirely. Planned as one complete vertical slice (author -> enforce -> read,
proven end-to-end against mongodb-memory-server) rather than split, since a
non-vertical slice cannot be shown to work. Independent of the SQL track.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden removed this pull request from the merge queue due to a manual request Jun 10, 2026
wmadden and others added 3 commits June 10, 2026 15:35
…aCodec

encodeEnumValue and encodeDefaultLiteralValue both did the same
codec-or-fallback dance. Merge them into one encodeViaCodec helper used
for both the column-default and enum-lowering paths. Folds the former
bare `as JsonValue` on the default path into the unified blindCast.

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

The enum-accessor builders and types are built purely from
contract.domain.namespaces[ns].enum (framework ContractEnum), with
nothing ORM-specific. Living in sql-orm-client forced the postgres and
sqlite facade tests to wholesale-mock @prisma-next/sql-orm-client and
pass buildNamespacedEnums through the mock to avoid a construction crash.

Move the module to @prisma-next/contract (the 0-foundation layer both
SQL facades and a future Mongo facade already depend on) under a new
@prisma-next/contract/enum-accessor entrypoint, and relax the type
constraint from Contract<SqlStorage> to Contract so it stays
lane-neutral. Update the postgres/sqlite facades, the postgres read-
surface type test, and the demo no-emit context to the new path; drop
the now-unneeded buildNamespacedEnums pass-through from all four facade
test mocks. The facade tests now run against the real, unmocked accessor.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The no-emit context hand-wired stack/context/sql and hand-built the
enums map with two blindCasts, behind a comment claiming "the no-emit
path has no facade to hang db.enums on" — which is wrong: postgres()
accepts a TypeScript-authored contract with deferred binding and exposes
sql/enums/context/stack directly.

Source those from the facade (db.sql.public, db.enums, db.context,
db.stack), dropping both blindCasts, the misleading comment, and the
custom rawCodecInferer stub (the facade uses the adapter inferer).
createOrmClient still uses the orm() builder because the demo binds an
externally-created runtime; everything else now comes from db.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit dc72201 Jun 10, 2026
28 of 29 checks passed
@wmadden-electric
wmadden-electric deleted the tml-2852-application-read-surface branch June 10, 2026 14:48
wmadden-electric pushed a commit that referenced this pull request Jun 10, 2026
The merge pulled in three enum tests from main (PR #769) that construct
runtimes through the deleted createRuntime / mocked-deserializer path. Port
them to this branch's design:

- postgres.test.ts: the two db.enums facade tests passed contractJson:{} with
  a mocked deserializeContract and asserted mocks.createRuntime. This branch's
  postgres.test.ts mocks only the pg boundary, so pass the real
  twoNamespaceDomain as contract and assert the pool never connects instead of
  inspecting a (deleted) createRuntime mock.
- enum-surface.integration.test.ts: openRuntime built the runtime via
  instantiateExecutionStack + createRuntime; rebuild it through the
  postgres({ contract, url, extensions }).connect() facade, matching
  repositories.integration.test.ts.
- runtime.ts: context.ts no longer exports validatedContract (took main's
  db-facade form), so pass the raw contract; the facade deserializes it.

Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
SevInf added a commit that referenced this pull request Jun 10, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added a commit that referenced this pull request Jun 11, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jun 11, 2026
…risma#805)

## Linked issue

Refs
[TML-2882](https://linear.app/prisma-company/issue/TML-2882/slice-transitional-psl-enum2-block-author-the-new-enum-through-psl).
Builds on the merged enum substrate (TML-2850, prisma#750), check enforcement
(TML-2851, prisma#755), and typed read surface (TML-2852, prisma#769).
Hands to TML-2855 (member defaults) and TML-2853 (cutover, now reduced
to rename + migrate + delete).

## At a glance

The demo's PSL schema now authors the new domain-concept enum directly —
while native `enum` keeps working untouched:

```prisma
enum2 Priority {
  @@type("pg/text@1")
  Low    = "low"
  High   = "high"
  Urgent = "urgent"
}

model Post {
  priority Priority
}
```

Emit it and the real app uses it end-to-end through the emitted contract
— `post.priority` reads as `'low' | 'high' | 'urgent'`,
`db.enums.public.Priority.values` returns the ordered tuple, `ORDER BY
priority` sorts by declaration order, and the migration adds the
`CHECK`:

```ts
export async function getPostsByPriority(limit = 10) {
  const plan = db.sql.public.post
    .select('id', 'title', 'priority')
    .orderBy('priority')          // declaration order: low, high, urgent
    .limit(limit)
    .build();
  return db.runtime().execute(plan);
}
```

Before this PR, the new enum mechanism was reachable only through the TS
`enumType` DSL — unreachable from PSL, and therefore from the demo's
real emitted-contract app.

## Decision

Add a **parallel transitional PSL keyword** (`enum2`) that lowers to the
new enum mechanism — domain `enum` entity + storage `valueSet` entity +
field/column `valueSet` restriction refs + check constraint — **reusing
the lowering the TS `enumType` path already has**. Native `enum` is
byte-for-byte untouched.

The point is to dissolve the constraint that forced an atomic cutover:
`enum` is one keyword and can't mean both native and the new shape at
once, so the new mechanism was unreachable through PSL until the very
end of the project. The second keyword makes it PSL-authorable
**additively**, takes it live through the product path (PSL → emit →
app) now, and shrinks the cutover (TML-2853) to a rename + migrate +
delete with the risky lowering already proven in live use.

The keyword is deliberately disposable: it is retired at the cutover,
when `enum` itself repoints at this lowering.

## Reviewer notes

- **The central guarantee is parity:** for the same schema, the PSL
`enum2` path and the TS `enumType` path emit **identical contract JSON,
including `storageHash`**. The parity test
([interpreter.enum2.test.ts](packages/2-sql/2-authoring/contract-psl/test/interpreter.enum2.test.ts))
asserts strict deep equality on every emitted slice plus hash equality —
it started life as `toMatchObject` and was hardened to `toEqual` after
subset matching let a divergence escape (next bullet).
- **Two correction arcs are visible in the history, kept honest rather
than rewritten.** (1) `ead068f57` patched the SQL-family schema verifier
and codec-ref resolver to tolerate a stray `typeRef` the PSL path was
leaking onto emitted columns; review caught that the leak was the bug,
so `3ec205e9e` fixed it at the source and reverted both patches
byte-identically. (2) The first round built a dedicated
`parseEnum2Block` grammar production and a per-target
`entityTypes.enum2` presence stub; review (correctly) rejected both, and
`aad4e15b3`–`99fc662dc` rework enum2 onto the generic extension-block
grammar and delete the stub mechanism entirely.
- **A latent interpreter bug is fixed in passing:** the final contract
reconstruction in `interpretPslDocumentToSqlContract` rebuilt domain
namespace slices copying only `models`/`valueObjects`, silently dropping
`enum` entities. Nothing PSL-authored produced domain enums until now,
so it was unobservable before this PR.
- **The PSL printer silently drops `enum2` blocks.** Verified no
in-scope flow round-trips authored PSL through the printer (it runs only
in the schema-inference direction), so printing support is deferred to
the cutover, where the keyword is renamed anyway.
- **Known emitter gap (pre-existing, now tracked as
[TML-2885](https://linear.app/prisma-company/issue/TML-2885)):** the
emitted `contract.d.ts` narrows enum **column/field types** to the value
union, but does not type the domain `enum` block itself — so on the
emitted path, `db.enums.<ns>.<Name>.members` values are
`JsonValue`-typed at the type level (runtime values are correct). The
demo's literal-union type proofs therefore live on the column types
(SELECT/INSERT), which the emitter does narrow. Project spec R6 amended
to require emit parity; TML-2885 is now a cutover prerequisite.
- `pnpm lint` shows two pre-existing `no-bare-cast` info notices in
files this branch never touches; no new casts are added.

## How it fits together

1. **Grammar — no enum2-specific parsing**
([psl-parser/src/parser.ts](packages/1-framework/2-authoring/psl-parser/src/parser.ts)):
`enum2 Priority { … }` rides the existing generic extension-block
grammar (`<keyword> <Name> { key = value … }`); members are ordinary
parameter lines captured raw. The parser gains three **generic**
extension-block capabilities (each independently tested, usable by any
contributed block): `@@attr(...)` block-attribute lines,
duplicate-parameter diagnostics, and bare-identifier parameters behind a
descriptor opt-in flag.
2. **Interpreter**
([contract-psl/src/interpreter.ts](packages/2-sql/2-authoring/contract-psl/src/interpreter.ts)):
`processEnum2Declarations` consumes the `enum2`-keyword extension blocks
— validates `@@type` presence (required, never inferred), validates each
member's raw value with `JSON.parse` + `codec.decodeJson` (bare members
default to their name for string-accepting codecs), and enforces
well-formedness. Per enum it builds an `EnumTypeHandle` via the existing
`enumType()` and a `ColumnDescriptor` in the existing by-name map — so
field resolution (`priority Priority`) is unchanged and doesn't care
which block declared the name. Support requires no per-target
registration: a target that lacks the codec fails with the unknown-codec
diagnostic; the block descriptor lives at the SQL-family level, marked
`interpreterLowered` (the factory invariant now admits blocks lowered by
the interpreter rather than an entity-type factory).
3. **Lowering is 100% reuse:** the handles flow into the existing
`buildSqlContractFromDefinition` as `enums`, and the domain enum,
storage value-set, field/column `valueSet` refs, and the table check all
fall out of the already-merged build-contract code. Zero new lowering.
4. **Demo goes live**
([examples/prisma-next-demo](examples/prisma-next-demo)): `enum2
Priority` in the PSL schema, re-emitted `contract.json`/`contract.d.ts`,
migration `20260610T0000_add_priority_enum` (addColumn → setNotNull →
addCheckConstraint), and `enum-priority` / `enum-priority-filter`
subcommands consuming the enum through the emitted contract — including
filtering by a live member value via the emitted accessor; seeds and
integration fixtures source values from the emitted accessor too, never
raw literals.

## Behavior changes & evidence

- **The generic extension-block grammar gains `@@attr(...)` block
attributes, duplicate-parameter diagnostics, and opt-in bare-identifier
parameters** — and `enum2` blocks parse through it with zero
block-specific grammar. Implementation:
[parser.ts](packages/1-framework/2-authoring/psl-parser/src/parser.ts),
[psl-extension-block.ts](packages/1-framework/1-core/framework-components/src/shared/psl-extension-block.ts).
Evidence:
[parser-enum2.test.ts](packages/1-framework/2-authoring/psl-parser/test/parser-enum2.test.ts).
- **The interpreter lowers `enum2` to the new two-plane shape,
identically to the TS path** — plus ten validation diagnostics (missing
`@@type`, unknown codec, non-JSON / codec-rejected values, bare member
under non-string codec, duplicate names/values, native-name collision,
namespaced `enum2`, unsupported target). Implementation:
[interpreter.ts](packages/2-sql/2-authoring/contract-psl/src/interpreter.ts).
Evidence:
[interpreter.enum2.test.ts](packages/2-sql/2-authoring/contract-psl/test/interpreter.enum2.test.ts)
— parity incl. `storageHash` equality, all diagnostics, native+enum2
mixed document, non-string codec.
- **The demo proves the feature through the emitted contract** — typed
value-union reads, `db.enums.public.Priority`, declaration-order `ORDER
BY`, and the check-adding migration. Implementation:
[contract.prisma](examples/prisma-next-demo/src/prisma/contract.prisma),
[get-posts-by-priority.ts](examples/prisma-next-demo/src/queries/get-posts-by-priority.ts),
[main.ts](examples/prisma-next-demo/src/main.ts). Evidence:
[demo-dx.types.test.ts](examples/prisma-next-demo/test/demo-dx.types.test.ts)
(non-vacuous: paired `.not.toEqualTypeOf<string>()` + `@ts-expect-error`
on an out-of-union insert), integration suites.
- **Native enums are untouched** — the demo's `user_type` emits
byte-identically; no native fixture changes; the mixed-document test
asserts the native slice is unchanged.

## Testing performed

- `pnpm test:packages` — 799 files, 10,328 tests green on final HEAD
- `pnpm typecheck` — 138 tasks green
- `pnpm fixtures:check` — zero diff outside the demo's deliberately
re-emitted artifacts
- `pnpm lint:deps` — clean
- Demo: type tests + integration suites; `enum-priority` subcommand run
end-to-end (declaration-order sort observed: low, high, urgent).
Occasional PGlite portal flakes reproduced and ruled pre-existing.

## Skill update

n/a — the `enum2` spelling is deliberately transitional and is retired
at the cutover (TML-2853), when `enum` itself gains this meaning.
Documenting a keyword scheduled for deletion in user-facing skills would
teach syntax users should never adopt long-term; the skill update lands
with the cutover rename.

## Follow-ups

- [TML-2885](https://linear.app/prisma-company/issue/TML-2885) — emit
the typed domain `enum` block so `db.enums` is literal-typed through the
emitted contract (R6 emit parity; surfaced by this PR's review; cutover
prerequisite).
- TML-2855 — enum member defaults (`@default(Low)` on a real PSL enum
field).
- TML-2853 — cutover: rename `enum2` → `enum`, migrate remaining native
enums, delete the native machinery, add printer support for the final
keyword.
- Numeric-codec SQL rendering (CHECK / `ORDER BY` for non-text
value-sets) stays guarded — tracked separately.

## Alternatives considered

- **No new keyword — discriminate within `enum` on `@@type` presence.**
The new syntax is already distinguishable from native, so `enum` could
mean the new shape when `@@type` is present. Rejected: it re-overloads
one keyword with two meanings depending on an attribute — exactly the
dual-meaning ambiguity this project removes. An explicit second keyword
is unambiguous, and the cutover rename is trivial.
- **Just do the atomic cutover now.** Rejected: the cutover can't land
until full parity with native (member defaults still outstanding), and
it would be a single non-additive big-bang with no prior live
validation. The transitional keyword exercises the new mechanism in
production use before the irreversible flip.
- **A dedicated `parseEnum2Block` grammar production instead of the
generic extension-block path.** Built in the first round (on the premise
that the missing `@@`-attribute support justified a bespoke parse),
rejected in review: the right fix for the gap was generic
block-attribute support in the extension-block grammar, landed in the
rework.
- **A per-target `entityTypes.enum2` presence registration.** Built in
the first round mirroring native enum's Postgres entry, rejected in
review: native enums are genuinely Postgres-specific, the domain enum is
target-agnostic. Support now falls out of codec resolution; the factory
invariant admits interpreter-lowered blocks.
- **`@map(...)` for member values.** Rejected: `@map` everywhere else in
PSL means a physical storage mapping; the member value is a first-class
domain value, so it's assigned with `=`.
- **Keep the SQL-family tolerance patches instead of fixing the
`typeRef` leak.** Rejected: they masked a parity violation (PSL emit ≠
TS emit, divergent `storageHash`). Fixed at the source; the patches
reverted as dead code.

## Checklist

- [x] All commits are signed off (`git commit -s`) per the
[DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco). The DCO
status check will block merge if any commit is missing a
`Signed-off-by:` trailer.
- [x] I read [CONTRIBUTING.md](../CONTRIBUTING.md) and the change is
scoped to one logical concern.
- [x] Tests are updated (or `n/a` if the change is doc-only / refactor
with no behavioural delta).
- [x] The PR title is in `TML-NNNN: <sentence-case title>` form (Linear
ticket prefix + concise title naming the concrete deliverable). See
`.claude/skills/create-pr/SKILL.md` for the full convention.
- [x] The **Skill update** section above is filled in (or stated `n/a —
internal only`).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Priority enum (Low, High, Urgent) for posts; demo supports
priority-aware listing and filtering.
  * Polymorphic Task types (Bug / Feature) exposed in demo.

* **Migrations**
* DB migration adds non-null post.priority and enforces allowed values.

* **CLI / Demo**
* New demo commands to list posts by priority and filter by priority
member; seed data updated with priorities.

* **Authoring**
* PSL authoring/parser extended to support enum2-style extension blocks.

* **Tests**
* Expanded tests covering enums, queries, seeding, and contract typings.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
SevInf added a commit that referenced this pull request Jun 12, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added a commit that referenced this pull request Jun 12, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added a commit that referenced this pull request Jun 15, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added a commit that referenced this pull request Jun 15, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added a commit that referenced this pull request Jun 15, 2026
Mains enum work (#769) renders enum value unions into the field-type maps;
our slice nests those maps by namespace id. Reconcile the enum type-tests to
the nested shape: index ExtractFieldOutputTypes/InputTypes through the default
namespace (public) or the fixtures __unbound__ coordinate, and pass the NsId
coordinate to ContractToQC. Enum value unions still resolve per-namespace; no
flat-map read reintroduced.

Signed-off-by: Serhii Tatarintsev <[email protected]>
wmadden-electric added a commit that referenced this pull request Jun 15, 2026
…havior; cover no-emit enum read

F01: the TML-2886 entries in both 0.13-to-0.14/instructions.md files described
the U3 behavior (enum field's FieldOutputTypes/FieldInputTypes entry "becomes
its plain codec channel"), which U6 reverted. Rewrite both to describe what
actually ships: the emitter renders the enum entry as a ref-following type
expression that indexes the emitted domain enum block, which STILL resolves to
the literal value union — FieldOutputTypes[ns][Model][enumField] stays
'low'|'high'|'urgent', not codec output. The source moved to the ref; the
observable type is unchanged. The "no API/SPI change, observable types
unchanged, no consumer action — incidental" conclusion is kept (correct, and
why it stays an incidental declaration).

F02: the no-emit baked-map fallback's reason-for-existing is already covered.
examples/prisma-next-demo/test/enum-surface.types.test-d.ts (committed, from
#769) asserts a no-emit (typeof contract) enum FIELD read through the
query-builder select — sql.post.select('id','priority') yields
Row['priority'] === 'low'|'high'|'urgent' and .not string — plus the no-emit
write. That exercises the no-emit query lane (the tier the baked-map fallback
backs), so no new test was added.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jun 15, 2026
## Linked issue

n/a — umbrella tracker maintenance for the Supabase integration
(`projects/supabase-integration/`). Adds the enums-as-domain-concept
framework project to the tracked list.

## At a glance

Enums are now a tracked part of the Supabase integration — they're
central to it: Supabase's `auth.*` schema declares Postgres enum types
and app schemas use enums heavily. New status-table row:

```md
| enums-as-domain-concept | Enum as a domain-plane name→value valueSet restriction on the
column's codec (not native CREATE TYPE); Postgres = value-set + check constraint, Mongo =
$jsonSchema; typed reads + db.enums + declaration-order ORDER BY | 🚧 In progress (separate
Terminal project) — substrate/enforcement/read-surface landed; PSL authoring, defaults,
cutover, Mongo remain |
```

## Decision

Doc-only. Add `enums-as-domain-concept` to the umbrella tracker. It is
**not** one of the original six constituents — it's a separate Terminal
Linear project — so it gets the same treatment the README already gives
the PSL-block substrate: a clearly-marked adopted framework project the
integration depends on, with a note explaining the relevance rather than
a claim that it was always in scope.

Why it belongs in the list: faithfully modelling enum-typed columns in
the Supabase contract (`auth.*` uses Postgres enums) and giving Supabase
apps first-class enums both depend on it. It's not a hard blocker for
the minimal walking skeleton, but it's required for the v0.1 enum story.

## What changed

- **Status table** — new `enums-as-domain-concept` row: substrate
(TML-2850) + Postgres enforcement (TML-2851) + read surface (TML-2852,
prisma#769) landed; PSL authoring (TML-2882), member defaults (TML-2855),
native-enum cutover (TML-2853), and the Mongo vertical (TML-2884)
remain.
- **Note below the table** — explains the Supabase relevance and flags
the design choice that the Postgres realization is a text column +
value-set + check constraint, **not** a native `CREATE TYPE … AS ENUM`.
- **Dependency graph** — `enums` node added; `foundation --> enums` and
a dashed `enums -.-> ext` ("enum-typed columns") edge.
- Bumped the status-pass date to 2026-06-11.

## Reviewer notes

- Pure docs; no source or behaviour change.
- `enums-as-domain-concept` has its own Linear project and its own
spec/plan under `projects/enums-as-domain-concept/` — this PR only
references it from the umbrella, it doesn't move or change it.
- The dashed graph edge mirrors the "adopted, not a hard blocker for the
minimal skeleton" framing in the prose.

## Testing performed

n/a — documentation only.

## Skill update

n/a — internal planning docs only; no user-facing surface change.

## Checklist

- [x] All commits are signed off (`git commit -s`).
- [x] I read CONTRIBUTING.md and the change is scoped to one logical
concern.
- [x] Tests are updated (n/a — doc-only).
- [ ] The PR title is in `TML-NNNN: <title>` form — n/a: umbrella
tracker maintenance with no single Linear ticket.
- [x] The **Skill update** section is filled in (n/a — internal only).

Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants