oak-domain 2.6.9 → 3.0.0
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/action.d.ts +1 -1
- package/lib/actions/action.js +2 -2
- package/lib/base-app-domain/ActionAuth/Schema.d.ts +25 -21
- package/lib/base-app-domain/ActionAuth/Storage.js +6 -13
- package/lib/base-app-domain/ActionDefDict.d.ts +1 -0
- package/lib/base-app-domain/ActionDefDict.js +3 -1
- package/lib/base-app-domain/EntityDict.d.ts +2 -0
- package/lib/base-app-domain/I18n/Schema.d.ts +129 -0
- package/lib/base-app-domain/I18n/Schema.js +2 -0
- package/lib/base-app-domain/I18n/Storage.d.ts +3 -0
- package/lib/base-app-domain/I18n/Storage.js +59 -0
- package/lib/base-app-domain/Modi/Action.d.ts +1 -1
- package/lib/base-app-domain/Modi/Schema.d.ts +10 -9
- package/lib/base-app-domain/ModiEntity/Schema.d.ts +42 -28
- package/lib/base-app-domain/ModiEntity/Storage.js +1 -1
- package/lib/base-app-domain/Oper/Schema.d.ts +15 -13
- package/lib/base-app-domain/OperEntity/Schema.d.ts +41 -27
- package/lib/base-app-domain/OperEntity/Storage.js +1 -1
- package/lib/base-app-domain/Relation/Schema.d.ts +50 -22
- package/lib/base-app-domain/Relation/Storage.js +1 -4
- package/lib/base-app-domain/Relation.d.ts +10 -0
- package/lib/base-app-domain/Relation.js +10 -0
- package/lib/base-app-domain/RelationAuth/Schema.d.ts +67 -43
- package/lib/base-app-domain/RelationAuth/Storage.js +9 -12
- package/lib/base-app-domain/Storage.js +20 -18
- package/lib/base-app-domain/User/Action.d.ts +1 -1
- package/lib/base-app-domain/User/Schema.d.ts +20 -14
- package/lib/base-app-domain/User/Storage.js +1 -2
- package/lib/base-app-domain/UserEntityGrant/Action.d.ts +5 -0
- package/lib/base-app-domain/UserEntityGrant/Action.js +5 -0
- package/lib/base-app-domain/UserEntityGrant/Schema.d.ts +53 -17
- package/lib/base-app-domain/UserEntityGrant/Storage.js +5 -7
- package/lib/base-app-domain/UserRelation/Schema.d.ts +35 -16
- package/lib/base-app-domain/UserRelation/Storage.js +21 -1
- package/lib/base-app-domain/_SubQuery.d.ts +40 -4
- package/lib/base-app-domain/index.d.ts +1 -0
- package/lib/base-app-domain/index.js +1 -0
- package/lib/checkers/index.d.ts +2 -2
- package/lib/checkers/index.js +2 -5
- package/lib/compiler/env.d.ts +3 -1
- package/lib/compiler/env.js +12 -2
- package/lib/compiler/localeBuilder.d.ts +22 -0
- package/lib/compiler/localeBuilder.js +169 -0
- package/lib/compiler/schemalBuilder.d.ts +9 -0
- package/lib/compiler/schemalBuilder.js +774 -362
- package/lib/entities/ActionAuth.d.ts +3 -2
- package/lib/entities/ActionAuth.js +21 -22
- package/lib/entities/I18n.d.ts +9 -0
- package/lib/entities/I18n.js +37 -0
- package/lib/entities/Modi.js +35 -33
- package/lib/entities/ModiEntity.js +12 -10
- package/lib/entities/Oper.js +15 -13
- package/lib/entities/OperEntity.js +12 -10
- package/lib/entities/Relation.d.ts +3 -3
- package/lib/entities/Relation.js +27 -25
- package/lib/entities/RelationAuth.d.ts +2 -5
- package/lib/entities/RelationAuth.js +27 -23
- package/lib/entities/User.js +20 -18
- package/lib/entities/UserEntityGrant.d.ts +2 -1
- package/lib/entities/UserEntityGrant.js +12 -7
- package/lib/entities/UserRelation.d.ts +3 -0
- package/lib/entities/UserRelation.js +30 -20
- package/lib/store/AsyncRowStore.d.ts +3 -0
- package/lib/store/AsyncRowStore.js +3 -0
- package/lib/store/CascadeStore.d.ts +9 -3
- package/lib/store/CascadeStore.js +247 -113
- package/lib/store/RelationAuth.d.ts +96 -0
- package/lib/store/RelationAuth.js +1307 -0
- package/lib/store/TriggerExecutor.d.ts +1 -2
- package/lib/store/TriggerExecutor.js +22 -22
- package/lib/store/actionAuth.d.ts +4 -0
- package/lib/store/actionAuth.js +40 -0
- package/lib/store/actionDef.d.ts +4 -3
- package/lib/store/actionDef.js +63 -45
- package/lib/store/checker.d.ts +2 -9
- package/lib/store/checker.js +39 -815
- package/lib/store/filter.d.ts +31 -18
- package/lib/store/filter.js +1256 -422
- package/lib/store/modi.d.ts +1 -1
- package/lib/store/modi.js +108 -9
- package/lib/store/relation.d.ts +3 -4
- package/lib/timers/oper.js +1 -1
- package/lib/timers/vaccum.js +2 -2
- package/lib/triggers/index.d.ts +2 -3
- package/lib/triggers/index.js +2 -5
- package/lib/types/Auth.d.ts +5 -0
- package/lib/types/DataType.d.ts +3 -0
- package/lib/types/Demand.d.ts +11 -0
- package/lib/types/Demand.js +2 -1
- package/lib/types/Entity.d.ts +10 -3
- package/lib/types/EntityDesc.d.ts +8 -0
- package/lib/types/EntityDesc.js +2 -0
- package/lib/types/Environment.d.ts +57 -0
- package/lib/types/Environment.js +2 -0
- package/lib/types/Exception.d.ts +6 -0
- package/lib/types/Exception.js +25 -1
- package/lib/types/Logger.d.ts +1 -0
- package/lib/types/Port.d.ts +3 -2
- package/lib/types/RowStore.d.ts +6 -4
- package/lib/types/Style.d.ts +1 -1
- package/lib/types/Trigger.d.ts +4 -5
- package/lib/types/Trigger.js +11 -6
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/SimpleConnector.js +1 -1
- package/lib/utils/money.js +1 -1
- package/lib/utils/string.d.ts +6 -0
- package/lib/utils/string.js +13 -1
- package/lib/utils/uuid.d.ts +5 -0
- package/lib/utils/uuid.js +64 -1
- package/package.json +3 -3
- package/src/entities/ActionAuth.ts +25 -33
- package/src/entities/I18n.ts +46 -0
- package/src/entities/Modi.ts +36 -36
- package/src/entities/ModiEntity.ts +14 -13
- package/src/entities/Oper.ts +17 -16
- package/src/entities/OperEntity.ts +13 -11
- package/src/entities/Relation.ts +31 -37
- package/src/entities/RelationAuth.ts +31 -37
- package/src/entities/User.ts +24 -21
- package/src/entities/UserEntityGrant.ts +16 -14
- package/src/entities/UserRelation.ts +33 -27
- package/lib/triggers/modi.d.ts +0 -5
- package/lib/triggers/modi.js +0 -72
package/lib/store/filter.js
CHANGED
|
@@ -1,94 +1,526 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.checkFilterRepel = exports.checkFilterContains = exports.checkDeduceFilters = exports.makeTreeDescendantFilter = exports.makeTreeAncestorFilter = exports.same = exports.getRelevantIds = exports.repel = exports.contains = exports.judgeValueRelation = exports.combineFilters = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
6
|
var types_1 = require("../types");
|
|
7
7
|
var lodash_1 = require("../utils/lodash");
|
|
8
8
|
var relation_1 = require("./relation");
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
|
11
|
+
* @param entity
|
|
12
|
+
* @param schema
|
|
13
|
+
* @param filters
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function addFilterSegment(entity, schema) {
|
|
10
17
|
var filters = [];
|
|
11
|
-
for (var _i =
|
|
12
|
-
filters[_i] = arguments[_i];
|
|
13
|
-
}
|
|
14
|
-
var filter
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
19
|
+
filters[_i - 2] = arguments[_i];
|
|
20
|
+
}
|
|
21
|
+
var filter;
|
|
22
|
+
var addIntoAnd = function (f) {
|
|
23
|
+
(0, assert_1.default)(filter);
|
|
24
|
+
if (filter.$and) {
|
|
25
|
+
filter.$and.push(f);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
filter.$and = [f];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var addSingleAttr = function (attr, value) {
|
|
32
|
+
var _a;
|
|
33
|
+
(0, assert_1.default)(filter);
|
|
34
|
+
if (!filter[attr]) {
|
|
35
|
+
filter[attr] = value;
|
|
36
|
+
}
|
|
37
|
+
// 只优化一种情况,就是两个都等值且相等
|
|
38
|
+
else if (filter[attr] === value) {
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
addIntoAnd((_a = {},
|
|
42
|
+
_a[attr] = value,
|
|
43
|
+
_a));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var manyToOneFilters = {};
|
|
47
|
+
var addManyToOneFilter = function (attr, entity2, filter) {
|
|
48
|
+
if (manyToOneFilters[attr]) {
|
|
49
|
+
manyToOneFilters[attr].push([entity2, filter]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
manyToOneFilters[attr] = [[entity2, filter]];
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var oneToManyFilters = {};
|
|
56
|
+
var addOneToManyFilter = function (attr, entity2, filter) {
|
|
57
|
+
if (oneToManyFilters[attr]) {
|
|
58
|
+
oneToManyFilters[attr].push([entity2, filter]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
oneToManyFilters[attr] = [[entity2, filter]];
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var addInner = function (f) {
|
|
65
|
+
var _a;
|
|
66
|
+
if (f) {
|
|
67
|
+
if (!filter) {
|
|
68
|
+
filter = {};
|
|
69
|
+
}
|
|
70
|
+
if (f.hasOwnProperty('$or')) {
|
|
71
|
+
// 如果有or是无法优化的,直接作为一个整体加入$and
|
|
72
|
+
addIntoAnd(f);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (var attr in f) {
|
|
76
|
+
if (attr === '$and') {
|
|
77
|
+
f[attr].forEach(function (f2) { return addInner(f2); });
|
|
78
|
+
}
|
|
79
|
+
else if (attr.startsWith('$')) {
|
|
80
|
+
addIntoAnd((_a = {},
|
|
81
|
+
_a[attr] = f[attr],
|
|
82
|
+
_a));
|
|
83
|
+
}
|
|
84
|
+
else if (attr.startsWith('#')) {
|
|
85
|
+
(0, assert_1.default)(!filter[attr] || filter[attr] === f[attr]);
|
|
86
|
+
filter[attr] = f[attr];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
90
|
+
if (rel === 1) {
|
|
91
|
+
addSingleAttr(attr, f[attr]);
|
|
22
92
|
}
|
|
23
|
-
else {
|
|
24
|
-
|
|
93
|
+
else if (rel === 2) {
|
|
94
|
+
addManyToOneFilter(attr, attr, f[attr]);
|
|
25
95
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (filter.$and) {
|
|
29
|
-
filter.$and.push((_b = {},
|
|
30
|
-
_b[k] = ele[k],
|
|
31
|
-
_b));
|
|
96
|
+
else if (typeof rel === 'string') {
|
|
97
|
+
addManyToOneFilter(attr, rel, f[attr]);
|
|
32
98
|
}
|
|
33
99
|
else {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_c[k] = ele[k],
|
|
37
|
-
_c)
|
|
38
|
-
];
|
|
100
|
+
(0, assert_1.default)(rel instanceof Array);
|
|
101
|
+
addOneToManyFilter(attr, rel[0], f[attr]);
|
|
39
102
|
}
|
|
40
103
|
}
|
|
41
|
-
else {
|
|
42
|
-
filter[k] = ele[k];
|
|
43
|
-
}
|
|
44
104
|
}
|
|
45
105
|
}
|
|
46
|
-
}
|
|
106
|
+
};
|
|
107
|
+
filters.forEach(function (ele) { return addInner(ele); });
|
|
108
|
+
for (var attr in manyToOneFilters) {
|
|
109
|
+
var filters2 = manyToOneFilters[attr].map(function (ele) { return ele[1]; });
|
|
110
|
+
var combined = addFilterSegment.apply(void 0, tslib_1.__spreadArray([manyToOneFilters[attr][0][0], schema], tslib_1.__read(filters2), false));
|
|
111
|
+
addSingleAttr(attr, combined);
|
|
112
|
+
}
|
|
113
|
+
var _loop_1 = function (attr) {
|
|
114
|
+
var _a;
|
|
115
|
+
var filters2 = oneToManyFilters[attr].map(function (ele) { return ele[1]; });
|
|
116
|
+
var sqpOps = filters2.map(function (ele) { return ele['#sqp'] || 'in'; });
|
|
117
|
+
// 只有全部是同一个子查询算子才能实施合并
|
|
118
|
+
if ((0, lodash_1.uniq)(sqpOps).length > 1) {
|
|
119
|
+
filters2.forEach(function (ele) {
|
|
120
|
+
var _a;
|
|
121
|
+
addIntoAnd((_a = {},
|
|
122
|
+
_a[attr] = ele,
|
|
123
|
+
_a));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
var unioned = unionFilterSegment.apply(void 0, tslib_1.__spreadArray([oneToManyFilters[attr][0][0], schema], tslib_1.__read(filters2), false));
|
|
128
|
+
addSingleAttr(attr, Object.assign(unioned, (_a = {},
|
|
129
|
+
_a['#sqp'] = sqpOps[0],
|
|
130
|
+
_a)));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
for (var attr in oneToManyFilters) {
|
|
134
|
+
_loop_1(attr);
|
|
135
|
+
}
|
|
47
136
|
return filter;
|
|
48
137
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
138
|
+
/**
|
|
139
|
+
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
|
140
|
+
* @param entity
|
|
141
|
+
* @param schema
|
|
142
|
+
* @param filters
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
function unionFilterSegment(entity, schema) {
|
|
52
146
|
var filters = [];
|
|
53
|
-
for (var _i =
|
|
54
|
-
filters[_i] = arguments[_i];
|
|
147
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
148
|
+
filters[_i - 2] = arguments[_i];
|
|
55
149
|
}
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
150
|
+
var filter;
|
|
151
|
+
var possibleCombiningAttrs = function (f1, f2) {
|
|
152
|
+
var e_1, _a, e_2, _b;
|
|
153
|
+
var pca1s = [], pca2s = [];
|
|
154
|
+
var attributes1 = Object.keys(f1);
|
|
155
|
+
var attributes2 = Object.keys(f2);
|
|
156
|
+
try {
|
|
157
|
+
for (var attributes1_1 = tslib_1.__values(attributes1), attributes1_1_1 = attributes1_1.next(); !attributes1_1_1.done; attributes1_1_1 = attributes1_1.next()) {
|
|
158
|
+
var a = attributes1_1_1.value;
|
|
159
|
+
if (a.startsWith('#')) {
|
|
160
|
+
if (f1[a] !== f2[a]) {
|
|
161
|
+
// metadata不相等,无法合并
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
pca1s.push(a);
|
|
167
|
+
}
|
|
63
168
|
}
|
|
64
169
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
170
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
171
|
+
finally {
|
|
172
|
+
try {
|
|
173
|
+
if (attributes1_1_1 && !attributes1_1_1.done && (_a = attributes1_1.return)) _a.call(attributes1_1);
|
|
174
|
+
}
|
|
175
|
+
finally { if (e_1) throw e_1.error; }
|
|
176
|
+
}
|
|
68
177
|
try {
|
|
69
|
-
|
|
178
|
+
for (var attributes2_1 = tslib_1.__values(attributes2), attributes2_1_1 = attributes2_1.next(); !attributes2_1_1.done; attributes2_1_1 = attributes2_1.next()) {
|
|
179
|
+
var a = attributes2_1_1.value;
|
|
180
|
+
if (a.startsWith('#')) {
|
|
181
|
+
if (f1[a] !== f2[a]) {
|
|
182
|
+
// metadata不相等,无法合并
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
pca2s.push(a);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
192
|
+
finally {
|
|
193
|
+
try {
|
|
194
|
+
if (attributes2_1_1 && !attributes2_1_1.done && (_b = attributes2_1.return)) _b.call(attributes2_1);
|
|
195
|
+
}
|
|
196
|
+
finally { if (e_2) throw e_2.error; }
|
|
197
|
+
}
|
|
198
|
+
if (pca1s.length > 1 || pca2s.length > 1) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
(0, assert_1.default)(pca1s.length === 1 && pca2s.length === 1);
|
|
202
|
+
if (pca1s[0] !== pca2s[0] && pca1s[0] !== '$or' && pca2s[0] !== '$or') {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return [pca1s[0], pca2s[0]];
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* 尝试合并同一个属性到f1上,这里只合并等值查询和$in
|
|
209
|
+
* @param f1
|
|
210
|
+
* @param f2
|
|
211
|
+
* @param attr
|
|
212
|
+
* @param justTry
|
|
213
|
+
*/
|
|
214
|
+
var tryMergeAttributeValue = function (f1, f2, attr, justTry) {
|
|
215
|
+
var _a, _b, _c, _d;
|
|
216
|
+
var op1 = typeof f1[attr] === 'object' && Object.keys(f1[attr])[0];
|
|
217
|
+
var op2 = typeof f2[attr] === 'object' && Object.keys(f2[attr])[0];
|
|
218
|
+
if (!op1 && op2 && ['$eq', '$in'].includes(op2)) {
|
|
219
|
+
if (justTry) {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
Object.assign(f1, (_a = {},
|
|
223
|
+
_a[attr] = {
|
|
224
|
+
$in: f2[attr][op2] instanceof Array ? f2[attr][op2].concat(f1[attr]) : [f1[attr], f2[attr][op2]],
|
|
225
|
+
},
|
|
226
|
+
_a));
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
else if (!op2 && op1 && ['$eq', '$in'].includes(op1)) {
|
|
230
|
+
if (justTry) {
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
Object.assign(f1, (_b = {},
|
|
234
|
+
_b[attr] = {
|
|
235
|
+
$in: f1[attr][op1] instanceof Array ? f1[attr][op1].concat(f2[attr]) : [f1[op1][attr], f2[attr]],
|
|
236
|
+
},
|
|
237
|
+
_b));
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
else if (op1 && ['$eq', '$in'].includes(op1) && op2 && ['$eq', '$in'].includes(op2)) {
|
|
241
|
+
if (justTry) {
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
Object.assign(f1, (_c = {},
|
|
245
|
+
_c[attr] = {
|
|
246
|
+
$in: f1[attr][op1] instanceof Array ? f1[attr][op1].concat(f2[attr][op2]) : [f1[attr][op1]].concat(f2[attr][op2]),
|
|
247
|
+
},
|
|
248
|
+
_c));
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
else if (!op1 && !op2) {
|
|
252
|
+
if (justTry) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
Object.assign(f1, (_d = {},
|
|
256
|
+
_d[attr] = {
|
|
257
|
+
$in: [f1[attr], f2[attr]],
|
|
258
|
+
},
|
|
259
|
+
_d));
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* 把f2尝试combine到f1中,保持or的语义
|
|
266
|
+
* @param f1
|
|
267
|
+
* @param f2
|
|
268
|
+
* @returns
|
|
269
|
+
*/
|
|
270
|
+
var tryMergeFilters = function (f1, f2, justTry) {
|
|
271
|
+
var e_3, _a, e_4, _b, e_5, _c, e_6, _d, e_7, _e, e_8, _f, e_9, _g, _h, _j, _k, _l, _m;
|
|
272
|
+
var pcaResult = possibleCombiningAttrs(f1, f2);
|
|
273
|
+
if (!pcaResult) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
var _o = tslib_1.__read(pcaResult, 2), pca1 = _o[0], pca2 = _o[1];
|
|
277
|
+
if (pca1 === '$or' && pca2 === '$or') {
|
|
278
|
+
try {
|
|
279
|
+
// 如果双方都是or,有可能可以交叉合并,如:
|
|
280
|
+
/**
|
|
281
|
+
* {
|
|
282
|
+
$or: [
|
|
283
|
+
{
|
|
284
|
+
password: '1234',
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
ref: {
|
|
288
|
+
nickname: 'xc',
|
|
289
|
+
},
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
$or: [
|
|
295
|
+
{
|
|
296
|
+
ref: {
|
|
297
|
+
name: 'xc2',
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
password: 'dddd',
|
|
302
|
+
}
|
|
303
|
+
]
|
|
304
|
+
}
|
|
305
|
+
*/
|
|
306
|
+
for (var _p = tslib_1.__values(f2[pca2]), _q = _p.next(); !_q.done; _q = _p.next()) {
|
|
307
|
+
var f21 = _q.value;
|
|
308
|
+
var success = false;
|
|
309
|
+
try {
|
|
310
|
+
for (var _r = (e_4 = void 0, tslib_1.__values(f1[pca2])), _s = _r.next(); !_s.done; _s = _r.next()) {
|
|
311
|
+
var f11 = _s.value;
|
|
312
|
+
if (tryMergeFilters(f11, f21, true)) {
|
|
313
|
+
success = true;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
319
|
+
finally {
|
|
320
|
+
try {
|
|
321
|
+
if (_s && !_s.done && (_b = _r.return)) _b.call(_r);
|
|
322
|
+
}
|
|
323
|
+
finally { if (e_4) throw e_4.error; }
|
|
324
|
+
}
|
|
325
|
+
if (!success) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
331
|
+
finally {
|
|
332
|
+
try {
|
|
333
|
+
if (_q && !_q.done && (_a = _p.return)) _a.call(_p);
|
|
334
|
+
}
|
|
335
|
+
finally { if (e_3) throw e_3.error; }
|
|
336
|
+
}
|
|
337
|
+
if (justTry) {
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
for (var _t = tslib_1.__values(f2[pca2]), _u = _t.next(); !_u.done; _u = _t.next()) {
|
|
342
|
+
var f21 = _u.value;
|
|
343
|
+
try {
|
|
344
|
+
for (var _v = (e_6 = void 0, tslib_1.__values(f1[pca2])), _w = _v.next(); !_w.done; _w = _v.next()) {
|
|
345
|
+
var f11 = _w.value;
|
|
346
|
+
if (tryMergeFilters(f11, f21)) {
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
352
|
+
finally {
|
|
353
|
+
try {
|
|
354
|
+
if (_w && !_w.done && (_d = _v.return)) _d.call(_v);
|
|
355
|
+
}
|
|
356
|
+
finally { if (e_6) throw e_6.error; }
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
361
|
+
finally {
|
|
362
|
+
try {
|
|
363
|
+
if (_u && !_u.done && (_c = _t.return)) _c.call(_t);
|
|
364
|
+
}
|
|
365
|
+
finally { if (e_5) throw e_5.error; }
|
|
366
|
+
}
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
else if (pca1 === '$or') {
|
|
370
|
+
try {
|
|
371
|
+
for (var _x = tslib_1.__values(f1[pca1]), _y = _x.next(); !_y.done; _y = _x.next()) {
|
|
372
|
+
var f11 = _y.value;
|
|
373
|
+
if (tryMergeFilters(f11, f2, justTry)) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
379
|
+
finally {
|
|
380
|
+
try {
|
|
381
|
+
if (_y && !_y.done && (_e = _x.return)) _e.call(_x);
|
|
382
|
+
}
|
|
383
|
+
finally { if (e_7) throw e_7.error; }
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
else if (pca2 === '$or') {
|
|
388
|
+
try {
|
|
389
|
+
for (var _z = tslib_1.__values(f2[pca2]), _0 = _z.next(); !_0.done; _0 = _z.next()) {
|
|
390
|
+
var f21 = _0.value;
|
|
391
|
+
if (!tryMergeFilters(f1, f21, true)) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
397
|
+
finally {
|
|
398
|
+
try {
|
|
399
|
+
if (_0 && !_0.done && (_f = _z.return)) _f.call(_z);
|
|
400
|
+
}
|
|
401
|
+
finally { if (e_8) throw e_8.error; }
|
|
402
|
+
}
|
|
403
|
+
if (justTry) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
for (var _1 = tslib_1.__values(f2[pca2]), _2 = _1.next(); !_2.done; _2 = _1.next()) {
|
|
408
|
+
var f12 = _2.value;
|
|
409
|
+
tryMergeFilters(f1, f12);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
413
|
+
finally {
|
|
414
|
+
try {
|
|
415
|
+
if (_2 && !_2.done && (_g = _1.return)) _g.call(_1);
|
|
416
|
+
}
|
|
417
|
+
finally { if (e_9) throw e_9.error; }
|
|
418
|
+
}
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
else if (pca1 === pca2) {
|
|
422
|
+
if (pca1 === '$and') {
|
|
423
|
+
(0, assert_1.default)(false, '只一个属性的时候不应该用$and');
|
|
424
|
+
}
|
|
425
|
+
else if (pca1 === '$not') {
|
|
426
|
+
// 先not后or 等于先and后not
|
|
427
|
+
if (justTry) {
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
Object.assign(f1, (_h = {},
|
|
431
|
+
_h[pca1] = addFilterSegment(entity, schema, f1[pca1], f2[pca2]),
|
|
432
|
+
_h));
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
else if (pca1.startsWith('$')) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
else {
|
|
439
|
+
// 原生属性
|
|
440
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, pca1);
|
|
441
|
+
if (rel === 1) {
|
|
442
|
+
return tryMergeAttributeValue(f1, f2, pca1, justTry);
|
|
443
|
+
}
|
|
444
|
+
else if (rel === 2) {
|
|
445
|
+
if (justTry) {
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
Object.assign(f1, (_j = {},
|
|
449
|
+
_j[pca1] = unionFilterSegment(pca1, schema, f1[pca1], f2[pca2]),
|
|
450
|
+
_j));
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
else if (typeof rel === 'string') {
|
|
454
|
+
if (justTry) {
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
Object.assign(f1, (_k = {},
|
|
458
|
+
_k[pca1] = unionFilterSegment(rel, schema, f1[pca1], f2[pca2]),
|
|
459
|
+
_k));
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
(0, assert_1.default)(rel instanceof Array);
|
|
464
|
+
// 一对多的子查询,只有子查询的语义算子一样才实施合并
|
|
465
|
+
var sqpOp1 = f1[pca1]['#sqp'];
|
|
466
|
+
var sqpOp2 = f2[pca1]['#sqp'];
|
|
467
|
+
if (sqpOp1 !== sqpOp2) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
if (justTry) {
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
Object.assign(f1, (_l = {},
|
|
474
|
+
_l[pca1] = Object.assign(addFilterSegment(rel[0], schema, f1[pca1], f2[pca2]), (_m = {},
|
|
475
|
+
_m['#sqp'] = sqpOp1,
|
|
476
|
+
_m)),
|
|
477
|
+
_l));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
482
|
+
};
|
|
483
|
+
var addIntoOr = function (f) {
|
|
484
|
+
(0, assert_1.default)(filter);
|
|
485
|
+
if (Object.keys(filter).length === 0) {
|
|
486
|
+
Object.assign(filter, f);
|
|
487
|
+
}
|
|
488
|
+
else if (filter.$or) {
|
|
489
|
+
filter.$or.push(f);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
filter = {
|
|
493
|
+
$or: [(0, lodash_1.cloneDeep)(filter), f],
|
|
494
|
+
};
|
|
70
495
|
}
|
|
71
|
-
finally { if (e_1) throw e_1.error; }
|
|
72
|
-
}
|
|
73
|
-
if (allOnlyOneOr) {
|
|
74
|
-
// 优化特殊情况,全部都是$or,直接合并
|
|
75
|
-
var ors = filters.map(function (ele) { return ele.$or; });
|
|
76
|
-
return {
|
|
77
|
-
$or: ors.reduce(function (prev, next) { return prev.concat(next); }, [])
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
$or: filters,
|
|
82
496
|
};
|
|
497
|
+
var addInner = function (f) {
|
|
498
|
+
if (f) {
|
|
499
|
+
if (!filter) {
|
|
500
|
+
filter = (0, lodash_1.cloneDeep)(f);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (tryMergeFilters(filter, f)) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
addIntoOr(f);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
filters.forEach(function (f) { return addInner(f); });
|
|
510
|
+
return filter;
|
|
83
511
|
}
|
|
84
|
-
|
|
85
|
-
function combineFilters(filters, union) {
|
|
512
|
+
function combineFilters(entity, schema, filters, union) {
|
|
86
513
|
if (union) {
|
|
87
|
-
return unionFilterSegment.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(filters), false));
|
|
514
|
+
return unionFilterSegment.apply(void 0, tslib_1.__spreadArray([entity, schema], tslib_1.__read(filters), false));
|
|
88
515
|
}
|
|
89
|
-
return addFilterSegment.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(filters), false));
|
|
516
|
+
return addFilterSegment.apply(void 0, tslib_1.__spreadArray([entity, schema], tslib_1.__read(filters), false));
|
|
90
517
|
}
|
|
91
518
|
exports.combineFilters = combineFilters;
|
|
519
|
+
/**
|
|
520
|
+
* 在以下判断相容或相斥的过程中,相容/相斥的事实标准是:满足两个条件的查询集合是否被包容/互斥,但如果两个filter在逻辑上相容或者相斥,在事实上不一定相容或者相斥
|
|
521
|
+
* 例如:{ a: 1 } 和 { a: { $ne: 1 } } 是明显不相容的查询,但如果数据为空集,则这两个查询并不能否定其相容
|
|
522
|
+
* 我们在处理这类数据时,优先使用逻辑判定的结果(更符合查询本身的期望而非真实数据集),同时也可减少对真实数据集不必要的查询访问
|
|
523
|
+
*/
|
|
92
524
|
/**
|
|
93
525
|
* 判断value1表达的单个属性查询与同属性上value2表达的查询是包容还是相斥
|
|
94
526
|
* 相容即value1所表达的查询结果一定被value2表达的查询结果所包含,例如:
|
|
@@ -111,6 +543,7 @@ exports.combineFilters = combineFilters;
|
|
|
111
543
|
*
|
|
112
544
|
* @param value1
|
|
113
545
|
* @param value2
|
|
546
|
+
* @return true代表肯定相容/相斥,false代表肯定不相容/不相斥,undefined代表不能确定
|
|
114
547
|
* @attention: 1)这里的测试不够充分,有些算子之间的相容或相斥可能有遗漏, 2)有新的算子加入需要修改代码
|
|
115
548
|
*/
|
|
116
549
|
function judgeValueRelation(value1, value2, contained) {
|
|
@@ -119,182 +552,212 @@ function judgeValueRelation(value1, value2, contained) {
|
|
|
119
552
|
if (['$gt', '$lt', '$gte', '$lte', '$eq', '$ne', '$startsWith', '$endsWith', '$includes'].includes(attr)) {
|
|
120
553
|
switch (attr) {
|
|
121
554
|
case '$gt': {
|
|
555
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
556
|
+
var c = attr2 && ['$gt', '$gte'].includes(attr2) && value2[attr2] <= value1.$gt || (attr2 === '$exists' && value2[attr2] === true);
|
|
557
|
+
var r = (attr2 && (['$lt', '$lte', '$eq'].includes(attr2) && value2[attr2] <= value1.$gt ||
|
|
558
|
+
attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele > value1.$gt; }))) || (attr2 === '$exists' && value2[attr2] === false) || ['string', 'number'].includes(typeof value2) && value2 <= value1.$gt);
|
|
122
559
|
if (contained) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var attr2 = Object.keys(value2)[0];
|
|
126
|
-
return ['$gt', '$gte'].includes(attr2) && value2[attr2] <= value1.$gt;
|
|
560
|
+
if (c) {
|
|
561
|
+
return true;
|
|
127
562
|
}
|
|
128
|
-
|
|
563
|
+
else if (r) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
129
567
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
568
|
+
else {
|
|
569
|
+
if (r) {
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
return false;
|
|
135
573
|
}
|
|
136
|
-
return value2 <= value1.$gt;
|
|
137
574
|
}
|
|
138
575
|
case '$gte': {
|
|
576
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
577
|
+
var c = attr2 && ((['$gte'].includes(attr2) && value2[attr2] <= value1.$gte
|
|
578
|
+
|| ['$gt'].includes(attr2) && value2[attr2] < value1.$gte) || (attr2 === '$exists' && value2[attr2] === true));
|
|
579
|
+
var r = (attr2 && (['$lt'].includes(attr2) && value2[attr2] <= value1.$gte
|
|
580
|
+
|| ['$eq', '$lte'].includes(attr2) && value2[attr2] < value1.gte
|
|
581
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !(value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gte || ele >= value1.$gte; }) || (attr2 === '$exists' && value2[attr2] === false))) || (['string', 'number'].includes(typeof value2) && value2 < value1.$gte);
|
|
139
582
|
if (contained) {
|
|
140
583
|
// 包容
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
return ['$gte'].includes(attr2) && value2[attr2] <= value1.$gte
|
|
144
|
-
|| ['$gt'].includes(attr2) && value2[attr2] < value1.$gte;
|
|
584
|
+
if (c) {
|
|
585
|
+
return true;
|
|
145
586
|
}
|
|
146
|
-
|
|
587
|
+
else if (r) {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
return;
|
|
147
591
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var attr2 = Object.keys(value2)[0];
|
|
151
|
-
return ['$lt'].includes(attr2) && value2[attr2] <= value1.$gte
|
|
152
|
-
|| ['$eq', '$lte'].includes(attr2) && value2[attr2] < value1.gte
|
|
153
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gte || ele >= value1.$gte; }));
|
|
592
|
+
if (r) {
|
|
593
|
+
return true;
|
|
154
594
|
}
|
|
155
|
-
return
|
|
595
|
+
return false;
|
|
156
596
|
}
|
|
157
597
|
case '$lt': {
|
|
598
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
599
|
+
var c = attr2 && (['$lt', '$lte'].includes(attr2) && value2[attr2] >= value1.$lt || attr2 === '$exists' && value2[attr2] === true);
|
|
600
|
+
var r = (attr2 && (['$gt', '$gte', '$eq'].includes(attr2) && value2[attr2] >= value1.$lt
|
|
601
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !(value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele < value1.$lt; }) || (attr2 === '$exists' && value2[attr2] === false))) || (['string', 'number'].includes(typeof value2) && value2 >= value1.$lt);
|
|
158
602
|
if (contained) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var attr2 = Object.keys(value2)[0];
|
|
162
|
-
return ['$lt', '$lte'].includes(attr2) && value2[attr2] >= value1.$lt;
|
|
603
|
+
if (c) {
|
|
604
|
+
return true;
|
|
163
605
|
}
|
|
164
|
-
|
|
606
|
+
else if (r) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
return;
|
|
165
610
|
}
|
|
166
611
|
// 互斥
|
|
167
|
-
if (
|
|
168
|
-
|
|
169
|
-
return ['$gt', '$gte', '$eq'].includes(attr2) && value2[attr2] >= value1.$lt
|
|
170
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$gt || ele < value1.$lt; }));
|
|
612
|
+
if (r) {
|
|
613
|
+
return true;
|
|
171
614
|
}
|
|
172
|
-
return
|
|
615
|
+
return false;
|
|
173
616
|
}
|
|
174
617
|
case '$lte': {
|
|
618
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
619
|
+
var c = attr2 && (['$lte'].includes(attr2) && value2[attr2] >= value1.$lte
|
|
620
|
+
|| ['$lt'].includes(attr2) && value2[attr2] > value1.$lte) || (attr2 === '$exists' && value2[attr2] === true);
|
|
621
|
+
var r = (attr2 && (['$gt'].includes(attr2) && value2[attr2] >= value1.$lte
|
|
622
|
+
|| ['$eq', '$gte'].includes(attr2) && value2[attr2] > value1.lte
|
|
623
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !(value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$lte || ele <= value1.$lte; }) || (attr2 === '$exists' && value2[attr2] === false))) || (['string', 'number'].includes(typeof value2) && value2 > value1.$lte);
|
|
175
624
|
if (contained) {
|
|
176
625
|
// 包容
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
return ['$lte'].includes(attr2) && value2[attr2] >= value1.$lte
|
|
180
|
-
|| ['$lt'].includes(attr2) && value2[attr2] > value1.$lte;
|
|
626
|
+
if (c) {
|
|
627
|
+
return true;
|
|
181
628
|
}
|
|
182
|
-
|
|
629
|
+
else if (r) {
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
183
633
|
}
|
|
184
634
|
// 互斥
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
return ['$gt'].includes(attr2) && value2[attr2] >= value1.$lte
|
|
188
|
-
|| ['$eq', '$gte'].includes(attr2) && value2[attr2] > value1.lte
|
|
189
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !((value2[attr2]).find(function (ele) { return typeof ele !== typeof value1.$lte || ele <= value1.$lte; }));
|
|
635
|
+
if (r) {
|
|
636
|
+
return true;
|
|
190
637
|
}
|
|
191
|
-
return
|
|
638
|
+
return false;
|
|
192
639
|
}
|
|
193
640
|
case '$eq': {
|
|
641
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
642
|
+
var c = (attr2 && (attr2 === '$eq' && value2[attr2] === value1.$eq || attr2 === '$ne' && value2[attr2] !== value1.$eq
|
|
643
|
+
|| attr2 === '$gt' && value2[attr2] < value1.$eq || attr2 === '$lt' && value2[attr2] > value1.$eq
|
|
644
|
+
|| attr2 === '$gte' && value2[attr2] <= value1.$eq || attr2 === '$lte' && value2[attr2] >= value1.$eq
|
|
645
|
+
|| attr2 === '$startsWith' && value1.$eq.startsWith(value2[attr2])
|
|
646
|
+
|| attr2 === '$endsWith' && value1.$eq.endsWith(value2[attr2])
|
|
647
|
+
|| attr2 === '$includes' && value1.$eq.includes(value2[attr2])
|
|
648
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1.$eq)
|
|
649
|
+
|| attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
|
|
650
|
+
|| attr2 === '$between' && value2[attr2][0] <= value1.$eq && value2[attr2][1] >= value1.$eq
|
|
651
|
+
|| attr2 === '$exists' && value2[attr2] === true)) || (['string', 'number'].includes(typeof value2) && value2 === value1.$eq);
|
|
652
|
+
var r = (attr2 && (attr2 === '$eq' && value2[attr2] !== value1.$eq || attr2 === '$gt' && value2[attr2] >= value1.$eq
|
|
653
|
+
|| attr2 === '$lt' && value2[attr2] <= value1.$eq
|
|
654
|
+
|| attr2 === '$gte' && value2[attr2] > value1.$eq || attr2 === '$lte' && value2[attr2] < value1.$eq
|
|
655
|
+
|| attr2 === '$startsWith' && !value1.$eq.startsWith(value2[attr2])
|
|
656
|
+
|| attr2 === '$endsWith' && !value1.$eq.endsWith(value2[attr2])
|
|
657
|
+
|| attr2 === '$includes' && !value1.$eq.includes(value2[attr2])
|
|
658
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
|
|
659
|
+
|| attr2 === '$between' && (value2[attr2][0] > value1.$eq || value2[attr2][1] < value1.$eq)
|
|
660
|
+
|| attr2 === '$exists' && value2[attr2] === false)) || value2 !== value1.$eq;
|
|
194
661
|
if (contained) {
|
|
195
662
|
// 相容
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|| attr2 === '$includes' && value1.$eq.includes(value2[attr2])
|
|
204
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1.$eq)
|
|
205
|
-
|| attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
|
|
206
|
-
|| attr2 === '$between' && value2[attr2][0] <= value1.$eq && value2[attr2][1] >= value1.$eq
|
|
207
|
-
|| attr2 === '$exists' && value2[attr2] === true;
|
|
208
|
-
}
|
|
209
|
-
return value2 === value1.$eq;
|
|
663
|
+
if (c) {
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
else if (r) {
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
669
|
+
return undefined;
|
|
210
670
|
}
|
|
211
671
|
// 互斥
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|| attr2 === '$gte' && value2[attr2] > value1.$eq || attr2 === '$lte' && value2[attr2] < value1.$eq
|
|
217
|
-
|| attr2 === '$startsWith' && !value1.$eq.startsWith(value2[attr2])
|
|
218
|
-
|| attr2 === '$endsWith' && !value1.$eq.endsWith(value2[attr2])
|
|
219
|
-
|| attr2 === '$includes' && !value1.$eq.includes(value2[attr2])
|
|
220
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1.$eq)
|
|
221
|
-
|| attr2 === '$between' && (value2[attr2][0] > value1.$eq || value2[attr2][1] < value1.$eq)
|
|
222
|
-
|| attr2 === '$exists' && value2[attr2] === false;
|
|
223
|
-
}
|
|
224
|
-
return value2 !== value1.$eq;
|
|
672
|
+
if (r) {
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
return false;
|
|
225
676
|
}
|
|
226
677
|
case '$ne': {
|
|
678
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
679
|
+
var c = attr2 && attr2 === '$ne' && value2[attr2] === value1.$ne;
|
|
680
|
+
var r = (attr2 === '$eq' && value2[attr2] === value1.$ne) || value2 === value1.$ne;
|
|
227
681
|
if (contained) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
682
|
+
if (c) {
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
685
|
+
else if (r) {
|
|
686
|
+
return false;
|
|
232
687
|
}
|
|
233
|
-
return false;
|
|
234
688
|
}
|
|
235
689
|
// 互斥
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
return attr2 === '$eq' && value2[attr2] === value1.$ne;
|
|
690
|
+
if (r) {
|
|
691
|
+
return true;
|
|
239
692
|
}
|
|
240
|
-
return
|
|
693
|
+
return false;
|
|
241
694
|
}
|
|
242
695
|
case '$startsWith': {
|
|
696
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
697
|
+
var c = attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
|
|
698
|
+
&& value1.$startsWith.startsWith(value2[attr2]);
|
|
699
|
+
var r = attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
|
|
700
|
+
&& !value1.$startsWith.startsWith(value2[attr2]) && !value2[attr2].startsWith(value1.$startsWith)
|
|
701
|
+
|| attr2 === '$eq' && !value2[attr2].startsWith(value1.$startsWith)
|
|
702
|
+
|| typeof value2 === 'string' && !value2.startsWith(value1.$startsWith);
|
|
703
|
+
// 这里似乎还有更多情况,但实际中不可能跑到,不处理了
|
|
243
704
|
if (contained) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
705
|
+
if (c) {
|
|
706
|
+
return true;
|
|
707
|
+
}
|
|
708
|
+
else if (r) {
|
|
709
|
+
return false;
|
|
249
710
|
}
|
|
250
|
-
return
|
|
711
|
+
return;
|
|
251
712
|
}
|
|
252
713
|
// 互斥
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
|
|
256
|
-
&& !value1.$startsWith.startsWith(value2[attr2]) && !value2[attr2].startsWith(value1.$startsWith)
|
|
257
|
-
|| attr2 === '$eq' && !value2[attr2].startsWith(value1.$startsWith);
|
|
714
|
+
if (r) {
|
|
715
|
+
return true;
|
|
258
716
|
}
|
|
259
|
-
return
|
|
717
|
+
return false;
|
|
260
718
|
}
|
|
261
719
|
case '$endsWith': {
|
|
720
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
721
|
+
var c = attr2 === '$endsWith' && typeof (value2[attr2]) === 'string'
|
|
722
|
+
&& value1.$endsWith.endsWith(value2[attr2]);
|
|
723
|
+
var r = (attr2 === '$endsWith' && typeof (value2[attr2]) === 'string'
|
|
724
|
+
&& !value1.$endsWith.endsWith(value2[attr2]) && !value2[attr2].endsWith(value1.$endsWith)
|
|
725
|
+
|| attr2 === '$eq' && !value2[attr2].endsWith(value1.$endsWith)) || typeof value2 === 'string' && !value2.endsWith(value1.$endsWith);
|
|
262
726
|
if (contained) {
|
|
263
727
|
// 相容
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
return attr2 === '$endsWith' && typeof (value2[attr2]) === 'string'
|
|
267
|
-
&& value1.$startsWith.endsWith(value2[attr2]);
|
|
728
|
+
if (c) {
|
|
729
|
+
return true;
|
|
268
730
|
}
|
|
269
|
-
|
|
731
|
+
else if (r) {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
270
735
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var attr2 = Object.keys(value2)[0];
|
|
274
|
-
return attr2 === '$startsWith' && typeof (value2[attr2]) === 'string'
|
|
275
|
-
&& !value1.$startsWith.endsWith(value2[attr2]) && !value2[attr2].endsWith(value1.$startsWith)
|
|
276
|
-
|| attr2 === '$eq' && !value2[attr2].endsWith(value1.$startsWith);
|
|
736
|
+
if (r) {
|
|
737
|
+
return true;
|
|
277
738
|
}
|
|
278
|
-
return
|
|
739
|
+
return false;
|
|
279
740
|
}
|
|
280
741
|
case '$includes': {
|
|
742
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
743
|
+
var c = (attr2 && ['$includes', '$startsWith', '$endsWith'].includes(attr2)
|
|
744
|
+
&& typeof (value2[attr2]) === 'string'
|
|
745
|
+
&& (value2[attr2]).includes(value1.$includes)) || typeof value2 === 'string' && value2.includes(value1.$includes);
|
|
746
|
+
var r = (attr2 === '$eq' && !value2[attr2].includes(value1.$includes)
|
|
747
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].find(function (ele) { return ele.includes(value1.$includes); })) || typeof value2 === 'string' && !value2.includes(value1.$includes);
|
|
281
748
|
if (contained) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
&& (value2[attr2]).includes(value1.$includes);
|
|
749
|
+
if (c) {
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
else if (r) {
|
|
753
|
+
return false;
|
|
288
754
|
}
|
|
289
|
-
return
|
|
755
|
+
return;
|
|
290
756
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
var attr2 = Object.keys(value2)[0];
|
|
294
|
-
return attr2 === '$eq' && !value2[attr2].includes(value1.$includes)
|
|
295
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].find(function (ele) { return ele.includes(value1.$includes); });
|
|
757
|
+
if (r) {
|
|
758
|
+
return true;
|
|
296
759
|
}
|
|
297
|
-
return
|
|
760
|
+
return false;
|
|
298
761
|
}
|
|
299
762
|
default: {
|
|
300
763
|
(0, assert_1.default)(false, "\u4E0D\u80FD\u5904\u7406\u7684\u7B97\u5B50\u300C".concat(attr, "\u300D"));
|
|
@@ -302,141 +765,122 @@ function judgeValueRelation(value1, value2, contained) {
|
|
|
302
765
|
}
|
|
303
766
|
}
|
|
304
767
|
else if (['$exists'].includes(attr)) {
|
|
305
|
-
|
|
768
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
769
|
+
var c = attr2 === '$exists' && value2[attr2] === value1.$exists;
|
|
770
|
+
var r = attr2 === '$exists' && value2[attr2] !== value1.$exists;
|
|
306
771
|
if (contained) {
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
return attr2 === '$exists' && value2[attr2] === value1.$exists;
|
|
772
|
+
if (c) {
|
|
773
|
+
return true;
|
|
310
774
|
}
|
|
311
|
-
|
|
775
|
+
else if (r) {
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
return;
|
|
312
779
|
}
|
|
313
|
-
|
|
780
|
+
if (r) {
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
return false;
|
|
314
784
|
}
|
|
315
785
|
else if (['$in', '$nin', '$between'].includes(attr)) {
|
|
316
786
|
switch (attr) {
|
|
317
787
|
case '$in': {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
else if (attr2 === '$nin') {
|
|
327
|
-
return value2[attr2] instanceof Array && (0, lodash_1.intersection)(value1.$in, value2[attr2]).length === 0;
|
|
328
|
-
}
|
|
329
|
-
else if (attr2 === '$exists') {
|
|
330
|
-
return value2[attr2] === true;
|
|
331
|
-
}
|
|
332
|
-
else if (['$gt', '$gte', '$lt', '$lte', '$between'].includes(attr2)) {
|
|
333
|
-
var min33_1, max33_1;
|
|
334
|
-
value1.$in.forEach(function (ele) {
|
|
335
|
-
if (!min33_1 || min33_1 > ele) {
|
|
336
|
-
min33_1 = ele;
|
|
337
|
-
}
|
|
338
|
-
if (!max33_1 || max33_1 < ele) {
|
|
339
|
-
max33_1 = ele;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
return attr2 === '$gt' && value2[attr2] < min33_1 || attr2 === '$gte' && value2[attr2] <= min33_1
|
|
343
|
-
|| attr2 === '$lt' && value2[attr2] > max33_1 || attr2 === '$lte' && value2[attr2] >= max33_1
|
|
344
|
-
|| attr2 === '$between' && value2[attr2][0] < min33_1 && value2[attr2][1] > max33_1;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
return false;
|
|
349
|
-
}
|
|
350
|
-
// 相斥
|
|
351
|
-
if (value1.$in instanceof Array) {
|
|
352
|
-
if (typeof value2 === 'object') {
|
|
353
|
-
var attr2 = Object.keys(value2)[0];
|
|
354
|
-
if (attr2 === '$in') {
|
|
355
|
-
return (0, lodash_1.intersection)(value2[attr2], value1.$in).length === 0;
|
|
788
|
+
(0, assert_1.default)(value1.$in instanceof Array);
|
|
789
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
790
|
+
var c = (attr2 === '$in' && value2[attr2] instanceof Array && (0, lodash_1.difference)(value1.$in, value2[attr2]).length === 0) || (attr2 === '$nin' && value2[attr2] instanceof Array && (0, lodash_1.intersection)(value1.$in, value2[attr2]).length === 0) || (attr2 === '$exists' && value2[attr2] === true);
|
|
791
|
+
if (!c && attr2 && ['$gt', '$gte', '$lt', '$lte', '$between'].includes(attr2)) {
|
|
792
|
+
var min33_1, max33_1;
|
|
793
|
+
value1.$in.forEach(function (ele) {
|
|
794
|
+
if (!min33_1 || min33_1 > ele) {
|
|
795
|
+
min33_1 = ele;
|
|
356
796
|
}
|
|
357
|
-
|
|
358
|
-
|
|
797
|
+
if (!max33_1 || max33_1 < ele) {
|
|
798
|
+
max33_1 = ele;
|
|
359
799
|
}
|
|
360
|
-
|
|
361
|
-
|
|
800
|
+
});
|
|
801
|
+
c = attr2 === '$gt' && value2[attr2] < min33_1 || attr2 === '$gte' && value2[attr2] <= min33_1
|
|
802
|
+
|| attr2 === '$lt' && value2[attr2] > max33_1 || attr2 === '$lte' && value2[attr2] >= max33_1
|
|
803
|
+
|| attr2 === '$between' && value2[attr2][0] < min33_1 && value2[attr2][1] > max33_1;
|
|
804
|
+
}
|
|
805
|
+
var r = (attr2 === '$in' && (0, lodash_1.intersection)(value2[attr2], value1.$in).length === 0) || (attr2 === '$eq' && !value1.$in.includes(value2[attr2])) || (attr2 === '$exists' && value2[attr2] === false) || (!value1.$in.includes(value2));
|
|
806
|
+
if (!r && attr2 && ['$gt', '$gte', '$lt', '$lte', '$between'].includes(attr2)) {
|
|
807
|
+
var min44_1, max44_1;
|
|
808
|
+
value1.$in.forEach(function (ele) {
|
|
809
|
+
if (!min44_1 || min44_1 > ele) {
|
|
810
|
+
min44_1 = ele;
|
|
362
811
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
value1.$in.forEach(function (ele) {
|
|
366
|
-
if (!min44_1 || min44_1 > ele) {
|
|
367
|
-
min44_1 = ele;
|
|
368
|
-
}
|
|
369
|
-
if (!max44_1 || max44_1 < ele) {
|
|
370
|
-
max44_1 = ele;
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
return attr2 === '$gt' && value2[attr2] >= max44_1 || attr2 === '$gte' && value2[attr2] > max44_1
|
|
374
|
-
|| attr2 === '$lt' && value2[attr2] <= min44_1 || attr2 === '$lte' && value2[attr2] < min44_1
|
|
375
|
-
|| attr2 === '$between' && (value2[attr2][0] > max44_1 || value2[attr2][1] < min44_1);
|
|
812
|
+
if (!max44_1 || max44_1 < ele) {
|
|
813
|
+
max44_1 = ele;
|
|
376
814
|
}
|
|
815
|
+
});
|
|
816
|
+
r = attr2 === '$gt' && value2[attr2] >= max44_1 || attr2 === '$gte' && value2[attr2] > max44_1
|
|
817
|
+
|| attr2 === '$lt' && value2[attr2] <= min44_1 || attr2 === '$lte' && value2[attr2] < min44_1
|
|
818
|
+
|| attr2 === '$between' && (value2[attr2][0] > max44_1 || value2[attr2][1] < min44_1);
|
|
819
|
+
}
|
|
820
|
+
if (contained) {
|
|
821
|
+
// 相容
|
|
822
|
+
if (c) {
|
|
823
|
+
return true;
|
|
824
|
+
}
|
|
825
|
+
else if (r) {
|
|
826
|
+
return false;
|
|
377
827
|
}
|
|
378
|
-
return
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
// 相斥
|
|
831
|
+
if (r) {
|
|
832
|
+
return true;
|
|
379
833
|
}
|
|
380
834
|
return false;
|
|
381
835
|
}
|
|
382
836
|
case '$nin': {
|
|
837
|
+
(0, assert_1.default)(value1.$nin instanceof Array);
|
|
838
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
839
|
+
var c = attr2 && (attr2 === '$nin' && value2[attr2] instanceof Array && (0, lodash_1.intersection)(value2[attr2], value1.$nin).length === 0
|
|
840
|
+
|| attr2 === '$ne' && value1.$nin.includes(value2[attr2]));
|
|
841
|
+
var r = attr2 && (attr2 === '$in' && value2[attr2] instanceof Array && (0, lodash_1.intersection)(value2[attr2], value1.$nin).length > 0) || value1.$nin.includes(value2);
|
|
383
842
|
if (contained) {
|
|
384
843
|
// 相容
|
|
385
|
-
if (
|
|
386
|
-
|
|
387
|
-
var attr2 = Object.keys(value2)[0];
|
|
388
|
-
if (attr2 === '$nin') {
|
|
389
|
-
return value2[attr2] instanceof Array && (0, lodash_1.intersection)(value2[attr2], value1.$nin).length === 0;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
844
|
+
if (c) {
|
|
845
|
+
return true;
|
|
392
846
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
// 相斥
|
|
396
|
-
if (value1.$nin instanceof Array) {
|
|
397
|
-
if (typeof value2 === 'object') {
|
|
398
|
-
var attr2 = Object.keys(value2)[0];
|
|
399
|
-
if (attr2 === '$in') {
|
|
400
|
-
return value2[attr2] instanceof Array && (0, lodash_1.difference)(value2[attr2], value1.$nin).length === 0;
|
|
401
|
-
}
|
|
847
|
+
else if (r) {
|
|
848
|
+
return false;
|
|
402
849
|
}
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (r) {
|
|
853
|
+
return true;
|
|
403
854
|
}
|
|
404
855
|
return false;
|
|
405
856
|
}
|
|
406
857
|
case '$between': {
|
|
407
858
|
(0, assert_1.default)(value1.$between instanceof Array);
|
|
859
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
860
|
+
var c = attr2 && (attr2 === '$between' && value2[attr2][0] <= value1.$between[0] && value2[attr2][1] >= value1.$between[1]
|
|
861
|
+
|| attr2 === '$gt' && value2[attr2] < value1.$between[0] || attr2 === '$gte' && value2[attr2] <= value1.$between[0]
|
|
862
|
+
|| attr2 === '$lt' && value2[attr2] > value1.$between[1] || attr2 === '$lte' && value2[attr2] >= value1.$between[1]
|
|
863
|
+
|| attr2 === '$exists' && value2[attr2] === true);
|
|
864
|
+
var r = attr2 && (attr2 === '$between' && (value2[attr2][0] > value1.$between[1] || value2[attr2][1] < value1.$between[0])
|
|
865
|
+
|| attr2 === '$gt' && value2[attr2] > value1.$between[1] || attr2 === '$gte' && value2[attr2] >= value1.$between[1]
|
|
866
|
+
|| attr2 === '$lt' && value2[attr2] < value1.$between[0] || attr2 === '$lte' && value2[attr2] <= value1.$between[0]
|
|
867
|
+
|| attr2 === '$eq' && (value2[attr2] > value1.$between[1] || value2[attr2] < value1.$between[0])
|
|
868
|
+
|| attr2 === '$exists' && value2[attr2] === false
|
|
869
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].find(function (ele) { return ele >= value1.$between[0] && ele <= value1.$between[1]; })) || value2 > value1.$between[1] || value2 < value1.$between[0];
|
|
408
870
|
if (contained) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
var attr2 = Object.keys(value2)[0];
|
|
412
|
-
if (['$gt', '$gte', '$lt', '$lte', '$between', '$eq'].includes(attr2)) {
|
|
413
|
-
return attr2 === '$between' && value2[attr2][0] <= value1.$between[0] && value2[attr2][1] >= value1.$between[1]
|
|
414
|
-
|| attr2 === '$gt' && value2[attr2] < value1.$between[0] || attr2 === '$gte' && value2[attr2] <= value1.$between[0]
|
|
415
|
-
|| attr2 === '$lt' && value2[attr2] > value1.$between[1] || attr2 === '$lte' && value2[attr2] >= value1.$between[1];
|
|
416
|
-
}
|
|
417
|
-
else if (attr2 === '$exists') {
|
|
418
|
-
return value2[attr2] === true;
|
|
419
|
-
}
|
|
871
|
+
if (c) {
|
|
872
|
+
return true;
|
|
420
873
|
}
|
|
421
|
-
|
|
874
|
+
else if (r) {
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
return;
|
|
422
878
|
}
|
|
423
879
|
// 相斥
|
|
424
|
-
if (
|
|
425
|
-
|
|
426
|
-
if (['$gt', '$gte', '$lt', '$lte', '$between', '$eq'].includes(attr2)) {
|
|
427
|
-
return attr2 === '$between' && (value2[attr2][0] > value1.$between[1] || value2[attr2][1] < value1.$between[0])
|
|
428
|
-
|| attr2 === '$gt' && value2[attr2] > value1.$between[1] || attr2 === '$gte' && value2[attr2] >= value1.$between[1]
|
|
429
|
-
|| attr2 === '$lt' && value2[attr2] < value1.$between[0] || attr2 === '$lte' && value2[attr2] <= value1.$between[0]
|
|
430
|
-
|| attr2 === '$eq' && (value2[attr2] > value1.$between[1] || value2[attr2] < value1.$between[0]);
|
|
431
|
-
}
|
|
432
|
-
else if (attr2 === '$exists') {
|
|
433
|
-
return value2[attr2] === false;
|
|
434
|
-
}
|
|
435
|
-
else if (attr2 === '$in' && value2[attr2] instanceof Array) {
|
|
436
|
-
return !value2[attr2].find(function (ele) { return ele >= value1.$between[0] && ele <= value1.$between[1]; });
|
|
437
|
-
}
|
|
438
|
-
return false;
|
|
880
|
+
if (r) {
|
|
881
|
+
return true;
|
|
439
882
|
}
|
|
883
|
+
return false;
|
|
440
884
|
}
|
|
441
885
|
default: {
|
|
442
886
|
(0, assert_1.default)(false, "\u6682\u4E0D\u652F\u6301\u7684\u7B97\u5B50".concat(attr));
|
|
@@ -444,80 +888,135 @@ function judgeValueRelation(value1, value2, contained) {
|
|
|
444
888
|
}
|
|
445
889
|
}
|
|
446
890
|
else {
|
|
891
|
+
console.warn("\u300CjudgeValueRelation\u300D\u672A\u77E5\u7B97\u5B50\u300C".concat(attr, "\u300D"));
|
|
447
892
|
return false;
|
|
448
893
|
}
|
|
449
894
|
}
|
|
450
895
|
else {
|
|
451
896
|
// value1是一个等值查询
|
|
897
|
+
var attr2 = (typeof value2 === 'object') && Object.keys(value2)[0];
|
|
898
|
+
var c = attr2 === '$eq' && value2[attr2] === value1 || attr2 === '$ne' && value2[attr2] !== value1
|
|
899
|
+
|| attr2 === '$gt' && value2[attr2] < value1 || attr2 === '$lt' && value2[attr2] > value1
|
|
900
|
+
|| attr2 === '$gte' && value2[attr2] <= value1 || attr2 === '$lte' && value2[attr2] >= value1
|
|
901
|
+
|| attr2 === '$startsWith' && value1.startsWith(value2[attr2])
|
|
902
|
+
|| attr2 === '$endsWith' && value1.endsWith(value2[attr2])
|
|
903
|
+
|| attr2 === '$includes' && value1.includes(value2[attr2])
|
|
904
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1)
|
|
905
|
+
|| attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
|
|
906
|
+
|| attr2 === '$between' && value2[attr2][0] <= value1 && value2[attr2][1] >= value1
|
|
907
|
+
|| attr2 === '$exists' && value2[attr2] === true
|
|
908
|
+
|| value2 === value1;
|
|
909
|
+
var r = attr2 === '$eq' && value2[attr2] !== value1 || attr2 === '$gt' && value2[attr2] >= value1
|
|
910
|
+
|| attr2 === '$lt' && value2[attr2] <= value1
|
|
911
|
+
|| attr2 === '$gte' && value2[attr2] > value1 || attr2 === '$lte' && value2[attr2] < value1
|
|
912
|
+
|| attr2 === '$startsWith' && !value1.startsWith(value2[attr2])
|
|
913
|
+
|| attr2 === '$endsWith' && !value1.endsWith(value2[attr2])
|
|
914
|
+
|| attr2 === '$includes' && !value1.includes(value2[attr2])
|
|
915
|
+
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
|
|
916
|
+
|| attr2 === '$between' && (value2[attr2][0] > value1 || value2[attr2][1] < value1)
|
|
917
|
+
|| attr2 === '$exists' && value2[attr2] === false
|
|
918
|
+
|| typeof value2 === typeof value1 && value2 !== value1;
|
|
452
919
|
if (contained) {
|
|
453
920
|
// 相容
|
|
454
|
-
if (
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|| attr2 === '$includes' && value1.includes(value2[attr2])
|
|
462
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && value2[attr2].includes(value1)
|
|
463
|
-
|| attr2 === '$nin' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
|
|
464
|
-
|| attr2 === '$between' && value2[attr2][0] <= value1 && value2[attr2][1] >= value1
|
|
465
|
-
|| attr2 === '$exists' && value2[attr2] === true;
|
|
466
|
-
}
|
|
467
|
-
return value2 === value1;
|
|
921
|
+
if (c) {
|
|
922
|
+
return true;
|
|
923
|
+
}
|
|
924
|
+
else if (r) {
|
|
925
|
+
return false;
|
|
926
|
+
}
|
|
927
|
+
return;
|
|
468
928
|
}
|
|
469
929
|
// 互斥
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|| attr2 === '$gte' && value2[attr2] > value1 || attr2 === '$lte' && value2[attr2] < value1
|
|
475
|
-
|| attr2 === '$startsWith' && !value1.startsWith(value2[attr2])
|
|
476
|
-
|| attr2 === '$endsWith' && !value1.endsWith(value2[attr2])
|
|
477
|
-
|| attr2 === '$includes' && !value1.includes(value2[attr2])
|
|
478
|
-
|| attr2 === '$in' && value2[attr2] instanceof Array && !value2[attr2].includes(value1)
|
|
479
|
-
|| attr2 === '$between' && (value2[attr2][0] > value1 || value2[attr2][1] < value1)
|
|
480
|
-
|| attr2 === '$exists' && value2[attr2] === false;
|
|
481
|
-
}
|
|
482
|
-
return value2 !== value1;
|
|
930
|
+
if (r) {
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
return false;
|
|
483
934
|
}
|
|
484
935
|
}
|
|
485
936
|
exports.judgeValueRelation = judgeValueRelation;
|
|
486
|
-
|
|
487
|
-
|
|
937
|
+
/**
|
|
938
|
+
* 判断filter条件对compared条件上的attr键值的条件是否相容或相斥
|
|
939
|
+
* @param entity
|
|
940
|
+
* @param schema
|
|
941
|
+
* @param attr
|
|
942
|
+
* @param filter
|
|
943
|
+
* @param compared
|
|
944
|
+
* @param contained
|
|
945
|
+
* @returns 返回true说明肯定相容(相斥),返回false说明肯定不相容(相斥),返回undefined说明无法判定相容(相斥),返回DeducedFilterCombination说明需要进一步判断此推断的条件
|
|
946
|
+
*/
|
|
947
|
+
function judgeFilterSingleAttrRelation(entity, schema, attr, filter, compared, contained) {
|
|
948
|
+
var e_10, _a, _b;
|
|
949
|
+
var comparedFilterAttrValue = compared[attr];
|
|
950
|
+
var orDeducedFilters = [];
|
|
951
|
+
if (attr === 'entityId') {
|
|
952
|
+
// entityId不可能作为查询条件单独存在
|
|
953
|
+
(0, assert_1.default)(compared.hasOwnProperty('entity'));
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
488
956
|
for (var attr2 in filter) {
|
|
489
957
|
if (['$and', '$or', '$not'].includes(attr2)) {
|
|
490
958
|
switch (attr2) {
|
|
491
959
|
case '$and':
|
|
492
|
-
case '$or':
|
|
493
|
-
|
|
960
|
+
case '$or': {
|
|
961
|
+
var andDeducedFilters = [];
|
|
494
962
|
var logicQueries = filter[attr2];
|
|
495
|
-
var results = logicQueries.map(function (logicQuery) { return
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
963
|
+
var results = logicQueries.map(function (logicQuery) { return judgeFilterSingleAttrRelation(entity, schema, attr, logicQuery, compared, contained); });
|
|
964
|
+
try {
|
|
965
|
+
// 如果filter的多个算子是and关系,则只要有一个包含此条件就是包含,只要有一个与此条件相斥就是相斥
|
|
966
|
+
// 如果filter的多个算子是or关系,则必须所有的条件都包含此条件才是包含,必须所有的条件都与此条件相斥才是相斥
|
|
967
|
+
for (var results_1 = (e_10 = void 0, tslib_1.__values(results)), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
|
|
968
|
+
var r = results_1_1.value;
|
|
969
|
+
if (r === true && attr2 === '$and') {
|
|
970
|
+
return true;
|
|
971
|
+
}
|
|
972
|
+
if (r === false && attr2 === '$or') {
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
if (r === undefined) {
|
|
976
|
+
if (attr2 === '$or') {
|
|
977
|
+
// or有一个不能确定就返回不确定
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
if (typeof r === 'object') {
|
|
982
|
+
if (attr2 === '$and') {
|
|
983
|
+
orDeducedFilters.push(r);
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
(0, assert_1.default)(attr2 === '$or');
|
|
987
|
+
andDeducedFilters.push(r);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
501
990
|
}
|
|
502
991
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
992
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
993
|
+
finally {
|
|
994
|
+
try {
|
|
995
|
+
if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
|
|
506
996
|
}
|
|
997
|
+
finally { if (e_10) throw e_10.error; }
|
|
507
998
|
}
|
|
508
|
-
|
|
509
|
-
|
|
999
|
+
if (andDeducedFilters.length > 0) {
|
|
1000
|
+
orDeducedFilters.push({
|
|
1001
|
+
$and: andDeducedFilters,
|
|
1002
|
+
});
|
|
510
1003
|
}
|
|
511
1004
|
break;
|
|
512
1005
|
}
|
|
513
1006
|
case '$not': {
|
|
514
1007
|
/*
|
|
515
|
-
* 若filter的not条件被
|
|
516
|
-
* filter包容
|
|
1008
|
+
* 若filter的not条件被comparedFilterAttrValue条件包容,则说明两者互斥
|
|
1009
|
+
* filter包容comparedFilterAttrValue条件暂时无法由其not条件推论出来
|
|
517
1010
|
*/
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
1011
|
+
if (!contained) {
|
|
1012
|
+
var logicQuery = filter[attr2];
|
|
1013
|
+
var r = judgeFilterRelation(entity, schema, (_b = {}, _b[attr] = comparedFilterAttrValue, _b), logicQuery, true);
|
|
1014
|
+
if (r === true) {
|
|
1015
|
+
return true;
|
|
1016
|
+
}
|
|
1017
|
+
else if (typeof r === 'object') {
|
|
1018
|
+
orDeducedFilters.push(r);
|
|
1019
|
+
}
|
|
521
1020
|
}
|
|
522
1021
|
break;
|
|
523
1022
|
}
|
|
@@ -527,78 +1026,259 @@ function judgeFilter2ValueRelation(entity, schema, attr, filter, conditionalFilt
|
|
|
527
1026
|
}
|
|
528
1027
|
}
|
|
529
1028
|
else if (attr2.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
|
|
530
|
-
|
|
1029
|
+
// 相当于缩小了filter的查询结果集,若其它条件能判断出来filter与compared[attr]相容或相斥,此条件无影响
|
|
531
1030
|
}
|
|
532
1031
|
else if (attr2.toLowerCase() === '$text') {
|
|
533
|
-
|
|
1032
|
+
// 相当于缩小了filter的查询结果集,若其它条件能判断出来filter与compared[attr]相容或相斥,此条件无影响
|
|
534
1033
|
}
|
|
535
1034
|
else {
|
|
1035
|
+
var rel = (0, relation_1.judgeRelation)(schema, entity, attr2);
|
|
536
1036
|
if (attr === attr2) {
|
|
537
|
-
var rel = (0, relation_1.judgeRelation)(schema, entity, attr2);
|
|
538
1037
|
if (rel === 1) {
|
|
539
|
-
|
|
1038
|
+
var r = judgeValueRelation(filter[attr2], comparedFilterAttrValue, contained);
|
|
1039
|
+
if (typeof r === 'boolean') {
|
|
1040
|
+
return r;
|
|
1041
|
+
}
|
|
540
1042
|
}
|
|
541
1043
|
else if (rel === 2) {
|
|
542
|
-
|
|
1044
|
+
var r = judgeFilterRelation(attr2, schema, filter[attr2], comparedFilterAttrValue, contained);
|
|
1045
|
+
if (typeof r === 'boolean') {
|
|
1046
|
+
return r;
|
|
1047
|
+
}
|
|
1048
|
+
else if (typeof r === 'object') {
|
|
1049
|
+
orDeducedFilters.push(r);
|
|
1050
|
+
}
|
|
543
1051
|
}
|
|
544
1052
|
else if (typeof rel === 'string') {
|
|
545
|
-
|
|
1053
|
+
var r = judgeFilterRelation(rel, schema, filter[attr2], comparedFilterAttrValue, contained);
|
|
1054
|
+
if (typeof r === 'boolean') {
|
|
1055
|
+
return r;
|
|
1056
|
+
}
|
|
1057
|
+
else if (typeof r === 'object') {
|
|
1058
|
+
orDeducedFilters.push(r);
|
|
1059
|
+
}
|
|
546
1060
|
}
|
|
547
1061
|
else {
|
|
548
|
-
|
|
1062
|
+
// todo 一对多如何判定?
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
else if (rel === 2 && attr === 'entity' && comparedFilterAttrValue === attr2 && compared.hasOwnProperty('entityId')) {
|
|
1066
|
+
// compared指定了entity和entityId,而filter指定了该entity上的查询条件,此时转而比较此entity上的filter
|
|
1067
|
+
var r = judgeFilterRelation(attr2, schema, filter[attr2], {
|
|
1068
|
+
id: compared.entityId
|
|
1069
|
+
}, contained);
|
|
1070
|
+
if (typeof r === 'boolean') {
|
|
1071
|
+
return r;
|
|
1072
|
+
}
|
|
1073
|
+
else if (typeof r === 'object') {
|
|
1074
|
+
orDeducedFilters.push(r);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
else if (typeof rel === 'string' && attr === "".concat(attr2, "Id")) {
|
|
1078
|
+
// compared指定了外键,而filter指定了该外键对象上的查询条件,此时转而比较此entity上的filter
|
|
1079
|
+
var r = judgeFilterRelation(rel, schema, filter[attr2], {
|
|
1080
|
+
id: comparedFilterAttrValue
|
|
1081
|
+
}, contained);
|
|
1082
|
+
if (typeof r === 'boolean') {
|
|
1083
|
+
return r;
|
|
1084
|
+
}
|
|
1085
|
+
else if (typeof r === 'object') {
|
|
1086
|
+
orDeducedFilters.push(r);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
var rel2 = (0, relation_1.judgeRelation)(schema, entity, attr);
|
|
1091
|
+
if (rel2 === 2 && attr2 === 'entity' && filter[attr2] === attr && filter.hasOwnProperty('entityId')) {
|
|
1092
|
+
// filter限制了外键范围,而compared指定了该外键对象上的查询条件, 此时转而比较此entity上的filter
|
|
1093
|
+
var r = judgeFilterRelation(attr, schema, {
|
|
1094
|
+
id: filter.entityId,
|
|
1095
|
+
}, comparedFilterAttrValue, contained);
|
|
1096
|
+
if (typeof r === 'boolean') {
|
|
1097
|
+
return r;
|
|
1098
|
+
}
|
|
1099
|
+
else if (typeof r === 'object') {
|
|
1100
|
+
orDeducedFilters.push(r);
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
else if (typeof rel2 === 'string' && attr2 === "".concat(attr, "Id")) {
|
|
1104
|
+
// filter限制了外键范围,而compared指定了该外键对象上的查询条件, 此时转而比较此entity上的filter
|
|
1105
|
+
var r = judgeFilterRelation(rel2, schema, {
|
|
1106
|
+
id: filter[attr2],
|
|
1107
|
+
}, comparedFilterAttrValue, contained);
|
|
1108
|
+
if (typeof r === 'boolean') {
|
|
1109
|
+
return r;
|
|
1110
|
+
}
|
|
1111
|
+
else if (typeof r === 'object') {
|
|
1112
|
+
orDeducedFilters.push(r);
|
|
1113
|
+
}
|
|
549
1114
|
}
|
|
550
1115
|
}
|
|
551
1116
|
}
|
|
552
1117
|
}
|
|
553
|
-
|
|
554
|
-
|
|
1118
|
+
if (orDeducedFilters.length > 0) {
|
|
1119
|
+
return {
|
|
1120
|
+
$or: orDeducedFilters,
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
// 到这里说明无法直接判断此attr上的相容或者相斥,也无法把判定推断到更深层的算子之上
|
|
1124
|
+
return;
|
|
555
1125
|
}
|
|
556
|
-
/**
|
|
1126
|
+
/** 判断filter条件对compared条件是否相容或相斥
|
|
557
1127
|
* @param entity
|
|
558
1128
|
* @param schema
|
|
559
1129
|
* @param filter
|
|
560
|
-
* @param
|
|
561
|
-
* @param contained: true
|
|
1130
|
+
* @param compared
|
|
1131
|
+
* @param contained: true代表判定filter包容compared(filter的查询结果是compared查询结果的子集), false代表判定filter与compared相斥(filter的查询结果与compared没有交集)
|
|
1132
|
+
* @returns 返回true说明肯定相容(相斥),返回false说明无法判定相容(相斥),返回DeducedFilterCombination说明需要进一步判断此推断的条件
|
|
562
1133
|
*/
|
|
563
|
-
function judgeFilterRelation(entity, schema, filter,
|
|
564
|
-
|
|
1134
|
+
function judgeFilterRelation(entity, schema, filter, compared, contained) {
|
|
1135
|
+
var e_11, _a, e_12, _b;
|
|
1136
|
+
var totalAndDeducedFilters = [];
|
|
1137
|
+
var totalOrDeducedFilters = [];
|
|
1138
|
+
var uncertainAttributes = [];
|
|
1139
|
+
var sureAttributes = []; // 对包容查询,肯定此属性可包容;对相斥查询,肯定此属性不相斥
|
|
1140
|
+
for (var attr in compared) {
|
|
1141
|
+
var result = undefined;
|
|
1142
|
+
var deducedCombinations = [];
|
|
565
1143
|
if (['$and', '$or', '$not'].includes(attr)) {
|
|
566
1144
|
switch (attr) {
|
|
567
|
-
case '$and':
|
|
1145
|
+
case '$and': {
|
|
1146
|
+
var logicQueries = compared[attr];
|
|
1147
|
+
var results = logicQueries.map(function (logicQuery) { return judgeFilterRelation(entity, schema, filter, logicQuery, contained); });
|
|
1148
|
+
var andDeducedFilters = [];
|
|
1149
|
+
var orDeducedFilters = [];
|
|
1150
|
+
try {
|
|
1151
|
+
for (var results_2 = (e_11 = void 0, tslib_1.__values(results)), results_2_1 = results_2.next(); !results_2_1.done; results_2_1 = results_2.next()) {
|
|
1152
|
+
var r = results_2_1.value;
|
|
1153
|
+
if (contained) {
|
|
1154
|
+
// 如果是包容关系,需要全部被包容,有一个被证伪就已经失败了
|
|
1155
|
+
if (r === false) {
|
|
1156
|
+
result = false;
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
else if (r === undefined) {
|
|
1160
|
+
// 有一个无法判断就放弃
|
|
1161
|
+
andDeducedFilters.splice(0, andDeducedFilters.length);
|
|
1162
|
+
result = undefined;
|
|
1163
|
+
break;
|
|
1164
|
+
}
|
|
1165
|
+
else if (typeof r === 'object') {
|
|
1166
|
+
andDeducedFilters.push(r);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
else {
|
|
1170
|
+
(0, assert_1.default)(!contained);
|
|
1171
|
+
// 如果是相斥关系,只要和一个相斥就可以,有一个被证实就成功了
|
|
1172
|
+
if (r === true) {
|
|
1173
|
+
orDeducedFilters.splice(0, orDeducedFilters.length);
|
|
1174
|
+
result = true;
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
else if (typeof r === 'object') {
|
|
1178
|
+
orDeducedFilters.push(r);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
1184
|
+
finally {
|
|
1185
|
+
try {
|
|
1186
|
+
if (results_2_1 && !results_2_1.done && (_a = results_2.return)) _a.call(results_2);
|
|
1187
|
+
}
|
|
1188
|
+
finally { if (e_11) throw e_11.error; }
|
|
1189
|
+
}
|
|
1190
|
+
if (andDeducedFilters.length > 0) {
|
|
1191
|
+
deducedCombinations.push({
|
|
1192
|
+
$and: andDeducedFilters,
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
if (orDeducedFilters.length > 0) {
|
|
1196
|
+
deducedCombinations.push({
|
|
1197
|
+
$or: orDeducedFilters,
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
568
1202
|
case '$or': {
|
|
569
|
-
var logicQueries =
|
|
1203
|
+
var logicQueries = compared[attr];
|
|
570
1204
|
var results = logicQueries.map(function (logicQuery) { return judgeFilterRelation(entity, schema, filter, logicQuery, contained); });
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1205
|
+
var andDeducedFilters = [];
|
|
1206
|
+
var orDeducedFilters = [];
|
|
1207
|
+
try {
|
|
1208
|
+
for (var results_3 = (e_12 = void 0, tslib_1.__values(results)), results_3_1 = results_3.next(); !results_3_1.done; results_3_1 = results_3.next()) {
|
|
1209
|
+
var r = results_3_1.value;
|
|
1210
|
+
if (contained) {
|
|
1211
|
+
// 如果是包容关系,只要包容一个(是其查询子集)就可以
|
|
1212
|
+
if (r === true) {
|
|
1213
|
+
orDeducedFilters.splice(0, orDeducedFilters.length);
|
|
1214
|
+
result = true;
|
|
1215
|
+
break;
|
|
1216
|
+
}
|
|
1217
|
+
else if (typeof r === 'object') {
|
|
1218
|
+
// 这里不能把or下降到所有的查询中去分别判定,有可能此条件需要多个compared中的情况来共同满足
|
|
1219
|
+
// orDeducedFilters.push(r);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
(0, assert_1.default)(!contained);
|
|
1224
|
+
// 如果是相斥关系,必须和每一个都相斥
|
|
1225
|
+
if (r === false) {
|
|
1226
|
+
result = false;
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
else if (r === undefined) {
|
|
1230
|
+
// 有一个无法判断就放弃
|
|
1231
|
+
andDeducedFilters.splice(0, andDeducedFilters.length);
|
|
1232
|
+
result = undefined;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
else if (typeof r === 'object') {
|
|
1236
|
+
andDeducedFilters.push(r);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
575
1239
|
}
|
|
576
1240
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
return
|
|
1241
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
1242
|
+
finally {
|
|
1243
|
+
try {
|
|
1244
|
+
if (results_3_1 && !results_3_1.done && (_b = results_3.return)) _b.call(results_3);
|
|
581
1245
|
}
|
|
1246
|
+
finally { if (e_12) throw e_12.error; }
|
|
582
1247
|
}
|
|
583
|
-
|
|
584
|
-
|
|
1248
|
+
if (andDeducedFilters.length > 0) {
|
|
1249
|
+
deducedCombinations.push({
|
|
1250
|
+
$and: andDeducedFilters,
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
if (orDeducedFilters.length > 0) {
|
|
1254
|
+
deducedCombinations.push({
|
|
1255
|
+
$or: orDeducedFilters,
|
|
1256
|
+
});
|
|
585
1257
|
}
|
|
586
1258
|
break;
|
|
587
1259
|
}
|
|
588
1260
|
case '$not': {
|
|
589
1261
|
/**
|
|
590
|
-
* 若filter与
|
|
591
|
-
* 若filter将
|
|
1262
|
+
* 若filter与compared not所定义的部分相斥,则filter与conditionalFilter相容
|
|
1263
|
+
* 若filter将compared not所定义的部分包容,则filter与conditionalFilter相斥
|
|
592
1264
|
*/
|
|
593
|
-
var logicQuery =
|
|
1265
|
+
var logicQuery = compared[attr];
|
|
594
1266
|
if (contained) {
|
|
595
|
-
|
|
596
|
-
|
|
1267
|
+
var r = judgeFilterRelation(entity, schema, filter, logicQuery, false);
|
|
1268
|
+
if (r === true) {
|
|
1269
|
+
result = true;
|
|
1270
|
+
}
|
|
1271
|
+
else if (typeof r === 'object') {
|
|
1272
|
+
deducedCombinations.push(r);
|
|
597
1273
|
}
|
|
598
1274
|
}
|
|
599
1275
|
else {
|
|
600
|
-
|
|
601
|
-
|
|
1276
|
+
var r = judgeFilterRelation(entity, schema, filter, logicQuery, true);
|
|
1277
|
+
if (r === true) {
|
|
1278
|
+
result = true;
|
|
1279
|
+
}
|
|
1280
|
+
else if (typeof r === 'object') {
|
|
1281
|
+
deducedCombinations.push(r);
|
|
602
1282
|
}
|
|
603
1283
|
}
|
|
604
1284
|
break;
|
|
@@ -609,28 +1289,95 @@ function judgeFilterRelation(entity, schema, filter, conditionalFilter, containe
|
|
|
609
1289
|
}
|
|
610
1290
|
}
|
|
611
1291
|
else if (attr.toLowerCase().startsWith(types_1.EXPRESSION_PREFIX)) {
|
|
612
|
-
|
|
1292
|
+
// 相当于缩小了compared查询结果,如果是判定相斥,对结果无影响,如果是判定相容,则认为无法判定,
|
|
1293
|
+
if (contained) {
|
|
1294
|
+
result = undefined;
|
|
1295
|
+
}
|
|
613
1296
|
}
|
|
614
1297
|
else if (attr.toLowerCase() === '$text') {
|
|
615
|
-
|
|
1298
|
+
// 相当于缩小了compared查询结果,如果是判定相斥,对结果无影响,如果是判定相容,则认为无法判定,
|
|
1299
|
+
if (contained) {
|
|
1300
|
+
result = undefined;
|
|
1301
|
+
}
|
|
616
1302
|
}
|
|
617
1303
|
else {
|
|
618
|
-
|
|
619
|
-
|
|
1304
|
+
var r = judgeFilterSingleAttrRelation(entity, schema, attr, filter, compared, contained);
|
|
1305
|
+
if (typeof r === 'object') {
|
|
1306
|
+
deducedCombinations.push(r);
|
|
1307
|
+
}
|
|
1308
|
+
else {
|
|
1309
|
+
result = r;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
if (contained) {
|
|
1313
|
+
// 相容必须compared中的每个属性都被相容
|
|
1314
|
+
if (result === true) {
|
|
1315
|
+
sureAttributes.push(attr);
|
|
1316
|
+
}
|
|
1317
|
+
else if (result === false) {
|
|
620
1318
|
return false;
|
|
621
1319
|
}
|
|
622
|
-
if (
|
|
623
|
-
|
|
1320
|
+
else if (deducedCombinations.length > 0) {
|
|
1321
|
+
totalAndDeducedFilters.push.apply(totalAndDeducedFilters, tslib_1.__spreadArray([], tslib_1.__read(deducedCombinations), false));
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
// 判定不了,也推断不了
|
|
1325
|
+
uncertainAttributes.push(attr);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
// 相斥只要有一个被肻定就可以返回true了
|
|
1330
|
+
if (result === true) {
|
|
624
1331
|
return true;
|
|
625
1332
|
}
|
|
1333
|
+
else if (result === false) {
|
|
1334
|
+
sureAttributes.push(attr);
|
|
1335
|
+
}
|
|
1336
|
+
else if (deducedCombinations.length > 0) {
|
|
1337
|
+
totalOrDeducedFilters.push.apply(totalOrDeducedFilters, tslib_1.__spreadArray([], tslib_1.__read(deducedCombinations), false));
|
|
1338
|
+
}
|
|
1339
|
+
else {
|
|
1340
|
+
// 判定不了,也推断不了
|
|
1341
|
+
uncertainAttributes.push(attr);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
if (contained) {
|
|
1346
|
+
if (sureAttributes.length === Object.keys(compared).length) {
|
|
1347
|
+
return true;
|
|
1348
|
+
}
|
|
1349
|
+
if (uncertainAttributes.length > 0) {
|
|
1350
|
+
// 有属性无法界定,此时只能拿本行去查询
|
|
1351
|
+
totalAndDeducedFilters.push({
|
|
1352
|
+
entity: entity,
|
|
1353
|
+
filter: combineFilters(entity, schema, [filter, {
|
|
1354
|
+
$not: (0, lodash_1.pick)(compared, uncertainAttributes),
|
|
1355
|
+
}]),
|
|
1356
|
+
});
|
|
626
1357
|
}
|
|
1358
|
+
return {
|
|
1359
|
+
$and: totalAndDeducedFilters,
|
|
1360
|
+
};
|
|
1361
|
+
}
|
|
1362
|
+
else {
|
|
1363
|
+
if (sureAttributes.length === Object.keys(compared).length) {
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1366
|
+
// uncertainAttributes中是无法判定的属性,和filter合并之后(同时满足)的查询结果如果不为空说明不互斥
|
|
1367
|
+
if (uncertainAttributes.length > 0) {
|
|
1368
|
+
totalOrDeducedFilters.push({
|
|
1369
|
+
entity: entity,
|
|
1370
|
+
filter: combineFilters(entity, schema, [filter, (0, lodash_1.pick)(compared, uncertainAttributes)]),
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
$or: totalOrDeducedFilters,
|
|
1375
|
+
};
|
|
627
1376
|
}
|
|
628
|
-
// 到这里说明不能否定其相容(所以要返回相容),也不能肯定其相斥(所以要返回不相斥)
|
|
629
|
-
return contained;
|
|
630
1377
|
}
|
|
631
1378
|
/**
|
|
632
1379
|
*
|
|
633
|
-
* 判断filter是否包含
|
|
1380
|
+
* 判断filter是否包含contained中的查询条件,即filter查询的结果一定是contained查询结果的子集
|
|
634
1381
|
* filter = {
|
|
635
1382
|
* a: 1
|
|
636
1383
|
* b: 2,
|
|
@@ -643,11 +1390,13 @@ function judgeFilterRelation(entity, schema, filter, conditionalFilter, containe
|
|
|
643
1390
|
* @param entity
|
|
644
1391
|
* @param schema
|
|
645
1392
|
* @param filter
|
|
646
|
-
* @param
|
|
1393
|
+
* @param contained
|
|
647
1394
|
* @returns
|
|
648
1395
|
*/
|
|
649
|
-
function contains(entity, schema, filter,
|
|
650
|
-
|
|
1396
|
+
function contains(entity, schema, filter, contained) {
|
|
1397
|
+
(0, assert_1.default)(filter);
|
|
1398
|
+
(0, assert_1.default)(contained);
|
|
1399
|
+
return judgeFilterRelation(entity, schema, filter, contained, true);
|
|
651
1400
|
// return false;
|
|
652
1401
|
}
|
|
653
1402
|
exports.contains = contains;
|
|
@@ -666,7 +1415,8 @@ exports.contains = contains;
|
|
|
666
1415
|
* @param conditionalFilter
|
|
667
1416
|
*/
|
|
668
1417
|
function repel(entity, schema, filter1, filter2) {
|
|
669
|
-
|
|
1418
|
+
(0, assert_1.default)(filter1);
|
|
1419
|
+
(0, assert_1.default)(filter2);
|
|
670
1420
|
return judgeFilterRelation(entity, schema, filter1, filter2, false);
|
|
671
1421
|
// return false;
|
|
672
1422
|
}
|
|
@@ -820,8 +1570,113 @@ function makeTreeDescendantFilter(entity, parentKey, filter, level, includeAll,
|
|
|
820
1570
|
return currentLevelInFilter;
|
|
821
1571
|
}
|
|
822
1572
|
exports.makeTreeDescendantFilter = makeTreeDescendantFilter;
|
|
1573
|
+
function checkDeduceFilters(dfc, context) {
|
|
1574
|
+
var e_13, _a, e_14, _b;
|
|
1575
|
+
var $and = dfc.$and, $or = dfc.$or;
|
|
1576
|
+
if ($and) {
|
|
1577
|
+
(0, assert_1.default)(!$or);
|
|
1578
|
+
var andResult = $and.map(function (ele) {
|
|
1579
|
+
if (ele.hasOwnProperty('entity')) {
|
|
1580
|
+
var ele2_1 = ele;
|
|
1581
|
+
return context.count(ele2_1.entity, {
|
|
1582
|
+
filter: ele2_1.filter
|
|
1583
|
+
}, {});
|
|
1584
|
+
}
|
|
1585
|
+
var ele2 = ele;
|
|
1586
|
+
return checkDeduceFilters(ele2, context);
|
|
1587
|
+
});
|
|
1588
|
+
// and 意味着只要有一个条件失败就返回false
|
|
1589
|
+
if (andResult.find(function (ele) { return ele instanceof Promise; })) {
|
|
1590
|
+
return Promise.all(andResult).then(function (ar) {
|
|
1591
|
+
var e_15, _a;
|
|
1592
|
+
try {
|
|
1593
|
+
for (var ar_1 = tslib_1.__values(ar), ar_1_1 = ar_1.next(); !ar_1_1.done; ar_1_1 = ar_1.next()) {
|
|
1594
|
+
var ele = ar_1_1.value;
|
|
1595
|
+
if (ele === false || typeof ele === 'number' && ele > 0) {
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1601
|
+
finally {
|
|
1602
|
+
try {
|
|
1603
|
+
if (ar_1_1 && !ar_1_1.done && (_a = ar_1.return)) _a.call(ar_1);
|
|
1604
|
+
}
|
|
1605
|
+
finally { if (e_15) throw e_15.error; }
|
|
1606
|
+
}
|
|
1607
|
+
return true;
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
try {
|
|
1611
|
+
for (var andResult_1 = tslib_1.__values(andResult), andResult_1_1 = andResult_1.next(); !andResult_1_1.done; andResult_1_1 = andResult_1.next()) {
|
|
1612
|
+
var ele = andResult_1_1.value;
|
|
1613
|
+
if (ele === false || typeof ele === 'number' && ele > 0) {
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1619
|
+
finally {
|
|
1620
|
+
try {
|
|
1621
|
+
if (andResult_1_1 && !andResult_1_1.done && (_a = andResult_1.return)) _a.call(andResult_1);
|
|
1622
|
+
}
|
|
1623
|
+
finally { if (e_13) throw e_13.error; }
|
|
1624
|
+
}
|
|
1625
|
+
return true;
|
|
1626
|
+
}
|
|
1627
|
+
(0, assert_1.default)($or);
|
|
1628
|
+
var orResult = $or.map(function (ele) {
|
|
1629
|
+
if (ele.hasOwnProperty('entity')) {
|
|
1630
|
+
var ele2_2 = ele;
|
|
1631
|
+
return context.count(ele2_2.entity, {
|
|
1632
|
+
filter: ele2_2.filter
|
|
1633
|
+
}, {});
|
|
1634
|
+
}
|
|
1635
|
+
var ele2 = ele;
|
|
1636
|
+
return checkDeduceFilters(ele2, context);
|
|
1637
|
+
});
|
|
1638
|
+
// or只要有一个条件通过就返回true
|
|
1639
|
+
if (orResult.find(function (ele) { return ele instanceof Promise; })) {
|
|
1640
|
+
return Promise.all(orResult).then(function (or) {
|
|
1641
|
+
var e_16, _a;
|
|
1642
|
+
try {
|
|
1643
|
+
for (var or_1 = tslib_1.__values(or), or_1_1 = or_1.next(); !or_1_1.done; or_1_1 = or_1.next()) {
|
|
1644
|
+
var ele = or_1_1.value;
|
|
1645
|
+
if (ele === true || ele === 0) {
|
|
1646
|
+
return true;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1651
|
+
finally {
|
|
1652
|
+
try {
|
|
1653
|
+
if (or_1_1 && !or_1_1.done && (_a = or_1.return)) _a.call(or_1);
|
|
1654
|
+
}
|
|
1655
|
+
finally { if (e_16) throw e_16.error; }
|
|
1656
|
+
}
|
|
1657
|
+
return false;
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
try {
|
|
1661
|
+
for (var orResult_1 = tslib_1.__values(orResult), orResult_1_1 = orResult_1.next(); !orResult_1_1.done; orResult_1_1 = orResult_1.next()) {
|
|
1662
|
+
var ele = orResult_1_1.value;
|
|
1663
|
+
if (ele === true || ele === 0) {
|
|
1664
|
+
return true;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1669
|
+
finally {
|
|
1670
|
+
try {
|
|
1671
|
+
if (orResult_1_1 && !orResult_1_1.done && (_b = orResult_1.return)) _b.call(orResult_1);
|
|
1672
|
+
}
|
|
1673
|
+
finally { if (e_14) throw e_14.error; }
|
|
1674
|
+
}
|
|
1675
|
+
return false;
|
|
1676
|
+
}
|
|
1677
|
+
exports.checkDeduceFilters = checkDeduceFilters;
|
|
823
1678
|
/**
|
|
824
|
-
* 检查filter是否包含contained(filter
|
|
1679
|
+
* 检查filter是否包含contained(filter查询的数据是contained查询数据的子集)
|
|
825
1680
|
* @param entity
|
|
826
1681
|
* @param context
|
|
827
1682
|
* @param contained
|
|
@@ -834,26 +1689,12 @@ function checkFilterContains(entity, context, contained, filter, dataCompare) {
|
|
|
834
1689
|
throw new types_1.OakRowInconsistencyException();
|
|
835
1690
|
}
|
|
836
1691
|
var schema = context.getSchema();
|
|
837
|
-
|
|
838
|
-
if (
|
|
839
|
-
return
|
|
1692
|
+
var result = contains(entity, schema, filter, contained);
|
|
1693
|
+
if (typeof result === 'boolean') {
|
|
1694
|
+
return result;
|
|
840
1695
|
}
|
|
841
1696
|
if (dataCompare) {
|
|
842
|
-
|
|
843
|
-
var filter2 = combineFilters([filter, {
|
|
844
|
-
$not: contained,
|
|
845
|
-
}]);
|
|
846
|
-
var count = context.count(entity, {
|
|
847
|
-
filter: filter2,
|
|
848
|
-
count: 1,
|
|
849
|
-
}, {
|
|
850
|
-
dontCollect: true,
|
|
851
|
-
blockTrigger: true,
|
|
852
|
-
});
|
|
853
|
-
if (count instanceof Promise) {
|
|
854
|
-
return count.then(function (count2) { return count2 === 0; });
|
|
855
|
-
}
|
|
856
|
-
return count === 0;
|
|
1697
|
+
return checkDeduceFilters(result, context);
|
|
857
1698
|
}
|
|
858
1699
|
return false;
|
|
859
1700
|
}
|
|
@@ -863,43 +1704,36 @@ function checkFilterRepel(entity, context, filter1, filter2, dataCompare) {
|
|
|
863
1704
|
throw new types_1.OakRowInconsistencyException();
|
|
864
1705
|
}
|
|
865
1706
|
var schema = context.getSchema();
|
|
866
|
-
|
|
867
|
-
if (
|
|
868
|
-
return
|
|
1707
|
+
var result = repel(entity, schema, filter2, filter1);
|
|
1708
|
+
if (typeof result === 'boolean') {
|
|
1709
|
+
return result;
|
|
869
1710
|
}
|
|
870
|
-
// 再判断两者同时成立时取得的行数是否为0
|
|
871
1711
|
if (dataCompare) {
|
|
872
|
-
|
|
873
|
-
var count = context.count(entity, {
|
|
874
|
-
filter: filter3,
|
|
875
|
-
}, {
|
|
876
|
-
dontCollect: true,
|
|
877
|
-
blockTrigger: true,
|
|
878
|
-
});
|
|
879
|
-
if (count instanceof Promise) {
|
|
880
|
-
return count.then(function (count2) { return count2 === 0; });
|
|
881
|
-
}
|
|
882
|
-
return count === 0;
|
|
1712
|
+
return checkDeduceFilters(result, context);
|
|
883
1713
|
}
|
|
884
1714
|
return false;
|
|
885
1715
|
}
|
|
886
1716
|
exports.checkFilterRepel = checkFilterRepel;
|
|
887
|
-
function getCascadeEntityFilter
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1717
|
+
/* export function getCascadeEntityFilter<ED extends EntityDict & BaseEntityDict, T extends keyof ED>(
|
|
1718
|
+
filter: NonNullable<ED[T]['Selection']['filter']>,
|
|
1719
|
+
attr: keyof NonNullable<ED[T]['Selection']['filter']>
|
|
1720
|
+
): ED[keyof ED]['Selection']['filter'] {
|
|
1721
|
+
const filters: ED[keyof ED]['Selection']['filter'][] = [];
|
|
1722
|
+
if (filter![attr]) {
|
|
1723
|
+
assert(typeof filter![attr] === 'object');
|
|
1724
|
+
filters.push(filter![attr]);
|
|
892
1725
|
}
|
|
893
1726
|
if (filter.$and) {
|
|
894
|
-
filter.$and.forEach(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
1727
|
+
filter.$and.forEach(
|
|
1728
|
+
(ele: NonNullable<ED[T]['Selection']['filter']>) => {
|
|
1729
|
+
const f2 = getCascadeEntityFilter(ele, attr);
|
|
1730
|
+
if (f2) {
|
|
1731
|
+
filters.push(f2)
|
|
1732
|
+
}
|
|
898
1733
|
}
|
|
899
|
-
|
|
1734
|
+
);
|
|
900
1735
|
}
|
|
901
1736
|
if (filters.length > 0) {
|
|
902
1737
|
return combineFilters(filters);
|
|
903
1738
|
}
|
|
904
|
-
}
|
|
905
|
-
exports.getCascadeEntityFilter = getCascadeEntityFilter;
|
|
1739
|
+
} */
|