Repository navigation
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces parameterized renderer plumbing with codec-dispatched output-type rendering: adds Changes
Sequence Diagram(s)sequenceDiagram
participant Emitter as Emitter
participant Control as ControlStack
participant CodecLookup as CodecLookup
participant Codec as Codec
participant Generator as ContractGenerator
Emitter->>Control: build stack (include codecInstances)
Control->>CodecLookup: extractCodecLookup(descriptors)
Emitter->>Generator: generateContractDts(contract, options, codecLookup)
Generator->>CodecLookup: for each model.field -> lookup.get(codecId)?
alt codec provides renderOutputType
CodecLookup->>Codec: renderOutputType(typeParams)
Codec-->>Generator: renderedType (if isSafeTypeExpression)
else fallback
Generator-->>Generator: use CodecTypes[codecId]['output'] or fallback
end
Generator-->>Emitter: emit contract.d.ts (includes FieldOutputTypes)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@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/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
@prisma-next/vite-plugin-contract-emit
@prisma-next/runtime-executor
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-emitter
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-pipeline-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/adapter-postgres
@prisma-next/driver-postgres
commit: |
8bfdf3e to
9ed377f
Compare
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts (1)
296-298:⚠️ Potential issue | 🟠 MajorThread
codecLookupthrough value object type generation to support codec-rendered output types.Value object fields can have scalar types with
typeParams, butgenerateValueObjectTypeAliasesdoesn't accept or forwardcodecLookuptogenerateFieldResolvedType. This means value object fields with parameterized codecs (e.g.,pg/char@1withlength: 36) won't get codec-rendered output types, unlike model fields which do viagenerateFieldOutputTypesMap.Update the signature chain:
generateValueObjectTypeAliases(codecLookup?)→generateValueObjectType(codecLookup?)→generateFieldResolvedType(field, codecLookup). Also passcodecLookupat the call site ingenerate-contract-dts.tsline 63.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts` around lines 296 - 298, The value-object type generation chain must thread the optional codecLookup so codec-rendered output types are used for parameterized codecs: change the signature of generateValueObjectTypeAliases to accept codecLookup?, update generateValueObjectType to accept and forward codecLookup, and modify calls to generateFieldResolvedType(field, codecLookup) inside generateValueObjectType (currently where fieldEntries are built). Also update the caller that invokes generateValueObjectTypeAliases (the generate-contract-dts invocation) to pass through its codecLookup argument so the whole chain gets the codecLookup.
♻️ Duplicate comments (1)
packages/3-targets/6-adapters/postgres/src/core/codecs.ts (1)
520-528:⚠️ Potential issue | 🟡 MinorIncomplete string escaping for enum values.
The enum
renderOutputTypeonly escapes single quotes but not backslash characters. If an enum value contains a backslash (e.g.,'path\\to'), it will produce invalid TypeScript output.🔧 Proposed fix to escape backslashes before single quotes
renderOutputType: (typeParams) => { const values = typeParams['values']; if (!Array.isArray(values)) { throw new Error( `renderOutputType: expected array "values" in typeParams for enum, got ${typeof values}`, ); } - return values.map((value) => `'${String(value).replace(/'/g, "\\'")}'`).join(' | '); + return values.map((value) => `'${String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`).join(' | '); },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/3-targets/6-adapters/postgres/src/core/codecs.ts` around lines 520 - 528, renderOutputType currently only escapes single quotes, so values containing backslashes produce invalid TypeScript; update renderOutputType (the function at the top-level renderOutputType entry) to first escape backslashes in each value (replace '\' with '\\') and then escape single quotes before wrapping in single quotes, ensuring you operate on String(value) and preserve the existing join(' | ') output format.
🧹 Nitpick comments (7)
docs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.md (1)
154-166: Move step-by-step emitter dispatch mechanics out of the ADR body.Lines 154-166 read like implementation algorithm/procedure. Keep ADR content focused on decision + invariants, and move execution mechanics to subsystem/spec docs to reduce drift.
Based on learnings: “ADRs in prisma/prisma-next should document architectural design decisions and the key constraints/assumptions only. Do not include implementation algorithms, emitter derivation logic, or step-by-step derivation/migration rules.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/architecture` docs/adrs/ADR 186 - Codec-dispatched type rendering.md around lines 154 - 166, The ADR currently contains implementation steps (the emitter dispatch algorithm) that should be removed from the ADR body and relocated to a subsystem/spec document; remove the numbered steps describing generateFieldResolvedType behavior, CodecLookup usage, codec.renderOutputType fallback to CodecTypes[codecId]['output'], stamping to FieldOutputTypes, and the typeParams serialization from the ADR text, keep only the high-level decision and invariants (that `@prisma-next/emitter` will dispatch to codecs via a core-provided lookup), and move the detailed procedural mechanics and any references to TypeRenderer, parameterizedRenderers, normalization pipeline, and parameterized maps into a new or existing emitter implementation spec under the tooling layer.packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts (1)
1-3: Consider additional unsafe patterns for defense-in-depth.The current regex catches common code injection vectors, but misses some patterns that could also be problematic in emitted
.d.tsfiles:
Function(constructornew Function(- Semicolons that could end a type and start a statement
Since codec authors are trusted and this is a secondary safeguard, this may be acceptable. However, for more complete coverage:
♻️ Optionally expand the pattern
export function isSafeTypeExpression(expr: string): boolean { - return !/import\s*\(|require\s*\(|declare\s|export\s|eval\s*\(/.test(expr); + return !/import\s*\(|require\s*\(|declare\s|export\s|eval\s*\(|Function\s*\(|;\s*\w/.test(expr); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts` around lines 1 - 3, Update isSafeTypeExpression to broaden the unsafe-pattern check: add detection for Function( constructor forms (both "Function(" and "new Function(") and for stray semicolons that could terminate a type and start a statement; modify the regex used inside isSafeTypeExpression (or add a second test) to include patterns like Function\s*\(, new\s+Function\s*\(, and a semicolon check (e.g., presence of ';' or ';\s*[\r\n]') so the function returns false for these cases as well.packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts (1)
67-74: Prefer the canonicalTypeMapsType<...>helper in this fixture.This alias is duplicating the public
TypeMapsshape by hand, so it can fall behind the realcontract.d.tssurface again on the next change. Switching it toTypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes>and importingTypeMaps as TypeMapsTypefrom@prisma-next/sql-contract/typeswould keep the fixture coupled to the actual API.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts` around lines 67 - 74, Replace the hand‑written TypeMaps alias with the canonical helper: import TypeMaps as TypeMapsType from "@prisma-next/sql-contract/types" and change the exported type named TypeMaps to use TypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes> so the fixture stays in sync; keep FieldOutputTypes, CodecTypes and OperationTypes names as the type args to locate the substitution easily.packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts (1)
81-88: Prefer the canonicalTypeMapsType<...>helper in this fixture.Hand-rolling
TypeMapshere makes the fixture drift-prone; the newfieldOutputTypesslot is exactly the kind of surface change that's easy to miss. Switching this alias toTypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes>and importingTypeMaps as TypeMapsTypefrom@prisma-next/sql-contract/typeswill keep the fixture aligned with the real emitted API.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts` around lines 81 - 88, Replace the hand-crafted TypeMaps alias with the canonical helper: import TypeMaps as TypeMapsType from "@prisma-next/sql-contract/types" and change the exported alias to use TypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes> (keep the CodecTypes, OperationTypes and FieldOutputTypes symbols as-is); this ensures the fixture uses the same TypeMapsType helper and won't drift when fields like fieldOutputTypes change.packages/1-framework/3-tooling/emitter/test/emitter.test.ts (1)
319-338: Consider updating test name to match narrowed scope.The test name still references
parameterizedTypeImportsbut only validatesqueryOperationTypeImports. Consider renaming for clarity.📝 Suggested rename
- it('passes parameterizedTypeImports and queryOperationTypeImports to generateContractDts', async () => { + it('passes queryOperationTypeImports to generateContractDts', async () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/test/emitter.test.ts` around lines 319 - 338, The test name refers to parameterizedTypeImports but the test only asserts behavior for queryOperationTypeImports; rename the test case title in the it(...) call to reflect the actual scope (e.g., "passes queryOperationTypeImports to generateContractDts") so it matches the validated symbol queryOperationTypeImports and the assertion on result.contractDts produced by emit; update the string in the it() declaration near the existing test that constructs options and calls emit to keep names consistent.packages/1-framework/1-core/framework-components/src/control-stack.ts (1)
253-253: Consider importingCodectype at the top of the file.The inline
import('./codec-types').Codecworks but is less conventional than addingCodecto the existing import statement.🔧 Suggested improvement
-import type { CodecLookup } from './codec-types'; +import type { Codec, CodecLookup } from './codec-types';Then on line 253:
- const byId = new Map<string, import('./codec-types').Codec>(); + const byId = new Map<string, Codec>();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/1-core/framework-components/src/control-stack.ts` at line 253, Replace the inline type import on the byId declaration with a top-level type import: add Codec to the file's existing import statement(s) and then change the declaration const byId = new Map<string, import('./codec-types').Codec>(); to use the imported Codec type (i.e., new Map<string, Codec>()), referencing the byId variable in control-stack.ts so the file uses a conventional top-level type import instead of inline import('./codec-types').Codec.packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts (1)
266-288: Unnecessary defensive check on line 276.
Object.entries(models)will never yieldundefinedas a value for existing entries. Theif (!model) continue;check is unreachable dead code.🔧 Remove unnecessary check
for (const [modelName, model] of Object.entries(models).sort(([a], [b]) => a.localeCompare(b))) { - if (!model) continue; const fieldEntries: string[] = [];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts` around lines 266 - 288, In generateFieldOutputTypesMap remove the unreachable defensive check by deleting the "if (!model) continue;" line inside the loop over Object.entries(models) so the loop simply processes each [modelName, model] pair; ensure any references to model later in that loop remain unchanged (e.g., the inner loop over model.fields and creation of fieldEntries and fieldsType).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/architecture` docs/ADR-INDEX.md:
- Line 62: Update the ADR-INDEX entry for ADR 186 to replace the outdated
symbols `renderTypeParams` and `parameterizedOutput` with the current
terminology `renderOutputType` and `FieldOutputTypes`, and remove the reference
to `EmissionSpi.generateModelsType?`/legacy renderer infrastructure so the
summary matches ADR 186's contents about codec-driven output type rendering;
edit the line that currently contains "Codec-dispatched type rendering | Codecs
own TypeScript type rendering via `renderTypeParams` and `parameterizedOutput`"
to instead mention `renderOutputType` and `FieldOutputTypes` and reflect the
removal of the legacy override.
In `@docs/architecture` docs/adrs/ADR 186 - Codec-dispatched type rendering.md:
- Line 233: Update the reference link text "[Design spec: Codec-dispatched type
rendering]" so it does not point into the transient projects/ tree; remove the
"projects/" segment from the target URL in ADR 186 and point the link at the
stable durable docs/spec location (i.e., change
"../../../projects/orm-consolidation/specs/codec-dispatched-type-rendering.md"
to the equivalent path without "projects/"), ensuring the link in the ADR file
now references the permanent spec location.
In `@packages/2-sql/2-authoring/contract-ts/src/staged-contract-types.ts`:
- Around line 480-504: StagedFieldOutputType currently only indexes
CodecTypesFromStagedDefinition by codecId and therefore ignores per-field
descriptor resolution (typeRef/typeParams), causing different parameterized
fields that share a codecId to collapse; update StagedFieldOutputType to extract
the full column descriptor from StagedModelStorageColumn (e.g., infer Col
extends { readonly codecId: infer Id; readonly typeRef?: infer TR; readonly
typeParams?: infer TP }) and then use those descriptor pieces to look up the
resolved codec output (create or reuse a utility lookup type like
ResolveCodecOutput<CodecTypesFromStagedDefinition, Id, TR, TP>) so the final
branch returns the codec’s output for the resolved typeRef/typeParams (and still
respects Col.readonly nullable) before falling back to unknown; apply the same
resolution logic to StagedFieldOutputTypes/SqlContractResult exports so
parameterized codecs no longer collapse.
In `@packages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.ts`:
- Around line 46-54: The current renderOutputType for Char (and the similar
Varchar renderer) throws when typeParams.length is absent, but expandLength
treats a missing length as valid; change renderOutputType in the Char and
Varchar codec renderers so they return undefined when typeParams['length'] is
undefined (allowing fallback to CodecTypes[codecId].output), and only throw if
length is present but not a number; keep the existing formatted return
`Char<${length}>` / `Varchar<${length}>` when a numeric length is provided.
In `@packages/2-sql/4-lanes/relational-core/test/schema.types.test-d.ts`:
- Around line 360-365: The mapped output type for fieldOutputTypes currently
mirrors the codec fallback (Embedding.vectorData as number[]), so change the
mapped type to a distinct type (e.g., Float32Array or ReadonlyArray<number> or
string[]) so the test actually verifies the resolved-field mapping path rather
than restating the codec output; locate the fieldOutputTypes object and update
Embedding.vectorData to the new distinct type and adjust any downstream
assertions to expect that new mapped type instead of number[] (references:
fieldOutputTypes, Embedding.vectorData, CodecTypes['pg/vector@1']['output']).
In `@packages/3-extensions/pgvector/src/core/codecs.ts`:
- Around line 14-22: renderOutputType currently accepts any JS number for
typeParams['length'], including NaN/Infinity/non-integers; tighten validation in
renderOutputType by checking that length is a finite integer (use
Number.isFinite and Number.isInteger) and that it is positive (e.g., > 0) before
returning `Vector<${length}>`, otherwise throw an Error with a clear message
referencing length and typeParams.
In
`@packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts`:
- Around line 23-43: GeneratedLikeFieldOutputTypes currently mirrors codec
output exactly; change it so its field types are observably different from the
codec-derived types (e.g., wrap one or more fields in a distinct shape or
branded type) so tests will fail if the fieldOutputTypes generic is dropped;
update the GeneratedLikeFieldOutputTypes declaration (referencing
GeneratedLikeFieldOutputTypes and GeneratedLikeTypeMaps/TypeMaps and
GeneratedLikeCodecTypes) to use those distinct output shapes for at least one
field per model, and adjust any test assertions expecting the new
wrapped/branded shapes.
---
Outside diff comments:
In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts`:
- Around line 296-298: The value-object type generation chain must thread the
optional codecLookup so codec-rendered output types are used for parameterized
codecs: change the signature of generateValueObjectTypeAliases to accept
codecLookup?, update generateValueObjectType to accept and forward codecLookup,
and modify calls to generateFieldResolvedType(field, codecLookup) inside
generateValueObjectType (currently where fieldEntries are built). Also update
the caller that invokes generateValueObjectTypeAliases (the
generate-contract-dts invocation) to pass through its codecLookup argument so
the whole chain gets the codecLookup.
---
Duplicate comments:
In `@packages/3-targets/6-adapters/postgres/src/core/codecs.ts`:
- Around line 520-528: renderOutputType currently only escapes single quotes, so
values containing backslashes produce invalid TypeScript; update
renderOutputType (the function at the top-level renderOutputType entry) to first
escape backslashes in each value (replace '\' with '\\') and then escape single
quotes before wrapping in single quotes, ensuring you operate on String(value)
and preserve the existing join(' | ') output format.
---
Nitpick comments:
In `@docs/architecture` docs/adrs/ADR 186 - Codec-dispatched type rendering.md:
- Around line 154-166: The ADR currently contains implementation steps (the
emitter dispatch algorithm) that should be removed from the ADR body and
relocated to a subsystem/spec document; remove the numbered steps describing
generateFieldResolvedType behavior, CodecLookup usage, codec.renderOutputType
fallback to CodecTypes[codecId]['output'], stamping to FieldOutputTypes, and the
typeParams serialization from the ADR text, keep only the high-level decision
and invariants (that `@prisma-next/emitter` will dispatch to codecs via a
core-provided lookup), and move the detailed procedural mechanics and any
references to TypeRenderer, parameterizedRenderers, normalization pipeline, and
parameterized maps into a new or existing emitter implementation spec under the
tooling layer.
In `@packages/1-framework/1-core/framework-components/src/control-stack.ts`:
- Line 253: Replace the inline type import on the byId declaration with a
top-level type import: add Codec to the file's existing import statement(s) and
then change the declaration const byId = new Map<string,
import('./codec-types').Codec>(); to use the imported Codec type (i.e., new
Map<string, Codec>()), referencing the byId variable in control-stack.ts so the
file uses a conventional top-level type import instead of inline
import('./codec-types').Codec.
In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts`:
- Around line 266-288: In generateFieldOutputTypesMap remove the unreachable
defensive check by deleting the "if (!model) continue;" line inside the loop
over Object.entries(models) so the loop simply processes each [modelName, model]
pair; ensure any references to model later in that loop remain unchanged (e.g.,
the inner loop over model.fields and creation of fieldEntries and fieldsType).
In `@packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts`:
- Around line 1-3: Update isSafeTypeExpression to broaden the unsafe-pattern
check: add detection for Function( constructor forms (both "Function(" and "new
Function(") and for stray semicolons that could terminate a type and start a
statement; modify the regex used inside isSafeTypeExpression (or add a second
test) to include patterns like Function\s*\(, new\s+Function\s*\(, and a
semicolon check (e.g., presence of ';' or ';\s*[\r\n]') so the function returns
false for these cases as well.
In `@packages/1-framework/3-tooling/emitter/test/emitter.test.ts`:
- Around line 319-338: The test name refers to parameterizedTypeImports but the
test only asserts behavior for queryOperationTypeImports; rename the test case
title in the it(...) call to reflect the actual scope (e.g., "passes
queryOperationTypeImports to generateContractDts") so it matches the validated
symbol queryOperationTypeImports and the assertion on result.contractDts
produced by emit; update the string in the it() declaration near the existing
test that constructs options and calls emit to keep names consistent.
In `@packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts`:
- Around line 67-74: Replace the hand‑written TypeMaps alias with the canonical
helper: import TypeMaps as TypeMapsType from "@prisma-next/sql-contract/types"
and change the exported type named TypeMaps to use TypeMapsType<CodecTypes,
OperationTypes, Record<string, never>, FieldOutputTypes> so the fixture stays in
sync; keep FieldOutputTypes, CodecTypes and OperationTypes names as the type
args to locate the substitution easily.
In `@packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts`:
- Around line 81-88: Replace the hand-crafted TypeMaps alias with the canonical
helper: import TypeMaps as TypeMapsType from "@prisma-next/sql-contract/types"
and change the exported alias to use TypeMapsType<CodecTypes, OperationTypes,
Record<string, never>, FieldOutputTypes> (keep the CodecTypes, OperationTypes
and FieldOutputTypes symbols as-is); this ensures the fixture uses the same
TypeMapsType helper and won't drift when fields like fieldOutputTypes change.
🪄 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: 819514d2-09c5-47b0-93a2-3e4da9ddaa8b
⛔ Files ignored due to path filters (5)
packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.mdis excluded by!projects/**projects/orm-consolidation/specs/codec-dispatched-type-rendering.mdis excluded by!projects/**test/e2e/framework/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**
📒 Files selected for processing (55)
docs/architecture docs/ADR-INDEX.mddocs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.mdexamples/prisma-next-demo/src/prisma/contract.d.tspackages/1-framework/0-foundation/contract/src/domain-types.tspackages/1-framework/1-core/framework-components/src/codec-types.tspackages/1-framework/1-core/framework-components/src/control-stack.tspackages/1-framework/1-core/framework-components/src/emission-types.tspackages/1-framework/1-core/framework-components/src/exports/components.tspackages/1-framework/1-core/framework-components/src/exports/control.tspackages/1-framework/1-core/framework-components/src/exports/emission.tspackages/1-framework/1-core/framework-components/src/framework-components.tspackages/1-framework/1-core/framework-components/src/type-renderers.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/1-framework/1-core/framework-components/test/framework-components.renderer.test.tspackages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.tspackages/1-framework/3-tooling/emitter/package.jsonpackages/1-framework/3-tooling/emitter/src/domain-type-generation.tspackages/1-framework/3-tooling/emitter/src/emit-types.tspackages/1-framework/3-tooling/emitter/src/emit.tspackages/1-framework/3-tooling/emitter/src/exports/index.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.tspackages/1-framework/3-tooling/emitter/src/type-expression-safety.tspackages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/1-framework/3-tooling/emitter/test/type-expression-safety.test.tspackages/1-framework/3-tooling/emitter/tsdown.config.tspackages/2-sql/1-core/contract/src/exports/types.tspackages/2-sql/1-core/contract/src/types.tspackages/2-sql/2-authoring/contract-ts/src/staged-contract-types.tspackages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.tspackages/2-sql/4-lanes/relational-core/src/ast/codec-types.tspackages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.tspackages/2-sql/4-lanes/relational-core/src/types.tspackages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.tspackages/2-sql/4-lanes/relational-core/test/schema.types.test-d.tspackages/2-sql/9-family/test/emit-parameterized.test.tspackages/3-extensions/pgvector/src/core/codecs.tspackages/3-extensions/pgvector/src/core/descriptor-meta.tspackages/3-extensions/pgvector/src/types/codec-types.tspackages/3-extensions/pgvector/test/codec-render-output-type.test.tspackages/3-extensions/pgvector/test/manifest.test.tspackages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.tspackages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.tspackages/3-targets/6-adapters/postgres/src/core/codecs.tspackages/3-targets/6-adapters/postgres/src/core/descriptor-meta.tspackages/3-targets/6-adapters/postgres/src/exports/codec-types.tspackages/3-targets/6-adapters/postgres/src/exports/column-types.tspackages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.tspackages/3-targets/6-adapters/postgres/test/descriptor-meta.test.tstest/integration/test/authoring/parity/pgvector-named-type/expected.contract.jsontest/integration/test/fixtures/contract.d.ts
💤 Files with no reviewable changes (11)
- packages/1-framework/1-core/framework-components/src/exports/control.ts
- packages/3-extensions/pgvector/test/manifest.test.ts
- packages/1-framework/1-core/framework-components/src/exports/emission.ts
- packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
- test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
- packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
- packages/1-framework/1-core/framework-components/src/emission-types.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
- packages/2-sql/9-family/test/emit-parameterized.test.ts
- packages/1-framework/1-core/framework-components/src/exports/components.ts
- packages/1-framework/1-core/framework-components/src/type-renderers.ts
eaafc89 to
510f3d4
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
packages/3-targets/6-adapters/postgres/src/core/codecs.ts (1)
520-528:⚠️ Potential issue | 🟡 MinorIncomplete string escaping in enum value rendering.
The enum value escaping on line 527 only escapes single quotes but not backslashes. If an enum value contains a backslash (e.g.,
'path\\to'), the generated TypeScript would have unescaped backslashes, potentially causing syntax errors or incorrect string interpretation.🔧 Proposed fix
- return values.map((value) => `'${String(value).replace(/'/g, "\\'")}'`).join(' | '); + return values.map((value) => `'${String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`).join(' | ');🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/3-targets/6-adapters/postgres/src/core/codecs.ts` around lines 520 - 528, renderOutputType currently only escapes single quotes for enum values, leaving backslashes unescaped which can produce invalid TypeScript for values like "path\\to"; update the escaping in renderOutputType (the mapping over typeParams['values'] in renderOutputType) to first escape backslashes and then escape single quotes (e.g., call String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'") before wrapping in quotes) and keep the join(' | ') behavior.
🧹 Nitpick comments (3)
packages/1-framework/3-tooling/emitter/test/emitter.test.ts (1)
292-310: Update test name to reflect actual behavior.The test name still references
parameterizedTypeImports, but the test body no longer tests that functionality (it was removed as part of this PR). The name should be updated to accurately describe what's being tested.💡 Proposed fix
- it('passes parameterizedTypeImports and queryOperationTypeImports to generateContractDts', async () => { + it('passes queryOperationTypeImports to generateContractDts', async () => {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/test/emitter.test.ts` around lines 292 - 310, Update the test's description string to accurately reflect what is being asserted: change the it(...) title that currently mentions "parameterizedTypeImports" to something like "passes queryOperationTypeImports to generateContractDts" so it matches the test body which constructs queryOperationTypeImports and calls emit(ir, options, mockSqlHook) and asserts result.contractDts contains "from '@ext/query'"; locate the test case around the it(...) invocation in emitter.test.ts and only modify the human-readable test name.packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts (1)
275-276: Minor: Redundant null check.The
if (!model) continuecheck on line 276 is unnecessary sinceObject.entries(models)won't yield undefined values for an object that already passed the empty check on line 270.Proposed simplification
for (const [modelName, model] of Object.entries(models).sort(([a], [b]) => a.localeCompare(b))) { - if (!model) continue; const fieldEntries: string[] = [];🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts` around lines 275 - 276, The null/undefined guard inside the loop is redundant: in the for...of over Object.entries(models).sort(...) the destructured variable model cannot be undefined after the prior empty check, so remove the line `if (!model) continue` inside the loop that iterates `for (const [modelName, model] of Object.entries(models).sort(...))`; simply rely on the sorted entries and proceed with using `model` (e.g., in the body that follows) without that extra check.packages/1-framework/1-core/framework-components/src/control-stack.ts (1)
250-250: Consider importingCodecat the top level.Line 250 uses an inline type import
import('./codec-types').CodecwhileCodecLookupis already imported from the same module at line 1. MovingCodecto the top-level import would be more consistent.Proposed change
-import type { CodecLookup } from './codec-types'; +import type { Codec, CodecLookup } from './codec-types';Then on line 250:
- const byId = new Map<string, import('./codec-types').Codec>(); + const byId = new Map<string, Codec>();🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/1-core/framework-components/src/control-stack.ts` at line 250, Replace the inline type import used in the declaration of byId with a top-level import: add Codec to the existing import from './codec-types' (the same module that already exports CodecLookup) and update the byId declaration to use Map<string, Codec>; this keeps imports consistent and removes the inline import('./codec-types').Codec usage in the byId variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@packages/3-targets/6-adapters/postgres/src/core/codecs.ts`:
- Around line 520-528: renderOutputType currently only escapes single quotes for
enum values, leaving backslashes unescaped which can produce invalid TypeScript
for values like "path\\to"; update the escaping in renderOutputType (the mapping
over typeParams['values'] in renderOutputType) to first escape backslashes and
then escape single quotes (e.g., call String(value).replace(/\\/g,
"\\\\").replace(/'/g, "\\'") before wrapping in quotes) and keep the join(' | ')
behavior.
---
Nitpick comments:
In `@packages/1-framework/1-core/framework-components/src/control-stack.ts`:
- Line 250: Replace the inline type import used in the declaration of byId with
a top-level import: add Codec to the existing import from './codec-types' (the
same module that already exports CodecLookup) and update the byId declaration to
use Map<string, Codec>; this keeps imports consistent and removes the inline
import('./codec-types').Codec usage in the byId variable.
In `@packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts`:
- Around line 275-276: The null/undefined guard inside the loop is redundant: in
the for...of over Object.entries(models).sort(...) the destructured variable
model cannot be undefined after the prior empty check, so remove the line `if
(!model) continue` inside the loop that iterates `for (const [modelName, model]
of Object.entries(models).sort(...))`; simply rely on the sorted entries and
proceed with using `model` (e.g., in the body that follows) without that extra
check.
In `@packages/1-framework/3-tooling/emitter/test/emitter.test.ts`:
- Around line 292-310: Update the test's description string to accurately
reflect what is being asserted: change the it(...) title that currently mentions
"parameterizedTypeImports" to something like "passes queryOperationTypeImports
to generateContractDts" so it matches the test body which constructs
queryOperationTypeImports and calls emit(ir, options, mockSqlHook) and asserts
result.contractDts contains "from '@ext/query'"; locate the test case around the
it(...) invocation in emitter.test.ts and only modify the human-readable test
name.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 9bde740e-2647-4265-a654-1b7381b89641
⛔ Files ignored due to path filters (5)
packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.mdis excluded by!projects/**projects/orm-consolidation/specs/codec-dispatched-type-rendering.mdis excluded by!projects/**test/e2e/framework/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**
📒 Files selected for processing (56)
docs/architecture docs/ADR-INDEX.mddocs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.mdexamples/prisma-next-demo/src/prisma/contract.d.tspackages/1-framework/0-foundation/contract/src/domain-types.tspackages/1-framework/1-core/framework-components/src/codec-types.tspackages/1-framework/1-core/framework-components/src/control-stack.tspackages/1-framework/1-core/framework-components/src/emission-types.tspackages/1-framework/1-core/framework-components/src/exports/components.tspackages/1-framework/1-core/framework-components/src/exports/control.tspackages/1-framework/1-core/framework-components/src/exports/emission.tspackages/1-framework/1-core/framework-components/src/framework-components.tspackages/1-framework/1-core/framework-components/src/type-renderers.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/1-framework/1-core/framework-components/test/framework-components.renderer.test.tspackages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.tspackages/1-framework/3-tooling/emitter/package.jsonpackages/1-framework/3-tooling/emitter/src/domain-type-generation.tspackages/1-framework/3-tooling/emitter/src/emit-types.tspackages/1-framework/3-tooling/emitter/src/emit.tspackages/1-framework/3-tooling/emitter/src/exports/index.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.tspackages/1-framework/3-tooling/emitter/src/type-expression-safety.tspackages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/1-framework/3-tooling/emitter/test/type-expression-safety.test.tspackages/1-framework/3-tooling/emitter/tsdown.config.tspackages/2-sql/1-core/contract/src/exports/types.tspackages/2-sql/1-core/contract/src/types.tspackages/2-sql/2-authoring/contract-ts/src/staged-contract-types.tspackages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.tspackages/2-sql/4-lanes/relational-core/src/ast/codec-types.tspackages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.tspackages/2-sql/4-lanes/relational-core/src/types.tspackages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.tspackages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.tspackages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.tspackages/2-sql/9-family/test/emit-parameterized.test.tspackages/3-extensions/pgvector/src/core/codecs.tspackages/3-extensions/pgvector/src/core/descriptor-meta.tspackages/3-extensions/pgvector/src/types/codec-types.tspackages/3-extensions/pgvector/test/codec-render-output-type.test.tspackages/3-extensions/pgvector/test/manifest.test.tspackages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.tspackages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.tspackages/3-targets/6-adapters/postgres/src/core/codecs.tspackages/3-targets/6-adapters/postgres/src/core/descriptor-meta.tspackages/3-targets/6-adapters/postgres/src/exports/codec-types.tspackages/3-targets/6-adapters/postgres/src/exports/column-types.tspackages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.tspackages/3-targets/6-adapters/postgres/test/descriptor-meta.test.tstest/integration/test/authoring/parity/pgvector-named-type/expected.contract.jsontest/integration/test/fixtures/contract.d.ts
💤 Files with no reviewable changes (11)
- packages/3-extensions/pgvector/test/manifest.test.ts
- packages/1-framework/1-core/framework-components/src/exports/control.ts
- packages/1-framework/1-core/framework-components/src/exports/emission.ts
- packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
- packages/1-framework/1-core/framework-components/src/exports/components.ts
- packages/1-framework/1-core/framework-components/src/emission-types.ts
- test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
- packages/2-sql/9-family/test/emit-parameterized.test.ts
- packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
- packages/1-framework/1-core/framework-components/src/type-renderers.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
✅ Files skipped from review due to trivial changes (12)
- packages/3-extensions/pgvector/src/core/codecs.ts
- packages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.ts
- packages/1-framework/3-tooling/emitter/tsdown.config.ts
- docs/architecture docs/ADR-INDEX.md
- packages/3-extensions/pgvector/test/codec-render-output-type.test.ts
- packages/2-sql/1-core/contract/src/exports/types.ts
- packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts
- packages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.ts
- packages/1-framework/3-tooling/emitter/package.json
- packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
- packages/1-framework/1-core/framework-components/src/framework-components.ts
🚧 Files skipped from review as they are similar to previous changes (20)
- packages/1-framework/3-tooling/emitter/src/exports/index.ts
- packages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.ts
- packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
- packages/1-framework/1-core/framework-components/src/codec-types.ts
- packages/1-framework/0-foundation/contract/src/domain-types.ts
- packages/1-framework/3-tooling/emitter/src/emit.ts
- packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
- packages/1-framework/1-core/framework-components/test/control-stack.test.ts
- packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts
- packages/1-framework/3-tooling/emitter/test/type-expression-safety.test.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
- packages/2-sql/1-core/contract/src/types.ts
- packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts
- packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts
- packages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.ts
- packages/3-extensions/pgvector/src/types/codec-types.ts
- examples/prisma-next-demo/src/prisma/contract.d.ts
- packages/2-sql/3-tooling/emitter/src/index.ts
- packages/1-framework/3-tooling/emitter/src/emit-types.ts
- packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts
510f3d4 to
b9486cd
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/3-targets/6-adapters/postgres/src/core/codecs.ts`:
- Around line 520-528: The renderOutputType function builds enum literal strings
but only escapes single quotes, causing malformed literals when values contain
backslashes; update renderOutputType (typeParams['values']) to first escape
backslashes in each value (replace \ with \\) and then escape single quotes,
e.g., transform the value by replacing backslashes before replacing single
quotes, then wrap in single quotes and join with ' | ' so all backslashes and
quotes are properly escaped.
- Around line 58-66: The function renderLength currently throws if
typeParams.length is absent; change its signature to return string | undefined
and update logic in renderLength (keep the function name) so that if length is
undefined it returns undefined (so callers can fall back to
CodecTypes[codecId]['output']), if length is present but not a number it still
throws the existing error, otherwise return `${typeName}<${length}>`; ensure the
return type annotation is updated accordingly.
🪄 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: 5765cabb-6652-4465-95e4-e25200489d6e
⛔ Files ignored due to path filters (5)
packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.mdis excluded by!projects/**projects/orm-consolidation/specs/codec-dispatched-type-rendering.mdis excluded by!projects/**test/e2e/framework/test/fixtures/generated/contract.d.tsis excluded by!**/generated/**
📒 Files selected for processing (56)
docs/architecture docs/ADR-INDEX.mddocs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.mdexamples/prisma-next-demo/src/prisma/contract.d.tspackages/1-framework/0-foundation/contract/src/domain-types.tspackages/1-framework/1-core/framework-components/src/codec-types.tspackages/1-framework/1-core/framework-components/src/control-stack.tspackages/1-framework/1-core/framework-components/src/emission-types.tspackages/1-framework/1-core/framework-components/src/exports/components.tspackages/1-framework/1-core/framework-components/src/exports/control.tspackages/1-framework/1-core/framework-components/src/exports/emission.tspackages/1-framework/1-core/framework-components/src/framework-components.tspackages/1-framework/1-core/framework-components/src/type-renderers.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/1-framework/1-core/framework-components/test/framework-components.renderer.test.tspackages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.tspackages/1-framework/3-tooling/emitter/package.jsonpackages/1-framework/3-tooling/emitter/src/domain-type-generation.tspackages/1-framework/3-tooling/emitter/src/emit-types.tspackages/1-framework/3-tooling/emitter/src/emit.tspackages/1-framework/3-tooling/emitter/src/exports/index.tspackages/1-framework/3-tooling/emitter/src/generate-contract-dts.tspackages/1-framework/3-tooling/emitter/src/type-expression-safety.tspackages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/1-framework/3-tooling/emitter/test/type-expression-safety.test.tspackages/1-framework/3-tooling/emitter/tsdown.config.tspackages/2-sql/1-core/contract/src/exports/types.tspackages/2-sql/1-core/contract/src/types.tspackages/2-sql/2-authoring/contract-ts/src/staged-contract-types.tspackages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.tspackages/2-sql/4-lanes/relational-core/src/ast/codec-types.tspackages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.tspackages/2-sql/4-lanes/relational-core/src/types.tspackages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.tspackages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.tspackages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.tspackages/2-sql/9-family/test/emit-parameterized.test.tspackages/3-extensions/pgvector/src/core/codecs.tspackages/3-extensions/pgvector/src/core/descriptor-meta.tspackages/3-extensions/pgvector/src/types/codec-types.tspackages/3-extensions/pgvector/test/codec-render-output-type.test.tspackages/3-extensions/pgvector/test/manifest.test.tspackages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.tspackages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.tspackages/3-targets/6-adapters/postgres/src/core/codecs.tspackages/3-targets/6-adapters/postgres/src/core/descriptor-meta.tspackages/3-targets/6-adapters/postgres/src/exports/codec-types.tspackages/3-targets/6-adapters/postgres/src/exports/column-types.tspackages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.tspackages/3-targets/6-adapters/postgres/test/descriptor-meta.test.tstest/integration/test/authoring/parity/pgvector-named-type/expected.contract.jsontest/integration/test/fixtures/contract.d.ts
💤 Files with no reviewable changes (11)
- test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
- packages/1-framework/1-core/framework-components/src/exports/control.ts
- packages/3-extensions/pgvector/test/manifest.test.ts
- packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
- packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
- packages/1-framework/1-core/framework-components/src/exports/components.ts
- packages/1-framework/1-core/framework-components/src/emission-types.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
- packages/2-sql/9-family/test/emit-parameterized.test.ts
- packages/1-framework/1-core/framework-components/src/exports/emission.ts
- packages/1-framework/1-core/framework-components/src/type-renderers.ts
✅ Files skipped from review due to trivial changes (9)
- packages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.ts
- docs/architecture docs/ADR-INDEX.md
- packages/1-framework/3-tooling/emitter/test/type-expression-safety.test.ts
- packages/2-sql/1-core/contract/src/exports/types.ts
- packages/1-framework/3-tooling/emitter/tsdown.config.ts
- packages/1-framework/3-tooling/emitter/src/exports/index.ts
- packages/1-framework/3-tooling/emitter/package.json
- packages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.ts
- packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts
🚧 Files skipped from review as they are similar to previous changes (21)
- packages/3-extensions/pgvector/test/codec-render-output-type.test.ts
- packages/3-extensions/pgvector/src/core/codecs.ts
- packages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.ts
- packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
- packages/1-framework/3-tooling/emitter/src/emit.ts
- packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts
- packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts
- packages/1-framework/0-foundation/contract/src/domain-types.ts
- packages/1-framework/3-tooling/emitter/src/emit-types.ts
- examples/prisma-next-demo/src/prisma/contract.d.ts
- packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
- packages/3-extensions/pgvector/src/types/codec-types.ts
- packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
- packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
- packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts
- packages/1-framework/1-core/framework-components/test/control-stack.test.ts
- packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
- packages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.ts
- packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
- packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts
- packages/1-framework/1-core/framework-components/src/codec-types.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts (1)
212-214: Consider consolidating assertions withtoEqual.Per coding guidelines, prefer object comparison using
toEqualover property-by-property checks. A singletoEqualassertion both verifiesimportis present and implicitly confirms no other properties exist:♻️ Suggested refactor
- expect(codecTypes).not.toHaveProperty('controlPlaneHooks'); - expect(codecTypes).not.toHaveProperty('codecInstances'); - expect(codecTypes['import']).toBeDefined(); + expect(codecTypes).toEqual({ + import: { + package: '@ext/pgvector', + named: 'PgvectorCodecTypes', + alias: 'PgvectorCodecTypes', + }, + });As per coding guidelines: "Prefer object comparison using
toEqualortoMatchObjectfor assertions on objects, rather than property-by-property checks withtoHaveProperty."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts` around lines 212 - 214, Replace the three separate assertions on codecTypes with a single exact object equality assertion: instead of checking not.toHaveProperty('controlPlaneHooks'), not.toHaveProperty('codecInstances') and that codecTypes['import'] is defined, assert expect(codecTypes).toEqual({ import: expect.anything() }) in the contract-enrichment.test.ts test so the presence of import is verified and no other properties exist.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts`:
- Around line 212-214: Replace the three separate assertions on codecTypes with
a single exact object equality assertion: instead of checking
not.toHaveProperty('controlPlaneHooks'), not.toHaveProperty('codecInstances')
and that codecTypes['import'] is defined, assert expect(codecTypes).toEqual({
import: expect.anything() }) in the contract-enrichment.test.ts test so the
presence of import is verified and no other properties exist.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: adf831f2-b816-4e4c-835f-fa3e8a33539e
📒 Files selected for processing (1)
packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts
Covers adding renderType to the Codec base interface, wiring the emitter to call it for scalar fields with typeParams, removing the phantom typeParams.schema path, and deleting the dead parameterizedRenderers infrastructure.
The no-emit path for JSON schema types was never wired end-to-end — the integration type test explicitly asserts unknown, not the schema-derived type. Removing the phantom schema key is safe and does not regress any working behavior. Branded types (vector, char) continue to work via parameterizedOutput in both paths.
The type-level parameterizedOutput path is conceptually sound — the authoring surface captures the schema type via phantom key and ResolveStandardSchemaOutput extracts it. The current unknown resolution is a plumbing bug (phantom key lost in the pipeline), not a fundamental limitation. renderType is needed specifically for the emit path where only serialized schemaJson is available.
Captures the design for TML-2204 — moving type rendering onto codecs, unifying parameterized type resolution across emit and no-emit paths, and removing the SQL emitter generateModelsType override.
Codecs own TypeScript type rendering via optional renderTypeParams and parameterizedOutput on CodecTypes. Removes EmissionSpi override, legacy parameterized renderer infrastructure, and descriptor metadata threading. Extends ADR 184 pattern (codec-owned representations) to the fourth representation: TypeScript types in contract.d.ts.
Rewrite to lead with grounding example, introduce the core insight (two representations of the same data) as its own section, trim legacy implementation detail from context, and drop the deletion table from the decision section.
Show both Vector (identity) and JSON Schema (transformation) examples end-to-end in the grounding section. Clarify that the type-level typeParams in contract.d.ts may differ from the runtime values in contract.json — this is intentional for codecs like pg/jsonb@1. Rename renderTypeParams to emitTypeParams — the method transforms runtime typeParams into the representation written into the d.ts, and the old name was ambiguous about what was being rendered.
Separate codec field configuration (typeParams, truthful, matches contract.json) from field output type (FieldOutputTypes map, resolved by emitter or builder). Eliminates parameterizedOutput on CodecTypes, simplifies ComputeColumnJsType to a single map lookup, and keeps typeParams honest. Codec method renamed to renderOutputType — produces the TypeScript output type string for a given field configuration.
Move renderOutputType codec example from At a glance into the Decision section where the reader has context. Define emit and no-emit workflows at the start of Context. Simplify the TML-2206 bullet. Clarify that the renderOutputType fallback emits a type-level reference expression.
Rewrite both documents from scratch grounded in the ADR and current codebase. The spec covers FieldOutputTypes map placement in TypeMaps, renderOutputType on every parameterized codec, ComputeColumnJsType simplification, and no-emit path changes. The plan has five milestones: add renderOutputType, emit FieldOutputTypes, wire consumers, no-emit path, delete legacy infrastructure. Replaces the outdated plan that used the old renderType name and lacked the FieldOutputTypes design.
ContractField post-TML-2206 has a type property (discriminated union of ScalarFieldType | ValueObjectFieldType | UnionFieldType) rather than flat codecId/typeParams at the top level. typeParams lives at field.type.typeParams for scalar fields. Update worked examples, field access paths, ComputeColumnJsType description, and framework emitter changes to reflect that generateFieldResolvedType already exists and handles all three field kinds with many/dict/nullable modifiers.
…rized codecs Adds the optional renderOutputType method to the framework Codec base, the SQL codec factory, and all parameterized Postgres/pgvector codecs. Adds isSafeTypeExpression as a shared emitter utility. Tests cover all parameterized codecs and non-parameterized fallbacks.
Adds codecLookup to EmitStackInput and ControlStack. Extends generateFieldResolvedType with codec dispatch via renderOutputType. Adds generateFieldOutputTypesMap and emits FieldOutputTypes in contract.d.ts. Extends TypeMaps with a fourth fieldOutputTypes parameter and adds FieldOutputTypesOf/ExtractFieldOutputTypes helpers.
Replaces ~100 lines of conditional type machinery with a direct FieldOutputTypes map lookup, falling back to CodecTypes for unmapped columns. Deletes ExtractFieldValue, ApplyNullability, ApplyFieldModifiers, ExtractValueObject, ExpandValueObjectFields, ResolveValueObjectJsType, ResolveModelFieldToJsType, ExtractColumnJsTypeFromModels, ResolveColumnTypeParams, ExtractParameterizedCodecOutputType, ExtractCodecOutputType, and ColumnMetaTypeId helper types.
Add StagedFieldOutputTypes type computation and wire it as the fourth TypeMaps parameter in SqlContractResult so programmatic contracts get FieldOutputTypes without the emitter. Remove TypedColumnDescriptor phantom schema key from JSON column types— no longer needed since ComputeColumnJsType reads from FieldOutputTypes instead of parameterizedOutput.
Delete type-renderers.ts, TypeRenderEntry, ParameterizedCodecDescriptor, parameterizedRenderers/parameterizedTypeImports from ControlStack and EmitStackInput. Remove EmissionSpi.generateModelsType override and SQL emitter's 120-line generateModelsType — framework generateModelsType now handles all model field emission. Delete parameterized maps from postgres and pgvector descriptor metadata, parameterizedOutput from codec-types, and phantom schema key helpers. Update all tests: remove parameterized renderer tests, update SQL emitter tests to expect ContractField descriptors instead of inlined rendered types, add FieldOutputTypes to type-level test fixtures.
FieldOutputTypes entries now use concrete TypeScript types (number, string, etc.) instead of CodecTypes lookups to avoid deep type resolution chains that TypeScript struggles with. Deletes emit-parameterized.test.ts which tested the removed legacy parameterized rendering infrastructure.
The parameterized renderer map was deleted from descriptor metadata in the M5 cleanup, so expected fixture must match.
…t JSON Postgres adapter and pgvector extension now contribute their codec instances via the codecInstances contribution point, enabling codec-dispatched type rendering during emission. Also strips codecInstances from extension pack metadata before serialization into contract.json (alongside the existing controlPlaneHooks stripping) to prevent runtime objects leaking into the serialized contract.
Replace silent first-wins deduplication with assertUniqueCodecOwner to detect conflicting codec instances contributed by different descriptors. Add tests covering the lookup and duplicate detection.
renderOutputType now fails fast when required typeParams keys are missing or wrong-typed, surfacing contract integrity errors early instead of silently falling back to generic CodecTypes output. renderPrecision returns the bare type name only when precision is explicitly absent (optional param), matching the paramsSchema contract.
…expression fallback Tests verify generateFieldResolvedType uses renderOutputType when codec and typeParams are present, falls back to CodecTypes when the expression is unsafe (import injection), and generateFieldOutputTypesMap produces entries with codec-dispatched rendering.
Now that parameterized renderers no longer replace field shapes in the model type, ContractModelBase.fields can use the precise ContractField type instead of Record<string, unknown>. Removes the defensive casts in generateFieldOutputTypesMap.
When a model or field exists in the contract but is missing from FieldOutputTypes, resolve to never instead of silently degrading to FallbackCodecLookup. This surfaces contract inconsistencies as compile-time errors rather than producing less-specific types. FallbackCodecLookup is retained only for genuinely unmapped columns (table not mapped to a model, or column not mapped to a field).
StagedBuiltModels.fields now produces the correct ContractField shape
with { nullable, type: { kind, codecId } } instead of the flat
{ codecId, nullable } that no longer satisfies the tightened
ContractModelBase.fields constraint.
…, and query-operation-registry Cover the renderOutputType throw paths for sql/char, sql/varchar, and sql/timestamp codecs. Exercise the identity encodeJson/decodeJson fallback in the codec factory and the Symbol.iterator protocol on CodecRegistry. Add unit tests for createQueryOperationRegistry.
Codecs without renderOutputType now fall back to CodecTypes[codecId][output] instead of inline-resolved types. Parameterized codecs (char, varchar) still render concrete types.
The query-operation-registry module was removed by the operations unification refactor on main. Remove the test that was added for it.
The parameterized property was deleted from codecTypes as part of codec-dispatched type rendering. Update the test to verify stripping of codecInstances instead, which is the replacement mechanism.
Return undefined (falling back to CodecTypes output) when length/ precision params are absent, instead of throwing. This handles legal bare char/varchar/bit/varbit/vector columns correctly. Also: escape backslashes before single quotes in enum rendering to prevent malformed string literals, and validate that numeric params are finite integers (reject NaN/Infinity).
Update ADR-INDEX entry to reference renderOutputType/FieldOutputTypes instead of legacy renderTypeParams/parameterizedOutput. Remove projects/ link from ADR 186 references (transient artifacts).
The e2e fixture was using a manual CodecLookup stub that only handled two codecs and had no renderOutputType. Replace with extractCodecLookup using the real postgres adapter descriptor, which carries all codec instances including renderOutputType implementations. Also export extractCodecLookup from framework-components/control.
Captures 12 explicit criteria identified during PR review, including codecInstances population, e2e parameterized column coverage, and renderOutputType error handling expectations.
assembly.ts still referenced deleted TypeRenderer; replaced with codecInstances (Codec[]). compute-column-js-type tests now construct contracts with explicit model types and FieldOutputTypes in TypeMaps, matching the new ComputeColumnJsType map-lookup pattern.
Main branch introduced TS authoring redesign (staged -> contract-types rename); regenerating ensures fixtures align with the new base.
…deferred no-emit parameterized) F09 -> M6: vector + jsonb-with-schema e2e coverage. F10 -> M7: bring mongo in line with ADR 186, including renderOutputType on mongoVectorCodec. F12 -> M8: deferred — no-emit path parameterized output types require separate design work.
7488bca to
d433a3f
Compare
Add fieldOutputTypes to MongoTypeMaps (third type parameter), ExtractMongoFieldOutputTypes helper, and update mongo emitter to include FieldOutputTypes in the TypeMaps expression. Extend mongoCodec() factory to accept renderOutputType, and add a renderOutputType implementation to mongoVectorCodec that produces Vector<N>. Add codecInstances and Vector typeImport to the mongo adapter descriptor so the emitter can resolve renderOutputType at emit time. Regenerate mongo integration fixture to verify the emitted contract includes FieldOutputTypes in TypeMaps.
The mongo emitter now produces MongoTypeMaps<CodecTypes, OperationTypes, FieldOutputTypes>. Update the generation and e2e test assertions to expect the third type parameter.
Wire pgvector extension pack into the e2e emission config and runtime
stack. Add an Embedding model with a vector(1536) column and a
jsonb(profileSchema) column using a StandardSchemaLike schema.
The emitted FieldOutputTypes now includes:
- Vector<1536> for the vector column
- { name: string; age: number } for the jsonb-with-schema column
This exercises the full codec-dispatched type rendering pipeline
end-to-end for parameterized types beyond Char/Varchar.
closes TML-2204
Intent
Consolidate output type rendering for
contract.d.tsonto the codec that owns the type, replacing three separate systems with one optional method and one type map.The story
Resolving a field's TypeScript output type was scattered across
CodecTypes(non-parameterized),parameterizedrenderer maps in descriptor metadata (emit path), andparameterizedOutputfunction types onCodecTypes(no-emit path). The SQL emitter overrodeEmissionSpi.generateModelsType?(~130 lines) to inject renderer dispatch, coupling it to storage internals. Renderers replaced the entire field shape, breaking code expecting structuralContractFieldmetadata.This PR consolidates all of that into:
renderOutputTypeon the Codec interface — an optional method producing the TypeScript type expression for a field given itstypeParams. The codec already owns wire format, JSON serialization, and DDL rendering; this completes the set.FieldOutputTypesmap incontract.d.ts— aModelName → FieldName → OutputTypemap produced by both the emit path (via codec dispatch) and the no-emit path (via the contract builder).ComputeColumnJsTypereads from this map — one lookup, every field.Behavior changes
FieldOutputTypesis a new export incontract.d.tscontaining resolved output types for every model field.ComputeColumnJsTypeis a map lookup instead of a ~60-line nested conditional type dispatching throughCodecTypesandExtractParameterizedCodecOutputType.EmissionSpi.generateModelsType?is removed — the framework emitter handles all families without SPI overrides.parameterizedOutputis removed fromCodecTypes— output types come fromFieldOutputTypes.typeParamsmatchescontract.json; renderers no longer replace the field shape.schemakey on JSON column descriptors is removed —json()/jsonb()return plainColumnTypeDescriptor.Change map
renderOutputTypeon Codec interface, implemented on all parameterized postgres/pgvector/SQL codecsFieldOutputTypesmap emitted incontract.d.ts, wired intoTypeMapsas fourth memberComputeColumnJsTypesimplified toFieldOutputTypeslookupFieldOutputTypesviaStagedFieldOutputTypesTypeRenderer, normalization pipeline,parameterizedmaps,parameterizedRenderers/parameterizedTypeImportsthreading,EmissionSpi.generateModelsType?override,parameterizedOutput, phantomschemakeyCompatibility / migration / risk
TypeMapsgains a fourth generic parameter with a default — existing instantiations continue to compile.FieldOutputTypesis additive.json()/jsonb()lose type-level schema narrowing in the no-emit path (resolves toJsonValue; documented as not-a-regression since the prior path was already broken).parameterizedOutputremoval is breaking for any consumer that relied on it at the type level (internal only).Summary by CodeRabbit
New Features
Documentation
Refactor
Tests