@zenstackhq/runtime 3.0.0-alpha.26 → 3.0.0-alpha.28

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,11 +1,11 @@
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-cndmlzV3.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-cndmlzV3.cjs';
3
3
  import 'decimal.js';
4
4
  import '@zenstackhq/sdk/schema';
5
5
  import 'kysely';
6
6
 
7
7
  /**
8
- * ZenStack client.
8
+ * ZenStack ORM client.
9
9
  */
10
10
  declare const ZenStackClient: ClientConstructor;
11
11
 
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
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-cndmlzV3.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-cndmlzV3.js';
3
3
  import 'decimal.js';
4
4
  import '@zenstackhq/sdk/schema';
5
5
  import 'kysely';
6
6
 
7
7
  /**
8
- * ZenStack client.
8
+ * ZenStack ORM client.
9
9
  */
10
10
  declare const ZenStackClient: ClientConstructor;
11
11
 
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);
@@ -430,7 +420,6 @@ import { createId } from "@paralleldrive/cuid2";
430
420
  import { invariant as invariant7, isPlainObject as isPlainObject3 } from "@zenstackhq/common-helpers";
431
421
  import { expressionBuilder as expressionBuilder3, sql as sql4 } from "kysely";
432
422
  import { nanoid } from "nanoid";
433
- import { inspect } from "util";
434
423
  import { match as match9 } from "ts-pattern";
435
424
  import { ulid } from "ulid";
436
425
  import * as uuid from "uuid";
@@ -525,6 +514,33 @@ var BaseCrudDialect = class {
525
514
  }
526
515
  return result;
527
516
  }
517
+ buildFilterSortTake(model, args, query) {
518
+ let result = query;
519
+ if (args.where) {
520
+ result = result.where((eb) => this.buildFilter(eb, model, model, args?.where));
521
+ }
522
+ let negateOrderBy = false;
523
+ const skip = args.skip;
524
+ let take = args.take;
525
+ if (take !== void 0 && take < 0) {
526
+ negateOrderBy = true;
527
+ take = -take;
528
+ }
529
+ result = this.buildSkipTake(result, skip, take);
530
+ result = this.buildOrderBy(result, model, model, args.orderBy, skip !== void 0 || take !== void 0, negateOrderBy);
531
+ if ("distinct" in args && args.distinct) {
532
+ const distinct = ensureArray(args.distinct);
533
+ if (this.supportsDistinctOn) {
534
+ result = result.distinctOn(distinct.map((f) => sql.ref(`${model}.${f}`)));
535
+ } else {
536
+ throw new QueryError(`"distinct" is not supported by "${this.schema.provider.type}" provider`);
537
+ }
538
+ }
539
+ if (args.cursor) {
540
+ result = this.buildCursorFilter(model, result, args.cursor, args.orderBy, negateOrderBy);
541
+ }
542
+ return result;
543
+ }
528
544
  buildFilter(eb, model, modelAlias, where) {
529
545
  if (where === true || where === void 0) {
530
546
  return this.true(eb);
@@ -562,6 +578,26 @@ var BaseCrudDialect = class {
562
578
  }
563
579
  return result;
564
580
  }
581
+ buildCursorFilter(model, query, cursor, orderBy, negateOrderBy) {
582
+ const _orderBy = orderBy ?? makeDefaultOrderBy(this.schema, model);
583
+ const orderByItems = ensureArray(_orderBy).flatMap((obj) => Object.entries(obj));
584
+ const eb = expressionBuilder();
585
+ const cursorFilter = this.buildFilter(eb, model, model, cursor);
586
+ let result = query;
587
+ const filters = [];
588
+ for (let i = orderByItems.length - 1; i >= 0; i--) {
589
+ const andFilters = [];
590
+ for (let j = 0; j <= i; j++) {
591
+ const [field, order] = orderByItems[j];
592
+ const _order = negateOrderBy ? order === "asc" ? "desc" : "asc" : order;
593
+ const op = j === i ? _order === "asc" ? ">=" : "<=" : "=";
594
+ andFilters.push(eb(eb.ref(`${model}.${field}`), op, eb.selectFrom(model).select(`${model}.${field}`).where(cursorFilter)));
595
+ }
596
+ filters.push(eb.and(andFilters));
597
+ }
598
+ result = result.where((eb2) => eb2.or(filters));
599
+ return result;
600
+ }
565
601
  isLogicalCombinator(key) {
566
602
  return LOGICAL_COMBINATORS.includes(key);
567
603
  }
@@ -1088,18 +1124,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1088
1124
  let subQuery = this.buildSelectModel(eb, relationModel);
1089
1125
  subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
1090
1126
  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);
1127
+ subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
1103
1128
  }
1104
1129
  const m2m = getManyToManyRelation(this.schema, model, relationField);
1105
1130
  if (m2m) {
@@ -1262,18 +1287,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
1262
1287
  let subQuery = this.buildSelectModel(eb, relationModel);
1263
1288
  subQuery = this.buildSelectAllFields(relationModel, subQuery, typeof payload === "object" ? payload?.omit : void 0);
1264
1289
  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);
1290
+ subQuery = this.buildFilterSortTake(relationModel, payload, subQuery);
1277
1291
  }
1278
1292
  const m2m = getManyToManyRelation(this.schema, model, relationField);
1279
1293
  if (m2m) {
@@ -2715,27 +2729,8 @@ var BaseOperationHandler = class {
2715
2729
  }
2716
2730
  async read(kysely, model, args) {
2717
2731
  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
- }
2732
+ if (args) {
2733
+ query = this.dialect.buildFilterSortTake(model, args, query);
2739
2734
  }
2740
2735
  if (args && "select" in args && args.select) {
2741
2736
  query = this.buildFieldSelection(model, query, args.select, model);
@@ -2745,9 +2740,6 @@ var BaseOperationHandler = class {
2745
2740
  if (args && "include" in args && args.include) {
2746
2741
  query = this.buildFieldSelection(model, query, args.include, model);
2747
2742
  }
2748
- if (args?.cursor) {
2749
- query = this.buildCursorFilter(model, query, args.cursor, args.orderBy, negateOrderBy);
2750
- }
2751
2743
  query = query.modifyEnd(this.makeContextComment({
2752
2744
  model,
2753
2745
  operation: "read"
@@ -2761,28 +2753,9 @@ var BaseOperationHandler = class {
2761
2753
  const r = await kysely.getExecutor().executeQuery(compiled, queryId);
2762
2754
  result = r.rows;
2763
2755
  } catch (err) {
2764
- let message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
2765
- if (this.options.debug) {
2766
- message += `, parameters:
2767
- ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
2768
- }
2756
+ const message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
2769
2757
  throw new QueryError(message, err);
2770
2758
  }
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
2759
  return result;
2787
2760
  }
2788
2761
  async readUnique(kysely, model, args) {
@@ -2821,28 +2794,6 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
2821
2794
  buildCountSelection(query, model, parentAlias, payload) {
2822
2795
  return query.select((eb) => this.dialect.buildCountJson(model, eb, parentAlias, payload).as("_count"));
2823
2796
  }
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
2797
  async create(kysely, model, data, fromRelation, creatingForDelegate = false) {
2847
2798
  const modelDef = this.requireModel(model);
2848
2799
  if (modelDef.isDelegate && !creatingForDelegate) {
@@ -4875,25 +4826,28 @@ var InputValidator = class {
4875
4826
  return z.strictObject(fields);
4876
4827
  }
4877
4828
  makeRelationSelectIncludeSchema(fieldDef) {
4829
+ let objSchema = z.strictObject({
4830
+ ...fieldDef.array || fieldDef.optional ? {
4831
+ // to-many relations and optional to-one relations are filterable
4832
+ where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
4833
+ } : {},
4834
+ select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4835
+ include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4836
+ omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
4837
+ ...fieldDef.array ? {
4838
+ // to-many relations can be ordered, skipped, taken, and cursor-located
4839
+ orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
4840
+ skip: this.makeSkipSchema().optional(),
4841
+ take: this.makeTakeSchema().optional(),
4842
+ cursor: this.makeCursorSchema(fieldDef.type).optional(),
4843
+ distinct: this.makeDistinctSchema(fieldDef.type).optional()
4844
+ } : {}
4845
+ });
4846
+ objSchema = this.refineForSelectIncludeMutuallyExclusive(objSchema);
4847
+ objSchema = this.refineForSelectOmitMutuallyExclusive(objSchema);
4878
4848
  return z.union([
4879
4849
  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
- })
4850
+ objSchema
4897
4851
  ]);
4898
4852
  }
4899
4853
  makeOmitSchema(model) {
@@ -4982,7 +4936,7 @@ var InputValidator = class {
4982
4936
  // #region Create
4983
4937
  makeCreateSchema(model) {
4984
4938
  const dataSchema = this.makeCreateDataSchema(model, false);
4985
- const schema = z.object({
4939
+ const schema = z.strictObject({
4986
4940
  data: dataSchema,
4987
4941
  select: this.makeSelectSchema(model).optional(),
4988
4942
  include: this.makeIncludeSchema(model).optional(),
@@ -4995,10 +4949,10 @@ var InputValidator = class {
4995
4949
  }
4996
4950
  makeCreateManyAndReturnSchema(model) {
4997
4951
  const base = this.makeCreateManyDataSchema(model, []);
4998
- const result = base.merge(z.strictObject({
4952
+ const result = base.extend({
4999
4953
  select: this.makeSelectSchema(model).optional(),
5000
4954
  omit: this.makeOmitSchema(model).optional()
5001
- }));
4955
+ });
5002
4956
  return this.refineForSelectOmitMutuallyExclusive(result).optional();
5003
4957
  }
5004
4958
  makeCreateDataSchema(model, canBeArray, withoutFields = [], withoutRelationFields = false) {
@@ -5163,13 +5117,13 @@ var InputValidator = class {
5163
5117
  makeConnectOrCreateDataSchema(model, canBeArray, withoutFields) {
5164
5118
  const whereSchema = this.makeWhereSchema(model, true);
5165
5119
  const createSchema = this.makeCreateDataSchema(model, false, withoutFields);
5166
- return this.orArray(z.object({
5120
+ return this.orArray(z.strictObject({
5167
5121
  where: whereSchema,
5168
5122
  create: createSchema
5169
5123
  }), canBeArray);
5170
5124
  }
5171
5125
  makeCreateManyDataSchema(model, withoutFields) {
5172
- return z.object({
5126
+ return z.strictObject({
5173
5127
  data: this.makeCreateDataSchema(model, true, withoutFields, true),
5174
5128
  skipDuplicates: z.boolean().optional()
5175
5129
  });
@@ -5177,7 +5131,7 @@ var InputValidator = class {
5177
5131
  // #endregion
5178
5132
  // #region Update
5179
5133
  makeUpdateSchema(model) {
5180
- const schema = z.object({
5134
+ const schema = z.strictObject({
5181
5135
  where: this.makeWhereSchema(model, true),
5182
5136
  data: this.makeUpdateDataSchema(model),
5183
5137
  select: this.makeSelectSchema(model).optional(),
@@ -5187,7 +5141,7 @@ var InputValidator = class {
5187
5141
  return this.refineForSelectIncludeMutuallyExclusive(schema);
5188
5142
  }
5189
5143
  makeUpdateManySchema(model) {
5190
- return z.object({
5144
+ return z.strictObject({
5191
5145
  where: this.makeWhereSchema(model, false).optional(),
5192
5146
  data: this.makeUpdateDataSchema(model, [], true),
5193
5147
  limit: z.int().nonnegative().optional()
@@ -5195,14 +5149,14 @@ var InputValidator = class {
5195
5149
  }
5196
5150
  makeUpdateManyAndReturnSchema(model) {
5197
5151
  const base = this.makeUpdateManySchema(model);
5198
- const result = base.merge(z.strictObject({
5152
+ const result = base.extend({
5199
5153
  select: this.makeSelectSchema(model).optional(),
5200
5154
  omit: this.makeOmitSchema(model).optional()
5201
- }));
5155
+ });
5202
5156
  return this.refineForSelectOmitMutuallyExclusive(result);
5203
5157
  }
5204
5158
  makeUpsertSchema(model) {
5205
- const schema = z.object({
5159
+ const schema = z.strictObject({
5206
5160
  where: this.makeWhereSchema(model, true),
5207
5161
  create: this.makeCreateDataSchema(model, false),
5208
5162
  update: this.makeUpdateDataSchema(model),
@@ -5287,7 +5241,7 @@ var InputValidator = class {
5287
5241
  // #endregion
5288
5242
  // #region Delete
5289
5243
  makeDeleteSchema(model) {
5290
- const schema = z.object({
5244
+ const schema = z.strictObject({
5291
5245
  where: this.makeWhereSchema(model, true),
5292
5246
  select: this.makeSelectSchema(model).optional(),
5293
5247
  include: this.makeIncludeSchema(model).optional()
@@ -5315,7 +5269,7 @@ var InputValidator = class {
5315
5269
  const modelDef = requireModel(this.schema, model);
5316
5270
  return z.union([
5317
5271
  z.literal(true),
5318
- z.object({
5272
+ z.strictObject({
5319
5273
  _all: z.literal(true).optional(),
5320
5274
  ...Object.keys(modelDef.fields).reduce((acc, field) => {
5321
5275
  acc[field] = z.literal(true).optional();
@@ -5362,7 +5316,7 @@ var InputValidator = class {
5362
5316
  makeGroupBySchema(model) {
5363
5317
  const modelDef = requireModel(this.schema, model);
5364
5318
  const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation);
5365
- let schema = z.object({
5319
+ let schema = z.strictObject({
5366
5320
  where: this.makeWhereSchema(model, false).optional(),
5367
5321
  orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(),
5368
5322
  by: this.orArray(z.enum(nonRelationFields), true),
@@ -5639,7 +5593,6 @@ __name(performanceNow, "performanceNow");
5639
5593
  // src/client/executor/zenstack-query-executor.ts
5640
5594
  import { AndNode as AndNode2, DefaultQueryExecutor, DeleteQueryNode as DeleteQueryNode2, InsertQueryNode as InsertQueryNode2, ReturningNode as ReturningNode3, SelectionNode as SelectionNode4, UpdateQueryNode as UpdateQueryNode2, WhereNode as WhereNode3 } from "kysely";
5641
5595
  import { nanoid as nanoid2 } from "nanoid";
5642
- import { inspect as inspect2 } from "util";
5643
5596
  import { match as match16 } from "ts-pattern";
5644
5597
 
5645
5598
  // src/client/executor/name-mapper.ts
@@ -5947,11 +5900,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends DefaultQueryExe
5947
5900
  };
5948
5901
  });
5949
5902
  } catch (err) {
5950
- let message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
5951
- if (this.options.debug) {
5952
- message += `, parameters:
5953
- ${compiled.parameters.map((p) => inspect2(p)).join("\n")}`;
5954
- }
5903
+ const message = `Failed to execute query: ${err}, sql: ${compiled.sql}`;
5955
5904
  throw new QueryError(message, err);
5956
5905
  }
5957
5906
  }
@@ -6408,6 +6357,9 @@ var SchemaDbPusher = class {
6408
6357
  if (this.isAutoIncrement(fieldDef) && this.schema.provider.type === "postgresql") {
6409
6358
  return "serial";
6410
6359
  }
6360
+ if (this.isCustomType(fieldDef.type)) {
6361
+ return "jsonb";
6362
+ }
6411
6363
  const type = fieldDef.type;
6412
6364
  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
6365
  throw new Error(`Unsupported field type: ${type}`);
@@ -6418,6 +6370,9 @@ var SchemaDbPusher = class {
6418
6370
  return result;
6419
6371
  }
6420
6372
  }
6373
+ isCustomType(type) {
6374
+ return this.schema.typeDefs && Object.values(this.schema.typeDefs).some((def) => def.name === type);
6375
+ }
6421
6376
  isAutoIncrement(fieldDef) {
6422
6377
  return fieldDef.default && ExpressionUtils.isCall(fieldDef.default) && fieldDef.default.function === "autoincrement";
6423
6378
  }
@@ -6868,7 +6823,7 @@ function createClientProxy(client) {
6868
6823
  }
6869
6824
  __name(createClientProxy, "createClientProxy");
6870
6825
  function createModelCrudHandler(client, model, inputValidator, resultProcessor) {
6871
- const createPromise = /* @__PURE__ */ __name((operation, args, handler, postProcess = false, throwIfNoResult = false) => {
6826
+ const createPromise = /* @__PURE__ */ __name((operation, nominalOperation, args, handler, postProcess = false, throwIfNoResult = false) => {
6872
6827
  return createZenStackPromise(async (txClient) => {
6873
6828
  let proceed = /* @__PURE__ */ __name(async (_args) => {
6874
6829
  const _handler = txClient ? handler.withClient(txClient) : handler;
@@ -6894,7 +6849,7 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6894
6849
  proceed = /* @__PURE__ */ __name((_args) => onQuery({
6895
6850
  client,
6896
6851
  model,
6897
- operation,
6852
+ operation: nominalOperation,
6898
6853
  // reflect the latest override if provided
6899
6854
  args: _args,
6900
6855
  // ensure inner overrides are propagated to the previous proceed
@@ -6907,55 +6862,55 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
6907
6862
  }, "createPromise");
6908
6863
  return {
6909
6864
  findUnique: /* @__PURE__ */ __name((args) => {
6910
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6865
+ return createPromise("findUnique", "findUnique", args, new FindOperationHandler(client, model, inputValidator), true);
6911
6866
  }, "findUnique"),
6912
6867
  findUniqueOrThrow: /* @__PURE__ */ __name((args) => {
6913
- return createPromise("findUnique", args, new FindOperationHandler(client, model, inputValidator), true, true);
6868
+ return createPromise("findUnique", "findUniqueOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6914
6869
  }, "findUniqueOrThrow"),
6915
6870
  findFirst: /* @__PURE__ */ __name((args) => {
6916
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6871
+ return createPromise("findFirst", "findFirst", args, new FindOperationHandler(client, model, inputValidator), true);
6917
6872
  }, "findFirst"),
6918
6873
  findFirstOrThrow: /* @__PURE__ */ __name((args) => {
6919
- return createPromise("findFirst", args, new FindOperationHandler(client, model, inputValidator), true, true);
6874
+ return createPromise("findFirst", "findFirstOrThrow", args, new FindOperationHandler(client, model, inputValidator), true, true);
6920
6875
  }, "findFirstOrThrow"),
6921
6876
  findMany: /* @__PURE__ */ __name((args) => {
6922
- return createPromise("findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6877
+ return createPromise("findMany", "findMany", args, new FindOperationHandler(client, model, inputValidator), true);
6923
6878
  }, "findMany"),
6924
6879
  create: /* @__PURE__ */ __name((args) => {
6925
- return createPromise("create", args, new CreateOperationHandler(client, model, inputValidator), true);
6880
+ return createPromise("create", "create", args, new CreateOperationHandler(client, model, inputValidator), true);
6926
6881
  }, "create"),
6927
6882
  createMany: /* @__PURE__ */ __name((args) => {
6928
- return createPromise("createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6883
+ return createPromise("createMany", "createMany", args, new CreateOperationHandler(client, model, inputValidator), false);
6929
6884
  }, "createMany"),
6930
6885
  createManyAndReturn: /* @__PURE__ */ __name((args) => {
6931
- return createPromise("createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6886
+ return createPromise("createManyAndReturn", "createManyAndReturn", args, new CreateOperationHandler(client, model, inputValidator), true);
6932
6887
  }, "createManyAndReturn"),
6933
6888
  update: /* @__PURE__ */ __name((args) => {
6934
- return createPromise("update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6889
+ return createPromise("update", "update", args, new UpdateOperationHandler(client, model, inputValidator), true);
6935
6890
  }, "update"),
6936
6891
  updateMany: /* @__PURE__ */ __name((args) => {
6937
- return createPromise("updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6892
+ return createPromise("updateMany", "updateMany", args, new UpdateOperationHandler(client, model, inputValidator), false);
6938
6893
  }, "updateMany"),
6939
6894
  updateManyAndReturn: /* @__PURE__ */ __name((args) => {
6940
- return createPromise("updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6895
+ return createPromise("updateManyAndReturn", "updateManyAndReturn", args, new UpdateOperationHandler(client, model, inputValidator), true);
6941
6896
  }, "updateManyAndReturn"),
6942
6897
  upsert: /* @__PURE__ */ __name((args) => {
6943
- return createPromise("upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6898
+ return createPromise("upsert", "upsert", args, new UpdateOperationHandler(client, model, inputValidator), true);
6944
6899
  }, "upsert"),
6945
6900
  delete: /* @__PURE__ */ __name((args) => {
6946
- return createPromise("delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6901
+ return createPromise("delete", "delete", args, new DeleteOperationHandler(client, model, inputValidator), true);
6947
6902
  }, "delete"),
6948
6903
  deleteMany: /* @__PURE__ */ __name((args) => {
6949
- return createPromise("deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6904
+ return createPromise("deleteMany", "deleteMany", args, new DeleteOperationHandler(client, model, inputValidator), false);
6950
6905
  }, "deleteMany"),
6951
6906
  count: /* @__PURE__ */ __name((args) => {
6952
- return createPromise("count", args, new CountOperationHandler(client, model, inputValidator), false);
6907
+ return createPromise("count", "count", args, new CountOperationHandler(client, model, inputValidator), false);
6953
6908
  }, "count"),
6954
6909
  aggregate: /* @__PURE__ */ __name((args) => {
6955
- return createPromise("aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6910
+ return createPromise("aggregate", "aggregate", args, new AggregateOperationHandler(client, model, inputValidator), false);
6956
6911
  }, "aggregate"),
6957
6912
  groupBy: /* @__PURE__ */ __name((args) => {
6958
- return createPromise("groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6913
+ return createPromise("groupBy", "groupBy", args, new GroupByOperationHandler(client, model, inputValidator), true);
6959
6914
  }, "groupBy")
6960
6915
  };
6961
6916
  }