oak-domain 4.1.0 → 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 +185 -185
- package/lib/base-app-domain/ActionDefDict.d.ts +2 -2
- package/lib/base-app-domain/I18n/Schema.d.ts +128 -128
- package/lib/base-app-domain/Modi/Schema.d.ts +135 -135
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +383 -383
- package/lib/base-app-domain/Oper/Schema.d.ts +158 -152
- package/lib/base-app-domain/Oper/Storage.js +19 -1
- package/lib/base-app-domain/OperEntity/Schema.d.ts +372 -372
- package/lib/base-app-domain/Path/Schema.d.ts +148 -148
- package/lib/base-app-domain/Relation/Schema.d.ts +187 -187
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +213 -213
- 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 +209 -209
- package/lib/base-app-domain/UserEntityClaim/Schema.d.ts +263 -263
- 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 +130 -130
- package/lib/base-app-domain/UserRelation/Schema.d.ts +207 -207
- 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 +4167 -4160
- 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 +66 -65
- 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 +29 -29
- package/lib/store/TriggerExecutor.js +468 -468
- package/lib/store/actionDef.js +278 -278
- 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 +13 -13
- package/lib/types/Configuration.d.ts +42 -0
- package/lib/types/Configuration.js +3 -0
- package/lib/types/Connector.d.ts +38 -38
- package/lib/types/Context.d.ts +7 -7
- package/lib/types/Entity.d.ts +4 -4
- package/lib/types/Environment.d.ts +93 -93
- 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 +64 -64
- package/lib/utils/SimpleConnector.js +206 -206
- package/lib/utils/assert.d.ts +5 -5
- 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';
|
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, Context, TxnOption, OpRecord, AggregationResult, ClusterInfo } from "../types";
|
|
3
|
-
import { IncomingHttpHeaders } from "http";
|
|
4
|
-
/**
|
|
5
|
-
* 服务器端执行的异步环境的底层抽象
|
|
6
|
-
*/
|
|
7
|
-
export declare abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|
8
|
-
rowStore: AsyncRowStore<ED, this>;
|
|
9
|
-
private uuid?;
|
|
10
|
-
opRecords: OpRecord<ED>[];
|
|
11
|
-
private scene?;
|
|
12
|
-
headers?: IncomingHttpHeaders;
|
|
13
|
-
clusterInfo?: ClusterInfo;
|
|
14
|
-
opResult: OperationResult<ED>;
|
|
15
|
-
private message?;
|
|
16
|
-
events: {
|
|
17
|
-
commit: Array<() => Promise<void>>;
|
|
18
|
-
rollback: Array<() => Promise<void>>;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* 在返回结果前调用,对数据行进行一些预处理,比如将一些敏感的列隐藏
|
|
22
|
-
*/
|
|
23
|
-
abstract refineOpRecords(): Promise<void>;
|
|
24
|
-
constructor(store: AsyncRowStore<ED, AsyncContext<ED>>);
|
|
25
|
-
restartToExecute(routine: (context: this) => Promise<any>): Promise<void>;
|
|
26
|
-
getHeader(key: string): string | string[] | undefined;
|
|
27
|
-
getScene(): string | undefined;
|
|
28
|
-
setScene(scene?: string): void;
|
|
29
|
-
private resetEvents;
|
|
30
|
-
on(event: 'commit' | 'rollback', callback: () => Promise<void>): void;
|
|
31
|
-
saveOpRecord<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): void;
|
|
32
|
-
/**
|
|
33
|
-
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
34
|
-
* @param options
|
|
35
|
-
*/
|
|
36
|
-
begin(options?: TxnOption): Promise<void>;
|
|
37
|
-
commit(): Promise<void>;
|
|
38
|
-
rollback(): Promise<void>;
|
|
39
|
-
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option: OP): Promise<OperationResult<ED>>;
|
|
40
|
-
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
|
41
|
-
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option: OP): Promise<AggregationResult<ED[T]["Schema"]>>;
|
|
42
|
-
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option: OP): Promise<number>;
|
|
43
|
-
exec(script: string, txnId?: string): Promise<void>;
|
|
44
|
-
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
|
|
45
|
-
getCurrentTxnId(): string | undefined;
|
|
46
|
-
getSchema(): import("../types").StorageSchema<ED>;
|
|
47
|
-
setMessage(message: string): void;
|
|
48
|
-
getMessage(): string | undefined;
|
|
49
|
-
abstract isRoot(): boolean;
|
|
50
|
-
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
51
|
-
abstract
|
|
52
|
-
abstract
|
|
53
|
-
abstract
|
|
54
|
-
abstract
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, Context, TxnOption, OpRecord, AggregationResult, ClusterInfo } from "../types";
|
|
3
|
+
import { IncomingHttpHeaders } from "http";
|
|
4
|
+
/**
|
|
5
|
+
* 服务器端执行的异步环境的底层抽象
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|
8
|
+
rowStore: AsyncRowStore<ED, this>;
|
|
9
|
+
private uuid?;
|
|
10
|
+
opRecords: OpRecord<ED>[];
|
|
11
|
+
private scene?;
|
|
12
|
+
headers?: IncomingHttpHeaders;
|
|
13
|
+
clusterInfo?: ClusterInfo;
|
|
14
|
+
opResult: OperationResult<ED>;
|
|
15
|
+
private message?;
|
|
16
|
+
events: {
|
|
17
|
+
commit: Array<() => Promise<void>>;
|
|
18
|
+
rollback: Array<() => Promise<void>>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* 在返回结果前调用,对数据行进行一些预处理,比如将一些敏感的列隐藏
|
|
22
|
+
*/
|
|
23
|
+
abstract refineOpRecords(): Promise<void>;
|
|
24
|
+
constructor(store: AsyncRowStore<ED, AsyncContext<ED>>);
|
|
25
|
+
restartToExecute(routine: (context: this) => Promise<any>): Promise<void>;
|
|
26
|
+
getHeader(key: string): string | string[] | undefined;
|
|
27
|
+
getScene(): string | undefined;
|
|
28
|
+
setScene(scene?: string): void;
|
|
29
|
+
private resetEvents;
|
|
30
|
+
on(event: 'commit' | 'rollback', callback: () => Promise<void>): void;
|
|
31
|
+
saveOpRecord<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): void;
|
|
32
|
+
/**
|
|
33
|
+
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
34
|
+
* @param options
|
|
35
|
+
*/
|
|
36
|
+
begin(options?: TxnOption): Promise<void>;
|
|
37
|
+
commit(): Promise<void>;
|
|
38
|
+
rollback(): Promise<void>;
|
|
39
|
+
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option: OP): Promise<OperationResult<ED>>;
|
|
40
|
+
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
|
41
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], option: OP): Promise<AggregationResult<ED[T]["Schema"]>>;
|
|
42
|
+
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option: OP): Promise<number>;
|
|
43
|
+
exec(script: string, txnId?: string): Promise<void>;
|
|
44
|
+
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
|
|
45
|
+
getCurrentTxnId(): string | undefined;
|
|
46
|
+
getSchema(): import("../types").StorageSchema<ED>;
|
|
47
|
+
setMessage(message: string): void;
|
|
48
|
+
getMessage(): string | undefined;
|
|
49
|
+
abstract isRoot(): boolean;
|
|
50
|
+
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
51
|
+
abstract setCurrentUserId(userId: string | undefined): void;
|
|
52
|
+
abstract toString(): Promise<string>;
|
|
53
|
+
abstract initialize(data: any): Promise<void>;
|
|
54
|
+
abstract allowUserUpdate(): boolean;
|
|
55
|
+
abstract openRootMode(): () => void;
|
|
56
|
+
}
|
|
57
|
+
export interface AsyncRowStore<ED extends EntityDict, Cxt extends AsyncContext<ED>> extends RowStore<ED> {
|
|
58
|
+
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
|
|
59
|
+
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]['Schema']>[]>;
|
|
60
|
+
aggregate<T extends keyof ED, OP extends SelectOption>(entity: T, aggregation: ED[T]['Aggregation'], context: Cxt, option: OP): Promise<AggregationResult<ED[T]['Schema']>>;
|
|
61
|
+
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): Promise<number>;
|
|
62
|
+
begin(option?: TxnOption): Promise<string>;
|
|
63
|
+
commit(txnId: string): Promise<void>;
|
|
64
|
+
rollback(txnId: string): Promise<void>;
|
|
65
|
+
exec(script: string, txnId?: string): Promise<void>;
|
|
66
|
+
}
|
|
@@ -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
|
+
;
|