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

TML-2981: serialize the whole namespace entries dict, not a branch per kind - #931

Merged
wmadden-electric merged 3 commits into
mainfrom
tml-2981-serialize-the-sql-namespace-entries-dict-generically
Jul 8, 2026
Merged

wmadden-electric merged 3 commits into
mainfrom
tml-2981-serialize-the-sql-namespace-entries-dict-generically

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

At a glance

Serializing a namespace's entity kinds used to mean one hand-written branch per kind, repeated in every SQL target:

// before — postgres-contract-serializer.ts
entries: {
  table: tablesOut,
  ...(Object.keys(valueSetOut).length > 0 ? { valueSet: valueSetOut } : {}),
  ...(Object.keys(roleOut).length > 0 ? { role: roleOut } : {}),
  ...(Object.keys(policyOut).length > 0 ? { policy: policyOut } : {}),
}

Now it means walking the whole entries dict once, in the shared base:

// after — SqlContractSerializerBase
protected serializeNamespaceEntries(entries) {
  const out = { table: this.serializeEntries(entries['table'] ?? {}) };
  for (const [kind, record] of Object.entries(entries)) {
    if (kind === 'table' || Object.keys(record).length === 0) continue;
    out[kind] = this.serializeEntries(record);
  }
  return out;
}

The decision

Serialize a namespace's entity kinds by iterating the entries dict generically, in SqlContractSerializerBase — no target names a kind. This makes writing a contract match how we already read one: hydration has always iterated the entity-kind registry, so an entity kind now round-trips in both directions with no serializer edit.

Why — the asymmetry we're fixing

Deserialize was already generic — it walks the registered kinds:

hydrateNamespaceEntities(entriesInput, this.entryKinds, 'fail', id)

Serialize was not — each target listed table / valueSet / role / policy by hand. The consequence: an extension that contributes a new entity kind reads back for free but is silently dropped on the way out, until someone remembers to edit the target serializer. There was no signal that the write path needed touching — the kind just quietly vanished from contract.json.

What changes

  • A new SqlContractSerializerBase.serializeNamespaceEntries walks Object.entries(entries). The Postgres and SQLite serializers — and their unbound-slot branches — delegate to it; the JSON round-trip helpers move down into the base beside it.
  • table is the one kind still named: it is the universal SQL base kind, always emitted even when empty. Every other kind is emitted only when it holds an entry — the exact rule the old branches applied by hand.
  • A pack-contributed kind is already an enumerable key on entries and already hydrated via the registry, so it now serializes with zero serializer edits.

The one thing to trust: output is byte-identical

The old code emitted kinds in a fixed order; the new walk uses insertion order. That does not change the emitted file, because the contract is canonicalized — recursive key sort — after serialization on every path that writes or hashes it, so walk order never reaches disk. The emitted key set is unchanged too (table always; others only when non-empty). fixtures:check shows zero drift.

Two details keep it that way:

  • native_enum stays excluded. It is authoring-time-only, carried non-enumerable on entries (its values survive via the derived valueSet), so Object.entries skips it with no special case.
  • SQLite is unaffected. It sets sql.enums: false, so its only non-table slot is always empty and stays omitted; a future SQLite kind would round-trip instead of being dropped.

Tests

A base-level test serializes a namespace whose entries carry table, a real non-table kind, a synthetic extension widget kind, an empty kind, and a non-enumerable native_enum — asserting the extension kind round-trips while native_enum and the empty kind drop out. Existing target-serializer tests plus fixtures:check are the byte-identical proof.

Alternatives considered

  • Fix it per-target — make each serializer iterate its own kinds. Rejected: it leaves the duplication in place and the next SQL target repeats the mistake. The asymmetry is with the base's generic hydrate, so the fix belongs in the base.
  • Add an alwaysPresent flag to the kind descriptor instead of naming table directly. Rejected: speculative generality for a set of size one. table is the only universal base kind; naming it is honest and cheaper than a descriptor field one kind would ever set.
  • Drive serialization off the entryKinds registry (mirroring hydrate's exact mechanism) rather than Object.entries. The enumerable-key walk is simpler and gets native_enum exclusion for free via non-enumerability; consulting the registry would add a lookup the write path doesn't need.

Origin: review point O1 on #906. Shaping spec: projects/native-postgres-enums/slices/generic-namespace-entries-serialization/spec.md.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved serialization of namespace entries so empty table entries are preserved consistently, while empty optional sections are omitted.
    • Fixed handling of undefined or non-enumerable namespace sections so they no longer appear in serialized output.
    • Made contract serialization more consistent across database targets, including cleaner handling of stored type metadata.

wmadden-electric and others added 2 commits July 8, 2026 15:42
…L-2981)

Slice spec + plan entry for O1 from the PR #906 review — make the SQL contract
serializer iterate the namespace `entries` dict generically (symmetric with the
already-generic hydrate path) so extension-contributed entity kinds round-trip
without a serializer edit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The SQL contract serializer round-tripped entity kinds asymmetrically:
hydration already iterated the registered kinds generically
(`hydrateNamespaceEntities(entriesInput, this.entryKinds, …)`), but
serialization hardcoded one branch per kind in each target, so an
extension-contributed kind hydrated for free yet was silently dropped on
serialize unless someone edited the target serializer (PR #906 review, O1).

Make serialization symmetric: a new `SqlContractSerializerBase.serializeNamespaceEntries`
walks `Object.entries(ns.entries)` — naming only `table`, the universal base
kind (always emitted; other kinds emitted only when non-empty). The Postgres
and SQLite serializers delegate to it and their unbound-slot branches; the JSON
round-trip helpers move down to the base alongside it. `native_enum` stays
excluded for free — it is non-enumerable on `ns.entries`, so `Object.entries`
skips it.

Output is byte-identical: the emitted contract is canonicalized (recursive key
sort) after serialization, so the generic walk order is irrelevant, and the
emitted key set is unchanged. A pack-contributed kind now round-trips serialize
with no serializer edit (proven by a base-level test with a synthetic `widget`
kind + a non-enumerable `native_enum`).

typecheck 143/143; family-sql + target-postgres + target-sqlite tests green;
fixtures:check zero drift; lint:casts flat (1031); lint:deps clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 8, 2026 14:02
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds shared namespace-entry serialization helpers to SqlContractSerializerBase, then updates postgres and sqlite contract serializers to delegate to them. A new test suite covers serializeNamespaceEntries behavior for table entries, empty kinds, non-enumerable properties, and undefined slots.

Changes

Namespace Entries Serialization Refactor

Layer / File(s) Summary
Base serializer helpers and tests
packages/2-sql/9-family/src/core/ir/sql-contract-serializer-base.ts, packages/2-sql/9-family/test/namespace-entries-serialization.test.ts
Adds serializeNamespaceEntries, serializeEntries, serializeJsonObject, and serializeJsonValue with a new JsonValue import; adds tests for table inclusion, omission of empty extension kinds, and exclusion of non-enumerable or undefined slots.
Postgres serializer migration
packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
serializeContract now delegates namespace entries serialization to serializeNamespaceEntries and removes local slot-wise JSON serialization logic.
SQLite serializer migration
packages/3-targets/3-targets/sqlite/src/core/sqlite-contract-serializer.ts
serializeContract now uses serializeNamespaceEntries for entries and serializeJsonObject for storage.types, replacing inline JSON cleaning.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • prisma/prisma-next#750: Related namespace-entry serialization work around valueSet and enum-backed serializer shapes.
  • prisma/prisma-next#757: Related namespace structure changes for the canonical entries[kind][name] shape.

Suggested reviewers: wmadden

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: moving namespace entry serialization to a shared, whole-dictionary approach instead of per-kind branches.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2981-serialize-the-sql-namespace-entries-dict-generically

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.

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 149.75 KB (-0.05% 🔽)
postgres / emit 127.19 KB (-0.08% 🔽)
mongo / no-emit 98.36 KB (0%)
mongo / emit 89.39 KB (0%)
cf-worker / no-emit 176.55 KB (+0.03% 🔺)
cf-worker / emit 151.7 KB (-0.05% 🔽)

@pkg-pr-new

pkg-pr-new Bot commented Jul 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@931

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/config-loader

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

@prisma-next/emitter

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

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@931

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: c781cc3

@wmadden-electric wmadden-electric changed the title TML-2981: serialize the SQL namespace entries dict generically TML-2981: serialize the whole namespace entries dict, not a branch per kind Jul 8, 2026
- F01 (correctness): guard the generic entries walk against a null/undefined
  record. `PostgresSchema` can carry an enumerable `valueSet: undefined` own-key
  (its empty-valueSet normalization); `Object.keys(undefined)` threw. Latent
  today (generated paths drop empty valueSets) but reachable via the public
  class — the old serializer was immune because it read through getters. Adds a
  base-level test planting an enumerable `undefined` slot.
- F02: `serializeEntries` → `private` (only called from `serializeNamespaceEntries`).
- F03 + family-blindness: the two Postgres namespace-serialize paths were
  byte-identical, so fold them into one loop and drop `serializePostgresNamespace`
  + its orphaned native-enum JSDoc; de-Postgres the family-base doc comment so it
  names no target concept.

typecheck 143/143; family-sql 337/337; target-postgres 686/686; target-sqlite
168/168; fixtures:check zero drift; lint:casts flat (1031); lint:deps clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric added this pull request to the merge queue Jul 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to invalid changes in the merge commit Jul 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.

🧹 Nitpick comments (1)
packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts (1)

112-115: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Trim the avoidable part of this comment per coding guidelines.

Lines 112–113 restate what the code already expresses (id, kind, entries). Only the native-enum exclusion explanation (lines 113–115) carries non-obvious context worth keeping. As per coding guidelines, don't add comments if avoidable — prefer code that expresses its intent.

♻️ Suggested trim
-    // Each namespace serializes to its id, its schema-kind tag, and the
-    // base's generic entries walk. Native enums are excluded upstream —
-    // carried non-enumerable on `PostgresSchema.entries`, so the walk
-    // never sees them.
+    // Native enums are excluded upstream — carried non-enumerable on
+    // `PostgresSchema.entries`, so the generic walk never sees them.
     for (const [nsId, ns] of Object.entries(storage.namespaces)) {
🤖 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-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts`
around lines 112 - 115, Trim the comment in postgres-contract-serializer’s
namespace serialization logic so it only keeps the non-obvious native-enum
exclusion context; the parts describing id, schema-kind, and entries are already
self-evident from the code. Update the comment near the namespace serialization
walk to remove the redundant explanation and retain only the note about native
enums being excluded upstream and carried non-enumerable on
PostgresSchema.entries.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In
`@packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts`:
- Around line 112-115: Trim the comment in postgres-contract-serializer’s
namespace serialization logic so it only keeps the non-obvious native-enum
exclusion context; the parts describing id, schema-kind, and entries are already
self-evident from the code. Update the comment near the namespace serialization
walk to remove the redundant explanation and retain only the note about native
enums being excluded upstream and carried non-enumerable on
PostgresSchema.entries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ca9fb6d5-baed-483b-bb4e-7d0ee650e183

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2cbac and c781cc3.

📒 Files selected for processing (3)
  • packages/2-sql/9-family/src/core/ir/sql-contract-serializer-base.ts
  • packages/2-sql/9-family/test/namespace-entries-serialization.test.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/2-sql/9-family/test/namespace-entries-serialization.test.ts
  • packages/2-sql/9-family/src/core/ir/sql-contract-serializer-base.ts

@wmadden-electric
wmadden-electric added this pull request to the merge queue Jul 8, 2026
Merged via the queue into main with commit f44cbcb Jul 8, 2026
20 checks passed
@wmadden-electric
wmadden-electric deleted the tml-2981-serialize-the-sql-namespace-entries-dict-generically branch July 8, 2026 14:58
paulwer pushed a commit to paulwer/prisma-next that referenced this pull request Jul 12, 2026
….json (prisma#946)

> **Stacked on prisma#944** (`infer-native-enum-adoption`). Review/merge that
first; this branch rebases onto main once it lands. The net diff below
is against prisma#944's head.

## What this does

A `native_enum` entity used to be **authoring-time-only** — carried
non-enumerable on `PostgresSchema.entries`, so the serializer, the
hashing pipeline, and `contract.json` all walked past it. Only the
*derived* `entries.valueSet` survived. That was Phase 1's "no readers
after emit" assumption, and it has expired twice:

1. **Phase 2 owns DDL for these types** (`CREATE TYPE`/`ADD VALUE`). The
migration planner must derive the expected type — name and *ordered*
members — from the storage segment of `contract.json` alone
(storage-only planning, ADR 004/199). It can't, if the entity isn't
there.
2. **Pack-owned enum subtraction was blind on hydrated contracts.** prisma#944
taught `contract infer` to omit an introspected enum type that a stack
pack already declares — but only when the pack's contract was *in
memory*. In production, `describedContracts` hydrate from
`contract.json`, which carried no enum type names, so the subtraction
silently matched nothing.

After this PR, `entries.native_enum` serializes like `role`/`policy`:

```jsonc
"entries": {
  "native_enum": { "AalLevel": { "kind": "postgres-enum", "typeName": "aal_level", "members": ["aal1", "aal2", "aal3"] } },
  "valueSet":    { "AalLevel": { /* derived, unchanged */ } }
}
```

and a JSON-hydrated Supabase pack contract exposes `aal_level` to the
infer subtraction — closing prisma#944's follow-up the production way.

## The change is a deletion

The entity was excluded from `contract.json` by exactly one thing: a
non-enumerable-property trick in `postgres-schema.ts`. The generic
serializer (TML-2981, prisma#931) already iterates the entries dict; hydration
already composes `nativeEnumEntityKind`. So the fix is **deleting the
carve-out** — the entity then serializes, hydrates, and is captured by
`storageHash` with no serializer or validator edit. Confirmed by reading
the machinery, not assuming it.

**Hash coherence is preserved, inverted.** The carve-out's own comment
said its purpose was keeping `computeStorageHash`'s `JSON.stringify`
walking past the entity, so the hash matched serialized bytes.
Enumerability restores that coherence in the inclusive direction: bytes
and hash now move *together*, and only for enum-bearing contracts. A
storageHash-differ test fails RED under the old carve-out and passes
only after the deletion — the coherence proof can't false-pass.

**`contract.d.ts` type surface is unchanged.** The generic-collapse
review removed raw-slot emission from the `.d.ts`; that stays true. The
only `.d.ts` movement is the `StorageHash` literal (the hash is baked
into the type), and it matches the moved `storageHash` in
`contract.json` byte-for-byte.

## Commits

1. **`native-enums(D1)`** — delete the carve-out; the entity flows
through the generic serialize/hydrate/hash path. Round-trip +
absent-key-tolerance + enum-free-byte-identity tests.
2. **`native-enums(D2)`** — prove the payoff production-shaped: an
infer-entry test builds the Supabase-shaped described contract,
round-trips it through serialize→JSON→hydrate, and asserts `contract
infer` omits the pack-owned `aal_level` while emitting a non-pack-owned
`factor_type` in the same run (selective, not blanket). No change to the
subtraction code — D1 was the whole enabler.
3. **`native-enums(D3)`** — regenerate the artifacts the byte/hash
change touches (Supabase pack `contract.{json,d.ts}`, parity
`expected.contract.json`) via `pnpm fixtures:emit`; drift reviewed to be
exactly `+ entries.native_enum + moved hashes` on enum-bearing
contracts, enum-free artifacts and all example ledgers byte-identical.

## What's out of scope (deliberately)

- **Phase-2 planner/differ/ops.** The entity is now *available* to the
planner from storage; nothing reads it yet. Slice A wires the projection
+ `CREATE TYPE`/`ADD VALUE`.
- **Multi-namespace infer** (TML-2958) and the **CLI schema-selection
limitation** — separate follow-ups; this PR makes the subtraction
*capable* on hydrated contracts, which those will exercise at scale.

## Verification

Full gate run (independently re-run by the coordinator on top of the
implementer's logged runs): `pnpm build`, `pnpm typecheck`, `lint:casts`
(−1), `lint:deps`, `lint:framework-vocabulary` (836/836), `pnpm
fixtures:check` (clean post-regeneration), `pnpm test:packages`, `pnpm
test:integration`, PSL↔TS parity, and the Supabase example suite
(db-verify passes against the regenerated pack). Residual test failures
were the repo's known flake families (PGlite portal-race,
`/var`→`/private/var` macOS symlink, 100ms teardown timeouts), each
passing on isolation rerun — the diff is regeneration-only, so no
failure can be a logic regression.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


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

## Summary by CodeRabbit

- **New Features**
- PostgreSQL native enum definitions are now preserved in contract data
and remain available after serialization and rehydration.
- Contract outputs now include native enum metadata, including names,
members, and database type names.
  - Storage hashes now reflect changes to native enum definitions.

- **Bug Fixes**
- Improved compatibility with contracts that omit native enum
information.
- Preserved correct enum handling when identifying pack-owned and
externally defined enums.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[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