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

feat(mongo-contract-ts): add Mongo contract.ts authoring support - #324

Merged
jkomyno merged 16 commits into
mainfrom
feat/contract-ts-mongodb
Apr 10, 2026
Merged

jkomyno merged 16 commits into
mainfrom
feat/contract-ts-mongodb

Conversation

@jkomyno

@jkomyno jkomyno commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add the new @prisma-next/mongo-contract-ts authoring package and the Mongo family/target support needed to author Mongo contracts in TypeScript
  • add Mongo index and collection options authoring, tighten typed collection metadata validation, and record deferred validator authoring in the active plan
  • add emitter, CLI emit, and integration coverage for Mongo contract.ts, including side-by-side Postgres and Mongo authoring fixtures with committed contract.json snapshots

Side-by-side authoring examples

These excerpts come from the new integration fixtures under test/integration/test/authoring/side-by-side/.

PostgreSQL

contract.ts

const UserBase = model('User', {
  fields: {
    id: field.column(int4Column).defaultSql('autoincrement()').id(),
    name: field.column(textColumn),
    email: field.column(textColumn),
    bio: field.column(textColumn).optional(),
  },
});

const Post = model('Post', {
  fields: {
    id: field.column(int4Column).defaultSql('autoincrement()').id(),
    authorId: field.column(int4Column),
    title: field.column(textColumn),
    publishedAt: field.column(timestamptzColumn).optional(),
  },
  relations: {
    author: rel.belongsTo(UserBase, { from: 'authorId', to: 'id' }).sql({ fk: {} }),
  },
}).sql({ table: 'posts' });

const User = UserBase.relations({
  posts: rel.hasMany(Post, { by: 'authorId' }),
}).sql({ table: 'users' });

contract.prisma (PSL / schema form)

model User {
  id    Int    @id @default(autoincrement())
  name  String
  email String
  bio   String?
  posts Post[]

  @@map("users")
}

model Post {
  id          Int      @id @default(autoincrement())
  authorId    Int
  title       String
  publishedAt DateTime?
  author      User     @relation(fields: [authorId], references: [id])

  @@map("posts")
}

MongoDB

contract.ts

const User = model('User', {
  collection: 'users',
  fields: {
    _id: field.objectId(),
    name: field.string(),
    email: field.string(),
    bio: field.string().optional(),
  },
  relations: {
    posts: rel.hasMany('Post', { from: '_id', to: 'authorId' }),
  },
});

const Post = model('Post', {
  collection: 'posts',
  fields: {
    _id: field.objectId(),
    authorId: field.objectId(),
    title: field.string(),
    publishedAt: field.date().optional(),
  },
  relations: {
    author: rel.belongsTo(User, { from: 'authorId', to: User.ref('_id') }),
  },
});

contract.prisma (PSL / schema form)

model User {
  id    ObjectId @id @map("_id")
  name  String
  email String
  bio   String?
  posts Post[]

  @@map("users")
}

model Post {
  id          ObjectId @id @map("_id")
  authorId    ObjectId
  title       String
  publishedAt DateTime?
  author      User     @relation(fields: [authorId], references: [id])

  @@map("posts")
}

Note on authoring shape:

  • The Postgres snippet uses the SQL DSL's staged UserBase.relations(...) helper to add the reverse side after Post exists.
  • The Mongo snippet authors relations inline inside model(...); the current Mongo DSL in this PR does not expose a .relations() augmenter.
  • This is an authoring-surface difference, not a canonical-contract difference: both emitted contract.json files still describe the same logical User.posts and Post.author relations.

The same fixture set also commits the emitted canonical JSON for both families:

  • test/integration/test/authoring/side-by-side/postgres/contract.json
  • test/integration/test/authoring/side-by-side/mongo/contract.json

Most important differences

  • Postgres authors storage through SQL-oriented descriptors and .sql({ table, fk }), while Mongo authors storage through collection plus document-native scalar helpers such as field.objectId().
  • Postgres uses relational IDs and defaults (Int, autoincrement()) and lowers relation storage into tables, columns, and foreignKeys; Mongo maps IDs to _id/ObjectId and lowers relations as document references over collections.
  • Postgres and Mongo share the same domain shape in the side-by-side fixtures, but Mongo also adds collection-level metadata in this PR, namely indexes and collectionOptions, through the TS DSL.
  • The side-by-side fixtures intentionally stay on the comparable core subset: models, scalar fields, nullability, naming, and reference relations.

Still unsupported / out of scope

  • Mongo validator authoring is deferred and not part of this PR.
  • The first Mongo TS authoring slice does not yet cover union or dict authoring.
  • Mongo control-plane database operations are still out of scope here: verify, schemaVerify, sign, readMarker, and introspect are not implemented yet.
  • The side-by-side PSL examples intentionally stop at the common subset; Mongo-specific collection metadata is demonstrated elsewhere in this PR through contract.ts fixtures and tests.

Testing

  • pnpm --filter @prisma-next/mongo-contract test
  • pnpm --filter @prisma-next/mongo-contract-ts test
  • pnpm --filter @prisma-next/mongo-contract lint
  • pnpm --filter @prisma-next/mongo-contract build
  • pnpm --filter @prisma-next/mongo-contract-ts lint
  • pnpm --filter @prisma-next/mongo-contract-ts build
  • pnpm --filter @prisma-next/mongo-emitter test -- test/emitter-hook.generation.test.ts
  • pnpm --filter @prisma-next/integration-tests exec vitest run test/cli.emit-command.test.ts -t "emits contract.json and contract.d.ts with Mongo contract.ts config"
  • pnpm --filter @prisma-next/integration-tests exec vitest run test/mongo/orm.test.ts -t "loads generated collection indexes and options"
  • pnpm --filter @prisma-next/integration-tests exec vitest run test/authoring/side-by-side-contracts.test.ts
  • pnpm --filter @prisma-next/integration-tests typecheck
  • pnpm --filter @prisma-next/integration-tests lint

Linear

Summary by CodeRabbit

  • New Features

    • Mongo family: full TypeScript contract authoring DSL, collection/index options and validation, Mongo target & codec surface (including a double/float codec), family/target pack entrypoints, and emitted contract artifacts (JSON + d.ts).
  • Documentation

    • Architecture, package layout, and package-naming guidance updated to include Mongo family/targets and naming patterns.
  • Tests

    • Added extensive unit, integration, CLI emit, ORM runtime, pipeline, and side-by-side SQL/Mongo verification tests.

@coderabbitai

coderabbitai Bot commented Apr 9, 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

Adds a Mongo family and Mongo target: structured Mongo contract schema (indexes, collection options), a TypeScript authoring DSL and pack exports, codec typings and adapter codec, emit/CLI and runtime integrations, tests, docs, and packaging changes across new packages/2-mongo-family/ and packages/3-mongo-target/ domains.

Changes

Cohort / File(s) Summary
Documentation & Packaging
docs/Architecture Overview.md, docs/Package-Layering.md, docs/subsystems/10. MongoDB Family.md, docs/reference/Package Naming Conventions.md
Introduce packages/2-mongo-family/ and packages/3-mongo-target/ domains; update package naming, layering rules, family/target mapping, and cross-family import constraints.
Mongo Contract Foundation (schema & types)
packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts, packages/2-mongo-family/1-foundation/mongo-contract/src/contract-types.ts, packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts, packages/2-mongo-family/1-foundation/mongo-contract/test/*
Replace placeholder collection shape with structured StorageCollection (indexes, options); add Mongo JSON/value types, collation, timeseries, clustered index, change-stream options; extend runtime validation and type tests.
Authoring DSL package
packages/2-mongo-family/2-authoring/contract-ts/*
package.json, src/contract-builder.ts, src/config-types.ts, src/exports/*, tsconfig*.json, tsdown.config.ts, vitest.config.ts, test/*
Add @prisma-next/mongo-contract-ts: builder primitives (field, model, rel, index, valueObject), defineContract with runtime guards, contract normalization/hashing/validation, and comprehensive unit/typing tests.
Family pack & exports
packages/2-mongo-family/9-family/src/exports/pack.ts, packages/2-mongo-family/9-family/package.json, packages/2-mongo-family/9-family/tsdown.config.ts, packages/2-mongo-family/9-family/README.md, packages/2-mongo-family/9-family/test/control.test.ts
Add mongoFamilyPack export and ./pack public subpath; update README to describe family descriptor+pack and authoring usage; include new pack entrypoint in tsdown.
Target pack, codec types & adapter
packages/3-mongo-target/1-mongo-target/src/exports/codec-types.ts, packages/3-mongo-target/1-mongo-target/src/exports/pack.ts, packages/3-mongo-target/1-mongo-target/package.json, packages/3-mongo-target/1-mongo-target/tsdown.config.ts, packages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.ts, packages/3-mongo-target/2-mongo-adapter/*
Add CodecTypes mapping and ./codec-types export; target pack default export typed to optionally include codec types; adapter adds mongo/double@1 codec, id, and tests.
Emitter, CLI & integration tests
packages/2-mongo-family/3-tooling/emitter/test/*, test/integration/.../cli.emit-command.test.ts, fixtures .../emit-command/*, test/integration/test/mongo/*, test/integration/package.json
Add end-to-end emitter/CLI integration tests and Mongo fixtures exercising emitted contract JSON/DTS (collection/index metadata); update integration workspace deps.
Query builders / pipeline types
packages/2-mongo-family/5-query-builders/pipeline-builder/src/types.ts
Unwrap accumulator expressions in GroupedDocShape to correctly infer grouped-result types when accumulators are present.
Adapter codecs & tests
packages/3-mongo-target/2-mongo-adapter/src/core/codec-ids.ts, .../codecs.ts, .../exports/codec-types.ts, .../exports/control.ts, .../test/codecs.test.ts
Introduce MONGO_DOUBLE_CODEC_ID and mongoDoubleCodec; extend codec type mapping and update codec tests.
Build/test configs & side-by-side authoring suite
tsdown.config.ts, tsconfig*.json, vitest.config.ts, test/integration/test/authoring/*, test/integration/test/authoring/side-by-side/*
Add/adjust build and test configs for new packages; add side-by-side SQL/Mongo authoring integration tests, fixtures, and committed contract snapshots.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Code
    participant Builder as Contract Builder
    participant Normalizer as Runtime Normalizer
    participant Validator as Validator / Hasher
    participant Emitter as Emitter / CLI

    Client->>Builder: call defineContract(scaffold | definition)
    Builder->>Builder: assemble models, indexes, collectionOptions
    Builder->>Normalizer: submit assembled contract
    Normalizer->>Normalizer: normalize names, merge collections
    Normalizer->>Validator: validate structure
    Validator->>Validator: compute profileHash & storageHash
    Validator-->>Builder: return validated contract
    Client->>Emitter: request emit (CLI or programmatic)
    Emitter->>Validator: accept validated contract
    Emitter->>Emitter: produce artifacts (contract.json, contract.d.ts)
    Emitter-->>Client: emit results / CLI JSON output
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • wmadden
  • saevarb

Poem

🐰 I hopped through types and indexes bright,
curled fields and collections into sight.
Packs and codecs, DSL in tow,
contracts sprout where carrots grow.
Cheers — a Mongo bloom, carrot-high! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.13% 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
Title check ✅ Passed The title 'feat(mongo-contract-ts): add Mongo contract.ts authoring support' accurately summarizes the main change—adding TypeScript authoring support for Mongo contracts through a new package. It is clear, specific, and reflects the primary objective.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 feat/contract-ts-mongodb

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

❤️ Share

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

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

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

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

@prisma-next/runtime-executor

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-pipeline-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-pipeline-builder@324

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: f739e88

@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 (3)
packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts (1)

7-7: Use double casts for mocked Contract values in tests.

Lines 7 and 21 use direct as Contract; test mocks must use as unknown as Contract per the test pattern guidelines.

♻️ Suggested patch
-    const contract = { targetFamily: 'mongo', target: 'mongo' } as Contract;
+    const contract = { targetFamily: 'mongo', target: 'mongo' } as unknown as Contract;
@@
-    const contract = { targetFamily: 'mongo', target: 'mongo' } as Contract;
+    const contract = { targetFamily: 'mongo', target: 'mongo' } as unknown as Contract;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts` at
line 7, The test uses a direct cast for the mocked Contract object (const
contract = { targetFamily: 'mongo', target: 'mongo' } as Contract;) which
violates the test pattern; change the cast to a double cast (as unknown as
Contract) for this variable and any other mocked Contract instances (e.g., the
other occurrence near line 21) so they become: const contract = { ... } as
unknown as Contract; to satisfy the test pattern and avoid type-narrowing
issues.
docs/architecture docs/Package-Layering.md (1)

104-125: Add language specifier to fenced code blocks.

The fenced code blocks at lines 104 and 145 are missing language specifiers. For directory tree structures, use an empty specifier or text to satisfy markdown linters.

📝 Proposed fix
-```
+```text
 * 2-mongo-family

Apply the same fix at line 145.

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

In `@docs/architecture` docs/Package-Layering.md around lines 104 - 125, The
fenced code block showing the directory tree for "2-mongo-family" in
Package-Layering.md is missing a language specifier; update that opening
triple-backtick to include a language (use "text" or an empty specifier) for
linting, and apply the same change to the other identical directory-tree fenced
block later in the file (the block that begins with "* 2-mongo-family" and the
second occurrence referenced in the review).
packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts (1)

51-52: Prefer grouping related identity assertions with an object matcher.

Line 51 and Line 52 assert related contract identity fields separately; combining them improves consistency with the test style guideline.

♻️ Suggested change
-    expect(contract.targetFamily).toBe('mongo');
-    expect(contract.target).toBe('mongo');
+    expect(contract).toMatchObject({
+      targetFamily: 'mongo',
+      target: 'mongo',
+    });

As per coding guidelines: test/**/*.{ts,js}: Prefer object matchers (toMatchObject) over multiple individual expect().toBe() calls when checking 2 or more related values in tests.

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

In
`@packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts`
around lines 51 - 52, Replace the two separate assertions on
contract.targetFamily and contract.target with a single object matcher using
toMatchObject to group related identity fields; locate the test in
contract-builder.dsl.test.ts where contract is asserted and change the two
expects (asserting contract.targetFamily and contract.target) to one
expect(contract).toMatchObject({ targetFamily: 'mongo', target: 'mongo' }) to
follow the test style guideline.
🤖 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` Overview.md:
- Around line 327-330: The layout lists a new domain "3-mongo-target/*" which
could be confused with the existing "3-targets/*" domain; add a concise
clarifying sentence in the layout section explaining that "3-mongo-target" is a
concrete target-domain package group focused on Mongo implementations (i.e., a
domain-specific subpackage under the broader targets concept), state how it maps
to or differs from "3-targets/*", and remind contributors to follow the
canonical "{domain}/{subdomain}" naming pattern used elsewhere (refer to the
symbols "3-mongo-target" and "3-targets" to locate where to insert the note).

---

Nitpick comments:
In `@docs/architecture` docs/Package-Layering.md:
- Around line 104-125: The fenced code block showing the directory tree for
"2-mongo-family" in Package-Layering.md is missing a language specifier; update
that opening triple-backtick to include a language (use "text" or an empty
specifier) for linting, and apply the same change to the other identical
directory-tree fenced block later in the file (the block that begins with "*
2-mongo-family" and the second occurrence referenced in the review).

In `@packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts`:
- Line 7: The test uses a direct cast for the mocked Contract object (const
contract = { targetFamily: 'mongo', target: 'mongo' } as Contract;) which
violates the test pattern; change the cast to a double cast (as unknown as
Contract) for this variable and any other mocked Contract instances (e.g., the
other occurrence near line 21) so they become: const contract = { ... } as
unknown as Contract; to satisfy the test pattern and avoid type-narrowing
issues.

In
`@packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts`:
- Around line 51-52: Replace the two separate assertions on
contract.targetFamily and contract.target with a single object matcher using
toMatchObject to group related identity fields; locate the test in
contract-builder.dsl.test.ts where contract is asserted and change the two
expects (asserting contract.targetFamily and contract.target) to one
expect(contract).toMatchObject({ targetFamily: 'mongo', target: 'mongo' }) to
follow the test style guideline.
🪄 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: f283929b-3915-4dfa-90b9-88b512d1f47d

📥 Commits

Reviewing files that changed from the base of the PR and between 345896b and c4c2b6f.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/mongodb-contract-ts-support/plan.md is excluded by !projects/**
  • projects/mongodb-contract-ts-support/spec.md is excluded by !projects/**
  • test/integration/test/mongo/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/mongo/fixtures/generated/contract.json is excluded by !**/generated/**
📒 Files selected for processing (43)
  • docs/Architecture Overview.md
  • docs/architecture docs/Package-Layering.md
  • docs/architecture docs/subsystems/10. MongoDB Family.md
  • docs/reference/Package Naming Conventions.md
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-types.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/contract-types.test-d.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/README.md
  • packages/2-mongo-family/2-authoring/contract-ts/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/src/config-types.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/config-types.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.entrypoint.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.types.test-d.ts
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.json
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.prod.json
  • packages/2-mongo-family/2-authoring/contract-ts/tsdown.config.ts
  • packages/2-mongo-family/2-authoring/contract-ts/vitest.config.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/2-mongo-family/9-family/README.md
  • packages/2-mongo-family/9-family/package.json
  • packages/2-mongo-family/9-family/src/exports/pack.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-mongo-family/9-family/tsdown.config.ts
  • packages/3-mongo-target/1-mongo-target/README.md
  • packages/3-mongo-target/1-mongo-target/package.json
  • packages/3-mongo-target/1-mongo-target/src/exports/codec-types.ts
  • packages/3-mongo-target/1-mongo-target/src/exports/pack.ts
  • packages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.ts
  • packages/3-mongo-target/1-mongo-target/tsdown.config.ts
  • test/integration/package.json
  • test/integration/test/cli.emit-command.test.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/contract.mongo.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.mongo-contract-ts.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/package.json
  • test/integration/test/mongo/fixtures/contract.ts
  • test/integration/test/mongo/no-emit.test.ts
  • test/integration/test/mongo/orm.test.ts

Comment thread docs/Architecture Overview.md Resolved
@jkomyno
jkomyno force-pushed the feat/contract-ts-mongodb branch from c4c2b6f to eb8a8a6 Compare April 9, 2026 10:27

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

🧹 Nitpick comments (5)
docs/architecture docs/Package-Layering.md (2)

29-36: Minor terminology inconsistency in directory structure comments.

Line 30 describes 2-sql/ as "SQL family" while line 36 describes 3-mongo-target/ as "Mongo target packages" (with "packages" suffix). For consistency with the SQL pattern, consider:

-  3-mongo-target/        # Domain 3: Mongo target packages
+  3-mongo-target/        # Domain 3: Mongo target

This aligns with how 3-targets/ is described elsewhere in the document.

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

In `@docs/architecture` docs/Package-Layering.md around lines 29 - 36, The
directory comment for "3-mongo-target/" is inconsistent with the "2-sql/"
comment — "2-sql/" uses "SQL family" while "3-mongo-target/" uses "Mongo target
packages"; update the comment for 3-mongo-target/ to match the concise pattern
(e.g., "Mongo target" or "Mongo family") used for 2-sql/, or align it to the
existing "3-targets/" phrasing so all directory comments (2-sql/,
3-mongo-target/, 3-targets/) follow the same terminology and suffix style.

256-260: Update dependency rules to include Mongo authoring layer.

The dependency rules at line 260 state: "SQL authoring may also import from SQL tooling layer." Consider updating this to clarify that the same pattern applies to Mongo authoring:

-**Dependency Rules:** Can import from `core/*` only. SQL authoring may also import from SQL tooling layer.
+**Dependency Rules:** Can import from `core/*` only. SQL authoring may also import from SQL tooling layer. Mongo authoring may also import from Mongo tooling layer.

This makes the pattern explicit for both families.

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

In `@docs/architecture` docs/Package-Layering.md around lines 256 - 260, Update
the Dependency Rules paragraph to explicitly include the Mongo authoring layer:
in the section titled "Mongo Domain (Migration Plane)" (references:
`packages/2-mongo-family/2-authoring/contract-psl/`,
`packages/2-mongo-family/2-authoring/contract-ts/`,
`@prisma-next/mongo-contract-psl`, `@prisma-next/mongo-contract-ts`) change the
rule text that currently reads "SQL authoring may also import from SQL tooling
layer." to also mention Mongo (e.g. "SQL authoring may also import from SQL
tooling layer; Mongo authoring may also import from Mongo tooling layer.") so
the pattern is explicit for both families.
packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts (1)

166-197: Add one shared-collection index merge case.

buildCollections() merges __indexes from multiple models that target the same collection, but the new suite only covers a single model plus the duplicate-collectionOptions error. A base/derived tasks example with indexes on both models would lock down the non-trivial merge path this PR relies on.

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

In
`@packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts`
around lines 166 - 197, Add a test that verifies buildCollections merges
__indexes from multiple models sharing the same collection: create two models
(e.g., TaskBase and TaskDerived) both with collection: 'tasks' and each
declaring distinct index(...) entries, call defineContract({ family:
mongoFamilyPack, target: mongoTargetPack, models: { TaskBase, TaskDerived } })
and assert that contract.storage.collections.tasks.indexes contains the indexes
from both models (preserving options like unique/expireAfterSeconds); reference
model(), index(), defineContract(), and buildCollections to locate where to
add/validate the merged-index behavior.
test/integration/test/mongo/no-emit.test.ts (1)

55-105: Move the runtime-executed pipeline case next to the mongo runtime tests.

This case builds a real mongoPipeline(...) plan and executes it through ctx.runtime, so it fits the runtime-package integration bucket better than the top-level integration suite. Keeping only the no-emit authoring coverage here would make ownership clearer and avoid split coverage of the same execution path.

Based on learnings, For prisma/prisma-next integration tests that exercise the pipeline builder via the mongo runtime execution path (i.e., through the runtime’s actual execution, not just unit-level construction), place the test in the consuming package’s test folder (e.g., packages/2-mongo-family/7-runtime/test/) rather than in prisma-next/integration-tests.

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

In `@test/integration/test/mongo/no-emit.test.ts` around lines 55 - 105, Move the
"mongoPipeline executes with a builder-authored contract directly" test (the
test that builds a real mongoPipeline with contract and calls
ctx.runtime.execute(plan).toArray()) out of this top-level integration suite
into the mongo-runtime consuming package's integration tests; keep only no-emit
authoring coverage here. When moving, preserve the usage of mongoPipeline,
contract, ctx.runtime, and the PlanRow<typeof plan> type assertion, and update
any imports/fixtures so the test still constructs the DB state (users/tasks) and
asserts the same results via the runtime execution path.
packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts (1)

80-99: Use explicit Arktype record schemas for the new map-shaped options.

The new partialFilterExpression, weights, and storageEngine properties use Record<...> string forms instead of the repo’s standard type({ '[string]': ... }) pattern. Switching these keeps the validators consistent with the rest of the Arktype surface.

As per coding guidelines, use type({ "[string]": Schema }) for defining record types in Arktype.

Also applies to: 107-110, 138-145

🤖 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-contract/src/contract-schema.ts`
around lines 80 - 99, Summary: Replace string-form Record<> schemas with
explicit Arktype map-shaped schemas to match repo conventions. Fix: in
IndexOptionsSchema change 'partialFilterExpression?' from 'Record<string,
unknown>' to type({ '[string]': unknown }), change 'weights?' from
'Record<string, number>' to type({ '[string]': 'number' }), and likewise replace
any 'storageEngine?' Record uses (mentioned at lines 107-110 and 138-145) with
type({ '[string]': <appropriate schema>) }); ensure you use the Arktype
type(...) pattern and the correct inner schema types (unknown or number or the
existing storage engine value schema) and import/use the same type helper as
used elsewhere in this file; reference IndexOptionsSchema and the property keys
'partialFilterExpression?', 'weights?', and 'storageEngine?' when making the
edits.
🤖 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/Package-Layering.md:
- Around line 145-153: The fenced code block that begins with "* 3-mongo-target"
is missing a language specifier; update the opening triple-backtick to include a
language (e.g., "text") so it becomes "```text" to ensure proper rendering,
leaving the block contents unchanged.
- Around line 104-125: Update the fenced block to include a language specifier
by changing the opening ``` to ```text for the package layering snippet, and in
the SQL family section replace the outdated "family-sql" layer reference
(previously listed as layer 3) with layer 9 so it matches the actual placement
of the family-sql package; look for the package-listing block containing
"2-mongo-family" and the SQL family prose referencing "family-sql" and update
those two spots accordingly.

In `@packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts`:
- Around line 57-60: IndexFieldsSchema currently allows an empty record (so {
fields: {} } and clusteredIndex.key = {} pass validation); update
IndexFieldsSchema (and the similar schema at the other occurrence) to require at
least one entry in the record by enforcing min-properties (or adding a
refinement) instead of the bare '[string]' map type — e.g. ensure the validator
for IndexFieldsSchema checks Object.keys(value).length > 0 so empty objects are
rejected; apply the same change to the clusteredIndex/key schema referenced in
your diff.

---

Nitpick comments:
In `@docs/architecture` docs/Package-Layering.md:
- Around line 29-36: The directory comment for "3-mongo-target/" is inconsistent
with the "2-sql/" comment — "2-sql/" uses "SQL family" while "3-mongo-target/"
uses "Mongo target packages"; update the comment for 3-mongo-target/ to match
the concise pattern (e.g., "Mongo target" or "Mongo family") used for 2-sql/, or
align it to the existing "3-targets/" phrasing so all directory comments
(2-sql/, 3-mongo-target/, 3-targets/) follow the same terminology and suffix
style.
- Around line 256-260: Update the Dependency Rules paragraph to explicitly
include the Mongo authoring layer: in the section titled "Mongo Domain
(Migration Plane)" (references:
`packages/2-mongo-family/2-authoring/contract-psl/`,
`packages/2-mongo-family/2-authoring/contract-ts/`,
`@prisma-next/mongo-contract-psl`, `@prisma-next/mongo-contract-ts`) change the
rule text that currently reads "SQL authoring may also import from SQL tooling
layer." to also mention Mongo (e.g. "SQL authoring may also import from SQL
tooling layer; Mongo authoring may also import from Mongo tooling layer.") so
the pattern is explicit for both families.

In `@packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts`:
- Around line 80-99: Summary: Replace string-form Record<> schemas with explicit
Arktype map-shaped schemas to match repo conventions. Fix: in IndexOptionsSchema
change 'partialFilterExpression?' from 'Record<string, unknown>' to type({
'[string]': unknown }), change 'weights?' from 'Record<string, number>' to
type({ '[string]': 'number' }), and likewise replace any 'storageEngine?' Record
uses (mentioned at lines 107-110 and 138-145) with type({ '[string]':
<appropriate schema>) }); ensure you use the Arktype type(...) pattern and the
correct inner schema types (unknown or number or the existing storage engine
value schema) and import/use the same type helper as used elsewhere in this
file; reference IndexOptionsSchema and the property keys
'partialFilterExpression?', 'weights?', and 'storageEngine?' when making the
edits.

In
`@packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts`:
- Around line 166-197: Add a test that verifies buildCollections merges
__indexes from multiple models sharing the same collection: create two models
(e.g., TaskBase and TaskDerived) both with collection: 'tasks' and each
declaring distinct index(...) entries, call defineContract({ family:
mongoFamilyPack, target: mongoTargetPack, models: { TaskBase, TaskDerived } })
and assert that contract.storage.collections.tasks.indexes contains the indexes
from both models (preserving options like unique/expireAfterSeconds); reference
model(), index(), defineContract(), and buildCollections to locate where to
add/validate the merged-index behavior.

In `@test/integration/test/mongo/no-emit.test.ts`:
- Around line 55-105: Move the "mongoPipeline executes with a builder-authored
contract directly" test (the test that builds a real mongoPipeline with contract
and calls ctx.runtime.execute(plan).toArray()) out of this top-level integration
suite into the mongo-runtime consuming package's integration tests; keep only
no-emit authoring coverage here. When moving, preserve the usage of
mongoPipeline, contract, ctx.runtime, and the PlanRow<typeof plan> type
assertion, and update any imports/fixtures so the test still constructs the DB
state (users/tasks) and asserts the same results via the runtime execution path.
🪄 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: 65be234e-a0d8-434e-88cd-08aa2358d63b

📥 Commits

Reviewing files that changed from the base of the PR and between c4c2b6f and eb8a8a6.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • projects/mongodb-contract-ts-support/plan.md is excluded by !projects/**
  • projects/mongodb-contract-ts-support/spec.md is excluded by !projects/**
  • test/integration/test/mongo/fixtures/generated/contract.d.ts is excluded by !**/generated/**
  • test/integration/test/mongo/fixtures/generated/contract.json is excluded by !**/generated/**
📒 Files selected for processing (49)
  • docs/Architecture Overview.md
  • docs/architecture docs/Package-Layering.md
  • docs/architecture docs/subsystems/10. MongoDB Family.md
  • docs/reference/Package Naming Conventions.md
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-types.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/contract-types.test-d.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/README.md
  • packages/2-mongo-family/2-authoring/contract-ts/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/src/config-types.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/config-types.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.entrypoint.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.types.test-d.ts
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.json
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.prod.json
  • packages/2-mongo-family/2-authoring/contract-ts/tsdown.config.ts
  • packages/2-mongo-family/2-authoring/contract-ts/vitest.config.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/2-mongo-family/5-query-builders/pipeline-builder/src/types.ts
  • packages/2-mongo-family/9-family/README.md
  • packages/2-mongo-family/9-family/package.json
  • packages/2-mongo-family/9-family/src/exports/pack.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-mongo-family/9-family/tsdown.config.ts
  • packages/3-mongo-target/1-mongo-target/README.md
  • packages/3-mongo-target/1-mongo-target/package.json
  • packages/3-mongo-target/1-mongo-target/src/exports/codec-types.ts
  • packages/3-mongo-target/1-mongo-target/src/exports/pack.ts
  • packages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.ts
  • packages/3-mongo-target/1-mongo-target/tsdown.config.ts
  • packages/3-mongo-target/2-mongo-adapter/src/core/codec-ids.ts
  • packages/3-mongo-target/2-mongo-adapter/src/core/codecs.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/codec-types.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts
  • packages/3-mongo-target/2-mongo-adapter/test/codecs.test.ts
  • test/integration/package.json
  • test/integration/test/cli.emit-command.test.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/contract.mongo.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.mongo-contract-ts.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/package.json
  • test/integration/test/mongo/fixtures/contract.ts
  • test/integration/test/mongo/no-emit.test.ts
  • test/integration/test/mongo/orm.test.ts
✅ Files skipped from review due to trivial changes (32)
  • test/integration/test/fixtures/cli/cli-integration-test-app/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.prod.json
  • packages/3-mongo-target/2-mongo-adapter/src/core/codec-ids.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/control.ts
  • packages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.ts
  • packages/3-mongo-target/2-mongo-adapter/src/exports/codec-types.ts
  • test/integration/test/mongo/orm.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/tsconfig.json
  • test/integration/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/config-types.ts
  • packages/3-mongo-target/1-mongo-target/tsdown.config.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/config-types.ts
  • packages/3-mongo-target/2-mongo-adapter/test/codecs.test.ts
  • packages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.ts
  • packages/2-mongo-family/9-family/tsdown.config.ts
  • docs/architecture docs/subsystems/10. MongoDB Family.md
  • packages/3-mongo-target/1-mongo-target/src/exports/pack.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.mongo-contract-ts.ts
  • packages/3-mongo-target/1-mongo-target/README.md
  • packages/2-mongo-family/2-authoring/contract-ts/vitest.config.ts
  • packages/2-mongo-family/9-family/src/exports/pack.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.ts
  • packages/2-mongo-family/2-authoring/contract-ts/tsdown.config.ts
  • packages/2-mongo-family/9-family/test/control.test.ts
  • packages/2-mongo-family/9-family/README.md
  • packages/2-mongo-family/2-authoring/contract-ts/README.md
  • packages/2-mongo-family/1-foundation/mongo-contract/test/contract-types.test-d.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/src/exports/index.ts
  • docs/reference/Package Naming Conventions.md
  • packages/3-mongo-target/1-mongo-target/src/exports/codec-types.ts
  • packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts
🚧 Files skipped from review as they are similar to previous changes (9)
  • docs/Architecture Overview.md
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • packages/3-mongo-target/1-mongo-target/package.json
  • packages/2-mongo-family/9-family/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.entrypoint.test.ts
  • test/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/contract.mongo.ts
  • packages/2-mongo-family/2-authoring/contract-ts/package.json
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.types.test-d.ts
  • test/integration/test/mongo/fixtures/contract.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 (2)
packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts (2)

75-119: Consider importing packs from canonical sources instead of inline definitions.

The established pattern (visible in test/integration/test/mongo/fixtures/contract.ts) imports family/target packs from @prisma-next/family-mongo/pack and @prisma-next/target-mongo/pack. The inline mongoFamilyPack and mongoTargetPack objects here duplicate that structure and could drift out of sync if the pack schema changes.

Suggested refactor
+import mongoFamilyPack from '@prisma-next/family-mongo/pack';
+import mongoTargetPack from '@prisma-next/target-mongo/pack';
 import { defineContract, field, model, rel } from '@prisma-next/mongo-contract-ts/contract-builder';

-const mongoFamilyPack = {
-  kind: 'family',
-  id: 'mongo',
-  familyId: 'mongo',
-  version: '0.0.1',
-} as const;
-
-const mongoTargetPack = {
-  kind: 'target',
-  id: 'mongo',
-  familyId: 'mongo',
-  targetId: 'mongo',
-  version: '0.0.1',
-} as const;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts` around lines
75 - 119, Replace the inline mongoFamilyPack and mongoTargetPack constants with
canonical imports from the official packs; import the family pack from
"@prisma-next/family-mongo/pack" and the target pack from
"@prisma-next/target-mongo/pack" and pass those imported symbols into
defineContract (instead of mongoFamilyPack and mongoTargetPack) so the test uses
the authoritative pack schema and avoids drift.

306-306: Both patterns are functionally equivalent; this is a style inconsistency, not an error.

execute() returns AsyncIterableResult<Row>, which implements PromiseLike<Row[]>. This means:

  • await ctx.runtime.execute(plan) (lines 149, 180, 207, 238, 258) awaits the PromiseLike directly, which internally calls toArray()
  • await ctx.runtime.execute(plan).toArray() (line 306) explicitly calls toArray() then awaits

Both return the same type. For consistency across the test file, use one pattern throughout. The direct await (without .toArray()) is more idiomatic since AsyncIterableResult implements PromiseLike specifically to support this.

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

In `@packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts` at line 306,
The test mixes two equivalent-await styles; change the instance that calls await
ctx.runtime.execute(plan).toArray() to the idiomatic direct await form used
elsewhere by awaiting the AsyncIterableResult directly (await
ctx.runtime.execute(plan)) so all tests consistently rely on
AsyncIterableResult's PromiseLike behavior; update the assertion variable name
if needed to match other usages that expect the awaited Row[] from execute().
🤖 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/1-foundation/mongo-contract/src/contract-schema.ts`:
- Around line 57-58: The current UnknownValueRecordSchema allows arbitrary
values; create a recursive Arktype schema named MongoJsonValueSchema that models
MongoJsonValue by unioning MongoJsonPrimitive (string|number|boolean|null),
arrays of MongoJsonValue, and record/object maps to MongoJsonValue (recursive),
then replace UnknownValueRecordSchema with this new MongoJsonValueSchema
wherever partialFilterExpression and both storageEngine fields are defined in
contract-schema.ts so those fields validate as proper JSON-serializable
structures matching the MongoJsonValue/MongoJsonObject types.

---

Nitpick comments:
In `@packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts`:
- Around line 75-119: Replace the inline mongoFamilyPack and mongoTargetPack
constants with canonical imports from the official packs; import the family pack
from "@prisma-next/family-mongo/pack" and the target pack from
"@prisma-next/target-mongo/pack" and pass those imported symbols into
defineContract (instead of mongoFamilyPack and mongoTargetPack) so the test uses
the authoritative pack schema and avoids drift.
- Line 306: The test mixes two equivalent-await styles; change the instance that
calls await ctx.runtime.execute(plan).toArray() to the idiomatic direct await
form used elsewhere by awaiting the AsyncIterableResult directly (await
ctx.runtime.execute(plan)) so all tests consistently rely on
AsyncIterableResult's PromiseLike behavior; update the assertion variable name
if needed to match other usages that expect the awaited Row[] from execute().
🪄 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: d7c67e70-e08c-44d1-b982-793ddfa6e268

📥 Commits

Reviewing files that changed from the base of the PR and between eb8a8a6 and 38ed635.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • docs/Architecture Overview.md
  • docs/architecture docs/Package-Layering.md
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • packages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.ts
  • packages/2-mongo-family/7-runtime/package.json
  • packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts
  • test/integration/test/authoring/README.md
  • test/integration/test/authoring/side-by-side-contracts.test.ts
  • test/integration/test/authoring/side-by-side/README.md
  • test/integration/test/authoring/side-by-side/mongo/contract.json
  • test/integration/test/authoring/side-by-side/mongo/contract.prisma
  • test/integration/test/authoring/side-by-side/mongo/contract.ts
  • test/integration/test/authoring/side-by-side/postgres/contract.json
  • test/integration/test/authoring/side-by-side/postgres/contract.prisma
  • test/integration/test/authoring/side-by-side/postgres/contract.ts
  • test/integration/test/mongo/no-emit.test.ts
✅ Files skipped from review due to trivial changes (10)
  • packages/2-mongo-family/7-runtime/package.json
  • test/integration/test/authoring/README.md
  • test/integration/test/authoring/side-by-side/README.md
  • docs/architecture docs/Package-Layering.md
  • test/integration/test/authoring/side-by-side/postgres/contract.ts
  • test/integration/test/authoring/side-by-side/postgres/contract.json
  • test/integration/test/authoring/side-by-side/postgres/contract.prisma
  • test/integration/test/authoring/side-by-side/mongo/contract.json
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • test/integration/test/authoring/side-by-side/mongo/contract.prisma
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/Architecture Overview.md

@wmadden wmadden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Preemptive approval — this is a well-scoped, high-confidence implementation and I am happy for it to merge. I have left inline comments for 7 findings; please address or respond to each before merging. No re-review needed — use your judgment on the deferred items.

What looks solid: the type-inference chain (MongoContractResult<Definition> → DerivedRootModels → value object rows) is rigorous and accurate; pack ref branding keeps contract.ts files inert; validateMongoContract() is called at construction time; the Arktype schemas use +:reject throughout; the side-by-side fixture is a strong parity proof.

Key findings (inline below):

  • F01 field.double() helper is missing despite mongo/double@1 being in the codec registry and type map
  • F02 Cross-model index accumulation on shared collections has no duplicate-detection guard and no test
  • F03 Inline MongoCodecTypes duplication from target-mongo/codec-types needs a comment explaining why
  • F04 family-mongo lists mongo-contract-ts as a runtime dep; should be devDependency
  • F05 typescriptContract() accepts the base Contract type, not MongoContract — worth a clarifying note
  • F06 Callback overload of defineContract is untested
  • F07 node:path used in new test file; workspace rule prefers pathe

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts`:
- Around line 70-82: isMongoJsonObject and isMongoJsonValue currently recurse
without cycle tracking and can crash on self-referential inputs; modify both to
accept or close over a WeakSet (e.g., visited) that records seen object/array
references and returns false if a reference is encountered again, using
WeakSet.add before recursing and removing/noting duplicates to short-circuit and
prevent infinite recursion; apply the same cycle-guard pattern to the analogous
validation functions in the 84-93 block so arrays/objects are tracked via the
same WeakSet and cyclic structures produce a validation failure instead of a
RangeError.
🪄 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: 90e16581-58b4-4813-9caa-2a60ca30699d

📥 Commits

Reviewing files that changed from the base of the PR and between 38ed635 and 85d5d86.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.ts
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
  • packages/2-mongo-family/7-runtime/package.json
  • packages/2-mongo-family/7-runtime/test/pipeline-builder.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/2-mongo-family/7-runtime/package.json

@wmadden

wmadden commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

The package and README look great. One follow-up worth tracking: it would be helpful to have a demo usage in the examples/mongo-demo/ app (or equivalent) that shows defineContract(...) end-to-end — models, relations, maybe a value object — as a reference for contributors and future users. Per the spec Non-goal #5 this is intentionally out of scope until the API is stable and reviewed, so no action needed here, but I wanted to flag it so it lands on the close-out checklist.

@jkomyno
jkomyno merged commit 0bcfdfa into main Apr 10, 2026
15 checks passed
@jkomyno
jkomyno deleted the feat/contract-ts-mongodb branch April 10, 2026 06:28
wmadden added a commit that referenced this pull request Apr 10, 2026
The root import from @prisma-next/mongo-query-ast has no default export;
MongoQueryPlan is exported from the ./execution subpath. This was broken
by PR #324 on main.
wmadden added a commit that referenced this pull request Apr 10, 2026
The root import from @prisma-next/mongo-query-ast has no default export;
MongoQueryPlan is exported from the ./execution subpath. This was broken
by PR #324 on main.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants