@zenstackhq/runtime 3.0.0-alpha.25 → 3.0.0-alpha.27
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/{contract-BOWN0dwS.d.cts → contract-c8GpEAl3.d.cts} +17 -14
- package/dist/{contract-BOWN0dwS.d.ts → contract-c8GpEAl3.d.ts} +17 -14
- package/dist/index.cjs +120 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +120 -152
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +59 -24
- package/dist/plugins/policy/index.cjs.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/dist/plugins/policy/index.js +59 -24
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -414,16 +414,6 @@ function ensureArray(value) {
|
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
__name(ensureArray, "ensureArray");
|
|
417
|
-
function safeJSONStringify(value) {
|
|
418
|
-
return JSON.stringify(value, (_, v) => {
|
|
419
|
-
if (typeof v === "bigint") {
|
|
420
|
-
return v.toString();
|
|
421
|
-
} else {
|
|
422
|
-
return v;
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
__name(safeJSONStringify, "safeJSONStringify");
|
|
427
417
|
function extractIdFields(entity, schema, model) {
|
|
428
418
|
const idFields = getIdFields(schema, model);
|
|
429
419
|
return extractFields(entity, idFields);
|
|
@@ -560,6 +550,33 @@ var BaseCrudDialect = class {
|
|
|
560
550
|
}
|
|
561
551
|
return result;
|
|
562
552
|
}
|
|
553
|
+
buildFilterSortTake(model, args, query) {
|
|
554
|
+
let result = query;
|
|
555
|
+
if (args.where) {
|
|
556
|
+
result = result.where((eb) => this.buildFilter(eb, model, model, args?.where));
|
|
557
|
+
}
|
|
558
|
+
let negateOrderBy = false;
|
|
559
|
+
const skip = args.skip;
|
|
560
|
+
let take = args.take;
|
|
561
|
+
if (take !== void 0 && take < 0) {
|
|
562
|
+
negateOrderBy = true;
|
|
563
|
+
take = -take;
|
|
564
|
+
}
|
|
565
|
+
result = this.buildSkipTake(result, skip, take);
|
|
566
|
+
result = this.buildOrderBy(result, model, model, args.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
567
|
+
if ("distinct" in args && args.distinct) {
|
|
568
|
+
const distinct = ensureArray(args.distinct);
|
|
569
|
+
if (this.supportsDistinctOn) {
|
|
570
|
+
result = result.distinctOn(distinct.map((f) => import_kysely.sql.ref(`${model}.${f}`)));
|
|
571
|
+
} else {
|
|
572
|
+
throw new QueryError(`"distinct" is not supported by "${this.schema.provider.type}" provider`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (args.cursor) {
|
|
576
|
+
result = this.buildCursorFilter(model, result, args.cursor, args.orderBy, negateOrderBy);
|
|
577
|
+
}
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
563
580
|
buildFilter(eb, model, modelAlias, where) {
|
|
564
581
|
if (where === true || where === void 0) {
|
|
565
582
|
return this.true(eb);
|
|
@@ -597,6 +614,26 @@ var BaseCrudDialect = class {
|
|
|
597
614
|
}
|
|
598
615
|
return result;
|
|
599
616
|
}
|
|
617
|
+
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
618
|
+
const _orderBy = orderBy ?? makeDefaultOrderBy(this.schema, model);
|
|
619
|
+
const orderByItems = ensureArray(_orderBy).flatMap((obj) => Object.entries(obj));
|
|
620
|
+
const eb = (0, import_kysely.expressionBuilder)();
|
|
621
|
+
const cursorFilter = this.buildFilter(eb, model, model, cursor);
|
|
622
|
+
let result = query;
|
|
623
|
+
const filters = [];
|
|
624
|
+
for (let i = orderByItems.length - 1; i >= 0; i--) {
|
|
625
|
+
const andFilters = [];
|
|
626
|
+
for (let j = 0; j <= i; j++) {
|
|
627
|
+
const [field, order] = orderByItems[j];
|
|
628
|
+
const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
|
|
629
|
+
const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
|
|
630
|
+
andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
|
|
631
|
+
}
|
|
632
|
+
filters.push(eb.and(andFilters));
|
|
633
|
+
}
|
|
634
|
+
result = result.where((eb2) => eb2.or(filters));
|
|
635
|
+
return result;
|
|
636
|
+
}
|
|
600
637
|
isLogicalCombinator(key) {
|
|
601
638
|
return LOGICAL_COMBINATORS.includes(key);
|
|
602
639
|
}
|
|
@@ -1123,18 +1160,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
|
|
|
1123
1160
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1124
1161
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
1125
1162
|
if (payload && typeof payload === "object") {
|
|
1126
|
-
|
|
1127
|
-
subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
|
|
1128
|
-
}
|
|
1129
|
-
const skip = payload.skip;
|
|
1130
|
-
let take = payload.take;
|
|
1131
|
-
let negateOrderBy = false;
|
|
1132
|
-
if (take !== void 0 && take < 0) {
|
|
1133
|
-
negateOrderBy = true;
|
|
1134
|
-
take = -take;
|
|
1135
|
-
}
|
|
1136
|
-
subQuery = this.buildSkipTake(subQuery, skip, take);
|
|
1137
|
-
subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
1163
|
+
subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
|
|
1138
1164
|
}
|
|
1139
1165
|
const m2m = getManyToManyRelation(this.schema, model, relationField);
|
|
1140
1166
|
if (m2m) {
|
|
@@ -1297,18 +1323,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
1297
1323
|
let subQuery = this.buildSelectModel(eb, relationModel);
|
|
1298
1324
|
subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
|
|
1299
1325
|
if (payload && typeof payload === "object") {
|
|
1300
|
-
|
|
1301
|
-
subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
|
|
1302
|
-
}
|
|
1303
|
-
const skip = payload.skip;
|
|
1304
|
-
let take = payload.take;
|
|
1305
|
-
let negateOrderBy = false;
|
|
1306
|
-
if (take !== void 0 && take < 0) {
|
|
1307
|
-
negateOrderBy = true;
|
|
1308
|
-
take = -take;
|
|
1309
|
-
}
|
|
1310
|
-
subQuery = this.buildSkipTake(subQuery, skip, take);
|
|
1311
|
-
subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
1326
|
+
subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
|
|
1312
1327
|
}
|
|
1313
1328
|
const m2m = getManyToManyRelation(this.schema, model, relationField);
|
|
1314
1329
|
if (m2m) {
|
|
@@ -2750,27 +2765,8 @@ var BaseOperationHandler = class {
|
|
|
2750
2765
|
}
|
|
2751
2766
|
async read(kysely, model, args) {
|
|
2752
2767
|
let query = this.dialect.buildSelectModel((0, import_kysely8.expressionBuilder)(), model);
|
|
2753
|
-
if (args
|
|
2754
|
-
query =
|
|
2755
|
-
}
|
|
2756
|
-
let negateOrderBy = false;
|
|
2757
|
-
const skip = args?.skip;
|
|
2758
|
-
let take = args?.take;
|
|
2759
|
-
if (take !== void 0 && take < 0) {
|
|
2760
|
-
negateOrderBy = true;
|
|
2761
|
-
take = -take;
|
|
2762
|
-
}
|
|
2763
|
-
query = this.dialect.buildSkipTake(query, skip, take);
|
|
2764
|
-
query = this.dialect.buildOrderBy(query, model, model, args?.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
|
|
2765
|
-
let inMemoryDistinct = void 0;
|
|
2766
|
-
if (args?.distinct) {
|
|
2767
|
-
const distinct = ensureArray(args.distinct);
|
|
2768
|
-
if (this.dialect.supportsDistinctOn) {
|
|
2769
|
-
query = query.distinctOn(distinct.map((f) => import_kysely8.sql.ref(`${model}.${f}`)));
|
|
2770
|
-
} else {
|
|
2771
|
-
inMemoryDistinct = distinct;
|
|
2772
|
-
query = distinct.reduce((acc, field) => acc.select((eb) => this.dialect.fieldRef(model, field, eb).as(`$distinct$${field}`)), query);
|
|
2773
|
-
}
|
|
2768
|
+
if (args) {
|
|
2769
|
+
query = this.dialect.buildFilterSortTake(model, args, query);
|
|
2774
2770
|
}
|
|
2775
2771
|
if (args && "select" in args && args.select) {
|
|
2776
2772
|
query = this.buildFieldSelection(model, query, args.select, model);
|
|
@@ -2780,9 +2776,6 @@ var BaseOperationHandler = class {
|
|
|
2780
2776
|
if (args && "include" in args && args.include) {
|
|
2781
2777
|
query = this.buildFieldSelection(model, query, args.include, model);
|
|
2782
2778
|
}
|
|
2783
|
-
if (args?.cursor) {
|
|
2784
|
-
query = this.buildCursorFilter(model, query, args.cursor, args.orderBy, negateOrderBy);
|
|
2785
|
-
}
|
|
2786
2779
|
query = query.modifyEnd(this.makeContextComment({
|
|
2787
2780
|
model,
|
|
2788
2781
|
operation: "read"
|
|
@@ -2803,21 +2796,6 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2803
2796
|
}
|
|
2804
2797
|
throw new QueryError(message, err);
|
|
2805
2798
|
}
|
|
2806
|
-
if (inMemoryDistinct) {
|
|
2807
|
-
const distinctResult = [];
|
|
2808
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2809
|
-
for (const r of result) {
|
|
2810
|
-
const key = safeJSONStringify(inMemoryDistinct.map((f) => r[`$distinct$${f}`]));
|
|
2811
|
-
if (!seen.has(key)) {
|
|
2812
|
-
distinctResult.push(r);
|
|
2813
|
-
seen.add(key);
|
|
2814
|
-
}
|
|
2815
|
-
}
|
|
2816
|
-
result = distinctResult;
|
|
2817
|
-
for (const r of result) {
|
|
2818
|
-
Object.keys(r).filter((k) => k.startsWith("$distinct$")).forEach((k) => delete r[k]);
|
|
2819
|
-
}
|
|
2820
|
-
}
|
|
2821
2799
|
return result;
|
|
2822
2800
|
}
|
|
2823
2801
|
async readUnique(kysely, model, args) {
|
|
@@ -2856,28 +2834,6 @@ ${compiled.parameters.map((p) => (0, import_node_util.inspect)(p)).join("\n")}`;
|
|
|
2856
2834
|
buildCountSelection(query, model, parentAlias, payload) {
|
|
2857
2835
|
return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
|
|
2858
2836
|
}
|
|
2859
|
-
buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
|
|
2860
|
-
if (!orderBy) {
|
|
2861
|
-
orderBy = makeDefaultOrderBy(this.schema, model);
|
|
2862
|
-
}
|
|
2863
|
-
const orderByItems = ensureArray(orderBy).flatMap((obj) => Object.entries(obj));
|
|
2864
|
-
const eb = (0, import_kysely8.expressionBuilder)();
|
|
2865
|
-
const cursorFilter = this.dialect.buildFilter(eb, model, model, cursor);
|
|
2866
|
-
let result = query;
|
|
2867
|
-
const filters = [];
|
|
2868
|
-
for (let i = orderByItems.length - 1; i >= 0; i--) {
|
|
2869
|
-
const andFilters = [];
|
|
2870
|
-
for (let j = 0; j <= i; j++) {
|
|
2871
|
-
const [field, order] = orderByItems[j];
|
|
2872
|
-
const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
|
|
2873
|
-
const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
|
|
2874
|
-
andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
|
|
2875
|
-
}
|
|
2876
|
-
filters.push(eb.and(andFilters));
|
|
2877
|
-
}
|
|
2878
|
-
result = result.where((eb2) => eb2.or(filters));
|
|
2879
|
-
return result;
|
|
2880
|
-
}
|
|
2881
2837
|
async create(kysely, model, data, fromRelation, creatingForDelegate = false) {
|
|
2882
2838
|
const modelDef = this.requireModel(model);
|
|
2883
2839
|
if (modelDef.isDelegate && !creatingForDelegate) {
|
|
@@ -4506,8 +4462,7 @@ var InputValidator = class {
|
|
|
4506
4462
|
}
|
|
4507
4463
|
validateFindArgs(model, unique, args) {
|
|
4508
4464
|
return this.validate(model, "find", {
|
|
4509
|
-
unique
|
|
4510
|
-
collection: true
|
|
4465
|
+
unique
|
|
4511
4466
|
}, (model2, options) => this.makeFindSchema(model2, options), args);
|
|
4512
4467
|
}
|
|
4513
4468
|
validateCreateArgs(model, args) {
|
|
@@ -4575,12 +4530,12 @@ var InputValidator = class {
|
|
|
4575
4530
|
fields["select"] = this.makeSelectSchema(model).optional();
|
|
4576
4531
|
fields["include"] = this.makeIncludeSchema(model).optional();
|
|
4577
4532
|
fields["omit"] = this.makeOmitSchema(model).optional();
|
|
4578
|
-
|
|
4579
|
-
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4580
|
-
if (options.collection) {
|
|
4533
|
+
if (!options.unique) {
|
|
4581
4534
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4582
4535
|
fields["take"] = this.makeTakeSchema().optional();
|
|
4583
4536
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4537
|
+
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4538
|
+
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4584
4539
|
}
|
|
4585
4540
|
let result = import_zod.z.strictObject(fields);
|
|
4586
4541
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
@@ -4886,13 +4841,7 @@ var InputValidator = class {
|
|
|
4886
4841
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4887
4842
|
const fieldDef = requireField(this.schema, model, field);
|
|
4888
4843
|
if (fieldDef.relation) {
|
|
4889
|
-
fields[field] =
|
|
4890
|
-
import_zod.z.literal(true),
|
|
4891
|
-
import_zod.z.strictObject({
|
|
4892
|
-
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4893
|
-
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4894
|
-
})
|
|
4895
|
-
]).optional();
|
|
4844
|
+
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4896
4845
|
} else {
|
|
4897
4846
|
fields[field] = import_zod.z.boolean().optional();
|
|
4898
4847
|
}
|
|
@@ -4916,6 +4865,31 @@ var InputValidator = class {
|
|
|
4916
4865
|
}
|
|
4917
4866
|
return import_zod.z.strictObject(fields);
|
|
4918
4867
|
}
|
|
4868
|
+
makeRelationSelectIncludeSchema(fieldDef) {
|
|
4869
|
+
let objSchema = import_zod.z.strictObject({
|
|
4870
|
+
...fieldDef.array || fieldDef.optional ? {
|
|
4871
|
+
// to-many relations and optional to-one relations are filterable
|
|
4872
|
+
where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4873
|
+
} : {},
|
|
4874
|
+
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4875
|
+
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4876
|
+
omit: import_zod.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4877
|
+
...fieldDef.array ? {
|
|
4878
|
+
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
4879
|
+
orderBy: import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4880
|
+
skip: this.makeSkipSchema().optional(),
|
|
4881
|
+
take: this.makeTakeSchema().optional(),
|
|
4882
|
+
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
4883
|
+
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4884
|
+
} : {}
|
|
4885
|
+
});
|
|
4886
|
+
objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
|
|
4887
|
+
objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
|
|
4888
|
+
return import_zod.z.union([
|
|
4889
|
+
import_zod.z.boolean(),
|
|
4890
|
+
objSchema
|
|
4891
|
+
]);
|
|
4892
|
+
}
|
|
4919
4893
|
makeOmitSchema(model) {
|
|
4920
4894
|
const modelDef = requireModel(this.schema, model);
|
|
4921
4895
|
const fields = {};
|
|
@@ -4933,19 +4907,7 @@ var InputValidator = class {
|
|
|
4933
4907
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4934
4908
|
const fieldDef = requireField(this.schema, model, field);
|
|
4935
4909
|
if (fieldDef.relation) {
|
|
4936
|
-
fields[field] =
|
|
4937
|
-
import_zod.z.literal(true),
|
|
4938
|
-
import_zod.z.strictObject({
|
|
4939
|
-
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4940
|
-
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4941
|
-
omit: import_zod.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4942
|
-
where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
|
|
4943
|
-
orderBy: import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4944
|
-
skip: this.makeSkipSchema().optional(),
|
|
4945
|
-
take: this.makeTakeSchema().optional(),
|
|
4946
|
-
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4947
|
-
})
|
|
4948
|
-
]).optional();
|
|
4910
|
+
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4949
4911
|
}
|
|
4950
4912
|
}
|
|
4951
4913
|
return import_zod.z.strictObject(fields);
|
|
@@ -5014,7 +4976,7 @@ var InputValidator = class {
|
|
|
5014
4976
|
// #region Create
|
|
5015
4977
|
makeCreateSchema(model) {
|
|
5016
4978
|
const dataSchema = this.makeCreateDataSchema(model, false);
|
|
5017
|
-
const schema = import_zod.z.
|
|
4979
|
+
const schema = import_zod.z.strictObject({
|
|
5018
4980
|
data: dataSchema,
|
|
5019
4981
|
select: this.makeSelectSchema(model).optional(),
|
|
5020
4982
|
include: this.makeIncludeSchema(model).optional(),
|
|
@@ -5027,10 +4989,10 @@ var InputValidator = class {
|
|
|
5027
4989
|
}
|
|
5028
4990
|
makeCreateManyAndReturnSchema(model) {
|
|
5029
4991
|
const base = this.makeCreateManyDataSchema(model, []);
|
|
5030
|
-
const result = base.
|
|
4992
|
+
const result = base.extend({
|
|
5031
4993
|
select: this.makeSelectSchema(model).optional(),
|
|
5032
4994
|
omit: this.makeOmitSchema(model).optional()
|
|
5033
|
-
})
|
|
4995
|
+
});
|
|
5034
4996
|
return this.refineForSelectOmitMutuallyExclusive(result).optional();
|
|
5035
4997
|
}
|
|
5036
4998
|
makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
|
|
@@ -5195,13 +5157,13 @@ var InputValidator = class {
|
|
|
5195
5157
|
makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
|
|
5196
5158
|
const whereSchema = this.makeWhereSchema(model, true);
|
|
5197
5159
|
const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
|
|
5198
|
-
return this.orArray(import_zod.z.
|
|
5160
|
+
return this.orArray(import_zod.z.strictObject({
|
|
5199
5161
|
where: whereSchema,
|
|
5200
5162
|
create: createSchema
|
|
5201
5163
|
}), canBeArray);
|
|
5202
5164
|
}
|
|
5203
5165
|
makeCreateManyDataSchema(model, withoutFields) {
|
|
5204
|
-
return import_zod.z.
|
|
5166
|
+
return import_zod.z.strictObject({
|
|
5205
5167
|
data: this.makeCreateDataSchema(model, true, withoutFields, true),
|
|
5206
5168
|
skipDuplicates: import_zod.z.boolean().optional()
|
|
5207
5169
|
});
|
|
@@ -5209,7 +5171,7 @@ var InputValidator = class {
|
|
|
5209
5171
|
// #endregion
|
|
5210
5172
|
// #region Update
|
|
5211
5173
|
makeUpdateSchema(model) {
|
|
5212
|
-
const schema = import_zod.z.
|
|
5174
|
+
const schema = import_zod.z.strictObject({
|
|
5213
5175
|
where: this.makeWhereSchema(model, true),
|
|
5214
5176
|
data: this.makeUpdateDataSchema(model),
|
|
5215
5177
|
select: this.makeSelectSchema(model).optional(),
|
|
@@ -5219,7 +5181,7 @@ var InputValidator = class {
|
|
|
5219
5181
|
return this.refineForSelectIncludeMutuallyExclusive(schema);
|
|
5220
5182
|
}
|
|
5221
5183
|
makeUpdateManySchema(model) {
|
|
5222
|
-
return import_zod.z.
|
|
5184
|
+
return import_zod.z.strictObject({
|
|
5223
5185
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5224
5186
|
data: this.makeUpdateDataSchema(model, [], true),
|
|
5225
5187
|
limit: import_zod.z.int().nonnegative().optional()
|
|
@@ -5227,14 +5189,14 @@ var InputValidator = class {
|
|
|
5227
5189
|
}
|
|
5228
5190
|
makeUpdateManyAndReturnSchema(model) {
|
|
5229
5191
|
const base = this.makeUpdateManySchema(model);
|
|
5230
|
-
const result = base.
|
|
5192
|
+
const result = base.extend({
|
|
5231
5193
|
select: this.makeSelectSchema(model).optional(),
|
|
5232
5194
|
omit: this.makeOmitSchema(model).optional()
|
|
5233
|
-
})
|
|
5195
|
+
});
|
|
5234
5196
|
return this.refineForSelectOmitMutuallyExclusive(result);
|
|
5235
5197
|
}
|
|
5236
5198
|
makeUpsertSchema(model) {
|
|
5237
|
-
const schema = import_zod.z.
|
|
5199
|
+
const schema = import_zod.z.strictObject({
|
|
5238
5200
|
where: this.makeWhereSchema(model, true),
|
|
5239
5201
|
create: this.makeCreateDataSchema(model, false),
|
|
5240
5202
|
update: this.makeUpdateDataSchema(model),
|
|
@@ -5319,7 +5281,7 @@ var InputValidator = class {
|
|
|
5319
5281
|
// #endregion
|
|
5320
5282
|
// #region Delete
|
|
5321
5283
|
makeDeleteSchema(model) {
|
|
5322
|
-
const schema = import_zod.z.
|
|
5284
|
+
const schema = import_zod.z.strictObject({
|
|
5323
5285
|
where: this.makeWhereSchema(model, true),
|
|
5324
5286
|
select: this.makeSelectSchema(model).optional(),
|
|
5325
5287
|
include: this.makeIncludeSchema(model).optional()
|
|
@@ -5347,7 +5309,7 @@ var InputValidator = class {
|
|
|
5347
5309
|
const modelDef = requireModel(this.schema, model);
|
|
5348
5310
|
return import_zod.z.union([
|
|
5349
5311
|
import_zod.z.literal(true),
|
|
5350
|
-
import_zod.z.
|
|
5312
|
+
import_zod.z.strictObject({
|
|
5351
5313
|
_all: import_zod.z.literal(true).optional(),
|
|
5352
5314
|
...Object.keys(modelDef.fields).reduce((acc, field) => {
|
|
5353
5315
|
acc[field] = import_zod.z.literal(true).optional();
|
|
@@ -5394,7 +5356,7 @@ var InputValidator = class {
|
|
|
5394
5356
|
makeGroupBySchema(model) {
|
|
5395
5357
|
const modelDef = requireModel(this.schema, model);
|
|
5396
5358
|
const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
|
|
5397
|
-
let schema = import_zod.z.
|
|
5359
|
+
let schema = import_zod.z.strictObject({
|
|
5398
5360
|
where: this.makeWhereSchema(model, false).optional(),
|
|
5399
5361
|
orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
|
|
5400
5362
|
by: this.orArray(import_zod.z.enum(nonRelationFields), true),
|
|
@@ -6440,6 +6402,9 @@ var SchemaDbPusher = class {
|
|
|
6440
6402
|
if (this.isAutoIncrement(fieldDef) && this.schema.provider.type === "postgresql") {
|
|
6441
6403
|
return "serial";
|
|
6442
6404
|
}
|
|
6405
|
+
if (this.isCustomType(fieldDef.type)) {
|
|
6406
|
+
return "jsonb";
|
|
6407
|
+
}
|
|
6443
6408
|
const type = fieldDef.type;
|
|
6444
6409
|
const result = (0, import_ts_pattern18.match)(type).with("String", () => "text").with("Boolean", () => "boolean").with("Int", () => "integer").with("Float", () => "real").with("BigInt", () => "bigint").with("Decimal", () => "decimal").with("DateTime", () => "timestamp").with("Bytes", () => this.schema.provider.type === "postgresql" ? "bytea" : "blob").with("Json", () => "jsonb").otherwise(() => {
|
|
6445
6410
|
throw new Error(`Unsupported field type: ${type}`);
|
|
@@ -6450,6 +6415,9 @@ var SchemaDbPusher = class {
|
|
|
6450
6415
|
return result;
|
|
6451
6416
|
}
|
|
6452
6417
|
}
|
|
6418
|
+
isCustomType(type) {
|
|
6419
|
+
return this.schema.typeDefs && Object.values(this.schema.typeDefs).some((def) => def.name === type);
|
|
6420
|
+
}
|
|
6453
6421
|
isAutoIncrement(fieldDef) {
|
|
6454
6422
|
return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
|
|
6455
6423
|
}
|
|
@@ -6900,7 +6868,7 @@ function createClientProxy(client) {
|
|
|
6900
6868
|
}
|
|
6901
6869
|
__name(createClientProxy, "createClientProxy");
|
|
6902
6870
|
function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
|
|
6903
|
-
const createPromise = /* @__PURE__ */ __name((operation, args, handler, postProcess = false, throwIfNoResult = false) => {
|
|
6871
|
+
const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
|
|
6904
6872
|
return createZenStackPromise(async (txClient) => {
|
|
6905
6873
|
let proceed = /* @__PURE__ */ __name(async (_args) => {
|
|
6906
6874
|
const _handler = txClient ? handler.withClient(txClient) : handler;
|
|
@@ -6926,7 +6894,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6926
6894
|
proceed = /* @__PURE__ */ __name((_args) => onQuery({
|
|
6927
6895
|
client,
|
|
6928
6896
|
model,
|
|
6929
|
-
operation,
|
|
6897
|
+
operation: nominalOperation,
|
|
6930
6898
|
// reflect the latest override if provided
|
|
6931
6899
|
args: _args,
|
|
6932
6900
|
// ensure inner overrides are propagated to the previous proceed
|
|
@@ -6939,55 +6907,55 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
|
|
|
6939
6907
|
}, "createPromise");
|
|
6940
6908
|
return {
|
|
6941
6909
|
findUnique: /* @__PURE__ */ __name((args) => {
|
|
6942
|
-
return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6910
|
+
return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6943
6911
|
}, "findUnique"),
|
|
6944
6912
|
findUniqueOrThrow: /* @__PURE__ */ __name((args) => {
|
|
6945
|
-
return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
6913
|
+
return createPromise("findUnique", "findUniqueOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
6946
6914
|
}, "findUniqueOrThrow"),
|
|
6947
6915
|
findFirst: /* @__PURE__ */ __name((args) => {
|
|
6948
|
-
return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6916
|
+
return createPromise("findFirst", "findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6949
6917
|
}, "findFirst"),
|
|
6950
6918
|
findFirstOrThrow: /* @__PURE__ */ __name((args) => {
|
|
6951
|
-
return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
6919
|
+
return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
|
|
6952
6920
|
}, "findFirstOrThrow"),
|
|
6953
6921
|
findMany: /* @__PURE__ */ __name((args) => {
|
|
6954
|
-
return createPromise("findMany", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6922
|
+
return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
|
|
6955
6923
|
}, "findMany"),
|
|
6956
6924
|
create: /* @__PURE__ */ __name((args) => {
|
|
6957
|
-
return createPromise("create", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
6925
|
+
return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
6958
6926
|
}, "create"),
|
|
6959
6927
|
createMany: /* @__PURE__ */ __name((args) => {
|
|
6960
|
-
return createPromise("createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
|
|
6928
|
+
return createPromise("createMany", "createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
|
|
6961
6929
|
}, "createMany"),
|
|
6962
6930
|
createManyAndReturn: /* @__PURE__ */ __name((args) => {
|
|
6963
|
-
return createPromise("createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
6931
|
+
return createPromise("createManyAndReturn", "createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
|
|
6964
6932
|
}, "createManyAndReturn"),
|
|
6965
6933
|
update: /* @__PURE__ */ __name((args) => {
|
|
6966
|
-
return createPromise("update", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6934
|
+
return createPromise("update", "update", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6967
6935
|
}, "update"),
|
|
6968
6936
|
updateMany: /* @__PURE__ */ __name((args) => {
|
|
6969
|
-
return createPromise("updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
|
|
6937
|
+
return createPromise("updateMany", "updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
|
|
6970
6938
|
}, "updateMany"),
|
|
6971
6939
|
updateManyAndReturn: /* @__PURE__ */ __name((args) => {
|
|
6972
|
-
return createPromise("updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6940
|
+
return createPromise("updateManyAndReturn", "updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6973
6941
|
}, "updateManyAndReturn"),
|
|
6974
6942
|
upsert: /* @__PURE__ */ __name((args) => {
|
|
6975
|
-
return createPromise("upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6943
|
+
return createPromise("upsert", "upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
|
|
6976
6944
|
}, "upsert"),
|
|
6977
6945
|
delete: /* @__PURE__ */ __name((args) => {
|
|
6978
|
-
return createPromise("delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
|
|
6946
|
+
return createPromise("delete", "delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
|
|
6979
6947
|
}, "delete"),
|
|
6980
6948
|
deleteMany: /* @__PURE__ */ __name((args) => {
|
|
6981
|
-
return createPromise("deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
|
|
6949
|
+
return createPromise("deleteMany", "deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
|
|
6982
6950
|
}, "deleteMany"),
|
|
6983
6951
|
count: /* @__PURE__ */ __name((args) => {
|
|
6984
|
-
return createPromise("count", args, new CountOperationHandler(client, model, inputValidator), false);
|
|
6952
|
+
return createPromise("count", "count", args, new CountOperationHandler(client, model, inputValidator), false);
|
|
6985
6953
|
}, "count"),
|
|
6986
6954
|
aggregate: /* @__PURE__ */ __name((args) => {
|
|
6987
|
-
return createPromise("aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
|
|
6955
|
+
return createPromise("aggregate", "aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
|
|
6988
6956
|
}, "aggregate"),
|
|
6989
6957
|
groupBy: /* @__PURE__ */ __name((args) => {
|
|
6990
|
-
return createPromise("groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
|
|
6958
|
+
return createPromise("groupBy", "groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
|
|
6991
6959
|
}, "groupBy")
|
|
6992
6960
|
};
|
|
6993
6961
|
}
|