Repository navigation
feat(adapters): honor custom and parameterized codecs in control-path query encoding - #807
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR shifts Postgres and SQLite control adapters from optional ChangesCodec Registry and Adapter Wiring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4a2c2a8 to
146fb22
Compare
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/extension-supabase
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
146fb22 to
26060c3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/1-framework/1-core/framework-components/src/control/control-stack.ts (1)
354-364: 💤 Low valueValidation failures produce misleading error messages.
When
paramsSchemavalidation fails (line 360),getForRefreturnsundefined, causing downstream code to throwRUNTIME.CODEC_DESCRIPTOR_MISSINGwith message "No codec descriptor registered for codecId". The actual issue is invalidtypeParams, not a missing descriptor.Consider logging validation issues before returning
undefinedto 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
📒 Files selected for processing (25)
packages/1-framework/1-core/framework-components/src/control/control-stack.tspackages/1-framework/1-core/framework-components/src/shared/codec-types.tspackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/1-framework/2-authoring/psl-parser/test/parser.test.tspackages/1-framework/3-tooling/cli/test/config-types.test.tspackages/1-framework/3-tooling/emitter/test/domain-type-generation.test.tspackages/2-mongo-family/2-authoring/contract-psl/test/derive-json-schema.test.tspackages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.tspackages/2-mongo-family/2-authoring/contract-psl/test/interpreter.test.tspackages/2-sql/2-authoring/contract-psl/test/fixtures.tspackages/2-sql/2-authoring/contract-psl/test/provider.test.tspackages/2-sql/2-authoring/contract-ts/test/config-types.test.tspackages/2-sql/2-authoring/contract-ts/test/contract-builder.contract-definition.test.tspackages/2-sql/2-authoring/contract-ts/test/contract-builder.value-objects.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.typeref-resolver.test.tspackages/3-mongo-target/1-mongo-target/test/mongo-runner.polymorphism.integration.test.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.tspackages/3-targets/6-adapters/postgres/test/raw-expr-lowering.test.tspackages/3-targets/6-adapters/postgres/test/sql-renderer-namespace-qualification.test.tspackages/3-targets/6-adapters/postgres/test/sql-renderer.cast-policy.test.tspackages/3-targets/6-adapters/sqlite/src/core/control-adapter.tspackages/3-targets/6-adapters/sqlite/src/exports/control.tspackages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.tstest/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
….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]>
26060c3 to
73edd41
Compare
…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]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/1-framework/1-core/framework-components/src/shared/runtime-error.ts (1)
28-42: ⚡ Quick winAvoid bare
ascast per coding guidelines.Line 29 uses a bare
as RuntimeErrorEnvelopecast on the Error before properties are assigned. The guidelines require usingblindCast<T, "Reason">orcastAs<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
messageassignment on line 39 is redundant sinceError(message)already sets themessageproperty.🤖 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
📒 Files selected for processing (7)
packages/1-framework/1-core/framework-components/src/execution/runtime-error.tspackages/1-framework/1-core/framework-components/src/shared/resolve-codec.tspackages/1-framework/1-core/framework-components/src/shared/runtime-error.tspackages/2-sql/5-runtime/src/codecs/ast-codec-registry.tspackages/2-sql/5-runtime/src/exports/index.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/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
left a comment
There was a problem hiding this comment.
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]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/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
📒 Files selected for processing (53)
packages/1-framework/1-core/framework-components/src/control/control-stack.tspackages/1-framework/1-core/framework-components/src/execution/runtime-error.tspackages/1-framework/1-core/framework-components/src/exports/codec.tspackages/1-framework/1-core/framework-components/src/shared/codec-types.tspackages/3-extensions/pgvector/test/migrations/planner.behavior.test.tspackages/3-extensions/pgvector/test/migrations/planner.contract-to-schema-ir.test.tspackages/3-extensions/pgvector/test/migrations/planner.storage-types.test.tspackages/3-targets/6-adapters/postgres/src/core/adapter.tspackages/3-targets/6-adapters/postgres/src/core/codec-lookup.tspackages/3-targets/6-adapters/postgres/src/core/control-adapter.tspackages/3-targets/6-adapters/postgres/src/core/types.tspackages/3-targets/6-adapters/postgres/src/exports/control.tspackages/3-targets/6-adapters/postgres/test/control-adapter.check-constraints.test.tspackages/3-targets/6-adapters/postgres/test/control-adapter.defaults.test.tspackages/3-targets/6-adapters/postgres/test/control-adapter.test.tspackages/3-targets/6-adapters/postgres/test/ddl-create-table-lowering.test.tspackages/3-targets/6-adapters/postgres/test/ddl-table-constraints-lowering.test.tspackages/3-targets/6-adapters/postgres/test/lower-to-execute-request.test.tspackages/3-targets/6-adapters/postgres/test/marker-ledger-writes.test.tspackages/3-targets/6-adapters/postgres/test/migrations/data-transform.test.tspackages/3-targets/6-adapters/postgres/test/migrations/fixtures/runner-fixtures.tspackages/3-targets/6-adapters/postgres/test/migrations/marker-ledger-writes.integration.test.tspackages/3-targets/6-adapters/postgres/test/migrations/marker-table-ddl.test.tspackages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.construction.test.tspackages/3-targets/6-adapters/postgres/test/migrations/op-factory-call.lowering.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.codec-field-event.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.cross-space-fk-ddl.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.fk-config.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.reconciliation.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.referential-actions.test.tspackages/3-targets/6-adapters/postgres/test/migrations/planner.semantic-satisfaction.test.tspackages/3-targets/6-adapters/postgres/test/migrations/render-typescript.roundtrip.test.tspackages/3-targets/6-adapters/postgres/test/migrations/runner.ledger.integration.test.tspackages/3-targets/6-adapters/sqlite/src/core/adapter.tspackages/3-targets/6-adapters/sqlite/src/core/codec-lookup.tspackages/3-targets/6-adapters/sqlite/src/core/control-adapter.tspackages/3-targets/6-adapters/sqlite/src/exports/control.tspackages/3-targets/6-adapters/sqlite/test/control-adapter.test.tspackages/3-targets/6-adapters/sqlite/test/ddl-table-constraints-lowering.test.tspackages/3-targets/6-adapters/sqlite/test/lower-to-execute-request.test.tspackages/3-targets/6-adapters/sqlite/test/marker-ledger-writes.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/create-table-call-lowering.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/fixtures/runner-fixtures.tspackages/3-targets/6-adapters/sqlite/test/migrations/planner-introspection.integration.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/planner.codec-field-event.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/planner.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/render-typescript.roundtrip.test.tspackages/3-targets/6-adapters/sqlite/test/migrations/runner.ledger.test.tstest/e2e/framework/test/sqlite/migrations/harness.tstest/integration/test/cross-package/postgres-control-policy-planner.test.tstest/integration/test/cross-package/postgres-issue-planner.test.tstest/integration/test/migration-ledger/ledger-operation-count-parity.test.tstest/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
…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]>
At a glance
A migration backfills an encrypted column:
ssnuses a custom codec — say a CipherStash-style encrypting codec, or a parameterized one likepg/vector@1. When the runner lowers this step for execution, the literal'123-45-6789'has to be encoded byssn'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:The query branch of
lowerToExecuteRequest— the path a PostgresdataTransformtakes — now resolves each parameter's codec throughgetForRefand encodes with it, instead of falling back to a builtin-only registry.Why the query branch was the gap
lowerToExecuteRequesthas two branches, and only one of them was already correct.CREATE TABLE) resolves codecs through the injectedCodecLookup, so a custom default already worked on Postgres.UPDATE … WHEREadataTransformlowers) did not. It encoded params through aCONTROL_CODECSregistry 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
getwasn't enough: parameterized codecsCodecLookupalready has aget(id), so the tempting shortcut isforCodecRef: ref => codecLookup.get(ref.codecId). It doesn't hold up for the case that matters.getreturns 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@1needs itslength; a per-column encrypting codec needs its key reference. For those,geteither 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'stypeParamsagainst 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:extractCodecLookupbuilds theCodecLookupfrom them, sogetForRefjust 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.codecLookupinto 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
CodecLookupimplementor: the two real ones resolve faithfully (the builtin lookups delegate toextractCodecLookup), and the inline stubs in tests gain agetForRef: () => undefined.buildContractCodecRegistrystays private; no new exports.Verification
pnpm typecheck— 138 tasks passpnpm test:packages— 801 files pass (the two flaky PGlite integration tests are unrelated)pnpm lint:packages— 67 tasks passpnpm lint:casts— delta 0pnpm fixtures:check— cleanpnpm lint:deps— cleanAlternatives considered
codecDescriptorsarray toControlStack, passed it as a second adapter constructor argument, and exportedbuildContractCodecRegistryfor the adapters to call. Dropped: it adds a second injected input alongsideCodecLookup, whenCodecLookupis already built from those same descriptors. One handle, expanded, beats two carrying overlapping information.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.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Refactoring