oak-domain 2.5.2 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/action.d.ts +16 -16
- package/lib/actions/action.js +17 -17
- package/lib/actions/relation.d.ts +5 -5
- package/lib/actions/relation.js +38 -38
- package/lib/base-app-domain/ActionDefDict.d.ts +8 -8
- package/lib/base-app-domain/ActionDefDict.js +9 -9
- package/lib/base-app-domain/EntityDict.d.ts +14 -14
- package/lib/base-app-domain/EntityDict.js +2 -2
- package/lib/base-app-domain/Modi/Action.d.ts +10 -10
- package/lib/base-app-domain/Modi/Action.js +14 -14
- package/lib/base-app-domain/Modi/Schema.d.ts +146 -146
- package/lib/base-app-domain/Modi/Schema.js +2 -2
- package/lib/base-app-domain/Modi/Storage.d.ts +3 -3
- package/lib/base-app-domain/Modi/Storage.js +60 -60
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +189 -189
- package/lib/base-app-domain/ModiEntity/Schema.js +2 -2
- package/lib/base-app-domain/ModiEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/ModiEntity/Storage.js +27 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +144 -144
- package/lib/base-app-domain/Oper/Schema.js +2 -2
- package/lib/base-app-domain/Oper/Storage.d.ts +3 -3
- package/lib/base-app-domain/Oper/Storage.js +29 -29
- package/lib/base-app-domain/OperEntity/Schema.d.ts +205 -205
- package/lib/base-app-domain/OperEntity/Schema.js +2 -2
- package/lib/base-app-domain/OperEntity/Storage.d.ts +3 -3
- package/lib/base-app-domain/OperEntity/Storage.js +27 -27
- package/lib/base-app-domain/Storage.d.ts +3 -3
- package/lib/base-app-domain/Storage.js +17 -17
- package/lib/base-app-domain/User/Action.d.ts +10 -10
- package/lib/base-app-domain/User/Action.js +12 -12
- package/lib/base-app-domain/User/Schema.d.ts +180 -180
- package/lib/base-app-domain/User/Schema.js +2 -2
- package/lib/base-app-domain/User/Storage.d.ts +3 -3
- package/lib/base-app-domain/User/Storage.js +36 -36
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +121 -121
- package/lib/base-app-domain/UserEntityGrant/Schema.js +2 -2
- package/lib/base-app-domain/UserEntityGrant/Storage.d.ts +3 -3
- package/lib/base-app-domain/UserEntityGrant/Storage.js +28 -28
- package/lib/base-app-domain/_SubQuery.d.ts +44 -44
- package/lib/base-app-domain/_SubQuery.js +2 -2
- package/lib/base-app-domain/index.d.ts +3 -3
- package/lib/base-app-domain/index.js +6 -6
- package/lib/checkers/index.d.ts +5 -5
- package/lib/checkers/index.js +16 -16
- package/lib/compiler/env.d.ts +11 -11
- package/lib/compiler/env.js +39 -39
- package/lib/compiler/schemalBuilder.d.ts +2 -2
- package/lib/compiler/schemalBuilder.js +3355 -3355
- package/lib/compiler/uiBuilder.d.ts +1 -1
- package/lib/compiler/uiBuilder.js +3 -3
- package/lib/entities/Modi.d.ts +11 -11
- package/lib/entities/Modi.js +46 -46
- package/lib/entities/ModiEntity.d.ts +8 -8
- package/lib/entities/ModiEntity.js +15 -15
- package/lib/entities/Oper.d.ts +10 -10
- package/lib/entities/Oper.js +17 -17
- package/lib/entities/OperEntity.d.ts +8 -8
- package/lib/entities/OperEntity.js +15 -15
- package/lib/entities/User.d.ts +8 -8
- package/lib/entities/User.js +28 -28
- package/lib/entities/UserEntityGrant.d.ts +7 -7
- package/lib/entities/UserEntityGrant.js +12 -12
- package/lib/store/AsyncRowStore.d.ts +51 -48
- package/lib/store/AsyncRowStore.js +189 -183
- package/lib/store/CascadeStore.d.ts +91 -91
- package/lib/store/CascadeStore.js +1634 -1603
- package/lib/store/SyncRowStore.d.ts +29 -29
- package/lib/store/SyncRowStore.js +48 -48
- package/lib/store/TriggerExecutor.d.ts +32 -32
- package/lib/store/TriggerExecutor.js +532 -532
- package/lib/store/actionDef.d.ts +9 -9
- package/lib/store/actionDef.js +333 -333
- package/lib/store/checker.d.ts +26 -26
- package/lib/store/checker.js +829 -867
- package/lib/store/filter.d.ts +109 -109
- package/lib/store/filter.js +893 -893
- package/lib/store/modi.d.ts +13 -13
- package/lib/store/modi.js +216 -216
- package/lib/store/relation.d.ts +13 -13
- package/lib/store/relation.js +66 -66
- package/lib/store/selection.d.ts +19 -7
- package/lib/store/selection.js +265 -238
- package/lib/triggers/index.d.ts +6 -6
- package/lib/triggers/index.js +11 -11
- package/lib/triggers/modi.d.ts +5 -5
- package/lib/triggers/modi.js +72 -72
- package/lib/types/Action.d.ts +20 -20
- package/lib/types/Action.js +2 -2
- package/lib/types/AppLoader.d.ts +11 -11
- package/lib/types/AppLoader.js +10 -10
- package/lib/types/Aspect.d.ts +13 -12
- package/lib/types/Aspect.js +4 -4
- package/lib/types/Auth.d.ts +69 -69
- package/lib/types/Auth.js +2 -2
- package/lib/types/Connector.d.ts +27 -26
- package/lib/types/Connector.js +9 -9
- package/lib/types/Context.d.ts +7 -7
- package/lib/types/Context.js +3 -3
- package/lib/types/DataType.d.ts +18 -18
- package/lib/types/DataType.js +5 -5
- package/lib/types/Demand.d.ts +77 -77
- package/lib/types/Demand.js +9 -9
- package/lib/types/Endpoint.d.ts +11 -11
- package/lib/types/Endpoint.js +3 -3
- package/lib/types/Entity.d.ts +183 -183
- package/lib/types/Entity.js +14 -14
- package/lib/types/Exception.d.ts +100 -98
- package/lib/types/Exception.js +327 -283
- package/lib/types/Expression.d.ts +163 -163
- package/lib/types/Expression.js +427 -427
- package/lib/types/Geo.d.ts +18 -18
- package/lib/types/Geo.js +2 -2
- package/lib/types/Locale.d.ts +24 -24
- package/lib/types/Locale.js +2 -2
- package/lib/types/Logger.d.ts +5 -5
- package/lib/types/Logger.js +3 -3
- package/lib/types/Polyfill.d.ts +23 -23
- package/lib/types/Polyfill.js +2 -2
- package/lib/types/Port.d.ts +17 -17
- package/lib/types/Port.js +2 -2
- package/lib/types/RowStore.d.ts +12 -12
- package/lib/types/RowStore.js +34 -34
- package/lib/types/Storage.d.ts +56 -56
- package/lib/types/Storage.js +2 -2
- package/lib/types/Timer.d.ts +13 -13
- package/lib/types/Timer.js +2 -2
- package/lib/types/Trigger.d.ts +109 -109
- package/lib/types/Trigger.js +49 -49
- package/lib/types/Txn.d.ts +2 -2
- package/lib/types/Txn.js +3 -3
- package/lib/types/Watcher.d.ts +19 -19
- package/lib/types/Watcher.js +4 -4
- package/lib/types/index.d.ts +21 -21
- package/lib/types/index.js +24 -24
- package/lib/types/schema/DataTypes.d.ts +32 -32
- package/lib/types/schema/DataTypes.js +3 -3
- package/lib/utils/SimpleConnector.d.ts +35 -30
- package/lib/utils/SimpleConnector.js +134 -117
- package/lib/utils/assert.d.ts +5 -5
- package/lib/utils/assert.js +9 -9
- package/lib/utils/concurrent.d.ts +15 -15
- package/lib/utils/concurrent.js +89 -89
- package/lib/utils/cron.d.ts +1 -1
- package/lib/utils/cron.js +18 -18
- package/lib/utils/date.d.ts +1 -1
- package/lib/utils/date.js +18 -18
- package/lib/utils/geo.d.ts +4 -4
- package/lib/utils/geo.js +24 -24
- package/lib/utils/lodash.d.ts +20 -20
- package/lib/utils/lodash.js +55 -55
- package/lib/utils/random/random.d.ts +1 -1
- package/lib/utils/random/random.js +24 -24
- package/lib/utils/random/random.mp.d.ts +1 -1
- package/lib/utils/random/random.mp.js +25 -25
- package/lib/utils/random/random.web.d.ts +1 -1
- package/lib/utils/random/random.web.js +17 -17
- package/lib/utils/string.d.ts +22 -22
- package/lib/utils/string.js +70 -70
- package/lib/utils/url.d.ts +1 -0
- package/lib/utils/url.js +12 -0
- package/lib/utils/uuid.d.ts +12 -12
- package/lib/utils/uuid.js +194 -194
- package/lib/utils/validator.d.ts +23 -23
- package/lib/utils/validator.js +123 -123
- package/package.json +48 -48
- package/src/entities/Modi.ts +68 -68
- package/src/entities/ModiEntity.ts +24 -24
- package/src/entities/Oper.ts +28 -28
- package/src/entities/OperEntity.ts +24 -24
- package/src/entities/User.ts +44 -44
- package/src/entities/UserEntityGrant.ts +24 -24
package/lib/store/checker.js
CHANGED
|
@@ -1,867 +1,829 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRemoveCheckers = exports.createAuthCheckers = exports.translateCheckerInSyncContext = exports.translateCheckerInAsyncContext = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
-
var filter_1 = require("../store/filter");
|
|
7
|
-
var Exception_1 = require("../types/Exception");
|
|
8
|
-
var types_1 = require("../types");
|
|
9
|
-
var actionDef_1 = require("./actionDef");
|
|
10
|
-
var string_1 = require("../utils/string");
|
|
11
|
-
var lodash_1 = require("../utils/lodash");
|
|
12
|
-
var relation_1 = require("./relation");
|
|
13
|
-
var uuid_1 = require("../utils/uuid");
|
|
14
|
-
function translateCheckerInAsyncContext(checker) {
|
|
15
|
-
var _this = this;
|
|
16
|
-
var entity = checker.entity, type = checker.type, action = checker.action;
|
|
17
|
-
var when = ((action === 'create' || action instanceof Array && action.includes('create')) && ['relation'].includes(type)) ? 'after' : 'before';
|
|
18
|
-
switch (type) {
|
|
19
|
-
case 'data': {
|
|
20
|
-
var checkerFn_1 = checker.checker;
|
|
21
|
-
var fn = (function (_a, context) {
|
|
22
|
-
var operation = _a.operation;
|
|
23
|
-
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
24
|
-
var data;
|
|
25
|
-
return tslib_1.__generator(this, function (_b) {
|
|
26
|
-
switch (_b.label) {
|
|
27
|
-
case 0:
|
|
28
|
-
data = operation.data;
|
|
29
|
-
return [4 /*yield*/, checkerFn_1(data, context)];
|
|
30
|
-
case 1:
|
|
31
|
-
_b.sent();
|
|
32
|
-
return [2 /*return*/, 0];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
fn: fn,
|
|
39
|
-
when: when,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
case 'row': {
|
|
43
|
-
var filter_2 = checker.filter, errMsg_1 = checker.errMsg, inconsistentRows_1 = checker.inconsistentRows;
|
|
44
|
-
var fn = (function (_a, context, option) {
|
|
45
|
-
var operation = _a.operation;
|
|
46
|
-
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var operationFilter, action, filter2, _b, entity2, selection2, rows2,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
case
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return [4 /*yield*/, relationFilter_1(operation, context, option)];
|
|
139
|
-
case
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
case
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return function (userId) {
|
|
350
|
-
var _a;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
checkers.push({
|
|
419
|
-
entity: userEntityName_1,
|
|
420
|
-
action: '
|
|
421
|
-
type: 'relation',
|
|
422
|
-
relationFilter: function (operation, context) {
|
|
423
|
-
var _a;
|
|
424
|
-
var
|
|
425
|
-
|
|
426
|
-
var
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
filter
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
}
|
|
831
|
-
return context.operate(entity, {
|
|
832
|
-
id: (0, uuid_1.generateNewId)(),
|
|
833
|
-
action: 'update',
|
|
834
|
-
data: {
|
|
835
|
-
entity: null,
|
|
836
|
-
entityId: null,
|
|
837
|
-
},
|
|
838
|
-
filter: filter ? (_b = {},
|
|
839
|
-
_b[e] = filter,
|
|
840
|
-
_b) : undefined,
|
|
841
|
-
}, { dontCollect: true });
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
};
|
|
845
|
-
try {
|
|
846
|
-
for (var restEntities_1 = (e_5 = void 0, tslib_1.__values(restEntities)), restEntities_1_1 = restEntities_1.next(); !restEntities_1_1.done; restEntities_1_1 = restEntities_1.next()) {
|
|
847
|
-
var e = restEntities_1_1.value;
|
|
848
|
-
_loop_8(e);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
852
|
-
finally {
|
|
853
|
-
try {
|
|
854
|
-
if (restEntities_1_1 && !restEntities_1_1.done && (_b = restEntities_1.return)) _b.call(restEntities_1);
|
|
855
|
-
}
|
|
856
|
-
finally { if (e_5) throw e_5.error; }
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
// 注入声明的cascade删除时的外键处理动作
|
|
862
|
-
for (var entity in authDict) {
|
|
863
|
-
_loop_4(entity);
|
|
864
|
-
}
|
|
865
|
-
return checkers;
|
|
866
|
-
}
|
|
867
|
-
exports.createRemoveCheckers = createRemoveCheckers;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRemoveCheckers = exports.createAuthCheckers = exports.translateCheckerInSyncContext = exports.translateCheckerInAsyncContext = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
var filter_1 = require("../store/filter");
|
|
7
|
+
var Exception_1 = require("../types/Exception");
|
|
8
|
+
var types_1 = require("../types");
|
|
9
|
+
var actionDef_1 = require("./actionDef");
|
|
10
|
+
var string_1 = require("../utils/string");
|
|
11
|
+
var lodash_1 = require("../utils/lodash");
|
|
12
|
+
var relation_1 = require("./relation");
|
|
13
|
+
var uuid_1 = require("../utils/uuid");
|
|
14
|
+
function translateCheckerInAsyncContext(checker) {
|
|
15
|
+
var _this = this;
|
|
16
|
+
var entity = checker.entity, type = checker.type, action = checker.action;
|
|
17
|
+
var when = ((action === 'create' || action instanceof Array && action.includes('create')) && ['relation'].includes(type)) ? 'after' : 'before';
|
|
18
|
+
switch (type) {
|
|
19
|
+
case 'data': {
|
|
20
|
+
var checkerFn_1 = checker.checker;
|
|
21
|
+
var fn = (function (_a, context) {
|
|
22
|
+
var operation = _a.operation;
|
|
23
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
24
|
+
var data;
|
|
25
|
+
return tslib_1.__generator(this, function (_b) {
|
|
26
|
+
switch (_b.label) {
|
|
27
|
+
case 0:
|
|
28
|
+
data = operation.data;
|
|
29
|
+
return [4 /*yield*/, checkerFn_1(data, context)];
|
|
30
|
+
case 1:
|
|
31
|
+
_b.sent();
|
|
32
|
+
return [2 /*return*/, 0];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
fn: fn,
|
|
39
|
+
when: when,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
case 'row': {
|
|
43
|
+
var filter_2 = checker.filter, errMsg_1 = checker.errMsg, inconsistentRows_1 = checker.inconsistentRows;
|
|
44
|
+
var fn = (function (_a, context, option) {
|
|
45
|
+
var operation = _a.operation;
|
|
46
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
47
|
+
var operationFilter, action, filter2, _b, entity2, selection2, rows2, e, rows2, e;
|
|
48
|
+
return tslib_1.__generator(this, function (_c) {
|
|
49
|
+
switch (_c.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
operationFilter = operation.filter, action = operation.action;
|
|
52
|
+
if (!(typeof filter_2 === 'function')) return [3 /*break*/, 2];
|
|
53
|
+
return [4 /*yield*/, filter_2(operation, context, option)];
|
|
54
|
+
case 1:
|
|
55
|
+
_b = _c.sent();
|
|
56
|
+
return [3 /*break*/, 3];
|
|
57
|
+
case 2:
|
|
58
|
+
_b = filter_2;
|
|
59
|
+
_c.label = 3;
|
|
60
|
+
case 3:
|
|
61
|
+
filter2 = _b;
|
|
62
|
+
if (!['select', 'count', 'stat'].includes(action)) return [3 /*break*/, 4];
|
|
63
|
+
operation.filter = (0, filter_1.addFilterSegment)(operationFilter || {}, filter2);
|
|
64
|
+
return [2 /*return*/, 0];
|
|
65
|
+
case 4: return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter || {}, true)];
|
|
66
|
+
case 5:
|
|
67
|
+
if (_c.sent()) {
|
|
68
|
+
return [2 /*return*/, 0];
|
|
69
|
+
}
|
|
70
|
+
if (!inconsistentRows_1) return [3 /*break*/, 7];
|
|
71
|
+
entity2 = inconsistentRows_1.entity, selection2 = inconsistentRows_1.selection;
|
|
72
|
+
return [4 /*yield*/, context.select(entity2, selection2(operationFilter), {
|
|
73
|
+
dontCollect: true,
|
|
74
|
+
blockTrigger: true,
|
|
75
|
+
})];
|
|
76
|
+
case 6:
|
|
77
|
+
rows2 = _c.sent();
|
|
78
|
+
e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
|
|
79
|
+
e.addData(entity2, rows2);
|
|
80
|
+
throw e;
|
|
81
|
+
case 7: return [4 /*yield*/, context.select(entity, {
|
|
82
|
+
data: (0, actionDef_1.getFullProjection)(entity, context.getSchema()),
|
|
83
|
+
filter: Object.assign({}, operationFilter, {
|
|
84
|
+
$not: filter2,
|
|
85
|
+
})
|
|
86
|
+
}, {
|
|
87
|
+
dontCollect: true,
|
|
88
|
+
blockTrigger: true,
|
|
89
|
+
})];
|
|
90
|
+
case 8:
|
|
91
|
+
rows2 = _c.sent();
|
|
92
|
+
e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
|
|
93
|
+
e.addData(entity, rows2);
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
fn: fn,
|
|
101
|
+
when: when,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
case 'relation': {
|
|
105
|
+
var relationFilter_1 = checker.relationFilter, errMsg_2 = checker.errMsg;
|
|
106
|
+
var fn = (function (_a, context, option) {
|
|
107
|
+
var operation = _a.operation;
|
|
108
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
109
|
+
var filter2, data, filter, _b, _c, _d;
|
|
110
|
+
return tslib_1.__generator(this, function (_e) {
|
|
111
|
+
switch (_e.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
if (context.isRoot()) {
|
|
114
|
+
return [2 /*return*/, 0];
|
|
115
|
+
}
|
|
116
|
+
if (!(operation.action === 'create')) return [3 /*break*/, 3];
|
|
117
|
+
return [4 /*yield*/, relationFilter_1(operation, context, option)];
|
|
118
|
+
case 1:
|
|
119
|
+
filter2 = _e.sent();
|
|
120
|
+
data = operation.data;
|
|
121
|
+
filter = data instanceof Array ? {
|
|
122
|
+
id: {
|
|
123
|
+
$in: data.map(function (ele) { return ele.id; }),
|
|
124
|
+
},
|
|
125
|
+
} : {
|
|
126
|
+
id: data.id,
|
|
127
|
+
};
|
|
128
|
+
return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, filter, true)];
|
|
129
|
+
case 2:
|
|
130
|
+
if (_e.sent()) {
|
|
131
|
+
return [2 /*return*/, 0];
|
|
132
|
+
}
|
|
133
|
+
throw new Exception_1.OakUserUnpermittedException(errMsg_2);
|
|
134
|
+
case 3:
|
|
135
|
+
_b = operation;
|
|
136
|
+
_c = filter_1.combineFilters;
|
|
137
|
+
_d = [operation.filter];
|
|
138
|
+
return [4 /*yield*/, relationFilter_1(operation, context, option)];
|
|
139
|
+
case 4:
|
|
140
|
+
_b.filter = _c.apply(void 0, [_d.concat([_e.sent()])]);
|
|
141
|
+
_e.label = 5;
|
|
142
|
+
case 5: return [2 /*return*/, 0];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
fn: fn,
|
|
149
|
+
when: when,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
case 'logical':
|
|
153
|
+
case 'logicalRelation': {
|
|
154
|
+
var checkerFn_2 = checker.checker;
|
|
155
|
+
var fn = (function (_a, context, option) {
|
|
156
|
+
var operation = _a.operation;
|
|
157
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
158
|
+
return tslib_1.__generator(this, function (_b) {
|
|
159
|
+
switch (_b.label) {
|
|
160
|
+
case 0:
|
|
161
|
+
if (context.isRoot() && type === 'logicalRelation') {
|
|
162
|
+
return [2 /*return*/, 0];
|
|
163
|
+
}
|
|
164
|
+
return [4 /*yield*/, checkerFn_2(operation, context, option)];
|
|
165
|
+
case 1:
|
|
166
|
+
_b.sent();
|
|
167
|
+
return [2 /*return*/, 0];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
fn: fn,
|
|
174
|
+
when: when,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
default: {
|
|
178
|
+
(0, assert_1.default)(false);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.translateCheckerInAsyncContext = translateCheckerInAsyncContext;
|
|
183
|
+
function translateCheckerInSyncContext(checker) {
|
|
184
|
+
var entity = checker.entity, type = checker.type, action = checker.action;
|
|
185
|
+
var when = ((action === 'create' || action instanceof Array && action.includes('create')) && ['relation'].includes(type)) ? 'after' : 'before';
|
|
186
|
+
switch (type) {
|
|
187
|
+
case 'data': {
|
|
188
|
+
var checkerFn_3 = checker.checker;
|
|
189
|
+
var fn = function (operation, context) { return checkerFn_3(operation.data, context); };
|
|
190
|
+
return {
|
|
191
|
+
fn: fn,
|
|
192
|
+
when: when,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
case 'row': {
|
|
196
|
+
var filter_3 = checker.filter, errMsg_3 = checker.errMsg;
|
|
197
|
+
var fn = function (operation, context, option) {
|
|
198
|
+
var operationFilter = operation.filter, action = operation.action;
|
|
199
|
+
var filter2 = typeof filter_3 === 'function' ? filter_3(operation, context, option) : filter_3;
|
|
200
|
+
(0, assert_1.default)(operationFilter);
|
|
201
|
+
if (['select', 'count', 'stat'].includes(action)) {
|
|
202
|
+
operation.filter = (0, filter_1.addFilterSegment)(operationFilter, filter2);
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
(0, assert_1.default)(!(filter2 instanceof Promise));
|
|
207
|
+
if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter, true)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_3);
|
|
211
|
+
throw e;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
fn: fn,
|
|
216
|
+
when: when,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
case 'relation': {
|
|
220
|
+
var relationFilter_2 = checker.relationFilter, errMsg_4 = checker.errMsg;
|
|
221
|
+
var fn = function (operation, context, option) {
|
|
222
|
+
if (context.isRoot()) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
var filter2 = typeof relationFilter_2 === 'function' ? relationFilter_2(operation, context, option) : relationFilter_2;
|
|
226
|
+
var filter = operation.filter, action = operation.action;
|
|
227
|
+
var filter3 = filter;
|
|
228
|
+
if (action === 'create') {
|
|
229
|
+
var data = operation.data;
|
|
230
|
+
filter3 = data instanceof Array ? {
|
|
231
|
+
id: {
|
|
232
|
+
$in: data.map(function (ele) { return ele.id; }),
|
|
233
|
+
},
|
|
234
|
+
} : { id: data.id };
|
|
235
|
+
}
|
|
236
|
+
(0, assert_1.default)(filter3);
|
|
237
|
+
(0, assert_1.default)(!(filter2 instanceof Promise));
|
|
238
|
+
if ((0, filter_1.checkFilterContains)(entity, context, filter2, filter3, true)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
throw new Exception_1.OakUserUnpermittedException(errMsg_4);
|
|
242
|
+
};
|
|
243
|
+
return {
|
|
244
|
+
fn: fn,
|
|
245
|
+
when: when,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
case 'logical':
|
|
249
|
+
case 'logicalRelation': {
|
|
250
|
+
var checkerFn_4 = checker.checker;
|
|
251
|
+
var fn = function (operation, context, option) {
|
|
252
|
+
if (context.isRoot() && type === 'logicalRelation') {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
checkerFn_4(operation, context, option);
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
fn: fn,
|
|
259
|
+
when: when,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
default: {
|
|
263
|
+
(0, assert_1.default)(false);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.translateCheckerInSyncContext = translateCheckerInSyncContext;
|
|
268
|
+
function translateCascadeRelationFilterMaker(schema, lch, entity2) {
|
|
269
|
+
var cascadePath = lch.cascadePath, relations = lch.relations;
|
|
270
|
+
var paths = cascadePath.split('.');
|
|
271
|
+
var translateRelationFilter = function (entity) {
|
|
272
|
+
// 有两种情况,此entity和user有Relation定义,或是此entity已经指向user
|
|
273
|
+
if (entity === 'user') {
|
|
274
|
+
return function (userId) { return ({
|
|
275
|
+
id: userId,
|
|
276
|
+
}); };
|
|
277
|
+
}
|
|
278
|
+
else if (schema[entity].relation) {
|
|
279
|
+
if (relations) {
|
|
280
|
+
var diff = (0, lodash_1.difference)(relations, schema[entity].relation);
|
|
281
|
+
if (diff.length > 0) {
|
|
282
|
+
throw new Error("".concat(entity2, "\u4E0A\u67D0auth\u5B9A\u4E49\u7684relations\u4E2D\u542B\u6709\u4E0D\u53EF\u8BC6\u522B\u7684\u5173\u7CFB\u5B9A\u4E49").concat(diff.join(','), "\uFF0C \u8BF7\u4ED4\u7EC6\u68C0\u67E5"));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
var relationEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
286
|
+
return function (userId) {
|
|
287
|
+
var _a;
|
|
288
|
+
var filter = relations ? {
|
|
289
|
+
userId: userId,
|
|
290
|
+
relation: {
|
|
291
|
+
$in: relations,
|
|
292
|
+
},
|
|
293
|
+
} : {
|
|
294
|
+
userId: userId,
|
|
295
|
+
};
|
|
296
|
+
return {
|
|
297
|
+
id: {
|
|
298
|
+
$in: {
|
|
299
|
+
entity: relationEntityName_1,
|
|
300
|
+
data: (_a = {},
|
|
301
|
+
_a["".concat(entity, "Id")] = 1,
|
|
302
|
+
_a),
|
|
303
|
+
filter: filter,
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
(0, assert_1.default)(false, "".concat(entity2, "\u4E0A\u67D0auth\u5B9A\u4E49\u7684cascadePath").concat(cascadePath, "\u4E0D\u80FD\u5B9A\u4F4D\u5230User\u5BF9\u8C61\u6216\u8005\u548CUser\u5173\u8054\u7684\u5173\u7CFB\u5BF9\u8C61\uFF0C \u8BF7\u4ED4\u7EC6\u68C0\u67E5"));
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
var translateFilterMakerIter = function (entity, iter) {
|
|
314
|
+
var relation = (0, relation_1.judgeRelation)(schema, entity, paths[iter]);
|
|
315
|
+
if (iter === paths.length - 1) {
|
|
316
|
+
if (relation === 2) {
|
|
317
|
+
var filterMaker_1 = translateRelationFilter(paths[iter]);
|
|
318
|
+
return function (userId) {
|
|
319
|
+
var filter = filterMaker_1(userId);
|
|
320
|
+
(0, assert_1.default)(filter.id);
|
|
321
|
+
return {
|
|
322
|
+
entity: paths[iter],
|
|
323
|
+
entityId: filter.id,
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
(0, assert_1.default)(typeof relation === 'string');
|
|
328
|
+
var filterMaker_2 = translateRelationFilter(relation);
|
|
329
|
+
return function (userId) {
|
|
330
|
+
var _a;
|
|
331
|
+
var filter = filterMaker_2(userId);
|
|
332
|
+
(0, assert_1.default)(filter.id);
|
|
333
|
+
return _a = {},
|
|
334
|
+
_a["".concat(paths[iter], "Id")] = filter.id,
|
|
335
|
+
_a;
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
var subFilterMaker_1 = translateFilterMakerIter(paths[iter], iter + 1);
|
|
340
|
+
if (iter === 0) {
|
|
341
|
+
return function (userId) {
|
|
342
|
+
var _a;
|
|
343
|
+
var subFilter = subFilterMaker_1(userId);
|
|
344
|
+
return _a = {},
|
|
345
|
+
_a[paths[iter]] = subFilter,
|
|
346
|
+
_a;
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return function (userId) {
|
|
350
|
+
var _a;
|
|
351
|
+
return (_a = {},
|
|
352
|
+
_a[paths[iter]] = subFilterMaker_1(userId),
|
|
353
|
+
_a);
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
var filter = cascadePath ? translateFilterMakerIter(entity2, 0) : translateRelationFilter(entity2);
|
|
358
|
+
return filter;
|
|
359
|
+
}
|
|
360
|
+
function translateActionAuthFilterMaker(schema, relationItem, entity) {
|
|
361
|
+
if (relationItem instanceof Array) {
|
|
362
|
+
var maker_1 = relationItem.map(function (ele) {
|
|
363
|
+
if (ele instanceof Array) {
|
|
364
|
+
return ele.map(function (ele2) { return translateCascadeRelationFilterMaker(schema, ele2, entity); });
|
|
365
|
+
}
|
|
366
|
+
return [translateCascadeRelationFilterMaker(schema, ele, entity)];
|
|
367
|
+
});
|
|
368
|
+
return function (userId) { return ({
|
|
369
|
+
$or: maker_1.map(function (ele) { return ({
|
|
370
|
+
$and: ele.map(function (ele2) { return ele2(userId); })
|
|
371
|
+
}); })
|
|
372
|
+
}); };
|
|
373
|
+
}
|
|
374
|
+
var filterMaker = translateCascadeRelationFilterMaker(schema, relationItem, entity);
|
|
375
|
+
return function (userId) { return filterMaker(userId); };
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 根据权限定义,创建出相应的checker
|
|
379
|
+
* @param schema
|
|
380
|
+
* @param authDict
|
|
381
|
+
* @returns
|
|
382
|
+
*/
|
|
383
|
+
function createAuthCheckers(schema, authDict) {
|
|
384
|
+
var checkers = [];
|
|
385
|
+
var _loop_1 = function (entity) {
|
|
386
|
+
var _a;
|
|
387
|
+
if (authDict[entity]) {
|
|
388
|
+
var _b = authDict[entity], relationAuth = _b.relationAuth, actionAuth = _b.actionAuth;
|
|
389
|
+
if (relationAuth) {
|
|
390
|
+
var raFilterMakerDict_1 = {};
|
|
391
|
+
var userEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
392
|
+
for (var r in relationAuth) {
|
|
393
|
+
Object.assign(raFilterMakerDict_1, (_a = {},
|
|
394
|
+
_a[r] = translateActionAuthFilterMaker(schema, relationAuth[r], entity),
|
|
395
|
+
_a));
|
|
396
|
+
}
|
|
397
|
+
var entityIdAttr_1 = "".concat(entity, "Id");
|
|
398
|
+
checkers.push({
|
|
399
|
+
entity: userEntityName_1,
|
|
400
|
+
action: 'create',
|
|
401
|
+
type: 'relation',
|
|
402
|
+
relationFilter: function (operation, context) {
|
|
403
|
+
var _a;
|
|
404
|
+
var data = operation.data;
|
|
405
|
+
(0, assert_1.default)(!(data instanceof Array));
|
|
406
|
+
var _b = data, relation = _b.relation, _c = entityIdAttr_1, entityId = _b[_c];
|
|
407
|
+
var userId = context.getCurrentUserId();
|
|
408
|
+
if (!raFilterMakerDict_1[relation]) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
var filter = raFilterMakerDict_1[relation](userId);
|
|
412
|
+
return _a = {},
|
|
413
|
+
_a[entity] = filter,
|
|
414
|
+
_a;
|
|
415
|
+
},
|
|
416
|
+
errMsg: '越权操作',
|
|
417
|
+
});
|
|
418
|
+
checkers.push({
|
|
419
|
+
entity: userEntityName_1,
|
|
420
|
+
action: 'remove',
|
|
421
|
+
type: 'relation',
|
|
422
|
+
relationFilter: function (operation, context) {
|
|
423
|
+
var _a;
|
|
424
|
+
var userId = context.getCurrentUserId();
|
|
425
|
+
var filter = operation.filter;
|
|
426
|
+
var makeFilterFromRows = function (rows) {
|
|
427
|
+
var relations = (0, lodash_1.uniq)(rows.map(function (ele) { return ele.relation; }));
|
|
428
|
+
var entityIds = (0, lodash_1.uniq)(rows.map(function (ele) { return ele[entityIdAttr_1]; }));
|
|
429
|
+
(0, assert_1.default)(entityIds.length === 1, "\u5728\u56DE\u6536".concat(userEntityName_1, "\u4E0A\u6743\u9650\u65F6\uFF0C\u5355\u6B21\u56DE\u6536\u6D89\u53CA\u5230\u4E86\u4E0D\u540C\u7684\u5BF9\u8C61\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u88AB\u5141\u8BB8"));
|
|
430
|
+
// const entityId = entityIds[0]!;
|
|
431
|
+
// 所有的relation条件要同时满足and关系(注意这里的filter翻译出来是在entity对象上,不是在userEntity对象上)
|
|
432
|
+
return {
|
|
433
|
+
$and: relations.map(function (relation) { return raFilterMakerDict_1[relation]; }).filter(function (ele) { return !!ele; }).map(function (ele) {
|
|
434
|
+
var _a;
|
|
435
|
+
return (_a = {},
|
|
436
|
+
_a[entity] = ele(userId),
|
|
437
|
+
_a);
|
|
438
|
+
})
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
var toBeRemoved = context.select(userEntityName_1, {
|
|
442
|
+
data: (_a = {
|
|
443
|
+
id: 1,
|
|
444
|
+
relation: 1
|
|
445
|
+
},
|
|
446
|
+
_a[entityIdAttr_1] = 1,
|
|
447
|
+
_a),
|
|
448
|
+
filter: filter,
|
|
449
|
+
}, { dontCollect: true });
|
|
450
|
+
if (toBeRemoved instanceof Promise) {
|
|
451
|
+
return toBeRemoved.then(function (rows) { return makeFilterFromRows(rows); });
|
|
452
|
+
}
|
|
453
|
+
return makeFilterFromRows(toBeRemoved);
|
|
454
|
+
},
|
|
455
|
+
errMsg: '越权操作',
|
|
456
|
+
});
|
|
457
|
+
// 转让权限现在用update动作,只允许update userId给其它人
|
|
458
|
+
// todo 等实现的时候再写
|
|
459
|
+
}
|
|
460
|
+
if (actionAuth) {
|
|
461
|
+
var _loop_2 = function (a) {
|
|
462
|
+
var filterMaker = translateActionAuthFilterMaker(schema, actionAuth[a], entity);
|
|
463
|
+
checkers.push({
|
|
464
|
+
entity: entity,
|
|
465
|
+
action: a,
|
|
466
|
+
type: 'relation',
|
|
467
|
+
relationFilter: function (operation, context) {
|
|
468
|
+
// const { filter } = operation;
|
|
469
|
+
var filter = filterMaker(context.getCurrentUserId());
|
|
470
|
+
return filter;
|
|
471
|
+
},
|
|
472
|
+
errMsg: '定义的actionAuth中检查出来越权操作',
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
for (var a in actionAuth) {
|
|
476
|
+
_loop_2(a);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
for (var entity in schema) {
|
|
482
|
+
_loop_1(entity);
|
|
483
|
+
}
|
|
484
|
+
return checkers;
|
|
485
|
+
}
|
|
486
|
+
exports.createAuthCheckers = createAuthCheckers;
|
|
487
|
+
/**
|
|
488
|
+
* 对对象的删除,检查其是否会产生其他行上的空指针,不允许这种情况的出现
|
|
489
|
+
* @param schema
|
|
490
|
+
* @returns
|
|
491
|
+
* 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
|
|
492
|
+
*/
|
|
493
|
+
function createRemoveCheckers(schema, authDict) {
|
|
494
|
+
var e_1, _a;
|
|
495
|
+
var checkers = [];
|
|
496
|
+
// 先建立所有的一对多的关系
|
|
497
|
+
var OneToManyMatrix = {};
|
|
498
|
+
var OneToManyOnEntityMatrix = {};
|
|
499
|
+
var addToMto = function (e, f, attr) {
|
|
500
|
+
var _a;
|
|
501
|
+
if (OneToManyMatrix[f]) {
|
|
502
|
+
(_a = OneToManyMatrix[f]) === null || _a === void 0 ? void 0 : _a.push([e, attr]);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
OneToManyMatrix[f] = [[e, attr]];
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
var addToMtoEntity = function (e, fs) {
|
|
509
|
+
var e_2, _a;
|
|
510
|
+
var _b;
|
|
511
|
+
try {
|
|
512
|
+
for (var fs_1 = tslib_1.__values(fs), fs_1_1 = fs_1.next(); !fs_1_1.done; fs_1_1 = fs_1.next()) {
|
|
513
|
+
var f = fs_1_1.value;
|
|
514
|
+
if (!OneToManyOnEntityMatrix[f]) {
|
|
515
|
+
OneToManyOnEntityMatrix[f] = [e];
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
(_b = OneToManyOnEntityMatrix[f]) === null || _b === void 0 ? void 0 : _b.push(e);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
523
|
+
finally {
|
|
524
|
+
try {
|
|
525
|
+
if (fs_1_1 && !fs_1_1.done && (_a = fs_1.return)) _a.call(fs_1);
|
|
526
|
+
}
|
|
527
|
+
finally { if (e_2) throw e_2.error; }
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
for (var entity in schema) {
|
|
531
|
+
if (['operEntity', 'modiEntity', 'userEntityGrant'].includes(entity)) {
|
|
532
|
+
continue; // 系统功能性数据,不用处理
|
|
533
|
+
}
|
|
534
|
+
var attributes = schema[entity].attributes;
|
|
535
|
+
for (var attr in attributes) {
|
|
536
|
+
if (attributes[attr].type === 'ref') {
|
|
537
|
+
addToMto(entity, attributes[attr].ref, attr);
|
|
538
|
+
}
|
|
539
|
+
else if (attr === 'entity') {
|
|
540
|
+
if (attributes[attr].ref) {
|
|
541
|
+
addToMtoEntity(entity, attributes[attr].ref);
|
|
542
|
+
}
|
|
543
|
+
else if (process.env.NODE_ENV === 'development') {
|
|
544
|
+
console.warn("".concat(entity, "\u7684entity\u53CD\u6307\u6307\u9488\u627E\u4E0D\u5230\u6709\u6548\u7684\u5BF9\u8C61"));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// 当删除一时,要确认多上面没有指向一的数据
|
|
550
|
+
var entities = (0, lodash_1.union)(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix));
|
|
551
|
+
var _loop_3 = function (entity) {
|
|
552
|
+
checkers.push({
|
|
553
|
+
entity: entity,
|
|
554
|
+
action: 'remove',
|
|
555
|
+
type: 'logical',
|
|
556
|
+
checker: function (operation, context, option) {
|
|
557
|
+
var e_3, _a, e_4, _b;
|
|
558
|
+
var promises = [];
|
|
559
|
+
if (OneToManyMatrix[entity]) {
|
|
560
|
+
var _loop_5 = function (otm) {
|
|
561
|
+
var _g, _h;
|
|
562
|
+
var _j = tslib_1.__read(otm, 2), e = _j[0], attr = _j[1];
|
|
563
|
+
var proj = (_g = {
|
|
564
|
+
id: 1
|
|
565
|
+
},
|
|
566
|
+
_g[attr] = 1,
|
|
567
|
+
_g);
|
|
568
|
+
var filter = operation.filter && (_h = {},
|
|
569
|
+
_h[attr.slice(0, attr.length - 2)] = operation.filter,
|
|
570
|
+
_h);
|
|
571
|
+
var result = context.select(e, {
|
|
572
|
+
data: proj,
|
|
573
|
+
filter: filter,
|
|
574
|
+
indexFrom: 0,
|
|
575
|
+
count: 1
|
|
576
|
+
}, { dontCollect: true });
|
|
577
|
+
if (result instanceof Promise) {
|
|
578
|
+
promises.push(result.then(function (_a) {
|
|
579
|
+
var _b = tslib_1.__read(_a, 1), row = _b[0];
|
|
580
|
+
if (row) {
|
|
581
|
+
var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
582
|
+
err.addData(e, [row]);
|
|
583
|
+
throw err;
|
|
584
|
+
}
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
var _k = tslib_1.__read(result, 1), row = _k[0];
|
|
589
|
+
if (row) {
|
|
590
|
+
var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
591
|
+
err.addData(e, [row]);
|
|
592
|
+
throw err;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
try {
|
|
597
|
+
for (var _c = (e_3 = void 0, tslib_1.__values(OneToManyMatrix[entity])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
598
|
+
var otm = _d.value;
|
|
599
|
+
_loop_5(otm);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
603
|
+
finally {
|
|
604
|
+
try {
|
|
605
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
606
|
+
}
|
|
607
|
+
finally { if (e_3) throw e_3.error; }
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (OneToManyOnEntityMatrix[entity]) {
|
|
611
|
+
var _loop_6 = function (otm) {
|
|
612
|
+
var _l, _m, _o;
|
|
613
|
+
var proj = {
|
|
614
|
+
id: 1,
|
|
615
|
+
entity: 1,
|
|
616
|
+
entityId: 1,
|
|
617
|
+
};
|
|
618
|
+
var filter = operation.filter && (_l = {},
|
|
619
|
+
_l[entity] = operation.filter,
|
|
620
|
+
_l);
|
|
621
|
+
var result = context.select(otm, {
|
|
622
|
+
data: proj,
|
|
623
|
+
filter: filter,
|
|
624
|
+
indexFrom: 0,
|
|
625
|
+
count: 1
|
|
626
|
+
}, { dontCollect: true });
|
|
627
|
+
if (result instanceof Promise) {
|
|
628
|
+
promises.push(result.then(function (_a) {
|
|
629
|
+
var _b = tslib_1.__read(_a, 1), row = _b[0];
|
|
630
|
+
if (row) {
|
|
631
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
|
|
632
|
+
e.addData(otm, [row]);
|
|
633
|
+
throw e;
|
|
634
|
+
}
|
|
635
|
+
}));
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
var _p = tslib_1.__read(result, 1), row = _p[0];
|
|
639
|
+
if (row) {
|
|
640
|
+
var record = {
|
|
641
|
+
a: 's',
|
|
642
|
+
d: (_m = {},
|
|
643
|
+
_m[otm] = (_o = {},
|
|
644
|
+
_o[row.id] = row,
|
|
645
|
+
_o),
|
|
646
|
+
_m)
|
|
647
|
+
};
|
|
648
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
|
|
649
|
+
e.addData(otm, [row]);
|
|
650
|
+
throw e;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
try {
|
|
655
|
+
for (var _e = (e_4 = void 0, tslib_1.__values(OneToManyOnEntityMatrix[entity])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
656
|
+
var otm = _f.value;
|
|
657
|
+
_loop_6(otm);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
661
|
+
finally {
|
|
662
|
+
try {
|
|
663
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
664
|
+
}
|
|
665
|
+
finally { if (e_4) throw e_4.error; }
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (promises.length > 0) {
|
|
669
|
+
return Promise.all(promises).then(function () { return undefined; });
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
try {
|
|
675
|
+
for (var entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
676
|
+
var entity = entities_1_1.value;
|
|
677
|
+
_loop_3(entity);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
681
|
+
finally {
|
|
682
|
+
try {
|
|
683
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
684
|
+
}
|
|
685
|
+
finally { if (e_1) throw e_1.error; }
|
|
686
|
+
}
|
|
687
|
+
var _loop_4 = function (entity) {
|
|
688
|
+
var e_5, _b;
|
|
689
|
+
var cascadeRemove = authDict[entity].cascadeRemove;
|
|
690
|
+
if (cascadeRemove) {
|
|
691
|
+
var entitiesOnEntityAttr = [];
|
|
692
|
+
var hasAllEntity = false;
|
|
693
|
+
var _loop_7 = function (attr) {
|
|
694
|
+
if (attr === '@entity') {
|
|
695
|
+
hasAllEntity = true;
|
|
696
|
+
return "continue";
|
|
697
|
+
}
|
|
698
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
699
|
+
if (rel === 2) {
|
|
700
|
+
entitiesOnEntityAttr.push(attr);
|
|
701
|
+
checkers.push({
|
|
702
|
+
entity: attr,
|
|
703
|
+
action: 'remove',
|
|
704
|
+
type: 'logical',
|
|
705
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
706
|
+
checker: function (operation, context) {
|
|
707
|
+
var _a, _b;
|
|
708
|
+
var filter = operation.filter;
|
|
709
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
710
|
+
return context.operate(entity, {
|
|
711
|
+
id: (0, uuid_1.generateNewId)(),
|
|
712
|
+
action: 'remove',
|
|
713
|
+
data: {},
|
|
714
|
+
filter: filter ? (_a = {},
|
|
715
|
+
_a[attr] = filter,
|
|
716
|
+
_a) : undefined,
|
|
717
|
+
}, { dontCollect: true });
|
|
718
|
+
}
|
|
719
|
+
return context.operate(entity, {
|
|
720
|
+
id: (0, uuid_1.generateNewId)(),
|
|
721
|
+
action: 'update',
|
|
722
|
+
data: {
|
|
723
|
+
entity: null,
|
|
724
|
+
entityId: null,
|
|
725
|
+
},
|
|
726
|
+
filter: filter ? (_b = {},
|
|
727
|
+
_b[attr] = filter,
|
|
728
|
+
_b) : undefined,
|
|
729
|
+
}, { dontCollect: true });
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
(0, assert_1.default)(typeof rel === 'string');
|
|
735
|
+
checkers.push({
|
|
736
|
+
entity: rel,
|
|
737
|
+
action: 'remove',
|
|
738
|
+
type: 'logical',
|
|
739
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
740
|
+
checker: function (operation, context) {
|
|
741
|
+
var _a, _b, _c;
|
|
742
|
+
var filter = operation.filter;
|
|
743
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
744
|
+
return context.operate(entity, {
|
|
745
|
+
id: (0, uuid_1.generateNewId)(),
|
|
746
|
+
action: 'remove',
|
|
747
|
+
data: {},
|
|
748
|
+
filter: filter ? (_a = {},
|
|
749
|
+
_a[attr] = filter,
|
|
750
|
+
_a) : undefined,
|
|
751
|
+
}, { dontCollect: true });
|
|
752
|
+
}
|
|
753
|
+
return context.operate(entity, {
|
|
754
|
+
id: (0, uuid_1.generateNewId)(),
|
|
755
|
+
action: 'update',
|
|
756
|
+
data: (_b = {},
|
|
757
|
+
_b["".concat(attr, "Id")] = null,
|
|
758
|
+
_b),
|
|
759
|
+
filter: filter ? (_c = {},
|
|
760
|
+
_c[attr] = filter,
|
|
761
|
+
_c) : undefined,
|
|
762
|
+
}, { dontCollect: true });
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
for (var attr in cascadeRemove) {
|
|
768
|
+
_loop_7(attr);
|
|
769
|
+
}
|
|
770
|
+
if (hasAllEntity) {
|
|
771
|
+
var attributes = schema[entity].attributes;
|
|
772
|
+
var ref = attributes.entity.ref;
|
|
773
|
+
var restEntities = (0, lodash_1.difference)(ref, entitiesOnEntityAttr);
|
|
774
|
+
var _loop_8 = function (e) {
|
|
775
|
+
checkers.push({
|
|
776
|
+
entity: e,
|
|
777
|
+
action: 'remove',
|
|
778
|
+
type: 'logical',
|
|
779
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
780
|
+
checker: function (operation, context) {
|
|
781
|
+
var _a, _b;
|
|
782
|
+
var filter = operation.filter;
|
|
783
|
+
if (cascadeRemove['@entity'] === 'remove') {
|
|
784
|
+
return context.operate(entity, {
|
|
785
|
+
id: (0, uuid_1.generateNewId)(),
|
|
786
|
+
action: 'remove',
|
|
787
|
+
data: {},
|
|
788
|
+
filter: filter ? (_a = {},
|
|
789
|
+
_a[e] = filter,
|
|
790
|
+
_a) : undefined,
|
|
791
|
+
}, { dontCollect: true });
|
|
792
|
+
}
|
|
793
|
+
return context.operate(entity, {
|
|
794
|
+
id: (0, uuid_1.generateNewId)(),
|
|
795
|
+
action: 'update',
|
|
796
|
+
data: {
|
|
797
|
+
entity: null,
|
|
798
|
+
entityId: null,
|
|
799
|
+
},
|
|
800
|
+
filter: filter ? (_b = {},
|
|
801
|
+
_b[e] = filter,
|
|
802
|
+
_b) : undefined,
|
|
803
|
+
}, { dontCollect: true });
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
try {
|
|
808
|
+
for (var restEntities_1 = (e_5 = void 0, tslib_1.__values(restEntities)), restEntities_1_1 = restEntities_1.next(); !restEntities_1_1.done; restEntities_1_1 = restEntities_1.next()) {
|
|
809
|
+
var e = restEntities_1_1.value;
|
|
810
|
+
_loop_8(e);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
814
|
+
finally {
|
|
815
|
+
try {
|
|
816
|
+
if (restEntities_1_1 && !restEntities_1_1.done && (_b = restEntities_1.return)) _b.call(restEntities_1);
|
|
817
|
+
}
|
|
818
|
+
finally { if (e_5) throw e_5.error; }
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
// 注入声明的cascade删除时的外键处理动作
|
|
824
|
+
for (var entity in authDict) {
|
|
825
|
+
_loop_4(entity);
|
|
826
|
+
}
|
|
827
|
+
return checkers;
|
|
828
|
+
}
|
|
829
|
+
exports.createRemoveCheckers = createRemoveCheckers;
|