Repository navigation
TML-2837: eliminate the defineContract cast pattern in the SQL extension wrappers via a shared bound builder - #731
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a reusable buildBoundContract API that centralizes contract construction with pre-bound family/target and updates Postgres and SQLite defineContract wrappers to call it; re-exports buildBoundContract and updates upgrade docs to note no extension-author action is required. ChangesContract Construction Refactoring
Sequence DiagramsequenceDiagram
participant PostgresExtension
participant SqliteExtension
participant ContractBuilder
participant buildContractFromDsl
PostgresExtension->>ContractBuilder: buildBoundContract(sqlFamilyPack, postgresPack, bound, factory?)
SqliteExtension->>ContractBuilder: buildBoundContract(sqlFamilyPack, sqlitePack, bound, factory?)
ContractBuilder->>buildContractFromDsl: buildContractFromDsl(mergedDefinition)
buildContractFromDsl-->>ContractBuilder: SqlContractResult
ContractBuilder-->>PostgresExtension: SqlContractResult
ContractBuilder-->>SqliteExtension: SqlContractResult
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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/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: |
size-limit report 📦
|
…ion wrappers via a shared bound builder Port of the mongo fix (TML-2817): add a family/target-bound buildBoundContract to the SQL contract-builder that the base defineContract and the sqlite + postgres extension wrappers all delegate to, so both wrappers carry zero casts. Signed-off-by: Will Madden <[email protected]>
The check:upgrade-coverage gate requires that every PR touching packages/3-extensions/ also modifies instructions.md in the in-flight upgrade directory and declares changes: [] (no consumer action) or a non-empty entry. This PR's changes to the postgres and sqlite defineContract wrappers are a pure internal refactor with no consumer-visible API change, so changes: [] is correct. Signed-off-by: Will Madden <[email protected]> Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
5c0dd04 to
f5e2867
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]>
|
Note: while addressing the CodeRabbit finding from the sibling mongo PR (#730), I applied the same hardening here in |
What & why
Port of #730 (TML-2817, mongo) to the SQL family. The sqlite and postgres extension
defineContractwrappers carried the same bare-cast pattern: they pre-bindfamily/targetand delegate from a non-generic impl body to the overloaded, generic basedefineContract, forcing construction /ContractInput/as unknown asfactory /Parameters<…>casts.Same fix: a shared, family/target-bound
buildBoundContractin the SQL contract-builder, which the basedefineContractand both extension wrappers delegate to. Both wrappers are now cast-free.Result
packages/3-extensions/sqlite/src/contract/define-contract.ts: 4 → 0 bare casts.packages/3-extensions/postgres/src/contract/define-contract.ts: 4 → 0 bare casts.buildBoundContract(new, in the SQLcontract-builder.ts): a single plainly-overloaded function — no overload-return cast, no new casts. The one irreducible helpers-composition cast already lives increateComposedAuthoringHelpers(composed-authoring-helpers.ts) — untouched, still in exactly one place.asremaining incontract-builder.tsis a pre-existing, unrelatedas Record<string, ModelLike>(byte-identical tomain).Result-type equivalence
The wrappers' result types were re-derived from
Omit<ReturnType<baseDefineContract<…>>, 'target'|'targetFamily'> & { target; targetFamily }toReturnType<typeof buildBoundContract<…>>. These are structurally identical — the oldOmit & {…}was a no-op re-statement, since the base builder's result already emits the target-id literal andtargetFamily: 'sql'. Verified empirically in review with a full-resulttoEqualTypeOf<wrapper, base>assertion across definition / factory / empty forms on both targets.Verification
@prisma-next/sql-contract-ts,@prisma-next/sqlite,@prisma-next/postgrestypecheck clean; 411 tests pass, including the type tests (define-contract.test-d.tsfor both extensions —family/targetrejection, definition- and factory-form result types, target/targetFamily literals). Pure type-level + structural refactor — no runtime behaviour change (factory-merge order and the baseisContractInputguard preserved). Independently reviewed.Refs: TML-2837
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor
Documentation