oak-domain 3.0.2 → 3.0.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.
@@ -24,13 +24,12 @@ var CascadeStore = /** @class */ (function (_super) {
24
24
  }
25
25
  CascadeStore.prototype.reinforceSelectionAsync = function (entity, selection, context, option) {
26
26
  return tslib_1.__awaiter(this, void 0, void 0, function () {
27
- var noRelationDestEntities, rewriterPromises;
27
+ var rewriterPromises;
28
28
  var _this = this;
29
29
  return tslib_1.__generator(this, function (_a) {
30
30
  switch (_a.label) {
31
31
  case 0:
32
- noRelationDestEntities = [];
33
- this.reinforceSelectionInner(entity, selection, context, noRelationDestEntities);
32
+ this.reinforceSelectionInner(entity, selection, context);
34
33
  rewriterPromises = this.selectionRewriters.map(function (ele) { return ele(_this.getSchema(), entity, selection, context); });
35
34
  if (!(rewriterPromises.length > 0)) return [3 /*break*/, 2];
36
35
  return [4 /*yield*/, Promise.all(rewriterPromises)];
@@ -44,13 +43,16 @@ var CascadeStore = /** @class */ (function (_super) {
44
43
  };
45
44
  CascadeStore.prototype.reinforceSelectionSync = function (entity, selection, context, option) {
46
45
  var _this = this;
47
- this.reinforceSelectionInner(entity, selection, context, []);
48
- var rewriterPromises = this.selectionRewriters.map(function (ele) { return ele(_this.getSchema(), entity, selection, context); });
46
+ this.reinforceSelectionInner(entity, selection, context);
47
+ this.selectionRewriters.forEach(function (ele) {
48
+ var result = ele(_this.getSchema(), entity, selection, context);
49
+ (0, assert_1.default)(!(result instanceof Promise));
50
+ });
49
51
  };
50
- CascadeStore.prototype.reinforceSelectionInner = function (entity, selection, context, noRelationDestEntities) {
52
+ CascadeStore.prototype.reinforceSelectionInner = function (entity, selection, context) {
51
53
  var _this = this;
52
54
  var filter = selection.filter, data = selection.data, sorter = selection.sorter;
53
- var checkNode = function (projectionNode, attrs) {
55
+ var assignNecessaryProjectionAttrs = function (projectionNode, attrs) {
54
56
  attrs.forEach(function (attr) {
55
57
  var _a;
56
58
  if (!projectionNode.hasOwnProperty(attr)) {
@@ -60,108 +62,108 @@ var CascadeStore = /** @class */ (function (_super) {
60
62
  }
61
63
  });
62
64
  };
63
- var relevantIds = [];
64
- if (filter) {
65
- var toBeAssignNode_1 = {}; // 用来记录在表达式中涉及到的结点
66
- // filter当中所关联到的属性必须在projection中
67
- var filterNodeDict_1 = {};
68
- var checkFilterNode_1 = function (entity2, filterNode, projectionNode) {
69
- var _a, e_1, _b, _c, _d, _e, _f;
70
- var necessaryAttrs = ['id'];
71
- for (var attr in filterNode) {
72
- if (attr === '#id') {
73
- (0, assert_1.default)(!filterNodeDict_1[filterNode[attr]], "projection\u4E2D\u7ED3\u70B9\u7684id\u6709\u91CD\u590D, ".concat(filterNode[attr]));
74
- Object.assign(filterNodeDict_1, (_a = {},
75
- _a[filterNode[attr]] = projectionNode,
76
- _a));
77
- if (toBeAssignNode_1[filterNode[attr]]) {
78
- checkNode(projectionNode, toBeAssignNode_1[filterNode[attr]]);
65
+ var checkFilterNode = function (entity2, filterNode, projectionNode, toBeAssignNode, filterNodeDict) {
66
+ var _a, e_1, _b, _c, _d, _e, _f;
67
+ var necessaryAttrs = ['id'];
68
+ for (var attr in filterNode) {
69
+ if (attr === '#id') {
70
+ (0, assert_1.default)(!filterNodeDict[filterNode[attr]], "projection\u4E2D\u7ED3\u70B9\u7684id\u6709\u91CD\u590D, ".concat(filterNode[attr]));
71
+ Object.assign(filterNodeDict, (_a = {},
72
+ _a[filterNode[attr]] = projectionNode,
73
+ _a));
74
+ if (toBeAssignNode[filterNode[attr]]) {
75
+ assignNecessaryProjectionAttrs(projectionNode, toBeAssignNode[filterNode[attr]]);
76
+ }
77
+ }
78
+ else if (['$and', '$or'].includes(attr)) {
79
+ try {
80
+ for (var _g = (e_1 = void 0, tslib_1.__values(filterNode[attr])), _h = _g.next(); !_h.done; _h = _g.next()) {
81
+ var node = _h.value;
82
+ checkFilterNode(entity2, node, projectionNode, toBeAssignNode, filterNodeDict);
79
83
  }
80
84
  }
81
- else if (['$and', '$or'].includes(attr)) {
85
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
86
+ finally {
82
87
  try {
83
- for (var _g = (e_1 = void 0, tslib_1.__values(filterNode[attr])), _h = _g.next(); !_h.done; _h = _g.next()) {
84
- var node = _h.value;
85
- checkFilterNode_1(entity2, node, projectionNode);
86
- }
87
- }
88
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
89
- finally {
90
- try {
91
- if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
92
- }
93
- finally { if (e_1) throw e_1.error; }
88
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
94
89
  }
90
+ finally { if (e_1) throw e_1.error; }
95
91
  }
96
- else if (attr === '$not') {
97
- checkFilterNode_1(entity2, filterNode[attr], projectionNode);
98
- }
99
- else if (attr === '$text') {
100
- // 全文检索首先要有fulltext索引,其次要把fulltext的相关属性加到projection里
101
- var indexes = _this.getSchema()[entity2].indexes;
102
- var fulltextIndex = indexes.find(function (ele) { return ele.config && ele.config.type === 'fulltext'; });
103
- var attributes = fulltextIndex.attributes;
104
- necessaryAttrs.push.apply(necessaryAttrs, tslib_1.__spreadArray([], tslib_1.__read((attributes.map(function (ele) { return ele.name; }))), false));
105
- }
106
- else {
107
- if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
108
- var exprResult = (0, types_1.getAttrRefInExpression)(filterNode[attr]);
109
- for (var nodeName in exprResult) {
110
- if (nodeName === '#current') {
111
- checkNode(projectionNode, exprResult[nodeName]);
112
- }
113
- else if (filterNodeDict_1[nodeName]) {
114
- checkNode(filterNodeDict_1[nodeName], exprResult[nodeName]);
92
+ }
93
+ else if (attr === '$not') {
94
+ checkFilterNode(entity2, filterNode[attr], projectionNode, toBeAssignNode, filterNodeDict);
95
+ }
96
+ else if (attr === '$text') {
97
+ // 全文检索首先要有fulltext索引,其次要把fulltext的相关属性加到projection里
98
+ var indexes = _this.getSchema()[entity2].indexes;
99
+ var fulltextIndex = indexes.find(function (ele) { return ele.config && ele.config.type === 'fulltext'; });
100
+ var attributes = fulltextIndex.attributes;
101
+ necessaryAttrs.push.apply(necessaryAttrs, tslib_1.__spreadArray([], tslib_1.__read((attributes.map(function (ele) { return ele.name; }))), false));
102
+ }
103
+ else {
104
+ if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
105
+ var exprResult = (0, types_1.getAttrRefInExpression)(filterNode[attr]);
106
+ for (var nodeName in exprResult) {
107
+ if (nodeName === '#current') {
108
+ assignNecessaryProjectionAttrs(projectionNode, exprResult[nodeName]);
109
+ }
110
+ else if (filterNodeDict[nodeName]) {
111
+ assignNecessaryProjectionAttrs(filterNodeDict[nodeName], exprResult[nodeName]);
112
+ }
113
+ else {
114
+ if (toBeAssignNode[nodeName]) {
115
+ (_c = toBeAssignNode[nodeName]).push.apply(_c, tslib_1.__spreadArray([], tslib_1.__read(exprResult[nodeName]), false));
115
116
  }
116
117
  else {
117
- if (toBeAssignNode_1[nodeName]) {
118
- (_c = toBeAssignNode_1[nodeName]).push.apply(_c, tslib_1.__spreadArray([], tslib_1.__read(exprResult[nodeName]), false));
119
- }
120
- else {
121
- Object.assign(toBeAssignNode_1, (_d = {},
122
- _d[nodeName] = exprResult[nodeName],
123
- _d));
124
- }
118
+ Object.assign(toBeAssignNode, (_d = {},
119
+ _d[nodeName] = exprResult[nodeName],
120
+ _d));
125
121
  }
126
122
  }
127
123
  }
128
- else {
129
- var rel = _this.judgeRelation(entity2, attr);
130
- if (rel === 1) {
131
- necessaryAttrs.push(attr);
132
- }
133
- else if (rel === 2) {
134
- // entity/entityId反指
135
- necessaryAttrs.push('entity', 'entityId');
136
- if (!projectionNode[attr]) {
137
- Object.assign(projectionNode, (_e = {},
138
- _e[attr] = {
139
- id: 1,
140
- },
141
- _e));
142
- }
143
- checkFilterNode_1(attr, filterNode[attr], projectionNode[attr]);
144
- }
145
- else if (typeof rel === 'string') {
146
- necessaryAttrs.push("".concat(attr, "Id"));
147
- if (!projectionNode[attr]) {
148
- Object.assign(projectionNode, (_f = {},
149
- _f[attr] = {
150
- id: 1,
151
- },
152
- _f));
153
- }
154
- checkFilterNode_1(rel, filterNode[attr], projectionNode[attr]);
124
+ }
125
+ else {
126
+ var rel = _this.judgeRelation(entity2, attr);
127
+ if (rel === 1) {
128
+ necessaryAttrs.push(attr);
129
+ }
130
+ else if (rel === 2) {
131
+ // entity/entityId反指
132
+ necessaryAttrs.push('entity', 'entityId');
133
+ if (!projectionNode[attr]) {
134
+ Object.assign(projectionNode, (_e = {},
135
+ _e[attr] = {
136
+ id: 1,
137
+ },
138
+ _e));
155
139
  }
156
- else if (rel instanceof Array) {
157
- // 现在filter中还不支持一对多的语义,先放着吧
140
+ checkFilterNode(attr, filterNode[attr], projectionNode[attr], toBeAssignNode, filterNodeDict);
141
+ }
142
+ else if (typeof rel === 'string') {
143
+ necessaryAttrs.push("".concat(attr, "Id"));
144
+ if (!projectionNode[attr]) {
145
+ Object.assign(projectionNode, (_f = {},
146
+ _f[attr] = {
147
+ id: 1,
148
+ },
149
+ _f));
158
150
  }
151
+ checkFilterNode(rel, filterNode[attr], projectionNode[attr], toBeAssignNode, filterNodeDict);
152
+ }
153
+ else if (rel instanceof Array) {
154
+ // 子查询,暂时不处理
159
155
  }
160
156
  }
161
- checkNode(projectionNode, necessaryAttrs);
162
157
  }
163
- };
164
- checkFilterNode_1(entity, filter, data);
158
+ assignNecessaryProjectionAttrs(projectionNode, necessaryAttrs);
159
+ }
160
+ };
161
+ var relevantIds = [];
162
+ if (filter) {
163
+ var toBeAssignNode = {}; // 用来记录在表达式中涉及到的结点
164
+ // filter当中所关联到的属性必须在projection中
165
+ var filterNodeDict = {};
166
+ checkFilterNode(entity, filter, data, toBeAssignNode, filterNodeDict);
165
167
  relevantIds = (0, filter_2.getRelevantIds)(filter);
166
168
  }
167
169
  // sorter感觉现在取不取影响不大,前端的list直接获取返回的ids了,先不管之
@@ -179,7 +181,7 @@ var CascadeStore = /** @class */ (function (_super) {
179
181
  _a[projectionNode[attr]] = projectionNode,
180
182
  _a));
181
183
  if (toBeAssignNode2[projectionNode[attr]]) {
182
- checkNode(projectionNode, toBeAssignNode2[projectionNode[attr]]);
184
+ assignNecessaryProjectionAttrs(projectionNode, toBeAssignNode2[projectionNode[attr]]);
183
185
  }
184
186
  }
185
187
  else {
@@ -187,10 +189,10 @@ var CascadeStore = /** @class */ (function (_super) {
187
189
  var exprResult = (0, types_1.getAttrRefInExpression)(projectionNode[attr]);
188
190
  for (var nodeName in exprResult) {
189
191
  if (nodeName === '#current') {
190
- checkNode(projectionNode, exprResult[nodeName]);
192
+ assignNecessaryProjectionAttrs(projectionNode, exprResult[nodeName]);
191
193
  }
192
194
  else if (projectionNodeDict[nodeName]) {
193
- checkNode(projectionNodeDict[nodeName], exprResult[nodeName]);
195
+ assignNecessaryProjectionAttrs(projectionNodeDict[nodeName], exprResult[nodeName]);
194
196
  }
195
197
  else {
196
198
  if (toBeAssignNode2[nodeName]) {
@@ -219,18 +221,18 @@ var CascadeStore = /** @class */ (function (_super) {
219
221
  checkProjectionNode(rel, projectionNode[attr]);
220
222
  }
221
223
  else if (rel instanceof Array && !attr.endsWith('$$aggr')) {
222
- var data_1 = projectionNode[attr].data;
224
+ var _d = projectionNode[attr], data_1 = _d.data, filter_3 = _d.filter;
223
225
  if (rel[1]) {
224
- checkNode(data_1, [rel[1]]);
226
+ assignNecessaryProjectionAttrs(data_1, [rel[1]]);
225
227
  }
226
228
  else {
227
- checkNode(data_1, ['entity', 'entityId']);
229
+ assignNecessaryProjectionAttrs(data_1, ['entity', 'entityId']);
228
230
  }
229
- _this.reinforceSelectionInner(rel[0], projectionNode[attr], context, noRelationDestEntities);
231
+ _this.reinforceSelectionInner(rel[0], projectionNode[attr], context);
230
232
  }
231
233
  }
232
234
  }
233
- checkNode(projectionNode, necessaryAttrs);
235
+ assignNecessaryProjectionAttrs(projectionNode, necessaryAttrs);
234
236
  }
235
237
  // 如果对象中指向一对多的Modi,此时加上指向Modi的projection
236
238
  if (_this.getSchema()[entity2].toModi) {
@@ -281,7 +283,6 @@ var CascadeStore = /** @class */ (function (_super) {
281
283
  },
282
284
  });
283
285
  }
284
- noRelationDestEntities.push(entity2);
285
286
  }
286
287
  }
287
288
  };
@@ -1160,12 +1160,12 @@ var RelationAuth = /** @class */ (function () {
1160
1160
  if (result instanceof Promise) {
1161
1161
  return result.then(function (r) {
1162
1162
  if (!r) {
1163
- throw new types_1.OakUserUnpermittedException();
1163
+ throw new types_1.OakUserInvisibleException();
1164
1164
  }
1165
1165
  });
1166
1166
  }
1167
1167
  if (!result) {
1168
- throw new types_1.OakUserUnpermittedException();
1168
+ throw new types_1.OakUserInvisibleException();
1169
1169
  }
1170
1170
  }
1171
1171
  else {
@@ -228,7 +228,7 @@ function makeIntrinsicCTWs(schema, actionDefDict) {
228
228
  return Promise.all(checkResult).then(function () { return undefined; });
229
229
  }
230
230
  }
231
- else {
231
+ else if (data) {
232
232
  return checkUnique(entity, data, context, uniqAttrs_2);
233
233
  }
234
234
  }
@@ -240,84 +240,86 @@ function makeIntrinsicCTWs(schema, actionDefDict) {
240
240
  checker: function (operation, context) {
241
241
  var e_4, _a, e_5, _b, _c;
242
242
  var _d = operation, data = _d.data, operationFilter = _d.filter;
243
- var attrs = Object.keys(data);
244
- var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
245
- if (refAttrs.length === 0) {
246
- // 如果本次更新和unique约束的属性之间没有交集则直接返回
247
- return;
248
- }
249
- try {
250
- for (var refAttrs_1 = (e_4 = void 0, tslib_1.__values(refAttrs)), refAttrs_1_1 = refAttrs_1.next(); !refAttrs_1_1.done; refAttrs_1_1 = refAttrs_1.next()) {
251
- var attr = refAttrs_1_1.value;
252
- // 如果有更新为null值,不用再检查约束
253
- if (data[attr] === null || data[attr] === undefined) {
254
- return;
255
- }
243
+ if (data) {
244
+ var attrs = Object.keys(data);
245
+ var refAttrs = (0, lodash_1.intersection)(attrs, uniqAttrs_2);
246
+ if (refAttrs.length === 0) {
247
+ // 如果本次更新和unique约束的属性之间没有交集则直接返回
248
+ return;
256
249
  }
257
- }
258
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
259
- finally {
260
250
  try {
261
- if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
251
+ for (var refAttrs_1 = (e_4 = void 0, tslib_1.__values(refAttrs)), refAttrs_1_1 = refAttrs_1.next(); !refAttrs_1_1.done; refAttrs_1_1 = refAttrs_1.next()) {
252
+ var attr = refAttrs_1_1.value;
253
+ // 如果有更新为null值,不用再检查约束
254
+ if (data[attr] === null || data[attr] === undefined) {
255
+ return;
256
+ }
257
+ }
262
258
  }
263
- finally { if (e_4) throw e_4.error; }
264
- }
265
- if (refAttrs.length === uniqAttrs_2.length) {
266
- // 如果更新了全部属性,直接检查
267
- var filter = (0, lodash_1.pick)(data, refAttrs);
268
- // 在这些行以外的行不和更新后的键值冲突
269
- var count = context.count(entity, {
270
- filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
271
- $not: operationFilter,
272
- }]),
273
- }, { dontCollect: true });
274
- var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
275
- // 更新的行只能有一行
276
- var rowCount = context.count(entity, {
277
- filter: operationFilter,
278
- }, { dontCollect: true });
279
- var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
280
- // 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
281
- if (checkRowCount instanceof Promise) {
282
- return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
259
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
260
+ finally {
261
+ try {
262
+ if (refAttrs_1_1 && !refAttrs_1_1.done && (_a = refAttrs_1.return)) _a.call(refAttrs_1);
263
+ }
264
+ finally { if (e_4) throw e_4.error; }
283
265
  }
284
- }
285
- // 否则需要结合本行现有的属性来进行检查
286
- var projection = { id: 1 };
287
- try {
288
- for (var uniqAttrs_3 = (e_5 = void 0, tslib_1.__values(uniqAttrs_2)), uniqAttrs_3_1 = uniqAttrs_3.next(); !uniqAttrs_3_1.done; uniqAttrs_3_1 = uniqAttrs_3.next()) {
289
- var attr = uniqAttrs_3_1.value;
290
- Object.assign(projection, (_c = {},
291
- _c[attr] = 1,
292
- _c));
266
+ if (refAttrs.length === uniqAttrs_2.length) {
267
+ // 如果更新了全部属性,直接检查
268
+ var filter = (0, lodash_1.pick)(data, refAttrs);
269
+ // 在这些行以外的行不和更新后的键值冲突
270
+ var count = context.count(entity, {
271
+ filter: (0, filter_1.combineFilters)(entity, context.getSchema(), [filter, {
272
+ $not: operationFilter,
273
+ }]),
274
+ }, { dontCollect: true });
275
+ var checkCount = checkCountLessThan(count, uniqAttrs_2, 0, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
276
+ // 更新的行只能有一行
277
+ var rowCount = context.count(entity, {
278
+ filter: operationFilter,
279
+ }, { dontCollect: true });
280
+ var checkRowCount = checkCountLessThan(rowCount, uniqAttrs_2, 1, operationFilter === null || operationFilter === void 0 ? void 0 : operationFilter.id);
281
+ // 如果更新的行数为零似乎也可以,但这应该不可能出现吧,by Xc 20230131
282
+ if (checkRowCount instanceof Promise) {
283
+ return Promise.all([checkCount, checkRowCount]).then(function () { return undefined; });
284
+ }
293
285
  }
294
- }
295
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
296
- finally {
286
+ // 否则需要结合本行现有的属性来进行检查
287
+ var projection = { id: 1 };
297
288
  try {
298
- if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
289
+ for (var uniqAttrs_3 = (e_5 = void 0, tslib_1.__values(uniqAttrs_2)), uniqAttrs_3_1 = uniqAttrs_3.next(); !uniqAttrs_3_1.done; uniqAttrs_3_1 = uniqAttrs_3.next()) {
290
+ var attr = uniqAttrs_3_1.value;
291
+ Object.assign(projection, (_c = {},
292
+ _c[attr] = 1,
293
+ _c));
294
+ }
299
295
  }
300
- finally { if (e_5) throw e_5.error; }
301
- }
302
- var checkWithRows = function (rows2) {
303
- var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
304
- // 先检查这些行本身之间是否冲突
305
- checkUniqueBetweenRows(rows22, uniqAttrs_2);
306
- var checkResults = rows22.map(function (row) { return checkUnique(entity, row, context, uniqAttrs_2, {
307
- $not: operationFilter
308
- }); });
309
- if (checkResults[0] instanceof Promise) {
310
- return Promise.all(checkResults).then(function () { return undefined; });
296
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
297
+ finally {
298
+ try {
299
+ if (uniqAttrs_3_1 && !uniqAttrs_3_1.done && (_b = uniqAttrs_3.return)) _b.call(uniqAttrs_3);
300
+ }
301
+ finally { if (e_5) throw e_5.error; }
302
+ }
303
+ var checkWithRows_1 = function (rows2) {
304
+ var rows22 = rows2.map(function (ele) { return Object.assign(ele, data); });
305
+ // 先检查这些行本身之间是否冲突
306
+ checkUniqueBetweenRows(rows22, uniqAttrs_2);
307
+ var checkResults = rows22.map(function (row) { return checkUnique(entity, row, context, uniqAttrs_2, {
308
+ $not: operationFilter
309
+ }); });
310
+ if (checkResults[0] instanceof Promise) {
311
+ return Promise.all(checkResults).then(function () { return undefined; });
312
+ }
313
+ };
314
+ var currentRows = context.select(entity, {
315
+ data: projection,
316
+ filter: operationFilter,
317
+ }, { dontCollect: true });
318
+ if (currentRows instanceof Promise) {
319
+ return currentRows.then(function (row2) { return checkWithRows_1(row2); });
311
320
  }
312
- };
313
- var currentRows = context.select(entity, {
314
- data: projection,
315
- filter: operationFilter,
316
- }, { dontCollect: true });
317
- if (currentRows instanceof Promise) {
318
- return currentRows.then(function (row2) { return checkWithRows(row2); });
321
+ return checkWithRows_1(currentRows);
319
322
  }
320
- return checkWithRows(currentRows);
321
323
  }
322
324
  });
323
325
  }
@@ -1,4 +1,4 @@
1
- import { EntityDict } from "./Entity";
1
+ import { EntityDict, SubDataDef } from "./Entity";
2
2
  import { OpRecord } from "./Entity";
3
3
  import { AsyncContext } from "../store/AsyncRowStore";
4
4
  export interface Aspect<ED extends EntityDict, Cxt extends AsyncContext<ED>> {
@@ -10,4 +10,6 @@ export interface AspectWrapper<ED extends EntityDict, Cxt extends AsyncContext<E
10
10
  opRecords?: OpRecord<ED>[];
11
11
  message?: string | null;
12
12
  }>;
13
+ sub: (data: Array<SubDataDef<ED, keyof ED>>, callback: (records: OpRecord<ED>[], ids: string[]) => void) => Promise<void>;
14
+ unsub: (ids: string[]) => Promise<void>;
13
15
  }
@@ -24,6 +24,7 @@ export declare abstract class Connector<ED extends EntityDict, BackCxt extends A
24
24
  body: any;
25
25
  headers?: Record<string, any>;
26
26
  };
27
+ abstract getSubscribeRouter(): string;
27
28
  abstract getBridgeRouter(): string;
28
29
  abstract makeBridgeUrl(url: string, headers?: Record<string, string>): string;
29
30
  abstract parseBridgeRequestQuery(urlParams: string): {
@@ -190,4 +190,9 @@ export declare type AuthDeduceRelationMap<ED extends EntityDict> = {
190
190
  };
191
191
  export declare type SelectFreeEntities<ED extends EntityDict> = (keyof ED)[];
192
192
  export declare type OtmKey<K extends string> = K | `${K}$${number}`;
193
+ export interface SubDataDef<ED extends EntityDict, T extends keyof ED> {
194
+ id: string;
195
+ entity: T;
196
+ filter: ED[T]['Selection']['filter'];
197
+ }
193
198
  export {};
@@ -12,3 +12,4 @@ exports.initinctiveAttributes = [exports.PrimaryKeyAttribute, exports.TriggerDat
12
12
  ;
13
13
  ;
14
14
  ;
15
+ ;
@@ -75,6 +75,11 @@ export declare class OakAttrNotNullException<ED extends EntityDict> extends OakI
75
75
  */
76
76
  export declare class OakUserUnpermittedException<ED extends EntityDict> extends OakUserException<ED> {
77
77
  }
78
+ /**
79
+ * 用户查询权限不够抛出异常
80
+ */
81
+ export declare class OakUserInvisibleException<ED extends EntityDict> extends OakUserException<ED> {
82
+ }
78
83
  /**
79
84
  * 用户未登录抛的异常
80
85
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserUnpermittedException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakException = void 0;
3
+ exports.makeException = exports.OakPreConditionUnsetException = exports.OakDeadlock = exports.OakCongruentRowExists = exports.OakRowLockedException = exports.OakUnloggedInException = exports.OakUserInvisibleException = exports.OakUserUnpermittedException = exports.OakAttrNotNullException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakRowUnexistedException = exports.OakOperExistedException = exports.OakNoRelationDefException = exports.OakImportDataParseException = exports.OakUniqueViolationException = exports.OakDataException = exports.OakException = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  var OakException = /** @class */ (function (_super) {
@@ -219,6 +219,18 @@ var OakUserUnpermittedException = /** @class */ (function (_super) {
219
219
  }(OakUserException));
220
220
  exports.OakUserUnpermittedException = OakUserUnpermittedException;
221
221
  ;
222
+ /**
223
+ * 用户查询权限不够抛出异常
224
+ */
225
+ var OakUserInvisibleException = /** @class */ (function (_super) {
226
+ tslib_1.__extends(OakUserInvisibleException, _super);
227
+ function OakUserInvisibleException() {
228
+ return _super !== null && _super.apply(this, arguments) || this;
229
+ }
230
+ return OakUserInvisibleException;
231
+ }(OakUserException));
232
+ exports.OakUserInvisibleException = OakUserInvisibleException;
233
+ ;
222
234
  /**
223
235
  * 用户未登录抛的异常
224
236
  */
@@ -327,6 +339,11 @@ function makeException(data) {
327
339
  e.setOpRecords(data.opRecords);
328
340
  return e;
329
341
  }
342
+ case 'OakUserInvisibleException': {
343
+ var e = new OakUserInvisibleException(data.message);
344
+ e.setOpRecords(data.opRecords);
345
+ return e;
346
+ }
330
347
  case 'OakUnloggedInException': {
331
348
  var e = new OakUnloggedInException(data.message);
332
349
  e.setOpRecords(data.opRecords);
@@ -6,6 +6,7 @@ import { Connector, EntityDict, OakException } from "../types";
6
6
  export declare class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> extends Connector<ED, BackCxt, FrontCxt> {
7
7
  static ASPECT_ROUTER: string;
8
8
  static BRIDGE_ROUTER: string;
9
+ static SUBSCRIBE_ROUTER: string;
9
10
  private serverAspectUrl;
10
11
  private serverBridgeUrl;
11
12
  private makeException;
@@ -21,6 +22,7 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
21
22
  opRecords?: undefined;
22
23
  }>;
23
24
  getRouter(): string;
25
+ getSubscribeRouter(): string;
24
26
  parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{
25
27
  name: string;
26
28
  params: any;
@@ -86,6 +86,9 @@ var SimpleConnector = /** @class */ (function (_super) {
86
86
  SimpleConnector.prototype.getRouter = function () {
87
87
  return SimpleConnector.ASPECT_ROUTER;
88
88
  };
89
+ SimpleConnector.prototype.getSubscribeRouter = function () {
90
+ return SimpleConnector.SUBSCRIBE_ROUTER;
91
+ };
89
92
  SimpleConnector.prototype.parseRequest = function (headers, body, store) {
90
93
  return tslib_1.__awaiter(this, void 0, void 0, function () {
91
94
  var oakCxtStr, aspectName, context;
@@ -175,6 +178,7 @@ var SimpleConnector = /** @class */ (function (_super) {
175
178
  };
176
179
  SimpleConnector.ASPECT_ROUTER = '/aspect';
177
180
  SimpleConnector.BRIDGE_ROUTER = '/bridge';
181
+ SimpleConnector.SUBSCRIBE_ROUTER = '/subscribe';
178
182
  return SimpleConnector;
179
183
  }(types_1.Connector));
180
184
  exports.SimpleConnector = SimpleConnector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-domain",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "author": {
5
5
  "name": "XuChang"
6
6
  },