@zenstackhq/runtime 1.8.2 → 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.
- package/constants.d.ts +5 -1
- package/constants.js +6 -2
- package/constants.js.map +1 -1
- package/cross/index.d.mts +60 -11
- package/cross/index.d.ts +60 -11
- 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 +92 -0
- package/enhancements/default-auth.js.map +1 -0
- package/enhancements/delegate.d.ts +64 -0
- package/enhancements/delegate.js +903 -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 +14 -14
- 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 -19
- package/enhancements/policy/handler.js +166 -168
- 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 +23 -45
- package/enhancements/policy/policy-utils.js +34 -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 +3 -3
- package/enhancements/utils.js +9 -68
- 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 +2 -2
- 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
|
*/
|
|
@@ -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
|
-
*
|
|
107
|
+
* Metadata for a data model
|
|
90
108
|
*/
|
|
91
|
-
type
|
|
109
|
+
type ModelInfo = {
|
|
92
110
|
/**
|
|
93
|
-
* Model
|
|
111
|
+
* Model name
|
|
94
112
|
*/
|
|
95
|
-
|
|
113
|
+
name: string;
|
|
114
|
+
/**
|
|
115
|
+
* Base types
|
|
116
|
+
*/
|
|
117
|
+
baseTypes?: string[];
|
|
96
118
|
/**
|
|
97
|
-
*
|
|
119
|
+
* Fields
|
|
98
120
|
*/
|
|
99
|
-
|
|
121
|
+
fields: Record<string, FieldInfo>;
|
|
100
122
|
/**
|
|
101
|
-
*
|
|
123
|
+
* Unique constraints
|
|
102
124
|
*/
|
|
103
|
-
|
|
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,
|
|
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
|
-
*
|
|
107
|
+
* Metadata for a data model
|
|
90
108
|
*/
|
|
91
|
-
type
|
|
109
|
+
type ModelInfo = {
|
|
92
110
|
/**
|
|
93
|
-
* Model
|
|
111
|
+
* Model name
|
|
94
112
|
*/
|
|
95
|
-
|
|
113
|
+
name: string;
|
|
114
|
+
/**
|
|
115
|
+
* Base types
|
|
116
|
+
*/
|
|
117
|
+
baseTypes?: string[];
|
|
96
118
|
/**
|
|
97
|
-
*
|
|
119
|
+
* Fields
|
|
98
120
|
*/
|
|
99
|
-
|
|
121
|
+
fields: Record<string, FieldInfo>;
|
|
100
122
|
/**
|
|
101
|
-
*
|
|
123
|
+
* Unique constraints
|
|
102
124
|
*/
|
|
103
|
-
|
|
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,
|
|
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.
|
|
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
|