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

feat(adapters): honor custom and parameterized codecs in control-path query encoding - #807

Merged
wmadden-electric merged 7 commits into
mainfrom
control-query-extension-codecs
Jun 11, 2026
Merged

wmadden-electric merged 7 commits into
mainfrom
control-query-extension-codecs

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

At a glance

A migration backfills an encrypted column:

dataTransform({
  id: 'data_migration.backfill-ssn',
  table: 'user',
  run: () => db.user.update({ ssn: '123-45-6789' }).where(({ ssn }) => ssn.isNull()),
})

ssn uses a custom codec — say a CipherStash-style encrypting codec, or a parameterized one like pg/vector@1. When the runner lowers this step for execution, the literal '123-45-6789' has to be encoded by ssn's codec before it reaches the driver.

Before: it threw RUNTIME.CODEC_DESCRIPTOR_MISSING. The control path could only encode the builtin codecs (text, int, jsonb, …); it had no entry for a custom or parameterized one.

After: the column's actual codec runs, and the encrypted wire value is what the driver receives.

This is latent today — no custom codec ships yet — so nothing is broken in practice. The point is to unblock them: an encrypted column simply can't be the target of a migration backfill until this works.

The decision

The control adapter already receives a CodecLookup — the injected handle it uses to resolve a column's codec. Rather than introduce a second way to get codecs, we expand that one interface with a params-aware resolver:

interface CodecLookup {
  get(id): Codec | undefined;                          // existing — a representative, empty-params instance
  getForRef(id, typeParams): Codec | undefined;        // new — the real codec for this column's params
  // …targetTypesFor, metaFor, renderOutputTypeFor
}

The query branch of lowerToExecuteRequest — the path a Postgres dataTransform takes — now resolves each parameter's codec through getForRef and encodes with it, instead of falling back to a builtin-only registry.

Why the query branch was the gap

lowerToExecuteRequest has two branches, and only one of them was already correct.

  • The DDL branch (column defaults in CREATE TABLE) resolves codecs through the injected CodecLookup, so a custom default already worked on Postgres.
  • The query branch (the UPDATE … WHERE a dataTransform lowers) did not. It encoded params through a CONTROL_CODECS registry built from the target's builtin codec list. A column whose codec wasn't builtin had no entry there, so encoding threw.

So the fix is to make the query branch resolve codecs the same way the DDL branch already does — through the one injected lookup.

Why get wasn't enough: parameterized codecs

CodecLookup already has a get(id), so the tempting shortcut is forCodecRef: ref => codecLookup.get(ref.codecId). It doesn't hold up for the case that matters.

get returns a representative codec built with empty params. That's fine for a codec whose behavior doesn't depend on its params, and wrong for one that does: pg/vector@1 needs its length; a per-column encrypting codec needs its key reference. For those, get either hands back a misconfigured instance or — when the factory requires params — returns nothing at all.

getForRef(id, typeParams) is the faithful version. It validates the column's typeParams against the codec's schema and calls the factory with them, producing the exact codec the column uses. And the descriptors it needs are already in hand: extractCodecLookup builds the CodecLookup from them, so getForRef just keeps them and resolves on demand.

A second gap this closes: SQLite parity

The SQLite control adapter was constructed with no codec lookup at all — builtin-only even for its DDL branch. Threading stack.codecLookup into its construction (needed anyway for the query branch) closes that too: SQLite DDL defaults now honor custom codecs the same way Postgres already did.

Scope

Follow-up to #794, which routed DDL default literals through codecs. Expanding the interface ripples to every CodecLookup implementor: the two real ones resolve faithfully (the builtin lookups delegate to extractCodecLookup), and the inline stubs in tests gain a getForRef: () => undefined. buildContractCodecRegistry stays private; no new exports.

Verification

  • pnpm typecheck — 138 tasks pass
  • pnpm test:packages — 801 files pass (the two flaky PGlite integration tests are unrelated)
  • pnpm lint:packages — 67 tasks pass
  • pnpm lint:casts — delta 0
  • pnpm fixtures:check — clean
  • pnpm lint:deps — clean

Alternatives considered

  • Thread the descriptors as a separate channel. The first cut added a codecDescriptors array to ControlStack, passed it as a second adapter constructor argument, and exported buildContractCodecRegistry for the adapters to call. Dropped: it adds a second injected input alongside CodecLookup, when CodecLookup is already built from those same descriptors. One handle, expanded, beats two carrying overlapping information.
  • Bridge through get. forCodecRef: ref => codecLookup.get(ref.codecId) — covered above. It drops params, so parameterized and key-bearing codecs resolve wrong or not at all, which is the exact failure this PR removes.
  • Leave it builtin-only. The query branch only ever sees builtin codecs today, so nothing breaks in practice. Rejected because this slice exists for custom codecs: shipping a control path that silently can't encode them — while the DDL branch can — bakes in an asymmetry the next person would have to rediscover.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added enhanced codec registry system supporting descriptor lookup and materialization with validation.
    • Improved extension codec handling with proper descriptor resolution and type validation.
  • Bug Fixes

    • Enhanced error handling for missing codec descriptors with descriptive runtime errors.
    • Added type parameter validation for parameterized codecs with synchronous validation enforcement.
  • Refactoring

    • Centralized runtime error handling abstraction.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 10, 2026 22:11
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR shifts Postgres and SQLite control adapters from optional CodecLookup defaults to required CodecRegistry instances, centralizes codec type-parameter validation and materialization, and updates all test instantiation sites to explicitly provide builtin codec lookup builders.

Changes

Codec Registry and Adapter Wiring

Layer / File(s) Summary
Shared runtime error envelope
packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts, packages/1-framework/1-core/framework-components/src/execution/runtime-error.ts
RuntimeErrorEnvelope interface, isRuntimeError type guard, and runtimeError factory are defined in shared utilities and re-exported from execution; internal resolveCategory derives category from code prefix.
Codec materialization and type-parameter validation
packages/1-framework/1-core/framework-components/src/shared/resolve-codec.ts, packages/2-sql/5-runtime/src/codecs/ast-codec-resolver.ts, packages/1-framework/1-core/framework-components/src/exports/codec.ts
validateCodecTypeParams normalizes and validates via descriptor schema; materializeCodec validates then invokes factory; AST resolver delegates to materializeCodec while caching codec instances; exports extended to include both functions and CodecRegistry type.
CodecRegistry interface and codec-types
packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
CodecRegistry extends CodecLookup with forCodecRef (materialize codec from CodecRef) and forColumn (resolve codec by column coordinate); CodecLookup.get documentation clarified for parameterized codec ids.
Control stack extractCodecLookup implementation
packages/1-framework/1-core/framework-components/src/control/control-stack.ts
extractCodecLookup now indexes descriptors by codecId, returns CodecRegistry, and implements forCodecRef to resolve and materialize codecs or throw RUNTIME.CODEC_DESCRIPTOR_MISSING; ControlStack.codecLookup typed as CodecRegistry.
PostgresControlAdapter CodecRegistry integration
packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts, packages/3-targets/6-adapters/postgres/src/core/types.ts, packages/3-targets/6-adapters/postgres/src/core/codec-lookup.ts, packages/3-targets/6-adapters/postgres/src/core/adapter.ts
Constructor now requires CodecRegistry (not optional CodecLookup); lower() uses registry for SQL rendering; lowerToExecuteRequest derives ContractCodecRegistry and passes explicitly to encodeControlQueryParams; createPostgresBuiltinCodecLookup return type updated to CodecRegistry.
SqliteControlAdapter CodecRegistry integration
packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts, packages/3-targets/6-adapters/sqlite/src/core/codec-lookup.ts, packages/3-targets/6-adapters/sqlite/src/core/adapter.ts, packages/3-targets/6-adapters/sqlite/src/exports/control.ts
Constructor now requires CodecRegistry; lowerToExecuteRequest routes DDL through sqliteRenderDdlExecuteRequest with registry and derives ContractCodecRegistry for parameter encoding; createSqliteBuiltinCodecLookup builder added; SqliteAdapterImpl and descriptor factory wired to use builtin lookup.
Postgres test fixtures and adapter instantiation
packages/3-targets/6-adapters/postgres/test/..., packages/3-extensions/pgvector/test/..., test/integration/test/...
All Postgres test files updated to construct PostgresControlAdapter with explicit createPostgresBuiltinCodecLookup() calls; includes introspection, DDL lowering, marker/ledger, migration planner, and integration test suites.
SQLite test fixtures and adapter instantiation
packages/3-targets/6-adapters/sqlite/test/..., test/e2e/framework/test/sqlite/..., test/integration/test/...
All SQLite test files updated to construct SqliteControlAdapter with explicit createSqliteBuiltinCodecLookup() calls; includes introspection, DDL lowering, marker/ledger, migration planner, and integration test suites.
Extension codec end-to-end integration tests
packages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.ts, packages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.ts
Postgres and SQLite tests add ExtTransformDescriptor and extension-backed contracts; verify extension codec encoding in wire output and error handling for missing descriptors; transformingLookup test doubles updated to CodecRegistry interface.
Cross-suite integration test adapter setup
test/integration/test/..., test/e2e/framework/...
Integration tests (pgvector migrations, cross-package planners, ledger parity, bootstrap) updated to construct adapters with explicit builtin codec lookup factories.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • prisma/prisma-next#397: Adjusts Postgres lowering/rendering to thread codec-derived metadata through the adapter and throw on missing codec ids.
  • prisma/prisma-next#794: Related to the codec-routed DDL/default and marker/ledger lowering flow that depends on the CodecRegistry and forCodecRef materialization.

Suggested reviewers

  • wmadden
  • SevInf

Poem

🐰 A rabbit hops through codec dreams so bright,
With registries and refs now burning light,
Type params dance where validation flows,
And adapters stride where codec magic grows,
SQL whispers sweet through contract's call—
Materialized codecs: we've got it all! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely summarizes the main objective: enabling control-path query encoding to use custom and parameterized codecs instead of builtin-only codecs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 control-query-extension-codecs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@wmadden-electric
wmadden-electric force-pushed the control-query-extension-codecs branch from 4a2c2a8 to 146fb22 Compare June 10, 2026 22:22
@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: cfe1b82

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 154.15 KB (+0.14% 🔺)
postgres / emit 121.51 KB (+0.18% 🔺)
mongo / no-emit 76.8 KB (+0.01% 🔺)
mongo / emit 70.95 KB (-0.02% 🔽)
cf-worker / no-emit 183.13 KB (+0.13% 🔺)
cf-worker / emit 147.21 KB (+0.14% 🔺)

@wmadden-electric
wmadden-electric force-pushed the control-query-extension-codecs branch from 146fb22 to 26060c3 Compare June 11, 2026 06:25
@wmadden-electric wmadden-electric changed the title feat(adapters): thread stack codec descriptors through control adapter query encoding feat(adapters): honor extension codecs in control-path query encoding via CodecLookup.getForRef Jun 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/1-framework/1-core/framework-components/src/control/control-stack.ts (1)

354-364: 💤 Low value

Validation failures produce misleading error messages.

When paramsSchema validation fails (line 360), getForRef returns undefined, causing downstream code to throw RUNTIME.CODEC_DESCRIPTOR_MISSING with message "No codec descriptor registered for codecId". The actual issue is invalid typeParams, not a missing descriptor.

Consider logging validation issues before returning undefined to aid debugging:

if (result.issues) {
  console.warn(`Codec param validation failed for '${id}':`, result.issues);
  return undefined;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/1-framework/1-core/framework-components/src/control/control-stack.ts`
around lines 354 - 364, getForRef currently swallows paramsSchema validation
failures and returns undefined, which leads callers to misinterpret the problem
as a missing descriptor; update getForRef (use descriptorsById,
d.paramsSchema['~standard'] and d.factory) to surface the validation details
before returning by logging or attaching the validation issues (e.g., log a
clear message including the descriptor id and result.issues) so callers can
distinguish invalid typeParams from a missing descriptor; keep the existing
undefined return but ensure the validation errors are emitted (or consider
returning/throwing a more specific error) immediately after detecting
result.issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/1-framework/1-core/framework-components/src/control/control-stack.ts`:
- Around line 354-364: The getForRef method currently masks caller-provided
typeParams for non-parameterized codecs and converts null/undefined for
parameterized ones, causing invalid params to bypass validation; update
getForRef (referencing descriptorsById, d.isParameterized,
d.paramsSchema['~standard'], and d.factory) to pass the incoming typeParams
directly into the validator (i.e., use typeParams as the rawParams) so the
schema itself can apply defaults and validate, keeping the existing Promise and
issues checks and the subsequent d.factory(result.value) invocation unchanged.

---

Nitpick comments:
In
`@packages/1-framework/1-core/framework-components/src/control/control-stack.ts`:
- Around line 354-364: getForRef currently swallows paramsSchema validation
failures and returns undefined, which leads callers to misinterpret the problem
as a missing descriptor; update getForRef (use descriptorsById,
d.paramsSchema['~standard'] and d.factory) to surface the validation details
before returning by logging or attaching the validation issues (e.g., log a
clear message including the descriptor id and result.issues) so callers can
distinguish invalid typeParams from a missing descriptor; keep the existing
undefined return but ensure the validation errors are emitted (or consider
returning/throwing a more specific error) immediately after detecting
result.issues.
🪄 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: 0304fe38-21fa-4b6e-8463-61eb45cd894c

📥 Commits

Reviewing files that changed from the base of the PR and between 146fb22 and 26060c3.

📒 Files selected for processing (25)
  • packages/1-framework/1-core/framework-components/src/control/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
  • packages/1-framework/1-core/framework-components/test/control-stack.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/parser.test.ts
  • packages/1-framework/3-tooling/cli/test/config-types.test.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/fixtures.ts
  • packages/2-sql/2-authoring/contract-psl/test/provider.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/config-types.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract-builder.contract-definition.test.ts
  • packages/2-sql/2-authoring/contract-ts/test/contract-builder.value-objects.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.typeref-resolver.test.ts
  • packages/3-mongo-target/1-mongo-target/test/mongo-runner.polymorphism.integration.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.ts
  • packages/3-targets/6-adapters/postgres/test/raw-expr-lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/sql-renderer-namespace-qualification.test.ts
  • packages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/exports/control.ts
  • packages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.ts
  • test/integration/test/mongo/migration-psl-authoring.test.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/3-targets/6-adapters/postgres/test/raw-expr-lowering.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.typeref-resolver.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.ts
  • packages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.ts

@wmadden-electric wmadden-electric changed the title feat(adapters): honor extension codecs in control-path query encoding via CodecLookup.getForRef feat(adapters): honor custom and parameterized codecs in control-path query encoding Jun 11, 2026
….getForRef

Extract shared validateCodecTypeParams + materializeCodec into
framework-components/src/shared/resolve-codec.ts. Both
createAstCodecResolver.forCodecRef and extractCodecLookup.getForRef now
delegate to materializeCodec, eliminating the duplicated validation logic.
Previously getForRef swallowed validation failures (returning undefined for
bad params instead of throwing RUNTIME.TYPE_PARAMS_INVALID); now it throws,
matching the runtime resolver's behavior.

Co-Authored-By: Will Madden <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric force-pushed the control-query-extension-codecs branch from 26060c3 to 73edd41 Compare June 11, 2026 08:03
wmadden added 2 commits June 11, 2026 10:30
…resolve-codec clone

RuntimeErrorEnvelope, runtimeError, isRuntimeError live in
framework-components/src/shared/runtime-error.ts (shared plane), so the
shared resolver can import them directly.

execution/runtime-error.ts re-exports the shared symbols so all existing
import paths (@prisma-next/framework-components/runtime and any direct
../execution/runtime-error imports) keep working unchanged.

resolve-codec.ts deletes the hand-rolled typeParamsInvalidError clone and
calls runtimeError('RUNTIME.TYPE_PARAMS_INVALID', ...) directly. Error
envelopes are structurally identical to before: same code, category,
severity, and details fields.

Co-Authored-By: Will Madden <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…istry in adapters

Both PostgresControlAdapter.lowerToExecuteRequest and
SqliteControlAdapter.lowerToExecuteRequest built the same inline
ContractCodecRegistry object: forColumn always returns undefined,
forCodecRef delegates to lookup.getForRef and throws
RUNTIME.CODEC_DESCRIPTOR_MISSING for unknown ids.

contractCodecRegistryFromLookup(lookup) in sql-runtime encapsulates that
pattern once. Both adapters now call it instead of the inline block,
removing the duplicate.

createAstCodecRegistry is left unchanged: it wraps a CodecDescriptorRegistry
(not a CodecLookup) and adds a content-keyed cache via AstCodecResolver, so
a shared inner helper would require forcing a common shape that doesn't
exist. The two adapters and createAstCodecRegistry are structurally related
but not mechanically unifiable without contortion.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts (1)

28-42: ⚡ Quick win

Avoid bare as cast per coding guidelines.

Line 29 uses a bare as RuntimeErrorEnvelope cast on the Error before properties are assigned. The guidelines require using blindCast<T, "Reason"> or castAs<T> from @prisma-next/utils/casts.

A cleaner alternative avoids the cast entirely by leveraging Object.assign's return type:

♻️ Proposed refactor to eliminate the cast
 export function runtimeError(
   code: string,
   message: string,
   details?: Record<string, unknown>,
 ): RuntimeErrorEnvelope {
-  const error = new Error(message) as RuntimeErrorEnvelope;
+  const error = new Error(message);
   Object.defineProperty(error, 'name', {
     value: 'RuntimeError',
     configurable: true,
   });

-  return Object.assign(error, {
+  return Object.assign(error as Error & { name: string }, {
     code,
     category: resolveCategory(code),
     severity: 'error' as const,
-    message,
     details,
-  });
+  }) as RuntimeErrorEnvelope;
 }

Or use the cast utilities:

+import { castAs } from '`@prisma-next/utils/casts`';
+
 export function runtimeError(
   code: string,
   message: string,
   details?: Record<string, unknown>,
 ): RuntimeErrorEnvelope {
-  const error = new Error(message) as RuntimeErrorEnvelope;
+  const error = new Error(message);
   Object.defineProperty(error, 'name', {
     value: 'RuntimeError',
     configurable: true,
   });

-  return Object.assign(error, {
+  return castAs<RuntimeErrorEnvelope>(Object.assign(error, {
     code,
     category: resolveCategory(code),
     severity: 'error' as const,
-    message,
     details,
-  });
+  }));
 }

Note: The explicit message assignment on line 39 is redundant since Error(message) already sets the message property.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts`
around lines 28 - 42, Replace the bare "as RuntimeErrorEnvelope" cast on the
Error instance by using the provided cast utilities (blindCast<T,"Reason"> or
castAs<T>) from `@prisma-next/utils/casts` or by relying on Object.assign's
inferred return type when constructing the RuntimeErrorEnvelope in the function
that returns RuntimeErrorEnvelope; specifically update the Error(message)
assignment in this function to avoid "as RuntimeErrorEnvelope" and remove the
redundant explicit message property in the Object.assign call, while keeping
assignments for code, category (resolveCategory(code)), severity, and details.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts`:
- Around line 28-42: Replace the bare "as RuntimeErrorEnvelope" cast on the
Error instance by using the provided cast utilities (blindCast<T,"Reason"> or
castAs<T>) from `@prisma-next/utils/casts` or by relying on Object.assign's
inferred return type when constructing the RuntimeErrorEnvelope in the function
that returns RuntimeErrorEnvelope; specifically update the Error(message)
assignment in this function to avoid "as RuntimeErrorEnvelope" and remove the
redundant explicit message property in the Object.assign call, while keeping
assignments for code, category (resolveCategory(code)), severity, and details.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7f1dfb2d-2af0-4d54-a2e5-d35c621526eb

📥 Commits

Reviewing files that changed from the base of the PR and between 73edd41 and dc23202.

📒 Files selected for processing (7)
  • packages/1-framework/1-core/framework-components/src/execution/runtime-error.ts
  • packages/1-framework/1-core/framework-components/src/shared/resolve-codec.ts
  • packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts
  • packages/2-sql/5-runtime/src/codecs/ast-codec-registry.ts
  • packages/2-sql/5-runtime/src/exports/index.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/1-framework/1-core/framework-components/src/shared/resolve-codec.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts

…okup with CodecRegistry

Introduce `CodecRegistry extends CodecLookup` with `forCodecRef(ref)` and
`forColumn()`. `extractCodecLookup` now returns `CodecRegistry` directly,
so the single object built once is what adapters hold and pass by reference.

- Delete `contractCodecRegistryFromLookup` and the `getForRef` member it
  relied on; adapters use `blindCast<ContractCodecRegistry>` at the SQL
  boundary instead of rebuilding a wrapper each call.
- `ControlStack.codecLookup` field type widened to `CodecRegistry`.
- Adapter constructors and `PostgresAdapterOptions.codecLookup` now typed
  as `CodecRegistry`; internal DDL helpers keep `CodecLookup` params.
- Remove 22 `getForRef: () => undefined` stubs from test files.

Signed-off-by: Will Madden <[email protected]>

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Address all outstanding comments then queue for merge

…tore runtimeAborted return type

Addresses two review comments on PR #807:
1. Restore explicit `RuntimeErrorEnvelope` return type on `runtimeAborted`.
2. Remove the `?? createBuiltinCodecLookup()` fallback from both
   `PostgresControlAdapter` and `SqliteControlAdapter` constructors,
   making `CodecRegistry` a required argument. Move
   `createSqliteBuiltinCodecLookup` into a new `codec-lookup.ts` module
   mirroring the postgres pattern, export both helpers from the adapter
   `/control` entrypoints, and update all construction sites
   (production + tests) to pass builtins explicitly.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts`:
- Line 168: Replace the bare TypeScript cast "context.contract as
PostgresContract" used when calling renderLoweredSql with the repo-approved
helper (e.g., blindCast<T,"Reason"> or castAs<T>) to avoid an untyped assertion;
update the call site in control-adapter.ts (the invocation of renderLoweredSql
with context.contract and this.codecRegistry) to cast context.contract using
blindCast<PostgresContract,"contract is PostgresContract here"> or
castAs<PostgresContract> so the code follows the no-bare-as rule.
🪄 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: c72a85cb-345f-424a-a5ad-9416b431eb6a

📥 Commits

Reviewing files that changed from the base of the PR and between dc23202 and 999097e.

📒 Files selected for processing (53)
  • packages/1-framework/1-core/framework-components/src/control/control-stack.ts
  • packages/1-framework/1-core/framework-components/src/execution/runtime-error.ts
  • packages/1-framework/1-core/framework-components/src/exports/codec.ts
  • packages/1-framework/1-core/framework-components/src/shared/codec-types.ts
  • packages/3-extensions/pgvector/test/migrations/planner.behavior.test.ts
  • packages/3-extensions/pgvector/test/migrations/planner.contract-to-schema-ir.test.ts
  • packages/3-extensions/pgvector/test/migrations/planner.storage-types.test.ts
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/codec-lookup.ts
  • packages/3-targets/6-adapters/postgres/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/postgres/src/core/types.ts
  • packages/3-targets/6-adapters/postgres/src/exports/control.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.check-constraints.test.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.defaults.test.ts
  • packages/3-targets/6-adapters/postgres/test/control-adapter.test.ts
  • packages/3-targets/6-adapters/postgres/test/ddl-create-table-lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/ddl-table-constraints-lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.ts
  • packages/3-targets/6-adapters/postgres/test/marker-ledger-writes.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/data-transform.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/marker-ledger-writes.integration.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/marker-table-ddl.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.construction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.lowering.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.codec-field-event.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.cross-space-fk-ddl.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/postgres/test/migrations/runner.ledger.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/core/codec-lookup.ts
  • packages/3-targets/6-adapters/sqlite/src/core/control-adapter.ts
  • packages/3-targets/6-adapters/sqlite/src/exports/control.ts
  • packages/3-targets/6-adapters/sqlite/test/control-adapter.test.ts
  • packages/3-targets/6-adapters/sqlite/test/ddl-table-constraints-lowering.test.ts
  • packages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.ts
  • packages/3-targets/6-adapters/sqlite/test/marker-ledger-writes.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/create-table-call-lowering.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.codec-field-event.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/planner.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/render-typescript.roundtrip.test.ts
  • packages/3-targets/6-adapters/sqlite/test/migrations/runner.ledger.test.ts
  • test/e2e/framework/test/sqlite/migrations/harness.ts
  • test/integration/test/cross-package/postgres-control-policy-planner.test.ts
  • test/integration/test/cross-package/postgres-issue-planner.test.ts
  • test/integration/test/migration-ledger/ledger-operation-count-parity.test.ts
  • test/integration/test/postgres-bootstrap.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/3-targets/6-adapters/postgres/src/core/adapter.ts
  • packages/3-targets/6-adapters/sqlite/test/marker-ledger-writes.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/3-targets/6-adapters/sqlite/src/exports/control.ts
  • packages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.ts
  • packages/1-framework/1-core/framework-components/src/execution/runtime-error.ts

wmadden and others added 2 commits June 11, 2026 13:08
…for upgrade-coverage

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…deRabbit)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit 622a001 Jun 11, 2026
20 checks passed
@wmadden-electric
wmadden-electric deleted the control-query-extension-codecs branch June 11, 2026 11:49
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