@zenstackhq/runtime 1.8.1 → 2.0.0-alpha.1

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.
Files changed (69) hide show
  1. package/constants.d.ts +5 -1
  2. package/constants.js +6 -2
  3. package/constants.js.map +1 -1
  4. package/cross/index.d.mts +60 -11
  5. package/cross/index.d.ts +60 -11
  6. package/cross/index.js +33 -7
  7. package/cross/index.js.map +1 -1
  8. package/cross/index.mjs +30 -7
  9. package/cross/index.mjs.map +1 -1
  10. package/enhance.d.ts +1 -0
  11. package/enhance.js +10 -0
  12. package/enhancements/create-enhancement.d.ts +78 -0
  13. package/enhancements/create-enhancement.js +86 -0
  14. package/enhancements/create-enhancement.js.map +1 -0
  15. package/enhancements/default-auth.d.ts +7 -0
  16. package/enhancements/default-auth.js +92 -0
  17. package/enhancements/default-auth.js.map +1 -0
  18. package/enhancements/delegate.d.ts +64 -0
  19. package/enhancements/delegate.js +903 -0
  20. package/enhancements/delegate.js.map +1 -0
  21. package/enhancements/index.d.ts +1 -6
  22. package/enhancements/index.js +1 -6
  23. package/enhancements/index.js.map +1 -1
  24. package/enhancements/logger.js.map +1 -0
  25. package/enhancements/omit.d.ts +4 -14
  26. package/enhancements/omit.js +14 -14
  27. package/enhancements/omit.js.map +1 -1
  28. package/enhancements/password.d.ts +4 -14
  29. package/enhancements/password.js +6 -10
  30. package/enhancements/password.js.map +1 -1
  31. package/enhancements/policy/handler.d.ts +19 -17
  32. package/enhancements/policy/handler.js +169 -157
  33. package/enhancements/policy/handler.js.map +1 -1
  34. package/enhancements/policy/index.d.ts +3 -37
  35. package/enhancements/policy/index.js +7 -24
  36. package/enhancements/policy/index.js.map +1 -1
  37. package/enhancements/policy/policy-utils.d.ts +23 -45
  38. package/enhancements/policy/policy-utils.js +34 -147
  39. package/enhancements/policy/policy-utils.js.map +1 -1
  40. package/enhancements/proxy.d.ts +11 -3
  41. package/enhancements/proxy.js +10 -9
  42. package/enhancements/proxy.js.map +1 -1
  43. package/enhancements/query-utils.d.ts +24 -0
  44. package/enhancements/query-utils.js +152 -0
  45. package/enhancements/query-utils.js.map +1 -0
  46. package/enhancements/types.d.ts +3 -3
  47. package/enhancements/utils.d.ts +3 -3
  48. package/enhancements/utils.js +9 -68
  49. package/enhancements/utils.js.map +1 -1
  50. package/index.d.ts +1 -1
  51. package/index.js +1 -1
  52. package/index.js.map +1 -1
  53. package/package.json +2 -2
  54. package/types.d.ts +9 -2
  55. package/version.d.ts +3 -4
  56. package/version.js +29 -46
  57. package/version.js.map +1 -1
  58. package/enhancements/enhance.d.ts +0 -18
  59. package/enhancements/enhance.js +0 -42
  60. package/enhancements/enhance.js.map +0 -1
  61. package/enhancements/policy/logger.js.map +0 -1
  62. package/enhancements/preset.d.ts +0 -15
  63. package/enhancements/preset.js +0 -21
  64. package/enhancements/preset.js.map +0 -1
  65. package/loader.d.ts +0 -22
  66. package/loader.js +0 -99
  67. package/loader.js.map +0 -1
  68. /package/enhancements/{policy/logger.d.ts → logger.d.ts} +0 -0
  69. /package/enhancements/{policy/logger.js → logger.js} +0 -0
package/constants.d.ts CHANGED
@@ -51,7 +51,7 @@ export declare const PRISMA_PROXY_ENHANCER = "$__zenstack_enhancer";
51
51
  /**
52
52
  * Minimum Prisma version supported
53
53
  */
54
- export declare const PRISMA_MINIMUM_VERSION = "4.8.0";
54
+ export declare const PRISMA_MINIMUM_VERSION = "5.0.0";
55
55
  /**
56
56
  * Selector function name for fetching pre-update entity values.
57
57
  */
@@ -80,3 +80,7 @@ export declare const FIELD_LEVEL_OVERRIDE_UPDATE_GUARD_PREFIX = "updateFieldGuar
80
80
  * Flag that indicates if the model has field-level access control
81
81
  */
82
82
  export declare const HAS_FIELD_LEVEL_POLICY_FLAG = "hasFieldLevelPolicy";
83
+ /**
84
+ * Prefix for auxiliary relation field generated for delegated models
85
+ */
86
+ export declare const DELEGATE_AUX_RELATION_PREFIX = "delegate_aux";
package/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HAS_FIELD_LEVEL_POLICY_FLAG = exports.FIELD_LEVEL_OVERRIDE_UPDATE_GUARD_PREFIX = exports.FIELD_LEVEL_UPDATE_GUARD_PREFIX = exports.FIELD_LEVEL_OVERRIDE_READ_GUARD_PREFIX = exports.FIELD_LEVEL_READ_CHECKER_SELECTOR = exports.FIELD_LEVEL_READ_CHECKER_PREFIX = exports.PRE_UPDATE_VALUE_SELECTOR = exports.PRISMA_MINIMUM_VERSION = exports.PRISMA_PROXY_ENHANCER = exports.PrismaErrorCode = exports.CrudFailureReason = exports.DEFAULT_PASSWORD_SALT_LENGTH = exports.DEFAULT_RUNTIME_LOAD_PATH = void 0;
3
+ exports.DELEGATE_AUX_RELATION_PREFIX = exports.HAS_FIELD_LEVEL_POLICY_FLAG = exports.FIELD_LEVEL_OVERRIDE_UPDATE_GUARD_PREFIX = exports.FIELD_LEVEL_UPDATE_GUARD_PREFIX = exports.FIELD_LEVEL_OVERRIDE_READ_GUARD_PREFIX = exports.FIELD_LEVEL_READ_CHECKER_SELECTOR = exports.FIELD_LEVEL_READ_CHECKER_PREFIX = exports.PRE_UPDATE_VALUE_SELECTOR = exports.PRISMA_MINIMUM_VERSION = exports.PRISMA_PROXY_ENHANCER = exports.PrismaErrorCode = exports.CrudFailureReason = exports.DEFAULT_PASSWORD_SALT_LENGTH = exports.DEFAULT_RUNTIME_LOAD_PATH = void 0;
4
4
  /**
5
5
  * Default path for loading CLI-generated code
6
6
  */
@@ -56,7 +56,7 @@ exports.PRISMA_PROXY_ENHANCER = '$__zenstack_enhancer';
56
56
  /**
57
57
  * Minimum Prisma version supported
58
58
  */
59
- exports.PRISMA_MINIMUM_VERSION = '4.8.0';
59
+ exports.PRISMA_MINIMUM_VERSION = '5.0.0';
60
60
  /**
61
61
  * Selector function name for fetching pre-update entity values.
62
62
  */
@@ -85,4 +85,8 @@ exports.FIELD_LEVEL_OVERRIDE_UPDATE_GUARD_PREFIX = 'updateFieldGuardOverride$';
85
85
  * Flag that indicates if the model has field-level access control
86
86
  */
87
87
  exports.HAS_FIELD_LEVEL_POLICY_FLAG = 'hasFieldLevelPolicy';
88
+ /**
89
+ * Prefix for auxiliary relation field generated for delegated models
90
+ */
91
+ exports.DELEGATE_AUX_RELATION_PREFIX = 'delegate_aux';
88
92
  //# sourceMappingURL=constants.js.map
package/constants.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,yBAAyB,GAAG,WAAW,CAAC;AAErD;;GAEG;AACU,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAE/C;;GAEG;AACH,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IACzB;;OAEG;IACH,wEAAmD,CAAA;IAEnD;;OAEG;IACH,gEAA2C,CAAA;IAE3C;;OAEG;IACH,4EAAuD,CAAA;AAC3D,CAAC,EAfW,iBAAiB,iCAAjB,iBAAiB,QAe5B;AAED;;GAEG;AACH,IAAY,eAoBX;AApBD,WAAY,eAAe;IACvB;;OAEG;IACH,qDAAkC,CAAA;IAElC;;OAEG;IACH,+CAA4B,CAAA;IAE5B;;OAEG;IACH,gEAA6C,CAAA;IAE7C;;OAEG;IACH,uDAAoC,CAAA;AACxC,CAAC,EApBW,eAAe,+BAAf,eAAe,QAoB1B;AAED;;GAEG;AACU,QAAA,qBAAqB,GAAG,sBAAsB,CAAC;AAE5D;;GAEG;AACU,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C;;GAEG;AACU,QAAA,yBAAyB,GAAG,gBAAgB,CAAC;AAE1D;;GAEG;AACU,QAAA,+BAA+B,GAAG,iBAAiB,CAAC;AAEjE;;GAEG;AACU,QAAA,iCAAiC,GAAG,iBAAiB,CAAC;AAEnE;;GAEG;AACU,QAAA,sCAAsC,GAAG,yBAAyB,CAAC;AAEhF;;GAEG;AACU,QAAA,+BAA+B,GAAG,mBAAmB,CAAC;AAEnE;;GAEG;AACU,QAAA,wCAAwC,GAAG,2BAA2B,CAAC;AAEpF;;GAEG;AACU,QAAA,2BAA2B,GAAG,qBAAqB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,yBAAyB,GAAG,WAAW,CAAC;AAErD;;GAEG;AACU,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAE/C;;GAEG;AACH,IAAY,iBAeX;AAfD,WAAY,iBAAiB;IACzB;;OAEG;IACH,wEAAmD,CAAA;IAEnD;;OAEG;IACH,gEAA2C,CAAA;IAE3C;;OAEG;IACH,4EAAuD,CAAA;AAC3D,CAAC,EAfW,iBAAiB,iCAAjB,iBAAiB,QAe5B;AAED;;GAEG;AACH,IAAY,eAoBX;AApBD,WAAY,eAAe;IACvB;;OAEG;IACH,qDAAkC,CAAA;IAElC;;OAEG;IACH,+CAA4B,CAAA;IAE5B;;OAEG;IACH,gEAA6C,CAAA;IAE7C;;OAEG;IACH,uDAAoC,CAAA;AACxC,CAAC,EApBW,eAAe,+BAAf,eAAe,QAoB1B;AAED;;GAEG;AACU,QAAA,qBAAqB,GAAG,sBAAsB,CAAC;AAE5D;;GAEG;AACU,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C;;GAEG;AACU,QAAA,yBAAyB,GAAG,gBAAgB,CAAC;AAE1D;;GAEG;AACU,QAAA,+BAA+B,GAAG,iBAAiB,CAAC;AAEjE;;GAEG;AACU,QAAA,iCAAiC,GAAG,iBAAiB,CAAC;AAEnE;;GAEG;AACU,QAAA,sCAAsC,GAAG,yBAAyB,CAAC;AAEhF;;GAEG;AACU,QAAA,+BAA+B,GAAG,mBAAmB,CAAC;AAEnE;;GAEG;AACU,QAAA,wCAAwC,GAAG,2BAA2B,CAAC;AAEpF;;GAEG;AACU,QAAA,2BAA2B,GAAG,qBAAqB,CAAC;AAEjE;;GAEG;AACU,QAAA,4BAA4B,GAAG,cAAc,CAAC"}
package/cross/index.d.mts CHANGED
@@ -18,12 +18,22 @@ declare class ModelDataVisitor {
18
18
  * Runtime information of a data model or field attribute
19
19
  */
20
20
  type RuntimeAttribute = {
21
+ /**
22
+ * Attribute name
23
+ */
21
24
  name: string;
25
+ /**
26
+ * Attribute arguments
27
+ */
22
28
  args: Array<{
23
29
  name?: string;
24
30
  value: unknown;
25
31
  }>;
26
32
  };
33
+ /**
34
+ * Function for computing default value for a field
35
+ */
36
+ type FieldDefaultValueProvider = (userContext: unknown) => unknown;
27
37
  /**
28
38
  * Runtime information of a data model field
29
39
  */
@@ -72,6 +82,14 @@ type FieldInfo = {
72
82
  * Mapping from foreign key field names to relation field names
73
83
  */
74
84
  foreignKeyMapping?: Record<string, string>;
85
+ /**
86
+ * Model from which the field is inherited
87
+ */
88
+ inheritedFrom?: string;
89
+ /**
90
+ * A function that provides a default value for the field
91
+ */
92
+ defaultValueProvider?: FieldDefaultValueProvider;
75
93
  /**
76
94
  * If the field is an auto-increment field
77
95
  */
@@ -86,21 +104,46 @@ type UniqueConstraint = {
86
104
  fields: string[];
87
105
  };
88
106
  /**
89
- * ZModel data model metadata
107
+ * Metadata for a data model
90
108
  */
91
- type ModelMeta = {
109
+ type ModelInfo = {
92
110
  /**
93
- * Model fields
111
+ * Model name
94
112
  */
95
- fields: Record<string, Record<string, FieldInfo>>;
113
+ name: string;
114
+ /**
115
+ * Base types
116
+ */
117
+ baseTypes?: string[];
96
118
  /**
97
- * Model unique constraints
119
+ * Fields
98
120
  */
99
- uniqueConstraints: Record<string, Record<string, UniqueConstraint>>;
121
+ fields: Record<string, FieldInfo>;
100
122
  /**
101
- * Information for cascading delete
123
+ * Unique constraints
102
124
  */
103
- deleteCascade: Record<string, string[]>;
125
+ uniqueConstraints?: Record<string, UniqueConstraint>;
126
+ /**
127
+ * Attributes on the model
128
+ */
129
+ attributes?: RuntimeAttribute[];
130
+ /**
131
+ * Discriminator field name
132
+ */
133
+ discriminator?: string;
134
+ };
135
+ /**
136
+ * ZModel data model metadata
137
+ */
138
+ type ModelMeta = {
139
+ /**
140
+ * Data models
141
+ */
142
+ models: Record<string, ModelInfo>;
143
+ /**
144
+ * Mapping from model name to models that will be deleted because of it due to cascade delete
145
+ */
146
+ deleteCascade?: Record<string, string[]>;
104
147
  /**
105
148
  * Name of model that backs the `auth()` function
106
149
  */
@@ -109,7 +152,7 @@ type ModelMeta = {
109
152
  /**
110
153
  * Resolves a model field to its metadata. Returns undefined if not found.
111
154
  */
112
- declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo;
155
+ declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo | undefined;
113
156
  /**
114
157
  * Resolves a model field to its metadata. Throws an error if not found.
115
158
  */
@@ -118,6 +161,10 @@ declare function requireField(modelMeta: ModelMeta, model: string, field: string
118
161
  * Gets all fields of a model.
119
162
  */
120
163
  declare function getFields(modelMeta: ModelMeta, model: string): Record<string, FieldInfo>;
164
+ /**
165
+ * Gets unique constraints of a model.
166
+ */
167
+ declare function getUniqueConstraints(modelMeta: ModelMeta, model: string): Record<string, UniqueConstraint> | undefined;
121
168
 
122
169
  /**
123
170
  * Tries to apply a mutation to a query result.
@@ -190,7 +237,7 @@ type NestedWriteVisitorContext = {
190
237
  * to let the visitor traverse it instead of its original children.
191
238
  */
192
239
  type NestedWriterVisitorCallback = {
193
- create?: (model: string, args: any[], context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
240
+ create?: (model: string, data: any, context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
194
241
  createMany?: (model: string, args: {
195
242
  data: any;
196
243
  skipDuplicates?: boolean;
@@ -265,5 +312,7 @@ declare function enumerate<T>(x: Enumerable<T>): T[];
265
312
  */
266
313
  declare function zip<T1, T2>(x: Enumerable<T1>, y: Enumerable<T2>): Array<[T1, T2]>;
267
314
  declare function getIdFields(modelMeta: ModelMeta, model: string, throwIfNotFound?: boolean): FieldInfo[];
315
+ declare function getModelInfo<Throw extends boolean = false>(modelMeta: ModelMeta, model: string, throwIfNotFound?: Throw): Throw extends true ? ModelInfo : ModelInfo | undefined;
316
+ declare function isDelegateModel(modelMeta: ModelMeta, model: string): boolean;
268
317
 
269
- export { type Enumerable, type FieldInfo, type MaybePromise, ModelDataVisitor, type ModelDataVisitorCallback, type ModelMeta, NestedReadVisitor, type NestedReadVisitorCallback, NestedWriteVisitor, type NestedWriteVisitorContext, type NestedWriterVisitorCallback, type PrismaWriteActionType, PrismaWriteActions, type RuntimeAttribute, type UniqueConstraint, applyMutation, enumerate, getFields, getIdFields, getModelFields, getMutatedModels, getReadModels, requireField, resolveField, zip };
318
+ export { type Enumerable, type FieldDefaultValueProvider, type FieldInfo, type MaybePromise, ModelDataVisitor, type ModelDataVisitorCallback, type ModelInfo, type ModelMeta, NestedReadVisitor, type NestedReadVisitorCallback, NestedWriteVisitor, type NestedWriteVisitorContext, type NestedWriterVisitorCallback, type PrismaWriteActionType, PrismaWriteActions, type RuntimeAttribute, type UniqueConstraint, applyMutation, enumerate, getFields, getIdFields, getModelFields, getModelInfo, getMutatedModels, getReadModels, getUniqueConstraints, isDelegateModel, requireField, resolveField, zip };
package/cross/index.d.ts CHANGED
@@ -18,12 +18,22 @@ declare class ModelDataVisitor {
18
18
  * Runtime information of a data model or field attribute
19
19
  */
20
20
  type RuntimeAttribute = {
21
+ /**
22
+ * Attribute name
23
+ */
21
24
  name: string;
25
+ /**
26
+ * Attribute arguments
27
+ */
22
28
  args: Array<{
23
29
  name?: string;
24
30
  value: unknown;
25
31
  }>;
26
32
  };
33
+ /**
34
+ * Function for computing default value for a field
35
+ */
36
+ type FieldDefaultValueProvider = (userContext: unknown) => unknown;
27
37
  /**
28
38
  * Runtime information of a data model field
29
39
  */
@@ -72,6 +82,14 @@ type FieldInfo = {
72
82
  * Mapping from foreign key field names to relation field names
73
83
  */
74
84
  foreignKeyMapping?: Record<string, string>;
85
+ /**
86
+ * Model from which the field is inherited
87
+ */
88
+ inheritedFrom?: string;
89
+ /**
90
+ * A function that provides a default value for the field
91
+ */
92
+ defaultValueProvider?: FieldDefaultValueProvider;
75
93
  /**
76
94
  * If the field is an auto-increment field
77
95
  */
@@ -86,21 +104,46 @@ type UniqueConstraint = {
86
104
  fields: string[];
87
105
  };
88
106
  /**
89
- * ZModel data model metadata
107
+ * Metadata for a data model
90
108
  */
91
- type ModelMeta = {
109
+ type ModelInfo = {
92
110
  /**
93
- * Model fields
111
+ * Model name
94
112
  */
95
- fields: Record<string, Record<string, FieldInfo>>;
113
+ name: string;
114
+ /**
115
+ * Base types
116
+ */
117
+ baseTypes?: string[];
96
118
  /**
97
- * Model unique constraints
119
+ * Fields
98
120
  */
99
- uniqueConstraints: Record<string, Record<string, UniqueConstraint>>;
121
+ fields: Record<string, FieldInfo>;
100
122
  /**
101
- * Information for cascading delete
123
+ * Unique constraints
102
124
  */
103
- deleteCascade: Record<string, string[]>;
125
+ uniqueConstraints?: Record<string, UniqueConstraint>;
126
+ /**
127
+ * Attributes on the model
128
+ */
129
+ attributes?: RuntimeAttribute[];
130
+ /**
131
+ * Discriminator field name
132
+ */
133
+ discriminator?: string;
134
+ };
135
+ /**
136
+ * ZModel data model metadata
137
+ */
138
+ type ModelMeta = {
139
+ /**
140
+ * Data models
141
+ */
142
+ models: Record<string, ModelInfo>;
143
+ /**
144
+ * Mapping from model name to models that will be deleted because of it due to cascade delete
145
+ */
146
+ deleteCascade?: Record<string, string[]>;
104
147
  /**
105
148
  * Name of model that backs the `auth()` function
106
149
  */
@@ -109,7 +152,7 @@ type ModelMeta = {
109
152
  /**
110
153
  * Resolves a model field to its metadata. Returns undefined if not found.
111
154
  */
112
- declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo;
155
+ declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo | undefined;
113
156
  /**
114
157
  * Resolves a model field to its metadata. Throws an error if not found.
115
158
  */
@@ -118,6 +161,10 @@ declare function requireField(modelMeta: ModelMeta, model: string, field: string
118
161
  * Gets all fields of a model.
119
162
  */
120
163
  declare function getFields(modelMeta: ModelMeta, model: string): Record<string, FieldInfo>;
164
+ /**
165
+ * Gets unique constraints of a model.
166
+ */
167
+ declare function getUniqueConstraints(modelMeta: ModelMeta, model: string): Record<string, UniqueConstraint> | undefined;
121
168
 
122
169
  /**
123
170
  * Tries to apply a mutation to a query result.
@@ -190,7 +237,7 @@ type NestedWriteVisitorContext = {
190
237
  * to let the visitor traverse it instead of its original children.
191
238
  */
192
239
  type NestedWriterVisitorCallback = {
193
- create?: (model: string, args: any[], context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
240
+ create?: (model: string, data: any, context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
194
241
  createMany?: (model: string, args: {
195
242
  data: any;
196
243
  skipDuplicates?: boolean;
@@ -265,5 +312,7 @@ declare function enumerate<T>(x: Enumerable<T>): T[];
265
312
  */
266
313
  declare function zip<T1, T2>(x: Enumerable<T1>, y: Enumerable<T2>): Array<[T1, T2]>;
267
314
  declare function getIdFields(modelMeta: ModelMeta, model: string, throwIfNotFound?: boolean): FieldInfo[];
315
+ declare function getModelInfo<Throw extends boolean = false>(modelMeta: ModelMeta, model: string, throwIfNotFound?: Throw): Throw extends true ? ModelInfo : ModelInfo | undefined;
316
+ declare function isDelegateModel(modelMeta: ModelMeta, model: string): boolean;
268
317
 
269
- export { type Enumerable, type FieldInfo, type MaybePromise, ModelDataVisitor, type ModelDataVisitorCallback, type ModelMeta, NestedReadVisitor, type NestedReadVisitorCallback, NestedWriteVisitor, type NestedWriteVisitorContext, type NestedWriterVisitorCallback, type PrismaWriteActionType, PrismaWriteActions, type RuntimeAttribute, type UniqueConstraint, applyMutation, enumerate, getFields, getIdFields, getModelFields, getMutatedModels, getReadModels, requireField, resolveField, zip };
318
+ export { type Enumerable, type FieldDefaultValueProvider, type FieldInfo, type MaybePromise, ModelDataVisitor, type ModelDataVisitorCallback, type ModelInfo, type ModelMeta, NestedReadVisitor, type NestedReadVisitorCallback, NestedWriteVisitor, type NestedWriteVisitorContext, type NestedWriterVisitorCallback, type PrismaWriteActionType, PrismaWriteActions, type RuntimeAttribute, type UniqueConstraint, applyMutation, enumerate, getFields, getIdFields, getModelFields, getModelInfo, getMutatedModels, getReadModels, getUniqueConstraints, isDelegateModel, requireField, resolveField, zip };
package/cross/index.js CHANGED
@@ -76,8 +76,11 @@ __export(cross_exports, {
76
76
  getFields: () => getFields,
77
77
  getIdFields: () => getIdFields,
78
78
  getModelFields: () => getModelFields,
79
+ getModelInfo: () => getModelInfo,
79
80
  getMutatedModels: () => getMutatedModels,
80
81
  getReadModels: () => getReadModels,
82
+ getUniqueConstraints: () => getUniqueConstraints,
83
+ isDelegateModel: () => isDelegateModel,
81
84
  requireField: () => requireField,
82
85
  resolveField: () => resolveField,
83
86
  zip: () => zip
@@ -118,8 +121,8 @@ var ModelDataVisitor = class {
118
121
  // src/cross/model-meta.ts
119
122
  var import_lower_case_first = require("lower-case-first");
120
123
  function resolveField(modelMeta, model, field) {
121
- var _a;
122
- return (_a = modelMeta.fields[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a[field];
124
+ var _a, _b;
125
+ return (_b = (_a = modelMeta.models[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a.fields) == null ? void 0 : _b[field];
123
126
  }
124
127
  function requireField(modelMeta, model, field) {
125
128
  const f = resolveField(modelMeta, model, field);
@@ -129,7 +132,12 @@ function requireField(modelMeta, model, field) {
129
132
  return f;
130
133
  }
131
134
  function getFields(modelMeta, model) {
132
- return modelMeta.fields[(0, import_lower_case_first.lowerCaseFirst)(model)];
135
+ var _a;
136
+ return (_a = modelMeta.models[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a.fields;
137
+ }
138
+ function getUniqueConstraints(modelMeta, model) {
139
+ var _a;
140
+ return (_a = modelMeta.models[(0, import_lower_case_first.lowerCaseFirst)(model)]) == null ? void 0 : _a.uniqueConstraints;
133
141
  }
134
142
 
135
143
  // src/cross/mutator.ts
@@ -396,7 +404,8 @@ function zip(x, y) {
396
404
  }
397
405
  }
398
406
  function getIdFields(modelMeta, model, throwIfNotFound = false) {
399
- let fields = modelMeta.fields[(0, import_lower_case_first2.lowerCaseFirst)(model)];
407
+ var _a;
408
+ let fields = (_a = modelMeta.models[(0, import_lower_case_first2.lowerCaseFirst)(model)]) == null ? void 0 : _a.fields;
400
409
  if (!fields) {
401
410
  if (throwIfNotFound) {
402
411
  throw new Error(`Unable to load fields for ${model}`);
@@ -410,6 +419,17 @@ function getIdFields(modelMeta, model, throwIfNotFound = false) {
410
419
  }
411
420
  return result;
412
421
  }
422
+ function getModelInfo(modelMeta, model, throwIfNotFound = false) {
423
+ const info = modelMeta.models[(0, import_lower_case_first2.lowerCaseFirst)(model)];
424
+ if (!info && throwIfNotFound) {
425
+ throw new Error(`Unable to load info for ${model}`);
426
+ }
427
+ return info;
428
+ }
429
+ function isDelegateModel(modelMeta, model) {
430
+ var _a, _b;
431
+ return !!((_b = (_a = getModelInfo(modelMeta, model)) == null ? void 0 : _a.attributes) == null ? void 0 : _b.some((attr) => attr.name === "@@delegate"));
432
+ }
413
433
 
414
434
  // src/cross/nested-write-visitor.ts
415
435
  var NestedWriteVisitor = class {
@@ -511,8 +531,10 @@ var NestedWriteVisitor = class {
511
531
  break;
512
532
  case "set":
513
533
  if (this.callback.set) {
514
- const newContext = pushNewContext(field, model, {});
515
- yield this.callback.set(model, data, newContext);
534
+ for (const item of enumerate(data)) {
535
+ const newContext = pushNewContext(field, model, item, true);
536
+ yield this.callback.set(model, item, newContext);
537
+ }
516
538
  }
517
539
  break;
518
540
  case "update":
@@ -664,11 +686,12 @@ function getMutatedModels(model, operation, mutationArgs, modelMeta) {
664
686
  });
665
687
  }
666
688
  function collectDeleteCascades(model, modelMeta, result, visited) {
689
+ var _a;
667
690
  if (visited.has(model)) {
668
691
  return;
669
692
  }
670
693
  visited.add(model);
671
- const cascades = modelMeta.deleteCascade[(0, import_lower_case_first3.lowerCaseFirst)(model)];
694
+ const cascades = (_a = modelMeta.deleteCascade) == null ? void 0 : _a[(0, import_lower_case_first3.lowerCaseFirst)(model)];
672
695
  if (!cascades) {
673
696
  return;
674
697
  }
@@ -688,8 +711,11 @@ function collectDeleteCascades(model, modelMeta, result, visited) {
688
711
  getFields,
689
712
  getIdFields,
690
713
  getModelFields,
714
+ getModelInfo,
691
715
  getMutatedModels,
692
716
  getReadModels,
717
+ getUniqueConstraints,
718
+ isDelegateModel,
693
719
  requireField,
694
720
  resolveField,
695
721
  zip