oak-domain 5.0.9 → 5.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/store/CascadeStore.js +1 -0
- package/lib/store/TriggerExecutor.js +58 -27
- package/lib/timers/oper.js +20 -13
- package/lib/types/Trigger.d.ts +1 -0
- package/lib/utils/projection.d.ts +1 -0
- package/lib/utils/projection.js +21 -1
- package/lib/utils/uuid.js +7 -7
- package/package.json +1 -1
|
@@ -304,9 +304,17 @@ class TriggerExecutor {
|
|
|
304
304
|
return execPreTrigger(idx + 1);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
307
|
+
const closeRoot = trigger.asRoot && context.openRootMode();
|
|
308
|
+
try {
|
|
309
|
+
const number = await trigger.fn({ operation: operation }, context, option);
|
|
310
|
+
if (number > 0 && process.env.NODE_ENV === 'development') {
|
|
311
|
+
this.logger.info(`前触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
|
|
312
|
+
}
|
|
313
|
+
closeRoot && closeRoot();
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
closeRoot && closeRoot();
|
|
317
|
+
throw err;
|
|
310
318
|
}
|
|
311
319
|
return execPreTrigger(idx + 1);
|
|
312
320
|
};
|
|
@@ -338,26 +346,41 @@ class TriggerExecutor {
|
|
|
338
346
|
(0, assert_1.default)(trigger && trigger.when === 'commit');
|
|
339
347
|
(0, assert_1.default)(ids.length > 0);
|
|
340
348
|
const { fn } = trigger;
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
349
|
+
const closeRoot = trigger.asRoot && context.openRootMode();
|
|
350
|
+
try {
|
|
351
|
+
const callback = await fn({ ids }, context, option);
|
|
352
|
+
if (trigger.strict === 'makeSure') {
|
|
353
|
+
// 这里开root模式,否则还可能有权限问题
|
|
354
|
+
const closeRoot2 = context.openRootMode();
|
|
355
|
+
try {
|
|
356
|
+
await context.operate(entity, {
|
|
357
|
+
id: await (0, uuid_1.generateNewIdAsync)(),
|
|
358
|
+
action: 'update',
|
|
359
|
+
data: {
|
|
360
|
+
[Entity_1.TriggerDataAttribute]: null,
|
|
361
|
+
[Entity_1.TriggerUuidAttribute]: null,
|
|
362
|
+
},
|
|
363
|
+
filter: {
|
|
364
|
+
id: {
|
|
365
|
+
$in: ids,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}, { includedDeleted: true, blockTrigger: true });
|
|
369
|
+
closeRoot2 && closeRoot2();
|
|
370
|
+
}
|
|
371
|
+
catch (err2) {
|
|
372
|
+
closeRoot2 && closeRoot2();
|
|
373
|
+
throw err2;
|
|
356
374
|
}
|
|
357
|
-
}
|
|
375
|
+
}
|
|
376
|
+
if (typeof callback === 'function') {
|
|
377
|
+
await callback(context, option);
|
|
378
|
+
}
|
|
379
|
+
closeRoot && closeRoot();
|
|
358
380
|
}
|
|
359
|
-
|
|
360
|
-
|
|
381
|
+
catch (err) {
|
|
382
|
+
closeRoot && closeRoot();
|
|
383
|
+
throw err;
|
|
361
384
|
}
|
|
362
385
|
}
|
|
363
386
|
/**
|
|
@@ -407,12 +430,20 @@ class TriggerExecutor {
|
|
|
407
430
|
return;
|
|
408
431
|
}
|
|
409
432
|
const trigger = postTriggers[idx];
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
433
|
+
const closeRoot = trigger.asRoot && context.openRootMode();
|
|
434
|
+
try {
|
|
435
|
+
const number = await trigger.fn({
|
|
436
|
+
operation: operation,
|
|
437
|
+
result: result,
|
|
438
|
+
}, context, option);
|
|
439
|
+
if (number > 0 && process.env.NODE_ENV === 'development') {
|
|
440
|
+
this.logger.info(`后触发器「${trigger.name}」成功触发了「${number}」行数据更改`);
|
|
441
|
+
}
|
|
442
|
+
closeRoot && closeRoot();
|
|
443
|
+
}
|
|
444
|
+
catch (err) {
|
|
445
|
+
closeRoot && closeRoot();
|
|
446
|
+
throw err;
|
|
416
447
|
}
|
|
417
448
|
return execPostTrigger(idx + 1);
|
|
418
449
|
};
|
package/lib/timers/oper.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vaccumOper = void 0;
|
|
4
|
+
const Entity_1 = require("../types/Entity");
|
|
4
5
|
const vaccum_1 = require("./vaccum");
|
|
5
6
|
const filter_1 = require("../store/filter");
|
|
6
7
|
/**
|
|
@@ -11,9 +12,14 @@ const filter_1 = require("../store/filter");
|
|
|
11
12
|
*/
|
|
12
13
|
async function vaccumOper(option, context) {
|
|
13
14
|
const { aliveLine, excludeOpers, ...rest } = option;
|
|
14
|
-
const
|
|
15
|
+
const notFilters = [
|
|
16
|
+
{
|
|
17
|
+
[Entity_1.TriggerUuidAttribute]: {
|
|
18
|
+
$exists: false,
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
];
|
|
15
22
|
if (excludeOpers) {
|
|
16
|
-
const notFilters = [];
|
|
17
23
|
for (const key in excludeOpers) {
|
|
18
24
|
if (excludeOpers[key].length > 0) {
|
|
19
25
|
notFilters.push({
|
|
@@ -29,27 +35,28 @@ async function vaccumOper(option, context) {
|
|
|
29
35
|
});
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
|
-
if (notFilters.length > 0) {
|
|
33
|
-
operFilter.$not = {
|
|
34
|
-
$or: notFilters,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
38
|
}
|
|
38
39
|
return (0, vaccum_1.vaccumEntities)({
|
|
39
40
|
entities: [{
|
|
40
41
|
entity: 'operEntity',
|
|
41
42
|
aliveLine: aliveLine + 10000,
|
|
42
43
|
filter: {
|
|
43
|
-
oper:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
oper: {
|
|
45
|
+
$$createAt$$: {
|
|
46
|
+
$lt: aliveLine,
|
|
47
|
+
},
|
|
48
|
+
$not: (0, filter_1.combineFilters)('oper', context.getSchema(), notFilters),
|
|
49
|
+
},
|
|
48
50
|
},
|
|
49
51
|
}, {
|
|
50
52
|
entity: 'oper',
|
|
51
53
|
aliveLine,
|
|
52
|
-
filter:
|
|
54
|
+
filter: {
|
|
55
|
+
$$createAt$$: {
|
|
56
|
+
$lt: aliveLine,
|
|
57
|
+
},
|
|
58
|
+
$not: (0, filter_1.combineFilters)('oper', context.getSchema(), notFilters),
|
|
59
|
+
},
|
|
53
60
|
}],
|
|
54
61
|
...rest,
|
|
55
62
|
}, context);
|
package/lib/types/Trigger.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
|
|
|
21
21
|
checkerType?: CheckerType;
|
|
22
22
|
entity: T;
|
|
23
23
|
name: string;
|
|
24
|
+
asRoot?: true;
|
|
24
25
|
priority?: number;
|
|
25
26
|
}
|
|
26
27
|
export interface CreateTriggerBase<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> extends TriggerBase<ED, T> {
|
|
@@ -2,3 +2,4 @@ import { EntityDict } from '../types/Entity';
|
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
3
|
import { StorageSchema } from '../types/Storage';
|
|
4
4
|
export declare function makeProjection<ED extends BaseEntityDict & EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>): ED[T]["Selection"]["data"];
|
|
5
|
+
export declare function traverseProjection<ED extends BaseEntityDict & EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, projection: ED[T]['Selection']['data'], callback: <T2 extends keyof ED>(entity2: T2, projection2: ED[T2]['Selection']['data']) => void): void;
|
package/lib/utils/projection.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeProjection = void 0;
|
|
3
|
+
exports.traverseProjection = exports.makeProjection = void 0;
|
|
4
4
|
const Entity_1 = require("../types/Entity");
|
|
5
|
+
const relation_1 = require("../store/relation");
|
|
5
6
|
function makeProjection(entity, schema) {
|
|
6
7
|
const { attributes } = schema[entity];
|
|
7
8
|
const attrs = Object.keys(attributes);
|
|
@@ -13,3 +14,22 @@ function makeProjection(entity, schema) {
|
|
|
13
14
|
return projection;
|
|
14
15
|
}
|
|
15
16
|
exports.makeProjection = makeProjection;
|
|
17
|
+
function traverseProjection(entity, schema, projection, callback) {
|
|
18
|
+
const access = (entity2, proj) => {
|
|
19
|
+
callback(entity2, proj);
|
|
20
|
+
for (const attr in proj) {
|
|
21
|
+
const rel = (0, relation_1.judgeRelation)(schema, entity2, attr);
|
|
22
|
+
if (rel === 2) {
|
|
23
|
+
access(attr, proj[attr]);
|
|
24
|
+
}
|
|
25
|
+
else if (typeof rel === 'string') {
|
|
26
|
+
access(rel, proj[attr]);
|
|
27
|
+
}
|
|
28
|
+
else if (rel instanceof Array) {
|
|
29
|
+
access(rel[0], proj[attr].data);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
access(entity, projection);
|
|
34
|
+
}
|
|
35
|
+
exports.traverseProjection = traverseProjection;
|
package/lib/utils/uuid.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.decompressFrom32 = exports.compressTo32 = exports.formUuid = exports.generateNewId = exports.setGenerateIdOption = exports.produceIds = exports.generateNewIdAsync = exports.expandUuidTo36Bytes = exports.shrinkUuidTo32Bytes = exports.sequentialUuid = void 0;
|
|
4
|
-
|
|
4
|
+
// import { v4 } from 'uuid';
|
|
5
5
|
const random_1 = require("./random/random");
|
|
6
6
|
let _nodeId;
|
|
7
7
|
let _clockseq;
|
|
@@ -112,9 +112,9 @@ exports.expandUuidTo36Bytes = expandUuidTo36Bytes;
|
|
|
112
112
|
// 直接生成uuid的接口,为了适配各种环境,写成异步
|
|
113
113
|
async function generateNewIdAsync(option) {
|
|
114
114
|
const option2 = option || ID_OPTION;
|
|
115
|
-
if (option2?.shuffle || process.env.NODE_ENV === 'development') {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
115
|
+
/* if (option2?.shuffle || process.env.NODE_ENV === 'development') {
|
|
116
|
+
return v4({ random: await getRandomValues(16) });
|
|
117
|
+
} */
|
|
118
118
|
return sequentialUuid({ random: await (0, random_1.getRandomValues)(16) });
|
|
119
119
|
}
|
|
120
120
|
exports.generateNewIdAsync = generateNewIdAsync;
|
|
@@ -150,9 +150,9 @@ function generateNewId() {
|
|
|
150
150
|
do {
|
|
151
151
|
random[iter] = Math.ceil(Math.random() * 1000) % 128;
|
|
152
152
|
} while (++iter < 16);
|
|
153
|
-
if (ID_OPTION?.shuffle || process.env.NODE_ENV === 'development') {
|
|
154
|
-
return
|
|
155
|
-
}
|
|
153
|
+
/* if (ID_OPTION?.shuffle || process.env.NODE_ENV === 'development') {
|
|
154
|
+
return v4({ random });
|
|
155
|
+
} */
|
|
156
156
|
return sequentialUuid({ random });
|
|
157
157
|
}
|
|
158
158
|
}
|