@zenstackhq/runtime 0.6.0-pre.2 → 1.0.0-alpha.101
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 +4 -0
- package/constants.js +8 -0
- package/constants.js.map +1 -0
- package/enhancements/index.d.ts +4 -0
- package/enhancements/index.js +21 -0
- package/enhancements/index.js.map +1 -0
- package/enhancements/model-meta.d.ts +9 -0
- package/enhancements/model-meta.js +25 -0
- package/enhancements/model-meta.js.map +1 -0
- package/enhancements/nested-write-vistor.d.ts +70 -0
- package/enhancements/nested-write-vistor.js +173 -0
- package/enhancements/nested-write-vistor.js.map +1 -0
- package/enhancements/omit.d.ts +5 -0
- package/enhancements/omit.js +60 -0
- package/enhancements/omit.js.map +1 -0
- package/enhancements/password.d.ts +5 -0
- package/enhancements/password.js +66 -0
- package/enhancements/password.js.map +1 -0
- package/enhancements/policy/handler.d.ts +36 -0
- package/enhancements/policy/handler.js +281 -0
- package/enhancements/policy/handler.js.map +1 -0
- package/enhancements/policy/index.d.ts +17 -0
- package/enhancements/policy/index.js +31 -0
- package/enhancements/policy/index.js.map +1 -0
- package/{lib/proxy → enhancements/policy}/logger.d.ts +3 -0
- package/{lib/proxy → enhancements/policy}/logger.js +4 -0
- package/enhancements/policy/logger.js.map +1 -0
- package/enhancements/policy/policy-utils.d.ts +94 -0
- package/enhancements/policy/policy-utils.js +755 -0
- package/enhancements/policy/policy-utils.js.map +1 -0
- package/enhancements/preset.d.ts +16 -0
- package/enhancements/preset.js +24 -0
- package/enhancements/preset.js.map +1 -0
- package/enhancements/proxy.d.ts +75 -0
- package/enhancements/proxy.js +196 -0
- package/enhancements/proxy.js.map +1 -0
- package/enhancements/types.d.ts +33 -0
- package/{lib/config.js → enhancements/types.js} +1 -1
- package/enhancements/types.js.map +1 -0
- package/enhancements/utils.d.ts +17 -0
- package/enhancements/utils.js +59 -0
- package/enhancements/utils.js.map +1 -0
- package/error.d.ts +11 -0
- package/error.js +17 -0
- package/error.js.map +1 -0
- package/index.d.ts +5 -0
- package/{lib/index.js → index.js} +3 -4
- package/index.js.map +1 -0
- package/package.json +8 -8
- package/serialization-utils.js.map +1 -0
- package/types.d.ts +101 -0
- package/types.js +16 -0
- package/types.js.map +1 -0
- package/{lib/validation.d.ts → validation.d.ts} +7 -0
- package/{lib/validation.js → validation.js} +15 -1
- package/validation.js.map +1 -0
- package/version.js +19 -0
- package/version.js.map +1 -0
- package/zod.d.ts +10 -0
- package/zod.js +17 -0
- package/zod.js.map +1 -0
- package/client/index.d.ts +0 -3
- package/client/index.js +0 -11
- package/lib/config.d.ts +0 -14
- package/lib/config.js.map +0 -1
- package/lib/constants.d.ts +0 -12
- package/lib/constants.js +0 -16
- package/lib/constants.js.map +0 -1
- package/lib/handler/data/crud.d.ts +0 -17
- package/lib/handler/data/crud.js +0 -255
- package/lib/handler/data/crud.js.map +0 -1
- package/lib/handler/data/handler.d.ts +0 -20
- package/lib/handler/data/handler.js +0 -150
- package/lib/handler/data/handler.js.map +0 -1
- package/lib/handler/data/nested-write-vistor.d.ts +0 -31
- package/lib/handler/data/nested-write-vistor.js +0 -67
- package/lib/handler/data/nested-write-vistor.js.map +0 -1
- package/lib/handler/data/policy-utils.d.ts +0 -73
- package/lib/handler/data/policy-utils.js +0 -447
- package/lib/handler/data/policy-utils.js.map +0 -1
- package/lib/handler/index.d.ts +0 -1
- package/lib/handler/index.js +0 -9
- package/lib/handler/index.js.map +0 -1
- package/lib/handler/types.d.ts +0 -28
- package/lib/handler/types.js +0 -36
- package/lib/handler/types.js.map +0 -1
- package/lib/index.d.ts +0 -6
- package/lib/index.js.map +0 -1
- package/lib/policy.d.ts +0 -11
- package/lib/policy.js +0 -10
- package/lib/policy.js.map +0 -1
- package/lib/proxy/handler.d.ts +0 -37
- package/lib/proxy/handler.js +0 -333
- package/lib/proxy/handler.js.map +0 -1
- package/lib/proxy/logger.js.map +0 -1
- package/lib/proxy/nested-write-vistor.d.ts +0 -30
- package/lib/proxy/nested-write-vistor.js +0 -69
- package/lib/proxy/nested-write-vistor.js.map +0 -1
- package/lib/proxy/policy-utils.d.ts +0 -78
- package/lib/proxy/policy-utils.js +0 -508
- package/lib/proxy/policy-utils.js.map +0 -1
- package/lib/request-handler.d.ts +0 -21
- package/lib/request-handler.js +0 -37
- package/lib/request-handler.js.map +0 -1
- package/lib/request.d.ts +0 -37
- package/lib/request.js +0 -164
- package/lib/request.js.map +0 -1
- package/lib/serialization-utils.js.map +0 -1
- package/lib/service.d.ts +0 -32
- package/lib/service.js +0 -184
- package/lib/service.js.map +0 -1
- package/lib/types.d.ts +0 -185
- package/lib/types.js +0 -71
- package/lib/types.js.map +0 -1
- package/lib/validation.js.map +0 -1
- package/lib/version.js +0 -9
- package/lib/version.js.map +0 -1
- package/server/index.d.ts +0 -16
- package/server/index.js +0 -6
- package/types/index.d.ts +0 -1
- package/types/index.js +0 -3
- /package/{lib/serialization-utils.d.ts → serialization-utils.d.ts} +0 -0
- /package/{lib/serialization-utils.js → serialization-utils.js} +0 -0
- /package/{lib/version.d.ts → version.d.ts} +0 -0
|
@@ -1,150 +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
|
-
const superjson_1 = __importDefault(require("superjson"));
|
|
16
|
-
const serialization_utils_1 = require("../../serialization-utils");
|
|
17
|
-
const types_1 = require("../../types");
|
|
18
|
-
const types_2 = require("../types");
|
|
19
|
-
const crud_1 = require("./crud");
|
|
20
|
-
(0, serialization_utils_1.registerSerializers)();
|
|
21
|
-
/**
|
|
22
|
-
* Request handler for /data endpoint which processes data CRUD requests.
|
|
23
|
-
*/
|
|
24
|
-
class DataHandler {
|
|
25
|
-
constructor(service, options) {
|
|
26
|
-
this.service = service;
|
|
27
|
-
this.options = options;
|
|
28
|
-
this.crud = new crud_1.CRUD(service);
|
|
29
|
-
}
|
|
30
|
-
handle(req, res, path) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const [model, id] = path;
|
|
33
|
-
const method = req.method;
|
|
34
|
-
const context = { user: yield this.options.getServerUser(req, res) };
|
|
35
|
-
this.service.verbose(`Data request: ${method} ${path}`);
|
|
36
|
-
if (req.body) {
|
|
37
|
-
this.service.verbose(`Request body: ${superjson_1.default.stringify(req.body)}`);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
switch (method) {
|
|
41
|
-
case 'GET':
|
|
42
|
-
yield this.get(req, res, model, id, context);
|
|
43
|
-
break;
|
|
44
|
-
case 'POST':
|
|
45
|
-
yield this.post(req, res, model, context);
|
|
46
|
-
break;
|
|
47
|
-
case 'PUT':
|
|
48
|
-
yield this.put(req, res, model, id, context);
|
|
49
|
-
break;
|
|
50
|
-
case 'DELETE':
|
|
51
|
-
yield this.del(req, res, model, id, context);
|
|
52
|
-
break;
|
|
53
|
-
default:
|
|
54
|
-
this.service.warn(`Unhandled method: ${method}`);
|
|
55
|
-
res.status(200).send({});
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
if (err instanceof types_2.CRUDError) {
|
|
61
|
-
this.service.warn(`${method} ${model}: ${err}`);
|
|
62
|
-
// in case of errors thrown directly by ZenStack
|
|
63
|
-
switch (err.code) {
|
|
64
|
-
case types_1.ServerErrorCode.DENIED_BY_POLICY:
|
|
65
|
-
case types_1.ServerErrorCode.READ_BACK_AFTER_WRITE_DENIED:
|
|
66
|
-
res.status(403).send({
|
|
67
|
-
code: err.code,
|
|
68
|
-
message: err.message,
|
|
69
|
-
});
|
|
70
|
-
break;
|
|
71
|
-
case types_1.ServerErrorCode.ENTITY_NOT_FOUND:
|
|
72
|
-
res.status(404).send({
|
|
73
|
-
code: err.code,
|
|
74
|
-
message: err.message,
|
|
75
|
-
});
|
|
76
|
-
break;
|
|
77
|
-
case types_1.ServerErrorCode.UNKNOWN:
|
|
78
|
-
res.status(500).send({
|
|
79
|
-
code: err.code,
|
|
80
|
-
message: err.message,
|
|
81
|
-
});
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
res.status(400).send({
|
|
85
|
-
code: err.code,
|
|
86
|
-
message: err.message,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
marshal(value) {
|
|
94
|
-
return JSON.parse(superjson_1.default.stringify(value));
|
|
95
|
-
}
|
|
96
|
-
unmarshal(value) {
|
|
97
|
-
if (typeof value === 'string') {
|
|
98
|
-
return superjson_1.default.parse(value);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return superjson_1.default.parse(JSON.stringify(value));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
get(req, res, model, id, context) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
// parse additional query args from "q" parameter
|
|
107
|
-
const args = req.query.q ? this.unmarshal(req.query.q) : {};
|
|
108
|
-
if (id) {
|
|
109
|
-
// GET <model>/:id, make sure "id" is injected
|
|
110
|
-
const result = yield this.crud.get(model, id, args, context);
|
|
111
|
-
if (!result) {
|
|
112
|
-
throw new types_2.CRUDError(types_1.ServerErrorCode.ENTITY_NOT_FOUND);
|
|
113
|
-
}
|
|
114
|
-
res.status(200).send(this.marshal(result));
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// GET <model>/, get list
|
|
118
|
-
const result = yield this.crud.find(model, args, context);
|
|
119
|
-
res.status(200).send(this.marshal(result));
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
post(req, res, model, context) {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
const result = yield this.crud.create(model, this.unmarshal(req.body), context);
|
|
126
|
-
res.status(201).send(this.marshal(result));
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
put(req, res, model, id, context) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
if (!id) {
|
|
132
|
-
throw new types_2.CRUDError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'missing "id" parameter');
|
|
133
|
-
}
|
|
134
|
-
const result = yield this.crud.update(model, id, this.unmarshal(req.body), context);
|
|
135
|
-
res.status(200).send(this.marshal(result));
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
del(req, res, model, id, context) {
|
|
139
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
-
if (!id) {
|
|
141
|
-
throw new types_2.CRUDError(types_1.ServerErrorCode.INVALID_REQUEST_PARAMS, 'missing "id" parameter');
|
|
142
|
-
}
|
|
143
|
-
const args = req.query.q ? this.unmarshal(req.query.q) : {};
|
|
144
|
-
const result = yield this.crud.del(model, id, args, context);
|
|
145
|
-
res.status(200).send(this.marshal(result));
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
exports.default = DataHandler;
|
|
150
|
-
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../../src/handler/data/handler.ts"],"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AC;aACL;YAED,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAC7D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC/C,CAAC;KAAA;CACJ;AArLD,8BAqLC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,67 +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
|
-
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,73 +0,0 @@
|
|
|
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 CRUDError 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 CRUDError.
|
|
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>;
|