oak-domain 1.1.0 → 1.1.3
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 +5 -2
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +2 -2
- package/lib/base-app-domain/Oper/Schema.d.ts +5 -2
- package/lib/base-app-domain/OperEntity/Schema.d.ts +2 -2
- package/lib/base-app-domain/User/Schema.d.ts +2 -2
- package/lib/checkers/index.d.ts +1 -1
- package/lib/checkers/index.js +3 -3
- package/lib/compiler/schemalBuilder.js +8 -4
- package/lib/store/CascadeStore.js +263 -178
- package/lib/store/actionDef.js +20 -4
- package/lib/store/modi.d.ts +4 -3
- package/lib/store/modi.js +58 -11
- package/lib/triggers/index.d.ts +4 -1
- package/lib/triggers/index.js +6 -0
- package/package.json +1 -1
|
@@ -47,6 +47,9 @@ declare type AttrFilter = {
|
|
|
47
47
|
entity: Q_StringValue;
|
|
48
48
|
entityId: Q_StringValue;
|
|
49
49
|
action: Q_StringValue;
|
|
50
|
+
data: Object;
|
|
51
|
+
filter: Object;
|
|
52
|
+
extra: Object;
|
|
50
53
|
iState: Q_EnumValue<IState>;
|
|
51
54
|
};
|
|
52
55
|
export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
|
|
@@ -119,8 +122,8 @@ export declare type SortNode = {
|
|
|
119
122
|
$direction?: "asc" | "desc";
|
|
120
123
|
};
|
|
121
124
|
export declare type Sorter = SortNode[];
|
|
122
|
-
export declare type SelectOperation<P = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
123
|
-
export declare type Selection<P = Projection> = Omit<SelectOperation<P>, "action">;
|
|
125
|
+
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
126
|
+
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
124
127
|
export declare type Exportation = OakOperation<"export", ExportProjection, Filter, Sorter>;
|
|
125
128
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId">> & ({
|
|
126
129
|
entity?: string;
|
|
@@ -97,8 +97,8 @@ export declare type SortNode = {
|
|
|
97
97
|
$direction?: "asc" | "desc";
|
|
98
98
|
};
|
|
99
99
|
export declare type Sorter = SortNode[];
|
|
100
|
-
export declare type SelectOperation<P = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
101
|
-
export declare type Selection<P = Projection> = Omit<SelectOperation<P>, "action">;
|
|
100
|
+
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
101
|
+
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
102
102
|
export declare type Exportation = OakOperation<"export", ExportProjection, Filter, Sorter>;
|
|
103
103
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "modiId">> & (({
|
|
104
104
|
modiId?: never;
|
|
@@ -38,6 +38,9 @@ declare type AttrFilter = {
|
|
|
38
38
|
$$createAt$$: Q_DateValue;
|
|
39
39
|
$$updateAt$$: Q_DateValue;
|
|
40
40
|
action: Q_StringValue;
|
|
41
|
+
data: Object;
|
|
42
|
+
filter: Object;
|
|
43
|
+
extra: Object;
|
|
41
44
|
operatorId: Q_StringValue | SubQuery.UserIdSubQuery;
|
|
42
45
|
operator: User.Filter;
|
|
43
46
|
};
|
|
@@ -100,8 +103,8 @@ export declare type SortNode = {
|
|
|
100
103
|
$direction?: "asc" | "desc";
|
|
101
104
|
};
|
|
102
105
|
export declare type Sorter = SortNode[];
|
|
103
|
-
export declare type SelectOperation<P = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
104
|
-
export declare type Selection<P = Projection> = Omit<SelectOperation<P>, "action">;
|
|
106
|
+
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
107
|
+
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
105
108
|
export declare type Exportation = OakOperation<"export", ExportProjection, Filter, Sorter>;
|
|
106
109
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "operatorId">> & (({
|
|
107
110
|
operatorId?: never;
|
|
@@ -107,8 +107,8 @@ export declare type SortNode = {
|
|
|
107
107
|
$direction?: "asc" | "desc";
|
|
108
108
|
};
|
|
109
109
|
export declare type Sorter = SortNode[];
|
|
110
|
-
export declare type SelectOperation<P = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
111
|
-
export declare type Selection<P = Projection> = Omit<SelectOperation<P>, "action">;
|
|
110
|
+
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
111
|
+
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
112
112
|
export declare type Exportation = OakOperation<"export", ExportProjection, Filter, Sorter>;
|
|
113
113
|
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "operId">> & (({
|
|
114
114
|
operId?: never;
|
|
@@ -101,8 +101,8 @@ export declare type SortNode = {
|
|
|
101
101
|
$direction?: "asc" | "desc";
|
|
102
102
|
};
|
|
103
103
|
export declare type Sorter = SortNode[];
|
|
104
|
-
export declare type SelectOperation<P = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
105
|
-
export declare type Selection<P = Projection> = Omit<SelectOperation<P>, "action">;
|
|
104
|
+
export declare type SelectOperation<P extends Object = Projection> = Omit<OakOperation<"select", P, Filter, Sorter>, "id">;
|
|
105
|
+
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
|
|
106
106
|
export declare type Exportation = OakOperation<"export", ExportProjection, Filter, Sorter>;
|
|
107
107
|
export declare type CreateOperationData = FormCreateData<OpSchema> & {
|
|
108
108
|
oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>;
|
package/lib/checkers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { EntityDict } from '../base-app-domain';
|
|
2
2
|
import { StorageSchema, EntityDict as BaseEntityDict, Context } from '../types';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): import("../types").Checker<ED, keyof ED, Cxt>[];
|
package/lib/checkers/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createDynamicCheckers = void 0;
|
|
4
4
|
var modi_1 = require("../store/modi");
|
|
5
|
-
function
|
|
5
|
+
function createDynamicCheckers(schema) {
|
|
6
6
|
return (0, modi_1.createModiRelatedCheckers)(schema);
|
|
7
7
|
}
|
|
8
|
-
exports.
|
|
8
|
+
exports.createDynamicCheckers = createDynamicCheckers;
|
|
@@ -1027,9 +1027,12 @@ function constructFilter(statements, entity) {
|
|
|
1027
1027
|
break;
|
|
1028
1028
|
}
|
|
1029
1029
|
case 'SingleGeo':
|
|
1030
|
-
case 'Geo':
|
|
1030
|
+
case 'Geo': {
|
|
1031
|
+
// geo类型暂时只支持通过expr查询
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1031
1034
|
case 'Object': {
|
|
1032
|
-
|
|
1035
|
+
type2 = factory.createTypeReferenceNode(factory.createIdentifier('Object'));
|
|
1033
1036
|
break;
|
|
1034
1037
|
}
|
|
1035
1038
|
default: {
|
|
@@ -1672,7 +1675,7 @@ function constructActions(statements, entity) {
|
|
|
1672
1675
|
var e_9, _a, e_10, _b, e_11, _c, e_12, _d, e_13, _e, e_14, _f, e_15, _g, e_16, _h, e_17, _j;
|
|
1673
1676
|
// Selection
|
|
1674
1677
|
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("SelectOperation"), [
|
|
1675
|
-
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
1678
|
+
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
1676
1679
|
], factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
1677
1680
|
factory.createTypeReferenceNode(factory.createIdentifier("OakOperation"), [
|
|
1678
1681
|
factory.createLiteralTypeNode(factory.createStringLiteral("select")),
|
|
@@ -1682,7 +1685,7 @@ function constructActions(statements, entity) {
|
|
|
1682
1685
|
]),
|
|
1683
1686
|
factory.createLiteralTypeNode(factory.createStringLiteral("id"))
|
|
1684
1687
|
])), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Selection"), [
|
|
1685
|
-
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), undefined, factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
1688
|
+
factory.createTypeParameterDeclaration(undefined, factory.createIdentifier("P"), factory.createTypeReferenceNode(factory.createIdentifier("Object"), undefined), factory.createTypeReferenceNode(factory.createIdentifier("Projection"), undefined))
|
|
1686
1689
|
], factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [
|
|
1687
1690
|
factory.createTypeReferenceNode(factory.createIdentifier("SelectOperation"), [
|
|
1688
1691
|
factory.createTypeReferenceNode(factory.createIdentifier("P"), undefined)
|
|
@@ -3027,6 +3030,7 @@ function analyzeInModi() {
|
|
|
3027
3030
|
if (schema.toModi || schema.inModi || schema.actionType === 'readOnly' || schema.static) {
|
|
3028
3031
|
return;
|
|
3029
3032
|
}
|
|
3033
|
+
console.log('setInModi', entity);
|
|
3030
3034
|
schema.inModi = true;
|
|
3031
3035
|
var related = getRelateEntities(entity);
|
|
3032
3036
|
related.forEach(function (ele) { return setInModi(ele); });
|
|
@@ -667,16 +667,22 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
667
667
|
opData = {};
|
|
668
668
|
if (modiAttr && action !== 'remove') {
|
|
669
669
|
// create/update具有modi对象的对象,对其子对象的update行为全部是create modi对象(缓存动作)
|
|
670
|
-
// delete
|
|
670
|
+
// delete此对象,所有的modi子对象应该通过触发器作废,这个通过系统的trigger来搞
|
|
671
671
|
(0, assert_1.default)(!option2.modiParentId && !option2.modiParentEntity);
|
|
672
|
-
|
|
672
|
+
if (action === 'create') {
|
|
673
|
+
option2.modiParentId = data.id;
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
(0, assert_1.default)((filter === null || filter === void 0 ? void 0 : filter.id) && typeof filter.id === 'string');
|
|
677
|
+
option2.modiParentId = filter.id;
|
|
678
|
+
}
|
|
673
679
|
option2.modiParentEntity = entity;
|
|
674
680
|
}
|
|
675
681
|
_loop_2 = function (attr) {
|
|
676
682
|
var relation, operationMto, actionMto, dataMto, filterMto, fkId, entity_1, result2, operationMto, actionMto, dataMto, filterMto, _d, _e, fkId, result2, _f, entityOtm_1, foreignKey_2, otmOperations, dealWithOneToMany, otmOperations_1, otmOperations_1_1, oper, e_2_1;
|
|
677
|
-
var _g, _h,
|
|
678
|
-
return tslib_1.__generator(this, function (
|
|
679
|
-
switch (
|
|
683
|
+
var _g, _h, e_2, _j;
|
|
684
|
+
return tslib_1.__generator(this, function (_k) {
|
|
685
|
+
switch (_k.label) {
|
|
680
686
|
case 0:
|
|
681
687
|
relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
|
|
682
688
|
if (!(relation === 1)) return [3 /*break*/, 1];
|
|
@@ -697,35 +703,36 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
697
703
|
else if (action === 'create') {
|
|
698
704
|
fkId = data.entityId, entity_1 = data.entity;
|
|
699
705
|
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr); // A中data的entityId作为B中filter的主键
|
|
700
|
-
|
|
701
|
-
|
|
706
|
+
(0, assert_1.default)(filterMto.id && filterMto.id === fkId);
|
|
707
|
+
/* Object.assign(operationMto, {
|
|
708
|
+
filter: addFilterSegment({
|
|
702
709
|
id: fkId,
|
|
703
|
-
}),
|
|
704
|
-
|
|
705
|
-
});
|
|
710
|
+
}), filterMto,
|
|
711
|
+
}); */
|
|
706
712
|
}
|
|
707
713
|
else {
|
|
708
714
|
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
|
709
|
-
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
|
710
|
-
|
|
711
|
-
|
|
715
|
+
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity')); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
|
716
|
+
(0, assert_1.default)(filterMto.id && typeof filterMto.id === 'string');
|
|
717
|
+
/* Object.assign(operationMto, {
|
|
718
|
+
filter: addFilterSegment({
|
|
712
719
|
id: {
|
|
713
720
|
$in: {
|
|
714
|
-
entity
|
|
721
|
+
entity,
|
|
715
722
|
data: {
|
|
716
723
|
entityId: 1,
|
|
717
724
|
},
|
|
718
|
-
filter:
|
|
725
|
+
filter: addFilterSegment({
|
|
719
726
|
entity: attr,
|
|
720
|
-
}, filter),
|
|
727
|
+
} as any, filter),
|
|
721
728
|
}
|
|
722
729
|
},
|
|
723
730
|
}, filterMto),
|
|
724
|
-
});
|
|
731
|
+
}); */
|
|
725
732
|
}
|
|
726
733
|
return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
|
|
727
734
|
case 2:
|
|
728
|
-
result2 =
|
|
735
|
+
result2 = _k.sent();
|
|
729
736
|
this_2.mergeOperationResult(result, result2);
|
|
730
737
|
return [3 /*break*/, 16];
|
|
731
738
|
case 3:
|
|
@@ -740,31 +747,33 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
740
747
|
else if (action === 'create') {
|
|
741
748
|
_d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
|
|
742
749
|
(0, assert_1.default)(typeof fkId === 'string');
|
|
743
|
-
|
|
744
|
-
|
|
750
|
+
(0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && filterMto.id === fkId); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
|
751
|
+
/* Object.assign(operationMto, {
|
|
752
|
+
filter: addFilterSegment(filterMto || {}, {
|
|
745
753
|
id: fkId,
|
|
746
754
|
}),
|
|
747
|
-
});
|
|
755
|
+
}); */
|
|
748
756
|
}
|
|
749
757
|
else {
|
|
750
758
|
(0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
|
|
751
|
-
|
|
752
|
-
|
|
759
|
+
(0, assert_1.default)((filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) && typeof filterMto.id === 'string'); // 这里不能再addFilterSegment,否则会造成后面判断不出来对应的id是多少。在实际情况中跑到这里应该不可能没有id
|
|
760
|
+
/* Object.assign(operationMto, {
|
|
761
|
+
filter: addFilterSegment(filterMto || {}, {
|
|
753
762
|
id: {
|
|
754
763
|
$in: {
|
|
755
|
-
entity
|
|
756
|
-
data:
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
filter
|
|
764
|
+
entity,
|
|
765
|
+
data: {
|
|
766
|
+
[`${attr}Id`]: 1,
|
|
767
|
+
},
|
|
768
|
+
filter,
|
|
760
769
|
}
|
|
761
770
|
},
|
|
762
771
|
}),
|
|
763
|
-
});
|
|
772
|
+
}); */
|
|
764
773
|
}
|
|
765
774
|
return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
|
|
766
775
|
case 4:
|
|
767
|
-
result2 =
|
|
776
|
+
result2 = _k.sent();
|
|
768
777
|
this_2.mergeOperationResult(result, result2);
|
|
769
778
|
return [3 /*break*/, 16];
|
|
770
779
|
case 5:
|
|
@@ -885,37 +894,37 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
885
894
|
});
|
|
886
895
|
}); };
|
|
887
896
|
if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
|
|
888
|
-
|
|
897
|
+
_k.label = 6;
|
|
889
898
|
case 6:
|
|
890
|
-
|
|
899
|
+
_k.trys.push([6, 11, 12, 13]);
|
|
891
900
|
otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
|
|
892
|
-
|
|
901
|
+
_k.label = 7;
|
|
893
902
|
case 7:
|
|
894
903
|
if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
|
|
895
904
|
oper = otmOperations_1_1.value;
|
|
896
905
|
return [4 /*yield*/, dealWithOneToMany(oper)];
|
|
897
906
|
case 8:
|
|
898
|
-
|
|
899
|
-
|
|
907
|
+
_k.sent();
|
|
908
|
+
_k.label = 9;
|
|
900
909
|
case 9:
|
|
901
910
|
otmOperations_1_1 = otmOperations_1.next();
|
|
902
911
|
return [3 /*break*/, 7];
|
|
903
912
|
case 10: return [3 /*break*/, 13];
|
|
904
913
|
case 11:
|
|
905
|
-
e_2_1 =
|
|
914
|
+
e_2_1 = _k.sent();
|
|
906
915
|
e_2 = { error: e_2_1 };
|
|
907
916
|
return [3 /*break*/, 13];
|
|
908
917
|
case 12:
|
|
909
918
|
try {
|
|
910
|
-
if (otmOperations_1_1 && !otmOperations_1_1.done && (
|
|
919
|
+
if (otmOperations_1_1 && !otmOperations_1_1.done && (_j = otmOperations_1.return)) _j.call(otmOperations_1);
|
|
911
920
|
}
|
|
912
921
|
finally { if (e_2) throw e_2.error; }
|
|
913
922
|
return [7 /*endfinally*/];
|
|
914
923
|
case 13: return [3 /*break*/, 16];
|
|
915
924
|
case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
|
|
916
925
|
case 15:
|
|
917
|
-
|
|
918
|
-
|
|
926
|
+
_k.sent();
|
|
927
|
+
_k.label = 16;
|
|
919
928
|
case 16: return [2 /*return*/];
|
|
920
929
|
}
|
|
921
930
|
});
|
|
@@ -1072,11 +1081,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1072
1081
|
*/
|
|
1073
1082
|
CascadeStore.prototype.doUpdateSingleRow = function (entity, operation, context, option) {
|
|
1074
1083
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1075
|
-
var data, action, operId, filter, now, _a, modiCreate, addTimestamp_1, result_1, e_5, congruentRow_1, rest, result2, row, updateData, result3, _b, _c, updateData, result2, _d, _e, createOper, _f,
|
|
1076
|
-
var
|
|
1084
|
+
var data, action, operId, filter, now, _a, modiCreate, addTimestamp_1, result_1, e_5, congruentRow_1, rest, result2, row, updateData, result3, _b, _c, updateData, result2, _d, _e, createOper, _f, ids_1, selection, rows, modiUpsert, upsertModis, _g, originData, originId, createOper, updateAttrCount, result_2;
|
|
1085
|
+
var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
1077
1086
|
var _this = this;
|
|
1078
|
-
return tslib_1.__generator(this, function (
|
|
1079
|
-
switch (
|
|
1087
|
+
return tslib_1.__generator(this, function (_t) {
|
|
1088
|
+
switch (_t.label) {
|
|
1080
1089
|
case 0:
|
|
1081
1090
|
data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
|
1082
1091
|
now = Date.now();
|
|
@@ -1096,13 +1105,18 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1096
1105
|
action: action,
|
|
1097
1106
|
entity: option.modiParentEntity,
|
|
1098
1107
|
entityId: option.modiParentId,
|
|
1108
|
+
filter: {
|
|
1109
|
+
id: {
|
|
1110
|
+
$in: [data.id], //这里记录这个filter是为了后面update的时候直接在其上面update,参见本函数后半段关于modiUpsert相关的优化
|
|
1111
|
+
},
|
|
1112
|
+
},
|
|
1099
1113
|
data: data,
|
|
1100
1114
|
iState: 'active',
|
|
1101
1115
|
},
|
|
1102
1116
|
};
|
|
1103
1117
|
return [4 /*yield*/, this.cascadeUpdate('modi', modiCreate, context, option)];
|
|
1104
1118
|
case 2:
|
|
1105
|
-
|
|
1119
|
+
_t.sent();
|
|
1106
1120
|
return [2 /*return*/, 1];
|
|
1107
1121
|
case 3:
|
|
1108
1122
|
addTimestamp_1 = function (data2) {
|
|
@@ -1117,15 +1131,15 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1117
1131
|
else {
|
|
1118
1132
|
addTimestamp_1(data);
|
|
1119
1133
|
}
|
|
1120
|
-
|
|
1134
|
+
_t.label = 4;
|
|
1121
1135
|
case 4:
|
|
1122
|
-
|
|
1136
|
+
_t.trys.push([4, 6, , 15]);
|
|
1123
1137
|
return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
|
|
1124
1138
|
case 5:
|
|
1125
|
-
result_1 =
|
|
1139
|
+
result_1 = _t.sent();
|
|
1126
1140
|
return [3 /*break*/, 15];
|
|
1127
1141
|
case 6:
|
|
1128
|
-
e_5 =
|
|
1142
|
+
e_5 = _t.sent();
|
|
1129
1143
|
if (!(e_5 instanceof types_1.OakCongruentRowExists)) return [3 /*break*/, 14];
|
|
1130
1144
|
if (!option.allowExists) return [3 /*break*/, 13];
|
|
1131
1145
|
congruentRow_1 = e_5.getData();
|
|
@@ -1138,23 +1152,23 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1138
1152
|
data: rest,
|
|
1139
1153
|
}), context, option)];
|
|
1140
1154
|
case 7:
|
|
1141
|
-
result2 =
|
|
1155
|
+
result2 = _t.sent();
|
|
1142
1156
|
row = data.find(function (ele) { return ele.id === congruentRow_1.id; });
|
|
1143
1157
|
updateData = (0, lodash_1.omit)(row, ['id', '$$createAt$$']);
|
|
1144
1158
|
_b = this.updateAbjointRow;
|
|
1145
1159
|
_c = [entity];
|
|
1146
|
-
|
|
1160
|
+
_h = {};
|
|
1147
1161
|
return [4 /*yield*/, generateNewId()];
|
|
1148
|
-
case 8: return [4 /*yield*/, _b.apply(this, _c.concat([(
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1162
|
+
case 8: return [4 /*yield*/, _b.apply(this, _c.concat([(_h.id = _t.sent(),
|
|
1163
|
+
_h.action = 'update',
|
|
1164
|
+
_h.data = updateData,
|
|
1165
|
+
_h.filter = {
|
|
1152
1166
|
id: congruentRow_1.id,
|
|
1153
1167
|
},
|
|
1154
|
-
|
|
1168
|
+
_h), context,
|
|
1155
1169
|
option]))];
|
|
1156
1170
|
case 9:
|
|
1157
|
-
result3 =
|
|
1171
|
+
result3 = _t.sent();
|
|
1158
1172
|
return [2 /*return*/, result2 + result3];
|
|
1159
1173
|
case 10:
|
|
1160
1174
|
if (data.id !== congruentRow_1.id) {
|
|
@@ -1163,18 +1177,18 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1163
1177
|
updateData = (0, lodash_1.omit)(data, ['id', '$$createAt$$']);
|
|
1164
1178
|
_d = this.updateAbjointRow;
|
|
1165
1179
|
_e = [entity];
|
|
1166
|
-
|
|
1180
|
+
_j = {};
|
|
1167
1181
|
return [4 /*yield*/, generateNewId()];
|
|
1168
|
-
case 11: return [4 /*yield*/, _d.apply(this, _e.concat([(
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1182
|
+
case 11: return [4 /*yield*/, _d.apply(this, _e.concat([(_j.id = _t.sent(),
|
|
1183
|
+
_j.action = 'update',
|
|
1184
|
+
_j.data = updateData,
|
|
1185
|
+
_j.filter = {
|
|
1172
1186
|
id: congruentRow_1.id,
|
|
1173
1187
|
},
|
|
1174
|
-
|
|
1188
|
+
_j), context,
|
|
1175
1189
|
option]))];
|
|
1176
1190
|
case 12:
|
|
1177
|
-
result2 =
|
|
1191
|
+
result2 = _t.sent();
|
|
1178
1192
|
return [2 /*return*/, result2];
|
|
1179
1193
|
case 13: throw e_5;
|
|
1180
1194
|
case 14: return [3 /*break*/, 15];
|
|
@@ -1189,20 +1203,20 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1189
1203
|
if (!(!option.dontCreateOper && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity))) return [3 /*break*/, 22];
|
|
1190
1204
|
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1191
1205
|
(0, assert_1.default)(operId);
|
|
1192
|
-
|
|
1206
|
+
_k = {
|
|
1193
1207
|
id: 'dummy',
|
|
1194
1208
|
action: 'create'
|
|
1195
1209
|
};
|
|
1196
|
-
|
|
1210
|
+
_l = {
|
|
1197
1211
|
id: operId,
|
|
1198
1212
|
action: action,
|
|
1199
1213
|
data: data
|
|
1200
1214
|
};
|
|
1201
1215
|
return [4 /*yield*/, context.getCurrentUserId()];
|
|
1202
1216
|
case 16:
|
|
1203
|
-
|
|
1217
|
+
_l.operatorId = _t.sent();
|
|
1204
1218
|
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
|
1205
|
-
|
|
1219
|
+
_m = {
|
|
1206
1220
|
id: 'dummy',
|
|
1207
1221
|
action: 'create'
|
|
1208
1222
|
};
|
|
@@ -1221,38 +1235,38 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1221
1235
|
});
|
|
1222
1236
|
}); }))];
|
|
1223
1237
|
case 17:
|
|
1224
|
-
_f = (
|
|
1225
|
-
|
|
1238
|
+
_f = (_m.data = _t.sent(),
|
|
1239
|
+
_m);
|
|
1226
1240
|
return [3 /*break*/, 20];
|
|
1227
1241
|
case 18:
|
|
1228
|
-
|
|
1242
|
+
_o = {
|
|
1229
1243
|
id: 'dummy',
|
|
1230
1244
|
action: 'create'
|
|
1231
1245
|
};
|
|
1232
|
-
|
|
1246
|
+
_p = {};
|
|
1233
1247
|
return [4 /*yield*/, generateNewId()];
|
|
1234
1248
|
case 19:
|
|
1235
|
-
_f = [(
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1249
|
+
_f = [(_o.data = (_p.id = _t.sent(),
|
|
1250
|
+
_p.entity = entity,
|
|
1251
|
+
_p.entityId = data.id,
|
|
1252
|
+
_p),
|
|
1253
|
+
_o)];
|
|
1254
|
+
_t.label = 20;
|
|
1241
1255
|
case 20:
|
|
1242
|
-
createOper = (
|
|
1243
|
-
|
|
1244
|
-
|
|
1256
|
+
createOper = (_k.data = (_l.operEntity$oper = _f,
|
|
1257
|
+
_l),
|
|
1258
|
+
_k);
|
|
1245
1259
|
return [4 /*yield*/, this.cascadeUpdate('oper', createOper, context, {
|
|
1246
1260
|
dontCollect: true,
|
|
1247
1261
|
dontCreateOper: true,
|
|
1248
1262
|
})];
|
|
1249
1263
|
case 21:
|
|
1250
|
-
|
|
1251
|
-
|
|
1264
|
+
_t.sent();
|
|
1265
|
+
_t.label = 22;
|
|
1252
1266
|
case 22: return [2 /*return*/, result_1];
|
|
1253
1267
|
case 23:
|
|
1254
|
-
|
|
1255
|
-
if (!(
|
|
1268
|
+
ids_1 = (0, filter_1.getRelevantIds)(filter);
|
|
1269
|
+
if (!(ids_1.length === 0)) return [3 /*break*/, 25];
|
|
1256
1270
|
selection = {
|
|
1257
1271
|
data: {
|
|
1258
1272
|
id: 1,
|
|
@@ -1265,16 +1279,64 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1265
1279
|
dontCollect: true,
|
|
1266
1280
|
})];
|
|
1267
1281
|
case 24:
|
|
1268
|
-
rows =
|
|
1269
|
-
|
|
1270
|
-
|
|
1282
|
+
rows = _t.sent();
|
|
1283
|
+
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
|
1284
|
+
_t.label = 25;
|
|
1271
1285
|
case 25:
|
|
1272
|
-
if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/,
|
|
1273
|
-
|
|
1286
|
+
if (!(option.modiParentEntity && !['modi', 'modiEntity'].includes(entity))) return [3 /*break*/, 31];
|
|
1287
|
+
modiUpsert = void 0;
|
|
1288
|
+
if (!(action !== 'remove')) return [3 /*break*/, 27];
|
|
1289
|
+
return [4 /*yield*/, this.selectAbjointRow('modi', {
|
|
1290
|
+
data: {
|
|
1291
|
+
id: 1,
|
|
1292
|
+
data: 1,
|
|
1293
|
+
},
|
|
1294
|
+
filter: {
|
|
1295
|
+
targetEntity: entity,
|
|
1296
|
+
action: {
|
|
1297
|
+
$in: ['create', 'update'],
|
|
1298
|
+
},
|
|
1299
|
+
iState: 'active',
|
|
1300
|
+
filter: {
|
|
1301
|
+
id: {
|
|
1302
|
+
$in: ids_1,
|
|
1303
|
+
},
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
sorter: [
|
|
1307
|
+
{
|
|
1308
|
+
$attr: {
|
|
1309
|
+
$$createAt$$: 1,
|
|
1310
|
+
},
|
|
1311
|
+
$direction: 'desc',
|
|
1312
|
+
}
|
|
1313
|
+
],
|
|
1314
|
+
indexFrom: 0,
|
|
1315
|
+
count: 1,
|
|
1316
|
+
}, context, option)];
|
|
1317
|
+
case 26:
|
|
1318
|
+
upsertModis = _t.sent();
|
|
1319
|
+
if (upsertModis.length > 0) {
|
|
1320
|
+
_g = upsertModis[0], originData = _g.data, originId = _g.id;
|
|
1321
|
+
modiUpsert = {
|
|
1322
|
+
id: 'dummy',
|
|
1323
|
+
action: 'update',
|
|
1324
|
+
data: {
|
|
1325
|
+
data: Object.assign({}, originData, data),
|
|
1326
|
+
},
|
|
1327
|
+
filter: {
|
|
1328
|
+
id: originId,
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
_t.label = 27;
|
|
1333
|
+
case 27:
|
|
1334
|
+
if (!!modiUpsert) return [3 /*break*/, 29];
|
|
1335
|
+
_q = {
|
|
1274
1336
|
id: 'dummy',
|
|
1275
1337
|
action: 'create'
|
|
1276
1338
|
};
|
|
1277
|
-
|
|
1339
|
+
_r = {
|
|
1278
1340
|
id: operId,
|
|
1279
1341
|
targetEntity: entity,
|
|
1280
1342
|
entity: option.modiParentEntity,
|
|
@@ -1284,15 +1346,15 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1284
1346
|
iState: 'active',
|
|
1285
1347
|
filter: {
|
|
1286
1348
|
id: {
|
|
1287
|
-
$in:
|
|
1349
|
+
$in: ids_1,
|
|
1288
1350
|
},
|
|
1289
1351
|
}
|
|
1290
1352
|
};
|
|
1291
|
-
|
|
1353
|
+
_s = {
|
|
1292
1354
|
id: 'dummy',
|
|
1293
1355
|
action: 'create'
|
|
1294
1356
|
};
|
|
1295
|
-
return [4 /*yield*/, Promise.all(
|
|
1357
|
+
return [4 /*yield*/, Promise.all(ids_1.map(function (id) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1296
1358
|
var _a;
|
|
1297
1359
|
return tslib_1.__generator(this, function (_b) {
|
|
1298
1360
|
switch (_b.label) {
|
|
@@ -1306,96 +1368,119 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1306
1368
|
}
|
|
1307
1369
|
});
|
|
1308
1370
|
}); }))];
|
|
1309
|
-
case
|
|
1310
|
-
|
|
1371
|
+
case 28:
|
|
1372
|
+
modiUpsert = (_q.data = (_r.modiEntity$modi = (_s.data = _t.sent(),
|
|
1373
|
+
_s),
|
|
1311
1374
|
_r),
|
|
1312
|
-
_q)
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
case
|
|
1316
|
-
|
|
1375
|
+
_q);
|
|
1376
|
+
_t.label = 29;
|
|
1377
|
+
case 29: return [4 /*yield*/, this.cascadeUpdate('modi', modiUpsert, context, option)];
|
|
1378
|
+
case 30:
|
|
1379
|
+
_t.sent();
|
|
1317
1380
|
return [2 /*return*/, 1];
|
|
1318
|
-
case
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1381
|
+
case 31:
|
|
1382
|
+
createOper = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1383
|
+
var createOper_1;
|
|
1384
|
+
var _a, _b, _c;
|
|
1385
|
+
var _this = this;
|
|
1386
|
+
return tslib_1.__generator(this, function (_d) {
|
|
1387
|
+
switch (_d.label) {
|
|
1388
|
+
case 0:
|
|
1389
|
+
if (!(!(option === null || option === void 0 ? void 0 : option.dontCreateOper) && !['oper', 'operEntity', 'modiEntity', 'modi'].includes(entity) && ids_1.length > 0)) return [3 /*break*/, 3];
|
|
1390
|
+
// 按照框架要求生成Oper和OperEntity这两个内置的对象
|
|
1391
|
+
(0, assert_1.default)(operId);
|
|
1392
|
+
_a = {
|
|
1393
|
+
id: 'dummy',
|
|
1394
|
+
action: 'create'
|
|
1395
|
+
};
|
|
1396
|
+
_b = {
|
|
1397
|
+
id: operId,
|
|
1398
|
+
action: action,
|
|
1399
|
+
data: data
|
|
1400
|
+
};
|
|
1401
|
+
_c = {
|
|
1402
|
+
id: 'dummy',
|
|
1403
|
+
action: 'create'
|
|
1404
|
+
};
|
|
1405
|
+
return [4 /*yield*/, Promise.all(ids_1.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1406
|
+
var _a;
|
|
1407
|
+
return tslib_1.__generator(this, function (_b) {
|
|
1408
|
+
switch (_b.label) {
|
|
1409
|
+
case 0:
|
|
1410
|
+
_a = {};
|
|
1411
|
+
return [4 /*yield*/, generateNewId()];
|
|
1412
|
+
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1413
|
+
_a.entity = entity,
|
|
1414
|
+
_a.entityId = ele,
|
|
1415
|
+
_a)];
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
}); }))];
|
|
1419
|
+
case 1:
|
|
1420
|
+
createOper_1 = (_a.data = (_b.operEntity$oper = (_c.data = _d.sent(),
|
|
1421
|
+
_c),
|
|
1422
|
+
_b),
|
|
1423
|
+
_a);
|
|
1424
|
+
return [4 /*yield*/, this.cascadeUpdate('oper', createOper_1, context, {
|
|
1425
|
+
dontCollect: true,
|
|
1426
|
+
dontCreateOper: true,
|
|
1427
|
+
})];
|
|
1428
|
+
case 2:
|
|
1429
|
+
_d.sent();
|
|
1430
|
+
_d.label = 3;
|
|
1431
|
+
case 3: return [2 /*return*/];
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
}); };
|
|
1435
|
+
if (!(action === 'remove')) return [3 /*break*/, 32];
|
|
1436
|
+
if (!option.dontCollect) {
|
|
1437
|
+
context.opRecords.push({
|
|
1438
|
+
a: 'r',
|
|
1439
|
+
e: entity,
|
|
1440
|
+
f: {
|
|
1441
|
+
id: {
|
|
1442
|
+
$in: ids_1,
|
|
1443
|
+
}
|
|
1444
|
+
},
|
|
1339
1445
|
});
|
|
1340
|
-
if (!option.dontCollect) {
|
|
1341
|
-
context.opRecords.push({
|
|
1342
|
-
a: 'u',
|
|
1343
|
-
e: entity,
|
|
1344
|
-
d: data,
|
|
1345
|
-
f: {
|
|
1346
|
-
id: {
|
|
1347
|
-
$in: ids,
|
|
1348
|
-
}
|
|
1349
|
-
},
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
1446
|
}
|
|
1353
|
-
return [
|
|
1354
|
-
case
|
|
1355
|
-
|
|
1356
|
-
if (!(
|
|
1357
|
-
//
|
|
1358
|
-
(
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
id: 'dummy',
|
|
1370
|
-
action: 'create'
|
|
1371
|
-
};
|
|
1372
|
-
return [4 /*yield*/, Promise.all(ids.map(function (ele) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1373
|
-
var _a;
|
|
1374
|
-
return tslib_1.__generator(this, function (_b) {
|
|
1375
|
-
switch (_b.label) {
|
|
1376
|
-
case 0:
|
|
1377
|
-
_a = {};
|
|
1378
|
-
return [4 /*yield*/, generateNewId()];
|
|
1379
|
-
case 1: return [2 /*return*/, (_a.id = _b.sent(),
|
|
1380
|
-
_a.entity = entity,
|
|
1381
|
-
_a.entityId = ele,
|
|
1382
|
-
_a)];
|
|
1447
|
+
return [3 /*break*/, 36];
|
|
1448
|
+
case 32:
|
|
1449
|
+
updateAttrCount = Object.keys(data).length;
|
|
1450
|
+
if (!(updateAttrCount > 0)) return [3 /*break*/, 33];
|
|
1451
|
+
// 优化一下,如果不更新任何属性,则不实际执行
|
|
1452
|
+
Object.assign(data, {
|
|
1453
|
+
$$updateAt$$: now,
|
|
1454
|
+
});
|
|
1455
|
+
if (!option.dontCollect) {
|
|
1456
|
+
context.opRecords.push({
|
|
1457
|
+
a: 'u',
|
|
1458
|
+
e: entity,
|
|
1459
|
+
d: data,
|
|
1460
|
+
f: {
|
|
1461
|
+
id: {
|
|
1462
|
+
$in: ids_1,
|
|
1383
1463
|
}
|
|
1384
|
-
}
|
|
1385
|
-
});
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return [4 /*yield*/,
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
case
|
|
1464
|
+
},
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
return [3 /*break*/, 36];
|
|
1468
|
+
case 33:
|
|
1469
|
+
if (!(action !== 'update')) return [3 /*break*/, 35];
|
|
1470
|
+
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
|
1471
|
+
return [4 /*yield*/, createOper()];
|
|
1472
|
+
case 34:
|
|
1473
|
+
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
|
1474
|
+
_t.sent();
|
|
1475
|
+
return [2 /*return*/, 0];
|
|
1476
|
+
case 35: return [2 /*return*/, 0];
|
|
1477
|
+
case 36: return [4 /*yield*/, this.updateAbjointRow(entity, operation, context, option)];
|
|
1478
|
+
case 37:
|
|
1479
|
+
result_2 = _t.sent();
|
|
1480
|
+
return [4 /*yield*/, createOper()];
|
|
1481
|
+
case 38:
|
|
1482
|
+
_t.sent();
|
|
1483
|
+
return [2 /*return*/, result_2];
|
|
1399
1484
|
}
|
|
1400
1485
|
});
|
|
1401
1486
|
});
|
package/lib/store/actionDef.js
CHANGED
|
@@ -182,10 +182,26 @@ function analyzeActionDefDict(schema, actionDefDict) {
|
|
|
182
182
|
var _b;
|
|
183
183
|
return tslib_1.__generator(this, function (_c) {
|
|
184
184
|
data = operation.data;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
if (data instanceof Array) {
|
|
186
|
+
data.forEach(function (ele) {
|
|
187
|
+
var _a;
|
|
188
|
+
if (!ele[attr]) {
|
|
189
|
+
Object.assign(ele, (_a = {},
|
|
190
|
+
_a[attr] = is,
|
|
191
|
+
_a));
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return [2 /*return*/, data.length];
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (!data[attr]) {
|
|
198
|
+
Object.assign(data, (_b = {},
|
|
199
|
+
_b[attr] = is,
|
|
200
|
+
_b));
|
|
201
|
+
}
|
|
202
|
+
return [2 /*return*/, 1];
|
|
203
|
+
}
|
|
204
|
+
return [2 /*return*/];
|
|
189
205
|
});
|
|
190
206
|
});
|
|
191
207
|
}
|
package/lib/store/modi.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
2
2
|
import { UniversalContext } from '../store/UniversalContext';
|
|
3
3
|
import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
|
|
4
|
-
import { Checker, Operation, StorageSchema, EntityDict, Context } from '../types';
|
|
4
|
+
import { Checker, Operation, StorageSchema, EntityDict, Context, OperateOption } from '../types';
|
|
5
5
|
export declare function createOperationsFromModies(modies: Modi[]): Array<{
|
|
6
6
|
operation: Operation<string, Object, Object>;
|
|
7
7
|
entity: string;
|
|
8
8
|
}>;
|
|
9
|
-
export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED
|
|
10
|
-
export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED
|
|
9
|
+
export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
|
|
10
|
+
export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends UniversalContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
|
|
11
11
|
export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
|
|
12
|
+
export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): void;
|
package/lib/store/modi.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
|
|
3
|
+
exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var types_1 = require("../types");
|
|
6
6
|
var action_1 = require("../actions/action");
|
|
@@ -19,7 +19,7 @@ function createOperationsFromModies(modies) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
exports.createOperationsFromModies = createOperationsFromModies;
|
|
22
|
-
function applyModis(filter, context) {
|
|
22
|
+
function applyModis(filter, context, option) {
|
|
23
23
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
24
24
|
var _a, _b, _c;
|
|
25
25
|
var _d;
|
|
@@ -42,16 +42,15 @@ function applyModis(filter, context) {
|
|
|
42
42
|
$direction: 'asc',
|
|
43
43
|
}
|
|
44
44
|
],
|
|
45
|
-
_d), context, {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}]))];
|
|
45
|
+
_d), context, Object.assign({}, option, {
|
|
46
|
+
blockTrigger: false,
|
|
47
|
+
})]))];
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
exports.applyModis = applyModis;
|
|
54
|
-
function abandonModis(filter, context) {
|
|
53
|
+
function abandonModis(filter, context, option) {
|
|
55
54
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
56
55
|
var _a, _b, _c;
|
|
57
56
|
var _d;
|
|
@@ -74,10 +73,9 @@ function abandonModis(filter, context) {
|
|
|
74
73
|
$direction: 'asc',
|
|
75
74
|
}
|
|
76
75
|
],
|
|
77
|
-
_d), context, {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}]))];
|
|
76
|
+
_d), context, Object.assign({}, option, {
|
|
77
|
+
blockTrigger: false,
|
|
78
|
+
})]))];
|
|
81
79
|
}
|
|
82
80
|
});
|
|
83
81
|
});
|
|
@@ -141,3 +139,52 @@ function createModiRelatedCheckers(schema) {
|
|
|
141
139
|
return checkers;
|
|
142
140
|
}
|
|
143
141
|
exports.createModiRelatedCheckers = createModiRelatedCheckers;
|
|
142
|
+
function createModiRelatedTriggers(schema) {
|
|
143
|
+
var _this = this;
|
|
144
|
+
var triggers = [];
|
|
145
|
+
var _loop_2 = function (entity) {
|
|
146
|
+
var inModi = schema[entity].inModi;
|
|
147
|
+
if (inModi) {
|
|
148
|
+
// 当关联modi的对象被删除时,对应的modi也删除
|
|
149
|
+
triggers.push({
|
|
150
|
+
name: "\u5F53\u5220\u9664".concat(entity, "\u5BF9\u8C61\u65F6\uFF0C\u5220\u9664\u76F8\u5173\u8054\u8FD8\u6D3B\u8DC3\u7684modi"),
|
|
151
|
+
action: 'remove',
|
|
152
|
+
entity: entity,
|
|
153
|
+
when: 'after',
|
|
154
|
+
fn: function (_a, context, option) {
|
|
155
|
+
var operation = _a.operation;
|
|
156
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
157
|
+
var data, id, _b, _c, _d;
|
|
158
|
+
var _e;
|
|
159
|
+
return tslib_1.__generator(this, function (_f) {
|
|
160
|
+
switch (_f.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
data = operation.data;
|
|
163
|
+
id = data.id;
|
|
164
|
+
_c = (_b = context.rowStore).operate;
|
|
165
|
+
_d = ['modi'];
|
|
166
|
+
_e = {};
|
|
167
|
+
return [4 /*yield*/, generateNewId()];
|
|
168
|
+
case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_e.id = _f.sent(),
|
|
169
|
+
_e.action = 'remove',
|
|
170
|
+
_e.data = {},
|
|
171
|
+
_e.filter = {
|
|
172
|
+
entity: entity,
|
|
173
|
+
entityId: id,
|
|
174
|
+
},
|
|
175
|
+
_e), context, option]))];
|
|
176
|
+
case 2:
|
|
177
|
+
_f.sent();
|
|
178
|
+
return [2 /*return*/, 1];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
for (var entity in schema) {
|
|
187
|
+
_loop_2(entity);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.createModiRelatedTriggers = createModiRelatedTriggers;
|
package/lib/triggers/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
2
|
+
import { StorageSchema, EntityDict, Context } from '../types';
|
|
3
|
+
declare const _default: import("../types").Trigger<BaseEntityDict, "modi", import("../store/UniversalContext").UniversalContext<BaseEntityDict>>[];
|
|
2
4
|
export default _default;
|
|
5
|
+
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): void;
|
package/lib/triggers/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDynamicTriggers = void 0;
|
|
3
4
|
var tslib_1 = require("tslib");
|
|
4
5
|
var modi_1 = tslib_1.__importDefault(require("./modi"));
|
|
6
|
+
var modi_2 = require("../store/modi");
|
|
5
7
|
exports.default = tslib_1.__spreadArray([], tslib_1.__read(modi_1.default), false);
|
|
8
|
+
function createDynamicTriggers(schema) {
|
|
9
|
+
return (0, modi_2.createModiRelatedTriggers)(schema);
|
|
10
|
+
}
|
|
11
|
+
exports.createDynamicTriggers = createDynamicTriggers;
|