Repository navigation
feat(postgres): native UUID storage type and String/Native uuid preset split - #810
Conversation
Introduces PG_UUID_CODEC_ID, PgUuidCodec, PgUuidDescriptor, and pgUuidColumn to the Postgres target pack. Non-parameterized string passthrough codec with equality+order traits (no textual — Postgres rejects LIKE on uuid without a cast). Registered in codecDescriptors, codec-type-map, and both export surfaces. Unit-tested alongside sibling codecs in codecs.test.ts and codecs-class.test.ts. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…r metadata - psl-column-resolution.ts: db.Uuid spec codecId: null → 'pg/uuid@1' - ids/index.ts: add 'pg/uuid@1' to applicableCodecIds for uuidv4 and uuidv7 - adapter-postgres/descriptor-meta.ts: add PG_UUID_CODEC_ID to controlPlaneHooks (identityHooks) and storage array (nativeType: 'uuid') - Tests: ids applicableCodecIds assertions, PSL @db.Uuid → pg/uuid@1 codecId, uuid()/uuid(7) applicability pass on @db.Uuid columns, nanoid rejection, adapter descriptor-meta identity hooks and storage entry coverage Signed-off-by: Will Madden <[email protected]>
Five integration tests in planner.uuid.integration.test.ts (adapter-postgres) prove SDoD1–SDoD3 end-to-end: - DDL creates a native `uuid`-type column (fails if pg/uuid@1 loses its nativeType binding) - insert + select round-trips a canonical uuid string unchanged (fails if codec detached) - introspect + verifySchema confirms schema matches the pg/uuid@1 contract (fails if storage descriptor entry removed) - native uuid column accepts a v4-format uuid string (confirms format compatibility) - native uuid column accepts gen_random_uuid() as an expression (fails if column type is text) Also regenerates the four supabase fixture files (examples/supabase and packages/3-extensions/supabase) whose @db.Uuid columns now emit codecId: "pg/uuid@1" instead of "pg/text@1". No other fixture churn. Co-Authored-By: Will Madden <[email protected]> Signed-off-by: Will Madden <[email protected]>
Signed-off-by: Will Madden <[email protected]>
📝 WalkthroughWalkthroughAdds native Postgres UUID codec ChangesPostgreSQL Native UUID Codec Support
Sequence Diagram(s)sequenceDiagram
participant SchemaAuthor as Schema Author
participant PSLResolver as PSL Resolver
participant CodecRegistry as Codec Registry
participant PostgresTarget as Postgres Target
participant Database as Postgres Database
SchemaAuthor->>PSLResolver: define `@db.Uuid` field or use `uuidNative` preset
PSLResolver->>CodecRegistry: resolve codec `pg/uuid@1`
CodecRegistry->>PSLResolver: return PgUuidDescriptor
PSLResolver->>PostgresTarget: emit DDL using native `uuid` type
PostgresTarget->>Database: CREATE TABLE with uuid column
SchemaAuthor->>Database: insert UUID string / use DEFAULT gen_random_uuid()
Database->>SchemaAuthor: store and return uuid as expected
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
…nd ids Family presets renamed: uuid → uuidString, id.uuidv4 → id.uuidv4String, id.uuidv7 → id.uuidv7String. Outputs unchanged (sql/char@1, char(36), same generators). Postgres target gains uuidNative (pg/uuid@1, nativeType uuid) and id.uuidv4Native / id.uuidv7Native (same codec, uuidv4/uuidv7 onCreate generator, id: true). Tests: preset-key assertions for both packages; namespace merge proof (family id.*String + target id.*Native compose without collision); emit-then-consume tests verifying pg/uuid@1 codec and generator in JSON output. Signed-off-by: Will Madden <[email protected]>
… names Move every field.uuid()/field.id.uuidv4()/field.id.uuidv7() call site in examples, CLI templates, tests, and docs to the renamed surface introduced in D4: field.uuidString(), field.id.uuidv4String(), field.id.uuidv7String(). Also renames the hand-rolled family pack in contract-ts tests to match the new preset keys (uuidString / id.uuidv4String / id.uuidv7String), regenerates the CLI snapshot via vitest -u, and updates docs/READMEs/ADRs to reflect the new names and the native preset additions (uuidNative/uuidv4Native/uuidv7Native on Postgres). The rename is byte-identical: pnpm fixtures:check shows zero contract.json churn. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…missed project file mergeAuthoringNamespaces mutated source pack objects when merging sub-namespaces for the first time. assembleAuthoringContributions (called during createControlStack) would assign the family pack's id sub-namespace directly into the accumulator, then subsequent merges from the target pack would mutate that same object. Any later call to createComposedAuthoringHelpers (e.g. when defineContract runs during typescriptContractFromPath.load) would then see duplicated keys in the already-mutated family pack object, throwing "Duplicate authoring field helper". Fix: copy sub-namespace objects on first assignment rather than assigning the reference. Also sweeps projects/supabase-integration/example to rename field.id.uuidv4() → field.id.uuidv4String() and field.uuid() → field.uuidString(), which was missed in the prior D5 sweep commit. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
Adds uuid-preset-rename entries to both upgrade skill clusters: - skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/ - skills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/ Each entry includes a colocated uuid-preset-rename.ts script that renames field.uuid() → field.uuidString(), field.id.uuidv4() → field.id.uuidv4String(), and field.id.uuidv7() → field.id.uuidv7String() across TypeScript files in the consumer's project. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…immutability Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
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/1-framework/1-core/framework-components/src/shared/framework-authoring.ts`:
- Around line 379-386: The current assignment in framework-authoring.ts uses a
shallow spread ({ ...sourceValue }) for namespace copying which still shares
deeper nested objects and allows subsequent mutations; change this to perform a
deep clone of namespace objects when isPlainNamespaceObject(sourceValue) &&
!leafGuard(sourceValue) so no nested references remain. Implement or call a
deepCloneNamespace helper (or use structuredClone if available) that recursively
clones plain namespace objects while preserving leaves (respect leafGuard), and
replace the shallow spread in the target[key] assignment with that deep clone.
🪄 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: fa375888-ad2f-41b5-a603-c969c104cac4
⛔ Files ignored due to path filters (2)
packages/1-framework/3-tooling/cli/test/commands/init/__snapshots__/templates.test.ts.snapis excluded by!**/*.snapprojects/supabase-integration/example/src/prisma/contract.tsis excluded by!projects/**
📒 Files selected for processing (34)
docs/architecture docs/adrs/ADR 170 - Pack-provided type constructors and field presets.mddocs/architecture docs/adrs/ADR 181 - Contract authoring DSL for SQL TS authoring.mddocs/architecture docs/subsystems/6. Ecosystem Extensions & Packs.mdexamples/bundle-size/src/postgres/contract.tsexamples/prisma-next-demo-sqlite/prisma/contract.tsexamples/prisma-next-demo/prisma/contract.tsexamples/prisma-next-demo/test/no-emit-typed-flow.test-d.tsexamples/react-router-demo/src/prisma/contract.tspackages/1-framework/1-core/framework-components/src/shared/framework-authoring.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/1-framework/3-tooling/cli/src/commands/init/templates/code-templates.tspackages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.tspackages/2-sql/2-authoring/contract-ts/API.mdpackages/2-sql/2-authoring/contract-ts/README.mdpackages/2-sql/2-authoring/contract-ts/test/authoring-uuid-native-presets.test.tspackages/2-sql/2-authoring/contract-ts/test/contract-builder.dsl.helpers.test.tspackages/2-sql/9-family/src/core/authoring-field-presets.tspackages/2-sql/9-family/test/authoring-field-presets.test.tspackages/3-extensions/arktype-json/README.mdpackages/3-extensions/postgres/README.mdpackages/3-extensions/postgres/test/contract-builder/define-contract.test-d.tspackages/3-extensions/postgres/test/contract-builder/define-contract.test.tspackages/3-extensions/postgres/test/contract-builder/enum-int-read-surface.test-d.tspackages/3-extensions/sqlite/README.mdpackages/3-extensions/sqlite/test/contract-builder/define-contract.test-d.tspackages/3-extensions/sqlite/test/contract-builder/define-contract.test.tspackages/3-targets/3-targets/postgres/src/core/authoring.tspackages/3-targets/3-targets/postgres/test/authoring-field-presets.test.tsskills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/instructions.mdskills/extension-author/prisma-next-extension-upgrade/upgrades/0.13-to-0.14/uuid-preset-rename.tsskills/prisma-next-contract/SKILL.mdskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.mdskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/uuid-preset-rename.tstest/integration/test/contract-builder.types.test-d.ts
✅ Files skipped from review due to trivial changes (10)
- packages/3-targets/3-targets/postgres/test/authoring-field-presets.test.ts
- packages/3-extensions/postgres/README.md
- packages/3-extensions/arktype-json/README.md
- skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/uuid-preset-rename.ts
- docs/architecture docs/subsystems/6. Ecosystem Extensions & Packs.md
- docs/architecture docs/adrs/ADR 170 - Pack-provided type constructors and field presets.md
- skills/prisma-next-contract/SKILL.md
- packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
- examples/prisma-next-demo/test/no-emit-typed-flow.test-d.ts
- packages/2-sql/2-authoring/contract-ts/README.md
Change Profile.id from String to the Uuid named type so the primary key uses the native pg/uuid@1 codec (DDL: uuid) instead of char(36). The uuidv4 onCreate generator remains, proving generator-on-native-uuid end-to-end. This required a fix in psl-field-resolution.ts: when a field is typed via a named type (e.g. `Uuid = String @db.Uuid`), the PSL interpreter was overwriting the resolved native-type descriptor with the generator's default descriptor (char(36)). The fix skips resolveGeneratedColumnDescriptor when the field already carries an explicit native type from a named type declaration. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
…amedType Signed-off-by: Will Madden <[email protected]>
…ere-d1e45f Signed-off-by: Will Madden <[email protected]> # Conflicts: # packages/1-framework/1-core/framework-components/test/control-stack.test.ts
… authoring merge
isPlainNamespaceObject matched any non-null non-array object, so
mergeAuthoringNamespaces would shallow-copy class instances used as
sub-namespace containers ({...instance}), stripping the prototype and
silencing any getter defined on it. The fix limits the plain-object
check to objects whose prototype is Object.prototype or null; class
instances fall through to the by-reference assignment path instead.
The three immutability regression tests from 6308e3c remain green:
only plain-object sub-namespaces are shallow-copied; class instances
are passed by reference as before, so source packs are not mutated.
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ristine main Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/1-framework/1-core/framework-components/test/control-stack.test.ts (1)
579-591: ⚡ Quick winRemove duplicate test.
This test duplicates the coverage already provided by the test at lines 351-363 ("rejects a pslBlockDescriptors contribution with no matching entityTypes factory"). Both tests verify that a pslBlockDescriptors entry without a matching entityTypes factory throws an error; the only difference is the discriminator string value ('no-factory-discriminator' vs 'fake-foo'), which doesn't exercise a different code path.
🤖 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/1-framework/1-core/framework-components/test/control-stack.test.ts` around lines 579 - 591, Remove the duplicate test that asserts a pslBlockDescriptors entry without a matching entityTypes factory throws; specifically delete the "it('rejects a pslBlockDescriptors entry with no matching entityTypes factory', ...)" test case which calls assembleAuthoringContributions with createDescriptor and makeDeclarativePslBlockDescriptor, leaving the original test ("rejects a pslBlockDescriptors contribution with no matching entityTypes factory") in place so coverage is unchanged.
🤖 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/1-framework/1-core/framework-components/test/control-stack.test.ts`:
- Around line 579-591: Remove the duplicate test that asserts a
pslBlockDescriptors entry without a matching entityTypes factory throws;
specifically delete the "it('rejects a pslBlockDescriptors entry with no
matching entityTypes factory', ...)" test case which calls
assembleAuthoringContributions with createDescriptor and
makeDeclarativePslBlockDescriptor, leaving the original test ("rejects a
pslBlockDescriptors contribution with no matching entityTypes factory") in place
so coverage is unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: f57f3e17-0d0c-4dc1-9155-ee73401542d3
📒 Files selected for processing (10)
drive/calibration/failure-modes.mdexamples/supabase/src/contract.d.tsexamples/supabase/src/contract.jsonexamples/supabase/src/contract.prismapackages/1-framework/1-core/framework-components/src/shared/framework-authoring.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.tspackages/2-sql/2-authoring/contract-psl/test/fixtures.tspackages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.tsskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
✅ Files skipped from review due to trivial changes (2)
- skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
- examples/supabase/src/contract.json
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts
- packages/2-sql/2-authoring/contract-psl/test/fixtures.ts
- packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
wmadden
left a comment
There was a problem hiding this comment.
A couple of small comments
|
A03a (shallow copy in mergeAuthoringNamespaces): Valid finding — on it. The shallow spread at line 423 only protects one level; nested sub-namespace objects still reference the source pack's originals. Will switch to |
|
A04 (duplicate test in control-stack.test.ts): Good catch — the test at lines 579-591 ("rejects a pslBlockDescriptors entry with no matching entityTypes factory") duplicates the one at line 351. Will remove it. |
… assignment; clarify merge helper names
- Rename `isPlainNamespaceObject` → `isCopyableNamespaceObject` to make the
purpose clear at call sites (A01).
- Rename `leafGuard` parameter → `isLeafDescriptor` throughout
`mergeAuthoringNamespaces` (A02).
- Replace the shallow-spread `{ ...sourceValue }` with `deepCopyNamespace`, which
recurses into plain-object sub-namespaces while passing leaves and class
instances by reference. Fixes mutation of nested sub-namespace objects owned by
source packs when a later pack merges into the same nested path (A03a).
- Add a depth-3 test: pack A owns `field.a.b.alpha`, pack B adds `field.a.b.beta`;
composing the same pack descriptors twice must not throw and must not mutate pack
A's original data structure.
- Remove duplicate `rejects a pslBlockDescriptors entry with no matching entityTypes
factory` test at lines 579-591 (superseded by the identical test at line 351) (A04).
Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
|
Done (A03a). Replaced the shallow spread |
|
Done (A04). Verified and removed the duplicate test at lines 579-591. Both tests checked the same code path (pslBlock with no matching entityType factory) — same assertion, same pattern, only different discriminator strings. The test at line 351 ( |
…ere-d1e45f Signed-off-by: Will Madden <[email protected]> # Conflicts: # examples/prisma-next-demo/prisma/contract.ts
…ast in PgUuidCodec.decodeJson Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Will Madden <[email protected]>
There was a problem hiding this comment.
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/1-framework/1-core/framework-components/src/shared/framework-authoring.ts`:
- Around line 375-387: deepCopyNamespace is recursing into nested objects
without enforcing the blocked-segment guard, allowing unsafe keys like
"__proto__" to slip in; fix by validating each property key with the existing
path-safety check (e.g., call assertSafePath(key) or the equivalent
blocked-segment guard) before assigning or recursing, and ensure the same change
is also applied to the other copy routine referenced (the second occurrence
around the other deep-copy function), so that both the branch that recurses
(isCopyableNamespaceObject(...) && !isLeafDescriptor(...)) and the branch that
assigns values first validate the key.
🪄 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: 438c720d-d590-4f2b-ba70-5bc0e95e3736
📒 Files selected for processing (6)
examples/prisma-next-demo/prisma/contract.tspackages/1-framework/1-core/framework-components/src/shared/framework-authoring.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.tspackages/3-targets/3-targets/postgres/src/core/codecs.tsskills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
✅ Files skipped from review due to trivial changes (1)
- skills/upgrade/prisma-next-upgrade/upgrades/0.13-to-0.14/instructions.md
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/3-targets/3-targets/postgres/src/core/codecs.ts
- packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
- examples/prisma-next-demo/prisma/contract.ts
| function deepCopyNamespace( | ||
| source: Record<string, unknown>, | ||
| isLeafDescriptor: (value: unknown) => boolean, | ||
| ): Record<string, unknown> { | ||
| const copy: Record<string, unknown> = {}; | ||
| for (const [key, value] of Object.entries(source)) { | ||
| copy[key] = | ||
| isCopyableNamespaceObject(value) && !isLeafDescriptor(value) | ||
| ? deepCopyNamespace(value, isLeafDescriptor) | ||
| : value; | ||
| } | ||
| return copy; | ||
| } |
There was a problem hiding this comment.
Nested blocked-path validation is bypassed during deep copy.
deepCopyNamespace recurses nested keys without applying the blocked-segment guard. So keys like __proto__ can slip in when a subtree is first assigned, bypassing assertSafePath and potentially mutating copied-object prototypes.
Suggested fix
-function deepCopyNamespace(
- source: Record<string, unknown>,
- isLeafDescriptor: (value: unknown) => boolean,
-): Record<string, unknown> {
+function deepCopyNamespace(
+ source: Record<string, unknown>,
+ isLeafDescriptor: (value: unknown) => boolean,
+ path: readonly string[],
+ label: string,
+): Record<string, unknown> {
const copy: Record<string, unknown> = {};
for (const [key, value] of Object.entries(source)) {
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
+ throw new Error(
+ `Invalid authoring ${label} helper "${[...path, key].join('.')}". Helper path segments must not use "${key}".`,
+ );
+ }
+ const currentPath = [...path, key];
copy[key] =
isCopyableNamespaceObject(value) && !isLeafDescriptor(value)
- ? deepCopyNamespace(value, isLeafDescriptor)
+ ? deepCopyNamespace(value, isLeafDescriptor, currentPath, label)
: value;
}
return copy;
}
@@
target[key] =
isCopyableNamespaceObject(sourceValue) && !isLeafDescriptor(sourceValue)
- ? deepCopyNamespace(sourceValue, isLeafDescriptor)
+ ? deepCopyNamespace(sourceValue, isLeafDescriptor, currentPath, label)
: sourceValue;Also applies to: 431-439
🤖 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/1-framework/1-core/framework-components/src/shared/framework-authoring.ts`
around lines 375 - 387, deepCopyNamespace is recursing into nested objects
without enforcing the blocked-segment guard, allowing unsafe keys like
"__proto__" to slip in; fix by validating each property key with the existing
path-safety check (e.g., call assertSafePath(key) or the equivalent
blocked-segment guard) before assigning or recursing, and ensure the same change
is also applied to the other copy routine referenced (the second occurrence
around the other deep-copy function), so that both the branch that recurses
(isCopyableNamespaceObject(...) && !isLeafDescriptor(...)) and the branch that
assigns values first validate the key.
entries.table is typed as optional (open dictionary intersection) after the ADR 224 changes; two test lines from the upstream uuid presets PR (#810) accessed it without ?. chaining, producing TS2532. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Gives Postgres a real native UUID storage type, and makes the uuid authoring surface unambiguous about what it stores.
Until now, PSL
String @db.UuidsetnativeType: 'uuid'but carriedcodecId: null, silently inheriting the text codec — DDL rendered auuidcolumn while the contract claimed text. Separately, the TS helpersfield.uuid()/field.id.uuidv4()read like native uuid but actually storecharacter(36)(they're shared with SQLite, which has no uuid type). This PR fixes the first by introducingpg/uuid@1end-to-end, and the second by renaming the helpers so storage is explicit.Changes
@prisma-next/target-postgres, Adapters layer): new non-parameterizedpg/uuid@1codec —PgUuidCodec/PgUuidDescriptor/pgUuidColumn, registered incodecDescriptors, the codec type map, and the export surfaces. String passthrough on the wire; traits areequality+orderonly, deliberately nottextual(Postgres rejectsLIKEonuuidwithout a cast).@prisma-next/sql-contract-psl, Authoring layer):NATIVE_TYPE_SPECS['db.Uuid']now resolves topg/uuid@1instead of inheriting the String codec.@db.*attributes live on named types (types { UuidId = String @db.Uuid }), as before.@prisma-next/ids, Authoring layer):uuidv4/uuidv7gainedpg/uuid@1inapplicableCodecIds, so@default(uuid())/@default(uuid(7))are valid on native-uuid columns. Other generators still reject uuid columns (their output is not a uuid literal).@prisma-next/adapter-postgres, Adapters layer): control-plane metadata forpg/uuid@1(identityHooks+ storage entry), which lets DDL renderuuidand introspection resolve a liveuuidcolumn back to the codec.field.uuid()→field.uuidString(),field.id.uuidv4()→field.id.uuidv4String(),field.id.uuidv7()→field.id.uuidv7String()(samecharacter(36)storage, cross-target). The Postgres pack now contributesfield.uuidNative(),field.id.uuidv4Native(),field.id.uuidv7Native()with nativeuuidstorage; on SQLite these don't exist, so using them is an immediate composition error rather than a silent fallback. Unsuffixed names are removed — no compat aliases. All call sites (examples, CLI init templates, docs, ADRs 170/181, READMEs) are swept; the renames are semantics-preserving, proven by zerocontract.jsonchurn infixtures:check.skills/upgrade/.../0.13-to-0.14/andskills/extension-author/.../0.13-to-0.14/with a codemod for the three renames.@prisma-next/framework-components, Core layer):mergeAuthoringNamespacesgrafted later packs' helpers onto the first pack's sub-namespace object by reference, so composing the same pack singletons twice in one process threw a spurious "Duplicate authoring field helper". Latent until the postgres pack started contributingfield.id.*Nativealongside the family'sfield.id.*String; now merges copy sub-namespaces on first assignment, with a regression test pinning source-pack immutability and duplicate detection.Profile.idbecomesid Uuid @id @default(uuid())— a nativeuuidprimary key with the client-side uuidv4 generator, alongside the already-nativeuserIdFK to Supabase auth. This exposed and fixed a latent PSL bug: the generator-default path unconditionally replaced a field's resolved descriptor with the generator'schar(36)fallback, clobbering named-type native descriptors; the fallback now applies only when the field has no named type (which is what the design always intended).mergeAuthoringNamespaces): the source-pack-immutability fix above initially shallow-copied any object sub-namespace, which dropped prototype getters off class-instance descriptors (surfaced by TML-2882's enum2 blocks after merging main: 11/14 enum2 tests red). The copy now applies to plain-prototype objects only; class instances pass by reference. Regression tests pin both guarantees.pg/text@1→pg/uuid@1codecId flip on their@db.Uuidcolumns (+storageHash). That and the CLI template snapshot are the entire regen diff.Why
The codec is the unit of target-type identity in this architecture (codec-owned storage hooks, not shared-IR enums), so native UUID support is a new codec plus wiring — zero changes to shared IR, the emitter, or DDL rendering, which are generic over descriptor metadata.
The rename (rather than changing
field.uuid()'s meaning per target) keeps every existing column type stable: migrating is a mechanical find/replace, not a schema migration. The String/Native suffix pair also keeps foreign-key typing honest — achar(36)id pairs withuuidString()FKs, a native id withuuidNative()FKs.Verification
packages/3-targets/6-adapters/postgres/test/migrations/planner.uuid.integration.test.ts(PGlite): DDL producesudt_name = 'uuid'; insert/select round-trips; introspection +verifySchemareconcile the live column withpg/uuid@1; v4-format andgen_random_uuid()values accepted.@db.Uuid→pg/uuid@1;uuid()/uuid(7)applicability positive; nanoid-on-uuid pins thePSL_INVALID_DEFAULT_APPLICABILITYdiagnostic.field.uuidNative()/field.id.uuidv4Native()emitpg/uuid@1+nativeType: 'uuid'+ the uuidv4 generator in contract JSON.pnpm typecheckgreen (138 tasks),pnpm lint:depsclean,pnpm fixtures:checkexit 0, grep gate shows no surviving old preset names outside the upgrade-instruction artifacts (which carry them by design as codemod find-patterns). Pre-existing test failures in target-postgres / contract-psl suites (class-instance vs plain-object drift) were verified pre-existing on the merge base during review.Follow-ups (not in this PR)
@default(uuid())on a native-uuid column (the halves are each covered separately today).uuidString()ids; adoptinguuidNative()in the Postgres demo is a separate, DDL-changing decision.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Docs