oak-domain 2.5.1 → 2.6.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/actions/relation.d.ts +3 -3
- package/lib/actions/relation.js +1 -1
- package/lib/checkers/index.js +1 -1
- package/lib/store/CascadeStore.js +126 -108
- package/lib/store/checker.d.ts +1 -1
- package/lib/store/checker.js +191 -87
- package/lib/store/selection.d.ts +12 -0
- package/lib/store/selection.js +31 -1
- package/lib/types/Action.d.ts +3 -1
- package/lib/types/Auth.d.ts +4 -1
- package/lib/types/Connector.d.ts +1 -1
- package/lib/types/Entity.d.ts +1 -1
- package/lib/types/Exception.d.ts +21 -19
- package/lib/types/Exception.js +65 -21
- package/lib/utils/SimpleConnector.d.ts +2 -2
- package/package.json +1 -1
package/lib/store/checker.js
CHANGED
|
@@ -5,10 +5,12 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var filter_1 = require("../store/filter");
|
|
7
7
|
var Exception_1 = require("../types/Exception");
|
|
8
|
+
var types_1 = require("../types");
|
|
8
9
|
var actionDef_1 = require("./actionDef");
|
|
9
10
|
var string_1 = require("../utils/string");
|
|
10
11
|
var lodash_1 = require("../utils/lodash");
|
|
11
12
|
var relation_1 = require("./relation");
|
|
13
|
+
var uuid_1 = require("../utils/uuid");
|
|
12
14
|
function translateCheckerInAsyncContext(checker) {
|
|
13
15
|
var _this = this;
|
|
14
16
|
var entity = checker.entity, type = checker.type, action = checker.action;
|
|
@@ -42,20 +44,19 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
42
44
|
var fn = (function (_a, context, option) {
|
|
43
45
|
var operation = _a.operation;
|
|
44
46
|
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
45
|
-
var operationFilter, action, filter2, _b, entity2, selection2, rows2,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
switch (_e.label) {
|
|
47
|
+
var operationFilter, action, filter2, _b, entity2, selection2, rows2, e, rows2, e;
|
|
48
|
+
return tslib_1.__generator(this, function (_c) {
|
|
49
|
+
switch (_c.label) {
|
|
49
50
|
case 0:
|
|
50
51
|
operationFilter = operation.filter, action = operation.action;
|
|
51
52
|
if (!(typeof filter_2 === 'function')) return [3 /*break*/, 2];
|
|
52
53
|
return [4 /*yield*/, filter_2(operation, context, option)];
|
|
53
54
|
case 1:
|
|
54
|
-
_b =
|
|
55
|
+
_b = _c.sent();
|
|
55
56
|
return [3 /*break*/, 3];
|
|
56
57
|
case 2:
|
|
57
58
|
_b = filter_2;
|
|
58
|
-
|
|
59
|
+
_c.label = 3;
|
|
59
60
|
case 3:
|
|
60
61
|
filter2 = _b;
|
|
61
62
|
if (!['select', 'count', 'stat'].includes(action)) return [3 /*break*/, 4];
|
|
@@ -63,7 +64,7 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
63
64
|
return [2 /*return*/, 0];
|
|
64
65
|
case 4: return [4 /*yield*/, (0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter || {}, true)];
|
|
65
66
|
case 5:
|
|
66
|
-
if (
|
|
67
|
+
if (_c.sent()) {
|
|
67
68
|
return [2 /*return*/, 0];
|
|
68
69
|
}
|
|
69
70
|
if (!inconsistentRows_1) return [3 /*break*/, 7];
|
|
@@ -73,20 +74,10 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
73
74
|
blockTrigger: true,
|
|
74
75
|
})];
|
|
75
76
|
case 6:
|
|
76
|
-
rows2 =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return Object.assign(data_1, (_a = {},
|
|
81
|
-
_a[ele.id] = ele,
|
|
82
|
-
_a));
|
|
83
|
-
});
|
|
84
|
-
throw new Exception_1.OakRowInconsistencyException({
|
|
85
|
-
a: 's',
|
|
86
|
-
d: (_c = {},
|
|
87
|
-
_c[entity2] = data_1,
|
|
88
|
-
_c)
|
|
89
|
-
}, errMsg_1);
|
|
77
|
+
rows2 = _c.sent();
|
|
78
|
+
e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
|
|
79
|
+
e.addData(entity2, rows2);
|
|
80
|
+
throw e;
|
|
90
81
|
case 7: return [4 /*yield*/, context.select(entity, {
|
|
91
82
|
data: (0, actionDef_1.getFullProjection)(entity, context.getSchema()),
|
|
92
83
|
filter: Object.assign({}, operationFilter, {
|
|
@@ -97,20 +88,10 @@ function translateCheckerInAsyncContext(checker) {
|
|
|
97
88
|
blockTrigger: true,
|
|
98
89
|
})];
|
|
99
90
|
case 8:
|
|
100
|
-
rows2 =
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return Object.assign(data_2, (_a = {},
|
|
105
|
-
_a[ele.id] = ele,
|
|
106
|
-
_a));
|
|
107
|
-
});
|
|
108
|
-
throw new Exception_1.OakRowInconsistencyException({
|
|
109
|
-
a: 's',
|
|
110
|
-
d: (_d = {},
|
|
111
|
-
_d[entity] = data_2,
|
|
112
|
-
_d)
|
|
113
|
-
}, errMsg_1);
|
|
91
|
+
rows2 = _c.sent();
|
|
92
|
+
e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_1);
|
|
93
|
+
e.addData(entity, rows2);
|
|
94
|
+
throw e;
|
|
114
95
|
}
|
|
115
96
|
});
|
|
116
97
|
});
|
|
@@ -226,7 +207,8 @@ function translateCheckerInSyncContext(checker) {
|
|
|
226
207
|
if ((0, filter_1.checkFilterContains)(entity, context, filter2, operationFilter, true)) {
|
|
227
208
|
return;
|
|
228
209
|
}
|
|
229
|
-
|
|
210
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, errMsg_3);
|
|
211
|
+
throw e;
|
|
230
212
|
}
|
|
231
213
|
};
|
|
232
214
|
return {
|
|
@@ -406,12 +388,12 @@ function createAuthCheckers(schema, authDict) {
|
|
|
406
388
|
var _b = authDict[entity], relationAuth = _b.relationAuth, actionAuth = _b.actionAuth;
|
|
407
389
|
if (relationAuth) {
|
|
408
390
|
var raFilterMakerDict_1 = {};
|
|
391
|
+
var userEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
409
392
|
for (var r in relationAuth) {
|
|
410
393
|
Object.assign(raFilterMakerDict_1, (_a = {},
|
|
411
394
|
_a[r] = translateActionAuthFilterMaker(schema, relationAuth[r], entity),
|
|
412
395
|
_a));
|
|
413
396
|
}
|
|
414
|
-
var userEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
415
397
|
var entityIdAttr_1 = "".concat(entity, "Id");
|
|
416
398
|
checkers.push({
|
|
417
399
|
entity: userEntityName_1,
|
|
@@ -508,7 +490,7 @@ exports.createAuthCheckers = createAuthCheckers;
|
|
|
508
490
|
* @returns
|
|
509
491
|
* 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
|
|
510
492
|
*/
|
|
511
|
-
function createRemoveCheckers(schema) {
|
|
493
|
+
function createRemoveCheckers(schema, authDict) {
|
|
512
494
|
var e_1, _a;
|
|
513
495
|
var checkers = [];
|
|
514
496
|
// 先建立所有的一对多的关系
|
|
@@ -575,9 +557,9 @@ function createRemoveCheckers(schema) {
|
|
|
575
557
|
var e_3, _a, e_4, _b;
|
|
576
558
|
var promises = [];
|
|
577
559
|
if (OneToManyMatrix[entity]) {
|
|
578
|
-
var
|
|
579
|
-
var _g, _h
|
|
580
|
-
var
|
|
560
|
+
var _loop_5 = function (otm) {
|
|
561
|
+
var _g, _h;
|
|
562
|
+
var _j = tslib_1.__read(otm, 2), e = _j[0], attr = _j[1];
|
|
581
563
|
var proj = (_g = {
|
|
582
564
|
id: 1
|
|
583
565
|
},
|
|
@@ -594,40 +576,27 @@ function createRemoveCheckers(schema) {
|
|
|
594
576
|
}, { dontCollect: true });
|
|
595
577
|
if (result instanceof Promise) {
|
|
596
578
|
promises.push(result.then(function (_a) {
|
|
597
|
-
var _b,
|
|
598
|
-
var _d = tslib_1.__read(_a, 1), row = _d[0];
|
|
579
|
+
var _b = tslib_1.__read(_a, 1), row = _b[0];
|
|
599
580
|
if (row) {
|
|
600
|
-
var
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
_b[e] = (_c = {},
|
|
604
|
-
_c[row.id] = row,
|
|
605
|
-
_c),
|
|
606
|
-
_b)
|
|
607
|
-
};
|
|
608
|
-
throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
581
|
+
var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
582
|
+
err.addData(e, [row]);
|
|
583
|
+
throw err;
|
|
609
584
|
}
|
|
610
585
|
}));
|
|
611
586
|
}
|
|
612
587
|
else {
|
|
613
|
-
var
|
|
588
|
+
var _k = tslib_1.__read(result, 1), row = _k[0];
|
|
614
589
|
if (row) {
|
|
615
|
-
var
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
_j[e] = (_k = {},
|
|
619
|
-
_k[row.id] = row,
|
|
620
|
-
_k),
|
|
621
|
-
_j)
|
|
622
|
-
};
|
|
623
|
-
throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
590
|
+
var err = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(e, "\u300D\u5173\u8054\u7684\u884C"));
|
|
591
|
+
err.addData(e, [row]);
|
|
592
|
+
throw err;
|
|
624
593
|
}
|
|
625
594
|
}
|
|
626
595
|
};
|
|
627
596
|
try {
|
|
628
597
|
for (var _c = (e_3 = void 0, tslib_1.__values(OneToManyMatrix[entity])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
629
598
|
var otm = _d.value;
|
|
630
|
-
|
|
599
|
+
_loop_5(otm);
|
|
631
600
|
}
|
|
632
601
|
}
|
|
633
602
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -639,16 +608,16 @@ function createRemoveCheckers(schema) {
|
|
|
639
608
|
}
|
|
640
609
|
}
|
|
641
610
|
if (OneToManyOnEntityMatrix[entity]) {
|
|
642
|
-
var
|
|
643
|
-
var
|
|
611
|
+
var _loop_6 = function (otm) {
|
|
612
|
+
var _l, _m, _o;
|
|
644
613
|
var proj = {
|
|
645
614
|
id: 1,
|
|
646
615
|
entity: 1,
|
|
647
616
|
entityId: 1,
|
|
648
617
|
};
|
|
649
|
-
var filter = operation.filter && (
|
|
650
|
-
|
|
651
|
-
|
|
618
|
+
var filter = operation.filter && (_l = {},
|
|
619
|
+
_l[entity] = operation.filter,
|
|
620
|
+
_l);
|
|
652
621
|
var result = context.select(otm, {
|
|
653
622
|
data: proj,
|
|
654
623
|
filter: filter,
|
|
@@ -657,40 +626,35 @@ function createRemoveCheckers(schema) {
|
|
|
657
626
|
}, { dontCollect: true });
|
|
658
627
|
if (result instanceof Promise) {
|
|
659
628
|
promises.push(result.then(function (_a) {
|
|
660
|
-
var _b,
|
|
661
|
-
var _d = tslib_1.__read(_a, 1), row = _d[0];
|
|
629
|
+
var _b = tslib_1.__read(_a, 1), row = _b[0];
|
|
662
630
|
if (row) {
|
|
663
|
-
var
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
_b[otm] = (_c = {},
|
|
667
|
-
_c[row.id] = row,
|
|
668
|
-
_c),
|
|
669
|
-
_b)
|
|
670
|
-
};
|
|
671
|
-
throw new Exception_1.OakRowInconsistencyException(record, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
|
|
631
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
|
|
632
|
+
e.addData(otm, [row]);
|
|
633
|
+
throw e;
|
|
672
634
|
}
|
|
673
635
|
}));
|
|
674
636
|
}
|
|
675
637
|
else {
|
|
676
|
-
var
|
|
638
|
+
var _p = tslib_1.__read(result, 1), row = _p[0];
|
|
677
639
|
if (row) {
|
|
678
640
|
var record = {
|
|
679
641
|
a: 's',
|
|
680
|
-
d: (
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
642
|
+
d: (_m = {},
|
|
643
|
+
_m[otm] = (_o = {},
|
|
644
|
+
_o[row.id] = row,
|
|
645
|
+
_o),
|
|
646
|
+
_m)
|
|
685
647
|
};
|
|
686
|
-
|
|
648
|
+
var e = new Exception_1.OakRowInconsistencyException(undefined, "\u60A8\u65E0\u6CD5\u5220\u9664\u5B58\u5728\u6709\u6548\u6570\u636E\u300C".concat(otm, "\u300D\u5173\u8054\u7684\u884C"));
|
|
649
|
+
e.addData(otm, [row]);
|
|
650
|
+
throw e;
|
|
687
651
|
}
|
|
688
652
|
}
|
|
689
653
|
};
|
|
690
654
|
try {
|
|
691
655
|
for (var _e = (e_4 = void 0, tslib_1.__values(OneToManyOnEntityMatrix[entity])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
692
656
|
var otm = _f.value;
|
|
693
|
-
|
|
657
|
+
_loop_6(otm);
|
|
694
658
|
}
|
|
695
659
|
}
|
|
696
660
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -720,6 +684,146 @@ function createRemoveCheckers(schema) {
|
|
|
720
684
|
}
|
|
721
685
|
finally { if (e_1) throw e_1.error; }
|
|
722
686
|
}
|
|
687
|
+
var _loop_4 = function (entity) {
|
|
688
|
+
var e_5, _b;
|
|
689
|
+
var cascadeRemove = authDict[entity].cascadeRemove;
|
|
690
|
+
if (cascadeRemove) {
|
|
691
|
+
var entitiesOnEntityAttr = [];
|
|
692
|
+
var hasAllEntity = false;
|
|
693
|
+
var _loop_7 = function (attr) {
|
|
694
|
+
if (attr === '@entity') {
|
|
695
|
+
hasAllEntity = true;
|
|
696
|
+
return "continue";
|
|
697
|
+
}
|
|
698
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
699
|
+
if (rel === 2) {
|
|
700
|
+
entitiesOnEntityAttr.push(attr);
|
|
701
|
+
checkers.push({
|
|
702
|
+
entity: attr,
|
|
703
|
+
action: 'remove',
|
|
704
|
+
type: 'logical',
|
|
705
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
706
|
+
checker: function (operation, context) {
|
|
707
|
+
var _a, _b;
|
|
708
|
+
var filter = operation.filter;
|
|
709
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
710
|
+
return context.operate(entity, {
|
|
711
|
+
id: (0, uuid_1.generateNewId)(),
|
|
712
|
+
action: 'remove',
|
|
713
|
+
data: {},
|
|
714
|
+
filter: filter ? (_a = {},
|
|
715
|
+
_a[attr] = filter,
|
|
716
|
+
_a) : undefined,
|
|
717
|
+
}, { dontCollect: true });
|
|
718
|
+
}
|
|
719
|
+
return context.operate(entity, {
|
|
720
|
+
id: (0, uuid_1.generateNewId)(),
|
|
721
|
+
action: 'update',
|
|
722
|
+
data: {
|
|
723
|
+
entity: null,
|
|
724
|
+
entityId: null,
|
|
725
|
+
},
|
|
726
|
+
filter: filter ? (_b = {},
|
|
727
|
+
_b[attr] = filter,
|
|
728
|
+
_b) : undefined,
|
|
729
|
+
}, { dontCollect: true });
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
(0, assert_1.default)(typeof rel === 'string');
|
|
735
|
+
checkers.push({
|
|
736
|
+
entity: rel,
|
|
737
|
+
action: 'remove',
|
|
738
|
+
type: 'logical',
|
|
739
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
740
|
+
checker: function (operation, context) {
|
|
741
|
+
var _a, _b, _c;
|
|
742
|
+
var filter = operation.filter;
|
|
743
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
744
|
+
return context.operate(entity, {
|
|
745
|
+
id: (0, uuid_1.generateNewId)(),
|
|
746
|
+
action: 'remove',
|
|
747
|
+
data: {},
|
|
748
|
+
filter: filter ? (_a = {},
|
|
749
|
+
_a[attr] = filter,
|
|
750
|
+
_a) : undefined,
|
|
751
|
+
}, { dontCollect: true });
|
|
752
|
+
}
|
|
753
|
+
return context.operate(entity, {
|
|
754
|
+
id: (0, uuid_1.generateNewId)(),
|
|
755
|
+
action: 'update',
|
|
756
|
+
data: (_b = {},
|
|
757
|
+
_b["".concat(attr, "Id")] = null,
|
|
758
|
+
_b),
|
|
759
|
+
filter: filter ? (_c = {},
|
|
760
|
+
_c[attr] = filter,
|
|
761
|
+
_c) : undefined,
|
|
762
|
+
}, { dontCollect: true });
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
for (var attr in cascadeRemove) {
|
|
768
|
+
_loop_7(attr);
|
|
769
|
+
}
|
|
770
|
+
if (hasAllEntity) {
|
|
771
|
+
var attributes = schema[entity].attributes;
|
|
772
|
+
var ref = attributes.entity.ref;
|
|
773
|
+
var restEntities = (0, lodash_1.difference)(ref, entitiesOnEntityAttr);
|
|
774
|
+
var _loop_8 = function (e) {
|
|
775
|
+
checkers.push({
|
|
776
|
+
entity: e,
|
|
777
|
+
action: 'remove',
|
|
778
|
+
type: 'logical',
|
|
779
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
780
|
+
checker: function (operation, context) {
|
|
781
|
+
var _a, _b;
|
|
782
|
+
var filter = operation.filter;
|
|
783
|
+
if (cascadeRemove['@entity'] === 'remove') {
|
|
784
|
+
return context.operate(entity, {
|
|
785
|
+
id: (0, uuid_1.generateNewId)(),
|
|
786
|
+
action: 'remove',
|
|
787
|
+
data: {},
|
|
788
|
+
filter: filter ? (_a = {},
|
|
789
|
+
_a[e] = filter,
|
|
790
|
+
_a) : undefined,
|
|
791
|
+
}, { dontCollect: true });
|
|
792
|
+
}
|
|
793
|
+
return context.operate(entity, {
|
|
794
|
+
id: (0, uuid_1.generateNewId)(),
|
|
795
|
+
action: 'update',
|
|
796
|
+
data: {
|
|
797
|
+
entity: null,
|
|
798
|
+
entityId: null,
|
|
799
|
+
},
|
|
800
|
+
filter: filter ? (_b = {},
|
|
801
|
+
_b[e] = filter,
|
|
802
|
+
_b) : undefined,
|
|
803
|
+
}, { dontCollect: true });
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
try {
|
|
808
|
+
for (var restEntities_1 = (e_5 = void 0, tslib_1.__values(restEntities)), restEntities_1_1 = restEntities_1.next(); !restEntities_1_1.done; restEntities_1_1 = restEntities_1.next()) {
|
|
809
|
+
var e = restEntities_1_1.value;
|
|
810
|
+
_loop_8(e);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
814
|
+
finally {
|
|
815
|
+
try {
|
|
816
|
+
if (restEntities_1_1 && !restEntities_1_1.done && (_b = restEntities_1.return)) _b.call(restEntities_1);
|
|
817
|
+
}
|
|
818
|
+
finally { if (e_5) throw e_5.error; }
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
// 注入声明的cascade删除时的外键处理动作
|
|
824
|
+
for (var entity in authDict) {
|
|
825
|
+
_loop_4(entity);
|
|
826
|
+
}
|
|
723
827
|
return checkers;
|
|
724
828
|
}
|
|
725
829
|
exports.createRemoveCheckers = createRemoveCheckers;
|
package/lib/store/selection.d.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { StorageSchema } from '../types';
|
|
2
2
|
import { EntityDict } from '../types/Entity';
|
|
3
|
+
declare type SelectionRewriter<ED extends EntityDict> = (schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection']) => void;
|
|
4
|
+
export declare function registerSelectionRewriter<ED extends EntityDict>(rewriter: SelectionRewriter<ED>): void;
|
|
5
|
+
declare type OperationRewriter<ED extends EntityDict> = (schema: StorageSchema<ED>, entity: keyof ED, operate: ED[keyof ED]['Operation']) => void;
|
|
6
|
+
export declare function registerOperationRewriter<ED extends EntityDict>(rewriter: OperationRewriter<ED>): void;
|
|
3
7
|
/**
|
|
4
8
|
* 对selection进行一些完善,避免编程人员的疏漏
|
|
5
9
|
* @param selection
|
|
6
10
|
*/
|
|
7
11
|
export declare function reinforceSelection<ED extends EntityDict>(schema: StorageSchema<ED>, entity: keyof ED, selection: ED[keyof ED]['Selection']): void;
|
|
12
|
+
/**
|
|
13
|
+
* 对operation进行一些完善,作为operation算子的注入点
|
|
14
|
+
* @param schema
|
|
15
|
+
* @param entity
|
|
16
|
+
* @param selection
|
|
17
|
+
*/
|
|
18
|
+
export declare function reinforceOperation<ED extends EntityDict>(schema: StorageSchema<ED>, entity: keyof ED, operation: ED[keyof ED]['Operation']): void;
|
|
19
|
+
export {};
|
package/lib/store/selection.js
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reinforceSelection = void 0;
|
|
3
|
+
exports.reinforceOperation = exports.reinforceSelection = exports.registerOperationRewriter = exports.registerSelectionRewriter = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var types_1 = require("../types");
|
|
7
7
|
var Demand_1 = require("../types/Demand");
|
|
8
8
|
var filter_1 = require("./filter");
|
|
9
9
|
var relation_1 = require("./relation");
|
|
10
|
+
var SelectionRewriters = [];
|
|
11
|
+
function registerSelectionRewriter(rewriter) {
|
|
12
|
+
SelectionRewriters.push(rewriter);
|
|
13
|
+
}
|
|
14
|
+
exports.registerSelectionRewriter = registerSelectionRewriter;
|
|
15
|
+
function getSelectionRewriters() {
|
|
16
|
+
return SelectionRewriters;
|
|
17
|
+
}
|
|
18
|
+
var OperationRewriters = [];
|
|
19
|
+
function registerOperationRewriter(rewriter) {
|
|
20
|
+
OperationRewriters.push(rewriter);
|
|
21
|
+
}
|
|
22
|
+
exports.registerOperationRewriter = registerOperationRewriter;
|
|
23
|
+
function getOperationRewriters() {
|
|
24
|
+
return OperationRewriters;
|
|
25
|
+
}
|
|
10
26
|
/**
|
|
11
27
|
* 对selection进行一些完善,避免编程人员的疏漏
|
|
12
28
|
* @param selection
|
|
13
29
|
*/
|
|
14
30
|
function reinforceSelection(schema, entity, selection) {
|
|
15
31
|
var filter = selection.filter, data = selection.data, sorter = selection.sorter;
|
|
32
|
+
Object.assign(data, {
|
|
33
|
+
'$$createAt$$': 1,
|
|
34
|
+
}); // 有的页面依赖于其它页面取数据,有时两个页面的filter的差异会导致有一个加createAt,有一个不加,此时可能产生前台取数据不完整的异常。先统一加上
|
|
16
35
|
var checkNode = function (projectionNode, attrs) {
|
|
17
36
|
attrs.forEach(function (attr) {
|
|
18
37
|
var _a;
|
|
@@ -234,5 +253,16 @@ function reinforceSelection(schema, entity, selection) {
|
|
|
234
253
|
$$createAt$$: 1,
|
|
235
254
|
});
|
|
236
255
|
}
|
|
256
|
+
SelectionRewriters.forEach(function (ele) { return ele(schema, entity, selection); });
|
|
237
257
|
}
|
|
238
258
|
exports.reinforceSelection = reinforceSelection;
|
|
259
|
+
/**
|
|
260
|
+
* 对operation进行一些完善,作为operation算子的注入点
|
|
261
|
+
* @param schema
|
|
262
|
+
* @param entity
|
|
263
|
+
* @param selection
|
|
264
|
+
*/
|
|
265
|
+
function reinforceOperation(schema, entity, operation) {
|
|
266
|
+
OperationRewriters.forEach(function (ele) { return ele(schema, entity, operation); });
|
|
267
|
+
}
|
|
268
|
+
exports.reinforceOperation = reinforceOperation;
|
package/lib/types/Action.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare type ActionDictOfEntityDict<E extends EntityDict> = {
|
|
|
13
13
|
[A in keyof E[T]['OpSchema']]?: ActionDef<string, string>;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
+
export declare type CascadeActionItem = CascadeRelationItem;
|
|
16
17
|
export declare type CascadeActionAuth<A extends Action = ''> = {
|
|
17
|
-
[K in A | GenericAction]?:
|
|
18
|
+
[K in A | GenericAction]?: CascadeActionItem | (CascadeActionItem | CascadeActionItem[])[];
|
|
18
19
|
};
|
|
20
|
+
export declare type ActionOnRemove = 'setNull' | 'remove';
|
package/lib/types/Auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CascadeActionAuth, CascadeRelationAuth } from ".";
|
|
1
|
+
import { CascadeActionAuth, CascadeRelationAuth, ActionOnRemove } from ".";
|
|
2
2
|
import { AsyncContext } from "../store/AsyncRowStore";
|
|
3
3
|
import { SyncContext } from "../store/SyncRowStore";
|
|
4
4
|
import { EntityDict, OperateOption, SelectOption } from "../types/Entity";
|
|
@@ -60,6 +60,9 @@ export declare type Checker<ED extends EntityDict, T extends keyof ED, Cxt exten
|
|
|
60
60
|
export declare type AuthDef<ED extends EntityDict, T extends keyof ED> = {
|
|
61
61
|
relationAuth?: CascadeRelationAuth<NonNullable<ED[T]['Relation']>>;
|
|
62
62
|
actionAuth?: CascadeActionAuth<ED[T]['Action']>;
|
|
63
|
+
cascadeRemove?: {
|
|
64
|
+
[E in (keyof ED | '@entity')]?: ActionOnRemove;
|
|
65
|
+
};
|
|
63
66
|
};
|
|
64
67
|
export declare type AuthDefDict<ED extends EntityDict> = {
|
|
65
68
|
[K in keyof ED]?: AuthDef<ED, K>;
|
package/lib/types/Connector.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare abstract class Connector<ED extends EntityDict, BackCxt extends A
|
|
|
19
19
|
body: any;
|
|
20
20
|
headers?: Record<string, any>;
|
|
21
21
|
};
|
|
22
|
-
abstract serializeException(exception: OakException
|
|
22
|
+
abstract serializeException(exception: OakException<ED>, headers: IncomingHttpHeaders, body: any): {
|
|
23
23
|
body: any;
|
|
24
24
|
headers?: Record<string, any>;
|
|
25
25
|
};
|
package/lib/types/Entity.d.ts
CHANGED
package/lib/types/Exception.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { EntityDict, OpRecord } from "./Entity";
|
|
2
|
-
export declare class OakException extends Error {
|
|
1
|
+
import { EntityDict, OpRecord, SelectOpResult } from "./Entity";
|
|
2
|
+
export declare class OakException<ED extends EntityDict> extends Error {
|
|
3
|
+
opRecord: SelectOpResult<ED>;
|
|
3
4
|
constructor(message?: string);
|
|
5
|
+
addData<T extends keyof ED>(entity: T, rows: Partial<ED[T]['OpSchema']>[]): void;
|
|
6
|
+
setOpRecords(opRecord: SelectOpResult<ED>): void;
|
|
4
7
|
toString(): string;
|
|
5
8
|
}
|
|
6
|
-
export declare class OakDataException extends OakException {
|
|
9
|
+
export declare class OakDataException<ED extends EntityDict> extends OakException<ED> {
|
|
7
10
|
}
|
|
8
|
-
export declare class OakUniqueViolationException extends OakException {
|
|
11
|
+
export declare class OakUniqueViolationException<ED extends EntityDict> extends OakException<ED> {
|
|
9
12
|
rows: Array<{
|
|
10
13
|
id?: string;
|
|
11
14
|
attrs: string[];
|
|
@@ -15,14 +18,14 @@ export declare class OakUniqueViolationException extends OakException {
|
|
|
15
18
|
attrs: string[];
|
|
16
19
|
}>, message?: string);
|
|
17
20
|
}
|
|
18
|
-
export declare class OakImportDataParseException extends OakException {
|
|
21
|
+
export declare class OakImportDataParseException<ED extends EntityDict> extends OakException<ED> {
|
|
19
22
|
line: number;
|
|
20
23
|
header?: string;
|
|
21
24
|
constructor(message: string, line: number, header?: string);
|
|
22
25
|
}
|
|
23
|
-
export declare class OakOperExistedException extends OakDataException {
|
|
26
|
+
export declare class OakOperExistedException<ED extends EntityDict> extends OakDataException<ED> {
|
|
24
27
|
}
|
|
25
|
-
export declare class OakRowUnexistedException extends OakDataException {
|
|
28
|
+
export declare class OakRowUnexistedException<ED extends EntityDict> extends OakDataException<ED> {
|
|
26
29
|
private rows;
|
|
27
30
|
constructor(rows: Array<{
|
|
28
31
|
entity: any;
|
|
@@ -36,22 +39,20 @@ export declare class OakRowUnexistedException extends OakDataException {
|
|
|
36
39
|
}
|
|
37
40
|
export declare class OakExternalException extends Error {
|
|
38
41
|
}
|
|
39
|
-
export declare class OakUserException extends OakException {
|
|
42
|
+
export declare class OakUserException<ED extends EntityDict> extends OakException<ED> {
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* 数据不一致异常,系统认为现有的数据不允许相应的动作时抛此异常
|
|
43
46
|
*
|
|
44
47
|
*/
|
|
45
|
-
export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException {
|
|
46
|
-
private data?;
|
|
48
|
+
export declare class OakRowInconsistencyException<ED extends EntityDict> extends OakUserException<ED> {
|
|
47
49
|
constructor(data?: OpRecord<ED>, message?: string);
|
|
48
|
-
getData(): OpRecord<ED> | undefined;
|
|
49
50
|
toString(): string;
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* 当输入的数据非法时抛此异常,attributes表示非法的属性
|
|
53
54
|
*/
|
|
54
|
-
export declare class OakInputIllegalException extends OakUserException {
|
|
55
|
+
export declare class OakInputIllegalException<ED extends EntityDict> extends OakUserException<ED> {
|
|
55
56
|
private attributes;
|
|
56
57
|
private entity;
|
|
57
58
|
constructor(entity: string, attributes: string[], message?: string);
|
|
@@ -63,24 +64,24 @@ export declare class OakInputIllegalException extends OakUserException {
|
|
|
63
64
|
/**
|
|
64
65
|
* 用户权限不够时抛的异常
|
|
65
66
|
*/
|
|
66
|
-
export declare class OakUserUnpermittedException extends OakUserException {
|
|
67
|
+
export declare class OakUserUnpermittedException<ED extends EntityDict> extends OakUserException<ED> {
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* 用户未登录抛的异常
|
|
70
71
|
*/
|
|
71
|
-
export declare class OakUnloggedInException extends OakUserException {
|
|
72
|
+
export declare class OakUnloggedInException<ED extends EntityDict> extends OakUserException<ED> {
|
|
72
73
|
constructor(message?: string);
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* 用户未登录抛的异常
|
|
76
77
|
*/
|
|
77
|
-
export declare class OakRowLockedException extends OakUserException {
|
|
78
|
+
export declare class OakRowLockedException<ED extends EntityDict> extends OakUserException<ED> {
|
|
78
79
|
constructor(message?: string);
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* 要插入行时,发现已经有相同的行数据
|
|
82
83
|
*/
|
|
83
|
-
export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> extends OakUserException {
|
|
84
|
+
export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyof ED> extends OakUserException<ED> {
|
|
84
85
|
private data;
|
|
85
86
|
private entity;
|
|
86
87
|
constructor(entity: T, data: ED[T]['OpSchema'], message?: string);
|
|
@@ -88,11 +89,12 @@ export declare class OakCongruentRowExists<ED extends EntityDict, T extends keyo
|
|
|
88
89
|
getEntity(): T;
|
|
89
90
|
toString(): string;
|
|
90
91
|
}
|
|
91
|
-
export declare class OakDeadlock extends OakUserException {
|
|
92
|
+
export declare class OakDeadlock<ED extends EntityDict> extends OakUserException<ED> {
|
|
92
93
|
constructor(message?: string | undefined);
|
|
93
94
|
}
|
|
94
|
-
export declare function makeException(data: {
|
|
95
|
+
export declare function makeException<ED extends EntityDict>(data: {
|
|
95
96
|
name: string;
|
|
96
97
|
message?: string;
|
|
98
|
+
opRecords: SelectOpResult<ED>;
|
|
97
99
|
[A: string]: any;
|
|
98
|
-
}): OakException |
|
|
100
|
+
}): OakException<EntityDict> | undefined;
|