Repository navigation
TML-2817: eliminate the defineContract cast pattern in @prisma-next/extension-mongo via a shared bound builder - #730
Conversation
|
Warning Review limit reached
More reviews will be available in 25 minutes and 34 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds an exported buildBoundContract helper, updates defineContract to delegate to it for both factory and non-factory paths, tweaks a factory overload to allow optional roots, and re-exports buildBoundContract from the contract-builder exports. ChangesMongo contract builder refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
size-limit report 📦
|
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@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/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@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-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-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: |
3c9b7b1 to
5e366dd
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.ts`:
- Around line 1711-1724: The factory output is currently spread after full (in
buildContractFromDefinition({ ...full, ...factory(helpers) })) allowing callers
to override bound scaffold keys like
family/target/extensionPacks/defaultControlPolicy; instead call factory(helpers)
into a local variable and selectively spread only the optional scaffold pieces
that are safe to accept (models, valueObjects, roots) using the ifDefined(key,
value) helper so the bound mongo packs (family, target, extensionPacks,
defaultControlPolicy, etc.) remain unmodified; update the return to pass
{...full, ...ifDefined('models', factoryOut.models),
...ifDefined('valueObjects', factoryOut.valueObjects), ...ifDefined('roots',
factoryOut.roots)} into buildContractFromDefinition, referencing
composeMongoEntityHelpers, ContractAuthoringHelpers and
buildContractFromDefinition to locate the change.
🪄 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: 45ab4d6f-e670-42e6-8deb-7e219571e416
📒 Files selected for processing (3)
packages/2-mongo-family/2-authoring/contract-ts/src/contract-builder.tspackages/2-mongo-family/2-authoring/contract-ts/src/exports/contract-builder.tspackages/3-extensions/mongo/src/contract/define-contract.ts
…sion-mongo via shared bound contract builder Introduce a single family/target-bound contract builder in the mongo contract-builder that both defineContract and extension wrappers delegate to, so the extension's define-contract wrapper carries zero casts. The shared builder removes the duplicated helpers-composition cast and avoids the overloaded-function-return cast entirely. Signed-off-by: Will Madden <[email protected]>
… change TML-2817 touched packages/3-extensions/mongo/src/contract/define-contract.ts as part of a cast elimination refactor. No extension API or behaviour change; changes: [] records the incidental diff. Signed-off-by: Will Madden <[email protected]>
5e366dd to
9e61482
Compare
…s in SQL buildBoundContract Spread only the factory's declared outputs (types/models) via ifDefined instead of the whole factory return, so a factory cannot clobber the pre-bound family/target/extensionPacks. Addresses the CodeRabbit finding from the sibling mongo PR (#730); same pattern existed here. Signed-off-by: Will Madden <[email protected]>
…s in mongo buildBoundContract Spread only the factory's declared outputs (models/valueObjects/roots) via ifDefined instead of the whole factory return, so a factory cannot clobber the pre-bound family/target/extensionPacks. Follow-up to the CodeRabbit finding on #730 (TML-2817), which merged before it was addressed. Signed-off-by: Will Madden <[email protected]>
What & why
TML-2817 was filed as "swap two bare
as unknown ascasts forblindCast." On review,packages/3-extensions/mongo/src/contract/define-contract.tsactually carried three structural casts — a construction cast, aContractScaffoldcast, and anas unknown asfactory cast — all symptoms of one thing: the wrapper pre-bindsfamily/targetand delegates from a non-generic implementation body to the overloaded, generic basedefineContract, so the factory param collapses to aParameters<…>union and needs casts to bridge it.Rather than paper those over with
blindCast(lipstick on a structural gap), this eliminates the pattern: a shared, family/target-boundbuildBoundContractlives in the mongo contract-builder, and both the basedefineContractand the extension wrapper delegate to it. The extension wrapper now carries zero casts.Result
packages/3-extensions/mongo/src/contract/define-contract.ts: 3 → 0 bare casts.buildBoundContract(new, in the basecontract-builder.ts): one shared, plainly-overloaded function — no overload-return cast, and the helpers-composition step is de-duplicated here (previously duplicated in the basedefineContractbody).The one residual cast (irreducible, documented)
buildBoundContractkeeps a singleas unknown as ContractAuthoringHelpers<…>where it assembles the authoring helpers. This is genuinely irreducible:composeMongoEntityHelpers→createEntityHelpersFromNamespacereturnsRecord<string, unknown>from a runtime walk over an opaque namespace, whileContractAuthoringHelpersis a mapped type reconstructed from the packs' staticentityTypesdeclarations — there is no structural path from one to the other. The SQL sibling does the identical thing (packages/2-sql/2-authoring/contract-ts/src/composed-authoring-helpers.ts), so this is the established, accepted boundary cast — now in exactly one place rather than two.Scope
Mongo only. The sqlite/postgres extension wrappers carry the identical cast pattern; porting
buildBoundContractto the SQL base + those wrappers is a follow-up (same shape, verified here first).Verification
@prisma-next/mongo-contract-tsand@prisma-next/mongotypecheck clean; all tests pass, including the negative-typing/result-type tests indefine-contract.test-d.ts(family/targetstill rejected; definition-form and factory-form result types intact). Pure type-level + structural refactor — no runtime behaviour change (factory-merge order and theisContractScaffoldguard preserved). Independently reviewed.Refs: TML-2817
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor