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

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-C9SubPBD.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-C9SubPBD.cjs';
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';
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-C9SubPBD.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-C9SubPBD.js';
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';
3
3
  import 'decimal.js';
4
4
  import '@zenstackhq/sdk/schema';
5
5
  import 'kysely';
package/dist/index.js CHANGED
@@ -270,11 +270,14 @@ function getIdValues(schema, model, data) {
270
270
  }), {});
271
271
  }
272
272
  __name(getIdValues, "getIdValues");
273
- function buildFieldRef(schema, model, field, options, eb, modelAlias) {
273
+ function buildFieldRef(schema, model, field, options, eb, modelAlias, inlineComputedField = true) {
274
274
  const fieldDef = requireField(schema, model, field);
275
275
  if (!fieldDef.computed) {
276
276
  return eb.ref(modelAlias ? `${modelAlias}.${field}` : field);
277
277
  } else {
278
+ if (!inlineComputedField) {
279
+ return eb.ref(modelAlias ? `${modelAlias}.${field}` : field);
280
+ }
278
281
  let computer;
279
282
  if ("computedFields" in options) {
280
283
  const computedFields = options.computedFields;
@@ -458,7 +461,6 @@ import { sql as sql2 } from "kysely";
458
461
  import { match as match3 } from "ts-pattern";
459
462
 
460
463
  // src/client/constants.ts
461
- var CONTEXT_COMMENT_PREFIX = "-- $$context:";
462
464
  var NUMERIC_FIELD_TYPES = [
463
465
  "Int",
464
466
  "Float",
@@ -1045,8 +1047,8 @@ var BaseCrudDialect = class {
1045
1047
  not(eb, ...args) {
1046
1048
  return eb.not(this.and(eb, ...args));
1047
1049
  }
1048
- fieldRef(model, field, eb, modelAlias) {
1049
- return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias);
1050
+ fieldRef(model, field, eb, modelAlias, inlineComputedField = true) {
1051
+ return buildFieldRef(this.schema, model, field, this.options, eb, modelAlias, inlineComputedField);
1050
1052
  }
1051
1053
  };
1052
1054
 
@@ -1141,7 +1143,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1141
1143
  if (payload === true || !payload.select) {
1142
1144
  objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
1143
1145
  sql2.lit(field),
1144
- this.fieldRef(relationModel, field, eb)
1146
+ this.fieldRef(relationModel, field, eb, void 0, false)
1145
1147
  ]).flatMap((v) => v));
1146
1148
  } else if (payload.select) {
1147
1149
  objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
@@ -1153,7 +1155,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1153
1155
  ];
1154
1156
  } else {
1155
1157
  const fieldDef = requireField(this.schema, relationModel, field);
1156
- const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : this.fieldRef(relationModel, field, eb);
1158
+ const fieldValue = fieldDef.relation ? eb.ref(`${parentAlias}$${relationField}$${field}.$j`) : this.fieldRef(relationModel, field, eb, void 0, false);
1157
1159
  return [
1158
1160
  sql2.lit(field),
1159
1161
  fieldValue
@@ -1304,7 +1306,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
1304
1306
  if (payload === true || !payload.select) {
1305
1307
  objArgs.push(...Object.entries(relationModelDef.fields).filter(([, value]) => !value.relation).filter(([name]) => !(typeof payload === "object" && payload.omit?.[name] === true)).map(([field]) => [
1306
1308
  sql3.lit(field),
1307
- this.fieldRef(relationModel, field, eb)
1309
+ this.fieldRef(relationModel, field, eb, void 0, false)
1308
1310
  ]).flatMap((v) => v));
1309
1311
  } else if (payload.select) {
1310
1312
  objArgs.push(...Object.entries(payload.select).filter(([, value]) => value).map(([field, value]) => {
@@ -1325,7 +1327,7 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
1325
1327
  } else {
1326
1328
  return [
1327
1329
  sql3.lit(field),
1328
- this.fieldRef(relationModel, field, eb)
1330
+ this.fieldRef(relationModel, field, eb, void 0, false)
1329
1331
  ];
1330
1332
  }
1331
1333
  }
@@ -3425,8 +3427,8 @@ ${compiled.parameters.map((p) => inspect(p)).join("\n")}`;
3425
3427
  isNumericField(fieldDef) {
3426
3428
  return NUMERIC_FIELD_TYPES.includes(fieldDef.type) && !fieldDef.array;
3427
3429
  }
3428
- makeContextComment(context) {
3429
- return sql4.raw(`${CONTEXT_COMMENT_PREFIX}${JSON.stringify(context)}`);
3430
+ makeContextComment(_context) {
3431
+ return sql4``;
3430
3432
  }
3431
3433
  async updateMany(kysely, model, where, data, limit, returnData, filterModel) {
3432
3434
  if (typeof data !== "object") {
@@ -4469,8 +4471,7 @@ var InputValidator = class {
4469
4471
  }
4470
4472
  validateFindArgs(model, unique, args) {
4471
4473
  return this.validate(model, "find", {
4472
- unique,
4473
- collection: true
4474
+ unique
4474
4475
  }, (model2, options) => this.makeFindSchema(model2, options), args);
4475
4476
  }
4476
4477
  validateCreateArgs(model, args) {
@@ -4538,12 +4539,12 @@ var InputValidator = class {
4538
4539
  fields["select"] = this.makeSelectSchema(model).optional();
4539
4540
  fields["include"] = this.makeIncludeSchema(model).optional();
4540
4541
  fields["omit"] = this.makeOmitSchema(model).optional();
4541
- fields["distinct"] = this.makeDistinctSchema(model).optional();
4542
- fields["cursor"] = this.makeCursorSchema(model).optional();
4543
- if (options.collection) {
4542
+ if (!options.unique) {
4544
4543
  fields["skip"] = this.makeSkipSchema().optional();
4545
4544
  fields["take"] = this.makeTakeSchema().optional();
4546
4545
  fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
4546
+ fields["cursor"] = this.makeCursorSchema(model).optional();
4547
+ fields["distinct"] = this.makeDistinctSchema(model).optional();
4547
4548
  }
4548
4549
  let result = z.strictObject(fields);
4549
4550
  result = this.refineForSelectIncludeMutuallyExclusive(result);
@@ -4849,13 +4850,7 @@ var InputValidator = class {
4849
4850
  for (const field of Object.keys(modelDef.fields)) {
4850
4851
  const fieldDef = requireField(this.schema, model, field);
4851
4852
  if (fieldDef.relation) {
4852
- fields[field] = z.union([
4853
- z.literal(true),
4854
- z.strictObject({
4855
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4856
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
4857
- })
4858
- ]).optional();
4853
+ fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
4859
4854
  } else {
4860
4855
  fields[field] = z.boolean().optional();
4861
4856
  }
@@ -4879,6 +4874,28 @@ var InputValidator = class {
4879
4874
  }
4880
4875
  return z.strictObject(fields);
4881
4876
  }
4877
+ makeRelationSelectIncludeSchema(fieldDef) {
4878
+ return z.union([
4879
+ 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
+ })
4897
+ ]);
4898
+ }
4882
4899
  makeOmitSchema(model) {
4883
4900
  const modelDef = requireModel(this.schema, model);
4884
4901
  const fields = {};
@@ -4896,19 +4913,7 @@ var InputValidator = class {
4896
4913
  for (const field of Object.keys(modelDef.fields)) {
4897
4914
  const fieldDef = requireField(this.schema, model, field);
4898
4915
  if (fieldDef.relation) {
4899
- fields[field] = z.union([
4900
- z.literal(true),
4901
- z.strictObject({
4902
- select: z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
4903
- include: z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
4904
- omit: z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
4905
- where: z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
4906
- orderBy: z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
4907
- skip: this.makeSkipSchema().optional(),
4908
- take: this.makeTakeSchema().optional(),
4909
- distinct: this.makeDistinctSchema(fieldDef.type).optional()
4910
- })
4911
- ]).optional();
4916
+ fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
4912
4917
  }
4913
4918
  }
4914
4919
  return z.strictObject(fields);