Repository navigation
feat(mongo-contract-ts): add Mongo contract.ts authoring support - #324
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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 Changes
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
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)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@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/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/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-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-pipeline-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
There was a problem hiding this comment.
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 mockedContractvalues in tests.Lines 7 and 21 use direct
as Contract; test mocks must useas unknown as Contractper 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
textto satisfy markdown linters.📝 Proposed fix
-``` +```text * 2-mongo-familyApply 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
⛔ Files ignored due to path filters (5)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/mongodb-contract-ts-support/plan.mdis excluded by!projects/**projects/mongodb-contract-ts-support/spec.mdis excluded by!projects/**test/integration/test/mongo/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/mongo/fixtures/generated/contract.jsonis excluded by!**/generated/**
📒 Files selected for processing (43)
docs/Architecture Overview.mddocs/architecture docs/Package-Layering.mddocs/architecture docs/subsystems/10. MongoDB Family.mddocs/reference/Package Naming Conventions.mdpackages/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/test/contract-types.test-d.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/2-authoring/contract-ts/README.mdpackages/2-mongo-family/2-authoring/contract-ts/package.jsonpackages/2-mongo-family/2-authoring/contract-ts/src/config-types.tspackages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.tspackages/2-mongo-family/2-authoring/contract-ts/src/exports/config-types.tspackages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.tspackages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.entrypoint.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.types.test-d.tspackages/2-mongo-family/2-authoring/contract-ts/tsconfig.jsonpackages/2-mongo-family/2-authoring/contract-ts/tsconfig.prod.jsonpackages/2-mongo-family/2-authoring/contract-ts/tsdown.config.tspackages/2-mongo-family/2-authoring/contract-ts/vitest.config.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.tspackages/2-mongo-family/9-family/README.mdpackages/2-mongo-family/9-family/package.jsonpackages/2-mongo-family/9-family/src/exports/pack.tspackages/2-mongo-family/9-family/test/control.test.tspackages/2-mongo-family/9-family/tsdown.config.tspackages/3-mongo-target/1-mongo-target/README.mdpackages/3-mongo-target/1-mongo-target/package.jsonpackages/3-mongo-target/1-mongo-target/src/exports/codec-types.tspackages/3-mongo-target/1-mongo-target/src/exports/pack.tspackages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.tspackages/3-mongo-target/1-mongo-target/tsdown.config.tstest/integration/package.jsontest/integration/test/cli.emit-command.test.tstest/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/contract.mongo.tstest/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.mongo-contract-ts.tstest/integration/test/fixtures/cli/cli-integration-test-app/package.jsontest/integration/test/mongo/fixtures/contract.tstest/integration/test/mongo/no-emit.test.tstest/integration/test/mongo/orm.test.ts
c4c2b6f to
eb8a8a6
Compare
There was a problem hiding this comment.
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 describes3-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 targetThis 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__indexesfrom multiple models that target the same collection, but the new suite only covers a single model plus the duplicate-collectionOptionserror. A base/derivedtasksexample 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 throughctx.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 inprisma-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, andstorageEngineproperties useRecord<...>string forms instead of the repo’s standardtype({ '[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
⛔ Files ignored due to path filters (5)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlprojects/mongodb-contract-ts-support/plan.mdis excluded by!projects/**projects/mongodb-contract-ts-support/spec.mdis excluded by!projects/**test/integration/test/mongo/fixtures/generated/contract.d.tsis excluded by!**/generated/**test/integration/test/mongo/fixtures/generated/contract.jsonis excluded by!**/generated/**
📒 Files selected for processing (49)
docs/Architecture Overview.mddocs/architecture docs/Package-Layering.mddocs/architecture docs/subsystems/10. MongoDB Family.mddocs/reference/Package Naming Conventions.mdpackages/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/test/contract-types.test-d.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/2-authoring/contract-ts/README.mdpackages/2-mongo-family/2-authoring/contract-ts/package.jsonpackages/2-mongo-family/2-authoring/contract-ts/src/config-types.tspackages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.tspackages/2-mongo-family/2-authoring/contract-ts/src/exports/config-types.tspackages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.tspackages/2-mongo-family/2-authoring/contract-ts/test/config-types.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.entrypoint.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.types.test-d.tspackages/2-mongo-family/2-authoring/contract-ts/tsconfig.jsonpackages/2-mongo-family/2-authoring/contract-ts/tsconfig.prod.jsonpackages/2-mongo-family/2-authoring/contract-ts/tsdown.config.tspackages/2-mongo-family/2-authoring/contract-ts/vitest.config.tspackages/2-mongo-family/3-tooling/emitter/test/emitter-hook.generation.test.tspackages/2-mongo-family/5-query-builders/pipeline-builder/src/types.tspackages/2-mongo-family/9-family/README.mdpackages/2-mongo-family/9-family/package.jsonpackages/2-mongo-family/9-family/src/exports/pack.tspackages/2-mongo-family/9-family/test/control.test.tspackages/2-mongo-family/9-family/tsdown.config.tspackages/3-mongo-target/1-mongo-target/README.mdpackages/3-mongo-target/1-mongo-target/package.jsonpackages/3-mongo-target/1-mongo-target/src/exports/codec-types.tspackages/3-mongo-target/1-mongo-target/src/exports/pack.tspackages/3-mongo-target/1-mongo-target/test/descriptor-meta.test.tspackages/3-mongo-target/1-mongo-target/tsdown.config.tspackages/3-mongo-target/2-mongo-adapter/src/core/codec-ids.tspackages/3-mongo-target/2-mongo-adapter/src/core/codecs.tspackages/3-mongo-target/2-mongo-adapter/src/exports/codec-types.tspackages/3-mongo-target/2-mongo-adapter/src/exports/control.tspackages/3-mongo-target/2-mongo-adapter/test/codecs.test.tstest/integration/package.jsontest/integration/test/cli.emit-command.test.tstest/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/contract.mongo.tstest/integration/test/fixtures/cli/cli-integration-test-app/fixtures/emit-command/prisma-next.config.mongo-contract-ts.tstest/integration/test/fixtures/cli/cli-integration-test-app/package.jsontest/integration/test/mongo/fixtures/contract.tstest/integration/test/mongo/no-emit.test.tstest/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
There was a problem hiding this comment.
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/packand@prisma-next/target-mongo/pack. The inlinemongoFamilyPackandmongoTargetPackobjects 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()returnsAsyncIterableResult<Row>, which implementsPromiseLike<Row[]>. This means:
await ctx.runtime.execute(plan)(lines 149, 180, 207, 238, 258) awaits thePromiseLikedirectly, which internally callstoArray()await ctx.runtime.execute(plan).toArray()(line 306) explicitly callstoArray()then awaitsBoth return the same type. For consistency across the test file, use one pattern throughout. The direct await (without
.toArray()) is more idiomatic sinceAsyncIterableResultimplementsPromiseLikespecifically 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (17)
docs/Architecture Overview.mddocs/architecture docs/Package-Layering.mdpackages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/2-authoring/contract-ts/test/contract-builder.dsl.test.tspackages/2-mongo-family/7-runtime/package.jsonpackages/2-mongo-family/7-runtime/test/pipeline-builder.test.tstest/integration/test/authoring/README.mdtest/integration/test/authoring/side-by-side-contracts.test.tstest/integration/test/authoring/side-by-side/README.mdtest/integration/test/authoring/side-by-side/mongo/contract.jsontest/integration/test/authoring/side-by-side/mongo/contract.prismatest/integration/test/authoring/side-by-side/mongo/contract.tstest/integration/test/authoring/side-by-side/postgres/contract.jsontest/integration/test/authoring/side-by-side/postgres/contract.prismatest/integration/test/authoring/side-by-side/postgres/contract.tstest/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
left a comment
There was a problem hiding this comment.
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 despitemongo/double@1being 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
MongoCodecTypesduplication fromtarget-mongo/codec-typesneeds a comment explaining why - F04
family-mongolistsmongo-contract-tsas a runtime dep; should be devDependency - F05
typescriptContract()accepts the baseContracttype, notMongoContract— worth a clarifying note - F06 Callback overload of
defineContractis untested - F07
node:pathused in new test file; workspace rule preferspathe
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
packages/2-mongo-family/1-foundation/mongo-contract/src/contract-schema.tspackages/2-mongo-family/1-foundation/mongo-contract/test/validate.test.tspackages/2-mongo-family/7-runtime/package.jsonpackages/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
|
The package and README look great. One follow-up worth tracking: it would be helpful to have a demo usage in the |
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.
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.
Summary
@prisma-next/mongo-contract-tsauthoring package and the Mongo family/target support needed to author Mongo contracts in TypeScriptcontract.ts, including side-by-side Postgres and Mongo authoring fixtures with committedcontract.jsonsnapshotsSide-by-side authoring examples
These excerpts come from the new integration fixtures under
test/integration/test/authoring/side-by-side/.PostgreSQL
contract.tscontract.prisma(PSL / schema form)MongoDB
contract.tscontract.prisma(PSL / schema form)Note on authoring shape:
UserBase.relations(...)helper to add the reverse side afterPostexists.model(...); the current Mongo DSL in this PR does not expose a.relations()augmenter.contract.jsonfiles still describe the same logicalUser.postsandPost.authorrelations.The same fixture set also commits the emitted canonical JSON for both families:
test/integration/test/authoring/side-by-side/postgres/contract.jsontest/integration/test/authoring/side-by-side/mongo/contract.jsonMost important differences
.sql({ table, fk }), while Mongo authors storage throughcollectionplus document-native scalar helpers such asfield.objectId().Int,autoincrement()) and lowers relation storage intotables,columns, andforeignKeys; Mongo maps IDs to_id/ObjectIdand lowers relations as document references over collections.indexesandcollectionOptions, through the TS DSL.Still unsupported / out of scope
verify,schemaVerify,sign,readMarker, andintrospectare not implemented yet.contract.tsfixtures and tests.Testing
pnpm --filter @prisma-next/mongo-contract testpnpm --filter @prisma-next/mongo-contract-ts testpnpm --filter @prisma-next/mongo-contract lintpnpm --filter @prisma-next/mongo-contract buildpnpm --filter @prisma-next/mongo-contract-ts lintpnpm --filter @prisma-next/mongo-contract-ts buildpnpm --filter @prisma-next/mongo-emitter test -- test/emitter-hook.generation.test.tspnpm --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.tspnpm --filter @prisma-next/integration-tests typecheckpnpm --filter @prisma-next/integration-tests lintLinear
Summary by CodeRabbit
New Features
Documentation
Tests