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

refactor(emitter): replace TargetFamilyHook with EmissionSpi - #304

Merged
wmadden merged 23 commits into
mainfrom
tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level
Apr 7, 2026
Merged

wmadden merged 23 commits into
mainfrom
tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level

Conversation

@wmadden

@wmadden wmadden commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

closes TML-2188

Intent

Replace the monolithic TargetFamilyHook.generateContractTypes() with a framework-owned .d.ts template assembler and a focused EmissionSpi that families implement with only storage-specific type fragments. After this change, neither the SQL nor Mongo emitter owns the full template — the framework orchestrates assembly from shared domain-level generators and family callbacks.

Key snippet

New — framework-owned template assembler

export function generateContractDts(
  contract: Contract,
  emitter: EmissionSpi,
  codecTypeImports: ReadonlyArray<TypesImportSpec>,
  operationTypeImports: ReadonlyArray<TypesImportSpec>,
  hashes: { readonly storageHash: string; readonly executionHash?: string; readonly profileHash: string },
  options?: GenerateContractTypesOptions,
): string {
  // ... gathers shared + family-specific parts ...
  return `// ⚠️  GENERATED FILE - DO NOT EDIT
${importLines.join('\n')}
${familyImportLines.join('\n')}
// ... hash aliases, codec/operation types, family type aliases, TypeMaps ...
type ContractBase = ContractType<${storageType}, ${modelsType}> & {
  readonly target: ${serializeValue(contract.target)};
  // ... roots, capabilities, extensionPacks, execution, profileHash ...
};
${contractWrapper}
`;
}

Change map

The story

  1. Extract shared model-level generation utilities — generateModelFieldsType (from Mongo hook) and generateModelsType (new) are added to @prisma-next/emitter/domain-type-generation, establishing the shared vocabulary for model type emission that both families can use.

  2. Replace TargetFamilyHook with EmissionSpi — The vague "hook" abstraction becomes a focused emission SPI. The ControlFamilyDescriptor field changes from hook to emission, namespacing the SPI on the descriptor for future extensibility (e.g., descriptor.migration.*).

  3. Framework takes over the template — generateContractDts() is added to @prisma-next/emitter, initially as a pass-through, then expanded to own the full .d.ts skeleton. It calls shared utilities for imports, hashes, codec intersections, roots, and models, and delegates to EmissionSpi callbacks for family-specific parts (storage type, family imports, type aliases, TypeMaps expression, contract wrapper).

  4. Narrow the SPI — EmissionSpi loses generateContractTypes() and gains focused callbacks: generateStorageType, generateModelStorageType, getFamilyImports, getFamilyTypeAliases, getTypeMapsExpression, getContractWrapper. SQL and Mongo emitters are migrated to provide only these callbacks.

  5. Wire emit() through the framework template — emit() now calls generateContractDts(contract, targetFamily, ...) instead of targetFamily.generateContractTypes(...).

  6. Clean up internal types and leaked helpers — Remove IRModelDefinition/IRModelField/IRModelStorage from the SQL emitter and MongoModelIR from the Mongo emitter (use ContractModel directly). Remove serializeValue/serializeTypeParamsLiteral properties leaked onto the SQL emitter object literal.

Behavior changes & evidence

Compatibility / migration / risk

  • No user-facing API changes. The ControlFamilyDescriptor field rename (hook → emission) is internal to the framework/family packages. No consumer code (ORM client, query builder, user configs) is affected.
  • Import ordering in emitted .d.ts changed. This is cosmetic but may affect snapshot/golden-file tests in CI.
  • Mongo .d.ts no longer emits targetFamily in the TypeScript type (it was in the old hand-crafted template). The JSON still contains it.

Follow-ups / open questions

  • Validation methods on EmissionSpi: The plan says to remove them but the implementation retains them. Either remove validation from the SPI or update the plan with the rationale.
  • SQL generateModelsType override: The SQL emitter provides its own models generation that bypasses the shared function. Track a follow-up to eliminate once SQL model construction populates model.fields.codecId at authoring time.
  • Export rename (sqlTargetFamilyHook → sqlEmission): Deferred to a follow-up commit.

Non-goals / intentionally out of scope

  • Removing validation from the emission pipeline (deferred despite plan's intent)
  • Renaming emitter exports to match the new SPI naming
  • Eliminating SQL's custom generateModelsType override

Summary by CodeRabbit

  • New Features

    • Centralized .d.ts generation and focused model/storage emitters for clearer contract output.
  • Refactor

    • Unified family emission API and descriptor surface; monolithic generator split into targeted emission helpers.
  • Documentation

    • READMEs and examples updated to reflect the new emission usage.
  • Tests

    • Tests and fixtures updated to exercise the new emission flow and mocks.
  • Bug Fixes

    • Improved validation behavior and determinism of emitted types.

@coderabbitai

coderabbitai Bot commented Apr 6, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces the TargetFamilyHook SPI with a new EmissionSpi focused on emission/type-generation; centralizes .d.ts assembly into generateContractDts; updates emitter core, family emitters, CLI wiring, framework descriptors, tests, fixtures, examples, and docs to use the new emission property and APIs.

Changes

Cohort / File(s) Summary
Core SPI & descriptors
packages/1-framework/1-core/framework-components/src/emission-types.ts, packages/1-framework/1-core/framework-components/src/control-descriptors.ts, packages/1-framework/1-core/framework-components/src/exports/emission.ts
Renamed TargetFamilyHook → EmissionSpi; removed broad validation/generateContractTypes methods; added granular emission methods (generateStorageType, generateModelStorageType, generateModelsType?, getFamilyImports, getFamilyTypeAliases, getTypeMapsExpression, getContractWrapper). ControlFamilyDescriptor.hook → emission.
Emitter core & DTS orchestration
packages/1-framework/3-tooling/emitter/src/emit.ts, packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts, packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts, packages/1-framework/3-tooling/emitter/src/exports/index.ts
Added generateContractDts and new domain-type helpers; emit now accepts EmissionSpi and delegates .d.ts generation to generateContractDts; removed emitter-owned pre-generation validation/context.
Framework config & validation
packages/1-framework/1-core/config/src/config-validation.ts, packages/1-framework/1-core/config/test/*
Config validation and tests updated to require family.emission (object) instead of family.hook; test fixtures and mocks reshaped to EmissionSpi surface.
CLI wiring
packages/1-framework/3-tooling/cli/src/control-api/*, packages/1-framework/3-tooling/cli/test/*
Emit callsites changed to pass family.emission; tests and CLI client updated to use the new emission property.
SQL family emitter
packages/2-sql/3-tooling/emitter/src/index.ts, packages/2-sql/3-tooling/emitter/test/*, packages/2-sql/9-family/*
Renamed sqlTargetFamilyHook → sqlEmission; removed monolithic generateContractTypes and implemented per-emission helpers and helpers for imports/type aliases/type-maps/wrapper; descriptors expose emission.
Mongo family emitter
packages/2-mongo-family/3-tooling/emitter/src/index.ts, packages/2-mongo-family/3-tooling/emitter/test/*, packages/2-mongo-family/9-family/*
Renamed mongoTargetFamilyHook → mongoEmission; replaced generateContractTypes with EmissionSpi generators; tests and descriptors updated to use mongoEmission + generateContractDts.
Emitter tests & utilities
packages/1-framework/3-tooling/emitter/test/mock-spi.ts, packages/1-framework/3-tooling/emitter/test/*
Added shared createMockSpi() producing EmissionSpi; updated many emitter tests to use shared SPI; added unit tests for new domain-type-generation helpers and serializeExecutionType.
Integration tests, fixtures, examples, docs
test/integration/**, test/integration/test/fixtures/contract.d.ts, test/integration/test/fixtures/cli/**, examples/*, docs/*, docs/architecture docs/adrs/*
Updated imports/usages to pass sqlEmission/mongoEmission, adjusted contract fixture types to include targetFamily: 'sql' in places, and refreshed README/ADR/examples to reflect EmissionSpi and emission property.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as Client/CLI
    participant Control as Control Client
    participant Emitter as Emitter (emit)
    participant Generator as generateContractDts
    participant Family as EmissionSpi (sqlEmission/mongoEmission)
    participant FS as Filesystem

    CLI->>Control: request emit(contractIR)
    Control->>Emitter: emit(contract, stack, family.emission)
    Emitter->>Emitter: compute hashes & canonicalize
    Emitter->>Generator: generateContractDts(contract, Family, imports..., hashes, options)
    Generator->>Family: getFamilyImports / getFamilyTypeAliases / getTypeMapsExpression
    alt family needs models
        Generator->>Family: generateModelStorageType(model)
        Generator->>Family: generateStorageType(contract, storageHashTypeName)
    end
    Generator-->>Emitter: return .d.ts content
    Emitter->>FS: write contract.json and contract.d.ts
    Emitter-->>Control: return emitResult (contractJson, contractDts, hashes)
    Control-->>CLI: success/failure
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • jkomyno

Poem

🐰 I nibble names and stitch the seams,
Hooks turned Emission, newer dreams,
DTS sings from one neat source,
Models and storage find their course,
Helpers hop — the types applaud. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(emitter): replace TargetFamilyHook with EmissionSpi' clearly and concisely identifies the main architectural change in the changeset: renaming/replacing the TargetFamilyHook interface with the new EmissionSpi interface across the emitter framework.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level

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

@wmadden
wmadden force-pushed the tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level branch from 0ac276e to c18519c Compare April 6, 2026 16:33
@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-orm

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

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

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

@prisma-next/runtime-executor

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/adapter-postgres

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

@prisma-next/driver-postgres

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

commit: 34b6bb4

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/1-framework/1-core/framework-components/README.md (1)

10-10: ⚠️ Potential issue | 🟡 Minor

Emission API list is stale relative to the new SPI description.

Line 24 correctly explains EmissionSpi, but Line 10 still documents removed TargetFamilyHook/ValidationContext generation-era types. Please update that bullet to only list the current emission types.

As per coding guidelines: "**/*.{md,mdx}: Keep documentation current including READMEs, rules, and links."

Also applies to: 24-24

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/1-framework/1-core/framework-components/README.md` at line 10,
Update the Emission SPI bullet to remove stale generation-era types
(TargetFamilyHook, ValidationContext, GenerateContractTypesOptions,
TypeRenderEntry, TypeRenderer, ParameterizedCodecDescriptor and related types)
and instead document the current emission types as described by EmissionSpi (the
new SPI); replace the old list with a concise, accurate enumeration that matches
the explanation of EmissionSpi on Line 24.
packages/2-mongo-family/3-tooling/emitter/README.md (1)

7-39: ⚠️ Potential issue | 🟡 Minor

README still documents removed TargetFamilyHook behavior.

The usage snippet is updated to mongoEmission, but the package contract still describes TargetFamilyHook/generateContractTypes and transition-state wording. Please align this section to the current EmissionSpi + framework-owned DTS assembly model only.

As per coding guidelines: "packages/**/*.md: Update design docs to reflect the current state only, not the transition history or legacy approaches" and "**/*.{md,mdx}: Keep documentation current including READMEs, rules, and links."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-mongo-family/3-tooling/emitter/README.md` around lines 7 - 39,
Update the README to remove references to the legacy TargetFamilyHook and
generateContractTypes flow and instead document the current EmissionSpi +
framework-owned DTS assembly model: keep the usage example showing
emit(contractIR, mongoEmission, options) and then replace the "What it provides"
and architecture sections to describe mongoEmission as an EmissionSpi
implementation that validates codec IDs and structure (ns/name@version),
delegates domain-level type generation to
`@prisma-next/emitter/domain-type-generation`, and relies on the framework to
assemble the final contract.d.ts artifacts; remove transition-state wording and
any mention of “generateContractTypes”/TargetFamilyHook while keeping
Mongo-specific validation points (collections, owned/embedded rules,
polymorphism, storage.relations) and references to contract.d.ts and contract
generation flow.
packages/2-mongo-family/3-tooling/emitter/src/index.ts (1)

6-120: ⚠️ Potential issue | 🟠 Major

Add : EmissionSpi type annotation to mongoEmission to enforce API boundary.

mongoEmission is exported as an unannotated object literal, so its public type includes every property—including validateTypes() and validateStructure(), which are not part of the EmissionSpi interface. This breaks the SPI contract for consumers. Either make these validation methods private (e.g., validateTypes → _validateTypes) or remove them entirely if they're not called from framework code, then annotate the export as : EmissionSpi to enforce the boundary going forward.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-mongo-family/3-tooling/emitter/src/index.ts` around lines 6 - 120,
The exported mongoEmission object exposes implementation-only methods
validateTypes and validateStructure which leak beyond the EmissionSpi boundary;
rename these methods to private names (e.g., _validateTypes and
_validateStructure) or remove them if unused, then add an explicit type
annotation ": EmissionSpi" to the mongoEmission export so the public surface
matches the SPI. Update any internal callers to reference the new private names
(mongoEmission._validateTypes / mongoEmission._validateStructure) or remove
those calls, and ensure the file imports/uses EmissionSpi so the annotation
type-checks.
🧹 Nitpick comments (6)
packages/2-sql/3-tooling/emitter/src/index.ts (1)

27-31: Blind casts on contract.storage and contract.models are present throughout.

Lines 31, 62, 204, 278, and 297-298 use as unknown as patterns to cast generic contract properties to SQL-specific types. Per coding guidelines, blind casts are forbidden in production code. Consider introducing a type predicate (e.g., isSqlStorage(storage): storage is SqlStorage) to narrow types safely, or documenting why these casts are necessary for the family-specific SPI context.

That said, this appears to be a pre-existing pattern being carried forward from the previous implementation, so it may be acceptable to defer this refactor.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/src/index.ts` around lines 27 - 31, The code
uses unsafe blind casts (as unknown as ...) on contract.storage and
contract.models inside sqlEmission (notably in validateTypes and other methods);
replace these with proper type guards such as isSqlStorage(storage): storage is
SqlStorage and isSqlModel(model): model is SqlModel and use them to narrow types
before accessing SQL-specific fields in functions like validateTypes and any
other methods referencing contract.storage/contract.models (replace casts at the
locations currently using as unknown as); if this cannot be completed now, add a
short justificatory comment where each cast remains explaining why the
SPI-family context guarantees the type and mark TODO to implement the type
predicate to avoid blind casts.
packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts (1)

1-933: Consider splitting this test file in a follow-up.

At 933 lines, this file exceeds the 500-line guideline for test files. Consider splitting by validation category (e.g., emitter-hook.structure.models.test.ts, emitter-hook.structure.tables.test.ts, emitter-hook.structure.foreignkeys.test.ts) in a follow-up PR. This is not blocking for the current refactor.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts` around
lines 1 - 933, The test file is too large (933 lines); split the single large
spec into multiple focused test files to meet the 500-line guideline: create
smaller files such as emitter-hook.structure.models.test.ts,
emitter-hook.structure.tables.test.ts, and
emitter-hook.structure.foreignkeys.test.ts (or similar) and move related test
cases that exercise sqlEmission.validateStructure, the
describe('sql-target-family-hook') block, and the helper createContract into
those files; ensure each new file imports sqlEmission and the createContract
helper (or extract createContract into a shared test helper), and preserve all
test names and expectations so tests for model-level checks, table-level checks,
and foreignKey/index/constraint checks remain equivalent.
packages/2-sql/3-tooling/emitter/README.md (2)

7-7: Stale reference to TargetFamilyHook in documentation.

Line 7 mentions "implements the TargetFamilyHook interface" but the code examples now use EmissionSpi. Consider updating the prose to reference EmissionSpi for consistency with the refactor.

📝 Suggested fix
-This package provides the SQL-specific emitter hook implementation for the Prisma Next emitter. It validates SQL contracts and generates TypeScript type definitions for SQL contracts. It's part of the SQL tooling layer (migration plane) and implements the `TargetFamilyHook` interface.
+This package provides the SQL-specific emitter hook implementation for the Prisma Next emitter. It validates SQL contracts and generates TypeScript type definitions for SQL contracts. It's part of the SQL tooling layer (migration plane) and implements the `EmissionSpi` interface.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/README.md` at line 7, The README references
the outdated symbol TargetFamilyHook; update the prose to reference the current
interface EmissionSpi so docs match the code examples and refactor: replace the
phrase "implements the `TargetFamilyHook` interface" with "implements the
`EmissionSpi` interface" and adjust any surrounding wording to reflect
EmissionSpi usage (search for TargetFamilyHook and EmissionSpi in the README to
ensure consistency).

21-21: Stale reference to TargetFamilyHook in dependencies section.

Line 21 mentions "TargetFamilyHook SPI" but should reference EmissionSpi to match the refactor.

📝 Suggested fix
-  - `@prisma-next/contract` (contract IR, `TargetFamilyHook` SPI, `ValidationContext`, `TypesImportSpec` - types moved to shared plane)
+  - `@prisma-next/contract` (contract IR, `EmissionSpi` SPI, `ValidationContext`, `TypesImportSpec` - types moved to shared plane)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/README.md` at line 21, The README's
dependency list mentions the outdated symbol TargetFamilyHook; update that entry
to reference the new EmissionSpi symbol instead (e.g., replace "TargetFamilyHook
SPI" with "EmissionSpi" while preserving surrounding context such as
`@prisma-next/contract` and other type names like `ValidationContext` and
`TypesImportSpec`) so the doc reflects the refactor.
packages/2-mongo-family/9-family/README.md (1)

8-16: Use emission terminology consistently in this README.

The symbol is correctly renamed to mongoEmission, but the surrounding text still calls it a “target family hook.” Consider updating this to EmissionSpi phrasing for consistency with the current API surface.

As per coding guidelines: "packages/**/*.md: Update design docs to reflect the current state only, not the transition history or legacy approaches."

Also applies to: 55-55

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-mongo-family/9-family/README.md` around lines 8 - 16, The README
uses outdated "target family hook" wording around the renamed symbol
mongoEmission; update the phrasing to consistently use "EmissionSpi" (or
"emission" terminology) throughout the document — especially the bullet
mentioning "Family Hook Integration" — and remove transition/legacy wording so
the responsibilities read: Family Descriptor Export (ControlFamilyDescriptor),
Family Instance Creation (MongoControlFamilyInstance via create()), and Family
Hook Integration (mongoEmission / EmissionSpi); ensure all mentions of "target
family hook" are replaced with "EmissionSpi" or "emission" to match the current
API surface.
packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts (1)

9-9: Rename the suite title to match generateContractDts usage.

The current title still references generateContractTypes, but the test exercises generateContractDts.

✏️ Suggested rename
-describe('mongoEmission.generateContractTypes', () => {
+describe('generateContractDts (mongo emission)', () => {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts`
at line 9, The test suite title is outdated: change the describe string from
'mongoEmission.generateContractTypes' to 'mongoEmission.generateContractDts' so
the suite name matches the actual function under test (generateContractDts) used
in the test; update the describe call in emitter-hook.generation.test.ts
accordingly to keep the test message accurate.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/architecture` docs/adrs/ADR 185 - SPI types live at the lowest consuming
layer.md:
- Around line 42-43: Update the ADR titled "ADR 185 - SPI types live at the
lowest consuming layer" to replace every reference to the old interface name
TargetFamilyHook with the current interface name EmissionSpi (including prose,
code examples, and any type/import mentions such as sqlEmission and
mongoEmission), ensuring examples and explanations still compile conceptually
with EmissionSpi and that any surrounding wording (e.g., "interface", "hook",
"SPI") is adjusted for the new name so the document is consistent.

In `@packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts`:
- Around line 60-63: The emitted execution clause currently serializes
contract.execution verbatim via serializeValue causing execution.executionHash
to become a plain string literal; instead, detect when contract.execution exists
and build the execution fragment explicitly so you can replace the nested
execution.executionHash with the generated ExecutionHash alias (same approach
used for contract.storage.storageHash), i.e., in the code that builds
executionClause (variable executionClause / function serializeValue usage),
construct an object/stringified fragment that injects ExecutionHash for
execution.executionHash rather than the literal from contract.execution and keep
other fields serialized as before.
- Around line 39-56: generateContractDts is passing an unvalidated Contract into
emitter.generateStorageType and generateModelsType which can produce generic
runtime errors; before computing storageType/modelsType call a contract
validation routine (e.g., validateContractStructure(contract) or
emitter.validateContract if available) and short-circuit by returning
diagnostics or throwing a clear ValidationError when validation fails. Also
ensure the serialized execution property uses the branded ExecutionHash alias
instead of the raw hash: when building models/storage types (before calling
emitter.generateStorageType and emitter.generateModelsType or in the data you
pass them), replace the nested execution.executionHash field with the generated
ExecutionHash type reference (the alias produced by generateHashTypeAliases) so
the emitted types reference ExecutionHash rather than the bare value.

In `@packages/2-sql/9-family/README.md`:
- Around line 8-17: The README mixes legacy "hook"/`TargetFamilyHook`
terminology with the new `sqlEmission`/`EmissionSpi` naming; update the document
to consistently use the new emission vocabulary (e.g., replace "target family
hook", `TargetFamilyHook`, and any "hook" mentions with "emission" and
`EmissionSpi`) including in the list items and responsibility bullets
(`sqlEmission`, `ControlFamilyDescriptor`, `SqlFamilyInstance`,
`MigrationPlanner`, `MigrationRunner`, `SqlControlTargetDescriptor`) so the doc
reflects the current API and removes transitional/legacy wording.

---

Outside diff comments:
In `@packages/1-framework/1-core/framework-components/README.md`:
- Line 10: Update the Emission SPI bullet to remove stale generation-era types
(TargetFamilyHook, ValidationContext, GenerateContractTypesOptions,
TypeRenderEntry, TypeRenderer, ParameterizedCodecDescriptor and related types)
and instead document the current emission types as described by EmissionSpi (the
new SPI); replace the old list with a concise, accurate enumeration that matches
the explanation of EmissionSpi on Line 24.

In `@packages/2-mongo-family/3-tooling/emitter/README.md`:
- Around line 7-39: Update the README to remove references to the legacy
TargetFamilyHook and generateContractTypes flow and instead document the current
EmissionSpi + framework-owned DTS assembly model: keep the usage example showing
emit(contractIR, mongoEmission, options) and then replace the "What it provides"
and architecture sections to describe mongoEmission as an EmissionSpi
implementation that validates codec IDs and structure (ns/name@version),
delegates domain-level type generation to
`@prisma-next/emitter/domain-type-generation`, and relies on the framework to
assemble the final contract.d.ts artifacts; remove transition-state wording and
any mention of “generateContractTypes”/TargetFamilyHook while keeping
Mongo-specific validation points (collections, owned/embedded rules,
polymorphism, storage.relations) and references to contract.d.ts and contract
generation flow.

In `@packages/2-mongo-family/3-tooling/emitter/src/index.ts`:
- Around line 6-120: The exported mongoEmission object exposes
implementation-only methods validateTypes and validateStructure which leak
beyond the EmissionSpi boundary; rename these methods to private names (e.g.,
_validateTypes and _validateStructure) or remove them if unused, then add an
explicit type annotation ": EmissionSpi" to the mongoEmission export so the
public surface matches the SPI. Update any internal callers to reference the new
private names (mongoEmission._validateTypes / mongoEmission._validateStructure)
or remove those calls, and ensure the file imports/uses EmissionSpi so the
annotation type-checks.

---

Nitpick comments:
In
`@packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts`:
- Line 9: The test suite title is outdated: change the describe string from
'mongoEmission.generateContractTypes' to 'mongoEmission.generateContractDts' so
the suite name matches the actual function under test (generateContractDts) used
in the test; update the describe call in emitter-hook.generation.test.ts
accordingly to keep the test message accurate.

In `@packages/2-mongo-family/9-family/README.md`:
- Around line 8-16: The README uses outdated "target family hook" wording around
the renamed symbol mongoEmission; update the phrasing to consistently use
"EmissionSpi" (or "emission" terminology) throughout the document — especially
the bullet mentioning "Family Hook Integration" — and remove transition/legacy
wording so the responsibilities read: Family Descriptor Export
(ControlFamilyDescriptor), Family Instance Creation (MongoControlFamilyInstance
via create()), and Family Hook Integration (mongoEmission / EmissionSpi); ensure
all mentions of "target family hook" are replaced with "EmissionSpi" or
"emission" to match the current API surface.

In `@packages/2-sql/3-tooling/emitter/README.md`:
- Line 7: The README references the outdated symbol TargetFamilyHook; update the
prose to reference the current interface EmissionSpi so docs match the code
examples and refactor: replace the phrase "implements the `TargetFamilyHook`
interface" with "implements the `EmissionSpi` interface" and adjust any
surrounding wording to reflect EmissionSpi usage (search for TargetFamilyHook
and EmissionSpi in the README to ensure consistency).
- Line 21: The README's dependency list mentions the outdated symbol
TargetFamilyHook; update that entry to reference the new EmissionSpi symbol
instead (e.g., replace "TargetFamilyHook SPI" with "EmissionSpi" while
preserving surrounding context such as `@prisma-next/contract` and other type
names like `ValidationContext` and `TypesImportSpec`) so the doc reflects the
refactor.

In `@packages/2-sql/3-tooling/emitter/src/index.ts`:
- Around line 27-31: The code uses unsafe blind casts (as unknown as ...) on
contract.storage and contract.models inside sqlEmission (notably in
validateTypes and other methods); replace these with proper type guards such as
isSqlStorage(storage): storage is SqlStorage and isSqlModel(model): model is
SqlModel and use them to narrow types before accessing SQL-specific fields in
functions like validateTypes and any other methods referencing
contract.storage/contract.models (replace casts at the locations currently using
as unknown as); if this cannot be completed now, add a short justificatory
comment where each cast remains explaining why the SPI-family context guarantees
the type and mark TODO to implement the type predicate to avoid blind casts.

In `@packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts`:
- Around line 1-933: The test file is too large (933 lines); split the single
large spec into multiple focused test files to meet the 500-line guideline:
create smaller files such as emitter-hook.structure.models.test.ts,
emitter-hook.structure.tables.test.ts, and
emitter-hook.structure.foreignkeys.test.ts (or similar) and move related test
cases that exercise sqlEmission.validateStructure, the
describe('sql-target-family-hook') block, and the helper createContract into
those files; ensure each new file imports sqlEmission and the createContract
helper (or extract createContract into a shared test helper), and preserve all
test names and expectations so tests for model-level checks, table-level checks,
and foreignKey/index/constraint checks remain equivalent.
🪄 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: eadbedc1-784a-4251-8988-6b7a4c30d5cd

📥 Commits

Reviewing files that changed from the base of the PR and between a77e628 and d8be901.

⛔ Files ignored due to path filters (6)
  • packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • projects/contract-domain-extraction/plan.md is excluded by !projects/**
  • projects/contract-domain-extraction/plans/6-sql-emitter-shared-generation-plan.md is excluded by !projects/**
  • test/e2e/framework/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/mongo/fixtures/generated/contract.d.ts is excluded by !**/generated/**
📒 Files selected for processing (60)
  • docs/Testing Guide.md
  • docs/architecture docs/adrs/ADR 185 - SPI types live at the lowest consuming layer.md
  • examples/mongo-demo/src/app/App.tsx
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/1-core/config/src/config-validation.ts
  • packages/1-framework/1-core/config/test/config-types.test-d.ts
  • packages/1-framework/1-core/config/test/config-validation.test.ts
  • packages/1-framework/1-core/framework-components/README.md
  • packages/1-framework/1-core/framework-components/src/control-descriptors.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts
  • packages/1-framework/3-tooling/cli/test/config-loader.test.ts
  • packages/1-framework/3-tooling/cli/test/config-types.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • packages/1-framework/3-tooling/emitter/README.md
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.integration.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.roundtrip.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/1-framework/3-tooling/emitter/test/mock-spi.ts
  • packages/2-mongo-family/3-tooling/emitter/README.md
  • packages/2-mongo-family/3-tooling/emitter/src/exports/index.ts
  • packages/2-mongo-family/3-tooling/emitter/src/index.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.e2e.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.ts
  • packages/2-mongo-family/9-family/README.md
  • packages/2-mongo-family/9-family/src/core/control-descriptor.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-sql/3-tooling/emitter/README.md
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/2-sql/9-family/README.md
  • packages/2-sql/9-family/src/core/control-descriptor.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/2-sql/9-family/test/schema-view.test.ts
  • test/integration/test/authoring/cli.emit-parity-fixtures.test.ts
  • test/integration/test/authoring/psl.pgvector-dbinit.test.ts
  • test/integration/test/cli.emit-contract.test.ts
  • test/integration/test/cli.emit.test.ts
  • test/integration/test/contract-imports.test.ts
  • test/integration/test/control-api.test.ts
  • test/integration/test/family.verify-database.basic.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • test/integration/test/fixtures/cli/cli-e2e-test-app/fixtures/db-verify/prisma-next.config.no-verify.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.document-family.ts
  • test/integration/test/fixtures/contract.d.ts

Comment thread packages/2-sql/9-family/README.md Resolved
@wmadden
wmadden force-pushed the tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level branch from d8be901 to db7e5ae Compare April 6, 2026 20:26

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/2-sql/3-tooling/emitter/src/index.ts (1)

390-400: ⚠️ Potential issue | 🟠 Major

Keep SQL models emission aligned with shared model metadata shape.

Line 397 emits owner without readonly, and this override currently drops optional model metadata (discriminator, variants, base) when present. That can create a type-shape drift versus framework emission.

🛠️ Proposed fix
-      if (model.owner) {
-        modelParts.push(`owner: ${serializeValue(model.owner)}`);
-      }
+      if (model.owner) {
+        modelParts.push(`readonly owner: ${serializeValue(model.owner)}`);
+      }
+      if (model.discriminator) {
+        modelParts.push(`readonly discriminator: ${serializeValue(model.discriminator)}`);
+      }
+      if (model.variants) {
+        modelParts.push(`readonly variants: ${serializeValue(model.variants)}`);
+      }
+      if (model.base) {
+        modelParts.push(`readonly base: ${serializeValue(model.base)}`);
+      }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/src/index.ts` around lines 390 - 400, The
emitted model object is overriding the readonly shape and dropping optional
metadata; change the push that handles model.owner to emit a readonly property
(`readonly owner: ${serializeValue(model.owner)}`) and also include any optional
metadata keys (`discriminator`, `variants`, `base`) into modelParts when present
instead of overwriting the object literal—i.e., before pushing to modelParts,
detect model.discriminator, model.variants, model.base and push corresponding
`readonly <key>: ${serializeValue(...)}` entries alongside the owner entry so
modelTypes (and symbols modelParts, modelName, serializeValue) preserve the full
shared model metadata shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/2-sql/3-tooling/emitter/src/index.ts`:
- Around line 303-305: The code is using a blind double-cast (as unknown as
SqlStorage) in generateModelsType and other methods which bypasses type safety;
replace these casts by either refining the Contract type signatures to carry
SqlStorage where appropriate (e.g., make the function accept
Contract<SqlStorage>) or add an explicit runtime/type predicate (e.g.,
isSqlStorage(storage): storage is SqlStorage) and use it to narrow storage
before using it in generateModelsType and the other affected functions (also
update uses in the other occurrences noted). If the check fails, return/throw a
clear error; this preserves safety without blind casting and keeps the
references to Contract, SqlStorage, ContractModel, and SqlModelStorage intact.

---

Outside diff comments:
In `@packages/2-sql/3-tooling/emitter/src/index.ts`:
- Around line 390-400: The emitted model object is overriding the readonly shape
and dropping optional metadata; change the push that handles model.owner to emit
a readonly property (`readonly owner: ${serializeValue(model.owner)}`) and also
include any optional metadata keys (`discriminator`, `variants`, `base`) into
modelParts when present instead of overwriting the object literal—i.e., before
pushing to modelParts, detect model.discriminator, model.variants, model.base
and push corresponding `readonly <key>: ${serializeValue(...)}` entries
alongside the owner entry so modelTypes (and symbols modelParts, modelName,
serializeValue) preserve the full shared model metadata shape.
🪄 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: 98ca4a36-796e-45d5-a5b7-c24dcb5af977

📥 Commits

Reviewing files that changed from the base of the PR and between d8be901 and db7e5ae.

⛔ Files ignored due to path filters (6)
  • packages/2-sql/4-lanes/sql-builder/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • packages/3-extensions/sql-orm-client/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • projects/contract-domain-extraction/plan.md is excluded by !projects/**
  • projects/contract-domain-extraction/plans/6-sql-emitter-shared-generation-plan.md is excluded by !projects/**
  • test/e2e/framework/test/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/mongo/fixtures/generated/contract.d.ts is excluded by !**/generated/**
📒 Files selected for processing (60)
  • docs/Testing Guide.md
  • docs/architecture docs/adrs/ADR 185 - SPI types live at the lowest consuming layer.md
  • examples/mongo-demo/src/app/App.tsx
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/1-core/config/src/config-validation.ts
  • packages/1-framework/1-core/config/test/config-types.test-d.ts
  • packages/1-framework/1-core/config/test/config-validation.test.ts
  • packages/1-framework/1-core/framework-components/README.md
  • packages/1-framework/1-core/framework-components/src/control-descriptors.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts
  • packages/1-framework/3-tooling/cli/test/config-loader.test.ts
  • packages/1-framework/3-tooling/cli/test/config-types.test.ts
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • packages/1-framework/3-tooling/emitter/README.md
  • packages/1-framework/3-tooling/emitter/src/domain-type-generation.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.integration.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.roundtrip.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/1-framework/3-tooling/emitter/test/mock-spi.ts
  • packages/2-mongo-family/3-tooling/emitter/README.md
  • packages/2-mongo-family/3-tooling/emitter/src/exports/index.ts
  • packages/2-mongo-family/3-tooling/emitter/src/index.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.e2e.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.ts
  • packages/2-mongo-family/9-family/README.md
  • packages/2-mongo-family/9-family/src/core/control-descriptor.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-sql/3-tooling/emitter/README.md
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/2-sql/9-family/README.md
  • packages/2-sql/9-family/src/core/control-descriptor.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/2-sql/9-family/test/schema-view.test.ts
  • test/integration/test/authoring/cli.emit-parity-fixtures.test.ts
  • test/integration/test/authoring/psl.pgvector-dbinit.test.ts
  • test/integration/test/cli.emit-contract.test.ts
  • test/integration/test/cli.emit.test.ts
  • test/integration/test/contract-imports.test.ts
  • test/integration/test/control-api.test.ts
  • test/integration/test/family.verify-database.basic.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • test/integration/test/fixtures/cli/cli-e2e-test-app/fixtures/db-verify/prisma-next.config.no-verify.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.document-family.ts
  • test/integration/test/fixtures/contract.d.ts
✅ Files skipped from review due to trivial changes (29)
  • examples/mongo-demo/src/app/App.tsx
  • test/integration/test/family.verify-database.basic.test.ts
  • test/integration/test/family.verify-database.errors.test.ts
  • packages/1-framework/1-core/framework-components/src/control-descriptors.ts
  • test/integration/test/contract-imports.test.ts
  • packages/1-framework/1-core/framework-components/README.md
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • test/integration/test/authoring/cli.emit-parity-fixtures.test.ts
  • packages/1-framework/1-core/framework-components/src/framework-components.ts
  • packages/1-framework/1-core/framework-components/src/exports/emission.ts
  • packages/2-sql/3-tooling/emitter/README.md
  • packages/2-mongo-family/3-tooling/emitter/README.md
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-sql/9-family/README.md
  • test/integration/test/control-api.test.ts
  • test/integration/test/cli.emit.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.types.test.ts
  • packages/1-framework/3-tooling/cli/test/config-loader.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.parameterized-types.test.ts
  • docs/architecture docs/adrs/ADR 185 - SPI types live at the lowest consuming layer.md
  • packages/1-framework/3-tooling/cli/test/control-api/client.test.ts
  • packages/1-framework/1-core/config/test/config-validation.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.structure.test.ts
  • packages/1-framework/3-tooling/emitter/README.md
  • test/integration/test/authoring/psl.pgvector-dbinit.test.ts
  • packages/2-mongo-family/3-tooling/emitter/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (23)
  • packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts
  • packages/1-framework/3-tooling/cli/src/control-api/client.ts
  • packages/1-framework/1-core/config/src/config-validation.ts
  • packages/1-framework/3-tooling/emitter/src/exports/index.ts
  • packages/2-mongo-family/9-family/README.md
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.document-family.ts
  • packages/2-sql/9-family/test/emit-parameterized.test.ts
  • packages/2-sql/9-family/src/core/control-descriptor.ts
  • packages/2-mongo-family/3-tooling/emitter/src/exports/index.ts
  • packages/2-sql/9-family/test/schema-view.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/1-framework/3-tooling/emitter/test/domain-type-generation.test.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.basic.test.ts
  • packages/1-framework/3-tooling/emitter/src/emit.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.integration.test.ts
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • examples/prisma-next-demo/src/prisma/contract.d.ts
  • packages/1-framework/3-tooling/emitter/src/generate-contract-dts.ts
  • docs/Testing Guide.md
  • packages/1-framework/3-tooling/cli/test/config-types.test.ts
  • packages/1-framework/1-core/framework-components/src/emission-types.ts
  • test/integration/test/fixtures/cli/cli-e2e-test-app/fixtures/db-verify/prisma-next.config.no-verify.ts
  • packages/1-framework/1-core/config/test/config-types.test-d.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/2-sql/3-tooling/emitter/src/index.ts (1)

27-31: Add explicit EmissionSpi type annotation.

The sqlEmission object relies on as const without an explicit type annotation. This defers interface compliance checking to usage sites rather than catching mismatches at the definition.

♻️ Suggested fix
+import type { EmissionSpi } from '@prisma-next/framework-components/emission';
+
-export const sqlEmission = {
+export const sqlEmission: EmissionSpi = {
   id: 'sql',

Note: This would require removing as const at the end of the object (line 442) since the explicit type provides the necessary constraints.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-sql/3-tooling/emitter/src/index.ts` around lines 27 - 31, The
sqlEmission object should be explicitly typed as EmissionSpi to enforce
interface conformance at the definition site; update the declaration to export
const sqlEmission: EmissionSpi = { ... } (remove the trailing as const) so the
compiler verifies all required members (e.g., validateTypes, id, and other
methods/properties) are present and correctly typed, and adjust any
implementations inside sqlEmission (such as validateTypes and references to
SqlStorage) to satisfy the EmissionSpi signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/2-sql/3-tooling/emitter/src/index.ts`:
- Around line 14-25: The function serializeTypeParamsLiteral has a runtime
defensive check for falsy params but its signature is Record<string, unknown>,
so update the signature to accept undefined (e.g., params: Record<string,
unknown> | undefined) and adjust any callers if necessary (notably where
typeInstance.typeParams is passed) so the type system reflects that the
parameter may be absent; ensure the rest of serializeTypeParamsLiteral logic
remains unchanged and still returns 'Record<string, never>' for undefined/empty
inputs.

---

Nitpick comments:
In `@packages/2-sql/3-tooling/emitter/src/index.ts`:
- Around line 27-31: The sqlEmission object should be explicitly typed as
EmissionSpi to enforce interface conformance at the definition site; update the
declaration to export const sqlEmission: EmissionSpi = { ... } (remove the
trailing as const) so the compiler verifies all required members (e.g.,
validateTypes, id, and other methods/properties) are present and correctly
typed, and adjust any implementations inside sqlEmission (such as validateTypes
and references to SqlStorage) to satisfy the EmissionSpi signature.
🪄 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: 3176bb01-d2ec-4d92-be74-d0d10e9fcb41

📥 Commits

Reviewing files that changed from the base of the PR and between db7e5ae and cf97aff.

📒 Files selected for processing (3)
  • packages/1-framework/3-tooling/emitter/test/emitter.test.ts
  • packages/2-sql/3-tooling/emitter/src/index.ts
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/2-sql/3-tooling/emitter/test/emitter-hook.generation.advanced.test.ts

@wmadden
wmadden force-pushed the tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level branch from cf97aff to 892c50d Compare April 7, 2026 05:54
wmadden added 21 commits April 7, 2026 11:49
Mark all M5 tasks complete. Rewrite M6 as a single-pass approach
(post-M5): extend shared domain-level utilities, narrow the
TargetFamilyHook interface, and migrate both SQL and Mongo hooks
onto framework-owned template generation.

Detailed plan: projects/contract-domain-extraction/plans/6-sql-emitter-shared-generation-plan.md
Move generateModelFieldsType from Mongo emitter local function to the
shared @prisma-next/emitter/domain-type-generation module. Both SQL and
Mongo families now emit { codecId, nullable } for model fields, so this
function is family-agnostic. Update Mongo hook to import from shared.
Iterates models sorted by name, generates fields via
generateModelFieldsType, relations via generateModelRelationsType,
and storage via a family-provided callback. Handles optional owner,
discriminator, variants, and base properties.
Replace the vague TargetFamilyHook name with EmissionSpi — a focused
interface for the family-specific parts of contract type emission.
Rename the descriptor property from hook to emission. Pure rename,
no behavioral change.
Establishes the call site for framework-owned template assembly.
Initially delegates to emitter.generateContractTypes — the real
template logic moves here in the next step.
…ntractDts

Replace the monolithic generateContractTypes method with focused SPI
callbacks: generateStorageType, generateModelStorageType,
getFamilyImports, getFamilyTypeAliases, getTypeMapsExpression,
getContractWrapper. SQL provides an optional generateModelsType
override because it derives field codecs from storage columns.

The framework generateContractDts function now owns the .d.ts template
assembly using shared utilities and SPI callbacks. Both SQL and Mongo
emitters implement the narrowed SPI. emit() delegates to
generateContractDts instead of calling the hook directly.
Update mockHook objects in config and CLI tests to implement all
EmissionSpi methods. Remove unused TypesImportSpec import and prefix
unused modelName param in SQL emitter. Fix ContractVariantEntry shape
in domain-type-generation test (value, not model). Regenerate e2e
fixture contract.d.ts with framework-owned template output ordering.
Remove IRModelField/IRModelStorage/IRModelDefinition from SQL emitter,
use ContractModel<SqlModelStorage> for type-safe storage access.
Remove MongoModelIR from Mongo emitter, use ContractModel directly.
Remove leaked serializeTypeParamsLiteral/serializeValue properties
from SQL hook object (not part of EmissionSpi). Remove unnecessary
type casts on contract.models in generateContractDts (always present).
Remove redundant serialization tests already covered by shared module.
…sion/mongoEmission

Align export names with the EmissionSpi concept. The old names
referenced the replaced TargetFamilyHook abstraction.
Remove validateTypes/validateStructure from the EmissionSpi interface
and from the emit() function. Validation is the responsibility of the
upstream pipeline (familyInstance.validateContract() in contract-emit).
The validation methods remain on the hook objects and are tested
independently via their dedicated test files.
The framework template now emits readonly targetFamily alongside
readonly target in the intersection type, restoring literal narrowing
that was present in the old family-specific templates. Also restore
empty-models guard in SQL generateModelsType.
Document the framework-owned template, EmissionSpi callbacks, and the
SQL generateModelsType override limitation. Remove stale references
to TargetFamilyHook and the old hook-based architecture.
The complex IR roundtrip test timed out at the default 200ms on CI.
Add timeouts.typeScriptCompilation to match other roundtrip tests.

Regenerate all contract.d.ts fixtures to reflect the new
framework-owned template output (import order, ContractType alias,
targetFamily literal, family type aliases positioning).
Cover emit.ts ?? fallbacks, generate-contract-dts.ts
generateModelsType delegation and execution clause branches,
and sql emitter generateModelStorageType and model.owner paths.
…nature

Align the type signature with the defensive runtime check for falsy params.
Serialize the execution section field-by-field so executionHash references
the generated ExecutionHash type alias instead of being a plain string literal.
Align all references, code examples, and descriptions with the renamed
interface and the removal of validation methods from the emission SPI.
…elsType

Rebase conflict resolution dropped the upstream renderer integration.
Restore the check that uses parameterized renderers when available,
clean up unused imports, and fix the resolved variable name mismatch.
@wmadden
wmadden force-pushed the tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level branch from 0f79c30 to f857cb5 Compare April 7, 2026 09:55
wmadden added 2 commits April 7, 2026 12:07
Cast contract.models to Record<string, ContractModel> at the
generate-contract-dts call site since Contract.models defaults to
ContractModelBase but at emit time fields are always ContractField.

Add timeouts.typeScriptCompilation to the stable-hashes integration
test to prevent CI timeout on slower runners.
Contract.models defaults to ContractModelBase where fields are
Readonly<Record<string, unknown>>, so field values are typed as
unknown. Add a targeted cast since this is a validation function
that checks for codecId presence.
@wmadden
wmadden merged commit 8d2cc5e into main Apr 7, 2026
15 checks passed
@wmadden
wmadden deleted the tml-2188-m6-migrate-sql-emitter-hook-to-shared-domain-level branch April 7, 2026 10:22
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.

1 participant