@prisma/orm-family-sql 8.0.0-rc.24-dev.28 → 8.0.0-rc.24-dev.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{aggregate-descriptor-registry-DM1hmlq-.mjs → aggregate-descriptor-registry-oSsBuRHQ.mjs} +2 -2
- package/dist/{aggregate-descriptor-registry-DM1hmlq-.mjs.map → aggregate-descriptor-registry-oSsBuRHQ.mjs.map} +1 -1
- package/dist/{ast-BO3Wgbrl.mjs → ast-BpFfUmb_.mjs} +2 -2
- package/dist/{ast-BO3Wgbrl.mjs.map → ast-BpFfUmb_.mjs.map} +1 -1
- package/dist/{ast-D0yJ7Yf0.d.mts → ast-DvD53wSW.d.mts} +3 -3
- package/dist/{ast-D0yJ7Yf0.d.mts.map → ast-DvD53wSW.d.mts.map} +1 -1
- package/dist/{attribute-specs-DL1btx0j.d.mts → attribute-specs-DgYb4op9.d.mts} +3 -3
- package/dist/{attribute-specs-DL1btx0j.d.mts.map → attribute-specs-DgYb4op9.d.mts.map} +1 -1
- package/dist/{authoring-entity-types-CgKIgWq5-BqNs-56x.d.mts → authoring-entity-types-CgKIgWq5-C3GyB8Hj.d.mts} +2 -2
- package/dist/{authoring-entity-types-CgKIgWq5-BqNs-56x.d.mts.map → authoring-entity-types-CgKIgWq5-C3GyB8Hj.d.mts.map} +1 -1
- package/dist/builder.d.mts +3 -3
- package/dist/builder__runtime.d.mts +7 -7
- package/dist/builder__runtime.mjs +26 -12
- package/dist/builder__runtime.mjs.map +1 -1
- package/dist/builder__types.d.mts +5 -5
- package/dist/{collection-methods-CN0GIWWR-BSJvP4Kc.d.mts → collection-methods-As4pXm7B-3xgTSoyU.d.mts} +3 -3
- package/dist/{collection-methods-CN0GIWWR-BSJvP4Kc.d.mts.map → collection-methods-As4pXm7B-3xgTSoyU.d.mts.map} +1 -1
- package/dist/collection-methods-CS1e16Ij.d.mts +1 -0
- package/dist/config-types-BVrGV95W.mjs +147 -0
- package/dist/config-types-BVrGV95W.mjs.map +1 -0
- package/dist/{config-types-Ce1tAJ0B.d.mts → config-types-DVRid5jV.d.mts} +15 -3
- package/dist/config-types-DVRid5jV.d.mts.map +1 -0
- package/dist/{contract-builder-BfPC4mQK.d.mts → contract-builder-fyzIdWqX.d.mts} +77 -2
- package/dist/{contract-builder-BfPC4mQK.d.mts.map → contract-builder-fyzIdWqX.d.mts.map} +1 -1
- package/dist/{contract-builder-Dbo5LeXs.mjs → contract-builder-q2-4IVcW.mjs} +3 -3
- package/dist/contract-builder-q2-4IVcW.mjs.map +1 -0
- package/dist/contract-emitter.d.mts +3 -2
- package/dist/contract-emitter.d.mts.map +1 -1
- package/dist/contract-emitter.mjs +1 -1
- package/dist/contract-prisma7__provider.mjs +6 -6
- package/dist/contract-psl.d.mts +1 -1
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.d.mts +1 -1
- package/dist/contract-psl__attribute-specs.mjs +1 -1
- package/dist/contract-psl__provider.mjs +22 -19
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/contract-ts.d.mts +3 -3
- package/dist/contract-ts.mjs +4 -4
- package/dist/contract-ts__config-types.d.mts +2 -2
- package/dist/contract-ts__config-types.mjs +2 -2
- package/dist/contract-ts__contract-builder.d.mts +2 -2
- package/dist/contract-ts__contract-builder.mjs +3 -3
- package/dist/contract.d.mts +2 -2
- package/dist/contract.mjs +4 -4
- package/dist/contract__foreign-key-materialization.d.mts +2 -2
- package/dist/contract__foreign-key-materialization.mjs +3 -3
- package/dist/contract__validators.mjs +1 -1
- package/dist/{control-Cb6YoQ8j.d.mts → control-L4h4N5uy.d.mts} +158 -42
- package/dist/control-L4h4N5uy.d.mts.map +1 -0
- package/dist/{control-kHFMtE8A.mjs → control-Mh99W3HI.mjs} +2117 -1315
- package/dist/control-Mh99W3HI.mjs.map +1 -0
- package/dist/{control-adapter-0z3ce44U-CLj4kqLI.d.mts → control-adapter-0z3ce44U-BQ26ercw.d.mts} +4 -4
- package/dist/{control-adapter-0z3ce44U-CLj4kqLI.d.mts.map → control-adapter-0z3ce44U-BQ26ercw.d.mts.map} +1 -1
- package/dist/{control-adapter-DIwBUSs6.d.mts → control-adapter-DRLco_j0.d.mts} +2 -2
- package/dist/{control-adapter-DIwBUSs6.d.mts.map → control-adapter-DRLco_j0.d.mts.map} +1 -1
- package/dist/{db-DfYeGVcu-B99ycjaC.d.mts → db-by-MuHF2-B7uz_0VW.d.mts} +27 -18
- package/dist/db-by-MuHF2-B7uz_0VW.d.mts.map +1 -0
- package/dist/{ddl-types-D22OYeFy-Be5-W-5z.d.mts → ddl-types-D93zTpm9-DhSkpX0K.d.mts} +3 -3
- package/dist/{ddl-types-D22OYeFy-Be5-W-5z.d.mts.map → ddl-types-D93zTpm9-DhSkpX0K.d.mts.map} +1 -1
- package/dist/{derived-checks-BWg0DOyz-7O0x1Tgn.mjs → derived-checks-BoHNzt-a-CK4ceMbs.mjs} +228 -10
- package/dist/derived-checks-BoHNzt-a-CK4ceMbs.mjs.map +1 -0
- package/dist/{diff-DbkXUf4C.d.mts → diff-DZHlisyY.d.mts} +2 -2
- package/dist/{diff-DbkXUf4C.d.mts.map → diff-DZHlisyY.d.mts.map} +1 -1
- package/dist/{dist-BJjqJT_M.mjs → dist-C-Gi4VUC.mjs} +20 -14
- package/dist/dist-C-Gi4VUC.mjs.map +1 -0
- package/dist/{exports-BR5ctYYI-C_-aedbr.mjs → exports-kqOXg2OT-D3lo7jnX.mjs} +168 -162
- package/dist/exports-kqOXg2OT-D3lo7jnX.mjs.map +1 -0
- package/dist/expression-Bz8uEh8W.d.mts +2 -0
- package/dist/{expression-D8c3t2Dx-CCHt1OdT.d.mts → expression-DYRYmkMl-BMKxN8Wf.d.mts} +64 -43
- package/dist/expression-DYRYmkMl-BMKxN8Wf.d.mts.map +1 -0
- package/dist/{expression-DL7L8You-C9BAeM2d.d.mts → expression-VJWwxbUB-BtNDaTCt.d.mts} +5 -5
- package/dist/expression-VJWwxbUB-BtNDaTCt.d.mts.map +1 -0
- package/dist/{expression-impl-DHdjzqE3-Cd9gP7oC.mjs → expression-impl-C5Ha-fXs-CxXn8gDo.mjs} +7 -5
- package/dist/expression-impl-C5Ha-fXs-CxXn8gDo.mjs.map +1 -0
- package/dist/family.d.mts +8 -8
- package/dist/family.mjs +6 -6
- package/dist/family__control-adapter.d.mts +2 -2
- package/dist/family__control.d.mts +3 -3
- package/dist/family__control.mjs +3 -3
- package/dist/family__diff.d.mts +1 -1
- package/dist/family__ir.mjs +1 -1
- package/dist/family__migration.d.mts +1 -1
- package/dist/family__pack.d.mts +1 -1
- package/dist/family__pack.mjs +2 -2
- package/dist/family__psl-infer.mjs +1 -1
- package/dist/{foreign-key-materialization-C53nVQuD.d.mts → foreign-key-materialization-Dntzsl64.d.mts} +8 -2
- package/dist/foreign-key-materialization-Dntzsl64.d.mts.map +1 -0
- package/dist/{foreign-key-materialization-CCHAR789.mjs → foreign-key-materialization-pYirysH0.mjs} +2 -2
- package/dist/foreign-key-materialization-pYirysH0.mjs.map +1 -0
- package/dist/{functions-Cl_egJ2w.mjs → functions-DGketpiK.mjs} +3 -3
- package/dist/{functions-Cl_egJ2w.mjs.map → functions-DGketpiK.mjs.map} +1 -1
- package/dist/functions-gl3PL1so.d.mts +1 -0
- package/dist/{generator-functions-Bze9nVHL-Cetbgui3.mjs → generator-functions-Bze9nVHL-q4YmMS5B.mjs} +3 -3
- package/dist/{generator-functions-Bze9nVHL-Cetbgui3.mjs.map → generator-functions-Bze9nVHL-q4YmMS5B.mjs.map} +1 -1
- package/dist/{index-equivalence-DswCiq5l-9GNm8oG9.mjs → index-equivalence-eC2jGpOp-SkExsiy1.mjs} +3 -3
- package/dist/{index-equivalence-DswCiq5l-9GNm8oG9.mjs.map → index-equivalence-eC2jGpOp-SkExsiy1.mjs.map} +1 -1
- package/dist/{index-DA1EEz4y.d.mts → index-nW0rAUTr.d.mts} +28 -30
- package/dist/index-nW0rAUTr.d.mts.map +1 -0
- package/dist/{index-reference-CSrhOgZL-PIYy9LTA.d.mts → index-reference-CjvRzUh1-CG0Ouv6i.d.mts} +3 -3
- package/dist/{index-reference-CSrhOgZL-PIYy9LTA.d.mts.map → index-reference-CjvRzUh1-CG0Ouv6i.d.mts.map} +1 -1
- package/dist/index-reference-X_kA2mV8.d.mts +1 -0
- package/dist/{interpreter-CVd521dx-wWck8W93.mjs → interpreter-DoQwVOyS-DXYLj31g.mjs} +209 -29
- package/dist/interpreter-DoQwVOyS-DXYLj31g.mjs.map +1 -0
- package/dist/middleware-CcDThETr.d.mts +1 -0
- package/dist/{middleware-4P5tDL8a-C1UaoUUN.d.mts → middleware-DzFPUERE-C6RrGmcp.d.mts} +3 -3
- package/dist/{middleware-4P5tDL8a-C1UaoUUN.d.mts.map → middleware-DzFPUERE-C6RrGmcp.d.mts.map} +1 -1
- package/dist/{migration-DctFInNJ.d.mts → migration-BUWF9_Tx.d.mts} +2 -2
- package/dist/{migration-DctFInNJ.d.mts.map → migration-BUWF9_Tx.d.mts.map} +1 -1
- package/dist/orm-client.d.mts +113 -69
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +391 -121
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{pack-BBsFyTEv.d.mts → pack-CbYm5Bfz.d.mts} +3 -3
- package/dist/{pack-BBsFyTEv.d.mts.map → pack-CbYm5Bfz.d.mts.map} +1 -1
- package/dist/plan-BjX90QC6.d.mts +2 -0
- package/dist/{plan-49sl7WSN-C22ZPSE9.d.mts → plan-Dv6v5_y4-CGWEjfCv.d.mts} +3 -3
- package/dist/{plan-49sl7WSN-C22ZPSE9.d.mts.map → plan-Dv6v5_y4-CGWEjfCv.d.mts.map} +1 -1
- package/dist/{psl-column-resolution-Bv_-TDHZ-Cuu5X_9o.d.mts → psl-column-resolution-Bv_-TDHZ-C9foRNXV.d.mts} +2 -2
- package/dist/{psl-column-resolution-Bv_-TDHZ-Cuu5X_9o.d.mts.map → psl-column-resolution-Bv_-TDHZ-C9foRNXV.d.mts.map} +1 -1
- package/dist/{psl-field-resolution-GN4iup8d-DjlZymdL.mjs → psl-field-resolution-CpxUePg1-COJnJkDs.mjs} +9 -5
- package/dist/psl-field-resolution-CpxUePg1-COJnJkDs.mjs.map +1 -0
- package/dist/{psl-infer-C9kVS9ma.mjs → psl-infer-Ckg3t4Kr.mjs} +2 -2
- package/dist/{psl-infer-C9kVS9ma.mjs.map → psl-infer-Ckg3t4Kr.mjs.map} +1 -1
- package/dist/{query-lane-context-DIJU7Owj-CAZQq4AD.d.mts → query-lane-context-BetHj4j--D3S5nucp.d.mts} +5 -5
- package/dist/{query-lane-context-DIJU7Owj-CAZQq4AD.d.mts.map → query-lane-context-BetHj4j--D3S5nucp.d.mts.map} +1 -1
- package/dist/query-lane-context-DgxWaKr-.d.mts +1 -0
- package/dist/relational-core.d.mts +13 -13
- package/dist/relational-core.mjs +3 -3
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__aggregate-descriptor-registry.mjs +1 -1
- package/dist/relational-core__ast.d.mts +3 -3
- package/dist/relational-core__ast.mjs +2 -2
- package/dist/relational-core__codec-descriptor-registry.d.mts +2 -2
- package/dist/relational-core__collection-methods.d.mts +2 -2
- package/dist/relational-core__contract-free.d.mts +2 -2
- package/dist/relational-core__contract-free.mjs +1 -1
- package/dist/relational-core__contract-free.mjs.map +1 -1
- package/dist/relational-core__expression.d.mts +4 -4
- package/dist/relational-core__expression.mjs +1 -1
- package/dist/relational-core__functions.d.mts +2 -2
- package/dist/relational-core__functions.mjs +1 -1
- package/dist/relational-core__index-reference.d.mts +2 -2
- package/dist/relational-core__middleware.d.mts +2 -2
- package/dist/relational-core__plan.d.mts +3 -3
- package/dist/relational-core__query-lane-context.d.mts +2 -2
- package/dist/relational-core__types.d.mts +2 -2
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +1 -1
- package/dist/runtime__internal__prepared-query.d.mts +1 -1
- package/dist/{sql-contract-serializer-sMY3prTx-D_K7uFJk.mjs → sql-contract-serializer-sMY3prTx-CIDal1t1.mjs} +2 -2
- package/dist/{sql-contract-serializer-sMY3prTx-D_K7uFJk.mjs.map → sql-contract-serializer-sMY3prTx-CIDal1t1.mjs.map} +1 -1
- package/dist/{sql-execution-plan-BeuM3CeD-DIzyMDsA.d.mts → sql-execution-plan-4OFBeONp-CLkDqMdz.d.mts} +3 -3
- package/dist/sql-execution-plan-4OFBeONp-CLkDqMdz.d.mts.map +1 -0
- package/dist/{transaction-state-CEe4TlC1-C8vX6Ror.d.mts → transaction-state-B4FVsvO7-DpvKYHSB.d.mts} +12 -10
- package/dist/{transaction-state-CEe4TlC1-C8vX6Ror.d.mts.map → transaction-state-B4FVsvO7-DpvKYHSB.d.mts.map} +1 -1
- package/dist/types-BFCrGkhG.d.mts +1 -0
- package/dist/{types-C6r7Myrr-3WL0WDKF.d.mts → types-CGr02DOy-CQsUdKCe.d.mts} +6 -6
- package/dist/{types-C6r7Myrr-3WL0WDKF.d.mts.map → types-CGr02DOy-CQsUdKCe.d.mts.map} +1 -1
- package/dist/{types-CWvmfrfd-DLQYhSUx.d.mts → types-CWvmfrfd-HPIh55bi.d.mts} +2 -2
- package/dist/{types-CWvmfrfd-DLQYhSUx.d.mts.map → types-CWvmfrfd-HPIh55bi.d.mts.map} +1 -1
- package/dist/{types-DeimCJiI-CVQS7KCu.d.mts → types-DEbNJhyS-CY7Ye2vN.d.mts} +5 -5
- package/dist/{types-DeimCJiI-CVQS7KCu.d.mts.map → types-DEbNJhyS-CY7Ye2vN.d.mts.map} +1 -1
- package/dist/{types-wn1bXh0b-CJPAJi22.mjs → types-DzQmUrUm-ColHE4Av.mjs} +18 -5
- package/dist/types-DzQmUrUm-ColHE4Av.mjs.map +1 -0
- package/dist/{validators-CWcdf_jZ.mjs → validators-DbCIebZb.mjs} +2 -2
- package/dist/{validators-CWcdf_jZ.mjs.map → validators-DbCIebZb.mjs.map} +1 -1
- package/package.json +18 -18
- package/dist/collection-methods-B-md3Mu9.d.mts +0 -1
- package/dist/config-types-BVAADwjp.mjs +0 -68
- package/dist/config-types-BVAADwjp.mjs.map +0 -1
- package/dist/config-types-Ce1tAJ0B.d.mts.map +0 -1
- package/dist/contract-builder-Dbo5LeXs.mjs.map +0 -1
- package/dist/control-Cb6YoQ8j.d.mts.map +0 -1
- package/dist/control-kHFMtE8A.mjs.map +0 -1
- package/dist/db-DfYeGVcu-B99ycjaC.d.mts.map +0 -1
- package/dist/derived-checks-BWg0DOyz-7O0x1Tgn.mjs.map +0 -1
- package/dist/dist-BJjqJT_M.mjs.map +0 -1
- package/dist/exports-BR5ctYYI-C_-aedbr.mjs.map +0 -1
- package/dist/expression-D8c3t2Dx-CCHt1OdT.d.mts.map +0 -1
- package/dist/expression-DL7L8You-C9BAeM2d.d.mts.map +0 -1
- package/dist/expression-Voyb-zN0.d.mts +0 -2
- package/dist/expression-impl-DHdjzqE3-Cd9gP7oC.mjs.map +0 -1
- package/dist/foreign-key-materialization-C53nVQuD.d.mts.map +0 -1
- package/dist/foreign-key-materialization-CCHAR789.mjs.map +0 -1
- package/dist/functions-zPzQYOjW.d.mts +0 -1
- package/dist/index-DA1EEz4y.d.mts.map +0 -1
- package/dist/index-reference-DuQ-0Da9.d.mts +0 -1
- package/dist/interpreter-CVd521dx-wWck8W93.mjs.map +0 -1
- package/dist/middleware-DDOdMwm4.d.mts +0 -1
- package/dist/plan-BEnXVtn1.d.mts +0 -2
- package/dist/psl-field-resolution-GN4iup8d-DjlZymdL.mjs.map +0 -1
- package/dist/query-lane-context-Dm5f9VAQ.d.mts +0 -1
- package/dist/sql-execution-plan-BeuM3CeD-DIzyMDsA.d.mts.map +0 -1
- package/dist/types-ChjF67Fc.d.mts +0 -1
- package/dist/types-wn1bXh0b-CJPAJi22.mjs.map +0 -1
package/dist/orm-client.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { t as resolveStorageTable } from "./resolve-storage-table-BHLQsOza.mjs";
|
|
2
|
-
import { A as ParamRef, C as LiteralExpr, E as NullCheckExpr, F as SelectAst, G as isOrderByDirection, H as collectTableSources, I as SubqueryExpr, J as isWhereExpr, K as isOrderByNulls, L as TableSource, M as ProjectionItem, O as OrExpr, R as UpdateAst, S as ListExpression, T as NotExpr, V as checkLimitOffset, W as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, k as OrderByItem, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as LockingClause, x as JsonObjectExpr, y as JoinAst, z as WindowFuncExpr } from "./types-
|
|
2
|
+
import { A as ParamRef, C as LiteralExpr, E as NullCheckExpr, F as SelectAst, G as isOrderByDirection, H as collectTableSources, I as SubqueryExpr, J as isWhereExpr, K as isOrderByNulls, L as TableSource, M as ProjectionItem, O as OrExpr, R as UpdateAst, S as ListExpression, T as NotExpr, V as checkLimitOffset, W as isAggregateFn, _ as InsertAst, b as JsonArrayAggExpr, c as DeleteAst, f as EqColJoinOn, i as CaseExpr, k as OrderByItem, l as DerivedTableSource, n as AndExpr, o as ColumnRef, p as ExistsExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, w as LockingClause, x as JsonObjectExpr, y as JoinAst, z as WindowFuncExpr } from "./types-DzQmUrUm-ColHE4Av.mjs";
|
|
3
3
|
import { t as collectOrderedParamRefs } from "./util-DixeJBri-Cad7x5ec.mjs";
|
|
4
|
-
import { D as lockWaitPolicyOf, E as lockStrengthCapabilities, O as missingCapability, T as lockOptionCapabilities, n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection, w as lockIncompatible } from "./ast-
|
|
5
|
-
import { a as isExpression, s as toExpr, t as ExpressionImpl } from "./expression-impl-
|
|
4
|
+
import { D as lockWaitPolicyOf, E as lockStrengthCapabilities, O as missingCapability, T as lockOptionCapabilities, n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection, w as lockIncompatible } from "./ast-BpFfUmb_.mjs";
|
|
5
|
+
import { a as isExpression, s as toExpr, t as ExpressionImpl } from "./expression-impl-C5Ha-fXs-CxXn8gDo.mjs";
|
|
6
6
|
import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-UiFDvDj4.mjs";
|
|
7
|
-
import { t as createFunctions } from "./functions-
|
|
7
|
+
import { t as createFunctions } from "./functions-DGketpiK.mjs";
|
|
8
8
|
import { t as createIndexReferences } from "./index-reference-BQSrkRfT.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { h as findActivitySource } from "./exports-BR5ctYYI-C_-aedbr.mjs";
|
|
9
|
+
import { h as findActivitySource } from "./exports-kqOXg2OT-D3lo7jnX.mjs";
|
|
11
10
|
import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
12
11
|
import { ifDefined } from "@prisma/orm-framework/utils/defined";
|
|
13
12
|
import { domainModelsAtDefaultNamespace } from "@prisma/orm-framework/contract/types";
|
|
@@ -1904,7 +1903,7 @@ function includeCarriesLock(include) {
|
|
|
1904
1903
|
function stateCarriesLock(state) {
|
|
1905
1904
|
return state.locking !== void 0 || state.includes.some(includeCarriesLock);
|
|
1906
1905
|
}
|
|
1907
|
-
function conflictOf(state, call) {
|
|
1906
|
+
function conflictOf$1(state, call) {
|
|
1908
1907
|
if (state.includes.some(includeCarriesLock)) return "includeRefinement";
|
|
1909
1908
|
if (state.locking === void 0) return void 0;
|
|
1910
1909
|
if (call !== void 0) return call;
|
|
@@ -1914,7 +1913,7 @@ function conflictOf(state, call) {
|
|
|
1914
1913
|
}
|
|
1915
1914
|
/** Refuses a row lock the ORM cannot render: inside an include, with include, distinct or distinctOn in the state, or before a call that drops it. */
|
|
1916
1915
|
function assertLockCompatible(state, call) {
|
|
1917
|
-
const conflict = conflictOf(state, call);
|
|
1916
|
+
const conflict = conflictOf$1(state, call);
|
|
1918
1917
|
if (conflict !== void 0) throw lockIncompatible(conflict, `A locking clause cannot be combined with ${conflict}`);
|
|
1919
1918
|
}
|
|
1920
1919
|
function augmentSelectionForJoinColumns(selectedFields, requiredColumns) {
|
|
@@ -4442,10 +4441,11 @@ function createFilteredRelationMutator(related) {
|
|
|
4442
4441
|
function createRelationMutator(related) {
|
|
4443
4442
|
const mutator = {
|
|
4444
4443
|
...createFilteredRelationMutator(related),
|
|
4445
|
-
create(data) {
|
|
4444
|
+
create(data, options) {
|
|
4446
4445
|
return {
|
|
4447
4446
|
kind: "create",
|
|
4448
|
-
data: Array.isArray(data) ? [...data] : [data]
|
|
4447
|
+
data: Array.isArray(data) ? [...data] : [data],
|
|
4448
|
+
...ifDefined("options", options)
|
|
4449
4449
|
};
|
|
4450
4450
|
},
|
|
4451
4451
|
variant(value) {
|
|
@@ -4454,8 +4454,8 @@ function createRelationMutator(related) {
|
|
|
4454
4454
|
const { variantValue } = state;
|
|
4455
4455
|
return {
|
|
4456
4456
|
...createFilteredRelationMutator(variantCollection),
|
|
4457
|
-
create: (data) => ({
|
|
4458
|
-
...mutator.create(data),
|
|
4457
|
+
create: (data, options) => ({
|
|
4458
|
+
...mutator.create(data, options),
|
|
4459
4459
|
...ifDefined("variant", variantValue)
|
|
4460
4460
|
}),
|
|
4461
4461
|
connect: (criteria) => ({
|
|
@@ -4506,7 +4506,7 @@ function parseMutationInput(contract, namespaceId, modelName, input, relatedColl
|
|
|
4506
4506
|
continue;
|
|
4507
4507
|
}
|
|
4508
4508
|
if (value === void 0) continue;
|
|
4509
|
-
if (!isRelationMutationCallback(value)) throw ormError("ORM.
|
|
4509
|
+
if (!isRelationMutationCallback(value)) throw ormError("ORM.ARGUMENT_INVALID", `Relation field "${fieldName}" on model "${modelName}" expects a mutator callback`, { meta: {
|
|
4510
4510
|
relation: fieldName,
|
|
4511
4511
|
model: modelName,
|
|
4512
4512
|
problem: "missing-callback"
|
|
@@ -4517,7 +4517,7 @@ function parseMutationInput(contract, namespaceId, modelName, input, relatedColl
|
|
|
4517
4517
|
if (Array.isArray(element) || !isRelationMutationDescriptor(element)) throw invalidRelationField(fieldName, modelName, Array.isArray(element), at);
|
|
4518
4518
|
return element;
|
|
4519
4519
|
});
|
|
4520
|
-
if (mutations.length > 1 && (relation.cardinality === "N:1" || relation.cardinality === "1:1")) throw ormError("ORM.
|
|
4520
|
+
if (mutations.length > 1 && (relation.cardinality === "N:1" || relation.cardinality === "1:1")) throw ormError("ORM.OPERATION_UNSUPPORTED", `Relation "${fieldName}" on model "${modelName}" is a to-one relation and takes one operation, not ${mutations.length}`, { meta: {
|
|
4521
4521
|
relation: fieldName,
|
|
4522
4522
|
model: modelName,
|
|
4523
4523
|
reason: "to-one-relation",
|
|
@@ -4537,7 +4537,7 @@ function parseMutationInput(contract, namespaceId, modelName, input, relatedColl
|
|
|
4537
4537
|
}
|
|
4538
4538
|
function invalidRelationField(fieldName, modelName, nested, index) {
|
|
4539
4539
|
const at = index === void 0 ? "" : ` at index ${index}`;
|
|
4540
|
-
return ormError("ORM.
|
|
4540
|
+
return ormError("ORM.ARGUMENT_INVALID", `Relation field "${fieldName}" on model "${modelName}" ${nested ? `returned a nested array${at}; return one flat array of mutations` : `returned an invalid mutation descriptor${at}`}`, { meta: {
|
|
4541
4541
|
relation: fieldName,
|
|
4542
4542
|
model: modelName,
|
|
4543
4543
|
problem: nested ? "nested-array" : "invalid-descriptor",
|
|
@@ -4573,7 +4573,7 @@ function assertJunctionPayloadWritable({ name, relation, mutations }) {
|
|
|
4573
4573
|
const mutation = mutations.find(({ kind }) => kind === "create" || kind === "connect");
|
|
4574
4574
|
if (mutation === void 0 || through.requiredPayloadColumns.length === 0) return;
|
|
4575
4575
|
const cols = through.requiredPayloadColumns.map((c) => `\`${c}\``).join(", ");
|
|
4576
|
-
throw ormError("ORM.
|
|
4576
|
+
throw ormError("ORM.OPERATION_UNSUPPORTED", `Cannot \`${mutation.kind}\` on relation \`${name}\`: its junction \`${through.table}\` has required column(s) ${cols} the relation API can't populate. Write the \`${through.table}\` junction directly or use the SQL builder.`, { meta: {
|
|
4577
4577
|
kind: mutation.kind,
|
|
4578
4578
|
relation: name,
|
|
4579
4579
|
reason: "junction-required-columns",
|
|
@@ -4648,15 +4648,27 @@ function normalizeInsertRows(contract, namespaceId, tableName, rows) {
|
|
|
4648
4648
|
return normalizedRow;
|
|
4649
4649
|
}) };
|
|
4650
4650
|
}
|
|
4651
|
-
function
|
|
4652
|
-
if (!
|
|
4653
|
-
if (
|
|
4654
|
-
|
|
4651
|
+
function conflictClause(contract, target, conflict) {
|
|
4652
|
+
if (!conflict) return void 0;
|
|
4653
|
+
if ("link" in conflict) {
|
|
4654
|
+
const columns = conflict.targeted ? conflict.columns : [];
|
|
4655
|
+
return InsertOnConflict.on(columns.map((column) => target.column(column))).doUpdateSet(linkAssignments(contract, target, conflict));
|
|
4656
|
+
}
|
|
4657
|
+
if (conflict.columns.length === 0) return InsertOnConflict.doNothing();
|
|
4658
|
+
return InsertOnConflict.on(conflict.columns.map((column) => target.column(column))).doNothing();
|
|
4659
|
+
}
|
|
4660
|
+
function linkAssignments(contract, target, { columns: [first], link, guard }) {
|
|
4661
|
+
if (link.length === 0 && first !== void 0) return { [first]: target.column(first) };
|
|
4662
|
+
const proposed = (column) => guard === void 0 ? ColumnRef.of("excluded", column) : CaseExpr.of([{
|
|
4663
|
+
condition: BinaryExpr.eq(target.column(guard.column), paramRefForStorageColumn(contract, target.storage, guard.column, guard.value)),
|
|
4664
|
+
value: ColumnRef.of("excluded", column)
|
|
4665
|
+
}], target.column(column));
|
|
4666
|
+
return Object.fromEntries(link.map((column) => [column, proposed(column)]));
|
|
4655
4667
|
}
|
|
4656
|
-
function insertAst(contract, target, rows,
|
|
4668
|
+
function insertAst(contract, target, rows, conflict) {
|
|
4657
4669
|
const { namespaceId, tableName } = target.storage;
|
|
4658
4670
|
const { rows: normalizedRows } = normalizeInsertRows(contract, namespaceId, tableName, rows);
|
|
4659
|
-
return InsertAst.into(target.tableSource(contract)).withRows(normalizedRows).withOnConflict(
|
|
4671
|
+
return InsertAst.into(target.tableSource(contract)).withRows(normalizedRows).withOnConflict(conflictClause(contract, target, conflict));
|
|
4660
4672
|
}
|
|
4661
4673
|
function stripUndefinedValues(row) {
|
|
4662
4674
|
const result = {};
|
|
@@ -4753,6 +4765,60 @@ function reportedInsertId(stats, generated, owner) {
|
|
|
4753
4765
|
affectedRows: stats.affectedRows
|
|
4754
4766
|
} });
|
|
4755
4767
|
}
|
|
4768
|
+
function conflictKeysOf(contract, namespaceId, tableName, onConflict, conflictColumns) {
|
|
4769
|
+
if (conflictColumns.length > 0) return [conflictColumns];
|
|
4770
|
+
const table = storageTableForContract(contract, namespaceId, tableName);
|
|
4771
|
+
if (onConflict === "connect") {
|
|
4772
|
+
const primaryKey = table.primaryKey?.columns;
|
|
4773
|
+
return primaryKey === void 0 || primaryKey.length === 0 ? [] : [primaryKey];
|
|
4774
|
+
}
|
|
4775
|
+
const uniqueIndexes = table.indexes.flatMap((index) => index.unique && index.columns !== void 0 ? [index.columns] : []);
|
|
4776
|
+
return [...resolveUniqueKeyColumnSets(contract, namespaceId, tableName), ...uniqueIndexes];
|
|
4777
|
+
}
|
|
4778
|
+
function rowThatCannotConflict(rows, keys, parentLinkColumns) {
|
|
4779
|
+
const index = rows.findIndex((row) => !keys.some((key) => key.every((column) => parentLinkColumns.has(column) || row[column] !== void 0 && row[column] !== null)));
|
|
4780
|
+
return index === -1 ? void 0 : index;
|
|
4781
|
+
}
|
|
4782
|
+
function variantInOwnTableOf(contract, namespaceId, modelName, variantValue) {
|
|
4783
|
+
const variant = variantValue === void 0 ? void 0 : resolvePolymorphismInfo(contract, namespaceId, modelName)?.variants.get(variantValue);
|
|
4784
|
+
return variant?.strategy === "mti" ? {
|
|
4785
|
+
variant: variant.modelName,
|
|
4786
|
+
model: modelName
|
|
4787
|
+
} : void 0;
|
|
4788
|
+
}
|
|
4789
|
+
function resolveConflict(contract, call, namespaceId, { onConflict, conflictOn }, accepted, variantInOwnTable) {
|
|
4790
|
+
const action = accepted.find((value) => value === onConflict);
|
|
4791
|
+
if (action === void 0) throw ormError("ORM.ARGUMENT_INVALID", `${call.action} takes onConflict ${accepted.map((value) => `"${value}"`).join(" or ")}; received ${JSON.stringify(onConflict)}`, { meta: {
|
|
4792
|
+
...call.meta,
|
|
4793
|
+
problem: "invalid-on-conflict"
|
|
4794
|
+
} });
|
|
4795
|
+
if (variantInOwnTable !== void 0) throw ormError("ORM.OPERATION_UNSUPPORTED", `The onConflict option is not supported on variant "${variantInOwnTable.variant}" of model "${variantInOwnTable.model}" because the variant is stored in its own table. Leave the option out; a duplicate row then makes the call fail.`, { meta: {
|
|
4796
|
+
...call.meta,
|
|
4797
|
+
variant: variantInOwnTable.variant,
|
|
4798
|
+
reason: "mti-variant"
|
|
4799
|
+
} });
|
|
4800
|
+
const fields = conflictOn ?? [];
|
|
4801
|
+
if (action === "skip") assertInsertConflictSkipCapability(contract, call.action, fields.length > 0);
|
|
4802
|
+
return {
|
|
4803
|
+
onConflict: action,
|
|
4804
|
+
columns: resolveInsertConflictColumns(contract, namespaceId, call.modelName, fields)
|
|
4805
|
+
};
|
|
4806
|
+
}
|
|
4807
|
+
function requireRowsThatCanConflict(contract, call, { namespaceId, tableName }, { onConflict, columns }, rows, filledColumns) {
|
|
4808
|
+
const keys = conflictKeysOf(contract, namespaceId, tableName, onConflict, columns);
|
|
4809
|
+
if (keys.length === 0) throw ormError("ORM.ARGUMENT_INVALID", onConflict === "skip" ? `${call.action} on model "${call.modelName}" has nothing to skip on: table "${tableName}" has no primary key, unique constraint or unique index over columns, so onConflict "skip" cannot skip any row` : `${call.action} on model "${call.modelName}" has nothing to connect on: table "${tableName}" has no primary key, so onConflict "connect" needs conflictOn`, { meta: {
|
|
4810
|
+
...call.meta,
|
|
4811
|
+
problem: "no-conflict-key"
|
|
4812
|
+
} });
|
|
4813
|
+
const index = rows.findIndex((row, at) => rowThatCannotConflict([row], keys, new Set(filledColumns(at))) !== void 0);
|
|
4814
|
+
if (index !== -1) throw ormError("ORM.ARGUMENT_INVALID", `${call.action} row ${index} for model "${call.modelName}" gives no value for any conflict key: ${keys.map((key) => `(${key.join(", ")})`).join(", ")}`, { meta: {
|
|
4815
|
+
...call.meta,
|
|
4816
|
+
problem: "row-cannot-conflict",
|
|
4817
|
+
index,
|
|
4818
|
+
conflictKeys: keys
|
|
4819
|
+
} });
|
|
4820
|
+
return keys;
|
|
4821
|
+
}
|
|
4756
4822
|
var Node = class {
|
|
4757
4823
|
checkIfCanRun(_graph, _id, _context) {}
|
|
4758
4824
|
};
|
|
@@ -5193,10 +5259,10 @@ function checkOwnValues(graph, id, context, asts, returns, owner) {
|
|
|
5193
5259
|
} });
|
|
5194
5260
|
rowIdentity(context.contract, namespaceId, tableName, owner.modelName, method);
|
|
5195
5261
|
const given = [graph.inputsOf(id)["payload"] ?? []].flat().flatMap((edge) => edge instanceof DataEdge ? edge.columns.map(([, target]) => target) : []);
|
|
5196
|
-
for (const ast of asts) refuseUpsertOfColumnsReadBack(ast, returns, owner);
|
|
5262
|
+
for (const ast of asts) refuseUpsertOfColumnsReadBack(ast, returns, owner, given);
|
|
5197
5263
|
generatedKeyColumn(insertedRowsOf(context, first.table, asts, returns, owner, given));
|
|
5198
5264
|
}
|
|
5199
|
-
function refuseUpsertOfColumnsReadBack(ast, returns, owner) {
|
|
5265
|
+
function refuseUpsertOfColumnsReadBack(ast, returns, owner, given) {
|
|
5200
5266
|
const action = ast.onConflict?.action;
|
|
5201
5267
|
if (action?.kind !== "do-update-set") return;
|
|
5202
5268
|
const method = `${owner.operation}()`;
|
|
@@ -5205,12 +5271,13 @@ function refuseUpsertOfColumnsReadBack(ast, returns, owner) {
|
|
|
5205
5271
|
action: method
|
|
5206
5272
|
} });
|
|
5207
5273
|
const read = returns.map((column) => column.alias);
|
|
5274
|
+
const unchanged = /* @__PURE__ */ new Set(["excluded", ast.table.alias ?? ast.table.name]);
|
|
5208
5275
|
const updated = read.filter((column) => {
|
|
5209
5276
|
const value = action.set[column];
|
|
5210
|
-
return value !== void 0 && !(value.kind === "column-ref" && value.table
|
|
5277
|
+
return value !== void 0 && !(value.kind === "column-ref" && unchanged.has(value.table) && value.column === column);
|
|
5211
5278
|
});
|
|
5212
5279
|
if (updated.length > 0) throw refused(`updates conflict column "${updated.join("\", \"")}"`);
|
|
5213
|
-
const absent = read.filter((column) => ast.rows.some((row) => row[column]?.kind !== "param-ref"));
|
|
5280
|
+
const absent = read.filter((column) => !given.some(({ alias }) => alias === column) && ast.rows.some((row) => row[column]?.kind !== "param-ref"));
|
|
5214
5281
|
if (absent.length > 0) throw refused(`gives conflict column "${absent.join("\", \"")}" no create value`);
|
|
5215
5282
|
}
|
|
5216
5283
|
function insertGivingOwnValues(asts, returns, owner, run) {
|
|
@@ -5340,7 +5407,7 @@ function foldRule(contract) {
|
|
|
5340
5407
|
function assertOneValuePerColumn(values, { relation, junction }) {
|
|
5341
5408
|
const seen = /* @__PURE__ */ new Map();
|
|
5342
5409
|
for (const [column, value] of values) {
|
|
5343
|
-
if (seen.has(column) && !Object.is(seen.get(column), value)) throw ormError("ORM.
|
|
5410
|
+
if (seen.has(column) && !Object.is(seen.get(column), value)) throw ormError("ORM.ARGUMENT_INVALID", `Cannot write junction "${junction}": conflicting values for junction column "${column}"`, { meta: {
|
|
5344
5411
|
relation,
|
|
5345
5412
|
junction,
|
|
5346
5413
|
column
|
|
@@ -5881,6 +5948,16 @@ function insertRows(b, model, rows, { conflict, keys, requires, owner, returns,
|
|
|
5881
5948
|
requires,
|
|
5882
5949
|
owner
|
|
5883
5950
|
});
|
|
5951
|
+
if (conflict !== void 0 && "link" in conflict) {
|
|
5952
|
+
if (afterWrite === void 0 && returns === "count") return inserted;
|
|
5953
|
+
const linked = readBack(b, model, inserted, conflict.columns, {
|
|
5954
|
+
shape,
|
|
5955
|
+
by: "keys",
|
|
5956
|
+
owner
|
|
5957
|
+
});
|
|
5958
|
+
afterWrite?.(linked);
|
|
5959
|
+
return returns === "count" ? inserted : linked;
|
|
5960
|
+
}
|
|
5884
5961
|
afterWrite?.(inserted);
|
|
5885
5962
|
return readBackRows(b, model, inserted, {
|
|
5886
5963
|
returns,
|
|
@@ -5983,20 +6060,24 @@ var Assert = class extends Node {
|
|
|
5983
6060
|
requires: "list"
|
|
5984
6061
|
};
|
|
5985
6062
|
error;
|
|
5986
|
-
|
|
6063
|
+
expected;
|
|
6064
|
+
constructor(error, expected = {}) {
|
|
5987
6065
|
super();
|
|
5988
6066
|
this.error = error;
|
|
6067
|
+
this.expected = Object.freeze({ ...expected });
|
|
5989
6068
|
Object.freeze(this);
|
|
5990
6069
|
}
|
|
5991
6070
|
execute(inputs, _run) {
|
|
5992
6071
|
if (requirementUnmet(inputs.requires)) return rowsResult([]);
|
|
5993
|
-
|
|
6072
|
+
const { expected } = this;
|
|
6073
|
+
if (inputs.rows.length === 0 || inputs.rows.some((row) => Object.entries(expected).some(([column, value]) => row[column] !== value))) throw this.error;
|
|
5994
6074
|
return rowsResult([]);
|
|
5995
6075
|
}
|
|
5996
6076
|
};
|
|
5997
6077
|
const nothingBefore = {
|
|
5998
6078
|
keys: [],
|
|
5999
|
-
nullColumns: {}
|
|
6079
|
+
nullColumns: {},
|
|
6080
|
+
unlinksAfterWrite: false
|
|
6000
6081
|
};
|
|
6001
6082
|
function modelOf(collection) {
|
|
6002
6083
|
const { modelName, namespaceId, state } = collection;
|
|
@@ -6092,6 +6173,11 @@ function updateValuesOf(collection, data) {
|
|
|
6092
6173
|
}
|
|
6093
6174
|
function mappedUpdateRow(collection, data) {
|
|
6094
6175
|
const { context, modelName, namespaceId } = collection;
|
|
6176
|
+
const discriminator = resolvePolymorphismInfo(context.contract, namespaceId, modelName)?.discriminatorField;
|
|
6177
|
+
if (discriminator !== void 0 && data[discriminator] !== void 0) throw ormError("ORM.FIELD_IMMUTABLE", `Update data for model "${modelName}" cannot set its discriminator "${discriminator}"`, { meta: {
|
|
6178
|
+
model: modelName,
|
|
6179
|
+
field: discriminator
|
|
6180
|
+
} });
|
|
6095
6181
|
return mapModelDataToStorageRow(context.contract, namespaceId, modelName, data);
|
|
6096
6182
|
}
|
|
6097
6183
|
function withUpdateDefaults(collection, set, before) {
|
|
@@ -6105,20 +6191,28 @@ function withUpdateDefaults(collection, set, before) {
|
|
|
6105
6191
|
...values
|
|
6106
6192
|
};
|
|
6107
6193
|
if (Object.keys(written).length === 0) return values;
|
|
6108
|
-
|
|
6109
|
-
|
|
6194
|
+
return {
|
|
6195
|
+
...values,
|
|
6196
|
+
...updateDefaultsOf(collection.context, modelOf(collection), written)
|
|
6197
|
+
};
|
|
6198
|
+
}
|
|
6199
|
+
function updateDefaultsOf(context, model, written) {
|
|
6200
|
+
const { namespaceId, tableName } = model.tables.root.storage;
|
|
6201
|
+
return Object.fromEntries(context.applyMutationDefaults({
|
|
6110
6202
|
op: "update",
|
|
6111
6203
|
entry: tableName,
|
|
6112
6204
|
namespace: namespaceId,
|
|
6113
6205
|
values: written
|
|
6114
|
-
}))
|
|
6115
|
-
|
|
6206
|
+
}).map((applied) => [applied.field, applied.value]));
|
|
6207
|
+
}
|
|
6208
|
+
function addCreateWithRelations(t, model, parsed, createOf) {
|
|
6209
|
+
return insertWithRelations(t, model, parsed, createOf, void 0, void 0);
|
|
6116
6210
|
}
|
|
6117
|
-
function
|
|
6211
|
+
function insertWithRelations(t, model, parsed, { keysFromParent, returns, shape, variantValue }, storageRow, nested) {
|
|
6118
6212
|
for (const relationMutation of parsed.relationMutations) rejectUpdateOnly(relationMutation);
|
|
6119
6213
|
const before = addBeforeWrite(t, model, parsed.relationMutations);
|
|
6120
|
-
return insertRows(t, model, [createRowOf(t.context, model, variantValue, parsed.scalarData, void 0)], {
|
|
6121
|
-
conflict:
|
|
6214
|
+
return insertRows(t, model, [storageRow ?? createRowOf(t.context, model, variantValue, parsed.scalarData, void 0)], {
|
|
6215
|
+
conflict: nested?.conflict,
|
|
6122
6216
|
keys: [...keysFromParent, ...before.keys],
|
|
6123
6217
|
requires: keysFromParent.length === 0 ? parentRowRequired(t) : [],
|
|
6124
6218
|
owner: {
|
|
@@ -6127,15 +6221,41 @@ function addCreateWithRelations(t, model, parsed, { keysFromParent, returns, sha
|
|
|
6127
6221
|
},
|
|
6128
6222
|
returns,
|
|
6129
6223
|
shape,
|
|
6130
|
-
afterWrite: (
|
|
6224
|
+
afterWrite: afterWriteOf(t, model, parsed.relationMutations, nested)
|
|
6131
6225
|
});
|
|
6132
6226
|
}
|
|
6133
|
-
function
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6227
|
+
function afterWriteOf(t, model, relationMutations, nested) {
|
|
6228
|
+
const { childOwned, junctionOwned } = partitionByOwnership(relationMutations);
|
|
6229
|
+
const readsRow = childOwned.length > 0 || junctionOwned.length > 0;
|
|
6230
|
+
const guard = nested !== void 0 && "link" in nested.conflict ? nested.conflict.guard : void 0;
|
|
6231
|
+
if (!readsRow && guard === void 0) return;
|
|
6232
|
+
return (written) => {
|
|
6233
|
+
if (guard !== void 0 && nested !== void 0) addVariantCheck(t, model, written, nested.relation, guard);
|
|
6234
|
+
if (readsRow) addAfterWrite(t, model, written, relationMutations);
|
|
6235
|
+
};
|
|
6236
|
+
}
|
|
6237
|
+
function addVariantCheck({ graph, context }, model, written, relation, { column, value }) {
|
|
6238
|
+
const discriminator = projectTableColumn(context.contract, model.tables.root, column);
|
|
6239
|
+
graph.add(new Assert(ormError("ORM.RELATION_ROW_MISSING", `create() nested mutation for relation "${relation}" found a row of another variant than "${value}" on its conflict key`, { meta: {
|
|
6240
|
+
kind: "create",
|
|
6241
|
+
relation,
|
|
6242
|
+
variant: value
|
|
6243
|
+
} }), { [column]: value }), {
|
|
6244
|
+
rows: new Rows(written, [[discriminator, discriminator]]),
|
|
6245
|
+
requires: []
|
|
6246
|
+
});
|
|
6247
|
+
}
|
|
6248
|
+
function addLinkedCreates(t, related, name, relatedCollection, mutation, resolved, data, link) {
|
|
6249
|
+
const rows = data.map((row) => parseCreateInput(t, related, row, relatedCollection));
|
|
6250
|
+
const values = rows.map((row) => createRowOf(t.context, related, mutation.variant, row.scalarData, void 0));
|
|
6251
|
+
const nested = conflictOf(t, related, name, [], resolved, rows, values, mutation.variant);
|
|
6252
|
+
rows.forEach((row, index) => {
|
|
6253
|
+
link(insertWithRelations(t, related, row, {
|
|
6254
|
+
keysFromParent: [],
|
|
6255
|
+
returns: "rows",
|
|
6256
|
+
shape: allColumns,
|
|
6257
|
+
variantValue: mutation.variant
|
|
6258
|
+
}, values[index], nested));
|
|
6139
6259
|
});
|
|
6140
6260
|
}
|
|
6141
6261
|
function addVariantInOwnTable(t, { relation, relatedCollection }, { data, variant }, keys, added) {
|
|
@@ -6166,36 +6286,96 @@ function addBeforeWrite(t, model, relationMutations) {
|
|
|
6166
6286
|
}
|
|
6167
6287
|
const keys = [];
|
|
6168
6288
|
const nullColumns = {};
|
|
6289
|
+
let unlinksAfterWrite = false;
|
|
6169
6290
|
for (const relationMutation of relationMutations) rejectFilteredWriteOnToOne(relationMutation);
|
|
6170
6291
|
for (const relationMutation of parentOwned) for (const mutation of relationMutation.mutations) {
|
|
6171
6292
|
if (isFilteredWrite(mutation)) continue;
|
|
6172
6293
|
if (mutation.kind === "disconnect") {
|
|
6173
|
-
|
|
6294
|
+
rejectNullOnRequiredKey(t.context.contract, mutation.kind, relationMutation.name, model, relationMutation.relation.on.localFields);
|
|
6295
|
+
if (disconnectsNothing(mutation)) continue;
|
|
6296
|
+
if (isConditionalUnlink(mutation)) {
|
|
6297
|
+
unlinksAfterWrite = true;
|
|
6298
|
+
continue;
|
|
6299
|
+
}
|
|
6174
6300
|
for (const column of localColumnsOf(t.context.contract, model, relationMutation.relation)) nullColumns[column] = null;
|
|
6175
6301
|
} else keys.push(...addParentOwned(t, model, relationMutation, mutation));
|
|
6176
6302
|
}
|
|
6177
6303
|
return {
|
|
6178
6304
|
keys,
|
|
6179
|
-
nullColumns
|
|
6305
|
+
nullColumns,
|
|
6306
|
+
unlinksAfterWrite
|
|
6180
6307
|
};
|
|
6181
6308
|
}
|
|
6182
6309
|
function addAfterWrite(t, model, parent, relationMutations) {
|
|
6183
|
-
const { childOwned, junctionOwned } = partitionByOwnership(relationMutations);
|
|
6310
|
+
const { parentOwned, childOwned, junctionOwned } = partitionByOwnership(relationMutations);
|
|
6311
|
+
for (const relationMutation of parentOwned) for (const mutation of relationMutation.mutations) if (mutation.kind === "disconnect" && !disconnectsNothing(mutation) && isConditionalUnlink(mutation)) addConditionalUnlink(t, model, parent, relationMutation, mutation);
|
|
6184
6312
|
for (const relationMutation of childOwned) for (const mutation of relationMutation.mutations) addChildOwned(t, model, parent, relationMutation, mutation);
|
|
6185
6313
|
for (const relationMutation of junctionOwned) for (const mutation of relationMutation.mutations) addJunctionOwned(t, model, parent, relationMutation, mutation);
|
|
6186
6314
|
}
|
|
6187
6315
|
function rejectUpdateOnly({ name, mutations }) {
|
|
6188
|
-
for (const { kind } of mutations) if (kind === "disconnect" || kind === "updateAll" || kind === "deleteAll") throw ormError("ORM.
|
|
6316
|
+
for (const { kind } of mutations) if (kind === "disconnect" || kind === "updateAll" || kind === "deleteAll") throw ormError("ORM.OPERATION_UNSUPPORTED", `${kind}() is only supported in update() nested mutations`, { meta: {
|
|
6189
6317
|
kind,
|
|
6190
6318
|
relation: name
|
|
6191
6319
|
} });
|
|
6192
6320
|
}
|
|
6193
|
-
function
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6321
|
+
function isConditionalUnlink(mutation) {
|
|
6322
|
+
return mutation.state !== void 0 || mutation.criteria !== void 0;
|
|
6323
|
+
}
|
|
6324
|
+
function disconnectsNothing(mutation) {
|
|
6325
|
+
return mutation.criteria !== void 0 && mutation.criteria.length === 0;
|
|
6326
|
+
}
|
|
6327
|
+
function addConditionalUnlink(t, model, parent, { name, relation }, mutation) {
|
|
6328
|
+
const { context } = t;
|
|
6329
|
+
const { contract } = context;
|
|
6330
|
+
const related = relatedModel(contract, relation, mutation.state);
|
|
6331
|
+
const localColumns = localColumnsOf(contract, model, relation);
|
|
6332
|
+
const keys = projectTableColumns(contract, model.tables.root, localColumns).map(({ expr }) => expr);
|
|
6333
|
+
const [only, ...others] = keys;
|
|
6334
|
+
const linked = only !== void 0 && others.length === 0 ? only : ListExpression.of(keys);
|
|
6335
|
+
const targets = projectTableColumns(contract, related.tables.root, resolveRelationTargetColumns(contract, relation));
|
|
6336
|
+
const { criteria } = mutation;
|
|
6337
|
+
const wheres = criteria === void 0 ? [variantWhere(contract, mutation.state, void 0)] : criteria.map((criterion) => requiredCriterion(context, related, name, mutation, criterion));
|
|
6338
|
+
const nulls = Object.fromEntries(localColumns.map((column) => [column, null]));
|
|
6339
|
+
const unlink = {
|
|
6340
|
+
...nulls,
|
|
6341
|
+
...updateDefaultsOf(context, model, {
|
|
6342
|
+
...t.parentValues,
|
|
6343
|
+
...nulls
|
|
6344
|
+
})
|
|
6345
|
+
};
|
|
6346
|
+
for (const where of wheres) {
|
|
6347
|
+
const target = SelectAst.from(related.tables.root.tableSource(contract)).withProjection(targets);
|
|
6348
|
+
updateRows(t, model, unlink, {
|
|
6349
|
+
where: BinaryExpr.in(linked, SubqueryExpr.of(where === void 0 ? target : target.withWhere(where))),
|
|
6350
|
+
filters: [{
|
|
6351
|
+
from: parent,
|
|
6352
|
+
columns: sameRowColumnsOf(contract, model.tables.root)
|
|
6353
|
+
}],
|
|
6354
|
+
links: [],
|
|
6355
|
+
payloads: [],
|
|
6356
|
+
owner: {
|
|
6357
|
+
operation: "update",
|
|
6358
|
+
modelName: model.modelName
|
|
6359
|
+
},
|
|
6360
|
+
returns: "count",
|
|
6361
|
+
shape: allColumns,
|
|
6362
|
+
afterWrite: void 0
|
|
6363
|
+
});
|
|
6364
|
+
}
|
|
6365
|
+
}
|
|
6366
|
+
function rejectNullOnRequiredKey(contract, kind, name, holder, keyFields) {
|
|
6367
|
+
const fields = getModelFields(contract, holder.namespaceId, holder.modelName);
|
|
6368
|
+
const required = keyFields.filter((field) => {
|
|
6369
|
+
const column = Object.hasOwn(fields, field) ? fields[field] : void 0;
|
|
6370
|
+
return column !== void 0 && storageTableForContract(contract, column.namespaceId, column.table).columns[column.column]?.nullable === false;
|
|
6371
|
+
});
|
|
6372
|
+
if (required.length === 0) return;
|
|
6373
|
+
throw ormError("ORM.OPERATION_UNSUPPORTED", `${kind}() nested mutation for relation "${name}" cannot set ${required.map((field) => `"${field}"`).join(", ")} of model "${holder.modelName}" to null, because the foreign key is required`, { meta: {
|
|
6374
|
+
kind,
|
|
6197
6375
|
relation: name,
|
|
6198
|
-
reason: "
|
|
6376
|
+
reason: "required-foreign-key",
|
|
6377
|
+
model: holder.modelName,
|
|
6378
|
+
fields: required
|
|
6199
6379
|
} });
|
|
6200
6380
|
}
|
|
6201
6381
|
function isFilteredWrite(mutation) {
|
|
@@ -6203,7 +6383,7 @@ function isFilteredWrite(mutation) {
|
|
|
6203
6383
|
}
|
|
6204
6384
|
function rejectFilteredWriteOnToOne({ name, relation, mutations }) {
|
|
6205
6385
|
const filtered = mutations.find(isFilteredWrite);
|
|
6206
|
-
if (filtered !== void 0 && (relation.cardinality === "N:1" || relation.cardinality === "1:1")) throw ormError("ORM.
|
|
6386
|
+
if (filtered !== void 0 && (relation.cardinality === "N:1" || relation.cardinality === "1:1")) throw ormError("ORM.OPERATION_UNSUPPORTED", `${filtered.kind}() nested mutation for relation "${name}" is only supported on to-many relations`, { meta: {
|
|
6207
6387
|
kind: filtered.kind,
|
|
6208
6388
|
relation: name,
|
|
6209
6389
|
reason: "to-one-relation"
|
|
@@ -6215,11 +6395,12 @@ function addParentOwned(t, model, { name, relation, relatedCollection }, mutatio
|
|
|
6215
6395
|
const columns = columnMappings(contract, related.tables.root, resolveRelationTargetColumns(contract, relation), model.tables.root, localColumnsOf(contract, model, relation));
|
|
6216
6396
|
if (mutation.kind === "create") {
|
|
6217
6397
|
const [row] = mutation.data;
|
|
6218
|
-
if (row === void 0) throw ormError("ORM.
|
|
6398
|
+
if (row === void 0) throw ormError("ORM.ARGUMENT_INVALID", `create() nested mutation for relation "${name}" requires data`, { meta: {
|
|
6219
6399
|
kind: "create",
|
|
6220
6400
|
relation: name,
|
|
6221
6401
|
problem: "missing-data"
|
|
6222
6402
|
} });
|
|
6403
|
+
const resolved = nestedConflictOf(t, name, relation, mutation);
|
|
6223
6404
|
const keys = [];
|
|
6224
6405
|
const added = (from) => keys.push({
|
|
6225
6406
|
from,
|
|
@@ -6232,13 +6413,11 @@ function addParentOwned(t, model, { name, relation, relatedCollection }, mutatio
|
|
|
6232
6413
|
...mutation,
|
|
6233
6414
|
data: [row]
|
|
6234
6415
|
}, [], added)) return keys;
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
columns
|
|
6238
|
-
}];
|
|
6416
|
+
addLinkedCreates(t, related, name, relatedCollection, mutation, resolved, [row], added);
|
|
6417
|
+
return keys;
|
|
6239
6418
|
}
|
|
6240
6419
|
const [criterion] = mutation.criteria;
|
|
6241
|
-
if (criterion === void 0) throw ormError("ORM.
|
|
6420
|
+
if (criterion === void 0) throw ormError("ORM.ARGUMENT_INVALID", `connect() nested mutation for relation "${name}" requires criterion`, { meta: {
|
|
6242
6421
|
kind: "connect",
|
|
6243
6422
|
relation: name,
|
|
6244
6423
|
problem: "missing-criterion"
|
|
@@ -6266,16 +6445,38 @@ function addChildOwned(t, model, parent, { name, relation, relatedCollection },
|
|
|
6266
6445
|
from: parent,
|
|
6267
6446
|
columns: fromParent
|
|
6268
6447
|
}];
|
|
6448
|
+
const resolved = nestedConflictOf(t, name, relation, mutation);
|
|
6269
6449
|
if (addVariantInOwnTable(t, {
|
|
6270
6450
|
relation,
|
|
6271
6451
|
relatedCollection
|
|
6272
6452
|
}, mutation, keys, () => void 0)) return;
|
|
6453
|
+
const variantValue = mutation.variant;
|
|
6273
6454
|
const rows = mutation.data.map((row) => parseCreateInput(t, related, row, relatedCollection));
|
|
6274
|
-
|
|
6275
|
-
|
|
6455
|
+
const values = rows.map((row) => createRowOf(context, related, variantValue, row.scalarData, void 0));
|
|
6456
|
+
const nested = conflictOf(t, related, name, targetColumns, resolved, rows, values, variantValue);
|
|
6457
|
+
if (nested !== void 0 && "link" in nested.conflict || rows.some((row) => row.relationMutations.length > 0)) {
|
|
6458
|
+
rows.forEach((row, index) => {
|
|
6459
|
+
insertWithRelations(t, related, row, {
|
|
6460
|
+
keysFromParent: keys,
|
|
6461
|
+
returns: "count",
|
|
6462
|
+
shape: allColumns,
|
|
6463
|
+
variantValue
|
|
6464
|
+
}, values[index], nested);
|
|
6465
|
+
});
|
|
6276
6466
|
return;
|
|
6277
6467
|
}
|
|
6278
|
-
|
|
6468
|
+
insertRows(t, related, values, {
|
|
6469
|
+
conflict: nested?.conflict,
|
|
6470
|
+
keys,
|
|
6471
|
+
requires: [],
|
|
6472
|
+
owner: {
|
|
6473
|
+
operation: "create",
|
|
6474
|
+
modelName: related.modelName
|
|
6475
|
+
},
|
|
6476
|
+
returns: "count",
|
|
6477
|
+
shape: allColumns,
|
|
6478
|
+
afterWrite: void 0
|
|
6479
|
+
});
|
|
6279
6480
|
return;
|
|
6280
6481
|
}
|
|
6281
6482
|
if (mutation.kind === "connect") {
|
|
@@ -6297,9 +6498,13 @@ function addChildOwned(t, model, parent, { name, relation, relatedCollection },
|
|
|
6297
6498
|
});
|
|
6298
6499
|
return;
|
|
6299
6500
|
}
|
|
6501
|
+
rejectNullOnRequiredKey(contract, mutation.kind, name, {
|
|
6502
|
+
namespaceId: relation.toNamespace,
|
|
6503
|
+
modelName: relation.to
|
|
6504
|
+
}, relation.on.targetFields);
|
|
6300
6505
|
const unlink = Object.fromEntries(targetColumns.map((column) => [column, null]));
|
|
6301
|
-
const criteria = mutation
|
|
6302
|
-
const wheres = criteria
|
|
6506
|
+
const { criteria } = mutation;
|
|
6507
|
+
const wheres = criteria === void 0 ? [variantWhere(contract, mutation.state, void 0)] : criteria.map((criterion) => requiredCriterion(context, related, name, mutation, criterion));
|
|
6303
6508
|
for (const where of wheres) updateRows(t, related, unlink, {
|
|
6304
6509
|
where,
|
|
6305
6510
|
filters: [{
|
|
@@ -6355,11 +6560,13 @@ function addJunctionOwned(t, model, parent, { name, relation, relatedCollection
|
|
|
6355
6560
|
});
|
|
6356
6561
|
};
|
|
6357
6562
|
if (mutation.kind === "create") {
|
|
6563
|
+
const resolved = nestedConflictOf(t, name, relation, mutation);
|
|
6358
6564
|
if (addVariantInOwnTable(t, {
|
|
6359
6565
|
relation,
|
|
6360
6566
|
relatedCollection
|
|
6361
6567
|
}, mutation, [], (base) => addLink(base, void 0))) return;
|
|
6362
|
-
|
|
6568
|
+
const conflict = resolved === void 0 ? void 0 : linkKeyConflict(contract, relation);
|
|
6569
|
+
addLinkedCreates(t, related, name, relatedCollection, mutation, resolved, mutation.data, (created) => addLink(created, conflict));
|
|
6363
6570
|
return;
|
|
6364
6571
|
}
|
|
6365
6572
|
if (mutation.kind === "connect") {
|
|
@@ -6371,7 +6578,7 @@ function addJunctionOwned(t, model, parent, { name, relation, relatedCollection
|
|
|
6371
6578
|
return;
|
|
6372
6579
|
}
|
|
6373
6580
|
const criteria = mutation.criteria ?? [];
|
|
6374
|
-
if (criteria.length === 0) throw ormError("ORM.
|
|
6581
|
+
if (criteria.length === 0) throw ormError("ORM.ARGUMENT_INVALID", `disconnect() nested mutation for relation "${name}" requires criterion`, { meta: {
|
|
6375
6582
|
kind: "disconnect",
|
|
6376
6583
|
relation: name,
|
|
6377
6584
|
problem: "missing-criterion"
|
|
@@ -6408,7 +6615,7 @@ function addFilteredWrite(t, model, parent, name, relation, mutation) {
|
|
|
6408
6615
|
}
|
|
6409
6616
|
const set = updateValuesOf(related, mutation.data);
|
|
6410
6617
|
const linking = (relation.through === void 0 ? relation.on.targetFields : []).filter((field) => Object.hasOwn(set, columnOfContractField(t.context.contract, relation.toNamespace, relation.to, field)));
|
|
6411
|
-
if (linking.length > 0) throw ormError("ORM.
|
|
6618
|
+
if (linking.length > 0) throw ormError("ORM.ARGUMENT_INVALID", `updateAll() nested mutation for relation "${name}" cannot set ${linking.map((field) => `"${field}"`).join(", ")}, which links the related rows to their parent`, { meta: {
|
|
6412
6619
|
kind: "updateAll",
|
|
6413
6620
|
relation: name,
|
|
6414
6621
|
problem: "parent-link-column",
|
|
@@ -6440,19 +6647,79 @@ function sourcesOf(contract, model, relation, { root, scope }, parent) {
|
|
|
6440
6647
|
}]
|
|
6441
6648
|
};
|
|
6442
6649
|
}
|
|
6443
|
-
function
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
|
|
6449
|
-
|
|
6450
|
-
|
|
6650
|
+
function rejectParentHeldInConflictRow(name, onConflict, { relationMutations }) {
|
|
6651
|
+
for (const { name: nested, mutations } of partitionByOwnership(relationMutations).parentOwned) {
|
|
6652
|
+
const mutation = mutations.find(({ kind }) => kind === "create" || kind === "connect");
|
|
6653
|
+
if (mutation === void 0) continue;
|
|
6654
|
+
throw ormError("ORM.OPERATION_UNSUPPORTED", `create() nested mutation for relation "${name}" cannot take a callback on relation "${nested}" in a row with onConflict "${onConflict}", because the foreign key of "${nested}" is on the row and the callback would write before the database decides whether the row conflicts`, { meta: {
|
|
6655
|
+
kind: "create",
|
|
6656
|
+
relation: name,
|
|
6657
|
+
reason: "parent-held-relation-in-conflict-row",
|
|
6658
|
+
nestedRelation: nested,
|
|
6659
|
+
nestedKind: mutation.kind
|
|
6660
|
+
} });
|
|
6661
|
+
}
|
|
6662
|
+
}
|
|
6663
|
+
function nestedCall(name, modelName) {
|
|
6664
|
+
return {
|
|
6665
|
+
action: `create() nested mutation for relation "${name}"`,
|
|
6666
|
+
modelName,
|
|
6667
|
+
meta: {
|
|
6668
|
+
kind: "create",
|
|
6669
|
+
relation: name
|
|
6670
|
+
}
|
|
6671
|
+
};
|
|
6672
|
+
}
|
|
6673
|
+
function nestedConflictOf(t, name, relation, { options, variant }) {
|
|
6674
|
+
if (options === void 0) return;
|
|
6675
|
+
const { contract } = t.context;
|
|
6676
|
+
const resolved = resolveConflict(contract, nestedCall(name, relation.to), relation.toNamespace, options, ["skip", "connect"], variantTargetOf(contract, relation, variant));
|
|
6677
|
+
if (resolved.onConflict === "skip") {
|
|
6678
|
+
const reason = hasThrough(relation) ? "many-to-many-relation" : relation.cardinality === "N:1" || relation.cardinality === "1:1" ? "to-one-relation" : void 0;
|
|
6679
|
+
if (reason !== void 0) throw ormError("ORM.OPERATION_UNSUPPORTED", `create() nested mutation for relation "${name}" supports onConflict "skip" only on one-to-many relations`, { meta: {
|
|
6680
|
+
kind: "create",
|
|
6681
|
+
relation: name,
|
|
6682
|
+
reason
|
|
6683
|
+
} });
|
|
6684
|
+
}
|
|
6685
|
+
return resolved;
|
|
6686
|
+
}
|
|
6687
|
+
function variantTargetOf(contract, relation, variantValue) {
|
|
6688
|
+
if (variantValue !== void 0) return variantInOwnTableOf(contract, relation.toNamespace, relation.to, variantValue);
|
|
6689
|
+
const base = modelOf$1(contract, relation.toNamespace, relation.to)?.base;
|
|
6690
|
+
if (base === void 0) return;
|
|
6691
|
+
const value = [...resolvePolymorphismInfo(contract, base.namespace, base.model)?.variants.values() ?? []].find((variant) => variant.modelName === relation.to && variant.namespaceId === relation.toNamespace)?.value;
|
|
6692
|
+
return variantInOwnTableOf(contract, base.namespace, base.model, value);
|
|
6693
|
+
}
|
|
6694
|
+
function conflictOf(t, model, name, parentLinkColumns, resolved, rows, values, variantValue) {
|
|
6695
|
+
if (resolved === void 0) return;
|
|
6696
|
+
const { context } = t;
|
|
6697
|
+
const { contract } = context;
|
|
6698
|
+
const call = nestedCall(name, model.modelName);
|
|
6699
|
+
for (const row of rows) rejectParentHeldInConflictRow(name, resolved.onConflict, row);
|
|
6700
|
+
const [connectColumns = []] = requireRowsThatCanConflict(contract, call, model.tables.root.storage, resolved, values, () => parentLinkColumns);
|
|
6701
|
+
if (resolved.onConflict === "skip") return {
|
|
6702
|
+
conflict: { columns: resolved.columns },
|
|
6703
|
+
relation: name
|
|
6704
|
+
};
|
|
6705
|
+
const targeted = hasContractCapability(contract, "insertOnConflictTarget");
|
|
6706
|
+
if (!targeted) for (const value of values) requireOnlyCollidingKey(context, model, value, connectColumns, call.action);
|
|
6707
|
+
return {
|
|
6708
|
+
conflict: {
|
|
6709
|
+
columns: connectColumns,
|
|
6710
|
+
targeted,
|
|
6711
|
+
link: parentLinkColumns,
|
|
6712
|
+
guard: variantGuardOf(contract, model, variantValue)
|
|
6451
6713
|
},
|
|
6452
|
-
|
|
6453
|
-
|
|
6454
|
-
|
|
6455
|
-
|
|
6714
|
+
relation: name
|
|
6715
|
+
};
|
|
6716
|
+
}
|
|
6717
|
+
function variantGuardOf(contract, { namespaceId, modelName }, variantValue) {
|
|
6718
|
+
const discriminator = variantValue === void 0 ? void 0 : resolvePolymorphismInfo(contract, namespaceId, modelName)?.discriminatorColumn;
|
|
6719
|
+
return discriminator === void 0 || variantValue === void 0 ? void 0 : {
|
|
6720
|
+
column: discriminator,
|
|
6721
|
+
value: variantValue
|
|
6722
|
+
};
|
|
6456
6723
|
}
|
|
6457
6724
|
function addFindAndAssert(t, { name, relation }, mutation, criterion, columns) {
|
|
6458
6725
|
const { graph, context } = t;
|
|
@@ -6482,7 +6749,7 @@ function addFindAndAssert(t, { name, relation }, mutation, criterion, columns) {
|
|
|
6482
6749
|
}
|
|
6483
6750
|
function requiredCriterion(context, model, name, { kind, state: variant }, criterion) {
|
|
6484
6751
|
const where = criterionWhere(context, model, criterion);
|
|
6485
|
-
if (where === void 0) throw ormError("ORM.
|
|
6752
|
+
if (where === void 0) throw ormError("ORM.ARGUMENT_INVALID", `${kind}() nested mutation for relation "${name}" requires non-empty criterion`, { meta: {
|
|
6486
6753
|
kind,
|
|
6487
6754
|
relation: name,
|
|
6488
6755
|
problem: "empty-criterion"
|
|
@@ -6640,7 +6907,8 @@ function updateFirstGraph(collection, data, relationMutations = []) {
|
|
|
6640
6907
|
const model = modelOf(collection);
|
|
6641
6908
|
const t = {
|
|
6642
6909
|
...b,
|
|
6643
|
-
parentRow: find
|
|
6910
|
+
parentRow: find,
|
|
6911
|
+
parentValues: set
|
|
6644
6912
|
};
|
|
6645
6913
|
const before = addBeforeWrite(t, model, relationMutations);
|
|
6646
6914
|
const values = withUpdateDefaults(collection, set, before);
|
|
@@ -6650,7 +6918,7 @@ function updateFirstGraph(collection, data, relationMutations = []) {
|
|
|
6650
6918
|
};
|
|
6651
6919
|
if (Object.keys(values).length === 0 && before.keys.length === 0) {
|
|
6652
6920
|
addAfterWrite(t, model, find, relationMutations);
|
|
6653
|
-
b.graph.setResult(state.includes.length === 0 ? find : readBack(b, model, find, identityColumnsOf(collection), {
|
|
6921
|
+
b.graph.setResult(state.includes.length === 0 && !before.unlinksAfterWrite ? find : readBack(b, model, find, identityColumnsOf(collection), {
|
|
6654
6922
|
shape: shapeOf(collection),
|
|
6655
6923
|
by: "filter",
|
|
6656
6924
|
owner
|
|
@@ -6694,6 +6962,21 @@ function createAllGraph(collection, data, conflict, returns) {
|
|
|
6694
6962
|
const b = builderOf(collection);
|
|
6695
6963
|
if (data.length === 0) return b.graph;
|
|
6696
6964
|
const rows = createRowsOf(collection, data);
|
|
6965
|
+
if (conflict !== void 0) {
|
|
6966
|
+
const method = returns === "rows" ? "createAll()" : "createAndCount()";
|
|
6967
|
+
const { modelName, state } = collection;
|
|
6968
|
+
requireRowsThatCanConflict(collection.context.contract, {
|
|
6969
|
+
action: method,
|
|
6970
|
+
modelName,
|
|
6971
|
+
meta: {
|
|
6972
|
+
method,
|
|
6973
|
+
model: modelName
|
|
6974
|
+
}
|
|
6975
|
+
}, state.tables.root.storage, {
|
|
6976
|
+
onConflict: "skip",
|
|
6977
|
+
columns: conflict.columns
|
|
6978
|
+
}, rows, () => []);
|
|
6979
|
+
}
|
|
6697
6980
|
if (returns === "rows") requireIdentityColumnsForIncludes(collection);
|
|
6698
6981
|
b.graph.setResult(insertRows(b, modelOf(collection), rows, {
|
|
6699
6982
|
conflict,
|
|
@@ -6714,7 +6997,8 @@ function createGraph(collection, parsed) {
|
|
|
6714
6997
|
requireIdentityColumnsForIncludes(collection);
|
|
6715
6998
|
b.graph.setResult(addCreateWithRelations({
|
|
6716
6999
|
...b,
|
|
6717
|
-
parentRow: void 0
|
|
7000
|
+
parentRow: void 0,
|
|
7001
|
+
parentValues: {}
|
|
6718
7002
|
}, modelOf(collection), parsed, {
|
|
6719
7003
|
keysFromParent: [],
|
|
6720
7004
|
returns: "rows",
|
|
@@ -6782,7 +7066,7 @@ function upsertGraph(collection, createData, updateData, conflictColumns) {
|
|
|
6782
7066
|
const b = builderOf(collection);
|
|
6783
7067
|
requireIdentityColumnsForIncludes(collection);
|
|
6784
7068
|
const targeted = hasContractCapability(contract, "insertOnConflictTarget");
|
|
6785
|
-
if (!targeted) requireOnlyCollidingKey(collection, create, conflictColumns);
|
|
7069
|
+
if (!targeted) requireOnlyCollidingKey(context, modelOf(collection), create, conflictColumns, "upsert()");
|
|
6786
7070
|
const updateSet = Object.keys(update).length > 0 ? updateAssignments(contract, root, update) : Object.fromEntries(conflictColumns.slice(0, 1).map((column) => [column, ColumnRef.of("excluded", column)]));
|
|
6787
7071
|
const owner = {
|
|
6788
7072
|
operation: "upsert",
|
|
@@ -6820,17 +7104,16 @@ function identityProjection(collection) {
|
|
|
6820
7104
|
return projectTableColumns(context.contract, state.tables.root, identityColumnsOf(collection));
|
|
6821
7105
|
}
|
|
6822
7106
|
/**
|
|
6823
|
-
* Without capability `insertOnConflictTarget`, the database's conflict clause fires on any unique key, so
|
|
7107
|
+
* Without capability `insertOnConflictTarget`, the database's conflict clause fires on any unique key, so a write that updates on conflict is allowed only when the named columns are the only key the create values can collide on: every other primary key or unique constraint contains an auto-increment column the create values leave out.
|
|
6824
7108
|
*/
|
|
6825
|
-
function requireOnlyCollidingKey(
|
|
6826
|
-
const {
|
|
6827
|
-
const { namespaceId, tableName } = state.tables.root.storage;
|
|
7109
|
+
function requireOnlyCollidingKey(context, { modelName, tables }, create, conflictColumns, action) {
|
|
7110
|
+
const { namespaceId, tableName } = tables.root.storage;
|
|
6828
7111
|
const named = new Set(conflictColumns);
|
|
6829
7112
|
const colliding = resolveUniqueKeyColumnSets(context.contract, namespaceId, tableName).find((columns) => !(columns.length === named.size && columns.every((column) => named.has(column))) && !columns.some((column) => create[column] === void 0 && isAutoIncrementColumn(context.contract, namespaceId, tableName, column)));
|
|
6830
7113
|
if (colliding === void 0) return;
|
|
6831
|
-
throw ormError("ORM.CAPABILITY_MISSING",
|
|
7114
|
+
throw ormError("ORM.CAPABILITY_MISSING", `${action} on model "${modelName}" requires contract capability "insertOnConflictTarget": without it the conflict clause applies to every unique key, and the create values can also collide on (${colliding.join(", ")}), which would update a row other than the one conflictOn names.`, { meta: {
|
|
6832
7115
|
capability: "insertOnConflictTarget",
|
|
6833
|
-
action
|
|
7116
|
+
action
|
|
6834
7117
|
} });
|
|
6835
7118
|
}
|
|
6836
7119
|
/** Refuses includes on a table with no identity, by which a write reads its rows back. */
|
|
@@ -6885,7 +7168,11 @@ function identityColumnsOf(collection) {
|
|
|
6885
7168
|
return resolveRowIdentityColumns(collection.context.contract, namespaceId, tableName);
|
|
6886
7169
|
}
|
|
6887
7170
|
function sameRowColumns(collection) {
|
|
6888
|
-
return
|
|
7171
|
+
return sameRowColumnsOf(collection.context.contract, collection.state.tables.root);
|
|
7172
|
+
}
|
|
7173
|
+
function sameRowColumnsOf(contract, root) {
|
|
7174
|
+
const { namespaceId, tableName } = root.storage;
|
|
7175
|
+
return sameColumns(projectTableColumns(contract, root, resolveRowIdentityColumns(contract, namespaceId, tableName)));
|
|
6889
7176
|
}
|
|
6890
7177
|
function whereOf(collection) {
|
|
6891
7178
|
const { context, state } = collection;
|
|
@@ -6917,25 +7204,9 @@ function returnCallerColumns(graph, callerRows) {
|
|
|
6917
7204
|
async function runAllNodes(graph, ctx, callerRows) {
|
|
6918
7205
|
checkNodes(graph, ctx);
|
|
6919
7206
|
const { runtime } = ctx;
|
|
6920
|
-
if (statementCount(graph) > 1 && graph.writesAnyTable && runtime.transaction !== void 0) return
|
|
7207
|
+
if (statementCount(graph) > 1 && graph.writesAnyTable && runtime.transaction !== void 0) return runtime.transaction((tx) => runNodesInOrder(graph, ctx, tx, callerRows), ctx.implicitTransactionOptions);
|
|
6921
7208
|
return runNodesInOrder(graph, ctx, runtime, callerRows);
|
|
6922
7209
|
}
|
|
6923
|
-
async function runInTransaction(transaction, run) {
|
|
6924
|
-
try {
|
|
6925
|
-
const result = await run(transaction);
|
|
6926
|
-
await transaction.commit();
|
|
6927
|
-
return result;
|
|
6928
|
-
} catch (error) {
|
|
6929
|
-
try {
|
|
6930
|
-
await transaction.rollback();
|
|
6931
|
-
} catch (rollbackError) {
|
|
6932
|
-
const settlement = settlementOf(transaction);
|
|
6933
|
-
if (settlement?.rolledBack !== true) throw rollbackError;
|
|
6934
|
-
settlement.logDroppedError(rollbackError);
|
|
6935
|
-
}
|
|
6936
|
-
throw error;
|
|
6937
|
-
}
|
|
6938
|
-
}
|
|
6939
7210
|
async function runNodesInOrder(graph, ctx, scope, callerRows) {
|
|
6940
7211
|
const run = runOn(ctx, scope);
|
|
6941
7212
|
const collected = [];
|
|
@@ -7703,22 +7974,21 @@ var CollectionBase = class CollectionBase {
|
|
|
7703
7974
|
}
|
|
7704
7975
|
#resolveConflictSkip(options, method) {
|
|
7705
7976
|
if (options === void 0) return void 0;
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7977
|
+
const createAll = method === "createAll()";
|
|
7978
|
+
if (!createAll) this.#assertNotMtiVariant(method);
|
|
7979
|
+
const { columns } = resolveConflict(this.contract, {
|
|
7980
|
+
action: method,
|
|
7981
|
+
modelName: this.modelName,
|
|
7982
|
+
meta: {
|
|
7983
|
+
method,
|
|
7984
|
+
model: this.modelName
|
|
7985
|
+
}
|
|
7986
|
+
}, this.namespaceId, options, ["skip"], createAll ? variantInOwnTableOf(this.contract, this.namespaceId, this.modelName, this.state.variantValue) : void 0);
|
|
7987
|
+
return { columns };
|
|
7715
7988
|
}
|
|
7716
7989
|
#assertNotMtiVariant(method) {
|
|
7717
7990
|
this.#refuseOnMtiVariant(method, `${method} is not supported for MTI variant "${this.#variantModelName()}" on model "${this.modelName}". Use createAll() instead.`);
|
|
7718
7991
|
}
|
|
7719
|
-
#assertConflictSkipNotOnMtiVariant(method) {
|
|
7720
|
-
this.#refuseOnMtiVariant(method, `The onConflict option is not supported on variant "${this.#variantModelName()}" of model "${this.modelName}" because the variant is stored in its own table. Call createAll(rows) without the option; a duplicate row then makes the call fail.`);
|
|
7721
|
-
}
|
|
7722
7992
|
#refuseOnMtiVariant(method, message) {
|
|
7723
7993
|
if (!mtiCreateContextOf(this.#descriptionOptions())) return;
|
|
7724
7994
|
throw ormError("ORM.OPERATION_UNSUPPORTED", message, { meta: {
|