oak-domain 2.6.9 → 3.0.0
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 +1 -1
- package/lib/actions/action.js +2 -2
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +25 -21
- package/lib/base-app-domain/ActionAuth/Storage.js +6 -13
- package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
- package/lib/base-app-domain/ActionDefDict.js +3 -1
- package/lib/base-app-domain/EntityDict.d.ts +2 -0
- package/lib/base-app-domain/I18n/Schema.d.ts +129 -0
- package/lib/base-app-domain/I18n/Schema.js +2 -0
- package/lib/base-app-domain/I18n/Storage.d.ts +3 -0
- package/lib/base-app-domain/I18n/Storage.js +59 -0
- package/lib/base-app-domain/Modi/Action.d.ts +1 -1
- package/lib/base-app-domain/Modi/Schema.d.ts +10 -9
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +42 -28
- package/lib/base-app-domain/ModiEntity/Storage.js +1 -1
- package/lib/base-app-domain/Oper/Schema.d.ts +15 -13
- package/lib/base-app-domain/OperEntity/Schema.d.ts +41 -27
- package/lib/base-app-domain/OperEntity/Storage.js +1 -1
- package/lib/base-app-domain/Relation/Schema.d.ts +50 -22
- package/lib/base-app-domain/Relation/Storage.js +1 -4
- package/lib/base-app-domain/Relation.d.ts +10 -0
- package/lib/base-app-domain/Relation.js +10 -0
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +67 -43
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -12
- package/lib/base-app-domain/Storage.js +20 -18
- package/lib/base-app-domain/User/Action.d.ts +1 -1
- package/lib/base-app-domain/User/Schema.d.ts +20 -14
- package/lib/base-app-domain/User/Storage.js +1 -2
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -0
- package/lib/base-app-domain/UserEntityGrant/Action.js +5 -0
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +53 -17
- package/lib/base-app-domain/UserEntityGrant/Storage.js +5 -7
- package/lib/base-app-domain/UserRelation/Schema.d.ts +35 -16
- package/lib/base-app-domain/UserRelation/Storage.js +21 -1
- package/lib/base-app-domain/_SubQuery.d.ts +40 -4
- package/lib/base-app-domain/index.d.ts +1 -0
- package/lib/base-app-domain/index.js +1 -0
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +2 -5
- package/lib/compiler/env.d.ts +3 -1
- package/lib/compiler/env.js +12 -2
- package/lib/compiler/localeBuilder.d.ts +22 -0
- package/lib/compiler/localeBuilder.js +169 -0
- package/lib/compiler/schemalBuilder.d.ts +9 -0
- package/lib/compiler/schemalBuilder.js +774 -362
- package/lib/entities/ActionAuth.d.ts +3 -2
- package/lib/entities/ActionAuth.js +21 -22
- package/lib/entities/I18n.d.ts +9 -0
- package/lib/entities/I18n.js +37 -0
- package/lib/entities/Modi.js +35 -33
- package/lib/entities/ModiEntity.js +12 -10
- package/lib/entities/Oper.js +15 -13
- package/lib/entities/OperEntity.js +12 -10
- package/lib/entities/Relation.d.ts +3 -3
- package/lib/entities/Relation.js +27 -25
- package/lib/entities/RelationAuth.d.ts +2 -5
- package/lib/entities/RelationAuth.js +27 -23
- package/lib/entities/User.js +20 -18
- package/lib/entities/UserEntityGrant.d.ts +2 -1
- package/lib/entities/UserEntityGrant.js +12 -7
- package/lib/entities/UserRelation.d.ts +3 -0
- package/lib/entities/UserRelation.js +30 -20
- package/lib/store/AsyncRowStore.d.ts +3 -0
- package/lib/store/AsyncRowStore.js +3 -0
- package/lib/store/CascadeStore.d.ts +9 -3
- package/lib/store/CascadeStore.js +247 -113
- package/lib/store/RelationAuth.d.ts +96 -0
- package/lib/store/RelationAuth.js +1307 -0
- package/lib/store/TriggerExecutor.d.ts +1 -2
- package/lib/store/TriggerExecutor.js +22 -22
- package/lib/store/actionAuth.d.ts +4 -0
- package/lib/store/actionAuth.js +40 -0
- package/lib/store/actionDef.d.ts +4 -3
- package/lib/store/actionDef.js +63 -45
- package/lib/store/checker.d.ts +2 -9
- package/lib/store/checker.js +39 -815
- package/lib/store/filter.d.ts +31 -18
- package/lib/store/filter.js +1256 -422
- package/lib/store/modi.d.ts +1 -1
- package/lib/store/modi.js +108 -9
- package/lib/store/relation.d.ts +3 -4
- package/lib/timers/oper.js +1 -1
- package/lib/timers/vaccum.js +2 -2
- package/lib/triggers/index.d.ts +2 -3
- package/lib/triggers/index.js +2 -5
- package/lib/types/Auth.d.ts +5 -0
- package/lib/types/DataType.d.ts +3 -0
- package/lib/types/Demand.d.ts +11 -0
- package/lib/types/Demand.js +2 -1
- package/lib/types/Entity.d.ts +10 -3
- package/lib/types/EntityDesc.d.ts +8 -0
- package/lib/types/EntityDesc.js +2 -0
- package/lib/types/Environment.d.ts +57 -0
- package/lib/types/Environment.js +2 -0
- package/lib/types/Exception.d.ts +6 -0
- package/lib/types/Exception.js +25 -1
- package/lib/types/Logger.d.ts +1 -0
- package/lib/types/Port.d.ts +3 -2
- package/lib/types/RowStore.d.ts +6 -4
- package/lib/types/Style.d.ts +1 -1
- package/lib/types/Trigger.d.ts +4 -5
- package/lib/types/Trigger.js +11 -6
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/SimpleConnector.js +1 -1
- package/lib/utils/money.js +1 -1
- package/lib/utils/string.d.ts +6 -0
- package/lib/utils/string.js +13 -1
- package/lib/utils/uuid.d.ts +5 -0
- package/lib/utils/uuid.js +64 -1
- package/package.json +3 -3
- package/src/entities/ActionAuth.ts +25 -33
- package/src/entities/I18n.ts +46 -0
- package/src/entities/Modi.ts +36 -36
- package/src/entities/ModiEntity.ts +14 -13
- package/src/entities/Oper.ts +17 -16
- package/src/entities/OperEntity.ts +13 -11
- package/src/entities/Relation.ts +31 -37
- package/src/entities/RelationAuth.ts +31 -37
- package/src/entities/User.ts +24 -21
- package/src/entities/UserEntityGrant.ts +16 -14
- package/src/entities/UserRelation.ts +33 -27
- package/lib/triggers/modi.d.ts +0 -5
- package/lib/triggers/modi.js +0 -72
package/lib/store/checker.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCreateCheckers = exports.createRemoveCheckers = exports.
|
|
3
|
+
exports.createCreateCheckers = exports.createRemoveCheckers = exports.translateCheckerInSyncContext = exports.translateCheckerInAsyncContext = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var filter_1 = require("../store/filter");
|
|
7
7
|
var Exception_1 = require("../types/Exception");
|
|
8
8
|
var types_1 = require("../types");
|
|
9
9
|
var actionDef_1 = require("./actionDef");
|
|
10
|
-
var string_1 = require("../utils/string");
|
|
11
10
|
var lodash_1 = require("../utils/lodash");
|
|
12
|
-
var relation_1 = require("./relation");
|
|
13
|
-
var uuid_1 = require("../utils/uuid");
|
|
14
11
|
var action_1 = require("../actions/action");
|
|
15
12
|
/**
|
|
16
13
|
*
|
|
@@ -67,7 +64,7 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
67
64
|
case 3:
|
|
68
65
|
filter2 = _b;
|
|
69
66
|
if (!['select', 'count', 'stat'].includes(action)) return [3 /*break*/, 4];
|
|
70
|
-
operation.filter = (0, filter_1.
|
|
67
|
+
operation.filter = (0, filter_1.combineFilters)(entity, context.getSchema(), [operationFilter, filter2]);
|
|
71
68
|
return [2 /*return*/, 0];
|
|
72
69
|
case 4: return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter || {}, true)];
|
|
73
70
|
case 5:
|
|
@@ -137,7 +134,7 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
137
134
|
return [2 /*return*/, 0];
|
|
138
135
|
}
|
|
139
136
|
if (['select', 'count', 'stat'].includes(action)) {
|
|
140
|
-
operation.filter = (0, filter_1.
|
|
137
|
+
operation.filter = (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, result]);
|
|
141
138
|
return [2 /*return*/, 0];
|
|
142
139
|
}
|
|
143
140
|
(0, assert_1.default)(filter);
|
|
@@ -266,650 +263,14 @@ function translateCheckerInSyncContext(checker) {
|
|
|
266
263
|
}
|
|
267
264
|
}
|
|
268
265
|
exports.translateCheckerInSyncContext = translateCheckerInSyncContext;
|
|
269
|
-
function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
|
|
270
|
-
var cascadePath = lch.cascadePath, relations = lch.relations;
|
|
271
|
-
var paths = cascadePath ? cascadePath.split('.') : [];
|
|
272
|
-
if (pathPrefix) {
|
|
273
|
-
paths.unshift(pathPrefix);
|
|
274
|
-
}
|
|
275
|
-
var translateRelationFilter = function (entity) {
|
|
276
|
-
// 有两种情况,此entity和user有Relation定义,或是此entity已经指向user
|
|
277
|
-
if (entity === 'user') {
|
|
278
|
-
return function (userId) { return ({
|
|
279
|
-
id: userId,
|
|
280
|
-
}); };
|
|
281
|
-
}
|
|
282
|
-
else if (schema[entity].relation) {
|
|
283
|
-
if (relations) {
|
|
284
|
-
var diff = (0, lodash_1.difference)(relations, schema[entity].relation);
|
|
285
|
-
if (diff.length > 0) {
|
|
286
|
-
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"));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
var relationEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
290
|
-
return function (userId) {
|
|
291
|
-
var _a;
|
|
292
|
-
var filter = relations ? {
|
|
293
|
-
userId: userId,
|
|
294
|
-
relation: {
|
|
295
|
-
$in: relations,
|
|
296
|
-
},
|
|
297
|
-
} : {
|
|
298
|
-
userId: userId,
|
|
299
|
-
};
|
|
300
|
-
return {
|
|
301
|
-
id: {
|
|
302
|
-
$in: {
|
|
303
|
-
entity: relationEntityName_1,
|
|
304
|
-
data: (_a = {},
|
|
305
|
-
_a["".concat(entity, "Id")] = 1,
|
|
306
|
-
_a),
|
|
307
|
-
filter: filter,
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
(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"));
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
var translateFilterMakerIter = function (entity, iter) {
|
|
318
|
-
var relation = (0, relation_1.judgeRelation)(schema, entity, paths[iter]);
|
|
319
|
-
(0, assert_1.default)(relation === 2 || typeof relation === 'string');
|
|
320
|
-
if (iter === paths.length - 1) {
|
|
321
|
-
if (relation === 2) {
|
|
322
|
-
var filterMaker2_1 = translateRelationFilter(paths[iter]);
|
|
323
|
-
return function (userId) {
|
|
324
|
-
var filter = filterMaker2_1(userId);
|
|
325
|
-
(0, assert_1.default)(filter.id);
|
|
326
|
-
return {
|
|
327
|
-
entity: paths[iter],
|
|
328
|
-
entityId: filter.id,
|
|
329
|
-
};
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
var filterMaker2_2 = translateRelationFilter(relation);
|
|
333
|
-
return function (userId) {
|
|
334
|
-
var _a;
|
|
335
|
-
var filter = filterMaker2_2(userId);
|
|
336
|
-
(0, assert_1.default)(filter.id);
|
|
337
|
-
return _a = {},
|
|
338
|
-
_a["".concat(paths[iter], "Id")] = filter.id,
|
|
339
|
-
_a;
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
var filterMaker_1 = relation === 2 ? translateFilterMakerIter(paths[iter], iter + 1) : translateFilterMakerIter(relation, iter + 1);
|
|
344
|
-
return function (userId) {
|
|
345
|
-
var _a;
|
|
346
|
-
return (_a = {},
|
|
347
|
-
_a[paths[iter]] = filterMaker_1(userId),
|
|
348
|
-
_a);
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
var filterMaker = paths.length ? translateFilterMakerIter(entity2, 0) : translateRelationFilter(entity2);
|
|
353
|
-
if (!paths.length) {
|
|
354
|
-
// 不可能是create
|
|
355
|
-
return function (oper, userId) { return filterMaker(userId); };
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* 针对第一层做一下特别优化,比如对象A指向对象B(多对一),如果A的cascadePath是 'B',
|
|
359
|
-
* 当create A时,会带有Bid。此时生成该B对象上的相关表达式查询返回,可以避免必须将此判定在对象创建之后再做
|
|
360
|
-
* 另一使用场景是,在查询A时,如果带有Bid(在对象跳一对多子对象场景下很常见),可以提前判定这个查询对某些用户一定返回空集
|
|
361
|
-
*
|
|
362
|
-
* 20230306:
|
|
363
|
-
* 在前台的权限判断中,会将list上的filter当成内在的限制对create动作进行判断,此时有一种可能是,filter并不能直接判断出外键,但会限制外键的查询范围。
|
|
364
|
-
* 例如,在jichuang项目中,就存在park/list上,平台的用户去访问时,其查询条件是{ system: { platformId: 1 }};而用户的关系落在system.platform.platformProvider上,
|
|
365
|
-
* 此时如直接通过data上的外键判断就会失败,需要通过对filter上相应的语义解构,进行进一步的判断
|
|
366
|
-
*/
|
|
367
|
-
var _a = tslib_1.__read(paths, 1), attr = _a[0];
|
|
368
|
-
var relation = (0, relation_1.judgeRelation)(schema, entity2, attr);
|
|
369
|
-
(0, assert_1.default)(relation === 2 || typeof relation === 'string');
|
|
370
|
-
var filterMaker2 = paths.length > 1
|
|
371
|
-
? (relation === 2 ? translateFilterMakerIter(attr, 1) : translateFilterMakerIter(relation, 1))
|
|
372
|
-
: (relation === 2 ? translateRelationFilter(attr) : translateRelationFilter(relation));
|
|
373
|
-
var translateCreateFilterMaker = function (entity, filter, userId) {
|
|
374
|
-
var counters = [];
|
|
375
|
-
if (filter) {
|
|
376
|
-
if (relation === 2) {
|
|
377
|
-
if (filter.entity === attr && filter.entityId) {
|
|
378
|
-
// 这里对entityId的限定的数据只要和userId有一条relation,就不能否定可能会有创建动作(外键在最终create时,data上一定会有判定)
|
|
379
|
-
counters.push({
|
|
380
|
-
$entity: attr,
|
|
381
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: filter.entityId }),
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
if (filter[attr]) {
|
|
385
|
-
counters.push({
|
|
386
|
-
$entity: attr,
|
|
387
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), filter[attr]),
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
(0, assert_1.default)(typeof relation === 'string');
|
|
393
|
-
if (filter["".concat(attr, "Id")]) {
|
|
394
|
-
var filterMaker3 = paths.length > 1 ? translateFilterMakerIter(relation, 1) : translateRelationFilter(relation);
|
|
395
|
-
// 这里对attrId的限定的数据只要和userId有一条relation,就不能否定可能会有创建动作(外键在最终create时,data上一定会有判定)
|
|
396
|
-
counters.push({
|
|
397
|
-
$entity: relation,
|
|
398
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker3(userId), { id: filter["".concat(attr, "Id")] }),
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
if (filter[attr]) {
|
|
402
|
-
counters.push({
|
|
403
|
-
$entity: relation,
|
|
404
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), filter[attr]),
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
if (filter.$and) {
|
|
409
|
-
var countersAnd = filter.$and.map(function (ele) { return translateCreateFilterMaker(entity, ele, userId); });
|
|
410
|
-
// and 只要有一个满足就行
|
|
411
|
-
var ca2 = countersAnd.filter(function (ele) { return !(ele instanceof Exception_1.OakUserUnpermittedException); });
|
|
412
|
-
counters.push.apply(counters, tslib_1.__spreadArray([], tslib_1.__read(ca2), false));
|
|
413
|
-
}
|
|
414
|
-
if (filter.$or) {
|
|
415
|
-
var countersOr = filter.$or.map(function (ele) { return translateCreateFilterMaker(entity, ele, userId); });
|
|
416
|
-
// or也只要有一个满足就行(不能否定)
|
|
417
|
-
var co2 = countersOr.filter(function (ele) { return !(ele instanceof Exception_1.OakUserUnpermittedException); });
|
|
418
|
-
counters.push.apply(counters, tslib_1.__spreadArray([], tslib_1.__read(co2), false));
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
if (counters.length === 0) {
|
|
422
|
-
// 一个counter都找不出来,说明当前路径上不满足
|
|
423
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
424
|
-
}
|
|
425
|
-
else if (counters.length === 1) {
|
|
426
|
-
return counters[0];
|
|
427
|
-
}
|
|
428
|
-
// 是or关系,只要其中有一个满足就可以通过
|
|
429
|
-
return {
|
|
430
|
-
$$or: counters,
|
|
431
|
-
};
|
|
432
|
-
};
|
|
433
|
-
return function (operation, userId) {
|
|
434
|
-
var action = operation.action;
|
|
435
|
-
if (action === 'create') {
|
|
436
|
-
var data = operation.data;
|
|
437
|
-
if (data) {
|
|
438
|
-
// 有data的情形根据data判定
|
|
439
|
-
var getForeignKeyId_1 = function (d) {
|
|
440
|
-
if (relation === 2) {
|
|
441
|
-
if (d.entity === attr && typeof d.entityId === 'string') {
|
|
442
|
-
return d.entityId;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
(0, assert_1.default)(typeof relation === 'string');
|
|
447
|
-
if (typeof d["".concat(attr, "Id")] === 'string') {
|
|
448
|
-
return d["".concat(attr, "Id")];
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
if (relation === 2) {
|
|
453
|
-
if (data instanceof Array) {
|
|
454
|
-
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }).filter(function (ele) { return !!ele; }));
|
|
455
|
-
if (fkIds.length === 0) {
|
|
456
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
457
|
-
}
|
|
458
|
-
return {
|
|
459
|
-
$entity: attr,
|
|
460
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
|
|
461
|
-
$count: fkIds.length,
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
var fkId_1 = getForeignKeyId_1(data);
|
|
465
|
-
if (!fkId_1) {
|
|
466
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
467
|
-
}
|
|
468
|
-
return {
|
|
469
|
-
$entity: attr,
|
|
470
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId_1 }),
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
(0, assert_1.default)(typeof relation === 'string');
|
|
474
|
-
if (data instanceof Array) {
|
|
475
|
-
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }).filter(function (ele) { return !!ele; }));
|
|
476
|
-
if (fkIds.length === 0) {
|
|
477
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
478
|
-
}
|
|
479
|
-
return {
|
|
480
|
-
$entity: relation,
|
|
481
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
|
|
482
|
-
$count: fkIds.length,
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
var fkId = getForeignKeyId_1(data);
|
|
486
|
-
if (!fkId) {
|
|
487
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
488
|
-
}
|
|
489
|
-
return {
|
|
490
|
-
$entity: relation,
|
|
491
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId }),
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
else {
|
|
495
|
-
// todo
|
|
496
|
-
var filter_4 = operation.filter;
|
|
497
|
-
if (filter_4) {
|
|
498
|
-
var counter = translateCreateFilterMaker(entity2, filter_4, userId);
|
|
499
|
-
// if (counter instanceof OakUserUnpermittedException) {
|
|
500
|
-
// throw counter;
|
|
501
|
-
// }
|
|
502
|
-
return counter;
|
|
503
|
-
}
|
|
504
|
-
throw new Exception_1.OakUserUnpermittedException();
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
var filter = operation.filter;
|
|
508
|
-
if (relation === 2 && (filter === null || filter === void 0 ? void 0 : filter.entity) === attr && (filter === null || filter === void 0 ? void 0 : filter.entityId)) {
|
|
509
|
-
if (typeof filter.entityId === 'string') {
|
|
510
|
-
return {
|
|
511
|
-
$entity: attr,
|
|
512
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: filter.entityId }),
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
else if (filter.entityId.$in && filter.entityId.$in instanceof Array) {
|
|
516
|
-
var entityIds = (0, lodash_1.uniq)(filter.entityId.$in);
|
|
517
|
-
return {
|
|
518
|
-
$entity: relation,
|
|
519
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: entityIds } }),
|
|
520
|
-
$count: entityIds.length,
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
else if (filter && filter["".concat(attr, "Id")]) {
|
|
525
|
-
if (typeof filter["".concat(attr, "Id")] === 'string') {
|
|
526
|
-
return {
|
|
527
|
-
$entity: attr,
|
|
528
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: filter["".concat(attr, "Id")] }),
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
else if (filter["".concat(attr, "Id")].$in && filter["".concat(attr, "Id")].$in instanceof Array) {
|
|
532
|
-
var entityIds = (0, lodash_1.uniq)(filter["".concat(attr, "Id")].$in);
|
|
533
|
-
return {
|
|
534
|
-
$entity: relation,
|
|
535
|
-
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: entityIds } }),
|
|
536
|
-
$count: entityIds.length,
|
|
537
|
-
};
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
return filterMaker(userId);
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
function translateActionAuthFilterMaker(schema, relationItem, entity, pathPrefix) {
|
|
544
|
-
if (relationItem instanceof Array) {
|
|
545
|
-
var maker = relationItem.map(function (ele) {
|
|
546
|
-
if (ele instanceof Array) {
|
|
547
|
-
return ele.map(function (ele2) { return translateCascadeRelationFilterMaker(schema, ele2, entity, pathPrefix); });
|
|
548
|
-
}
|
|
549
|
-
return translateCascadeRelationFilterMaker(schema, ele, entity, pathPrefix);
|
|
550
|
-
});
|
|
551
|
-
return maker;
|
|
552
|
-
}
|
|
553
|
-
var filterMaker = translateCascadeRelationFilterMaker(schema, relationItem, entity, pathPrefix);
|
|
554
|
-
return filterMaker;
|
|
555
|
-
}
|
|
556
|
-
function execCreateCounter(context, counter) {
|
|
557
|
-
if (counter === null || counter === void 0 ? void 0 : counter.$$and) {
|
|
558
|
-
// 每个counter都要满足才能过
|
|
559
|
-
var counters = counter === null || counter === void 0 ? void 0 : counter.$$and;
|
|
560
|
-
(0, assert_1.default)(counters.length > 0);
|
|
561
|
-
var counterResults = counters.map(function (ele) { return execCreateCounter(context, ele); });
|
|
562
|
-
if (counterResults[0] instanceof Promise) {
|
|
563
|
-
return Promise.all(counterResults)
|
|
564
|
-
.then(function (cr2) {
|
|
565
|
-
var unpermitted = cr2.find(function (ele) { return ele instanceof Exception_1.OakUserUnpermittedException; });
|
|
566
|
-
if (unpermitted) {
|
|
567
|
-
return unpermitted;
|
|
568
|
-
}
|
|
569
|
-
return undefined;
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
else {
|
|
573
|
-
var unpermitted = counterResults.find(function (ele) { return ele instanceof Exception_1.OakUserUnpermittedException; });
|
|
574
|
-
if (unpermitted) {
|
|
575
|
-
return unpermitted;
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
return undefined;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
else if (counter === null || counter === void 0 ? void 0 : counter.$$or) {
|
|
583
|
-
// 只要有一个counter能过就算过
|
|
584
|
-
var counters = counter === null || counter === void 0 ? void 0 : counter.$$or;
|
|
585
|
-
(0, assert_1.default)(counters.length > 0);
|
|
586
|
-
var counterResults = counters.map(function (ele) { return execCreateCounter(context, ele); });
|
|
587
|
-
if (counterResults[0] instanceof Promise) {
|
|
588
|
-
return Promise.all(counterResults)
|
|
589
|
-
.then(function (cr2) {
|
|
590
|
-
var permittedIdx = cr2.indexOf(undefined);
|
|
591
|
-
if (permittedIdx !== -1) {
|
|
592
|
-
return undefined;
|
|
593
|
-
}
|
|
594
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
var permittedIndex = counterResults.indexOf(undefined);
|
|
599
|
-
if (permittedIndex !== -1) {
|
|
600
|
-
return undefined;
|
|
601
|
-
}
|
|
602
|
-
else {
|
|
603
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
else if (counter === null || counter === void 0 ? void 0 : counter.$entity) {
|
|
608
|
-
var _a = counter, $entity = _a.$entity, $filter = _a.$filter, _b = _a.$count, $count_1 = _b === void 0 ? 1 : _b;
|
|
609
|
-
// count不走reinforceSelection,先用select
|
|
610
|
-
var result = context.select($entity, {
|
|
611
|
-
data: {
|
|
612
|
-
id: 1,
|
|
613
|
-
},
|
|
614
|
-
filter: $filter,
|
|
615
|
-
indexFrom: 0,
|
|
616
|
-
count: $count_1,
|
|
617
|
-
}, { dontCollect: true });
|
|
618
|
-
if (result instanceof Promise) {
|
|
619
|
-
return result.then(function (r2) {
|
|
620
|
-
if (r2.length >= $count_1) {
|
|
621
|
-
return undefined;
|
|
622
|
-
}
|
|
623
|
-
return new Exception_1.OakUserUnpermittedException();
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
return result.length >= $count_1 ? undefined : new Exception_1.OakUserUnpermittedException();
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
function makePotentialFilter(operation, context, filterMaker) {
|
|
632
|
-
var e_1, _a, e_2, _b;
|
|
633
|
-
var userId = context.getCurrentUserId();
|
|
634
|
-
(0, assert_1.default)(userId);
|
|
635
|
-
var filters = filterMaker instanceof Array ? filterMaker.map(function (ele) {
|
|
636
|
-
if (ele instanceof Array) {
|
|
637
|
-
return ele.map(function (ele2) { return ele2(operation, userId); });
|
|
638
|
-
}
|
|
639
|
-
return ele(operation, userId);
|
|
640
|
-
}) : [filterMaker(operation, userId)];
|
|
641
|
-
/**
|
|
642
|
-
* 在下面的逻辑中,如果某个maker返回的是$entity类型,则检查是否有满足条件的项,没有就要抛出异常,有就返回undefined
|
|
643
|
-
* undefined项即意味着该条件通过
|
|
644
|
-
* 再加上and和or的布尔逻辑判断,得到最终结果
|
|
645
|
-
* 还要考虑同步和异步……
|
|
646
|
-
* 代码比较复杂,因为原先没有$entity这种返回结果的设计
|
|
647
|
-
* by Xc 20130219
|
|
648
|
-
*/
|
|
649
|
-
var filtersOr = [];
|
|
650
|
-
var isAsyncOr = false;
|
|
651
|
-
try {
|
|
652
|
-
for (var filters_1 = tslib_1.__values(filters), filters_1_1 = filters_1.next(); !filters_1_1.done; filters_1_1 = filters_1.next()) {
|
|
653
|
-
var f = filters_1_1.value;
|
|
654
|
-
if (f instanceof Array) {
|
|
655
|
-
var isAsyncAnd = false;
|
|
656
|
-
(0, assert_1.default)(f.length > 0);
|
|
657
|
-
var filtersAnd = [];
|
|
658
|
-
try {
|
|
659
|
-
for (var f_1 = (e_2 = void 0, tslib_1.__values(f)), f_1_1 = f_1.next(); !f_1_1.done; f_1_1 = f_1.next()) {
|
|
660
|
-
var ff = f_1_1.value;
|
|
661
|
-
if ((ff === null || ff === void 0 ? void 0 : ff.$$and) || (ff === null || ff === void 0 ? void 0 : ff.$$or) || (ff === null || ff === void 0 ? void 0 : ff.$entity)) {
|
|
662
|
-
// 每个counter都要满足才能过
|
|
663
|
-
var result = execCreateCounter(context, ff);
|
|
664
|
-
if (result instanceof Promise) {
|
|
665
|
-
isAsyncAnd = true;
|
|
666
|
-
}
|
|
667
|
-
filtersAnd.push(result);
|
|
668
|
-
}
|
|
669
|
-
else if (ff) {
|
|
670
|
-
filtersAnd.push(ff);
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
675
|
-
finally {
|
|
676
|
-
try {
|
|
677
|
-
if (f_1_1 && !f_1_1.done && (_b = f_1.return)) _b.call(f_1);
|
|
678
|
-
}
|
|
679
|
-
finally { if (e_2) throw e_2.error; }
|
|
680
|
-
}
|
|
681
|
-
if (isAsyncAnd = true) {
|
|
682
|
-
isAsyncOr = true;
|
|
683
|
-
filtersOr.push(isAsyncAnd ? Promise.all(filtersAnd).then(function (fa) {
|
|
684
|
-
var e_3, _a;
|
|
685
|
-
var faR = [];
|
|
686
|
-
try {
|
|
687
|
-
for (var fa_1 = (e_3 = void 0, tslib_1.__values(fa)), fa_1_1 = fa_1.next(); !fa_1_1.done; fa_1_1 = fa_1.next()) {
|
|
688
|
-
var faItem = fa_1_1.value;
|
|
689
|
-
if (faItem instanceof Exception_1.OakUserUnpermittedException) {
|
|
690
|
-
return faItem;
|
|
691
|
-
}
|
|
692
|
-
else if (faItem) {
|
|
693
|
-
faR.push(faItem);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
698
|
-
finally {
|
|
699
|
-
try {
|
|
700
|
-
if (fa_1_1 && !fa_1_1.done && (_a = fa_1.return)) _a.call(fa_1);
|
|
701
|
-
}
|
|
702
|
-
finally { if (e_3) throw e_3.error; }
|
|
703
|
-
}
|
|
704
|
-
if (faR.length > 0) {
|
|
705
|
-
return {
|
|
706
|
-
$and: faR,
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
}) : {
|
|
710
|
-
$and: filtersAnd,
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
else {
|
|
715
|
-
if ((f === null || f === void 0 ? void 0 : f.$$and) || (f === null || f === void 0 ? void 0 : f.$$or) || (f === null || f === void 0 ? void 0 : f.$entity)) {
|
|
716
|
-
var counterResults = execCreateCounter(context, f);
|
|
717
|
-
if (counterResults instanceof Promise) {
|
|
718
|
-
isAsyncOr = true;
|
|
719
|
-
}
|
|
720
|
-
filtersOr.push(counterResults);
|
|
721
|
-
}
|
|
722
|
-
else if (f) {
|
|
723
|
-
filtersOr.push(f);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
729
|
-
finally {
|
|
730
|
-
try {
|
|
731
|
-
if (filters_1_1 && !filters_1_1.done && (_a = filters_1.return)) _a.call(filters_1);
|
|
732
|
-
}
|
|
733
|
-
finally { if (e_1) throw e_1.error; }
|
|
734
|
-
}
|
|
735
|
-
// or的逻辑是,有一个成功就直接通过
|
|
736
|
-
var returnOrFilters = function (filters) {
|
|
737
|
-
if (filters.length === 0 || filters.includes(undefined)) {
|
|
738
|
-
return undefined;
|
|
739
|
-
}
|
|
740
|
-
var foFilters = filters.filter(function (ele) { return ele !== undefined && !(ele instanceof Exception_1.OakUserUnpermittedException); });
|
|
741
|
-
if (foFilters.length > 0) {
|
|
742
|
-
return {
|
|
743
|
-
$or: foFilters,
|
|
744
|
-
};
|
|
745
|
-
}
|
|
746
|
-
throw new Exception_1.OakUserUnpermittedException();
|
|
747
|
-
};
|
|
748
|
-
if (isAsyncOr) {
|
|
749
|
-
return Promise.all(filtersOr)
|
|
750
|
-
.then(function (filters) { return returnOrFilters(filters); });
|
|
751
|
-
}
|
|
752
|
-
return returnOrFilters(filtersOr);
|
|
753
|
-
}
|
|
754
|
-
/**
|
|
755
|
-
* 根据权限定义,创建出相应的checker
|
|
756
|
-
* @param schema
|
|
757
|
-
* @param authDict
|
|
758
|
-
* @returns
|
|
759
|
-
*/
|
|
760
|
-
function createAuthCheckers(schema, authDict) {
|
|
761
|
-
var checkers = [];
|
|
762
|
-
var _loop_1 = function (entity) {
|
|
763
|
-
var _a;
|
|
764
|
-
if (authDict[entity]) {
|
|
765
|
-
var _b = authDict[entity], relationAuth = _b.relationAuth, actionAuth = _b.actionAuth;
|
|
766
|
-
if (relationAuth) {
|
|
767
|
-
var raFilterMakerDict_1 = {};
|
|
768
|
-
var userEntityName = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
769
|
-
var allAuthItem = [];
|
|
770
|
-
for (var r in relationAuth) {
|
|
771
|
-
var authItem = relationAuth[r];
|
|
772
|
-
Object.assign(raFilterMakerDict_1, (_a = {},
|
|
773
|
-
_a[r] = translateActionAuthFilterMaker(schema, authItem, userEntityName, entity),
|
|
774
|
-
_a));
|
|
775
|
-
if (authItem instanceof Array) {
|
|
776
|
-
allAuthItem.push.apply(allAuthItem, tslib_1.__spreadArray([], tslib_1.__read(authItem), false));
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
allAuthItem.push(authItem);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
// 如果不指定relation,则使用所有的authItem的or组合
|
|
783
|
-
Object.assign(raFilterMakerDict_1, {
|
|
784
|
-
'@@all': translateActionAuthFilterMaker(schema, allAuthItem, userEntityName, entity),
|
|
785
|
-
});
|
|
786
|
-
var entityIdAttr_1 = "".concat(entity, "Id");
|
|
787
|
-
checkers.push({
|
|
788
|
-
entity: userEntityName,
|
|
789
|
-
action: 'create',
|
|
790
|
-
type: 'relation',
|
|
791
|
-
relationFilter: function (operation, context) {
|
|
792
|
-
var data = operation.data;
|
|
793
|
-
(0, assert_1.default)(!(data instanceof Array));
|
|
794
|
-
var _a = data, relation = _a.relation, _b = entityIdAttr_1, entityId = _a[_b];
|
|
795
|
-
if (!relation) {
|
|
796
|
-
// 不指定relation测试是否有创建权限
|
|
797
|
-
return makePotentialFilter(operation, context, raFilterMakerDict_1['@@all']);
|
|
798
|
-
}
|
|
799
|
-
if (!raFilterMakerDict_1[relation]) {
|
|
800
|
-
throw new Exception_1.OakUserUnpermittedException();
|
|
801
|
-
}
|
|
802
|
-
var filter = makePotentialFilter(operation, context, raFilterMakerDict_1[relation]);
|
|
803
|
-
return filter;
|
|
804
|
-
},
|
|
805
|
-
errMsg: function (operation, context) {
|
|
806
|
-
console.error("\u521B\u5EFA".concat(entity, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\uFF0C\u6570\u636E\u662F").concat(JSON.stringify(operation.data)));
|
|
807
|
-
return "\u521B\u5EFA".concat(entity, "\u65F6\u8D8A\u6743");
|
|
808
|
-
},
|
|
809
|
-
});
|
|
810
|
-
checkers.push({
|
|
811
|
-
entity: userEntityName,
|
|
812
|
-
action: 'remove',
|
|
813
|
-
type: 'relation',
|
|
814
|
-
relationFilter: function (operation, context) {
|
|
815
|
-
// 目前过不去
|
|
816
|
-
return undefined;
|
|
817
|
-
/* const userId = context.getCurrentUserId();
|
|
818
|
-
const { filter } = operation as ED[keyof ED]['Remove'];
|
|
819
|
-
const makeFilterFromRows = (rows: Partial<ED[keyof ED]['Schema']>[]): SyncOrAsync<ED[keyof ED]['Selection']['filter']> => {
|
|
820
|
-
const relations = uniq(rows.map(ele => ele.relation));
|
|
821
|
-
const entityIds = uniq(rows.map(ele => ele[entityIdAttr]));
|
|
822
|
-
assert(entityIds.length === 1, `在回收${userEntityName}上权限时,单次回收涉及到了不同的对象,此操作不被允许`);
|
|
823
|
-
// const entityId = entityIds[0]!;
|
|
824
|
-
|
|
825
|
-
// 所有的relation条件要同时满足and关系(注意这里的filter翻译出来是在entity对象上,不是在userEntity对象上)
|
|
826
|
-
const filtersAnd = relations.map(
|
|
827
|
-
(relation) => raFilterMakerDict[relation!]
|
|
828
|
-
).filter(
|
|
829
|
-
ele => !!ele
|
|
830
|
-
).map(
|
|
831
|
-
ele => makePotentialFilter(operation, context, ele)
|
|
832
|
-
);
|
|
833
|
-
if (filtersAnd.find(ele => ele instanceof Promise)) {
|
|
834
|
-
return Promise.all(filtersAnd).then(
|
|
835
|
-
(fa) => {
|
|
836
|
-
if (fa.length > 0) {
|
|
837
|
-
return {
|
|
838
|
-
$and: fa,
|
|
839
|
-
} as ED[keyof ED]['Selection']['filter'];
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
if (filtersAnd.length > 0) {
|
|
845
|
-
return {
|
|
846
|
-
$and: filtersAnd
|
|
847
|
-
} as ED[keyof ED]['Selection']['filter'];
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
|
|
851
|
-
const toBeRemoved = context.select(userEntityName, {
|
|
852
|
-
data: {
|
|
853
|
-
id: 1,
|
|
854
|
-
relation: 1,
|
|
855
|
-
[entityIdAttr]: 1,
|
|
856
|
-
},
|
|
857
|
-
filter,
|
|
858
|
-
}, { dontCollect: true });
|
|
859
|
-
if (toBeRemoved instanceof Promise) {
|
|
860
|
-
return toBeRemoved.then(
|
|
861
|
-
(rows) => makeFilterFromRows(rows)
|
|
862
|
-
);
|
|
863
|
-
}
|
|
864
|
-
return makeFilterFromRows(toBeRemoved); */
|
|
865
|
-
},
|
|
866
|
-
errMsg: function (operation, context) {
|
|
867
|
-
console.error("\u79FB\u9664".concat(entity, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\uFF0C\u79FB\u9664\u6761\u4EF6\u662F").concat(JSON.stringify(operation.filter)));
|
|
868
|
-
return "\u79FB\u9664".concat(entity, "\u65F6\u8D8A\u6743");
|
|
869
|
-
},
|
|
870
|
-
});
|
|
871
|
-
// 转让权限现在用update动作,只允许update userId给其它人
|
|
872
|
-
// todo 等实现的时候再写
|
|
873
|
-
}
|
|
874
|
-
if (actionAuth) {
|
|
875
|
-
var _loop_2 = function (a) {
|
|
876
|
-
var filterMaker = translateActionAuthFilterMaker(schema, actionAuth[a], entity);
|
|
877
|
-
checkers.push({
|
|
878
|
-
entity: entity,
|
|
879
|
-
action: a,
|
|
880
|
-
type: 'relation',
|
|
881
|
-
relationFilter: function (operation, context) {
|
|
882
|
-
// const { filter } = operation;
|
|
883
|
-
var filter = makePotentialFilter(operation, context, filterMaker);
|
|
884
|
-
return filter;
|
|
885
|
-
},
|
|
886
|
-
errMsg: function (operation, context) {
|
|
887
|
-
var _a = operation, action = _a.action, data = _a.data, filter = _a.filter;
|
|
888
|
-
console.error("\u5BF9".concat(entity, "\u8FDB\u884C").concat(action, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\n \u6570\u636E\u662F").concat(JSON.stringify(data), "\uFF0C\u6761\u4EF6\u662F").concat(JSON.stringify(filter)));
|
|
889
|
-
return "\u5BF9".concat(entity, "\u8FDB\u884C").concat(action, "\u65F6\u8D8A\u6743");
|
|
890
|
-
},
|
|
891
|
-
});
|
|
892
|
-
};
|
|
893
|
-
for (var a in actionAuth) {
|
|
894
|
-
_loop_2(a);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
for (var entity in schema) {
|
|
900
|
-
_loop_1(entity);
|
|
901
|
-
}
|
|
902
|
-
return checkers;
|
|
903
|
-
}
|
|
904
|
-
exports.createAuthCheckers = createAuthCheckers;
|
|
905
266
|
/**
|
|
906
267
|
* 对对象的删除,检查其是否会产生其他行上的空指针,不允许这种情况的出现
|
|
907
268
|
* @param schema
|
|
908
269
|
* @returns
|
|
909
270
|
* 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
|
|
910
271
|
*/
|
|
911
|
-
function createRemoveCheckers(schema
|
|
912
|
-
var
|
|
272
|
+
function createRemoveCheckers(schema) {
|
|
273
|
+
var e_1, _a;
|
|
913
274
|
var checkers = [];
|
|
914
275
|
// 先建立所有的一对多的关系
|
|
915
276
|
var OneToManyMatrix = {};
|
|
@@ -924,7 +285,7 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
924
285
|
}
|
|
925
286
|
};
|
|
926
287
|
var addToMtoEntity = function (e, fs) {
|
|
927
|
-
var
|
|
288
|
+
var e_2, _a;
|
|
928
289
|
var _b;
|
|
929
290
|
try {
|
|
930
291
|
for (var fs_1 = tslib_1.__values(fs), fs_1_1 = fs_1.next(); !fs_1_1.done; fs_1_1 = fs_1.next()) {
|
|
@@ -937,12 +298,12 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
937
298
|
}
|
|
938
299
|
}
|
|
939
300
|
}
|
|
940
|
-
catch (
|
|
301
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
941
302
|
finally {
|
|
942
303
|
try {
|
|
943
304
|
if (fs_1_1 && !fs_1_1.done && (_a = fs_1.return)) _a.call(fs_1);
|
|
944
305
|
}
|
|
945
|
-
finally { if (
|
|
306
|
+
finally { if (e_2) throw e_2.error; }
|
|
946
307
|
}
|
|
947
308
|
};
|
|
948
309
|
for (var entity in schema) {
|
|
@@ -966,16 +327,17 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
966
327
|
}
|
|
967
328
|
// 当删除一时,要确认多上面没有指向一的数据
|
|
968
329
|
var entities = (0, lodash_1.union)(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix));
|
|
969
|
-
var
|
|
330
|
+
var _loop_1 = function (entity) {
|
|
970
331
|
checkers.push({
|
|
971
332
|
entity: entity,
|
|
972
333
|
action: 'remove',
|
|
973
334
|
type: 'logical',
|
|
335
|
+
priority: types_1.CHECKER_MAX_PRIORITY,
|
|
974
336
|
checker: function (operation, context, option) {
|
|
975
|
-
var
|
|
337
|
+
var e_3, _a, e_4, _b;
|
|
976
338
|
var promises = [];
|
|
977
339
|
if (OneToManyMatrix[entity]) {
|
|
978
|
-
var
|
|
340
|
+
var _loop_2 = function (otm) {
|
|
979
341
|
var _g, _h;
|
|
980
342
|
var _j = tslib_1.__read(otm, 2), e = _j[0], attr = _j[1];
|
|
981
343
|
var proj = (_g = {
|
|
@@ -1012,21 +374,21 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1012
374
|
}
|
|
1013
375
|
};
|
|
1014
376
|
try {
|
|
1015
|
-
for (var _c = (
|
|
377
|
+
for (var _c = (e_3 = void 0, tslib_1.__values(OneToManyMatrix[entity])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1016
378
|
var otm = _d.value;
|
|
1017
|
-
|
|
379
|
+
_loop_2(otm);
|
|
1018
380
|
}
|
|
1019
381
|
}
|
|
1020
|
-
catch (
|
|
382
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1021
383
|
finally {
|
|
1022
384
|
try {
|
|
1023
385
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
1024
386
|
}
|
|
1025
|
-
finally { if (
|
|
387
|
+
finally { if (e_3) throw e_3.error; }
|
|
1026
388
|
}
|
|
1027
389
|
}
|
|
1028
390
|
if (OneToManyOnEntityMatrix[entity]) {
|
|
1029
|
-
var
|
|
391
|
+
var _loop_3 = function (otm) {
|
|
1030
392
|
var _l, _m, _o;
|
|
1031
393
|
var proj = {
|
|
1032
394
|
id: 1,
|
|
@@ -1070,17 +432,17 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1070
432
|
}
|
|
1071
433
|
};
|
|
1072
434
|
try {
|
|
1073
|
-
for (var _e = (
|
|
435
|
+
for (var _e = (e_4 = void 0, tslib_1.__values(OneToManyOnEntityMatrix[entity])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
1074
436
|
var otm = _f.value;
|
|
1075
|
-
|
|
437
|
+
_loop_3(otm);
|
|
1076
438
|
}
|
|
1077
439
|
}
|
|
1078
|
-
catch (
|
|
440
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
1079
441
|
finally {
|
|
1080
442
|
try {
|
|
1081
443
|
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
1082
444
|
}
|
|
1083
|
-
finally { if (
|
|
445
|
+
finally { if (e_4) throw e_4.error; }
|
|
1084
446
|
}
|
|
1085
447
|
}
|
|
1086
448
|
if (promises.length > 0) {
|
|
@@ -1092,165 +454,26 @@ function createRemoveCheckers(schema, authDict) {
|
|
|
1092
454
|
try {
|
|
1093
455
|
for (var entities_1 = tslib_1.__values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
1094
456
|
var entity = entities_1_1.value;
|
|
1095
|
-
|
|
457
|
+
_loop_1(entity);
|
|
1096
458
|
}
|
|
1097
459
|
}
|
|
1098
|
-
catch (
|
|
460
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1099
461
|
finally {
|
|
1100
462
|
try {
|
|
1101
463
|
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
1102
464
|
}
|
|
1103
|
-
finally { if (
|
|
1104
|
-
}
|
|
1105
|
-
var _loop_4 = function (entity) {
|
|
1106
|
-
var e_8, _b;
|
|
1107
|
-
var cascadeRemove = authDict[entity].cascadeRemove;
|
|
1108
|
-
if (cascadeRemove) {
|
|
1109
|
-
var entitiesOnEntityAttr = [];
|
|
1110
|
-
var hasAllEntity = false;
|
|
1111
|
-
var _loop_7 = function (attr) {
|
|
1112
|
-
if (attr === '@entity') {
|
|
1113
|
-
hasAllEntity = true;
|
|
1114
|
-
return "continue";
|
|
1115
|
-
}
|
|
1116
|
-
var rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
1117
|
-
if (rel === 2) {
|
|
1118
|
-
entitiesOnEntityAttr.push(attr);
|
|
1119
|
-
checkers.push({
|
|
1120
|
-
entity: attr,
|
|
1121
|
-
action: 'remove',
|
|
1122
|
-
type: 'logical',
|
|
1123
|
-
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
1124
|
-
checker: function (operation, context) {
|
|
1125
|
-
var _a, _b;
|
|
1126
|
-
var filter = operation.filter;
|
|
1127
|
-
if (cascadeRemove[attr] === 'remove') {
|
|
1128
|
-
return context.operate(entity, {
|
|
1129
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1130
|
-
action: 'remove',
|
|
1131
|
-
data: {},
|
|
1132
|
-
filter: filter ? (_a = {},
|
|
1133
|
-
_a[attr] = filter,
|
|
1134
|
-
_a) : undefined,
|
|
1135
|
-
}, { dontCollect: true });
|
|
1136
|
-
}
|
|
1137
|
-
return context.operate(entity, {
|
|
1138
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1139
|
-
action: 'update',
|
|
1140
|
-
data: {
|
|
1141
|
-
entity: null,
|
|
1142
|
-
entityId: null,
|
|
1143
|
-
},
|
|
1144
|
-
filter: filter ? (_b = {},
|
|
1145
|
-
_b[attr] = filter,
|
|
1146
|
-
_b) : undefined,
|
|
1147
|
-
}, { dontCollect: true });
|
|
1148
|
-
}
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
else {
|
|
1152
|
-
(0, assert_1.default)(typeof rel === 'string');
|
|
1153
|
-
checkers.push({
|
|
1154
|
-
entity: rel,
|
|
1155
|
-
action: 'remove',
|
|
1156
|
-
type: 'logical',
|
|
1157
|
-
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
1158
|
-
checker: function (operation, context) {
|
|
1159
|
-
var _a, _b, _c;
|
|
1160
|
-
var filter = operation.filter;
|
|
1161
|
-
if (cascadeRemove[attr] === 'remove') {
|
|
1162
|
-
return context.operate(entity, {
|
|
1163
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1164
|
-
action: 'remove',
|
|
1165
|
-
data: {},
|
|
1166
|
-
filter: filter ? (_a = {},
|
|
1167
|
-
_a[attr] = filter,
|
|
1168
|
-
_a) : undefined,
|
|
1169
|
-
}, { dontCollect: true });
|
|
1170
|
-
}
|
|
1171
|
-
return context.operate(entity, {
|
|
1172
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1173
|
-
action: 'update',
|
|
1174
|
-
data: (_b = {},
|
|
1175
|
-
_b["".concat(attr, "Id")] = null,
|
|
1176
|
-
_b),
|
|
1177
|
-
filter: filter ? (_c = {},
|
|
1178
|
-
_c[attr] = filter,
|
|
1179
|
-
_c) : undefined,
|
|
1180
|
-
}, { dontCollect: true });
|
|
1181
|
-
}
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
};
|
|
1185
|
-
for (var attr in cascadeRemove) {
|
|
1186
|
-
_loop_7(attr);
|
|
1187
|
-
}
|
|
1188
|
-
if (hasAllEntity) {
|
|
1189
|
-
var attributes = schema[entity].attributes;
|
|
1190
|
-
var ref = attributes.entity.ref;
|
|
1191
|
-
var restEntities = (0, lodash_1.difference)(ref, entitiesOnEntityAttr);
|
|
1192
|
-
var _loop_8 = function (e) {
|
|
1193
|
-
checkers.push({
|
|
1194
|
-
entity: e,
|
|
1195
|
-
action: 'remove',
|
|
1196
|
-
type: 'logical',
|
|
1197
|
-
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
1198
|
-
checker: function (operation, context) {
|
|
1199
|
-
var _a, _b;
|
|
1200
|
-
var filter = operation.filter;
|
|
1201
|
-
if (cascadeRemove['@entity'] === 'remove') {
|
|
1202
|
-
return context.operate(entity, {
|
|
1203
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1204
|
-
action: 'remove',
|
|
1205
|
-
data: {},
|
|
1206
|
-
filter: filter ? (_a = {},
|
|
1207
|
-
_a[e] = filter,
|
|
1208
|
-
_a) : undefined,
|
|
1209
|
-
}, { dontCollect: true });
|
|
1210
|
-
}
|
|
1211
|
-
return context.operate(entity, {
|
|
1212
|
-
id: (0, uuid_1.generateNewId)(),
|
|
1213
|
-
action: 'update',
|
|
1214
|
-
data: {
|
|
1215
|
-
entity: null,
|
|
1216
|
-
entityId: null,
|
|
1217
|
-
},
|
|
1218
|
-
filter: filter ? (_b = {},
|
|
1219
|
-
_b[e] = filter,
|
|
1220
|
-
_b) : undefined,
|
|
1221
|
-
}, { dontCollect: true });
|
|
1222
|
-
}
|
|
1223
|
-
});
|
|
1224
|
-
};
|
|
1225
|
-
try {
|
|
1226
|
-
for (var restEntities_1 = (e_8 = void 0, tslib_1.__values(restEntities)), restEntities_1_1 = restEntities_1.next(); !restEntities_1_1.done; restEntities_1_1 = restEntities_1.next()) {
|
|
1227
|
-
var e = restEntities_1_1.value;
|
|
1228
|
-
_loop_8(e);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
1232
|
-
finally {
|
|
1233
|
-
try {
|
|
1234
|
-
if (restEntities_1_1 && !restEntities_1_1.done && (_b = restEntities_1.return)) _b.call(restEntities_1);
|
|
1235
|
-
}
|
|
1236
|
-
finally { if (e_8) throw e_8.error; }
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
// 注入声明的cascade删除时的外键处理动作
|
|
1242
|
-
for (var entity in authDict) {
|
|
1243
|
-
_loop_4(entity);
|
|
465
|
+
finally { if (e_1) throw e_1.error; }
|
|
1244
466
|
}
|
|
1245
467
|
return checkers;
|
|
1246
468
|
}
|
|
1247
469
|
exports.createRemoveCheckers = createRemoveCheckers;
|
|
1248
470
|
function checkAttributeLegal(schema, entity, data) {
|
|
1249
471
|
var _a;
|
|
472
|
+
var _b;
|
|
1250
473
|
var attributes = schema[entity].attributes;
|
|
1251
474
|
for (var attr in data) {
|
|
1252
475
|
if (attributes[attr]) {
|
|
1253
|
-
var
|
|
476
|
+
var _c = attributes[attr], type = _c.type, params = _c.params, defaultValue = _c.default, enumeration = _c.enumeration, notNull = _c.notNull;
|
|
1254
477
|
if (data[attr] === null || data[attr] === undefined) {
|
|
1255
478
|
if (notNull && defaultValue === undefined) {
|
|
1256
479
|
throw new Exception_1.OakAttrNotNullException(entity, [attr]);
|
|
@@ -1283,7 +506,7 @@ function checkAttributeLegal(schema, entity, data) {
|
|
|
1283
506
|
if (typeof data[attr] !== 'number') {
|
|
1284
507
|
throw new Exception_1.OakInputIllegalException(entity, [attr], 'not a number');
|
|
1285
508
|
}
|
|
1286
|
-
var
|
|
509
|
+
var _d = params || {}, min = _d.min, max = _d.max;
|
|
1287
510
|
if (typeof min === 'number' && data[attr] < min) {
|
|
1288
511
|
throw new Exception_1.OakInputIllegalException(entity, [attr], 'too small');
|
|
1289
512
|
}
|
|
@@ -1303,7 +526,7 @@ function checkAttributeLegal(schema, entity, data) {
|
|
|
1303
526
|
}
|
|
1304
527
|
else {
|
|
1305
528
|
// 这里似乎还有一种update中带cascade remove的case,等遇到再说(貌似cascadeUpdate没有处理完整这种情况) by Xc
|
|
1306
|
-
if (typeof data[attr] === 'object' && data[attr].action === 'remove') {
|
|
529
|
+
if (typeof data[attr] === 'object' && ((_b = data[attr]) === null || _b === void 0 ? void 0 : _b.action) === 'remove') {
|
|
1307
530
|
console.warn('cascade remove可能是未处理的边界,请注意');
|
|
1308
531
|
}
|
|
1309
532
|
}
|
|
@@ -1311,7 +534,7 @@ function checkAttributeLegal(schema, entity, data) {
|
|
|
1311
534
|
}
|
|
1312
535
|
function createCreateCheckers(schema) {
|
|
1313
536
|
var checkers = [];
|
|
1314
|
-
var
|
|
537
|
+
var _loop_4 = function (entity) {
|
|
1315
538
|
var _a = schema[entity], attributes = _a.attributes, actions = _a.actions;
|
|
1316
539
|
var notNullAttrs = Object.keys(attributes).filter(function (ele) { return attributes[ele].notNull; });
|
|
1317
540
|
var updateActions = (0, lodash_1.difference)(actions, action_1.excludeUpdateActions);
|
|
@@ -1321,12 +544,12 @@ function createCreateCheckers(schema) {
|
|
|
1321
544
|
action: 'create',
|
|
1322
545
|
checker: function (data) {
|
|
1323
546
|
var checkData = function (data2) {
|
|
1324
|
-
var
|
|
547
|
+
var e_5, _a, e_6, _b;
|
|
1325
548
|
var illegalNullAttrs = (0, lodash_1.difference)(notNullAttrs, Object.keys(data2));
|
|
1326
549
|
if (illegalNullAttrs.length > 0) {
|
|
1327
550
|
try {
|
|
1328
551
|
// 要处理多对一的cascade create
|
|
1329
|
-
for (var illegalNullAttrs_1 = (
|
|
552
|
+
for (var illegalNullAttrs_1 = (e_5 = void 0, tslib_1.__values(illegalNullAttrs)), illegalNullAttrs_1_1 = illegalNullAttrs_1.next(); !illegalNullAttrs_1_1.done; illegalNullAttrs_1_1 = illegalNullAttrs_1.next()) {
|
|
1330
553
|
var attr = illegalNullAttrs_1_1.value;
|
|
1331
554
|
if (attr === 'entityId') {
|
|
1332
555
|
if (illegalNullAttrs.includes('entity')) {
|
|
@@ -1336,7 +559,7 @@ function createCreateCheckers(schema) {
|
|
|
1336
559
|
else if (attr === 'entity' && attributes[attr].ref) {
|
|
1337
560
|
var hasCascadeCreate = false;
|
|
1338
561
|
try {
|
|
1339
|
-
for (var _c = (
|
|
562
|
+
for (var _c = (e_6 = void 0, tslib_1.__values(attributes[attr].ref)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
1340
563
|
var ref = _d.value;
|
|
1341
564
|
if (data2[ref] && data2[ref].action === 'create') {
|
|
1342
565
|
hasCascadeCreate = true;
|
|
@@ -1344,12 +567,12 @@ function createCreateCheckers(schema) {
|
|
|
1344
567
|
}
|
|
1345
568
|
}
|
|
1346
569
|
}
|
|
1347
|
-
catch (
|
|
570
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1348
571
|
finally {
|
|
1349
572
|
try {
|
|
1350
573
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
1351
574
|
}
|
|
1352
|
-
finally { if (
|
|
575
|
+
finally { if (e_6) throw e_6.error; }
|
|
1353
576
|
}
|
|
1354
577
|
if (hasCascadeCreate) {
|
|
1355
578
|
continue;
|
|
@@ -1357,7 +580,8 @@ function createCreateCheckers(schema) {
|
|
|
1357
580
|
}
|
|
1358
581
|
else if (attributes[attr].type === 'ref') {
|
|
1359
582
|
var ref = attributes[attr].ref;
|
|
1360
|
-
|
|
583
|
+
var attr2 = attr.slice(0, attr.length - 2);
|
|
584
|
+
if (data2[attr2] && data2[attr2].action === 'create') {
|
|
1361
585
|
continue;
|
|
1362
586
|
}
|
|
1363
587
|
}
|
|
@@ -1365,12 +589,12 @@ function createCreateCheckers(schema) {
|
|
|
1365
589
|
throw new Exception_1.OakAttrNotNullException(entity, illegalNullAttrs);
|
|
1366
590
|
}
|
|
1367
591
|
}
|
|
1368
|
-
catch (
|
|
592
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
1369
593
|
finally {
|
|
1370
594
|
try {
|
|
1371
595
|
if (illegalNullAttrs_1_1 && !illegalNullAttrs_1_1.done && (_a = illegalNullAttrs_1.return)) _a.call(illegalNullAttrs_1);
|
|
1372
596
|
}
|
|
1373
|
-
finally { if (
|
|
597
|
+
finally { if (e_5) throw e_5.error; }
|
|
1374
598
|
}
|
|
1375
599
|
}
|
|
1376
600
|
checkAttributeLegal(schema, entity, data2);
|
|
@@ -1392,7 +616,7 @@ function createCreateCheckers(schema) {
|
|
|
1392
616
|
});
|
|
1393
617
|
};
|
|
1394
618
|
for (var entity in schema) {
|
|
1395
|
-
|
|
619
|
+
_loop_4(entity);
|
|
1396
620
|
}
|
|
1397
621
|
return checkers;
|
|
1398
622
|
}
|