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