oak-domain 2.5.1 → 2.5.2
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 +121 -108
- package/lib/store/checker.d.ts +1 -1
- package/lib/store/checker.js +148 -6
- package/lib/types/Action.d.ts +3 -1
- package/lib/types/Auth.d.ts +4 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CascadeRelationItem, RelationHierarchy } from "../types/Entity";
|
|
1
|
+
import { CascadeRelationItem, RelationHierarchy, EntityDict } from "../types/Entity";
|
|
2
2
|
export declare type GenericRelation = 'owner';
|
|
3
|
-
export declare function convertHierarchyToAuth<
|
|
4
|
-
[K in
|
|
3
|
+
export declare function convertHierarchyToAuth<ED extends EntityDict, T extends keyof ED>(entity: T, hierarchy: RelationHierarchy<NonNullable<ED[T]['Relation']>>): {
|
|
4
|
+
[K in NonNullable<ED[T]['Relation']>]?: CascadeRelationItem;
|
|
5
5
|
};
|
package/lib/actions/relation.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertHierarchyToAuth = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
function convertHierarchyToAuth(hierarchy) {
|
|
5
|
+
function convertHierarchyToAuth(entity, hierarchy) {
|
|
6
6
|
var e_1, _a;
|
|
7
7
|
var _b;
|
|
8
8
|
var reverseHierarchy = {};
|
package/lib/checkers/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var modi_1 = require("../store/modi");
|
|
|
7
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
|
-
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createRemoveCheckers)(schema)), false));
|
|
10
|
+
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createRemoveCheckers)(schema, authDict)), false));
|
|
11
11
|
if (authDict) {
|
|
12
12
|
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createAuthCheckers)(schema, authDict)), false));
|
|
13
13
|
}
|
|
@@ -100,20 +100,27 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
|
-
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
var entityIds = (0, lodash_1.uniq)(result.filter(function (ele) { return ele.entity === attr; }).map(function (ele) {
|
|
104
|
+
(0, assert_1.default)(ele.entityId !== null);
|
|
105
|
+
return ele.entityId;
|
|
106
|
+
}));
|
|
107
|
+
if (entityIds.length > 0) {
|
|
108
|
+
var subRows = cascadeSelectFn.call(_this, attr, {
|
|
109
|
+
data: projection2[attr],
|
|
110
|
+
filter: {
|
|
111
|
+
id: {
|
|
112
|
+
$in: entityIds
|
|
113
|
+
},
|
|
109
114
|
},
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
}, context, option);
|
|
116
|
+
if (subRows instanceof Promise) {
|
|
117
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
dealWithSubRows(subRows);
|
|
121
|
+
}
|
|
114
122
|
}
|
|
115
123
|
else {
|
|
116
|
-
dealWithSubRows(subRows);
|
|
117
124
|
}
|
|
118
125
|
});
|
|
119
126
|
}
|
|
@@ -191,18 +198,20 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
191
198
|
});
|
|
192
199
|
};
|
|
193
200
|
var ids = (0, lodash_1.uniq)(result.filter(function (ele) { return !!(ele["".concat(attr, "Id")]); }).map(function (ele) { return ele["".concat(attr, "Id")]; }));
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
if (ids.length > 0) {
|
|
202
|
+
var subRows = cascadeSelectFn.call(_this, relation, {
|
|
203
|
+
data: projection2[attr],
|
|
204
|
+
filter: {
|
|
205
|
+
id: {
|
|
206
|
+
$in: ids
|
|
207
|
+
},
|
|
199
208
|
},
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
209
|
+
}, context, option);
|
|
210
|
+
if (subRows instanceof Promise) {
|
|
211
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
212
|
+
}
|
|
213
|
+
dealWithSubRows(subRows);
|
|
204
214
|
}
|
|
205
|
-
dealWithSubRows(subRows);
|
|
206
215
|
});
|
|
207
216
|
}
|
|
208
217
|
}
|
|
@@ -261,21 +270,23 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
261
270
|
_a));
|
|
262
271
|
});
|
|
263
272
|
};
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
273
|
+
if (ids.length > 0) {
|
|
274
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
275
|
+
data: subProjection_1,
|
|
276
|
+
filter: (0, filter_1.combineFilters)([(_a = {},
|
|
277
|
+
_a[foreignKey_1] = {
|
|
278
|
+
$in: ids,
|
|
279
|
+
},
|
|
280
|
+
_a), subFilter_1]),
|
|
281
|
+
sorter: subSorter_1,
|
|
282
|
+
indexFrom: indexFrom_1,
|
|
283
|
+
count: count_1
|
|
284
|
+
}, context, option);
|
|
285
|
+
if (subRows instanceof Promise) {
|
|
286
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
287
|
+
}
|
|
288
|
+
dealWithSubRows(subRows);
|
|
277
289
|
}
|
|
278
|
-
dealWithSubRows(subRows);
|
|
279
290
|
});
|
|
280
291
|
}
|
|
281
292
|
}
|
|
@@ -329,22 +340,24 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
329
340
|
_a));
|
|
330
341
|
});
|
|
331
342
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
343
|
+
if (ids.length > 0) {
|
|
344
|
+
var subRows = cascadeSelectFn.call(_this, entity2_1, {
|
|
345
|
+
data: subProjection_1,
|
|
346
|
+
filter: (0, filter_1.combineFilters)([{
|
|
347
|
+
entity: entity,
|
|
348
|
+
entityId: {
|
|
349
|
+
$in: ids,
|
|
350
|
+
}
|
|
351
|
+
}, subFilter_1]),
|
|
352
|
+
sorter: subSorter_1,
|
|
353
|
+
indexFrom: indexFrom_1,
|
|
354
|
+
count: count_1
|
|
355
|
+
}, context, option);
|
|
356
|
+
if (subRows instanceof Promise) {
|
|
357
|
+
return subRows.then(function (subRowss) { return dealWithSubRows(subRowss); });
|
|
358
|
+
}
|
|
359
|
+
dealWithSubRows(subRows);
|
|
346
360
|
}
|
|
347
|
-
dealWithSubRows(subRows);
|
|
348
361
|
});
|
|
349
362
|
}
|
|
350
363
|
}
|
|
@@ -708,11 +721,11 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
708
721
|
*/
|
|
709
722
|
CascadeStore.prototype.doUpdateSingleRowAsync = function (entity, operation, context, option) {
|
|
710
723
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
711
|
-
var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, createOper, updateAttrCount, result;
|
|
712
|
-
var e_2,
|
|
724
|
+
var data, action, operId, filter, now, _a, modiCreate, result_1, createInner, multipleCreate, data_1, data_1_1, d, createSingleOper, e_2_1, operatorId, createOper, _b, ids_1, selection, rows, modiUpsert, upsertModis, _c, originData, originId, _d, createOper, updateAttrCount, result;
|
|
725
|
+
var e_2, _e, _f, _g, _h, _j, _k, _l;
|
|
713
726
|
var _this = this;
|
|
714
|
-
return tslib_1.__generator(this, function (
|
|
715
|
-
switch (
|
|
727
|
+
return tslib_1.__generator(this, function (_m) {
|
|
728
|
+
switch (_m.label) {
|
|
716
729
|
case 0:
|
|
717
730
|
data = operation.data, action = operation.action, operId = operation.id, filter = operation.filter;
|
|
718
731
|
now = Date.now();
|
|
@@ -746,7 +759,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
746
759
|
};
|
|
747
760
|
return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiCreate, context, option)];
|
|
748
761
|
case 2:
|
|
749
|
-
|
|
762
|
+
_m.sent();
|
|
750
763
|
return [2 /*return*/, 1];
|
|
751
764
|
case 3:
|
|
752
765
|
result_1 = 0;
|
|
@@ -836,12 +849,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
836
849
|
if (!multipleCreate) return [3 /*break*/, 5];
|
|
837
850
|
return [4 /*yield*/, createInner(operation)];
|
|
838
851
|
case 4:
|
|
839
|
-
|
|
852
|
+
_m.sent();
|
|
840
853
|
return [3 /*break*/, 12];
|
|
841
854
|
case 5:
|
|
842
|
-
|
|
855
|
+
_m.trys.push([5, 10, 11, 12]);
|
|
843
856
|
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
|
|
844
|
-
|
|
857
|
+
_m.label = 6;
|
|
845
858
|
case 6:
|
|
846
859
|
if (!!data_1_1.done) return [3 /*break*/, 9];
|
|
847
860
|
d = data_1_1.value;
|
|
@@ -852,27 +865,27 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
852
865
|
};
|
|
853
866
|
return [4 /*yield*/, createInner(createSingleOper)];
|
|
854
867
|
case 7:
|
|
855
|
-
|
|
856
|
-
|
|
868
|
+
_m.sent();
|
|
869
|
+
_m.label = 8;
|
|
857
870
|
case 8:
|
|
858
871
|
data_1_1 = data_1.next();
|
|
859
872
|
return [3 /*break*/, 6];
|
|
860
873
|
case 9: return [3 /*break*/, 12];
|
|
861
874
|
case 10:
|
|
862
|
-
e_2_1 =
|
|
875
|
+
e_2_1 = _m.sent();
|
|
863
876
|
e_2 = { error: e_2_1 };
|
|
864
877
|
return [3 /*break*/, 12];
|
|
865
878
|
case 11:
|
|
866
879
|
try {
|
|
867
|
-
if (data_1_1 && !data_1_1.done && (
|
|
880
|
+
if (data_1_1 && !data_1_1.done && (_e = data_1.return)) _e.call(data_1);
|
|
868
881
|
}
|
|
869
882
|
finally { if (e_2) throw e_2.error; }
|
|
870
883
|
return [7 /*endfinally*/];
|
|
871
884
|
case 12: return [3 /*break*/, 15];
|
|
872
885
|
case 13: return [4 /*yield*/, createInner(operation)];
|
|
873
886
|
case 14:
|
|
874
|
-
|
|
875
|
-
|
|
887
|
+
_m.sent();
|
|
888
|
+
_m.label = 15;
|
|
876
889
|
case 15:
|
|
877
890
|
if (!option.dontCollect) {
|
|
878
891
|
context.opRecords.push({
|
|
@@ -886,20 +899,20 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
886
899
|
(0, assert_1.default)(operId);
|
|
887
900
|
return [4 /*yield*/, context.getCurrentUserId(true)];
|
|
888
901
|
case 16:
|
|
889
|
-
operatorId =
|
|
902
|
+
operatorId = _m.sent();
|
|
890
903
|
if (!operatorId) return [3 /*break*/, 22];
|
|
891
|
-
|
|
904
|
+
_f = {
|
|
892
905
|
id: 'dummy',
|
|
893
906
|
action: 'create'
|
|
894
907
|
};
|
|
895
|
-
|
|
908
|
+
_g = {
|
|
896
909
|
id: operId,
|
|
897
910
|
action: action,
|
|
898
911
|
data: data,
|
|
899
912
|
operatorId: operatorId
|
|
900
913
|
};
|
|
901
914
|
if (!(data instanceof Array)) return [3 /*break*/, 18];
|
|
902
|
-
|
|
915
|
+
_h = {
|
|
903
916
|
id: 'dummy',
|
|
904
917
|
action: 'create'
|
|
905
918
|
};
|
|
@@ -918,34 +931,34 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
918
931
|
});
|
|
919
932
|
}); }))];
|
|
920
933
|
case 17:
|
|
921
|
-
_b = (
|
|
922
|
-
|
|
934
|
+
_b = (_h.data = _m.sent(),
|
|
935
|
+
_h);
|
|
923
936
|
return [3 /*break*/, 20];
|
|
924
937
|
case 18:
|
|
925
|
-
|
|
938
|
+
_j = {
|
|
926
939
|
id: 'dummy',
|
|
927
940
|
action: 'create'
|
|
928
941
|
};
|
|
929
|
-
|
|
942
|
+
_k = {};
|
|
930
943
|
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
931
944
|
case 19:
|
|
932
|
-
_b = [(
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
945
|
+
_b = [(_j.data = (_k.id = _m.sent(),
|
|
946
|
+
_k.entity = entity,
|
|
947
|
+
_k.entityId = data.id,
|
|
948
|
+
_k),
|
|
949
|
+
_j)];
|
|
950
|
+
_m.label = 20;
|
|
938
951
|
case 20:
|
|
939
|
-
createOper = (
|
|
940
|
-
|
|
941
|
-
|
|
952
|
+
createOper = (_f.data = (_g.operEntity$oper = _b,
|
|
953
|
+
_g),
|
|
954
|
+
_f);
|
|
942
955
|
return [4 /*yield*/, this.cascadeUpdateAsync('oper', createOper, context, {
|
|
943
956
|
dontCollect: true,
|
|
944
957
|
dontCreateOper: true,
|
|
945
958
|
})];
|
|
946
959
|
case 21:
|
|
947
|
-
|
|
948
|
-
|
|
960
|
+
_m.sent();
|
|
961
|
+
_m.label = 22;
|
|
949
962
|
case 22: return [2 /*return*/, result_1];
|
|
950
963
|
case 23:
|
|
951
964
|
ids_1 = (0, filter_2.getRelevantIds)(filter);
|
|
@@ -962,9 +975,9 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
962
975
|
dontCollect: true,
|
|
963
976
|
})];
|
|
964
977
|
case 24:
|
|
965
|
-
rows =
|
|
978
|
+
rows = _m.sent();
|
|
966
979
|
ids_1.push.apply(ids_1, tslib_1.__spreadArray([], tslib_1.__read((rows.map(function (ele) { return ele.id; }))), false));
|
|
967
|
-
|
|
980
|
+
_m.label = 25;
|
|
968
981
|
case 25:
|
|
969
982
|
if (data) {
|
|
970
983
|
this.preProcessDataUpdated(data);
|
|
@@ -1003,7 +1016,7 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1003
1016
|
count: 1,
|
|
1004
1017
|
}, context, option)];
|
|
1005
1018
|
case 26:
|
|
1006
|
-
upsertModis =
|
|
1019
|
+
upsertModis = _m.sent();
|
|
1007
1020
|
if (upsertModis.length > 0) {
|
|
1008
1021
|
_c = upsertModis[0], originData = _c.data, originId = _c.id;
|
|
1009
1022
|
modiUpsert = {
|
|
@@ -1017,24 +1030,26 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1017
1030
|
}
|
|
1018
1031
|
};
|
|
1019
1032
|
}
|
|
1020
|
-
|
|
1033
|
+
_m.label = 27;
|
|
1021
1034
|
case 27:
|
|
1022
1035
|
if (!!modiUpsert) return [3 /*break*/, 29];
|
|
1023
|
-
|
|
1036
|
+
modiUpsert = {
|
|
1024
1037
|
id: 'dummy',
|
|
1025
|
-
action: 'create'
|
|
1038
|
+
action: 'create',
|
|
1039
|
+
data: {
|
|
1040
|
+
id: operId,
|
|
1041
|
+
targetEntity: entity,
|
|
1042
|
+
entity: option.modiParentEntity,
|
|
1043
|
+
entityId: option.modiParentId,
|
|
1044
|
+
action: action,
|
|
1045
|
+
data: data,
|
|
1046
|
+
iState: 'active',
|
|
1047
|
+
filter: filter,
|
|
1048
|
+
},
|
|
1026
1049
|
};
|
|
1050
|
+
if (!(ids_1.length > 0)) return [3 /*break*/, 29];
|
|
1051
|
+
_d = modiUpsert.data;
|
|
1027
1052
|
_l = {
|
|
1028
|
-
id: operId,
|
|
1029
|
-
targetEntity: entity,
|
|
1030
|
-
entity: option.modiParentEntity,
|
|
1031
|
-
entityId: option.modiParentId,
|
|
1032
|
-
action: action,
|
|
1033
|
-
data: data,
|
|
1034
|
-
iState: 'active',
|
|
1035
|
-
filter: filter
|
|
1036
|
-
};
|
|
1037
|
-
_m = {
|
|
1038
1053
|
id: 'dummy',
|
|
1039
1054
|
action: 'create'
|
|
1040
1055
|
};
|
|
@@ -1053,14 +1068,12 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1053
1068
|
});
|
|
1054
1069
|
}); }))];
|
|
1055
1070
|
case 28:
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
_k);
|
|
1060
|
-
_o.label = 29;
|
|
1071
|
+
_d.modiEntity$modi = (_l.data = _m.sent(),
|
|
1072
|
+
_l);
|
|
1073
|
+
_m.label = 29;
|
|
1061
1074
|
case 29: return [4 /*yield*/, this.cascadeUpdateAsync('modi', modiUpsert, context, option)];
|
|
1062
1075
|
case 30:
|
|
1063
|
-
|
|
1076
|
+
_m.sent();
|
|
1064
1077
|
return [2 /*return*/, 1];
|
|
1065
1078
|
case 31:
|
|
1066
1079
|
createOper = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
@@ -1155,15 +1168,15 @@ var CascadeStore = /** @class */ (function (_super) {
|
|
|
1155
1168
|
return [4 /*yield*/, createOper()];
|
|
1156
1169
|
case 34:
|
|
1157
1170
|
// 如果不是update动作而是用户自定义的动作,这里还是要记录oper
|
|
1158
|
-
|
|
1171
|
+
_m.sent();
|
|
1159
1172
|
return [2 /*return*/, 0];
|
|
1160
1173
|
case 35: return [2 /*return*/, 0];
|
|
1161
1174
|
case 36: return [4 /*yield*/, this.updateAbjointRowAsync(entity, operation, context, option)];
|
|
1162
1175
|
case 37:
|
|
1163
|
-
result =
|
|
1176
|
+
result = _m.sent();
|
|
1164
1177
|
return [4 /*yield*/, createOper()];
|
|
1165
1178
|
case 38:
|
|
1166
|
-
|
|
1179
|
+
_m.sent();
|
|
1167
1180
|
return [2 /*return*/, result];
|
|
1168
1181
|
}
|
|
1169
1182
|
});
|
package/lib/store/checker.d.ts
CHANGED
|
@@ -23,4 +23,4 @@ export declare function createAuthCheckers<ED extends EntityDict & BaseEntityDic
|
|
|
23
23
|
* @returns
|
|
24
24
|
* 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
|
|
25
25
|
*/
|
|
26
|
-
export declare function createRemoveCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): Checker<ED, keyof ED, Cxt>[];
|
|
26
|
+
export declare function createRemoveCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict?: AuthDefDict<ED>): Checker<ED, keyof ED, Cxt>[];
|
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;
|
|
@@ -406,12 +408,12 @@ function createAuthCheckers(schema, authDict) {
|
|
|
406
408
|
var _b = authDict[entity], relationAuth = _b.relationAuth, actionAuth = _b.actionAuth;
|
|
407
409
|
if (relationAuth) {
|
|
408
410
|
var raFilterMakerDict_1 = {};
|
|
411
|
+
var userEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
409
412
|
for (var r in relationAuth) {
|
|
410
413
|
Object.assign(raFilterMakerDict_1, (_a = {},
|
|
411
414
|
_a[r] = translateActionAuthFilterMaker(schema, relationAuth[r], entity),
|
|
412
415
|
_a));
|
|
413
416
|
}
|
|
414
|
-
var userEntityName_1 = "user".concat((0, string_1.firstLetterUpperCase)(entity));
|
|
415
417
|
var entityIdAttr_1 = "".concat(entity, "Id");
|
|
416
418
|
checkers.push({
|
|
417
419
|
entity: userEntityName_1,
|
|
@@ -508,7 +510,7 @@ exports.createAuthCheckers = createAuthCheckers;
|
|
|
508
510
|
* @returns
|
|
509
511
|
* 如果有的对象允许删除,需要使用trigger来处理其相关联的外键对象,这些trigger写作before,则会在checker之前执行,仍然可以删除成功
|
|
510
512
|
*/
|
|
511
|
-
function createRemoveCheckers(schema) {
|
|
513
|
+
function createRemoveCheckers(schema, authDict) {
|
|
512
514
|
var e_1, _a;
|
|
513
515
|
var checkers = [];
|
|
514
516
|
// 先建立所有的一对多的关系
|
|
@@ -575,7 +577,7 @@ function createRemoveCheckers(schema) {
|
|
|
575
577
|
var e_3, _a, e_4, _b;
|
|
576
578
|
var promises = [];
|
|
577
579
|
if (OneToManyMatrix[entity]) {
|
|
578
|
-
var
|
|
580
|
+
var _loop_5 = function (otm) {
|
|
579
581
|
var _g, _h, _j, _k;
|
|
580
582
|
var _l = tslib_1.__read(otm, 2), e = _l[0], attr = _l[1];
|
|
581
583
|
var proj = (_g = {
|
|
@@ -627,7 +629,7 @@ function createRemoveCheckers(schema) {
|
|
|
627
629
|
try {
|
|
628
630
|
for (var _c = (e_3 = void 0, tslib_1.__values(OneToManyMatrix[entity])), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
629
631
|
var otm = _d.value;
|
|
630
|
-
|
|
632
|
+
_loop_5(otm);
|
|
631
633
|
}
|
|
632
634
|
}
|
|
633
635
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
@@ -639,7 +641,7 @@ function createRemoveCheckers(schema) {
|
|
|
639
641
|
}
|
|
640
642
|
}
|
|
641
643
|
if (OneToManyOnEntityMatrix[entity]) {
|
|
642
|
-
var
|
|
644
|
+
var _loop_6 = function (otm) {
|
|
643
645
|
var _o, _p, _q;
|
|
644
646
|
var proj = {
|
|
645
647
|
id: 1,
|
|
@@ -690,7 +692,7 @@ function createRemoveCheckers(schema) {
|
|
|
690
692
|
try {
|
|
691
693
|
for (var _e = (e_4 = void 0, tslib_1.__values(OneToManyOnEntityMatrix[entity])), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
692
694
|
var otm = _f.value;
|
|
693
|
-
|
|
695
|
+
_loop_6(otm);
|
|
694
696
|
}
|
|
695
697
|
}
|
|
696
698
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -720,6 +722,146 @@ function createRemoveCheckers(schema) {
|
|
|
720
722
|
}
|
|
721
723
|
finally { if (e_1) throw e_1.error; }
|
|
722
724
|
}
|
|
725
|
+
var _loop_4 = function (entity) {
|
|
726
|
+
var e_5, _b;
|
|
727
|
+
var cascadeRemove = authDict[entity].cascadeRemove;
|
|
728
|
+
if (cascadeRemove) {
|
|
729
|
+
var entitiesOnEntityAttr = [];
|
|
730
|
+
var hasAllEntity = false;
|
|
731
|
+
var _loop_7 = function (attr) {
|
|
732
|
+
if (attr === '@entity') {
|
|
733
|
+
hasAllEntity = true;
|
|
734
|
+
return "continue";
|
|
735
|
+
}
|
|
736
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
737
|
+
if (rel === 2) {
|
|
738
|
+
entitiesOnEntityAttr.push(attr);
|
|
739
|
+
checkers.push({
|
|
740
|
+
entity: attr,
|
|
741
|
+
action: 'remove',
|
|
742
|
+
type: 'logical',
|
|
743
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
744
|
+
checker: function (operation, context) {
|
|
745
|
+
var _a, _b;
|
|
746
|
+
var filter = operation.filter;
|
|
747
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
748
|
+
return context.operate(entity, {
|
|
749
|
+
id: (0, uuid_1.generateNewId)(),
|
|
750
|
+
action: 'remove',
|
|
751
|
+
data: {},
|
|
752
|
+
filter: filter ? (_a = {},
|
|
753
|
+
_a[attr] = filter,
|
|
754
|
+
_a) : undefined,
|
|
755
|
+
}, { dontCollect: true });
|
|
756
|
+
}
|
|
757
|
+
return context.operate(entity, {
|
|
758
|
+
id: (0, uuid_1.generateNewId)(),
|
|
759
|
+
action: 'update',
|
|
760
|
+
data: {
|
|
761
|
+
entity: null,
|
|
762
|
+
entityId: null,
|
|
763
|
+
},
|
|
764
|
+
filter: filter ? (_b = {},
|
|
765
|
+
_b[attr] = filter,
|
|
766
|
+
_b) : undefined,
|
|
767
|
+
}, { dontCollect: true });
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
(0, assert_1.default)(typeof rel === 'string');
|
|
773
|
+
checkers.push({
|
|
774
|
+
entity: rel,
|
|
775
|
+
action: 'remove',
|
|
776
|
+
type: 'logical',
|
|
777
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
778
|
+
checker: function (operation, context) {
|
|
779
|
+
var _a, _b, _c;
|
|
780
|
+
var filter = operation.filter;
|
|
781
|
+
if (cascadeRemove[attr] === 'remove') {
|
|
782
|
+
return context.operate(entity, {
|
|
783
|
+
id: (0, uuid_1.generateNewId)(),
|
|
784
|
+
action: 'remove',
|
|
785
|
+
data: {},
|
|
786
|
+
filter: filter ? (_a = {},
|
|
787
|
+
_a[attr] = filter,
|
|
788
|
+
_a) : undefined,
|
|
789
|
+
}, { dontCollect: true });
|
|
790
|
+
}
|
|
791
|
+
return context.operate(entity, {
|
|
792
|
+
id: (0, uuid_1.generateNewId)(),
|
|
793
|
+
action: 'update',
|
|
794
|
+
data: (_b = {},
|
|
795
|
+
_b["".concat(attr, "Id")] = null,
|
|
796
|
+
_b),
|
|
797
|
+
filter: filter ? (_c = {},
|
|
798
|
+
_c[attr] = filter,
|
|
799
|
+
_c) : undefined,
|
|
800
|
+
}, { dontCollect: true });
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
for (var attr in cascadeRemove) {
|
|
806
|
+
_loop_7(attr);
|
|
807
|
+
}
|
|
808
|
+
if (hasAllEntity) {
|
|
809
|
+
var attributes = schema[entity].attributes;
|
|
810
|
+
var ref = attributes.entity.ref;
|
|
811
|
+
var restEntities = (0, lodash_1.difference)(ref, entitiesOnEntityAttr);
|
|
812
|
+
var _loop_8 = function (e) {
|
|
813
|
+
checkers.push({
|
|
814
|
+
entity: e,
|
|
815
|
+
action: 'remove',
|
|
816
|
+
type: 'logical',
|
|
817
|
+
priority: types_1.REMOVE_CASCADE_PRIORITY,
|
|
818
|
+
checker: function (operation, context) {
|
|
819
|
+
var _a, _b;
|
|
820
|
+
var filter = operation.filter;
|
|
821
|
+
if (cascadeRemove['@entity'] === 'remove') {
|
|
822
|
+
return context.operate(entity, {
|
|
823
|
+
id: (0, uuid_1.generateNewId)(),
|
|
824
|
+
action: 'remove',
|
|
825
|
+
data: {},
|
|
826
|
+
filter: filter ? (_a = {},
|
|
827
|
+
_a[e] = filter,
|
|
828
|
+
_a) : undefined,
|
|
829
|
+
}, { dontCollect: true });
|
|
830
|
+
}
|
|
831
|
+
return context.operate(entity, {
|
|
832
|
+
id: (0, uuid_1.generateNewId)(),
|
|
833
|
+
action: 'update',
|
|
834
|
+
data: {
|
|
835
|
+
entity: null,
|
|
836
|
+
entityId: null,
|
|
837
|
+
},
|
|
838
|
+
filter: filter ? (_b = {},
|
|
839
|
+
_b[e] = filter,
|
|
840
|
+
_b) : undefined,
|
|
841
|
+
}, { dontCollect: true });
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
};
|
|
845
|
+
try {
|
|
846
|
+
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()) {
|
|
847
|
+
var e = restEntities_1_1.value;
|
|
848
|
+
_loop_8(e);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
852
|
+
finally {
|
|
853
|
+
try {
|
|
854
|
+
if (restEntities_1_1 && !restEntities_1_1.done && (_b = restEntities_1.return)) _b.call(restEntities_1);
|
|
855
|
+
}
|
|
856
|
+
finally { if (e_5) throw e_5.error; }
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
// 注入声明的cascade删除时的外键处理动作
|
|
862
|
+
for (var entity in authDict) {
|
|
863
|
+
_loop_4(entity);
|
|
864
|
+
}
|
|
723
865
|
return checkers;
|
|
724
866
|
}
|
|
725
867
|
exports.createRemoveCheckers = createRemoveCheckers;
|
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[T]['OpSchema'] | '@entity']?: ActionOnRemove;
|
|
65
|
+
};
|
|
63
66
|
};
|
|
64
67
|
export declare type AuthDefDict<ED extends EntityDict> = {
|
|
65
68
|
[K in keyof ED]?: AuthDef<ED, K>;
|