@zenstackhq/runtime 1.10.0 → 2.0.0-alpha.2
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/constants.d.ts +5 -1
- package/constants.js +6 -2
- package/constants.js.map +1 -1
- package/cross/index.d.mts +67 -12
- package/cross/index.d.ts +67 -12
- package/cross/index.js +33 -7
- package/cross/index.js.map +1 -1
- package/cross/index.mjs +30 -7
- package/cross/index.mjs.map +1 -1
- package/enhance.d.ts +1 -0
- package/enhance.js +10 -0
- package/enhancements/create-enhancement.d.ts +78 -0
- package/enhancements/create-enhancement.js +86 -0
- package/enhancements/create-enhancement.js.map +1 -0
- package/enhancements/default-auth.d.ts +7 -0
- package/enhancements/default-auth.js +127 -0
- package/enhancements/default-auth.js.map +1 -0
- package/enhancements/delegate.d.ts +64 -0
- package/enhancements/delegate.js +911 -0
- package/enhancements/delegate.js.map +1 -0
- package/enhancements/index.d.ts +1 -6
- package/enhancements/index.js +1 -6
- package/enhancements/index.js.map +1 -1
- package/enhancements/logger.js.map +1 -0
- package/enhancements/omit.d.ts +4 -14
- package/enhancements/omit.js +6 -10
- package/enhancements/omit.js.map +1 -1
- package/enhancements/password.d.ts +4 -14
- package/enhancements/password.js +6 -10
- package/enhancements/password.js.map +1 -1
- package/enhancements/policy/handler.d.ts +18 -21
- package/enhancements/policy/handler.js +150 -184
- package/enhancements/policy/handler.js.map +1 -1
- package/enhancements/policy/index.d.ts +3 -53
- package/enhancements/policy/index.js +7 -24
- package/enhancements/policy/index.js.map +1 -1
- package/enhancements/policy/policy-utils.d.ts +19 -45
- package/enhancements/policy/policy-utils.js +16 -147
- package/enhancements/policy/policy-utils.js.map +1 -1
- package/enhancements/proxy.d.ts +11 -3
- package/enhancements/proxy.js +10 -9
- package/enhancements/proxy.js.map +1 -1
- package/enhancements/query-utils.d.ts +24 -0
- package/enhancements/query-utils.js +152 -0
- package/enhancements/query-utils.js.map +1 -0
- package/enhancements/types.d.ts +3 -3
- package/enhancements/utils.d.ts +6 -3
- package/enhancements/utils.js +29 -69
- package/enhancements/utils.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +5 -2
- package/prisma.d.ts +1 -0
- package/types.d.ts +9 -2
- package/version.d.ts +3 -4
- package/version.js +29 -46
- package/version.js.map +1 -1
- package/enhancements/enhance.d.ts +0 -18
- package/enhancements/enhance.js +0 -42
- package/enhancements/enhance.js.map +0 -1
- package/enhancements/policy/logger.js.map +0 -1
- package/enhancements/preset.d.ts +0 -15
- package/enhancements/preset.js +0 -21
- package/enhancements/preset.js.map +0 -1
- package/loader.d.ts +0 -22
- package/loader.js +0 -99
- package/loader.js.map +0 -1
- /package/enhancements/{policy/logger.d.ts → logger.d.ts} +0 -0
- /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 = "
|
|
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 = '
|
|
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
|
*/
|
|
@@ -69,9 +79,23 @@ type FieldInfo = {
|
|
|
69
79
|
*/
|
|
70
80
|
isForeignKey?: boolean;
|
|
71
81
|
/**
|
|
72
|
-
*
|
|
82
|
+
* If the field is a foreign key field, the field name of the corresponding relation field.
|
|
83
|
+
* Only available on foreign key fields.
|
|
84
|
+
*/
|
|
85
|
+
relationField?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Mapping from foreign key field names to relation field names.
|
|
88
|
+
* Only available on relation fields.
|
|
73
89
|
*/
|
|
74
90
|
foreignKeyMapping?: Record<string, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Model from which the field is inherited
|
|
93
|
+
*/
|
|
94
|
+
inheritedFrom?: string;
|
|
95
|
+
/**
|
|
96
|
+
* A function that provides a default value for the field
|
|
97
|
+
*/
|
|
98
|
+
defaultValueProvider?: FieldDefaultValueProvider;
|
|
75
99
|
/**
|
|
76
100
|
* If the field is an auto-increment field
|
|
77
101
|
*/
|
|
@@ -86,21 +110,46 @@ type UniqueConstraint = {
|
|
|
86
110
|
fields: string[];
|
|
87
111
|
};
|
|
88
112
|
/**
|
|
89
|
-
*
|
|
113
|
+
* Metadata for a data model
|
|
90
114
|
*/
|
|
91
|
-
type
|
|
115
|
+
type ModelInfo = {
|
|
116
|
+
/**
|
|
117
|
+
* Model name
|
|
118
|
+
*/
|
|
119
|
+
name: string;
|
|
92
120
|
/**
|
|
93
|
-
*
|
|
121
|
+
* Base types
|
|
94
122
|
*/
|
|
95
|
-
|
|
123
|
+
baseTypes?: string[];
|
|
96
124
|
/**
|
|
97
|
-
*
|
|
125
|
+
* Fields
|
|
98
126
|
*/
|
|
99
|
-
|
|
127
|
+
fields: Record<string, FieldInfo>;
|
|
100
128
|
/**
|
|
101
|
-
*
|
|
129
|
+
* Unique constraints
|
|
102
130
|
*/
|
|
103
|
-
|
|
131
|
+
uniqueConstraints?: Record<string, UniqueConstraint>;
|
|
132
|
+
/**
|
|
133
|
+
* Attributes on the model
|
|
134
|
+
*/
|
|
135
|
+
attributes?: RuntimeAttribute[];
|
|
136
|
+
/**
|
|
137
|
+
* Discriminator field name
|
|
138
|
+
*/
|
|
139
|
+
discriminator?: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* ZModel data model metadata
|
|
143
|
+
*/
|
|
144
|
+
type ModelMeta = {
|
|
145
|
+
/**
|
|
146
|
+
* Data models
|
|
147
|
+
*/
|
|
148
|
+
models: Record<string, ModelInfo>;
|
|
149
|
+
/**
|
|
150
|
+
* Mapping from model name to models that will be deleted because of it due to cascade delete
|
|
151
|
+
*/
|
|
152
|
+
deleteCascade?: Record<string, string[]>;
|
|
104
153
|
/**
|
|
105
154
|
* Name of model that backs the `auth()` function
|
|
106
155
|
*/
|
|
@@ -109,7 +158,7 @@ type ModelMeta = {
|
|
|
109
158
|
/**
|
|
110
159
|
* Resolves a model field to its metadata. Returns undefined if not found.
|
|
111
160
|
*/
|
|
112
|
-
declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo;
|
|
161
|
+
declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo | undefined;
|
|
113
162
|
/**
|
|
114
163
|
* Resolves a model field to its metadata. Throws an error if not found.
|
|
115
164
|
*/
|
|
@@ -118,6 +167,10 @@ declare function requireField(modelMeta: ModelMeta, model: string, field: string
|
|
|
118
167
|
* Gets all fields of a model.
|
|
119
168
|
*/
|
|
120
169
|
declare function getFields(modelMeta: ModelMeta, model: string): Record<string, FieldInfo>;
|
|
170
|
+
/**
|
|
171
|
+
* Gets unique constraints of a model.
|
|
172
|
+
*/
|
|
173
|
+
declare function getUniqueConstraints(modelMeta: ModelMeta, model: string): Record<string, UniqueConstraint> | undefined;
|
|
121
174
|
|
|
122
175
|
/**
|
|
123
176
|
* Tries to apply a mutation to a query result.
|
|
@@ -190,7 +243,7 @@ type NestedWriteVisitorContext = {
|
|
|
190
243
|
* to let the visitor traverse it instead of its original children.
|
|
191
244
|
*/
|
|
192
245
|
type NestedWriterVisitorCallback = {
|
|
193
|
-
create?: (model: string,
|
|
246
|
+
create?: (model: string, data: any, context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
|
|
194
247
|
createMany?: (model: string, args: {
|
|
195
248
|
data: any;
|
|
196
249
|
skipDuplicates?: boolean;
|
|
@@ -265,5 +318,7 @@ declare function enumerate<T>(x: Enumerable<T>): T[];
|
|
|
265
318
|
*/
|
|
266
319
|
declare function zip<T1, T2>(x: Enumerable<T1>, y: Enumerable<T2>): Array<[T1, T2]>;
|
|
267
320
|
declare function getIdFields(modelMeta: ModelMeta, model: string, throwIfNotFound?: boolean): FieldInfo[];
|
|
321
|
+
declare function getModelInfo<Throw extends boolean = false>(modelMeta: ModelMeta, model: string, throwIfNotFound?: Throw): Throw extends true ? ModelInfo : ModelInfo | undefined;
|
|
322
|
+
declare function isDelegateModel(modelMeta: ModelMeta, model: string): boolean;
|
|
268
323
|
|
|
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 };
|
|
324
|
+
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
|
*/
|
|
@@ -69,9 +79,23 @@ type FieldInfo = {
|
|
|
69
79
|
*/
|
|
70
80
|
isForeignKey?: boolean;
|
|
71
81
|
/**
|
|
72
|
-
*
|
|
82
|
+
* If the field is a foreign key field, the field name of the corresponding relation field.
|
|
83
|
+
* Only available on foreign key fields.
|
|
84
|
+
*/
|
|
85
|
+
relationField?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Mapping from foreign key field names to relation field names.
|
|
88
|
+
* Only available on relation fields.
|
|
73
89
|
*/
|
|
74
90
|
foreignKeyMapping?: Record<string, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Model from which the field is inherited
|
|
93
|
+
*/
|
|
94
|
+
inheritedFrom?: string;
|
|
95
|
+
/**
|
|
96
|
+
* A function that provides a default value for the field
|
|
97
|
+
*/
|
|
98
|
+
defaultValueProvider?: FieldDefaultValueProvider;
|
|
75
99
|
/**
|
|
76
100
|
* If the field is an auto-increment field
|
|
77
101
|
*/
|
|
@@ -86,21 +110,46 @@ type UniqueConstraint = {
|
|
|
86
110
|
fields: string[];
|
|
87
111
|
};
|
|
88
112
|
/**
|
|
89
|
-
*
|
|
113
|
+
* Metadata for a data model
|
|
90
114
|
*/
|
|
91
|
-
type
|
|
115
|
+
type ModelInfo = {
|
|
116
|
+
/**
|
|
117
|
+
* Model name
|
|
118
|
+
*/
|
|
119
|
+
name: string;
|
|
92
120
|
/**
|
|
93
|
-
*
|
|
121
|
+
* Base types
|
|
94
122
|
*/
|
|
95
|
-
|
|
123
|
+
baseTypes?: string[];
|
|
96
124
|
/**
|
|
97
|
-
*
|
|
125
|
+
* Fields
|
|
98
126
|
*/
|
|
99
|
-
|
|
127
|
+
fields: Record<string, FieldInfo>;
|
|
100
128
|
/**
|
|
101
|
-
*
|
|
129
|
+
* Unique constraints
|
|
102
130
|
*/
|
|
103
|
-
|
|
131
|
+
uniqueConstraints?: Record<string, UniqueConstraint>;
|
|
132
|
+
/**
|
|
133
|
+
* Attributes on the model
|
|
134
|
+
*/
|
|
135
|
+
attributes?: RuntimeAttribute[];
|
|
136
|
+
/**
|
|
137
|
+
* Discriminator field name
|
|
138
|
+
*/
|
|
139
|
+
discriminator?: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* ZModel data model metadata
|
|
143
|
+
*/
|
|
144
|
+
type ModelMeta = {
|
|
145
|
+
/**
|
|
146
|
+
* Data models
|
|
147
|
+
*/
|
|
148
|
+
models: Record<string, ModelInfo>;
|
|
149
|
+
/**
|
|
150
|
+
* Mapping from model name to models that will be deleted because of it due to cascade delete
|
|
151
|
+
*/
|
|
152
|
+
deleteCascade?: Record<string, string[]>;
|
|
104
153
|
/**
|
|
105
154
|
* Name of model that backs the `auth()` function
|
|
106
155
|
*/
|
|
@@ -109,7 +158,7 @@ type ModelMeta = {
|
|
|
109
158
|
/**
|
|
110
159
|
* Resolves a model field to its metadata. Returns undefined if not found.
|
|
111
160
|
*/
|
|
112
|
-
declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo;
|
|
161
|
+
declare function resolveField(modelMeta: ModelMeta, model: string, field: string): FieldInfo | undefined;
|
|
113
162
|
/**
|
|
114
163
|
* Resolves a model field to its metadata. Throws an error if not found.
|
|
115
164
|
*/
|
|
@@ -118,6 +167,10 @@ declare function requireField(modelMeta: ModelMeta, model: string, field: string
|
|
|
118
167
|
* Gets all fields of a model.
|
|
119
168
|
*/
|
|
120
169
|
declare function getFields(modelMeta: ModelMeta, model: string): Record<string, FieldInfo>;
|
|
170
|
+
/**
|
|
171
|
+
* Gets unique constraints of a model.
|
|
172
|
+
*/
|
|
173
|
+
declare function getUniqueConstraints(modelMeta: ModelMeta, model: string): Record<string, UniqueConstraint> | undefined;
|
|
121
174
|
|
|
122
175
|
/**
|
|
123
176
|
* Tries to apply a mutation to a query result.
|
|
@@ -190,7 +243,7 @@ type NestedWriteVisitorContext = {
|
|
|
190
243
|
* to let the visitor traverse it instead of its original children.
|
|
191
244
|
*/
|
|
192
245
|
type NestedWriterVisitorCallback = {
|
|
193
|
-
create?: (model: string,
|
|
246
|
+
create?: (model: string, data: any, context: NestedWriteVisitorContext) => MaybePromise<boolean | object | void>;
|
|
194
247
|
createMany?: (model: string, args: {
|
|
195
248
|
data: any;
|
|
196
249
|
skipDuplicates?: boolean;
|
|
@@ -265,5 +318,7 @@ declare function enumerate<T>(x: Enumerable<T>): T[];
|
|
|
265
318
|
*/
|
|
266
319
|
declare function zip<T1, T2>(x: Enumerable<T1>, y: Enumerable<T2>): Array<[T1, T2]>;
|
|
267
320
|
declare function getIdFields(modelMeta: ModelMeta, model: string, throwIfNotFound?: boolean): FieldInfo[];
|
|
321
|
+
declare function getModelInfo<Throw extends boolean = false>(modelMeta: ModelMeta, model: string, throwIfNotFound?: Throw): Throw extends true ? ModelInfo : ModelInfo | undefined;
|
|
322
|
+
declare function isDelegateModel(modelMeta: ModelMeta, model: string): boolean;
|
|
268
323
|
|
|
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 };
|
|
324
|
+
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
515
|
-
|
|
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
|