@zenstackhq/runtime 3.0.0-alpha.4 → 3.0.0-alpha.6
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/client.cjs +266 -240
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -4
- package/dist/client.d.ts +2 -4
- package/dist/client.js +61 -36
- package/dist/client.js.map +1 -1
- package/dist/{contract-BBUC-uVq.d.cts → contract-DW8XGrtV.d.cts} +725 -697
- package/dist/{contract-BBUC-uVq.d.ts → contract-DW8XGrtV.d.ts} +725 -697
- package/dist/index.cjs +256 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +53 -35
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy.cjs +34 -45
- package/dist/plugins/policy.cjs.map +1 -1
- package/dist/plugins/policy.d.cts +2 -4
- package/dist/plugins/policy.d.ts +2 -4
- package/dist/plugins/policy.js +6 -7
- package/dist/plugins/policy.js.map +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.js.map +1 -1
- package/package.json +12 -14
package/dist/client.cjs
CHANGED
|
@@ -34,11 +34,13 @@ __export(client_exports, {
|
|
|
34
34
|
InternalError: () => InternalError,
|
|
35
35
|
NotFoundError: () => NotFoundError,
|
|
36
36
|
QueryError: () => QueryError,
|
|
37
|
-
ZenStackClient: () => ZenStackClient
|
|
37
|
+
ZenStackClient: () => ZenStackClient,
|
|
38
|
+
definePlugin: () => definePlugin
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(client_exports);
|
|
40
41
|
|
|
41
42
|
// src/client/client-impl.ts
|
|
43
|
+
var import_common_helpers12 = require("@zenstackhq/common-helpers");
|
|
42
44
|
var import_kysely16 = require("kysely");
|
|
43
45
|
var import_ts_pattern19 = require("ts-pattern");
|
|
44
46
|
|
|
@@ -313,9 +315,9 @@ __name(safeJSONStringify, "safeJSONStringify");
|
|
|
313
315
|
|
|
314
316
|
// src/client/crud/operations/base.ts
|
|
315
317
|
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
318
|
+
var import_common_helpers8 = require("@zenstackhq/common-helpers");
|
|
316
319
|
var import_kysely8 = require("kysely");
|
|
317
320
|
var import_nanoid = require("nanoid");
|
|
318
|
-
var import_tiny_invariant7 = __toESM(require("tiny-invariant"), 1);
|
|
319
321
|
var import_ts_pattern8 = require("ts-pattern");
|
|
320
322
|
var import_ulid = require("ulid");
|
|
321
323
|
var uuid = __toESM(require("uuid"), 1);
|
|
@@ -333,21 +335,21 @@ var RejectedByPolicyError = class extends Error {
|
|
|
333
335
|
};
|
|
334
336
|
|
|
335
337
|
// src/plugins/policy/policy-handler.ts
|
|
338
|
+
var import_common_helpers6 = require("@zenstackhq/common-helpers");
|
|
336
339
|
var import_kysely7 = require("kysely");
|
|
337
|
-
var import_tiny_invariant6 = __toESM(require("tiny-invariant"), 1);
|
|
338
340
|
var import_ts_pattern7 = require("ts-pattern");
|
|
339
341
|
|
|
340
342
|
// src/client/crud/dialects/index.ts
|
|
341
343
|
var import_ts_pattern4 = require("ts-pattern");
|
|
342
344
|
|
|
343
345
|
// src/client/crud/dialects/postgresql.ts
|
|
346
|
+
var import_common_helpers2 = require("@zenstackhq/common-helpers");
|
|
344
347
|
var import_kysely2 = require("kysely");
|
|
345
|
-
var import_tiny_invariant2 = __toESM(require("tiny-invariant"), 1);
|
|
346
348
|
var import_ts_pattern2 = require("ts-pattern");
|
|
347
349
|
|
|
348
350
|
// src/client/crud/dialects/base.ts
|
|
351
|
+
var import_common_helpers = require("@zenstackhq/common-helpers");
|
|
349
352
|
var import_kysely = require("kysely");
|
|
350
|
-
var import_tiny_invariant = __toESM(require("tiny-invariant"), 1);
|
|
351
353
|
var import_ts_pattern = require("ts-pattern");
|
|
352
354
|
|
|
353
355
|
// src/utils/enumerate.ts
|
|
@@ -365,7 +367,6 @@ function enumerate(x) {
|
|
|
365
367
|
__name(enumerate, "enumerate");
|
|
366
368
|
|
|
367
369
|
// src/client/crud/dialects/base.ts
|
|
368
|
-
var import_is_plain_object = require("is-plain-object");
|
|
369
370
|
var BaseCrudDialect = class {
|
|
370
371
|
static {
|
|
371
372
|
__name(this, "BaseCrudDialect");
|
|
@@ -563,7 +564,7 @@ var BaseCrudDialect = class {
|
|
|
563
564
|
return eb(lhs, "=", rhs !== null && rhs !== void 0 ? this.transformPrimitive(rhs, type) : rhs);
|
|
564
565
|
}
|
|
565
566
|
buildStandardFilter(eb, type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0) {
|
|
566
|
-
if (payload === null || !(0,
|
|
567
|
+
if (payload === null || !(0, import_common_helpers.isPlainObject)(payload)) {
|
|
567
568
|
return {
|
|
568
569
|
conditions: [
|
|
569
570
|
this.buildLiteralFilter(eb, lhs, type, payload)
|
|
@@ -579,14 +580,14 @@ var BaseCrudDialect = class {
|
|
|
579
580
|
}
|
|
580
581
|
const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
|
|
581
582
|
const condition = (0, import_ts_pattern.match)(op).with("equals", () => rhs === null ? eb(lhs, "is", null) : eb(lhs, "=", rhs)).with("in", () => {
|
|
582
|
-
(0,
|
|
583
|
+
(0, import_common_helpers.invariant)(Array.isArray(rhs), "right hand side must be an array");
|
|
583
584
|
if (rhs.length === 0) {
|
|
584
585
|
return this.false(eb);
|
|
585
586
|
} else {
|
|
586
587
|
return eb(lhs, "in", rhs);
|
|
587
588
|
}
|
|
588
589
|
}).with("notIn", () => {
|
|
589
|
-
(0,
|
|
590
|
+
(0, import_common_helpers.invariant)(Array.isArray(rhs), "right hand side must be an array");
|
|
590
591
|
if (rhs.length === 0) {
|
|
591
592
|
return this.true(eb);
|
|
592
593
|
} else {
|
|
@@ -700,9 +701,9 @@ var BaseCrudDialect = class {
|
|
|
700
701
|
"_min",
|
|
701
702
|
"_max"
|
|
702
703
|
].includes(field)) {
|
|
703
|
-
(0,
|
|
704
|
+
(0, import_common_helpers.invariant)(value && typeof value === "object", `invalid orderBy value for field "${field}"`);
|
|
704
705
|
for (const [k, v] of Object.entries(value)) {
|
|
705
|
-
(0,
|
|
706
|
+
(0, import_common_helpers.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
706
707
|
result = result.orderBy((eb) => eb.fn(field.slice(1), [
|
|
707
708
|
import_kysely.sql.ref(k)
|
|
708
709
|
]), import_kysely.sql.raw(this.negateSort(v, negated)));
|
|
@@ -711,9 +712,9 @@ var BaseCrudDialect = class {
|
|
|
711
712
|
}
|
|
712
713
|
switch (field) {
|
|
713
714
|
case "_count": {
|
|
714
|
-
(0,
|
|
715
|
+
(0, import_common_helpers.invariant)(value && typeof value === "object", 'invalid orderBy value for field "_count"');
|
|
715
716
|
for (const [k, v] of Object.entries(value)) {
|
|
716
|
-
(0,
|
|
717
|
+
(0, import_common_helpers.invariant)(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
717
718
|
result = result.orderBy((eb) => eb.fn.count(import_kysely.sql.ref(k)), import_kysely.sql.raw(this.negateSort(v, negated)));
|
|
718
719
|
}
|
|
719
720
|
continue;
|
|
@@ -735,7 +736,7 @@ var BaseCrudDialect = class {
|
|
|
735
736
|
throw new QueryError(`invalid orderBy value for field "${field}"`);
|
|
736
737
|
}
|
|
737
738
|
if ("_count" in value) {
|
|
738
|
-
(0,
|
|
739
|
+
(0, import_common_helpers.invariant)(value._count === "asc" || value._count === "desc", 'invalid orderBy value for field "_count"');
|
|
739
740
|
const sort = this.negateSort(value._count, negated);
|
|
740
741
|
result = result.orderBy((eb) => {
|
|
741
742
|
let subQuery = eb.selectFrom(relationModel);
|
|
@@ -853,8 +854,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
853
854
|
if (m2m) {
|
|
854
855
|
const parentIds = getIdFields(this.schema, model);
|
|
855
856
|
const relationIds = getIdFields(this.schema, relationModel);
|
|
856
|
-
(0,
|
|
857
|
-
(0,
|
|
857
|
+
(0, import_common_helpers2.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
858
|
+
(0, import_common_helpers2.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
858
859
|
subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentName}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
|
|
859
860
|
} else {
|
|
860
861
|
const joinPairs = buildJoinPairs(this.schema, model, parentName, relationField, relationModel);
|
|
@@ -948,8 +949,8 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
948
949
|
};
|
|
949
950
|
|
|
950
951
|
// src/client/crud/dialects/sqlite.ts
|
|
952
|
+
var import_common_helpers3 = require("@zenstackhq/common-helpers");
|
|
951
953
|
var import_kysely3 = require("kysely");
|
|
952
|
-
var import_tiny_invariant3 = __toESM(require("tiny-invariant"), 1);
|
|
953
954
|
var import_ts_pattern3 = require("ts-pattern");
|
|
954
955
|
var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
955
956
|
static {
|
|
@@ -996,8 +997,8 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
996
997
|
if (m2m) {
|
|
997
998
|
const parentIds = getIdFields(this.schema, model);
|
|
998
999
|
const relationIds = getIdFields(this.schema, relationModel);
|
|
999
|
-
(0,
|
|
1000
|
-
(0,
|
|
1000
|
+
(0, import_common_helpers3.invariant)(parentIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1001
|
+
(0, import_common_helpers3.invariant)(relationIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
1001
1002
|
subQuery = subQuery.where(eb(eb.ref(`${relationModel}.${relationIds[0]}`), "in", eb.selectFrom(m2m.joinTable).select(`${m2m.joinTable}.${m2m.otherFkName}`).whereRef(`${parentName}.${parentIds[0]}`, "=", `${m2m.joinTable}.${m2m.parentFkName}`)));
|
|
1002
1003
|
} else {
|
|
1003
1004
|
const { keyPairs, ownedByModel } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
|
|
@@ -1493,12 +1494,12 @@ var ColumnCollector = class extends DefaultOperationNodeVisitor {
|
|
|
1493
1494
|
};
|
|
1494
1495
|
|
|
1495
1496
|
// src/plugins/policy/expression-transformer.ts
|
|
1497
|
+
var import_common_helpers5 = require("@zenstackhq/common-helpers");
|
|
1496
1498
|
var import_kysely6 = require("kysely");
|
|
1497
|
-
var import_tiny_invariant5 = __toESM(require("tiny-invariant"), 1);
|
|
1498
1499
|
var import_ts_pattern6 = require("ts-pattern");
|
|
1499
1500
|
|
|
1500
1501
|
// src/plugins/policy/expression-evaluator.ts
|
|
1501
|
-
var
|
|
1502
|
+
var import_common_helpers4 = require("@zenstackhq/common-helpers");
|
|
1502
1503
|
var import_ts_pattern5 = require("ts-pattern");
|
|
1503
1504
|
var ExpressionEvaluator = class {
|
|
1504
1505
|
static {
|
|
@@ -1542,18 +1543,18 @@ var ExpressionEvaluator = class {
|
|
|
1542
1543
|
const right = this.evaluate(expr2.right, context);
|
|
1543
1544
|
return (0, import_ts_pattern5.match)(expr2.op).with("==", () => left === right).with("!=", () => left !== right).with(">", () => left > right).with(">=", () => left >= right).with("<", () => left < right).with("<=", () => left <= right).with("&&", () => left && right).with("||", () => left || right).with("in", () => {
|
|
1544
1545
|
const _right = right ?? [];
|
|
1545
|
-
(0,
|
|
1546
|
+
(0, import_common_helpers4.invariant)(Array.isArray(_right), 'expected array for "in" operator');
|
|
1546
1547
|
return _right.includes(left);
|
|
1547
1548
|
}).exhaustive();
|
|
1548
1549
|
}
|
|
1549
1550
|
evaluateCollectionPredicate(expr2, context) {
|
|
1550
1551
|
const op = expr2.op;
|
|
1551
|
-
(0,
|
|
1552
|
+
(0, import_common_helpers4.invariant)(op === "?" || op === "!" || op === "^", 'expected "?" or "!" or "^" operator');
|
|
1552
1553
|
const left = this.evaluate(expr2.left, context);
|
|
1553
1554
|
if (!left) {
|
|
1554
1555
|
return false;
|
|
1555
1556
|
}
|
|
1556
|
-
(0,
|
|
1557
|
+
(0, import_common_helpers4.invariant)(Array.isArray(left), "expected array");
|
|
1557
1558
|
return (0, import_ts_pattern5.match)(op).with("?", () => left.some((item) => this.evaluate(expr2.right, {
|
|
1558
1559
|
...context,
|
|
1559
1560
|
thisValue: item
|
|
@@ -1775,20 +1776,20 @@ var ExpressionTransformer = class {
|
|
|
1775
1776
|
return import_kysely6.BinaryOperationNode.create(left, this.transformOperator(op), right);
|
|
1776
1777
|
}
|
|
1777
1778
|
transformCollectionPredicate(expr2, context) {
|
|
1778
|
-
(0,
|
|
1779
|
+
(0, import_common_helpers5.invariant)(expr2.op === "?" || expr2.op === "!" || expr2.op === "^", 'expected "?" or "!" or "^" operator');
|
|
1779
1780
|
if (this.isAuthCall(expr2.left) || this.isAuthMember(expr2.left)) {
|
|
1780
1781
|
const value = new ExpressionEvaluator().evaluate(expr2, {
|
|
1781
1782
|
auth: this.auth
|
|
1782
1783
|
});
|
|
1783
1784
|
return this.transformValue(value, "Boolean");
|
|
1784
1785
|
}
|
|
1785
|
-
(0,
|
|
1786
|
+
(0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.left) || ExpressionUtils.isMember(expr2.left), "left operand must be field or member access");
|
|
1786
1787
|
let newContextModel;
|
|
1787
1788
|
if (ExpressionUtils.isField(expr2.left)) {
|
|
1788
1789
|
const fieldDef = requireField(this.schema, context.model, expr2.left.field);
|
|
1789
1790
|
newContextModel = fieldDef.type;
|
|
1790
1791
|
} else {
|
|
1791
|
-
(0,
|
|
1792
|
+
(0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.left.receiver));
|
|
1792
1793
|
const fieldDef = requireField(this.schema, context.model, expr2.left.receiver.field);
|
|
1793
1794
|
newContextModel = fieldDef.type;
|
|
1794
1795
|
for (const member of expr2.left.members) {
|
|
@@ -1835,7 +1836,7 @@ var ExpressionTransformer = class {
|
|
|
1835
1836
|
return import_kysely6.ValueNode.create(this.dialect.transformPrimitive(value, type) ?? null);
|
|
1836
1837
|
}
|
|
1837
1838
|
_unary(expr2, context) {
|
|
1838
|
-
(0,
|
|
1839
|
+
(0, import_common_helpers5.invariant)(expr2.op === "!", 'only "!" operator is supported');
|
|
1839
1840
|
return import_kysely6.BinaryOperationNode.create(this.transform(expr2.operand, context), this.transformOperator("!="), trueNode(this.dialect));
|
|
1840
1841
|
}
|
|
1841
1842
|
transformOperator(op) {
|
|
@@ -1878,10 +1879,10 @@ var ExpressionTransformer = class {
|
|
|
1878
1879
|
if (this.isAuthCall(expr2.receiver)) {
|
|
1879
1880
|
return this.valueMemberAccess(this.auth, expr2, this.authType);
|
|
1880
1881
|
}
|
|
1881
|
-
(0,
|
|
1882
|
+
(0, import_common_helpers5.invariant)(ExpressionUtils.isField(expr2.receiver), "expect receiver to be field expression");
|
|
1882
1883
|
const { memberFilter, memberSelect, ...restContext } = context;
|
|
1883
1884
|
const receiver = this.transform(expr2.receiver, restContext);
|
|
1884
|
-
(0,
|
|
1885
|
+
(0, import_common_helpers5.invariant)(import_kysely6.SelectQueryNode.is(receiver), "expected receiver to be select query");
|
|
1885
1886
|
const receiverField = requireField(this.schema, context.model, expr2.receiver.field);
|
|
1886
1887
|
const memberFields = [];
|
|
1887
1888
|
let currType = receiverField.type;
|
|
@@ -1905,7 +1906,7 @@ var ExpressionTransformer = class {
|
|
|
1905
1906
|
thisEntity: void 0
|
|
1906
1907
|
});
|
|
1907
1908
|
if (currNode) {
|
|
1908
|
-
(0,
|
|
1909
|
+
(0, import_common_helpers5.invariant)(import_kysely6.SelectQueryNode.is(currNode), "expected select query node");
|
|
1909
1910
|
currNode = {
|
|
1910
1911
|
...relation,
|
|
1911
1912
|
selections: [
|
|
@@ -1922,8 +1923,8 @@ var ExpressionTransformer = class {
|
|
|
1922
1923
|
};
|
|
1923
1924
|
}
|
|
1924
1925
|
} else {
|
|
1925
|
-
(0,
|
|
1926
|
-
(0,
|
|
1926
|
+
(0, import_common_helpers5.invariant)(i === expr2.members.length - 1, "plain field access must be the last segment");
|
|
1927
|
+
(0, import_common_helpers5.invariant)(!currNode, "plain field access must be the last segment");
|
|
1927
1928
|
currNode = import_kysely6.ColumnNode.create(member);
|
|
1928
1929
|
}
|
|
1929
1930
|
}
|
|
@@ -2168,13 +2169,13 @@ var PolicyHandler = class extends import_kysely7.OperationNodeTransformer {
|
|
|
2168
2169
|
}
|
|
2169
2170
|
}
|
|
2170
2171
|
unwrapCreateValueRow(data, model, fields) {
|
|
2171
|
-
(0,
|
|
2172
|
+
(0, import_common_helpers6.invariant)(data.length === fields.length, "data length must match fields length");
|
|
2172
2173
|
const result = [];
|
|
2173
2174
|
for (let i = 0; i < data.length; i++) {
|
|
2174
2175
|
const item = data[i];
|
|
2175
2176
|
const fieldDef = requireField(this.client.$schema, model, fields[i]);
|
|
2176
2177
|
if (typeof item === "object" && item && "kind" in item) {
|
|
2177
|
-
(0,
|
|
2178
|
+
(0, import_common_helpers6.invariant)(item.kind === "ValueNode", "expecting a ValueNode");
|
|
2178
2179
|
result.push({
|
|
2179
2180
|
node: import_kysely7.ValueNode.create(this.dialect.transformPrimitive(item.value, fieldDef.type)),
|
|
2180
2181
|
raw: item.value
|
|
@@ -2382,8 +2383,8 @@ var PolicyHandler = class extends import_kysely7.OperationNodeTransformer {
|
|
|
2382
2383
|
const modelDef = requireModel(this.client.$schema, modelName);
|
|
2383
2384
|
const result = [];
|
|
2384
2385
|
const extractOperations = /* @__PURE__ */ __name((expr2) => {
|
|
2385
|
-
(0,
|
|
2386
|
-
(0,
|
|
2386
|
+
(0, import_common_helpers6.invariant)(ExpressionUtils.isLiteral(expr2), "expecting a literal");
|
|
2387
|
+
(0, import_common_helpers6.invariant)(typeof expr2.value === "string", "expecting a string literal");
|
|
2387
2388
|
return expr2.value.split(",").filter((v) => !!v).map((v) => v.trim());
|
|
2388
2389
|
}, "extractOperations");
|
|
2389
2390
|
if (modelDef.attributes) {
|
|
@@ -2418,13 +2419,13 @@ var PolicyPlugin = class {
|
|
|
2418
2419
|
};
|
|
2419
2420
|
|
|
2420
2421
|
// src/utils/clone.ts
|
|
2421
|
-
var
|
|
2422
|
+
var import_common_helpers7 = require("@zenstackhq/common-helpers");
|
|
2422
2423
|
function clone(value) {
|
|
2423
2424
|
if (Array.isArray(value)) {
|
|
2424
2425
|
return value.map((v) => clone(v));
|
|
2425
2426
|
}
|
|
2426
2427
|
if (typeof value === "object") {
|
|
2427
|
-
if (!value || !(0,
|
|
2428
|
+
if (!value || !(0, import_common_helpers7.isPlainObject)(value)) {
|
|
2428
2429
|
return value;
|
|
2429
2430
|
}
|
|
2430
2431
|
const result = {};
|
|
@@ -2744,8 +2745,8 @@ var BaseOperationHandler = class {
|
|
|
2744
2745
|
}
|
|
2745
2746
|
buildFkAssignments(model, relationField, entity) {
|
|
2746
2747
|
const parentFkFields = {};
|
|
2747
|
-
(0,
|
|
2748
|
-
(0,
|
|
2748
|
+
(0, import_common_helpers8.invariant)(relationField, "parentField must be defined if parentModel is defined");
|
|
2749
|
+
(0, import_common_helpers8.invariant)(entity, "parentEntity must be defined if parentModel is defined");
|
|
2749
2750
|
const { keyPairs } = getRelationForeignKeyFieldPairs(this.schema, model, relationField);
|
|
2750
2751
|
for (const pair of keyPairs) {
|
|
2751
2752
|
if (!(pair.pk in entity)) {
|
|
@@ -2772,8 +2773,8 @@ var BaseOperationHandler = class {
|
|
|
2772
2773
|
].sort((a, b) => a.model.localeCompare(b.model));
|
|
2773
2774
|
const firstIds = getIdFields(this.schema, sortedRecords[0].model);
|
|
2774
2775
|
const secondIds = getIdFields(this.schema, sortedRecords[1].model);
|
|
2775
|
-
(0,
|
|
2776
|
-
(0,
|
|
2776
|
+
(0, import_common_helpers8.invariant)(firstIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
2777
|
+
(0, import_common_helpers8.invariant)(secondIds.length === 1, "many-to-many relation must have exactly one id field");
|
|
2777
2778
|
if (action === "connect") {
|
|
2778
2779
|
const result = await kysely.insertInto(joinTable).values({
|
|
2779
2780
|
A: sortedRecords[0].entity[firstIds[0]],
|
|
@@ -2790,10 +2791,10 @@ var BaseOperationHandler = class {
|
|
|
2790
2791
|
}
|
|
2791
2792
|
}
|
|
2792
2793
|
resetManyToManyRelation(kysely, model, field, parentIds) {
|
|
2793
|
-
(0,
|
|
2794
|
+
(0, import_common_helpers8.invariant)(Object.keys(parentIds).length === 1, "parentIds must have exactly one field");
|
|
2794
2795
|
const parentId = Object.values(parentIds)[0];
|
|
2795
2796
|
const m2m = getManyToManyRelation(this.schema, model, field);
|
|
2796
|
-
(0,
|
|
2797
|
+
(0, import_common_helpers8.invariant)(m2m, "not a many-to-many relation");
|
|
2797
2798
|
const eb = (0, import_kysely8.expressionBuilder)();
|
|
2798
2799
|
return kysely.deleteFrom(m2m.joinTable).where(eb(`${m2m.joinTable}.${m2m.parentFkName}`, "=", parentId)).execute();
|
|
2799
2800
|
}
|
|
@@ -2815,7 +2816,7 @@ var BaseOperationHandler = class {
|
|
|
2815
2816
|
}
|
|
2816
2817
|
case "connect": {
|
|
2817
2818
|
const referencedPkFields = relationField.relation.references;
|
|
2818
|
-
(0,
|
|
2819
|
+
(0, import_common_helpers8.invariant)(referencedPkFields, "relation must have fields info");
|
|
2819
2820
|
const extractedFks = extractFields(subPayload, referencedPkFields);
|
|
2820
2821
|
if (Object.keys(extractedFks).length === referencedPkFields.length) {
|
|
2821
2822
|
result = extractedFks;
|
|
@@ -2904,7 +2905,7 @@ var BaseOperationHandler = class {
|
|
|
2904
2905
|
const newItem = {};
|
|
2905
2906
|
for (const [name, value] of Object.entries(item)) {
|
|
2906
2907
|
const fieldDef = this.requireField(model, name);
|
|
2907
|
-
(0,
|
|
2908
|
+
(0, import_common_helpers8.invariant)(!fieldDef.relation, "createMany does not support relations");
|
|
2908
2909
|
newItem[name] = this.dialect.transformPrimitive(value, fieldDef.type);
|
|
2909
2910
|
}
|
|
2910
2911
|
if (fromRelation) {
|
|
@@ -2983,7 +2984,7 @@ var BaseOperationHandler = class {
|
|
|
2983
2984
|
}
|
|
2984
2985
|
} else {
|
|
2985
2986
|
const fromRelationFieldDef = this.requireField(fromRelation.model, fromRelation.field);
|
|
2986
|
-
(0,
|
|
2987
|
+
(0, import_common_helpers8.invariant)(fromRelationFieldDef.relation?.opposite);
|
|
2987
2988
|
parentWhere[fromRelationFieldDef.relation.opposite] = {
|
|
2988
2989
|
some: fromRelation.ids
|
|
2989
2990
|
};
|
|
@@ -3073,7 +3074,7 @@ var BaseOperationHandler = class {
|
|
|
3073
3074
|
}
|
|
3074
3075
|
}
|
|
3075
3076
|
transformIncrementalUpdate(model, field, fieldDef, payload) {
|
|
3076
|
-
(0,
|
|
3077
|
+
(0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided');
|
|
3077
3078
|
const key = Object.keys(payload)[0];
|
|
3078
3079
|
const value = this.dialect.transformPrimitive(payload[key], fieldDef.type);
|
|
3079
3080
|
const eb = (0, import_kysely8.expressionBuilder)();
|
|
@@ -3083,7 +3084,7 @@ var BaseOperationHandler = class {
|
|
|
3083
3084
|
});
|
|
3084
3085
|
}
|
|
3085
3086
|
transformScalarListUpdate(model, field, fieldDef, payload) {
|
|
3086
|
-
(0,
|
|
3087
|
+
(0, import_common_helpers8.invariant)(Object.keys(payload).length === 1, 'Only one of "set", "push" can be provided');
|
|
3087
3088
|
const key = Object.keys(payload)[0];
|
|
3088
3089
|
const value = this.dialect.transformPrimitive(payload[key], fieldDef.type);
|
|
3089
3090
|
const eb = (0, import_kysely8.expressionBuilder)();
|
|
@@ -3164,12 +3165,12 @@ var BaseOperationHandler = class {
|
|
|
3164
3165
|
for (const [key, value] of Object.entries(args)) {
|
|
3165
3166
|
switch (key) {
|
|
3166
3167
|
case "create": {
|
|
3167
|
-
(0,
|
|
3168
|
+
(0, import_common_helpers8.invariant)(!Array.isArray(value) || fieldDef.array, "relation must be an array if create is an array");
|
|
3168
3169
|
tasks.push(...enumerate(value).map((item) => this.create(kysely, fieldModel, item, fromRelationContext)));
|
|
3169
3170
|
break;
|
|
3170
3171
|
}
|
|
3171
3172
|
case "createMany": {
|
|
3172
|
-
(0,
|
|
3173
|
+
(0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array for createMany");
|
|
3173
3174
|
tasks.push(this.createMany(kysely, fieldModel, value, false, fromRelationContext));
|
|
3174
3175
|
break;
|
|
3175
3176
|
}
|
|
@@ -3186,7 +3187,7 @@ var BaseOperationHandler = class {
|
|
|
3186
3187
|
break;
|
|
3187
3188
|
}
|
|
3188
3189
|
case "set": {
|
|
3189
|
-
(0,
|
|
3190
|
+
(0, import_common_helpers8.invariant)(fieldDef.array, "relation must be an array");
|
|
3190
3191
|
tasks.push(this.setRelation(kysely, fieldModel, value, fromRelationContext));
|
|
3191
3192
|
break;
|
|
3192
3193
|
}
|
|
@@ -3255,7 +3256,7 @@ var BaseOperationHandler = class {
|
|
|
3255
3256
|
const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
|
|
3256
3257
|
let updateResult;
|
|
3257
3258
|
if (ownedByModel) {
|
|
3258
|
-
(0,
|
|
3259
|
+
(0, import_common_helpers8.invariant)(_data.length === 1, "only one entity can be connected");
|
|
3259
3260
|
const target = await this.readUnique(kysely, model, {
|
|
3260
3261
|
where: _data[0]
|
|
3261
3262
|
});
|
|
@@ -3345,7 +3346,7 @@ var BaseOperationHandler = class {
|
|
|
3345
3346
|
const { ownedByModel, keyPairs } = getRelationForeignKeyFieldPairs(this.schema, fromRelation.model, fromRelation.field);
|
|
3346
3347
|
const eb = (0, import_kysely8.expressionBuilder)();
|
|
3347
3348
|
if (ownedByModel) {
|
|
3348
|
-
(0,
|
|
3349
|
+
(0, import_common_helpers8.invariant)(disconnectConditions.length === 1, "only one entity can be disconnected");
|
|
3349
3350
|
const condition = disconnectConditions[0];
|
|
3350
3351
|
const query = kysely.updateTable(fromRelation.model).where(eb.and(fromRelation.ids)).$if(condition !== true, (qb) => qb.where(eb(
|
|
3351
3352
|
// @ts-ignore
|
|
@@ -3453,7 +3454,7 @@ var BaseOperationHandler = class {
|
|
|
3453
3454
|
const m2m = getManyToManyRelation(this.schema, fromRelation.model, fromRelation.field);
|
|
3454
3455
|
if (m2m) {
|
|
3455
3456
|
const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
|
|
3456
|
-
(0,
|
|
3457
|
+
(0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
|
|
3457
3458
|
deleteResult = await this.delete(kysely, model, {
|
|
3458
3459
|
AND: [
|
|
3459
3460
|
{
|
|
@@ -3476,7 +3477,7 @@ var BaseOperationHandler = class {
|
|
|
3476
3477
|
throw new NotFoundError(model);
|
|
3477
3478
|
}
|
|
3478
3479
|
const fieldDef = this.requireField(fromRelation.model, fromRelation.field);
|
|
3479
|
-
(0,
|
|
3480
|
+
(0, import_common_helpers8.invariant)(fieldDef.relation?.opposite);
|
|
3480
3481
|
deleteResult = await this.delete(kysely, model, {
|
|
3481
3482
|
AND: [
|
|
3482
3483
|
// filter for parent
|
|
@@ -3981,16 +3982,15 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
3981
3982
|
var import_decimal = __toESM(require("decimal.js"), 1);
|
|
3982
3983
|
var import_json_stable_stringify = __toESM(require("json-stable-stringify"), 1);
|
|
3983
3984
|
var import_ts_pattern14 = require("ts-pattern");
|
|
3984
|
-
var
|
|
3985
|
+
var import_v4 = require("zod/v4");
|
|
3985
3986
|
var InputValidator = class {
|
|
3986
3987
|
static {
|
|
3987
3988
|
__name(this, "InputValidator");
|
|
3988
3989
|
}
|
|
3989
3990
|
schema;
|
|
3990
|
-
schemaCache;
|
|
3991
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
3991
3992
|
constructor(schema) {
|
|
3992
3993
|
this.schema = schema;
|
|
3993
|
-
this.schemaCache = /* @__PURE__ */ new Map();
|
|
3994
3994
|
}
|
|
3995
3995
|
validateFindArgs(model, unique, args) {
|
|
3996
3996
|
return this.validate(model, "find", {
|
|
@@ -4066,11 +4066,11 @@ var InputValidator = class {
|
|
|
4066
4066
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4067
4067
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4068
4068
|
if (options.collection) {
|
|
4069
|
-
fields["skip"] =
|
|
4070
|
-
fields["take"] =
|
|
4069
|
+
fields["skip"] = import_v4.z.number().int().nonnegative().optional();
|
|
4070
|
+
fields["take"] = import_v4.z.number().int().optional();
|
|
4071
4071
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4072
4072
|
}
|
|
4073
|
-
let result =
|
|
4073
|
+
let result = import_v4.z.object(fields).strict();
|
|
4074
4074
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
4075
4075
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
4076
4076
|
if (!options.unique) {
|
|
@@ -4079,17 +4079,17 @@ var InputValidator = class {
|
|
|
4079
4079
|
return result;
|
|
4080
4080
|
}
|
|
4081
4081
|
makePrimitiveSchema(type) {
|
|
4082
|
-
return (0, import_ts_pattern14.match)(type).with("String", () =>
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
])).with("Decimal", () =>
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
])).with("DateTime", () =>
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
])).with("Bytes", () =>
|
|
4082
|
+
return (0, import_ts_pattern14.match)(type).with("String", () => import_v4.z.string()).with("Int", () => import_v4.z.number()).with("Float", () => import_v4.z.number()).with("Boolean", () => import_v4.z.boolean()).with("BigInt", () => import_v4.z.union([
|
|
4083
|
+
import_v4.z.number(),
|
|
4084
|
+
import_v4.z.bigint()
|
|
4085
|
+
])).with("Decimal", () => import_v4.z.union([
|
|
4086
|
+
import_v4.z.number(),
|
|
4087
|
+
import_v4.z.instanceof(import_decimal.default),
|
|
4088
|
+
import_v4.z.string()
|
|
4089
|
+
])).with("DateTime", () => import_v4.z.union([
|
|
4090
|
+
import_v4.z.date(),
|
|
4091
|
+
import_v4.z.string().datetime()
|
|
4092
|
+
])).with("Bytes", () => import_v4.z.instanceof(Uint8Array)).otherwise(() => import_v4.z.unknown());
|
|
4093
4093
|
}
|
|
4094
4094
|
makeWhereSchema(model, unique, withoutRelationFields = false) {
|
|
4095
4095
|
const modelDef = getModel(this.schema, model);
|
|
@@ -4104,21 +4104,21 @@ var InputValidator = class {
|
|
|
4104
4104
|
if (withoutRelationFields) {
|
|
4105
4105
|
continue;
|
|
4106
4106
|
}
|
|
4107
|
-
fieldSchema =
|
|
4107
|
+
fieldSchema = import_v4.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
4108
4108
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
4109
4109
|
if (fieldDef.array) {
|
|
4110
|
-
fieldSchema =
|
|
4110
|
+
fieldSchema = import_v4.z.union([
|
|
4111
4111
|
fieldSchema,
|
|
4112
|
-
|
|
4112
|
+
import_v4.z.object({
|
|
4113
4113
|
some: fieldSchema.optional(),
|
|
4114
4114
|
every: fieldSchema.optional(),
|
|
4115
4115
|
none: fieldSchema.optional()
|
|
4116
4116
|
})
|
|
4117
4117
|
]);
|
|
4118
4118
|
} else {
|
|
4119
|
-
fieldSchema =
|
|
4119
|
+
fieldSchema = import_v4.z.union([
|
|
4120
4120
|
fieldSchema,
|
|
4121
|
-
|
|
4121
|
+
import_v4.z.object({
|
|
4122
4122
|
is: fieldSchema.optional(),
|
|
4123
4123
|
isNot: fieldSchema.optional()
|
|
4124
4124
|
})
|
|
@@ -4144,18 +4144,18 @@ var InputValidator = class {
|
|
|
4144
4144
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
4145
4145
|
for (const uniqueField of uniqueFields) {
|
|
4146
4146
|
if ("defs" in uniqueField) {
|
|
4147
|
-
fields[uniqueField.name] =
|
|
4147
|
+
fields[uniqueField.name] = import_v4.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => [
|
|
4148
4148
|
key,
|
|
4149
4149
|
this.makePrimitiveFilterSchema(def.type, !!def.optional)
|
|
4150
4150
|
]))).optional();
|
|
4151
4151
|
}
|
|
4152
4152
|
}
|
|
4153
4153
|
}
|
|
4154
|
-
fields["$expr"] =
|
|
4155
|
-
fields["AND"] = this.orArray(
|
|
4156
|
-
fields["OR"] =
|
|
4157
|
-
fields["NOT"] = this.orArray(
|
|
4158
|
-
const baseWhere =
|
|
4154
|
+
fields["$expr"] = import_v4.z.custom((v) => typeof v === "function").optional();
|
|
4155
|
+
fields["AND"] = this.orArray(import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4156
|
+
fields["OR"] = import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
4157
|
+
fields["NOT"] = this.orArray(import_v4.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
4158
|
+
const baseWhere = import_v4.z.object(fields).strict();
|
|
4159
4159
|
let result = baseWhere;
|
|
4160
4160
|
if (unique) {
|
|
4161
4161
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -4175,11 +4175,11 @@ var InputValidator = class {
|
|
|
4175
4175
|
return result;
|
|
4176
4176
|
}
|
|
4177
4177
|
makeEnumFilterSchema(enumDef, optional) {
|
|
4178
|
-
const baseSchema =
|
|
4179
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4180
|
-
return
|
|
4178
|
+
const baseSchema = import_v4.z.enum(Object.keys(enumDef));
|
|
4179
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_v4.z.lazy(() => this.makeEnumFilterSchema(enumDef, optional)));
|
|
4180
|
+
return import_v4.z.union([
|
|
4181
4181
|
this.nullableIf(baseSchema, optional),
|
|
4182
|
-
|
|
4182
|
+
import_v4.z.object({
|
|
4183
4183
|
equals: components.equals,
|
|
4184
4184
|
in: components.in,
|
|
4185
4185
|
notIn: components.notIn,
|
|
@@ -4188,38 +4188,38 @@ var InputValidator = class {
|
|
|
4188
4188
|
]);
|
|
4189
4189
|
}
|
|
4190
4190
|
makeArrayFilterSchema(type) {
|
|
4191
|
-
return
|
|
4191
|
+
return import_v4.z.object({
|
|
4192
4192
|
equals: this.makePrimitiveSchema(type).array().optional(),
|
|
4193
4193
|
has: this.makePrimitiveSchema(type).optional(),
|
|
4194
4194
|
hasEvery: this.makePrimitiveSchema(type).array().optional(),
|
|
4195
4195
|
hasSome: this.makePrimitiveSchema(type).array().optional(),
|
|
4196
|
-
isEmpty:
|
|
4196
|
+
isEmpty: import_v4.z.boolean().optional()
|
|
4197
4197
|
});
|
|
4198
4198
|
}
|
|
4199
4199
|
makePrimitiveFilterSchema(type, optional) {
|
|
4200
4200
|
return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makePrimitiveSchema(type2), optional)).with("Boolean", () => this.makeBooleanFilterSchema(optional)).with("DateTime", () => this.makeDateTimeFilterSchema(optional)).with("Bytes", () => this.makeBytesFilterSchema(optional)).exhaustive();
|
|
4201
4201
|
}
|
|
4202
4202
|
makeDateTimeFilterSchema(optional) {
|
|
4203
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
]), optional, () =>
|
|
4203
|
+
return this.makeCommonPrimitiveFilterSchema(import_v4.z.union([
|
|
4204
|
+
import_v4.z.string().datetime(),
|
|
4205
|
+
import_v4.z.date()
|
|
4206
|
+
]), optional, () => import_v4.z.lazy(() => this.makeDateTimeFilterSchema(optional)));
|
|
4207
4207
|
}
|
|
4208
4208
|
makeBooleanFilterSchema(optional) {
|
|
4209
|
-
return
|
|
4210
|
-
this.nullableIf(
|
|
4211
|
-
|
|
4212
|
-
equals: this.nullableIf(
|
|
4213
|
-
not:
|
|
4209
|
+
return import_v4.z.union([
|
|
4210
|
+
this.nullableIf(import_v4.z.boolean(), optional),
|
|
4211
|
+
import_v4.z.object({
|
|
4212
|
+
equals: this.nullableIf(import_v4.z.boolean(), optional).optional(),
|
|
4213
|
+
not: import_v4.z.lazy(() => this.makeBooleanFilterSchema(optional)).optional()
|
|
4214
4214
|
})
|
|
4215
4215
|
]);
|
|
4216
4216
|
}
|
|
4217
4217
|
makeBytesFilterSchema(optional) {
|
|
4218
|
-
const baseSchema =
|
|
4219
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
4220
|
-
return
|
|
4218
|
+
const baseSchema = import_v4.z.instanceof(Uint8Array);
|
|
4219
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_v4.z.instanceof(Uint8Array));
|
|
4220
|
+
return import_v4.z.union([
|
|
4221
4221
|
this.nullableIf(baseSchema, optional),
|
|
4222
|
-
|
|
4222
|
+
import_v4.z.object({
|
|
4223
4223
|
equals: components.equals,
|
|
4224
4224
|
in: components.in,
|
|
4225
4225
|
notIn: components.notIn,
|
|
@@ -4241,16 +4241,16 @@ var InputValidator = class {
|
|
|
4241
4241
|
};
|
|
4242
4242
|
}
|
|
4243
4243
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis) {
|
|
4244
|
-
return
|
|
4244
|
+
return import_v4.z.union([
|
|
4245
4245
|
this.nullableIf(baseSchema, optional),
|
|
4246
|
-
|
|
4246
|
+
import_v4.z.object(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis))
|
|
4247
4247
|
]);
|
|
4248
4248
|
}
|
|
4249
4249
|
makeNumberFilterSchema(baseSchema, optional) {
|
|
4250
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
4250
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_v4.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional)));
|
|
4251
4251
|
}
|
|
4252
4252
|
makeStringFilterSchema(optional) {
|
|
4253
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
4253
|
+
return this.makeCommonPrimitiveFilterSchema(import_v4.z.string(), optional, () => import_v4.z.lazy(() => this.makeStringFilterSchema(optional)));
|
|
4254
4254
|
}
|
|
4255
4255
|
makeSelectSchema(model) {
|
|
4256
4256
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4258,33 +4258,33 @@ var InputValidator = class {
|
|
|
4258
4258
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4259
4259
|
const fieldDef = requireField(this.schema, model, field);
|
|
4260
4260
|
if (fieldDef.relation) {
|
|
4261
|
-
fields[field] =
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
select:
|
|
4265
|
-
include:
|
|
4261
|
+
fields[field] = import_v4.z.union([
|
|
4262
|
+
import_v4.z.literal(true),
|
|
4263
|
+
import_v4.z.object({
|
|
4264
|
+
select: import_v4.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4265
|
+
include: import_v4.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4266
4266
|
})
|
|
4267
4267
|
]).optional();
|
|
4268
4268
|
} else {
|
|
4269
|
-
fields[field] =
|
|
4269
|
+
fields[field] = import_v4.z.boolean().optional();
|
|
4270
4270
|
}
|
|
4271
4271
|
}
|
|
4272
4272
|
const toManyRelations = Object.entries(modelDef.fields).filter(([, value]) => value.relation && value.array);
|
|
4273
4273
|
if (toManyRelations.length > 0) {
|
|
4274
|
-
fields["_count"] =
|
|
4275
|
-
|
|
4276
|
-
|
|
4274
|
+
fields["_count"] = import_v4.z.union([
|
|
4275
|
+
import_v4.z.literal(true),
|
|
4276
|
+
import_v4.z.object(toManyRelations.reduce((acc, [name, fieldDef]) => ({
|
|
4277
4277
|
...acc,
|
|
4278
|
-
[name]:
|
|
4279
|
-
|
|
4280
|
-
|
|
4278
|
+
[name]: import_v4.z.union([
|
|
4279
|
+
import_v4.z.boolean(),
|
|
4280
|
+
import_v4.z.object({
|
|
4281
4281
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
4282
4282
|
})
|
|
4283
4283
|
]).optional()
|
|
4284
4284
|
}), {}))
|
|
4285
4285
|
]).optional();
|
|
4286
4286
|
}
|
|
4287
|
-
return
|
|
4287
|
+
return import_v4.z.object(fields).strict();
|
|
4288
4288
|
}
|
|
4289
4289
|
makeOmitSchema(model) {
|
|
4290
4290
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4292,10 +4292,10 @@ var InputValidator = class {
|
|
|
4292
4292
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4293
4293
|
const fieldDef = requireField(this.schema, model, field);
|
|
4294
4294
|
if (!fieldDef.relation) {
|
|
4295
|
-
fields[field] =
|
|
4295
|
+
fields[field] = import_v4.z.boolean().optional();
|
|
4296
4296
|
}
|
|
4297
4297
|
}
|
|
4298
|
-
return
|
|
4298
|
+
return import_v4.z.object(fields).strict();
|
|
4299
4299
|
}
|
|
4300
4300
|
makeIncludeSchema(model) {
|
|
4301
4301
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -4303,40 +4303,40 @@ var InputValidator = class {
|
|
|
4303
4303
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4304
4304
|
const fieldDef = requireField(this.schema, model, field);
|
|
4305
4305
|
if (fieldDef.relation) {
|
|
4306
|
-
fields[field] =
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
select:
|
|
4310
|
-
include:
|
|
4311
|
-
where:
|
|
4306
|
+
fields[field] = import_v4.z.union([
|
|
4307
|
+
import_v4.z.literal(true),
|
|
4308
|
+
import_v4.z.object({
|
|
4309
|
+
select: import_v4.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4310
|
+
include: import_v4.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4311
|
+
where: import_v4.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4312
4312
|
})
|
|
4313
4313
|
]).optional();
|
|
4314
4314
|
}
|
|
4315
4315
|
}
|
|
4316
|
-
return
|
|
4316
|
+
return import_v4.z.object(fields).strict();
|
|
4317
4317
|
}
|
|
4318
4318
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
4319
4319
|
const modelDef = requireModel(this.schema, model);
|
|
4320
4320
|
const fields = {};
|
|
4321
|
-
const sort =
|
|
4322
|
-
|
|
4323
|
-
|
|
4321
|
+
const sort = import_v4.z.union([
|
|
4322
|
+
import_v4.z.literal("asc"),
|
|
4323
|
+
import_v4.z.literal("desc")
|
|
4324
4324
|
]);
|
|
4325
4325
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4326
4326
|
const fieldDef = requireField(this.schema, model, field);
|
|
4327
4327
|
if (fieldDef.relation) {
|
|
4328
4328
|
if (withRelation) {
|
|
4329
|
-
fields[field] =
|
|
4329
|
+
fields[field] = import_v4.z.lazy(() => this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation).optional());
|
|
4330
4330
|
}
|
|
4331
4331
|
} else {
|
|
4332
4332
|
if (fieldDef.optional) {
|
|
4333
|
-
fields[field] =
|
|
4333
|
+
fields[field] = import_v4.z.union([
|
|
4334
4334
|
sort,
|
|
4335
|
-
|
|
4335
|
+
import_v4.z.object({
|
|
4336
4336
|
sort,
|
|
4337
|
-
nulls:
|
|
4338
|
-
|
|
4339
|
-
|
|
4337
|
+
nulls: import_v4.z.union([
|
|
4338
|
+
import_v4.z.literal("first"),
|
|
4339
|
+
import_v4.z.literal("last")
|
|
4340
4340
|
])
|
|
4341
4341
|
})
|
|
4342
4342
|
]).optional();
|
|
@@ -4354,15 +4354,15 @@ var InputValidator = class {
|
|
|
4354
4354
|
"_max"
|
|
4355
4355
|
];
|
|
4356
4356
|
for (const agg of aggregationFields) {
|
|
4357
|
-
fields[agg] =
|
|
4357
|
+
fields[agg] = import_v4.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
4358
4358
|
}
|
|
4359
4359
|
}
|
|
4360
|
-
return
|
|
4360
|
+
return import_v4.z.object(fields);
|
|
4361
4361
|
}
|
|
4362
4362
|
makeDistinctSchema(model) {
|
|
4363
4363
|
const modelDef = requireModel(this.schema, model);
|
|
4364
4364
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4365
|
-
return this.orArray(
|
|
4365
|
+
return this.orArray(import_v4.z.enum(nonRelationFields), true);
|
|
4366
4366
|
}
|
|
4367
4367
|
makeCursorSchema(model) {
|
|
4368
4368
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -4371,7 +4371,7 @@ var InputValidator = class {
|
|
|
4371
4371
|
// #region Create
|
|
4372
4372
|
makeCreateSchema(model) {
|
|
4373
4373
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
4374
|
-
const schema =
|
|
4374
|
+
const schema = import_v4.z.object({
|
|
4375
4375
|
data: dataSchema,
|
|
4376
4376
|
select: this.makeSelectSchema(model).optional(),
|
|
4377
4377
|
include: this.makeIncludeSchema(model).optional(),
|
|
@@ -4384,7 +4384,7 @@ var InputValidator = class {
|
|
|
4384
4384
|
}
|
|
4385
4385
|
makeCreateManyAndReturnSchema(model) {
|
|
4386
4386
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
4387
|
-
const result = base.merge(
|
|
4387
|
+
const result = base.merge(import_v4.z.object({
|
|
4388
4388
|
select: this.makeSelectSchema(model).optional(),
|
|
4389
4389
|
omit: this.makeOmitSchema(model).optional()
|
|
4390
4390
|
}));
|
|
@@ -4416,7 +4416,7 @@ var InputValidator = class {
|
|
|
4416
4416
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4417
4417
|
}
|
|
4418
4418
|
}
|
|
4419
|
-
let fieldSchema =
|
|
4419
|
+
let fieldSchema = import_v4.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "create"));
|
|
4420
4420
|
if (fieldDef.optional || fieldDef.array) {
|
|
4421
4421
|
fieldSchema = fieldSchema.optional();
|
|
4422
4422
|
} else {
|
|
@@ -4438,10 +4438,10 @@ var InputValidator = class {
|
|
|
4438
4438
|
} else {
|
|
4439
4439
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type);
|
|
4440
4440
|
if (fieldDef.array) {
|
|
4441
|
-
fieldSchema =
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
set:
|
|
4441
|
+
fieldSchema = import_v4.z.union([
|
|
4442
|
+
import_v4.z.array(fieldSchema),
|
|
4443
|
+
import_v4.z.object({
|
|
4444
|
+
set: import_v4.z.array(fieldSchema)
|
|
4445
4445
|
})
|
|
4446
4446
|
]).optional();
|
|
4447
4447
|
}
|
|
@@ -4458,16 +4458,16 @@ var InputValidator = class {
|
|
|
4458
4458
|
}
|
|
4459
4459
|
});
|
|
4460
4460
|
if (!hasRelation) {
|
|
4461
|
-
return this.orArray(
|
|
4461
|
+
return this.orArray(import_v4.z.object(regularAndFkFields).strict(), canBeArray);
|
|
4462
4462
|
} else {
|
|
4463
|
-
return
|
|
4464
|
-
|
|
4465
|
-
|
|
4463
|
+
return import_v4.z.union([
|
|
4464
|
+
import_v4.z.object(regularAndFkFields).strict(),
|
|
4465
|
+
import_v4.z.object(regularAndRelationFields).strict(),
|
|
4466
4466
|
...canBeArray ? [
|
|
4467
|
-
|
|
4467
|
+
import_v4.z.array(import_v4.z.object(regularAndFkFields).strict())
|
|
4468
4468
|
] : [],
|
|
4469
4469
|
...canBeArray ? [
|
|
4470
|
-
|
|
4470
|
+
import_v4.z.array(import_v4.z.object(regularAndRelationFields).strict())
|
|
4471
4471
|
] : []
|
|
4472
4472
|
]);
|
|
4473
4473
|
}
|
|
@@ -4488,31 +4488,31 @@ var InputValidator = class {
|
|
|
4488
4488
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
4489
4489
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
4490
4490
|
}
|
|
4491
|
-
fields["update"] = array ? this.orArray(
|
|
4491
|
+
fields["update"] = array ? this.orArray(import_v4.z.object({
|
|
4492
4492
|
where: this.makeWhereSchema(fieldType, true),
|
|
4493
4493
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4494
|
-
}), true).optional() :
|
|
4495
|
-
|
|
4494
|
+
}), true).optional() : import_v4.z.union([
|
|
4495
|
+
import_v4.z.object({
|
|
4496
4496
|
where: this.makeWhereSchema(fieldType, true),
|
|
4497
4497
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4498
4498
|
}),
|
|
4499
4499
|
this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4500
4500
|
]).optional();
|
|
4501
|
-
fields["upsert"] = this.orArray(
|
|
4501
|
+
fields["upsert"] = this.orArray(import_v4.z.object({
|
|
4502
4502
|
where: this.makeWhereSchema(fieldType, true),
|
|
4503
4503
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
4504
4504
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4505
4505
|
}), true).optional();
|
|
4506
4506
|
if (array) {
|
|
4507
4507
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
4508
|
-
fields["updateMany"] = this.orArray(
|
|
4508
|
+
fields["updateMany"] = this.orArray(import_v4.z.object({
|
|
4509
4509
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
4510
4510
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
4511
4511
|
}), true).optional();
|
|
4512
4512
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
4513
4513
|
}
|
|
4514
4514
|
}
|
|
4515
|
-
return
|
|
4515
|
+
return import_v4.z.object(fields).strict().refine((v) => Object.keys(v).length > 0, "At least one action is required");
|
|
4516
4516
|
}
|
|
4517
4517
|
makeSetDataSchema(model, canBeArray) {
|
|
4518
4518
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -4524,36 +4524,36 @@ var InputValidator = class {
|
|
|
4524
4524
|
if (canBeArray) {
|
|
4525
4525
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
4526
4526
|
} else {
|
|
4527
|
-
return
|
|
4528
|
-
|
|
4527
|
+
return import_v4.z.union([
|
|
4528
|
+
import_v4.z.boolean(),
|
|
4529
4529
|
this.makeWhereSchema(model, false)
|
|
4530
4530
|
]);
|
|
4531
4531
|
}
|
|
4532
4532
|
}
|
|
4533
4533
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
4534
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
4535
|
-
|
|
4534
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_v4.z.union([
|
|
4535
|
+
import_v4.z.boolean(),
|
|
4536
4536
|
this.makeWhereSchema(model, uniqueFilter)
|
|
4537
4537
|
]);
|
|
4538
4538
|
}
|
|
4539
4539
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
4540
4540
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
4541
4541
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
4542
|
-
return this.orArray(
|
|
4542
|
+
return this.orArray(import_v4.z.object({
|
|
4543
4543
|
where: whereSchema,
|
|
4544
4544
|
create: createSchema
|
|
4545
4545
|
}).strict(), canBeArray);
|
|
4546
4546
|
}
|
|
4547
4547
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
4548
|
-
return
|
|
4548
|
+
return import_v4.z.object({
|
|
4549
4549
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
4550
|
-
skipDuplicates:
|
|
4550
|
+
skipDuplicates: import_v4.z.boolean().optional()
|
|
4551
4551
|
}).strict();
|
|
4552
4552
|
}
|
|
4553
4553
|
// #endregion
|
|
4554
4554
|
// #region Update
|
|
4555
4555
|
makeUpdateSchema(model) {
|
|
4556
|
-
const schema =
|
|
4556
|
+
const schema = import_v4.z.object({
|
|
4557
4557
|
where: this.makeWhereSchema(model, true),
|
|
4558
4558
|
data: this.makeUpdateDataSchema(model),
|
|
4559
4559
|
select: this.makeSelectSchema(model).optional(),
|
|
@@ -4563,22 +4563,22 @@ var InputValidator = class {
|
|
|
4563
4563
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4564
4564
|
}
|
|
4565
4565
|
makeUpdateManySchema(model) {
|
|
4566
|
-
return
|
|
4566
|
+
return import_v4.z.object({
|
|
4567
4567
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4568
4568
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
4569
|
-
limit:
|
|
4569
|
+
limit: import_v4.z.number().int().nonnegative().optional()
|
|
4570
4570
|
}).strict();
|
|
4571
4571
|
}
|
|
4572
4572
|
makeUpdateManyAndReturnSchema(model) {
|
|
4573
4573
|
const base = this.makeUpdateManySchema(model);
|
|
4574
|
-
const result = base.merge(
|
|
4574
|
+
const result = base.merge(import_v4.z.object({
|
|
4575
4575
|
select: this.makeSelectSchema(model).optional(),
|
|
4576
4576
|
omit: this.makeOmitSchema(model).optional()
|
|
4577
4577
|
}));
|
|
4578
4578
|
return this.refineForSelectOmitMutuallyExclusive(result);
|
|
4579
4579
|
}
|
|
4580
4580
|
makeUpsertSchema(model) {
|
|
4581
|
-
const schema =
|
|
4581
|
+
const schema = import_v4.z.object({
|
|
4582
4582
|
where: this.makeWhereSchema(model, true),
|
|
4583
4583
|
create: this.makeCreateDataSchema(model, false),
|
|
4584
4584
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -4611,7 +4611,7 @@ var InputValidator = class {
|
|
|
4611
4611
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
4612
4612
|
}
|
|
4613
4613
|
}
|
|
4614
|
-
let fieldSchema =
|
|
4614
|
+
let fieldSchema = import_v4.z.lazy(() => this.makeRelationManipulationSchema(fieldDef, excludeFields, "update")).optional();
|
|
4615
4615
|
if (fieldDef.optional && !fieldDef.array) {
|
|
4616
4616
|
fieldSchema = fieldSchema.nullable();
|
|
4617
4617
|
}
|
|
@@ -4619,22 +4619,22 @@ var InputValidator = class {
|
|
|
4619
4619
|
} else {
|
|
4620
4620
|
let fieldSchema = this.makePrimitiveSchema(fieldDef.type).optional();
|
|
4621
4621
|
if (this.isNumericField(fieldDef)) {
|
|
4622
|
-
fieldSchema =
|
|
4622
|
+
fieldSchema = import_v4.z.union([
|
|
4623
4623
|
fieldSchema,
|
|
4624
|
-
|
|
4625
|
-
set: this.nullableIf(
|
|
4626
|
-
increment:
|
|
4627
|
-
decrement:
|
|
4628
|
-
multiply:
|
|
4629
|
-
divide:
|
|
4624
|
+
import_v4.z.object({
|
|
4625
|
+
set: this.nullableIf(import_v4.z.number().optional(), !!fieldDef.optional),
|
|
4626
|
+
increment: import_v4.z.number().optional(),
|
|
4627
|
+
decrement: import_v4.z.number().optional(),
|
|
4628
|
+
multiply: import_v4.z.number().optional(),
|
|
4629
|
+
divide: import_v4.z.number().optional()
|
|
4630
4630
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
4631
4631
|
]);
|
|
4632
4632
|
}
|
|
4633
4633
|
if (fieldDef.array) {
|
|
4634
|
-
fieldSchema =
|
|
4634
|
+
fieldSchema = import_v4.z.union([
|
|
4635
4635
|
fieldSchema.array(),
|
|
4636
|
-
|
|
4637
|
-
set:
|
|
4636
|
+
import_v4.z.object({
|
|
4637
|
+
set: import_v4.z.array(fieldSchema).optional(),
|
|
4638
4638
|
push: this.orArray(fieldSchema, true).optional()
|
|
4639
4639
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "push" can be provided')
|
|
4640
4640
|
]).optional();
|
|
@@ -4649,18 +4649,18 @@ var InputValidator = class {
|
|
|
4649
4649
|
}
|
|
4650
4650
|
});
|
|
4651
4651
|
if (!hasRelation) {
|
|
4652
|
-
return
|
|
4652
|
+
return import_v4.z.object(regularAndFkFields).strict();
|
|
4653
4653
|
} else {
|
|
4654
|
-
return
|
|
4655
|
-
|
|
4656
|
-
|
|
4654
|
+
return import_v4.z.union([
|
|
4655
|
+
import_v4.z.object(regularAndFkFields).strict(),
|
|
4656
|
+
import_v4.z.object(regularAndRelationFields).strict()
|
|
4657
4657
|
]);
|
|
4658
4658
|
}
|
|
4659
4659
|
}
|
|
4660
4660
|
// #endregion
|
|
4661
4661
|
// #region Delete
|
|
4662
4662
|
makeDeleteSchema(model) {
|
|
4663
|
-
const schema =
|
|
4663
|
+
const schema = import_v4.z.object({
|
|
4664
4664
|
where: this.makeWhereSchema(model, true),
|
|
4665
4665
|
select: this.makeSelectSchema(model).optional(),
|
|
4666
4666
|
include: this.makeIncludeSchema(model).optional()
|
|
@@ -4668,30 +4668,30 @@ var InputValidator = class {
|
|
|
4668
4668
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
4669
4669
|
}
|
|
4670
4670
|
makeDeleteManySchema(model) {
|
|
4671
|
-
return
|
|
4671
|
+
return import_v4.z.object({
|
|
4672
4672
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4673
|
-
limit:
|
|
4673
|
+
limit: import_v4.z.number().int().nonnegative().optional()
|
|
4674
4674
|
}).strict().optional();
|
|
4675
4675
|
}
|
|
4676
4676
|
// #endregion
|
|
4677
4677
|
// #region Count
|
|
4678
4678
|
makeCountSchema(model) {
|
|
4679
|
-
return
|
|
4679
|
+
return import_v4.z.object({
|
|
4680
4680
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4681
|
-
skip:
|
|
4682
|
-
take:
|
|
4681
|
+
skip: import_v4.z.number().int().nonnegative().optional(),
|
|
4682
|
+
take: import_v4.z.number().int().optional(),
|
|
4683
4683
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
4684
4684
|
select: this.makeCountAggregateInputSchema(model).optional()
|
|
4685
4685
|
}).strict().optional();
|
|
4686
4686
|
}
|
|
4687
4687
|
makeCountAggregateInputSchema(model) {
|
|
4688
4688
|
const modelDef = requireModel(this.schema, model);
|
|
4689
|
-
return
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
_all:
|
|
4689
|
+
return import_v4.z.union([
|
|
4690
|
+
import_v4.z.literal(true),
|
|
4691
|
+
import_v4.z.object({
|
|
4692
|
+
_all: import_v4.z.literal(true).optional(),
|
|
4693
4693
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4694
|
-
acc[field] =
|
|
4694
|
+
acc[field] = import_v4.z.literal(true).optional();
|
|
4695
4695
|
return acc;
|
|
4696
4696
|
}, {})
|
|
4697
4697
|
}).strict()
|
|
@@ -4700,10 +4700,10 @@ var InputValidator = class {
|
|
|
4700
4700
|
// #endregion
|
|
4701
4701
|
// #region Aggregate
|
|
4702
4702
|
makeAggregateSchema(model) {
|
|
4703
|
-
return
|
|
4703
|
+
return import_v4.z.object({
|
|
4704
4704
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4705
|
-
skip:
|
|
4706
|
-
take:
|
|
4705
|
+
skip: import_v4.z.number().int().nonnegative().optional(),
|
|
4706
|
+
take: import_v4.z.number().int().optional(),
|
|
4707
4707
|
orderBy: this.orArray(this.makeOrderBySchema(model, true, false), true).optional(),
|
|
4708
4708
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
4709
4709
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
@@ -4714,20 +4714,20 @@ var InputValidator = class {
|
|
|
4714
4714
|
}
|
|
4715
4715
|
makeSumAvgInputSchema(model) {
|
|
4716
4716
|
const modelDef = requireModel(this.schema, model);
|
|
4717
|
-
return
|
|
4717
|
+
return import_v4.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4718
4718
|
const fieldDef = requireField(this.schema, model, field);
|
|
4719
4719
|
if (this.isNumericField(fieldDef)) {
|
|
4720
|
-
acc[field] =
|
|
4720
|
+
acc[field] = import_v4.z.literal(true).optional();
|
|
4721
4721
|
}
|
|
4722
4722
|
return acc;
|
|
4723
4723
|
}, {}));
|
|
4724
4724
|
}
|
|
4725
4725
|
makeMinMaxInputSchema(model) {
|
|
4726
4726
|
const modelDef = requireModel(this.schema, model);
|
|
4727
|
-
return
|
|
4727
|
+
return import_v4.z.object(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
4728
4728
|
const fieldDef = requireField(this.schema, model, field);
|
|
4729
4729
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
4730
|
-
acc[field] =
|
|
4730
|
+
acc[field] = import_v4.z.literal(true).optional();
|
|
4731
4731
|
}
|
|
4732
4732
|
return acc;
|
|
4733
4733
|
}, {}));
|
|
@@ -4735,13 +4735,13 @@ var InputValidator = class {
|
|
|
4735
4735
|
makeGroupBySchema(model) {
|
|
4736
4736
|
const modelDef = requireModel(this.schema, model);
|
|
4737
4737
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
4738
|
-
let schema =
|
|
4738
|
+
let schema = import_v4.z.object({
|
|
4739
4739
|
where: this.makeWhereSchema(model, false).optional(),
|
|
4740
4740
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
4741
|
-
by: this.orArray(
|
|
4741
|
+
by: this.orArray(import_v4.z.enum(nonRelationFields), true),
|
|
4742
4742
|
having: this.makeWhereSchema(model, false, true).optional(),
|
|
4743
|
-
skip:
|
|
4744
|
-
take:
|
|
4743
|
+
skip: import_v4.z.number().int().nonnegative().optional(),
|
|
4744
|
+
take: import_v4.z.number().int().optional(),
|
|
4745
4745
|
_count: this.makeCountAggregateInputSchema(model).optional(),
|
|
4746
4746
|
_avg: this.makeSumAvgInputSchema(model).optional(),
|
|
4747
4747
|
_sum: this.makeSumAvgInputSchema(model).optional(),
|
|
@@ -4782,9 +4782,9 @@ var InputValidator = class {
|
|
|
4782
4782
|
return nullable ? schema.nullable() : schema;
|
|
4783
4783
|
}
|
|
4784
4784
|
orArray(schema, canBeArray) {
|
|
4785
|
-
return canBeArray ?
|
|
4785
|
+
return canBeArray ? import_v4.z.union([
|
|
4786
4786
|
schema,
|
|
4787
|
-
|
|
4787
|
+
import_v4.z.array(schema)
|
|
4788
4788
|
]) : schema;
|
|
4789
4789
|
}
|
|
4790
4790
|
isNumericField(fieldDef) {
|
|
@@ -4958,11 +4958,11 @@ var QueryNameMapper = class extends import_kysely12.OperationNodeTransformer {
|
|
|
4958
4958
|
__name(this, "QueryNameMapper");
|
|
4959
4959
|
}
|
|
4960
4960
|
schema;
|
|
4961
|
-
modelToTableMap;
|
|
4962
|
-
fieldToColumnMap;
|
|
4963
|
-
modelStack;
|
|
4961
|
+
modelToTableMap = /* @__PURE__ */ new Map();
|
|
4962
|
+
fieldToColumnMap = /* @__PURE__ */ new Map();
|
|
4963
|
+
modelStack = [];
|
|
4964
4964
|
constructor(schema) {
|
|
4965
|
-
super(), this.schema = schema
|
|
4965
|
+
super(), this.schema = schema;
|
|
4966
4966
|
for (const [modelName, modelDef] of Object.entries(schema.models)) {
|
|
4967
4967
|
const mappedName = this.getMappedName(modelDef);
|
|
4968
4968
|
if (mappedName) {
|
|
@@ -5419,8 +5419,8 @@ __export(functions_exports, {
|
|
|
5419
5419
|
search: () => search,
|
|
5420
5420
|
startsWith: () => startsWith
|
|
5421
5421
|
});
|
|
5422
|
+
var import_common_helpers9 = require("@zenstackhq/common-helpers");
|
|
5422
5423
|
var import_kysely14 = require("kysely");
|
|
5423
|
-
var import_tiny_invariant8 = __toESM(require("tiny-invariant"), 1);
|
|
5424
5424
|
var import_ts_pattern16 = require("ts-pattern");
|
|
5425
5425
|
var contains = /* @__PURE__ */ __name((eb, args) => {
|
|
5426
5426
|
const [field, search2, caseInsensitive = false] = args;
|
|
@@ -5526,8 +5526,8 @@ var currentOperation = /* @__PURE__ */ __name((_eb, args, { operation }) => {
|
|
|
5526
5526
|
}, "currentOperation");
|
|
5527
5527
|
function processCasing(casing, result, model) {
|
|
5528
5528
|
const opNode = casing.toOperationNode();
|
|
5529
|
-
(0,
|
|
5530
|
-
result = (0, import_ts_pattern16.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () =>
|
|
5529
|
+
(0, import_common_helpers9.invariant)(import_kysely14.ValueNode.is(opNode) && typeof opNode.value === "string", '"casting" parameter must be a string value');
|
|
5530
|
+
result = (0, import_ts_pattern16.match)(opNode.value).with("original", () => model).with("upper", () => result.toUpperCase()).with("lower", () => result.toLowerCase()).with("capitalize", () => (0, import_common_helpers9.upperCaseFirst)(result)).with("uncapitalize", () => (0, import_common_helpers9.lowerCaseFirst)(result)).otherwise(() => {
|
|
5531
5531
|
throw new Error(`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`);
|
|
5532
5532
|
});
|
|
5533
5533
|
return result;
|
|
@@ -5535,8 +5535,8 @@ function processCasing(casing, result, model) {
|
|
|
5535
5535
|
__name(processCasing, "processCasing");
|
|
5536
5536
|
|
|
5537
5537
|
// src/client/helpers/schema-db-pusher.ts
|
|
5538
|
+
var import_common_helpers10 = require("@zenstackhq/common-helpers");
|
|
5538
5539
|
var import_kysely15 = require("kysely");
|
|
5539
|
-
var import_tiny_invariant9 = __toESM(require("tiny-invariant"), 1);
|
|
5540
5540
|
var import_ts_pattern17 = require("ts-pattern");
|
|
5541
5541
|
var SchemaDbPusher = class {
|
|
5542
5542
|
static {
|
|
@@ -5568,7 +5568,7 @@ var SchemaDbPusher = class {
|
|
|
5568
5568
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
5569
5569
|
if (fieldDef.relation) {
|
|
5570
5570
|
table = this.addForeignKeyConstraint(table, model, fieldName, fieldDef);
|
|
5571
|
-
} else {
|
|
5571
|
+
} else if (!this.isComputedField(fieldDef)) {
|
|
5572
5572
|
table = this.createModelField(table, fieldName, fieldDef, modelDef);
|
|
5573
5573
|
}
|
|
5574
5574
|
}
|
|
@@ -5576,6 +5576,9 @@ var SchemaDbPusher = class {
|
|
|
5576
5576
|
table = this.addUniqueConstraint(table, modelDef);
|
|
5577
5577
|
return table;
|
|
5578
5578
|
}
|
|
5579
|
+
isComputedField(fieldDef) {
|
|
5580
|
+
return fieldDef.attributes?.some((a) => a.name === "@computed");
|
|
5581
|
+
}
|
|
5579
5582
|
addPrimaryKeyConstraint(table, model, modelDef) {
|
|
5580
5583
|
if (modelDef.idFields.length === 1) {
|
|
5581
5584
|
if (Object.values(modelDef.fields).some((f) => f.id)) {
|
|
@@ -5589,7 +5592,7 @@ var SchemaDbPusher = class {
|
|
|
5589
5592
|
}
|
|
5590
5593
|
addUniqueConstraint(table, modelDef) {
|
|
5591
5594
|
for (const [key, value] of Object.entries(modelDef.uniqueFields)) {
|
|
5592
|
-
(0,
|
|
5595
|
+
(0, import_common_helpers10.invariant)(typeof value === "object", "expecting an object");
|
|
5593
5596
|
if ("type" in value) {
|
|
5594
5597
|
const fieldDef = modelDef.fields[key];
|
|
5595
5598
|
if (fieldDef.unique) {
|
|
@@ -5648,7 +5651,7 @@ var SchemaDbPusher = class {
|
|
|
5648
5651
|
return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
|
|
5649
5652
|
}
|
|
5650
5653
|
addForeignKeyConstraint(table, model, fieldName, fieldDef) {
|
|
5651
|
-
(0,
|
|
5654
|
+
(0, import_common_helpers10.invariant)(fieldDef.relation, "field must be a relation");
|
|
5652
5655
|
if (!fieldDef.relation.fields || !fieldDef.relation.references) {
|
|
5653
5656
|
return table;
|
|
5654
5657
|
}
|
|
@@ -5702,8 +5705,8 @@ function valueToPromise(thing) {
|
|
|
5702
5705
|
__name(valueToPromise, "valueToPromise");
|
|
5703
5706
|
|
|
5704
5707
|
// src/client/result-processor.ts
|
|
5708
|
+
var import_common_helpers11 = require("@zenstackhq/common-helpers");
|
|
5705
5709
|
var import_decimal2 = __toESM(require("decimal.js"), 1);
|
|
5706
|
-
var import_tiny_invariant10 = __toESM(require("tiny-invariant"), 1);
|
|
5707
5710
|
var import_ts_pattern18 = require("ts-pattern");
|
|
5708
5711
|
var ResultProcessor = class {
|
|
5709
5712
|
static {
|
|
@@ -5783,14 +5786,14 @@ var ResultProcessor = class {
|
|
|
5783
5786
|
if (value instanceof import_decimal2.default) {
|
|
5784
5787
|
return value;
|
|
5785
5788
|
}
|
|
5786
|
-
(0,
|
|
5789
|
+
(0, import_common_helpers11.invariant)(typeof value === "string" || typeof value === "number" || value instanceof import_decimal2.default, `Expected string, number or Decimal, got ${typeof value}`);
|
|
5787
5790
|
return new import_decimal2.default(value);
|
|
5788
5791
|
}
|
|
5789
5792
|
transformBigInt(value) {
|
|
5790
5793
|
if (typeof value === "bigint") {
|
|
5791
5794
|
return value;
|
|
5792
5795
|
}
|
|
5793
|
-
(0,
|
|
5796
|
+
(0, import_common_helpers11.invariant)(typeof value === "string" || typeof value === "number", `Expected string or number, got ${typeof value}`);
|
|
5794
5797
|
return BigInt(value);
|
|
5795
5798
|
}
|
|
5796
5799
|
transformBoolean(value) {
|
|
@@ -5937,12 +5940,19 @@ var ClientImpl = class _ClientImpl {
|
|
|
5937
5940
|
const newOptions = {
|
|
5938
5941
|
...this.options,
|
|
5939
5942
|
plugins: [
|
|
5940
|
-
...this.options
|
|
5943
|
+
...this.options.plugins ?? [],
|
|
5941
5944
|
plugin
|
|
5942
5945
|
]
|
|
5943
5946
|
};
|
|
5944
5947
|
return new _ClientImpl(this.schema, newOptions, this);
|
|
5945
5948
|
}
|
|
5949
|
+
$unuse(pluginId) {
|
|
5950
|
+
const newOptions = {
|
|
5951
|
+
...this.options,
|
|
5952
|
+
plugins: this.options.plugins?.filter((p) => p.id !== pluginId)
|
|
5953
|
+
};
|
|
5954
|
+
return new _ClientImpl(this.schema, newOptions, this);
|
|
5955
|
+
}
|
|
5946
5956
|
$unuseAll() {
|
|
5947
5957
|
const newOptions = {
|
|
5948
5958
|
...this.options,
|
|
@@ -5998,22 +6008,31 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
5998
6008
|
}
|
|
5999
6009
|
return result;
|
|
6000
6010
|
}, "proceed");
|
|
6001
|
-
const context = {
|
|
6002
|
-
client,
|
|
6003
|
-
model,
|
|
6004
|
-
operation,
|
|
6005
|
-
queryArgs: args
|
|
6006
|
-
};
|
|
6007
6011
|
const plugins = [
|
|
6008
6012
|
...client.$options.plugins ?? []
|
|
6009
6013
|
];
|
|
6010
6014
|
for (const plugin of plugins) {
|
|
6011
|
-
if (plugin.onQuery) {
|
|
6012
|
-
const
|
|
6013
|
-
|
|
6014
|
-
|
|
6015
|
-
|
|
6016
|
-
|
|
6015
|
+
if (plugin.onQuery && typeof plugin.onQuery === "object") {
|
|
6016
|
+
for (const [_model, modelHooks] of Object.entries(plugin.onQuery)) {
|
|
6017
|
+
if (_model === (0, import_common_helpers12.lowerCaseFirst)(model) || _model === "$allModels") {
|
|
6018
|
+
if (modelHooks && typeof modelHooks === "object") {
|
|
6019
|
+
for (const [op, opHooks] of Object.entries(modelHooks)) {
|
|
6020
|
+
if (op === operation || op === "$allOperations") {
|
|
6021
|
+
if (typeof opHooks === "function") {
|
|
6022
|
+
const _proceed = proceed;
|
|
6023
|
+
proceed = /* @__PURE__ */ __name(() => opHooks({
|
|
6024
|
+
client,
|
|
6025
|
+
model,
|
|
6026
|
+
operation,
|
|
6027
|
+
args,
|
|
6028
|
+
query: _proceed
|
|
6029
|
+
}), "proceed");
|
|
6030
|
+
}
|
|
6031
|
+
}
|
|
6032
|
+
}
|
|
6033
|
+
}
|
|
6034
|
+
}
|
|
6035
|
+
}
|
|
6017
6036
|
}
|
|
6018
6037
|
}
|
|
6019
6038
|
return proceed(args);
|
|
@@ -6074,11 +6093,18 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6074
6093
|
};
|
|
6075
6094
|
}
|
|
6076
6095
|
__name(createModelCrudHandler, "createModelCrudHandler");
|
|
6096
|
+
|
|
6097
|
+
// src/client/plugin.ts
|
|
6098
|
+
function definePlugin(plugin) {
|
|
6099
|
+
return plugin;
|
|
6100
|
+
}
|
|
6101
|
+
__name(definePlugin, "definePlugin");
|
|
6077
6102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6078
6103
|
0 && (module.exports = {
|
|
6079
6104
|
InternalError,
|
|
6080
6105
|
NotFoundError,
|
|
6081
6106
|
QueryError,
|
|
6082
|
-
ZenStackClient
|
|
6107
|
+
ZenStackClient,
|
|
6108
|
+
definePlugin
|
|
6083
6109
|
});
|
|
6084
6110
|
//# sourceMappingURL=client.cjs.map
|