@zenstackhq/runtime 3.0.0-alpha.26 → 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-BF6mvhVn.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-BF6mvhVn.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-BF6mvhVn.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-BF6mvhVn.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) {
@@ -4875,25 +4831,28 @@ var InputValidator = class {
4875
4831
  return z.strictObject(fields);
4876
4832
  }
4877
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);
4878
4853
  return z.union([
4879
4854
  z.boolean(),
4880
- z.strictObject({
4881
- ...fieldDef.array || fieldDef.optional ? {
4882
- // to-many relations and optional to-one relations are filterable
4883
- where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
4884
- } : {},
4885
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4886
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4887
- omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
4888
- ...fieldDef.array ? {
4889
- // to-many relations can be ordered, skipped, taken, and cursor-located
4890
- orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
4891
- skip: this.makeSkipSchema().optional(),
4892
- take: this.makeTakeSchema().optional(),
4893
- cursor: this.makeCursorSchema(fieldDef.type).optional(),
4894
- distinct: this.makeDistinctSchema(fieldDef.type).optional()
4895
- } : {}
4896
- })
4855
+ objSchema
4897
4856
  ]);
4898
4857
  }
4899
4858
  makeOmitSchema(model) {
@@ -4982,7 +4941,7 @@ var InputValidator = class {
4982
4941
  // #region Create
4983
4942
  makeCreateSchema(model) {
4984
4943
  const dataSchema = this.makeCreateDataSchema(model, false);
4985
- const schema = z.object({
4944
+ const schema = z.strictObject({
4986
4945
  data: dataSchema,
4987
4946
  select: this.makeSelectSchema(model).optional(),
4988
4947
  include: this.makeIncludeSchema(model).optional(),
@@ -4995,10 +4954,10 @@ var InputValidator = class {
4995
4954
  }
4996
4955
  makeCreateManyAndReturnSchema(model) {
4997
4956
  const base = this.makeCreateManyDataSchema(model, []);
4998
- const result = base.merge(z.strictObject({
4957
+ const result = base.extend({
4999
4958
  select: this.makeSelectSchema(model).optional(),
5000
4959
  omit: this.makeOmitSchema(model).optional()
5001
- }));
4960
+ });
5002
4961
  return this.refineForSelectOmitMutuallyExclusive(result).optional();
5003
4962
  }
5004
4963
  makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
@@ -5163,13 +5122,13 @@ var InputValidator = class {
5163
5122
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
5164
5123
  const whereSchema = this.makeWhereSchema(model, true);
5165
5124
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
5166
- return this.orArray(z.object({
5125
+ return this.orArray(z.strictObject({
5167
5126
  where: whereSchema,
5168
5127
  create: createSchema
5169
5128
  }), canBeArray);
5170
5129
  }
5171
5130
  makeCreateManyDataSchema(model, withoutFields) {
5172
- return z.object({
5131
+ return z.strictObject({
5173
5132
  data: this.makeCreateDataSchema(model, true, withoutFields, true),
5174
5133
  skipDuplicates: z.boolean().optional()
5175
5134
  });
@@ -5177,7 +5136,7 @@ var InputValidator = class {
5177
5136
  // #endregion
5178
5137
  // #region Update
5179
5138
  makeUpdateSchema(model) {
5180
- const schema = z.object({
5139
+ const schema = z.strictObject({
5181
5140
  where: this.makeWhereSchema(model, true),
5182
5141
  data: this.makeUpdateDataSchema(model),
5183
5142
  select: this.makeSelectSchema(model).optional(),
@@ -5187,7 +5146,7 @@ var InputValidator = class {
5187
5146
  return this.refineForSelectIncludeMutuallyExclusive(schema);
5188
5147
  }
5189
5148
  makeUpdateManySchema(model) {
5190
- return z.object({
5149
+ return z.strictObject({
5191
5150
  where: this.makeWhereSchema(model, false).optional(),
5192
5151
  data: this.makeUpdateDataSchema(model, [], true),
5193
5152
  limit: z.int().nonnegative().optional()
@@ -5195,14 +5154,14 @@ var InputValidator = class {
5195
5154
  }
5196
5155
  makeUpdateManyAndReturnSchema(model) {
5197
5156
  const base = this.makeUpdateManySchema(model);
5198
- const result = base.merge(z.strictObject({
5157
+ const result = base.extend({
5199
5158
  select: this.makeSelectSchema(model).optional(),
5200
5159
  omit: this.makeOmitSchema(model).optional()
5201
- }));
5160
+ });
5202
5161
  return this.refineForSelectOmitMutuallyExclusive(result);
5203
5162
  }
5204
5163
  makeUpsertSchema(model) {
5205
- const schema = z.object({
5164
+ const schema = z.strictObject({
5206
5165
  where: this.makeWhereSchema(model, true),
5207
5166
  create: this.makeCreateDataSchema(model, false),
5208
5167
  update: this.makeUpdateDataSchema(model),
@@ -5287,7 +5246,7 @@ var InputValidator = class {
5287
5246
  // #endregion
5288
5247
  // #region Delete
5289
5248
  makeDeleteSchema(model) {
5290
- const schema = z.object({
5249
+ const schema = z.strictObject({
5291
5250
  where: this.makeWhereSchema(model, true),
5292
5251
  select: this.makeSelectSchema(model).optional(),
5293
5252
  include: this.makeIncludeSchema(model).optional()
@@ -5315,7 +5274,7 @@ var InputValidator = class {
5315
5274
  const modelDef = requireModel(this.schema, model);
5316
5275
  return z.union([
5317
5276
  z.literal(true),
5318
- z.object({
5277
+ z.strictObject({
5319
5278
  _all: z.literal(true).optional(),
5320
5279
  ...Object.keys(modelDef.fields).reduce((acc, field) => {
5321
5280
  acc[field] = z.literal(true).optional();
@@ -5362,7 +5321,7 @@ var InputValidator = class {
5362
5321
  makeGroupBySchema(model) {
5363
5322
  const modelDef = requireModel(this.schema, model);
5364
5323
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
5365
- let schema = z.object({
5324
+ let schema = z.strictObject({
5366
5325
  where: this.makeWhereSchema(model, false).optional(),
5367
5326
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
5368
5327
  by: this.orArray(z.enum(nonRelationFields), true),
@@ -6408,6 +6367,9 @@ var SchemaDbPusher = class {
6408
6367
  if (this.isAutoIncrement(fieldDef) && this.schema.provider.type === "postgresql") {
6409
6368
  return "serial";
6410
6369
  }
6370
+ if (this.isCustomType(fieldDef.type)) {
6371
+ return "jsonb";
6372
+ }
6411
6373
  const type = fieldDef.type;
6412
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(() => {
6413
6375
  throw new Error(`Unsupported field type: ${type}`);
@@ -6418,6 +6380,9 @@ var SchemaDbPusher = class {
6418
6380
  return result;
6419
6381
  }
6420
6382
  }
6383
+ isCustomType(type) {
6384
+ return this.schema.typeDefs && Object.values(this.schema.typeDefs).some((def) => def.name === type);
6385
+ }
6421
6386
  isAutoIncrement(fieldDef) {
6422
6387
  return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
6423
6388
  }
@@ -6868,7 +6833,7 @@ function createClientProxy(client) {
6868
6833
  }
6869
6834
  __name(createClientProxy, "createClientProxy");
6870
6835
  function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
6871
- const createPromise = /* @__PURE__ */ __name((operation, args, handler, postProcess = false, throwIfNoResult = false) => {
6836
+ const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
6872
6837
  return createZenStackPromise(async (txClient) => {
6873
6838
  let proceed = /* @__PURE__ */ __name(async (_args) => {
6874
6839
  const _handler = txClient ? handler.withClient(txClient) : handler;
@@ -6894,7 +6859,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6894
6859
  proceed = /* @__PURE__ */ __name((_args) => onQuery({
6895
6860
  client,
6896
6861
  model,
6897
- operation,
6862
+ operation: nominalOperation,
6898
6863
  // reflect the latest override if provided
6899
6864
  args: _args,
6900
6865
  // ensure inner overrides are propagated to the previous proceed
@@ -6907,55 +6872,55 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6907
6872
  }, "createPromise");
6908
6873
  return {
6909
6874
  findUnique: /* @__PURE__ */ __name((args) => {
6910
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6875
+ return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6911
6876
  }, "findUnique"),
6912
6877
  findUniqueOrThrow: /* @__PURE__ */ __name((args) => {
6913
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true, true);
6878
+ return createPromise("findUnique", "findUniqueOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6914
6879
  }, "findUniqueOrThrow"),
6915
6880
  findFirst: /* @__PURE__ */ __name((args) => {
6916
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6881
+ return createPromise("findFirst", "findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6917
6882
  }, "findFirst"),
6918
6883
  findFirstOrThrow: /* @__PURE__ */ __name((args) => {
6919
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true, true);
6884
+ return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6920
6885
  }, "findFirstOrThrow"),
6921
6886
  findMany: /* @__PURE__ */ __name((args) => {
6922
- return createPromise("findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6887
+ return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6923
6888
  }, "findMany"),
6924
6889
  create: /* @__PURE__ */ __name((args) => {
6925
- return createPromise("create", args, new CreateOperationHandler(client, model, inputValidator), true);
6890
+ return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
6926
6891
  }, "create"),
6927
6892
  createMany: /* @__PURE__ */ __name((args) => {
6928
- return createPromise("createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6893
+ return createPromise("createMany", "createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6929
6894
  }, "createMany"),
6930
6895
  createManyAndReturn: /* @__PURE__ */ __name((args) => {
6931
- return createPromise("createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6896
+ return createPromise("createManyAndReturn", "createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6932
6897
  }, "createManyAndReturn"),
6933
6898
  update: /* @__PURE__ */ __name((args) => {
6934
- return createPromise("update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6899
+ return createPromise("update", "update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6935
6900
  }, "update"),
6936
6901
  updateMany: /* @__PURE__ */ __name((args) => {
6937
- return createPromise("updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6902
+ return createPromise("updateMany", "updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6938
6903
  }, "updateMany"),
6939
6904
  updateManyAndReturn: /* @__PURE__ */ __name((args) => {
6940
- return createPromise("updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6905
+ return createPromise("updateManyAndReturn", "updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6941
6906
  }, "updateManyAndReturn"),
6942
6907
  upsert: /* @__PURE__ */ __name((args) => {
6943
- return createPromise("upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6908
+ return createPromise("upsert", "upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6944
6909
  }, "upsert"),
6945
6910
  delete: /* @__PURE__ */ __name((args) => {
6946
- return createPromise("delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6911
+ return createPromise("delete", "delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6947
6912
  }, "delete"),
6948
6913
  deleteMany: /* @__PURE__ */ __name((args) => {
6949
- return createPromise("deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6914
+ return createPromise("deleteMany", "deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6950
6915
  }, "deleteMany"),
6951
6916
  count: /* @__PURE__ */ __name((args) => {
6952
- return createPromise("count", args, new CountOperationHandler(client, model, inputValidator), false);
6917
+ return createPromise("count", "count", args, new CountOperationHandler(client, model, inputValidator), false);
6953
6918
  }, "count"),
6954
6919
  aggregate: /* @__PURE__ */ __name((args) => {
6955
- return createPromise("aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6920
+ return createPromise("aggregate", "aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6956
6921
  }, "aggregate"),
6957
6922
  groupBy: /* @__PURE__ */ __name((args) => {
6958
- return createPromise("groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6923
+ return createPromise("groupBy", "groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6959
6924
  }, "groupBy")
6960
6925
  };
6961
6926
  }