@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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientConstructor } from './contract-BOWN0dwS.cjs';
2
- export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-BOWN0dwS.cjs';
1
+ import { C as ClientConstructor } from './contract-c8GpEAl3.cjs';
2
+ export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-c8GpEAl3.cjs';
3
3
  import 'decimal.js';
4
4
  import '@zenstackhq/sdk/schema';
5
5
  import 'kysely';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientConstructor } from './contract-BOWN0dwS.js';
2
- export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-BOWN0dwS.js';
1
+ import { C as ClientConstructor } from './contract-c8GpEAl3.js';
2
+ export { K as AggregateArgs, L as AggregateResult, B as BatchResult, i as BooleanFilter, h as BytesFilter, c as ClientContract, d as ClientOptions, G as CountArgs, H as CountResult, u as CreateArgs, w as CreateManyAndReturnArgs, v as CreateManyArgs, D as DateTimeFilter, A as DeleteArgs, E as DeleteManyArgs, F as FindArgs, s as FindFirstArgs, r as FindManyArgs, t as FindUniqueArgs, P as GroupByArgs, Q as GroupByResult, I as IncludeInput, J as JsonArray, a as JsonObject, b as JsonValue, M as ModelResult, k as NullsOrder, N as NumberFilter, m as OmitInput, O as OrderBy, n as SelectIncludeOmit, o as SelectInput, q as SelectSubset, S as SimplifiedModelResult, j as SortOrder, g as StringFilter, p as Subset, T as ToKysely, f as TypeDefResult, U as UpdateArgs, y as UpdateManyAndReturnArgs, x as UpdateManyArgs, z as UpsertArgs, W as WhereInput, l as WhereUniqueInput, e as definePlugin } from './contract-c8GpEAl3.js';
3
3
  import 'decimal.js';
4
4
  import '@zenstackhq/sdk/schema';
5
5
  import 'kysely';
package/dist/index.js CHANGED
@@ -379,16 +379,6 @@ function ensureArray(value) {
379
379
  }
380
380
  }
381
381
  __name(ensureArray, "ensureArray");
382
- function safeJSONStringify(value) {
383
- return JSON.stringify(value, (_, v) => {
384
- if (typeof v === "bigint") {
385
- return v.toString();
386
- } else {
387
- return v;
388
- }
389
- });
390
- }
391
- __name(safeJSONStringify, "safeJSONStringify");
392
382
  function extractIdFields(entity, schema, model) {
393
383
  const idFields = getIdFields(schema, model);
394
384
  return extractFields(entity, idFields);
@@ -525,6 +515,33 @@ var BaseCrudDialect = class {
525
515
  }
526
516
  return result;
527
517
  }
518
+ buildFilterSortTake(model, args, query) {
519
+ let result = query;
520
+ if (args.where) {
521
+ result = result.where((eb) => this.buildFilter(eb, model, model, args?.where));
522
+ }
523
+ let negateOrderBy = false;
524
+ const skip = args.skip;
525
+ let take = args.take;
526
+ if (take !== void 0 && take < 0) {
527
+ negateOrderBy = true;
528
+ take = -take;
529
+ }
530
+ result = this.buildSkipTake(result, skip, take);
531
+ result = this.buildOrderBy(result, model, model, args.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
532
+ if ("distinct" in args && args.distinct) {
533
+ const distinct = ensureArray(args.distinct);
534
+ if (this.supportsDistinctOn) {
535
+ result = result.distinctOn(distinct.map((f) => sql.ref(`${model}.${f}`)));
536
+ } else {
537
+ throw new QueryError(`"distinct" is not supported by "${this.schema.provider.type}" provider`);
538
+ }
539
+ }
540
+ if (args.cursor) {
541
+ result = this.buildCursorFilter(model, result, args.cursor, args.orderBy, negateOrderBy);
542
+ }
543
+ return result;
544
+ }
528
545
  buildFilter(eb, model, modelAlias, where) {
529
546
  if (where === true || where === void 0) {
530
547
  return this.true(eb);
@@ -562,6 +579,26 @@ var BaseCrudDialect = class {
562
579
  }
563
580
  return result;
564
581
  }
582
+ buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
583
+ const _orderBy = orderBy ?? makeDefaultOrderBy(this.schema, model);
584
+ const orderByItems = ensureArray(_orderBy).flatMap((obj) => Object.entries(obj));
585
+ const eb = expressionBuilder();
586
+ const cursorFilter = this.buildFilter(eb, model, model, cursor);
587
+ let result = query;
588
+ const filters = [];
589
+ for (let i = orderByItems.length - 1; i >= 0; i--) {
590
+ const andFilters = [];
591
+ for (let j = 0; j <= i; j++) {
592
+ const [field, order] = orderByItems[j];
593
+ const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
594
+ const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
595
+ andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
596
+ }
597
+ filters.push(eb.and(andFilters));
598
+ }
599
+ result = result.where((eb2) => eb2.or(filters));
600
+ return result;
601
+ }
565
602
  isLogicalCombinator(key) {
566
603
  return LOGICAL_COMBINATORS.includes(key);
567
604
  }
@@ -1088,18 +1125,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1088
1125
  let subQuery = this.buildSelectModel(eb, relationModel);
1089
1126
  subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
1090
1127
  if (payload && typeof payload === "object") {
1091
- if (payload.where) {
1092
- subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
1093
- }
1094
- const skip = payload.skip;
1095
- let take = payload.take;
1096
- let negateOrderBy = false;
1097
- if (take !== void 0 && take < 0) {
1098
- negateOrderBy = true;
1099
- take = -take;
1100
- }
1101
- subQuery = this.buildSkipTake(subQuery, skip, take);
1102
- subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
1128
+ subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
1103
1129
  }
1104
1130
  const m2m = getManyToManyRelation(this.schema, model, relationField);
1105
1131
  if (m2m) {
@@ -1262,18 +1288,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
1262
1288
  let subQuery = this.buildSelectModel(eb, relationModel);
1263
1289
  subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
1264
1290
  if (payload && typeof payload === "object") {
1265
- if (payload.where) {
1266
- subQuery = subQuery.where((eb2) => this.buildFilter(eb2, relationModel, relationModel, payload.where));
1267
- }
1268
- const skip = payload.skip;
1269
- let take = payload.take;
1270
- let negateOrderBy = false;
1271
- if (take !== void 0 && take < 0) {
1272
- negateOrderBy = true;
1273
- take = -take;
1274
- }
1275
- subQuery = this.buildSkipTake(subQuery, skip, take);
1276
- subQuery = this.buildOrderBy(subQuery, relationModel, relationModel, payload.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
1291
+ subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
1277
1292
  }
1278
1293
  const m2m = getManyToManyRelation(this.schema, model, relationField);
1279
1294
  if (m2m) {
@@ -2715,27 +2730,8 @@ var BaseOperationHandler = class {
2715
2730
  }
2716
2731
  async read(kysely, model, args) {
2717
2732
  let query = this.dialect.buildSelectModel(expressionBuilder3(), model);
2718
- if (args?.where) {
2719
- query = query.where((eb) => this.dialect.buildFilter(eb, model, model, args?.where));
2720
- }
2721
- let negateOrderBy = false;
2722
- const skip = args?.skip;
2723
- let take = args?.take;
2724
- if (take !== void 0 && take < 0) {
2725
- negateOrderBy = true;
2726
- take = -take;
2727
- }
2728
- query = this.dialect.buildSkipTake(query, skip, take);
2729
- query = this.dialect.buildOrderBy(query, model, model, args?.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
2730
- let inMemoryDistinct = void 0;
2731
- if (args?.distinct) {
2732
- const distinct = ensureArray(args.distinct);
2733
- if (this.dialect.supportsDistinctOn) {
2734
- query = query.distinctOn(distinct.map((f) => sql4.ref(`${model}.${f}`)));
2735
- } else {
2736
- inMemoryDistinct = distinct;
2737
- query = distinct.reduce((acc, field) => acc.select((eb) => this.dialect.fieldRef(model, field, eb).as(`$distinct$${field}`)), query);
2738
- }
2733
+ if (args) {
2734
+ query = this.dialect.buildFilterSortTake(model, args, query);
2739
2735
  }
2740
2736
  if (args && "select" in args && args.select) {
2741
2737
  query = this.buildFieldSelection(model, query, args.select, model);
@@ -2745,9 +2741,6 @@ var BaseOperationHandler = class {
2745
2741
  if (args && "include" in args && args.include) {
2746
2742
  query = this.buildFieldSelection(model, query, args.include, model);
2747
2743
  }
2748
- if (args?.cursor) {
2749
- query = this.buildCursorFilter(model, query, args.cursor, args.orderBy, negateOrderBy);
2750
- }
2751
2744
  query = query.modifyEnd(this.makeContextComment({
2752
2745
  model,
2753
2746
  operation: "read"
@@ -2768,21 +2761,6 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
2768
2761
  }
2769
2762
  throw new QueryError(message, err);
2770
2763
  }
2771
- if (inMemoryDistinct) {
2772
- const distinctResult = [];
2773
- const seen = /* @__PURE__ */ new Set();
2774
- for (const r of result) {
2775
- const key = safeJSONStringify(inMemoryDistinct.map((f) => r[`$distinct$${f}`]));
2776
- if (!seen.has(key)) {
2777
- distinctResult.push(r);
2778
- seen.add(key);
2779
- }
2780
- }
2781
- result = distinctResult;
2782
- for (const r of result) {
2783
- Object.keys(r).filter((k) => k.startsWith("$distinct$")).forEach((k) => delete r[k]);
2784
- }
2785
- }
2786
2764
  return result;
2787
2765
  }
2788
2766
  async readUnique(kysely, model, args) {
@@ -2821,28 +2799,6 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
2821
2799
  buildCountSelection(query, model, parentAlias, payload) {
2822
2800
  return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
2823
2801
  }
2824
- buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
2825
- if (!orderBy) {
2826
- orderBy = makeDefaultOrderBy(this.schema, model);
2827
- }
2828
- const orderByItems = ensureArray(orderBy).flatMap((obj) => Object.entries(obj));
2829
- const eb = expressionBuilder3();
2830
- const cursorFilter = this.dialect.buildFilter(eb, model, model, cursor);
2831
- let result = query;
2832
- const filters = [];
2833
- for (let i = orderByItems.length - 1; i >= 0; i--) {
2834
- const andFilters = [];
2835
- for (let j = 0; j <= i; j++) {
2836
- const [field, order] = orderByItems[j];
2837
- const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
2838
- const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
2839
- andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
2840
- }
2841
- filters.push(eb.and(andFilters));
2842
- }
2843
- result = result.where((eb2) => eb2.or(filters));
2844
- return result;
2845
- }
2846
2802
  async create(kysely, model, data, fromRelation, creatingForDelegate = false) {
2847
2803
  const modelDef = this.requireModel(model);
2848
2804
  if (modelDef.isDelegate && !creatingForDelegate) {
@@ -4471,8 +4427,7 @@ var InputValidator = class {
4471
4427
  }
4472
4428
  validateFindArgs(model, unique, args) {
4473
4429
  return this.validate(model, "find", {
4474
- unique,
4475
- collection: true
4430
+ unique
4476
4431
  }, (model2, options) => this.makeFindSchema(model2, options), args);
4477
4432
  }
4478
4433
  validateCreateArgs(model, args) {
@@ -4540,12 +4495,12 @@ var InputValidator = class {
4540
4495
  fields["select"] = this.makeSelectSchema(model).optional();
4541
4496
  fields["include"] = this.makeIncludeSchema(model).optional();
4542
4497
  fields["omit"] = this.makeOmitSchema(model).optional();
4543
- fields["distinct"] = this.makeDistinctSchema(model).optional();
4544
- fields["cursor"] = this.makeCursorSchema(model).optional();
4545
- if (options.collection) {
4498
+ if (!options.unique) {
4546
4499
  fields["skip"] = this.makeSkipSchema().optional();
4547
4500
  fields["take"] = this.makeTakeSchema().optional();
4548
4501
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
4502
+ fields["cursor"] = this.makeCursorSchema(model).optional();
4503
+ fields["distinct"] = this.makeDistinctSchema(model).optional();
4549
4504
  }
4550
4505
  let result = z.strictObject(fields);
4551
4506
  result = this.refineForSelectIncludeMutuallyExclusive(result);
@@ -4851,13 +4806,7 @@ var InputValidator = class {
4851
4806
  for (const field of Object.keys(modelDef.fields)) {
4852
4807
  const fieldDef = requireField(this.schema, model, field);
4853
4808
  if (fieldDef.relation) {
4854
- fields[field] = z.union([
4855
- z.literal(true),
4856
- z.strictObject({
4857
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4858
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
4859
- })
4860
- ]).optional();
4809
+ fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
4861
4810
  } else {
4862
4811
  fields[field] = z.boolean().optional();
4863
4812
  }
@@ -4881,6 +4830,31 @@ var InputValidator = class {
4881
4830
  }
4882
4831
  return z.strictObject(fields);
4883
4832
  }
4833
+ makeRelationSelectIncludeSchema(fieldDef) {
4834
+ let objSchema = z.strictObject({
4835
+ ...fieldDef.array || fieldDef.optional ? {
4836
+ // to-many relations and optional to-one relations are filterable
4837
+ where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
4838
+ } : {},
4839
+ select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4840
+ include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4841
+ omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
4842
+ ...fieldDef.array ? {
4843
+ // to-many relations can be ordered, skipped, taken, and cursor-located
4844
+ orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
4845
+ skip: this.makeSkipSchema().optional(),
4846
+ take: this.makeTakeSchema().optional(),
4847
+ cursor: this.makeCursorSchema(fieldDef.type).optional(),
4848
+ distinct: this.makeDistinctSchema(fieldDef.type).optional()
4849
+ } : {}
4850
+ });
4851
+ objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
4852
+ objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
4853
+ return z.union([
4854
+ z.boolean(),
4855
+ objSchema
4856
+ ]);
4857
+ }
4884
4858
  makeOmitSchema(model) {
4885
4859
  const modelDef = requireModel(this.schema, model);
4886
4860
  const fields = {};
@@ -4898,19 +4872,7 @@ var InputValidator = class {
4898
4872
  for (const field of Object.keys(modelDef.fields)) {
4899
4873
  const fieldDef = requireField(this.schema, model, field);
4900
4874
  if (fieldDef.relation) {
4901
- fields[field] = z.union([
4902
- z.literal(true),
4903
- z.strictObject({
4904
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4905
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4906
- omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
4907
- where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
4908
- orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
4909
- skip: this.makeSkipSchema().optional(),
4910
- take: this.makeTakeSchema().optional(),
4911
- distinct: this.makeDistinctSchema(fieldDef.type).optional()
4912
- })
4913
- ]).optional();
4875
+ fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
4914
4876
  }
4915
4877
  }
4916
4878
  return z.strictObject(fields);
@@ -4979,7 +4941,7 @@ var InputValidator = class {
4979
4941
  // #region Create
4980
4942
  makeCreateSchema(model) {
4981
4943
  const dataSchema = this.makeCreateDataSchema(model, false);
4982
- const schema = z.object({
4944
+ const schema = z.strictObject({
4983
4945
  data: dataSchema,
4984
4946
  select: this.makeSelectSchema(model).optional(),
4985
4947
  include: this.makeIncludeSchema(model).optional(),
@@ -4992,10 +4954,10 @@ var InputValidator = class {
4992
4954
  }
4993
4955
  makeCreateManyAndReturnSchema(model) {
4994
4956
  const base = this.makeCreateManyDataSchema(model, []);
4995
- const result = base.merge(z.strictObject({
4957
+ const result = base.extend({
4996
4958
  select: this.makeSelectSchema(model).optional(),
4997
4959
  omit: this.makeOmitSchema(model).optional()
4998
- }));
4960
+ });
4999
4961
  return this.refineForSelectOmitMutuallyExclusive(result).optional();
5000
4962
  }
5001
4963
  makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
@@ -5160,13 +5122,13 @@ var InputValidator = class {
5160
5122
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
5161
5123
  const whereSchema = this.makeWhereSchema(model, true);
5162
5124
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
5163
- return this.orArray(z.object({
5125
+ return this.orArray(z.strictObject({
5164
5126
  where: whereSchema,
5165
5127
  create: createSchema
5166
5128
  }), canBeArray);
5167
5129
  }
5168
5130
  makeCreateManyDataSchema(model, withoutFields) {
5169
- return z.object({
5131
+ return z.strictObject({
5170
5132
  data: this.makeCreateDataSchema(model, true, withoutFields, true),
5171
5133
  skipDuplicates: z.boolean().optional()
5172
5134
  });
@@ -5174,7 +5136,7 @@ var InputValidator = class {
5174
5136
  // #endregion
5175
5137
  // #region Update
5176
5138
  makeUpdateSchema(model) {
5177
- const schema = z.object({
5139
+ const schema = z.strictObject({
5178
5140
  where: this.makeWhereSchema(model, true),
5179
5141
  data: this.makeUpdateDataSchema(model),
5180
5142
  select: this.makeSelectSchema(model).optional(),
@@ -5184,7 +5146,7 @@ var InputValidator = class {
5184
5146
  return this.refineForSelectIncludeMutuallyExclusive(schema);
5185
5147
  }
5186
5148
  makeUpdateManySchema(model) {
5187
- return z.object({
5149
+ return z.strictObject({
5188
5150
  where: this.makeWhereSchema(model, false).optional(),
5189
5151
  data: this.makeUpdateDataSchema(model, [], true),
5190
5152
  limit: z.int().nonnegative().optional()
@@ -5192,14 +5154,14 @@ var InputValidator = class {
5192
5154
  }
5193
5155
  makeUpdateManyAndReturnSchema(model) {
5194
5156
  const base = this.makeUpdateManySchema(model);
5195
- const result = base.merge(z.strictObject({
5157
+ const result = base.extend({
5196
5158
  select: this.makeSelectSchema(model).optional(),
5197
5159
  omit: this.makeOmitSchema(model).optional()
5198
- }));
5160
+ });
5199
5161
  return this.refineForSelectOmitMutuallyExclusive(result);
5200
5162
  }
5201
5163
  makeUpsertSchema(model) {
5202
- const schema = z.object({
5164
+ const schema = z.strictObject({
5203
5165
  where: this.makeWhereSchema(model, true),
5204
5166
  create: this.makeCreateDataSchema(model, false),
5205
5167
  update: this.makeUpdateDataSchema(model),
@@ -5284,7 +5246,7 @@ var InputValidator = class {
5284
5246
  // #endregion
5285
5247
  // #region Delete
5286
5248
  makeDeleteSchema(model) {
5287
- const schema = z.object({
5249
+ const schema = z.strictObject({
5288
5250
  where: this.makeWhereSchema(model, true),
5289
5251
  select: this.makeSelectSchema(model).optional(),
5290
5252
  include: this.makeIncludeSchema(model).optional()
@@ -5312,7 +5274,7 @@ var InputValidator = class {
5312
5274
  const modelDef = requireModel(this.schema, model);
5313
5275
  return z.union([
5314
5276
  z.literal(true),
5315
- z.object({
5277
+ z.strictObject({
5316
5278
  _all: z.literal(true).optional(),
5317
5279
  ...Object.keys(modelDef.fields).reduce((acc, field) => {
5318
5280
  acc[field] = z.literal(true).optional();
@@ -5359,7 +5321,7 @@ var InputValidator = class {
5359
5321
  makeGroupBySchema(model) {
5360
5322
  const modelDef = requireModel(this.schema, model);
5361
5323
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
5362
- let schema = z.object({
5324
+ let schema = z.strictObject({
5363
5325
  where: this.makeWhereSchema(model, false).optional(),
5364
5326
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
5365
5327
  by: this.orArray(z.enum(nonRelationFields), true),
@@ -6405,6 +6367,9 @@ var SchemaDbPusher = class {
6405
6367
  if (this.isAutoIncrement(fieldDef) && this.schema.provider.type === "postgresql") {
6406
6368
  return "serial";
6407
6369
  }
6370
+ if (this.isCustomType(fieldDef.type)) {
6371
+ return "jsonb";
6372
+ }
6408
6373
  const type = fieldDef.type;
6409
6374
  const result = match18(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(() => {
6410
6375
  throw new Error(`Unsupported field type: ${type}`);
@@ -6415,6 +6380,9 @@ var SchemaDbPusher = class {
6415
6380
  return result;
6416
6381
  }
6417
6382
  }
6383
+ isCustomType(type) {
6384
+ return this.schema.typeDefs && Object.values(this.schema.typeDefs).some((def) => def.name === type);
6385
+ }
6418
6386
  isAutoIncrement(fieldDef) {
6419
6387
  return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
6420
6388
  }
@@ -6865,7 +6833,7 @@ function createClientProxy(client) {
6865
6833
  }
6866
6834
  __name(createClientProxy, "createClientProxy");
6867
6835
  function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
6868
- const createPromise = /* @__PURE__ */ __name((operation, args, handler, postProcess = false, throwIfNoResult = false) => {
6836
+ const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
6869
6837
  return createZenStackPromise(async (txClient) => {
6870
6838
  let proceed = /* @__PURE__ */ __name(async (_args) => {
6871
6839
  const _handler = txClient ? handler.withClient(txClient) : handler;
@@ -6891,7 +6859,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6891
6859
  proceed = /* @__PURE__ */ __name((_args) => onQuery({
6892
6860
  client,
6893
6861
  model,
6894
- operation,
6862
+ operation: nominalOperation,
6895
6863
  // reflect the latest override if provided
6896
6864
  args: _args,
6897
6865
  // ensure inner overrides are propagated to the previous proceed
@@ -6904,55 +6872,55 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6904
6872
  }, "createPromise");
6905
6873
  return {
6906
6874
  findUnique: /* @__PURE__ */ __name((args) => {
6907
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6875
+ return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6908
6876
  }, "findUnique"),
6909
6877
  findUniqueOrThrow: /* @__PURE__ */ __name((args) => {
6910
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true, true);
6878
+ return createPromise("findUnique", "findUniqueOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6911
6879
  }, "findUniqueOrThrow"),
6912
6880
  findFirst: /* @__PURE__ */ __name((args) => {
6913
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6881
+ return createPromise("findFirst", "findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6914
6882
  }, "findFirst"),
6915
6883
  findFirstOrThrow: /* @__PURE__ */ __name((args) => {
6916
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true, true);
6884
+ return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6917
6885
  }, "findFirstOrThrow"),
6918
6886
  findMany: /* @__PURE__ */ __name((args) => {
6919
- return createPromise("findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6887
+ return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6920
6888
  }, "findMany"),
6921
6889
  create: /* @__PURE__ */ __name((args) => {
6922
- return createPromise("create", args, new CreateOperationHandler(client, model, inputValidator), true);
6890
+ return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
6923
6891
  }, "create"),
6924
6892
  createMany: /* @__PURE__ */ __name((args) => {
6925
- return createPromise("createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6893
+ return createPromise("createMany", "createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6926
6894
  }, "createMany"),
6927
6895
  createManyAndReturn: /* @__PURE__ */ __name((args) => {
6928
- return createPromise("createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6896
+ return createPromise("createManyAndReturn", "createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6929
6897
  }, "createManyAndReturn"),
6930
6898
  update: /* @__PURE__ */ __name((args) => {
6931
- return createPromise("update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6899
+ return createPromise("update", "update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6932
6900
  }, "update"),
6933
6901
  updateMany: /* @__PURE__ */ __name((args) => {
6934
- return createPromise("updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6902
+ return createPromise("updateMany", "updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6935
6903
  }, "updateMany"),
6936
6904
  updateManyAndReturn: /* @__PURE__ */ __name((args) => {
6937
- return createPromise("updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6905
+ return createPromise("updateManyAndReturn", "updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6938
6906
  }, "updateManyAndReturn"),
6939
6907
  upsert: /* @__PURE__ */ __name((args) => {
6940
- return createPromise("upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6908
+ return createPromise("upsert", "upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6941
6909
  }, "upsert"),
6942
6910
  delete: /* @__PURE__ */ __name((args) => {
6943
- return createPromise("delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6911
+ return createPromise("delete", "delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6944
6912
  }, "delete"),
6945
6913
  deleteMany: /* @__PURE__ */ __name((args) => {
6946
- return createPromise("deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6914
+ return createPromise("deleteMany", "deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6947
6915
  }, "deleteMany"),
6948
6916
  count: /* @__PURE__ */ __name((args) => {
6949
- return createPromise("count", args, new CountOperationHandler(client, model, inputValidator), false);
6917
+ return createPromise("count", "count", args, new CountOperationHandler(client, model, inputValidator), false);
6950
6918
  }, "count"),
6951
6919
  aggregate: /* @__PURE__ */ __name((args) => {
6952
- return createPromise("aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6920
+ return createPromise("aggregate", "aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6953
6921
  }, "aggregate"),
6954
6922
  groupBy: /* @__PURE__ */ __name((args) => {
6955
- return createPromise("groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6923
+ return createPromise("groupBy", "groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6956
6924
  }, "groupBy")
6957
6925
  };
6958
6926
  }