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

feat(framework): codec-dispatched type rendering with FieldOutputTypes map - #312

Merged
wmadden merged 41 commits into
mainfrom
tml-2204-typed-json-simplification-codec-dispatched-type-rendering
Apr 8, 2026
Merged

wmadden merged 41 commits into
mainfrom
tml-2204-typed-json-simplification-codec-dispatched-type-rendering

Conversation

@wmadden

@wmadden wmadden commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

closes TML-2204

Intent

Consolidate output type rendering for contract.d.ts onto 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), parameterized renderer maps in descriptor metadata (emit path), and parameterizedOutput function types on CodecTypes (no-emit path). The SQL emitter overrode EmissionSpi.generateModelsType? (~130 lines) to inject renderer dispatch, coupling it to storage internals. Renderers replaced the entire field shape, breaking code expecting structural ContractField metadata.

This PR consolidates all of that into:

  1. renderOutputType on the Codec interface — an optional method producing the TypeScript type expression for a field given its typeParams. The codec already owns wire format, JSON serialization, and DDL rendering; this completes the set.

  2. FieldOutputTypes map in contract.d.ts — a ModelName → FieldName → OutputType map produced by both the emit path (via codec dispatch) and the no-emit path (via the contract builder). ComputeColumnJsType reads from this map — one lookup, every field.

Behavior changes

  • FieldOutputTypes is a new export in contract.d.ts containing resolved output types for every model field.
  • ComputeColumnJsType is a map lookup instead of a ~60-line nested conditional type dispatching through CodecTypes and ExtractParameterizedCodecOutputType.
  • EmissionSpi.generateModelsType? is removed — the framework emitter handles all families without SPI overrides.
  • parameterizedOutput is removed from CodecTypes — output types come from FieldOutputTypes.
  • Model fields stay structural — typeParams matches contract.json; renderers no longer replace the field shape.
  • Phantom schema key on JSON column descriptors is removed — json()/jsonb() return plain ColumnTypeDescriptor.

Change map

  • ADR 186 — architectural decision and rationale
  • Design spec — detailed design with worked examples and deletion inventory
  • Execution plan — five milestones from additive codec changes through legacy deletion
  • Implementation — all five milestones delivered:
    • renderOutputType on Codec interface, implemented on all parameterized postgres/pgvector/SQL codecs
    • FieldOutputTypes map emitted in contract.d.ts, wired into TypeMaps as fourth member
    • ComputeColumnJsType simplified to FieldOutputTypes lookup
    • No-emit path produces FieldOutputTypes via StagedFieldOutputTypes
    • Legacy infrastructure deleted (~1200 lines net): TypeRenderer, normalization pipeline, parameterized maps, parameterizedRenderers/parameterizedTypeImports threading, EmissionSpi.generateModelsType? override, parameterizedOutput, phantom schema key

Compatibility / migration / risk

  • TypeMaps gains a fourth generic parameter with a default — existing instantiations continue to compile.
  • FieldOutputTypes is additive.
  • json()/jsonb() lose type-level schema narrowing in the no-emit path (resolves to JsonValue; documented as not-a-regression since the prior path was already broken).
  • parameterizedOutput removal is breaking for any consumer that relied on it at the type level (internal only).

Summary by CodeRabbit

  • New Features

    • Emits a new FieldOutputTypes map in generated contract types for explicit per-field output typings.
    • Codecs can optionally provide renderOutputType to produce custom TypeScript output expressions.
    • Generated type expressions are validated for safety before being emitted.
  • Documentation

    • Added ADR 186 documenting the codec-dispatched type rendering approach.
  • Refactor

    • Replaced template-based parameterized rendering with codec-driven dispatch in the emission pipeline.
  • Tests

    • Added and updated tests covering codec rendering, safety checks, and field-output map generation.

@coderabbitai

coderabbitai Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces parameterized renderer plumbing with codec-dispatched output-type rendering: adds FieldOutputTypes to generated contracts, adds optional Codec.renderOutputType, introduces codecLookup in control/emission stacks, and updates emitters/adapters/tests to resolve field output types via codec instances with a safe-expression check.

Changes

Cohort / File(s) Summary
Architecture & ADR
docs/architecture docs/ADR-INDEX.md, docs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.md
Add ADR 186 describing codec-dispatched FieldOutputTypes and removal of parameterized renderer infrastructure.
Framework — codec surface & metadata
packages/1-framework/1-core/framework-components/src/codec-types.ts, packages/1-framework/1-core/framework-components/src/framework-components.ts
Add optional Codec.renderOutputType?(typeParams) and replace component types.codecTypes.parameterized with codecInstances.
Framework — control stack & exports
packages/1-framework/1-core/framework-components/src/control-stack.ts, packages/1-framework/1-core/framework-components/src/exports/control.ts, packages/1-framework/1-core/framework-components/src/exports/components.ts, packages/1-framework/1-core/framework-components/src/exports/emission.ts
Replace parameterizedRenderers/parameterizedTypeImports with codecLookup; add extractCodecLookup; remove renderer-related re-exports.
Framework — renderer module & types removed
packages/1-framework/1-core/framework-components/src/type-renderers.ts, packages/1-framework/1-core/framework-components/src/emission-types.ts, packages/1-framework/1-core/framework-components/src/domain-types.ts
Delete type-renderer utilities and related types; tighten ContractModelBase.fields to Record<string, ContractField>; remove generateModelsType? SPI hook.
Emitter — domain & generation
packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts, packages/1-framework/3-tooling/emitter/src/emit.ts, packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts, packages/1-framework/3-tooling/emitter/src/emit-types.ts
Add generateFieldOutputTypesMap; accept codecLookup and use it to render field output types (with safety check); emit new FieldOutputTypes in generated .d.ts; remove parameterized renderer inputs.
Emitter — safety helper & packaging
packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts, packages/1-framework/3-tooling/emitter/package.json, packages/1-framework/3-tooling/emitter/tsdown.config.ts
Add isSafeTypeExpression utility, publish export and build entry.
Emitter — tests updated
packages/1-framework/3-tooling/emitter/test/*
Add tests for codec-dispatched resolution and safety; remove tests for parameterized renderer/type-import forwarding and generateModelsType delegation.
SQL — contract typing & emit
packages/2-sql/1-core/contract/src/types.ts, packages/2-sql/1-core/contract/src/exports/types.ts, packages/2-sql/3-tooling/emitter/src/index.ts, packages/2-sql/2-authoring/contract-ts/src/staged-contract-types.ts
Add FieldOutputTypes generic to TypeMaps; add utilities (FieldOutputTypesOf, ExtractFieldOutputTypes); remove generateModelsType and shift model field descriptors to include type metadata.
SQL — relational core codecs & types
packages/2-sql/4-lanes/relational-core/src/ast/codec-types.ts, packages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.ts, packages/2-sql/4-lanes/relational-core/src/types.ts
Allow codec renderOutputType in codec factory; implement renderOutputType for char/varchar/timestamp; simplify ComputeColumnJsType to prefer emitted FieldOutputTypes with a codec-output fallback.
Postgres adapter — codecs & descriptors
packages/3-targets/6-adapters/postgres/src/core/codecs.ts, packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts, packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts, packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
Add many renderOutputType implementations (numeric, temporal, bit, enum, json/jsonb rendering); replace parameterized map with codecInstances; remove compile-time parameterizedOutput overrides and TypedColumnDescriptor generics.
pgvector extension
packages/3-extensions/pgvector/src/core/codecs.ts, packages/3-extensions/pgvector/src/core/descriptor-meta.ts, packages/3-extensions/pgvector/src/types/codec-types.ts
Add renderOutputType to pgvector codec, expose codec instances instead of parameterized templates, remove compile-time parameterized CodecTypes override.
Examples & fixtures
examples/prisma-next-demo/src/prisma/contract.d.ts, test/integration/test/fixtures/contract.d.ts, packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts, packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts, other test fixtures`
Emit and update FieldOutputTypes in contract .d.ts fixtures; adjust TypeMaps to accept FieldOutputTypes and align field typing (e.g., Address -> string).
Tests removed/updated across repo
packages/1-framework/.../test/*, packages/2-sql/.../test/*, packages/2-sql/9-family/test/emit-parameterized.test.ts, packages/3-extensions/*/test/*
Remove broad coverage of parameterized renderer/template system and update/add tests for codec.renderOutputType and field-output emission.
CLI — pack metadata cleaning
packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
Strip codecInstances (and controlPlaneHooks) from serialized extension pack metadata during enrichment.

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)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • jkomyno

"I nibble on small specs,
render types from tiny specs,
codecs hum the tune,
FieldOutputTypes bloom,
a rabbit hops—contracts fixed!" 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: introducing codec-dispatched type rendering with a FieldOutputTypes map, which is the primary focus of the changeset.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2204-typed-json-simplification-codec-dispatched-type-rendering

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Apr 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

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

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

@prisma-next/runtime-executor

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/runtime-executor@312

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-pipeline-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-pipeline-builder@312

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/adapter-postgres

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

@prisma-next/driver-postgres

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

commit: bfbf8a0

@wmadden
wmadden force-pushed the tml-2204-typed-json-simplification-codec-dispatched-type-rendering branch from 8bfdf3e to 9ed377f Compare April 7, 2026 15:33
@wmadden
wmadden marked this pull request as ready for review April 7, 2026 16:10
@wmadden wmadden changed the title docs(framework): ADR 186 codec-dispatched type rendering feat(framework): codec-dispatched type rendering with FieldOutputTypes map Apr 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 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 | 🟠 Major

Thread codecLookup through value object type generation to support codec-rendered output types.

Value object fields can have scalar types with typeParams, but generateValueObjectTypeAliases doesn't accept or forward codecLookup to generateFieldResolvedType. This means value object fields with parameterized codecs (e.g., pg/char@1 with length: 36) won't get codec-rendered output types, unlike model fields which do via generateFieldOutputTypesMap.

Update the signature chain: generateValueObjectTypeAliases(codecLookup?) → generateValueObjectType(codecLookup?) → generateFieldResolvedType(field, codecLookup). Also pass codecLookup at the call site in generate-contract-dts.ts line 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 | 🟡 Minor

Incomplete string escaping for enum values.

The enum renderOutputType only 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.ts files:

  • Function( constructor
  • new 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 canonical TypeMapsType<...> helper in this fixture.

This alias is duplicating the public TypeMaps shape by hand, so it can fall behind the real contract.d.ts surface again on the next change. Switching it to TypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes> and importing TypeMaps as TypeMapsType from @prisma-next/sql-contract/types would 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 canonical TypeMapsType<...> helper in this fixture.

Hand-rolling TypeMaps here makes the fixture drift-prone; the new fieldOutputTypes slot is exactly the kind of surface change that's easy to miss. Switching this alias to TypeMapsType<CodecTypes, OperationTypes, Record<string, never>, FieldOutputTypes> and importing TypeMaps as TypeMapsType from @prisma-next/sql-contract/types will 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 parameterizedTypeImports but only validates queryOperationTypeImports. 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 importing Codec type at the top of the file.

The inline import('./codec-types').Codec works but is less conventional than adding Codec to 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 yield undefined as a value for existing entries. The if (!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

📥 Commits

Reviewing files that changed from the base of the PR and between 30bc9d2 and a5be7ae.

⛔ Files ignored due to path filters (5)
  • packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.md is excluded by !projects/**
  • projects/orm-consolidation/specs/codec-dispatched-type-rendering.md is excluded by !projects/**
  • test/e2e/framework/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
📒 Files selected for processing (55)
  • docs/architecture docs/ADR-INDEX.md
  • docs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.md
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/0-foundation/contract/src/domain-types.ts
  • packages/1-framework/1-core/framework-components/src/codec-types.ts
  • packages/1-framework/1-core/framework-components/src/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • packages/1-framework/1-core/framework-components/src/exports/components.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/1-core/framework-components/src/type-renderers.ts
  • packages/1-framework/1-core/framework-components/test/control-stack.test.ts
  • packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
  • packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
  • packages/1-framework/3-tooling/emitter/package.json
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/src/emit-types.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/1-framework/3-tooling/emitter/test/type-expression-safety.test.ts
  • packages/1-framework/3-tooling/emitter/tsdown.config.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • packages/2-sql/2-authoring/contract-ts/src/staged-contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/codec-types.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.ts
  • packages/2-sql/4-lanes/relational-core/src/types.ts
  • packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts
  • packages/2-sql/4-lanes/relational-core/test/schema.types.test-d.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/3-extensions/pgvector/src/core/codecs.ts
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts
  • packages/3-extensions/pgvector/src/types/codec-types.ts
  • packages/3-extensions/pgvector/test/codec-render-output-type.test.ts
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.ts
  • packages/3-targets/6-adapters/postgres/src/core/codecs.ts
  • packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
  • packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts
  • packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
  • packages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.ts
  • packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
  • test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
  • test/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

Comment thread docs/architecture docs/ADR-INDEX.md Resolved
@wmadden
wmadden force-pushed the tml-2204-typed-json-simplification-codec-dispatched-type-rendering branch from eaafc89 to 510f3d4 Compare April 8, 2026 10:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
packages/3-targets/6-adapters/postgres/src/core/codecs.ts (1)

520-528: ⚠️ Potential issue | 🟡 Minor

Incomplete 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) continue check on line 276 is unnecessary since Object.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 importing Codec at the top level.

Line 250 uses an inline type import import('./codec-types').Codec while CodecLookup is already imported from the same module at line 1. Moving Codec to 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

📥 Commits

Reviewing files that changed from the base of the PR and between eaafc89 and 510f3d4.

⛔ Files ignored due to path filters (5)
  • packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.md is excluded by !projects/**
  • projects/orm-consolidation/specs/codec-dispatched-type-rendering.md is excluded by !projects/**
  • test/e2e/framework/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
📒 Files selected for processing (56)
  • docs/architecture docs/ADR-INDEX.md
  • docs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.md
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/0-foundation/contract/src/domain-types.ts
  • packages/1-framework/1-core/framework-components/src/codec-types.ts
  • packages/1-framework/1-core/framework-components/src/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • packages/1-framework/1-core/framework-components/src/exports/components.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/1-core/framework-components/src/type-renderers.ts
  • packages/1-framework/1-core/framework-components/test/control-stack.test.ts
  • packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
  • packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
  • packages/1-framework/3-tooling/emitter/package.json
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/src/emit-types.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/1-framework/3-tooling/emitter/test/type-expression-safety.test.ts
  • packages/1-framework/3-tooling/emitter/tsdown.config.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • packages/2-sql/2-authoring/contract-ts/src/staged-contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/codec-types.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.ts
  • packages/2-sql/4-lanes/relational-core/src/types.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.ts
  • packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/3-extensions/pgvector/src/core/codecs.ts
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts
  • packages/3-extensions/pgvector/src/types/codec-types.ts
  • packages/3-extensions/pgvector/test/codec-render-output-type.test.ts
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.ts
  • packages/3-targets/6-adapters/postgres/src/core/codecs.ts
  • packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
  • packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts
  • packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
  • packages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.ts
  • packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
  • test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
  • test/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

@wmadden
wmadden force-pushed the tml-2204-typed-json-simplification-codec-dispatched-type-rendering branch from 510f3d4 to b9486cd Compare April 8, 2026 10:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 510f3d4 and b9486cd.

⛔ Files ignored due to path filters (5)
  • packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • projects/orm-consolidation/plans/codec-dispatched-type-rendering-plan.md is excluded by !projects/**
  • projects/orm-consolidation/specs/codec-dispatched-type-rendering.md is excluded by !projects/**
  • test/e2e/framework/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
📒 Files selected for processing (56)
  • docs/architecture docs/ADR-INDEX.md
  • docs/architecture docs/adrs/ADR 186 - Codec-dispatched type rendering.md
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/0-foundation/contract/src/domain-types.ts
  • packages/1-framework/1-core/framework-components/src/codec-types.ts
  • packages/1-framework/1-core/framework-components/src/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • packages/1-framework/1-core/framework-components/src/exports/components.ts
  • packages/1-framework/1-core/framework-components/src/exports/control.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/1-core/framework-components/src/type-renderers.ts
  • packages/1-framework/1-core/framework-components/test/control-stack.test.ts
  • packages/1-framework/1-core/framework-components/test/framework-components.renderer.test.ts
  • packages/1-framework/3-tooling/cli/src/control-api/contract-enrichment.ts
  • packages/1-framework/3-tooling/emitter/package.json
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/src/emit-types.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/src/type-expression-safety.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/1-framework/3-tooling/emitter/test/type-expression-safety.test.ts
  • packages/1-framework/3-tooling/emitter/tsdown.config.ts
  • packages/2-sql/1-core/contract/src/exports/types.ts
  • packages/2-sql/1-core/contract/src/types.ts
  • packages/2-sql/2-authoring/contract-ts/src/staged-contract-types.ts
  • packages/2-sql/2-authoring/contract-ts/test/fixtures/contract.d.ts
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/codec-types.ts
  • packages/2-sql/4-lanes/relational-core/src/ast/sql-codecs.ts
  • packages/2-sql/4-lanes/relational-core/src/types.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/codec-types.test.ts
  • packages/2-sql/4-lanes/relational-core/test/ast/sql-codecs.test.ts
  • packages/2-sql/4-lanes/relational-core/test/fixtures/contract.d.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/3-extensions/pgvector/src/core/codecs.ts
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts
  • packages/3-extensions/pgvector/src/types/codec-types.ts
  • packages/3-extensions/pgvector/test/codec-render-output-type.test.ts
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/sql-orm-client/test/generated-contract-types.test-d.ts
  • packages/3-extensions/sql-orm-client/test/value-object-inputs.test-d.ts
  • packages/3-targets/6-adapters/postgres/src/core/codecs.ts
  • packages/3-targets/6-adapters/postgres/src/core/descriptor-meta.ts
  • packages/3-targets/6-adapters/postgres/src/exports/codec-types.ts
  • packages/3-targets/6-adapters/postgres/src/exports/column-types.ts
  • packages/3-targets/6-adapters/postgres/test/codec-render-output-type.test.ts
  • packages/3-targets/6-adapters/postgres/test/descriptor-meta.test.ts
  • test/integration/test/authoring/parity/pgvector-named-type/expected.contract.json
  • test/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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts (1)

212-214: Consider consolidating assertions with toEqual.

Per coding guidelines, prefer object comparison using toEqual over property-by-property checks. A single toEqual assertion both verifies import is 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 toEqual or toMatchObject for assertions on objects, rather than property-by-property checks with toHaveProperty."

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between b9486cd and dd00ccd.

📒 Files selected for processing (1)
  • packages/1-framework/3-tooling/cli/test/control-api/contract-enrichment.test.ts

wmadden added 18 commits April 8, 2026 16:21
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.
wmadden added 20 commits April 8, 2026 16:22
…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.
@wmadden
wmadden force-pushed the tml-2204-typed-json-simplification-codec-dispatched-type-rendering branch from 7488bca to d433a3f Compare April 8, 2026 14:35
wmadden added 3 commits April 8, 2026 17:23
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.
@wmadden
wmadden merged commit 954b107 into main Apr 8, 2026
15 checks passed
@wmadden
wmadden deleted the tml-2204-typed-json-simplification-codec-dispatched-type-rendering branch April 8, 2026 15:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants