@prisma/orm-family-sql 8.0.0-rc.16-dev.1 → 8.0.0-rc.16-dev.3
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/{ast-DFvrXEbF.mjs → ast-B_UPqRyb.mjs} +29 -2
- package/dist/ast-B_UPqRyb.mjs.map +1 -0
- package/dist/{ast-fsQdXFSV.d.mts → ast-Bf6J9_ra.d.mts} +83 -3
- package/dist/ast-Bf6J9_ra.d.mts.map +1 -0
- package/dist/builder.d.mts +1 -1
- package/dist/builder__runtime.d.mts +2 -2
- package/dist/builder__runtime.mjs +17 -16
- package/dist/builder__runtime.mjs.map +1 -1
- package/dist/builder__types.d.mts +1 -1
- package/dist/{control-Bi2JsNep.d.mts → control-DCt08EpW.d.mts} +4 -4
- package/dist/{control-Bi2JsNep.d.mts.map → control-DCt08EpW.d.mts.map} +1 -1
- package/dist/control-adapter-CD_gz6TI.d.mts +1 -0
- package/dist/{control-adapter-CkFfBVei-gLS9b87G.d.mts → control-adapter-CkFfBVei-Ba9JNrCN.d.mts} +2 -2
- package/dist/{control-adapter-CkFfBVei-gLS9b87G.d.mts.map → control-adapter-CkFfBVei-Ba9JNrCN.d.mts.map} +1 -1
- package/dist/{db-CJxU3aL_-CM2IReAK.d.mts → db-D7R5zKiH-SEM04lcK.d.mts} +9 -47
- package/dist/{db-CJxU3aL_-CM2IReAK.d.mts.map → db-D7R5zKiH-SEM04lcK.d.mts.map} +1 -1
- package/dist/{diff-Bg9o9CgK.d.mts → diff-3tfqwWS7.d.mts} +3 -3
- package/dist/{diff-Bg9o9CgK.d.mts.map → diff-3tfqwWS7.d.mts.map} +1 -1
- package/dist/family.d.mts +6 -6
- package/dist/family__control-adapter.d.mts +2 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__diff.d.mts +2 -2
- package/dist/family__migration.d.mts +1 -1
- package/dist/{index-Z2FIIMxv.d.mts → index-DYjWQAcJ.d.mts} +3 -3
- package/dist/{index-Z2FIIMxv.d.mts.map → index-DYjWQAcJ.d.mts.map} +1 -1
- package/dist/{migration-o-g1rSb-.d.mts → migration-D6NJlA6-.d.mts} +2 -2
- package/dist/{migration-o-g1rSb-.d.mts.map → migration-D6NJlA6-.d.mts.map} +1 -1
- package/dist/orm-client.d.mts +41 -11
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +101 -6
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{prepared-statement-YtgdlN7e-BU4UQxB5.d.mts → prepared-statement-YtgdlN7e-DBJtJAm7.d.mts} +2 -2
- package/dist/{prepared-statement-YtgdlN7e-BU4UQxB5.d.mts.map → prepared-statement-YtgdlN7e-DBJtJAm7.d.mts.map} +1 -1
- package/dist/relational-core.d.mts +2 -2
- package/dist/relational-core.mjs +2 -2
- package/dist/relational-core__ast.d.mts +2 -2
- package/dist/relational-core__ast.mjs +2 -2
- package/dist/runtime.d.mts +3 -3
- package/dist/runtime__internal__prepared-query.d.mts +1 -1
- package/dist/{types-CvuS68sy-Dip2oI3M.d.mts → types-CvuS68sy-ReNXbgpE.d.mts} +2 -2
- package/dist/{types-CvuS68sy-Dip2oI3M.d.mts.map → types-CvuS68sy-ReNXbgpE.d.mts.map} +1 -1
- package/package.json +18 -18
- package/dist/ast-DFvrXEbF.mjs.map +0 -1
- package/dist/ast-fsQdXFSV.d.mts.map +0 -1
- package/dist/control-adapter-Ciule8Fh.d.mts +0 -1
package/dist/orm-client.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as resolveStorageTable } from "./resolve-storage-table-DZsfnzeW.mjs";
|
|
2
2
|
import { i as isUniqueConstraintViolation } from "./dist-x6jvtkKM.mjs";
|
|
3
|
-
import { A as ParamRef, C as LiteralExpr, E as NullCheckExpr, F as SelectAst, G as isOrderByNulls, I as SubqueryExpr, L as TableSource, M as ProjectionItem, O as OrExpr, R as UpdateAst, S as ListExpression, T as NotExpr, U as isAggregateFn, V as checkLimitOffset, W as isOrderByDirection, _ 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, q as isWhereExpr, r as BinaryExpr, s as DefaultValueExpr, t as AggregateExpr, v as InsertOnConflict, x as JsonObjectExpr, y as JoinAst, z as WindowFuncExpr } from "./types-NTQsD2MS-DAP2yVDn.mjs";
|
|
3
|
+
import { A as ParamRef, C as LiteralExpr, E as NullCheckExpr, F as SelectAst, G as isOrderByNulls, I as SubqueryExpr, L as TableSource, M as ProjectionItem, O as OrExpr, R as UpdateAst, S as ListExpression, T as NotExpr, U as isAggregateFn, V as checkLimitOffset, W as isOrderByDirection, _ 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, q as isWhereExpr, 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-NTQsD2MS-DAP2yVDn.mjs";
|
|
4
4
|
import { t as collectOrderedParamRefs } from "./util-BBgcP3gI-XJBkxo1K.mjs";
|
|
5
|
-
import { n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection } from "./ast-
|
|
5
|
+
import { C as lockStrengthCapabilities, S as lockOptionCapabilities, T as missingCapability, n as JsonDocumentProjection, r as NativeJsonValueProjection, t as CodecJsonValueProjection, w as lockWaitPolicyOf, x as lockIncompatible } from "./ast-B_UPqRyb.mjs";
|
|
6
6
|
import { i as isExpression, o as toExpr } from "./expression-JOe6lo4g.mjs";
|
|
7
7
|
import { n as codecRefForStorageColumn } from "./codec-descriptor-registry-DoGFktu5.mjs";
|
|
8
8
|
import { structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
@@ -371,6 +371,14 @@ function assertDistinctOnCapability(contract, methodName) {
|
|
|
371
371
|
method: methodName
|
|
372
372
|
} });
|
|
373
373
|
}
|
|
374
|
+
function assertLockCapability(contract, requirement, methodName) {
|
|
375
|
+
const capability = missingCapability(contract.capabilities, requirement);
|
|
376
|
+
if (capability === void 0) return;
|
|
377
|
+
throw ormError("ORM.CAPABILITY_MISSING", `${methodName}() requires capability ${capability}`, { meta: {
|
|
378
|
+
capability,
|
|
379
|
+
method: methodName
|
|
380
|
+
} });
|
|
381
|
+
}
|
|
374
382
|
function hasContractCapability(contract, capability) {
|
|
375
383
|
const capabilities = contract.capabilities;
|
|
376
384
|
const value = capabilities[capability];
|
|
@@ -1039,6 +1047,7 @@ function emptyState() {
|
|
|
1039
1047
|
limit: void 0,
|
|
1040
1048
|
offset: void 0,
|
|
1041
1049
|
variantName: void 0,
|
|
1050
|
+
locking: void 0,
|
|
1042
1051
|
annotations: /* @__PURE__ */ new Map()
|
|
1043
1052
|
};
|
|
1044
1053
|
}
|
|
@@ -1464,6 +1473,29 @@ function compileDeleteCount(contract, namespaceId, tableName, filters, variantNa
|
|
|
1464
1473
|
const { params } = deriveParamsFromAst(ast);
|
|
1465
1474
|
return buildOrmQueryPlan(contract, ast, params);
|
|
1466
1475
|
}
|
|
1476
|
+
function includeCarriesLock(include) {
|
|
1477
|
+
return [
|
|
1478
|
+
include.nested,
|
|
1479
|
+
...include.scalar === void 0 ? [] : [include.scalar.state],
|
|
1480
|
+
...Object.values(include.combine ?? {}).map((branch) => branch.kind === "rows" ? branch.state : branch.selector.state)
|
|
1481
|
+
].some(stateCarriesLock);
|
|
1482
|
+
}
|
|
1483
|
+
function stateCarriesLock(state) {
|
|
1484
|
+
return state.locking !== void 0 || state.includes.some(includeCarriesLock);
|
|
1485
|
+
}
|
|
1486
|
+
function conflictOf(state, call) {
|
|
1487
|
+
if (state.includes.some(includeCarriesLock)) return "includeRefinement";
|
|
1488
|
+
if (state.locking === void 0) return void 0;
|
|
1489
|
+
if (call !== void 0) return call;
|
|
1490
|
+
if (state.includes.length > 0) return "include";
|
|
1491
|
+
if (state.distinct !== void 0 && state.distinct.length > 0) return "distinct";
|
|
1492
|
+
if (state.distinctOn !== void 0 && state.distinctOn.length > 0) return "distinctOn";
|
|
1493
|
+
}
|
|
1494
|
+
/** 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. */
|
|
1495
|
+
function assertLockCompatible(state, call) {
|
|
1496
|
+
const conflict = conflictOf(state, call);
|
|
1497
|
+
if (conflict !== void 0) throw lockIncompatible(conflict, `A locking clause cannot be combined with ${conflict}`);
|
|
1498
|
+
}
|
|
1467
1499
|
function augmentSelectionForJoinColumns(selectedFields, requiredColumns) {
|
|
1468
1500
|
if (!selectedFields) return {
|
|
1469
1501
|
selectedForQuery: selectedFields,
|
|
@@ -2047,9 +2079,11 @@ function buildSelectAst(contract, tableName, state, options) {
|
|
|
2047
2079
|
if (state.limit !== void 0) ast = ast.withLimit(state.limit);
|
|
2048
2080
|
if (state.offset !== void 0) ast = ast.withOffset(state.offset);
|
|
2049
2081
|
if (options.joins && options.joins.length > 0) ast = ast.withJoins(options.joins);
|
|
2082
|
+
if (state.locking !== void 0) ast = ast.withLocking(state.locking);
|
|
2050
2083
|
return ast;
|
|
2051
2084
|
}
|
|
2052
2085
|
function compileSelect(contract, namespaceId, tableName, state, modelName) {
|
|
2086
|
+
assertLockCompatible(state);
|
|
2053
2087
|
if (state.distinctOn !== void 0 && state.distinctOn.length > 0) assertDistinctOnCapability(contract, "distinctOn");
|
|
2054
2088
|
const polyInfo = modelName ? resolvePolymorphismInfo(contract, namespaceId, modelName) : void 0;
|
|
2055
2089
|
const selection = polyInfo && modelName ? resolvePolymorphicProjectionSelection(contract, namespaceId, modelName, polyInfo, state) : void 0;
|
|
@@ -2071,6 +2105,7 @@ function compileSelect(contract, namespaceId, tableName, state, modelName) {
|
|
|
2071
2105
|
return buildOrmQueryPlan(contract, ast, params, state.annotations);
|
|
2072
2106
|
}
|
|
2073
2107
|
function compileSelectWithIncludes(contract, aggregates, namespaceId, tableName, state, modelName) {
|
|
2108
|
+
assertLockCompatible(state);
|
|
2074
2109
|
const includeJoins = [];
|
|
2075
2110
|
const includeProjection = [];
|
|
2076
2111
|
const topLevelWhere = buildStateWhere(contract, tableName, state, { namespaceId });
|
|
@@ -3914,7 +3949,7 @@ function isModelCollection(value) {
|
|
|
3914
3949
|
function assertScopeReceiver(value) {
|
|
3915
3950
|
if (!isModelCollection(value)) throw ormError("ORM.ARGUMENT_INVALID", "Cannot apply the scope: it was not given a collection", {
|
|
3916
3951
|
why: `A scope is applied to a collection, such as db.orm.public.Post; received ${describeReceived(value)}.`,
|
|
3917
|
-
fix: "
|
|
3952
|
+
fix: "Pass the scope to with on a collection: collection.with(scope).",
|
|
3918
3953
|
meta: { argument: "collection" }
|
|
3919
3954
|
});
|
|
3920
3955
|
}
|
|
@@ -4183,7 +4218,7 @@ function listed(items, conjunction) {
|
|
|
4183
4218
|
const last = items.at(-1) ?? "";
|
|
4184
4219
|
return items.length > 1 ? `${items.slice(0, -1).join(", ")} ${conjunction} ${last}` : last;
|
|
4185
4220
|
}
|
|
4186
|
-
const HIDDEN_BY_A_SCOPE = "A scope
|
|
4221
|
+
const HIDDEN_BY_A_SCOPE = "A scope passed to with can add one without showing it at the call site.";
|
|
4187
4222
|
/** Throws `ORM.ARGUMENT_INVALID` when the collection has a limit, an offset, a cursor or a distinct selection, which `method`, a write of every matching row, would ignore. */
|
|
4188
4223
|
function assertBulkWriteIgnoresNothing(state, modelName, method) {
|
|
4189
4224
|
const { nouns, calls } = presentParts(state, [
|
|
@@ -4354,7 +4389,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4354
4389
|
if (!filter) return blindCast(this);
|
|
4355
4390
|
return this.#cloneSelf({ filters: [...this.state.filters, filter] });
|
|
4356
4391
|
}
|
|
4357
|
-
|
|
4392
|
+
with(fn) {
|
|
4358
4393
|
return fn(this);
|
|
4359
4394
|
}
|
|
4360
4395
|
/**
|
|
@@ -4362,7 +4397,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4362
4397
|
*
|
|
4363
4398
|
* ```ts
|
|
4364
4399
|
* const summary = db.Post.scope((posts) => posts.select('id', 'title').include('user'));
|
|
4365
|
-
* db.User.include('posts', (posts) => posts.
|
|
4400
|
+
* db.User.include('posts', (posts) => posts.with(summary));
|
|
4366
4401
|
* ```
|
|
4367
4402
|
*/
|
|
4368
4403
|
scope(body) {
|
|
@@ -4475,6 +4510,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4475
4510
|
* ```
|
|
4476
4511
|
*/
|
|
4477
4512
|
groupBy(...fields) {
|
|
4513
|
+
assertLockCompatible(this.state, "groupBy");
|
|
4478
4514
|
const groupByColumns = mapFieldsToColumns(this.contract, this.namespaceId, this.modelName, fields);
|
|
4479
4515
|
return new GroupedCollection(this.ctx, this.modelName, {
|
|
4480
4516
|
tableName: this.tableName,
|
|
@@ -4551,6 +4587,42 @@ var CollectionBase = class CollectionBase {
|
|
|
4551
4587
|
distinctOn: distinctOnFields
|
|
4552
4588
|
});
|
|
4553
4589
|
}
|
|
4590
|
+
/**
|
|
4591
|
+
* Lock the selected rows of this model with `FOR UPDATE` until the transaction ends.
|
|
4592
|
+
*
|
|
4593
|
+
* Requires the `sql.forUpdate` and `sql.lockOf` capabilities, because the lock always names the model's table with `OF`.
|
|
4594
|
+
*
|
|
4595
|
+
* ```typescript
|
|
4596
|
+
* const job = await tx.orm.Job.where({ state: 'queued' }).limit(1).forUpdate({ skipLocked: true }).first();
|
|
4597
|
+
* ```
|
|
4598
|
+
*/
|
|
4599
|
+
forUpdate(...options) {
|
|
4600
|
+
return this.#lock("forUpdate", options[0]);
|
|
4601
|
+
}
|
|
4602
|
+
/**
|
|
4603
|
+
* Lock the selected rows of this model with `FOR NO KEY UPDATE` until the transaction ends. Unlike `forUpdate`, it does not block foreign-key checks from rows that reference them.
|
|
4604
|
+
*
|
|
4605
|
+
* Requires the `postgres.forNoKeyUpdate` and `sql.lockOf` capabilities, because the lock always names the model's table with `OF`.
|
|
4606
|
+
*/
|
|
4607
|
+
forNoKeyUpdate(...options) {
|
|
4608
|
+
return this.#lock("forNoKeyUpdate", options[0]);
|
|
4609
|
+
}
|
|
4610
|
+
/**
|
|
4611
|
+
* Lock the selected rows of this model with `FOR SHARE` until the transaction ends; other transactions may share-lock them but not write them.
|
|
4612
|
+
*
|
|
4613
|
+
* Requires the `sql.forShare` and `sql.lockOf` capabilities, because the lock always names the model's table with `OF`.
|
|
4614
|
+
*/
|
|
4615
|
+
forShare(...options) {
|
|
4616
|
+
return this.#lock("forShare", options[0]);
|
|
4617
|
+
}
|
|
4618
|
+
/**
|
|
4619
|
+
* Lock the selected rows of this model with `FOR KEY SHARE` until the transaction ends; only deletes and key changes are blocked.
|
|
4620
|
+
*
|
|
4621
|
+
* Requires the `postgres.forKeyShare` and `sql.lockOf` capabilities, because the lock always names the model's table with `OF`.
|
|
4622
|
+
*/
|
|
4623
|
+
forKeyShare(...options) {
|
|
4624
|
+
return this.#lock("forKeyShare", options[0]);
|
|
4625
|
+
}
|
|
4554
4626
|
limit(n) {
|
|
4555
4627
|
return this.#cloneSelf({ limit: typeof n === "number" ? n : toExpr(n) });
|
|
4556
4628
|
}
|
|
@@ -4612,6 +4684,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4612
4684
|
return description.consume(queryPlanRows(this.ctx.runtime, description.plan));
|
|
4613
4685
|
}
|
|
4614
4686
|
#describeAggregate(fn, configure) {
|
|
4687
|
+
assertLockCompatible(this.state, "aggregate");
|
|
4615
4688
|
const aggregateSpec = fn(createAggregateBuilder(this.contract, this.ctx.context.aggregateDescriptors, this.namespaceId, this.modelName));
|
|
4616
4689
|
const entries = Object.entries(aggregateSpec);
|
|
4617
4690
|
if (entries.length === 0) throw ormError("ORM.AGGREGATE_SELECTOR_MISSING", "aggregate() requires at least one aggregation selector", { meta: {
|
|
@@ -4651,6 +4724,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4651
4724
|
};
|
|
4652
4725
|
}
|
|
4653
4726
|
async create(data, configure) {
|
|
4727
|
+
assertLockCompatible(this.state, "mutation");
|
|
4654
4728
|
assertReturningCapability(this.contract, "create()");
|
|
4655
4729
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "create");
|
|
4656
4730
|
if (hasNestedMutationCallbacks(this.contract, this.namespaceId, this.modelName, blindCast(data))) {
|
|
@@ -4677,6 +4751,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4677
4751
|
} });
|
|
4678
4752
|
}
|
|
4679
4753
|
createAll(data, optionsOrConfigure, configure) {
|
|
4754
|
+
assertLockCompatible(this.state, "mutation");
|
|
4680
4755
|
const { options, configureCallback } = splitCreateArguments(optionsOrConfigure, configure);
|
|
4681
4756
|
const conflictSkip = this.#resolveConflictSkip(options, "createAll()");
|
|
4682
4757
|
return this.#createAllWithAnnotations(data, this.#collectAnnotationsFromMeta(configureCallback, "write", "createAll"), conflictSkip);
|
|
@@ -4878,6 +4953,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4878
4953
|
* Not supported on MTI variants — use `createAll(...)` instead.
|
|
4879
4954
|
*/
|
|
4880
4955
|
async createAndCount(data, optionsOrConfigure, configure) {
|
|
4956
|
+
assertLockCompatible(this.state, "mutation");
|
|
4881
4957
|
const { options, configureCallback } = splitCreateArguments(optionsOrConfigure, configure);
|
|
4882
4958
|
const conflictSkip = this.#resolveConflictSkip(options, "createAndCount()");
|
|
4883
4959
|
if (data.length === 0) return 0;
|
|
@@ -4899,6 +4975,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4899
4975
|
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
4900
4976
|
}
|
|
4901
4977
|
async upsert(input, configure) {
|
|
4978
|
+
assertLockCompatible(this.state, "mutation");
|
|
4902
4979
|
assertReturningCapability(this.contract, "upsert()");
|
|
4903
4980
|
this.#assertNotMtiVariant("upsert()");
|
|
4904
4981
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "upsert");
|
|
@@ -4941,6 +5018,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4941
5018
|
} });
|
|
4942
5019
|
}
|
|
4943
5020
|
async update(data, configure) {
|
|
5021
|
+
assertLockCompatible(this.state, "mutation");
|
|
4944
5022
|
assertReturningCapability(this.contract, "update()");
|
|
4945
5023
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "update");
|
|
4946
5024
|
if (hasNestedMutationCallbacks(this.contract, this.namespaceId, this.modelName, blindCast(data))) {
|
|
@@ -4966,6 +5044,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4966
5044
|
}
|
|
4967
5045
|
updateAll(data, configure) {
|
|
4968
5046
|
assertBulkWriteIgnoresNothing(this.state, this.modelName, "updateAll");
|
|
5047
|
+
assertLockCompatible(this.state, "mutation");
|
|
4969
5048
|
return this.#updateAllWithAnnotations(data, this.#collectAnnotationsFromMeta(configure, "write", "updateAll"));
|
|
4970
5049
|
}
|
|
4971
5050
|
#updateAllWithAnnotations(data, annotationsMap) {
|
|
@@ -4994,6 +5073,7 @@ var CollectionBase = class CollectionBase {
|
|
|
4994
5073
|
}
|
|
4995
5074
|
async updateAndCount(data, configure) {
|
|
4996
5075
|
assertBulkWriteIgnoresNothing(this.state, this.modelName, "updateAndCount");
|
|
5076
|
+
assertLockCompatible(this.state, "mutation");
|
|
4997
5077
|
const mappedData = mapModelDataToStorageRow(this.contract, this.namespaceId, this.modelName, data);
|
|
4998
5078
|
if (Object.keys(mappedData).length === 0) return 0;
|
|
4999
5079
|
applyUpdateDefaults(this.ctx, this.namespaceId, this.tableName, mappedData);
|
|
@@ -5002,6 +5082,7 @@ var CollectionBase = class CollectionBase {
|
|
|
5002
5082
|
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
5003
5083
|
}
|
|
5004
5084
|
async delete(configure) {
|
|
5085
|
+
assertLockCompatible(this.state, "mutation");
|
|
5005
5086
|
assertReturningCapability(this.contract, "delete()");
|
|
5006
5087
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "delete");
|
|
5007
5088
|
return withMutationScope(this.ctx.runtime, async (scope) => {
|
|
@@ -5017,6 +5098,7 @@ var CollectionBase = class CollectionBase {
|
|
|
5017
5098
|
}
|
|
5018
5099
|
deleteAll(configure) {
|
|
5019
5100
|
assertBulkWriteIgnoresNothing(this.state, this.modelName, "deleteAll");
|
|
5101
|
+
assertLockCompatible(this.state, "mutation");
|
|
5020
5102
|
return this.#deleteAllWithAnnotations(this.#collectAnnotationsFromMeta(configure, "write", "deleteAll"));
|
|
5021
5103
|
}
|
|
5022
5104
|
#deleteAllWithAnnotations(annotationsMap) {
|
|
@@ -5076,6 +5158,7 @@ var CollectionBase = class CollectionBase {
|
|
|
5076
5158
|
}
|
|
5077
5159
|
async deleteAndCount(configure) {
|
|
5078
5160
|
assertBulkWriteIgnoresNothing(this.state, this.modelName, "deleteAndCount");
|
|
5161
|
+
assertLockCompatible(this.state, "mutation");
|
|
5079
5162
|
const annotationsMap = this.#collectAnnotationsFromMeta(configure, "write", "deleteAndCount");
|
|
5080
5163
|
const compiled = mergeAnnotations(compileDeleteCount(this.contract, this.namespaceId, this.tableName, this.state.filters, this.state.variantName, this.modelName), annotationsMap);
|
|
5081
5164
|
return (await this.ctx.runtime.execute(compiled)).affectedRows;
|
|
@@ -5170,6 +5253,18 @@ var CollectionBase = class CollectionBase {
|
|
|
5170
5253
|
if (this.includeRefinementMode) return;
|
|
5171
5254
|
throw ormError("ORM.INCLUDE_INVALID", `${action} is only available inside include() refinement callbacks`, { meta: { action } });
|
|
5172
5255
|
}
|
|
5256
|
+
#lock(strength, options) {
|
|
5257
|
+
if (this.includeRefinementMode) throw lockIncompatible("includeRefinement", `${strength}() cannot be called inside an include() refinement callback`);
|
|
5258
|
+
assertLockCapability(this.contract, lockStrengthCapabilities[strength], strength);
|
|
5259
|
+
assertLockCapability(this.contract, lockOptionCapabilities.of, strength);
|
|
5260
|
+
const waitPolicy = lockWaitPolicyOf(strength, options);
|
|
5261
|
+
if (waitPolicy !== void 0) assertLockCapability(this.contract, lockOptionCapabilities[waitPolicy], strength);
|
|
5262
|
+
const clause = LockingClause.of(strength, {
|
|
5263
|
+
of: [this.tableName],
|
|
5264
|
+
...ifDefined("waitPolicy", waitPolicy)
|
|
5265
|
+
});
|
|
5266
|
+
return this.#clone({ locking: [...this.state.locking ?? [], clause] });
|
|
5267
|
+
}
|
|
5173
5268
|
#clone(overrides) {
|
|
5174
5269
|
return this.#createSelf({
|
|
5175
5270
|
...this.state,
|