@zenstackhq/runtime 0.6.0-pre.2 → 1.0.0-alpha.19

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 (120) hide show
  1. package/constants.d.ts +4 -0
  2. package/constants.js +8 -0
  3. package/constants.js.map +1 -0
  4. package/enhancements/index.d.ts +4 -0
  5. package/enhancements/index.js +21 -0
  6. package/enhancements/index.js.map +1 -0
  7. package/enhancements/model-meta.d.ts +9 -0
  8. package/enhancements/model-meta.js +25 -0
  9. package/enhancements/model-meta.js.map +1 -0
  10. package/enhancements/nested-write-vistor.d.ts +65 -0
  11. package/enhancements/nested-write-vistor.js +155 -0
  12. package/enhancements/nested-write-vistor.js.map +1 -0
  13. package/enhancements/omit.d.ts +5 -0
  14. package/enhancements/omit.js +60 -0
  15. package/enhancements/omit.js.map +1 -0
  16. package/enhancements/password.d.ts +5 -0
  17. package/enhancements/password.js +66 -0
  18. package/enhancements/password.js.map +1 -0
  19. package/enhancements/policy/handler.d.ts +36 -0
  20. package/enhancements/policy/handler.js +278 -0
  21. package/enhancements/policy/handler.js.map +1 -0
  22. package/enhancements/policy/index.d.ts +17 -0
  23. package/enhancements/policy/index.js +31 -0
  24. package/enhancements/policy/index.js.map +1 -0
  25. package/{lib/proxy → enhancements/policy}/logger.d.ts +3 -0
  26. package/{lib/proxy → enhancements/policy}/logger.js +4 -0
  27. package/enhancements/policy/logger.js.map +1 -0
  28. package/enhancements/policy/policy-utils.d.ts +78 -0
  29. package/enhancements/policy/policy-utils.js +575 -0
  30. package/enhancements/policy/policy-utils.js.map +1 -0
  31. package/enhancements/preset.d.ts +16 -0
  32. package/enhancements/preset.js +24 -0
  33. package/enhancements/preset.js.map +1 -0
  34. package/enhancements/proxy.d.ts +75 -0
  35. package/enhancements/proxy.js +196 -0
  36. package/enhancements/proxy.js.map +1 -0
  37. package/enhancements/types.d.ts +24 -0
  38. package/{lib/config.js → enhancements/types.js} +1 -1
  39. package/enhancements/types.js.map +1 -0
  40. package/enhancements/utils.d.ts +16 -0
  41. package/enhancements/utils.js +31 -0
  42. package/enhancements/utils.js.map +1 -0
  43. package/error.d.ts +10 -0
  44. package/error.js +17 -0
  45. package/error.js.map +1 -0
  46. package/index.d.ts +5 -0
  47. package/{lib/index.js → index.js} +3 -4
  48. package/index.js.map +1 -0
  49. package/package.json +5 -4
  50. package/{lib/serialization-utils.d.ts → serialization-utils.d.ts} +0 -0
  51. package/{lib/serialization-utils.js → serialization-utils.js} +0 -0
  52. package/serialization-utils.js.map +1 -0
  53. package/types.d.ts +73 -0
  54. package/types.js +14 -0
  55. package/types.js.map +1 -0
  56. package/{lib/validation.d.ts → validation.d.ts} +0 -0
  57. package/{lib/validation.js → validation.js} +0 -0
  58. package/validation.js.map +1 -0
  59. package/{lib/version.d.ts → version.d.ts} +0 -0
  60. package/{lib/version.js → version.js} +6 -1
  61. package/version.js.map +1 -0
  62. package/client/index.d.ts +0 -3
  63. package/client/index.js +0 -11
  64. package/lib/config.d.ts +0 -14
  65. package/lib/config.js.map +0 -1
  66. package/lib/constants.d.ts +0 -12
  67. package/lib/constants.js +0 -16
  68. package/lib/constants.js.map +0 -1
  69. package/lib/handler/data/crud.d.ts +0 -17
  70. package/lib/handler/data/crud.js +0 -255
  71. package/lib/handler/data/crud.js.map +0 -1
  72. package/lib/handler/data/handler.d.ts +0 -20
  73. package/lib/handler/data/handler.js +0 -150
  74. package/lib/handler/data/handler.js.map +0 -1
  75. package/lib/handler/data/nested-write-vistor.d.ts +0 -31
  76. package/lib/handler/data/nested-write-vistor.js +0 -67
  77. package/lib/handler/data/nested-write-vistor.js.map +0 -1
  78. package/lib/handler/data/policy-utils.d.ts +0 -73
  79. package/lib/handler/data/policy-utils.js +0 -447
  80. package/lib/handler/data/policy-utils.js.map +0 -1
  81. package/lib/handler/index.d.ts +0 -1
  82. package/lib/handler/index.js +0 -9
  83. package/lib/handler/index.js.map +0 -1
  84. package/lib/handler/types.d.ts +0 -28
  85. package/lib/handler/types.js +0 -36
  86. package/lib/handler/types.js.map +0 -1
  87. package/lib/index.d.ts +0 -6
  88. package/lib/index.js.map +0 -1
  89. package/lib/policy.d.ts +0 -11
  90. package/lib/policy.js +0 -10
  91. package/lib/policy.js.map +0 -1
  92. package/lib/proxy/handler.d.ts +0 -37
  93. package/lib/proxy/handler.js +0 -333
  94. package/lib/proxy/handler.js.map +0 -1
  95. package/lib/proxy/logger.js.map +0 -1
  96. package/lib/proxy/nested-write-vistor.d.ts +0 -30
  97. package/lib/proxy/nested-write-vistor.js +0 -69
  98. package/lib/proxy/nested-write-vistor.js.map +0 -1
  99. package/lib/proxy/policy-utils.d.ts +0 -78
  100. package/lib/proxy/policy-utils.js +0 -508
  101. package/lib/proxy/policy-utils.js.map +0 -1
  102. package/lib/request-handler.d.ts +0 -21
  103. package/lib/request-handler.js +0 -37
  104. package/lib/request-handler.js.map +0 -1
  105. package/lib/request.d.ts +0 -37
  106. package/lib/request.js +0 -164
  107. package/lib/request.js.map +0 -1
  108. package/lib/serialization-utils.js.map +0 -1
  109. package/lib/service.d.ts +0 -32
  110. package/lib/service.js +0 -184
  111. package/lib/service.js.map +0 -1
  112. package/lib/types.d.ts +0 -185
  113. package/lib/types.js +0 -71
  114. package/lib/types.js.map +0 -1
  115. package/lib/validation.js.map +0 -1
  116. package/lib/version.js.map +0 -1
  117. package/server/index.d.ts +0 -16
  118. package/server/index.js +0 -6
  119. package/types/index.d.ts +0 -1
  120. package/types/index.js +0 -3
package/lib/policy.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":";AAAA,uDAAuD;;;AAEvD,6CAA2D;AAmB3D,SAAgB,UAAU,CACtB,MAAgB,EAChB,MAAiB,EACjB,OAA0B;IAE1B,OAAO,IAAI,KAAK,CACZ,MAAM,EACN,IAAA,kCAAwB,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CACzD,CAAC;AACN,CAAC;AATD,gCASC"}
@@ -1,37 +0,0 @@
1
- import { DbClientContract, DbOperations } from '../types';
2
- import { AuthUser } from '../types';
3
- import { PolicyDef } from '../policy';
4
- type PrismaClientOperations = 'findUnique' | 'findUniqueOrThrow' | 'findFirst' | 'findFirstOrThrow' | 'findMany' | 'create' | 'createMany' | 'delete' | 'update' | 'deleteMany' | 'updateMany' | 'upsert' | 'aggregate' | 'groupBy' | 'count';
5
- export declare function prismaClientProxyHandler(prisma: any, policy: PolicyDef, user?: AuthUser): {
6
- get: (target: any, prop: string | symbol, receiver: any) => any;
7
- };
8
- /**
9
- * Request handler for /data endpoint which processes data CRUD requests.
10
- */
11
- export declare class PrismaModelHandler<DbClient extends DbClientContract> implements Record<PrismaClientOperations, (args: any) => Promise<unknown>> {
12
- private readonly prisma;
13
- private readonly policy;
14
- private readonly model;
15
- private readonly user?;
16
- private readonly logger;
17
- constructor(prisma: DbClient, policy: PolicyDef, model: string, user?: AuthUser | undefined);
18
- findUnique(args: any): Promise<unknown>;
19
- findUniqueOrThrow(args: any): Promise<{}>;
20
- findFirst(args: any): Promise<unknown>;
21
- findFirstOrThrow(args: any): Promise<{}>;
22
- findMany(args: any): Promise<unknown[]>;
23
- private checkPolicyForCreatedModels;
24
- private checkReadback;
25
- create(args: any): Promise<unknown>;
26
- createMany(args: any, skipDuplicates?: boolean): Promise<unknown>;
27
- doUpdate(args: any, updateAction: (db: DbOperations) => Promise<unknown>, operation: string): Promise<unknown>;
28
- update(args: any): Promise<unknown>;
29
- updateMany(args: any): Promise<unknown>;
30
- upsert(args: any): Promise<unknown>;
31
- delete(args: any): Promise<any>;
32
- deleteMany(args: any): Promise<unknown>;
33
- aggregate(args: any): Promise<unknown>;
34
- groupBy(args: any): Promise<unknown>;
35
- count(args: any): Promise<number>;
36
- }
37
- export {};
@@ -1,333 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.PrismaModelHandler = exports.prismaClientProxyHandler = void 0;
16
- /* eslint-disable @typescript-eslint/no-explicit-any */
17
- const cuid_1 = __importDefault(require("cuid"));
18
- const superjson_1 = __importDefault(require("superjson"));
19
- const constants_1 = require("../constants");
20
- const policy_utils_1 = require("./policy-utils");
21
- const runtime_1 = require("@prisma/client/runtime");
22
- const logger_1 = require("./logger");
23
- function prismaClientProxyHandler(prisma, policy, user) {
24
- return {
25
- get: (target, prop, receiver) => {
26
- const propVal = Reflect.get(target, prop, receiver);
27
- if (!propVal || typeof prop !== 'string' || prop.startsWith('$')) {
28
- return Reflect.get(target, prop, receiver);
29
- }
30
- return new PrismaModelHandler(prisma, policy, prop, user);
31
- },
32
- };
33
- }
34
- exports.prismaClientProxyHandler = prismaClientProxyHandler;
35
- /**
36
- * Request handler for /data endpoint which processes data CRUD requests.
37
- */
38
- class PrismaModelHandler {
39
- constructor(prisma, policy, model, user) {
40
- this.prisma = prisma;
41
- this.policy = policy;
42
- this.model = model;
43
- this.user = user;
44
- this.logger = new logger_1.Logger(prisma);
45
- }
46
- findUnique(args) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const entities = yield (0, policy_utils_1.readWithCheck)(this.model, args, this.user, this.prisma, this.policy, this.logger);
49
- return entities[0];
50
- });
51
- }
52
- findUniqueOrThrow(args) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const entity = yield this.findUnique(args);
55
- if (!entity) {
56
- throw new runtime_1.NotFoundError('entity not found');
57
- }
58
- return entity;
59
- });
60
- }
61
- findFirst(args) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const entities = yield (0, policy_utils_1.readWithCheck)(this.model, args, this.user, this.prisma, this.policy, this.logger);
64
- return entities[0];
65
- });
66
- }
67
- findFirstOrThrow(args) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- const entity = yield this.findFirst(args);
70
- if (!entity) {
71
- throw new runtime_1.NotFoundError('entity not found');
72
- }
73
- return entity;
74
- });
75
- }
76
- findMany(args) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- return (0, policy_utils_1.readWithCheck)(this.model, args, this.user, this.prisma, this.policy, this.logger);
79
- });
80
- }
81
- checkPolicyForCreatedModels(createdModels, transactionId, tx) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- if (createdModels.length === 0) {
84
- return;
85
- }
86
- yield Promise.all(createdModels.map((model) => __awaiter(this, void 0, void 0, function* () {
87
- yield (0, policy_utils_1.checkPolicyForFilter)(model, {
88
- [constants_1.TRANSACTION_FIELD_NAME]: `${transactionId}:create`,
89
- }, 'create', this.user, tx, this.policy, this.logger);
90
- })));
91
- });
92
- }
93
- checkReadback(readArgs, operation) {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- try {
96
- const result = yield (0, policy_utils_1.readWithCheck)(this.model, readArgs, this.user, this.prisma, this.policy, this.logger);
97
- if (result.length === 0) {
98
- this.logger.warn(`${operation} result cannot be read back`);
99
- return undefined;
100
- }
101
- return result[0];
102
- }
103
- catch (err) {
104
- this.logger.warn(`${operation} result cannot be read back: ${err}`);
105
- return undefined;
106
- }
107
- });
108
- }
109
- create(args) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- if (!args) {
112
- throw new runtime_1.PrismaClientValidationError('query argument is required');
113
- }
114
- if (!args.data) {
115
- throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
116
- }
117
- yield (0, policy_utils_1.validateModelPayload)(this.model, 'create', args.data);
118
- // preprocess payload to modify fields as required by attribute like @password
119
- yield (0, policy_utils_1.preprocessWritePayload)(this.policy, this.model, args.data);
120
- const transactionId = (0, cuid_1.default)();
121
- const { createdModels } = yield (0, policy_utils_1.injectTransactionId)(this.model, args.data, 'create', transactionId, this.policy);
122
- // start an interactive transaction
123
- const createResult = yield this.prisma.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
124
- // inject transaction id into update/create payload (direct and nested)
125
- // conduct the create
126
- this.logger.info(`Conducting create: ${this.model}:\n${superjson_1.default.stringify(args)}`);
127
- const createResult = (yield tx[this.model].create(args));
128
- // verify that nested creates pass policy check
129
- this.logger.info(`Checking all created models: [${createdModels.join(',')}]`);
130
- yield this.checkPolicyForCreatedModels(createdModels, transactionId, tx);
131
- return createResult;
132
- }));
133
- // verify that return data requested by query args pass policy check
134
- const readArgs = Object.assign(Object.assign({}, args), { where: { id: createResult.id } });
135
- delete readArgs.data;
136
- return this.checkReadback(readArgs, 'create');
137
- });
138
- }
139
- createMany(args, skipDuplicates) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- if (!args) {
142
- throw new runtime_1.PrismaClientValidationError('query argument is required');
143
- }
144
- if (!args.data) {
145
- throw new runtime_1.PrismaClientValidationError('data field is required and must be an array');
146
- }
147
- const transactionId = (0, cuid_1.default)();
148
- let createdModels = [];
149
- for (const data of (0, policy_utils_1.ensureArray)(args.data)) {
150
- yield (0, policy_utils_1.validateModelPayload)(this.model, 'create', data);
151
- // preprocess payload to modify fields as required by attribute like @password
152
- yield (0, policy_utils_1.preprocessWritePayload)(this.policy, this.model, data);
153
- // inject transaction id into update/create payload (direct and nested)
154
- const { createdModels: created } = yield (0, policy_utils_1.injectTransactionId)(this.model, data, 'create', transactionId, this.policy);
155
- createdModels.push(...created);
156
- }
157
- createdModels = [...new Set(createdModels)];
158
- // start an interactive transaction
159
- const createResult = yield this.prisma.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
160
- // conduct the create
161
- this.logger.info(`Conducting createMany: ${this.model}:\n${superjson_1.default.stringify(args)}`);
162
- const createResult = yield tx[this.model].createMany(args, skipDuplicates);
163
- // verify that nested creates pass policy check
164
- this.logger.info(`Checking all created models: [${createdModels.join(',')}]`);
165
- yield this.checkPolicyForCreatedModels(createdModels, transactionId, tx);
166
- return createResult;
167
- }));
168
- return createResult;
169
- });
170
- }
171
- doUpdate(args, updateAction, operation) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- yield (0, policy_utils_1.validateModelPayload)(this.model, 'update', args.data);
174
- // preprocess payload to modify fields as required by attribute like @password
175
- yield (0, policy_utils_1.preprocessWritePayload)(this.policy, this.model, args.data);
176
- const transactionId = (0, cuid_1.default)();
177
- yield this.prisma.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
178
- // make sure the entity (including ones involved in nested write) pass policy check
179
- yield (0, policy_utils_1.preUpdateCheck)(this.model, args, this.user, tx, this.policy, this.logger);
180
- // inject transaction id into update/create payload (direct and nested)
181
- const { createdModels } = yield (0, policy_utils_1.injectTransactionId)(this.model, args.data, 'update', transactionId, this.policy);
182
- // conduct the update
183
- this.logger.info(`Conducting update: ${this.model}:\n${superjson_1.default.stringify(args)}`);
184
- yield updateAction(tx[this.model]);
185
- // verify that nested creates pass policy check
186
- if (createdModels.length > 0) {
187
- this.logger.info(`Checking all created models: [${createdModels.join(',')}]`);
188
- yield this.checkPolicyForCreatedModels(createdModels, transactionId, tx);
189
- }
190
- }));
191
- // verify that return data requested by query args pass policy check
192
- const readArgs = Object.assign({}, args);
193
- delete readArgs.data;
194
- return this.checkReadback(readArgs, operation);
195
- });
196
- }
197
- update(args) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- if (!args) {
200
- throw new runtime_1.PrismaClientValidationError('query argument is required');
201
- }
202
- if (!args.where) {
203
- throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
204
- }
205
- if (!args.data) {
206
- throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
207
- }
208
- return this.doUpdate(args, (db) => db.update(args), 'update');
209
- });
210
- }
211
- updateMany(args) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- if (!args) {
214
- throw new runtime_1.PrismaClientValidationError('query argument is required');
215
- }
216
- if (!args.data) {
217
- throw new runtime_1.PrismaClientValidationError('data field is required in query argument');
218
- }
219
- return this.doUpdate(args, (db) => db.updateMany(args), 'updateMany');
220
- });
221
- }
222
- upsert(args) {
223
- return __awaiter(this, void 0, void 0, function* () {
224
- if (!args) {
225
- throw new runtime_1.PrismaClientValidationError('query argument is required');
226
- }
227
- if (!args.where) {
228
- throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
229
- }
230
- if (!args.create) {
231
- throw new runtime_1.PrismaClientValidationError('create field is required in query argument');
232
- }
233
- if (!args.update) {
234
- throw new runtime_1.PrismaClientValidationError('update field is required in query argument');
235
- }
236
- yield (0, policy_utils_1.validateModelPayload)(this.model, 'create', args.create);
237
- yield (0, policy_utils_1.validateModelPayload)(this.model, 'update', args.update);
238
- // preprocess payload to modify fields as required by attribute like @password
239
- yield (0, policy_utils_1.preprocessWritePayload)(this.policy, this.model, args.create);
240
- yield (0, policy_utils_1.preprocessWritePayload)(this.policy, this.model, args.update);
241
- const transactionId = (0, cuid_1.default)();
242
- yield this.prisma.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
243
- // make sure the entity (including ones involved in nested write) pass policy check
244
- yield (0, policy_utils_1.preUpdateCheck)(this.model, args, this.user, tx, this.policy, this.logger);
245
- // inject transaction id into update/create payload (direct and nested)
246
- const { createdModels: createdFromCreate } = yield (0, policy_utils_1.injectTransactionId)(this.model, args.create, 'create', transactionId, this.policy);
247
- const { createdModels: createdFromUpdate } = yield (0, policy_utils_1.injectTransactionId)(this.model, args.update, 'update', transactionId, this.policy);
248
- const createdModels = [
249
- ...new Set([...createdFromCreate, ...createdFromUpdate]),
250
- ];
251
- // conduct the update
252
- this.logger.info(`Conducting update: ${this.model}:\n${superjson_1.default.stringify(args)}`);
253
- yield tx[this.model].upsert(args);
254
- // verify that nested creates pass policy check
255
- yield this.checkPolicyForCreatedModels(createdModels, transactionId, tx);
256
- }));
257
- // verify that return data requested by query args pass policy check
258
- const readArgs = Object.assign({}, args);
259
- delete readArgs.create;
260
- delete readArgs.update;
261
- return this.checkReadback(readArgs, 'upsert');
262
- });
263
- }
264
- delete(args) {
265
- return __awaiter(this, void 0, void 0, function* () {
266
- if (!args) {
267
- throw new runtime_1.PrismaClientValidationError('query argument is required');
268
- }
269
- if (!args.where) {
270
- throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
271
- }
272
- // ensures the item under deletion passes policy check
273
- yield (0, policy_utils_1.checkPolicyForFilter)(this.model, args.where, 'delete', this.user, this.prisma, this.policy, this.logger);
274
- let readResult;
275
- try {
276
- const items = yield (0, policy_utils_1.readWithCheck)(this.model, args, this.user, this.prisma, this.policy, this.logger);
277
- readResult = items[0];
278
- }
279
- catch (err) {
280
- // not readable
281
- readResult = undefined;
282
- }
283
- // conduct the deletion
284
- this.logger.info(`Conducting delete ${this.model}:\n${superjson_1.default.stringify(args)}`);
285
- yield this.prisma[this.model].delete(args);
286
- return readResult;
287
- });
288
- }
289
- deleteMany(args) {
290
- return __awaiter(this, void 0, void 0, function* () {
291
- if (!args) {
292
- throw new runtime_1.PrismaClientValidationError('query argument is required');
293
- }
294
- if (!args.where) {
295
- throw new runtime_1.PrismaClientValidationError('where field is required in query argument');
296
- }
297
- // ensures the item under deletion passes policy check
298
- yield (0, policy_utils_1.checkPolicyForFilter)(this.model, args.where, 'delete', this.user, this.prisma, this.policy, this.logger);
299
- // conduct the deletion
300
- this.logger.info(`Conducting delete ${this.model}:\n${superjson_1.default.stringify(args)}`);
301
- return this.prisma[this.model].deleteMany(args);
302
- });
303
- }
304
- aggregate(args) {
305
- return __awaiter(this, void 0, void 0, function* () {
306
- if (!args) {
307
- throw new runtime_1.PrismaClientValidationError('query argument is required');
308
- }
309
- const aggArgs = yield (0, policy_utils_1.ensureAuthGuard)(args, this.model, 'read', this.user, this.policy);
310
- return this.prisma[this.model].aggregate(aggArgs);
311
- });
312
- }
313
- groupBy(args) {
314
- return __awaiter(this, void 0, void 0, function* () {
315
- if (!args) {
316
- throw new runtime_1.PrismaClientValidationError('query argument is required');
317
- }
318
- const aggArgs = yield (0, policy_utils_1.ensureAuthGuard)(args, this.model, 'read', this.user, this.policy);
319
- return this.prisma[this.model].groupBy(aggArgs);
320
- });
321
- }
322
- count(args) {
323
- return __awaiter(this, void 0, void 0, function* () {
324
- if (!args) {
325
- throw new runtime_1.PrismaClientValidationError('query argument is required');
326
- }
327
- const aggArgs = yield (0, policy_utils_1.ensureAuthGuard)(args, this.model, 'read', this.user, this.policy);
328
- return this.prisma[this.model].count(aggArgs);
329
- });
330
- }
331
- }
332
- exports.PrismaModelHandler = PrismaModelHandler;
333
- //# sourceMappingURL=handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/proxy/handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,gDAAwB;AACxB,0DAAkC;AAClC,4CAAsD;AAGtD,iDASwB;AACxB,oDAGgC;AAChC,qCAAkC;AAoBlC,SAAgB,wBAAwB,CACpC,MAAW,EACX,MAAiB,EACjB,IAAe;IAEf,OAAO;QACH,GAAG,EAAE,CAAC,MAAW,EAAE,IAAqB,EAAE,QAAa,EAAE,EAAE;YACvD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YACpD,IAAI,CAAC,OAAO,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBAC9D,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;aAC9C;YACD,OAAO,IAAI,kBAAkB,CACzB,MAA0B,EAC1B,MAAM,EACN,IAAI,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E;YACtB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO;YACP,MAAM,EAAE,UAAU;SACrB,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAe;QACvB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,OAAe;QACvB,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAe;QACxB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;CACJ;AApCD,wBAoCC"}
@@ -1,30 +0,0 @@
1
- import { PrismaWriteActionType, FieldInfo } from '../types';
2
- /**
3
- * Visitor callback function type
4
- *
5
- * @fieldInfo current visiting field
6
- * @action prisma action for this field, e.g., update, create, etc.
7
- * @fieldData data attached to the field, a scalar type for simple field
8
- * and nested structure for model field
9
- * @parentData parent data of @see fieldData, can be used to replace current field data
10
- * @state a custom state
11
- *
12
- * @return if a truethy value is returned, recursive visiting will continue and the return
13
- * value will be used as the new state passed to visiting of the direct child level; otherwise
14
- * visiting is stopped at this level
15
- */
16
- export type NestedWriterVisitorCallback<State = unknown> = (fieldInfo: FieldInfo, action: PrismaWriteActionType, fieldData: any, parentData: any, state: State) => Promise<State | undefined>;
17
- /**
18
- * Recursive visitor for nested write (create/update) payload
19
- */
20
- export declare class NestedWriteVisitor<State> {
21
- private readonly resolveField;
22
- constructor(resolveField: (model: string, field: string) => Promise<FieldInfo | undefined>);
23
- private isPrismaWriteAction;
24
- /**
25
- * Start visiting
26
- *
27
- * @see NestedWriterVisitorCallback
28
- */
29
- visit(model: string, fieldData: any, parentData: any, state: State, callback: NestedWriterVisitorCallback<State>): Promise<void>;
30
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.NestedWriteVisitor = void 0;
15
- const types_1 = require("../types");
16
- /**
17
- * Recursive visitor for nested write (create/update) payload
18
- */
19
- class NestedWriteVisitor {
20
- constructor(resolveField) {
21
- this.resolveField = resolveField;
22
- }
23
- isPrismaWriteAction(value) {
24
- return types_1.PrismaWriteActions.includes(value);
25
- }
26
- /**
27
- * Start visiting
28
- *
29
- * @see NestedWriterVisitorCallback
30
- */
31
- visit(model, fieldData, parentData, state, callback) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- if (!fieldData) {
34
- return;
35
- }
36
- for (const [field, payload] of Object.entries(fieldData)) {
37
- if (!payload) {
38
- continue;
39
- }
40
- const fieldInfo = yield this.resolveField(model, field);
41
- if (!fieldInfo) {
42
- continue;
43
- }
44
- if (!fieldInfo.isDataModel) {
45
- // simple field, just call action
46
- yield callback(fieldInfo, 'none', payload, fieldData, state);
47
- }
48
- else {
49
- // deal with nested write of other model, here payload is a
50
- // potentially nested structure like:
51
- //
52
- // { update: { field: {...} } }
53
- //
54
- for (const [subKey, subPayload] of Object.entries(payload)) {
55
- if (this.isPrismaWriteAction(subKey) && subPayload) {
56
- const newState = yield callback(fieldInfo, subKey, subPayload, payload, state);
57
- if (newState) {
58
- // recurse into content
59
- yield this.visit(fieldInfo.type, subPayload, payload, newState, callback);
60
- }
61
- }
62
- }
63
- }
64
- }
65
- });
66
- }
67
- }
68
- exports.NestedWriteVisitor = NestedWriteVisitor;
69
- //# sourceMappingURL=nested-write-vistor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nested-write-vistor.js","sourceRoot":"","sources":["../../../src/proxy/nested-write-vistor.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,uDAAuD;;;;;;;;;;;;AAEvD,oCAAgF;AAwBhF;;GAEG;AACH,MAAa,kBAAkB;IAC3B,YACqB,YAGkB;QAHlB,iBAAY,GAAZ,YAAY,CAGM;IACpC,CAAC;IAEI,mBAAmB,CAAC,KAAa;QACrC,OAAO,0BAAkB,CAAC,QAAQ,CAAC,KAA8B,CAAC,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACG,KAAK,CACP,KAAa,EACb,SAAc,EACd,UAAe,EACf,KAAY,EACZ,QAA4C;;YAE5C,IAAI,CAAC,SAAS,EAAE;gBACZ,OAAO;aACV;YAED,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAM,SAAS,CAAC,EAAE;gBAC3D,IAAI,CAAC,OAAO,EAAE;oBACV,SAAS;iBACZ;gBAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACxD,IAAI,CAAC,SAAS,EAAE;oBACZ,SAAS;iBACZ;gBAED,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;oBACxB,iCAAiC;oBACjC,MAAM,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;iBAChE;qBAAM;oBACH,2DAA2D;oBAC3D,qCAAqC;oBACrC,EAAE;oBACF,mCAAmC;oBACnC,EAAE;oBACF,KAAK,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAC7C,OAAO,CACV,EAAE;wBACC,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,UAAU,EAAE;4BAChD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAC3B,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,KAAK,CACR,CAAC;4BACF,IAAI,QAAQ,EAAE;gCACV,uBAAuB;gCACvB,MAAM,IAAI,CAAC,KAAK,CACZ,SAAS,CAAC,IAAI,EACd,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,CACX,CAAC;6BACL;yBACJ;qBACJ;iBACJ;aACJ;QACL,CAAC;KAAA;CACJ;AAzED,gDAyEC"}
@@ -1,78 +0,0 @@
1
- import { AuthUser, DbOperations, PolicyOperationKind } from '../types';
2
- import { Logger } from './logger';
3
- import { PolicyDef } from '../policy';
4
- /**
5
- * Creates a conjunction of a list of query conditions.
6
- */
7
- export declare function and(...conditions: unknown[]): any;
8
- /**
9
- * Creates a disjunction of a list of query conditions.
10
- */
11
- export declare function or(...conditions: unknown[]): any;
12
- /**
13
- * Wraps a value into array if it's not already one
14
- */
15
- export declare function ensureArray<T>(value: T): Array<T>;
16
- /**
17
- * Given a where condition, queries db and returns IDs of result entities
18
- */
19
- export declare function queryIds(model: string, db: Record<string, DbOperations>, where: unknown): Promise<string[]>;
20
- export declare function getAuthGuard(policy: PolicyDef, model: string, operation: PolicyOperationKind, user: AuthUser | undefined): Promise<any>;
21
- export declare function ensureAuthGuard(args: any, model: string, operation: PolicyOperationKind, user: AuthUser | undefined, policy: PolicyDef): Promise<any>;
22
- /**
23
- * Read model entities w.r.t the given query args. The result list
24
- * are guaranteed to fully satisfy 'read' policy rules recursively.
25
- *
26
- * For to-many relations involved, items not satisfying policy are
27
- * silently trimmed. For to-one relation, if relation data fails policy
28
- * an CRUDError is thrown.
29
- *
30
- * @param model the model to query for
31
- * @param queryArgs the Prisma query args
32
- * @param service the ZenStack service
33
- * @param context the query context
34
- * @param db the db (or transaction)
35
- * @returns
36
- */
37
- export declare function readWithCheck(model: string, queryArgs: any, user: AuthUser | undefined, db: Record<string, DbOperations>, policy: PolicyDef, logger: Logger): Promise<unknown[]>;
38
- /**
39
- * Validates that a model entity satisfies 'update' policy rules
40
- * before conducting an update
41
- *
42
- * @param model model under update
43
- * @param updateArgs Prisma update args
44
- * @param service the ZenStack service
45
- * @param context the query context
46
- * @param transaction the db transaction context
47
- */
48
- export declare function preUpdateCheck(model: string, updateArgs: any, user: AuthUser | undefined, transaction: Record<string, DbOperations>, policy: PolicyDef, logger: Logger): Promise<void>;
49
- /**
50
- * Given a list of ids for a model, check if they all match policy rules, and if not,
51
- * throw a CRUDError.
52
- *
53
- * @param model the model
54
- * @param ids the entity ids
55
- * @param operation the operation to check for
56
- * @param service the ZenStack service
57
- * @param context the query context
58
- * @param db the db or transaction
59
- */
60
- export declare function checkPolicyForIds(model: string, ids: string[], operation: PolicyOperationKind, user: AuthUser | undefined, db: Record<string, DbOperations>, policy: PolicyDef, logger: Logger): Promise<void>;
61
- export declare function checkPolicyForFilter(model: string, filter: any, operation: PolicyOperationKind, user: AuthUser | undefined, db: Record<string, DbOperations>, policy: PolicyDef, logger: Logger): Promise<void>;
62
- /**
63
- * Injects assignment of zenstack_transaction field for all nested
64
- * update/create in a Prisma update args recursively.
65
- *
66
- * @return a tuple containing all model types that are involved in
67
- * creation or updating, respectively
68
- */
69
- export declare function injectTransactionId(model: string, args: any, operation: 'create' | 'update', transactionId: string, policy: PolicyDef): Promise<{
70
- createdModels: string[];
71
- updatedModels: string[];
72
- }>;
73
- /**
74
- * Preprocesses the given write args to modify field values (in place) based on
75
- * attributes like @password
76
- */
77
- export declare function preprocessWritePayload(policy: PolicyDef, model: string, args: any): Promise<void>;
78
- export declare function validateModelPayload(model: string, mode: 'create' | 'update' | 'upsert', payload: unknown): Promise<void>;