oak-domain 1.1.3 → 1.1.6
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/store/CascadeStore.js +83 -58
- package/lib/store/modi.d.ts +2 -2
- package/lib/store/modi.js +1 -0
- package/lib/triggers/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -680,9 +680,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
680
680
|
}
|
|
681
681
|
_loop_2 = function (attr) {
|
|
682
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;
|
|
683
|
-
var _g, _h, e_2,
|
|
684
|
-
return tslib_1.__generator(this, function (
|
|
685
|
-
switch (
|
|
683
|
+
var _g, _h, _j, e_2, _k;
|
|
684
|
+
return tslib_1.__generator(this, function (_l) {
|
|
685
|
+
switch (_l.label) {
|
|
686
686
|
case 0:
|
|
687
687
|
relation = (0, relation_1.judgeRelation)(this_2.storageSchema, entity, attr);
|
|
688
688
|
if (!(relation === 1)) return [3 /*break*/, 1];
|
|
@@ -702,37 +702,50 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
702
702
|
}
|
|
703
703
|
else if (action === 'create') {
|
|
704
704
|
fkId = data.entityId, entity_1 = data.entity;
|
|
705
|
-
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
705
|
+
(0, assert_1.default)(typeof fkId === 'string' || entity_1 === attr);
|
|
706
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
707
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
708
|
+
(0, assert_1.default)(filterMto.id === fkId);
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
// A中data的entityId作为B中filter的主键
|
|
712
|
+
Object.assign(operationMto, {
|
|
713
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
714
|
+
id: fkId,
|
|
715
|
+
}),
|
|
716
|
+
filterMto: filterMto,
|
|
717
|
+
});
|
|
718
|
+
}
|
|
712
719
|
}
|
|
713
720
|
else {
|
|
714
721
|
// 剩下三种情况都是B中的filter的id来自A中row的entityId
|
|
715
|
-
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
entity:
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
722
|
+
(0, assert_1.default)(!data.hasOwnProperty('entityId') && !data.hasOwnProperty('entity'));
|
|
723
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
724
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
725
|
+
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
// A中data的entityId作为B中filter的主键
|
|
729
|
+
Object.assign(operationMto, {
|
|
730
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
731
|
+
id: {
|
|
732
|
+
$in: {
|
|
733
|
+
entity: entity,
|
|
734
|
+
data: {
|
|
735
|
+
entityId: 1,
|
|
736
|
+
},
|
|
737
|
+
filter: (0, filter_1.addFilterSegment)({
|
|
738
|
+
entity: attr,
|
|
739
|
+
}, filter),
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
}, filterMto),
|
|
743
|
+
});
|
|
744
|
+
}
|
|
732
745
|
}
|
|
733
746
|
return [4 /*yield*/, this_2.cascadeUpdate(attr, operationMto, context, option2)];
|
|
734
747
|
case 2:
|
|
735
|
-
result2 =
|
|
748
|
+
result2 = _l.sent();
|
|
736
749
|
this_2.mergeOperationResult(result, result2);
|
|
737
750
|
return [3 /*break*/, 16];
|
|
738
751
|
case 3:
|
|
@@ -747,33 +760,45 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
747
760
|
else if (action === 'create') {
|
|
748
761
|
_d = data, _e = "".concat(attr, "Id"), fkId = _d[_e];
|
|
749
762
|
(0, assert_1.default)(typeof fkId === 'string');
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
763
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
764
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
765
|
+
(0, assert_1.default)(filterMto.id === fkId);
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
// A中data的entityId作为B中filter的主键
|
|
769
|
+
Object.assign(operationMto, {
|
|
770
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
771
|
+
id: fkId,
|
|
772
|
+
}),
|
|
773
|
+
});
|
|
774
|
+
}
|
|
756
775
|
}
|
|
757
776
|
else {
|
|
758
777
|
(0, assert_1.default)(!data.hasOwnProperty("".concat(attr, "Id")));
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
778
|
+
if (filterMto === null || filterMto === void 0 ? void 0 : filterMto.id) {
|
|
779
|
+
// 若已有id则不用处理,否则会干扰modi的后续判断(会根据filter来判断对象id,如果判断不出来去查实际的对象,但实际的对象其实还未创建好)
|
|
780
|
+
(0, assert_1.default)(typeof filterMto.id === 'string');
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
// A中data的entityId作为B中filter的主键
|
|
784
|
+
Object.assign(operationMto, {
|
|
785
|
+
filter: (0, filter_1.addFilterSegment)(filterMto || {}, {
|
|
786
|
+
id: {
|
|
787
|
+
$in: {
|
|
788
|
+
entity: entity,
|
|
789
|
+
data: (_j = {},
|
|
790
|
+
_j["".concat(attr, "Id")] = 1,
|
|
791
|
+
_j),
|
|
792
|
+
filter: filter,
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
}),
|
|
796
|
+
});
|
|
797
|
+
}
|
|
773
798
|
}
|
|
774
799
|
return [4 /*yield*/, this_2.cascadeUpdate(relation, operationMto, context, option2)];
|
|
775
800
|
case 4:
|
|
776
|
-
result2 =
|
|
801
|
+
result2 = _l.sent();
|
|
777
802
|
this_2.mergeOperationResult(result, result2);
|
|
778
803
|
return [3 /*break*/, 16];
|
|
779
804
|
case 5:
|
|
@@ -894,37 +919,37 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
894
919
|
});
|
|
895
920
|
}); };
|
|
896
921
|
if (!(otmOperations instanceof Array)) return [3 /*break*/, 14];
|
|
897
|
-
|
|
922
|
+
_l.label = 6;
|
|
898
923
|
case 6:
|
|
899
|
-
|
|
924
|
+
_l.trys.push([6, 11, 12, 13]);
|
|
900
925
|
otmOperations_1 = (e_2 = void 0, tslib_1.__values(otmOperations)), otmOperations_1_1 = otmOperations_1.next();
|
|
901
|
-
|
|
926
|
+
_l.label = 7;
|
|
902
927
|
case 7:
|
|
903
928
|
if (!!otmOperations_1_1.done) return [3 /*break*/, 10];
|
|
904
929
|
oper = otmOperations_1_1.value;
|
|
905
930
|
return [4 /*yield*/, dealWithOneToMany(oper)];
|
|
906
931
|
case 8:
|
|
907
|
-
|
|
908
|
-
|
|
932
|
+
_l.sent();
|
|
933
|
+
_l.label = 9;
|
|
909
934
|
case 9:
|
|
910
935
|
otmOperations_1_1 = otmOperations_1.next();
|
|
911
936
|
return [3 /*break*/, 7];
|
|
912
937
|
case 10: return [3 /*break*/, 13];
|
|
913
938
|
case 11:
|
|
914
|
-
e_2_1 =
|
|
939
|
+
e_2_1 = _l.sent();
|
|
915
940
|
e_2 = { error: e_2_1 };
|
|
916
941
|
return [3 /*break*/, 13];
|
|
917
942
|
case 12:
|
|
918
943
|
try {
|
|
919
|
-
if (otmOperations_1_1 && !otmOperations_1_1.done && (
|
|
944
|
+
if (otmOperations_1_1 && !otmOperations_1_1.done && (_k = otmOperations_1.return)) _k.call(otmOperations_1);
|
|
920
945
|
}
|
|
921
946
|
finally { if (e_2) throw e_2.error; }
|
|
922
947
|
return [7 /*endfinally*/];
|
|
923
948
|
case 13: return [3 /*break*/, 16];
|
|
924
949
|
case 14: return [4 /*yield*/, dealWithOneToMany(otmOperations)];
|
|
925
950
|
case 15:
|
|
926
|
-
|
|
927
|
-
|
|
951
|
+
_l.sent();
|
|
952
|
+
_l.label = 16;
|
|
928
953
|
case 16: return [2 /*return*/];
|
|
929
954
|
}
|
|
930
955
|
});
|
package/lib/store/modi.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, OperateOption } from '../types';
|
|
4
|
+
import { Checker, Operation, StorageSchema, EntityDict, Context, OperateOption, Trigger } from '../types';
|
|
5
5
|
export declare function createOperationsFromModies(modies: Modi[]): Array<{
|
|
6
6
|
operation: Operation<string, Object, Object>;
|
|
7
7
|
entity: string;
|
|
@@ -9,4 +9,4 @@ export declare function createOperationsFromModies(modies: Modi[]): Array<{
|
|
|
9
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
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>):
|
|
12
|
+
export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];
|
package/lib/store/modi.js
CHANGED
package/lib/triggers/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
|
2
2
|
import { StorageSchema, EntityDict, Context } from '../types';
|
|
3
3
|
declare const _default: import("../types").Trigger<BaseEntityDict, "modi", import("../store/UniversalContext").UniversalContext<BaseEntityDict>>[];
|
|
4
4
|
export default _default;
|
|
5
|
-
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>):
|
|
5
|
+
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>): import("../types").Trigger<ED, keyof ED, Cxt>[];
|