@zenstackhq/orm 3.6.4 → 3.7.0
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/common-types.cjs +23 -0
- package/dist/common-types.cjs.map +1 -0
- package/dist/common-types.d.cts +25 -0
- package/dist/common-types.d.mts +25 -0
- package/dist/common-types.mjs +17 -0
- package/dist/common-types.mjs.map +1 -0
- package/dist/index.cjs +408 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +364 -69
- package/dist/index.d.mts +366 -71
- package/dist/index.mjs +534 -239
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -10
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
|
|
2
|
+
import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonNull, JsonNullClass } from "./common-types.mjs";
|
|
2
3
|
import { clone, enumerate, invariant, isPlainObject, lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
|
|
3
4
|
import { AliasNode, AndNode, ColumnNode, ColumnUpdateNode, CompiledQuery, DefaultConnectionProvider, DefaultQueryExecutor, DeleteQueryNode, ExpressionWrapper, FromNode, IdentifierNode, InsertQueryNode, Kysely, Log, OperationNodeTransformer, OperationNodeVisitor, PrimitiveValueListNode, ReferenceNode, ReturningNode, SelectAllNode, SelectionNode, SingleConnectionProvider, TableNode, Transaction, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode, WhereNode, createQueryId, expressionBuilder, sql } from "kysely";
|
|
4
|
-
import z, { ZodObject, ZodType, z
|
|
5
|
+
import z$1, { ZodObject, ZodType, z } from "zod";
|
|
5
6
|
import { fromError } from "zod-validation-error/v4";
|
|
6
7
|
import { P, match } from "ts-pattern";
|
|
7
8
|
import { ExpressionUtils } from "@zenstackhq/schema";
|
|
@@ -530,6 +531,8 @@ const FILTER_PROPERTY_TO_KIND = {
|
|
|
530
531
|
array_contains: "Json",
|
|
531
532
|
array_starts_with: "Json",
|
|
532
533
|
array_ends_with: "Json",
|
|
534
|
+
fuzzy: "Fuzzy",
|
|
535
|
+
fts: "FullText",
|
|
533
536
|
has: "List",
|
|
534
537
|
hasEvery: "List",
|
|
535
538
|
hasSome: "List",
|
|
@@ -549,6 +552,19 @@ let TransactionIsolationLevel = /* @__PURE__ */ function(TransactionIsolationLev
|
|
|
549
552
|
return TransactionIsolationLevel;
|
|
550
553
|
}({});
|
|
551
554
|
/**
|
|
555
|
+
* Symbol used as a type-only key on `ClientContract` to brand the `ExtQueryArgs`
|
|
556
|
+
* generic slot. Hidden from member-access autocomplete since symbol keys are
|
|
557
|
+
* not surfaced. Consumed by `InferExtQueryArgs` to recover the slot.
|
|
558
|
+
* @internal
|
|
559
|
+
*/
|
|
560
|
+
const ExtQueryArgsMarker = Symbol("zenstack.client.extQueryArgs");
|
|
561
|
+
/**
|
|
562
|
+
* Symbol used as a type-only key on `ClientContract` to brand the `ExtResult`
|
|
563
|
+
* generic slot. Consumed by `InferExtResult` to recover the slot.
|
|
564
|
+
* @internal
|
|
565
|
+
*/
|
|
566
|
+
const ExtResultMarker = Symbol("zenstack.client.extResult");
|
|
567
|
+
/**
|
|
552
568
|
* CRUD operations.
|
|
553
569
|
*/
|
|
554
570
|
const CRUD = [
|
|
@@ -562,20 +578,6 @@ const CRUD = [
|
|
|
562
578
|
*/
|
|
563
579
|
const CRUD_EXT = [...CRUD, "post-update"];
|
|
564
580
|
//#endregion
|
|
565
|
-
//#region src/common-types.ts
|
|
566
|
-
var DbNullClass = class {
|
|
567
|
-
__brand = "DbNull";
|
|
568
|
-
};
|
|
569
|
-
const DbNull = new DbNullClass();
|
|
570
|
-
var JsonNullClass = class {
|
|
571
|
-
__brand = "JsonNull";
|
|
572
|
-
};
|
|
573
|
-
const JsonNull = new JsonNullClass();
|
|
574
|
-
var AnyNullClass = class {
|
|
575
|
-
__brand = "AnyNull";
|
|
576
|
-
};
|
|
577
|
-
const AnyNull = new AnyNullClass();
|
|
578
|
-
//#endregion
|
|
579
581
|
//#region src/client/crud/dialects/base-dialect.ts
|
|
580
582
|
var BaseCrudDialect = class {
|
|
581
583
|
eb = expressionBuilder();
|
|
@@ -585,8 +587,13 @@ var BaseCrudDialect = class {
|
|
|
585
587
|
}
|
|
586
588
|
/**
|
|
587
589
|
* Transforms input value before sending to database.
|
|
590
|
+
*
|
|
591
|
+
* `fieldDef` is optional so existing callers that don't have it stay
|
|
592
|
+
* source-compatible. Dialects can use it to inspect `@db.*` native-type
|
|
593
|
+
* attributes (e.g. to format `@db.Time` values as `HH:MM:SS` rather than
|
|
594
|
+
* full ISO timestamps).
|
|
588
595
|
*/
|
|
589
|
-
transformInput(value, _type, _forArrayField) {
|
|
596
|
+
transformInput(value, _type, _forArrayField, _fieldDef) {
|
|
590
597
|
return value;
|
|
591
598
|
}
|
|
592
599
|
/**
|
|
@@ -629,7 +636,17 @@ var BaseCrudDialect = class {
|
|
|
629
636
|
if (existingOrderBy.length > 0 && !alreadySatisfied) effectiveOrderBy = [...distinctFields.map((f) => ({ [f]: "asc" })), ...existingOrderBy];
|
|
630
637
|
}
|
|
631
638
|
result = this.buildOrderBy(result, model, modelAlias, effectiveOrderBy, negateOrderBy, take);
|
|
632
|
-
if (args.cursor)
|
|
639
|
+
if (args.cursor) {
|
|
640
|
+
if (effectiveOrderBy) {
|
|
641
|
+
const offendingKey = enumerate(effectiveOrderBy).map((ob) => {
|
|
642
|
+
if (typeof ob !== "object" || ob === null) return void 0;
|
|
643
|
+
if ("_fuzzyRelevance" in ob) return "_fuzzyRelevance";
|
|
644
|
+
if ("_ftsRelevance" in ob) return "_ftsRelevance";
|
|
645
|
+
}).find((k) => k !== void 0);
|
|
646
|
+
if (offendingKey) throw createNotSupportedError(`cursor pagination cannot be combined with "${offendingKey}" ordering`);
|
|
647
|
+
}
|
|
648
|
+
result = this.buildCursorFilter(model, result, args.cursor, effectiveOrderBy, negateOrderBy, modelAlias);
|
|
649
|
+
}
|
|
633
650
|
return result;
|
|
634
651
|
}
|
|
635
652
|
buildFilter(model, modelAlias, where) {
|
|
@@ -769,7 +786,7 @@ var BaseCrudDialect = class {
|
|
|
769
786
|
for (const [key, _value] of Object.entries(payload)) {
|
|
770
787
|
if (_value === void 0) continue;
|
|
771
788
|
invariant(fieldDef.array, "Field must be an array type to build array filter");
|
|
772
|
-
const value = this.transformInput(_value, fieldType, true);
|
|
789
|
+
const value = this.transformInput(_value, fieldType, true, fieldDef);
|
|
773
790
|
let receiver = fieldRef;
|
|
774
791
|
if (isEnum(this.schema, fieldType)) receiver = this.eb.cast(fieldRef, sql.raw("text[]"));
|
|
775
792
|
const buildArray = (value) => {
|
|
@@ -804,7 +821,7 @@ var BaseCrudDialect = class {
|
|
|
804
821
|
if (payload instanceof DbNullClass || payload instanceof JsonNullClass || payload instanceof AnyNullClass) return this.buildJsonValueFilterClause(fieldRef, payload);
|
|
805
822
|
return this.buildJsonFilter(fieldRef, payload, fieldDef);
|
|
806
823
|
}
|
|
807
|
-
return match(fieldDef.type).with("String", () => this.buildStringFilter(fieldRef, payload)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.buildNumberFilter(fieldRef, type, payload)).with("Boolean", () => this.buildBooleanFilter(fieldRef, payload)).with("DateTime", () => this.buildDateTimeFilter(fieldRef, payload)).with("Bytes", () => this.buildBytesFilter(fieldRef, payload)).with("Json", () => this.buildJsonFilter(fieldRef, payload, fieldDef)).with("Unsupported", () => {
|
|
824
|
+
return match(fieldDef.type).with("String", () => this.buildStringFilter(fieldRef, payload, fieldDef)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.buildNumberFilter(fieldRef, type, payload)).with("Boolean", () => this.buildBooleanFilter(fieldRef, payload)).with("DateTime", () => this.buildDateTimeFilter(fieldRef, payload)).with("Bytes", () => this.buildBytesFilter(fieldRef, payload)).with("Json", () => this.buildJsonFilter(fieldRef, payload, fieldDef)).with("Unsupported", () => {
|
|
808
825
|
throw createInvalidInputError(`Unsupported field cannot be used in filters`);
|
|
809
826
|
}).exhaustive();
|
|
810
827
|
}
|
|
@@ -972,13 +989,23 @@ var BaseCrudDialect = class {
|
|
|
972
989
|
consumedKeys
|
|
973
990
|
};
|
|
974
991
|
}
|
|
975
|
-
buildStringFilter(fieldRef, payload) {
|
|
992
|
+
buildStringFilter(fieldRef, payload, fieldDef) {
|
|
976
993
|
let mode;
|
|
977
994
|
if (payload && typeof payload === "object" && "mode" in payload) mode = payload.mode;
|
|
978
|
-
const { conditions, consumedKeys } = this.buildStandardFilter("String", payload, mode === "insensitive" ? this.eb.fn("lower", [fieldRef]) : fieldRef, (value) => this.prepStringCasing(this.eb, value, mode), (value) => this.buildStringFilter(fieldRef, value));
|
|
995
|
+
const { conditions, consumedKeys } = this.buildStandardFilter("String", payload, mode === "insensitive" ? this.eb.fn("lower", [fieldRef]) : fieldRef, (value) => this.prepStringCasing(this.eb, value, mode), (value) => this.buildStringFilter(fieldRef, value, fieldDef));
|
|
979
996
|
if (payload && typeof payload === "object") for (const [key, value] of Object.entries(payload)) {
|
|
980
997
|
if (key === "mode" || consumedKeys.includes(key)) continue;
|
|
981
998
|
if (value === void 0) continue;
|
|
999
|
+
if (key === "fuzzy") {
|
|
1000
|
+
invariant(fieldDef?.fuzzy === true, `field "${fieldDef?.name ?? "<unknown>"}" is not fuzzy-searchable; add the \`@fuzzy\` attribute to use the \`fuzzy\` filter`);
|
|
1001
|
+
conditions.push(this.buildFuzzyFilter(fieldRef, this.normalizeFuzzyOptions(value)));
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
if (key === "fts") {
|
|
1005
|
+
invariant(fieldDef?.fullText === true, `field "${fieldDef?.name ?? "<unknown>"}" is not full-text-searchable; add the \`@fullText\` attribute to use the \`fts\` filter`);
|
|
1006
|
+
conditions.push(this.buildFullTextFilter(fieldRef, value));
|
|
1007
|
+
continue;
|
|
1008
|
+
}
|
|
982
1009
|
invariant(typeof value === "string", `${key} value must be a string`);
|
|
983
1010
|
const escapedValue = this.escapeLikePattern(value);
|
|
984
1011
|
const condition = match(key).with("contains", () => this.buildStringLike(fieldRef, `%${escapedValue}%`, mode === "insensitive")).with("startsWith", () => this.buildStringLike(fieldRef, `${escapedValue}%`, mode === "insensitive")).with("endsWith", () => this.buildStringLike(fieldRef, `%${escapedValue}`, mode === "insensitive")).otherwise(() => {
|
|
@@ -1047,6 +1074,14 @@ var BaseCrudDialect = class {
|
|
|
1047
1074
|
enumerate(orderBy).forEach((orderBy, index) => {
|
|
1048
1075
|
for (const [field, value] of Object.entries(orderBy)) {
|
|
1049
1076
|
if (!value) continue;
|
|
1077
|
+
if (field === "_fuzzyRelevance") {
|
|
1078
|
+
result = this.applyFuzzyRelevanceOrderBy(result, model, modelAlias, value, negated, buildFieldRef);
|
|
1079
|
+
continue;
|
|
1080
|
+
}
|
|
1081
|
+
if (field === "_ftsRelevance") {
|
|
1082
|
+
result = this.applyFtsRelevanceOrderBy(result, model, modelAlias, value, negated, buildFieldRef);
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1050
1085
|
if ([
|
|
1051
1086
|
"_count",
|
|
1052
1087
|
"_avg",
|
|
@@ -1054,47 +1089,84 @@ var BaseCrudDialect = class {
|
|
|
1054
1089
|
"_min",
|
|
1055
1090
|
"_max"
|
|
1056
1091
|
].includes(field)) {
|
|
1057
|
-
|
|
1058
|
-
for (const [k, v] of Object.entries(value)) {
|
|
1059
|
-
invariant(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
1060
|
-
result = result.orderBy((eb) => aggregate(eb, buildFieldRef(model, k, modelAlias), field), this.negateSort(v, negated));
|
|
1061
|
-
}
|
|
1092
|
+
result = this.applyAggregationOrderBy(result, model, modelAlias, field, value, negated, buildFieldRef);
|
|
1062
1093
|
continue;
|
|
1063
1094
|
}
|
|
1064
1095
|
const fieldDef = requireField(this.schema, model, field);
|
|
1065
|
-
if (!fieldDef.relation)
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
const joinAlias = tmpAlias(`${modelAlias}$ob$${index}`);
|
|
1087
|
-
result = result.leftJoin(`${relationModel} as ${joinAlias}`, (join) => {
|
|
1088
|
-
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, joinAlias);
|
|
1089
|
-
return join.on((eb) => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
1090
|
-
});
|
|
1091
|
-
result = this.buildOrderBy(result, relationModel, joinAlias, value, negated, take);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1096
|
+
if (!fieldDef.relation) result = this.applyScalarOrderBy(result, model, modelAlias, field, value, negated, buildFieldRef);
|
|
1097
|
+
else result = this.applyRelationOrderBy(result, model, modelAlias, field, fieldDef, value, negated, take, index);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
return result;
|
|
1101
|
+
}
|
|
1102
|
+
applyRelationOrderBy(query, model, modelAlias, field, fieldDef, value, negated, take, index) {
|
|
1103
|
+
const relationModel = fieldDef.type;
|
|
1104
|
+
if (fieldDef.array) {
|
|
1105
|
+
if (typeof value !== "object") throw createInvalidInputError(`invalid orderBy value for field "${field}"`);
|
|
1106
|
+
if ("_count" in value) {
|
|
1107
|
+
invariant(value._count === "asc" || value._count === "desc", "invalid orderBy value for field \"_count\"");
|
|
1108
|
+
const sort = this.negateSort(value._count, negated);
|
|
1109
|
+
return query.orderBy((eb) => {
|
|
1110
|
+
const subQueryAlias = tmpAlias(`${modelAlias}$ob$${field}$ct`);
|
|
1111
|
+
let subQuery = this.buildSelectModel(relationModel, subQueryAlias);
|
|
1112
|
+
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, subQueryAlias);
|
|
1113
|
+
subQuery = subQuery.where(() => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
1114
|
+
subQuery = subQuery.select(() => eb.fn.count(eb.lit(1)).as("_count"));
|
|
1115
|
+
return subQuery;
|
|
1116
|
+
}, sort);
|
|
1094
1117
|
}
|
|
1118
|
+
return query;
|
|
1119
|
+
}
|
|
1120
|
+
const joinAlias = tmpAlias(`${modelAlias}$ob$${index}`);
|
|
1121
|
+
const joined = query.leftJoin(`${relationModel} as ${joinAlias}`, (join) => {
|
|
1122
|
+
const joinPairs = buildJoinPairs(this.schema, model, modelAlias, field, joinAlias);
|
|
1123
|
+
return join.on((eb) => this.and(...joinPairs.map(([left, right]) => eb(this.eb.ref(left), "=", this.eb.ref(right)))));
|
|
1095
1124
|
});
|
|
1125
|
+
return this.buildOrderBy(joined, relationModel, joinAlias, value, negated, take);
|
|
1126
|
+
}
|
|
1127
|
+
applyScalarOrderBy(query, model, modelAlias, field, value, negated, buildFieldRef) {
|
|
1128
|
+
const fieldRef = buildFieldRef(model, field, modelAlias);
|
|
1129
|
+
if (value === "asc" || value === "desc") return query.orderBy(fieldRef, this.negateSort(value, negated));
|
|
1130
|
+
if (typeof value === "object" && "sort" in value && (value.sort === "asc" || value.sort === "desc")) {
|
|
1131
|
+
const sort = this.negateSort(value.sort, negated);
|
|
1132
|
+
if (value.nulls === "first" || value.nulls === "last") return this.buildOrderByField(query, fieldRef, sort, value.nulls);
|
|
1133
|
+
else return query.orderBy(fieldRef, sort);
|
|
1134
|
+
}
|
|
1135
|
+
return query;
|
|
1136
|
+
}
|
|
1137
|
+
applyAggregationOrderBy(query, model, modelAlias, field, value, negated, buildFieldRef) {
|
|
1138
|
+
invariant(typeof value === "object", `invalid orderBy value for field "${field}"`);
|
|
1139
|
+
let result = query;
|
|
1140
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1141
|
+
invariant(v === "asc" || v === "desc", `invalid orderBy value for field "${field}"`);
|
|
1142
|
+
result = result.orderBy((eb) => aggregate(eb, buildFieldRef(model, k, modelAlias), field), this.negateSort(v, negated));
|
|
1143
|
+
}
|
|
1096
1144
|
return result;
|
|
1097
1145
|
}
|
|
1146
|
+
applyFuzzyRelevanceOrderBy(query, model, modelAlias, value, negated, buildFieldRef) {
|
|
1147
|
+
invariant(typeof value === "object" && "fields" in value && "search" in value && "sort" in value, "invalid orderBy value for \"_fuzzyRelevance\"");
|
|
1148
|
+
invariant(Array.isArray(value.fields) && value.fields.length > 0, "_fuzzyRelevance.fields must be a non-empty array");
|
|
1149
|
+
invariant(value.sort === "asc" || value.sort === "desc", "invalid sort value for \"_fuzzyRelevance\"");
|
|
1150
|
+
invariant(typeof value.search === "string" && value.search.length > 0, "_fuzzyRelevance.search must be a non-empty string");
|
|
1151
|
+
const mode = value.mode ?? "simple";
|
|
1152
|
+
invariant(mode === "simple" || mode === "word" || mode === "strictWord", "_fuzzyRelevance.mode must be \"simple\", \"word\" or \"strictWord\"");
|
|
1153
|
+
const unaccent = value.unaccent ?? false;
|
|
1154
|
+
invariant(typeof unaccent === "boolean", "_fuzzyRelevance.unaccent must be a boolean");
|
|
1155
|
+
for (const fieldName of value.fields) invariant(requireField(this.schema, model, fieldName).fuzzy === true, `field "${fieldName}" is not fuzzy-searchable; add the \`@fuzzy\` attribute to use it in \`_fuzzyRelevance\``);
|
|
1156
|
+
const fieldRefs = value.fields.map((f) => buildFieldRef(model, f, modelAlias));
|
|
1157
|
+
return this.buildFuzzyRelevanceOrderBy(query, fieldRefs, value.search, this.negateSort(value.sort, negated), mode, unaccent);
|
|
1158
|
+
}
|
|
1159
|
+
applyFtsRelevanceOrderBy(query, model, modelAlias, value, negated, buildFieldRef) {
|
|
1160
|
+
invariant(typeof value === "object" && "fields" in value && "search" in value && "sort" in value, "invalid orderBy value for \"_ftsRelevance\"");
|
|
1161
|
+
invariant(Array.isArray(value.fields) && value.fields.length > 0, "_ftsRelevance.fields must be a non-empty array");
|
|
1162
|
+
invariant(value.sort === "asc" || value.sort === "desc", "invalid sort value for \"_ftsRelevance\"");
|
|
1163
|
+
invariant(typeof value.search === "string" && value.search.length > 0, "_ftsRelevance.search must be a non-empty string");
|
|
1164
|
+
if (value.config !== void 0) invariant(typeof value.config === "string" && value.config.length > 0, "_ftsRelevance.config must be a non-empty string");
|
|
1165
|
+
const config = value.config;
|
|
1166
|
+
for (const fieldName of value.fields) invariant(requireField(this.schema, model, fieldName).fullText === true, `field "${fieldName}" is not full-text-searchable; add the \`@fullText\` attribute to use it in \`_ftsRelevance\``);
|
|
1167
|
+
const fieldRefs = value.fields.map((f) => buildFieldRef(model, f, modelAlias));
|
|
1168
|
+
return this.buildFtsRelevanceOrderBy(query, fieldRefs, value.search, config, this.negateSort(value.sort, negated));
|
|
1169
|
+
}
|
|
1098
1170
|
buildSelectAllFields(model, query, omit, modelAlias) {
|
|
1099
1171
|
let result = query;
|
|
1100
1172
|
for (const fieldDef of getModelFields(this.schema, model, {
|
|
@@ -1237,6 +1309,27 @@ var BaseCrudDialect = class {
|
|
|
1237
1309
|
buildComparison(left, _leftFieldDef, op, right, _rightFieldDef) {
|
|
1238
1310
|
return this.eb(left, op, right);
|
|
1239
1311
|
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Validate the user-provided fuzzy filter payload and apply defaults so dialects
|
|
1314
|
+
* always receive a fully-resolved {@link FuzzyFilterOptions} value.
|
|
1315
|
+
*/
|
|
1316
|
+
normalizeFuzzyOptions(value) {
|
|
1317
|
+
invariant(value !== null && typeof value === "object" && !Array.isArray(value), "fuzzy filter must be an object with at least a \"search\" field");
|
|
1318
|
+
const raw = value;
|
|
1319
|
+
invariant(typeof raw["search"] === "string" && raw["search"].length > 0, "fuzzy.search must be a non-empty string");
|
|
1320
|
+
const mode = raw["mode"] ?? "simple";
|
|
1321
|
+
invariant(mode === "simple" || mode === "word" || mode === "strictWord", "fuzzy.mode must be \"simple\", \"word\" or \"strictWord\"");
|
|
1322
|
+
const threshold = raw["threshold"];
|
|
1323
|
+
if (threshold !== void 0) invariant(typeof threshold === "number" && threshold >= 0 && threshold <= 1, "fuzzy.threshold must be a number between 0 and 1");
|
|
1324
|
+
const unaccent = raw["unaccent"] ?? false;
|
|
1325
|
+
invariant(typeof unaccent === "boolean", "fuzzy.unaccent must be a boolean");
|
|
1326
|
+
return {
|
|
1327
|
+
search: raw["search"],
|
|
1328
|
+
mode,
|
|
1329
|
+
threshold,
|
|
1330
|
+
unaccent
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1240
1333
|
};
|
|
1241
1334
|
//#endregion
|
|
1242
1335
|
//#region src/client/crud/dialects/lateral-join-dialect-base.ts
|
|
@@ -1521,9 +1614,32 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1521
1614
|
}
|
|
1522
1615
|
return result;
|
|
1523
1616
|
}
|
|
1617
|
+
buildFuzzyFilter(_fieldRef, _options) {
|
|
1618
|
+
throw createNotSupportedError("\"fuzzy\" filter is not supported by the \"mysql\" provider");
|
|
1619
|
+
}
|
|
1620
|
+
buildFuzzyRelevanceOrderBy(_query, _fieldRefs, _search, _sort, _mode, _unaccent) {
|
|
1621
|
+
throw createNotSupportedError("\"_fuzzyRelevance\" ordering is not supported by the \"mysql\" provider");
|
|
1622
|
+
}
|
|
1623
|
+
buildFullTextFilter(_fieldRef, _payload) {
|
|
1624
|
+
throw createNotSupportedError("\"fts\" filter is not supported by the \"mysql\" provider");
|
|
1625
|
+
}
|
|
1626
|
+
buildFtsRelevanceOrderBy(_query, _fieldRefs, _search, _config, _sort) {
|
|
1627
|
+
throw createNotSupportedError("\"_ftsRelevance\" ordering is not supported by the \"mysql\" provider");
|
|
1628
|
+
}
|
|
1524
1629
|
};
|
|
1525
1630
|
//#endregion
|
|
1526
1631
|
//#region src/client/crud/dialects/postgresql.ts
|
|
1632
|
+
/**
|
|
1633
|
+
* Formats a JS `Date` as a Postgres TIME / TIMETZ literal (`HH:MM:SS.fff`,
|
|
1634
|
+
* optionally with `+ZZ:ZZ` for TIMETZ). Reads UTC components so the value
|
|
1635
|
+
* round-trips with ISO-input parsing — callers anchor time-only inputs to
|
|
1636
|
+
* the Unix epoch.
|
|
1637
|
+
*/
|
|
1638
|
+
function formatTimeOfDay(date, withTimezone) {
|
|
1639
|
+
const pad = (n, w = 2) => String(n).padStart(w, "0");
|
|
1640
|
+
const time = `${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())}.${pad(date.getUTCMilliseconds(), 3)}`;
|
|
1641
|
+
return withTimezone ? `${time}+00:00` : time;
|
|
1642
|
+
}
|
|
1527
1643
|
var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBase {
|
|
1528
1644
|
static typeParserOverrideApplied = false;
|
|
1529
1645
|
zmodelToSqlTypeMap = {
|
|
@@ -1617,7 +1733,7 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1617
1733
|
get insertIgnoreMethod() {
|
|
1618
1734
|
return "onConflict";
|
|
1619
1735
|
}
|
|
1620
|
-
transformInput(value, type, forArrayField) {
|
|
1736
|
+
transformInput(value, type, forArrayField, fieldDef) {
|
|
1621
1737
|
if (value === void 0) return value;
|
|
1622
1738
|
if (value instanceof JsonNullClass) return "null";
|
|
1623
1739
|
else if (value instanceof DbNullClass) return null;
|
|
@@ -1625,9 +1741,15 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1625
1741
|
if (isTypeDef(this.schema, type)) if (typeof value !== "string") return JSON.stringify(value);
|
|
1626
1742
|
else return value;
|
|
1627
1743
|
else if (Array.isArray(value)) if (type === "Json" && !forArrayField) return JSON.stringify(value);
|
|
1628
|
-
else return value.map((v) => this.transformInput(v, type, false));
|
|
1744
|
+
else return value.map((v) => this.transformInput(v, type, false, fieldDef));
|
|
1629
1745
|
else switch (type) {
|
|
1630
|
-
case "DateTime":
|
|
1746
|
+
case "DateTime": {
|
|
1747
|
+
const date = value instanceof Date ? value : typeof value === "string" ? new Date(value) : null;
|
|
1748
|
+
if (date === null || isNaN(date.getTime())) return value;
|
|
1749
|
+
const dbAttrName = fieldDef?.attributes?.find((a) => a.name.startsWith("@db."))?.name;
|
|
1750
|
+
if (dbAttrName === "@db.Time" || dbAttrName === "@db.Timetz") return formatTimeOfDay(date, dbAttrName === "@db.Timetz");
|
|
1751
|
+
return date.toISOString();
|
|
1752
|
+
}
|
|
1631
1753
|
case "Decimal": return value !== null ? value.toString() : value;
|
|
1632
1754
|
case "Json": if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") return JSON.stringify(value);
|
|
1633
1755
|
else return value;
|
|
@@ -1799,6 +1921,72 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1799
1921
|
return ob;
|
|
1800
1922
|
});
|
|
1801
1923
|
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Wraps an expression with `unaccent(lower(...))` or just `lower(...)` depending on
|
|
1926
|
+
* whether the user opted into accent-insensitive matching. The lowering is always
|
|
1927
|
+
* applied so trigram comparisons are case-insensitive on both sides.
|
|
1928
|
+
*/
|
|
1929
|
+
normalizeForTrigram(expr, applyUnaccent) {
|
|
1930
|
+
return applyUnaccent ? sql`unaccent(lower(${expr}))` : sql`lower(${expr})`;
|
|
1931
|
+
}
|
|
1932
|
+
buildFuzzyFilter(fieldRef, options) {
|
|
1933
|
+
const fieldExpr = this.normalizeForTrigram(fieldRef, options.unaccent);
|
|
1934
|
+
const valueExpr = this.normalizeForTrigram(sql.val(options.search), options.unaccent);
|
|
1935
|
+
if (options.threshold === void 0) switch (options.mode) {
|
|
1936
|
+
case "simple": return sql`${fieldExpr} % ${valueExpr}`;
|
|
1937
|
+
case "word": return sql`${valueExpr} <% ${fieldExpr}`;
|
|
1938
|
+
case "strictWord": return sql`${valueExpr} <<% ${fieldExpr}`;
|
|
1939
|
+
}
|
|
1940
|
+
const threshold = sql.val(options.threshold);
|
|
1941
|
+
switch (options.mode) {
|
|
1942
|
+
case "simple": return sql`similarity(${fieldExpr}, ${valueExpr}) > ${threshold}`;
|
|
1943
|
+
case "word": return sql`word_similarity(${valueExpr}, ${fieldExpr}) > ${threshold}`;
|
|
1944
|
+
case "strictWord": return sql`strict_word_similarity(${valueExpr}, ${fieldExpr}) > ${threshold}`;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
buildFuzzyRelevanceOrderBy(query, fieldRefs, search, sort, mode, unaccent) {
|
|
1948
|
+
const valueExpr = this.normalizeForTrigram(sql.val(search), unaccent);
|
|
1949
|
+
const buildSimilarity = (fieldRef) => {
|
|
1950
|
+
const fieldExpr = this.normalizeForTrigram(fieldRef, unaccent);
|
|
1951
|
+
switch (mode) {
|
|
1952
|
+
case "simple": return sql`similarity(${fieldExpr}, ${valueExpr})`;
|
|
1953
|
+
case "word": return sql`word_similarity(${valueExpr}, ${fieldExpr})`;
|
|
1954
|
+
case "strictWord": return sql`strict_word_similarity(${valueExpr}, ${fieldExpr})`;
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
if (fieldRefs.length === 1) return query.orderBy(buildSimilarity(fieldRefs[0]), sort);
|
|
1958
|
+
const similarities = fieldRefs.map((ref) => buildSimilarity(ref));
|
|
1959
|
+
return query.orderBy(sql`GREATEST(${sql.join(similarities)})`, sort);
|
|
1960
|
+
}
|
|
1961
|
+
buildFullTextFilter(fieldRef, payload) {
|
|
1962
|
+
const options = this.normalizeFullTextOptions(payload);
|
|
1963
|
+
const query = sql.val(options.search);
|
|
1964
|
+
if (options.config === void 0) return sql`to_tsvector(${fieldRef}) @@ to_tsquery(${query})`;
|
|
1965
|
+
const cfg = sql.val(options.config);
|
|
1966
|
+
return sql`to_tsvector(${cfg}::regconfig, ${fieldRef}) @@ to_tsquery(${cfg}::regconfig, ${query})`;
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Validate the user-provided `fts` filter payload. When `config` is omitted
|
|
1970
|
+
* it stays `undefined` so {@link buildFullTextFilter} can emit the no-regconfig
|
|
1971
|
+
* SQL form and let Postgres fall back to `default_text_search_config`.
|
|
1972
|
+
*/
|
|
1973
|
+
normalizeFullTextOptions(value) {
|
|
1974
|
+
invariant(value !== null && typeof value === "object" && !Array.isArray(value), "fts filter must be an object with at least a \"search\" field");
|
|
1975
|
+
const raw = value;
|
|
1976
|
+
invariant(typeof raw["search"] === "string" && raw["search"].length > 0, "fts.search must be a non-empty string");
|
|
1977
|
+
if (raw["config"] !== void 0) invariant(typeof raw["config"] === "string" && raw["config"].length > 0, "fts.config must be a non-empty string");
|
|
1978
|
+
return {
|
|
1979
|
+
search: raw["search"],
|
|
1980
|
+
config: raw["config"]
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
buildFtsRelevanceOrderBy(query, fieldRefs, search, config, sort) {
|
|
1984
|
+
const q = sql.val(search);
|
|
1985
|
+
const document = fieldRefs.length === 1 ? sql`coalesce(${fieldRefs[0]}, '')` : sql`concat_ws(' ', ${sql.join(fieldRefs)})`;
|
|
1986
|
+
if (config === void 0) return query.orderBy(sql`ts_rank(to_tsvector(${document}), to_tsquery(${q}))`, sort);
|
|
1987
|
+
const cfg = sql.val(config);
|
|
1988
|
+
return query.orderBy(sql`ts_rank(to_tsvector(${cfg}::regconfig, ${document}), to_tsquery(${cfg}::regconfig, ${q}))`, sort);
|
|
1989
|
+
}
|
|
1802
1990
|
};
|
|
1803
1991
|
//#endregion
|
|
1804
1992
|
//#region src/client/crud/dialects/sqlite.ts
|
|
@@ -2016,6 +2204,18 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2016
2204
|
return ob;
|
|
2017
2205
|
});
|
|
2018
2206
|
}
|
|
2207
|
+
buildFuzzyFilter(_fieldRef, _options) {
|
|
2208
|
+
throw createNotSupportedError("\"fuzzy\" filter is not supported by the \"sqlite\" provider");
|
|
2209
|
+
}
|
|
2210
|
+
buildFuzzyRelevanceOrderBy(_query, _fieldRefs, _search, _sort, _mode, _unaccent) {
|
|
2211
|
+
throw createNotSupportedError("\"_fuzzyRelevance\" ordering is not supported by the \"sqlite\" provider");
|
|
2212
|
+
}
|
|
2213
|
+
buildFullTextFilter(_fieldRef, _payload) {
|
|
2214
|
+
throw createNotSupportedError("\"fts\" filter is not supported by the \"sqlite\" provider");
|
|
2215
|
+
}
|
|
2216
|
+
buildFtsRelevanceOrderBy(_query, _fieldRefs, _search, _config, _sort) {
|
|
2217
|
+
throw createNotSupportedError("\"_ftsRelevance\" ordering is not supported by the \"sqlite\" provider");
|
|
2218
|
+
}
|
|
2019
2219
|
};
|
|
2020
2220
|
//#endregion
|
|
2021
2221
|
//#region src/client/crud/dialects/index.ts
|
|
@@ -2071,11 +2271,38 @@ function createQuerySchemaFactory(clientOrSchema, options) {
|
|
|
2071
2271
|
return new ZodSchemaFactory(clientOrSchema, options);
|
|
2072
2272
|
}
|
|
2073
2273
|
/**
|
|
2274
|
+
* Builds a `DateTime` value schema that accepts a `Date` object or any string
|
|
2275
|
+
* the JS `Date` constructor parses, and coerces it to a `Date`. ISO datetime,
|
|
2276
|
+
* ISO date, and time-only strings (e.g. `"09:00:00"` for `@db.Time` fields,
|
|
2277
|
+
* anchored to the Unix epoch) are the documented happy paths; other formats
|
|
2278
|
+
* accepted by `new Date(...)` also pass through, mirroring Prisma's pre-3.5
|
|
2279
|
+
* behaviour. Strings the engine can't parse fall through and are rejected by
|
|
2280
|
+
* `z.date()` with the standard error.
|
|
2281
|
+
*
|
|
2282
|
+
* @see https://github.com/zenstackhq/zenstack/issues/2631
|
|
2283
|
+
*/
|
|
2284
|
+
function coercedDateTimeSchema() {
|
|
2285
|
+
return z.preprocess((val) => {
|
|
2286
|
+
if (typeof val !== "string") return val;
|
|
2287
|
+
if (/^\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d\d(?::\d\d)?)?$/.test(val)) {
|
|
2288
|
+
const hasTz = val.endsWith("Z") || /[+-]\d\d(?::\d\d)?$/.test(val);
|
|
2289
|
+
const d = /* @__PURE__ */ new Date(`1970-01-01T${val}${hasTz ? "" : "Z"}`);
|
|
2290
|
+
return isNaN(d.getTime()) ? val : d;
|
|
2291
|
+
}
|
|
2292
|
+
const d = new Date(val);
|
|
2293
|
+
return isNaN(d.getTime()) ? val : d;
|
|
2294
|
+
}, z.union([
|
|
2295
|
+
z.iso.datetime(),
|
|
2296
|
+
z.iso.date(),
|
|
2297
|
+
z.date()
|
|
2298
|
+
]));
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2074
2301
|
* Factory class responsible for creating and caching Zod schemas for ORM input validation.
|
|
2075
2302
|
*/
|
|
2076
2303
|
var ZodSchemaFactory = class {
|
|
2077
2304
|
schemaCache = /* @__PURE__ */ new Map();
|
|
2078
|
-
schemaRegistry = z
|
|
2305
|
+
schemaRegistry = z.registry();
|
|
2079
2306
|
allFilterKinds = [...new Set(Object.values(FILTER_PROPERTY_TO_KIND))];
|
|
2080
2307
|
schema;
|
|
2081
2308
|
options;
|
|
@@ -2167,7 +2394,7 @@ var ZodSchemaFactory = class {
|
|
|
2167
2394
|
this.makeGroupBySchema(m);
|
|
2168
2395
|
}
|
|
2169
2396
|
for (const procName of Object.keys(this.schema.procedures ?? {})) if (this.isProcedureAllowed(procName)) this.makeProcedureArgsSchema(procName);
|
|
2170
|
-
return z
|
|
2397
|
+
return z.toJSONSchema(this.schemaRegistry, { unrepresentable: "any" });
|
|
2171
2398
|
}
|
|
2172
2399
|
get cacheStats() {
|
|
2173
2400
|
return {
|
|
@@ -2196,13 +2423,13 @@ var ZodSchemaFactory = class {
|
|
|
2196
2423
|
fields["omit"] = this.makeOmitSchema(model).optional().nullable();
|
|
2197
2424
|
if (!unique) {
|
|
2198
2425
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
2199
|
-
if (findOne) fields["take"] = z
|
|
2426
|
+
if (findOne) fields["take"] = z.literal(1).optional();
|
|
2200
2427
|
else fields["take"] = this.makeTakeSchema().optional();
|
|
2201
2428
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false, options), true).optional();
|
|
2202
2429
|
fields["cursor"] = this.makeCursorSchema(model, options).optional();
|
|
2203
2430
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
2204
2431
|
}
|
|
2205
|
-
const baseSchema = z
|
|
2432
|
+
const baseSchema = z.strictObject(fields);
|
|
2206
2433
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
2207
2434
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
2208
2435
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -2212,7 +2439,7 @@ var ZodSchemaFactory = class {
|
|
|
2212
2439
|
return result;
|
|
2213
2440
|
}
|
|
2214
2441
|
makeExistsSchema(model, options) {
|
|
2215
|
-
const baseSchema = z
|
|
2442
|
+
const baseSchema = z.strictObject({ where: this.makeWhereSchema(model, false, false, false, options).optional() });
|
|
2216
2443
|
const result = this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
2217
2444
|
this.registerSchema(`${model}ExistsArgs`, result);
|
|
2218
2445
|
return result;
|
|
@@ -2220,31 +2447,31 @@ var ZodSchemaFactory = class {
|
|
|
2220
2447
|
makeScalarSchema(type, attributes) {
|
|
2221
2448
|
if (this.schema.typeDefs && type in this.schema.typeDefs) return this.makeTypeDefSchema(type);
|
|
2222
2449
|
else if (this.schema.enums && type in this.schema.enums) return this.makeEnumSchema(type);
|
|
2223
|
-
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z
|
|
2224
|
-
return z
|
|
2225
|
-
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z
|
|
2226
|
-
ZodUtils.addDecimalValidation(z
|
|
2227
|
-
ZodUtils.addDecimalValidation(z
|
|
2450
|
+
else return match(type).with("String", () => this.extraValidationsEnabled ? ZodUtils.addStringValidation(z.string(), attributes) : z.string()).with("Int", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int()).with("Float", () => this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number()).with("Boolean", () => z.boolean()).with("BigInt", () => z.union([this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number().int(), attributes) : z.number().int(), this.extraValidationsEnabled ? ZodUtils.addBigIntValidation(z.bigint(), attributes) : z.bigint()])).with("Decimal", () => {
|
|
2451
|
+
return z.union([
|
|
2452
|
+
this.extraValidationsEnabled ? ZodUtils.addNumberValidation(z.number(), attributes) : z.number(),
|
|
2453
|
+
ZodUtils.addDecimalValidation(z.instanceof(Decimal), attributes, this.extraValidationsEnabled),
|
|
2454
|
+
ZodUtils.addDecimalValidation(z.string(), attributes, this.extraValidationsEnabled)
|
|
2228
2455
|
]);
|
|
2229
|
-
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z
|
|
2456
|
+
}).with("DateTime", () => this.makeDateTimeValueSchema()).with("Bytes", () => z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema()).otherwise(() => z.unknown());
|
|
2230
2457
|
}
|
|
2231
2458
|
makeEnumSchema(_enum) {
|
|
2232
2459
|
const enumDef = getEnum(this.schema, _enum);
|
|
2233
2460
|
invariant(enumDef, `Enum "${_enum}" not found in schema`);
|
|
2234
|
-
const schema = z
|
|
2461
|
+
const schema = z.enum(Object.keys(enumDef.values));
|
|
2235
2462
|
this.registerSchema(_enum, schema);
|
|
2236
2463
|
return schema;
|
|
2237
2464
|
}
|
|
2238
2465
|
makeTypeDefSchema(type) {
|
|
2239
2466
|
const typeDef = getTypeDef(this.schema, type);
|
|
2240
2467
|
invariant(typeDef, `Type definition "${type}" not found in schema`);
|
|
2241
|
-
const schema = z
|
|
2242
|
-
let fieldSchema = this.makeScalarSchema(def.type);
|
|
2468
|
+
const schema = z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
2469
|
+
let fieldSchema = isTypeDef(this.schema, def.type) ? z.lazy(() => this.makeTypeDefSchema(def.type)) : this.makeScalarSchema(def.type);
|
|
2243
2470
|
if (def.array) fieldSchema = fieldSchema.array();
|
|
2244
2471
|
if (def.optional) fieldSchema = fieldSchema.nullish();
|
|
2245
2472
|
return [field, fieldSchema];
|
|
2246
2473
|
})));
|
|
2247
|
-
const finalSchema = z
|
|
2474
|
+
const finalSchema = z.any().superRefine((value, ctx) => {
|
|
2248
2475
|
const parseResult = schema.safeParse(value);
|
|
2249
2476
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
2250
2477
|
});
|
|
@@ -2260,17 +2487,17 @@ var ZodSchemaFactory = class {
|
|
|
2260
2487
|
if (fieldDef.relation) {
|
|
2261
2488
|
if (withoutRelationFields || !this.shouldIncludeRelations(options)) continue;
|
|
2262
2489
|
const allowedFilterKinds = this.getEffectiveFilterKinds(model, field);
|
|
2263
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z
|
|
2490
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Relation")) fieldSchema = z.never();
|
|
2264
2491
|
else {
|
|
2265
|
-
fieldSchema = z
|
|
2266
|
-
if (fieldDef.array) fieldSchema = z
|
|
2492
|
+
fieldSchema = z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts).optional());
|
|
2493
|
+
if (fieldDef.array) fieldSchema = z.strictObject({
|
|
2267
2494
|
some: fieldSchema.optional(),
|
|
2268
2495
|
every: fieldSchema.optional(),
|
|
2269
2496
|
none: fieldSchema.optional()
|
|
2270
2497
|
});
|
|
2271
2498
|
else {
|
|
2272
2499
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
2273
|
-
fieldSchema = z
|
|
2500
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({
|
|
2274
2501
|
is: fieldSchema.optional(),
|
|
2275
2502
|
isNot: fieldSchema.optional()
|
|
2276
2503
|
})]);
|
|
@@ -2283,27 +2510,27 @@ var ZodSchemaFactory = class {
|
|
|
2283
2510
|
if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, withAggregations, allowedFilterKinds);
|
|
2284
2511
|
} else if (fieldDef.array) fieldSchema = this.makeArrayFilterSchema(fieldDef.type, allowedFilterKinds);
|
|
2285
2512
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeTypedJsonFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, allowedFilterKinds);
|
|
2286
|
-
else fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations, allowedFilterKinds);
|
|
2513
|
+
else fieldSchema = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, withAggregations, allowedFilterKinds, !!fieldDef.fuzzy, !!fieldDef.fullText);
|
|
2287
2514
|
}
|
|
2288
2515
|
if (fieldSchema) fields[field] = fieldSchema.optional();
|
|
2289
2516
|
}
|
|
2290
2517
|
if (unique) {
|
|
2291
2518
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
2292
|
-
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z
|
|
2519
|
+
for (const uniqueField of uniqueFields) if ("defs" in uniqueField) fields[uniqueField.name] = z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
2293
2520
|
invariant(!def.relation, "unique field cannot be a relation");
|
|
2294
2521
|
let fieldSchema;
|
|
2295
2522
|
const enumDef = getEnum(this.schema, def.type);
|
|
2296
2523
|
if (enumDef) if (Object.keys(enumDef.values).length > 0) fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, !!def.array, false, void 0);
|
|
2297
|
-
else fieldSchema = z
|
|
2524
|
+
else fieldSchema = z.never();
|
|
2298
2525
|
else fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false, void 0);
|
|
2299
2526
|
return [key, fieldSchema];
|
|
2300
2527
|
}))).optional();
|
|
2301
2528
|
}
|
|
2302
|
-
fields["$expr"] = z
|
|
2303
|
-
fields["AND"] = this.orArray(z
|
|
2304
|
-
fields["OR"] = z
|
|
2305
|
-
fields["NOT"] = this.orArray(z
|
|
2306
|
-
const baseWhere = z
|
|
2529
|
+
fields["$expr"] = z.custom((v) => typeof v === "function", { error: "\"$expr\" must be a function" }).optional();
|
|
2530
|
+
fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2531
|
+
fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
|
|
2532
|
+
fields["NOT"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
|
|
2533
|
+
const baseWhere = z.strictObject(fields);
|
|
2307
2534
|
let result = baseWhere;
|
|
2308
2535
|
if (unique) {
|
|
2309
2536
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -2329,26 +2556,26 @@ var ZodSchemaFactory = class {
|
|
|
2329
2556
|
else if (getEnum(this.schema, fieldDef.type)) fieldSchemas[fieldName] = this.makeEnumFilterSchema(fieldDef.type, !!fieldDef.optional, !!fieldDef.array, false, void 0).optional();
|
|
2330
2557
|
else if (fieldDef.array) fieldSchemas[fieldName] = this.makeArrayFilterSchema(fieldDef.type, void 0).optional();
|
|
2331
2558
|
else fieldSchemas[fieldName] = this.makePrimitiveFilterSchema(fieldDef.type, !!fieldDef.optional, false, void 0).optional();
|
|
2332
|
-
candidates.push(z
|
|
2559
|
+
candidates.push(z.strictObject(fieldSchemas));
|
|
2333
2560
|
}
|
|
2334
|
-
const recursiveSchema = z
|
|
2335
|
-
if (array) candidates.push(z
|
|
2561
|
+
const recursiveSchema = z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false, allowedFilterKinds)).optional();
|
|
2562
|
+
if (array) candidates.push(z.strictObject({
|
|
2336
2563
|
some: recursiveSchema,
|
|
2337
2564
|
every: recursiveSchema,
|
|
2338
2565
|
none: recursiveSchema
|
|
2339
2566
|
}));
|
|
2340
|
-
else candidates.push(z
|
|
2567
|
+
else candidates.push(z.strictObject({
|
|
2341
2568
|
is: recursiveSchema,
|
|
2342
2569
|
isNot: recursiveSchema
|
|
2343
2570
|
}));
|
|
2344
2571
|
candidates.push(this.makeJsonFilterSchema(optional, allowedFilterKinds));
|
|
2345
2572
|
if (optional) {
|
|
2346
|
-
candidates.push(z
|
|
2347
|
-
candidates.push(z
|
|
2348
|
-
candidates.push(z
|
|
2349
|
-
candidates.push(z
|
|
2573
|
+
candidates.push(z.null());
|
|
2574
|
+
candidates.push(z.instanceof(DbNullClass));
|
|
2575
|
+
candidates.push(z.instanceof(JsonNullClass));
|
|
2576
|
+
candidates.push(z.instanceof(AnyNullClass));
|
|
2350
2577
|
}
|
|
2351
|
-
const result = z
|
|
2578
|
+
const result = z.union(candidates);
|
|
2352
2579
|
this.registerSchema(`${type}Filter${this.filterSchemaSuffix({
|
|
2353
2580
|
optional,
|
|
2354
2581
|
array,
|
|
@@ -2357,7 +2584,7 @@ var ZodSchemaFactory = class {
|
|
|
2357
2584
|
return result;
|
|
2358
2585
|
}
|
|
2359
2586
|
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
2360
|
-
return z
|
|
2587
|
+
return z.any().superRefine((value, ctx) => {
|
|
2361
2588
|
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) return;
|
|
2362
2589
|
const parseResult = fieldSchema.safeParse(value);
|
|
2363
2590
|
if (!parseResult.success) parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -2369,11 +2596,11 @@ var ZodSchemaFactory = class {
|
|
|
2369
2596
|
makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds) {
|
|
2370
2597
|
const enumDef = getEnum(this.schema, enumName);
|
|
2371
2598
|
invariant(enumDef, `Enum "${enumName}" not found in schema`);
|
|
2372
|
-
const baseSchema = z
|
|
2599
|
+
const baseSchema = z.enum(Object.keys(enumDef.values));
|
|
2373
2600
|
let schema;
|
|
2374
2601
|
if (array) schema = this.internalMakeArrayFilterSchema(baseSchema, allowedFilterKinds);
|
|
2375
2602
|
else {
|
|
2376
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2603
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.lazy(() => this.makeEnumFilterSchema(enumName, optional, array, withAggregations, allowedFilterKinds)), [
|
|
2377
2604
|
"equals",
|
|
2378
2605
|
"in",
|
|
2379
2606
|
"notIn",
|
|
@@ -2407,42 +2634,42 @@ var ZodSchemaFactory = class {
|
|
|
2407
2634
|
has: elementSchema.optional(),
|
|
2408
2635
|
hasEvery: elementSchema.array().optional(),
|
|
2409
2636
|
hasSome: elementSchema.array().optional(),
|
|
2410
|
-
isEmpty: z
|
|
2637
|
+
isEmpty: z.boolean().optional()
|
|
2411
2638
|
};
|
|
2412
2639
|
const filteredOperators = this.trimFilterOperators(operators, allowedFilterKinds);
|
|
2413
|
-
return z
|
|
2640
|
+
return z.strictObject(filteredOperators);
|
|
2414
2641
|
}
|
|
2415
|
-
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2416
|
-
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z
|
|
2642
|
+
makePrimitiveFilterSchema(type, optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2643
|
+
return match(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds)).with("Json", () => this.makeJsonFilterSchema(optional, allowedFilterKinds)).with("Unsupported", () => z.never()).exhaustive();
|
|
2417
2644
|
}
|
|
2418
2645
|
makeJsonValueSchema() {
|
|
2419
|
-
const schema = z
|
|
2420
|
-
z
|
|
2421
|
-
z
|
|
2422
|
-
z
|
|
2423
|
-
z
|
|
2424
|
-
z
|
|
2425
|
-
z
|
|
2646
|
+
const schema = z.union([
|
|
2647
|
+
z.string(),
|
|
2648
|
+
z.number(),
|
|
2649
|
+
z.boolean(),
|
|
2650
|
+
z.instanceof(JsonNullClass),
|
|
2651
|
+
z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()]).array()),
|
|
2652
|
+
z.record(z.string(), z.lazy(() => z.union([this.makeJsonValueSchema(), z.null()])))
|
|
2426
2653
|
]);
|
|
2427
2654
|
this.registerSchema("JsonValue", schema);
|
|
2428
2655
|
return schema;
|
|
2429
2656
|
}
|
|
2430
2657
|
makeJsonFilterSchema(optional, allowedFilterKinds) {
|
|
2431
|
-
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z
|
|
2658
|
+
if (allowedFilterKinds && !allowedFilterKinds.includes("Json")) return z.never();
|
|
2432
2659
|
const filterMembers = [
|
|
2433
2660
|
this.makeJsonValueSchema(),
|
|
2434
|
-
z
|
|
2435
|
-
z
|
|
2661
|
+
z.instanceof(DbNullClass),
|
|
2662
|
+
z.instanceof(AnyNullClass)
|
|
2436
2663
|
];
|
|
2437
|
-
if (optional) filterMembers.push(z
|
|
2438
|
-
const filterValueSchema = z
|
|
2439
|
-
const schema = z
|
|
2440
|
-
path: z
|
|
2664
|
+
if (optional) filterMembers.push(z.null());
|
|
2665
|
+
const filterValueSchema = z.union(filterMembers);
|
|
2666
|
+
const schema = z.strictObject({
|
|
2667
|
+
path: z.string().optional(),
|
|
2441
2668
|
equals: filterValueSchema.optional(),
|
|
2442
2669
|
not: filterValueSchema.optional(),
|
|
2443
|
-
string_contains: z
|
|
2444
|
-
string_starts_with: z
|
|
2445
|
-
string_ends_with: z
|
|
2670
|
+
string_contains: z.string().optional(),
|
|
2671
|
+
string_starts_with: z.string().optional(),
|
|
2672
|
+
string_ends_with: z.string().optional(),
|
|
2446
2673
|
mode: this.makeStringModeSchema().optional(),
|
|
2447
2674
|
array_contains: filterValueSchema.optional(),
|
|
2448
2675
|
array_starts_with: filterValueSchema.optional(),
|
|
@@ -2455,17 +2682,13 @@ var ZodSchemaFactory = class {
|
|
|
2455
2682
|
return schema;
|
|
2456
2683
|
}
|
|
2457
2684
|
makeDateTimeValueSchema() {
|
|
2458
|
-
const schema =
|
|
2459
|
-
z$1.iso.datetime(),
|
|
2460
|
-
z$1.iso.date(),
|
|
2461
|
-
z$1.date()
|
|
2462
|
-
]);
|
|
2685
|
+
const schema = coercedDateTimeSchema();
|
|
2463
2686
|
this.registerSchema("DateTime", schema);
|
|
2464
2687
|
return schema;
|
|
2465
2688
|
}
|
|
2466
2689
|
makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2467
2690
|
const filterValueSchema = this.makeDateTimeValueSchema();
|
|
2468
|
-
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z
|
|
2691
|
+
const schema = this.makeCommonPrimitiveFilterSchema(filterValueSchema, optional, () => z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2469
2692
|
"_count",
|
|
2470
2693
|
"_min",
|
|
2471
2694
|
"_max"
|
|
@@ -2478,12 +2701,12 @@ var ZodSchemaFactory = class {
|
|
|
2478
2701
|
return schema;
|
|
2479
2702
|
}
|
|
2480
2703
|
makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2481
|
-
const components = this.makeCommonPrimitiveFilterComponents(z
|
|
2704
|
+
const components = this.makeCommonPrimitiveFilterComponents(z.boolean(), optional, () => z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations, allowedFilterKinds)), ["equals", "not"], withAggregations ? [
|
|
2482
2705
|
"_count",
|
|
2483
2706
|
"_min",
|
|
2484
2707
|
"_max"
|
|
2485
2708
|
] : void 0, allowedFilterKinds);
|
|
2486
|
-
const schema = this.createUnionFilterSchema(z
|
|
2709
|
+
const schema = this.createUnionFilterSchema(z.boolean(), optional, components, allowedFilterKinds);
|
|
2487
2710
|
this.registerSchema(`BooleanFilter${this.filterSchemaSuffix({
|
|
2488
2711
|
optional,
|
|
2489
2712
|
allowedFilterKinds,
|
|
@@ -2492,8 +2715,8 @@ var ZodSchemaFactory = class {
|
|
|
2492
2715
|
return schema;
|
|
2493
2716
|
}
|
|
2494
2717
|
makeBytesFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2495
|
-
const baseSchema = z
|
|
2496
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z
|
|
2718
|
+
const baseSchema = z.instanceof(Uint8Array);
|
|
2719
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z.instanceof(Uint8Array), [
|
|
2497
2720
|
"equals",
|
|
2498
2721
|
"in",
|
|
2499
2722
|
"notIn",
|
|
@@ -2541,7 +2764,7 @@ var ZodSchemaFactory = class {
|
|
|
2541
2764
|
return this.createUnionFilterSchema(baseSchema, optional, components, allowedFilterKinds);
|
|
2542
2765
|
}
|
|
2543
2766
|
makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds) {
|
|
2544
|
-
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z
|
|
2767
|
+
const schema = this.makeCommonPrimitiveFilterSchema(this.makeScalarSchema(type), optional, () => z.lazy(() => this.makeNumberFilterSchema(type, optional, withAggregations, allowedFilterKinds)), withAggregations ? [
|
|
2545
2768
|
"_count",
|
|
2546
2769
|
"_avg",
|
|
2547
2770
|
"_sum",
|
|
@@ -2555,16 +2778,18 @@ var ZodSchemaFactory = class {
|
|
|
2555
2778
|
})}`, schema);
|
|
2556
2779
|
return schema;
|
|
2557
2780
|
}
|
|
2558
|
-
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds) {
|
|
2559
|
-
const baseComponents = this.makeCommonPrimitiveFilterComponents(z
|
|
2781
|
+
makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy = false, withFullText = false) {
|
|
2782
|
+
const baseComponents = this.makeCommonPrimitiveFilterComponents(z.string(), optional, () => z.lazy(() => this.makeStringFilterSchema(optional, withAggregations, allowedFilterKinds, withFuzzy, withFullText)), void 0, withAggregations ? [
|
|
2560
2783
|
"_count",
|
|
2561
2784
|
"_min",
|
|
2562
2785
|
"_max"
|
|
2563
2786
|
] : void 0, allowedFilterKinds);
|
|
2564
2787
|
const stringSpecificOperators = {
|
|
2565
|
-
startsWith: z
|
|
2566
|
-
endsWith: z
|
|
2567
|
-
contains: z
|
|
2788
|
+
startsWith: z.string().optional(),
|
|
2789
|
+
endsWith: z.string().optional(),
|
|
2790
|
+
contains: z.string().optional(),
|
|
2791
|
+
...withFuzzy && this.providerSupportsFuzzySearch ? { fuzzy: this.makeFuzzyFilterSchema().optional() } : {},
|
|
2792
|
+
...withFullText && this.providerSupportsFullTextSearch ? { fts: this.makeFullTextFilterSchema().optional() } : {},
|
|
2568
2793
|
...this.providerSupportsCaseSensitivity ? { mode: this.makeStringModeSchema().optional() } : {}
|
|
2569
2794
|
};
|
|
2570
2795
|
const filteredStringOperators = this.trimFilterOperators(stringSpecificOperators, allowedFilterKinds);
|
|
@@ -2572,29 +2797,48 @@ var ZodSchemaFactory = class {
|
|
|
2572
2797
|
...baseComponents,
|
|
2573
2798
|
...filteredStringOperators
|
|
2574
2799
|
};
|
|
2575
|
-
const schema = this.createUnionFilterSchema(z
|
|
2800
|
+
const schema = this.createUnionFilterSchema(z.string(), optional, allComponents, allowedFilterKinds);
|
|
2801
|
+
const featureSuffix = `${withFuzzy ? "Fuzzy" : ""}${withFullText ? "FullText" : ""}`;
|
|
2576
2802
|
this.registerSchema(`StringFilter${this.filterSchemaSuffix({
|
|
2577
2803
|
optional,
|
|
2578
2804
|
allowedFilterKinds,
|
|
2579
2805
|
withAggregations
|
|
2580
|
-
})}`, schema);
|
|
2806
|
+
})}${featureSuffix}`, schema);
|
|
2581
2807
|
return schema;
|
|
2582
2808
|
}
|
|
2583
2809
|
makeStringModeSchema() {
|
|
2584
|
-
return z
|
|
2810
|
+
return z.union([z.literal("default"), z.literal("insensitive")]);
|
|
2811
|
+
}
|
|
2812
|
+
makeFuzzyFilterSchema() {
|
|
2813
|
+
return z.strictObject({
|
|
2814
|
+
search: z.string().min(1),
|
|
2815
|
+
mode: z.union([
|
|
2816
|
+
z.literal("simple"),
|
|
2817
|
+
z.literal("word"),
|
|
2818
|
+
z.literal("strictWord")
|
|
2819
|
+
]).default("simple"),
|
|
2820
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
2821
|
+
unaccent: z.boolean().default(false)
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
makeFullTextFilterSchema() {
|
|
2825
|
+
return z.strictObject({
|
|
2826
|
+
search: z.string().min(1),
|
|
2827
|
+
config: z.string().min(1).optional()
|
|
2828
|
+
});
|
|
2585
2829
|
}
|
|
2586
2830
|
makeSelectSchema(model, options) {
|
|
2587
2831
|
const fields = {};
|
|
2588
2832
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2589
2833
|
if (!this.shouldIncludeRelations(options)) continue;
|
|
2590
2834
|
if (this.isModelAllowed(fieldDef.type)) fields[field] = this.makeRelationSelectIncludeSchema(model, field, options).optional();
|
|
2591
|
-
} else fields[field] = z
|
|
2835
|
+
} else fields[field] = z.boolean().optional();
|
|
2592
2836
|
if (this.shouldIncludeRelations(options)) {
|
|
2593
2837
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2594
|
-
if (!(_countSchema instanceof z
|
|
2838
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2595
2839
|
}
|
|
2596
2840
|
this.addExtResultFields(model, fields);
|
|
2597
|
-
const result = z
|
|
2841
|
+
const result = z.strictObject(fields);
|
|
2598
2842
|
this.registerSchema(`${model}Select`, result);
|
|
2599
2843
|
return result;
|
|
2600
2844
|
}
|
|
@@ -2603,24 +2847,24 @@ var ZodSchemaFactory = class {
|
|
|
2603
2847
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
2604
2848
|
if (toManyRelations.length > 0) {
|
|
2605
2849
|
const nextOpts = this.nextOptions(options);
|
|
2606
|
-
const schema = z
|
|
2850
|
+
const schema = z.union([z.literal(true), z.strictObject({ select: z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
2607
2851
|
...acc,
|
|
2608
|
-
[fieldDef.name]: z
|
|
2852
|
+
[fieldDef.name]: z.union([z.boolean(), z.strictObject({ where: this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts) })]).optional()
|
|
2609
2853
|
}), {})) })]).optional();
|
|
2610
2854
|
this.registerSchema(`${model}CountSelection`, schema);
|
|
2611
2855
|
return schema;
|
|
2612
|
-
} else return z
|
|
2856
|
+
} else return z.never();
|
|
2613
2857
|
}
|
|
2614
2858
|
makeRelationSelectIncludeSchema(model, field, options) {
|
|
2615
2859
|
const fieldDef = requireField(this.schema, model, field);
|
|
2616
2860
|
const nextOpts = this.nextOptions(options);
|
|
2617
|
-
let objSchema = z
|
|
2618
|
-
...fieldDef.array || fieldDef.optional ? { where: z
|
|
2619
|
-
select: z
|
|
2620
|
-
include: z
|
|
2621
|
-
omit: z
|
|
2861
|
+
let objSchema = z.strictObject({
|
|
2862
|
+
...fieldDef.array || fieldDef.optional ? { where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false, false, false, nextOpts)).optional() } : {},
|
|
2863
|
+
select: z.lazy(() => this.makeSelectSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2864
|
+
include: z.lazy(() => this.makeIncludeSchema(fieldDef.type, nextOpts)).optional().nullable(),
|
|
2865
|
+
omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
2622
2866
|
...fieldDef.array ? {
|
|
2623
|
-
orderBy: z
|
|
2867
|
+
orderBy: z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false, nextOpts), true)).optional(),
|
|
2624
2868
|
skip: this.makeSkipSchema().optional(),
|
|
2625
2869
|
take: this.makeTakeSchema().optional(),
|
|
2626
2870
|
cursor: this.makeCursorSchema(fieldDef.type, nextOpts).optional(),
|
|
@@ -2630,16 +2874,16 @@ var ZodSchemaFactory = class {
|
|
|
2630
2874
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
2631
2875
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
2632
2876
|
objSchema = this.refineForSelectHasTruthyField(objSchema);
|
|
2633
|
-
const result = z
|
|
2877
|
+
const result = z.union([z.boolean(), objSchema]);
|
|
2634
2878
|
this.registerSchema(`${model}${upperCaseFirst(field)}RelationInput`, result);
|
|
2635
2879
|
return result;
|
|
2636
2880
|
}
|
|
2637
2881
|
makeOmitSchema(model) {
|
|
2638
2882
|
const fields = {};
|
|
2639
|
-
for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z
|
|
2640
|
-
else fields[field] = z
|
|
2883
|
+
for (const [field, fieldDef] of this.getModelFields(model)) if (!fieldDef.relation) if (this.options.allowQueryTimeOmitOverride !== false) fields[field] = z.boolean().optional();
|
|
2884
|
+
else fields[field] = z.literal(true).optional();
|
|
2641
2885
|
this.addExtResultFields(model, fields);
|
|
2642
|
-
const result = z
|
|
2886
|
+
const result = z.strictObject(fields);
|
|
2643
2887
|
this.registerSchema(`${model}OmitInput`, result);
|
|
2644
2888
|
return result;
|
|
2645
2889
|
}
|
|
@@ -2648,7 +2892,7 @@ var ZodSchemaFactory = class {
|
|
|
2648
2892
|
const resultConfig = plugin.result;
|
|
2649
2893
|
if (resultConfig) {
|
|
2650
2894
|
const modelConfig = resultConfig[lowerCaseFirst(model)];
|
|
2651
|
-
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z
|
|
2895
|
+
if (modelConfig) for (const field of Object.keys(modelConfig)) fields[field] = z.boolean().optional();
|
|
2652
2896
|
}
|
|
2653
2897
|
}
|
|
2654
2898
|
}
|
|
@@ -2664,26 +2908,26 @@ var ZodSchemaFactory = class {
|
|
|
2664
2908
|
}
|
|
2665
2909
|
if (this.shouldIncludeRelations(options)) {
|
|
2666
2910
|
const _countSchema = this.makeCountSelectionSchema(model, options);
|
|
2667
|
-
if (!(_countSchema instanceof z
|
|
2911
|
+
if (!(_countSchema instanceof z.ZodNever)) fields["_count"] = _countSchema;
|
|
2668
2912
|
}
|
|
2669
|
-
const result = z
|
|
2913
|
+
const result = z.strictObject(fields);
|
|
2670
2914
|
this.registerSchema(`${model}Include`, result);
|
|
2671
2915
|
return result;
|
|
2672
2916
|
}
|
|
2673
2917
|
makeOrderBySchema(model, withRelation, WithAggregation, options) {
|
|
2674
2918
|
const fields = {};
|
|
2675
|
-
const sort = z
|
|
2919
|
+
const sort = z.union([z.literal("asc"), z.literal("desc")]);
|
|
2676
2920
|
const refineAtMostOneKey = (s) => s.refine((v) => Object.keys(v).length <= 1, { message: "Each orderBy element must have at most one key" });
|
|
2677
2921
|
const nextOpts = this.nextOptions(options);
|
|
2678
2922
|
for (const [field, fieldDef] of this.getModelFields(model)) if (fieldDef.relation) {
|
|
2679
|
-
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z
|
|
2923
|
+
if (withRelation && this.shouldIncludeRelations(options)) fields[field] = z.lazy(() => {
|
|
2680
2924
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation, nextOpts);
|
|
2681
2925
|
if (fieldDef.array) relationOrderBy = refineAtMostOneKey(relationOrderBy.safeExtend({ _count: sort }));
|
|
2682
2926
|
return relationOrderBy;
|
|
2683
2927
|
}).optional();
|
|
2684
|
-
} else if (fieldDef.optional) fields[field] = z
|
|
2928
|
+
} else if (fieldDef.optional) fields[field] = z.union([sort, z.strictObject({
|
|
2685
2929
|
sort,
|
|
2686
|
-
nulls: z
|
|
2930
|
+
nulls: z.union([z.literal("first"), z.literal("last")]).optional()
|
|
2687
2931
|
})]).optional();
|
|
2688
2932
|
else fields[field] = sort.optional();
|
|
2689
2933
|
if (WithAggregation) for (const agg of [
|
|
@@ -2692,8 +2936,31 @@ var ZodSchemaFactory = class {
|
|
|
2692
2936
|
"_sum",
|
|
2693
2937
|
"_min",
|
|
2694
2938
|
"_max"
|
|
2695
|
-
]) fields[agg] = z
|
|
2696
|
-
|
|
2939
|
+
]) fields[agg] = z.lazy(() => this.makeOrderBySchema(model, true, false, options).optional());
|
|
2940
|
+
if (this.providerSupportsFuzzySearch) {
|
|
2941
|
+
const fuzzyFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fuzzy === true).map(([name]) => name);
|
|
2942
|
+
if (fuzzyFieldNames.length > 0) fields["_fuzzyRelevance"] = z.strictObject({
|
|
2943
|
+
fields: z.array(z.enum(fuzzyFieldNames)).min(1),
|
|
2944
|
+
search: z.string(),
|
|
2945
|
+
mode: z.union([
|
|
2946
|
+
z.literal("simple"),
|
|
2947
|
+
z.literal("word"),
|
|
2948
|
+
z.literal("strictWord")
|
|
2949
|
+
]).default("simple"),
|
|
2950
|
+
unaccent: z.boolean().default(false),
|
|
2951
|
+
sort
|
|
2952
|
+
}).optional();
|
|
2953
|
+
}
|
|
2954
|
+
if (this.providerSupportsFullTextSearch) {
|
|
2955
|
+
const fullTextFieldNames = this.getModelFields(model).filter(([, def]) => !def.relation && def.type === "String" && def.fullText === true).map(([name]) => name);
|
|
2956
|
+
if (fullTextFieldNames.length > 0) fields["_ftsRelevance"] = z.strictObject({
|
|
2957
|
+
fields: z.array(z.enum(fullTextFieldNames)).min(1),
|
|
2958
|
+
search: z.string().min(1),
|
|
2959
|
+
config: z.string().min(1).optional(),
|
|
2960
|
+
sort
|
|
2961
|
+
}).optional();
|
|
2962
|
+
}
|
|
2963
|
+
const schema = refineAtMostOneKey(z.strictObject(fields));
|
|
2697
2964
|
let schemaId = `${model}OrderBy`;
|
|
2698
2965
|
if (withRelation) schemaId += "WithRelation";
|
|
2699
2966
|
if (WithAggregation) schemaId += "WithAggregation";
|
|
@@ -2703,7 +2970,7 @@ var ZodSchemaFactory = class {
|
|
|
2703
2970
|
}
|
|
2704
2971
|
makeDistinctSchema(model) {
|
|
2705
2972
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
2706
|
-
const schema = nonRelationFields.length > 0 ? this.orArray(z
|
|
2973
|
+
const schema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
2707
2974
|
this.registerSchema(`${model}DistinctInput`, schema);
|
|
2708
2975
|
return schema;
|
|
2709
2976
|
}
|
|
@@ -2714,7 +2981,7 @@ var ZodSchemaFactory = class {
|
|
|
2714
2981
|
}
|
|
2715
2982
|
makeCreateSchema(model, options) {
|
|
2716
2983
|
const dataSchema = this.makeCreateDataSchema(model, false, [], false, options);
|
|
2717
|
-
const baseSchema = z
|
|
2984
|
+
const baseSchema = z.strictObject({
|
|
2718
2985
|
data: dataSchema,
|
|
2719
2986
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
2720
2987
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -2763,7 +3030,7 @@ var ZodSchemaFactory = class {
|
|
|
2763
3030
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
2764
3031
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
2765
3032
|
}
|
|
2766
|
-
let fieldSchema = z
|
|
3033
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create", nextOpts));
|
|
2767
3034
|
if (fieldDef.optional || fieldDef.array) fieldSchema = fieldSchema.optional();
|
|
2768
3035
|
else {
|
|
2769
3036
|
let allFksOptional = false;
|
|
@@ -2780,23 +3047,23 @@ var ZodSchemaFactory = class {
|
|
|
2780
3047
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
2781
3048
|
if (fieldDef.array) {
|
|
2782
3049
|
fieldSchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
2783
|
-
fieldSchema = z
|
|
3050
|
+
fieldSchema = z.union([fieldSchema, z.strictObject({ set: fieldSchema })]).optional();
|
|
2784
3051
|
}
|
|
2785
3052
|
if (fieldDef.optional || fieldHasDefaultValue(fieldDef)) fieldSchema = fieldSchema.optional();
|
|
2786
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3053
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
2787
3054
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
2788
3055
|
else fieldSchema = fieldSchema.nullable();
|
|
2789
3056
|
uncheckedVariantFields[field] = fieldSchema;
|
|
2790
3057
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
2791
3058
|
}
|
|
2792
3059
|
});
|
|
2793
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
2794
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
2795
|
-
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z
|
|
3060
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3061
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3062
|
+
const result = !hasRelation ? this.orArray(uncheckedCreateSchema, canBeArray) : z.union([
|
|
2796
3063
|
uncheckedCreateSchema,
|
|
2797
3064
|
checkedCreateSchema,
|
|
2798
|
-
...canBeArray ? [z
|
|
2799
|
-
...canBeArray ? [z
|
|
3065
|
+
...canBeArray ? [z.array(uncheckedCreateSchema)] : [],
|
|
3066
|
+
...canBeArray ? [z.array(checkedCreateSchema)] : []
|
|
2800
3067
|
]);
|
|
2801
3068
|
const idParts = [`${model}CreateData`];
|
|
2802
3069
|
if (canBeArray) idParts.push("Array");
|
|
@@ -2821,17 +3088,17 @@ var ZodSchemaFactory = class {
|
|
|
2821
3088
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array, options).optional();
|
|
2822
3089
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true, options).optional();
|
|
2823
3090
|
}
|
|
2824
|
-
fields["update"] = array ? this.orArray(z
|
|
3091
|
+
fields["update"] = array ? this.orArray(z.strictObject({
|
|
2825
3092
|
where: this.makeWhereSchema(fieldType, true, false, false, options),
|
|
2826
3093
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
2827
|
-
}), true).optional() : z
|
|
3094
|
+
}), true).optional() : z.union([z.strictObject({
|
|
2828
3095
|
where: this.makeWhereSchema(fieldType, false, false, false, options).optional(),
|
|
2829
3096
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
2830
3097
|
}), this.makeUpdateDataSchema(fieldType, withoutFields, false, options)]).optional();
|
|
2831
3098
|
if (canCreateModel) {
|
|
2832
3099
|
let upsertWhere = this.makeWhereSchema(fieldType, true, false, false, options);
|
|
2833
3100
|
if (!fieldDef.array) upsertWhere = upsertWhere.optional();
|
|
2834
|
-
fields["upsert"] = this.orArray(z
|
|
3101
|
+
fields["upsert"] = this.orArray(z.strictObject({
|
|
2835
3102
|
where: upsertWhere,
|
|
2836
3103
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields, false, options),
|
|
2837
3104
|
update: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
@@ -2839,14 +3106,14 @@ var ZodSchemaFactory = class {
|
|
|
2839
3106
|
}
|
|
2840
3107
|
if (array) {
|
|
2841
3108
|
fields["set"] = this.makeSetDataSchema(fieldType, true, options).optional();
|
|
2842
|
-
fields["updateMany"] = this.orArray(z
|
|
3109
|
+
fields["updateMany"] = this.orArray(z.strictObject({
|
|
2843
3110
|
where: this.makeWhereSchema(fieldType, false, true, false, options),
|
|
2844
3111
|
data: this.makeUpdateDataSchema(fieldType, withoutFields, false, options)
|
|
2845
3112
|
}), true).optional();
|
|
2846
3113
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false, options).optional();
|
|
2847
3114
|
}
|
|
2848
3115
|
}
|
|
2849
|
-
return z
|
|
3116
|
+
return z.strictObject(fields);
|
|
2850
3117
|
}
|
|
2851
3118
|
makeSetDataSchema(model, canBeArray, options) {
|
|
2852
3119
|
return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
@@ -2856,23 +3123,23 @@ var ZodSchemaFactory = class {
|
|
|
2856
3123
|
}
|
|
2857
3124
|
makeDisconnectDataSchema(model, canBeArray, options) {
|
|
2858
3125
|
if (canBeArray) return this.orArray(this.makeWhereSchema(model, true, false, false, options), canBeArray);
|
|
2859
|
-
else return z
|
|
3126
|
+
else return z.union([z.boolean(), this.makeWhereSchema(model, false, false, false, options)]);
|
|
2860
3127
|
}
|
|
2861
3128
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter, options) {
|
|
2862
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z
|
|
3129
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter, false, false, options), true) : z.union([z.boolean(), this.makeWhereSchema(model, uniqueFilter, false, false, options)]);
|
|
2863
3130
|
}
|
|
2864
3131
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields, options) {
|
|
2865
3132
|
const whereSchema = this.makeWhereSchema(model, true, false, false, options);
|
|
2866
3133
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields, false, options);
|
|
2867
|
-
return this.orArray(z
|
|
3134
|
+
return this.orArray(z.strictObject({
|
|
2868
3135
|
where: whereSchema,
|
|
2869
3136
|
create: createSchema
|
|
2870
3137
|
}), canBeArray);
|
|
2871
3138
|
}
|
|
2872
3139
|
makeCreateManyPayloadSchema(model, withoutFields, options) {
|
|
2873
|
-
const schema = z
|
|
3140
|
+
const schema = z.strictObject({
|
|
2874
3141
|
data: this.makeCreateDataSchema(model, true, withoutFields, true, options),
|
|
2875
|
-
skipDuplicates: z
|
|
3142
|
+
skipDuplicates: z.boolean().optional()
|
|
2876
3143
|
});
|
|
2877
3144
|
const idParts = [`${model}CreateManyPayload`];
|
|
2878
3145
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -2880,7 +3147,7 @@ var ZodSchemaFactory = class {
|
|
|
2880
3147
|
return schema;
|
|
2881
3148
|
}
|
|
2882
3149
|
makeUpdateSchema(model, options) {
|
|
2883
|
-
const baseSchema = z
|
|
3150
|
+
const baseSchema = z.strictObject({
|
|
2884
3151
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
2885
3152
|
data: this.makeUpdateDataSchema(model, [], false, options),
|
|
2886
3153
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
@@ -2895,10 +3162,10 @@ var ZodSchemaFactory = class {
|
|
|
2895
3162
|
return schema;
|
|
2896
3163
|
}
|
|
2897
3164
|
makeUpdateManySchema(model, options) {
|
|
2898
|
-
const result = this.mergePluginArgsSchema(z
|
|
3165
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
2899
3166
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
2900
3167
|
data: this.makeUpdateDataSchema(model, [], true, options),
|
|
2901
|
-
limit: z
|
|
3168
|
+
limit: z.number().int().nonnegative().optional()
|
|
2902
3169
|
}), "updateMany");
|
|
2903
3170
|
this.registerSchema(`${model}UpdateManyArgs`, result);
|
|
2904
3171
|
return result;
|
|
@@ -2914,7 +3181,7 @@ var ZodSchemaFactory = class {
|
|
|
2914
3181
|
return schema;
|
|
2915
3182
|
}
|
|
2916
3183
|
makeUpsertSchema(model, options) {
|
|
2917
|
-
const baseSchema = z
|
|
3184
|
+
const baseSchema = z.strictObject({
|
|
2918
3185
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
2919
3186
|
create: this.makeCreateDataSchema(model, false, [], false, options),
|
|
2920
3187
|
update: this.makeUpdateDataSchema(model, [], false, options),
|
|
@@ -2950,27 +3217,27 @@ var ZodSchemaFactory = class {
|
|
|
2950
3217
|
const oppositeFieldDef = requireField(this.schema, fieldDef.type, oppositeField);
|
|
2951
3218
|
if (oppositeFieldDef.relation?.fields) excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
2952
3219
|
}
|
|
2953
|
-
let fieldSchema = z
|
|
3220
|
+
let fieldSchema = z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update", nextOpts)).optional();
|
|
2954
3221
|
if (fieldDef.optional && !fieldDef.array) fieldSchema = fieldSchema.nullable();
|
|
2955
3222
|
checkedVariantFields[field] = fieldSchema;
|
|
2956
3223
|
if (fieldDef.array || !fieldDef.relation.references) uncheckedVariantFields[field] = fieldSchema;
|
|
2957
3224
|
} else {
|
|
2958
3225
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
2959
|
-
if (this.isNumericField(fieldDef)) fieldSchema = z
|
|
2960
|
-
set: this.nullableIf(z
|
|
2961
|
-
increment: z
|
|
2962
|
-
decrement: z
|
|
2963
|
-
multiply: z
|
|
2964
|
-
divide: z
|
|
3226
|
+
if (this.isNumericField(fieldDef)) fieldSchema = z.union([fieldSchema, z.object({
|
|
3227
|
+
set: this.nullableIf(z.number().optional(), !!fieldDef.optional).optional(),
|
|
3228
|
+
increment: z.number().optional(),
|
|
3229
|
+
decrement: z.number().optional(),
|
|
3230
|
+
multiply: z.number().optional(),
|
|
3231
|
+
divide: z.number().optional()
|
|
2965
3232
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided")]);
|
|
2966
3233
|
if (fieldDef.array) {
|
|
2967
3234
|
const arraySchema = ZodUtils.addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
2968
|
-
fieldSchema = z
|
|
3235
|
+
fieldSchema = z.union([arraySchema, z.object({
|
|
2969
3236
|
set: arraySchema.optional(),
|
|
2970
|
-
push: z
|
|
3237
|
+
push: z.union([fieldSchema, fieldSchema.array()]).optional()
|
|
2971
3238
|
}).refine((v) => Object.keys(v).length === 1, "Only one of \"set\", \"push\" can be provided")]);
|
|
2972
3239
|
}
|
|
2973
|
-
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z
|
|
3240
|
+
if (fieldDef.optional) if (fieldDef.type === "Json") fieldSchema = z.union([fieldSchema, z.instanceof(DbNullClass)]);
|
|
2974
3241
|
else if (this.isTypeDefType(fieldDef.type)) fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
2975
3242
|
else fieldSchema = fieldSchema.nullable();
|
|
2976
3243
|
fieldSchema = fieldSchema.optional();
|
|
@@ -2978,9 +3245,9 @@ var ZodSchemaFactory = class {
|
|
|
2978
3245
|
if (!fieldDef.foreignKeyFor) checkedVariantFields[field] = fieldSchema;
|
|
2979
3246
|
}
|
|
2980
3247
|
});
|
|
2981
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
2982
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z
|
|
2983
|
-
const result = !hasRelation ? uncheckedUpdateSchema : z
|
|
3248
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(uncheckedVariantFields), modelDef.attributes) : z.strictObject(uncheckedVariantFields);
|
|
3249
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? ZodUtils.addCustomValidation(z.strictObject(checkedVariantFields), modelDef.attributes) : z.strictObject(checkedVariantFields);
|
|
3250
|
+
const result = !hasRelation ? uncheckedUpdateSchema : z.union([uncheckedUpdateSchema, checkedUpdateSchema]);
|
|
2984
3251
|
const idParts = [`${model}UpdateData`];
|
|
2985
3252
|
if (withoutRelationFields) idParts.push("WithoutRelation");
|
|
2986
3253
|
if (withoutFields.length) idParts.push(`Without${withoutFields.slice().sort().join("")}`);
|
|
@@ -2988,7 +3255,7 @@ var ZodSchemaFactory = class {
|
|
|
2988
3255
|
return result;
|
|
2989
3256
|
}
|
|
2990
3257
|
makeDeleteSchema(model, options) {
|
|
2991
|
-
const baseSchema = z
|
|
3258
|
+
const baseSchema = z.strictObject({
|
|
2992
3259
|
where: this.makeWhereSchema(model, true, false, false, options),
|
|
2993
3260
|
select: this.makeSelectSchema(model, options).optional().nullable(),
|
|
2994
3261
|
include: this.makeIncludeSchema(model, options).optional().nullable(),
|
|
@@ -3002,15 +3269,15 @@ var ZodSchemaFactory = class {
|
|
|
3002
3269
|
return schema;
|
|
3003
3270
|
}
|
|
3004
3271
|
makeDeleteManySchema(model, options) {
|
|
3005
|
-
const result = this.mergePluginArgsSchema(z
|
|
3272
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3006
3273
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3007
|
-
limit: z
|
|
3274
|
+
limit: z.number().int().nonnegative().optional()
|
|
3008
3275
|
}), "deleteMany").optional();
|
|
3009
3276
|
this.registerSchema(`${model}DeleteManyArgs`, result);
|
|
3010
3277
|
return result;
|
|
3011
3278
|
}
|
|
3012
3279
|
makeCountSchema(model, options) {
|
|
3013
|
-
const result = this.mergePluginArgsSchema(z
|
|
3280
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3014
3281
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3015
3282
|
skip: this.makeSkipSchema().optional(),
|
|
3016
3283
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3021,10 +3288,10 @@ var ZodSchemaFactory = class {
|
|
|
3021
3288
|
return result;
|
|
3022
3289
|
}
|
|
3023
3290
|
makeCountAggregateInputSchema(model) {
|
|
3024
|
-
const schema = z
|
|
3025
|
-
_all: z
|
|
3291
|
+
const schema = z.union([z.literal(true), z.strictObject({
|
|
3292
|
+
_all: z.literal(true).optional(),
|
|
3026
3293
|
...this.getModelFields(model).reduce((acc, [field]) => {
|
|
3027
|
-
acc[field] = z
|
|
3294
|
+
acc[field] = z.literal(true).optional();
|
|
3028
3295
|
return acc;
|
|
3029
3296
|
}, {})
|
|
3030
3297
|
})]);
|
|
@@ -3032,7 +3299,7 @@ var ZodSchemaFactory = class {
|
|
|
3032
3299
|
return schema;
|
|
3033
3300
|
}
|
|
3034
3301
|
makeAggregateSchema(model, options) {
|
|
3035
|
-
const result = this.mergePluginArgsSchema(z
|
|
3302
|
+
const result = this.mergePluginArgsSchema(z.strictObject({
|
|
3036
3303
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3037
3304
|
skip: this.makeSkipSchema().optional(),
|
|
3038
3305
|
take: this.makeTakeSchema().optional(),
|
|
@@ -3047,16 +3314,16 @@ var ZodSchemaFactory = class {
|
|
|
3047
3314
|
return result;
|
|
3048
3315
|
}
|
|
3049
3316
|
makeSumAvgInputSchema(model) {
|
|
3050
|
-
const schema = z
|
|
3051
|
-
if (this.isNumericField(fieldDef)) acc[field] = z
|
|
3317
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3318
|
+
if (this.isNumericField(fieldDef)) acc[field] = z.literal(true).optional();
|
|
3052
3319
|
return acc;
|
|
3053
3320
|
}, {}));
|
|
3054
3321
|
this.registerSchema(`${model}SumAvgAggregateInput`, schema);
|
|
3055
3322
|
return schema;
|
|
3056
3323
|
}
|
|
3057
3324
|
makeMinMaxInputSchema(model) {
|
|
3058
|
-
const schema = z
|
|
3059
|
-
if (!fieldDef.relation && !fieldDef.array) acc[field] = z
|
|
3325
|
+
const schema = z.strictObject(this.getModelFields(model).reduce((acc, [field, fieldDef]) => {
|
|
3326
|
+
if (!fieldDef.relation && !fieldDef.array) acc[field] = z.literal(true).optional();
|
|
3060
3327
|
return acc;
|
|
3061
3328
|
}, {}));
|
|
3062
3329
|
this.registerSchema(`${model}MinMaxAggregateInput`, schema);
|
|
@@ -3064,8 +3331,8 @@ var ZodSchemaFactory = class {
|
|
|
3064
3331
|
}
|
|
3065
3332
|
makeGroupBySchema(model, options) {
|
|
3066
3333
|
const nonRelationFields = this.getModelFields(model).filter(([, def]) => !def.relation).map(([name]) => name);
|
|
3067
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(z
|
|
3068
|
-
const baseSchema = z
|
|
3334
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(z.enum(nonRelationFields), true) : z.never();
|
|
3335
|
+
const baseSchema = z.strictObject({
|
|
3069
3336
|
where: this.makeWhereSchema(model, false, false, false, options).optional(),
|
|
3070
3337
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true, options), true).optional(),
|
|
3071
3338
|
by: bySchema,
|
|
@@ -3117,7 +3384,7 @@ var ZodSchemaFactory = class {
|
|
|
3117
3384
|
if (!procDef) throw createInternalError(`Procedure not found: ${procName}`);
|
|
3118
3385
|
const shape = {};
|
|
3119
3386
|
for (const param of Object.values(procDef.params ?? {})) shape[param.name] = this.makeProcedureParamSchema(param);
|
|
3120
|
-
const schema = z
|
|
3387
|
+
const schema = z.object(shape);
|
|
3121
3388
|
this.registerSchema(`${procName}ProcArgs`, schema);
|
|
3122
3389
|
return schema;
|
|
3123
3390
|
}
|
|
@@ -3125,10 +3392,10 @@ var ZodSchemaFactory = class {
|
|
|
3125
3392
|
let schema;
|
|
3126
3393
|
if (isTypeDef(this.schema, param.type)) schema = this.makeTypeDefSchema(param.type);
|
|
3127
3394
|
else if (isEnum(this.schema, param.type)) schema = this.makeEnumSchema(param.type);
|
|
3128
|
-
else if (param.type in (this.schema.models ?? {})) schema = z
|
|
3395
|
+
else if (param.type in (this.schema.models ?? {})) schema = z.record(z.string(), z.unknown());
|
|
3129
3396
|
else {
|
|
3130
3397
|
schema = this.makeScalarSchema(param.type);
|
|
3131
|
-
if (schema instanceof z
|
|
3398
|
+
if (schema instanceof z.ZodUnknown) throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
3132
3399
|
}
|
|
3133
3400
|
if (param.array) schema = schema.array();
|
|
3134
3401
|
if (param.optional) schema = schema.optional();
|
|
@@ -3164,10 +3431,10 @@ var ZodSchemaFactory = class {
|
|
|
3164
3431
|
return result;
|
|
3165
3432
|
}
|
|
3166
3433
|
makeSkipSchema() {
|
|
3167
|
-
return z
|
|
3434
|
+
return z.number().int().nonnegative();
|
|
3168
3435
|
}
|
|
3169
3436
|
makeTakeSchema() {
|
|
3170
|
-
return z
|
|
3437
|
+
return z.number().int();
|
|
3171
3438
|
}
|
|
3172
3439
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
3173
3440
|
return schema.refine((value) => !(value["select"] && value["include"]), "\"select\" and \"include\" cannot be used together");
|
|
@@ -3186,7 +3453,7 @@ var ZodSchemaFactory = class {
|
|
|
3186
3453
|
return nullable ? schema.nullable() : schema;
|
|
3187
3454
|
}
|
|
3188
3455
|
orArray(schema, canBeArray) {
|
|
3189
|
-
return canBeArray ? z
|
|
3456
|
+
return canBeArray ? z.union([schema, z.array(schema)]) : schema;
|
|
3190
3457
|
}
|
|
3191
3458
|
isNumericField(fieldDef) {
|
|
3192
3459
|
return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
|
|
@@ -3194,6 +3461,12 @@ var ZodSchemaFactory = class {
|
|
|
3194
3461
|
get providerSupportsCaseSensitivity() {
|
|
3195
3462
|
return this.schema.provider.type === "postgresql";
|
|
3196
3463
|
}
|
|
3464
|
+
get providerSupportsFullTextSearch() {
|
|
3465
|
+
return this.schema.provider.type === "postgresql";
|
|
3466
|
+
}
|
|
3467
|
+
get providerSupportsFuzzySearch() {
|
|
3468
|
+
return this.schema.provider.type === "postgresql";
|
|
3469
|
+
}
|
|
3197
3470
|
/**
|
|
3198
3471
|
* Gets the effective set of allowed FilterKind values for a specific model and field.
|
|
3199
3472
|
* Respects the precedence: model[field] > model.$all > $all[field] > $all.$all.
|
|
@@ -3242,10 +3515,10 @@ var ZodSchemaFactory = class {
|
|
|
3242
3515
|
createUnionFilterSchema(valueSchema, optional, components, allowedFilterKinds) {
|
|
3243
3516
|
if (Object.keys(components).length === 0) {
|
|
3244
3517
|
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return this.nullableIf(valueSchema, optional);
|
|
3245
|
-
return z
|
|
3518
|
+
return z.never();
|
|
3246
3519
|
}
|
|
3247
|
-
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z
|
|
3248
|
-
else return z
|
|
3520
|
+
if (!allowedFilterKinds || allowedFilterKinds.includes("Equality")) return z.union([this.nullableIf(valueSchema, optional), z.strictObject(components)]);
|
|
3521
|
+
else return z.strictObject(components);
|
|
3249
3522
|
}
|
|
3250
3523
|
canCreateModel(model) {
|
|
3251
3524
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -3355,6 +3628,8 @@ __decorate([
|
|
|
3355
3628
|
Object,
|
|
3356
3629
|
Boolean,
|
|
3357
3630
|
Boolean,
|
|
3631
|
+
Object,
|
|
3632
|
+
Object,
|
|
3358
3633
|
Object
|
|
3359
3634
|
]),
|
|
3360
3635
|
__decorateMetadata("design:returntype", void 0)
|
|
@@ -3424,6 +3699,8 @@ __decorate([
|
|
|
3424
3699
|
__decorateMetadata("design:paramtypes", [
|
|
3425
3700
|
Boolean,
|
|
3426
3701
|
Boolean,
|
|
3702
|
+
Object,
|
|
3703
|
+
Object,
|
|
3427
3704
|
Object
|
|
3428
3705
|
]),
|
|
3429
3706
|
__decorateMetadata("design:returntype", typeof (_ref10 = typeof ZodType !== "undefined" && ZodType) === "function" ? _ref10 : Object)
|
|
@@ -3913,7 +4190,7 @@ var BaseOperationHandler = class {
|
|
|
3913
4190
|
return new this.constructor(client, this.model, this.inputValidator);
|
|
3914
4191
|
}
|
|
3915
4192
|
get hasPolicyEnabled() {
|
|
3916
|
-
return this.options.plugins?.some((plugin) => plugin.
|
|
4193
|
+
return this.options.plugins?.some((plugin) => plugin.id === "policy") ?? false;
|
|
3917
4194
|
}
|
|
3918
4195
|
requireModel(model) {
|
|
3919
4196
|
return requireModel(this.schema, model);
|
|
@@ -4014,8 +4291,8 @@ var BaseOperationHandler = class {
|
|
|
4014
4291
|
const postCreateRelations = {};
|
|
4015
4292
|
for (const [field, value] of Object.entries(data)) {
|
|
4016
4293
|
const fieldDef = this.requireField(model, field);
|
|
4017
|
-
if (isScalarField(this.schema, model, field) || isForeignKeyField(this.schema, model, field)) if (fieldDef.array && value && typeof value === "object" && "set" in value && Array.isArray(value.set)) createFields[field] = this.dialect.transformInput(value.set, fieldDef.type, true);
|
|
4018
|
-
else createFields[field] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array);
|
|
4294
|
+
if (isScalarField(this.schema, model, field) || isForeignKeyField(this.schema, model, field)) if (fieldDef.array && value && typeof value === "object" && "set" in value && Array.isArray(value.set)) createFields[field] = this.dialect.transformInput(value.set, fieldDef.type, true, fieldDef);
|
|
4295
|
+
else createFields[field] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4019
4296
|
else if (!getManyToManyRelation(this.schema, model, field) && fieldDef.relation?.fields && fieldDef.relation?.references) {
|
|
4020
4297
|
const fkValues = await this.processOwnedRelationForCreate(kysely, fieldDef, value);
|
|
4021
4298
|
for (let i = 0; i < fieldDef.relation.fields.length; i++) createFields[fieldDef.relation.fields[i]] = fkValues[fieldDef.relation.references[i]];
|
|
@@ -4215,7 +4492,7 @@ var BaseOperationHandler = class {
|
|
|
4215
4492
|
for (const [name, value] of Object.entries(item)) {
|
|
4216
4493
|
const fieldDef = this.requireField(model, name);
|
|
4217
4494
|
invariant(!fieldDef.relation, "createMany does not support relations");
|
|
4218
|
-
newItem[name] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array);
|
|
4495
|
+
newItem[name] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4219
4496
|
}
|
|
4220
4497
|
if (fromRelation) for (const { fk, pk } of relationKeyPairs) newItem[fk] = fromRelation.ids[pk];
|
|
4221
4498
|
return this.fillGeneratedAndDefaultValues(modelDef, newItem);
|
|
@@ -4231,7 +4508,7 @@ var BaseOperationHandler = class {
|
|
|
4231
4508
|
if (Object.keys(item).length === allPassedFields.length) continue;
|
|
4232
4509
|
for (const field of allPassedFields) if (!(field in item)) {
|
|
4233
4510
|
const fieldDef = this.requireField(model, field);
|
|
4234
|
-
if (fieldDef.default !== void 0 && fieldDef.default !== null && typeof fieldDef.default !== "object") item[field] = this.dialect.transformInput(fieldDef.default, fieldDef.type, !!fieldDef.array);
|
|
4511
|
+
if (fieldDef.default !== void 0 && fieldDef.default !== null && typeof fieldDef.default !== "object") item[field] = this.dialect.transformInput(fieldDef.default, fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4235
4512
|
}
|
|
4236
4513
|
}
|
|
4237
4514
|
}
|
|
@@ -4294,15 +4571,15 @@ var BaseOperationHandler = class {
|
|
|
4294
4571
|
if (!(field in data)) {
|
|
4295
4572
|
if (typeof fieldDef?.default === "object" && "kind" in fieldDef.default) {
|
|
4296
4573
|
const generated = this.evalGenerator(fieldDef.default);
|
|
4297
|
-
if (generated !== void 0) values[field] = this.dialect.transformInput(generated, fieldDef.type, !!fieldDef.array);
|
|
4298
|
-
} else if (fieldDef?.updatedAt) values[field] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false);
|
|
4574
|
+
if (generated !== void 0) values[field] = this.dialect.transformInput(generated, fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4575
|
+
} else if (fieldDef?.updatedAt) values[field] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false, fieldDef);
|
|
4299
4576
|
else if (fieldDef?.default !== void 0) {
|
|
4300
4577
|
let value = fieldDef.default;
|
|
4301
4578
|
if (fieldDef.type === "Json") {
|
|
4302
4579
|
if (fieldDef.array && Array.isArray(value)) value = value.map((v) => typeof v === "string" ? JSON.parse(v) : v);
|
|
4303
4580
|
else if (typeof value === "string") value = JSON.parse(value);
|
|
4304
4581
|
}
|
|
4305
|
-
values[field] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array);
|
|
4582
|
+
values[field] = this.dialect.transformInput(value, fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4306
4583
|
}
|
|
4307
4584
|
}
|
|
4308
4585
|
}
|
|
@@ -4352,7 +4629,7 @@ var BaseOperationHandler = class {
|
|
|
4352
4629
|
const ignoredFields = new Set(typeof fieldDef.updatedAt === "boolean" ? [] : fieldDef.updatedAt.ignore);
|
|
4353
4630
|
if (Object.keys(data).some((field) => (isScalarField(this.schema, modelDef.name, field) || isForeignKeyField(this.schema, modelDef.name, field)) && !ignoredFields.has(field))) {
|
|
4354
4631
|
if (finalData === data) finalData = clone(data);
|
|
4355
|
-
finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false);
|
|
4632
|
+
finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false, fieldDef);
|
|
4356
4633
|
autoUpdatedFields.push(fieldName);
|
|
4357
4634
|
}
|
|
4358
4635
|
}
|
|
@@ -4456,7 +4733,7 @@ var BaseOperationHandler = class {
|
|
|
4456
4733
|
const fieldDef = this.requireField(model, field);
|
|
4457
4734
|
if (this.isNumericIncrementalUpdate(fieldDef, data[field])) return this.transformIncrementalUpdate(model, field, fieldDef, data[field]);
|
|
4458
4735
|
if (fieldDef.array && typeof data[field] === "object" && !Array.isArray(data[field]) && data[field]) return this.transformScalarListUpdate(model, field, fieldDef, data[field]);
|
|
4459
|
-
return this.dialect.transformInput(data[field], fieldDef.type, !!fieldDef.array);
|
|
4736
|
+
return this.dialect.transformInput(data[field], fieldDef.type, !!fieldDef.array, fieldDef);
|
|
4460
4737
|
}
|
|
4461
4738
|
isNumericIncrementalUpdate(fieldDef, value) {
|
|
4462
4739
|
if (!this.isNumericField(fieldDef)) return false;
|
|
@@ -4484,7 +4761,7 @@ var BaseOperationHandler = class {
|
|
|
4484
4761
|
transformIncrementalUpdate(model, field, fieldDef, payload) {
|
|
4485
4762
|
invariant(Object.keys(payload).length === 1, "Only one of \"set\", \"increment\", \"decrement\", \"multiply\", or \"divide\" can be provided");
|
|
4486
4763
|
const key = Object.keys(payload)[0];
|
|
4487
|
-
const value = this.dialect.transformInput(payload[key], fieldDef.type, false);
|
|
4764
|
+
const value = this.dialect.transformInput(payload[key], fieldDef.type, false, fieldDef);
|
|
4488
4765
|
const eb = expressionBuilder();
|
|
4489
4766
|
const fieldRef = this.dialect.fieldRef(model, field);
|
|
4490
4767
|
return match(key).with("set", () => value).with("increment", () => eb(fieldRef, "+", value)).with("decrement", () => eb(fieldRef, "-", value)).with("multiply", () => eb(fieldRef, "*", value)).with("divide", () => eb(fieldRef, "/", value)).otherwise(() => {
|
|
@@ -4494,7 +4771,7 @@ var BaseOperationHandler = class {
|
|
|
4494
4771
|
transformScalarListUpdate(model, field, fieldDef, payload) {
|
|
4495
4772
|
invariant(Object.keys(payload).length === 1, "Only one of \"set\", \"push\" can be provided");
|
|
4496
4773
|
const key = Object.keys(payload)[0];
|
|
4497
|
-
const value = this.dialect.transformInput(payload[key], fieldDef.type, true);
|
|
4774
|
+
const value = this.dialect.transformInput(payload[key], fieldDef.type, true, fieldDef);
|
|
4498
4775
|
const eb = expressionBuilder();
|
|
4499
4776
|
const fieldRef = this.dialect.fieldRef(model, field);
|
|
4500
4777
|
return match(key).with("set", () => value).with("push", () => {
|
|
@@ -6849,9 +7126,9 @@ var ClientImpl = class ClientImpl {
|
|
|
6849
7126
|
validateOptions(baseClient, options) {
|
|
6850
7127
|
if (!baseClient && !options.skipValidationForComputedFields) this.validateComputedFieldsConfig(options);
|
|
6851
7128
|
if (options.diagnostics) {
|
|
6852
|
-
const parseResult = z.object({
|
|
6853
|
-
slowQueryThresholdMs: z.number().nonnegative().optional(),
|
|
6854
|
-
slowQueryMaxRecords: z.int().nonnegative().or(z.literal(Infinity)).optional()
|
|
7129
|
+
const parseResult = z$1.object({
|
|
7130
|
+
slowQueryThresholdMs: z$1.number().nonnegative().optional(),
|
|
7131
|
+
slowQueryMaxRecords: z$1.int().nonnegative().or(z$1.literal(Infinity)).optional()
|
|
6855
7132
|
}).safeParse(options.diagnostics);
|
|
6856
7133
|
if (!parseResult.success) throw createConfigError(`Invalid diagnostics configuration: ${formatError(parseResult.error)}`);
|
|
6857
7134
|
}
|
|
@@ -6905,12 +7182,21 @@ var ClientImpl = class ClientImpl {
|
|
|
6905
7182
|
});
|
|
6906
7183
|
}
|
|
6907
7184
|
}
|
|
7185
|
+
getPromiseCallback(promise) {
|
|
7186
|
+
invariant(promise.cb, "Invalid ZenStackPromise, missing cb property");
|
|
7187
|
+
const cb = promise.cb;
|
|
7188
|
+
invariant(typeof cb === "function", "Invalid ZenStackPromise, cb property is not a function");
|
|
7189
|
+
return promise.cb;
|
|
7190
|
+
}
|
|
6908
7191
|
async sequentialTransaction(arg, options) {
|
|
6909
7192
|
const execute = async (tx) => {
|
|
6910
7193
|
const txClient = new ClientImpl(this.schema, this.$options, this);
|
|
6911
7194
|
txClient.kysely = tx;
|
|
6912
7195
|
const result = [];
|
|
6913
|
-
for (const promise of arg)
|
|
7196
|
+
for (const promise of arg) {
|
|
7197
|
+
const cb = this.getPromiseCallback(promise);
|
|
7198
|
+
result.push(await cb(txClient));
|
|
7199
|
+
}
|
|
6914
7200
|
return result;
|
|
6915
7201
|
};
|
|
6916
7202
|
if (this.kysely.isTransaction) return execute(this.kysely);
|
|
@@ -7697,6 +7983,15 @@ var DefaultOperationNodeVisitor = class extends OperationNodeVisitor {
|
|
|
7697
7983
|
visitCollate(node) {
|
|
7698
7984
|
this.defaultVisit(node);
|
|
7699
7985
|
}
|
|
7986
|
+
visitAlterType(node) {
|
|
7987
|
+
this.defaultVisit(node);
|
|
7988
|
+
}
|
|
7989
|
+
visitAddValue(node) {
|
|
7990
|
+
this.defaultVisit(node);
|
|
7991
|
+
}
|
|
7992
|
+
visitRenameValue(node) {
|
|
7993
|
+
this.defaultVisit(node);
|
|
7994
|
+
}
|
|
7700
7995
|
};
|
|
7701
7996
|
//#endregion
|
|
7702
7997
|
//#region src/utils/schema-utils.ts
|
|
@@ -7756,6 +8051,6 @@ var MatchingExpressionVisitor = class extends ExpressionVisitor {
|
|
|
7756
8051
|
}
|
|
7757
8052
|
};
|
|
7758
8053
|
//#endregion
|
|
7759
|
-
export { AllCrudOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, BaseCrudDialect, CRUD, CRUD_EXT, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, DbNull, DbNullClass, InputValidator, JsonNull, JsonNullClass, kysely_utils_exports as KyselyUtils, ORMError, ORMErrorReason, query_utils_exports as QueryUtils, RejectedByPolicyReason, schema_utils_exports as SchemaUtils, TransactionIsolationLevel, ZenStackClient, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
8054
|
+
export { AllCrudOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, BaseCrudDialect, CRUD, CRUD_EXT, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, DbNull, DbNullClass, ExtQueryArgsMarker, ExtResultMarker, InputValidator, JsonNull, JsonNullClass, kysely_utils_exports as KyselyUtils, ORMError, ORMErrorReason, query_utils_exports as QueryUtils, RejectedByPolicyReason, schema_utils_exports as SchemaUtils, TransactionIsolationLevel, ZenStackClient, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
7760
8055
|
|
|
7761
8056
|
//# sourceMappingURL=index.mjs.map
|