oak-domain 4.0.3 → 4.2.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/base-app-domain/ActionAuth/Schema.d.ts +1 -2
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -2
- package/lib/base-app-domain/I18n/Schema.d.ts +1 -2
- package/lib/base-app-domain/Modi/Schema.d.ts +1 -2
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +1 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +8 -3
- package/lib/base-app-domain/Oper/Storage.js +19 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +1 -2
- package/lib/base-app-domain/Path/Schema.d.ts +1 -2
- package/lib/base-app-domain/Relation/Schema.d.ts +1 -2
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +1 -2
- package/lib/base-app-domain/User/Action.d.ts +1 -0
- package/lib/base-app-domain/User/Action.js +3 -3
- package/lib/base-app-domain/User/Schema.d.ts +1 -2
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +1 -2
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -5
- package/lib/base-app-domain/UserEntityGrant/Action.js +5 -5
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +1 -2
- package/lib/base-app-domain/UserRelation/Schema.d.ts +1 -2
- package/lib/compiler/localeBuilder.d.ts +27 -27
- package/lib/compiler/localeBuilder.js +215 -215
- package/lib/compiler/routerBuilder.js +263 -263
- package/lib/compiler/schemalBuilder.js +1058 -460
- package/lib/entities/Oper.d.ts +2 -1
- package/lib/entities/Oper.js +16 -1
- package/lib/entities/User.d.ts +10 -0
- package/lib/entities/User.js +3 -2
- package/lib/index.d.ts +0 -22
- package/lib/index.js +1 -35
- package/lib/store/AsyncRowStore.d.ts +2 -1
- package/lib/store/AsyncRowStore.js +180 -180
- package/lib/store/CascadeStore.js +7 -31
- package/lib/store/RelationAuth.d.ts +103 -103
- package/lib/store/RelationAuth.js +1209 -1343
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/TriggerExecutor.js +1 -1
- package/lib/store/actionDef.js +4 -4
- package/lib/store/checker.js +487 -487
- package/lib/triggers/index.d.ts +2 -2
- package/lib/triggers/index.js +21 -1
- package/lib/types/Aspect.d.ts +1 -1
- package/lib/types/Configuration.d.ts +42 -0
- package/lib/types/Configuration.js +3 -0
- package/lib/types/Connector.d.ts +1 -1
- package/lib/types/Context.d.ts +1 -1
- package/lib/types/Entity.d.ts +4 -4
- package/lib/types/Environment.d.ts +3 -0
- package/lib/types/Exception.d.ts +155 -155
- package/lib/types/Exception.js +436 -436
- package/lib/types/Sync.d.ts +48 -0
- package/lib/types/Sync.js +8 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/utils/SimpleConnector.d.ts +1 -1
- package/lib/utils/SimpleConnector.js +1 -1
- package/lib/utils/assert.d.ts +0 -1
- package/lib/utils/projection.d.ts +1 -1
- package/lib/utils/relationPath.d.ts +31 -0
- package/lib/utils/relationPath.js +202 -0
- package/package.json +51 -51
- package/src/entities/ActionAuth.ts +41 -41
- package/src/entities/I18n.ts +45 -45
- package/src/entities/Modi.ts +69 -69
- package/src/entities/ModiEntity.ts +26 -26
- package/src/entities/Oper.ts +48 -32
- package/src/entities/OperEntity.ts +27 -27
- package/src/entities/Path.ts +43 -43
- package/src/entities/Relation.ts +43 -43
- package/src/entities/RelationAuth.ts +44 -44
- package/src/entities/User.ts +48 -48
- package/src/entities/UserEntityClaim.ts +29 -29
- package/src/entities/UserEntityGrant.ts +24 -24
- package/src/entities/UserRelation.ts +50 -50
package/lib/entities/Oper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { String } from '../types/DataType';
|
|
1
|
+
import { String, Datetime } from '../types/DataType';
|
|
2
2
|
import { EntityShape } from '../types/Entity';
|
|
3
3
|
import { Schema as User } from './User';
|
|
4
4
|
export interface Schema extends EntityShape {
|
|
@@ -8,4 +8,5 @@ export interface Schema extends EntityShape {
|
|
|
8
8
|
extra?: Object;
|
|
9
9
|
operator?: User;
|
|
10
10
|
targetEntity: String<32>;
|
|
11
|
+
bornAt: Datetime;
|
|
11
12
|
}
|
package/lib/entities/Oper.js
CHANGED
|
@@ -12,10 +12,25 @@ const entityDesc = {
|
|
|
12
12
|
extra: '其它',
|
|
13
13
|
operator: '操作者',
|
|
14
14
|
targetEntity: '关联对象',
|
|
15
|
+
bornAt: '诞生时间'
|
|
15
16
|
},
|
|
16
17
|
},
|
|
17
18
|
},
|
|
18
19
|
configuration: {
|
|
19
20
|
actionType: 'appendOnly',
|
|
20
|
-
}
|
|
21
|
+
},
|
|
22
|
+
indexes: [
|
|
23
|
+
{
|
|
24
|
+
name: 'index_bornAt_operatorId',
|
|
25
|
+
attributes: [
|
|
26
|
+
{
|
|
27
|
+
name: 'bornAt',
|
|
28
|
+
direction: 'DESC',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'operator',
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
21
36
|
};
|
package/lib/entities/User.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { String, Text } from '../types/DataType';
|
|
2
2
|
import { EntityShape } from '../types/Entity';
|
|
3
|
+
import { ActionDef } from '../types/Action';
|
|
4
|
+
import { EntityDesc } from '../types/EntityDesc';
|
|
3
5
|
export interface Schema extends EntityShape {
|
|
4
6
|
name?: String<16>;
|
|
5
7
|
nickname?: String<64>;
|
|
6
8
|
password?: Text;
|
|
7
9
|
ref?: Schema;
|
|
8
10
|
}
|
|
11
|
+
type UserAction = 'mergeTo';
|
|
12
|
+
type UserState = 'normal' | 'merged';
|
|
13
|
+
export type Action = UserAction;
|
|
14
|
+
export declare const UserActionDef: ActionDef<UserAction, UserState>;
|
|
15
|
+
export declare const entityDesc: EntityDesc<Schema, Action, '', {
|
|
16
|
+
userState: UserState;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
package/lib/entities/User.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entityDesc = exports.UserActionDef = void 0;
|
|
3
4
|
;
|
|
4
|
-
|
|
5
|
+
exports.UserActionDef = {
|
|
5
6
|
stm: {
|
|
6
7
|
mergeTo: ['normal', 'merged'],
|
|
7
8
|
},
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
exports.entityDesc = {
|
|
10
11
|
locales: {
|
|
11
12
|
zh_CN: {
|
|
12
13
|
name: '用户',
|
package/lib/index.d.ts
CHANGED
|
@@ -1,23 +1 @@
|
|
|
1
|
-
export { storageSchema } from './base-app-domain';
|
|
2
1
|
export type { EntityDict as BaseEntityDict } from './base-app-domain';
|
|
3
|
-
export * from './store/AsyncRowStore';
|
|
4
|
-
export * from './store/SyncRowStore';
|
|
5
|
-
export * from './store/CascadeStore';
|
|
6
|
-
export * from './store/relation';
|
|
7
|
-
export * from './store/RelationAuth';
|
|
8
|
-
export * from './store/TriggerExecutor';
|
|
9
|
-
export * from './store/actionDef';
|
|
10
|
-
export * from './store/checker';
|
|
11
|
-
export * from './store/filter';
|
|
12
|
-
export * from './store/modi';
|
|
13
|
-
export * from './timers/oper';
|
|
14
|
-
export * from './timers/vaccum';
|
|
15
|
-
export * from './actions/action';
|
|
16
|
-
export * from './actions/relation';
|
|
17
|
-
export { SimpleConnector } from './utils/SimpleConnector';
|
|
18
|
-
export { assert } from './utils/assert';
|
|
19
|
-
export { composeUrl } from './utils/domain';
|
|
20
|
-
export { checkAttributesNotNull, checkAttributesScope, } from './utils/validator';
|
|
21
|
-
export { compareVersion } from './utils/version';
|
|
22
|
-
export * from './types';
|
|
23
|
-
export { generateNewIdAsync, generateNewId, shrinkUuidTo32Bytes, expandUuidTo36Bytes, } from './utils/uuid';
|
package/lib/index.js
CHANGED
|
@@ -1,37 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
var base_app_domain_1 = require("./base-app-domain");
|
|
6
|
-
Object.defineProperty(exports, "storageSchema", { enumerable: true, get: function () { return base_app_domain_1.storageSchema; } });
|
|
7
|
-
tslib_1.__exportStar(require("./store/AsyncRowStore"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./store/SyncRowStore"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./store/CascadeStore"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./store/relation"), exports);
|
|
11
|
-
tslib_1.__exportStar(require("./store/RelationAuth"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./store/TriggerExecutor"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./store/actionDef"), exports);
|
|
14
|
-
tslib_1.__exportStar(require("./store/checker"), exports);
|
|
15
|
-
tslib_1.__exportStar(require("./store/filter"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./store/modi"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./timers/oper"), exports);
|
|
18
|
-
tslib_1.__exportStar(require("./timers/vaccum"), exports);
|
|
19
|
-
tslib_1.__exportStar(require("./actions/action"), exports);
|
|
20
|
-
tslib_1.__exportStar(require("./actions/relation"), exports);
|
|
21
|
-
var SimpleConnector_1 = require("./utils/SimpleConnector");
|
|
22
|
-
Object.defineProperty(exports, "SimpleConnector", { enumerable: true, get: function () { return SimpleConnector_1.SimpleConnector; } });
|
|
23
|
-
var assert_1 = require("./utils/assert");
|
|
24
|
-
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } });
|
|
25
|
-
var domain_1 = require("./utils/domain");
|
|
26
|
-
Object.defineProperty(exports, "composeUrl", { enumerable: true, get: function () { return domain_1.composeUrl; } });
|
|
27
|
-
var validator_1 = require("./utils/validator");
|
|
28
|
-
Object.defineProperty(exports, "checkAttributesNotNull", { enumerable: true, get: function () { return validator_1.checkAttributesNotNull; } });
|
|
29
|
-
Object.defineProperty(exports, "checkAttributesScope", { enumerable: true, get: function () { return validator_1.checkAttributesScope; } });
|
|
30
|
-
var version_1 = require("./utils/version");
|
|
31
|
-
Object.defineProperty(exports, "compareVersion", { enumerable: true, get: function () { return version_1.compareVersion; } });
|
|
32
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
33
|
-
var uuid_1 = require("./utils/uuid");
|
|
34
|
-
Object.defineProperty(exports, "generateNewIdAsync", { enumerable: true, get: function () { return uuid_1.generateNewIdAsync; } });
|
|
35
|
-
Object.defineProperty(exports, "generateNewId", { enumerable: true, get: function () { return uuid_1.generateNewId; } });
|
|
36
|
-
Object.defineProperty(exports, "shrinkUuidTo32Bytes", { enumerable: true, get: function () { return uuid_1.shrinkUuidTo32Bytes; } });
|
|
37
|
-
Object.defineProperty(exports, "expandUuidTo36Bytes", { enumerable: true, get: function () { return uuid_1.expandUuidTo36Bytes; } });
|
|
3
|
+
// export * from './types';
|
|
@@ -48,7 +48,8 @@ export declare abstract class AsyncContext<ED extends EntityDict> implements Con
|
|
|
48
48
|
getMessage(): string | undefined;
|
|
49
49
|
abstract isRoot(): boolean;
|
|
50
50
|
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
51
|
-
abstract
|
|
51
|
+
abstract setCurrentUserId(userId: string | undefined): void;
|
|
52
|
+
abstract toString(): Promise<string>;
|
|
52
53
|
abstract initialize(data: any): Promise<void>;
|
|
53
54
|
abstract allowUserUpdate(): boolean;
|
|
54
55
|
abstract openRootMode(): () => void;
|
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AsyncContext = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const action_1 = require("../actions/action");
|
|
6
|
-
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
-
/**
|
|
8
|
-
* 服务器端执行的异步环境的底层抽象
|
|
9
|
-
*/
|
|
10
|
-
class AsyncContext {
|
|
11
|
-
rowStore;
|
|
12
|
-
uuid;
|
|
13
|
-
opRecords;
|
|
14
|
-
scene;
|
|
15
|
-
headers;
|
|
16
|
-
clusterInfo;
|
|
17
|
-
opResult;
|
|
18
|
-
message;
|
|
19
|
-
events;
|
|
20
|
-
constructor(store) {
|
|
21
|
-
this.rowStore = store;
|
|
22
|
-
this.opRecords = [];
|
|
23
|
-
this.events = {
|
|
24
|
-
commit: [],
|
|
25
|
-
rollback: [],
|
|
26
|
-
};
|
|
27
|
-
this.opResult = {};
|
|
28
|
-
}
|
|
29
|
-
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
|
30
|
-
async restartToExecute(routine) {
|
|
31
|
-
const newContext = !this.uuid ? this : {
|
|
32
|
-
...this,
|
|
33
|
-
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
|
34
|
-
if (newContext !== this) {
|
|
35
|
-
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
|
36
|
-
}
|
|
37
|
-
newContext.opRecords = [];
|
|
38
|
-
newContext.events = {
|
|
39
|
-
commit: [],
|
|
40
|
-
rollback: [],
|
|
41
|
-
};
|
|
42
|
-
newContext.opResult = {};
|
|
43
|
-
await newContext.begin();
|
|
44
|
-
try {
|
|
45
|
-
await routine(newContext);
|
|
46
|
-
await newContext.commit();
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
await newContext.rollback();
|
|
50
|
-
throw err;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
getHeader(key) {
|
|
54
|
-
if (this.headers) {
|
|
55
|
-
return this.headers[key];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
getScene() {
|
|
59
|
-
return this.scene;
|
|
60
|
-
}
|
|
61
|
-
setScene(scene) {
|
|
62
|
-
this.scene = scene;
|
|
63
|
-
}
|
|
64
|
-
resetEvents() {
|
|
65
|
-
this.events = {
|
|
66
|
-
commit: [],
|
|
67
|
-
rollback: [],
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
on(event, callback) {
|
|
71
|
-
this.uuid && this.events[event].push(callback);
|
|
72
|
-
}
|
|
73
|
-
saveOpRecord(entity, operation) {
|
|
74
|
-
const { action, data, filter, id } = operation;
|
|
75
|
-
switch (action) {
|
|
76
|
-
case 'create': {
|
|
77
|
-
this.opRecords.push({
|
|
78
|
-
id,
|
|
79
|
-
a: 'c',
|
|
80
|
-
e: entity,
|
|
81
|
-
d: data
|
|
82
|
-
});
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
case 'remove': {
|
|
86
|
-
this.opRecords.push({
|
|
87
|
-
id,
|
|
88
|
-
a: 'r',
|
|
89
|
-
e: entity,
|
|
90
|
-
f: filter,
|
|
91
|
-
});
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
default: {
|
|
95
|
-
(0, assert_1.default)(!action_1.readOnlyActions.includes(action));
|
|
96
|
-
this.opRecords.push({
|
|
97
|
-
id,
|
|
98
|
-
a: 'u',
|
|
99
|
-
e: entity,
|
|
100
|
-
d: data,
|
|
101
|
-
f: filter,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
108
|
-
* @param options
|
|
109
|
-
*/
|
|
110
|
-
async begin(options) {
|
|
111
|
-
if (!this.uuid) {
|
|
112
|
-
this.uuid = await this.rowStore.begin(options);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
(0, assert_1.default)(false);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
async commit() {
|
|
119
|
-
if (this.uuid) {
|
|
120
|
-
await this.rowStore.commit(this.uuid);
|
|
121
|
-
const { commit: commitEvents } = this.events;
|
|
122
|
-
for (const e of commitEvents) {
|
|
123
|
-
await e();
|
|
124
|
-
}
|
|
125
|
-
this.uuid = undefined;
|
|
126
|
-
this.resetEvents();
|
|
127
|
-
this.opRecords = [];
|
|
128
|
-
this.opResult = {};
|
|
129
|
-
this.message = '';
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
async rollback() {
|
|
133
|
-
if (this.uuid) {
|
|
134
|
-
await this.rowStore.rollback(this.uuid);
|
|
135
|
-
const { rollback: rollbackEvents } = this.events;
|
|
136
|
-
for (const e of rollbackEvents) {
|
|
137
|
-
await e();
|
|
138
|
-
}
|
|
139
|
-
this.uuid = undefined;
|
|
140
|
-
this.opRecords = [];
|
|
141
|
-
this.opResult = {};
|
|
142
|
-
this.resetEvents();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async operate(entity, operation, option) {
|
|
146
|
-
const result = await this.rowStore.operate(entity, operation, this, option);
|
|
147
|
-
this.opResult = this.mergeMultipleResults([this.opResult, result]);
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
select(entity, selection, option) {
|
|
151
|
-
return this.rowStore.select(entity, selection, this, option);
|
|
152
|
-
}
|
|
153
|
-
aggregate(entity, aggregation, option) {
|
|
154
|
-
return this.rowStore.aggregate(entity, aggregation, this, option);
|
|
155
|
-
}
|
|
156
|
-
count(entity, selection, option) {
|
|
157
|
-
return this.rowStore.count(entity, selection, this, option);
|
|
158
|
-
}
|
|
159
|
-
exec(script, txnId) {
|
|
160
|
-
return this.rowStore.exec(script, txnId);
|
|
161
|
-
}
|
|
162
|
-
mergeMultipleResults(toBeMerged) {
|
|
163
|
-
return this.rowStore.mergeMultipleResults(toBeMerged);
|
|
164
|
-
}
|
|
165
|
-
getCurrentTxnId() {
|
|
166
|
-
return this.uuid;
|
|
167
|
-
}
|
|
168
|
-
getSchema() {
|
|
169
|
-
return this.rowStore.getSchema();
|
|
170
|
-
}
|
|
171
|
-
setMessage(message) {
|
|
172
|
-
this.message = message;
|
|
173
|
-
}
|
|
174
|
-
getMessage() {
|
|
175
|
-
return this.message;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.AsyncContext = AsyncContext;
|
|
179
|
-
;
|
|
180
|
-
;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncContext = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const action_1 = require("../actions/action");
|
|
6
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
7
|
+
/**
|
|
8
|
+
* 服务器端执行的异步环境的底层抽象
|
|
9
|
+
*/
|
|
10
|
+
class AsyncContext {
|
|
11
|
+
rowStore;
|
|
12
|
+
uuid;
|
|
13
|
+
opRecords;
|
|
14
|
+
scene;
|
|
15
|
+
headers;
|
|
16
|
+
clusterInfo;
|
|
17
|
+
opResult;
|
|
18
|
+
message;
|
|
19
|
+
events;
|
|
20
|
+
constructor(store) {
|
|
21
|
+
this.rowStore = store;
|
|
22
|
+
this.opRecords = [];
|
|
23
|
+
this.events = {
|
|
24
|
+
commit: [],
|
|
25
|
+
rollback: [],
|
|
26
|
+
};
|
|
27
|
+
this.opResult = {};
|
|
28
|
+
}
|
|
29
|
+
// 使一个上下文重新开始事务执行,清除历史数据(定时器中使用)
|
|
30
|
+
async restartToExecute(routine) {
|
|
31
|
+
const newContext = !this.uuid ? this : {
|
|
32
|
+
...this,
|
|
33
|
+
}; // 这里可能有问题,继承的context对象中如果有对象属性会变成指针公用,但是估计目前是跑不到的。by Xc 20231215
|
|
34
|
+
if (newContext !== this) {
|
|
35
|
+
console.warn('restartToExecute跑出了非重用当前context的情况,请仔细调试');
|
|
36
|
+
}
|
|
37
|
+
newContext.opRecords = [];
|
|
38
|
+
newContext.events = {
|
|
39
|
+
commit: [],
|
|
40
|
+
rollback: [],
|
|
41
|
+
};
|
|
42
|
+
newContext.opResult = {};
|
|
43
|
+
await newContext.begin();
|
|
44
|
+
try {
|
|
45
|
+
await routine(newContext);
|
|
46
|
+
await newContext.commit();
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
await newContext.rollback();
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
getHeader(key) {
|
|
54
|
+
if (this.headers) {
|
|
55
|
+
return this.headers[key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
getScene() {
|
|
59
|
+
return this.scene;
|
|
60
|
+
}
|
|
61
|
+
setScene(scene) {
|
|
62
|
+
this.scene = scene;
|
|
63
|
+
}
|
|
64
|
+
resetEvents() {
|
|
65
|
+
this.events = {
|
|
66
|
+
commit: [],
|
|
67
|
+
rollback: [],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
on(event, callback) {
|
|
71
|
+
this.uuid && this.events[event].push(callback);
|
|
72
|
+
}
|
|
73
|
+
saveOpRecord(entity, operation) {
|
|
74
|
+
const { action, data, filter, id } = operation;
|
|
75
|
+
switch (action) {
|
|
76
|
+
case 'create': {
|
|
77
|
+
this.opRecords.push({
|
|
78
|
+
id,
|
|
79
|
+
a: 'c',
|
|
80
|
+
e: entity,
|
|
81
|
+
d: data
|
|
82
|
+
});
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'remove': {
|
|
86
|
+
this.opRecords.push({
|
|
87
|
+
id,
|
|
88
|
+
a: 'r',
|
|
89
|
+
e: entity,
|
|
90
|
+
f: filter,
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
default: {
|
|
95
|
+
(0, assert_1.default)(!action_1.readOnlyActions.includes(action));
|
|
96
|
+
this.opRecords.push({
|
|
97
|
+
id,
|
|
98
|
+
a: 'u',
|
|
99
|
+
e: entity,
|
|
100
|
+
d: data,
|
|
101
|
+
f: filter,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
108
|
+
* @param options
|
|
109
|
+
*/
|
|
110
|
+
async begin(options) {
|
|
111
|
+
if (!this.uuid) {
|
|
112
|
+
this.uuid = await this.rowStore.begin(options);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
(0, assert_1.default)(false);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async commit() {
|
|
119
|
+
if (this.uuid) {
|
|
120
|
+
await this.rowStore.commit(this.uuid);
|
|
121
|
+
const { commit: commitEvents } = this.events;
|
|
122
|
+
for (const e of commitEvents) {
|
|
123
|
+
await e();
|
|
124
|
+
}
|
|
125
|
+
this.uuid = undefined;
|
|
126
|
+
this.resetEvents();
|
|
127
|
+
this.opRecords = [];
|
|
128
|
+
this.opResult = {};
|
|
129
|
+
this.message = '';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async rollback() {
|
|
133
|
+
if (this.uuid) {
|
|
134
|
+
await this.rowStore.rollback(this.uuid);
|
|
135
|
+
const { rollback: rollbackEvents } = this.events;
|
|
136
|
+
for (const e of rollbackEvents) {
|
|
137
|
+
await e();
|
|
138
|
+
}
|
|
139
|
+
this.uuid = undefined;
|
|
140
|
+
this.opRecords = [];
|
|
141
|
+
this.opResult = {};
|
|
142
|
+
this.resetEvents();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async operate(entity, operation, option) {
|
|
146
|
+
const result = await this.rowStore.operate(entity, operation, this, option);
|
|
147
|
+
this.opResult = this.mergeMultipleResults([this.opResult, result]);
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
select(entity, selection, option) {
|
|
151
|
+
return this.rowStore.select(entity, selection, this, option);
|
|
152
|
+
}
|
|
153
|
+
aggregate(entity, aggregation, option) {
|
|
154
|
+
return this.rowStore.aggregate(entity, aggregation, this, option);
|
|
155
|
+
}
|
|
156
|
+
count(entity, selection, option) {
|
|
157
|
+
return this.rowStore.count(entity, selection, this, option);
|
|
158
|
+
}
|
|
159
|
+
exec(script, txnId) {
|
|
160
|
+
return this.rowStore.exec(script, txnId);
|
|
161
|
+
}
|
|
162
|
+
mergeMultipleResults(toBeMerged) {
|
|
163
|
+
return this.rowStore.mergeMultipleResults(toBeMerged);
|
|
164
|
+
}
|
|
165
|
+
getCurrentTxnId() {
|
|
166
|
+
return this.uuid;
|
|
167
|
+
}
|
|
168
|
+
getSchema() {
|
|
169
|
+
return this.rowStore.getSchema();
|
|
170
|
+
}
|
|
171
|
+
setMessage(message) {
|
|
172
|
+
this.message = message;
|
|
173
|
+
}
|
|
174
|
+
getMessage() {
|
|
175
|
+
return this.message;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.AsyncContext = AsyncContext;
|
|
179
|
+
;
|
|
180
|
+
;
|
|
@@ -680,7 +680,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
680
680
|
const opData = {};
|
|
681
681
|
const beforeFns = [];
|
|
682
682
|
const afterFns = [];
|
|
683
|
-
if (modiAttr && action !== 'remove'
|
|
683
|
+
if (modiAttr && action !== 'remove') {
|
|
684
684
|
// create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
|
|
685
685
|
// delete此对象,所有的modi子对象应该通过触发器作废,这个目前先通过系统的trigger来实现
|
|
686
686
|
(0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
|
|
@@ -1017,7 +1017,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1017
1017
|
* @param option
|
|
1018
1018
|
*/
|
|
1019
1019
|
async doUpdateSingleRowAsync(entity, operation, context, option) {
|
|
1020
|
-
const { data, action, id: operId, filter } = operation;
|
|
1020
|
+
const { data, action, id: operId, filter, bornAt } = operation;
|
|
1021
1021
|
const now = Date.now();
|
|
1022
1022
|
switch (action) {
|
|
1023
1023
|
case 'create': {
|
|
@@ -1146,11 +1146,6 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
if (!option.dontCollect) {
|
|
1148
1148
|
context.saveOpRecord(entity, operation);
|
|
1149
|
-
/* context.opRecords.push({
|
|
1150
|
-
a: 'c',
|
|
1151
|
-
e: entity,
|
|
1152
|
-
d: data as ED[T]['OpSchema'] | ED[T]['OpSchema'][],
|
|
1153
|
-
}); */
|
|
1154
1149
|
}
|
|
1155
1150
|
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity)) {
|
|
1156
1151
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
@@ -1166,6 +1161,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1166
1161
|
data,
|
|
1167
1162
|
operatorId,
|
|
1168
1163
|
targetEntity: entity,
|
|
1164
|
+
bornAt,
|
|
1169
1165
|
operEntity$oper: data instanceof Array ? {
|
|
1170
1166
|
id: 'dummy',
|
|
1171
1167
|
action: 'create',
|
|
@@ -1182,13 +1178,12 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1182
1178
|
entityId: data.id,
|
|
1183
1179
|
entity: entity,
|
|
1184
1180
|
},
|
|
1185
|
-
}]
|
|
1181
|
+
}],
|
|
1186
1182
|
},
|
|
1187
1183
|
};
|
|
1188
1184
|
const closeRootMode = context.openRootMode();
|
|
1189
1185
|
await this.cascadeUpdateAsync('oper', createOper, context, {
|
|
1190
1186
|
dontCollect: true,
|
|
1191
|
-
dontCreateOper: true,
|
|
1192
1187
|
});
|
|
1193
1188
|
closeRootMode();
|
|
1194
1189
|
}
|
|
@@ -1308,7 +1303,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1308
1303
|
}
|
|
1309
1304
|
else {
|
|
1310
1305
|
const createOper = async () => {
|
|
1311
|
-
if (!option
|
|
1306
|
+
if (!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids.length > 0) {
|
|
1312
1307
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1313
1308
|
(0, assert_1.default)(operId);
|
|
1314
1309
|
const createOper = {
|
|
@@ -1319,6 +1314,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1319
1314
|
action,
|
|
1320
1315
|
data,
|
|
1321
1316
|
targetEntity: entity,
|
|
1317
|
+
bornAt,
|
|
1322
1318
|
operEntity$oper: {
|
|
1323
1319
|
id: 'dummy',
|
|
1324
1320
|
action: 'create',
|
|
@@ -1333,7 +1329,6 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1333
1329
|
const closeRootMode = context.openRootMode();
|
|
1334
1330
|
await this.cascadeUpdateAsync('oper', createOper, context, {
|
|
1335
1331
|
dontCollect: true,
|
|
1336
|
-
dontCreateOper: true,
|
|
1337
1332
|
});
|
|
1338
1333
|
closeRootMode();
|
|
1339
1334
|
}
|
|
@@ -1350,15 +1345,6 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1350
1345
|
}
|
|
1351
1346
|
}
|
|
1352
1347
|
});
|
|
1353
|
-
/* context.opRecords.push({
|
|
1354
|
-
a: 'r',
|
|
1355
|
-
e: entity,
|
|
1356
|
-
f: {
|
|
1357
|
-
id: {
|
|
1358
|
-
$in: ids,
|
|
1359
|
-
}
|
|
1360
|
-
},
|
|
1361
|
-
}); */
|
|
1362
1348
|
}
|
|
1363
1349
|
}
|
|
1364
1350
|
else {
|
|
@@ -1366,7 +1352,7 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1366
1352
|
if (updateAttrCount > 0) {
|
|
1367
1353
|
// 优化一下,如果不更新任何属性,则不实际执行
|
|
1368
1354
|
Object.assign(data, {
|
|
1369
|
-
|
|
1355
|
+
[Entity_1.UpdateAtAttribute]: now,
|
|
1370
1356
|
});
|
|
1371
1357
|
if (!option.dontCollect) {
|
|
1372
1358
|
context.saveOpRecord(entity, {
|
|
@@ -1379,16 +1365,6 @@ class CascadeStore extends RowStore_1.RowStore {
|
|
|
1379
1365
|
}
|
|
1380
1366
|
},
|
|
1381
1367
|
});
|
|
1382
|
-
/* context.opRecords.push({
|
|
1383
|
-
a: 'u',
|
|
1384
|
-
e: entity,
|
|
1385
|
-
d: data as ED[T]['Update']['data'],
|
|
1386
|
-
f: {
|
|
1387
|
-
id: {
|
|
1388
|
-
$in: ids,
|
|
1389
|
-
}
|
|
1390
|
-
},
|
|
1391
|
-
}); */
|
|
1392
1368
|
}
|
|
1393
1369
|
}
|
|
1394
1370
|
else if (action !== 'update') {
|