oak-domain 2.2.0 → 2.3.1
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/base-app-domain/Modi/Schema.d.ts +10 -23
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +4 -16
- package/lib/base-app-domain/Oper/Schema.d.ts +6 -18
- package/lib/base-app-domain/OperEntity/Schema.d.ts +4 -17
- package/lib/base-app-domain/User/Schema.d.ts +14 -21
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +6 -1
- package/lib/compiler/schemalBuilder.js +145 -31
- package/lib/store/AsyncRowStore.d.ts +3 -1
- package/lib/store/AsyncRowStore.js +3 -0
- package/lib/store/CascadeStore.d.ts +4 -2
- package/lib/store/CascadeStore.js +141 -62
- package/lib/store/SyncRowStore.d.ts +3 -1
- package/lib/store/SyncRowStore.js +3 -0
- package/lib/store/TriggerExecutor.js +43 -5
- package/lib/store/checker.d.ts +2 -1
- package/lib/store/checker.js +193 -23
- package/lib/store/filter.d.ts +1 -0
- package/lib/store/filter.js +49 -26
- package/lib/store/modi.js +39 -5
- package/lib/store/relation.js +4 -2
- package/lib/store/selection.js +2 -2
- package/lib/types/Auth.d.ts +11 -2
- package/lib/types/Entity.d.ts +32 -1
- package/lib/types/Expression.js +19 -4
- package/lib/types/Storage.d.ts +4 -3
- package/lib/types/Timer.d.ts +1 -2
- package/lib/types/Trigger.d.ts +12 -0
- package/lib/utils/SimpleConnector.js +15 -0
- package/lib/utils/cron.d.ts +1 -0
- package/lib/utils/cron.js +18 -0
- package/lib/utils/lodash.d.ts +16 -1
- package/lib/utils/lodash.js +48 -31
- package/lib/utils/uuid.js +18 -6
- package/package.json +2 -2
|
@@ -17,7 +17,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
17
17
|
function CascadeStore(storageSchema) {
|
|
18
18
|
return _super.call(this, storageSchema) || this;
|
|
19
19
|
}
|
|
20
|
-
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context,
|
|
20
|
+
CascadeStore.prototype.destructCascadeSelect = function (entity, projection2, context, cascadeSelectFn, aggregateFn, option) {
|
|
21
21
|
var _this = this;
|
|
22
22
|
var projection = {};
|
|
23
23
|
var cascadeSelectionFns = [];
|
|
@@ -58,7 +58,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
var _e = this_1.destructCascadeSelect(attr, projection2[attr], context,
|
|
61
|
+
var _e = this_1.destructCascadeSelect(attr, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _e.projection, subCascadeSelectionFns = _e.cascadeSelectionFns;
|
|
62
62
|
Object.assign(projection, (_b = {},
|
|
63
63
|
_b[attr] = subProjection,
|
|
64
64
|
_b));
|
|
@@ -101,7 +101,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
103
|
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) { return ele.entityId; }));
|
|
104
|
-
var subRows =
|
|
104
|
+
var subRows = cascadeSelectFn.call(_this, attr, {
|
|
105
105
|
data: projection2[attr],
|
|
106
106
|
filter: {
|
|
107
107
|
id: {
|
|
@@ -143,7 +143,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
|
-
var _f = this_1.destructCascadeSelect(relation, projection2[attr], context,
|
|
146
|
+
var _f = this_1.destructCascadeSelect(relation, projection2[attr], context, cascadeSelectFn, aggregateFn, option), subProjection = _f.projection, subCascadeSelectionFns = _f.cascadeSelectionFns;
|
|
147
147
|
Object.assign(projection, (_d = {},
|
|
148
148
|
_d[attr] = subProjection,
|
|
149
149
|
_d));
|
|
@@ -191,7 +191,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
191
191
|
});
|
|
192
192
|
};
|
|
193
193
|
var ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
|
|
194
|
-
var subRows =
|
|
194
|
+
var subRows = cascadeSelectFn.call(_this, relation, {
|
|
195
195
|
data: projection2[attr],
|
|
196
196
|
filter: {
|
|
197
197
|
id: {
|
|
@@ -210,69 +210,143 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
210
210
|
(0, assert_1.default)(relation instanceof Array);
|
|
211
211
|
var _g = projection2[attr], subProjection_1 = _g.data, subFilter_1 = _g.filter, indexFrom_1 = _g.indexFrom, count_1 = _g.count, subSorter_1 = _g.sorter;
|
|
212
212
|
var _h = tslib_1.__read(relation, 2), entity2_1 = _h[0], foreignKey_1 = _h[1];
|
|
213
|
+
var isAggr = attr.endsWith('$$aggr');
|
|
213
214
|
if (foreignKey_1) {
|
|
214
215
|
// 基于属性的一对多
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
var
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
216
|
+
if (isAggr) {
|
|
217
|
+
// 是聚合运算
|
|
218
|
+
cascadeSelectionFns.push(function (result) {
|
|
219
|
+
var aggrResults = result.map(function (row) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
var aggrResult = aggregateFn.call(_this, entity2_1, {
|
|
222
|
+
data: subProjection_1,
|
|
223
|
+
filter: (0, filter_1.combineFilters)([(_a = {},
|
|
224
|
+
_a[foreignKey_1] = row.id,
|
|
225
|
+
_a), subFilter_1]),
|
|
226
|
+
sorter: subSorter_1,
|
|
227
|
+
indexFrom: indexFrom_1,
|
|
228
|
+
count: count_1
|
|
229
|
+
}, context, option);
|
|
230
|
+
if (aggrResult instanceof Promise) {
|
|
231
|
+
return aggrResult.then(function (aggrResultResult) {
|
|
232
|
+
var _a;
|
|
233
|
+
return Object.assign(row, (_a = {},
|
|
234
|
+
_a[attr] = aggrResultResult,
|
|
235
|
+
_a));
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
Object.assign(row, (_b = {},
|
|
240
|
+
_b[attr] = aggrResult,
|
|
241
|
+
_b));
|
|
242
|
+
}
|
|
226
243
|
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
if (aggrResults.length > 0 && aggrResults[0] instanceof Promise) {
|
|
245
|
+
return Promise.all(aggrResults).then(function () { return undefined; });
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
// 是一对多查询
|
|
251
|
+
cascadeSelectionFns.push(function (result) {
|
|
252
|
+
var _a;
|
|
253
|
+
var ids = result.map(function (ele) { return ele.id; });
|
|
254
|
+
var dealWithSubRows = function (subRows) {
|
|
255
|
+
result.forEach(function (ele) {
|
|
256
|
+
var _a;
|
|
257
|
+
var subRowss = subRows.filter(function (ele2) { return ele2[foreignKey_1] === ele.id; });
|
|
258
|
+
(0, assert_1.default)(subRowss);
|
|
259
|
+
Object.assign(ele, (_a = {},
|
|
260
|
+
_a[attr] = subRowss,
|
|
261
|
+
_a));
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
265
|
+
data: subProjection_1,
|
|
266
|
+
filter: (0, filter_1.combineFilters)([(_a = {},
|
|
267
|
+
_a[foreignKey_1] = {
|
|
268
|
+
$in: ids,
|
|
269
|
+
},
|
|
270
|
+
_a), subFilter_1]),
|
|
271
|
+
sorter: subSorter_1,
|
|
272
|
+
indexFrom: indexFrom_1,
|
|
273
|
+
count: count_1
|
|
274
|
+
}, context, option);
|
|
275
|
+
if (subRows instanceof Promise) {
|
|
276
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
277
|
+
}
|
|
278
|
+
dealWithSubRows(subRows);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
244
281
|
}
|
|
245
282
|
else {
|
|
246
283
|
// 基于entity的多对一
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
result.
|
|
284
|
+
if (isAggr) {
|
|
285
|
+
// 是聚合运算
|
|
286
|
+
cascadeSelectionFns.push(function (result) {
|
|
287
|
+
var aggrResults = result.map(function (row) {
|
|
251
288
|
var _a;
|
|
252
|
-
var
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
289
|
+
var aggrResult = aggregateFn.call(_this, entity2_1, {
|
|
290
|
+
data: subProjection_1,
|
|
291
|
+
filter: (0, filter_1.combineFilters)([{
|
|
292
|
+
entity: entity,
|
|
293
|
+
entityId: row.id,
|
|
294
|
+
}, subFilter_1]),
|
|
295
|
+
sorter: subSorter_1,
|
|
296
|
+
indexFrom: indexFrom_1,
|
|
297
|
+
count: count_1
|
|
298
|
+
}, context, option);
|
|
299
|
+
if (aggrResult instanceof Promise) {
|
|
300
|
+
return aggrResult.then(function (aggrResultResult) {
|
|
301
|
+
var _a;
|
|
302
|
+
return Object.assign(row, (_a = {},
|
|
303
|
+
_a[attr] = aggrResultResult,
|
|
304
|
+
_a));
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
Object.assign(row, (_a = {},
|
|
309
|
+
_a[attr] = aggrResult,
|
|
310
|
+
_a));
|
|
311
|
+
}
|
|
257
312
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
313
|
+
if (aggrResults.length > 0 && aggrResults[0] instanceof Promise) {
|
|
314
|
+
return Promise.all(aggrResults).then(function () { return undefined; });
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
// 是一对多查询
|
|
320
|
+
cascadeSelectionFns.push(function (result) {
|
|
321
|
+
var ids = result.map(function (ele) { return ele.id; });
|
|
322
|
+
var dealWithSubRows = function (subRows) {
|
|
323
|
+
result.forEach(function (ele) {
|
|
324
|
+
var _a;
|
|
325
|
+
var subRowss = subRows.filter(function (ele2) { return ele2.entityId === ele.id; });
|
|
326
|
+
(0, assert_1.default)(subRowss);
|
|
327
|
+
Object.assign(ele, (_a = {},
|
|
328
|
+
_a[attr] = subRowss,
|
|
329
|
+
_a));
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
333
|
+
data: subProjection_1,
|
|
334
|
+
filter: (0, filter_1.combineFilters)([{
|
|
335
|
+
entity: entity,
|
|
336
|
+
entityId: {
|
|
337
|
+
$in: ids,
|
|
338
|
+
}
|
|
339
|
+
}, subFilter_1]),
|
|
340
|
+
sorter: subSorter_1,
|
|
341
|
+
indexFrom: indexFrom_1,
|
|
342
|
+
count: count_1
|
|
343
|
+
}, context, option);
|
|
344
|
+
if (subRows instanceof Promise) {
|
|
345
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
346
|
+
}
|
|
347
|
+
dealWithSubRows(subRows);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
276
350
|
}
|
|
277
351
|
}
|
|
278
352
|
};
|
|
@@ -611,6 +685,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
611
685
|
Object.assign(data2, (_b = {},
|
|
612
686
|
_b[Entity_1.CreateAtAttribute] = now,
|
|
613
687
|
_b[Entity_1.UpdateAtAttribute] = now,
|
|
688
|
+
_b[Entity_1.DeleteAtAttribute] = null,
|
|
614
689
|
_b));
|
|
615
690
|
};
|
|
616
691
|
if (data instanceof Array) {
|
|
@@ -653,6 +728,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
653
728
|
case 1:
|
|
654
729
|
this.preProcessDataCreated(entity, data);
|
|
655
730
|
if (!(option.modiParentEntity && !['modi', 'modiEntity', 'oper', 'operEntity'].includes(entity))) return [3 /*break*/, 3];
|
|
731
|
+
// 变成对modi的插入
|
|
732
|
+
(0, assert_1.default)(option.modiParentId);
|
|
656
733
|
modiCreate = {
|
|
657
734
|
id: 'dummy',
|
|
658
735
|
action: 'create',
|
|
@@ -909,6 +986,8 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
909
986
|
action: {
|
|
910
987
|
$in: ['create', 'update'],
|
|
911
988
|
},
|
|
989
|
+
entity: option.modiParentEntity,
|
|
990
|
+
entityId: option.modiParentId,
|
|
912
991
|
iState: 'active',
|
|
913
992
|
filter: ids_1.length > 0 ? {
|
|
914
993
|
id: {
|
|
@@ -1339,7 +1418,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1339
1418
|
};
|
|
1340
1419
|
CascadeStore.prototype.cascadeSelect = function (entity, selection, context, option) {
|
|
1341
1420
|
var data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
|
|
1342
|
-
var _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelect, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1421
|
+
var _a = this.destructCascadeSelect(entity, data, context, this.cascadeSelect, this.aggregateSync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1343
1422
|
var rows = this.selectAbjointRow(entity, {
|
|
1344
1423
|
data: projection,
|
|
1345
1424
|
filter: filter,
|
|
@@ -1460,7 +1539,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1460
1539
|
switch (_b.label) {
|
|
1461
1540
|
case 0:
|
|
1462
1541
|
data = selection.data, filter = selection.filter, indexFrom = selection.indexFrom, count = selection.count, sorter = selection.sorter;
|
|
1463
|
-
_a = this.destructCascadeSelect(entity, data, context, this.cascadeSelectAsync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1542
|
+
_a = this.destructCascadeSelect(entity, data, context, this.cascadeSelectAsync, this.aggregateAsync, option), projection = _a.projection, cascadeSelectionFns = _a.cascadeSelectionFns;
|
|
1464
1543
|
return [4 /*yield*/, this.selectAbjointRowAsync(entity, {
|
|
1465
1544
|
data: projection,
|
|
1466
1545
|
filter: filter,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, TxnOption, Context } from "../types";
|
|
1
|
+
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, TxnOption, Context, AggregationResult } from "../types";
|
|
2
2
|
export declare abstract class SyncContext<ED extends EntityDict> implements Context {
|
|
3
3
|
private rowStore;
|
|
4
4
|
private uuid?;
|
|
@@ -13,6 +13,7 @@ export declare abstract class SyncContext<ED extends EntityDict> implements Cont
|
|
|
13
13
|
getSchema(): import("../types").StorageSchema<ED>;
|
|
14
14
|
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option: OP): OperationResult<ED>;
|
|
15
15
|
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option: OP): Partial<ED[T]["Schema"]>[];
|
|
16
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option: OP): AggregationResult<ED[T]["Schema"]>;
|
|
16
17
|
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option: OP): number;
|
|
17
18
|
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
|
|
18
19
|
abstract allowUserUpdate(): boolean;
|
|
@@ -21,6 +22,7 @@ export interface SyncRowStore<ED extends EntityDict, Cxt extends Context> extend
|
|
|
21
22
|
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): OperationResult<ED>;
|
|
22
23
|
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Partial<ED[T]['Schema']>[];
|
|
23
24
|
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): number;
|
|
25
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): AggregationResult<ED[T]['Schema']>;
|
|
24
26
|
begin(option?: TxnOption): string;
|
|
25
27
|
commit(txnId: string): void;
|
|
26
28
|
rollback(txnId: string): void;
|
|
@@ -32,6 +32,9 @@ var SyncContext = /** @class */ (function () {
|
|
|
32
32
|
SyncContext.prototype.select = function (entity, selection, option) {
|
|
33
33
|
return this.rowStore.select(entity, selection, this, option);
|
|
34
34
|
};
|
|
35
|
+
SyncContext.prototype.aggregate = function (entity, aggregation, option) {
|
|
36
|
+
return this.rowStore.aggregate(entity, aggregation, this, option);
|
|
37
|
+
};
|
|
35
38
|
SyncContext.prototype.count = function (entity, selection, option) {
|
|
36
39
|
return this.rowStore.count(entity, selection, this, option);
|
|
37
40
|
};
|
|
@@ -30,7 +30,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
30
30
|
this.counter = 0;
|
|
31
31
|
}
|
|
32
32
|
TriggerExecutor.prototype.registerChecker = function (checker) {
|
|
33
|
-
var entity = checker.entity, action = checker.action, type = checker.type;
|
|
33
|
+
var entity = checker.entity, action = checker.action, type = checker.type, conditionalFilter = checker.conditionalFilter;
|
|
34
34
|
var triggerName = "".concat(String(entity)).concat(action, "\u6743\u9650\u68C0\u67E5-").concat(this.counter++);
|
|
35
35
|
var fn = (0, checker_1.translateCheckerInAsyncContext)(checker);
|
|
36
36
|
var trigger = {
|
|
@@ -41,6 +41,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
41
41
|
action: action,
|
|
42
42
|
fn: fn,
|
|
43
43
|
when: 'before',
|
|
44
|
+
filter: conditionalFilter,
|
|
44
45
|
};
|
|
45
46
|
this.registerTrigger(trigger);
|
|
46
47
|
};
|
|
@@ -60,6 +61,11 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
60
61
|
if (typeof trigger.priority !== 'number') {
|
|
61
62
|
trigger.priority = 1; // 默认最低
|
|
62
63
|
}
|
|
64
|
+
if (trigger.filter) {
|
|
65
|
+
(0, assert_1.default)(typeof trigger.action === 'string' && trigger.action !== 'create'
|
|
66
|
+
|| trigger.action instanceof Array && !trigger.action.includes('create'), "trigger\u3010".concat(trigger.name, "\u3011\u662Fcreate\u7C7B\u578B\u4F46\u5374\u5E26\u6709filter"));
|
|
67
|
+
(0, assert_1.default)(trigger.when === 'before' || trigger.when === 'commit', "\u5B9A\u4E49\u4E86filter\u7684trigger\u3010".concat(trigger.name, "\u3011\u7684when\u53EA\u80FD\u662Fbefore\u6216\u8005commit"));
|
|
68
|
+
}
|
|
63
69
|
Object.assign(this.triggerNameMap, (_a = {},
|
|
64
70
|
_a[trigger.name] = trigger,
|
|
65
71
|
_a));
|
|
@@ -194,6 +200,16 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
194
200
|
try {
|
|
195
201
|
for (var preTriggers_1 = tslib_1.__values(preTriggers_2), preTriggers_1_1 = preTriggers_1.next(); !preTriggers_1_1.done; preTriggers_1_1 = preTriggers_1.next()) {
|
|
196
202
|
var trigger = preTriggers_1_1.value;
|
|
203
|
+
if (trigger.filter) {
|
|
204
|
+
// trigger只对满足条件的前项进行判断,如果确定不满足可以pass
|
|
205
|
+
(0, assert_1.default)(operation.action !== 'create');
|
|
206
|
+
var filter = trigger.filter;
|
|
207
|
+
var filterr = typeof filter === 'function' ? filter(operation, context, option) : filter;
|
|
208
|
+
var filterRepelled = (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter);
|
|
209
|
+
if (filterRepelled) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
197
213
|
var number = trigger.fn({ operation: operation }, context, option);
|
|
198
214
|
if (number > 0) {
|
|
199
215
|
this.logger.info("\u89E6\u53D1\u5668\u300C".concat(trigger.name, "\u300D\u6210\u529F\u89E6\u53D1\u4E86\u300C").concat(number, "\u300D\u884C\u6570\u636E\u66F4\u6539"));
|
|
@@ -212,7 +228,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
212
228
|
else {
|
|
213
229
|
// 异步context
|
|
214
230
|
var execPreTrigger_1 = function (idx) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
215
|
-
var trigger, number;
|
|
231
|
+
var trigger, filter, filterr, filterRepelled, number;
|
|
216
232
|
return tslib_1.__generator(this, function (_a) {
|
|
217
233
|
switch (_a.label) {
|
|
218
234
|
case 0:
|
|
@@ -220,8 +236,19 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
220
236
|
return [2 /*return*/];
|
|
221
237
|
}
|
|
222
238
|
trigger = preTriggers_2[idx];
|
|
223
|
-
return [
|
|
239
|
+
if (!trigger.filter) return [3 /*break*/, 2];
|
|
240
|
+
(0, assert_1.default)(operation.action !== 'create');
|
|
241
|
+
filter = trigger.filter;
|
|
242
|
+
filterr = typeof filter === 'function' ? filter(operation, context, option) : filter;
|
|
243
|
+
return [4 /*yield*/, (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter)];
|
|
224
244
|
case 1:
|
|
245
|
+
filterRepelled = _a.sent();
|
|
246
|
+
if (filterRepelled) {
|
|
247
|
+
return [2 /*return*/, execPreTrigger_1(idx + 1)];
|
|
248
|
+
}
|
|
249
|
+
_a.label = 2;
|
|
250
|
+
case 2: return [4 /*yield*/, trigger.fn({ operation: operation }, context, option)];
|
|
251
|
+
case 3:
|
|
225
252
|
number = _a.sent();
|
|
226
253
|
if (number > 0) {
|
|
227
254
|
this.logger.info("\u89E6\u53D1\u5668\u300C".concat(trigger.name, "\u300D\u6210\u529F\u89E6\u53D1\u4E86\u300C").concat(number, "\u300D\u884C\u6570\u636E\u66F4\u6539"));
|
|
@@ -231,7 +258,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
231
258
|
});
|
|
232
259
|
}); };
|
|
233
260
|
var execCommitTrigger_1 = function (idx) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
234
|
-
var trigger;
|
|
261
|
+
var trigger, filter, filterr, filterRepelled;
|
|
235
262
|
return tslib_1.__generator(this, function (_a) {
|
|
236
263
|
switch (_a.label) {
|
|
237
264
|
case 0:
|
|
@@ -239,8 +266,19 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
239
266
|
return [2 /*return*/];
|
|
240
267
|
}
|
|
241
268
|
trigger = commitTriggers_1[idx];
|
|
242
|
-
return [
|
|
269
|
+
if (!trigger.filter) return [3 /*break*/, 2];
|
|
270
|
+
(0, assert_1.default)(operation.action !== 'create');
|
|
271
|
+
filter = trigger.filter;
|
|
272
|
+
filterr = typeof filter === 'function' ? filter(operation, context, option) : filter;
|
|
273
|
+
return [4 /*yield*/, (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter)];
|
|
243
274
|
case 1:
|
|
275
|
+
filterRepelled = _a.sent();
|
|
276
|
+
if (filterRepelled) {
|
|
277
|
+
return [2 /*return*/, execCommitTrigger_1(idx + 1)];
|
|
278
|
+
}
|
|
279
|
+
_a.label = 2;
|
|
280
|
+
case 2: return [4 /*yield*/, this.preCommitTrigger(entity, operation, trigger, context, option)];
|
|
281
|
+
case 3:
|
|
244
282
|
_a.sent();
|
|
245
283
|
return [2 /*return*/, execCommitTrigger_1(idx + 1)];
|
|
246
284
|
}
|
package/lib/store/checker.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Checker, EntityDict, OperateOption, SelectOption, Trigger } from "../types";
|
|
1
|
+
import { Checker, EntityDict, OperateOption, SelectOption, StorageSchema, Trigger } from "../types";
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
3
|
import { AsyncContext } from "./AsyncRowStore";
|
|
4
4
|
import { SyncContext } from './SyncRowStore';
|
|
5
5
|
export declare function translateCheckerInAsyncContext<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(checker: Checker<ED, keyof ED, Cxt>): Trigger<ED, keyof ED, Cxt>['fn'];
|
|
6
6
|
export declare function translateCheckerInSyncContext<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends SyncContext<ED>>(checker: Checker<ED, T, Cxt>): (operation: ED[T]['Operation'], context: Cxt, option: OperateOption | SelectOption) => void;
|
|
7
|
+
export declare function createRelationHierarchyCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
|