@zenstackhq/orm 3.3.0-beta.3 → 3.3.0-beta.5
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/index.cjs +339 -327
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -9
- package/dist/index.d.ts +17 -9
- package/dist/index.js +342 -330
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -956,24 +956,31 @@ var BaseCrudDialect = class {
|
|
|
956
956
|
if (_value === void 0) {
|
|
957
957
|
continue;
|
|
958
958
|
}
|
|
959
|
-
|
|
959
|
+
(0, import_common_helpers2.invariant)(fieldDef.array, "Field must be an array type to build array filter");
|
|
960
|
+
const value = this.transformInput(_value, fieldType, true);
|
|
961
|
+
let receiver = fieldRef;
|
|
962
|
+
if (isEnum(this.schema, fieldType)) {
|
|
963
|
+
receiver = this.eb.cast(fieldRef, import_kysely2.sql.raw("text[]"));
|
|
964
|
+
}
|
|
965
|
+
const buildArray = /* @__PURE__ */ __name((value2) => {
|
|
966
|
+
(0, import_common_helpers2.invariant)(Array.isArray(value2), "Array filter value must be an array");
|
|
967
|
+
return this.buildArrayValue(value2.map((v) => this.eb.val(v)), fieldType);
|
|
968
|
+
}, "buildArray");
|
|
960
969
|
switch (key) {
|
|
961
970
|
case "equals": {
|
|
962
|
-
clauses.push(this.
|
|
971
|
+
clauses.push(this.eb(receiver, "=", buildArray(value)));
|
|
963
972
|
break;
|
|
964
973
|
}
|
|
965
974
|
case "has": {
|
|
966
|
-
clauses.push(this.
|
|
967
|
-
value
|
|
968
|
-
])));
|
|
975
|
+
clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
|
|
969
976
|
break;
|
|
970
977
|
}
|
|
971
978
|
case "hasEvery": {
|
|
972
|
-
clauses.push(this.
|
|
979
|
+
clauses.push(this.buildArrayHasEvery(receiver, buildArray(value)));
|
|
973
980
|
break;
|
|
974
981
|
}
|
|
975
982
|
case "hasSome": {
|
|
976
|
-
clauses.push(this.
|
|
983
|
+
clauses.push(this.buildArrayHasSome(receiver, buildArray(value)));
|
|
977
984
|
break;
|
|
978
985
|
}
|
|
979
986
|
case "isEmpty": {
|
|
@@ -1809,8 +1816,17 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1809
1816
|
array
|
|
1810
1817
|
]);
|
|
1811
1818
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1819
|
+
buildArrayValue(values, _elemType) {
|
|
1820
|
+
return new import_kysely3.ExpressionWrapper(import_kysely3.ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
1821
|
+
}
|
|
1822
|
+
buildArrayContains(_field, _value) {
|
|
1823
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1824
|
+
}
|
|
1825
|
+
buildArrayHasEvery(_field, _values) {
|
|
1826
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1827
|
+
}
|
|
1828
|
+
buildArrayHasSome(_field, _values) {
|
|
1829
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1814
1830
|
}
|
|
1815
1831
|
buildJsonEqualityFilter(lhs, rhs) {
|
|
1816
1832
|
return this.eb.and([
|
|
@@ -1848,21 +1864,6 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1848
1864
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
1849
1865
|
return this.eb.exists(this.eb.selectFrom(import_kysely3.sql`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
1850
1866
|
}
|
|
1851
|
-
getFieldSqlType(fieldDef) {
|
|
1852
|
-
if (fieldDef.relation) {
|
|
1853
|
-
throw createInternalError("Cannot get SQL type of a relation field");
|
|
1854
|
-
}
|
|
1855
|
-
let result;
|
|
1856
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
1857
|
-
result = "varchar(255)";
|
|
1858
|
-
} else {
|
|
1859
|
-
result = (0, import_ts_pattern3.match)(fieldDef.type).with("String", () => "varchar(255)").with("Boolean", () => "tinyint(1)").with("Int", () => "int").with("BigInt", () => "bigint").with("Float", () => "double").with("Decimal", () => "decimal").with("DateTime", () => "datetime").with("Bytes", () => "blob").with("Json", () => "json").otherwise(() => "text");
|
|
1860
|
-
}
|
|
1861
|
-
if (fieldDef.array) {
|
|
1862
|
-
result = "json";
|
|
1863
|
-
}
|
|
1864
|
-
return result;
|
|
1865
|
-
}
|
|
1866
1867
|
getStringCasingBehavior() {
|
|
1867
1868
|
return {
|
|
1868
1869
|
supportsILike: false,
|
|
@@ -1902,21 +1903,36 @@ var import_decimal2 = __toESM(require("decimal.js"), 1);
|
|
|
1902
1903
|
var import_kysely4 = require("kysely");
|
|
1903
1904
|
var import_postgres_array = require("postgres-array");
|
|
1904
1905
|
var import_ts_pattern4 = require("ts-pattern");
|
|
1905
|
-
var
|
|
1906
|
-
var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
1906
|
+
var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectBase {
|
|
1907
1907
|
static {
|
|
1908
1908
|
__name(this, "PostgresCrudDialect");
|
|
1909
1909
|
}
|
|
1910
|
-
|
|
1911
|
-
local: true,
|
|
1912
|
-
offset: true
|
|
1913
|
-
});
|
|
1910
|
+
static typeParserOverrideApplied = false;
|
|
1914
1911
|
constructor(schema, options) {
|
|
1915
1912
|
super(schema, options);
|
|
1913
|
+
this.overrideTypeParsers();
|
|
1916
1914
|
}
|
|
1917
1915
|
get provider() {
|
|
1918
1916
|
return "postgresql";
|
|
1919
1917
|
}
|
|
1918
|
+
overrideTypeParsers() {
|
|
1919
|
+
if (this.options.fixPostgresTimezone !== false && !_PostgresCrudDialect.typeParserOverrideApplied) {
|
|
1920
|
+
_PostgresCrudDialect.typeParserOverrideApplied = true;
|
|
1921
|
+
import("pg").then((pg) => {
|
|
1922
|
+
pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (value) => {
|
|
1923
|
+
if (typeof value !== "string") {
|
|
1924
|
+
return value;
|
|
1925
|
+
}
|
|
1926
|
+
if (!this.hasTimezoneOffset(value)) {
|
|
1927
|
+
value += "Z";
|
|
1928
|
+
}
|
|
1929
|
+
const result = new Date(value);
|
|
1930
|
+
return isNaN(result.getTime()) ? value : result;
|
|
1931
|
+
});
|
|
1932
|
+
}).catch(() => {
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1920
1936
|
// #region capabilities
|
|
1921
1937
|
get supportsUpdateWithLimit() {
|
|
1922
1938
|
return false;
|
|
@@ -1961,9 +1977,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1961
1977
|
} else if (Array.isArray(value)) {
|
|
1962
1978
|
if (type === "Json" && !forArrayField) {
|
|
1963
1979
|
return JSON.stringify(value);
|
|
1964
|
-
}
|
|
1965
|
-
if (isEnum(this.schema, type)) {
|
|
1966
|
-
return this.eb.cast(import_kysely4.sql`ARRAY[${import_kysely4.sql.join(value.map((v) => this.transformInput(v, type, false)), import_kysely4.sql.raw(","))}]`, this.createSchemaQualifiedEnumType(type, true));
|
|
1967
1980
|
} else {
|
|
1968
1981
|
return value.map((v) => this.transformInput(v, type, false));
|
|
1969
1982
|
}
|
|
@@ -1977,24 +1990,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1977
1990
|
}).otherwise(() => value);
|
|
1978
1991
|
}
|
|
1979
1992
|
}
|
|
1980
|
-
createSchemaQualifiedEnumType(type, array) {
|
|
1981
|
-
let qualified = type;
|
|
1982
|
-
const enumDef = getEnum(this.schema, type);
|
|
1983
|
-
if (enumDef) {
|
|
1984
|
-
const schemaAttr = enumDef.attributes?.find((attr) => attr.name === "@@schema");
|
|
1985
|
-
if (schemaAttr) {
|
|
1986
|
-
const mapArg = schemaAttr.args?.find((arg) => arg.name === "map");
|
|
1987
|
-
if (mapArg && mapArg.value.kind === "literal") {
|
|
1988
|
-
const schemaName = mapArg.value.value;
|
|
1989
|
-
qualified = `"${schemaName}"."${type}"`;
|
|
1990
|
-
}
|
|
1991
|
-
} else {
|
|
1992
|
-
const defaultSchema = this.schema.provider.defaultSchema ?? "public";
|
|
1993
|
-
qualified = `"${defaultSchema}"."${type}"`;
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
return array ? import_kysely4.sql.raw(`${qualified}[]`) : import_kysely4.sql.raw(qualified);
|
|
1997
|
-
}
|
|
1998
1993
|
transformOutput(value, type, array) {
|
|
1999
1994
|
if (value === null || value === void 0) {
|
|
2000
1995
|
return value;
|
|
@@ -2017,18 +2012,16 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2017
2012
|
}
|
|
2018
2013
|
transformOutputDate(value) {
|
|
2019
2014
|
if (typeof value === "string") {
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
} else {
|
|
2024
|
-
return value;
|
|
2025
|
-
}
|
|
2026
|
-
} else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
|
|
2027
|
-
return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
|
|
2015
|
+
const normalized = this.hasTimezoneOffset(value) ? value : `${value}Z`;
|
|
2016
|
+
const parsed = new Date(normalized);
|
|
2017
|
+
return Number.isNaN(parsed.getTime()) ? value : parsed;
|
|
2028
2018
|
} else {
|
|
2029
2019
|
return value;
|
|
2030
2020
|
}
|
|
2031
2021
|
}
|
|
2022
|
+
hasTimezoneOffset(value) {
|
|
2023
|
+
return value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
|
|
2024
|
+
}
|
|
2032
2025
|
transformOutputBytes(value) {
|
|
2033
2026
|
return Buffer.isBuffer(value) ? Uint8Array.from(value) : typeof value === "string" && value.startsWith("\\x") ? Uint8Array.from(Buffer.from(value.slice(2), "hex")) : value;
|
|
2034
2027
|
}
|
|
@@ -2078,12 +2071,19 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2078
2071
|
array
|
|
2079
2072
|
]);
|
|
2080
2073
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2074
|
+
buildArrayValue(values, elemType) {
|
|
2075
|
+
const arr = import_kysely4.sql`ARRAY[${import_kysely4.sql.join(values, import_kysely4.sql.raw(","))}]`;
|
|
2076
|
+
const mappedType = this.getSqlType(elemType);
|
|
2077
|
+
return this.eb.cast(arr, import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]`);
|
|
2078
|
+
}
|
|
2079
|
+
buildArrayContains(field, value) {
|
|
2080
|
+
return this.eb(field, "@>", import_kysely4.sql`ARRAY[${value}]`);
|
|
2081
|
+
}
|
|
2082
|
+
buildArrayHasEvery(field, values) {
|
|
2083
|
+
return this.eb(field, "@>", values);
|
|
2084
|
+
}
|
|
2085
|
+
buildArrayHasSome(field, values) {
|
|
2086
|
+
return this.eb(field, "&&", values);
|
|
2087
2087
|
}
|
|
2088
2088
|
buildJsonPathSelection(receiver, path) {
|
|
2089
2089
|
if (path) {
|
|
@@ -2114,20 +2114,12 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2114
2114
|
receiver
|
|
2115
2115
|
]).as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2116
2116
|
}
|
|
2117
|
-
|
|
2118
|
-
if (
|
|
2119
|
-
|
|
2120
|
-
}
|
|
2121
|
-
let result;
|
|
2122
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
2123
|
-
result = "text";
|
|
2117
|
+
getSqlType(zmodelType) {
|
|
2118
|
+
if (isEnum(this.schema, zmodelType)) {
|
|
2119
|
+
return "text";
|
|
2124
2120
|
} else {
|
|
2125
|
-
|
|
2121
|
+
return (0, import_ts_pattern4.match)(zmodelType).with("String", () => "text").with("Boolean", () => "boolean").with("Int", () => "integer").with("BigInt", () => "bigint").with("Float", () => "double precision").with("Decimal", () => "decimal").with("DateTime", () => "timestamp").with("Bytes", () => "bytea").with("Json", () => "jsonb").otherwise(() => "text");
|
|
2126
2122
|
}
|
|
2127
|
-
if (fieldDef.array) {
|
|
2128
|
-
result += "[]";
|
|
2129
|
-
}
|
|
2130
|
-
return result;
|
|
2131
2123
|
}
|
|
2132
2124
|
getStringCasingBehavior() {
|
|
2133
2125
|
return {
|
|
@@ -2149,7 +2141,11 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2149
2141
|
}
|
|
2150
2142
|
}
|
|
2151
2143
|
const eb = (0, import_kysely4.expressionBuilder)();
|
|
2152
|
-
return eb.selectFrom(import_kysely4.sql`(VALUES ${import_kysely4.sql.join(rows.map((row) => import_kysely4.sql`(${import_kysely4.sql.join(row.map((v) => import_kysely4.sql.val(v)))})`), import_kysely4.sql.raw(", "))})`.as("$values")).select(fields.map((f, i) =>
|
|
2144
|
+
return eb.selectFrom(import_kysely4.sql`(VALUES ${import_kysely4.sql.join(rows.map((row) => import_kysely4.sql`(${import_kysely4.sql.join(row.map((v) => import_kysely4.sql.val(v)))})`), import_kysely4.sql.raw(", "))})`.as("$values")).select(fields.map((f, i) => {
|
|
2145
|
+
const mappedType = this.getSqlType(f.type);
|
|
2146
|
+
const castType = f.array ? import_kysely4.sql`${import_kysely4.sql.raw(mappedType)}[]` : import_kysely4.sql.raw(mappedType);
|
|
2147
|
+
return this.eb.cast(import_kysely4.sql.ref(`$values.column${i + 1}`), castType).as(f.name);
|
|
2148
|
+
}));
|
|
2153
2149
|
}
|
|
2154
2150
|
buildOrderByField(query, field, sort, nulls) {
|
|
2155
2151
|
return query.orderBy(field, (ob) => {
|
|
@@ -2414,8 +2410,17 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2414
2410
|
array
|
|
2415
2411
|
]);
|
|
2416
2412
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2413
|
+
buildArrayValue(values, _elemType) {
|
|
2414
|
+
return new import_kysely5.ExpressionWrapper(import_kysely5.ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
2415
|
+
}
|
|
2416
|
+
buildArrayContains(_field, _value) {
|
|
2417
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2418
|
+
}
|
|
2419
|
+
buildArrayHasEvery(_field, _values) {
|
|
2420
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2421
|
+
}
|
|
2422
|
+
buildArrayHasSome(_field, _values) {
|
|
2423
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2419
2424
|
}
|
|
2420
2425
|
castInt(expression) {
|
|
2421
2426
|
return expression;
|
|
@@ -2429,18 +2434,6 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2429
2434
|
import_kysely5.sql.lit('"')
|
|
2430
2435
|
]);
|
|
2431
2436
|
}
|
|
2432
|
-
getFieldSqlType(fieldDef) {
|
|
2433
|
-
if (fieldDef.relation) {
|
|
2434
|
-
throw createInternalError("Cannot get SQL type of a relation field");
|
|
2435
|
-
}
|
|
2436
|
-
if (fieldDef.array) {
|
|
2437
|
-
throw createInternalError("SQLite does not support scalar list type");
|
|
2438
|
-
}
|
|
2439
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
2440
|
-
return "text";
|
|
2441
|
-
}
|
|
2442
|
-
return (0, import_ts_pattern5.match)(fieldDef.type).with("String", () => "text").with("Boolean", () => "integer").with("Int", () => "integer").with("BigInt", () => "integer").with("Float", () => "real").with("Decimal", () => "decimal").with("DateTime", () => "numeric").with("Bytes", () => "blob").with("Json", () => "jsonb").otherwise(() => "text");
|
|
2443
|
-
}
|
|
2444
2437
|
getStringCasingBehavior() {
|
|
2445
2438
|
return {
|
|
2446
2439
|
supportsILike: false,
|
|
@@ -3157,11 +3150,15 @@ var BaseOperationHandler = class {
|
|
|
3157
3150
|
const autoUpdatedFields = [];
|
|
3158
3151
|
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
|
|
3159
3152
|
if (fieldDef.updatedAt && finalData[fieldName] === void 0) {
|
|
3160
|
-
|
|
3161
|
-
|
|
3153
|
+
const ignoredFields = new Set(typeof fieldDef.updatedAt === "boolean" ? [] : fieldDef.updatedAt.ignore);
|
|
3154
|
+
const hasNonIgnoredFields = Object.keys(data).some((field) => (isScalarField(this.schema, modelDef.name, field) || isForeignKeyField(this.schema, modelDef.name, field)) && !ignoredFields.has(field));
|
|
3155
|
+
if (hasNonIgnoredFields) {
|
|
3156
|
+
if (finalData === data) {
|
|
3157
|
+
finalData = (0, import_common_helpers7.clone)(data);
|
|
3158
|
+
}
|
|
3159
|
+
finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false);
|
|
3160
|
+
autoUpdatedFields.push(fieldName);
|
|
3162
3161
|
}
|
|
3163
|
-
finalData[fieldName] = this.dialect.transformInput(/* @__PURE__ */ new Date(), "DateTime", false);
|
|
3164
|
-
autoUpdatedFields.push(fieldName);
|
|
3165
3162
|
}
|
|
3166
3163
|
}
|
|
3167
3164
|
const thisEntity = await this.getEntityIds(kysely, model, combinedWhere);
|
|
@@ -4598,7 +4595,7 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
4598
4595
|
var import_common_helpers9 = require("@zenstackhq/common-helpers");
|
|
4599
4596
|
var import_decimal5 = __toESM(require("decimal.js"), 1);
|
|
4600
4597
|
var import_ts_pattern14 = require("ts-pattern");
|
|
4601
|
-
var
|
|
4598
|
+
var import_zod2 = require("zod");
|
|
4602
4599
|
|
|
4603
4600
|
// src/utils/zod-utils.ts
|
|
4604
4601
|
var import_v4 = require("zod-validation-error/v4");
|
|
@@ -4643,7 +4640,7 @@ __name(cache, "cache");
|
|
|
4643
4640
|
var import_common_helpers8 = require("@zenstackhq/common-helpers");
|
|
4644
4641
|
var import_decimal4 = __toESM(require("decimal.js"), 1);
|
|
4645
4642
|
var import_ts_pattern13 = require("ts-pattern");
|
|
4646
|
-
var
|
|
4643
|
+
var import_zod = require("zod");
|
|
4647
4644
|
var import_v3 = require("zod/v3");
|
|
4648
4645
|
function getArgValue(expr) {
|
|
4649
4646
|
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
@@ -4752,13 +4749,13 @@ function addBigIntValidation(schema, attributes) {
|
|
|
4752
4749
|
__name(addBigIntValidation, "addBigIntValidation");
|
|
4753
4750
|
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
4754
4751
|
let result = schema;
|
|
4755
|
-
if (schema instanceof
|
|
4752
|
+
if (schema instanceof import_zod.z.ZodString) {
|
|
4756
4753
|
result = schema.superRefine((v, ctx) => {
|
|
4757
4754
|
try {
|
|
4758
4755
|
new import_decimal4.default(v);
|
|
4759
4756
|
} catch (err) {
|
|
4760
4757
|
ctx.addIssue({
|
|
4761
|
-
code:
|
|
4758
|
+
code: import_zod.z.ZodIssueCode.custom,
|
|
4762
4759
|
message: `Invalid decimal: ${err}`
|
|
4763
4760
|
});
|
|
4764
4761
|
}
|
|
@@ -4766,7 +4763,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
|
4766
4763
|
}
|
|
4767
4764
|
function refine(schema2, op, value) {
|
|
4768
4765
|
return schema2.superRefine((v, ctx) => {
|
|
4769
|
-
const base =
|
|
4766
|
+
const base = import_zod.z.number();
|
|
4770
4767
|
const { error } = base[op](value).safeParse(v.toNumber());
|
|
4771
4768
|
error?.issues.forEach((issue) => {
|
|
4772
4769
|
if (op === "gt" || op === "gte") {
|
|
@@ -4975,7 +4972,7 @@ function evalCall(data, expr) {
|
|
|
4975
4972
|
}
|
|
4976
4973
|
(0, import_common_helpers8.invariant)(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
4977
4974
|
const fn = (0, import_ts_pattern13.match)(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
4978
|
-
return
|
|
4975
|
+
return import_zod.z.string()[fn]().safeParse(fieldArg).success;
|
|
4979
4976
|
}).with(import_ts_pattern13.P.union("has", "hasEvery", "hasSome"), (f) => {
|
|
4980
4977
|
(0, import_common_helpers8.invariant)(expr.args?.[1], `${f} requires a search argument`);
|
|
4981
4978
|
if (fieldArg === void 0 || fieldArg === null) {
|
|
@@ -5174,8 +5171,8 @@ var InputValidator = class {
|
|
|
5174
5171
|
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5175
5172
|
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5176
5173
|
if (createSchema && updateSchema) {
|
|
5177
|
-
(0, import_common_helpers9.invariant)(createSchema instanceof
|
|
5178
|
-
(0, import_common_helpers9.invariant)(updateSchema instanceof
|
|
5174
|
+
(0, import_common_helpers9.invariant)(createSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5175
|
+
(0, import_common_helpers9.invariant)(updateSchema instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5179
5176
|
result = createSchema.extend(updateSchema.shape);
|
|
5180
5177
|
} else if (createSchema) {
|
|
5181
5178
|
result = createSchema;
|
|
@@ -5196,7 +5193,7 @@ var InputValidator = class {
|
|
|
5196
5193
|
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5197
5194
|
result = plugin.queryArgs["$all"];
|
|
5198
5195
|
}
|
|
5199
|
-
(0, import_common_helpers9.invariant)(result === void 0 || result instanceof
|
|
5196
|
+
(0, import_common_helpers9.invariant)(result === void 0 || result instanceof import_zod2.z.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5200
5197
|
return result;
|
|
5201
5198
|
}
|
|
5202
5199
|
// #endregion
|
|
@@ -5217,7 +5214,7 @@ var InputValidator = class {
|
|
|
5217
5214
|
if (!unique) {
|
|
5218
5215
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
5219
5216
|
if (findOne) {
|
|
5220
|
-
fields["take"] =
|
|
5217
|
+
fields["take"] = import_zod2.z.literal(1).optional();
|
|
5221
5218
|
} else {
|
|
5222
5219
|
fields["take"] = this.makeTakeSchema().optional();
|
|
5223
5220
|
}
|
|
@@ -5225,7 +5222,7 @@ var InputValidator = class {
|
|
|
5225
5222
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
5226
5223
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
5227
5224
|
}
|
|
5228
|
-
const baseSchema =
|
|
5225
|
+
const baseSchema = import_zod2.z.strictObject(fields);
|
|
5229
5226
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
5230
5227
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
5231
5228
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -5235,7 +5232,7 @@ var InputValidator = class {
|
|
|
5235
5232
|
return result;
|
|
5236
5233
|
}
|
|
5237
5234
|
makeExistsSchema(model) {
|
|
5238
|
-
const baseSchema =
|
|
5235
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
5239
5236
|
where: this.makeWhereSchema(model, false).optional()
|
|
5240
5237
|
});
|
|
5241
5238
|
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
@@ -5246,30 +5243,30 @@ var InputValidator = class {
|
|
|
5246
5243
|
} else if (this.schema.enums && type in this.schema.enums) {
|
|
5247
5244
|
return this.makeEnumSchema(type);
|
|
5248
5245
|
} else {
|
|
5249
|
-
return (0, import_ts_pattern14.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(
|
|
5250
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
5251
|
-
this.extraValidationsEnabled ? addBigIntValidation(
|
|
5246
|
+
return (0, import_ts_pattern14.match)(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(import_zod2.z.string(), attributes) : import_zod2.z.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number()).with("Boolean", () => import_zod2.z.boolean()).with("BigInt", () => import_zod2.z.union([
|
|
5247
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number().int(), attributes) : import_zod2.z.number().int(),
|
|
5248
|
+
this.extraValidationsEnabled ? addBigIntValidation(import_zod2.z.bigint(), attributes) : import_zod2.z.bigint()
|
|
5252
5249
|
])).with("Decimal", () => {
|
|
5253
|
-
return
|
|
5254
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
5255
|
-
addDecimalValidation(
|
|
5256
|
-
addDecimalValidation(
|
|
5250
|
+
return import_zod2.z.union([
|
|
5251
|
+
this.extraValidationsEnabled ? addNumberValidation(import_zod2.z.number(), attributes) : import_zod2.z.number(),
|
|
5252
|
+
addDecimalValidation(import_zod2.z.instanceof(import_decimal5.default), attributes, this.extraValidationsEnabled),
|
|
5253
|
+
addDecimalValidation(import_zod2.z.string(), attributes, this.extraValidationsEnabled)
|
|
5257
5254
|
]);
|
|
5258
|
-
}).with("DateTime", () =>
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
])).with("Bytes", () =>
|
|
5255
|
+
}).with("DateTime", () => import_zod2.z.union([
|
|
5256
|
+
import_zod2.z.date(),
|
|
5257
|
+
import_zod2.z.iso.datetime()
|
|
5258
|
+
])).with("Bytes", () => import_zod2.z.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => import_zod2.z.unknown());
|
|
5262
5259
|
}
|
|
5263
5260
|
}
|
|
5264
5261
|
makeEnumSchema(type) {
|
|
5265
5262
|
const enumDef = getEnum(this.schema, type);
|
|
5266
5263
|
(0, import_common_helpers9.invariant)(enumDef, `Enum "${type}" not found in schema`);
|
|
5267
|
-
return
|
|
5264
|
+
return import_zod2.z.enum(Object.keys(enumDef.values));
|
|
5268
5265
|
}
|
|
5269
5266
|
makeTypeDefSchema(type) {
|
|
5270
5267
|
const typeDef = getTypeDef(this.schema, type);
|
|
5271
5268
|
(0, import_common_helpers9.invariant)(typeDef, `Type definition "${type}" not found in schema`);
|
|
5272
|
-
const schema =
|
|
5269
|
+
const schema = import_zod2.z.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
5273
5270
|
let fieldSchema = this.makeScalarSchema(def.type);
|
|
5274
5271
|
if (def.array) {
|
|
5275
5272
|
fieldSchema = fieldSchema.array();
|
|
@@ -5282,7 +5279,7 @@ var InputValidator = class {
|
|
|
5282
5279
|
fieldSchema
|
|
5283
5280
|
];
|
|
5284
5281
|
})));
|
|
5285
|
-
const finalSchema =
|
|
5282
|
+
const finalSchema = import_zod2.z.any().superRefine((value, ctx) => {
|
|
5286
5283
|
const parseResult = schema.safeParse(value);
|
|
5287
5284
|
if (!parseResult.success) {
|
|
5288
5285
|
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -5300,21 +5297,21 @@ var InputValidator = class {
|
|
|
5300
5297
|
if (withoutRelationFields) {
|
|
5301
5298
|
continue;
|
|
5302
5299
|
}
|
|
5303
|
-
fieldSchema =
|
|
5300
|
+
fieldSchema = import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
5304
5301
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
5305
5302
|
if (fieldDef.array) {
|
|
5306
|
-
fieldSchema =
|
|
5303
|
+
fieldSchema = import_zod2.z.union([
|
|
5307
5304
|
fieldSchema,
|
|
5308
|
-
|
|
5305
|
+
import_zod2.z.strictObject({
|
|
5309
5306
|
some: fieldSchema.optional(),
|
|
5310
5307
|
every: fieldSchema.optional(),
|
|
5311
5308
|
none: fieldSchema.optional()
|
|
5312
5309
|
})
|
|
5313
5310
|
]);
|
|
5314
5311
|
} else {
|
|
5315
|
-
fieldSchema =
|
|
5312
|
+
fieldSchema = import_zod2.z.union([
|
|
5316
5313
|
fieldSchema,
|
|
5317
|
-
|
|
5314
|
+
import_zod2.z.strictObject({
|
|
5318
5315
|
is: fieldSchema.optional(),
|
|
5319
5316
|
isNot: fieldSchema.optional()
|
|
5320
5317
|
})
|
|
@@ -5342,7 +5339,7 @@ var InputValidator = class {
|
|
|
5342
5339
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
5343
5340
|
for (const uniqueField of uniqueFields) {
|
|
5344
5341
|
if ("defs" in uniqueField) {
|
|
5345
|
-
fields[uniqueField.name] =
|
|
5342
|
+
fields[uniqueField.name] = import_zod2.z.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
5346
5343
|
(0, import_common_helpers9.invariant)(!def.relation, "unique field cannot be a relation");
|
|
5347
5344
|
let fieldSchema;
|
|
5348
5345
|
const enumDef = getEnum(this.schema, def.type);
|
|
@@ -5350,7 +5347,7 @@ var InputValidator = class {
|
|
|
5350
5347
|
if (Object.keys(enumDef.values).length > 0) {
|
|
5351
5348
|
fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, false, false);
|
|
5352
5349
|
} else {
|
|
5353
|
-
fieldSchema =
|
|
5350
|
+
fieldSchema = import_zod2.z.never();
|
|
5354
5351
|
}
|
|
5355
5352
|
} else {
|
|
5356
5353
|
fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
|
|
@@ -5363,13 +5360,13 @@ var InputValidator = class {
|
|
|
5363
5360
|
}
|
|
5364
5361
|
}
|
|
5365
5362
|
}
|
|
5366
|
-
fields["$expr"] =
|
|
5363
|
+
fields["$expr"] = import_zod2.z.custom((v) => typeof v === "function", {
|
|
5367
5364
|
error: '"$expr" must be a function'
|
|
5368
5365
|
}).optional();
|
|
5369
|
-
fields["AND"] = this.orArray(
|
|
5370
|
-
fields["OR"] =
|
|
5371
|
-
fields["NOT"] = this.orArray(
|
|
5372
|
-
const baseWhere =
|
|
5366
|
+
fields["AND"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
5367
|
+
fields["OR"] = import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
5368
|
+
fields["NOT"] = this.orArray(import_zod2.z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
5369
|
+
const baseWhere = import_zod2.z.strictObject(fields);
|
|
5373
5370
|
let result = baseWhere;
|
|
5374
5371
|
if (unique) {
|
|
5375
5372
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -5408,26 +5405,26 @@ var InputValidator = class {
|
|
|
5408
5405
|
}
|
|
5409
5406
|
}
|
|
5410
5407
|
}
|
|
5411
|
-
candidates.push(
|
|
5408
|
+
candidates.push(import_zod2.z.strictObject(fieldSchemas));
|
|
5412
5409
|
}
|
|
5413
|
-
const recursiveSchema =
|
|
5410
|
+
const recursiveSchema = import_zod2.z.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
|
|
5414
5411
|
if (array) {
|
|
5415
|
-
candidates.push(
|
|
5412
|
+
candidates.push(import_zod2.z.strictObject({
|
|
5416
5413
|
some: recursiveSchema,
|
|
5417
5414
|
every: recursiveSchema,
|
|
5418
5415
|
none: recursiveSchema
|
|
5419
5416
|
}));
|
|
5420
5417
|
} else {
|
|
5421
|
-
candidates.push(
|
|
5418
|
+
candidates.push(import_zod2.z.strictObject({
|
|
5422
5419
|
is: recursiveSchema,
|
|
5423
5420
|
isNot: recursiveSchema
|
|
5424
5421
|
}));
|
|
5425
5422
|
}
|
|
5426
5423
|
candidates.push(this.makeJsonFilterSchema(optional));
|
|
5427
5424
|
if (optional) {
|
|
5428
|
-
candidates.push(
|
|
5425
|
+
candidates.push(import_zod2.z.null());
|
|
5429
5426
|
}
|
|
5430
|
-
return
|
|
5427
|
+
return import_zod2.z.union(candidates);
|
|
5431
5428
|
}
|
|
5432
5429
|
isTypeDefType(type) {
|
|
5433
5430
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
@@ -5435,11 +5432,11 @@ var InputValidator = class {
|
|
|
5435
5432
|
makeEnumFilterSchema(enumName, optional, withAggregations, array) {
|
|
5436
5433
|
const enumDef = getEnum(this.schema, enumName);
|
|
5437
5434
|
(0, import_common_helpers9.invariant)(enumDef, `Enum "${enumName}" not found in schema`);
|
|
5438
|
-
const baseSchema =
|
|
5435
|
+
const baseSchema = import_zod2.z.enum(Object.keys(enumDef.values));
|
|
5439
5436
|
if (array) {
|
|
5440
5437
|
return this.internalMakeArrayFilterSchema(baseSchema);
|
|
5441
5438
|
}
|
|
5442
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
5439
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeEnumFilterSchema(enumName, optional, withAggregations, array)), [
|
|
5443
5440
|
"equals",
|
|
5444
5441
|
"in",
|
|
5445
5442
|
"notIn",
|
|
@@ -5449,65 +5446,65 @@ var InputValidator = class {
|
|
|
5449
5446
|
"_min",
|
|
5450
5447
|
"_max"
|
|
5451
5448
|
] : void 0);
|
|
5452
|
-
return
|
|
5449
|
+
return import_zod2.z.union([
|
|
5453
5450
|
this.nullableIf(baseSchema, optional),
|
|
5454
|
-
|
|
5451
|
+
import_zod2.z.strictObject(components)
|
|
5455
5452
|
]);
|
|
5456
5453
|
}
|
|
5457
5454
|
makeArrayFilterSchema(type) {
|
|
5458
5455
|
return this.internalMakeArrayFilterSchema(this.makeScalarSchema(type));
|
|
5459
5456
|
}
|
|
5460
5457
|
internalMakeArrayFilterSchema(elementSchema) {
|
|
5461
|
-
return
|
|
5458
|
+
return import_zod2.z.strictObject({
|
|
5462
5459
|
equals: elementSchema.array().optional(),
|
|
5463
5460
|
has: elementSchema.optional(),
|
|
5464
5461
|
hasEvery: elementSchema.array().optional(),
|
|
5465
5462
|
hasSome: elementSchema.array().optional(),
|
|
5466
|
-
isEmpty:
|
|
5463
|
+
isEmpty: import_zod2.z.boolean().optional()
|
|
5467
5464
|
});
|
|
5468
5465
|
}
|
|
5469
5466
|
makePrimitiveFilterSchema(type, optional, withAggregations) {
|
|
5470
|
-
return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () =>
|
|
5467
|
+
return (0, import_ts_pattern14.match)(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(import_ts_pattern14.P.union("Int", "Float", "Decimal", "BigInt"), (type2) => this.makeNumberFilterSchema(this.makeScalarSchema(type2), optional, withAggregations)).with("Boolean", () => this.makeBooleanFilterSchema(optional, withAggregations)).with("DateTime", () => this.makeDateTimeFilterSchema(optional, withAggregations)).with("Bytes", () => this.makeBytesFilterSchema(optional, withAggregations)).with("Json", () => this.makeJsonFilterSchema(optional)).with("Unsupported", () => import_zod2.z.never()).exhaustive();
|
|
5471
5468
|
}
|
|
5472
5469
|
makeJsonValueSchema(nullable, forFilter) {
|
|
5473
5470
|
const options = [
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5471
|
+
import_zod2.z.string(),
|
|
5472
|
+
import_zod2.z.number(),
|
|
5473
|
+
import_zod2.z.boolean(),
|
|
5474
|
+
import_zod2.z.instanceof(JsonNullClass)
|
|
5478
5475
|
];
|
|
5479
5476
|
if (forFilter) {
|
|
5480
|
-
options.push(
|
|
5477
|
+
options.push(import_zod2.z.instanceof(DbNullClass));
|
|
5481
5478
|
} else {
|
|
5482
5479
|
if (nullable) {
|
|
5483
|
-
options.push(
|
|
5480
|
+
options.push(import_zod2.z.instanceof(DbNullClass));
|
|
5484
5481
|
}
|
|
5485
5482
|
}
|
|
5486
5483
|
if (forFilter) {
|
|
5487
|
-
options.push(
|
|
5484
|
+
options.push(import_zod2.z.instanceof(AnyNullClass));
|
|
5488
5485
|
}
|
|
5489
|
-
const schema =
|
|
5486
|
+
const schema = import_zod2.z.union([
|
|
5490
5487
|
...options,
|
|
5491
|
-
|
|
5488
|
+
import_zod2.z.lazy(() => import_zod2.z.union([
|
|
5492
5489
|
this.makeJsonValueSchema(false, false),
|
|
5493
|
-
|
|
5490
|
+
import_zod2.z.null()
|
|
5494
5491
|
]).array()),
|
|
5495
|
-
|
|
5492
|
+
import_zod2.z.record(import_zod2.z.string(), import_zod2.z.lazy(() => import_zod2.z.union([
|
|
5496
5493
|
this.makeJsonValueSchema(false, false),
|
|
5497
|
-
|
|
5494
|
+
import_zod2.z.null()
|
|
5498
5495
|
])))
|
|
5499
5496
|
]);
|
|
5500
5497
|
return this.nullableIf(schema, nullable);
|
|
5501
5498
|
}
|
|
5502
5499
|
makeJsonFilterSchema(optional) {
|
|
5503
5500
|
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
5504
|
-
return
|
|
5505
|
-
path:
|
|
5501
|
+
return import_zod2.z.strictObject({
|
|
5502
|
+
path: import_zod2.z.string().optional(),
|
|
5506
5503
|
equals: valueSchema.optional(),
|
|
5507
5504
|
not: valueSchema.optional(),
|
|
5508
|
-
string_contains:
|
|
5509
|
-
string_starts_with:
|
|
5510
|
-
string_ends_with:
|
|
5505
|
+
string_contains: import_zod2.z.string().optional(),
|
|
5506
|
+
string_starts_with: import_zod2.z.string().optional(),
|
|
5507
|
+
string_ends_with: import_zod2.z.string().optional(),
|
|
5511
5508
|
mode: this.makeStringModeSchema().optional(),
|
|
5512
5509
|
array_contains: valueSchema.optional(),
|
|
5513
5510
|
array_starts_with: valueSchema.optional(),
|
|
@@ -5515,17 +5512,17 @@ var InputValidator = class {
|
|
|
5515
5512
|
});
|
|
5516
5513
|
}
|
|
5517
5514
|
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
5518
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
]), optional, () =>
|
|
5515
|
+
return this.makeCommonPrimitiveFilterSchema(import_zod2.z.union([
|
|
5516
|
+
import_zod2.z.iso.datetime(),
|
|
5517
|
+
import_zod2.z.date()
|
|
5518
|
+
]), optional, () => import_zod2.z.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
5522
5519
|
"_count",
|
|
5523
5520
|
"_min",
|
|
5524
5521
|
"_max"
|
|
5525
5522
|
] : void 0);
|
|
5526
5523
|
}
|
|
5527
5524
|
makeBooleanFilterSchema(optional, withAggregations) {
|
|
5528
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
5525
|
+
const components = this.makeCommonPrimitiveFilterComponents(import_zod2.z.boolean(), optional, () => import_zod2.z.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
5529
5526
|
"equals",
|
|
5530
5527
|
"not"
|
|
5531
5528
|
], withAggregations ? [
|
|
@@ -5533,14 +5530,14 @@ var InputValidator = class {
|
|
|
5533
5530
|
"_min",
|
|
5534
5531
|
"_max"
|
|
5535
5532
|
] : void 0);
|
|
5536
|
-
return
|
|
5537
|
-
this.nullableIf(
|
|
5538
|
-
|
|
5533
|
+
return import_zod2.z.union([
|
|
5534
|
+
this.nullableIf(import_zod2.z.boolean(), optional),
|
|
5535
|
+
import_zod2.z.strictObject(components)
|
|
5539
5536
|
]);
|
|
5540
5537
|
}
|
|
5541
5538
|
makeBytesFilterSchema(optional, withAggregations) {
|
|
5542
|
-
const baseSchema =
|
|
5543
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
5539
|
+
const baseSchema = import_zod2.z.instanceof(Uint8Array);
|
|
5540
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => import_zod2.z.instanceof(Uint8Array), [
|
|
5544
5541
|
"equals",
|
|
5545
5542
|
"in",
|
|
5546
5543
|
"notIn",
|
|
@@ -5550,9 +5547,9 @@ var InputValidator = class {
|
|
|
5550
5547
|
"_min",
|
|
5551
5548
|
"_max"
|
|
5552
5549
|
] : void 0);
|
|
5553
|
-
return
|
|
5550
|
+
return import_zod2.z.union([
|
|
5554
5551
|
this.nullableIf(baseSchema, optional),
|
|
5555
|
-
|
|
5552
|
+
import_zod2.z.strictObject(components)
|
|
5556
5553
|
]);
|
|
5557
5554
|
}
|
|
5558
5555
|
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
@@ -5569,7 +5566,7 @@ var InputValidator = class {
|
|
|
5569
5566
|
between: baseSchema.array().length(2).optional(),
|
|
5570
5567
|
not: makeThis().optional(),
|
|
5571
5568
|
...withAggregations?.includes("_count") ? {
|
|
5572
|
-
_count: this.makeNumberFilterSchema(
|
|
5569
|
+
_count: this.makeNumberFilterSchema(import_zod2.z.number().int(), false, false).optional()
|
|
5573
5570
|
} : {},
|
|
5574
5571
|
...withAggregations?.includes("_avg") ? {
|
|
5575
5572
|
_avg: commonAggSchema()
|
|
@@ -5594,13 +5591,13 @@ var InputValidator = class {
|
|
|
5594
5591
|
return result;
|
|
5595
5592
|
}
|
|
5596
5593
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
5597
|
-
return
|
|
5594
|
+
return import_zod2.z.union([
|
|
5598
5595
|
this.nullableIf(baseSchema, optional),
|
|
5599
|
-
|
|
5596
|
+
import_zod2.z.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
5600
5597
|
]);
|
|
5601
5598
|
}
|
|
5602
5599
|
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
5603
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
5600
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => import_zod2.z.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
5604
5601
|
"_count",
|
|
5605
5602
|
"_avg",
|
|
5606
5603
|
"_sum",
|
|
@@ -5609,17 +5606,17 @@ var InputValidator = class {
|
|
|
5609
5606
|
] : void 0);
|
|
5610
5607
|
}
|
|
5611
5608
|
makeStringFilterSchema(optional, withAggregations) {
|
|
5612
|
-
return
|
|
5613
|
-
this.nullableIf(
|
|
5614
|
-
|
|
5615
|
-
...this.makeCommonPrimitiveFilterComponents(
|
|
5609
|
+
return import_zod2.z.union([
|
|
5610
|
+
this.nullableIf(import_zod2.z.string(), optional),
|
|
5611
|
+
import_zod2.z.strictObject({
|
|
5612
|
+
...this.makeCommonPrimitiveFilterComponents(import_zod2.z.string(), optional, () => import_zod2.z.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
|
|
5616
5613
|
"_count",
|
|
5617
5614
|
"_min",
|
|
5618
5615
|
"_max"
|
|
5619
5616
|
] : void 0),
|
|
5620
|
-
startsWith:
|
|
5621
|
-
endsWith:
|
|
5622
|
-
contains:
|
|
5617
|
+
startsWith: import_zod2.z.string().optional(),
|
|
5618
|
+
endsWith: import_zod2.z.string().optional(),
|
|
5619
|
+
contains: import_zod2.z.string().optional(),
|
|
5623
5620
|
...this.providerSupportsCaseSensitivity ? {
|
|
5624
5621
|
mode: this.makeStringModeSchema().optional()
|
|
5625
5622
|
} : {}
|
|
@@ -5627,9 +5624,9 @@ var InputValidator = class {
|
|
|
5627
5624
|
]);
|
|
5628
5625
|
}
|
|
5629
5626
|
makeStringModeSchema() {
|
|
5630
|
-
return
|
|
5631
|
-
|
|
5632
|
-
|
|
5627
|
+
return import_zod2.z.union([
|
|
5628
|
+
import_zod2.z.literal("default"),
|
|
5629
|
+
import_zod2.z.literal("insensitive")
|
|
5633
5630
|
]);
|
|
5634
5631
|
}
|
|
5635
5632
|
makeSelectSchema(model) {
|
|
@@ -5640,27 +5637,27 @@ var InputValidator = class {
|
|
|
5640
5637
|
if (fieldDef.relation) {
|
|
5641
5638
|
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5642
5639
|
} else {
|
|
5643
|
-
fields[field] =
|
|
5640
|
+
fields[field] = import_zod2.z.boolean().optional();
|
|
5644
5641
|
}
|
|
5645
5642
|
}
|
|
5646
5643
|
const _countSchema = this.makeCountSelectionSchema(model);
|
|
5647
|
-
if (!(_countSchema instanceof
|
|
5644
|
+
if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
|
|
5648
5645
|
fields["_count"] = _countSchema;
|
|
5649
5646
|
}
|
|
5650
|
-
return
|
|
5647
|
+
return import_zod2.z.strictObject(fields);
|
|
5651
5648
|
}
|
|
5652
5649
|
makeCountSelectionSchema(model) {
|
|
5653
5650
|
const modelDef = requireModel(this.schema, model);
|
|
5654
5651
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
5655
5652
|
if (toManyRelations.length > 0) {
|
|
5656
|
-
return
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
select:
|
|
5653
|
+
return import_zod2.z.union([
|
|
5654
|
+
import_zod2.z.literal(true),
|
|
5655
|
+
import_zod2.z.strictObject({
|
|
5656
|
+
select: import_zod2.z.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
5660
5657
|
...acc,
|
|
5661
|
-
[fieldDef.name]:
|
|
5662
|
-
|
|
5663
|
-
|
|
5658
|
+
[fieldDef.name]: import_zod2.z.union([
|
|
5659
|
+
import_zod2.z.boolean(),
|
|
5660
|
+
import_zod2.z.strictObject({
|
|
5664
5661
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
5665
5662
|
})
|
|
5666
5663
|
]).optional()
|
|
@@ -5668,22 +5665,22 @@ var InputValidator = class {
|
|
|
5668
5665
|
})
|
|
5669
5666
|
]).optional();
|
|
5670
5667
|
} else {
|
|
5671
|
-
return
|
|
5668
|
+
return import_zod2.z.never();
|
|
5672
5669
|
}
|
|
5673
5670
|
}
|
|
5674
5671
|
makeRelationSelectIncludeSchema(model, field) {
|
|
5675
5672
|
const fieldDef = requireField(this.schema, model, field);
|
|
5676
|
-
let objSchema =
|
|
5673
|
+
let objSchema = import_zod2.z.strictObject({
|
|
5677
5674
|
...fieldDef.array || fieldDef.optional ? {
|
|
5678
5675
|
// to-many relations and optional to-one relations are filterable
|
|
5679
|
-
where:
|
|
5676
|
+
where: import_zod2.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
5680
5677
|
} : {},
|
|
5681
|
-
select:
|
|
5682
|
-
include:
|
|
5683
|
-
omit:
|
|
5678
|
+
select: import_zod2.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
5679
|
+
include: import_zod2.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
5680
|
+
omit: import_zod2.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
5684
5681
|
...fieldDef.array ? {
|
|
5685
5682
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
5686
|
-
orderBy:
|
|
5683
|
+
orderBy: import_zod2.z.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
5687
5684
|
skip: this.makeSkipSchema().optional(),
|
|
5688
5685
|
take: this.makeTakeSchema().optional(),
|
|
5689
5686
|
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
@@ -5692,8 +5689,8 @@ var InputValidator = class {
|
|
|
5692
5689
|
});
|
|
5693
5690
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
5694
5691
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
5695
|
-
return
|
|
5696
|
-
|
|
5692
|
+
return import_zod2.z.union([
|
|
5693
|
+
import_zod2.z.boolean(),
|
|
5697
5694
|
objSchema
|
|
5698
5695
|
]);
|
|
5699
5696
|
}
|
|
@@ -5704,13 +5701,13 @@ var InputValidator = class {
|
|
|
5704
5701
|
const fieldDef = requireField(this.schema, model, field);
|
|
5705
5702
|
if (!fieldDef.relation) {
|
|
5706
5703
|
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
5707
|
-
fields[field] =
|
|
5704
|
+
fields[field] = import_zod2.z.boolean().optional();
|
|
5708
5705
|
} else {
|
|
5709
|
-
fields[field] =
|
|
5706
|
+
fields[field] = import_zod2.z.literal(true).optional();
|
|
5710
5707
|
}
|
|
5711
5708
|
}
|
|
5712
5709
|
}
|
|
5713
|
-
return
|
|
5710
|
+
return import_zod2.z.strictObject(fields);
|
|
5714
5711
|
}
|
|
5715
5712
|
makeIncludeSchema(model) {
|
|
5716
5713
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5722,23 +5719,23 @@ var InputValidator = class {
|
|
|
5722
5719
|
}
|
|
5723
5720
|
}
|
|
5724
5721
|
const _countSchema = this.makeCountSelectionSchema(model);
|
|
5725
|
-
if (!(_countSchema instanceof
|
|
5722
|
+
if (!(_countSchema instanceof import_zod2.z.ZodNever)) {
|
|
5726
5723
|
fields["_count"] = _countSchema;
|
|
5727
5724
|
}
|
|
5728
|
-
return
|
|
5725
|
+
return import_zod2.z.strictObject(fields);
|
|
5729
5726
|
}
|
|
5730
5727
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
5731
5728
|
const modelDef = requireModel(this.schema, model);
|
|
5732
5729
|
const fields = {};
|
|
5733
|
-
const sort =
|
|
5734
|
-
|
|
5735
|
-
|
|
5730
|
+
const sort = import_zod2.z.union([
|
|
5731
|
+
import_zod2.z.literal("asc"),
|
|
5732
|
+
import_zod2.z.literal("desc")
|
|
5736
5733
|
]);
|
|
5737
5734
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5738
5735
|
const fieldDef = requireField(this.schema, model, field);
|
|
5739
5736
|
if (fieldDef.relation) {
|
|
5740
5737
|
if (withRelation) {
|
|
5741
|
-
fields[field] =
|
|
5738
|
+
fields[field] = import_zod2.z.lazy(() => {
|
|
5742
5739
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
5743
5740
|
if (fieldDef.array) {
|
|
5744
5741
|
relationOrderBy = relationOrderBy.extend({
|
|
@@ -5750,13 +5747,13 @@ var InputValidator = class {
|
|
|
5750
5747
|
}
|
|
5751
5748
|
} else {
|
|
5752
5749
|
if (fieldDef.optional) {
|
|
5753
|
-
fields[field] =
|
|
5750
|
+
fields[field] = import_zod2.z.union([
|
|
5754
5751
|
sort,
|
|
5755
|
-
|
|
5752
|
+
import_zod2.z.strictObject({
|
|
5756
5753
|
sort,
|
|
5757
|
-
nulls:
|
|
5758
|
-
|
|
5759
|
-
|
|
5754
|
+
nulls: import_zod2.z.union([
|
|
5755
|
+
import_zod2.z.literal("first"),
|
|
5756
|
+
import_zod2.z.literal("last")
|
|
5760
5757
|
])
|
|
5761
5758
|
})
|
|
5762
5759
|
]).optional();
|
|
@@ -5774,15 +5771,15 @@ var InputValidator = class {
|
|
|
5774
5771
|
"_max"
|
|
5775
5772
|
];
|
|
5776
5773
|
for (const agg of aggregationFields) {
|
|
5777
|
-
fields[agg] =
|
|
5774
|
+
fields[agg] = import_zod2.z.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
5778
5775
|
}
|
|
5779
5776
|
}
|
|
5780
|
-
return
|
|
5777
|
+
return import_zod2.z.strictObject(fields);
|
|
5781
5778
|
}
|
|
5782
5779
|
makeDistinctSchema(model) {
|
|
5783
5780
|
const modelDef = requireModel(this.schema, model);
|
|
5784
5781
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5785
|
-
return this.orArray(
|
|
5782
|
+
return this.orArray(import_zod2.z.enum(nonRelationFields), true);
|
|
5786
5783
|
}
|
|
5787
5784
|
makeCursorSchema(model) {
|
|
5788
5785
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -5791,7 +5788,7 @@ var InputValidator = class {
|
|
|
5791
5788
|
// #region Create
|
|
5792
5789
|
makeCreateSchema(model) {
|
|
5793
5790
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5794
|
-
const baseSchema =
|
|
5791
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
5795
5792
|
data: dataSchema,
|
|
5796
5793
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5797
5794
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -5843,7 +5840,7 @@ var InputValidator = class {
|
|
|
5843
5840
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
5844
5841
|
}
|
|
5845
5842
|
}
|
|
5846
|
-
let fieldSchema =
|
|
5843
|
+
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create"));
|
|
5847
5844
|
if (fieldDef.optional || fieldDef.array) {
|
|
5848
5845
|
fieldSchema = fieldSchema.optional();
|
|
5849
5846
|
} else {
|
|
@@ -5869,9 +5866,9 @@ var InputValidator = class {
|
|
|
5869
5866
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
5870
5867
|
if (fieldDef.array) {
|
|
5871
5868
|
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5872
|
-
fieldSchema =
|
|
5869
|
+
fieldSchema = import_zod2.z.union([
|
|
5873
5870
|
fieldSchema,
|
|
5874
|
-
|
|
5871
|
+
import_zod2.z.strictObject({
|
|
5875
5872
|
set: fieldSchema
|
|
5876
5873
|
})
|
|
5877
5874
|
]).optional();
|
|
@@ -5881,9 +5878,9 @@ var InputValidator = class {
|
|
|
5881
5878
|
}
|
|
5882
5879
|
if (fieldDef.optional) {
|
|
5883
5880
|
if (fieldDef.type === "Json") {
|
|
5884
|
-
fieldSchema =
|
|
5881
|
+
fieldSchema = import_zod2.z.union([
|
|
5885
5882
|
fieldSchema,
|
|
5886
|
-
|
|
5883
|
+
import_zod2.z.instanceof(DbNullClass)
|
|
5887
5884
|
]);
|
|
5888
5885
|
} else {
|
|
5889
5886
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -5895,19 +5892,19 @@ var InputValidator = class {
|
|
|
5895
5892
|
}
|
|
5896
5893
|
}
|
|
5897
5894
|
});
|
|
5898
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5899
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5895
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
5896
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
5900
5897
|
if (!hasRelation) {
|
|
5901
5898
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
5902
5899
|
} else {
|
|
5903
|
-
return
|
|
5900
|
+
return import_zod2.z.union([
|
|
5904
5901
|
uncheckedCreateSchema,
|
|
5905
5902
|
checkedCreateSchema,
|
|
5906
5903
|
...canBeArray ? [
|
|
5907
|
-
|
|
5904
|
+
import_zod2.z.array(uncheckedCreateSchema)
|
|
5908
5905
|
] : [],
|
|
5909
5906
|
...canBeArray ? [
|
|
5910
|
-
|
|
5907
|
+
import_zod2.z.array(checkedCreateSchema)
|
|
5911
5908
|
] : []
|
|
5912
5909
|
]);
|
|
5913
5910
|
}
|
|
@@ -5936,11 +5933,11 @@ var InputValidator = class {
|
|
|
5936
5933
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
5937
5934
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
5938
5935
|
}
|
|
5939
|
-
fields["update"] = array ? this.orArray(
|
|
5936
|
+
fields["update"] = array ? this.orArray(import_zod2.z.strictObject({
|
|
5940
5937
|
where: this.makeWhereSchema(fieldType, true),
|
|
5941
5938
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5942
|
-
}), true).optional() :
|
|
5943
|
-
|
|
5939
|
+
}), true).optional() : import_zod2.z.union([
|
|
5940
|
+
import_zod2.z.strictObject({
|
|
5944
5941
|
where: this.makeWhereSchema(fieldType, false).optional(),
|
|
5945
5942
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5946
5943
|
}),
|
|
@@ -5950,21 +5947,21 @@ var InputValidator = class {
|
|
|
5950
5947
|
if (!fieldDef.array) {
|
|
5951
5948
|
upsertWhere = upsertWhere.optional();
|
|
5952
5949
|
}
|
|
5953
|
-
fields["upsert"] = this.orArray(
|
|
5950
|
+
fields["upsert"] = this.orArray(import_zod2.z.strictObject({
|
|
5954
5951
|
where: upsertWhere,
|
|
5955
5952
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
5956
5953
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5957
5954
|
}), true).optional();
|
|
5958
5955
|
if (array) {
|
|
5959
5956
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5960
|
-
fields["updateMany"] = this.orArray(
|
|
5957
|
+
fields["updateMany"] = this.orArray(import_zod2.z.strictObject({
|
|
5961
5958
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
5962
5959
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5963
5960
|
}), true).optional();
|
|
5964
5961
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5965
5962
|
}
|
|
5966
5963
|
}
|
|
5967
|
-
return
|
|
5964
|
+
return import_zod2.z.strictObject(fields);
|
|
5968
5965
|
}
|
|
5969
5966
|
makeSetDataSchema(model, canBeArray) {
|
|
5970
5967
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -5976,36 +5973,36 @@ var InputValidator = class {
|
|
|
5976
5973
|
if (canBeArray) {
|
|
5977
5974
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5978
5975
|
} else {
|
|
5979
|
-
return
|
|
5980
|
-
|
|
5976
|
+
return import_zod2.z.union([
|
|
5977
|
+
import_zod2.z.boolean(),
|
|
5981
5978
|
this.makeWhereSchema(model, false)
|
|
5982
5979
|
]);
|
|
5983
5980
|
}
|
|
5984
5981
|
}
|
|
5985
5982
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
5986
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
5987
|
-
|
|
5983
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : import_zod2.z.union([
|
|
5984
|
+
import_zod2.z.boolean(),
|
|
5988
5985
|
this.makeWhereSchema(model, uniqueFilter)
|
|
5989
5986
|
]);
|
|
5990
5987
|
}
|
|
5991
5988
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
5992
5989
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
5993
5990
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
5994
|
-
return this.orArray(
|
|
5991
|
+
return this.orArray(import_zod2.z.strictObject({
|
|
5995
5992
|
where: whereSchema,
|
|
5996
5993
|
create: createSchema
|
|
5997
5994
|
}), canBeArray);
|
|
5998
5995
|
}
|
|
5999
5996
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
6000
|
-
return
|
|
5997
|
+
return import_zod2.z.strictObject({
|
|
6001
5998
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
6002
|
-
skipDuplicates:
|
|
5999
|
+
skipDuplicates: import_zod2.z.boolean().optional()
|
|
6003
6000
|
});
|
|
6004
6001
|
}
|
|
6005
6002
|
// #endregion
|
|
6006
6003
|
// #region Update
|
|
6007
6004
|
makeUpdateSchema(model) {
|
|
6008
|
-
const baseSchema =
|
|
6005
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
6009
6006
|
where: this.makeWhereSchema(model, true),
|
|
6010
6007
|
data: this.makeUpdateDataSchema(model),
|
|
6011
6008
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
@@ -6018,10 +6015,10 @@ var InputValidator = class {
|
|
|
6018
6015
|
return schema;
|
|
6019
6016
|
}
|
|
6020
6017
|
makeUpdateManySchema(model) {
|
|
6021
|
-
return this.mergePluginArgsSchema(
|
|
6018
|
+
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6022
6019
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6023
6020
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
6024
|
-
limit:
|
|
6021
|
+
limit: import_zod2.z.number().int().nonnegative().optional()
|
|
6025
6022
|
}), "updateMany");
|
|
6026
6023
|
}
|
|
6027
6024
|
makeUpdateManyAndReturnSchema(model) {
|
|
@@ -6034,7 +6031,7 @@ var InputValidator = class {
|
|
|
6034
6031
|
return schema;
|
|
6035
6032
|
}
|
|
6036
6033
|
makeUpsertSchema(model) {
|
|
6037
|
-
const baseSchema =
|
|
6034
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
6038
6035
|
where: this.makeWhereSchema(model, true),
|
|
6039
6036
|
create: this.makeCreateDataSchema(model, false),
|
|
6040
6037
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -6070,7 +6067,7 @@ var InputValidator = class {
|
|
|
6070
6067
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
6071
6068
|
}
|
|
6072
6069
|
}
|
|
6073
|
-
let fieldSchema =
|
|
6070
|
+
let fieldSchema = import_zod2.z.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update")).optional();
|
|
6074
6071
|
if (fieldDef.optional && !fieldDef.array) {
|
|
6075
6072
|
fieldSchema = fieldSchema.nullable();
|
|
6076
6073
|
}
|
|
@@ -6081,24 +6078,24 @@ var InputValidator = class {
|
|
|
6081
6078
|
} else {
|
|
6082
6079
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
6083
6080
|
if (this.isNumericField(fieldDef)) {
|
|
6084
|
-
fieldSchema =
|
|
6081
|
+
fieldSchema = import_zod2.z.union([
|
|
6085
6082
|
fieldSchema,
|
|
6086
|
-
|
|
6087
|
-
set: this.nullableIf(
|
|
6088
|
-
increment:
|
|
6089
|
-
decrement:
|
|
6090
|
-
multiply:
|
|
6091
|
-
divide:
|
|
6083
|
+
import_zod2.z.object({
|
|
6084
|
+
set: this.nullableIf(import_zod2.z.number().optional(), !!fieldDef.optional).optional(),
|
|
6085
|
+
increment: import_zod2.z.number().optional(),
|
|
6086
|
+
decrement: import_zod2.z.number().optional(),
|
|
6087
|
+
multiply: import_zod2.z.number().optional(),
|
|
6088
|
+
divide: import_zod2.z.number().optional()
|
|
6092
6089
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
6093
6090
|
]);
|
|
6094
6091
|
}
|
|
6095
6092
|
if (fieldDef.array) {
|
|
6096
6093
|
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
6097
|
-
fieldSchema =
|
|
6094
|
+
fieldSchema = import_zod2.z.union([
|
|
6098
6095
|
arraySchema,
|
|
6099
|
-
|
|
6096
|
+
import_zod2.z.object({
|
|
6100
6097
|
set: arraySchema.optional(),
|
|
6101
|
-
push:
|
|
6098
|
+
push: import_zod2.z.union([
|
|
6102
6099
|
fieldSchema,
|
|
6103
6100
|
fieldSchema.array()
|
|
6104
6101
|
]).optional()
|
|
@@ -6107,9 +6104,9 @@ var InputValidator = class {
|
|
|
6107
6104
|
}
|
|
6108
6105
|
if (fieldDef.optional) {
|
|
6109
6106
|
if (fieldDef.type === "Json") {
|
|
6110
|
-
fieldSchema =
|
|
6107
|
+
fieldSchema = import_zod2.z.union([
|
|
6111
6108
|
fieldSchema,
|
|
6112
|
-
|
|
6109
|
+
import_zod2.z.instanceof(DbNullClass)
|
|
6113
6110
|
]);
|
|
6114
6111
|
} else {
|
|
6115
6112
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -6122,12 +6119,12 @@ var InputValidator = class {
|
|
|
6122
6119
|
}
|
|
6123
6120
|
}
|
|
6124
6121
|
});
|
|
6125
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
6126
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
6122
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(uncheckedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(uncheckedVariantFields);
|
|
6123
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(import_zod2.z.strictObject(checkedVariantFields), modelDef.attributes) : import_zod2.z.strictObject(checkedVariantFields);
|
|
6127
6124
|
if (!hasRelation) {
|
|
6128
6125
|
return uncheckedUpdateSchema;
|
|
6129
6126
|
} else {
|
|
6130
|
-
return
|
|
6127
|
+
return import_zod2.z.union([
|
|
6131
6128
|
uncheckedUpdateSchema,
|
|
6132
6129
|
checkedUpdateSchema
|
|
6133
6130
|
]);
|
|
@@ -6136,7 +6133,7 @@ var InputValidator = class {
|
|
|
6136
6133
|
// #endregion
|
|
6137
6134
|
// #region Delete
|
|
6138
6135
|
makeDeleteSchema(model) {
|
|
6139
|
-
const baseSchema =
|
|
6136
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
6140
6137
|
where: this.makeWhereSchema(model, true),
|
|
6141
6138
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6142
6139
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -6148,15 +6145,15 @@ var InputValidator = class {
|
|
|
6148
6145
|
return schema;
|
|
6149
6146
|
}
|
|
6150
6147
|
makeDeleteManySchema(model) {
|
|
6151
|
-
return this.mergePluginArgsSchema(
|
|
6148
|
+
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6152
6149
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6153
|
-
limit:
|
|
6150
|
+
limit: import_zod2.z.number().int().nonnegative().optional()
|
|
6154
6151
|
}), "deleteMany").optional();
|
|
6155
6152
|
}
|
|
6156
6153
|
// #endregion
|
|
6157
6154
|
// #region Count
|
|
6158
6155
|
makeCountSchema(model) {
|
|
6159
|
-
return this.mergePluginArgsSchema(
|
|
6156
|
+
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6160
6157
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6161
6158
|
skip: this.makeSkipSchema().optional(),
|
|
6162
6159
|
take: this.makeTakeSchema().optional(),
|
|
@@ -6166,12 +6163,12 @@ var InputValidator = class {
|
|
|
6166
6163
|
}
|
|
6167
6164
|
makeCountAggregateInputSchema(model) {
|
|
6168
6165
|
const modelDef = requireModel(this.schema, model);
|
|
6169
|
-
return
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
_all:
|
|
6166
|
+
return import_zod2.z.union([
|
|
6167
|
+
import_zod2.z.literal(true),
|
|
6168
|
+
import_zod2.z.strictObject({
|
|
6169
|
+
_all: import_zod2.z.literal(true).optional(),
|
|
6173
6170
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6174
|
-
acc[field] =
|
|
6171
|
+
acc[field] = import_zod2.z.literal(true).optional();
|
|
6175
6172
|
return acc;
|
|
6176
6173
|
}, {})
|
|
6177
6174
|
})
|
|
@@ -6180,7 +6177,7 @@ var InputValidator = class {
|
|
|
6180
6177
|
// #endregion
|
|
6181
6178
|
// #region Aggregate
|
|
6182
6179
|
makeAggregateSchema(model) {
|
|
6183
|
-
return this.mergePluginArgsSchema(
|
|
6180
|
+
return this.mergePluginArgsSchema(import_zod2.z.strictObject({
|
|
6184
6181
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6185
6182
|
skip: this.makeSkipSchema().optional(),
|
|
6186
6183
|
take: this.makeTakeSchema().optional(),
|
|
@@ -6194,20 +6191,20 @@ var InputValidator = class {
|
|
|
6194
6191
|
}
|
|
6195
6192
|
makeSumAvgInputSchema(model) {
|
|
6196
6193
|
const modelDef = requireModel(this.schema, model);
|
|
6197
|
-
return
|
|
6194
|
+
return import_zod2.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6198
6195
|
const fieldDef = requireField(this.schema, model, field);
|
|
6199
6196
|
if (this.isNumericField(fieldDef)) {
|
|
6200
|
-
acc[field] =
|
|
6197
|
+
acc[field] = import_zod2.z.literal(true).optional();
|
|
6201
6198
|
}
|
|
6202
6199
|
return acc;
|
|
6203
6200
|
}, {}));
|
|
6204
6201
|
}
|
|
6205
6202
|
makeMinMaxInputSchema(model) {
|
|
6206
6203
|
const modelDef = requireModel(this.schema, model);
|
|
6207
|
-
return
|
|
6204
|
+
return import_zod2.z.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6208
6205
|
const fieldDef = requireField(this.schema, model, field);
|
|
6209
6206
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
6210
|
-
acc[field] =
|
|
6207
|
+
acc[field] = import_zod2.z.literal(true).optional();
|
|
6211
6208
|
}
|
|
6212
6209
|
return acc;
|
|
6213
6210
|
}, {}));
|
|
@@ -6215,8 +6212,8 @@ var InputValidator = class {
|
|
|
6215
6212
|
makeGroupBySchema(model) {
|
|
6216
6213
|
const modelDef = requireModel(this.schema, model);
|
|
6217
6214
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
6218
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
6219
|
-
const baseSchema =
|
|
6215
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(import_zod2.z.enum(nonRelationFields), true) : import_zod2.z.never();
|
|
6216
|
+
const baseSchema = import_zod2.z.strictObject({
|
|
6220
6217
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6221
6218
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
6222
6219
|
by: bySchema,
|
|
@@ -6290,10 +6287,10 @@ var InputValidator = class {
|
|
|
6290
6287
|
} else if (isEnum(this.schema, param.type)) {
|
|
6291
6288
|
schema = this.makeEnumSchema(param.type);
|
|
6292
6289
|
} else if (param.type in (this.schema.models ?? {})) {
|
|
6293
|
-
schema =
|
|
6290
|
+
schema = import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown());
|
|
6294
6291
|
} else {
|
|
6295
6292
|
schema = this.makeScalarSchema(param.type);
|
|
6296
|
-
if (schema instanceof
|
|
6293
|
+
if (schema instanceof import_zod2.z.ZodUnknown) {
|
|
6297
6294
|
throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
6298
6295
|
}
|
|
6299
6296
|
}
|
|
@@ -6325,10 +6322,10 @@ var InputValidator = class {
|
|
|
6325
6322
|
// #endregion
|
|
6326
6323
|
// #region Helpers
|
|
6327
6324
|
makeSkipSchema() {
|
|
6328
|
-
return
|
|
6325
|
+
return import_zod2.z.number().int().nonnegative();
|
|
6329
6326
|
}
|
|
6330
6327
|
makeTakeSchema() {
|
|
6331
|
-
return
|
|
6328
|
+
return import_zod2.z.number().int();
|
|
6332
6329
|
}
|
|
6333
6330
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
6334
6331
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -6340,9 +6337,9 @@ var InputValidator = class {
|
|
|
6340
6337
|
return nullable ? schema.nullable() : schema;
|
|
6341
6338
|
}
|
|
6342
6339
|
orArray(schema, canBeArray) {
|
|
6343
|
-
return canBeArray ?
|
|
6340
|
+
return canBeArray ? import_zod2.z.union([
|
|
6344
6341
|
schema,
|
|
6345
|
-
|
|
6342
|
+
import_zod2.z.array(schema)
|
|
6346
6343
|
]) : schema;
|
|
6347
6344
|
}
|
|
6348
6345
|
isNumericField(fieldDef) {
|
|
@@ -6383,7 +6380,7 @@ _ts_decorate([
|
|
|
6383
6380
|
_ts_metadata("design:paramtypes", [
|
|
6384
6381
|
String
|
|
6385
6382
|
]),
|
|
6386
|
-
_ts_metadata("design:returntype", typeof
|
|
6383
|
+
_ts_metadata("design:returntype", typeof import_zod2.z === "undefined" || typeof import_zod2.z.ZodType === "undefined" ? Object : import_zod2.z.ZodType)
|
|
6387
6384
|
], InputValidator.prototype, "makeTypeDefSchema", null);
|
|
6388
6385
|
_ts_decorate([
|
|
6389
6386
|
cache(),
|
|
@@ -6394,7 +6391,7 @@ _ts_decorate([
|
|
|
6394
6391
|
void 0,
|
|
6395
6392
|
void 0
|
|
6396
6393
|
]),
|
|
6397
|
-
_ts_metadata("design:returntype", typeof
|
|
6394
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6398
6395
|
], InputValidator.prototype, "makeWhereSchema", null);
|
|
6399
6396
|
_ts_decorate([
|
|
6400
6397
|
cache(),
|
|
@@ -6450,7 +6447,7 @@ _ts_decorate([
|
|
|
6450
6447
|
Boolean,
|
|
6451
6448
|
Boolean
|
|
6452
6449
|
]),
|
|
6453
|
-
_ts_metadata("design:returntype", typeof
|
|
6450
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6454
6451
|
], InputValidator.prototype, "makeDateTimeFilterSchema", null);
|
|
6455
6452
|
_ts_decorate([
|
|
6456
6453
|
cache(),
|
|
@@ -6459,7 +6456,7 @@ _ts_decorate([
|
|
|
6459
6456
|
Boolean,
|
|
6460
6457
|
Boolean
|
|
6461
6458
|
]),
|
|
6462
|
-
_ts_metadata("design:returntype", typeof
|
|
6459
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6463
6460
|
], InputValidator.prototype, "makeBooleanFilterSchema", null);
|
|
6464
6461
|
_ts_decorate([
|
|
6465
6462
|
cache(),
|
|
@@ -6468,7 +6465,7 @@ _ts_decorate([
|
|
|
6468
6465
|
Boolean,
|
|
6469
6466
|
Boolean
|
|
6470
6467
|
]),
|
|
6471
|
-
_ts_metadata("design:returntype", typeof
|
|
6468
|
+
_ts_metadata("design:returntype", typeof import_zod2.ZodType === "undefined" ? Object : import_zod2.ZodType)
|
|
6472
6469
|
], InputValidator.prototype, "makeBytesFilterSchema", null);
|
|
6473
6470
|
_ts_decorate([
|
|
6474
6471
|
cache(),
|
|
@@ -6743,7 +6740,7 @@ _ts_decorate([
|
|
|
6743
6740
|
_ts_metadata("design:paramtypes", [
|
|
6744
6741
|
Object
|
|
6745
6742
|
]),
|
|
6746
|
-
_ts_metadata("design:returntype", typeof
|
|
6743
|
+
_ts_metadata("design:returntype", typeof import_zod2.z === "undefined" || typeof import_zod2.z.ZodType === "undefined" ? Object : import_zod2.z.ZodType)
|
|
6747
6744
|
], InputValidator.prototype, "makeProcedureParamSchema", null);
|
|
6748
6745
|
_ts_decorate([
|
|
6749
6746
|
cache(),
|
|
@@ -6956,6 +6953,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
6956
6953
|
client;
|
|
6957
6954
|
modelToTableMap = /* @__PURE__ */ new Map();
|
|
6958
6955
|
fieldToColumnMap = /* @__PURE__ */ new Map();
|
|
6956
|
+
enumTypeMap = /* @__PURE__ */ new Map();
|
|
6959
6957
|
scopes = [];
|
|
6960
6958
|
dialect;
|
|
6961
6959
|
constructor(client) {
|
|
@@ -6973,14 +6971,20 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
6973
6971
|
}
|
|
6974
6972
|
}
|
|
6975
6973
|
}
|
|
6974
|
+
for (const [enumName, enumDef] of Object.entries(client.$schema.enums ?? {})) {
|
|
6975
|
+
const mappedName = this.getMappedName(enumDef);
|
|
6976
|
+
if (mappedName) {
|
|
6977
|
+
this.enumTypeMap.set(enumName, mappedName);
|
|
6978
|
+
}
|
|
6979
|
+
}
|
|
6976
6980
|
}
|
|
6977
6981
|
get schema() {
|
|
6978
6982
|
return this.client.$schema;
|
|
6979
6983
|
}
|
|
6980
6984
|
// #region overrides
|
|
6981
|
-
transformSelectQuery(node) {
|
|
6985
|
+
transformSelectQuery(node, queryId) {
|
|
6982
6986
|
if (!node.from?.froms) {
|
|
6983
|
-
return super.transformSelectQuery(node);
|
|
6987
|
+
return super.transformSelectQuery(node, queryId);
|
|
6984
6988
|
}
|
|
6985
6989
|
const processedFroms = node.from.froms.map((from) => this.processSelectTable(from));
|
|
6986
6990
|
const processedJoins = [];
|
|
@@ -6999,7 +7003,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
6999
7003
|
on: this.transformNode(join.on)
|
|
7000
7004
|
})) : void 0;
|
|
7001
7005
|
const selections = this.processSelectQuerySelections(node);
|
|
7002
|
-
const baseResult = super.transformSelectQuery(node);
|
|
7006
|
+
const baseResult = super.transformSelectQuery(node, queryId);
|
|
7003
7007
|
return {
|
|
7004
7008
|
...baseResult,
|
|
7005
7009
|
from: import_kysely7.FromNode.create(processedFroms.map((f) => f.node)),
|
|
@@ -7008,16 +7012,16 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7008
7012
|
};
|
|
7009
7013
|
});
|
|
7010
7014
|
}
|
|
7011
|
-
transformInsertQuery(node) {
|
|
7015
|
+
transformInsertQuery(node, queryId) {
|
|
7012
7016
|
if (!node.into) {
|
|
7013
|
-
return super.transformInsertQuery(node);
|
|
7017
|
+
return super.transformInsertQuery(node, queryId);
|
|
7014
7018
|
}
|
|
7015
7019
|
const model = extractModelName(node.into);
|
|
7016
7020
|
(0, import_common_helpers10.invariant)(model, 'InsertQueryNode must have a model name in the "into" clause');
|
|
7017
7021
|
return this.withScope({
|
|
7018
7022
|
model
|
|
7019
7023
|
}, () => {
|
|
7020
|
-
const baseResult = super.transformInsertQuery(node);
|
|
7024
|
+
const baseResult = super.transformInsertQuery(node, queryId);
|
|
7021
7025
|
let values = baseResult.values;
|
|
7022
7026
|
if (node.columns && values) {
|
|
7023
7027
|
values = this.processEnumMappingForColumns(model, node.columns, values);
|
|
@@ -7040,9 +7044,9 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7040
7044
|
selections: this.processSelections(node.selections)
|
|
7041
7045
|
};
|
|
7042
7046
|
}
|
|
7043
|
-
transformReference(node) {
|
|
7047
|
+
transformReference(node, queryId) {
|
|
7044
7048
|
if (!import_kysely7.ColumnNode.is(node.column)) {
|
|
7045
|
-
return super.transformReference(node);
|
|
7049
|
+
return super.transformReference(node, queryId);
|
|
7046
7050
|
}
|
|
7047
7051
|
const scope = this.resolveFieldFromScopes(node.column.column.name, node.table?.table.identifier.name);
|
|
7048
7052
|
if (scope && !scope.namesMapped && scope.model) {
|
|
@@ -7059,15 +7063,15 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7059
7063
|
return node;
|
|
7060
7064
|
}
|
|
7061
7065
|
}
|
|
7062
|
-
transformColumn(node) {
|
|
7066
|
+
transformColumn(node, queryId) {
|
|
7063
7067
|
const scope = this.resolveFieldFromScopes(node.column.name);
|
|
7064
7068
|
if (!scope || scope.namesMapped || !scope.model) {
|
|
7065
|
-
return super.transformColumn(node);
|
|
7069
|
+
return super.transformColumn(node, queryId);
|
|
7066
7070
|
}
|
|
7067
7071
|
const mappedName = this.mapFieldName(scope.model, node.column.name);
|
|
7068
7072
|
return import_kysely7.ColumnNode.create(mappedName);
|
|
7069
7073
|
}
|
|
7070
|
-
transformBinaryOperation(node) {
|
|
7074
|
+
transformBinaryOperation(node, queryId) {
|
|
7071
7075
|
if (import_kysely7.ReferenceNode.is(node.leftOperand) && import_kysely7.ColumnNode.is(node.leftOperand.column) && (import_kysely7.ValueNode.is(node.rightOperand) || import_kysely7.PrimitiveValueListNode.is(node.rightOperand))) {
|
|
7072
7076
|
const columnNode = node.leftOperand.column;
|
|
7073
7077
|
const resolvedScope = this.resolveFieldFromScopes(columnNode.column.name, node.leftOperand.table?.table.identifier.name);
|
|
@@ -7082,14 +7086,14 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7082
7086
|
return super.transformBinaryOperation({
|
|
7083
7087
|
...node,
|
|
7084
7088
|
rightOperand: resultValue
|
|
7085
|
-
});
|
|
7089
|
+
}, queryId);
|
|
7086
7090
|
}
|
|
7087
7091
|
}
|
|
7088
|
-
return super.transformBinaryOperation(node);
|
|
7092
|
+
return super.transformBinaryOperation(node, queryId);
|
|
7089
7093
|
}
|
|
7090
|
-
transformUpdateQuery(node) {
|
|
7094
|
+
transformUpdateQuery(node, queryId) {
|
|
7091
7095
|
if (!node.table) {
|
|
7092
|
-
return super.transformUpdateQuery(node);
|
|
7096
|
+
return super.transformUpdateQuery(node, queryId);
|
|
7093
7097
|
}
|
|
7094
7098
|
const { alias, node: innerTable } = stripAlias(node.table);
|
|
7095
7099
|
if (!innerTable || !import_kysely7.TableNode.is(innerTable)) {
|
|
@@ -7101,7 +7105,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7101
7105
|
model,
|
|
7102
7106
|
alias
|
|
7103
7107
|
}, () => {
|
|
7104
|
-
const baseResult = super.transformUpdateQuery(node);
|
|
7108
|
+
const baseResult = super.transformUpdateQuery(node, queryId);
|
|
7105
7109
|
const updates = baseResult.updates?.map((update, i) => {
|
|
7106
7110
|
if (import_kysely7.ColumnNode.is(update.column)) {
|
|
7107
7111
|
const origColumn = node.updates[i].column;
|
|
@@ -7118,7 +7122,7 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7118
7122
|
};
|
|
7119
7123
|
});
|
|
7120
7124
|
}
|
|
7121
|
-
transformDeleteQuery(node) {
|
|
7125
|
+
transformDeleteQuery(node, queryId) {
|
|
7122
7126
|
const scopes = node.from.froms.map((node2) => {
|
|
7123
7127
|
const { alias, node: innerNode } = stripAlias(node2);
|
|
7124
7128
|
return {
|
|
@@ -7132,12 +7136,12 @@ var QueryNameMapper = class extends import_kysely7.OperationNodeTransformer {
|
|
|
7132
7136
|
if (import_kysely7.TableNode.is(innerNode)) {
|
|
7133
7137
|
return this.wrapAlias(this.processTableRef(innerNode), alias);
|
|
7134
7138
|
} else {
|
|
7135
|
-
return super.transformNode(from);
|
|
7139
|
+
return super.transformNode(from, queryId);
|
|
7136
7140
|
}
|
|
7137
7141
|
});
|
|
7138
7142
|
return this.withScopes(scopes, () => {
|
|
7139
7143
|
return {
|
|
7140
|
-
...super.transformDeleteQuery(node),
|
|
7144
|
+
...super.transformDeleteQuery(node, queryId),
|
|
7141
7145
|
from: import_kysely7.FromNode.create(froms)
|
|
7142
7146
|
};
|
|
7143
7147
|
});
|
|
@@ -8046,7 +8050,7 @@ var textMatch = /* @__PURE__ */ __name((eb, args, { dialect }, method) => {
|
|
|
8046
8050
|
])).exhaustive();
|
|
8047
8051
|
return import_kysely9.sql`${fieldExpr} ${import_kysely9.sql.raw(op)} ${searchExpr} escape ${import_kysely9.sql.val("\\")}`;
|
|
8048
8052
|
}, "textMatch");
|
|
8049
|
-
var has = /* @__PURE__ */ __name((
|
|
8053
|
+
var has = /* @__PURE__ */ __name((_eb, args, context) => {
|
|
8050
8054
|
const [field, search2] = args;
|
|
8051
8055
|
if (!field) {
|
|
8052
8056
|
throw new Error('"field" parameter is required');
|
|
@@ -8054,11 +8058,9 @@ var has = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8054
8058
|
if (!search2) {
|
|
8055
8059
|
throw new Error('"search" parameter is required');
|
|
8056
8060
|
}
|
|
8057
|
-
return
|
|
8058
|
-
search2
|
|
8059
|
-
]);
|
|
8061
|
+
return context.dialect.buildArrayContains(field, search2);
|
|
8060
8062
|
}, "has");
|
|
8061
|
-
var hasEvery = /* @__PURE__ */ __name((
|
|
8063
|
+
var hasEvery = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
|
|
8062
8064
|
const [field, search2] = args;
|
|
8063
8065
|
if (!field) {
|
|
8064
8066
|
throw new Error('"field" parameter is required');
|
|
@@ -8066,9 +8068,9 @@ var hasEvery = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8066
8068
|
if (!search2) {
|
|
8067
8069
|
throw new Error('"search" parameter is required');
|
|
8068
8070
|
}
|
|
8069
|
-
return
|
|
8071
|
+
return dialect.buildArrayHasEvery(field, search2);
|
|
8070
8072
|
}, "hasEvery");
|
|
8071
|
-
var hasSome = /* @__PURE__ */ __name((
|
|
8073
|
+
var hasSome = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
|
|
8072
8074
|
const [field, search2] = args;
|
|
8073
8075
|
if (!field) {
|
|
8074
8076
|
throw new Error('"field" parameter is required');
|
|
@@ -8076,7 +8078,7 @@ var hasSome = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8076
8078
|
if (!search2) {
|
|
8077
8079
|
throw new Error('"search" parameter is required');
|
|
8078
8080
|
}
|
|
8079
|
-
return
|
|
8081
|
+
return dialect.buildArrayHasSome(field, search2);
|
|
8080
8082
|
}, "hasSome");
|
|
8081
8083
|
var isEmpty = /* @__PURE__ */ __name((eb, args, { dialect }) => {
|
|
8082
8084
|
const [field] = args;
|
|
@@ -8139,7 +8141,7 @@ var SchemaDbPusher = class {
|
|
|
8139
8141
|
async push() {
|
|
8140
8142
|
await this.kysely.transaction().execute(async (tx) => {
|
|
8141
8143
|
if (this.schema.enums && this.providerSupportsNativeEnum) {
|
|
8142
|
-
for (const
|
|
8144
|
+
for (const enumDef of Object.values(this.schema.enums)) {
|
|
8143
8145
|
let enumValues;
|
|
8144
8146
|
if (enumDef.fields) {
|
|
8145
8147
|
enumValues = Object.values(enumDef.fields).map((f) => {
|
|
@@ -8155,7 +8157,7 @@ var SchemaDbPusher = class {
|
|
|
8155
8157
|
} else {
|
|
8156
8158
|
enumValues = Object.values(enumDef.values);
|
|
8157
8159
|
}
|
|
8158
|
-
const createEnum = tx.schema.createType(
|
|
8160
|
+
const createEnum = tx.schema.createType(this.getEnumName(enumDef)).asEnum(enumValues);
|
|
8159
8161
|
await createEnum.execute();
|
|
8160
8162
|
}
|
|
8161
8163
|
}
|
|
@@ -8233,6 +8235,16 @@ var SchemaDbPusher = class {
|
|
|
8233
8235
|
}
|
|
8234
8236
|
return modelDef.name;
|
|
8235
8237
|
}
|
|
8238
|
+
getEnumName(enumDef) {
|
|
8239
|
+
const mapAttr = enumDef.attributes?.find((a) => a.name === "@@map");
|
|
8240
|
+
if (mapAttr && mapAttr.args?.[0]) {
|
|
8241
|
+
const mappedName = schema_exports.ExpressionUtils.getLiteralValue(mapAttr.args[0].value);
|
|
8242
|
+
if (mappedName) {
|
|
8243
|
+
return mappedName;
|
|
8244
|
+
}
|
|
8245
|
+
}
|
|
8246
|
+
return enumDef.name;
|
|
8247
|
+
}
|
|
8236
8248
|
getColumnName(fieldDef) {
|
|
8237
8249
|
const mapAttr = fieldDef.attributes?.find((a) => a.name === "@map");
|
|
8238
8250
|
if (mapAttr && mapAttr.args?.[0]) {
|