oak-domain 2.3.2 → 2.4.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/actions/relation.d.ts +4 -0
- package/lib/actions/relation.js +36 -0
- package/lib/base-app-domain/Modi/Schema.d.ts +2 -4
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +2 -4
- package/lib/base-app-domain/Oper/Schema.d.ts +2 -4
- package/lib/base-app-domain/OperEntity/Schema.d.ts +2 -4
- package/lib/base-app-domain/User/Schema.d.ts +2 -4
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +4 -2
- package/lib/compiler/schemalBuilder.js +87 -31
- package/lib/store/CascadeStore.d.ts +4 -4
- package/lib/store/TriggerExecutor.js +45 -26
- package/lib/store/checker.d.ts +10 -4
- package/lib/store/checker.js +342 -235
- package/lib/store/filter.d.ts +11 -2
- package/lib/store/filter.js +40 -25
- package/lib/store/modi.js +0 -8
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/relation.js +1 -1
- package/lib/types/Action.d.ts +5 -1
- package/lib/types/Auth.d.ts +26 -26
- package/lib/types/Endpoint.d.ts +10 -0
- package/lib/types/Endpoint.js +3 -0
- package/lib/types/Entity.d.ts +55 -69
- package/lib/types/Entity.js +0 -1
- package/lib/types/Exception.d.ts +5 -0
- package/lib/types/Exception.js +16 -1
- package/lib/types/Expression.d.ts +24 -2
- package/lib/types/Expression.js +27 -2
- package/lib/types/Port.d.ts +17 -0
- package/lib/types/Port.js +2 -0
- package/lib/types/Storage.d.ts +4 -4
- package/lib/types/Trigger.d.ts +2 -2
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/date.d.ts +1 -0
- package/lib/utils/date.js +18 -0
- package/package.json +2 -2
package/lib/actions/relation.js
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertHierarchyToAuth = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function convertHierarchyToAuth(hierarchy) {
|
|
6
|
+
var e_1, _a;
|
|
7
|
+
var _b;
|
|
8
|
+
var reverseHierarchy = {};
|
|
9
|
+
for (var r in hierarchy) {
|
|
10
|
+
try {
|
|
11
|
+
for (var _c = (e_1 = void 0, tslib_1.__values(hierarchy[r])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
12
|
+
var r2 = _d.value;
|
|
13
|
+
if (reverseHierarchy[r2]) {
|
|
14
|
+
(_b = reverseHierarchy[r2]) === null || _b === void 0 ? void 0 : _b.push(r);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
reverseHierarchy[r2] = [r];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
22
|
+
finally {
|
|
23
|
+
try {
|
|
24
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
25
|
+
}
|
|
26
|
+
finally { if (e_1) throw e_1.error; }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var result = {};
|
|
30
|
+
for (var r in reverseHierarchy) {
|
|
31
|
+
result[r] = {
|
|
32
|
+
cascadePath: '',
|
|
33
|
+
relations: reverseHierarchy[r],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
exports.convertHierarchyToAuth = convertHierarchyToAuth;
|
|
@@ -107,7 +107,7 @@ export declare type SortNode = {
|
|
|
107
107
|
export declare type Sorter = SortNode[];
|
|
108
108
|
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
109
109
|
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
110
|
-
export declare type Aggregation = Omit<DeduceAggregation<
|
|
110
|
+
export declare type Aggregation = Omit<DeduceAggregation<Projection, Filter, Sorter>, "id">;
|
|
111
111
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId">> & ({
|
|
112
112
|
entity?: string;
|
|
113
113
|
entityId?: string;
|
|
@@ -127,10 +127,8 @@ export declare type UpdateOperationData = FormUpdateData<OpSchema> & {
|
|
|
127
127
|
export declare type UpdateOperation = OakOperation<"update" | ParticularAction | string, UpdateOperationData, Filter, Sorter>;
|
|
128
128
|
export declare type RemoveOperationData = {};
|
|
129
129
|
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
130
|
-
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation
|
|
130
|
+
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
131
131
|
export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
|
|
132
|
-
export declare type NativeAttr = OpAttr;
|
|
133
|
-
export declare type FullAttr = NativeAttr | `modiEntitys$${number}.${ModiEntity.NativeAttr}` | `operEntitys$${number}.${OperEntity.NativeAttr}`;
|
|
134
132
|
export declare type EntityDef = {
|
|
135
133
|
Schema: Schema;
|
|
136
134
|
OpSchema: OpSchema;
|
|
@@ -83,7 +83,7 @@ export declare type SortNode = {
|
|
|
83
83
|
export declare type Sorter = SortNode[];
|
|
84
84
|
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
85
85
|
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
86
|
-
export declare type Aggregation = Omit<DeduceAggregation<
|
|
86
|
+
export declare type Aggregation = Omit<DeduceAggregation<Projection, Filter, Sorter>, "id">;
|
|
87
87
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "modiId">> & (({
|
|
88
88
|
modiId?: never;
|
|
89
89
|
modi: Modi.CreateSingleOperation;
|
|
@@ -142,12 +142,10 @@ export declare type RemoveOperationData = {} & (({
|
|
|
142
142
|
[k: string]: any;
|
|
143
143
|
});
|
|
144
144
|
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
145
|
-
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation
|
|
145
|
+
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
146
146
|
export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
|
|
147
147
|
export declare type UserIdSubQuery = Selection<UserIdProjection>;
|
|
148
148
|
export declare type ModiEntityIdSubQuery = Selection<ModiEntityIdProjection>;
|
|
149
|
-
export declare type NativeAttr = OpAttr | `modi.${Modi.NativeAttr}` | `entity.${User.NativeAttr}`;
|
|
150
|
-
export declare type FullAttr = NativeAttr;
|
|
151
149
|
export declare type EntityDef = {
|
|
152
150
|
Schema: Schema;
|
|
153
151
|
OpSchema: OpSchema;
|
|
@@ -89,7 +89,7 @@ export declare type SortNode = {
|
|
|
89
89
|
export declare type Sorter = SortNode[];
|
|
90
90
|
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
91
91
|
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
92
|
-
export declare type Aggregation = Omit<DeduceAggregation<
|
|
92
|
+
export declare type Aggregation = Omit<DeduceAggregation<Projection, Filter, Sorter>, "id">;
|
|
93
93
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "operatorId">> & (({
|
|
94
94
|
operatorId?: never;
|
|
95
95
|
operator?: User.CreateSingleOperation;
|
|
@@ -125,11 +125,9 @@ export declare type RemoveOperationData = {} & (({
|
|
|
125
125
|
operator?: User.UpdateOperation | User.RemoveOperation;
|
|
126
126
|
}));
|
|
127
127
|
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
128
|
-
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation
|
|
128
|
+
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
129
129
|
export declare type UserIdSubQuery = Selection<UserIdProjection>;
|
|
130
130
|
export declare type OperIdSubQuery = Selection<OperIdProjection>;
|
|
131
|
-
export declare type NativeAttr = OpAttr | `operator.${User.NativeAttr}`;
|
|
132
|
-
export declare type FullAttr = NativeAttr | `operEntitys$${number}.${OperEntity.NativeAttr}`;
|
|
133
131
|
export declare type EntityDef = {
|
|
134
132
|
Schema: Schema;
|
|
135
133
|
OpSchema: OpSchema;
|
|
@@ -92,7 +92,7 @@ export declare type SortNode = {
|
|
|
92
92
|
export declare type Sorter = SortNode[];
|
|
93
93
|
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
94
94
|
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
95
|
-
export declare type Aggregation = Omit<DeduceAggregation<
|
|
95
|
+
export declare type Aggregation = Omit<DeduceAggregation<Projection, Filter, Sorter>, "id">;
|
|
96
96
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "operId">> & (({
|
|
97
97
|
operId?: never;
|
|
98
98
|
oper: Oper.CreateSingleOperation;
|
|
@@ -157,13 +157,11 @@ export declare type RemoveOperationData = {} & ({
|
|
|
157
157
|
[k: string]: any;
|
|
158
158
|
});
|
|
159
159
|
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
160
|
-
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation
|
|
160
|
+
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
161
161
|
export declare type OperIdSubQuery = Selection<OperIdProjection>;
|
|
162
162
|
export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
|
|
163
163
|
export declare type UserIdSubQuery = Selection<UserIdProjection>;
|
|
164
164
|
export declare type OperEntityIdSubQuery = Selection<OperEntityIdProjection>;
|
|
165
|
-
export declare type NativeAttr = OpAttr | `oper.${Oper.NativeAttr}` | `entity.${Modi.NativeAttr}` | `entity.${User.NativeAttr}`;
|
|
166
|
-
export declare type FullAttr = NativeAttr;
|
|
167
165
|
export declare type EntityDef = {
|
|
168
166
|
Schema: Schema;
|
|
169
167
|
OpSchema: OpSchema;
|
|
@@ -92,7 +92,7 @@ export declare type SortNode = {
|
|
|
92
92
|
export declare type Sorter = SortNode[];
|
|
93
93
|
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
94
94
|
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
95
|
-
export declare type Aggregation = Omit<DeduceAggregation<
|
|
95
|
+
export declare type Aggregation = Omit<DeduceAggregation<Projection, Filter, Sorter>, "id">;
|
|
96
96
|
export declare type CreateOperationData = FormCreateData<OpSchema> & {
|
|
97
97
|
oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>;
|
|
98
98
|
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
|
|
@@ -110,10 +110,8 @@ export declare type UpdateOperationData = FormUpdateData<OpSchema> & {
|
|
|
110
110
|
export declare type UpdateOperation = OakOperation<"update" | RelationAction | string, UpdateOperationData, Filter, Sorter>;
|
|
111
111
|
export declare type RemoveOperationData = {};
|
|
112
112
|
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
113
|
-
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation
|
|
113
|
+
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
114
114
|
export declare type UserIdSubQuery = Selection<UserIdProjection>;
|
|
115
|
-
export declare type NativeAttr = OpAttr;
|
|
116
|
-
export declare type FullAttr = NativeAttr | `opers$${number}.${Oper.NativeAttr}` | `operEntitys$${number}.${OperEntity.NativeAttr}` | `modiEntitys$${number}.${ModiEntity.NativeAttr}`;
|
|
117
115
|
export declare type EntityDef = {
|
|
118
116
|
Schema: Schema;
|
|
119
117
|
OpSchema: OpSchema;
|
package/lib/checkers/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EntityDict } from '../base-app-domain';
|
|
2
2
|
import { AsyncContext } from '../store/AsyncRowStore';
|
|
3
3
|
import { SyncContext } from '../store/SyncRowStore';
|
|
4
|
-
import { StorageSchema, EntityDict as BaseEntityDict, Checker } from '../types';
|
|
5
|
-
export declare function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
|
|
4
|
+
import { StorageSchema, EntityDict as BaseEntityDict, Checker, AuthDefDict } from '../types';
|
|
5
|
+
export declare function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict?: AuthDefDict<ED>): Checker<ED, keyof ED, Cxt>[];
|
package/lib/checkers/index.js
CHANGED
|
@@ -4,10 +4,12 @@ exports.createDynamicCheckers = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var checker_1 = require("../store/checker");
|
|
6
6
|
var modi_1 = require("../store/modi");
|
|
7
|
-
function createDynamicCheckers(schema) {
|
|
7
|
+
function createDynamicCheckers(schema, authDict) {
|
|
8
8
|
var checkers = [];
|
|
9
9
|
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, modi_1.createModiRelatedCheckers)(schema)), false));
|
|
10
|
-
|
|
10
|
+
if (authDict) {
|
|
11
|
+
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createAuthCheckers)(schema, authDict)), false));
|
|
12
|
+
}
|
|
11
13
|
return checkers;
|
|
12
14
|
}
|
|
13
15
|
exports.createDynamicCheckers = createDynamicCheckers;
|
|
@@ -337,7 +337,8 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
337
337
|
var localEnumStringTypes = [];
|
|
338
338
|
var additionalImports = [];
|
|
339
339
|
var localeDef = undefined;
|
|
340
|
-
|
|
340
|
+
// let relationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
|
|
341
|
+
// let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
|
|
341
342
|
ts.forEachChild(sourceFile, function (node) {
|
|
342
343
|
var _a, _b, _c, _d;
|
|
343
344
|
if (ts.isImportDeclaration(node)) {
|
|
@@ -795,15 +796,22 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
795
796
|
_static = true; // static如果有值只能为true
|
|
796
797
|
}
|
|
797
798
|
}
|
|
798
|
-
else if (ts.isTypeReferenceNode(declaration.type) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'RelationHierarchy') {
|
|
799
|
+
/* else if (ts.isTypeReferenceNode(declaration.type!) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'RelationHierarchy') {
|
|
799
800
|
// RelationHierary
|
|
800
|
-
(
|
|
801
|
-
|
|
802
|
-
(
|
|
801
|
+
assert(hasRelationDef, `${moduleName}中的Relation定义在RelationHierarchy之后`);
|
|
802
|
+
const { initializer } = declaration;
|
|
803
|
+
assert(ts.isObjectLiteralExpression(initializer!), `${moduleName}中的RelationHierarchy的定义必须是初始化为ObjectLiteralExpress`);
|
|
803
804
|
relationHierarchy = initializer;
|
|
804
805
|
}
|
|
806
|
+
else if (ts.isTypeReferenceNode(declaration.type!) && ts.isIdentifier(declaration.type.typeName) && declaration.type.typeName.text === 'ReverseCascadeRelationHierarchy') {
|
|
807
|
+
// ReverseCascadeRelationHierarchy
|
|
808
|
+
assert(hasRelationDef, `${moduleName}中的Relation定义在ReverseCascadeRelationHierarchy之后`);
|
|
809
|
+
const { initializer } = declaration;
|
|
810
|
+
assert(ts.isObjectLiteralExpression(initializer!), `${moduleName}中的RelationHierarchy的定义必须是初始化为ObjectLiteralExpress`);
|
|
811
|
+
reverseCascadeRelationHierarchy = initializer;
|
|
812
|
+
} */
|
|
805
813
|
else {
|
|
806
|
-
throw new Error("".concat(moduleName, "\uFF1A\u4E0D\u80FD\u7406\u89E3\u7684\u5B9A\u4E49\u5185\u5BB9").concat(declaration.name.
|
|
814
|
+
throw new Error("".concat(moduleName, "\uFF1A\u4E0D\u80FD\u7406\u89E3\u7684\u5B9A\u4E49\u5185\u5BB9").concat(declaration.name.text));
|
|
807
815
|
}
|
|
808
816
|
});
|
|
809
817
|
}
|
|
@@ -843,15 +851,25 @@ function analyzeEntity(filename, path, program, relativePath) {
|
|
|
843
851
|
locale: localeDef,
|
|
844
852
|
});
|
|
845
853
|
}
|
|
846
|
-
if (hasRelationDef) {
|
|
847
|
-
(
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
854
|
+
/* if (hasRelationDef) {
|
|
855
|
+
if(!relationHierarchy && !reverseCascadeRelationHierarchy){
|
|
856
|
+
console.warn(`${filename}中定义了Relation,但并没有relationHierarchy或reverseCascadeRelationHierarchy的定义,请注意自主编写权限分配的checker`);
|
|
857
|
+
}
|
|
858
|
+
if (relationHierarchy) {
|
|
859
|
+
assign(schema, {
|
|
860
|
+
relationHierarchy,
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
if (reverseCascadeRelationHierarchy) {
|
|
864
|
+
assign(schema, {
|
|
865
|
+
reverseCascadeRelationHierarchy,
|
|
866
|
+
});
|
|
867
|
+
}
|
|
851
868
|
}
|
|
852
869
|
else {
|
|
853
|
-
(
|
|
854
|
-
|
|
870
|
+
assert(!relationHierarchy, `${filename}中具有relationHierarchy定义但没有Relation定义`);
|
|
871
|
+
assert(!reverseCascadeRelationHierarchy, `${filename}中具有reverseCascadeRelationHierarchy定义但没有Relation定义`)
|
|
872
|
+
} */
|
|
855
873
|
(0, lodash_1.assign)(Schema, (_a = {},
|
|
856
874
|
_a[moduleName] = schema,
|
|
857
875
|
_a));
|
|
@@ -1783,7 +1801,6 @@ function constructActions(statements, entity) {
|
|
|
1783
1801
|
factory.createLiteralTypeNode(factory.createStringLiteral("action"))
|
|
1784
1802
|
])), factory.createTypeAliasDeclaration(undefined, [factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Aggregation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
1785
1803
|
factory.createTypeReferenceNode(factory.createIdentifier("DeduceAggregation"), [
|
|
1786
|
-
factory.createTypeReferenceNode(factory.createIdentifier("Schema"), undefined),
|
|
1787
1804
|
factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined),
|
|
1788
1805
|
factory.createTypeReferenceNode(factory.createIdentifier("Filter"), undefined),
|
|
1789
1806
|
factory.createTypeReferenceNode(factory.createIdentifier("Sorter"), undefined)
|
|
@@ -1939,6 +1956,11 @@ function constructActions(statements, entity) {
|
|
|
1939
1956
|
var reverseOneNodes = [];
|
|
1940
1957
|
if (ReversePointerEntities[entity]) {
|
|
1941
1958
|
if (ReversePointerRelations[entity]) {
|
|
1959
|
+
var schemaAttrs = Schema[entity].schemaAttrs;
|
|
1960
|
+
var questionToken = schemaAttrs.find(function (ele) {
|
|
1961
|
+
var name = ele.name;
|
|
1962
|
+
return name.text === 'entity';
|
|
1963
|
+
}).questionToken;
|
|
1942
1964
|
try {
|
|
1943
1965
|
for (var _q = tslib_1.__values(ReversePointerRelations[entity]), _r = _q.next(); !_r.done; _r = _q.next()) {
|
|
1944
1966
|
var one = _r.value;
|
|
@@ -1956,10 +1978,8 @@ function constructActions(statements, entity) {
|
|
|
1956
1978
|
factory.createPropertySignature(undefined, factory.createIdentifier((0, string_1.firstLetterLowerCase)(one)), undefined, factory.createTypeReferenceNode(createForeignRef(entity, one, 'UpdateOperation')))
|
|
1957
1979
|
]);
|
|
1958
1980
|
var noCascadeNode = factory.createTypeLiteralNode([
|
|
1959
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('entity'),
|
|
1960
|
-
factory.
|
|
1961
|
-
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), undefined, // 反向指针好像不能为空,以后或许会有特例 by Xc
|
|
1962
|
-
factory.createTypeReferenceNode(factory.createIdentifier("String"), [factory.createLiteralTypeNode(factory.createNumericLiteral("64"))]))
|
|
1981
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('entity'), questionToken, factory.createLiteralTypeNode(factory.createStringLiteral("".concat((0, string_1.firstLetterLowerCase)(one))))),
|
|
1982
|
+
factory.createPropertySignature(undefined, factory.createIdentifier('entityId'), questionToken, factory.createTypeReferenceNode(factory.createIdentifier("String"), [factory.createLiteralTypeNode(factory.createNumericLiteral("64"))]))
|
|
1963
1983
|
]);
|
|
1964
1984
|
if (Schema[one].static) {
|
|
1965
1985
|
reverseOneNodes.push(noCascadeNode);
|
|
@@ -2584,8 +2604,7 @@ function constructActions(statements, entity) {
|
|
|
2584
2604
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Operation"), undefined, factory.createUnionTypeNode([
|
|
2585
2605
|
factory.createTypeReferenceNode(factory.createIdentifier("CreateOperation"), undefined),
|
|
2586
2606
|
factory.createTypeReferenceNode(factory.createIdentifier("UpdateOperation"), undefined),
|
|
2587
|
-
factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)
|
|
2588
|
-
factory.createTypeReferenceNode(factory.createIdentifier("SelectOperation"), undefined)
|
|
2607
|
+
factory.createTypeReferenceNode(factory.createIdentifier("RemoveOperation"), undefined)
|
|
2589
2608
|
])));
|
|
2590
2609
|
}
|
|
2591
2610
|
var initialStatements = function () { return [
|
|
@@ -2642,7 +2661,6 @@ var initialStatements = function () { return [
|
|
|
2642
2661
|
function outputSubQuery(outputDir, printer) {
|
|
2643
2662
|
var statements = [];
|
|
2644
2663
|
if (process.env.COMPLING_AS_LIB) {
|
|
2645
|
-
statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("Selection"))])), factory.createStringLiteral((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(1)), undefined));
|
|
2646
2664
|
}
|
|
2647
2665
|
for (var entity in Schema) {
|
|
2648
2666
|
// import * as User from '../User/Schema';
|
|
@@ -2755,7 +2773,8 @@ function outputSchema(outputDir, printer) {
|
|
|
2755
2773
|
constructSorter(statements, entity);
|
|
2756
2774
|
constructActions(statements, entity);
|
|
2757
2775
|
constructQuery(statements, entity);
|
|
2758
|
-
|
|
2776
|
+
// 现在FullAttrs和NativeAttrs似乎没什么用,还会引起递归
|
|
2777
|
+
// constructFullAttrs(statements, entity);
|
|
2759
2778
|
var makeActionArguments = [];
|
|
2760
2779
|
if (ActionAsts[entity]) {
|
|
2761
2780
|
makeActionArguments.push(factory.createTypeReferenceNode('Action'));
|
|
@@ -2787,6 +2806,9 @@ function outputSchema(outputDir, printer) {
|
|
|
2787
2806
|
if (ActionAsts[entity]) {
|
|
2788
2807
|
EntityDefAttrs.push(factory.createPropertySignature(undefined, factory.createIdentifier("ParticularAction"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('ParticularAction'), undefined)));
|
|
2789
2808
|
}
|
|
2809
|
+
if (typeof Schema[entity].hasRelationDef === 'object' && ts.isTypeAliasDeclaration(Schema[entity].hasRelationDef)) {
|
|
2810
|
+
EntityDefAttrs.push(factory.createPropertySignature(undefined, factory.createIdentifier("Relation"), undefined, factory.createTypeReferenceNode(factory.createIdentifier('Relation'), undefined)));
|
|
2811
|
+
}
|
|
2790
2812
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDef"), undefined, factory.createTypeLiteralNode(EntityDefAttrs)));
|
|
2791
2813
|
var result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), Schema[entity].sourceFile);
|
|
2792
2814
|
var fileName = path_1.default.join(outputDir, entity, 'Schema.ts');
|
|
@@ -3045,13 +3067,19 @@ function outputStorage(outputDir, printer) {
|
|
|
3045
3067
|
var entityAssignments = [];
|
|
3046
3068
|
for (var entity in Schema) {
|
|
3047
3069
|
var indexExpressions = [];
|
|
3048
|
-
var _a = Schema[entity], sourceFile = _a.sourceFile, inModi = _a.inModi, indexes = _a.indexes, toModi = _a.toModi, actionType = _a.actionType, _static = _a.static,
|
|
3070
|
+
var _a = Schema[entity], sourceFile = _a.sourceFile, inModi = _a.inModi, indexes = _a.indexes, toModi = _a.toModi, actionType = _a.actionType, _static = _a.static, hasRelationDef = _a.hasRelationDef;
|
|
3049
3071
|
var fromSchemaSpecifiers = [
|
|
3050
3072
|
factory.createImportSpecifier(false, undefined, factory.createIdentifier("OpSchema"))
|
|
3051
3073
|
];
|
|
3052
|
-
if (relationHierarchy) {
|
|
3053
|
-
fromSchemaSpecifiers.push(
|
|
3054
|
-
|
|
3074
|
+
/* if (relationHierarchy || reverseCascadeRelationHierarchy) {
|
|
3075
|
+
fromSchemaSpecifiers.push(
|
|
3076
|
+
factory.createImportSpecifier(
|
|
3077
|
+
false,
|
|
3078
|
+
undefined,
|
|
3079
|
+
factory.createIdentifier("Relation")
|
|
3080
|
+
)
|
|
3081
|
+
);
|
|
3082
|
+
} */
|
|
3055
3083
|
var statements = [
|
|
3056
3084
|
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("StorageDesc"))])), factory.createStringLiteral("".concat((0, env_1.TYPE_PATH_IN_OAK_DOMAIN)(), "Storage")), undefined),
|
|
3057
3085
|
factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports(fromSchemaSpecifiers)), factory.createStringLiteral("./Schema"), undefined)
|
|
@@ -3110,15 +3138,43 @@ function outputStorage(outputDir, printer) {
|
|
|
3110
3138
|
if (indexExpressions.length > 0) {
|
|
3111
3139
|
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("indexes"), factory.createArrayLiteralExpression(indexExpressions, true)));
|
|
3112
3140
|
}
|
|
3113
|
-
if (relationHierarchy) {
|
|
3114
|
-
propertyAssignments.push(
|
|
3141
|
+
/* if (relationHierarchy) {
|
|
3142
|
+
propertyAssignments.push(
|
|
3143
|
+
factory.createPropertyAssignment(
|
|
3144
|
+
factory.createIdentifier("relationHierarchy"),
|
|
3145
|
+
relationHierarchy,
|
|
3146
|
+
)
|
|
3147
|
+
);
|
|
3148
|
+
}
|
|
3149
|
+
if (reverseCascadeRelationHierarchy) {
|
|
3150
|
+
propertyAssignments.push(
|
|
3151
|
+
factory.createPropertyAssignment(
|
|
3152
|
+
factory.createIdentifier("reverseCascadeRelationHierarchy"),
|
|
3153
|
+
reverseCascadeRelationHierarchy,
|
|
3154
|
+
)
|
|
3155
|
+
);
|
|
3156
|
+
} */
|
|
3157
|
+
if (hasRelationDef) {
|
|
3158
|
+
var type = hasRelationDef.type;
|
|
3159
|
+
if (ts.isUnionTypeNode(type)) {
|
|
3160
|
+
var types = type.types;
|
|
3161
|
+
var relationTexts = types.map(function (ele) {
|
|
3162
|
+
(0, assert_1.default)(ts.isLiteralTypeNode(ele) && ts.isStringLiteral(ele.literal));
|
|
3163
|
+
return ele.literal.text;
|
|
3164
|
+
});
|
|
3165
|
+
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("relation"), factory.createArrayLiteralExpression(relationTexts.map(function (ele) { return factory.createStringLiteral(ele); }))));
|
|
3166
|
+
}
|
|
3167
|
+
else {
|
|
3168
|
+
(0, assert_1.default)(ts.isLiteralTypeNode(type));
|
|
3169
|
+
(0, assert_1.default)(ts.isStringLiteral(type.literal));
|
|
3170
|
+
propertyAssignments.push(factory.createPropertyAssignment(factory.createIdentifier("relation"), factory.createArrayLiteralExpression([
|
|
3171
|
+
type.literal
|
|
3172
|
+
])));
|
|
3173
|
+
}
|
|
3115
3174
|
}
|
|
3116
3175
|
var sdTypeArguments = [
|
|
3117
3176
|
factory.createTypeReferenceNode(factory.createIdentifier("OpSchema"), undefined)
|
|
3118
3177
|
];
|
|
3119
|
-
if (relationHierarchy) {
|
|
3120
|
-
sdTypeArguments.push(factory.createTypeReferenceNode(factory.createIdentifier("Relation"), undefined));
|
|
3121
|
-
}
|
|
3122
3178
|
statements.push(factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier("desc"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("StorageDesc"), sdTypeArguments), factory.createObjectLiteralExpression(propertyAssignments, true))], ts.NodeFlags.Const)));
|
|
3123
3179
|
var result_2 = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements), sourceFile);
|
|
3124
3180
|
var filename_1 = path_1.default.join(outputDir, entity, 'Storage.ts');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityDict, OperateOption, SelectOption, OperationResult,
|
|
1
|
+
import { EntityDict, OperateOption, SelectOption, OperationResult, AggregationResult } from "../types/Entity";
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
3
|
import { RowStore } from '../types/RowStore';
|
|
4
4
|
import { StorageSchema } from '../types/Storage';
|
|
@@ -51,14 +51,14 @@ export declare abstract class CascadeStore<ED extends EntityDict & BaseEntityDic
|
|
|
51
51
|
* @param filter
|
|
52
52
|
* @returns
|
|
53
53
|
*/
|
|
54
|
-
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?:
|
|
54
|
+
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?: ED[T]['Update']['filter']): {
|
|
55
55
|
data: Record<string, any>;
|
|
56
56
|
beforeFns: (() => R)[];
|
|
57
57
|
afterFns: (() => R)[];
|
|
58
58
|
};
|
|
59
59
|
protected preProcessDataCreated<T extends keyof ED>(entity: T, data: ED[T]['Create']['data']): void;
|
|
60
|
-
protected preProcessDataUpdated
|
|
61
|
-
judgeRelation(entity: keyof ED, attr: string): string |
|
|
60
|
+
protected preProcessDataUpdated(data: Record<string, any>): void;
|
|
61
|
+
judgeRelation(entity: keyof ED, attr: string): string | 1 | 2 | string[] | 0;
|
|
62
62
|
/**
|
|
63
63
|
* 和具体的update过程无关的例程放在这里,包括对later动作的处理、对oper的记录以及对record的收集等
|
|
64
64
|
* @param entity
|
|
@@ -32,15 +32,15 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
32
32
|
TriggerExecutor.prototype.registerChecker = function (checker) {
|
|
33
33
|
var entity = checker.entity, action = checker.action, type = checker.type, conditionalFilter = checker.conditionalFilter;
|
|
34
34
|
var triggerName = "".concat(String(entity)).concat(action, "\u6743\u9650\u68C0\u67E5-").concat(this.counter++);
|
|
35
|
-
var
|
|
35
|
+
var _a = (0, checker_1.translateCheckerInAsyncContext)(checker), fn = _a.fn, when = _a.when;
|
|
36
36
|
var trigger = {
|
|
37
37
|
checkerType: type,
|
|
38
38
|
name: triggerName,
|
|
39
|
-
priority: checker.priority ||
|
|
39
|
+
priority: checker.priority || 20,
|
|
40
40
|
entity: entity,
|
|
41
41
|
action: action,
|
|
42
42
|
fn: fn,
|
|
43
|
-
when:
|
|
43
|
+
when: when,
|
|
44
44
|
filter: conditionalFilter,
|
|
45
45
|
};
|
|
46
46
|
this.registerTrigger(trigger);
|
|
@@ -59,7 +59,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
59
59
|
throw new Error("\u4E0D\u53EF\u6709\u540C\u540D\u7684\u89E6\u53D1\u5668\u300C".concat(trigger.name, "\u300D"));
|
|
60
60
|
}
|
|
61
61
|
if (typeof trigger.priority !== 'number') {
|
|
62
|
-
trigger.priority =
|
|
62
|
+
trigger.priority = 10; // 默认值
|
|
63
63
|
}
|
|
64
64
|
if (trigger.filter) {
|
|
65
65
|
(0, assert_1.default)(typeof trigger.action === 'string' && trigger.action !== 'create'
|
|
@@ -205,6 +205,7 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
205
205
|
(0, assert_1.default)(operation.action !== 'create');
|
|
206
206
|
var filter = trigger.filter;
|
|
207
207
|
var filterr = typeof filter === 'function' ? filter(operation, context, option) : filter;
|
|
208
|
+
(0, assert_1.default)(!(filterr instanceof Promise));
|
|
208
209
|
var filterRepelled = (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter);
|
|
209
210
|
if (filterRepelled) {
|
|
210
211
|
continue;
|
|
@@ -228,28 +229,37 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
228
229
|
else {
|
|
229
230
|
// 异步context
|
|
230
231
|
var execPreTrigger_1 = function (idx) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
231
|
-
var trigger, filter, filterr, filterRepelled, number;
|
|
232
|
-
return tslib_1.__generator(this, function (
|
|
233
|
-
switch (
|
|
232
|
+
var trigger, filter, filterr, _a, filterRepelled, number;
|
|
233
|
+
return tslib_1.__generator(this, function (_b) {
|
|
234
|
+
switch (_b.label) {
|
|
234
235
|
case 0:
|
|
235
236
|
if (idx >= preTriggers_2.length) {
|
|
236
237
|
return [2 /*return*/];
|
|
237
238
|
}
|
|
238
239
|
trigger = preTriggers_2[idx];
|
|
239
|
-
if (!trigger.filter) return [3 /*break*/,
|
|
240
|
+
if (!trigger.filter) return [3 /*break*/, 5];
|
|
240
241
|
(0, assert_1.default)(operation.action !== 'create');
|
|
241
242
|
filter = trigger.filter;
|
|
242
|
-
|
|
243
|
-
return [4 /*yield*/, (
|
|
243
|
+
if (!(typeof filter === 'function')) return [3 /*break*/, 2];
|
|
244
|
+
return [4 /*yield*/, filter(operation, context, option)];
|
|
244
245
|
case 1:
|
|
245
|
-
|
|
246
|
+
_a = _b.sent();
|
|
247
|
+
return [3 /*break*/, 3];
|
|
248
|
+
case 2:
|
|
249
|
+
_a = filter;
|
|
250
|
+
_b.label = 3;
|
|
251
|
+
case 3:
|
|
252
|
+
filterr = _a;
|
|
253
|
+
return [4 /*yield*/, (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter)];
|
|
254
|
+
case 4:
|
|
255
|
+
filterRepelled = _b.sent();
|
|
246
256
|
if (filterRepelled) {
|
|
247
257
|
return [2 /*return*/, execPreTrigger_1(idx + 1)];
|
|
248
258
|
}
|
|
249
|
-
|
|
250
|
-
case
|
|
251
|
-
case
|
|
252
|
-
number =
|
|
259
|
+
_b.label = 5;
|
|
260
|
+
case 5: return [4 /*yield*/, trigger.fn({ operation: operation }, context, option)];
|
|
261
|
+
case 6:
|
|
262
|
+
number = _b.sent();
|
|
253
263
|
if (number > 0) {
|
|
254
264
|
this.logger.info("\u89E6\u53D1\u5668\u300C".concat(trigger.name, "\u300D\u6210\u529F\u89E6\u53D1\u4E86\u300C").concat(number, "\u300D\u884C\u6570\u636E\u66F4\u6539"));
|
|
255
265
|
}
|
|
@@ -258,28 +268,37 @@ var TriggerExecutor = /** @class */ (function () {
|
|
|
258
268
|
});
|
|
259
269
|
}); };
|
|
260
270
|
var execCommitTrigger_1 = function (idx) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
261
|
-
var trigger, filter, filterr, filterRepelled;
|
|
262
|
-
return tslib_1.__generator(this, function (
|
|
263
|
-
switch (
|
|
271
|
+
var trigger, filter, filterr, _a, filterRepelled;
|
|
272
|
+
return tslib_1.__generator(this, function (_b) {
|
|
273
|
+
switch (_b.label) {
|
|
264
274
|
case 0:
|
|
265
275
|
if (idx >= commitTriggers_1.length) {
|
|
266
276
|
return [2 /*return*/];
|
|
267
277
|
}
|
|
268
278
|
trigger = commitTriggers_1[idx];
|
|
269
|
-
if (!trigger.filter) return [3 /*break*/,
|
|
279
|
+
if (!trigger.filter) return [3 /*break*/, 5];
|
|
270
280
|
(0, assert_1.default)(operation.action !== 'create');
|
|
271
281
|
filter = trigger.filter;
|
|
272
|
-
|
|
273
|
-
return [4 /*yield*/, (
|
|
282
|
+
if (!(typeof filter === 'function')) return [3 /*break*/, 2];
|
|
283
|
+
return [4 /*yield*/, filter(operation, context, option)];
|
|
274
284
|
case 1:
|
|
275
|
-
|
|
285
|
+
_a = _b.sent();
|
|
286
|
+
return [3 /*break*/, 3];
|
|
287
|
+
case 2:
|
|
288
|
+
_a = filter;
|
|
289
|
+
_b.label = 3;
|
|
290
|
+
case 3:
|
|
291
|
+
filterr = _a;
|
|
292
|
+
return [4 /*yield*/, (0, filter_1.checkFilterRepel)(entity, context, filterr, operation.filter)];
|
|
293
|
+
case 4:
|
|
294
|
+
filterRepelled = _b.sent();
|
|
276
295
|
if (filterRepelled) {
|
|
277
296
|
return [2 /*return*/, execCommitTrigger_1(idx + 1)];
|
|
278
297
|
}
|
|
279
|
-
|
|
280
|
-
case
|
|
281
|
-
case
|
|
282
|
-
|
|
298
|
+
_b.label = 5;
|
|
299
|
+
case 5: return [4 /*yield*/, this.preCommitTrigger(entity, operation, trigger, context, option)];
|
|
300
|
+
case 6:
|
|
301
|
+
_b.sent();
|
|
283
302
|
return [2 /*return*/, execCommitTrigger_1(idx + 1)];
|
|
284
303
|
}
|
|
285
304
|
});
|
package/lib/store/checker.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { Checker, EntityDict, OperateOption, SelectOption, StorageSchema, Trigger } from "../types";
|
|
1
|
+
import { AuthDefDict, Checker, EntityDict, OperateOption, SelectOption, StorageSchema, Trigger } from "../types";
|
|
2
2
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
3
3
|
import { AsyncContext } from "./AsyncRowStore";
|
|
4
4
|
import { SyncContext } from './SyncRowStore';
|
|
5
|
-
export declare function translateCheckerInAsyncContext<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(checker: Checker<ED, keyof ED, Cxt>):
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export declare function translateCheckerInAsyncContext<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(checker: Checker<ED, keyof ED, Cxt>): {
|
|
6
|
+
fn: Trigger<ED, keyof ED, Cxt>['fn'];
|
|
7
|
+
when: 'before' | 'after';
|
|
8
|
+
};
|
|
9
|
+
export declare function translateCheckerInSyncContext<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends SyncContext<ED>>(checker: Checker<ED, T, Cxt>): {
|
|
10
|
+
fn: (operation: ED[T]['Operation'], context: Cxt, option: OperateOption | SelectOption) => void;
|
|
11
|
+
when: 'before' | 'after';
|
|
12
|
+
};
|
|
13
|
+
export declare function createAuthCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict: AuthDefDict<ED>): Checker<ED, keyof ED, Cxt>[];
|