@zenstackhq/runtime 0.3.9 → 0.3.11

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 (61) hide show
  1. package/{LICENSE.md → LICENSE} +0 -0
  2. package/client/index.d.ts +4 -0
  3. package/client/index.js +7 -0
  4. package/lib/client.d.ts +3 -0
  5. package/lib/client.js +34 -0
  6. package/lib/client.js.map +1 -0
  7. package/lib/config.d.ts +14 -0
  8. package/lib/config.js +3 -0
  9. package/lib/config.js.map +1 -0
  10. package/lib/constants.d.ts +12 -0
  11. package/lib/constants.js +16 -0
  12. package/lib/constants.js.map +1 -0
  13. package/lib/handler/data/handler.d.ts +19 -0
  14. package/lib/handler/data/handler.js +306 -0
  15. package/lib/handler/data/handler.js.map +1 -0
  16. package/lib/handler/data/nested-write-vistor.d.ts +31 -0
  17. package/lib/handler/data/nested-write-vistor.js +67 -0
  18. package/lib/handler/data/nested-write-vistor.js.map +1 -0
  19. package/lib/handler/data/policy-utils.d.ts +73 -0
  20. package/lib/handler/data/policy-utils.js +477 -0
  21. package/lib/handler/data/policy-utils.js.map +1 -0
  22. package/lib/handler/index.d.ts +1 -0
  23. package/lib/handler/index.js +9 -0
  24. package/lib/handler/index.js.map +1 -0
  25. package/lib/handler/types.d.ts +28 -0
  26. package/lib/handler/types.js +36 -0
  27. package/lib/handler/types.js.map +1 -0
  28. package/lib/index.d.ts +5 -0
  29. package/lib/index.js +22 -0
  30. package/lib/index.js.map +1 -0
  31. package/lib/request-handler.d.ts +21 -0
  32. package/lib/request-handler.js +37 -0
  33. package/lib/request-handler.js.map +1 -0
  34. package/lib/request.d.ts +16 -0
  35. package/lib/request.js +171 -0
  36. package/lib/request.js.map +1 -0
  37. package/lib/service.d.ts +32 -0
  38. package/lib/service.js +185 -0
  39. package/lib/service.js.map +1 -0
  40. package/lib/types.d.ts +168 -0
  41. package/lib/types.js +59 -0
  42. package/lib/types.js.map +1 -0
  43. package/lib/validation.d.ts +12 -0
  44. package/lib/validation.js +26 -0
  45. package/lib/validation.js.map +1 -0
  46. package/package.json +32 -7
  47. package/{auth.d.ts → server/auth.d.ts} +0 -0
  48. package/{auth.js → server/auth.js} +0 -0
  49. package/server/index.d.ts +16 -0
  50. package/server/index.js +7 -0
  51. package/{types.d.ts → types/index.d.ts} +0 -0
  52. package/{types.js → types/index.js} +0 -0
  53. package/README.md +0 -5
  54. package/client.d.ts +0 -1
  55. package/client.js +0 -3
  56. package/hooks.d.ts +0 -10
  57. package/hooks.js +0 -3
  58. package/index.d.ts +0 -3
  59. package/index.js +0 -1
  60. package/server.d.ts +0 -1
  61. package/server.js +0 -3
File without changes
@@ -0,0 +1,4 @@
1
+ export * from '.zenstack/lib/hooks';
2
+ export { HooksError, ServerErrorCode, RequestOptions } from '../lib/types';
3
+ export * as request from '../lib/request';
4
+ export * from '../lib/validation';
@@ -0,0 +1,7 @@
1
+ const request = require('../lib/request');
2
+
3
+ module.exports = {
4
+ ...require('.zenstack/lib/hooks'),
5
+ ...require('../lib/validation'),
6
+ request,
7
+ };
@@ -0,0 +1,3 @@
1
+ export { ServerErrorCode, RequestOptions } from './types';
2
+ export * as request from './request';
3
+ export * from './validation';
package/lib/client.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.request = exports.ServerErrorCode = void 0;
30
+ var types_1 = require("./types");
31
+ Object.defineProperty(exports, "ServerErrorCode", { enumerable: true, get: function () { return types_1.ServerErrorCode; } });
32
+ exports.request = __importStar(require("./request"));
33
+ __exportStar(require("./validation"), exports);
34
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0D;AAAjD,wGAAA,eAAe,OAAA;AACxB,qDAAqC;AACrC,+CAA6B"}
@@ -0,0 +1,14 @@
1
+ import { LogLevel } from './types';
2
+ /**
3
+ * Logging config definition
4
+ */
5
+ export type LogDefinition = {
6
+ level: LogLevel;
7
+ emit: 'stdout' | 'event';
8
+ };
9
+ /**
10
+ * Service configuration
11
+ */
12
+ export interface ServiceConfig {
13
+ log?: Array<LogLevel | LogDefinition>;
14
+ }
package/lib/config.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Auxiliary database field for supporting policy check for nested writes
3
+ */
4
+ export declare const TRANSACTION_FIELD_NAME = "zenstack_transaction";
5
+ /**
6
+ * Auxiliary database field for building up policy check queries
7
+ */
8
+ export declare const GUARD_FIELD_NAME = "zenstack_guard";
9
+ /**
10
+ * Default length of password hash salt (used by bcryptjs to hash password)
11
+ */
12
+ export declare const DEFAULT_PASSWORD_SALT_LENGTH = 12;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_PASSWORD_SALT_LENGTH = exports.GUARD_FIELD_NAME = exports.TRANSACTION_FIELD_NAME = void 0;
4
+ /**
5
+ * Auxiliary database field for supporting policy check for nested writes
6
+ */
7
+ exports.TRANSACTION_FIELD_NAME = 'zenstack_transaction';
8
+ /**
9
+ * Auxiliary database field for building up policy check queries
10
+ */
11
+ exports.GUARD_FIELD_NAME = 'zenstack_guard';
12
+ /**
13
+ * Default length of password hash salt (used by bcryptjs to hash password)
14
+ */
15
+ exports.DEFAULT_PASSWORD_SALT_LENGTH = 12;
16
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,sBAAsB,GAAG,sBAAsB,CAAC;AAE7D;;GAEG;AACU,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AAEjD;;GAEG;AACU,QAAA,4BAA4B,GAAG,EAAE,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { NextApiRequest, NextApiResponse } from 'next';
2
+ import { RequestHandlerOptions } from '../../request-handler';
3
+ import { DbClientContract, Service } from '../../types';
4
+ import { RequestHandler } from '../types';
5
+ /**
6
+ * Request handler for /data endpoint which processes data CRUD requests.
7
+ */
8
+ export default class DataHandler<DbClient extends DbClientContract> implements RequestHandler {
9
+ private readonly service;
10
+ private readonly options;
11
+ constructor(service: Service<DbClient>, options: RequestHandlerOptions);
12
+ handle(req: NextApiRequest, res: NextApiResponse, path: string[]): Promise<void>;
13
+ private get;
14
+ private post;
15
+ private put;
16
+ private del;
17
+ private isPrismaClientKnownRequestError;
18
+ private isPrismaClientValidationError;
19
+ }
@@ -0,0 +1,306 @@
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
+ /* eslint-disable @typescript-eslint/no-explicit-any */
16
+ const cuid_1 = __importDefault(require("cuid"));
17
+ const constants_1 = require("../../constants");
18
+ const types_1 = require("../../types");
19
+ const validation_1 = require("../../validation");
20
+ const types_2 = require("../types");
21
+ const policy_utils_1 = require("./policy-utils");
22
+ const PRISMA_ERROR_MAPPING = {
23
+ P2002: types_1.ServerErrorCode.UNIQUE_CONSTRAINT_VIOLATION,
24
+ P2003: types_1.ServerErrorCode.REFERENCE_CONSTRAINT_VIOLATION,
25
+ P2025: types_1.ServerErrorCode.REFERENCE_CONSTRAINT_VIOLATION,
26
+ };
27
+ /**
28
+ * Request handler for /data endpoint which processes data CRUD requests.
29
+ */
30
+ class DataHandler {
31
+ constructor(service, options) {
32
+ this.service = service;
33
+ this.options = options;
34
+ }
35
+ handle(req, res, path) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const [model, id] = path;
38
+ const method = req.method;
39
+ const context = { user: yield this.options.getServerUser(req, res) };
40
+ this.service.verbose(`Data request: ${method} ${path}`);
41
+ if (req.body) {
42
+ this.service.verbose(`Request body: ${JSON.stringify(req.body)}`);
43
+ }
44
+ try {
45
+ switch (method) {
46
+ case 'GET':
47
+ yield this.get(req, res, model, id, context);
48
+ break;
49
+ case 'POST':
50
+ yield this.post(req, res, model, context);
51
+ break;
52
+ case 'PUT':
53
+ yield this.put(req, res, model, id, context);
54
+ break;
55
+ case 'DELETE':
56
+ yield this.del(req, res, model, id, context);
57
+ break;
58
+ default:
59
+ this.service.warn(`Unhandled method: ${method}`);
60
+ res.status(200).send({});
61
+ break;
62
+ }
63
+ }
64
+ catch (err) {
65
+ if (err instanceof types_2.RequestHandlerError) {
66
+ this.service.warn(`${method} ${model}: ${err}`);
67
+ // in case of errors thrown directly by ZenStack
68
+ switch (err.code) {
69
+ case types_1.ServerErrorCode.DENIED_BY_POLICY:
70
+ case types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED:
71
+ res.status(403).send({
72
+ code: err.code,
73
+ message: err.message,
74
+ });
75
+ break;
76
+ case types_1.ServerErrorCode.ENTITY_NOT_FOUND:
77
+ res.status(404).send({
78
+ code: err.code,
79
+ message: err.message,
80
+ });
81
+ break;
82
+ default:
83
+ res.status(400).send({
84
+ code: err.code,
85
+ message: err.message,
86
+ });
87
+ }
88
+ }
89
+ else if (this.isPrismaClientKnownRequestError(err)) {
90
+ this.service.warn(`${method} ${model}: ${err}`);
91
+ // errors thrown by Prisma, try mapping to a known error
92
+ if (PRISMA_ERROR_MAPPING[err.code]) {
93
+ res.status(400).send({
94
+ code: PRISMA_ERROR_MAPPING[err.code],
95
+ message: (0, types_1.getServerErrorMessage)(PRISMA_ERROR_MAPPING[err.code]),
96
+ });
97
+ }
98
+ else {
99
+ res.status(400).send({
100
+ code: 'PRISMA:' + err.code,
101
+ message: 'an unhandled Prisma error occurred',
102
+ });
103
+ }
104
+ }
105
+ else if (this.isPrismaClientValidationError(err)) {
106
+ this.service.warn(`${method} ${model}: ${err}`);
107
+ // prisma validation error
108
+ res.status(400).send({
109
+ code: types_1.ServerErrorCode.INVALID_REQUEST_PARAMS,
110
+ message: (0, types_1.getServerErrorMessage)(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS),
111
+ });
112
+ }
113
+ else if (err instanceof validation_1.ValidationError) {
114
+ this.service.warn(`Field constraint validation error for model "${model}": ${err.message}`);
115
+ res.status(400).send({
116
+ code: types_1.ServerErrorCode.INVALID_REQUEST_PARAMS,
117
+ message: err.message,
118
+ });
119
+ }
120
+ else {
121
+ // generic errors
122
+ this.service.error(`An unknown error occurred: ${JSON.stringify(err)}`);
123
+ if (err instanceof Error && err.stack) {
124
+ this.service.error(err.stack);
125
+ }
126
+ res.status(500).send({
127
+ code: types_1.ServerErrorCode.UNKNOWN,
128
+ message: (0, types_1.getServerErrorMessage)(types_1.ServerErrorCode.UNKNOWN),
129
+ });
130
+ }
131
+ }
132
+ });
133
+ }
134
+ get(req, res, model, id, context) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ // parse additional query args from "q" parameter
137
+ const args = req.query.q ? JSON.parse(req.query.q) : {};
138
+ if (id) {
139
+ // GET <model>/:id, make sure "id" is injected
140
+ args.where = (0, policy_utils_1.and)(args.where, { id });
141
+ const result = yield (0, policy_utils_1.readWithCheck)(model, args, this.service, context, this.service.db);
142
+ if (result.length === 0) {
143
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.ENTITY_NOT_FOUND);
144
+ }
145
+ res.status(200).send(result[0]);
146
+ }
147
+ else {
148
+ // GET <model>/, get list
149
+ const result = yield (0, policy_utils_1.readWithCheck)(model, args, this.service, context, this.service.db);
150
+ res.status(200).send(result);
151
+ }
152
+ });
153
+ }
154
+ post(req, res, model, context) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ // validate args
157
+ const args = req.body;
158
+ if (!args) {
159
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'body is required');
160
+ }
161
+ if (!args.data) {
162
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'data field is required');
163
+ }
164
+ yield this.service.validateModelPayload(model, 'create', args.data);
165
+ // preprocess payload to modify fields as required by attribute like @password
166
+ yield (0, policy_utils_1.preprocessWritePayload)(model, args, this.service);
167
+ const transactionId = (0, cuid_1.default)();
168
+ // start an interactive transaction
169
+ const r = yield this.service.db.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
170
+ // inject transaction id into update/create payload (direct and nested)
171
+ const { createdModels } = yield (0, policy_utils_1.injectTransactionId)(model, args, 'create', transactionId, this.service);
172
+ // conduct the create
173
+ this.service.verbose(`Conducting create: ${model}:\n${JSON.stringify(args)}`);
174
+ const createResult = (yield tx[model].create(args));
175
+ // verify that the created entity pass policy check
176
+ yield (0, policy_utils_1.checkPolicyForIds)(model, [createResult.id], 'create', this.service, context, tx);
177
+ // verify that nested creates pass policy check
178
+ yield Promise.all(createdModels.map((model) => __awaiter(this, void 0, void 0, function* () {
179
+ const createdIds = yield (0, policy_utils_1.queryIds)(model, tx, {
180
+ [constants_1.TRANSACTION_FIELD_NAME]: `${transactionId}:create`,
181
+ });
182
+ this.service.verbose(`Validating nestedly created entities: ${model}#[${createdIds.join(', ')}]`);
183
+ yield (0, policy_utils_1.checkPolicyForIds)(model, createdIds, 'create', this.service, context, tx);
184
+ })));
185
+ return createResult;
186
+ }));
187
+ // verify that return data requested by query args pass policy check
188
+ const readArgs = Object.assign(Object.assign({}, args), { where: { id: r.id } });
189
+ delete readArgs.data;
190
+ try {
191
+ const result = yield (0, policy_utils_1.readWithCheck)(model, readArgs, this.service, context, this.service.db);
192
+ if (result.length === 0) {
193
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED);
194
+ }
195
+ res.status(201).send(result[0]);
196
+ }
197
+ catch (err) {
198
+ if (err instanceof types_2.RequestHandlerError &&
199
+ err.code === types_1.ServerErrorCode.DENIED_BY_POLICY) {
200
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED);
201
+ }
202
+ else {
203
+ throw err;
204
+ }
205
+ }
206
+ });
207
+ }
208
+ put(req, res, model, id, context) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ if (!id) {
211
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'missing "id" parameter');
212
+ }
213
+ const args = req.body;
214
+ if (!args) {
215
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'body is required');
216
+ }
217
+ yield this.service.validateModelPayload(model, 'update', args.data);
218
+ // preprocess payload to modify fields as required by attribute like @password
219
+ yield (0, policy_utils_1.preprocessWritePayload)(model, args, this.service);
220
+ args.where = Object.assign(Object.assign({}, args.where), { id });
221
+ const transactionId = (0, cuid_1.default)();
222
+ yield this.service.db.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
223
+ // make sure the entity (including ones involved in nested write) pass policy check
224
+ yield (0, policy_utils_1.preUpdateCheck)(model, id, args, this.service, context, tx);
225
+ // inject transaction id into update/create payload (direct and nested)
226
+ const { createdModels } = yield (0, policy_utils_1.injectTransactionId)(model, args, 'update', transactionId, this.service);
227
+ // conduct the update
228
+ this.service.verbose(`Conducting update: ${model}:\n${JSON.stringify(args)}`);
229
+ yield tx[model].update(args);
230
+ // verify that nested creates pass policy check
231
+ yield Promise.all(createdModels.map((model) => __awaiter(this, void 0, void 0, function* () {
232
+ const createdIds = yield (0, policy_utils_1.queryIds)(model, tx, {
233
+ [constants_1.TRANSACTION_FIELD_NAME]: `${transactionId}:create`,
234
+ });
235
+ this.service.verbose(`Validating nestedly created entities: ${model}#[${createdIds.join(', ')}]`);
236
+ yield (0, policy_utils_1.checkPolicyForIds)(model, createdIds, 'create', this.service, context, tx);
237
+ })));
238
+ }));
239
+ // verify that return data requested by query args pass policy check
240
+ const readArgs = Object.assign({}, args);
241
+ delete readArgs.data;
242
+ try {
243
+ const result = yield (0, policy_utils_1.readWithCheck)(model, readArgs, this.service, context, this.service.db);
244
+ if (result.length === 0) {
245
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED);
246
+ }
247
+ res.status(200).send(result[0]);
248
+ }
249
+ catch (err) {
250
+ if (err instanceof types_2.RequestHandlerError &&
251
+ err.code === types_1.ServerErrorCode.DENIED_BY_POLICY) {
252
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED);
253
+ }
254
+ else {
255
+ throw err;
256
+ }
257
+ }
258
+ });
259
+ }
260
+ del(req, res, model, id, context) {
261
+ return __awaiter(this, void 0, void 0, function* () {
262
+ if (!id) {
263
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'missing "id" parameter');
264
+ }
265
+ // ensures the item under deletion passes policy check
266
+ yield (0, policy_utils_1.checkPolicyForIds)(model, [id], 'delete', this.service, context, this.service.db);
267
+ const args = req.query.q ? JSON.parse(req.query.q) : {};
268
+ args.where = Object.assign(Object.assign({}, args.where), { id });
269
+ const r = yield this.service.db.$transaction((tx) => __awaiter(this, void 0, void 0, function* () {
270
+ // first fetch the data that needs to be returned after deletion
271
+ let readResult;
272
+ try {
273
+ const items = yield (0, policy_utils_1.readWithCheck)(model, args, this.service, context, tx);
274
+ readResult = items[0];
275
+ }
276
+ catch (err) {
277
+ if (err instanceof types_2.RequestHandlerError &&
278
+ err.code === types_1.ServerErrorCode.DENIED_BY_POLICY) {
279
+ // can't read back, just return undefined, outer logic handles it
280
+ }
281
+ else {
282
+ throw err;
283
+ }
284
+ }
285
+ // conduct the deletion
286
+ this.service.verbose(`Conducting delete ${model}:\n${JSON.stringify(args)}`);
287
+ yield tx[model].delete(args);
288
+ return readResult;
289
+ }));
290
+ if (r) {
291
+ res.status(200).send(r);
292
+ }
293
+ else {
294
+ throw new types_2.RequestHandlerError(types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED);
295
+ }
296
+ });
297
+ }
298
+ isPrismaClientKnownRequestError(err) {
299
+ return (err.__proto__.constructor.name === 'PrismaClientKnownRequestError');
300
+ }
301
+ isPrismaClientValidationError(err) {
302
+ return err.__proto__.constructor.name === 'PrismaClientValidationError';
303
+ }
304
+ }
305
+ exports.default = DataHandler;
306
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/handler/data/handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,gDAAwB;AAExB,+CAAyD;AAEzD,uCAOqB;AACrB,iDAAmD;AACnD,oCAA+D;AAC/D,iDAQwB;AAExB,MAAM,oBAAoB,GAAoC;IAC1D,KAAK,EAAE,uBAAe,CAAC,2BAA2B;IAClD,KAAK,EAAE,uBAAe,CAAC,8BAA8B;IACrD,KAAK,EAAE,uBAAe,CAAC,8BAA8B;CACxD,CAAC;AAEF;;GAEG;AACH,MAAqB,WAAW;IAG5B,YACqB,OAA0B,EAC1B,OAA8B;QAD9B,YAAO,GAAP,OAAO,CAAmB;QAC1B,YAAO,GAAP,OAAO,CAAuB;IAChD,CAAC;IAEE,MAAM,CACR,GAAmB,EACnB,GAAoB,EACpB,IAAc;;YAEd,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;YACzB,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;YAE1B,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;YAErE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC;YACxD,IAAI,GAAG,CAAC,IAAI,EAAE;gBACV,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACrE;YAED,IAAI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AAI,CAAC,CAAC,CAAC,CAAC;aAC3B;iBAAM;gBACH,MAAM,IAAI,2BAAmB,CACzB,uBAAe,CAAC,4BAA4B,CAC/C,CAAC;aACL;QACL,CAAC;KAAA;IAEO,+BAA+B,CACnC,GAAQ;QAER,OAAO,CACH,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,KAAK,+BAA+B,CACrE,CAAC;IACN,CAAC;IAEO,6BAA6B,CACjC,GAAQ;QAER,OAAO,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,KAAK,6BAA6B,CAAC;IAC5E,CAAC;CACJ;AA5dD,8BA4dC"}
@@ -0,0 +1,31 @@
1
+ import { FieldInfo, Service } from '../../types';
2
+ import { PrismaWriteActionType } from '../types';
3
+ /**
4
+ * Visitor callback function type
5
+ *
6
+ * @fieldInfo current visiting field
7
+ * @action prisma action for this field, e.g., update, create, etc.
8
+ * @fieldData data attached to the field, a scalar type for simple field
9
+ * and nested structure for model field
10
+ * @parentData parent data of @see fieldData, can be used to replace current field data
11
+ * @state a custom state
12
+ *
13
+ * @return if a truethy value is returned, recursive visiting will continue and the return
14
+ * value will be used as the new state passed to visiting of the direct child level; otherwise
15
+ * visiting is stopped at this level
16
+ */
17
+ export type NestedWriterVisitorCallback<State = unknown> = (fieldInfo: FieldInfo, action: PrismaWriteActionType, fieldData: any, parentData: any, state: State) => Promise<State | undefined>;
18
+ /**
19
+ * Recursive visitor for nested write (create/update) payload
20
+ */
21
+ export declare class NestedWriteVisitor<State> {
22
+ private readonly service;
23
+ constructor(service: Service);
24
+ private isPrismaWriteAction;
25
+ /**
26
+ * Start visiting
27
+ *
28
+ * @see NestedWriterVisitorCallback
29
+ */
30
+ visit(model: string, fieldData: any, parentData: any, state: State, callback: NestedWriterVisitorCallback<State>): Promise<void>;
31
+ }
@@ -0,0 +1,67 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NestedWriteVisitor = void 0;
13
+ const types_1 = require("../types");
14
+ /**
15
+ * Recursive visitor for nested write (create/update) payload
16
+ */
17
+ class NestedWriteVisitor {
18
+ constructor(service) {
19
+ this.service = service;
20
+ }
21
+ isPrismaWriteAction(value) {
22
+ return types_1.PrismaWriteActions.includes(value);
23
+ }
24
+ /**
25
+ * Start visiting
26
+ *
27
+ * @see NestedWriterVisitorCallback
28
+ */
29
+ visit(model, fieldData, parentData, state, callback) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ if (!fieldData) {
32
+ return;
33
+ }
34
+ for (const [field, payload] of Object.entries(fieldData)) {
35
+ if (!payload) {
36
+ continue;
37
+ }
38
+ const fieldInfo = yield this.service.resolveField(model, field);
39
+ if (!fieldInfo) {
40
+ continue;
41
+ }
42
+ if (!fieldInfo.isDataModel) {
43
+ // simple field, just call action
44
+ yield callback(fieldInfo, 'none', payload, fieldData, state);
45
+ }
46
+ else {
47
+ // deal with nested write of other model, here payload is a
48
+ // potentially nested structure like:
49
+ //
50
+ // { update: { field: {...} } }
51
+ //
52
+ for (const [subKey, subPayload] of Object.entries(payload)) {
53
+ if (this.isPrismaWriteAction(subKey) && subPayload) {
54
+ const newState = yield callback(fieldInfo, subKey, subPayload, payload, state);
55
+ if (newState) {
56
+ // recurse into content
57
+ yield this.visit(fieldInfo.type, subPayload, payload, newState, callback);
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ });
64
+ }
65
+ }
66
+ exports.NestedWriteVisitor = NestedWriteVisitor;
67
+ //# sourceMappingURL=nested-write-vistor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nested-write-vistor.js","sourceRoot":"","sources":["../../../../src/handler/data/nested-write-vistor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oCAAqE;AAwBrE;;GAEG;AACH,MAAa,kBAAkB;IAC3B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEzC,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,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBAChE,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;AApED,gDAoEC"}
@@ -0,0 +1,73 @@
1
+ import { DbOperations, PolicyOperationKind, QueryContext, Service } from '../../types';
2
+ /**
3
+ * Creates a conjunction of a list of query conditions.
4
+ */
5
+ export declare function and(...conditions: unknown[]): any;
6
+ /**
7
+ * Creates a disjunction of a list of query conditions.
8
+ */
9
+ export declare function or(...conditions: unknown[]): any;
10
+ /**
11
+ * Wraps a value into array if it's not already one
12
+ */
13
+ export declare function ensureArray<T>(value: T): Array<T>;
14
+ /**
15
+ * Given a where condition, queries db and returns IDs of result entities
16
+ */
17
+ export declare function queryIds(model: string, db: Record<string, DbOperations>, where: unknown): Promise<string[]>;
18
+ /**
19
+ * Read model entities w.r.t the given query args. The result list
20
+ * are guaranteed to fully satisfy 'read' policy rules recursively.
21
+ *
22
+ * For to-many relations involved, items not satisfying policy are
23
+ * silently trimmed. For to-one relation, if relation data fails policy
24
+ * an RequestHandlerError is thrown.
25
+ *
26
+ * @param model the model to query for
27
+ * @param queryArgs the Prisma query args
28
+ * @param service the ZenStack service
29
+ * @param context the query context
30
+ * @param db the db (or transaction)
31
+ * @returns
32
+ */
33
+ export declare function readWithCheck(model: string, queryArgs: any, service: Service, context: QueryContext, db: Record<string, DbOperations>): Promise<unknown[]>;
34
+ /**
35
+ * Validates that a model entity satisfies 'update' policy rules
36
+ * before conducting an update
37
+ *
38
+ * @param model model under update
39
+ * @param id id of entity under update
40
+ * @param updateArgs Prisma update args
41
+ * @param service the ZenStack service
42
+ * @param context the query context
43
+ * @param transaction the db transaction context
44
+ */
45
+ export declare function preUpdateCheck(model: string, id: string, updateArgs: any, service: Service, context: QueryContext, transaction: Record<string, DbOperations>): Promise<void>;
46
+ /**
47
+ * Given a list of ids for a model, check if they all match policy rules, and if not,
48
+ * throw a RequestHandlerError.
49
+ *
50
+ * @param model the model
51
+ * @param ids the entity ids
52
+ * @param operation the operation to check for
53
+ * @param service the ZenStack service
54
+ * @param context the query context
55
+ * @param db the db or transaction
56
+ */
57
+ export declare function checkPolicyForIds(model: string, ids: string[], operation: PolicyOperationKind, service: Service, context: QueryContext, db: Record<string, DbOperations>): Promise<void>;
58
+ /**
59
+ * Injects assignment of zenstack_transaction field for all nested
60
+ * update/create in a Prisma update args recursively.
61
+ *
62
+ * @return a tuple containing all model types that are involved in
63
+ * creation or updating, respectively
64
+ */
65
+ export declare function injectTransactionId(model: string, args: any, operation: PolicyOperationKind, transactionId: string, service: Service): Promise<{
66
+ createdModels: string[];
67
+ updatedModels: string[];
68
+ }>;
69
+ /**
70
+ * Preprocesses the given write args to modify field values (in place) based on
71
+ * attributes like @password
72
+ */
73
+ export declare function preprocessWritePayload(model: string, args: any, service: Service): Promise<void>;