@zenstackhq/runtime 3.0.0-beta.12 → 3.0.0-beta.13

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
@@ -1038,7 +1038,8 @@ declare class ZenStackError extends Error {
1038
1038
  * Error thrown when input validation fails.
1039
1039
  */
1040
1040
  declare class InputValidationError extends ZenStackError {
1041
- constructor(message: string, cause?: unknown);
1041
+ readonly model: string;
1042
+ constructor(model: string, message: string, cause?: unknown);
1042
1043
  }
1043
1044
  /**
1044
1045
  * Error thrown when a query fails.
@@ -1055,6 +1056,7 @@ declare class InternalError extends ZenStackError {
1055
1056
  * Error thrown when an entity is not found.
1056
1057
  */
1057
1058
  declare class NotFoundError extends ZenStackError {
1059
+ readonly model: string;
1058
1060
  constructor(model: string, details?: string);
1059
1061
  }
1060
1062
  /**
@@ -1129,7 +1131,6 @@ declare function getManyToManyRelation(schema: SchemaDef, model: string, field:
1129
1131
  */
1130
1132
  declare function flattenCompoundUniqueFilters(schema: SchemaDef, model: string, filter: unknown): any;
1131
1133
  declare function ensureArray<T>(value: T | T[]): T[];
1132
- declare function safeJSONStringify(value: unknown): string;
1133
1134
  declare function extractIdFields(entity: any, schema: SchemaDef, model: string): {
1134
1135
  [k: string]: unknown;
1135
1136
  };
@@ -1184,10 +1185,9 @@ declare const queryUtils_makeDefaultOrderBy: typeof makeDefaultOrderBy;
1184
1185
  declare const queryUtils_requireField: typeof requireField;
1185
1186
  declare const queryUtils_requireIdFields: typeof requireIdFields;
1186
1187
  declare const queryUtils_requireModel: typeof requireModel;
1187
- declare const queryUtils_safeJSONStringify: typeof safeJSONStringify;
1188
1188
  declare const queryUtils_stripAlias: typeof stripAlias;
1189
1189
  declare namespace queryUtils {
1190
- export { queryUtils_aggregate as aggregate, queryUtils_buildJoinPairs as buildJoinPairs, queryUtils_ensureArray as ensureArray, queryUtils_extractFieldName as extractFieldName, queryUtils_extractIdFields as extractIdFields, queryUtils_extractModelName as extractModelName, queryUtils_fieldHasDefaultValue as fieldHasDefaultValue, queryUtils_flattenCompoundUniqueFilters as flattenCompoundUniqueFilters, queryUtils_getDelegateDescendantModels as getDelegateDescendantModels, queryUtils_getDiscriminatorField as getDiscriminatorField, queryUtils_getEnum as getEnum, queryUtils_getField as getField, queryUtils_getIdFields as getIdFields, queryUtils_getIdValues as getIdValues, queryUtils_getManyToManyRelation as getManyToManyRelation, queryUtils_getModel as getModel, queryUtils_getRelationForeignKeyFieldPairs as getRelationForeignKeyFieldPairs, queryUtils_getTypeDef as getTypeDef, queryUtils_getUniqueFields as getUniqueFields, queryUtils_hasModel as hasModel, queryUtils_isEnum as isEnum, queryUtils_isForeignKeyField as isForeignKeyField, queryUtils_isInheritedField as isInheritedField, queryUtils_isRelationField as isRelationField, queryUtils_isScalarField as isScalarField, queryUtils_makeDefaultOrderBy as makeDefaultOrderBy, queryUtils_requireField as requireField, queryUtils_requireIdFields as requireIdFields, queryUtils_requireModel as requireModel, queryUtils_safeJSONStringify as safeJSONStringify, queryUtils_stripAlias as stripAlias };
1190
+ export { queryUtils_aggregate as aggregate, queryUtils_buildJoinPairs as buildJoinPairs, queryUtils_ensureArray as ensureArray, queryUtils_extractFieldName as extractFieldName, queryUtils_extractIdFields as extractIdFields, queryUtils_extractModelName as extractModelName, queryUtils_fieldHasDefaultValue as fieldHasDefaultValue, queryUtils_flattenCompoundUniqueFilters as flattenCompoundUniqueFilters, queryUtils_getDelegateDescendantModels as getDelegateDescendantModels, queryUtils_getDiscriminatorField as getDiscriminatorField, queryUtils_getEnum as getEnum, queryUtils_getField as getField, queryUtils_getIdFields as getIdFields, queryUtils_getIdValues as getIdValues, queryUtils_getManyToManyRelation as getManyToManyRelation, queryUtils_getModel as getModel, queryUtils_getRelationForeignKeyFieldPairs as getRelationForeignKeyFieldPairs, queryUtils_getTypeDef as getTypeDef, queryUtils_getUniqueFields as getUniqueFields, queryUtils_hasModel as hasModel, queryUtils_isEnum as isEnum, queryUtils_isForeignKeyField as isForeignKeyField, queryUtils_isInheritedField as isInheritedField, queryUtils_isRelationField as isRelationField, queryUtils_isScalarField as isScalarField, queryUtils_makeDefaultOrderBy as makeDefaultOrderBy, queryUtils_requireField as requireField, queryUtils_requireIdFields as requireIdFields, queryUtils_requireModel as requireModel, queryUtils_stripAlias as stripAlias };
1191
1191
  }
1192
1192
 
1193
1193
  declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
package/dist/index.d.ts CHANGED
@@ -1038,7 +1038,8 @@ declare class ZenStackError extends Error {
1038
1038
  * Error thrown when input validation fails.
1039
1039
  */
1040
1040
  declare class InputValidationError extends ZenStackError {
1041
- constructor(message: string, cause?: unknown);
1041
+ readonly model: string;
1042
+ constructor(model: string, message: string, cause?: unknown);
1042
1043
  }
1043
1044
  /**
1044
1045
  * Error thrown when a query fails.
@@ -1055,6 +1056,7 @@ declare class InternalError extends ZenStackError {
1055
1056
  * Error thrown when an entity is not found.
1056
1057
  */
1057
1058
  declare class NotFoundError extends ZenStackError {
1059
+ readonly model: string;
1058
1060
  constructor(model: string, details?: string);
1059
1061
  }
1060
1062
  /**
@@ -1129,7 +1131,6 @@ declare function getManyToManyRelation(schema: SchemaDef, model: string, field:
1129
1131
  */
1130
1132
  declare function flattenCompoundUniqueFilters(schema: SchemaDef, model: string, filter: unknown): any;
1131
1133
  declare function ensureArray<T>(value: T | T[]): T[];
1132
- declare function safeJSONStringify(value: unknown): string;
1133
1134
  declare function extractIdFields(entity: any, schema: SchemaDef, model: string): {
1134
1135
  [k: string]: unknown;
1135
1136
  };
@@ -1184,10 +1185,9 @@ declare const queryUtils_makeDefaultOrderBy: typeof makeDefaultOrderBy;
1184
1185
  declare const queryUtils_requireField: typeof requireField;
1185
1186
  declare const queryUtils_requireIdFields: typeof requireIdFields;
1186
1187
  declare const queryUtils_requireModel: typeof requireModel;
1187
- declare const queryUtils_safeJSONStringify: typeof safeJSONStringify;
1188
1188
  declare const queryUtils_stripAlias: typeof stripAlias;
1189
1189
  declare namespace queryUtils {
1190
- export { queryUtils_aggregate as aggregate, queryUtils_buildJoinPairs as buildJoinPairs, queryUtils_ensureArray as ensureArray, queryUtils_extractFieldName as extractFieldName, queryUtils_extractIdFields as extractIdFields, queryUtils_extractModelName as extractModelName, queryUtils_fieldHasDefaultValue as fieldHasDefaultValue, queryUtils_flattenCompoundUniqueFilters as flattenCompoundUniqueFilters, queryUtils_getDelegateDescendantModels as getDelegateDescendantModels, queryUtils_getDiscriminatorField as getDiscriminatorField, queryUtils_getEnum as getEnum, queryUtils_getField as getField, queryUtils_getIdFields as getIdFields, queryUtils_getIdValues as getIdValues, queryUtils_getManyToManyRelation as getManyToManyRelation, queryUtils_getModel as getModel, queryUtils_getRelationForeignKeyFieldPairs as getRelationForeignKeyFieldPairs, queryUtils_getTypeDef as getTypeDef, queryUtils_getUniqueFields as getUniqueFields, queryUtils_hasModel as hasModel, queryUtils_isEnum as isEnum, queryUtils_isForeignKeyField as isForeignKeyField, queryUtils_isInheritedField as isInheritedField, queryUtils_isRelationField as isRelationField, queryUtils_isScalarField as isScalarField, queryUtils_makeDefaultOrderBy as makeDefaultOrderBy, queryUtils_requireField as requireField, queryUtils_requireIdFields as requireIdFields, queryUtils_requireModel as requireModel, queryUtils_safeJSONStringify as safeJSONStringify, queryUtils_stripAlias as stripAlias };
1190
+ export { queryUtils_aggregate as aggregate, queryUtils_buildJoinPairs as buildJoinPairs, queryUtils_ensureArray as ensureArray, queryUtils_extractFieldName as extractFieldName, queryUtils_extractIdFields as extractIdFields, queryUtils_extractModelName as extractModelName, queryUtils_fieldHasDefaultValue as fieldHasDefaultValue, queryUtils_flattenCompoundUniqueFilters as flattenCompoundUniqueFilters, queryUtils_getDelegateDescendantModels as getDelegateDescendantModels, queryUtils_getDiscriminatorField as getDiscriminatorField, queryUtils_getEnum as getEnum, queryUtils_getField as getField, queryUtils_getIdFields as getIdFields, queryUtils_getIdValues as getIdValues, queryUtils_getManyToManyRelation as getManyToManyRelation, queryUtils_getModel as getModel, queryUtils_getRelationForeignKeyFieldPairs as getRelationForeignKeyFieldPairs, queryUtils_getTypeDef as getTypeDef, queryUtils_getUniqueFields as getUniqueFields, queryUtils_hasModel as hasModel, queryUtils_isEnum as isEnum, queryUtils_isForeignKeyField as isForeignKeyField, queryUtils_isInheritedField as isInheritedField, queryUtils_isRelationField as isRelationField, queryUtils_isScalarField as isScalarField, queryUtils_makeDefaultOrderBy as makeDefaultOrderBy, queryUtils_requireField as requireField, queryUtils_requireIdFields as requireIdFields, queryUtils_requireModel as requireModel, queryUtils_stripAlias as stripAlias };
1191
1191
  }
1192
1192
 
1193
1193
  declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
package/dist/index.js CHANGED
@@ -44,7 +44,6 @@ __export(query_utils_exports, {
44
44
  requireField: () => requireField,
45
45
  requireIdFields: () => requireIdFields,
46
46
  requireModel: () => requireModel,
47
- safeJSONStringify: () => safeJSONStringify,
48
47
  stripAlias: () => stripAlias
49
48
  });
50
49
  import { invariant } from "@zenstackhq/common-helpers";
@@ -159,10 +158,11 @@ var InputValidationError = class extends ZenStackError {
159
158
  static {
160
159
  __name(this, "InputValidationError");
161
160
  }
162
- constructor(message, cause) {
161
+ model;
162
+ constructor(model, message, cause) {
163
163
  super(message, {
164
164
  cause
165
- });
165
+ }), this.model = model;
166
166
  }
167
167
  };
168
168
  var QueryError = class extends ZenStackError {
@@ -184,8 +184,9 @@ var NotFoundError = class extends ZenStackError {
184
184
  static {
185
185
  __name(this, "NotFoundError");
186
186
  }
187
+ model;
187
188
  constructor(model, details) {
188
- super(`Entity not found for model "${model}"${details ? `: ${details}` : ""}`);
189
+ super(`Entity not found for model "${model}"${details ? `: ${details}` : ""}`), this.model = model;
189
190
  }
190
191
  };
191
192
  var RejectedByPolicyReason = /* @__PURE__ */ function(RejectedByPolicyReason2) {
@@ -499,16 +500,6 @@ function ensureArray(value) {
499
500
  }
500
501
  }
501
502
  __name(ensureArray, "ensureArray");
502
- function safeJSONStringify(value) {
503
- return JSON.stringify(value, (_, v) => {
504
- if (typeof v === "bigint") {
505
- return v.toString();
506
- } else {
507
- return v;
508
- }
509
- });
510
- }
511
- __name(safeJSONStringify, "safeJSONStringify");
512
503
  function extractIdFields(entity, schema, model) {
513
504
  const idFields = requireIdFields(schema, model);
514
505
  return extractFields(entity, idFields);
@@ -1369,7 +1360,7 @@ var PostgresCrudDialect = class extends BaseCrudDialect {
1369
1360
  }
1370
1361
  }
1371
1362
  transformOutputBytes(value) {
1372
- return Buffer.isBuffer(value) ? Uint8Array.from(value) : value;
1363
+ return Buffer.isBuffer(value) ? Uint8Array.from(value) : typeof value === "string" && value.startsWith("\\x") ? Uint8Array.from(Buffer.from(value.slice(2), "hex")) : value;
1373
1364
  }
1374
1365
  buildRelationSelection(query, model, relationField, parentAlias, payload) {
1375
1366
  const relationResultName = `${parentAlias}$${relationField}`;
@@ -4091,7 +4082,7 @@ var InputValidator = class {
4091
4082
  }
4092
4083
  const { error, data } = schema.safeParse(args);
4093
4084
  if (error) {
4094
- throw new InputValidationError(`Invalid ${operation} args for model "${model}": ${formatError(error)}`, error);
4085
+ throw new InputValidationError(model, `Invalid ${operation} args for model "${model}": ${formatError(error)}`, error);
4095
4086
  }
4096
4087
  return data;
4097
4088
  }
@@ -6246,9 +6237,15 @@ var SchemaDbPusher = class {
6246
6237
  table = table.addForeignKeyConstraint(`fk_${model}_${fieldName}`, fieldDef.relation.fields.map((f) => this.getColumnName(modelDef.fields[f])), this.getTableName(relationModelDef), fieldDef.relation.references.map((f) => this.getColumnName(relationModelDef.fields[f])), (cb) => {
6247
6238
  if (fieldDef.relation?.onDelete) {
6248
6239
  cb = cb.onDelete(this.mapCascadeAction(fieldDef.relation.onDelete));
6240
+ } else if (fieldDef.optional) {
6241
+ cb = cb.onDelete("set null");
6242
+ } else {
6243
+ cb = cb.onDelete("restrict");
6249
6244
  }
6250
6245
  if (fieldDef.relation?.onUpdate) {
6251
6246
  cb = cb.onUpdate(this.mapCascadeAction(fieldDef.relation.onUpdate));
6247
+ } else {
6248
+ cb = cb.onUpdate("cascade");
6252
6249
  }
6253
6250
  return cb;
6254
6251
  });