Repository navigation
TML-1808 3: Emission plumbing for parameterized types - #97
Conversation
WalkthroughRemoved four planning documents and added end-to-end support for parameterized codec type imports: descriptors now declare parameterized imports, the SQL family extracts and forwards them through emission, and emitter/generator deduplicate and emit those imports into contract.d.ts. Changes
Sequence Diagram(s)mermaid Descriptor->>Assembly: provide descriptors (including types.codecTypes.parameterizedImports) 📜 Recent review detailsConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Lite 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (25)**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/use-correct-tools.mdc)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/use-correct-tools.mdc)
Files:
packages/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/control-plane-descriptors.mdc)
Files:
packages/{2-sql,sql}/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/include-many-patterns.mdc)
Files:
packages/**/src/**📄 CodeRabbit inference engine (.cursor/rules/multi-plane-entrypoints.mdc)
Files:
packages/**📄 CodeRabbit inference engine (.cursor/rules/no-backward-compatibility.md)
Files:
packages/**/*.{js,ts,tsx,jsx}📄 CodeRabbit inference engine (.cursor/rules/no-backward-compatibility.md)
Files:
packages/**/src/index.ts📄 CodeRabbit inference engine (.cursor/rules/no-barrel-files.mdc)
Files:
{packages,examples,test}/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/object-hasown.mdc)
Files:
packages/{2-sql,3-targets}/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/postgres-lateral-patterns.mdc)
Files:
packages/**/src/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/shared-plane-packages.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/shared-plane-packages.mdc)
Files:
{packages/2-sql/**,packages/3-targets/**,examples/**,test/**}/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/sql-types-imports.mdc)
Files:
**/*.{ts,tsx,test-d.ts}📄 CodeRabbit inference engine (.cursor/rules/validate-contract-usage.mdc)
Files:
**/!(*.test|*.test-d|*.spec).ts?(x)📄 CodeRabbit inference engine (.cursor/rules/validate-contract-usage.mdc)
Files:
{packages,test,examples}/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/arktype-usage.mdc)
Files:
{packages,examples,test}/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/no-target-branches.mdc)
Files:
{packages,test,examples}/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/prefer-assertions-over-defensive-checks.mdc)
Files:
packages/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/prefer-assertions-over-defensive-checks.mdc)
Files:
{packages/2-sql,packages/sql,examples,test}/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/query-patterns.mdc)
Files:
{packages,examples}/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/type-predicates.mdc)
Files:
packages/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/README.md)
Files:
**/*.{sql,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/README.md)
Files:
**/index.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/README.md)
Files:
packages/{2-sql,3-targets}/**📄 CodeRabbit inference engine (.cursor/rules/directory-layout.mdc)
Files:
🧠 Learnings (1)📚 Learning: 2025-12-26T23:02:40.679ZApplied to files:
🧬 Code graph analysis (1)packages/2-sql/3-tooling/emitter/src/index.ts (1)
🔇 Additional comments (3)
Comment |
ea950a9 to
e3adb15
Compare
Update emission API surfaces to include parameterized codec info: - Add parameterizedCodecs to EmitOptions (Map<codecId, descriptor>) - Add parameterizedCodecs to ValidationContext - Add GenerateContractTypesOptions interface for structured options - Update TargetFamilyHook.generateContractTypes signature with optional options - Update emit() to pass parameterizedCodecs to both validateTypes and generateContractTypes Update SQL family hook to accept the new options parameter. Update SQL family instance to extract and pass parameterized codecs: - Call extractParameterizedCodecs during instance creation - Pass parameterizedCodecs to emit() calls Add tests proving: - parameterizedCodecs are passed to generateContractTypes options - parameterizedCodecs are passed to ValidationContext Part of TML-1808: Parameterized column types
- Add emit-parameterized.test.ts with integration tests covering: - typesImport from parameterizedCodecs appears in contract.d.ts - Multiple parameterized codecs from different packages - Multiple named exports from the same package - Update SQL emitter generateContractTypes to: - Extract typesImport from parameterizedCodecs in options - Add them to the import list with deduplication - Omit redundant "as Alias" when named === alias This completes the Phase 3 plumbing by ensuring parameterized type imports flow from family instance through to emitted contract.d.ts.
Replace verbose ternary conditional spread patterns with ifDefined() utility for cleaner, more readable code. Also removes duplicate GenerateContractTypesOptions interface that was causing type conflicts. The correct interface has only parameterizedRenderers, since codecTypeImports and operationTypeImports are passed as separate args.
Replace two low-signal tests checking parameterizedCodecs (which did not match the implementation) with a single focused test that verifies parameterizedRenderers propagation to generateContractTypes. The test now correctly matches the actual data flow: - EmitOptions receives parameterizedRenderers (Map<string, TypeRenderEntry>) - These are passed through to generateContractTypes options - The renderer function is callable with params and context
…ring Add two high-signal tests that prove parameterized renderers affect actual contract.d.ts output: 1. When a column has typeParams and a matching renderer exists, the renderer produces the parameterized type (e.g., Vector<1536>) 2. When no renderer exists for a codec, falls back to CodecTypes lookup These tests verify the end-to-end behavior rather than just plumbing.
43d7c06 to
781f051
Compare
…structure Add parameterizedImports field to ComponentMetadata.types.codecTypes for extensions to declare type imports needed by their parameterized renderers. This separates import concerns from renderer concerns in the new consolidated codecTypes surface. - Make codecTypes.import optional (adapters provide it, extensions usually do not) - Add parameterizedTypeImports to GenerateContractTypesOptions - Add parameterizedTypeImports to EmitOptions This enables the emission pipeline to collect and deduplicate type imports from parameterized codec descriptors across all loaded components.
Extract parameterized type imports from control descriptors during family instance creation. These imports are collected from codecTypes.parameterizedImports on adapters and extensions, then passed through the emission pipeline. Follows the same pattern as extractCodecTypeImports and extractOperationTypeImports.
…line Pass parameterized type imports from family instance through emit() to generateContractTypes(). The SQL family instance now extracts these imports during creation and includes them in the EmitOptions. This completes the plumbing for parameterized type imports from component descriptors to the emitter hook.
…edCodecs Update generateContractTypes to consume the new parameterizedTypeImports array instead of the non-existent parameterizedCodecs map. The new approach is simpler: imports are already extracted and flattened by assembly, so the emitter just merges them with other type imports. This fixes the typecheck error from the incomplete API refactoring.
Migrate tests from the old ParameterizedCodecDescriptor array API to the consolidated codecTypes surface: - Use codecTypes.parameterized record for renderers (keyed by codecId) - Use codecTypes.parameterizedImports array for type imports Also fix createMockTarget to include required create method.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @packages/2-sql/3-tooling/emitter/src/index.ts:
- Around line 206-232: The comment above the deduplication loop is misleading:
update the comment near the dedupe logic that references
allImports/seenImports/uniqueImports to state that imports are deduplicated by
package+named and that when duplicates occur the first occurrence (and its
alias) is kept; specifically clarify that different aliases for the same
package+named are not preserved but silently ignored because the key is
constructed as `${imp.package}::${imp.named}` and the loop pushes only the first
matching imp into uniqueImports.
📜 Review details
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Lite
📒 Files selected for processing (14)
agent-os/specs/2025-12-05-db-init-command/planning/descriptor-manifest-serialized-view.plan.mdagent-os/specs/2025-12-05-db-init-command/planning/extend-planner.mdagent-os/specs/2025-12-05-db-init-command/planning/pack-refs-and-descriptor-manifest-serialized-view.plan.mdagent-os/specs/2025-12-05-db-init-command/planning/pack-refs-contract-authoring.plan.mdpackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.ts
💤 Files with no reviewable changes (4)
- agent-os/specs/2025-12-05-db-init-command/planning/pack-refs-and-descriptor-manifest-serialized-view.plan.md
- agent-os/specs/2025-12-05-db-init-command/planning/extend-planner.md
- agent-os/specs/2025-12-05-db-init-command/planning/descriptor-manifest-serialized-view.plan.md
- agent-os/specs/2025-12-05-db-init-command/planning/pack-refs-contract-authoring.plan.md
🧰 Additional context used
📓 Path-based instructions (41)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/use-correct-tools.mdc)
**/*.{ts,tsx}: Use localpnpm typecheckscripts instead of writingtsccommands from scratch for TypeScript type checking
Never add file extensions to imports in TypeScript
**/*.{ts,tsx}: Core contract types (ContractBase,Source) and document family types (DocumentContract) should be imported from@prisma-next/contract/types
SQL emitter hook should be imported from@prisma-next/sql-contract-emitter(canonical source)
Target-neutral operations should be imported from@prisma-next/operations(canonical source)
**/*.{ts,tsx}: ExtractCodecTypesfrom contract usingExtractCodecTypes<Contract>helper type with fallback toRecord<string, never>
ExtractOperationTypesfrom contract usingExtractOperationTypes<Contract>helper type with fallback toRecord<string, never>
Never passCodecTypesorOperationTypesas separate type parameters toschema(),sql(), ororm()functions
Always extract types from contract using the helper types instead of passing them directly
Contract must be validated before passing tocreateRuntimeContext()usingvalidateContract<Contract>()
**/*.{ts,tsx}: Use pnpm and local scripts (not ad-hoctsc,jest) for building and testing
Use adapters instead of branching on target in core code
Prefer links to canonical docs over long comments in code
Use type parameter pattern with.d.tsfor precise types instead of inferring types from JSON imports
Always usevalidateContract<Contract>(json)with fully-typed Contract type parameter, not genericSqlContract<SqlStorage>
Access table columns usingtable.columns.fieldNameto avoid conflicts with table properties
Builder methods return new instances; always chain calls instead of reassigning variables
No backward-compatibility shims; update call sites instead
Package layering is enforced; fix violations rather than bypassing them
Capability-gated features must be enabled in contract capabilities before use (e.g.,includeMany,returning())
Expo...
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/use-correct-tools.mdc)
**/*.{ts,tsx,js,jsx}: Use arktype instead of zod for schema validation
Don't add comments if avoidable; prefer code which expresses its intent
Don't add exports for backwards compatibility unless explicitly requested
Do not reexport things from one file in another, except in theexports/foldersImport from shared plane packages using package name and export identifier (e.g.,
@prisma-next/sql-contract/types), not/exports/paths
**/*.{ts,tsx,js,jsx}: Follow layering rules and exceptions for imports as defined in.cursor/rules/import-validation.mdcand.cursor/architecture.config.json
Follow includeMany type inference patterns (as per.cursor/rules/include-many-patterns.mdc)
Follow Arktype usage guidelines defined in.cursor/rules/arktype-usage.mdc
UseObject.hasOwn()instead ofhasOwnProperty()(as per.cursor/rules/object-hasown.mdc)
Prefer assertions over defensive checks to avoid schema validation redundancy (as per.cursor/rules/prefer-assertions-over-defensive-checks.mdc)
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/control-plane-descriptors.mdc)
packages/**/*.{ts,tsx}: UseControlFamilyDescriptor<TFamilyId, TFamilyInstance>type for family descriptors in control plane implementations
UseControlTargetDescriptor<TFamilyId, TTargetId, TTargetInstance>type for target descriptors in control plane implementations
UseControlAdapterDescriptor<TFamilyId, TTargetId, TAdapterInstance>type for adapter descriptors in control plane implementations
UseControlDriverDescriptor<TFamilyId, TTargetId, TDriverInstance>type for driver descriptors in control plane implementations
UseControlExtensionDescriptor<TFamilyId, TTargetId, TExtensionInstance>type for extension descriptors in control plane implementations
All control plane descriptors must includekindproperty as a discriminator with value'family' | 'target' | 'adapter' | 'driver' | 'extension'
All control plane descriptors must includeidproperty as a string identifier
All control plane descriptors must includefamilyIdproperty as a literal type (e.g.,'sql')
Target, adapter, driver, and extension descriptors must includetargetIdproperty as a literal type (e.g.,'postgres')
All control plane descriptors must includemanifestproperty of typeExtensionPackManifest
All control plane descriptors must includecreate()factory method that returns an instance
Always passdriverparameter toControlFamilyDescriptor.create(), even for commands that don't use it (e.g.,contract emit)
Do not use legacy descriptor types (FamilyDescriptor,TargetDescriptor,AdapterDescriptor,DriverDescriptor,ExtensionDescriptor,ControlPlaneDriver). UseControl*DescriptorandControl*Instancetypes instead
packages/**/*.{ts,tsx}: Family instances must implement control-plane domain actions (e.g.,emitContract,verify,schemaVerify,introspect) as self-contained methods that own their implementation logic
In family instance domain actions, import and use pure helper functions (e.g.,canonicalizeContract, `computeCoreHas...
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/src/**
📄 CodeRabbit inference engine (.cursor/rules/multi-plane-entrypoints.mdc)
Structure multi-plane packages with split sources by plane:
src/core/**for shared,src/exports/control.tsfor migration,src/exports/runtime.tsfor runtime
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/src/core/instance.ts
packages/**
📄 CodeRabbit inference engine (.cursor/rules/no-backward-compatibility.md)
Do not add backward-compatibility shims or migration scaffolding in the codebase
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/no-backward-compatibility.md)
Do not add deprecation warnings or migration helpers
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages,examples,test}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/object-hasown.mdc)
Always use
Object.hasOwn()instead ofhasOwnProperty()to check for own properties. The modern ES2022 API is preferred as it cannot be overridden or shadowed, and is enforced by Biome lint rulenoPrototypeBuiltins.Export interfaces and factory functions for public APIs; keep concrete classes as private implementation details
No generic defaults unless meaningful: defaults are semantics, not flexibility. See
.cursor/rules/generic-parameters.mdcfor details.
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/src/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/shared-plane-packages.mdc)
Organize shared plane package source code with separate files: types.ts, validators.ts (optional), and factories.ts (optional)
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/src/core/instance.ts
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/shared-plane-packages.mdc)
Do not import migration-plane packages (emitter, CLI) or runtime-plane packages (lanes, runtime) in shared plane packages
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/src/core/instance.ts
**/*.{ts,tsx,test-d.ts}
📄 CodeRabbit inference engine (.cursor/rules/validate-contract-usage.mdc)
When using
validateContract<TContract>(), always use a fully-typed contract type (not a genericSqlContract<SqlStorage>). Using a generic type causes all subsequent type inference to fail, resulting inunknowntypes throughout the code.
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/!(*.test|*.test-d|*.spec).ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/validate-contract-usage.mdc)
For production code using
validateContract<TContract>(), always import the contract type fromcontract.d.ts(generated by the emitter) rather than defining types inline.
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/src/core/instance.ts
{packages,test,examples}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/arktype-usage.mdc)
{packages,test,examples}/**/*.{ts,tsx}: Use Arktype instead of Zod for schema validation and type definitions
Use optional keys via 'key?' syntax in Arktype schemas (not 'string | undefined')
Use 'type({ "[string]": Schema })' for defining record types in Arktype
Use 'Schema.array()' for array definitions in Arktype (avoid tuple mistakes)
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages,examples,test}/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/no-target-branches.mdc)
Never branch on
targetin core code - use adapters instead. Target-specific logic should be encapsulated in adapter interfaces and target-specific packages, not in conditional branches checking the target value.
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages,test,examples}/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/prefer-assertions-over-defensive-checks.mdc)
{packages,test,examples}/**/*.ts: Prefer assertions over defensive checks when data is guaranteed to be valid - use non-null assertions (e.g.,columnMeta!) after validation checks instead of optional chaining
Remove optional chaining and conditional property spreading for properties that are guaranteed to exist after validation - access required properties directly without?.operators
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/prefer-assertions-over-defensive-checks.mdc)
packages/**/*.ts: Use schema validators (Arktype) for structural validation of required fields, types, and shapes rather than redundant manual checks for these properties
Focus logical validators on consistency checks (foreign key references, model-to-table mappings, constraint relationships) that schema validators cannot perform, not on re-validating structural properties
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages,examples}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/type-predicates.mdc)
Avoid blind casts like
as unknown as Xin production TypeScript code. Use type predicates (value is X) or type guards instead to let the compiler narrow types safely.
{packages,examples}/**/*.{ts,tsx}: Export interfaces; construct via factories: keep classes as private implementation details.
Replace blind casts with type predicates. See.cursor/rules/type-predicates.mdcfor details.
Use interface-based design with factory functions for object construction. See.cursor/rules/interface-factory-pattern.mdcfor details.
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/README.md)
For packages that span multiple planes, follow patterns in
.cursor/rules/multi-plane-packages.mdcand.cursor/rules/multi-plane-entrypoints.mdc
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.{sql,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/README.md)
Use LATERAL and json_agg patterns as defined in
.cursor/rules/postgres-lateral-patterns.mdc
Files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/{2-sql,sql}/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/include-many-patterns.mdc)
packages/{2-sql,sql}/**/*.ts: Use a generic type parameter that accumulates include definitions across multipleincludeMany()calls with an Includes map:Includes extends Record<string, any> = Record<string, never>
Use a helper typeExtractIncludeType<K extends string, Includes extends Record<string, any>>for safe type-safe lookup of include types from accumulated map with fallback tounknown
Handle booleantruein type inference to allowselect({ posts: true })to inferArray<ChildShape>from the Includes map using pattern:P[K] extends true ? Array<ExtractIncludeType<K & string, Includes>> : ...
Implement runtime capability checks in builder methods to gate features likeincludeMany()andreturning(), throwingplanInvalid()errors when required capabilities are missing or false
For features requiring multiple capabilities (e.g.,includeManyrequires both 'lateral' and 'jsonAgg'), check all required capabilities at runtime:if (targetCapabilities['lateral'] !== true || targetCapabilities['jsonAgg'] !== true)
Files:
packages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/src/index.ts
📄 CodeRabbit inference engine (.cursor/rules/no-barrel-files.mdc)
packages/**/src/index.ts: Never createindex.tsfiles that only containexport * from './other-module'orexport { something } from './other-module'- prefer explicit, direct imports instead
Only createindex.tsfiles when they contain actual implementation code; useexports/index.tspattern only for explicit, intentional API surfaces
Files:
packages/2-sql/3-tooling/emitter/src/index.ts
packages/{2-sql,3-targets}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/postgres-lateral-patterns.mdc)
packages/{2-sql,3-targets}/**/*.{ts,tsx}: Don't quote identifiers early in functions. Quote them only when needed in SQL generation to avoid double-quoting issues.
When using LATERAL joins in PostgreSQL adapters, use different aliases for the table alias and column alias: table alias as{alias}_lateral, column alias as{alias}, and select usingtable_alias.column_alias(e.g.,posts_lateral.posts)
When both ORDER BY and LIMIT are present in a LATERAL subquery, wrap the query in an inner SELECT that projects individual columns with aliases, then usejson_agg(row_to_json(sub.*))on the result
Use column aliases in ORDER BY when the column is in the SELECT list; map column references to their aliases before generating ORDER BY clause
Files:
packages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages/2-sql/**,packages/3-targets/**,examples/**,test/**}/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/sql-types-imports.mdc)
{packages/2-sql/**,packages/3-targets/**,examples/**,test/**}/*.{ts,tsx,js}: Import SQL-specific contract types (SqlContract,SqlStorage,SqlMappings,ModelDefinition,StorageTable,StorageColumn, etc.) from@prisma-next/sql-contract/types(shared plane package), not from@prisma-next/contract/types
SQL contract validators should be imported from@prisma-next/sql-contract/validators(shared plane)
SQL contract IR factories should be imported from@prisma-next/sql-contract/factories(shared plane)
SQL-specific operations should be imported from@prisma-next/sql-operations(canonical source, shared plane)
Files:
packages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
{packages/2-sql,packages/sql,examples,test}/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/query-patterns.mdc)
{packages/2-sql,packages/sql,examples,test}/**/*.ts: Prefer accessing columns viatables.user.columns.emailpattern instead of conflicting with table properties
Extract local variables when a file usestablesfrequently - useconst user = tables.userandconst cols = user.columnsfor readability
Files:
packages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/index.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/README.md)
Avoid barrel files (as per
.cursor/rules/no-barrel-files.mdc)
Files:
packages/2-sql/3-tooling/emitter/src/index.ts
packages/{2-sql,3-targets}/**
📄 CodeRabbit inference engine (.cursor/rules/directory-layout.mdc)
Place all SQL target-family packages (all layers and planes) under
packages/2-sql/**; place concrete dialects, adapters, and drivers underpackages/3-targets/**
Files:
packages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/src/core/**
📄 CodeRabbit inference engine (.cursor/rules/multi-plane-entrypoints.mdc)
packages/**/src/core/**: Keepsrc/core/**free of migration/runtime imports; depend only on shared-plane packages
Do not add plane-crossing imports insidesrc/core/**
Files:
packages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/src/core/instance.ts
packages/**/{src/core,src/exports}/**
📄 CodeRabbit inference engine (.cursor/rules/multi-plane-packages.mdc)
Multi-plane packages must use a structured directory layout with
src/core/for shared plane code andsrc/exports/for entry points (control.ts, runtime.ts)
Files:
packages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/src/core/instance.ts
packages/**/src/core/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/multi-plane-packages.mdc)
Core plane code in
src/core/**must not include CLI-specific or runtime-specific dependencies, only imports from shared plane packages
Files:
packages/2-sql/3-tooling/family/src/core/assembly.tspackages/2-sql/3-tooling/family/src/core/instance.ts
**/*.{test,spec}.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/omit-should-in-tests.mdc)
Omit the word 'should' in test descriptions - write concise, direct descriptions instead (e.g., 'equals 1' instead of 'should equal 1')
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/use-correct-tools.mdc)
Use local
pnpm testscripts for testing; usepnpm test:coveragefor all packages orpnpm coverage:packagesfor packages only
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.test.ts
📄 CodeRabbit inference engine (.cursor/rules/contract-normalization-responsibilities.mdc)
When writing tests for contract normalization, test that the builder normalizes correctly. Tests for validators, parsers, and emitter hooks should test that they work with already-normalized contracts, NOT that they normalize.
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/*.{test,spec}.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/no-backward-compatibility.md)
Do not keep old code or 'legacy' test fixtures for reference; delete old code entirely and update all references to use new approaches
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.test.ts
📄 CodeRabbit inference engine (.cursor/rules/prefer-object-matcher.mdc)
Prefer object matchers (toMatchObject) over multiple individual expect().toBe() calls when checking 2 or more related values in tests
**/*.test.ts: Keep test files under 500 lines to maintain readability and navigability. If a test file exceeds this limit, it should be split into multiple files.
Split test files when they exceed 500 lines, contain multiple distinct concerns that can be logically separated, or have multiple top-leveldescribeblocks that can be split by functionality.
Use descriptive file names with the pattern{base}.{category}.test.ts, such as.basic.test.ts,.errors.test.ts,.structure.test.ts, or feature-area prefixes likeruntime.joins.test.ts,runtime.projections.test.ts. Keep the base name consistent across related test files.
Group tests by logical boundaries: by functionality (e.g., 'basic', 'errors', 'structure', 'generation'), by feature area (e.g., 'joins', 'projections', 'includes'), or by test type (e.g., 'unit', 'integration', 'edge-cases'). Split at natural boundaries defined bydescribeblocks.
Prefer object comparison usingtoEqualortoMatchObjectfor assertions on objects, rather than property-by-property checks withtoHavePropertyor individual property assertions. Useexpect.any()for type-only checks andexpect.not.objectContaining()for absence checks.
Compare entire plan structures using singletoEqualassertions rather than piece-by-piece checks. Verify complete AST structures to ensure all fields are present and correct, not just a subset.
Ensure each split test file is complete and independently runnable: include all necessary imports, all necessary setup/teardown code, and verify all files are under 500 lines after splitting.
**/*.test.ts: Use factory functions (createColumnRef, createParamRef, createLiteralExpr, createTableRef, createBinaryExpr) from @prisma-next/sql-relational-core/ast instead of manual object creation when creating AST nodes in tests
Exception: Manual creation of Opera...
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/test/**/*.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/prefer-object-matcher.mdc)
Prefer object matchers (toMatchObject) over multiple individual expect().toBe() calls when checking 2 or more related values in tests
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/test/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/shared-plane-packages.mdc)
packages/**/test/**/*.{ts,tsx}: Create unit tests for validators and factories in shared plane packages, and include type tests for exported types
Do not create integration tests in shared plane packages that require migration-plane or runtime-plane packages
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/test/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/test-file-organization.mdc)
Integration tests that depend on multiple packages should be placed in
@prisma-next/integration-teststo avoid cyclic dependencies.Use factory functions like
createContractIR()instead of manual object creation for ContractIR objects in test utilities to avoid duplication, ensure type safety, and reduce maintenance burden when ContractIR structure changes
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/test/**
📄 CodeRabbit inference engine (.cursor/rules/use-ast-factories.mdc)
Use factory functions (createColumnRef, createParamRef, createLiteralExpr, createTableRef, createBinaryExpr) from @prisma-next/sql-relational-core/ast instead of manual object creation when creating AST nodes in tests
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.{test,test-d,spec}.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/validate-contract-usage.mdc)
For tests using
validateContract<TContract>(), either use the fixture contract type or define a fully-typed contract type inline; never usevalidateContract<SqlContract<SqlStorage>>().
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
packages/**/test/**/*.{test.ts,test-d.ts}
📄 CodeRabbit inference engine (.cursor/rules/test-import-patterns.mdc)
Within-package tests: Import from source (
../src/...), not from package exports
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.{test.ts,test-d.ts}
📄 CodeRabbit inference engine (.cursor/rules/test-mocking-patterns.mdc)
**/*.{test.ts,test-d.ts}: Use@ts-expect-errorwith a short reason in tests instead of blanket@ts-ignore
Use double casts (as unknown as X) for mocks and dynamic proxies in tests instead of direct casts
Preferunknownoveranyin tests to keep the unsafe boundary explicit
Don't spread class instances in tests ({ ...instance }), as you'll lose prototype methods. UseObject.create()andObject.assign()instead
Keep mock shapes minimal, containing only the fields needed for the test
Place type casts at mock boundaries (return statements), not sprinkled throughout the test
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
**/*.test.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/README.md)
**/*.test.{ts,tsx,js,jsx}: In test descriptions, omit the word 'should' (as per.cursor/rules/omit-should-in-tests.mdc)
In test files, use source file imports with relative paths, not exports intended for tests (as per.cursor/rules/test-import-patterns.mdc)
Organize test files with a maximum of 500 lines per file; split by functionality (as per.cursor/rules/test-file-organization.mdc)
Prefer object matchers over multiple individualexpect().toBe()calls in tests (as per.cursor/rules/prefer-object-matcher.mdc)
Use factory functions for creating AST nodes instead of manual object creation (as per.cursor/rules/use-ast-factories.mdc)
Use factory functions for ContractIR objects in tests instead of manual object creation (as per.cursor/rules/use-contract-ir-factories.mdc)
Follow test-only assertions and mocking patterns (as per.cursor/rules/test-mocking-patterns.mdc)
Files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
🧠 Learnings (2)
📚 Learning: 2025-12-26T23:02:40.679Z
Learnt from: wmadden
Repo: prisma/prisma-next PR: 38
File: packages/2-sql/3-tooling/family/src/core/migrations/plan-helpers.ts:40-47
Timestamp: 2025-12-26T23:02:40.679Z
Learning: In Prisma-next's TypeScript codebase, prefer using well-established utility libraries (e.g., Lodash) rather than building custom utilities for complex object operations such as deep freezing or deep cloning. Favor reliable, battle-tested functions and ensure dependencies are reviewed for tree-shaking and bundle size. If a lightweight utility suffices, consider modern native approaches or smaller libs.
Applied to files:
packages/1-framework/1-core/shared/contract/src/framework-components.tspackages/1-framework/1-core/migration/control-plane/src/emission/types.tspackages/2-sql/3-tooling/emitter/src/index.tspackages/2-sql/3-tooling/family/src/core/assembly.tspackages/1-framework/1-core/migration/control-plane/src/emission/emit.tspackages/1-framework/1-core/shared/contract/src/types.tspackages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/2-sql/3-tooling/family/src/core/instance.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
📚 Learning: 2026-01-07T05:58:01.640Z
Learnt from: wmadden
Repo: prisma/prisma-next PR: 95
File: packages/2-sql/2-authoring/contract-ts/test/contract.parameterized-types.test.ts:5-10
Timestamp: 2026-01-07T05:58:01.640Z
Learning: In test files named with .test.*, .spec.*, or .test-d.* (e.g., *.test.ts, *.spec.ts, *.test-d.ts, *.test.tsx), when using validateContract, it's acceptable to use a type alias like 'type TestContract = SqlContract<SqlStorage>' even if it doesn't provide full TypeScript type inference. The priority in tests is runtime validation behavior over precise TS type inference; use such aliases to simplify tests while keeping runtime correctness clear.
Applied to files:
packages/2-sql/3-tooling/family/test/emit-parameterized.test.tspackages/1-framework/3-tooling/emitter/test/emitter.test.tspackages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
🧬 Code graph analysis (5)
packages/1-framework/1-core/shared/contract/src/framework-components.ts (2)
packages/1-framework/1-core/shared/contract/src/types.ts (1)
TypesImportSpec(169-173)packages/1-framework/1-core/shared/contract/src/exports/types.ts (1)
TypesImportSpec(29-29)
packages/1-framework/1-core/migration/control-plane/src/emission/types.ts (2)
packages/1-framework/1-core/shared/contract/src/types.ts (1)
TypesImportSpec(169-173)packages/1-framework/1-core/shared/contract/src/exports/types.ts (1)
TypesImportSpec(29-29)
packages/2-sql/3-tooling/emitter/src/index.ts (1)
packages/1-framework/1-core/shared/contract/src/types.ts (1)
TypesImportSpec(169-173)
packages/1-framework/1-core/migration/control-plane/src/emission/emit.ts (2)
packages/1-framework/1-core/shared/contract/src/types.ts (1)
ValidationContext(179-189)packages/1-framework/1-core/shared/contract/src/exports/types.ts (1)
ValidationContext(30-30)
packages/1-framework/3-tooling/emitter/test/emitter.test.ts (3)
packages/1-framework/1-core/shared/contract/src/ir.ts (1)
ContractIR(11-26)packages/1-framework/3-tooling/emitter/test/utils.ts (1)
createContractIR(11-166)packages/1-framework/1-core/shared/contract/src/types.ts (3)
GenerateContractTypesOptions(211-223)TargetFamilyHook(229-259)TypeRenderEntry(203-206)
🔇 Additional comments (20)
packages/1-framework/3-tooling/emitter/test/emitter.test.ts (3)
3-7: LGTM - Import changes align with new test requirements.The additions of
GenerateContractTypesOptionsandTypeRenderEntrysupport the new parameterized renderers test, and removingValidationContextis correct since the mock no longer uses it.
17-17: LGTM - Mock signatures correctly updated.The mock hook signatures now match the updated
TargetFamilyHookinterface, withvalidateTypesno longer requiringValidationContextandgenerateContractTypesaccepting the newoptionsparameter.Also applies to: 49-59
652-702: LGTM - Comprehensive test for parameterized renderers propagation.The test validates the complete flow of parameterized renderers through the emission pipeline, from
EmitOptionstogenerateContractTypes. The assertions confirm both the propagation and the renderer's ability to produce parameterized type expressions.packages/1-framework/1-core/shared/contract/src/framework-components.ts (2)
225-229: LGTM - Appropriate change to support extension pack flexibility.Making
importoptional is correct—extensions that only provide parameterized codecs don't need to declare a base codec types import. The updated comment clearly documents this behavior.
238-243: LGTM - Well-designed addition for parameterized type imports.The new
parameterizedImportsfield provides a clean way for components to declare type imports needed for parameterized codecs. The documentation is clear and the field is appropriately optional.packages/1-framework/1-core/migration/control-plane/src/emission/types.ts (1)
15-19: LGTM - Clean addition to emission options.The new
parameterizedTypeImportsfield follows the established pattern ofcodecTypeImportsandoperationTypeImports, providing a consistent way to pass parameterized type imports through the emission pipeline. The documentation clearly explains its purpose.packages/2-sql/3-tooling/family/src/core/instance.ts (1)
37-37: LGTM - Consistent implementation following established patterns.The extraction and propagation of
parameterizedTypeImportsfollows the exact same pattern as the existing metadata fields (codecTypeImports,operationTypeImports,parameterizedRenderers). The implementation is clean and consistent with the surrounding code.Also applies to: 415-415, 896-896
packages/1-framework/1-core/shared/contract/src/types.ts (2)
184-188: LGTM!The
parameterizedCodecsfield is well-designed for quick lookup during type generation, using aMap<string, ParameterizedCodecDescriptor>structure. The JSDoc clearly explains the purpose.
218-222: LGTM!The
parameterizedTypeImportsoption correctly mirrors the structure used elsewhere (ReadonlyArray<TypesImportSpec>) and integrates cleanly with the existing codec and operation type imports in the generation options.packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts (3)
2-2: LGTM!Import of
TypeRenderEntryfrom the correct package path supports the new parameterized rendering tests.
582-631: LGTM!The test correctly verifies that when a column has
typeParamsand a matching renderer exists inparameterizedRenderers, the emitter uses the renderer to produce the type expression (Vector<1536>). The assertions also properly verify that scalar codecs without parameterized renderers continue using theCodecTypeslookup pattern.
633-669: LGTM!Good coverage of the fallback behavior—when no renderer exists for a codec with
typeParams, the emitter correctly falls back to the standardCodecTypes['codecId']['output']pattern.packages/2-sql/3-tooling/family/src/core/assembly.ts (1)
166-190: LGTM!The
extractParameterizedTypeImportsfunction follows the established pattern of its sibling extraction functions. The JSDoc appropriately notes that duplicates may be present, pushing deduplication responsibility to the caller (which aligns with how the emitter handles import deduplication).packages/1-framework/1-core/migration/control-plane/src/emission/emit.ts (2)
58-63: LGTM!The use of
ifDefinedfor conditional spreading is clean and prevents addingundefinedproperties to theValidationContext. This pattern is consistent throughout the function.
108-120: LGTM!Good approach to conditionally construct
generateOptionsonly when eitherparameterizedRenderersorparameterizedTypeImportsis present, avoiding unnecessary object allocation when both are absent.packages/2-sql/3-tooling/family/test/emit-parameterized.test.ts (5)
1-8: LGTM!Imports are correctly sourced: types from
@prisma-next/contract/types, control plane types from@prisma-next/core-control-plane/types, and the family instance factory from the local source path per coding guidelines.
17-74: LGTM!The mock creator functions are well-structured with all required descriptor fields. The
createMockExtensionWithParameterizedCodecfunction cleanly accepts configuration and conditionally includesparameterizedImportswhen atypesImportis provided.
76-149: LGTM!Good integration test that exercises the full flow: creating a family instance with a parameterized codec extension, emitting a contract with a vector column, and verifying the type import appears in the generated
contract.d.ts.
151-253: LGTM!This test effectively validates that parameterized type imports are collected from multiple sources (both adapter and extension) and both appear in the emitted output.
255-353: LGTM!Good test for verifying that different named exports from the same package are NOT incorrectly deduplicated. The comment on line 346 helpfully explains the expected behavior when
alias === named.
Part 3 of 6 in the parameterized column types stack.
Extends emission plumbing to pass parameterized codec descriptors and adds integration tests for parameterized type rendering.
Summary by CodeRabbit
New Features
Improvements
Tests
Revert
✏️ Tip: You can customize this high-level summary in your review settings.