oak-domain 1.1.13 → 2.0.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/base-app-domain/Modi/Schema.d.ts +29 -32
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +24 -27
- package/lib/base-app-domain/Oper/Schema.d.ts +24 -27
- package/lib/base-app-domain/OperEntity/Schema.d.ts +25 -28
- package/lib/base-app-domain/User/Schema.d.ts +22 -25
- package/lib/checkers/index.d.ts +4 -2
- package/lib/compiler/schemalBuilder.js +22 -24
- package/lib/store/AsyncRowStore.d.ts +45 -0
- package/lib/store/{UniversalContext.js → AsyncRowStore.js} +39 -29
- package/lib/store/CascadeStore.d.ts +46 -20
- package/lib/store/CascadeStore.js +960 -996
- package/lib/store/SyncRowStore.d.ts +26 -0
- package/lib/store/SyncRowStore.js +45 -0
- package/lib/store/TriggerExecutor.d.ts +14 -14
- package/lib/store/TriggerExecutor.js +225 -238
- package/lib/store/actionDef.d.ts +5 -4
- package/lib/store/actionDef.js +44 -133
- package/lib/store/checker.d.ts +6 -0
- package/lib/store/checker.js +165 -0
- package/lib/store/filter.d.ts +5 -0
- package/lib/store/filter.js +395 -3
- package/lib/store/modi.d.ts +7 -6
- package/lib/store/modi.js +35 -46
- package/lib/store/relation.d.ts +1 -1
- package/lib/store/selection.js +1 -0
- package/lib/triggers/index.d.ts +4 -3
- package/lib/triggers/modi.d.ts +2 -2
- package/lib/triggers/modi.js +5 -5
- package/lib/types/AppLoader.d.ts +3 -3
- package/lib/types/Aspect.d.ts +3 -3
- package/lib/types/Auth.d.ts +25 -22
- package/lib/types/Connector.d.ts +7 -7
- package/lib/types/Context.d.ts +4 -14
- package/lib/types/DataType.d.ts +1 -0
- package/lib/types/Entity.d.ts +26 -18
- package/lib/types/Entity.js +9 -2
- package/lib/types/Exception.d.ts +6 -1
- package/lib/types/Exception.js +30 -13
- package/lib/types/RowStore.d.ts +2 -13
- package/lib/types/RowStore.js +1 -6
- package/lib/types/Storage.d.ts +1 -0
- package/lib/types/Trigger.d.ts +32 -48
- package/lib/types/Trigger.js +24 -9
- package/lib/types/Watcher.d.ts +7 -8
- package/lib/types/schema/DataTypes.d.ts +1 -1
- package/lib/utils/SimpleConnector.d.ts +9 -8
- package/lib/utils/SimpleConnector.js +4 -5
- package/lib/utils/random/random.d.ts +1 -0
- package/lib/utils/random/random.js +24 -0
- package/lib/utils/random/random.mp.d.ts +1 -0
- package/lib/utils/random/random.mp.js +25 -0
- package/lib/utils/random/random.web.d.ts +1 -0
- package/lib/utils/random/random.web.js +17 -0
- package/lib/utils/string.d.ts +20 -0
- package/lib/utils/string.js +60 -1
- package/lib/utils/uuid.d.ts +10 -0
- package/lib/utils/uuid.js +172 -1
- package/lib/utils/validator.d.ts +2 -2
- package/lib/utils/validator.js +5 -5
- package/package.json +5 -3
- package/lib/OakError.d.ts +0 -7
- package/lib/OakError.js +0 -15
- package/lib/compiler/utils.d.ts +0 -2
- package/lib/compiler/utils.js +0 -11
- package/lib/entities/Action.d.ts +0 -12
- package/lib/entities/Action.js +0 -17
- package/lib/entities/Ooperation.d.ts +0 -12
- package/lib/entities/Ooperation.js +0 -17
- package/lib/entities/Update.d.ts +0 -9
- package/lib/entities/Update.js +0 -44
- package/lib/entities/Uupdate.d.ts +0 -9
- package/lib/entities/Uupdate.js +0 -44
- package/lib/store/UniversalContext.d.ts +0 -32
- package/lib/store/action.d.ts +0 -6
- package/lib/store/action.js +0 -14
- package/lib/store/projection.d.ts +0 -7
- package/lib/store/projection.js +0 -211
- package/lib/store/watchers.d.ts +0 -2
- package/lib/store/watchers.js +0 -32
package/lib/store/filter.js
CHANGED
|
@@ -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.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,371 @@ function combineFilters(filters, union) {
|
|
|
96
98
|
}
|
|
97
99
|
exports.combineFilters = combineFilters;
|
|
98
100
|
/**
|
|
101
|
+
* 判断value1表达的单个属性查询与同属性上value2表达的查询是相容还是相斥
|
|
102
|
+
* 相容即value2所表达的查询结果一定符合value1表达的查询结果,例如:
|
|
103
|
+
* value1: {
|
|
104
|
+
* $gt: 8,
|
|
105
|
+
* }
|
|
106
|
+
* value2: {
|
|
107
|
+
* $eq: 12
|
|
108
|
+
* }
|
|
109
|
+
* 此时value1相容value2
|
|
110
|
+
*
|
|
111
|
+
* 相斥即value1所表达的查询结果与value2一定毫无联系,例如:
|
|
112
|
+
* value1: {
|
|
113
|
+
* $gt: 8,
|
|
114
|
+
* }
|
|
115
|
+
* value2: {
|
|
116
|
+
* $lt: 2,
|
|
117
|
+
* }
|
|
118
|
+
* @param value1
|
|
119
|
+
* @param value2
|
|
120
|
+
*/
|
|
121
|
+
function judgeFilterValueRelation(value1, value2, contained) {
|
|
122
|
+
if (typeof value1 === 'object') {
|
|
123
|
+
var attr = Object.keys(value1)[0];
|
|
124
|
+
if (['$gt', '$lt', '$gte', '$lte', '$eq', '$ne',
|
|
125
|
+
'$startsWith', '$endsWith', '$includes'].includes(attr)) {
|
|
126
|
+
switch (attr) {
|
|
127
|
+
case '$gt': {
|
|
128
|
+
if (typeof value2 === 'object') {
|
|
129
|
+
var attr2 = Object.keys(value2)[0];
|
|
130
|
+
return attr2 === '$gt' && value2[attr2] >= value1.$gt
|
|
131
|
+
|| ['$gte', '$eq'].includes(attr2) && value2[attr2] > value1.$gt
|
|
132
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele <= value1.$gt; }));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
return value2 > value1.$gt;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
case '$gte': {
|
|
139
|
+
if (typeof value2 === 'object') {
|
|
140
|
+
var attr2 = Object.keys(value2)[0];
|
|
141
|
+
return attr2 === '$gt' && value2[attr2] > value1.$gte
|
|
142
|
+
|| ['$gte', '$eq'].includes(attr2) && value2[attr2] >= value1.$gte
|
|
143
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gte || ele < value1.$gte; }));
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
return value2 >= value1.$gt;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
case '$lt': {
|
|
150
|
+
if (typeof value2 === 'object') {
|
|
151
|
+
var attr2 = Object.keys(value2)[0];
|
|
152
|
+
return attr2 === '$lt' && value2[attr2] <= value1.$lt
|
|
153
|
+
|| ['$lte', '$eq'].includes(attr2) && value2[attr2] < value1.$lt
|
|
154
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !(value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$lt || ele >= value1.$lt; });
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
return value2 < value1.$lt;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
case '$lte': {
|
|
161
|
+
if (typeof value2 === 'object') {
|
|
162
|
+
var attr2 = Object.keys(value2)[0];
|
|
163
|
+
return attr2 === '$lt' && value2[attr2] < value1.$lte
|
|
164
|
+
|| ['$lte', '$eq'].includes(attr2) && value2[attr2] <= value1.$lte
|
|
165
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !(value2[attr2].find(function (ele) { return typeof ele !== typeof value1.$lte || ele > value1.$lte; }));
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
return value2 <= value1.$lte;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
case '$eq': {
|
|
172
|
+
if (typeof value2 === 'object') {
|
|
173
|
+
var attr2 = Object.keys(value2)[0];
|
|
174
|
+
return attr2 === '$eq' && value2[attr2] === value1.$eq;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
return value2 === value1.$eq;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
case '$ne': {
|
|
181
|
+
if (typeof value2 === 'object') {
|
|
182
|
+
var attr2 = Object.keys(value2)[0];
|
|
183
|
+
return attr2 === '$eq' && value2[attr2] !== value1.$ne
|
|
184
|
+
|| attr2 === '$ne' && value2[attr2] === value1.$ne
|
|
185
|
+
|| attr2 === '$gt' && value2[attr2] >= value1.$ne
|
|
186
|
+
|| attr2 === '$gte' && value2[attr2] > value1.$ne
|
|
187
|
+
|| attr2 === '$lt' && value2[attr2] <= value1.$ne
|
|
188
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return ele === value1.$ne; }))
|
|
189
|
+
|| attr2 === '$nin' && value2[attr2] instanceof Array && !!(value2[attr2]).find(function (ele) { return ele === value1.$ne; });
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return value2 !== value1.$ne;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
case '$startsWith': {
|
|
196
|
+
if (typeof value2 === 'object') {
|
|
197
|
+
var attr2 = Object.keys(value2)[0];
|
|
198
|
+
return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
|
|
199
|
+
&& value2[attr2].startsWith(value1.$startsWith)
|
|
200
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array
|
|
201
|
+
&& !value2[attr2].find(function (ele) { return typeof ele !== 'string' || !ele.startsWith(value1.$startsWith); });
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return typeof value2 === 'string' && value2.startsWith(value1.$startsWith);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
case '$endsWith': {
|
|
208
|
+
if (typeof value2 === 'object') {
|
|
209
|
+
var attr2 = Object.keys(value2)[0];
|
|
210
|
+
return attr2 === '$endsWith' && typeof (value2[attr2]) === 'string'
|
|
211
|
+
&& value2[attr2].endsWith(value1.$endsWith)
|
|
212
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array
|
|
213
|
+
&& !value2[attr2].find(function (ele) { return typeof ele !== 'string' || !ele.endsWith(value1.$endsWith); });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
return typeof value2 === 'string' && value2.endsWith(value1.$endsWith);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
case '$includes': {
|
|
220
|
+
if (typeof value2 === 'object') {
|
|
221
|
+
var attr2 = Object.keys(value2)[0];
|
|
222
|
+
return ['$includes', '$startsWith', '$endsWith'].includes(attr2)
|
|
223
|
+
&& typeof (value2[attr2]) === 'string'
|
|
224
|
+
&& value2[attr2].includes(value1.$includes)
|
|
225
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array
|
|
226
|
+
&& !value2[attr2].find(function (ele) { return typeof ele !== 'string' || !ele.includes(value1.$includes); });
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return typeof value2 === 'string' && value2.includes(value1.$includes);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
default: {
|
|
233
|
+
(0, assert_1.default)(false, "\u4E0D\u80FD\u5904\u7406\u7684\u7B97\u5B50\u300C".concat(attr, "\u300D"));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else if (['$exists'].includes(attr)) {
|
|
238
|
+
(0, assert_1.default)(attr === '$exists');
|
|
239
|
+
if (typeof value2 === 'object') {
|
|
240
|
+
var attr2 = Object.keys(value2)[0];
|
|
241
|
+
if (value1.$exists === false) {
|
|
242
|
+
return attr2 === '$exists' && value2[attr2] === false;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
// 可能不完整,有没有更多情况?
|
|
246
|
+
return !(attr2 === '$exists' && value2[attr2] === false
|
|
247
|
+
|| attr2 === '$nin');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
return value1.$exists === true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else if (['$in', '$nin', '$between'].includes(attr)) {
|
|
255
|
+
switch (attr) {
|
|
256
|
+
case '$in': {
|
|
257
|
+
if (value1.$in instanceof Array) {
|
|
258
|
+
if (typeof value2 === 'object') {
|
|
259
|
+
var attr2 = Object.keys(value2)[0];
|
|
260
|
+
return attr2 === '$in' && value2[attr2] instanceof Array
|
|
261
|
+
&& (0, lodash_1.difference)(value2[attr2], value1.$in).length === 0;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
return value1.$in.includes(value2);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// 子查询,暂不支持
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
case '$nin': {
|
|
273
|
+
if (value1.$nin instanceof Array) {
|
|
274
|
+
if (typeof value2 === 'object') {
|
|
275
|
+
var attr2 = Object.keys(value2)[0];
|
|
276
|
+
return attr2 === '$in' && value2[attr2] instanceof Array
|
|
277
|
+
&& (0, lodash_1.intersection)(value2[attr2], value1.$nin).length === 0
|
|
278
|
+
|| attr2 === '$nin' && value2[attr2] instanceof Array
|
|
279
|
+
&& (0, lodash_1.difference)(value1.$nin, value2[attr2]).length === 0;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return !value1.$nin.includes(value2);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
// 子查询,暂不支持
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
case '$between': {
|
|
291
|
+
(0, assert_1.default)(value1.$between instanceof Array);
|
|
292
|
+
if (typeof value2 === 'object') {
|
|
293
|
+
var attr2 = Object.keys(value2)[0];
|
|
294
|
+
return attr2 === '$in' && value2[attr2] instanceof Array
|
|
295
|
+
&& Math.max.apply(Math, tslib_1.__spreadArray([], tslib_1.__read(value2[attr2]), false)) <= value1.$between[1] && Math.min.apply(Math, tslib_1.__spreadArray([], tslib_1.__read(value2[attr2]), false)) >= value1.$between[0]
|
|
296
|
+
|| attr2 === '$eq' && typeof value2[attr2] === 'number'
|
|
297
|
+
&& value2[attr2] <= value1.$between[1] && value2[attr2] >= value1.$between[0];
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return value2 <= value1.$between[1] && value2 >= value1.$between[0];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
default: {
|
|
304
|
+
(0, assert_1.default)(false, "\u6682\u4E0D\u652F\u6301\u7684\u7B97\u5B50".concat(attr));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
// value1是一个等值查询
|
|
314
|
+
if (typeof value2 === 'object') {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return value1 === value2;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function compareFilter2AttributeValue(entity, schema, attr, filter, conditionalFilterAttrValue, contained) {
|
|
323
|
+
var _a;
|
|
324
|
+
for (var attr2 in filter) {
|
|
325
|
+
if (['$and', '$or'].includes(attr2)) {
|
|
326
|
+
switch (attr2) {
|
|
327
|
+
case '$and':
|
|
328
|
+
case '$or':
|
|
329
|
+
case '$xor': {
|
|
330
|
+
var logicQueries = filter[attr2];
|
|
331
|
+
var results = logicQueries.map(function (logicQuery) { return compareFilter2AttributeValue(entity, schema, attr, logicQuery, conditionalFilterAttrValue, contained); });
|
|
332
|
+
if (attr2 === '$and' && contained || attr2 === '$or' && !contained) {
|
|
333
|
+
// 如果filter的多个算子是and关系,则只要有一个包含此条件就行
|
|
334
|
+
// 如果filter的多个算子是or关系,则只要有一个相斥只条件就行
|
|
335
|
+
if (results.includes(true)) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else if (attr2 === '$or' && contained || attr2 === '$and' && !contained) {
|
|
340
|
+
// 如果filter的多个算子是or关系,则必须每个都能包含此条件
|
|
341
|
+
// 如果filter的多个算子是and关系,则必须每个都与此条件相斥
|
|
342
|
+
if (!results.includes(false)) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
(0, assert_1.default)(false);
|
|
348
|
+
}
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case '$not': {
|
|
352
|
+
/* 判断相容,如果filter的中有not,此not条件应当和conditionalFilterAttrValue的条件相斥
|
|
353
|
+
* 如: conditionalFilter 为 { a: { $ne: 3 } }
|
|
354
|
+
* filter 为 { $not: { a: 3 }}
|
|
355
|
+
* 判断相斥,如果filter中有not,此not条件应当被conditionalFilterAttrValue的条件相容
|
|
356
|
+
* 如: conditionalFilter为 { a: 2 }
|
|
357
|
+
* filter 为 { $not: { a: { $gt: 1 }}}
|
|
358
|
+
*
|
|
359
|
+
* todo 再想一想对吗?
|
|
360
|
+
*/
|
|
361
|
+
var logicQuery = filter[attr2];
|
|
362
|
+
if (contained && !compareFilter2AttributeValue(entity, schema, attr2, logicQuery, conditionalFilterAttrValue, !contained)) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (!contained && judgeFilterRelation(entity, schema, (_a = {}, _a[attr2] = conditionalFilterAttrValue, _a), logicQuery, contained)) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
default: {
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else if (attr2.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
else if (attr2.toLowerCase() === '$text') {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (attr === attr2) {
|
|
383
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr2);
|
|
384
|
+
if (rel === 1) {
|
|
385
|
+
return judgeFilterValueRelation(filter[attr2], conditionalFilterAttrValue, contained);
|
|
386
|
+
}
|
|
387
|
+
else if (rel === 2) {
|
|
388
|
+
return judgeFilterRelation(attr2, schema, filter[attr2], conditionalFilterAttrValue, contained);
|
|
389
|
+
}
|
|
390
|
+
else if (typeof rel === 'string') {
|
|
391
|
+
return judgeFilterRelation(rel, schema, filter[attr2], conditionalFilterAttrValue, contained);
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
(0, assert_1.default)(false);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return contained;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* @param entity
|
|
403
|
+
* @param schema
|
|
404
|
+
* @param filter
|
|
405
|
+
* @param conditionalFilter
|
|
406
|
+
* @param contained: true代表filter包容conditionalFilter, false代表filter与conditionalFilter相斥
|
|
407
|
+
*/
|
|
408
|
+
function judgeFilterRelation(entity, schema, filter, conditionalFilter, contained) {
|
|
409
|
+
for (var attr in conditionalFilter) {
|
|
410
|
+
if (['$and', '$or', '$not'].includes(attr)) {
|
|
411
|
+
switch (attr) {
|
|
412
|
+
case '$and':
|
|
413
|
+
case '$or': {
|
|
414
|
+
var logicQueries = conditionalFilter[attr];
|
|
415
|
+
var results = logicQueries.map(function (logicQuery) { return judgeFilterRelation(entity, schema, filter, logicQuery, contained); });
|
|
416
|
+
if (contained) {
|
|
417
|
+
// 如果是包容关系,则无论and还是or,conditionalFilter中的任何一个查询条件都应当被filter所包容
|
|
418
|
+
if (results.includes(false)) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (!contained) {
|
|
423
|
+
// 如果是相斥关系,则无论and还是or,conditionalFilter中的任何一个查询条件都应当与filter所相斥
|
|
424
|
+
if (!results.includes(true)) {
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
(0, assert_1.default)(false);
|
|
430
|
+
}
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
case '$not': {
|
|
434
|
+
var logicQuery = conditionalFilter[attr];
|
|
435
|
+
if (!judgeFilterRelation(entity, schema, filter, logicQuery, !contained)) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
default: {
|
|
441
|
+
throw new Error("\u6682\u4E0D\u652F\u6301\u7684\u903B\u8F91\u7B97\u5B50".concat(attr));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
else if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
else if (attr.toLowerCase() === '$text') {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
if (contained && !compareFilter2AttributeValue(entity, schema, attr, filter, conditionalFilter[attr], contained)) {
|
|
453
|
+
// 相容关系只要有一个不相容就不相容
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
if (!contained && !compareFilter2AttributeValue(entity, schema, attr, filter, conditionalFilter[attr], contained)) {
|
|
457
|
+
// 相斥关系只要有一个相斥就相斥
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return contained;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
*
|
|
99
466
|
* 判断filter是否包含conditionalFilter中的查询条件,即filter查询的结果一定满足conditionalFilter的约束
|
|
100
467
|
* filter = {
|
|
101
468
|
* a: 1
|
|
@@ -110,9 +477,9 @@ exports.combineFilters = combineFilters;
|
|
|
110
477
|
* @param schema
|
|
111
478
|
* @param filter
|
|
112
479
|
* @param conditionalFilter
|
|
480
|
+
* @returns
|
|
113
481
|
*/
|
|
114
482
|
function contains(entity, schema, filter, conditionalFilter) {
|
|
115
|
-
// todo
|
|
116
483
|
return false;
|
|
117
484
|
}
|
|
118
485
|
exports.contains = contains;
|
|
@@ -150,7 +517,7 @@ function getRelevantIds(filter) {
|
|
|
150
517
|
}
|
|
151
518
|
// 因为要准确判定id,如果有其它的过滤条件,可能会使实际处理的行数少于id指向的行数,只能返回空数组
|
|
152
519
|
var attrs = Object.keys(filter);
|
|
153
|
-
if ((0, lodash_1.
|
|
520
|
+
if ((0, lodash_1.intersection)(attrs, ['id', '$and', '$or']).length > 3) {
|
|
154
521
|
return [];
|
|
155
522
|
}
|
|
156
523
|
if (filter === null || filter === void 0 ? void 0 : filter.$and) {
|
|
@@ -284,3 +651,28 @@ function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll,
|
|
|
284
651
|
return currentLevelInFilter;
|
|
285
652
|
}
|
|
286
653
|
exports.makeTreeDescendantFilter = makeTreeDescendantFilter;
|
|
654
|
+
function checkFilterContains(entity, context, contained, filter) {
|
|
655
|
+
if (!filter) {
|
|
656
|
+
throw new types_1.OakRowInconsistencyException();
|
|
657
|
+
}
|
|
658
|
+
var schema = context.getSchema();
|
|
659
|
+
// 优先判断两个条件是否相容
|
|
660
|
+
if (contains(entity, schema, filter, contained)) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
// 再判断加上了conditionalFilter后取得的行数是否缩减
|
|
664
|
+
var filter2 = combineFilters([filter, {
|
|
665
|
+
$not: contained,
|
|
666
|
+
}]);
|
|
667
|
+
var count = context.count(entity, {
|
|
668
|
+
filter: filter2,
|
|
669
|
+
}, {
|
|
670
|
+
dontCollect: true,
|
|
671
|
+
blockTrigger: true,
|
|
672
|
+
});
|
|
673
|
+
if (count instanceof Promise) {
|
|
674
|
+
return count.then(function (count2) { return count2 === 0; });
|
|
675
|
+
}
|
|
676
|
+
return count === 0;
|
|
677
|
+
}
|
|
678
|
+
exports.checkFilterContains = checkFilterContains;
|
package/lib/store/modi.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
10
|
-
export declare function abandonModis<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
11
|
-
export declare function createModiRelatedCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
12
|
-
export declare function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
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>[];
|
package/lib/store/modi.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var types_1 = require("../types");
|
|
6
5
|
var action_1 = require("../actions/action");
|
|
7
6
|
var lodash_1 = require("../utils/lodash");
|
|
7
|
+
var uuid_1 = require("../utils/uuid");
|
|
8
8
|
function createOperationsFromModies(modies) {
|
|
9
9
|
return modies.map(function (modi) {
|
|
10
10
|
return {
|
|
@@ -26,15 +26,15 @@ function applyModis(filter, context, option) {
|
|
|
26
26
|
return tslib_1.__generator(this, function (_e) {
|
|
27
27
|
switch (_e.label) {
|
|
28
28
|
case 0:
|
|
29
|
-
_b = (_a = context
|
|
29
|
+
_b = (_a = context).operate;
|
|
30
30
|
_c = ['modi'];
|
|
31
31
|
_d = {};
|
|
32
|
-
return [4 /*yield*/,
|
|
32
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
33
33
|
case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
|
|
34
34
|
_d.action = 'apply',
|
|
35
35
|
_d.data = {},
|
|
36
36
|
_d.filter = filter,
|
|
37
|
-
_d),
|
|
37
|
+
_d), Object.assign({}, option, {
|
|
38
38
|
blockTrigger: false,
|
|
39
39
|
})]))];
|
|
40
40
|
}
|
|
@@ -49,10 +49,10 @@ function abandonModis(filter, context, option) {
|
|
|
49
49
|
return tslib_1.__generator(this, function (_e) {
|
|
50
50
|
switch (_e.label) {
|
|
51
51
|
case 0:
|
|
52
|
-
_b = (_a = context
|
|
52
|
+
_b = (_a = context).operate;
|
|
53
53
|
_c = ['modi'];
|
|
54
54
|
_d = {};
|
|
55
|
-
return [4 /*yield*/,
|
|
55
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
56
56
|
case 1: return [2 /*return*/, _b.apply(_a, _c.concat([(_d.id = _e.sent(),
|
|
57
57
|
_d.action = 'abandon',
|
|
58
58
|
_d.data = {},
|
|
@@ -65,7 +65,7 @@ function abandonModis(filter, context, option) {
|
|
|
65
65
|
$direction: 'asc',
|
|
66
66
|
}
|
|
67
67
|
],
|
|
68
|
-
_d),
|
|
68
|
+
_d), Object.assign({}, option, {
|
|
69
69
|
blockTrigger: false,
|
|
70
70
|
})]))];
|
|
71
71
|
}
|
|
@@ -74,7 +74,6 @@ function abandonModis(filter, context, option) {
|
|
|
74
74
|
}
|
|
75
75
|
exports.abandonModis = abandonModis;
|
|
76
76
|
function createModiRelatedCheckers(schema) {
|
|
77
|
-
var _this = this;
|
|
78
77
|
var checkers = [];
|
|
79
78
|
var _loop_1 = function (entity) {
|
|
80
79
|
var _a = schema[entity], actionType = _a.actionType, actions = _a.actions, inModi = _a.inModi;
|
|
@@ -86,43 +85,33 @@ function createModiRelatedCheckers(schema) {
|
|
|
86
85
|
entity: entity,
|
|
87
86
|
action: restActions,
|
|
88
87
|
type: 'row',
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Object.assign(filter2, {
|
|
110
|
-
entity: entity,
|
|
111
|
-
});
|
|
88
|
+
filter: function (context, option) {
|
|
89
|
+
if (option.modiParentId && option.modiParentEntity) {
|
|
90
|
+
// 如果本身也是创建modi就允许通过
|
|
91
|
+
return {
|
|
92
|
+
id: {
|
|
93
|
+
$exists: true,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
id: {
|
|
99
|
+
$nin: {
|
|
100
|
+
entity: 'modiEntity',
|
|
101
|
+
data: {
|
|
102
|
+
entityId: 1,
|
|
103
|
+
},
|
|
104
|
+
filter: {
|
|
105
|
+
entity: entity,
|
|
106
|
+
modi: {
|
|
107
|
+
iState: 'active',
|
|
112
108
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
count = _c.sent();
|
|
118
|
-
if (count > 0) {
|
|
119
|
-
throw new types_1.OakRowLockedException();
|
|
120
|
-
}
|
|
121
|
-
return [2 /*return*/, 0];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
};
|
|
125
113
|
},
|
|
114
|
+
errMsg: "\u66F4\u65B0\u7684\u5BF9\u8C61".concat(entity, "\u4E0A\u6709\u5C1A\u672A\u7ED3\u675F\u7684modi"),
|
|
126
115
|
});
|
|
127
116
|
};
|
|
128
117
|
for (var entity in schema) {
|
|
@@ -153,10 +142,10 @@ function createModiRelatedTriggers(schema) {
|
|
|
153
142
|
case 0:
|
|
154
143
|
data = operation.data;
|
|
155
144
|
id = data.id;
|
|
156
|
-
_c = (_b = context
|
|
145
|
+
_c = (_b = context).operate;
|
|
157
146
|
_d = ['modi'];
|
|
158
147
|
_e = {};
|
|
159
|
-
return [4 /*yield*/,
|
|
148
|
+
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
|
160
149
|
case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_e.id = _f.sent(),
|
|
161
150
|
_e.action = 'remove',
|
|
162
151
|
_e.data = {},
|
|
@@ -164,7 +153,7 @@ function createModiRelatedTriggers(schema) {
|
|
|
164
153
|
entity: entity,
|
|
165
154
|
entityId: id,
|
|
166
155
|
},
|
|
167
|
-
_e),
|
|
156
|
+
_e), option]))];
|
|
168
157
|
case 2:
|
|
169
158
|
_f.sent();
|
|
170
159
|
return [2 /*return*/, 1];
|
package/lib/store/relation.d.ts
CHANGED
|
@@ -10,4 +10,4 @@ import { StorageSchema } from "../types/Storage";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function judgeRelation<ED extends {
|
|
12
12
|
[E: string]: EntityDef;
|
|
13
|
-
}>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string |
|
|
13
|
+
}>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string | 2 | 1 | string[] | 0;
|
package/lib/store/selection.js
CHANGED
package/lib/triggers/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EntityDict as BaseEntityDict } from '../base-app-domain';
|
|
2
|
-
import { StorageSchema, EntityDict
|
|
3
|
-
|
|
2
|
+
import { StorageSchema, EntityDict } from '../types';
|
|
3
|
+
import { AsyncContext } from '../store/AsyncRowStore';
|
|
4
|
+
declare const _default: import("../types").Trigger<BaseEntityDict, "modi", AsyncContext<BaseEntityDict>>[];
|
|
4
5
|
export default _default;
|
|
5
|
-
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|
6
|
+
export declare function createDynamicTriggers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED>>(schema: StorageSchema<ED>): import("../types").Trigger<ED, keyof ED, Cxt>[];
|
package/lib/triggers/modi.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EntityDict } from "../base-app-domain";
|
|
2
|
+
import { AsyncContext } from "../store/AsyncRowStore";
|
|
2
3
|
import { Trigger } from "../types";
|
|
3
|
-
|
|
4
|
-
declare const triggers: Trigger<EntityDict, 'modi', UniversalContext<EntityDict>>[];
|
|
4
|
+
declare const triggers: Trigger<EntityDict, 'modi', AsyncContext<EntityDict>>[];
|
|
5
5
|
export default triggers;
|