oak-domain 1.1.13 → 2.0.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 +29 -32
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +24 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +24 -27
- package/lib/base-app-domain/OperEntity/Schema.d.ts +25 -28
- package/lib/base-app-domain/User/Schema.d.ts +22 -25
- package/lib/checkers/index.d.ts +4 -2
- package/lib/compiler/schemalBuilder.js +22 -24
- package/lib/store/AsyncRowStore.d.ts +45 -0
- package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
- package/lib/store/CascadeStore.d.ts +46 -20
- package/lib/store/CascadeStore.js +960 -996
- package/lib/store/SyncRowStore.d.ts +26 -0
- package/lib/store/SyncRowStore.js +45 -0
- package/lib/store/TriggerExecutor.d.ts +14 -14
- package/lib/store/TriggerExecutor.js +225 -238
- package/lib/store/actionDef.d.ts +5 -4
- package/lib/store/actionDef.js +44 -133
- package/lib/store/checker.d.ts +6 -0
- package/lib/store/checker.js +165 -0
- package/lib/store/filter.d.ts +5 -0
- package/lib/store/filter.js +395 -3
- package/lib/store/modi.d.ts +7 -6
- package/lib/store/modi.js +35 -46
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/selection.js +1 -0
- package/lib/triggers/index.d.ts +4 -3
- package/lib/triggers/modi.d.ts +2 -2
- package/lib/triggers/modi.js +5 -5
- package/lib/types/AppLoader.d.ts +3 -3
- package/lib/types/Aspect.d.ts +3 -3
- package/lib/types/Auth.d.ts +25 -22
- package/lib/types/Connector.d.ts +7 -7
- package/lib/types/Context.d.ts +4 -14
- package/lib/types/DataType.d.ts +1 -0
- package/lib/types/Entity.d.ts +26 -18
- package/lib/types/Entity.js +9 -2
- package/lib/types/Exception.d.ts +6 -1
- package/lib/types/Exception.js +30 -13
- package/lib/types/RowStore.d.ts +2 -13
- package/lib/types/RowStore.js +1 -6
- package/lib/types/Storage.d.ts +1 -0
- package/lib/types/Trigger.d.ts +32 -48
- package/lib/types/Trigger.js +24 -9
- package/lib/types/Watcher.d.ts +7 -8
- package/lib/types/schema/DataTypes.d.ts +1 -1
- package/lib/utils/SimpleConnector.d.ts +9 -8
- package/lib/utils/SimpleConnector.js +4 -5
- package/lib/utils/random/random.d.ts +1 -0
- package/lib/utils/random/random.js +24 -0
- package/lib/utils/random/random.mp.d.ts +1 -0
- package/lib/utils/random/random.mp.js +25 -0
- package/lib/utils/random/random.web.d.ts +1 -0
- package/lib/utils/random/random.web.js +17 -0
- package/lib/utils/string.d.ts +20 -0
- package/lib/utils/string.js +60 -1
- package/lib/utils/uuid.d.ts +10 -0
- package/lib/utils/uuid.js +172 -1
- package/lib/utils/validator.d.ts +2 -2
- package/lib/utils/validator.js +5 -5
- package/package.json +5 -3
- package/lib/OakError.d.ts +0 -7
- package/lib/OakError.js +0 -15
- package/lib/compiler/utils.d.ts +0 -2
- package/lib/compiler/utils.js +0 -11
- package/lib/entities/Action.d.ts +0 -12
- package/lib/entities/Action.js +0 -17
- package/lib/entities/Ooperation.d.ts +0 -12
- package/lib/entities/Ooperation.js +0 -17
- package/lib/entities/Update.d.ts +0 -9
- package/lib/entities/Update.js +0 -44
- package/lib/entities/Uupdate.d.ts +0 -9
- package/lib/entities/Uupdate.js +0 -44
- package/lib/store/UniversalContext.d.ts +0 -32
- package/lib/store/action.d.ts +0 -6
- package/lib/store/action.js +0 -14
- package/lib/store/projection.d.ts +0 -7
- package/lib/store/projection.js +0 -211
- package/lib/store/watchers.d.ts +0 -2
- package/lib/store/watchers.js +0 -32
|
@@ -850,19 +850,7 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
850
850
|
function constructSchema(statements, entity) {
|
|
851
851
|
var e_1, _a, e_2, _b;
|
|
852
852
|
var schemaAttrs = Schema[entity].schemaAttrs;
|
|
853
|
-
var members = [
|
|
854
|
-
// id: String<64>
|
|
855
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('id'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('PrimaryKey'))),
|
|
856
|
-
// $$createAt$$: Datetime
|
|
857
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('$$createAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Datetime'))),
|
|
858
|
-
// $$updateAt$$: Datetime
|
|
859
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('$$updateAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Datetime'))),
|
|
860
|
-
// $$updateAt$$: Datetime
|
|
861
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('$$deleteAt$$'), factory.createToken(ts.SyntaxKind.QuestionToken), factory.createUnionTypeNode([
|
|
862
|
-
factory.createTypeReferenceNode(factory.createIdentifier('Datetime')),
|
|
863
|
-
factory.createLiteralTypeNode(factory.createNull())
|
|
864
|
-
]))
|
|
865
|
-
];
|
|
853
|
+
var members = [];
|
|
866
854
|
var members2 = [];
|
|
867
855
|
var _c = ManyToOne, _d = entity, manyToOneSet = _c[_d];
|
|
868
856
|
var _e = OneToMany, _f = entity, oneToManySet = _e[_f];
|
|
@@ -997,10 +985,14 @@ function constructSchema(statements, entity) {
|
|
|
997
985
|
}
|
|
998
986
|
statements.push(factory.createTypeAliasDeclaration(undefined, [
|
|
999
987
|
factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1000
|
-
], factory.createIdentifier('OpSchema'), undefined, factory.
|
|
988
|
+
], factory.createIdentifier('OpSchema'), undefined, factory.createIntersectionTypeNode([
|
|
989
|
+
factory.createTypeReferenceNode('EntityShape'),
|
|
990
|
+
factory.createTypeLiteralNode(members)
|
|
991
|
+
])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("OpAttr"), undefined, factory.createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined))));
|
|
1001
992
|
statements.push(factory.createTypeAliasDeclaration(undefined, [
|
|
1002
993
|
factory.createModifier(ts.SyntaxKind.ExportKeyword)
|
|
1003
994
|
], factory.createIdentifier('Schema'), undefined, factory.createIntersectionTypeNode([
|
|
995
|
+
factory.createTypeReferenceNode('EntityShape'),
|
|
1004
996
|
factory.createTypeLiteralNode(members.concat(members2)),
|
|
1005
997
|
factory.createMappedTypeNode(undefined, factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("A"), factory.createTypeReferenceNode(factory.createIdentifier("ExpressionKey"), undefined), undefined), undefined, factory.createToken(ts.SyntaxKind.QuestionToken), factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword), undefined)
|
|
1006
998
|
])));
|
|
@@ -1022,6 +1014,8 @@ function constructFilter(statements, entity) {
|
|
|
1022
1014
|
])),
|
|
1023
1015
|
// $$createAt$$: Q_DateValue
|
|
1024
1016
|
factory.createPropertySignature(undefined, factory.createIdentifier('$$createAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue'))),
|
|
1017
|
+
// $$seq$$: Q_StringValue
|
|
1018
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('$$seq$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_StringValue'))),
|
|
1025
1019
|
// $$updateAt$$: Q_DateValue
|
|
1026
1020
|
factory.createPropertySignature(undefined, factory.createIdentifier('$$updateAt$$'), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Q_DateValue')))
|
|
1027
1021
|
];
|
|
@@ -1176,6 +1170,7 @@ function constructProjection(statements, entity) {
|
|
|
1176
1170
|
['id', true],
|
|
1177
1171
|
['$$createAt$$', false],
|
|
1178
1172
|
['$$updateAt$$', false],
|
|
1173
|
+
['$$seq$$', false],
|
|
1179
1174
|
];
|
|
1180
1175
|
var foreignKeyProperties = (_a = {},
|
|
1181
1176
|
_a[entity] = [''],
|
|
@@ -1341,7 +1336,7 @@ function constructProjection(statements, entity) {
|
|
|
1341
1336
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Projection"), undefined, factory.createIntersectionTypeNode([
|
|
1342
1337
|
factory.createTypeLiteralNode(MetaPropertySignaturs.concat(properties.map(function (_a) {
|
|
1343
1338
|
var _b = tslib_1.__read(_a, 3), n = _b[0], q = _b[1], v = _b[2];
|
|
1344
|
-
return factory.createPropertySignature(undefined, n, q ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), v || factory.
|
|
1339
|
+
return factory.createPropertySignature(undefined, n, q ? undefined : factory.createToken(ts.SyntaxKind.QuestionToken), v || factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword));
|
|
1345
1340
|
}))),
|
|
1346
1341
|
exprNode,
|
|
1347
1342
|
])));
|
|
@@ -1357,7 +1352,7 @@ function constructProjection(statements, entity) {
|
|
|
1357
1352
|
for (var foreignKey in foreignKeyProperties) {
|
|
1358
1353
|
var identifier = "".concat(foreignKey, "IdProjection");
|
|
1359
1354
|
statements.push(factory.createTypeAliasDeclaration(undefined, undefined, factory.createIdentifier(identifier), undefined, factory.createTypeReferenceNode(factory.createIdentifier("OneOf"), [
|
|
1360
|
-
factory.createTypeLiteralNode(foreignKeyProperties[foreignKey].map(function (attr) { return factory.createPropertySignature(undefined, attr ? factory.createIdentifier("".concat(attr, "Id")) : 'id', undefined, factory.
|
|
1355
|
+
factory.createTypeLiteralNode(foreignKeyProperties[foreignKey].map(function (attr) { return factory.createPropertySignature(undefined, attr ? factory.createIdentifier("".concat(attr, "Id")) : 'id', undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword)); }))
|
|
1361
1356
|
])));
|
|
1362
1357
|
}
|
|
1363
1358
|
}
|
|
@@ -1498,11 +1493,13 @@ function constructSorter(statements, entity) {
|
|
|
1498
1493
|
var schemaAttrs = Schema[entity].schemaAttrs;
|
|
1499
1494
|
var members = [
|
|
1500
1495
|
// id: 1
|
|
1501
|
-
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("id"), undefined, factory.
|
|
1496
|
+
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("id"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
|
|
1502
1497
|
// $$createAt$$: 1
|
|
1503
|
-
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$createAt$$"), undefined, factory.
|
|
1498
|
+
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$createAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
|
|
1499
|
+
// $$seq$$: 1
|
|
1500
|
+
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$seq$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
|
|
1504
1501
|
// $$updateAt$$: 1
|
|
1505
|
-
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$updateAt$$"), undefined, factory.
|
|
1502
|
+
factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("$$updateAt$$"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]),
|
|
1506
1503
|
];
|
|
1507
1504
|
var _b = ManyToOne, _c = entity, manyToOneSet = _b[_c];
|
|
1508
1505
|
var _loop_6 = function (attr) {
|
|
@@ -1522,7 +1519,7 @@ function constructSorter(statements, entity) {
|
|
|
1522
1519
|
case 'Datetime':
|
|
1523
1520
|
case 'Image':
|
|
1524
1521
|
case 'File': {
|
|
1525
|
-
type2 = factory.
|
|
1522
|
+
type2 = factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
1526
1523
|
break;
|
|
1527
1524
|
}
|
|
1528
1525
|
default: {
|
|
@@ -1533,11 +1530,11 @@ function constructSorter(statements, entity) {
|
|
|
1533
1530
|
});
|
|
1534
1531
|
if (manyToOneItem) {
|
|
1535
1532
|
type2 = factory.createTypeReferenceNode(createForeignRef(entity, text2_5, 'SortAttr'));
|
|
1536
|
-
members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("".concat(name_5.text, "Id")), undefined, factory.
|
|
1533
|
+
members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, factory.createIdentifier("".concat(name_5.text, "Id")), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
|
|
1537
1534
|
}
|
|
1538
1535
|
else if (!['Object'].includes(text)) {
|
|
1539
1536
|
// todo 对State的专门处理
|
|
1540
|
-
type2 = factory.
|
|
1537
|
+
type2 = factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword);
|
|
1541
1538
|
}
|
|
1542
1539
|
}
|
|
1543
1540
|
}
|
|
@@ -1547,7 +1544,7 @@ function constructSorter(statements, entity) {
|
|
|
1547
1544
|
}
|
|
1548
1545
|
}
|
|
1549
1546
|
else if (ts.isUnionTypeNode(type) && ts.isLiteralTypeNode(type.types[0]) || ts.isLiteralTypeNode(type)) {
|
|
1550
|
-
members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name_5, undefined, factory.
|
|
1547
|
+
members.push(factory.createTypeLiteralNode([factory.createPropertySignature(undefined, name_5, undefined, factory.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword))]));
|
|
1551
1548
|
}
|
|
1552
1549
|
else {
|
|
1553
1550
|
// 本地规定的shape,非结构化属性不参与排序
|
|
@@ -2549,7 +2546,8 @@ var initialStatements = function () { return [
|
|
|
2549
2546
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormCreateData")),
|
|
2550
2547
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("FormUpdateData")),
|
|
2551
2548
|
factory.createImportSpecifier(false, factory.createIdentifier("Operation"), factory.createIdentifier("OakOperation")),
|
|
2552
|
-
factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction"))
|
|
2549
|
+
factory.createImportSpecifier(false, factory.createIdentifier("MakeAction"), factory.createIdentifier("OakMakeAction")),
|
|
2550
|
+
factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityShape")),
|
|
2553
2551
|
])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Entity")), undefined)
|
|
2554
2552
|
]; };
|
|
2555
2553
|
function outputSubQuery(outputDir, printer) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EntityDict, RowStore, OperateOption, OperationResult, SelectOption, Context, TxnOption, OpRecord } from "../types";
|
|
3
|
+
import { IncomingHttpHeaders } from "http";
|
|
4
|
+
export declare abstract class AsyncContext<ED extends EntityDict> implements Context {
|
|
5
|
+
private rowStore;
|
|
6
|
+
private uuid?;
|
|
7
|
+
opRecords: OpRecord<ED>[];
|
|
8
|
+
private scene?;
|
|
9
|
+
private headers?;
|
|
10
|
+
events: {
|
|
11
|
+
commit: Array<() => Promise<void>>;
|
|
12
|
+
rollback: Array<() => Promise<void>>;
|
|
13
|
+
};
|
|
14
|
+
constructor(store: AsyncRowStore<ED, AsyncContext<ED>>, headers?: IncomingHttpHeaders);
|
|
15
|
+
setHeaders(headers: IncomingHttpHeaders): void;
|
|
16
|
+
getHeader(key: string): string | string[] | undefined;
|
|
17
|
+
getScene(): string | undefined;
|
|
18
|
+
setScene(scene?: string): void;
|
|
19
|
+
private resetEvents;
|
|
20
|
+
on(event: 'commit' | 'rollback', callback: () => Promise<void>): void;
|
|
21
|
+
/**
|
|
22
|
+
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
23
|
+
* @param options
|
|
24
|
+
*/
|
|
25
|
+
begin(options?: TxnOption): Promise<void>;
|
|
26
|
+
commit(): Promise<void>;
|
|
27
|
+
rollback(): Promise<void>;
|
|
28
|
+
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], option: OP): Promise<OperationResult<ED>>;
|
|
29
|
+
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
|
30
|
+
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, option: OP): Promise<number>;
|
|
31
|
+
mergeMultipleResults(toBeMerged: OperationResult<ED>[]): OperationResult<ED>;
|
|
32
|
+
getCurrentTxnId(): string | undefined;
|
|
33
|
+
getSchema(): import("../types").StorageSchema<ED>;
|
|
34
|
+
abstract isRoot(): boolean;
|
|
35
|
+
abstract getCurrentUserId(allowUnloggedIn?: boolean): string | undefined;
|
|
36
|
+
abstract toString(): string;
|
|
37
|
+
}
|
|
38
|
+
export interface AsyncRowStore<ED extends EntityDict, Cxt extends Context> extends RowStore<ED> {
|
|
39
|
+
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
|
|
40
|
+
select<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]['Schema']>[]>;
|
|
41
|
+
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]['Selection'], 'filter' | 'count'>, context: Cxt, option: OP): Promise<number>;
|
|
42
|
+
begin(option?: TxnOption): Promise<string>;
|
|
43
|
+
commit(txnId: string): Promise<void>;
|
|
44
|
+
rollback(txnId: string): Promise<void>;
|
|
45
|
+
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AsyncContext = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
function UniversalContext(store, headers) {
|
|
6
|
+
var AsyncContext = /** @class */ (function () {
|
|
7
|
+
function AsyncContext(store, headers) {
|
|
9
8
|
this.rowStore = store;
|
|
10
9
|
this.opRecords = [];
|
|
11
|
-
this.rwLock = new concurrent_1.RWLock();
|
|
12
10
|
this.events = {
|
|
13
11
|
commit: [],
|
|
14
12
|
rollback: [],
|
|
@@ -17,56 +15,54 @@ var UniversalContext = /** @class */ (function () {
|
|
|
17
15
|
this.headers = headers;
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
AsyncContext.prototype.setHeaders = function (headers) {
|
|
21
19
|
this.headers = headers;
|
|
22
20
|
};
|
|
23
|
-
|
|
21
|
+
AsyncContext.prototype.getHeader = function (key) {
|
|
24
22
|
if (this.headers) {
|
|
25
23
|
return this.headers[key];
|
|
26
24
|
}
|
|
27
25
|
};
|
|
28
|
-
|
|
26
|
+
AsyncContext.prototype.getScene = function () {
|
|
29
27
|
return this.scene;
|
|
30
28
|
};
|
|
31
|
-
|
|
29
|
+
AsyncContext.prototype.setScene = function (scene) {
|
|
32
30
|
this.scene = scene;
|
|
33
31
|
};
|
|
34
|
-
|
|
32
|
+
AsyncContext.prototype.resetEvents = function () {
|
|
35
33
|
this.events = {
|
|
36
34
|
commit: [],
|
|
37
35
|
rollback: [],
|
|
38
36
|
};
|
|
39
37
|
};
|
|
40
|
-
|
|
38
|
+
AsyncContext.prototype.on = function (event, callback) {
|
|
41
39
|
this.uuid && this.events[event].push(callback);
|
|
42
40
|
};
|
|
43
41
|
/**
|
|
44
42
|
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
45
43
|
* @param options
|
|
46
44
|
*/
|
|
47
|
-
|
|
45
|
+
AsyncContext.prototype.begin = function (options) {
|
|
48
46
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
49
47
|
var _a;
|
|
50
48
|
return tslib_1.__generator(this, function (_b) {
|
|
51
49
|
switch (_b.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
|
|
54
|
-
_b.sent();
|
|
55
|
-
if (!!this.uuid) return [3 /*break*/, 3];
|
|
50
|
+
case 0:
|
|
51
|
+
if (!!this.uuid) return [3 /*break*/, 2];
|
|
56
52
|
_a = this;
|
|
57
53
|
return [4 /*yield*/, this.rowStore.begin(options)];
|
|
58
|
-
case
|
|
54
|
+
case 1:
|
|
59
55
|
_a.uuid = _b.sent();
|
|
60
|
-
return [3 /*break*/,
|
|
61
|
-
case
|
|
56
|
+
return [3 /*break*/, 3];
|
|
57
|
+
case 2:
|
|
62
58
|
(0, assert_1.default)(false);
|
|
63
|
-
_b.label =
|
|
64
|
-
case
|
|
59
|
+
_b.label = 3;
|
|
60
|
+
case 3: return [2 /*return*/];
|
|
65
61
|
}
|
|
66
62
|
});
|
|
67
63
|
});
|
|
68
64
|
};
|
|
69
|
-
|
|
65
|
+
AsyncContext.prototype.commit = function () {
|
|
70
66
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
71
67
|
var _a, _b, e, e_1_1;
|
|
72
68
|
var e_1, _c;
|
|
@@ -77,9 +73,7 @@ var UniversalContext = /** @class */ (function () {
|
|
|
77
73
|
return [4 /*yield*/, this.rowStore.commit(this.uuid)];
|
|
78
74
|
case 1:
|
|
79
75
|
_d.sent();
|
|
80
|
-
// console.log('commit', this.uuid);
|
|
81
76
|
this.uuid = undefined;
|
|
82
|
-
this.rwLock.release();
|
|
83
77
|
_d.label = 2;
|
|
84
78
|
case 2:
|
|
85
79
|
_d.trys.push([2, 7, 8, 9]);
|
|
@@ -114,7 +108,7 @@ var UniversalContext = /** @class */ (function () {
|
|
|
114
108
|
});
|
|
115
109
|
});
|
|
116
110
|
};
|
|
117
|
-
|
|
111
|
+
AsyncContext.prototype.rollback = function () {
|
|
118
112
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
119
113
|
var _a, _b, e, e_2_1;
|
|
120
114
|
var e_2, _c;
|
|
@@ -127,7 +121,6 @@ var UniversalContext = /** @class */ (function () {
|
|
|
127
121
|
_d.sent();
|
|
128
122
|
// console.log('rollback', this.uuid);
|
|
129
123
|
this.uuid = undefined;
|
|
130
|
-
this.rwLock.release();
|
|
131
124
|
_d.label = 2;
|
|
132
125
|
case 2:
|
|
133
126
|
_d.trys.push([2, 7, 8, 9]);
|
|
@@ -162,9 +155,26 @@ var UniversalContext = /** @class */ (function () {
|
|
|
162
155
|
});
|
|
163
156
|
});
|
|
164
157
|
};
|
|
165
|
-
|
|
158
|
+
AsyncContext.prototype.operate = function (entity, operation, option) {
|
|
159
|
+
return this.rowStore.operate(entity, operation, this, option);
|
|
160
|
+
};
|
|
161
|
+
AsyncContext.prototype.select = function (entity, selection, option) {
|
|
162
|
+
return this.rowStore.select(entity, selection, this, option);
|
|
163
|
+
};
|
|
164
|
+
AsyncContext.prototype.count = function (entity, selection, option) {
|
|
165
|
+
return this.rowStore.count(entity, selection, this, option);
|
|
166
|
+
};
|
|
167
|
+
AsyncContext.prototype.mergeMultipleResults = function (toBeMerged) {
|
|
168
|
+
return this.rowStore.mergeMultipleResults(toBeMerged);
|
|
169
|
+
};
|
|
170
|
+
AsyncContext.prototype.getCurrentTxnId = function () {
|
|
166
171
|
return this.uuid;
|
|
167
172
|
};
|
|
168
|
-
|
|
173
|
+
AsyncContext.prototype.getSchema = function () {
|
|
174
|
+
return this.rowStore.getSchema();
|
|
175
|
+
};
|
|
176
|
+
return AsyncContext;
|
|
169
177
|
}());
|
|
170
|
-
exports.
|
|
178
|
+
exports.AsyncContext = AsyncContext;
|
|
179
|
+
;
|
|
180
|
+
;
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EntityDict, OperateOption, SelectOption, OperationResult, SelectRowShape } from "../types/Entity";
|
|
1
|
+
import { EntityDict, OperateOption, SelectOption, OperationResult, DeduceFilter } from "../types/Entity";
|
|
3
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
4
3
|
import { RowStore } from '../types/RowStore';
|
|
5
4
|
import { StorageSchema } from '../types/Storage';
|
|
5
|
+
import { SyncContext } from "./SyncRowStore";
|
|
6
|
+
import { AsyncContext } from "./AsyncRowStore";
|
|
6
7
|
/**这个用来处理级联的select和update,对不同能力的 */
|
|
7
|
-
export declare abstract class CascadeStore<ED extends EntityDict & BaseEntityDict
|
|
8
|
+
export declare abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> extends RowStore<ED> {
|
|
8
9
|
constructor(storageSchema: StorageSchema<ED>);
|
|
9
10
|
protected abstract supportManyToOneJoin(): boolean;
|
|
10
11
|
protected abstract supportMultipleCreate(): boolean;
|
|
11
|
-
protected abstract selectAbjointRow<T extends keyof ED,
|
|
12
|
-
protected abstract updateAbjointRow<T extends keyof ED, OP extends OperateOption
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
private addToResultSelections;
|
|
20
|
-
private reduceDescendants;
|
|
21
|
-
private destructCascadeSelect;
|
|
22
|
-
protected cascadeSelect<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
|
|
23
|
-
protected cascadeSelect2<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
|
|
24
|
-
private destructCascadeUpdate;
|
|
12
|
+
protected abstract selectAbjointRow<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Partial<ED[T]['Schema']>[];
|
|
13
|
+
protected abstract updateAbjointRow<T extends keyof ED, OP extends OperateOption, Cxt extends SyncContext<ED>>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): number;
|
|
14
|
+
protected abstract selectAbjointRowAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]['Schema']>[]>;
|
|
15
|
+
protected abstract updateAbjointRowAsync<T extends keyof ED, OP extends OperateOption, Cxt extends AsyncContext<ED>>(entity: T, operation: ED[T]['Create'] | ED[T]['Update'] | ED[T]['Remove'], context: Cxt, option: OP): Promise<number>;
|
|
16
|
+
protected destructCascadeSelect<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED> | AsyncContext<ED>, R>(entity: T, projection2: ED[T]['Selection']['data'], context: Cxt, cascadeSelect: <T2 extends keyof ED>(entity2: T2, selection: ED[T2]['Selection'], context: Cxt, op: OP) => R, option: OP): {
|
|
17
|
+
projection: ED[T]["Selection"]["data"];
|
|
18
|
+
cascadeSelectionFns: ((result: Partial<ED[T]['Schema']>[]) => Promise<void> | void)[];
|
|
19
|
+
};
|
|
25
20
|
/**
|
|
26
21
|
* 级联更新
|
|
27
22
|
* A --> B
|
|
@@ -46,11 +41,22 @@ export declare abstract class CascadeStore<ED extends EntityDict & BaseEntityDic
|
|
|
46
41
|
* 两者必须通过entity/entityId关联
|
|
47
42
|
* 此时需要把对B的更新记录成一条新插入的Modi对象,并将A上的entity/entityId指向该对象(新生成的Modi对象的id与此operation的id保持一致)
|
|
48
43
|
* @param entity
|
|
49
|
-
* @param
|
|
44
|
+
* @param action
|
|
45
|
+
* @param data
|
|
50
46
|
* @param context
|
|
51
47
|
* @param option
|
|
48
|
+
* @param result
|
|
49
|
+
* @param filter
|
|
50
|
+
* @returns
|
|
52
51
|
*/
|
|
53
|
-
protected
|
|
52
|
+
protected destructCascadeUpdate<T extends keyof ED, Cxt extends SyncContext<ED> | AsyncContext<ED>, OP extends OperateOption, R>(entity: T, action: ED[T]['Action'], data: ED[T]['CreateSingle']['data'] | ED[T]['Update']['data'] | ED[T]['Remove']['data'], context: Cxt, option: OP, cascadeUpdate: <T2 extends keyof ED>(entity: T2, operation: ED[T2]['Operation'], context: Cxt, option: OP) => R, filter?: DeduceFilter<ED[T]['Schema']>): {
|
|
53
|
+
data: Record<string, any>;
|
|
54
|
+
beforeFns: (() => R)[];
|
|
55
|
+
afterFns: (() => R)[];
|
|
56
|
+
};
|
|
57
|
+
protected preProcessDataCreated<T extends keyof ED>(entity: T, data: ED[T]['Create']['data']): void;
|
|
58
|
+
protected preProcessDataUpdated<T extends keyof ED>(data: ED[T]['Update']['data']): void;
|
|
59
|
+
judgeRelation(entity: keyof ED, attr: string): string | 2 | 1 | string[] | 0;
|
|
54
60
|
/**
|
|
55
61
|
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
|
56
62
|
* @param entity
|
|
@@ -58,6 +64,26 @@ export declare abstract class CascadeStore<ED extends EntityDict & BaseEntityDic
|
|
|
58
64
|
* @param context
|
|
59
65
|
* @param option
|
|
60
66
|
*/
|
|
67
|
+
private doUpdateSingleRowAsync;
|
|
61
68
|
private doUpdateSingleRow;
|
|
62
|
-
|
|
69
|
+
protected cascadeUpdate<T extends keyof ED, Cxt extends SyncContext<ED>, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): OperationResult<ED>;
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param entity
|
|
73
|
+
* @param operation
|
|
74
|
+
* @param context
|
|
75
|
+
* @param option
|
|
76
|
+
*/
|
|
77
|
+
protected cascadeUpdateAsync<T extends keyof ED, Cxt extends AsyncContext<ED>, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
|
|
78
|
+
protected cascadeSelect<T extends keyof ED, OP extends SelectOption, Cxt extends SyncContext<ED>>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Partial<ED[T]['Schema']>[];
|
|
79
|
+
/**
|
|
80
|
+
* 将一次查询的结果集加入result
|
|
81
|
+
* todo 如果是supportMtoOJoin,这里还要解构(未充分测试)
|
|
82
|
+
* @param entity
|
|
83
|
+
* @param rows
|
|
84
|
+
* @param context
|
|
85
|
+
*/
|
|
86
|
+
private addToResultSelections;
|
|
87
|
+
private addSingleRowToResultSelections;
|
|
88
|
+
protected cascadeSelectAsync<T extends keyof ED, OP extends SelectOption, Cxt extends AsyncContext<ED>>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]['Schema']>[]>;
|
|
63
89
|
}
|