Repository navigation
refactor(mongo): decompose mongo-core into layered packages - #298
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRestructures the MongoDB family by splitting Changes
Sequence Diagram(s)sequenceDiagram
participant Runtime as MongoRuntime
participant Adapter as MongoAdapter
participant Driver as MongoDriver
participant DB as MongoDB
Runtime->>Adapter: execute(plan: MongoQueryPlan) -> adapter.lower(plan)
Adapter-->>Runtime: AnyMongoWireCommand
Runtime->>Driver: driver.execute(wireCommand)
Driver->>DB: run wire command
DB-->>Driver: results (cursor/iterable)
Driver-->>Runtime: AsyncIterableResult<Row>
Runtime-->>Client: AsyncIterableResult<Row>
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
packages/2-mongo-family/1-foundation/mongo-codec/package.json (1)
30-36: Expose module-level subpaths for the shared codec surface.Only exporting
.here means internal callers have to come through the root package instead of explicit modules. For a shared-plane package, it would be better to publish the stable surfaces separately—at least the type surface and the factory surface—so consumers can import them directly.As per coding guidelines, "Create explicit export paths in package.json following the pattern: ./types, ./validators, ./factories for shared plane packages" and "Import directly from the specific module ... instead of barrel imports."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/2-mongo-family/1-foundation/mongo-codec/package.json` around lines 30 - 36, The package currently only exports the root ("."), forcing consumers to import from the package barrel; add explicit export subpaths for the stable shared surfaces so callers can import modules directly. Update the "exports" block in package.json to include "./types", "./validators", and "./factories" keys mapped to their built JS (e.g., dist/types.mjs, dist/validators.mjs, dist/factories.mjs) and corresponding type entries (e.g., types: "./dist/index.d.mts" or matching per-subpath), and ensure the "types" and "main"/"module" fields align with those subpath entries so consumers can import from "mongo-codec/types", "mongo-codec/validators", and "mongo-codec/factories" instead of the root.packages/2-mongo-family/6-transport/mongo-wire/package.json (1)
31-37: Expose the wire modules as explicit package subpaths.Right now consumers only have the root barrel, which encourages imports like
@prisma-next/mongo-wireinstead of explicit module boundaries. Publishing the stable modules separately—e.g. commands and results—would keep the new layering more explicit.As per coding guidelines, "Create explicit export paths in package.json following the pattern: ./types, ./validators, ./factories for shared plane packages" and "Import directly from the specific module ... instead of barrel imports."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/2-mongo-family/6-transport/mongo-wire/package.json` around lines 31 - 37, Update the package.json "exports" to add explicit subpath exports for the wire modules (e.g., "./commands", "./results", "./types", "./validators", "./factories") so consumers can import specific modules instead of the barrel; point each export to the compiled ESM entry in dist (e.g., "./dist/commands/index.mjs", "./dist/results/index.mjs") and add corresponding type entries pointing to their declaration files (e.g., "./dist/commands/index.d.mts"), and mirror these subpaths under "types" or include "./package.json" as already present—modify the existing "exports" map (and ensure "main"/"module"/"types" remain consistent) so each unique symbol (the export keys like "./commands" and "./results") resolves to the right dist and type files.docs/architecture docs/adrs/ADR 184 - Codec-owned value serialization.md (1)
92-101: Minor: Consider varying sentence structure for readability.Three sentences in this section begin with "PSL" which reads slightly repetitively. Consider rephrasing for variety:
📝 Suggested rewording
-PSL is an authoring-specific concern. PSL's grammar constrains what literal syntax is possible — not every codec can have a PSL literal representation. Contributed through the authoring layer, keyed by codec ID: +PSL is an authoring-specific concern. The grammar constrains what literal syntax is possible — not every codec can have a PSL literal representation. Contributed through the authoring layer, keyed by codec ID:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/architecture` docs/adrs/ADR 184 - Codec-owned value serialization.md around lines 92 - 101, The opening sentences in the PSL literal interface section have repetitive structure, with multiple sentences beginning with "PSL" which reduces readability. Rephrase the sentences that start with "PSL is an authoring-specific concern" and "PSL's grammar constrains what literal syntax is possible" to vary the sentence structure and improve flow, while maintaining the same technical meaning and information content.
🤖 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-mongo-family/4-query/query-ast/tsconfig.json`:
- Line 7: Update the tsconfig "exclude" array to also exclude fixture files by
adding the pattern "test/fixtures/**/*" so fixture-only types won't be pulled
into project typechecking; modify the existing "exclude" entry (the "exclude"
key in tsconfig.json) to include that string alongside "dist", "dist-tsc",
"dist-tsc-prod", and "node_modules".
---
Nitpick comments:
In `@docs/architecture` docs/adrs/ADR 184 - Codec-owned value serialization.md:
- Around line 92-101: The opening sentences in the PSL literal interface section
have repetitive structure, with multiple sentences beginning with "PSL" which
reduces readability. Rephrase the sentences that start with "PSL is an
authoring-specific concern" and "PSL's grammar constrains what literal syntax is
possible" to vary the sentence structure and improve flow, while maintaining the
same technical meaning and information content.
In `@packages/2-mongo-family/1-foundation/mongo-codec/package.json`:
- Around line 30-36: The package currently only exports the root ("."), forcing
consumers to import from the package barrel; add explicit export subpaths for
the stable shared surfaces so callers can import modules directly. Update the
"exports" block in package.json to include "./types", "./validators", and
"./factories" keys mapped to their built JS (e.g., dist/types.mjs,
dist/validators.mjs, dist/factories.mjs) and corresponding type entries (e.g.,
types: "./dist/index.d.mts" or matching per-subpath), and ensure the "types" and
"main"/"module" fields align with those subpath entries so consumers can import
from "mongo-codec/types", "mongo-codec/validators", and "mongo-codec/factories"
instead of the root.
In `@packages/2-mongo-family/6-transport/mongo-wire/package.json`:
- Around line 31-37: Update the package.json "exports" to add explicit subpath
exports for the wire modules (e.g., "./commands", "./results", "./types",
"./validators", "./factories") so consumers can import specific modules instead
of the barrel; point each export to the compiled ESM entry in dist (e.g.,
"./dist/commands/index.mjs", "./dist/results/index.mjs") and add corresponding
type entries pointing to their declaration files (e.g.,
"./dist/commands/index.d.mts"), and mirror these subpaths under "types" or
include "./package.json" as already present—modify the existing "exports" map
(and ensure "main"/"module"/"types" remain consistent) so each unique symbol
(the export keys like "./commands" and "./results") resolves to the right dist
and type files.
🪄 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: d4f513a9-47f7-44c9-8ac4-1b23ae6fe3be
⛔ Files ignored due to path filters (5)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/orm-consolidation/plan.mdis excluded by!projects/**projects/orm-consolidation/plans/mongo-family-layering-execution.mdis excluded by!projects/**projects/orm-consolidation/plans/mongo-family-layering.mdis excluded by!projects/**test/integration/test/mongo/fixtures/generated/contract.d.tsis excluded by!**/generated/**
📒 Files selected for processing (143)
architecture.config.jsondocs/architecture docs/adrs/ADR 167 - Typed default literal pipeline and extensibility.mddocs/architecture docs/adrs/ADR 173 - Polymorphism via discriminator and variants.mddocs/architecture docs/adrs/ADR 184 - Codec-owned value serialization.mddocs/architecture docs/subsystems/10. MongoDB Family.mddocs/planning/april-milestone.mddocs/planning/mongo-target/1-design-docs/mongo-execution-components.mdexamples/mongo-demo/package.jsonexamples/mongo-demo/src/contract.d.tsexamples/mongo-demo/src/db.tsexamples/mongo-demo/test/blog.test.tsexamples/mongo-demo/test/crud-lifecycle.test.tspackages/1-framework/1-core/shared/framework-components/test/control-stack.test.tspackages/2-mongo-family/1-core/README.mdpackages/2-mongo-family/1-core/src/adapter-types.tspackages/2-mongo-family/1-core/src/exports/codec-types.tspackages/2-mongo-family/1-core/src/exports/index.tspackages/2-mongo-family/1-core/src/validate-domain.tspackages/2-mongo-family/1-foundation/mongo-codec/package.jsonpackages/2-mongo-family/1-foundation/mongo-codec/src/codec-registry.tspackages/2-mongo-family/1-foundation/mongo-codec/src/codecs.tspackages/2-mongo-family/1-foundation/mongo-codec/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-codec/test/codecs.test-d.tspackages/2-mongo-family/1-foundation/mongo-codec/test/codecs.test.tspackages/2-mongo-family/1-foundation/mongo-codec/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-codec/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-codec/vitest.config.tspackages/2-mongo-family/1-foundation/mongo-contract/package.jsonpackages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.tspackages/2-mongo-family/1-foundation/mongo-contract/src/contract-types.tspackages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-contract/src/validate-mongo-contract.tspackages/2-mongo-family/1-foundation/mongo-contract/src/validate-storage.tspackages/2-mongo-family/1-foundation/mongo-contract/test/fixtures/orm-contract.d.tspackages/2-mongo-family/1-foundation/mongo-contract/test/fixtures/orm-contract.jsonpackages/2-mongo-family/1-foundation/mongo-contract/test/validate-domain.test.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate-storage.test.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/1-foundation/mongo-contract/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-contract/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-contract/vitest.config.tspackages/2-mongo-family/1-foundation/mongo-value/package.jsonpackages/2-mongo-family/1-foundation/mongo-value/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-value/src/param-ref.tspackages/2-mongo-family/1-foundation/mongo-value/src/values.tspackages/2-mongo-family/1-foundation/mongo-value/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-value/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-value/vitest.config.tspackages/2-mongo-family/3-tooling/emitter/package.jsonpackages/2-mongo-family/3-tooling/emitter/src/index.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.e2e.test.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.tspackages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.tspackages/2-mongo-family/4-query/query-ast/README.mdpackages/2-mongo-family/4-query/query-ast/biome.jsoncpackages/2-mongo-family/4-query/query-ast/package.jsonpackages/2-mongo-family/4-query/query-ast/src/ast-node.tspackages/2-mongo-family/4-query/query-ast/src/commands.tspackages/2-mongo-family/4-query/query-ast/src/exports/index.tspackages/2-mongo-family/4-query/query-ast/src/filter-expressions.tspackages/2-mongo-family/4-query/query-ast/src/query-plan.tspackages/2-mongo-family/4-query/query-ast/src/stages.tspackages/2-mongo-family/4-query/query-ast/src/visitors.tspackages/2-mongo-family/4-query/query-ast/test/filter-expressions.test.tspackages/2-mongo-family/4-query/query-ast/test/stages.test.tspackages/2-mongo-family/4-query/query-ast/tsconfig.jsonpackages/2-mongo-family/4-query/query-ast/tsconfig.prod.jsonpackages/2-mongo-family/4-query/query-ast/tsdown.config.tspackages/2-mongo-family/4-query/query-ast/vitest.config.tspackages/2-mongo-family/5-query-builders/README.mdpackages/2-mongo-family/5-query-builders/package.jsonpackages/2-mongo-family/5-query-builders/src/collection-state.tspackages/2-mongo-family/5-query-builders/src/collection.tspackages/2-mongo-family/5-query-builders/src/compile.tspackages/2-mongo-family/5-query-builders/src/executor.tspackages/2-mongo-family/5-query-builders/src/exports/index.tspackages/2-mongo-family/5-query-builders/src/mongo-orm.tspackages/2-mongo-family/5-query-builders/src/types.tspackages/2-mongo-family/5-query-builders/test/collection.test.tspackages/2-mongo-family/5-query-builders/test/compile.test.tspackages/2-mongo-family/5-query-builders/test/orm-types.test-d.tspackages/2-mongo-family/5-query-builders/tsconfig.jsonpackages/2-mongo-family/5-query-builders/tsconfig.prod.jsonpackages/2-mongo-family/5-query-builders/tsdown.config.tspackages/2-mongo-family/5-query-builders/vitest.config.tspackages/2-mongo-family/5-runtime/biome.jsoncpackages/2-mongo-family/5-runtime/tsconfig.prod.jsonpackages/2-mongo-family/6-transport/mongo-lowering/package.jsonpackages/2-mongo-family/6-transport/mongo-lowering/src/adapter-types.tspackages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.tspackages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.tspackages/2-mongo-family/6-transport/mongo-lowering/tsconfig.jsonpackages/2-mongo-family/6-transport/mongo-lowering/tsdown.config.tspackages/2-mongo-family/6-transport/mongo-lowering/vitest.config.tspackages/2-mongo-family/6-transport/mongo-wire/package.jsonpackages/2-mongo-family/6-transport/mongo-wire/src/exports/index.tspackages/2-mongo-family/6-transport/mongo-wire/src/results.tspackages/2-mongo-family/6-transport/mongo-wire/src/wire-commands.tspackages/2-mongo-family/6-transport/mongo-wire/tsconfig.jsonpackages/2-mongo-family/6-transport/mongo-wire/tsdown.config.tspackages/2-mongo-family/6-transport/mongo-wire/vitest.config.tspackages/2-mongo-family/7-runtime/README.mdpackages/2-mongo-family/7-runtime/biome.jsoncpackages/2-mongo-family/7-runtime/package.jsonpackages/2-mongo-family/7-runtime/src/exports/index.tspackages/2-mongo-family/7-runtime/src/mongo-runtime.tspackages/2-mongo-family/7-runtime/test/aggregate.test.tspackages/2-mongo-family/7-runtime/test/contract-types.test-d.tspackages/2-mongo-family/7-runtime/test/delete-many.test.tspackages/2-mongo-family/7-runtime/test/delete.test.tspackages/2-mongo-family/7-runtime/test/find-one-and-delete.test.tspackages/2-mongo-family/7-runtime/test/find-one-and-update.test.tspackages/2-mongo-family/7-runtime/test/fixtures/contract.d.tspackages/2-mongo-family/7-runtime/test/fixtures/contract.jsonpackages/2-mongo-family/7-runtime/test/insert-many.test.tspackages/2-mongo-family/7-runtime/test/insert.test.tspackages/2-mongo-family/7-runtime/test/orm-contract-types.test-d.tspackages/2-mongo-family/7-runtime/test/read-plan.test.tspackages/2-mongo-family/7-runtime/test/setup.tspackages/2-mongo-family/7-runtime/test/update-many.test.tspackages/2-mongo-family/7-runtime/test/update.test.tspackages/2-mongo-family/7-runtime/tsconfig.jsonpackages/2-mongo-family/7-runtime/tsconfig.prod.jsonpackages/2-mongo-family/7-runtime/tsdown.config.tspackages/2-mongo-family/7-runtime/vitest.config.tspackages/2-mongo-family/9-family/package.jsonpackages/2-mongo-family/9-family/src/core/control-instance.tspackages/2-mongo-family/9-family/src/core/mongo-target-descriptor.tspackages/2-mongo-family/9-family/test/control.test.tspackages/3-mongo-target/1-mongo-target/package.jsonpackages/3-mongo-target/2-mongo-adapter/package.jsonpackages/3-mongo-target/2-mongo-adapter/src/core/codecs.tspackages/3-mongo-target/2-mongo-adapter/src/exports/control.tspackages/3-mongo-target/2-mongo-adapter/src/lowering.tspackages/3-mongo-target/2-mongo-adapter/src/mongo-adapter.tspackages/3-mongo-target/2-mongo-adapter/src/resolve-value.tspackages/3-mongo-target/2-mongo-adapter/test/lowering.test.tspackages/3-mongo-target/2-mongo-adapter/test/mongo-adapter.test.tspackages/3-mongo-target/3-mongo-driver/package.jsonpackages/3-mongo-target/3-mongo-driver/src/mongo-driver.tspackages/3-mongo-target/3-mongo-driver/test/mongo-driver.test.tstest/integration/package.jsontest/integration/test/mongo/orm.test.ts
💤 Files with no reviewable changes (11)
- packages/2-mongo-family/9-family/test/control.test.ts
- packages/2-mongo-family/1-foundation/mongo-value/tsdown.config.ts
- packages/2-mongo-family/1-core/README.md
- packages/2-mongo-family/1-foundation/mongo-codec/vitest.config.ts
- packages/2-mongo-family/1-core/src/exports/codec-types.ts
- packages/2-mongo-family/1-core/src/validate-domain.ts
- packages/2-mongo-family/5-runtime/tsconfig.prod.json
- packages/2-mongo-family/5-runtime/biome.jsonc
- packages/2-mongo-family/1-core/src/adapter-types.ts
- packages/2-mongo-family/9-family/src/core/mongo-target-descriptor.ts
- packages/2-mongo-family/1-core/src/exports/index.ts
@prisma-next/mongo-orm
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/core-control-plane
@prisma-next/core-execution-plane
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
@prisma-next/vite-plugin-contract-emit
@prisma-next/runtime-executor
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-emitter
@prisma-next/mongo-query-ast
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/adapter-postgres
@prisma-next/driver-postgres
commit: |
643d2f8 to
b7976cd
Compare
Record implementation phases (foundation split, transport layer, shim elimination, renumber) and design decisions: MongoQueryExecutor stays in ORM, codec-types moves to adapter descriptor, mongo-codec has no codec-types entrypoint.
validate-domain.ts is a pure re-export — delete it, import directly from @prisma-next/contract. Update MongoQueryExecutor rationale with the SQL ORM client precedent (consumer owns the interface).
Move MongoValue, Document, MongoParamRef, and related value types into a dedicated foundation package. Update all consumers to import from the new package directly.
Move MongoCodec interface, mongoCodec() factory, MongoCodecRegistry, and related types into a dedicated foundation package. Update adapter codecs import to use the new package.
Move contract types (MongoContract, MongoStorage, etc.), validation (validateMongoContract, validateMongoStorage), and related schemas into a dedicated foundation package. Update the emitter template string, ORM, family, runtime fixtures, examples, and integration tests to import from the new package. Delete validate-domain.ts re-export in favor of direct imports from @prisma-next/contract.
Delete the hand-maintained CodecTypes duplicate from mongo-core, remove types.codecTypes.import from the target descriptor, and add it to the mongo adapter descriptor following the postgres pattern. Update all generated contract.d.ts fixtures and emitter tests to reference @prisma-next/adapter-mongo/codec-types.
Remove all re-exports of value, codec, contract, and validation types from mongo-core exports. mongo-core now only exports wire command types and lowering interfaces (adapter/driver types).
Move wire command classes (InsertOneWireCommand, etc.) and result types into a dedicated transport-layer package. Update adapter, driver, and their tests to import from the new package.
Move MongoAdapter and MongoDriver interfaces (with MongoQueryPlanLike) into a dedicated transport-layer package. Update runtime, adapter, and driver to import from the new package.
All contents have been extracted to dedicated packages: - mongo-value, mongo-codec, mongo-contract (foundation) - mongo-wire, mongo-lowering (transport) Remove all @prisma-next/mongo-core dependency declarations and update remaining test imports to reference the new packages.
Align WS4 task 3 with the updated ORM consolidation plan: implement polymorphism independently in both ORM clients before extracting the shared Collection interface (Phase 2). The two families diverge in query compilation for polymorphism, so both concrete implementations are needed to discover the right abstraction boundary (ADR 175).
Replace the structural MongoQueryPlanLike interface with the concrete MongoQueryPlan type from @prisma-next/mongo-query-ast in the adapter interface, runtime, and adapter implementation. This is possible now that the transport layer sits above the query layer in the package hierarchy.
Rename 2-query -> 4-query, 4-orm -> 5-query-builders, 5-runtime -> 7-runtime to match the layer order defined in the layering plan. Update architecture.config.json with new layer names and globs for the mongo domain. Fix test fixtures and imports that referenced the deleted 1-core directory.
Codecs own all representations of their values (wire, contract JSON, DDL, PSL) instead of hardcoding bigint/Date branches across five pipeline stages. Eliminates the tagged type system ($type wrappers) by relying on the codec ID from context. Supersedes ADR 167 v2. Resolves ADR 173 open question on untyped discriminator values.
Lead with the concrete pain (six hardcoded branches for bigint), build to the key insight (codec ID is always in context), then present the decision and walk through an end-to-end example. Add migration operations as an additional boundary. Move alternatives considered to the end.
Address code review feedback F01 and F02: update the package layout section to match the current directory structure after renumbering, and fix the MongoRuntimeCore name to MongoRuntime (the public interface name, not the private implementation class).
Codec-owned value serialization is a prerequisite for Phase 1.75 (polymorphism): the emitter and runtime need codec dispatch to serialize/decode discriminator values in contract.json. Sequenced after Phase 1.5 and before Phase 1.75 with updated dependency chain.
Split coarse whole-package plane globs into per-entrypoint assignments to match the SQL/Postgres precedent. This allows lint:deps to enforce the migration-runtime boundary within these packages. - 9-family: src/core/** -> shared, src/exports/control.ts -> migration - 2-mongo-adapter: control.ts -> migration, index.ts -> runtime, codec-types.ts -> shared
…lification in Phase 1.75 Value objects and typed JSON columns serve different purposes but share infrastructure. This spec defines the end-to-end implementation of value objects (ADR 178) and the simplification of typed JSON column machinery to use codec-dispatched type rendering (ADR 184 pattern) instead of bespoke parameterizedRenderers.
…n orm-contract fixture The orm-contract.d.ts test fixture imports CodecTypes from @prisma-next/adapter-mongo/codec-types. TypeScript resolves module imports relative to the file location (mongo-contract), not the importing package (mongo-orm). Both packages need the dependency: mongo-contract for resolution and mongo-orm for completeness.
Phase 1.75a: typed JSON simplification (TML-2204) Phase 1.75b: polymorphism in both families (TML-2205) Phase 1.75c: value objects & embedded documents (TML-2206) 1.75a and 1.75b are independent and can run in parallel. 1.75c depends on 1.75a (codec-dispatched renderType). Replaces cancelled TML-2203.
ADR 183 (aggregation pipeline only) was created first and has widespread references. The SPI types ADR was created a day later on a different branch, unaware of the collision.
validateContractDomain now returns void (warnings and orphan detection were removed from main). Align mongo-contract validation and tests accordingly.
b7976cd to
570be0b
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@architecture.config.json`:
- Around line 316-329: Update the package exports for
packages/3-mongo-target/2-mongo-adapter and packages/2-mongo-family/9-family so
they expose the standardized subpath keys ./runtime, ./adapter and ./control (or
./ as appropriate) instead of mapping default or wrong subpaths: open each
package.json and add/replace the "exports" map to include "./runtime" pointing
to the runtime entry (e.g., src/exports/index.ts), "./adapter" pointing to
shared/codec or adapter types (e.g., src/exports/codec-types.ts), and
"./control" pointing to control entry (e.g., src/exports/control.ts); then
update architecture.config.json globs to exactly match those source files
(ensure entries reference
packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts, .../index.ts,
.../codec-types.ts and the corresponding files under
packages/2-mongo-family/9-family) so the domain/layer/plane mapping aligns with
the new subpath names.
In `@docs/architecture` docs/subsystems/10. MongoDB Family.md:
- Line 255: The docs incorrectly show MongoRuntime.execute as execute(plan:
MongoQueryPlan): AsyncIterableResult<Row>; update the signature to include the
generic type parameter by documenting it as execute<Row>(plan:
MongoQueryPlan<Row>): AsyncIterableResult<Row>, ensuring the generic appears on
the method and on the MongoQueryPlan type argument (referencing
MongoRuntime.execute, MongoQueryPlan and AsyncIterableResult) so the
documentation matches the actual interface.
🪄 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: 5ba65237-a4d5-4558-8560-20e020fbb167
📒 Files selected for processing (109)
architecture.config.jsondocs/architecture docs/adrs/ADR 167 - Typed default literal pipeline and extensibility.mddocs/architecture docs/adrs/ADR 173 - Polymorphism via discriminator and variants.mddocs/architecture docs/adrs/ADR 184 - Codec-owned value serialization.mddocs/architecture docs/adrs/ADR 185 - SPI types live at the lowest consuming layer.mddocs/architecture docs/subsystems/10. MongoDB Family.mddocs/planning/april-milestone.mddocs/planning/mongo-target/1-design-docs/mongo-execution-components.mdexamples/mongo-demo/package.jsonexamples/mongo-demo/src/contract.d.tsexamples/mongo-demo/src/db.tsexamples/mongo-demo/test/blog.test.tsexamples/mongo-demo/test/crud-lifecycle.test.tspackages/1-framework/0-foundation/contract/README.mdpackages/1-framework/1-core/framework-components/README.mdpackages/1-framework/1-core/framework-components/test/control-stack.test.tspackages/2-mongo-family/1-core/README.mdpackages/2-mongo-family/1-core/src/adapter-types.tspackages/2-mongo-family/1-core/src/exports/codec-types.tspackages/2-mongo-family/1-core/src/exports/index.tspackages/2-mongo-family/1-core/src/validate-domain.tspackages/2-mongo-family/1-foundation/mongo-codec/README.mdpackages/2-mongo-family/1-foundation/mongo-codec/package.jsonpackages/2-mongo-family/1-foundation/mongo-codec/src/codec-registry.tspackages/2-mongo-family/1-foundation/mongo-codec/src/codecs.tspackages/2-mongo-family/1-foundation/mongo-codec/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-codec/test/codecs.test-d.tspackages/2-mongo-family/1-foundation/mongo-codec/test/codecs.test.tspackages/2-mongo-family/1-foundation/mongo-codec/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-codec/tsconfig.prod.jsonpackages/2-mongo-family/1-foundation/mongo-codec/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-codec/vitest.config.tspackages/2-mongo-family/1-foundation/mongo-contract/README.mdpackages/2-mongo-family/1-foundation/mongo-contract/package.jsonpackages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.tspackages/2-mongo-family/1-foundation/mongo-contract/src/contract-types.tspackages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-contract/src/validate-mongo-contract.tspackages/2-mongo-family/1-foundation/mongo-contract/src/validate-storage.tspackages/2-mongo-family/1-foundation/mongo-contract/test/fixtures/orm-contract.d.tspackages/2-mongo-family/1-foundation/mongo-contract/test/fixtures/orm-contract.jsonpackages/2-mongo-family/1-foundation/mongo-contract/test/validate-domain.test.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate-storage.test.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/1-foundation/mongo-contract/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-contract/tsconfig.prod.jsonpackages/2-mongo-family/1-foundation/mongo-contract/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-contract/vitest.config.tspackages/2-mongo-family/1-foundation/mongo-value/README.mdpackages/2-mongo-family/1-foundation/mongo-value/package.jsonpackages/2-mongo-family/1-foundation/mongo-value/src/exports/index.tspackages/2-mongo-family/1-foundation/mongo-value/src/param-ref.tspackages/2-mongo-family/1-foundation/mongo-value/src/values.tspackages/2-mongo-family/1-foundation/mongo-value/tsconfig.jsonpackages/2-mongo-family/1-foundation/mongo-value/tsconfig.prod.jsonpackages/2-mongo-family/1-foundation/mongo-value/tsdown.config.tspackages/2-mongo-family/1-foundation/mongo-value/vitest.config.tspackages/2-mongo-family/3-tooling/emitter/package.jsonpackages/2-mongo-family/3-tooling/emitter/src/index.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.e2e.test.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.tspackages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.tspackages/2-mongo-family/4-query/query-ast/README.mdpackages/2-mongo-family/4-query/query-ast/biome.jsoncpackages/2-mongo-family/4-query/query-ast/package.jsonpackages/2-mongo-family/4-query/query-ast/src/ast-node.tspackages/2-mongo-family/4-query/query-ast/src/commands.tspackages/2-mongo-family/4-query/query-ast/src/exports/index.tspackages/2-mongo-family/4-query/query-ast/src/filter-expressions.tspackages/2-mongo-family/4-query/query-ast/src/query-plan.tspackages/2-mongo-family/4-query/query-ast/src/stages.tspackages/2-mongo-family/4-query/query-ast/src/visitors.tspackages/2-mongo-family/4-query/query-ast/test/filter-expressions.test.tspackages/2-mongo-family/4-query/query-ast/test/stages.test.tspackages/2-mongo-family/4-query/query-ast/tsconfig.jsonpackages/2-mongo-family/4-query/query-ast/tsconfig.prod.jsonpackages/2-mongo-family/4-query/query-ast/tsdown.config.tspackages/2-mongo-family/4-query/query-ast/vitest.config.tspackages/2-mongo-family/5-query-builders/README.mdpackages/2-mongo-family/5-query-builders/package.jsonpackages/2-mongo-family/5-query-builders/src/collection-state.tspackages/2-mongo-family/5-query-builders/src/collection.tspackages/2-mongo-family/5-query-builders/src/compile.tspackages/2-mongo-family/5-query-builders/src/executor.tspackages/2-mongo-family/5-query-builders/src/exports/index.tspackages/2-mongo-family/5-query-builders/src/mongo-orm.tspackages/2-mongo-family/5-query-builders/src/types.tspackages/2-mongo-family/5-query-builders/test/collection.test.tspackages/2-mongo-family/5-query-builders/test/compile.test.tspackages/2-mongo-family/5-query-builders/test/orm-types.test-d.tspackages/2-mongo-family/5-query-builders/tsconfig.jsonpackages/2-mongo-family/5-query-builders/tsconfig.prod.jsonpackages/2-mongo-family/5-query-builders/tsdown.config.tspackages/2-mongo-family/5-query-builders/vitest.config.tspackages/2-mongo-family/5-runtime/biome.jsoncpackages/2-mongo-family/6-transport/mongo-lowering/README.mdpackages/2-mongo-family/6-transport/mongo-lowering/package.jsonpackages/2-mongo-family/6-transport/mongo-lowering/src/adapter-types.tspackages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.tspackages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.tspackages/2-mongo-family/6-transport/mongo-lowering/tsconfig.jsonpackages/2-mongo-family/6-transport/mongo-lowering/tsconfig.prod.jsonpackages/2-mongo-family/6-transport/mongo-lowering/tsdown.config.tspackages/2-mongo-family/6-transport/mongo-lowering/vitest.config.tspackages/2-mongo-family/6-transport/mongo-wire/README.mdpackages/2-mongo-family/6-transport/mongo-wire/package.jsonpackages/2-mongo-family/6-transport/mongo-wire/src/exports/index.tspackages/2-mongo-family/6-transport/mongo-wire/src/results.tspackages/2-mongo-family/6-transport/mongo-wire/src/wire-commands.ts
💤 Files with no reviewable changes (8)
- packages/2-mongo-family/1-foundation/mongo-codec/vitest.config.ts
- packages/2-mongo-family/1-foundation/mongo-value/tsdown.config.ts
- packages/2-mongo-family/1-core/src/exports/codec-types.ts
- packages/2-mongo-family/5-runtime/biome.jsonc
- packages/2-mongo-family/1-core/README.md
- packages/2-mongo-family/1-core/src/validate-domain.ts
- packages/2-mongo-family/1-core/src/adapter-types.ts
- packages/2-mongo-family/1-core/src/exports/index.ts
✅ Files skipped from review due to trivial changes (49)
- docs/architecture docs/adrs/ADR 185 - SPI types live at the lowest consuming layer.md
- packages/1-framework/1-core/framework-components/README.md
- examples/mongo-demo/src/db.ts
- examples/mongo-demo/package.json
- packages/2-mongo-family/6-transport/mongo-wire/src/wire-commands.ts
- examples/mongo-demo/test/crud-lifecycle.test.ts
- packages/2-mongo-family/1-foundation/mongo-contract/test/validate-domain.test.ts
- packages/2-mongo-family/5-query-builders/src/types.ts
- packages/2-mongo-family/1-foundation/mongo-contract/src/validate-mongo-contract.ts
- packages/2-mongo-family/4-query/query-ast/src/commands.ts
- packages/2-mongo-family/5-query-builders/src/mongo-orm.ts
- packages/2-mongo-family/4-query/query-ast/package.json
- packages/2-mongo-family/1-foundation/mongo-value/tsconfig.json
- packages/1-framework/0-foundation/contract/README.md
- examples/mongo-demo/test/blog.test.ts
- packages/2-mongo-family/6-transport/mongo-lowering/tsconfig.prod.json
- packages/2-mongo-family/5-query-builders/test/orm-types.test-d.ts
- packages/2-mongo-family/6-transport/mongo-lowering/tsconfig.json
- packages/2-mongo-family/6-transport/mongo-lowering/src/driver-types.ts
- packages/2-mongo-family/3-tooling/emitter/package.json
- packages/2-mongo-family/5-query-builders/test/collection.test.ts
- packages/2-mongo-family/5-query-builders/tsconfig.prod.json
- packages/2-mongo-family/6-transport/mongo-lowering/src/exports/index.ts
- packages/2-mongo-family/5-query-builders/src/collection.ts
- packages/2-mongo-family/5-query-builders/package.json
- packages/2-mongo-family/1-foundation/mongo-contract/test/fixtures/orm-contract.d.ts
- packages/2-mongo-family/6-transport/mongo-lowering/tsdown.config.ts
- packages/2-mongo-family/4-query/query-ast/README.md
- packages/2-mongo-family/3-tooling/emitter/src/index.ts
- packages/2-mongo-family/1-foundation/mongo-codec/README.md
- packages/2-mongo-family/4-query/query-ast/tsconfig.json
- packages/2-mongo-family/6-transport/mongo-lowering/README.md
- packages/2-mongo-family/3-tooling/emitter/test/generate-orm-fixture.ts
- packages/2-mongo-family/6-transport/mongo-lowering/vitest.config.ts
- examples/mongo-demo/src/contract.d.ts
- packages/2-mongo-family/4-query/query-ast/vitest.config.ts
- packages/2-mongo-family/6-transport/mongo-wire/README.md
- packages/2-mongo-family/1-foundation/mongo-value/src/exports/index.ts
- packages/2-mongo-family/1-foundation/mongo-value/README.md
- packages/2-mongo-family/1-foundation/mongo-value/vitest.config.ts
- packages/2-mongo-family/1-foundation/mongo-contract/README.md
- packages/2-mongo-family/6-transport/mongo-wire/package.json
- packages/2-mongo-family/1-foundation/mongo-codec/src/exports/index.ts
- packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts
- packages/2-mongo-family/1-foundation/mongo-value/package.json
- packages/2-mongo-family/6-transport/mongo-lowering/package.json
- packages/2-mongo-family/1-foundation/mongo-codec/package.json
- packages/2-mongo-family/6-transport/mongo-wire/src/exports/index.ts
- docs/architecture docs/adrs/ADR 167 - Typed default literal pipeline and extensibility.md
🚧 Files skipped from review as they are similar to previous changes (9)
- docs/architecture docs/adrs/ADR 173 - Polymorphism via discriminator and variants.md
- packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.e2e.test.ts
- packages/2-mongo-family/4-query/query-ast/src/filter-expressions.ts
- docs/planning/mongo-target/1-design-docs/mongo-execution-components.md
- packages/2-mongo-family/6-transport/mongo-lowering/src/adapter-types.ts
- packages/2-mongo-family/5-query-builders/tsdown.config.ts
- packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
- packages/2-mongo-family/1-foundation/mongo-contract/package.json
- docs/architecture docs/adrs/ADR 184 - Codec-owned value serialization.md
closes TML-2201
Key snippet
Before / After
The adapter interface moves from layer 1 (
1-core) to layer 6 (6-transport), where it can directly reference the real query plan type — eliminating the structural shim.Intent
Decompose the
@prisma-next/mongo-coremonolith into properly layered packages so that each package has a bounded responsibility and the adapter interface can reference real query-layer types — eliminating theMongoQueryPlanLikestructural shim that existed solely to work around a layering constraint. Additionally, record the codec-owned value serialization design (ADR 184) that emerged during this work.Change map
1-core)1-core)1-core)1-core)1-core, rewritten)MongoQueryPlandirectlyMongoQueryPlan<Row>The story
Document design decisions before implementing. Two docs commits record the execution plan and update the layering design with decisions made during shaping (executor stays in ORM, codec-types owned by adapter, validate-domain deleted). These establish expectations for the implementation.
Extract foundation packages from
1-core. Three packages are carved out of the monolith bottom-up —mongo-value(no deps),mongo-codec(no deps),mongo-contract(depends on framework contract types). Each commit moves source files, creates the package boilerplate, writes the newexports/index.ts, and updates all imports across the repo. After this,1-coreretains only wire/transport concerns.Move codec-type ownership to the adapter. The
CodecTypesimport pointer is removed from the family'smongoTargetDescriptorand added to the adapter descriptor inadapter-mongo. The duplicatecodec-types.tsin1-coreis deleted. This follows the SQL precedent where the adapter declares its own codec types.Extract transport packages and delete
1-core. Wire command classes and result types move tomongo-wire; adapter and driver interfaces move tomongo-lowering. After both are extracted,1-coreis empty and deleted.Eliminate the
MongoQueryPlanLikeshim. With the adapter interface now in the transport layer (above query),MongoAdapter.lower()can acceptMongoQueryPlandirectly. The adapter implementation no longer needs theplan.command as AnyMongoCommandcast — it destructuresplan.commandwith full type safety.MongoRuntime.execute()upgrades fromMongoQueryPlanLiketoMongoQueryPlan<Row>, gaining row-type propagation.Renumber directories and update architecture config. Directories are renumbered to match the target layer ordering (
2-query->4-query,4-orm->5-query-builders,5-runtime->7-runtime). Thearchitecture.config.jsonlayer order for mongo is updated to the eight-layer sequence, and all package globs are adjusted.Record ADR 184 — codec-owned value serialization. During the layering work, a design question surfaced: how should typed values (column defaults, discriminator values) be serialized across boundaries? ADR 184 establishes that the codec owning a type is responsible for all its serialization boundaries (contract JSON, wire, DDL, PSL), eliminating the hardcoded bigint/Date branches and the tagged type system. This supersedes ADR 167's deferred v2 design and resolves ADR 173's open question about discriminator value encoding.
Behavior changes & evidence
MongoAdapter.lower()acceptsMongoQueryPlaninstead ofMongoQueryPlanLike: Before, the adapter accepted a structural shim with a genericcommand: { kind: string; collection: string }field, and internally cast it toAnyMongoCommand. After, it accepts the fully-typedMongoQueryPlanand destructurescommanddirectly — the exhaustiveswitchoncommand.kindhas full type narrowing.MongoAdapterlived at layer 1 and couldn't importMongoQueryPlanfrom the query layer. Moving the interface to layer 6 (transport, above query) eliminates the constraint.MongoRuntime.execute()acceptsMongoQueryPlan<Row>instead ofMongoQueryPlanLike: The runtime'sexecutemethod now accepts the fully-typed plan, propagating the row type parameter through the execution chain.Codec-type import pointer moves from target descriptor to adapter descriptor: Before, the family's
mongoTargetDescriptordeclaredtypes.codecTypes.importpointing to@prisma-next/mongo-core/codec-types. After, the adapter descriptor declares it pointing to@prisma-next/adapter-mongo/codec-types. Generatedcontract.d.tsfiles import from the adapter path.Package decomposition and directory renumbering (no behavior change): Six source groups move from
1-coreto five new packages. Directories renumbered. All import paths updated.ADR 184 — codec-owned value serialization (design record, no implementation): New ADR establishing that codecs own all value serialization boundaries. Supersedes ADR 167 v2; resolves ADR 173's open question about discriminator value encoding.
Compatibility / migration / risk
@prisma-next/mongo-coreno longer exists. All internal consumers are updated. No external consumers exist (prototype).contract.d.tsfiles now import from@prisma-next/mongo-contractand@prisma-next/adapter-mongo/codec-types. Existing generated contracts will need re-emission.MongoRuntime.execute()signature changes fromexecute<Row>(plan: MongoQueryPlanLike)toexecute<Row>(plan: MongoQueryPlan<Row>). Source-compatible for existing call sites.Follow-ups / open questions
Non-goals / intentionally out of scope
mongo-query-ast— explicitly deferred.MongoQueryExecutorfrom ORM to query layer — decided against.Summary by CodeRabbit