@zenstackhq/orm 3.3.0-beta.3 → 3.3.0-beta.4
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 +331 -323
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -6
- package/dist/index.d.ts +14 -6
- package/dist/index.js +334 -326
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -633,7 +633,7 @@ import { match as match6 } from "ts-pattern";
|
|
|
633
633
|
// src/client/crud/dialects/mysql.ts
|
|
634
634
|
import { invariant as invariant4 } from "@zenstackhq/common-helpers";
|
|
635
635
|
import Decimal from "decimal.js";
|
|
636
|
-
import { expressionBuilder as expressionBuilder2, sql as sql2 } from "kysely";
|
|
636
|
+
import { expressionBuilder as expressionBuilder2, ExpressionWrapper, sql as sql2, ValueListNode } from "kysely";
|
|
637
637
|
import { match as match3 } from "ts-pattern";
|
|
638
638
|
|
|
639
639
|
// src/common-types.ts
|
|
@@ -911,24 +911,31 @@ var BaseCrudDialect = class {
|
|
|
911
911
|
if (_value === void 0) {
|
|
912
912
|
continue;
|
|
913
913
|
}
|
|
914
|
-
|
|
914
|
+
invariant2(fieldDef.array, "Field must be an array type to build array filter");
|
|
915
|
+
const value = this.transformInput(_value, fieldType, true);
|
|
916
|
+
let receiver = fieldRef;
|
|
917
|
+
if (isEnum(this.schema, fieldType)) {
|
|
918
|
+
receiver = this.eb.cast(fieldRef, sql.raw("text[]"));
|
|
919
|
+
}
|
|
920
|
+
const buildArray = /* @__PURE__ */ __name((value2) => {
|
|
921
|
+
invariant2(Array.isArray(value2), "Array filter value must be an array");
|
|
922
|
+
return this.buildArrayValue(value2.map((v) => this.eb.val(v)), fieldType);
|
|
923
|
+
}, "buildArray");
|
|
915
924
|
switch (key) {
|
|
916
925
|
case "equals": {
|
|
917
|
-
clauses.push(this.
|
|
926
|
+
clauses.push(this.eb(receiver, "=", buildArray(value)));
|
|
918
927
|
break;
|
|
919
928
|
}
|
|
920
929
|
case "has": {
|
|
921
|
-
clauses.push(this.
|
|
922
|
-
value
|
|
923
|
-
])));
|
|
930
|
+
clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
|
|
924
931
|
break;
|
|
925
932
|
}
|
|
926
933
|
case "hasEvery": {
|
|
927
|
-
clauses.push(this.
|
|
934
|
+
clauses.push(this.buildArrayHasEvery(receiver, buildArray(value)));
|
|
928
935
|
break;
|
|
929
936
|
}
|
|
930
937
|
case "hasSome": {
|
|
931
|
-
clauses.push(this.
|
|
938
|
+
clauses.push(this.buildArrayHasSome(receiver, buildArray(value)));
|
|
932
939
|
break;
|
|
933
940
|
}
|
|
934
941
|
case "isEmpty": {
|
|
@@ -1764,8 +1771,17 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1764
1771
|
array
|
|
1765
1772
|
]);
|
|
1766
1773
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1774
|
+
buildArrayValue(values, _elemType) {
|
|
1775
|
+
return new ExpressionWrapper(ValueListNode.create(values.map((v) => v.toOperationNode())));
|
|
1776
|
+
}
|
|
1777
|
+
buildArrayContains(_field, _value) {
|
|
1778
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1779
|
+
}
|
|
1780
|
+
buildArrayHasEvery(_field, _values) {
|
|
1781
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1782
|
+
}
|
|
1783
|
+
buildArrayHasSome(_field, _values) {
|
|
1784
|
+
throw createNotSupportedError("MySQL does not support native array operations");
|
|
1769
1785
|
}
|
|
1770
1786
|
buildJsonEqualityFilter(lhs, rhs) {
|
|
1771
1787
|
return this.eb.and([
|
|
@@ -1803,21 +1819,6 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1803
1819
|
buildJsonArrayExistsPredicate(receiver, buildFilter) {
|
|
1804
1820
|
return this.eb.exists(this.eb.selectFrom(sql2`JSON_TABLE(${receiver}, '$[*]' COLUMNS(value JSON PATH '$'))`.as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
1805
1821
|
}
|
|
1806
|
-
getFieldSqlType(fieldDef) {
|
|
1807
|
-
if (fieldDef.relation) {
|
|
1808
|
-
throw createInternalError("Cannot get SQL type of a relation field");
|
|
1809
|
-
}
|
|
1810
|
-
let result;
|
|
1811
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
1812
|
-
result = "varchar(255)";
|
|
1813
|
-
} else {
|
|
1814
|
-
result = match3(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");
|
|
1815
|
-
}
|
|
1816
|
-
if (fieldDef.array) {
|
|
1817
|
-
result = "json";
|
|
1818
|
-
}
|
|
1819
|
-
return result;
|
|
1820
|
-
}
|
|
1821
1822
|
getStringCasingBehavior() {
|
|
1822
1823
|
return {
|
|
1823
1824
|
supportsILike: false,
|
|
@@ -1857,21 +1858,36 @@ import Decimal2 from "decimal.js";
|
|
|
1857
1858
|
import { expressionBuilder as expressionBuilder3, sql as sql3 } from "kysely";
|
|
1858
1859
|
import { parse as parsePostgresArray } from "postgres-array";
|
|
1859
1860
|
import { match as match4 } from "ts-pattern";
|
|
1860
|
-
|
|
1861
|
-
var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
1861
|
+
var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectBase {
|
|
1862
1862
|
static {
|
|
1863
1863
|
__name(this, "PostgresCrudDialect");
|
|
1864
1864
|
}
|
|
1865
|
-
|
|
1866
|
-
local: true,
|
|
1867
|
-
offset: true
|
|
1868
|
-
});
|
|
1865
|
+
static typeParserOverrideApplied = false;
|
|
1869
1866
|
constructor(schema, options) {
|
|
1870
1867
|
super(schema, options);
|
|
1868
|
+
this.overrideTypeParsers();
|
|
1871
1869
|
}
|
|
1872
1870
|
get provider() {
|
|
1873
1871
|
return "postgresql";
|
|
1874
1872
|
}
|
|
1873
|
+
overrideTypeParsers() {
|
|
1874
|
+
if (this.options.fixPostgresTimezone !== false && !_PostgresCrudDialect.typeParserOverrideApplied) {
|
|
1875
|
+
_PostgresCrudDialect.typeParserOverrideApplied = true;
|
|
1876
|
+
import("pg").then((pg) => {
|
|
1877
|
+
pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (value) => {
|
|
1878
|
+
if (typeof value !== "string") {
|
|
1879
|
+
return value;
|
|
1880
|
+
}
|
|
1881
|
+
if (!this.hasTimezoneOffset(value)) {
|
|
1882
|
+
value += "Z";
|
|
1883
|
+
}
|
|
1884
|
+
const result = new Date(value);
|
|
1885
|
+
return isNaN(result.getTime()) ? value : result;
|
|
1886
|
+
});
|
|
1887
|
+
}).catch(() => {
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1875
1891
|
// #region capabilities
|
|
1876
1892
|
get supportsUpdateWithLimit() {
|
|
1877
1893
|
return false;
|
|
@@ -1916,9 +1932,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1916
1932
|
} else if (Array.isArray(value)) {
|
|
1917
1933
|
if (type === "Json" && !forArrayField) {
|
|
1918
1934
|
return JSON.stringify(value);
|
|
1919
|
-
}
|
|
1920
|
-
if (isEnum(this.schema, type)) {
|
|
1921
|
-
return this.eb.cast(sql3`ARRAY[${sql3.join(value.map((v) => this.transformInput(v, type, false)), sql3.raw(","))}]`, this.createSchemaQualifiedEnumType(type, true));
|
|
1922
1935
|
} else {
|
|
1923
1936
|
return value.map((v) => this.transformInput(v, type, false));
|
|
1924
1937
|
}
|
|
@@ -1932,24 +1945,6 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1932
1945
|
}).otherwise(() => value);
|
|
1933
1946
|
}
|
|
1934
1947
|
}
|
|
1935
|
-
createSchemaQualifiedEnumType(type, array) {
|
|
1936
|
-
let qualified = type;
|
|
1937
|
-
const enumDef = getEnum(this.schema, type);
|
|
1938
|
-
if (enumDef) {
|
|
1939
|
-
const schemaAttr = enumDef.attributes?.find((attr) => attr.name === "@@schema");
|
|
1940
|
-
if (schemaAttr) {
|
|
1941
|
-
const mapArg = schemaAttr.args?.find((arg) => arg.name === "map");
|
|
1942
|
-
if (mapArg && mapArg.value.kind === "literal") {
|
|
1943
|
-
const schemaName = mapArg.value.value;
|
|
1944
|
-
qualified = `"${schemaName}"."${type}"`;
|
|
1945
|
-
}
|
|
1946
|
-
} else {
|
|
1947
|
-
const defaultSchema = this.schema.provider.defaultSchema ?? "public";
|
|
1948
|
-
qualified = `"${defaultSchema}"."${type}"`;
|
|
1949
|
-
}
|
|
1950
|
-
}
|
|
1951
|
-
return array ? sql3.raw(`${qualified}[]`) : sql3.raw(qualified);
|
|
1952
|
-
}
|
|
1953
1948
|
transformOutput(value, type, array) {
|
|
1954
1949
|
if (value === null || value === void 0) {
|
|
1955
1950
|
return value;
|
|
@@ -1972,18 +1967,16 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1972
1967
|
}
|
|
1973
1968
|
transformOutputDate(value) {
|
|
1974
1969
|
if (typeof value === "string") {
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
} else {
|
|
1979
|
-
return value;
|
|
1980
|
-
}
|
|
1981
|
-
} else if (value instanceof Date && this.options.fixPostgresTimezone !== false) {
|
|
1982
|
-
return new Date(value.getTime() - value.getTimezoneOffset() * 60 * 1e3);
|
|
1970
|
+
const normalized = this.hasTimezoneOffset(value) ? value : `${value}Z`;
|
|
1971
|
+
const parsed = new Date(normalized);
|
|
1972
|
+
return Number.isNaN(parsed.getTime()) ? value : parsed;
|
|
1983
1973
|
} else {
|
|
1984
1974
|
return value;
|
|
1985
1975
|
}
|
|
1986
1976
|
}
|
|
1977
|
+
hasTimezoneOffset(value) {
|
|
1978
|
+
return value.endsWith("Z") || /[+-]\d{2}:\d{2}$/.test(value);
|
|
1979
|
+
}
|
|
1987
1980
|
transformOutputBytes(value) {
|
|
1988
1981
|
return Buffer.isBuffer(value) ? Uint8Array.from(value) : typeof value === "string" && value.startsWith("\\x") ? Uint8Array.from(Buffer.from(value.slice(2), "hex")) : value;
|
|
1989
1982
|
}
|
|
@@ -2033,12 +2026,19 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2033
2026
|
array
|
|
2034
2027
|
]);
|
|
2035
2028
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2029
|
+
buildArrayValue(values, elemType) {
|
|
2030
|
+
const arr = sql3`ARRAY[${sql3.join(values, sql3.raw(","))}]`;
|
|
2031
|
+
const mappedType = this.getSqlType(elemType);
|
|
2032
|
+
return this.eb.cast(arr, sql3`${sql3.raw(mappedType)}[]`);
|
|
2033
|
+
}
|
|
2034
|
+
buildArrayContains(field, value) {
|
|
2035
|
+
return this.eb(field, "@>", sql3`ARRAY[${value}]`);
|
|
2036
|
+
}
|
|
2037
|
+
buildArrayHasEvery(field, values) {
|
|
2038
|
+
return this.eb(field, "@>", values);
|
|
2039
|
+
}
|
|
2040
|
+
buildArrayHasSome(field, values) {
|
|
2041
|
+
return this.eb(field, "&&", values);
|
|
2042
2042
|
}
|
|
2043
2043
|
buildJsonPathSelection(receiver, path) {
|
|
2044
2044
|
if (path) {
|
|
@@ -2069,20 +2069,12 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2069
2069
|
receiver
|
|
2070
2070
|
]).as("$items")).select(this.eb.lit(1).as("$t")).where(buildFilter(this.eb.ref("$items.value"))));
|
|
2071
2071
|
}
|
|
2072
|
-
|
|
2073
|
-
if (
|
|
2074
|
-
|
|
2075
|
-
}
|
|
2076
|
-
let result;
|
|
2077
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
2078
|
-
result = "text";
|
|
2072
|
+
getSqlType(zmodelType) {
|
|
2073
|
+
if (isEnum(this.schema, zmodelType)) {
|
|
2074
|
+
return "text";
|
|
2079
2075
|
} else {
|
|
2080
|
-
|
|
2081
|
-
}
|
|
2082
|
-
if (fieldDef.array) {
|
|
2083
|
-
result += "[]";
|
|
2076
|
+
return match4(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");
|
|
2084
2077
|
}
|
|
2085
|
-
return result;
|
|
2086
2078
|
}
|
|
2087
2079
|
getStringCasingBehavior() {
|
|
2088
2080
|
return {
|
|
@@ -2104,7 +2096,11 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2104
2096
|
}
|
|
2105
2097
|
}
|
|
2106
2098
|
const eb = expressionBuilder3();
|
|
2107
|
-
return eb.selectFrom(sql3`(VALUES ${sql3.join(rows.map((row) => sql3`(${sql3.join(row.map((v) => sql3.val(v)))})`), sql3.raw(", "))})`.as("$values")).select(fields.map((f, i) =>
|
|
2099
|
+
return eb.selectFrom(sql3`(VALUES ${sql3.join(rows.map((row) => sql3`(${sql3.join(row.map((v) => sql3.val(v)))})`), sql3.raw(", "))})`.as("$values")).select(fields.map((f, i) => {
|
|
2100
|
+
const mappedType = this.getSqlType(f.type);
|
|
2101
|
+
const castType = f.array ? sql3`${sql3.raw(mappedType)}[]` : sql3.raw(mappedType);
|
|
2102
|
+
return this.eb.cast(sql3.ref(`$values.column${i + 1}`), castType).as(f.name);
|
|
2103
|
+
}));
|
|
2108
2104
|
}
|
|
2109
2105
|
buildOrderByField(query, field, sort, nulls) {
|
|
2110
2106
|
return query.orderBy(field, (ob) => {
|
|
@@ -2118,7 +2114,7 @@ var PostgresCrudDialect = class extends LateralJoinDialectBase {
|
|
|
2118
2114
|
// src/client/crud/dialects/sqlite.ts
|
|
2119
2115
|
import { invariant as invariant6 } from "@zenstackhq/common-helpers";
|
|
2120
2116
|
import Decimal3 from "decimal.js";
|
|
2121
|
-
import { expressionBuilder as expressionBuilder4, sql as sql4 } from "kysely";
|
|
2117
|
+
import { expressionBuilder as expressionBuilder4, ExpressionWrapper as ExpressionWrapper2, sql as sql4, ValueListNode as ValueListNode2 } from "kysely";
|
|
2122
2118
|
import { match as match5 } from "ts-pattern";
|
|
2123
2119
|
var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
2124
2120
|
static {
|
|
@@ -2369,8 +2365,17 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2369
2365
|
array
|
|
2370
2366
|
]);
|
|
2371
2367
|
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2368
|
+
buildArrayValue(values, _elemType) {
|
|
2369
|
+
return new ExpressionWrapper2(ValueListNode2.create(values.map((v) => v.toOperationNode())));
|
|
2370
|
+
}
|
|
2371
|
+
buildArrayContains(_field, _value) {
|
|
2372
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2373
|
+
}
|
|
2374
|
+
buildArrayHasEvery(_field, _values) {
|
|
2375
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2376
|
+
}
|
|
2377
|
+
buildArrayHasSome(_field, _values) {
|
|
2378
|
+
throw createNotSupportedError("SQLite does not support native array operations");
|
|
2374
2379
|
}
|
|
2375
2380
|
castInt(expression) {
|
|
2376
2381
|
return expression;
|
|
@@ -2384,18 +2389,6 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2384
2389
|
sql4.lit('"')
|
|
2385
2390
|
]);
|
|
2386
2391
|
}
|
|
2387
|
-
getFieldSqlType(fieldDef) {
|
|
2388
|
-
if (fieldDef.relation) {
|
|
2389
|
-
throw createInternalError("Cannot get SQL type of a relation field");
|
|
2390
|
-
}
|
|
2391
|
-
if (fieldDef.array) {
|
|
2392
|
-
throw createInternalError("SQLite does not support scalar list type");
|
|
2393
|
-
}
|
|
2394
|
-
if (this.schema.enums?.[fieldDef.type]) {
|
|
2395
|
-
return "text";
|
|
2396
|
-
}
|
|
2397
|
-
return match5(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");
|
|
2398
|
-
}
|
|
2399
2392
|
getStringCasingBehavior() {
|
|
2400
2393
|
return {
|
|
2401
2394
|
supportsILike: false,
|
|
@@ -4553,7 +4546,7 @@ var UpdateOperationHandler = class extends BaseOperationHandler {
|
|
|
4553
4546
|
import { enumerate as enumerate3, invariant as invariant9 } from "@zenstackhq/common-helpers";
|
|
4554
4547
|
import Decimal5 from "decimal.js";
|
|
4555
4548
|
import { match as match14, P as P3 } from "ts-pattern";
|
|
4556
|
-
import { z as
|
|
4549
|
+
import { z as z2, ZodType } from "zod";
|
|
4557
4550
|
|
|
4558
4551
|
// src/utils/zod-utils.ts
|
|
4559
4552
|
import { fromError } from "zod-validation-error/v4";
|
|
@@ -4598,7 +4591,7 @@ __name(cache, "cache");
|
|
|
4598
4591
|
import { invariant as invariant8 } from "@zenstackhq/common-helpers";
|
|
4599
4592
|
import Decimal4 from "decimal.js";
|
|
4600
4593
|
import { match as match13, P as P2 } from "ts-pattern";
|
|
4601
|
-
import { z
|
|
4594
|
+
import { z } from "zod";
|
|
4602
4595
|
import { ZodIssueCode } from "zod/v3";
|
|
4603
4596
|
function getArgValue(expr) {
|
|
4604
4597
|
if (!expr || !schema_exports.ExpressionUtils.isLiteral(expr)) {
|
|
@@ -4707,13 +4700,13 @@ function addBigIntValidation(schema, attributes) {
|
|
|
4707
4700
|
__name(addBigIntValidation, "addBigIntValidation");
|
|
4708
4701
|
function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
4709
4702
|
let result = schema;
|
|
4710
|
-
if (schema instanceof
|
|
4703
|
+
if (schema instanceof z.ZodString) {
|
|
4711
4704
|
result = schema.superRefine((v, ctx) => {
|
|
4712
4705
|
try {
|
|
4713
4706
|
new Decimal4(v);
|
|
4714
4707
|
} catch (err) {
|
|
4715
4708
|
ctx.addIssue({
|
|
4716
|
-
code:
|
|
4709
|
+
code: z.ZodIssueCode.custom,
|
|
4717
4710
|
message: `Invalid decimal: ${err}`
|
|
4718
4711
|
});
|
|
4719
4712
|
}
|
|
@@ -4721,7 +4714,7 @@ function addDecimalValidation(schema, attributes, addExtraValidation) {
|
|
|
4721
4714
|
}
|
|
4722
4715
|
function refine(schema2, op, value) {
|
|
4723
4716
|
return schema2.superRefine((v, ctx) => {
|
|
4724
|
-
const base =
|
|
4717
|
+
const base = z.number();
|
|
4725
4718
|
const { error } = base[op](value).safeParse(v.toNumber());
|
|
4726
4719
|
error?.issues.forEach((issue) => {
|
|
4727
4720
|
if (op === "gt" || op === "gte") {
|
|
@@ -4930,7 +4923,7 @@ function evalCall(data, expr) {
|
|
|
4930
4923
|
}
|
|
4931
4924
|
invariant8(typeof fieldArg === "string", `"${f}" first argument must be a string`);
|
|
4932
4925
|
const fn = match13(f).with("isEmail", () => "email").with("isUrl", () => "url").with("isDateTime", () => "datetime").exhaustive();
|
|
4933
|
-
return
|
|
4926
|
+
return z.string()[fn]().safeParse(fieldArg).success;
|
|
4934
4927
|
}).with(P2.union("has", "hasEvery", "hasSome"), (f) => {
|
|
4935
4928
|
invariant8(expr.args?.[1], `${f} requires a search argument`);
|
|
4936
4929
|
if (fieldArg === void 0 || fieldArg === null) {
|
|
@@ -5129,8 +5122,8 @@ var InputValidator = class {
|
|
|
5129
5122
|
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
5130
5123
|
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
5131
5124
|
if (createSchema && updateSchema) {
|
|
5132
|
-
invariant9(createSchema instanceof
|
|
5133
|
-
invariant9(updateSchema instanceof
|
|
5125
|
+
invariant9(createSchema instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5126
|
+
invariant9(updateSchema instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5134
5127
|
result = createSchema.extend(updateSchema.shape);
|
|
5135
5128
|
} else if (createSchema) {
|
|
5136
5129
|
result = createSchema;
|
|
@@ -5151,7 +5144,7 @@ var InputValidator = class {
|
|
|
5151
5144
|
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
5152
5145
|
result = plugin.queryArgs["$all"];
|
|
5153
5146
|
}
|
|
5154
|
-
invariant9(result === void 0 || result instanceof
|
|
5147
|
+
invariant9(result === void 0 || result instanceof z2.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
5155
5148
|
return result;
|
|
5156
5149
|
}
|
|
5157
5150
|
// #endregion
|
|
@@ -5172,7 +5165,7 @@ var InputValidator = class {
|
|
|
5172
5165
|
if (!unique) {
|
|
5173
5166
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
5174
5167
|
if (findOne) {
|
|
5175
|
-
fields["take"] =
|
|
5168
|
+
fields["take"] = z2.literal(1).optional();
|
|
5176
5169
|
} else {
|
|
5177
5170
|
fields["take"] = this.makeTakeSchema().optional();
|
|
5178
5171
|
}
|
|
@@ -5180,7 +5173,7 @@ var InputValidator = class {
|
|
|
5180
5173
|
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
5181
5174
|
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
5182
5175
|
}
|
|
5183
|
-
const baseSchema =
|
|
5176
|
+
const baseSchema = z2.strictObject(fields);
|
|
5184
5177
|
let result = this.mergePluginArgsSchema(baseSchema, operation);
|
|
5185
5178
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
5186
5179
|
result = this.refineForSelectOmitMutuallyExclusive(result);
|
|
@@ -5190,7 +5183,7 @@ var InputValidator = class {
|
|
|
5190
5183
|
return result;
|
|
5191
5184
|
}
|
|
5192
5185
|
makeExistsSchema(model) {
|
|
5193
|
-
const baseSchema =
|
|
5186
|
+
const baseSchema = z2.strictObject({
|
|
5194
5187
|
where: this.makeWhereSchema(model, false).optional()
|
|
5195
5188
|
});
|
|
5196
5189
|
return this.mergePluginArgsSchema(baseSchema, "exists").optional();
|
|
@@ -5201,30 +5194,30 @@ var InputValidator = class {
|
|
|
5201
5194
|
} else if (this.schema.enums && type in this.schema.enums) {
|
|
5202
5195
|
return this.makeEnumSchema(type);
|
|
5203
5196
|
} else {
|
|
5204
|
-
return match14(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(
|
|
5205
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
5206
|
-
this.extraValidationsEnabled ? addBigIntValidation(
|
|
5197
|
+
return match14(type).with("String", () => this.extraValidationsEnabled ? addStringValidation(z2.string(), attributes) : z2.string()).with("Int", () => this.extraValidationsEnabled ? addNumberValidation(z2.number().int(), attributes) : z2.number().int()).with("Float", () => this.extraValidationsEnabled ? addNumberValidation(z2.number(), attributes) : z2.number()).with("Boolean", () => z2.boolean()).with("BigInt", () => z2.union([
|
|
5198
|
+
this.extraValidationsEnabled ? addNumberValidation(z2.number().int(), attributes) : z2.number().int(),
|
|
5199
|
+
this.extraValidationsEnabled ? addBigIntValidation(z2.bigint(), attributes) : z2.bigint()
|
|
5207
5200
|
])).with("Decimal", () => {
|
|
5208
|
-
return
|
|
5209
|
-
this.extraValidationsEnabled ? addNumberValidation(
|
|
5210
|
-
addDecimalValidation(
|
|
5211
|
-
addDecimalValidation(
|
|
5201
|
+
return z2.union([
|
|
5202
|
+
this.extraValidationsEnabled ? addNumberValidation(z2.number(), attributes) : z2.number(),
|
|
5203
|
+
addDecimalValidation(z2.instanceof(Decimal5), attributes, this.extraValidationsEnabled),
|
|
5204
|
+
addDecimalValidation(z2.string(), attributes, this.extraValidationsEnabled)
|
|
5212
5205
|
]);
|
|
5213
|
-
}).with("DateTime", () =>
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
])).with("Bytes", () =>
|
|
5206
|
+
}).with("DateTime", () => z2.union([
|
|
5207
|
+
z2.date(),
|
|
5208
|
+
z2.iso.datetime()
|
|
5209
|
+
])).with("Bytes", () => z2.instanceof(Uint8Array)).with("Json", () => this.makeJsonValueSchema(false, false)).otherwise(() => z2.unknown());
|
|
5217
5210
|
}
|
|
5218
5211
|
}
|
|
5219
5212
|
makeEnumSchema(type) {
|
|
5220
5213
|
const enumDef = getEnum(this.schema, type);
|
|
5221
5214
|
invariant9(enumDef, `Enum "${type}" not found in schema`);
|
|
5222
|
-
return
|
|
5215
|
+
return z2.enum(Object.keys(enumDef.values));
|
|
5223
5216
|
}
|
|
5224
5217
|
makeTypeDefSchema(type) {
|
|
5225
5218
|
const typeDef = getTypeDef(this.schema, type);
|
|
5226
5219
|
invariant9(typeDef, `Type definition "${type}" not found in schema`);
|
|
5227
|
-
const schema =
|
|
5220
|
+
const schema = z2.looseObject(Object.fromEntries(Object.entries(typeDef.fields).map(([field, def]) => {
|
|
5228
5221
|
let fieldSchema = this.makeScalarSchema(def.type);
|
|
5229
5222
|
if (def.array) {
|
|
5230
5223
|
fieldSchema = fieldSchema.array();
|
|
@@ -5237,7 +5230,7 @@ var InputValidator = class {
|
|
|
5237
5230
|
fieldSchema
|
|
5238
5231
|
];
|
|
5239
5232
|
})));
|
|
5240
|
-
const finalSchema =
|
|
5233
|
+
const finalSchema = z2.any().superRefine((value, ctx) => {
|
|
5241
5234
|
const parseResult = schema.safeParse(value);
|
|
5242
5235
|
if (!parseResult.success) {
|
|
5243
5236
|
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
@@ -5255,21 +5248,21 @@ var InputValidator = class {
|
|
|
5255
5248
|
if (withoutRelationFields) {
|
|
5256
5249
|
continue;
|
|
5257
5250
|
}
|
|
5258
|
-
fieldSchema =
|
|
5251
|
+
fieldSchema = z2.lazy(() => this.makeWhereSchema(fieldDef.type, false).optional());
|
|
5259
5252
|
fieldSchema = this.nullableIf(fieldSchema, !fieldDef.array && !!fieldDef.optional);
|
|
5260
5253
|
if (fieldDef.array) {
|
|
5261
|
-
fieldSchema =
|
|
5254
|
+
fieldSchema = z2.union([
|
|
5262
5255
|
fieldSchema,
|
|
5263
|
-
|
|
5256
|
+
z2.strictObject({
|
|
5264
5257
|
some: fieldSchema.optional(),
|
|
5265
5258
|
every: fieldSchema.optional(),
|
|
5266
5259
|
none: fieldSchema.optional()
|
|
5267
5260
|
})
|
|
5268
5261
|
]);
|
|
5269
5262
|
} else {
|
|
5270
|
-
fieldSchema =
|
|
5263
|
+
fieldSchema = z2.union([
|
|
5271
5264
|
fieldSchema,
|
|
5272
|
-
|
|
5265
|
+
z2.strictObject({
|
|
5273
5266
|
is: fieldSchema.optional(),
|
|
5274
5267
|
isNot: fieldSchema.optional()
|
|
5275
5268
|
})
|
|
@@ -5297,7 +5290,7 @@ var InputValidator = class {
|
|
|
5297
5290
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
5298
5291
|
for (const uniqueField of uniqueFields) {
|
|
5299
5292
|
if ("defs" in uniqueField) {
|
|
5300
|
-
fields[uniqueField.name] =
|
|
5293
|
+
fields[uniqueField.name] = z2.object(Object.fromEntries(Object.entries(uniqueField.defs).map(([key, def]) => {
|
|
5301
5294
|
invariant9(!def.relation, "unique field cannot be a relation");
|
|
5302
5295
|
let fieldSchema;
|
|
5303
5296
|
const enumDef = getEnum(this.schema, def.type);
|
|
@@ -5305,7 +5298,7 @@ var InputValidator = class {
|
|
|
5305
5298
|
if (Object.keys(enumDef.values).length > 0) {
|
|
5306
5299
|
fieldSchema = this.makeEnumFilterSchema(def.type, !!def.optional, false, false);
|
|
5307
5300
|
} else {
|
|
5308
|
-
fieldSchema =
|
|
5301
|
+
fieldSchema = z2.never();
|
|
5309
5302
|
}
|
|
5310
5303
|
} else {
|
|
5311
5304
|
fieldSchema = this.makePrimitiveFilterSchema(def.type, !!def.optional, false);
|
|
@@ -5318,13 +5311,13 @@ var InputValidator = class {
|
|
|
5318
5311
|
}
|
|
5319
5312
|
}
|
|
5320
5313
|
}
|
|
5321
|
-
fields["$expr"] =
|
|
5314
|
+
fields["$expr"] = z2.custom((v) => typeof v === "function", {
|
|
5322
5315
|
error: '"$expr" must be a function'
|
|
5323
5316
|
}).optional();
|
|
5324
|
-
fields["AND"] = this.orArray(
|
|
5325
|
-
fields["OR"] =
|
|
5326
|
-
fields["NOT"] = this.orArray(
|
|
5327
|
-
const baseWhere =
|
|
5317
|
+
fields["AND"] = this.orArray(z2.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
5318
|
+
fields["OR"] = z2.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)).array().optional();
|
|
5319
|
+
fields["NOT"] = this.orArray(z2.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields)), true).optional();
|
|
5320
|
+
const baseWhere = z2.strictObject(fields);
|
|
5328
5321
|
let result = baseWhere;
|
|
5329
5322
|
if (unique) {
|
|
5330
5323
|
const uniqueFields = getUniqueFields(this.schema, model);
|
|
@@ -5363,26 +5356,26 @@ var InputValidator = class {
|
|
|
5363
5356
|
}
|
|
5364
5357
|
}
|
|
5365
5358
|
}
|
|
5366
|
-
candidates.push(
|
|
5359
|
+
candidates.push(z2.strictObject(fieldSchemas));
|
|
5367
5360
|
}
|
|
5368
|
-
const recursiveSchema =
|
|
5361
|
+
const recursiveSchema = z2.lazy(() => this.makeTypedJsonFilterSchema(type, optional, false)).optional();
|
|
5369
5362
|
if (array) {
|
|
5370
|
-
candidates.push(
|
|
5363
|
+
candidates.push(z2.strictObject({
|
|
5371
5364
|
some: recursiveSchema,
|
|
5372
5365
|
every: recursiveSchema,
|
|
5373
5366
|
none: recursiveSchema
|
|
5374
5367
|
}));
|
|
5375
5368
|
} else {
|
|
5376
|
-
candidates.push(
|
|
5369
|
+
candidates.push(z2.strictObject({
|
|
5377
5370
|
is: recursiveSchema,
|
|
5378
5371
|
isNot: recursiveSchema
|
|
5379
5372
|
}));
|
|
5380
5373
|
}
|
|
5381
5374
|
candidates.push(this.makeJsonFilterSchema(optional));
|
|
5382
5375
|
if (optional) {
|
|
5383
|
-
candidates.push(
|
|
5376
|
+
candidates.push(z2.null());
|
|
5384
5377
|
}
|
|
5385
|
-
return
|
|
5378
|
+
return z2.union(candidates);
|
|
5386
5379
|
}
|
|
5387
5380
|
isTypeDefType(type) {
|
|
5388
5381
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
@@ -5390,11 +5383,11 @@ var InputValidator = class {
|
|
|
5390
5383
|
makeEnumFilterSchema(enumName, optional, withAggregations, array) {
|
|
5391
5384
|
const enumDef = getEnum(this.schema, enumName);
|
|
5392
5385
|
invariant9(enumDef, `Enum "${enumName}" not found in schema`);
|
|
5393
|
-
const baseSchema =
|
|
5386
|
+
const baseSchema = z2.enum(Object.keys(enumDef.values));
|
|
5394
5387
|
if (array) {
|
|
5395
5388
|
return this.internalMakeArrayFilterSchema(baseSchema);
|
|
5396
5389
|
}
|
|
5397
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
5390
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z2.lazy(() => this.makeEnumFilterSchema(enumName, optional, withAggregations, array)), [
|
|
5398
5391
|
"equals",
|
|
5399
5392
|
"in",
|
|
5400
5393
|
"notIn",
|
|
@@ -5404,65 +5397,65 @@ var InputValidator = class {
|
|
|
5404
5397
|
"_min",
|
|
5405
5398
|
"_max"
|
|
5406
5399
|
] : void 0);
|
|
5407
|
-
return
|
|
5400
|
+
return z2.union([
|
|
5408
5401
|
this.nullableIf(baseSchema, optional),
|
|
5409
|
-
|
|
5402
|
+
z2.strictObject(components)
|
|
5410
5403
|
]);
|
|
5411
5404
|
}
|
|
5412
5405
|
makeArrayFilterSchema(type) {
|
|
5413
5406
|
return this.internalMakeArrayFilterSchema(this.makeScalarSchema(type));
|
|
5414
5407
|
}
|
|
5415
5408
|
internalMakeArrayFilterSchema(elementSchema) {
|
|
5416
|
-
return
|
|
5409
|
+
return z2.strictObject({
|
|
5417
5410
|
equals: elementSchema.array().optional(),
|
|
5418
5411
|
has: elementSchema.optional(),
|
|
5419
5412
|
hasEvery: elementSchema.array().optional(),
|
|
5420
5413
|
hasSome: elementSchema.array().optional(),
|
|
5421
|
-
isEmpty:
|
|
5414
|
+
isEmpty: z2.boolean().optional()
|
|
5422
5415
|
});
|
|
5423
5416
|
}
|
|
5424
5417
|
makePrimitiveFilterSchema(type, optional, withAggregations) {
|
|
5425
|
-
return match14(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(P3.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", () =>
|
|
5418
|
+
return match14(type).with("String", () => this.makeStringFilterSchema(optional, withAggregations)).with(P3.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", () => z2.never()).exhaustive();
|
|
5426
5419
|
}
|
|
5427
5420
|
makeJsonValueSchema(nullable, forFilter) {
|
|
5428
5421
|
const options = [
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5422
|
+
z2.string(),
|
|
5423
|
+
z2.number(),
|
|
5424
|
+
z2.boolean(),
|
|
5425
|
+
z2.instanceof(JsonNullClass)
|
|
5433
5426
|
];
|
|
5434
5427
|
if (forFilter) {
|
|
5435
|
-
options.push(
|
|
5428
|
+
options.push(z2.instanceof(DbNullClass));
|
|
5436
5429
|
} else {
|
|
5437
5430
|
if (nullable) {
|
|
5438
|
-
options.push(
|
|
5431
|
+
options.push(z2.instanceof(DbNullClass));
|
|
5439
5432
|
}
|
|
5440
5433
|
}
|
|
5441
5434
|
if (forFilter) {
|
|
5442
|
-
options.push(
|
|
5435
|
+
options.push(z2.instanceof(AnyNullClass));
|
|
5443
5436
|
}
|
|
5444
|
-
const schema =
|
|
5437
|
+
const schema = z2.union([
|
|
5445
5438
|
...options,
|
|
5446
|
-
|
|
5439
|
+
z2.lazy(() => z2.union([
|
|
5447
5440
|
this.makeJsonValueSchema(false, false),
|
|
5448
|
-
|
|
5441
|
+
z2.null()
|
|
5449
5442
|
]).array()),
|
|
5450
|
-
|
|
5443
|
+
z2.record(z2.string(), z2.lazy(() => z2.union([
|
|
5451
5444
|
this.makeJsonValueSchema(false, false),
|
|
5452
|
-
|
|
5445
|
+
z2.null()
|
|
5453
5446
|
])))
|
|
5454
5447
|
]);
|
|
5455
5448
|
return this.nullableIf(schema, nullable);
|
|
5456
5449
|
}
|
|
5457
5450
|
makeJsonFilterSchema(optional) {
|
|
5458
5451
|
const valueSchema = this.makeJsonValueSchema(optional, true);
|
|
5459
|
-
return
|
|
5460
|
-
path:
|
|
5452
|
+
return z2.strictObject({
|
|
5453
|
+
path: z2.string().optional(),
|
|
5461
5454
|
equals: valueSchema.optional(),
|
|
5462
5455
|
not: valueSchema.optional(),
|
|
5463
|
-
string_contains:
|
|
5464
|
-
string_starts_with:
|
|
5465
|
-
string_ends_with:
|
|
5456
|
+
string_contains: z2.string().optional(),
|
|
5457
|
+
string_starts_with: z2.string().optional(),
|
|
5458
|
+
string_ends_with: z2.string().optional(),
|
|
5466
5459
|
mode: this.makeStringModeSchema().optional(),
|
|
5467
5460
|
array_contains: valueSchema.optional(),
|
|
5468
5461
|
array_starts_with: valueSchema.optional(),
|
|
@@ -5470,17 +5463,17 @@ var InputValidator = class {
|
|
|
5470
5463
|
});
|
|
5471
5464
|
}
|
|
5472
5465
|
makeDateTimeFilterSchema(optional, withAggregations) {
|
|
5473
|
-
return this.makeCommonPrimitiveFilterSchema(
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
]), optional, () =>
|
|
5466
|
+
return this.makeCommonPrimitiveFilterSchema(z2.union([
|
|
5467
|
+
z2.iso.datetime(),
|
|
5468
|
+
z2.date()
|
|
5469
|
+
]), optional, () => z2.lazy(() => this.makeDateTimeFilterSchema(optional, withAggregations)), withAggregations ? [
|
|
5477
5470
|
"_count",
|
|
5478
5471
|
"_min",
|
|
5479
5472
|
"_max"
|
|
5480
5473
|
] : void 0);
|
|
5481
5474
|
}
|
|
5482
5475
|
makeBooleanFilterSchema(optional, withAggregations) {
|
|
5483
|
-
const components = this.makeCommonPrimitiveFilterComponents(
|
|
5476
|
+
const components = this.makeCommonPrimitiveFilterComponents(z2.boolean(), optional, () => z2.lazy(() => this.makeBooleanFilterSchema(optional, withAggregations)), [
|
|
5484
5477
|
"equals",
|
|
5485
5478
|
"not"
|
|
5486
5479
|
], withAggregations ? [
|
|
@@ -5488,14 +5481,14 @@ var InputValidator = class {
|
|
|
5488
5481
|
"_min",
|
|
5489
5482
|
"_max"
|
|
5490
5483
|
] : void 0);
|
|
5491
|
-
return
|
|
5492
|
-
this.nullableIf(
|
|
5493
|
-
|
|
5484
|
+
return z2.union([
|
|
5485
|
+
this.nullableIf(z2.boolean(), optional),
|
|
5486
|
+
z2.strictObject(components)
|
|
5494
5487
|
]);
|
|
5495
5488
|
}
|
|
5496
5489
|
makeBytesFilterSchema(optional, withAggregations) {
|
|
5497
|
-
const baseSchema =
|
|
5498
|
-
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () =>
|
|
5490
|
+
const baseSchema = z2.instanceof(Uint8Array);
|
|
5491
|
+
const components = this.makeCommonPrimitiveFilterComponents(baseSchema, optional, () => z2.instanceof(Uint8Array), [
|
|
5499
5492
|
"equals",
|
|
5500
5493
|
"in",
|
|
5501
5494
|
"notIn",
|
|
@@ -5505,9 +5498,9 @@ var InputValidator = class {
|
|
|
5505
5498
|
"_min",
|
|
5506
5499
|
"_max"
|
|
5507
5500
|
] : void 0);
|
|
5508
|
-
return
|
|
5501
|
+
return z2.union([
|
|
5509
5502
|
this.nullableIf(baseSchema, optional),
|
|
5510
|
-
|
|
5503
|
+
z2.strictObject(components)
|
|
5511
5504
|
]);
|
|
5512
5505
|
}
|
|
5513
5506
|
makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, supportedOperators = void 0, withAggregations = void 0) {
|
|
@@ -5524,7 +5517,7 @@ var InputValidator = class {
|
|
|
5524
5517
|
between: baseSchema.array().length(2).optional(),
|
|
5525
5518
|
not: makeThis().optional(),
|
|
5526
5519
|
...withAggregations?.includes("_count") ? {
|
|
5527
|
-
_count: this.makeNumberFilterSchema(
|
|
5520
|
+
_count: this.makeNumberFilterSchema(z2.number().int(), false, false).optional()
|
|
5528
5521
|
} : {},
|
|
5529
5522
|
...withAggregations?.includes("_avg") ? {
|
|
5530
5523
|
_avg: commonAggSchema()
|
|
@@ -5549,13 +5542,13 @@ var InputValidator = class {
|
|
|
5549
5542
|
return result;
|
|
5550
5543
|
}
|
|
5551
5544
|
makeCommonPrimitiveFilterSchema(baseSchema, optional, makeThis, withAggregations = void 0) {
|
|
5552
|
-
return
|
|
5545
|
+
return z2.union([
|
|
5553
5546
|
this.nullableIf(baseSchema, optional),
|
|
5554
|
-
|
|
5547
|
+
z2.strictObject(this.makeCommonPrimitiveFilterComponents(baseSchema, optional, makeThis, void 0, withAggregations))
|
|
5555
5548
|
]);
|
|
5556
5549
|
}
|
|
5557
5550
|
makeNumberFilterSchema(baseSchema, optional, withAggregations) {
|
|
5558
|
-
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () =>
|
|
5551
|
+
return this.makeCommonPrimitiveFilterSchema(baseSchema, optional, () => z2.lazy(() => this.makeNumberFilterSchema(baseSchema, optional, withAggregations)), withAggregations ? [
|
|
5559
5552
|
"_count",
|
|
5560
5553
|
"_avg",
|
|
5561
5554
|
"_sum",
|
|
@@ -5564,17 +5557,17 @@ var InputValidator = class {
|
|
|
5564
5557
|
] : void 0);
|
|
5565
5558
|
}
|
|
5566
5559
|
makeStringFilterSchema(optional, withAggregations) {
|
|
5567
|
-
return
|
|
5568
|
-
this.nullableIf(
|
|
5569
|
-
|
|
5570
|
-
...this.makeCommonPrimitiveFilterComponents(
|
|
5560
|
+
return z2.union([
|
|
5561
|
+
this.nullableIf(z2.string(), optional),
|
|
5562
|
+
z2.strictObject({
|
|
5563
|
+
...this.makeCommonPrimitiveFilterComponents(z2.string(), optional, () => z2.lazy(() => this.makeStringFilterSchema(optional, withAggregations)), void 0, withAggregations ? [
|
|
5571
5564
|
"_count",
|
|
5572
5565
|
"_min",
|
|
5573
5566
|
"_max"
|
|
5574
5567
|
] : void 0),
|
|
5575
|
-
startsWith:
|
|
5576
|
-
endsWith:
|
|
5577
|
-
contains:
|
|
5568
|
+
startsWith: z2.string().optional(),
|
|
5569
|
+
endsWith: z2.string().optional(),
|
|
5570
|
+
contains: z2.string().optional(),
|
|
5578
5571
|
...this.providerSupportsCaseSensitivity ? {
|
|
5579
5572
|
mode: this.makeStringModeSchema().optional()
|
|
5580
5573
|
} : {}
|
|
@@ -5582,9 +5575,9 @@ var InputValidator = class {
|
|
|
5582
5575
|
]);
|
|
5583
5576
|
}
|
|
5584
5577
|
makeStringModeSchema() {
|
|
5585
|
-
return
|
|
5586
|
-
|
|
5587
|
-
|
|
5578
|
+
return z2.union([
|
|
5579
|
+
z2.literal("default"),
|
|
5580
|
+
z2.literal("insensitive")
|
|
5588
5581
|
]);
|
|
5589
5582
|
}
|
|
5590
5583
|
makeSelectSchema(model) {
|
|
@@ -5595,27 +5588,27 @@ var InputValidator = class {
|
|
|
5595
5588
|
if (fieldDef.relation) {
|
|
5596
5589
|
fields[field] = this.makeRelationSelectIncludeSchema(model, field).optional();
|
|
5597
5590
|
} else {
|
|
5598
|
-
fields[field] =
|
|
5591
|
+
fields[field] = z2.boolean().optional();
|
|
5599
5592
|
}
|
|
5600
5593
|
}
|
|
5601
5594
|
const _countSchema = this.makeCountSelectionSchema(model);
|
|
5602
|
-
if (!(_countSchema instanceof
|
|
5595
|
+
if (!(_countSchema instanceof z2.ZodNever)) {
|
|
5603
5596
|
fields["_count"] = _countSchema;
|
|
5604
5597
|
}
|
|
5605
|
-
return
|
|
5598
|
+
return z2.strictObject(fields);
|
|
5606
5599
|
}
|
|
5607
5600
|
makeCountSelectionSchema(model) {
|
|
5608
5601
|
const modelDef = requireModel(this.schema, model);
|
|
5609
5602
|
const toManyRelations = Object.values(modelDef.fields).filter((def) => def.relation && def.array);
|
|
5610
5603
|
if (toManyRelations.length > 0) {
|
|
5611
|
-
return
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
select:
|
|
5604
|
+
return z2.union([
|
|
5605
|
+
z2.literal(true),
|
|
5606
|
+
z2.strictObject({
|
|
5607
|
+
select: z2.strictObject(toManyRelations.reduce((acc, fieldDef) => ({
|
|
5615
5608
|
...acc,
|
|
5616
|
-
[fieldDef.name]:
|
|
5617
|
-
|
|
5618
|
-
|
|
5609
|
+
[fieldDef.name]: z2.union([
|
|
5610
|
+
z2.boolean(),
|
|
5611
|
+
z2.strictObject({
|
|
5619
5612
|
where: this.makeWhereSchema(fieldDef.type, false, false)
|
|
5620
5613
|
})
|
|
5621
5614
|
]).optional()
|
|
@@ -5623,22 +5616,22 @@ var InputValidator = class {
|
|
|
5623
5616
|
})
|
|
5624
5617
|
]).optional();
|
|
5625
5618
|
} else {
|
|
5626
|
-
return
|
|
5619
|
+
return z2.never();
|
|
5627
5620
|
}
|
|
5628
5621
|
}
|
|
5629
5622
|
makeRelationSelectIncludeSchema(model, field) {
|
|
5630
5623
|
const fieldDef = requireField(this.schema, model, field);
|
|
5631
|
-
let objSchema =
|
|
5624
|
+
let objSchema = z2.strictObject({
|
|
5632
5625
|
...fieldDef.array || fieldDef.optional ? {
|
|
5633
5626
|
// to-many relations and optional to-one relations are filterable
|
|
5634
|
-
where:
|
|
5627
|
+
where: z2.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
5635
5628
|
} : {},
|
|
5636
|
-
select:
|
|
5637
|
-
include:
|
|
5638
|
-
omit:
|
|
5629
|
+
select: z2.lazy(() => this.makeSelectSchema(fieldDef.type)).optional().nullable(),
|
|
5630
|
+
include: z2.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional().nullable(),
|
|
5631
|
+
omit: z2.lazy(() => this.makeOmitSchema(fieldDef.type)).optional().nullable(),
|
|
5639
5632
|
...fieldDef.array ? {
|
|
5640
5633
|
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
5641
|
-
orderBy:
|
|
5634
|
+
orderBy: z2.lazy(() => this.orArray(this.makeOrderBySchema(fieldDef.type, true, false), true)).optional(),
|
|
5642
5635
|
skip: this.makeSkipSchema().optional(),
|
|
5643
5636
|
take: this.makeTakeSchema().optional(),
|
|
5644
5637
|
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
@@ -5647,8 +5640,8 @@ var InputValidator = class {
|
|
|
5647
5640
|
});
|
|
5648
5641
|
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
5649
5642
|
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
5650
|
-
return
|
|
5651
|
-
|
|
5643
|
+
return z2.union([
|
|
5644
|
+
z2.boolean(),
|
|
5652
5645
|
objSchema
|
|
5653
5646
|
]);
|
|
5654
5647
|
}
|
|
@@ -5659,13 +5652,13 @@ var InputValidator = class {
|
|
|
5659
5652
|
const fieldDef = requireField(this.schema, model, field);
|
|
5660
5653
|
if (!fieldDef.relation) {
|
|
5661
5654
|
if (this.options.allowQueryTimeOmitOverride !== false) {
|
|
5662
|
-
fields[field] =
|
|
5655
|
+
fields[field] = z2.boolean().optional();
|
|
5663
5656
|
} else {
|
|
5664
|
-
fields[field] =
|
|
5657
|
+
fields[field] = z2.literal(true).optional();
|
|
5665
5658
|
}
|
|
5666
5659
|
}
|
|
5667
5660
|
}
|
|
5668
|
-
return
|
|
5661
|
+
return z2.strictObject(fields);
|
|
5669
5662
|
}
|
|
5670
5663
|
makeIncludeSchema(model) {
|
|
5671
5664
|
const modelDef = requireModel(this.schema, model);
|
|
@@ -5677,23 +5670,23 @@ var InputValidator = class {
|
|
|
5677
5670
|
}
|
|
5678
5671
|
}
|
|
5679
5672
|
const _countSchema = this.makeCountSelectionSchema(model);
|
|
5680
|
-
if (!(_countSchema instanceof
|
|
5673
|
+
if (!(_countSchema instanceof z2.ZodNever)) {
|
|
5681
5674
|
fields["_count"] = _countSchema;
|
|
5682
5675
|
}
|
|
5683
|
-
return
|
|
5676
|
+
return z2.strictObject(fields);
|
|
5684
5677
|
}
|
|
5685
5678
|
makeOrderBySchema(model, withRelation, WithAggregation) {
|
|
5686
5679
|
const modelDef = requireModel(this.schema, model);
|
|
5687
5680
|
const fields = {};
|
|
5688
|
-
const sort =
|
|
5689
|
-
|
|
5690
|
-
|
|
5681
|
+
const sort = z2.union([
|
|
5682
|
+
z2.literal("asc"),
|
|
5683
|
+
z2.literal("desc")
|
|
5691
5684
|
]);
|
|
5692
5685
|
for (const field of Object.keys(modelDef.fields)) {
|
|
5693
5686
|
const fieldDef = requireField(this.schema, model, field);
|
|
5694
5687
|
if (fieldDef.relation) {
|
|
5695
5688
|
if (withRelation) {
|
|
5696
|
-
fields[field] =
|
|
5689
|
+
fields[field] = z2.lazy(() => {
|
|
5697
5690
|
let relationOrderBy = this.makeOrderBySchema(fieldDef.type, withRelation, WithAggregation);
|
|
5698
5691
|
if (fieldDef.array) {
|
|
5699
5692
|
relationOrderBy = relationOrderBy.extend({
|
|
@@ -5705,13 +5698,13 @@ var InputValidator = class {
|
|
|
5705
5698
|
}
|
|
5706
5699
|
} else {
|
|
5707
5700
|
if (fieldDef.optional) {
|
|
5708
|
-
fields[field] =
|
|
5701
|
+
fields[field] = z2.union([
|
|
5709
5702
|
sort,
|
|
5710
|
-
|
|
5703
|
+
z2.strictObject({
|
|
5711
5704
|
sort,
|
|
5712
|
-
nulls:
|
|
5713
|
-
|
|
5714
|
-
|
|
5705
|
+
nulls: z2.union([
|
|
5706
|
+
z2.literal("first"),
|
|
5707
|
+
z2.literal("last")
|
|
5715
5708
|
])
|
|
5716
5709
|
})
|
|
5717
5710
|
]).optional();
|
|
@@ -5729,15 +5722,15 @@ var InputValidator = class {
|
|
|
5729
5722
|
"_max"
|
|
5730
5723
|
];
|
|
5731
5724
|
for (const agg of aggregationFields) {
|
|
5732
|
-
fields[agg] =
|
|
5725
|
+
fields[agg] = z2.lazy(() => this.makeOrderBySchema(model, true, false).optional());
|
|
5733
5726
|
}
|
|
5734
5727
|
}
|
|
5735
|
-
return
|
|
5728
|
+
return z2.strictObject(fields);
|
|
5736
5729
|
}
|
|
5737
5730
|
makeDistinctSchema(model) {
|
|
5738
5731
|
const modelDef = requireModel(this.schema, model);
|
|
5739
5732
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5740
|
-
return this.orArray(
|
|
5733
|
+
return this.orArray(z2.enum(nonRelationFields), true);
|
|
5741
5734
|
}
|
|
5742
5735
|
makeCursorSchema(model) {
|
|
5743
5736
|
return this.makeWhereSchema(model, true, true).optional();
|
|
@@ -5746,7 +5739,7 @@ var InputValidator = class {
|
|
|
5746
5739
|
// #region Create
|
|
5747
5740
|
makeCreateSchema(model) {
|
|
5748
5741
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5749
|
-
const baseSchema =
|
|
5742
|
+
const baseSchema = z2.strictObject({
|
|
5750
5743
|
data: dataSchema,
|
|
5751
5744
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
5752
5745
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -5798,7 +5791,7 @@ var InputValidator = class {
|
|
|
5798
5791
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
5799
5792
|
}
|
|
5800
5793
|
}
|
|
5801
|
-
let fieldSchema =
|
|
5794
|
+
let fieldSchema = z2.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "create"));
|
|
5802
5795
|
if (fieldDef.optional || fieldDef.array) {
|
|
5803
5796
|
fieldSchema = fieldSchema.optional();
|
|
5804
5797
|
} else {
|
|
@@ -5824,9 +5817,9 @@ var InputValidator = class {
|
|
|
5824
5817
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
5825
5818
|
if (fieldDef.array) {
|
|
5826
5819
|
fieldSchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
5827
|
-
fieldSchema =
|
|
5820
|
+
fieldSchema = z2.union([
|
|
5828
5821
|
fieldSchema,
|
|
5829
|
-
|
|
5822
|
+
z2.strictObject({
|
|
5830
5823
|
set: fieldSchema
|
|
5831
5824
|
})
|
|
5832
5825
|
]).optional();
|
|
@@ -5836,9 +5829,9 @@ var InputValidator = class {
|
|
|
5836
5829
|
}
|
|
5837
5830
|
if (fieldDef.optional) {
|
|
5838
5831
|
if (fieldDef.type === "Json") {
|
|
5839
|
-
fieldSchema =
|
|
5832
|
+
fieldSchema = z2.union([
|
|
5840
5833
|
fieldSchema,
|
|
5841
|
-
|
|
5834
|
+
z2.instanceof(DbNullClass)
|
|
5842
5835
|
]);
|
|
5843
5836
|
} else {
|
|
5844
5837
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -5850,19 +5843,19 @@ var InputValidator = class {
|
|
|
5850
5843
|
}
|
|
5851
5844
|
}
|
|
5852
5845
|
});
|
|
5853
|
-
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5854
|
-
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
5846
|
+
const uncheckedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(z2.strictObject(uncheckedVariantFields), modelDef.attributes) : z2.strictObject(uncheckedVariantFields);
|
|
5847
|
+
const checkedCreateSchema = this.extraValidationsEnabled ? addCustomValidation(z2.strictObject(checkedVariantFields), modelDef.attributes) : z2.strictObject(checkedVariantFields);
|
|
5855
5848
|
if (!hasRelation) {
|
|
5856
5849
|
return this.orArray(uncheckedCreateSchema, canBeArray);
|
|
5857
5850
|
} else {
|
|
5858
|
-
return
|
|
5851
|
+
return z2.union([
|
|
5859
5852
|
uncheckedCreateSchema,
|
|
5860
5853
|
checkedCreateSchema,
|
|
5861
5854
|
...canBeArray ? [
|
|
5862
|
-
|
|
5855
|
+
z2.array(uncheckedCreateSchema)
|
|
5863
5856
|
] : [],
|
|
5864
5857
|
...canBeArray ? [
|
|
5865
|
-
|
|
5858
|
+
z2.array(checkedCreateSchema)
|
|
5866
5859
|
] : []
|
|
5867
5860
|
]);
|
|
5868
5861
|
}
|
|
@@ -5891,11 +5884,11 @@ var InputValidator = class {
|
|
|
5891
5884
|
fields["disconnect"] = this.makeDisconnectDataSchema(fieldType, array).optional();
|
|
5892
5885
|
fields["delete"] = this.makeDeleteRelationDataSchema(fieldType, array, true).optional();
|
|
5893
5886
|
}
|
|
5894
|
-
fields["update"] = array ? this.orArray(
|
|
5887
|
+
fields["update"] = array ? this.orArray(z2.strictObject({
|
|
5895
5888
|
where: this.makeWhereSchema(fieldType, true),
|
|
5896
5889
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5897
|
-
}), true).optional() :
|
|
5898
|
-
|
|
5890
|
+
}), true).optional() : z2.union([
|
|
5891
|
+
z2.strictObject({
|
|
5899
5892
|
where: this.makeWhereSchema(fieldType, false).optional(),
|
|
5900
5893
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5901
5894
|
}),
|
|
@@ -5905,21 +5898,21 @@ var InputValidator = class {
|
|
|
5905
5898
|
if (!fieldDef.array) {
|
|
5906
5899
|
upsertWhere = upsertWhere.optional();
|
|
5907
5900
|
}
|
|
5908
|
-
fields["upsert"] = this.orArray(
|
|
5901
|
+
fields["upsert"] = this.orArray(z2.strictObject({
|
|
5909
5902
|
where: upsertWhere,
|
|
5910
5903
|
create: this.makeCreateDataSchema(fieldType, false, withoutFields),
|
|
5911
5904
|
update: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5912
5905
|
}), true).optional();
|
|
5913
5906
|
if (array) {
|
|
5914
5907
|
fields["set"] = this.makeSetDataSchema(fieldType, true).optional();
|
|
5915
|
-
fields["updateMany"] = this.orArray(
|
|
5908
|
+
fields["updateMany"] = this.orArray(z2.strictObject({
|
|
5916
5909
|
where: this.makeWhereSchema(fieldType, false, true),
|
|
5917
5910
|
data: this.makeUpdateDataSchema(fieldType, withoutFields)
|
|
5918
5911
|
}), true).optional();
|
|
5919
5912
|
fields["deleteMany"] = this.makeDeleteRelationDataSchema(fieldType, true, false).optional();
|
|
5920
5913
|
}
|
|
5921
5914
|
}
|
|
5922
|
-
return
|
|
5915
|
+
return z2.strictObject(fields);
|
|
5923
5916
|
}
|
|
5924
5917
|
makeSetDataSchema(model, canBeArray) {
|
|
5925
5918
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
@@ -5931,36 +5924,36 @@ var InputValidator = class {
|
|
|
5931
5924
|
if (canBeArray) {
|
|
5932
5925
|
return this.orArray(this.makeWhereSchema(model, true), canBeArray);
|
|
5933
5926
|
} else {
|
|
5934
|
-
return
|
|
5935
|
-
|
|
5927
|
+
return z2.union([
|
|
5928
|
+
z2.boolean(),
|
|
5936
5929
|
this.makeWhereSchema(model, false)
|
|
5937
5930
|
]);
|
|
5938
5931
|
}
|
|
5939
5932
|
}
|
|
5940
5933
|
makeDeleteRelationDataSchema(model, toManyRelation, uniqueFilter) {
|
|
5941
|
-
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) :
|
|
5942
|
-
|
|
5934
|
+
return toManyRelation ? this.orArray(this.makeWhereSchema(model, uniqueFilter), true) : z2.union([
|
|
5935
|
+
z2.boolean(),
|
|
5943
5936
|
this.makeWhereSchema(model, uniqueFilter)
|
|
5944
5937
|
]);
|
|
5945
5938
|
}
|
|
5946
5939
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
5947
5940
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
5948
5941
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
5949
|
-
return this.orArray(
|
|
5942
|
+
return this.orArray(z2.strictObject({
|
|
5950
5943
|
where: whereSchema,
|
|
5951
5944
|
create: createSchema
|
|
5952
5945
|
}), canBeArray);
|
|
5953
5946
|
}
|
|
5954
5947
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
5955
|
-
return
|
|
5948
|
+
return z2.strictObject({
|
|
5956
5949
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5957
|
-
skipDuplicates:
|
|
5950
|
+
skipDuplicates: z2.boolean().optional()
|
|
5958
5951
|
});
|
|
5959
5952
|
}
|
|
5960
5953
|
// #endregion
|
|
5961
5954
|
// #region Update
|
|
5962
5955
|
makeUpdateSchema(model) {
|
|
5963
|
-
const baseSchema =
|
|
5956
|
+
const baseSchema = z2.strictObject({
|
|
5964
5957
|
where: this.makeWhereSchema(model, true),
|
|
5965
5958
|
data: this.makeUpdateDataSchema(model),
|
|
5966
5959
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
@@ -5973,10 +5966,10 @@ var InputValidator = class {
|
|
|
5973
5966
|
return schema;
|
|
5974
5967
|
}
|
|
5975
5968
|
makeUpdateManySchema(model) {
|
|
5976
|
-
return this.mergePluginArgsSchema(
|
|
5969
|
+
return this.mergePluginArgsSchema(z2.strictObject({
|
|
5977
5970
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5978
5971
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5979
|
-
limit:
|
|
5972
|
+
limit: z2.number().int().nonnegative().optional()
|
|
5980
5973
|
}), "updateMany");
|
|
5981
5974
|
}
|
|
5982
5975
|
makeUpdateManyAndReturnSchema(model) {
|
|
@@ -5989,7 +5982,7 @@ var InputValidator = class {
|
|
|
5989
5982
|
return schema;
|
|
5990
5983
|
}
|
|
5991
5984
|
makeUpsertSchema(model) {
|
|
5992
|
-
const baseSchema =
|
|
5985
|
+
const baseSchema = z2.strictObject({
|
|
5993
5986
|
where: this.makeWhereSchema(model, true),
|
|
5994
5987
|
create: this.makeCreateDataSchema(model, false),
|
|
5995
5988
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -6025,7 +6018,7 @@ var InputValidator = class {
|
|
|
6025
6018
|
excludeFields.push(...oppositeFieldDef.relation.fields);
|
|
6026
6019
|
}
|
|
6027
6020
|
}
|
|
6028
|
-
let fieldSchema =
|
|
6021
|
+
let fieldSchema = z2.lazy(() => this.makeRelationManipulationSchema(model, field, excludeFields, "update")).optional();
|
|
6029
6022
|
if (fieldDef.optional && !fieldDef.array) {
|
|
6030
6023
|
fieldSchema = fieldSchema.nullable();
|
|
6031
6024
|
}
|
|
@@ -6036,24 +6029,24 @@ var InputValidator = class {
|
|
|
6036
6029
|
} else {
|
|
6037
6030
|
let fieldSchema = this.makeScalarSchema(fieldDef.type, fieldDef.attributes);
|
|
6038
6031
|
if (this.isNumericField(fieldDef)) {
|
|
6039
|
-
fieldSchema =
|
|
6032
|
+
fieldSchema = z2.union([
|
|
6040
6033
|
fieldSchema,
|
|
6041
|
-
|
|
6042
|
-
set: this.nullableIf(
|
|
6043
|
-
increment:
|
|
6044
|
-
decrement:
|
|
6045
|
-
multiply:
|
|
6046
|
-
divide:
|
|
6034
|
+
z2.object({
|
|
6035
|
+
set: this.nullableIf(z2.number().optional(), !!fieldDef.optional).optional(),
|
|
6036
|
+
increment: z2.number().optional(),
|
|
6037
|
+
decrement: z2.number().optional(),
|
|
6038
|
+
multiply: z2.number().optional(),
|
|
6039
|
+
divide: z2.number().optional()
|
|
6047
6040
|
}).refine((v) => Object.keys(v).length === 1, 'Only one of "set", "increment", "decrement", "multiply", or "divide" can be provided')
|
|
6048
6041
|
]);
|
|
6049
6042
|
}
|
|
6050
6043
|
if (fieldDef.array) {
|
|
6051
6044
|
const arraySchema = addListValidation(fieldSchema.array(), fieldDef.attributes);
|
|
6052
|
-
fieldSchema =
|
|
6045
|
+
fieldSchema = z2.union([
|
|
6053
6046
|
arraySchema,
|
|
6054
|
-
|
|
6047
|
+
z2.object({
|
|
6055
6048
|
set: arraySchema.optional(),
|
|
6056
|
-
push:
|
|
6049
|
+
push: z2.union([
|
|
6057
6050
|
fieldSchema,
|
|
6058
6051
|
fieldSchema.array()
|
|
6059
6052
|
]).optional()
|
|
@@ -6062,9 +6055,9 @@ var InputValidator = class {
|
|
|
6062
6055
|
}
|
|
6063
6056
|
if (fieldDef.optional) {
|
|
6064
6057
|
if (fieldDef.type === "Json") {
|
|
6065
|
-
fieldSchema =
|
|
6058
|
+
fieldSchema = z2.union([
|
|
6066
6059
|
fieldSchema,
|
|
6067
|
-
|
|
6060
|
+
z2.instanceof(DbNullClass)
|
|
6068
6061
|
]);
|
|
6069
6062
|
} else {
|
|
6070
6063
|
fieldSchema = fieldSchema.nullable();
|
|
@@ -6077,12 +6070,12 @@ var InputValidator = class {
|
|
|
6077
6070
|
}
|
|
6078
6071
|
}
|
|
6079
6072
|
});
|
|
6080
|
-
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
6081
|
-
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(
|
|
6073
|
+
const uncheckedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(z2.strictObject(uncheckedVariantFields), modelDef.attributes) : z2.strictObject(uncheckedVariantFields);
|
|
6074
|
+
const checkedUpdateSchema = this.extraValidationsEnabled ? addCustomValidation(z2.strictObject(checkedVariantFields), modelDef.attributes) : z2.strictObject(checkedVariantFields);
|
|
6082
6075
|
if (!hasRelation) {
|
|
6083
6076
|
return uncheckedUpdateSchema;
|
|
6084
6077
|
} else {
|
|
6085
|
-
return
|
|
6078
|
+
return z2.union([
|
|
6086
6079
|
uncheckedUpdateSchema,
|
|
6087
6080
|
checkedUpdateSchema
|
|
6088
6081
|
]);
|
|
@@ -6091,7 +6084,7 @@ var InputValidator = class {
|
|
|
6091
6084
|
// #endregion
|
|
6092
6085
|
// #region Delete
|
|
6093
6086
|
makeDeleteSchema(model) {
|
|
6094
|
-
const baseSchema =
|
|
6087
|
+
const baseSchema = z2.strictObject({
|
|
6095
6088
|
where: this.makeWhereSchema(model, true),
|
|
6096
6089
|
select: this.makeSelectSchema(model).optional().nullable(),
|
|
6097
6090
|
include: this.makeIncludeSchema(model).optional().nullable(),
|
|
@@ -6103,15 +6096,15 @@ var InputValidator = class {
|
|
|
6103
6096
|
return schema;
|
|
6104
6097
|
}
|
|
6105
6098
|
makeDeleteManySchema(model) {
|
|
6106
|
-
return this.mergePluginArgsSchema(
|
|
6099
|
+
return this.mergePluginArgsSchema(z2.strictObject({
|
|
6107
6100
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6108
|
-
limit:
|
|
6101
|
+
limit: z2.number().int().nonnegative().optional()
|
|
6109
6102
|
}), "deleteMany").optional();
|
|
6110
6103
|
}
|
|
6111
6104
|
// #endregion
|
|
6112
6105
|
// #region Count
|
|
6113
6106
|
makeCountSchema(model) {
|
|
6114
|
-
return this.mergePluginArgsSchema(
|
|
6107
|
+
return this.mergePluginArgsSchema(z2.strictObject({
|
|
6115
6108
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6116
6109
|
skip: this.makeSkipSchema().optional(),
|
|
6117
6110
|
take: this.makeTakeSchema().optional(),
|
|
@@ -6121,12 +6114,12 @@ var InputValidator = class {
|
|
|
6121
6114
|
}
|
|
6122
6115
|
makeCountAggregateInputSchema(model) {
|
|
6123
6116
|
const modelDef = requireModel(this.schema, model);
|
|
6124
|
-
return
|
|
6125
|
-
|
|
6126
|
-
|
|
6127
|
-
_all:
|
|
6117
|
+
return z2.union([
|
|
6118
|
+
z2.literal(true),
|
|
6119
|
+
z2.strictObject({
|
|
6120
|
+
_all: z2.literal(true).optional(),
|
|
6128
6121
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6129
|
-
acc[field] =
|
|
6122
|
+
acc[field] = z2.literal(true).optional();
|
|
6130
6123
|
return acc;
|
|
6131
6124
|
}, {})
|
|
6132
6125
|
})
|
|
@@ -6135,7 +6128,7 @@ var InputValidator = class {
|
|
|
6135
6128
|
// #endregion
|
|
6136
6129
|
// #region Aggregate
|
|
6137
6130
|
makeAggregateSchema(model) {
|
|
6138
|
-
return this.mergePluginArgsSchema(
|
|
6131
|
+
return this.mergePluginArgsSchema(z2.strictObject({
|
|
6139
6132
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6140
6133
|
skip: this.makeSkipSchema().optional(),
|
|
6141
6134
|
take: this.makeTakeSchema().optional(),
|
|
@@ -6149,20 +6142,20 @@ var InputValidator = class {
|
|
|
6149
6142
|
}
|
|
6150
6143
|
makeSumAvgInputSchema(model) {
|
|
6151
6144
|
const modelDef = requireModel(this.schema, model);
|
|
6152
|
-
return
|
|
6145
|
+
return z2.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6153
6146
|
const fieldDef = requireField(this.schema, model, field);
|
|
6154
6147
|
if (this.isNumericField(fieldDef)) {
|
|
6155
|
-
acc[field] =
|
|
6148
|
+
acc[field] = z2.literal(true).optional();
|
|
6156
6149
|
}
|
|
6157
6150
|
return acc;
|
|
6158
6151
|
}, {}));
|
|
6159
6152
|
}
|
|
6160
6153
|
makeMinMaxInputSchema(model) {
|
|
6161
6154
|
const modelDef = requireModel(this.schema, model);
|
|
6162
|
-
return
|
|
6155
|
+
return z2.strictObject(Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
6163
6156
|
const fieldDef = requireField(this.schema, model, field);
|
|
6164
6157
|
if (!fieldDef.relation && !fieldDef.array) {
|
|
6165
|
-
acc[field] =
|
|
6158
|
+
acc[field] = z2.literal(true).optional();
|
|
6166
6159
|
}
|
|
6167
6160
|
return acc;
|
|
6168
6161
|
}, {}));
|
|
@@ -6170,8 +6163,8 @@ var InputValidator = class {
|
|
|
6170
6163
|
makeGroupBySchema(model) {
|
|
6171
6164
|
const modelDef = requireModel(this.schema, model);
|
|
6172
6165
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
6173
|
-
const bySchema = nonRelationFields.length > 0 ? this.orArray(
|
|
6174
|
-
const baseSchema =
|
|
6166
|
+
const bySchema = nonRelationFields.length > 0 ? this.orArray(z2.enum(nonRelationFields), true) : z2.never();
|
|
6167
|
+
const baseSchema = z2.strictObject({
|
|
6175
6168
|
where: this.makeWhereSchema(model, false).optional(),
|
|
6176
6169
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
6177
6170
|
by: bySchema,
|
|
@@ -6245,10 +6238,10 @@ var InputValidator = class {
|
|
|
6245
6238
|
} else if (isEnum(this.schema, param.type)) {
|
|
6246
6239
|
schema = this.makeEnumSchema(param.type);
|
|
6247
6240
|
} else if (param.type in (this.schema.models ?? {})) {
|
|
6248
|
-
schema =
|
|
6241
|
+
schema = z2.record(z2.string(), z2.unknown());
|
|
6249
6242
|
} else {
|
|
6250
6243
|
schema = this.makeScalarSchema(param.type);
|
|
6251
|
-
if (schema instanceof
|
|
6244
|
+
if (schema instanceof z2.ZodUnknown) {
|
|
6252
6245
|
throw createInternalError(`Unsupported procedure parameter type: ${param.type}`);
|
|
6253
6246
|
}
|
|
6254
6247
|
}
|
|
@@ -6280,10 +6273,10 @@ var InputValidator = class {
|
|
|
6280
6273
|
// #endregion
|
|
6281
6274
|
// #region Helpers
|
|
6282
6275
|
makeSkipSchema() {
|
|
6283
|
-
return
|
|
6276
|
+
return z2.number().int().nonnegative();
|
|
6284
6277
|
}
|
|
6285
6278
|
makeTakeSchema() {
|
|
6286
|
-
return
|
|
6279
|
+
return z2.number().int();
|
|
6287
6280
|
}
|
|
6288
6281
|
refineForSelectIncludeMutuallyExclusive(schema) {
|
|
6289
6282
|
return schema.refine((value) => !(value["select"] && value["include"]), '"select" and "include" cannot be used together');
|
|
@@ -6295,9 +6288,9 @@ var InputValidator = class {
|
|
|
6295
6288
|
return nullable ? schema.nullable() : schema;
|
|
6296
6289
|
}
|
|
6297
6290
|
orArray(schema, canBeArray) {
|
|
6298
|
-
return canBeArray ?
|
|
6291
|
+
return canBeArray ? z2.union([
|
|
6299
6292
|
schema,
|
|
6300
|
-
|
|
6293
|
+
z2.array(schema)
|
|
6301
6294
|
]) : schema;
|
|
6302
6295
|
}
|
|
6303
6296
|
isNumericField(fieldDef) {
|
|
@@ -6338,7 +6331,7 @@ _ts_decorate([
|
|
|
6338
6331
|
_ts_metadata("design:paramtypes", [
|
|
6339
6332
|
String
|
|
6340
6333
|
]),
|
|
6341
|
-
_ts_metadata("design:returntype", typeof
|
|
6334
|
+
_ts_metadata("design:returntype", typeof z2 === "undefined" || typeof z2.ZodType === "undefined" ? Object : z2.ZodType)
|
|
6342
6335
|
], InputValidator.prototype, "makeTypeDefSchema", null);
|
|
6343
6336
|
_ts_decorate([
|
|
6344
6337
|
cache(),
|
|
@@ -6698,7 +6691,7 @@ _ts_decorate([
|
|
|
6698
6691
|
_ts_metadata("design:paramtypes", [
|
|
6699
6692
|
Object
|
|
6700
6693
|
]),
|
|
6701
|
-
_ts_metadata("design:returntype", typeof
|
|
6694
|
+
_ts_metadata("design:returntype", typeof z2 === "undefined" || typeof z2.ZodType === "undefined" ? Object : z2.ZodType)
|
|
6702
6695
|
], InputValidator.prototype, "makeProcedureParamSchema", null);
|
|
6703
6696
|
_ts_decorate([
|
|
6704
6697
|
cache(),
|
|
@@ -6903,7 +6896,7 @@ import { match as match15 } from "ts-pattern";
|
|
|
6903
6896
|
|
|
6904
6897
|
// src/client/executor/name-mapper.ts
|
|
6905
6898
|
import { invariant as invariant10 } from "@zenstackhq/common-helpers";
|
|
6906
|
-
import { AliasNode as AliasNode2, ColumnNode as ColumnNode2, ColumnUpdateNode, expressionBuilder as expressionBuilder6, ExpressionWrapper, FromNode, IdentifierNode, OperationNodeTransformer, PrimitiveValueListNode, ReferenceNode as ReferenceNode2, SelectAllNode, SelectionNode, TableNode as TableNode2, ValueListNode, ValueNode, ValuesNode } from "kysely";
|
|
6899
|
+
import { AliasNode as AliasNode2, ColumnNode as ColumnNode2, ColumnUpdateNode, expressionBuilder as expressionBuilder6, ExpressionWrapper as ExpressionWrapper3, FromNode, IdentifierNode, OperationNodeTransformer, PrimitiveValueListNode, ReferenceNode as ReferenceNode2, SelectAllNode, SelectionNode, TableNode as TableNode2, ValueListNode as ValueListNode3, ValueNode, ValuesNode } from "kysely";
|
|
6907
6900
|
var QueryNameMapper = class extends OperationNodeTransformer {
|
|
6908
6901
|
static {
|
|
6909
6902
|
__name(this, "QueryNameMapper");
|
|
@@ -6911,6 +6904,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6911
6904
|
client;
|
|
6912
6905
|
modelToTableMap = /* @__PURE__ */ new Map();
|
|
6913
6906
|
fieldToColumnMap = /* @__PURE__ */ new Map();
|
|
6907
|
+
enumTypeMap = /* @__PURE__ */ new Map();
|
|
6914
6908
|
scopes = [];
|
|
6915
6909
|
dialect;
|
|
6916
6910
|
constructor(client) {
|
|
@@ -6928,14 +6922,20 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6928
6922
|
}
|
|
6929
6923
|
}
|
|
6930
6924
|
}
|
|
6925
|
+
for (const [enumName, enumDef] of Object.entries(client.$schema.enums ?? {})) {
|
|
6926
|
+
const mappedName = this.getMappedName(enumDef);
|
|
6927
|
+
if (mappedName) {
|
|
6928
|
+
this.enumTypeMap.set(enumName, mappedName);
|
|
6929
|
+
}
|
|
6930
|
+
}
|
|
6931
6931
|
}
|
|
6932
6932
|
get schema() {
|
|
6933
6933
|
return this.client.$schema;
|
|
6934
6934
|
}
|
|
6935
6935
|
// #region overrides
|
|
6936
|
-
transformSelectQuery(node) {
|
|
6936
|
+
transformSelectQuery(node, queryId) {
|
|
6937
6937
|
if (!node.from?.froms) {
|
|
6938
|
-
return super.transformSelectQuery(node);
|
|
6938
|
+
return super.transformSelectQuery(node, queryId);
|
|
6939
6939
|
}
|
|
6940
6940
|
const processedFroms = node.from.froms.map((from) => this.processSelectTable(from));
|
|
6941
6941
|
const processedJoins = [];
|
|
@@ -6954,7 +6954,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6954
6954
|
on: this.transformNode(join.on)
|
|
6955
6955
|
})) : void 0;
|
|
6956
6956
|
const selections = this.processSelectQuerySelections(node);
|
|
6957
|
-
const baseResult = super.transformSelectQuery(node);
|
|
6957
|
+
const baseResult = super.transformSelectQuery(node, queryId);
|
|
6958
6958
|
return {
|
|
6959
6959
|
...baseResult,
|
|
6960
6960
|
from: FromNode.create(processedFroms.map((f) => f.node)),
|
|
@@ -6963,16 +6963,16 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6963
6963
|
};
|
|
6964
6964
|
});
|
|
6965
6965
|
}
|
|
6966
|
-
transformInsertQuery(node) {
|
|
6966
|
+
transformInsertQuery(node, queryId) {
|
|
6967
6967
|
if (!node.into) {
|
|
6968
|
-
return super.transformInsertQuery(node);
|
|
6968
|
+
return super.transformInsertQuery(node, queryId);
|
|
6969
6969
|
}
|
|
6970
6970
|
const model = extractModelName(node.into);
|
|
6971
6971
|
invariant10(model, 'InsertQueryNode must have a model name in the "into" clause');
|
|
6972
6972
|
return this.withScope({
|
|
6973
6973
|
model
|
|
6974
6974
|
}, () => {
|
|
6975
|
-
const baseResult = super.transformInsertQuery(node);
|
|
6975
|
+
const baseResult = super.transformInsertQuery(node, queryId);
|
|
6976
6976
|
let values = baseResult.values;
|
|
6977
6977
|
if (node.columns && values) {
|
|
6978
6978
|
values = this.processEnumMappingForColumns(model, node.columns, values);
|
|
@@ -6995,9 +6995,9 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
6995
6995
|
selections: this.processSelections(node.selections)
|
|
6996
6996
|
};
|
|
6997
6997
|
}
|
|
6998
|
-
transformReference(node) {
|
|
6998
|
+
transformReference(node, queryId) {
|
|
6999
6999
|
if (!ColumnNode2.is(node.column)) {
|
|
7000
|
-
return super.transformReference(node);
|
|
7000
|
+
return super.transformReference(node, queryId);
|
|
7001
7001
|
}
|
|
7002
7002
|
const scope = this.resolveFieldFromScopes(node.column.column.name, node.table?.table.identifier.name);
|
|
7003
7003
|
if (scope && !scope.namesMapped && scope.model) {
|
|
@@ -7014,15 +7014,15 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7014
7014
|
return node;
|
|
7015
7015
|
}
|
|
7016
7016
|
}
|
|
7017
|
-
transformColumn(node) {
|
|
7017
|
+
transformColumn(node, queryId) {
|
|
7018
7018
|
const scope = this.resolveFieldFromScopes(node.column.name);
|
|
7019
7019
|
if (!scope || scope.namesMapped || !scope.model) {
|
|
7020
|
-
return super.transformColumn(node);
|
|
7020
|
+
return super.transformColumn(node, queryId);
|
|
7021
7021
|
}
|
|
7022
7022
|
const mappedName = this.mapFieldName(scope.model, node.column.name);
|
|
7023
7023
|
return ColumnNode2.create(mappedName);
|
|
7024
7024
|
}
|
|
7025
|
-
transformBinaryOperation(node) {
|
|
7025
|
+
transformBinaryOperation(node, queryId) {
|
|
7026
7026
|
if (ReferenceNode2.is(node.leftOperand) && ColumnNode2.is(node.leftOperand.column) && (ValueNode.is(node.rightOperand) || PrimitiveValueListNode.is(node.rightOperand))) {
|
|
7027
7027
|
const columnNode = node.leftOperand.column;
|
|
7028
7028
|
const resolvedScope = this.resolveFieldFromScopes(columnNode.column.name, node.leftOperand.table?.table.identifier.name);
|
|
@@ -7037,14 +7037,14 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7037
7037
|
return super.transformBinaryOperation({
|
|
7038
7038
|
...node,
|
|
7039
7039
|
rightOperand: resultValue
|
|
7040
|
-
});
|
|
7040
|
+
}, queryId);
|
|
7041
7041
|
}
|
|
7042
7042
|
}
|
|
7043
|
-
return super.transformBinaryOperation(node);
|
|
7043
|
+
return super.transformBinaryOperation(node, queryId);
|
|
7044
7044
|
}
|
|
7045
|
-
transformUpdateQuery(node) {
|
|
7045
|
+
transformUpdateQuery(node, queryId) {
|
|
7046
7046
|
if (!node.table) {
|
|
7047
|
-
return super.transformUpdateQuery(node);
|
|
7047
|
+
return super.transformUpdateQuery(node, queryId);
|
|
7048
7048
|
}
|
|
7049
7049
|
const { alias, node: innerTable } = stripAlias(node.table);
|
|
7050
7050
|
if (!innerTable || !TableNode2.is(innerTable)) {
|
|
@@ -7056,7 +7056,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7056
7056
|
model,
|
|
7057
7057
|
alias
|
|
7058
7058
|
}, () => {
|
|
7059
|
-
const baseResult = super.transformUpdateQuery(node);
|
|
7059
|
+
const baseResult = super.transformUpdateQuery(node, queryId);
|
|
7060
7060
|
const updates = baseResult.updates?.map((update, i) => {
|
|
7061
7061
|
if (ColumnNode2.is(update.column)) {
|
|
7062
7062
|
const origColumn = node.updates[i].column;
|
|
@@ -7073,7 +7073,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7073
7073
|
};
|
|
7074
7074
|
});
|
|
7075
7075
|
}
|
|
7076
|
-
transformDeleteQuery(node) {
|
|
7076
|
+
transformDeleteQuery(node, queryId) {
|
|
7077
7077
|
const scopes = node.from.froms.map((node2) => {
|
|
7078
7078
|
const { alias, node: innerNode } = stripAlias(node2);
|
|
7079
7079
|
return {
|
|
@@ -7087,12 +7087,12 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7087
7087
|
if (TableNode2.is(innerNode)) {
|
|
7088
7088
|
return this.wrapAlias(this.processTableRef(innerNode), alias);
|
|
7089
7089
|
} else {
|
|
7090
|
-
return super.transformNode(from);
|
|
7090
|
+
return super.transformNode(from, queryId);
|
|
7091
7091
|
}
|
|
7092
7092
|
});
|
|
7093
7093
|
return this.withScopes(scopes, () => {
|
|
7094
7094
|
return {
|
|
7095
|
-
...super.transformDeleteQuery(node),
|
|
7095
|
+
...super.transformDeleteQuery(node, queryId),
|
|
7096
7096
|
from: FromNode.create(froms)
|
|
7097
7097
|
};
|
|
7098
7098
|
});
|
|
@@ -7394,7 +7394,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7394
7394
|
if (PrimitiveValueListNode.is(valueItems)) {
|
|
7395
7395
|
return PrimitiveValueListNode.create(this.processEnumMappingForValues(model, columns, valueItems.values));
|
|
7396
7396
|
} else {
|
|
7397
|
-
return
|
|
7397
|
+
return ValueListNode3.create(this.processEnumMappingForValues(model, columns, valueItems.values));
|
|
7398
7398
|
}
|
|
7399
7399
|
}));
|
|
7400
7400
|
} else if (PrimitiveValueListNode.is(values)) {
|
|
@@ -7465,12 +7465,12 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
7465
7465
|
let caseWhen;
|
|
7466
7466
|
for (const [key, value] of Object.entries(enumValueMapping)) {
|
|
7467
7467
|
if (!caseWhen) {
|
|
7468
|
-
caseWhen = caseBuilder.when(new
|
|
7468
|
+
caseWhen = caseBuilder.when(new ExpressionWrapper3(node), "=", value).then(key);
|
|
7469
7469
|
} else {
|
|
7470
|
-
caseWhen = caseWhen.when(new
|
|
7470
|
+
caseWhen = caseWhen.when(new ExpressionWrapper3(node), "=", value).then(key);
|
|
7471
7471
|
}
|
|
7472
7472
|
}
|
|
7473
|
-
const finalExpr = caseWhen.else(this.dialect.castText(new
|
|
7473
|
+
const finalExpr = caseWhen.else(this.dialect.castText(new ExpressionWrapper3(node))).end();
|
|
7474
7474
|
if (aliasName) {
|
|
7475
7475
|
return finalExpr.as(aliasName).toOperationNode();
|
|
7476
7476
|
} else {
|
|
@@ -8001,7 +8001,7 @@ var textMatch = /* @__PURE__ */ __name((eb, args, { dialect }, method) => {
|
|
|
8001
8001
|
])).exhaustive();
|
|
8002
8002
|
return sql6`${fieldExpr} ${sql6.raw(op)} ${searchExpr} escape ${sql6.val("\\")}`;
|
|
8003
8003
|
}, "textMatch");
|
|
8004
|
-
var has = /* @__PURE__ */ __name((
|
|
8004
|
+
var has = /* @__PURE__ */ __name((_eb, args, context) => {
|
|
8005
8005
|
const [field, search2] = args;
|
|
8006
8006
|
if (!field) {
|
|
8007
8007
|
throw new Error('"field" parameter is required');
|
|
@@ -8009,11 +8009,9 @@ var has = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8009
8009
|
if (!search2) {
|
|
8010
8010
|
throw new Error('"search" parameter is required');
|
|
8011
8011
|
}
|
|
8012
|
-
return
|
|
8013
|
-
search2
|
|
8014
|
-
]);
|
|
8012
|
+
return context.dialect.buildArrayContains(field, search2);
|
|
8015
8013
|
}, "has");
|
|
8016
|
-
var hasEvery = /* @__PURE__ */ __name((
|
|
8014
|
+
var hasEvery = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
|
|
8017
8015
|
const [field, search2] = args;
|
|
8018
8016
|
if (!field) {
|
|
8019
8017
|
throw new Error('"field" parameter is required');
|
|
@@ -8021,9 +8019,9 @@ var hasEvery = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8021
8019
|
if (!search2) {
|
|
8022
8020
|
throw new Error('"search" parameter is required');
|
|
8023
8021
|
}
|
|
8024
|
-
return
|
|
8022
|
+
return dialect.buildArrayHasEvery(field, search2);
|
|
8025
8023
|
}, "hasEvery");
|
|
8026
|
-
var hasSome = /* @__PURE__ */ __name((
|
|
8024
|
+
var hasSome = /* @__PURE__ */ __name((_eb, args, { dialect }) => {
|
|
8027
8025
|
const [field, search2] = args;
|
|
8028
8026
|
if (!field) {
|
|
8029
8027
|
throw new Error('"field" parameter is required');
|
|
@@ -8031,7 +8029,7 @@ var hasSome = /* @__PURE__ */ __name((eb, args) => {
|
|
|
8031
8029
|
if (!search2) {
|
|
8032
8030
|
throw new Error('"search" parameter is required');
|
|
8033
8031
|
}
|
|
8034
|
-
return
|
|
8032
|
+
return dialect.buildArrayHasSome(field, search2);
|
|
8035
8033
|
}, "hasSome");
|
|
8036
8034
|
var isEmpty = /* @__PURE__ */ __name((eb, args, { dialect }) => {
|
|
8037
8035
|
const [field] = args;
|
|
@@ -8094,7 +8092,7 @@ var SchemaDbPusher = class {
|
|
|
8094
8092
|
async push() {
|
|
8095
8093
|
await this.kysely.transaction().execute(async (tx) => {
|
|
8096
8094
|
if (this.schema.enums && this.providerSupportsNativeEnum) {
|
|
8097
|
-
for (const
|
|
8095
|
+
for (const enumDef of Object.values(this.schema.enums)) {
|
|
8098
8096
|
let enumValues;
|
|
8099
8097
|
if (enumDef.fields) {
|
|
8100
8098
|
enumValues = Object.values(enumDef.fields).map((f) => {
|
|
@@ -8110,7 +8108,7 @@ var SchemaDbPusher = class {
|
|
|
8110
8108
|
} else {
|
|
8111
8109
|
enumValues = Object.values(enumDef.values);
|
|
8112
8110
|
}
|
|
8113
|
-
const createEnum = tx.schema.createType(
|
|
8111
|
+
const createEnum = tx.schema.createType(this.getEnumName(enumDef)).asEnum(enumValues);
|
|
8114
8112
|
await createEnum.execute();
|
|
8115
8113
|
}
|
|
8116
8114
|
}
|
|
@@ -8188,6 +8186,16 @@ var SchemaDbPusher = class {
|
|
|
8188
8186
|
}
|
|
8189
8187
|
return modelDef.name;
|
|
8190
8188
|
}
|
|
8189
|
+
getEnumName(enumDef) {
|
|
8190
|
+
const mapAttr = enumDef.attributes?.find((a) => a.name === "@@map");
|
|
8191
|
+
if (mapAttr && mapAttr.args?.[0]) {
|
|
8192
|
+
const mappedName = schema_exports.ExpressionUtils.getLiteralValue(mapAttr.args[0].value);
|
|
8193
|
+
if (mappedName) {
|
|
8194
|
+
return mappedName;
|
|
8195
|
+
}
|
|
8196
|
+
}
|
|
8197
|
+
return enumDef.name;
|
|
8198
|
+
}
|
|
8191
8199
|
getColumnName(fieldDef) {
|
|
8192
8200
|
const mapAttr = fieldDef.attributes?.find((a) => a.name === "@map");
|
|
8193
8201
|
if (mapAttr && mapAttr.args?.[0]) {
|