oak-domain 1.1.14 → 2.0.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.
Files changed (73) hide show
  1. package/lib/base-app-domain/Modi/Schema.d.ts +22 -22
  2. package/lib/base-app-domain/ModiEntity/Schema.d.ts +17 -17
  3. package/lib/base-app-domain/Oper/Schema.d.ts +17 -17
  4. package/lib/base-app-domain/OperEntity/Schema.d.ts +18 -18
  5. package/lib/base-app-domain/User/Schema.d.ts +15 -15
  6. package/lib/checkers/index.d.ts +4 -2
  7. package/lib/compiler/schemalBuilder.js +10 -10
  8. package/lib/store/AsyncRowStore.d.ts +45 -0
  9. package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
  10. package/lib/store/CascadeStore.d.ts +46 -20
  11. package/lib/store/CascadeStore.js +954 -995
  12. package/lib/store/SyncRowStore.d.ts +26 -0
  13. package/lib/store/SyncRowStore.js +45 -0
  14. package/lib/store/TriggerExecutor.d.ts +14 -14
  15. package/lib/store/TriggerExecutor.js +225 -238
  16. package/lib/store/actionDef.d.ts +5 -4
  17. package/lib/store/actionDef.js +44 -134
  18. package/lib/store/checker.d.ts +6 -0
  19. package/lib/store/checker.js +165 -0
  20. package/lib/store/filter.d.ts +30 -0
  21. package/lib/store/filter.js +571 -2
  22. package/lib/store/modi.d.ts +7 -6
  23. package/lib/store/modi.js +35 -46
  24. package/lib/store/relation.d.ts +1 -1
  25. package/lib/triggers/index.d.ts +4 -3
  26. package/lib/triggers/modi.d.ts +2 -2
  27. package/lib/triggers/modi.js +5 -5
  28. package/lib/types/AppLoader.d.ts +3 -3
  29. package/lib/types/Aspect.d.ts +3 -3
  30. package/lib/types/Auth.d.ts +25 -22
  31. package/lib/types/Connector.d.ts +7 -7
  32. package/lib/types/Context.d.ts +4 -14
  33. package/lib/types/Entity.d.ts +20 -15
  34. package/lib/types/Entity.js +9 -2
  35. package/lib/types/Exception.js +11 -11
  36. package/lib/types/RowStore.d.ts +2 -13
  37. package/lib/types/RowStore.js +1 -6
  38. package/lib/types/Trigger.d.ts +32 -48
  39. package/lib/types/Trigger.js +24 -9
  40. package/lib/types/Watcher.d.ts +7 -8
  41. package/lib/utils/SimpleConnector.d.ts +9 -8
  42. package/lib/utils/SimpleConnector.js +4 -5
  43. package/lib/utils/random/random.d.ts +1 -0
  44. package/lib/utils/random/random.js +24 -0
  45. package/lib/utils/random/random.mp.d.ts +1 -0
  46. package/lib/utils/random/random.mp.js +25 -0
  47. package/lib/utils/random/random.web.d.ts +1 -0
  48. package/lib/utils/random/random.web.js +17 -0
  49. package/lib/utils/string.d.ts +20 -0
  50. package/lib/utils/string.js +60 -1
  51. package/lib/utils/uuid.d.ts +10 -0
  52. package/lib/utils/uuid.js +172 -1
  53. package/lib/utils/validator.js +1 -1
  54. package/package.json +7 -4
  55. package/lib/OakError.d.ts +0 -7
  56. package/lib/OakError.js +0 -15
  57. package/lib/compiler/utils.d.ts +0 -2
  58. package/lib/compiler/utils.js +0 -11
  59. package/lib/entities/Action.d.ts +0 -12
  60. package/lib/entities/Action.js +0 -17
  61. package/lib/entities/Ooperation.d.ts +0 -12
  62. package/lib/entities/Ooperation.js +0 -17
  63. package/lib/entities/Update.d.ts +0 -9
  64. package/lib/entities/Update.js +0 -44
  65. package/lib/entities/Uupdate.d.ts +0 -9
  66. package/lib/entities/Uupdate.js +0 -44
  67. package/lib/store/UniversalContext.d.ts +0 -32
  68. package/lib/store/action.d.ts +0 -6
  69. package/lib/store/action.js +0 -14
  70. package/lib/store/projection.d.ts +0 -7
  71. package/lib/store/projection.js +0 -211
  72. package/lib/store/watchers.d.ts +0 -2
  73. package/lib/store/watchers.js +0 -32
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeTreeDescendantFilter = exports.makeTreeAncestorFilter = exports.same = exports.getRelevantIds = exports.repel = exports.contains = exports.combineFilters = exports.unionFilterSegment = exports.addFilterSegment = void 0;
3
+ exports.checkFilterContains = exports.makeTreeDescendantFilter = exports.makeTreeAncestorFilter = exports.same = exports.getRelevantIds = exports.repel = exports.contains = exports.judgeValueRelation = exports.combineFilters = exports.unionFilterSegment = exports.addFilterSegment = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var assert_1 = tslib_1.__importDefault(require("assert"));
6
+ var types_1 = require("../types");
6
7
  var lodash_1 = require("../utils/lodash");
8
+ var relation_1 = require("./relation");
7
9
  function addFilterSegment() {
8
10
  var filters = [];
9
11
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -96,6 +98,546 @@ function combineFilters(filters, union) {
96
98
  }
97
99
  exports.combineFilters = combineFilters;
98
100
  /**
101
+ * 判断value1表达的单个属性查询与同属性上value2表达的查询是包容还是相斥
102
+ * 相容即value1所表达的查询结果一定被value2表达的查询结果所包含,例如:
103
+ * value1: {
104
+ * $eq: 12
105
+ * }
106
+ * value2: {
107
+ * $gt: 8,
108
+ * }
109
+ * 此时value1相容value2
110
+ *
111
+ * 相斥即value1所表达的查询结果与value2一定毫无联系,例如:
112
+ * value1: {
113
+ * $gt: 8,
114
+ * }
115
+ * value2: {
116
+ * $lt: 2,
117
+ * }
118
+ *
119
+ *
120
+ * @param value1
121
+ * @param value2
122
+ * @attention: 1)这里的测试不够充分,有些算子之间的相容或相斥可能有遗漏, 2)有新的算子加入需要修改代码
123
+ */
124
+ function judgeValueRelation(value1, value2, contained) {
125
+ if (typeof value1 === 'object') {
126
+ var attr = Object.keys(value1)[0];
127
+ if (['$gt', '$lt', '$gte', '$lte', '$eq', '$ne', '$startsWith', '$endsWith', '$includes'].includes(attr)) {
128
+ switch (attr) {
129
+ case '$gt': {
130
+ if (contained) {
131
+ // 包容
132
+ if (typeof value2 === 'object') {
133
+ var attr2 = Object.keys(value2)[0];
134
+ return ['$gt', '$gte'].includes(attr2) && value2[attr2] <= value1.$gt;
135
+ }
136
+ return false;
137
+ }
138
+ // 互斥
139
+ if (typeof value2 === 'object') {
140
+ var attr2 = Object.keys(value2)[0];
141
+ return ['$lt', '$lte', '$eq'].includes(attr2) && value2[attr2] <= value1.$gt
142
+ || attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele > value1.$gt; }));
143
+ }
144
+ return value2 <= value1.$gt;
145
+ }
146
+ case '$gte': {
147
+ if (contained) {
148
+ // 包容
149
+ if (typeof value2 === 'object') {
150
+ var attr2 = Object.keys(value2)[0];
151
+ return ['$gte'].includes(attr2) && value2[attr2] <= value1.$gte
152
+ || ['$gt'].includes(attr2) && value2[attr2] < value1.$gte;
153
+ }
154
+ return false;
155
+ }
156
+ // 互斥
157
+ if (typeof value2 === 'object') {
158
+ var attr2 = Object.keys(value2)[0];
159
+ return ['$lt'].includes(attr2) && value2[attr2] <= value1.$gte
160
+ || ['$eq', '$lte'].includes(attr2) && value2[attr2] < value1.gte
161
+ || attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gte || ele >= value1.$gte; }));
162
+ }
163
+ return value2 < value1.$gte;
164
+ }
165
+ case '$lt': {
166
+ if (contained) {
167
+ // 相容
168
+ if (typeof value2 === 'object') {
169
+ var attr2 = Object.keys(value2)[0];
170
+ return ['$lt', '$lte'].includes(attr2) && value2[attr2] >= value1.$lt;
171
+ }
172
+ return false;
173
+ }
174
+ // 互斥
175
+ if (typeof value2 === 'object') {
176
+ var attr2 = Object.keys(value2)[0];
177
+ return ['$gt', '$gte', '$eq'].includes(attr2) && value2[attr2] >= value1.$lt
178
+ || attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele < value1.$lt; }));
179
+ }
180
+ return value2 >= value1.$gt;
181
+ }
182
+ case '$lte': {
183
+ if (contained) {
184
+ // 包容
185
+ if (typeof value2 === 'object') {
186
+ var attr2 = Object.keys(value2)[0];
187
+ return ['$lte'].includes(attr2) && value2[attr2] >= value1.$lte
188
+ || ['$lt'].includes(attr2) && value2[attr2] > value1.$lte;
189
+ }
190
+ return false;
191
+ }
192
+ // 互斥
193
+ if (typeof value2 === 'object') {
194
+ var attr2 = Object.keys(value2)[0];
195
+ return ['$gt'].includes(attr2) && value2[attr2] >= value1.$lte
196
+ || ['$eq', '$gte'].includes(attr2) && value2[attr2] > value1.lte
197
+ || attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$lte || ele <= value1.$lte; }));
198
+ }
199
+ return value2 > value1.$gte;
200
+ }
201
+ case '$eq': {
202
+ if (contained) {
203
+ // 相容
204
+ if (typeof value2 === 'object') {
205
+ var attr2 = Object.keys(value2)[0];
206
+ return attr2 === '$eq' && value2[attr2] === value1.$eq || attr2 === '$ne' && value2[attr2] !== value1.$eq
207
+ || attr2 === '$gt' && value2[attr2] < value1.$eq || attr2 === '$lt' && value2[attr2] > value1.$eq
208
+ || attr2 === '$gte' && value2[attr2] <= value1.$eq || attr2 === '$lte' && value2[attr2] >= value1.$eq
209
+ || attr2 === '$startsWith' && value1.$eq.startsWith(value2[attr2])
210
+ || attr2 === '$endsWith' && value1.$eq.endsWith(value2[attr2])
211
+ || attr2 === '$includes' && value1.$eq.includes(value2[attr2])
212
+ || attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1.$eq)
213
+ || attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
214
+ || attr2 === '$between' && value2[attr2][0] <= value1.$eq && value2[attr2][1] >= value1.$eq
215
+ || attr2 === '$exists' && value2[attr2] === true;
216
+ }
217
+ return value2 === value1.$eq;
218
+ }
219
+ // 互斥
220
+ if (typeof value2 === 'object') {
221
+ var attr2 = Object.keys(value2)[0];
222
+ return attr2 === '$eq' && value2[attr2] !== value1.$eq || attr2 === '$gt' && value2[attr2] >= value1.$eq
223
+ || attr2 === '$lt' && value2[attr2] <= value1.$eq
224
+ || attr2 === '$gte' && value2[attr2] > value1.$eq || attr2 === '$lte' && value2[attr2] < value1.$eq
225
+ || attr2 === '$startsWith' && !value1.$eq.startsWith(value2[attr2])
226
+ || attr2 === '$endsWith' && !value1.$eq.endsWith(value2[attr2])
227
+ || attr2 === '$includes' && !value1.$eq.includes(value2[attr2])
228
+ || attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
229
+ || attr2 === '$between' && (value2[attr2][0] > value1.$eq || value2[attr2][1] < value1.$eq)
230
+ || attr2 === '$exists' && value2[attr2] === false;
231
+ }
232
+ return value2 !== value1.$eq;
233
+ }
234
+ case '$ne': {
235
+ if (contained) {
236
+ // 相容
237
+ if (typeof value2 === 'object') {
238
+ var attr2 = Object.keys(value2)[0];
239
+ return attr2 === '$ne' && value2[attr2] === value1.$ne;
240
+ }
241
+ return false;
242
+ }
243
+ // 互斥
244
+ if (typeof value2 === 'object') {
245
+ var attr2 = Object.keys(value2)[0];
246
+ return attr2 === '$eq' && value2[attr2] === value1.$ne;
247
+ }
248
+ return value2 === value1.$ne;
249
+ }
250
+ case '$startsWith': {
251
+ if (contained) {
252
+ // 相容
253
+ if (typeof value2 === 'object') {
254
+ var attr2 = Object.keys(value2)[0];
255
+ return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
256
+ && value1.$startsWith.startsWith(value2[attr2]);
257
+ }
258
+ return typeof value2 === 'string' && value1.$startsWith.startsWith(value2);
259
+ }
260
+ // 互斥
261
+ if (typeof value2 === 'object') {
262
+ var attr2 = Object.keys(value2)[0];
263
+ return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
264
+ && !value1.$startsWith.startsWith(value2[attr2]) && !value2[attr2].startsWith(value1.$startsWith)
265
+ || attr2 === '$eq' && !value2[attr2].startsWith(value1.$startsWith);
266
+ }
267
+ return !value2.startsWith(value1.$startsWith);
268
+ }
269
+ case '$endsWith': {
270
+ if (contained) {
271
+ // 相容
272
+ if (typeof value2 === 'object') {
273
+ var attr2 = Object.keys(value2)[0];
274
+ return attr2 === '$endsWith' && typeof (value2[attr2]) === 'string'
275
+ && value1.$startsWith.endsWith(value2[attr2]);
276
+ }
277
+ return typeof value2 === 'string' && value1.$startsWith.endsWith(value2);
278
+ }
279
+ // 互斥
280
+ if (typeof value2 === 'object') {
281
+ var attr2 = Object.keys(value2)[0];
282
+ return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
283
+ && !value1.$startsWith.endsWith(value2[attr2]) && !value2[attr2].endsWith(value1.$startsWith)
284
+ || attr2 === '$eq' && !value2[attr2].endsWith(value1.$startsWith);
285
+ }
286
+ return !value2.endsWith(value1.$startsWith);
287
+ }
288
+ case '$includes': {
289
+ if (contained) {
290
+ // 相容
291
+ if (typeof value2 === 'object') {
292
+ var attr2 = Object.keys(value2)[0];
293
+ return ['$includes', '$startsWith', '$endsWith'].includes(attr2)
294
+ && typeof (value2[attr2]) === 'string'
295
+ && (value2[attr2]).includes(value1.$includes);
296
+ }
297
+ return typeof value2 === 'string' && value2.includes(value1.$includes);
298
+ }
299
+ // 互斥
300
+ if (typeof value2 === 'object') {
301
+ var attr2 = Object.keys(value2)[0];
302
+ return attr2 === '$eq' && !value2[attr2].includes(value1.$includes)
303
+ || attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].find(function (ele) { return ele.includes(value1.$includes); });
304
+ }
305
+ return typeof value2 === 'string' && !value2.includes(value1.$includes);
306
+ }
307
+ default: {
308
+ (0, assert_1.default)(false, "\u4E0D\u80FD\u5904\u7406\u7684\u7B97\u5B50\u300C".concat(attr, "\u300D"));
309
+ }
310
+ }
311
+ }
312
+ else if (['$exists'].includes(attr)) {
313
+ (0, assert_1.default)(attr === '$exists');
314
+ if (contained) {
315
+ if (typeof value2 === 'object') {
316
+ var attr2 = Object.keys(value2)[0];
317
+ return attr2 === '$exists' && value2[attr2] === value1.$exists;
318
+ }
319
+ return false;
320
+ }
321
+ return typeof value2 === 'object' && value2.$exists === !(value1.$exists);
322
+ }
323
+ else if (['$in', '$nin', '$between'].includes(attr)) {
324
+ switch (attr) {
325
+ case '$in': {
326
+ if (contained) {
327
+ // 相容
328
+ if (value1.$in instanceof Array) {
329
+ if (typeof value2 === 'object') {
330
+ var attr2 = Object.keys(value2)[0];
331
+ if (attr2 === '$in') {
332
+ return value2[attr2] instanceof Array && (0, lodash_1.difference)(value1.$in, value2[attr2]).length === 0;
333
+ }
334
+ else if (attr2 === '$nin') {
335
+ return value2[attr2] instanceof Array && (0, lodash_1.intersection)(value1.$in, value2[attr2]).length === 0;
336
+ }
337
+ else if (attr2 === '$exists') {
338
+ return value2[attr2] === true;
339
+ }
340
+ else if (['$gt', '$gte', '$lt', '$lte', '$between'].includes(attr2)) {
341
+ var min33_1, max33_1;
342
+ value1.$in.forEach(function (ele) {
343
+ if (!min33_1 || min33_1 > ele) {
344
+ min33_1 = ele;
345
+ }
346
+ if (!max33_1 || max33_1 < ele) {
347
+ max33_1 = ele;
348
+ }
349
+ });
350
+ return attr2 === '$gt' && value2[attr2] < min33_1 || attr2 === '$gte' && value2[attr2] <= min33_1
351
+ || attr2 === '$lt' && value2[attr2] > max33_1 || attr2 === '$lte' && value2[attr2] >= max33_1
352
+ || attr2 === '$between' && value2[attr2][0] < min33_1 && value2[attr2][1] > max33_1;
353
+ }
354
+ }
355
+ }
356
+ return false;
357
+ }
358
+ // 相斥
359
+ if (value1.$in instanceof Array) {
360
+ if (typeof value2 === 'object') {
361
+ var attr2 = Object.keys(value2)[0];
362
+ if (attr2 === '$in') {
363
+ return (0, lodash_1.intersection)(value2[attr2], value1.$in).length === 0;
364
+ }
365
+ else if (attr2 === '$eq') {
366
+ return !value1.$in.includes(value2[attr2]);
367
+ }
368
+ else if (attr2 === '$exists') {
369
+ return value2[attr2] === false;
370
+ }
371
+ else if (['$gt', '$gte', '$lt', '$lte', '$between'].includes(attr2)) {
372
+ var min44_1, max44_1;
373
+ value1.$in.forEach(function (ele) {
374
+ if (!min44_1 || min44_1 > ele) {
375
+ min44_1 = ele;
376
+ }
377
+ if (!max44_1 || max44_1 < ele) {
378
+ max44_1 = ele;
379
+ }
380
+ });
381
+ return attr2 === '$gt' && value2[attr2] >= max44_1 || attr2 === '$gte' && value2[attr2] > max44_1
382
+ || attr2 === '$lt' && value2[attr2] <= min44_1 || attr2 === '$lte' && value2[attr2] < min44_1
383
+ || attr2 === '$between' && (value2[attr2][0] > max44_1 || value2[attr2][1] < min44_1);
384
+ }
385
+ }
386
+ return !value1.$in.includes(value2);
387
+ }
388
+ return false;
389
+ }
390
+ case '$nin': {
391
+ if (contained) {
392
+ // 相容
393
+ if (value1.$nin instanceof Array) {
394
+ if (typeof value2 === 'object') {
395
+ var attr2 = Object.keys(value2)[0];
396
+ if (attr2 === '$nin') {
397
+ return value2[attr2] instanceof Array && (0, lodash_1.intersection)(value2[attr2], value1.$nin).length === 0;
398
+ }
399
+ }
400
+ }
401
+ return false;
402
+ }
403
+ // 相斥
404
+ if (value1.$nin instanceof Array) {
405
+ if (typeof value2 === 'object') {
406
+ var attr2 = Object.keys(value2)[0];
407
+ if (attr2 === '$in') {
408
+ return value2[attr2] instanceof Array && (0, lodash_1.difference)(value2[attr2], value1.$nin).length === 0;
409
+ }
410
+ }
411
+ }
412
+ return false;
413
+ }
414
+ case '$between': {
415
+ (0, assert_1.default)(value1.$between instanceof Array);
416
+ if (contained) {
417
+ // 相容
418
+ if (typeof value2 === 'object') {
419
+ var attr2 = Object.keys(value2)[0];
420
+ if (['$gt', '$gte', '$lt', '$lte', '$between', '$eq'].includes(attr2)) {
421
+ return attr2 === '$between' && value2[attr2][0] <= value1.$between[0] && value2[attr2][1] >= value1.$between[1]
422
+ || attr2 === '$gt' && value2[attr2] < value1.$between[0] || attr2 === '$gte' && value2[attr2] <= value1.$between[0]
423
+ || attr2 === '$lt' && value2[attr2] > value1.$between[1] || attr2 === '$lte' && value2[attr2] >= value1.$between[1];
424
+ }
425
+ else if (attr2 === '$exists') {
426
+ return value2[attr2] === true;
427
+ }
428
+ }
429
+ return false;
430
+ }
431
+ // 相斥
432
+ if (typeof value2 === 'object') {
433
+ var attr2 = Object.keys(value2)[0];
434
+ if (['$gt', '$gte', '$lt', '$lte', '$between', '$eq'].includes(attr2)) {
435
+ return attr2 === '$between' && (value2[attr2][0] > value1.$between[1] || value2[attr2][1] < value1.$between[0])
436
+ || attr2 === '$gt' && value2[attr2] > value1.$between[1] || attr2 === '$gte' && value2[attr2] >= value1.$between[1]
437
+ || attr2 === '$lt' && value2[attr2] < value1.$between[0] || attr2 === '$lte' && value2[attr2] <= value1.$between[0]
438
+ || attr2 === '$eq' && (value2[attr2] > value1.$between[1] || value2[attr2] < value1.$between[0]);
439
+ }
440
+ else if (attr2 === '$exists') {
441
+ return value2[attr2] === false;
442
+ }
443
+ else if (attr2 === '$in' && value2[attr2] instanceof Array) {
444
+ return !value2[attr2].find(function (ele) { return ele >= value1.$between[0] && ele <= value1.$between[1]; });
445
+ }
446
+ return false;
447
+ }
448
+ }
449
+ default: {
450
+ (0, assert_1.default)(false, "\u6682\u4E0D\u652F\u6301\u7684\u7B97\u5B50".concat(attr));
451
+ }
452
+ }
453
+ }
454
+ else {
455
+ return false;
456
+ }
457
+ }
458
+ else {
459
+ // value1是一个等值查询
460
+ if (contained) {
461
+ // 相容
462
+ if (typeof value2 === 'object') {
463
+ var attr2 = Object.keys(value2)[0];
464
+ return attr2 === '$eq' && value2[attr2] === value1 || attr2 === '$ne' && value2[attr2] !== value1
465
+ || attr2 === '$gt' && value2[attr2] < value1 || attr2 === '$lt' && value2[attr2] > value1
466
+ || attr2 === '$gte' && value2[attr2] <= value1 || attr2 === '$lte' && value2[attr2] >= value1
467
+ || attr2 === '$startsWith' && value1.startsWith(value2[attr2])
468
+ || attr2 === '$endsWith' && value1.endsWith(value2[attr2])
469
+ || attr2 === '$includes' && value1.includes(value2[attr2])
470
+ || attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1)
471
+ || attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
472
+ || attr2 === '$between' && value2[attr2][0] <= value1 && value2[attr2][1] >= value1
473
+ || attr2 === '$exists' && value2[attr2] === true;
474
+ }
475
+ return value2 === value1;
476
+ }
477
+ // 互斥
478
+ if (typeof value2 === 'object') {
479
+ var attr2 = Object.keys(value2)[0];
480
+ return attr2 === '$eq' && value2[attr2] !== value1 || attr2 === '$gt' && value2[attr2] >= value1
481
+ || attr2 === '$lt' && value2[attr2] <= value1
482
+ || attr2 === '$gte' && value2[attr2] > value1 || attr2 === '$lte' && value2[attr2] < value1
483
+ || attr2 === '$startsWith' && !value1.startsWith(value2[attr2])
484
+ || attr2 === '$endsWith' && !value1.endsWith(value2[attr2])
485
+ || attr2 === '$includes' && !value1.includes(value2[attr2])
486
+ || attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
487
+ || attr2 === '$between' && (value2[attr2][0] > value1 || value2[attr2][1] < value1)
488
+ || attr2 === '$exists' && value2[attr2] === false;
489
+ }
490
+ return value2 !== value1;
491
+ }
492
+ }
493
+ exports.judgeValueRelation = judgeValueRelation;
494
+ function judgeFilter2ValueRelation(entity, schema, attr, filter, conditionalFilterAttrValue, contained) {
495
+ var _a;
496
+ for (var attr2 in filter) {
497
+ if (['$and', '$or', '$not'].includes(attr2)) {
498
+ switch (attr2) {
499
+ case '$and':
500
+ case '$or':
501
+ case '$xor': {
502
+ var logicQueries = filter[attr2];
503
+ var results = logicQueries.map(function (logicQuery) { return judgeFilter2ValueRelation(entity, schema, attr, logicQuery, conditionalFilterAttrValue, contained); });
504
+ // 如果filter的多个算子是and关系,则只要有一个包含此条件就是包含,只要有一个与此条件相斥就是相斥
505
+ // 如果filter的多个算子是or关系,则必须所有的条件都包含此条件才是包含,必须所有的条件都与此条件相斥才是相斥
506
+ if (attr2 === '$and') {
507
+ if (results.includes(true)) {
508
+ return true;
509
+ }
510
+ }
511
+ else if (attr2 === '$or') {
512
+ if (!results.includes(false)) {
513
+ return true;
514
+ }
515
+ }
516
+ else {
517
+ (0, assert_1.default)(false);
518
+ }
519
+ break;
520
+ }
521
+ case '$not': {
522
+ /*
523
+ * 若filter的not条件被conditionalFilterAttrValue包容,则说明两者互斥
524
+ * 若filter的not条件被conditionalFilterAttrValue的not条件所包容,则说明此条件包容conditionalFilterAttrValue
525
+ * 但两条规则都没法应用,会无限递归
526
+ */
527
+ var logicQuery = filter[attr2];
528
+ /* if (contained && judgeFilterRelation(entity, schema, {
529
+ [attr2]: {
530
+ $not: conditionalFilterAttrValue
531
+ }
532
+ }, logicQuery, contained)) {
533
+ return true;
534
+ } */
535
+ if (!contained && judgeFilterRelation(entity, schema, (_a = {}, _a[attr2] = conditionalFilterAttrValue, _a), logicQuery, contained)) {
536
+ return true;
537
+ }
538
+ break;
539
+ }
540
+ default: {
541
+ break;
542
+ }
543
+ }
544
+ }
545
+ else if (attr2.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
546
+ return false;
547
+ }
548
+ else if (attr2.toLowerCase() === '$text') {
549
+ return false;
550
+ }
551
+ else {
552
+ if (attr === attr2) {
553
+ var rel = (0, relation_1.judgeRelation)(schema, entity, attr2);
554
+ if (rel === 1) {
555
+ return judgeValueRelation(filter[attr2], conditionalFilterAttrValue, contained);
556
+ }
557
+ else if (rel === 2) {
558
+ return judgeFilterRelation(attr2, schema, filter[attr2], conditionalFilterAttrValue, contained);
559
+ }
560
+ else if (typeof rel === 'string') {
561
+ return judgeFilterRelation(rel, schema, filter[attr2], conditionalFilterAttrValue, contained);
562
+ }
563
+ else {
564
+ (0, assert_1.default)(false);
565
+ }
566
+ }
567
+ }
568
+ }
569
+ return false;
570
+ }
571
+ /**
572
+ * @param entity
573
+ * @param schema
574
+ * @param filter
575
+ * @param conditionalFilter
576
+ * @param contained: true代表filter包容conditionalFilter, false代表filter与conditionalFilter相斥
577
+ */
578
+ function judgeFilterRelation(entity, schema, filter, conditionalFilter, contained) {
579
+ for (var attr in conditionalFilter) {
580
+ if (['$and', '$or', '$not'].includes(attr)) {
581
+ switch (attr) {
582
+ case '$and':
583
+ case '$or': {
584
+ var logicQueries = conditionalFilter[attr];
585
+ var results = logicQueries.map(function (logicQuery) { return judgeFilterRelation(entity, schema, filter, logicQuery, contained); });
586
+ if (contained) {
587
+ // 如果是包容关系,则无论and还是or,conditionalFilter中的任何一个查询条件都应当被filter所包容
588
+ if (results.includes(false)) {
589
+ return false;
590
+ }
591
+ }
592
+ else if (!contained) {
593
+ // 如果是相斥关系,则无论and还是or,conditionalFilter中的任何一个查询条件都应当与filter所相斥
594
+ if (!results.includes(true)) {
595
+ return false;
596
+ }
597
+ }
598
+ else {
599
+ (0, assert_1.default)(false);
600
+ }
601
+ break;
602
+ }
603
+ case '$not': {
604
+ /**
605
+ * 若filter与not所定义的filter相斥,则filter与conditionalFilter相容
606
+ * 若filter与not所定义的filter相容,则filter与conditionalFilter相斥
607
+ */
608
+ var logicQuery = conditionalFilter[attr];
609
+ if (judgeFilterRelation(entity, schema, filter, logicQuery, !contained)) {
610
+ return true;
611
+ }
612
+ break;
613
+ }
614
+ default: {
615
+ throw new Error("\u6682\u4E0D\u652F\u6301\u7684\u903B\u8F91\u7B97\u5B50".concat(attr));
616
+ }
617
+ }
618
+ }
619
+ else if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
620
+ return false;
621
+ }
622
+ else if (attr.toLowerCase() === '$text') {
623
+ return false;
624
+ }
625
+ else {
626
+ if (contained && !judgeFilter2ValueRelation(entity, schema, attr, filter, conditionalFilter[attr], contained)) {
627
+ // 相容关系只要有一个不相容就不相容
628
+ return false;
629
+ }
630
+ if (!contained && judgeFilter2ValueRelation(entity, schema, attr, filter, conditionalFilter[attr], contained)) {
631
+ // 相斥关系只要有一个相斥就相斥
632
+ return true;
633
+ }
634
+ }
635
+ }
636
+ // 到这里说明不能否定其相容(所以要返回相容),也不能肯定其相斥(所以要返回不相斥)
637
+ return contained;
638
+ }
639
+ /**
640
+ *
99
641
  * 判断filter是否包含conditionalFilter中的查询条件,即filter查询的结果一定满足conditionalFilter的约束
100
642
  * filter = {
101
643
  * a: 1
@@ -110,9 +652,10 @@ exports.combineFilters = combineFilters;
110
652
  * @param schema
111
653
  * @param filter
112
654
  * @param conditionalFilter
655
+ * @returns
113
656
  */
114
657
  function contains(entity, schema, filter, conditionalFilter) {
115
- // todo
658
+ // return judgeFilterRelation(entity, schema, filter, conditionalFilter, true);
116
659
  return false;
117
660
  }
118
661
  exports.contains = contains;
@@ -132,6 +675,7 @@ exports.contains = contains;
132
675
  */
133
676
  function repel(entity, schema, filter1, filter2) {
134
677
  // todo
678
+ // return judgeFilterRelation(entity, schema, filter1, filter2, false);
135
679
  return false;
136
680
  }
137
681
  exports.repel = repel;
@@ -284,3 +828,28 @@ function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll,
284
828
  return currentLevelInFilter;
285
829
  }
286
830
  exports.makeTreeDescendantFilter = makeTreeDescendantFilter;
831
+ function checkFilterContains(entity, context, contained, filter) {
832
+ if (!filter) {
833
+ throw new types_1.OakRowInconsistencyException();
834
+ }
835
+ var schema = context.getSchema();
836
+ // 优先判断两个条件是否相容
837
+ if (contains(entity, schema, filter, contained)) {
838
+ return true;
839
+ }
840
+ // 再判断加上了conditionalFilter后取得的行数是否缩减
841
+ var filter2 = combineFilters([filter, {
842
+ $not: contained,
843
+ }]);
844
+ var count = context.count(entity, {
845
+ filter: filter2,
846
+ }, {
847
+ dontCollect: true,
848
+ blockTrigger: true,
849
+ });
850
+ if (count instanceof Promise) {
851
+ return count.then(function (count2) { return count2 === 0; });
852
+ }
853
+ return count === 0;
854
+ }
855
+ exports.checkFilterContains = checkFilterContains;
@@ -1,12 +1,13 @@
1
1
  import { EntityDict as BaseEntityDict } from '../base-app-domain';
2
- import { UniversalContext } from '../store/UniversalContext';
3
2
  import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
4
- import { Checker, Operation, StorageSchema, EntityDict, Context, OperateOption, Trigger } from '../types';
3
+ import { Operation, StorageSchema, RowChecker, EntityDict, OperateOption, Trigger } from '../types';
4
+ import { AsyncContext } from './AsyncRowStore';
5
+ import { SyncContext } from './SyncRowStore';
5
6
  export declare function createOperationsFromModies(modies: Modi[]): Array<{
6
7
  operation: Operation<string, Object, Object>;
7
8
  entity: string;
8
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
- 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
- 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>): Trigger<ED, keyof ED, Cxt>[];
10
+ export declare function applyModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
11
+ export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>, Op extends OperateOption>(filter: ED['modi']['Selection']['filter'], context: Cxt, option: Op): Promise<import("../types").OperationResult<ED>>;
12
+ export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>): RowChecker<ED, keyof ED, Cxt>[];
13
+ export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(schema: StorageSchema<ED>): Trigger<ED, keyof ED, Cxt>[];