@devisfuture/mega-collection 2.4.7 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -75
- package/dist/{State.d.ts → State-CYIe-3He.d.ts} +5 -3
- package/dist/chunks/constants-DK9S0Db0.mjs +1 -0
- package/dist/chunks/merge-C6intZSe.mjs +1 -0
- package/dist/filter/index.d.ts +114 -4
- package/dist/filter/index.mjs +1 -2
- package/dist/index.d.ts +2 -4
- package/dist/index.mjs +1 -2
- package/dist/merge/index.d.ts +131 -4
- package/dist/merge/index.mjs +1 -2
- package/dist/search/index.d.ts +191 -4
- package/dist/search/index.mjs +1 -2
- package/dist/sort/index.d.ts +57 -4
- package/dist/sort/index.mjs +1 -2
- package/dist/types-DONld7xY.d.ts +74 -0
- package/package.json +6 -2
- package/dist/State.mjs +0 -183
- package/dist/constants.d.ts +0 -5
- package/dist/constants.mjs +0 -4
- package/dist/filter/chain.d.ts +0 -9
- package/dist/filter/chain.mjs +0 -22
- package/dist/filter/constants.d.ts +0 -2
- package/dist/filter/criterion.d.ts +0 -6
- package/dist/filter/criterion.mjs +0 -64
- package/dist/filter/errors.d.ts +0 -7
- package/dist/filter/errors.mjs +0 -17
- package/dist/filter/filter.d.ts +0 -89
- package/dist/filter/filter.mjs +0 -439
- package/dist/filter/nested.d.ts +0 -32
- package/dist/filter/nested.mjs +0 -246
- package/dist/filter/types.d.ts +0 -74
- package/dist/filter/utils.d.ts +0 -4
- package/dist/filter/utils.mjs +0 -29
- package/dist/indexer.d.ts +0 -41
- package/dist/indexer.mjs +0 -101
- package/dist/internal.d.ts +0 -6
- package/dist/internal.mjs +0 -18
- package/dist/merge/chain.d.ts +0 -9
- package/dist/merge/chain.mjs +0 -23
- package/dist/merge/constants.d.ts +0 -6
- package/dist/merge/constants.mjs +0 -8
- package/dist/merge/errors.d.ts +0 -8
- package/dist/merge/errors.mjs +0 -19
- package/dist/merge/merge-engines.d.ts +0 -75
- package/dist/merge/merge-engines.mjs +0 -432
- package/dist/merge/module-adapters.d.ts +0 -7
- package/dist/merge/module-adapters.mjs +0 -41
- package/dist/merge/types.d.ts +0 -125
- package/dist/search/constants.d.ts +0 -5
- package/dist/search/nested.d.ts +0 -41
- package/dist/search/nested.mjs +0 -210
- package/dist/search/ngram.d.ts +0 -23
- package/dist/search/ngram.mjs +0 -96
- package/dist/search/text-search.d.ts +0 -146
- package/dist/search/text-search.mjs +0 -696
- package/dist/search/types.d.ts +0 -93
- package/dist/search/utils.d.ts +0 -4
- package/dist/search/utils.mjs +0 -22
- package/dist/sort/errors.d.ts +0 -5
- package/dist/sort/errors.mjs +0 -11
- package/dist/sort/sorter.d.ts +0 -47
- package/dist/sort/sorter.mjs +0 -375
- package/dist/sort/types.d.ts +0 -18
- package/dist/sort/utils.d.ts +0 -17
- package/dist/sort/utils.mjs +0 -38
- package/dist/types.d.ts +0 -73
package/dist/filter/filter.mjs
DELETED
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
import { State as e } from "../State.mjs";
|
|
2
|
-
import { DEFER_FILTER_MUTATION_INDEX_UPDATES_KEY as t, MERGE_SHARED_SCOPE as n } from "../constants.mjs";
|
|
3
|
-
import { Indexer as r } from "../indexer.mjs";
|
|
4
|
-
import { FilterEngineChainBuilder as i } from "./chain.mjs";
|
|
5
|
-
import { FilterEngineError as a } from "./errors.mjs";
|
|
6
|
-
import { isCriterionUnsatisfiable as o, matchesCriterionValue as s, resolveCriteria as c } from "./criterion.mjs";
|
|
7
|
-
import { FilterNestedCollection as l } from "./nested.mjs";
|
|
8
|
-
import { createFilterRuntime as u } from "./utils.mjs";
|
|
9
|
-
//#region src/filter/filter.ts
|
|
10
|
-
var d = class {
|
|
11
|
-
constructor(t = {}) {
|
|
12
|
-
this.chainBuilder = new i({
|
|
13
|
-
filter: (e, t) => t === void 0 ? this.filter(e) : this.filter(e, t),
|
|
14
|
-
getOriginData: () => this.getOriginData(),
|
|
15
|
-
add: (e) => this.add(e),
|
|
16
|
-
update: (e) => this.update(e),
|
|
17
|
-
data: (e) => this.data(e),
|
|
18
|
-
clearIndexes: () => this.clearIndexes(),
|
|
19
|
-
clearData: () => this.clearData(),
|
|
20
|
-
resetFilterState: () => this.resetFilterState()
|
|
21
|
-
}), this.mutableExcludeField = t.mutableExcludeField ?? null, this.state = t.state ?? new e(t.data ?? [], { filterByPreviousResult: t.filterByPreviousResult ?? !1 }), t.state && t.filterByPreviousResult && this.state.setFilterByPreviousResult(!0), this.filterByPreviousResult = this.state.isFilterByPreviousResultEnabled(), this.namespace = this.state.createNamespace("filter"), this.indexer = new r(this.runtime.indexerStorage), this.nestedCollection = new l(this.runtime.nestedStorage), this.nestedCollection.registerFields(t.nestedFields), this.state.subscribe((e) => this.handleStateMutation(e)), this.rebuildMutableExcludeState();
|
|
22
|
-
let n = t.fields?.length, a = this.nestedCollection.hasRegisteredFields();
|
|
23
|
-
if (n) for (let e of t.fields) this.indexedFields.add(e);
|
|
24
|
-
this.dataset.length > 0 && (n || a) && this.rebuildConfiguredIndexes();
|
|
25
|
-
}
|
|
26
|
-
get dataset() {
|
|
27
|
-
return this.state.getOriginData();
|
|
28
|
-
}
|
|
29
|
-
get runtime() {
|
|
30
|
-
return this.state.getOrCreateScopedValue(this.namespace, "runtime", u);
|
|
31
|
-
}
|
|
32
|
-
get mutableExcludeState() {
|
|
33
|
-
return this.runtime.mutableExclude;
|
|
34
|
-
}
|
|
35
|
-
get indexedFields() {
|
|
36
|
-
return this.runtime.indexedFields;
|
|
37
|
-
}
|
|
38
|
-
get sequentialCache() {
|
|
39
|
-
return this.runtime.sequentialCache;
|
|
40
|
-
}
|
|
41
|
-
shouldDeferMutationIndexUpdates() {
|
|
42
|
-
return this.state.getScopedValue(n, t) === !0;
|
|
43
|
-
}
|
|
44
|
-
markDeferredMutationState() {
|
|
45
|
-
this.runtime.deferredMutationVersion = this.state.getMutationVersion(), this.indexer.clear(), this.nestedCollection.clearIndexes(), this.clearMutableExcludeState(), this.resetFilterState();
|
|
46
|
-
}
|
|
47
|
-
ensureRuntimeReady() {
|
|
48
|
-
this.runtime.deferredMutationVersion !== null && (this.runtime.deferredMutationVersion = null, this.rebuildMutableExcludeState(), this.dataset.length > 0 && (this.indexedFields.size > 0 || this.nestedCollection.hasRegisteredFields()) && this.rebuildConfiguredIndexes());
|
|
49
|
-
}
|
|
50
|
-
rebuildConfiguredIndexes() {
|
|
51
|
-
this.indexer.clear(), this.nestedCollection.clearIndexes();
|
|
52
|
-
for (let e of this.indexedFields) this.buildIndex(this.dataset, e);
|
|
53
|
-
this.nestedCollection.hasRegisteredFields() && this.nestedCollection.buildIndexes(this.dataset);
|
|
54
|
-
}
|
|
55
|
-
buildIndex(e, t) {
|
|
56
|
-
if (!Array.isArray(e)) {
|
|
57
|
-
if (!this.dataset.length) throw a.missingDatasetForBuildIndex();
|
|
58
|
-
return this.indexer.buildIndex(this.dataset, e), this;
|
|
59
|
-
}
|
|
60
|
-
return this.resetFilterState(), this.rebuildMutableExcludeState(), this.indexer.buildIndex(e, t), this;
|
|
61
|
-
}
|
|
62
|
-
clearIndexes() {
|
|
63
|
-
return this.indexer.clear(), this.nestedCollection.clearIndexes(), this;
|
|
64
|
-
}
|
|
65
|
-
resetFilterState() {
|
|
66
|
-
return this.sequentialCache.previousResult = null, this.sequentialCache.previousCriteria = null, this.sequentialCache.previousCriteriaKey = null, this.sequentialCache.previousBaseData = null, this.sequentialCache.previousResultsByCriteria.clear(), this.sequentialCache.previousResultSet = null, this.state.clearPreviousResult(), this;
|
|
67
|
-
}
|
|
68
|
-
clearData() {
|
|
69
|
-
return this.state.clearData(), this;
|
|
70
|
-
}
|
|
71
|
-
data(e) {
|
|
72
|
-
return this.state.data(e), this;
|
|
73
|
-
}
|
|
74
|
-
add(e) {
|
|
75
|
-
return this.state.add(e), this;
|
|
76
|
-
}
|
|
77
|
-
update(e) {
|
|
78
|
-
return this.state.update(e), this;
|
|
79
|
-
}
|
|
80
|
-
applyAddedItems(e, t) {
|
|
81
|
-
return e.length === 0 ? this : (this.updateMutableExcludeStateForAddedItems(e, t), this.resetFilterState(), this.indexer.addItems(e), this.nestedCollection.addItems(e), this);
|
|
82
|
-
}
|
|
83
|
-
getOriginData() {
|
|
84
|
-
return this.state.getOriginData();
|
|
85
|
-
}
|
|
86
|
-
filter(e, t) {
|
|
87
|
-
return t === void 0 ? this.withChain(this.rawFilter(e)) : this.withChain(this.rawFilter(e, t));
|
|
88
|
-
}
|
|
89
|
-
rawFilter(e, t) {
|
|
90
|
-
this.ensureRuntimeReady();
|
|
91
|
-
let n = t === void 0;
|
|
92
|
-
if (n && !this.dataset.length) throw a.missingDatasetForFilter();
|
|
93
|
-
let r = c(n ? e : t), i = n ? this.dataset : e;
|
|
94
|
-
if (n) {
|
|
95
|
-
let e = this.applyMutableExclude(r);
|
|
96
|
-
if (e !== void 0) return e;
|
|
97
|
-
}
|
|
98
|
-
let s = i, l = r;
|
|
99
|
-
if (this.filterByPreviousResult) {
|
|
100
|
-
let e = this.resolveWithSequentialCache(i, n, r);
|
|
101
|
-
if (e.isFromCache) return e.result;
|
|
102
|
-
s = e.sourceData, l = e.executionCriteria;
|
|
103
|
-
}
|
|
104
|
-
if (r.length === 0) return this.filterByPreviousResult && this.resetFilterState(), i;
|
|
105
|
-
for (let e = 0; e < l.length; e++) if (o(l[e])) return this.createEmptyResult(n, i, r);
|
|
106
|
-
let u = [], d = [];
|
|
107
|
-
for (let e = 0; e < l.length; e++) {
|
|
108
|
-
let t = l[e];
|
|
109
|
-
this.nestedCollection.hasField(t.field) ? u.push(t) : d.push(t);
|
|
110
|
-
}
|
|
111
|
-
if (u.length > 0 && (s = this.nestedCollection.filter(s, u, this.dataset), s.length === 0)) return this.createEmptyResult(n, i, r);
|
|
112
|
-
if (d.length === 0) return this.storePreviousResult(s, n, i, r), s;
|
|
113
|
-
let f = [], p = [];
|
|
114
|
-
for (let e = 0; e < d.length; e++) {
|
|
115
|
-
let t = d[e];
|
|
116
|
-
this.indexer.hasIndex(t.field) ? f.push(t) : p.push(t);
|
|
117
|
-
}
|
|
118
|
-
let m;
|
|
119
|
-
if (f.length > 0 && p.length === 0) return m = this.filterViaIndex(f, s), this.storePreviousResult(m, n, i, r), m;
|
|
120
|
-
if (f.length > 0 && p.length > 0) {
|
|
121
|
-
let e = this.filterViaIndex(f, s);
|
|
122
|
-
return m = this.linearFilter(e, p), this.storePreviousResult(m, n, i, r), m;
|
|
123
|
-
}
|
|
124
|
-
return m = this.linearFilter(s, d), this.storePreviousResult(m, n, i, r), m;
|
|
125
|
-
}
|
|
126
|
-
resolveWithSequentialCache(e, t, n) {
|
|
127
|
-
let { previousResult: r, previousCriteria: i, previousCriteriaKey: a, previousBaseData: o, previousResultsByCriteria: s } = this.sequentialCache;
|
|
128
|
-
if (r === null || i === null || o !== e) return {
|
|
129
|
-
isFromCache: !1,
|
|
130
|
-
sourceData: e,
|
|
131
|
-
executionCriteria: n
|
|
132
|
-
};
|
|
133
|
-
let c = this.createCriteriaCacheKey(n), l = s.get(c);
|
|
134
|
-
if (c === a) return {
|
|
135
|
-
isFromCache: !0,
|
|
136
|
-
result: r
|
|
137
|
-
};
|
|
138
|
-
if (l !== void 0) return this.storePreviousResult(l.result, t, e, n, c, l.resultSet), {
|
|
139
|
-
isFromCache: !0,
|
|
140
|
-
result: l.result
|
|
141
|
-
};
|
|
142
|
-
let u = this.hasCriteriaBacktrack(i, n) || r.length === 0 && !this.canApplySequentiallyToEmptyResult(i, n);
|
|
143
|
-
return {
|
|
144
|
-
isFromCache: !1,
|
|
145
|
-
sourceData: u ? e : r,
|
|
146
|
-
executionCriteria: u ? n : this.createSequentialExecutionCriteria(i, n)
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
withChain(e) {
|
|
150
|
-
return this.chainBuilder.create(e);
|
|
151
|
-
}
|
|
152
|
-
handleStateMutation(e) {
|
|
153
|
-
if (this.shouldDeferMutationIndexUpdates() && (e.type === "add" || e.type === "update")) {
|
|
154
|
-
this.markDeferredMutationState();
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
switch (e.type) {
|
|
158
|
-
case "add":
|
|
159
|
-
this.applyAddedItems(e.items, e.startIndex);
|
|
160
|
-
return;
|
|
161
|
-
case "update":
|
|
162
|
-
this.applyUpdatedItem(e.index, e.previousItem, e.nextItem);
|
|
163
|
-
return;
|
|
164
|
-
case "data":
|
|
165
|
-
this.runtime.deferredMutationVersion = null, this.rebuildMutableExcludeState(), this.resetFilterState(), this.rebuildConfiguredIndexes();
|
|
166
|
-
return;
|
|
167
|
-
case "clearData":
|
|
168
|
-
this.runtime.deferredMutationVersion = null, this.clearMutableExcludeState(), this.indexer.clear(), this.nestedCollection.clearIndexes(), this.resetFilterState();
|
|
169
|
-
return;
|
|
170
|
-
case "remove":
|
|
171
|
-
this.applyRemovedItem(e.field, e.value, e.removedItem, e.removedIndex, e.movedItem);
|
|
172
|
-
return;
|
|
173
|
-
case "removeMany":
|
|
174
|
-
this.applyRemovedItems(e.field, e.entries);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
rebuildMutableExcludeState() {
|
|
179
|
-
if (this.clearMutableExcludeState(), this.mutableExcludeField !== null) for (let e = 0; e < this.dataset.length; e++) {
|
|
180
|
-
let t = this.dataset[e][this.mutableExcludeField];
|
|
181
|
-
t != null && this.registerMutableExcludeValue(t, e);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
updateMutableExcludeStateForAddedItems(e, t) {
|
|
185
|
-
if (this.mutableExcludeField !== null) for (let n = 0; n < e.length; n++) {
|
|
186
|
-
let r = e[n][this.mutableExcludeField];
|
|
187
|
-
r != null && this.registerMutableExcludeValue(r, t + n);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
applyMutableExclude(e) {
|
|
191
|
-
if (this.mutableExcludeField === null || e.length !== 1) return;
|
|
192
|
-
let t = e[0];
|
|
193
|
-
if (!(t.field !== this.mutableExcludeField || t.hasValues || !t.hasExclude)) {
|
|
194
|
-
if (this.mutableExcludeState.hasDuplicateValues) throw a.duplicateMutableExcludeField(this.mutableExcludeField);
|
|
195
|
-
return this.state.removeByFieldValues(this.mutableExcludeField, t.exclude), this.resetFilterState(), this.dataset;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
applyUpdatedItem(e, t, n) {
|
|
199
|
-
this.updateMutableExcludeStateForUpdatedItem(e, t, n), this.resetFilterState(), this.indexer.updateItem(t, n), this.nestedCollection.updateItem(n, t);
|
|
200
|
-
}
|
|
201
|
-
applyRemovedItem(e, t, n, r, i) {
|
|
202
|
-
if (e === this.mutableExcludeField && (this.unregisterMutableExcludeValue(t), this.mutableExcludeState.datasetPositions.delete(t), i !== null && this.mutableExcludeField !== null)) {
|
|
203
|
-
let e = i[this.mutableExcludeField];
|
|
204
|
-
e != null && this.mutableExcludeState.datasetPositions.set(e, r);
|
|
205
|
-
}
|
|
206
|
-
this.resetFilterState(), this.indexer.removeItem(n), this.nestedCollection.removeItem(n);
|
|
207
|
-
}
|
|
208
|
-
applyRemovedItems(e, t) {
|
|
209
|
-
for (let n = 0; n < t.length; n++) {
|
|
210
|
-
let r = t[n];
|
|
211
|
-
if (e === this.mutableExcludeField && (this.unregisterMutableExcludeValue(r.value), this.mutableExcludeState.datasetPositions.delete(r.value), r.movedItem !== null && this.mutableExcludeField !== null)) {
|
|
212
|
-
let e = r.movedItem[this.mutableExcludeField];
|
|
213
|
-
e != null && this.mutableExcludeState.datasetPositions.set(e, r.removedIndex);
|
|
214
|
-
}
|
|
215
|
-
this.indexer.removeItem(r.removedItem), this.nestedCollection.removeItem(r.removedItem);
|
|
216
|
-
}
|
|
217
|
-
this.resetFilterState();
|
|
218
|
-
}
|
|
219
|
-
updateMutableExcludeStateForUpdatedItem(e, t, n) {
|
|
220
|
-
if (this.mutableExcludeField === null) return;
|
|
221
|
-
let r = t[this.mutableExcludeField], i = n[this.mutableExcludeField];
|
|
222
|
-
if (r === i) {
|
|
223
|
-
i != null && this.mutableExcludeState.datasetPositions.set(i, e);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
r != null && (this.unregisterMutableExcludeValue(r), this.mutableExcludeState.datasetPositions.get(r) === e && this.mutableExcludeState.datasetPositions.delete(r)), i != null && this.registerMutableExcludeValue(i, e);
|
|
227
|
-
}
|
|
228
|
-
clearMutableExcludeState() {
|
|
229
|
-
this.mutableExcludeState.datasetPositions.clear(), this.mutableExcludeState.valueCounts.clear(), this.mutableExcludeState.duplicateValueCount = 0, this.mutableExcludeState.hasDuplicateValues = !1;
|
|
230
|
-
}
|
|
231
|
-
registerMutableExcludeValue(e, t) {
|
|
232
|
-
let n = (this.mutableExcludeState.valueCounts.get(e) ?? 0) + 1;
|
|
233
|
-
n === 2 && this.mutableExcludeState.duplicateValueCount++, this.mutableExcludeState.valueCounts.set(e, n), this.mutableExcludeState.datasetPositions.set(e, t), this.mutableExcludeState.hasDuplicateValues = this.mutableExcludeState.duplicateValueCount > 0;
|
|
234
|
-
}
|
|
235
|
-
unregisterMutableExcludeValue(e) {
|
|
236
|
-
let t = this.mutableExcludeState.valueCounts.get(e);
|
|
237
|
-
t !== void 0 && (t === 2 && this.mutableExcludeState.duplicateValueCount--, t <= 1 ? this.mutableExcludeState.valueCounts.delete(e) : this.mutableExcludeState.valueCounts.set(e, t - 1), this.mutableExcludeState.hasDuplicateValues = this.mutableExcludeState.duplicateValueCount > 0);
|
|
238
|
-
}
|
|
239
|
-
linearFilter(e, t) {
|
|
240
|
-
let n = [];
|
|
241
|
-
for (let r = 0; r < e.length; r++) {
|
|
242
|
-
let i = e[r], a = !0;
|
|
243
|
-
for (let e = 0; e < t.length; e++) {
|
|
244
|
-
let n = t[e];
|
|
245
|
-
if (!s(n, i[n.field])) {
|
|
246
|
-
a = !1;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
a && n.push(i);
|
|
251
|
-
}
|
|
252
|
-
return n;
|
|
253
|
-
}
|
|
254
|
-
filterViaIndex(e, t) {
|
|
255
|
-
let n = t !== this.dataset, r = null;
|
|
256
|
-
if (n) {
|
|
257
|
-
if (t === this.sequentialCache.previousResult && this.sequentialCache.previousResultSet !== null) r = this.sequentialCache.previousResultSet;
|
|
258
|
-
else if (r = new Set(t), t === this.sequentialCache.previousResult) {
|
|
259
|
-
this.sequentialCache.previousResultSet = r;
|
|
260
|
-
let e = this.sequentialCache.previousCriteriaKey;
|
|
261
|
-
if (e !== null) {
|
|
262
|
-
let t = this.sequentialCache.previousResultsByCriteria.get(e);
|
|
263
|
-
t && (t.resultSet = r);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
let i = [], a = [];
|
|
268
|
-
for (let t = 0; t < e.length; t++) {
|
|
269
|
-
let n = e[t];
|
|
270
|
-
n.hasValues && i.push(n), n.hasExclude && a.push(n);
|
|
271
|
-
}
|
|
272
|
-
if (i.length === 0) return this.applyIndexedExclusions(t, a);
|
|
273
|
-
if (i.length === 1) {
|
|
274
|
-
let e = i[0], t = !1;
|
|
275
|
-
for (let n = 0; n < a.length; n++) if (a[n].field !== e.field) {
|
|
276
|
-
t = !0;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
if (r === null && !t) return e.values.length === 1 ? this.indexer.getByValue(e.field, e.values[0]).slice() : this.indexer.getByValues(e.field, e.values);
|
|
280
|
-
let n = this.indexer.getByValues(e.field, e.values), o = [];
|
|
281
|
-
for (let e = 0; e < n.length; e++) {
|
|
282
|
-
let t = n[e];
|
|
283
|
-
r && !r.has(t) || o.push(t);
|
|
284
|
-
}
|
|
285
|
-
return this.applyIndexedExclusions(o, a);
|
|
286
|
-
}
|
|
287
|
-
let o = i[0], c = this.estimateIndexSize(o);
|
|
288
|
-
for (let e = 1; e < i.length; e++) {
|
|
289
|
-
let t = i[e], n = this.estimateIndexSize(t);
|
|
290
|
-
n < c && (o = t, c = n);
|
|
291
|
-
}
|
|
292
|
-
let l = this.indexer.getByValues(o.field, o.values);
|
|
293
|
-
if (l.length === 0) return [];
|
|
294
|
-
let u = [];
|
|
295
|
-
for (let e = 0; e < l.length; e++) {
|
|
296
|
-
let t = l[e], n = !0;
|
|
297
|
-
if (!(r && !r.has(t))) {
|
|
298
|
-
for (let e = 0; e < i.length; e++) {
|
|
299
|
-
let r = i[e];
|
|
300
|
-
if (r !== o && !s(r, t[r.field])) {
|
|
301
|
-
n = !1;
|
|
302
|
-
break;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
n && u.push(t);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return this.applyIndexedExclusions(u, a);
|
|
309
|
-
}
|
|
310
|
-
estimateIndexSize(e) {
|
|
311
|
-
let t = this.indexer.getIndexMap(e.field);
|
|
312
|
-
if (!t) return Infinity;
|
|
313
|
-
let n = 0;
|
|
314
|
-
for (let r = 0; r < e.values.length; r++) {
|
|
315
|
-
let i = t.get(e.values[r]);
|
|
316
|
-
i && (n += i.length);
|
|
317
|
-
}
|
|
318
|
-
return n;
|
|
319
|
-
}
|
|
320
|
-
applyIndexedExclusions(e, t) {
|
|
321
|
-
if (t.length === 0 || e.length === 0) return e;
|
|
322
|
-
let n = /* @__PURE__ */ new Set();
|
|
323
|
-
for (let e = 0; e < t.length; e++) {
|
|
324
|
-
let r = t[e], i = this.indexer.getIndexMap(r.field);
|
|
325
|
-
if (i) for (let e = 0; e < r.exclude.length; e++) {
|
|
326
|
-
let t = i.get(r.exclude[e]);
|
|
327
|
-
if (t) for (let e = 0; e < t.length; e++) n.add(t[e]);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if (n.size === 0) return e;
|
|
331
|
-
let r = [];
|
|
332
|
-
for (let t = 0; t < e.length; t++) {
|
|
333
|
-
let i = e[t];
|
|
334
|
-
n.has(i) || r.push(i);
|
|
335
|
-
}
|
|
336
|
-
return r;
|
|
337
|
-
}
|
|
338
|
-
createEmptyResult(e, t, n) {
|
|
339
|
-
let r = [];
|
|
340
|
-
return this.storePreviousResult(r, e, t, n), r;
|
|
341
|
-
}
|
|
342
|
-
storePreviousResult(e, t, n, r, i = this.createCriteriaCacheKey(r), a) {
|
|
343
|
-
if (!this.filterByPreviousResult) return;
|
|
344
|
-
let o = a === void 0 ? null : a;
|
|
345
|
-
this.sequentialCache.previousResult = e, this.sequentialCache.previousCriteria = r, this.sequentialCache.previousCriteriaKey = i, this.sequentialCache.previousBaseData = t ? this.dataset : n, this.sequentialCache.previousResultSet = o, this.state.setPreviousResult(e, t ? this.dataset : n), this.sequentialCache.previousResultsByCriteria.set(i, this.createSequentialCacheEntry(e, o));
|
|
346
|
-
}
|
|
347
|
-
createCriteriaCacheKey(e) {
|
|
348
|
-
let t = "";
|
|
349
|
-
for (let n = 0; n < e.length; n++) t += e[n].cacheKeySegment, t += ";";
|
|
350
|
-
return t;
|
|
351
|
-
}
|
|
352
|
-
createSequentialCacheEntry(e, t) {
|
|
353
|
-
return {
|
|
354
|
-
result: e,
|
|
355
|
-
resultSet: t
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
createSequentialExecutionCriteria(e, t) {
|
|
359
|
-
let n = /* @__PURE__ */ new Map();
|
|
360
|
-
for (let t = 0; t < e.length; t++) {
|
|
361
|
-
let r = e[t];
|
|
362
|
-
n.set(r.field, r);
|
|
363
|
-
}
|
|
364
|
-
return t.map((e) => {
|
|
365
|
-
let t = n.get(e.field);
|
|
366
|
-
if (!t || !t.hasValues || !e.hasValues || t.hasExclude || e.hasExclude || e.includedValues.size <= t.includedValues.size) return e;
|
|
367
|
-
for (let n of t.includedValues) if (!e.includedValues.has(n)) return e;
|
|
368
|
-
let r = [];
|
|
369
|
-
for (let n of e.includedValues) t.includedValues.has(n) || r.push(n);
|
|
370
|
-
return r.length === 0 ? e : {
|
|
371
|
-
...e,
|
|
372
|
-
values: r,
|
|
373
|
-
includedValues: new Set(r)
|
|
374
|
-
};
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
hasCriteriaBacktrack(e, t) {
|
|
378
|
-
let n = this.createCriteriaStateMap(e), r = this.createCriteriaStateMap(t);
|
|
379
|
-
for (let [e, t] of n) {
|
|
380
|
-
let n = r.get(e);
|
|
381
|
-
if (!n || this.isCriterionBacktracked(t, n)) return !0;
|
|
382
|
-
}
|
|
383
|
-
return !1;
|
|
384
|
-
}
|
|
385
|
-
canApplySequentiallyToEmptyResult(e, t) {
|
|
386
|
-
let n = this.createCriteriaStateMap(e), r = this.createCriteriaStateMap(t);
|
|
387
|
-
for (let [e, t] of r) {
|
|
388
|
-
let r = n.get(e);
|
|
389
|
-
if (r) {
|
|
390
|
-
if (r.hasValues !== t.hasValues && (r.hasValues || !t.hasValues)) return !1;
|
|
391
|
-
if (r.hasValues && t.hasValues) {
|
|
392
|
-
let e = r.includedValues, n = t.includedValues;
|
|
393
|
-
if (!this.areSetsEqual(e, n) && !this.isSubset(e, n)) return !1;
|
|
394
|
-
}
|
|
395
|
-
if (r.hasExclude !== t.hasExclude && (r.hasExclude || !t.hasExclude)) return !1;
|
|
396
|
-
if (r.hasExclude && t.hasExclude) {
|
|
397
|
-
let e = r.excludedValues, n = t.excludedValues;
|
|
398
|
-
if (!this.areSetsEqual(e, n) && !this.isSubset(e, n)) return !1;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return !0;
|
|
403
|
-
}
|
|
404
|
-
createCriteriaStateMap(e) {
|
|
405
|
-
let t = /* @__PURE__ */ new Map();
|
|
406
|
-
for (let n = 0; n < e.length; n++) {
|
|
407
|
-
let r = e[n];
|
|
408
|
-
t.set(r.field, r);
|
|
409
|
-
}
|
|
410
|
-
return t;
|
|
411
|
-
}
|
|
412
|
-
isCriterionBacktracked(e, t) {
|
|
413
|
-
if (e.hasValues && !t.hasValues) return !0;
|
|
414
|
-
if (e.hasValues && t.hasValues) {
|
|
415
|
-
let n = e.includedValues, r = t.includedValues;
|
|
416
|
-
if (!this.areSetsEqual(n, r)) return this.isSubset(r, n);
|
|
417
|
-
}
|
|
418
|
-
if (!e.hasValues && t.hasValues) return !1;
|
|
419
|
-
if (e.hasExclude && !t.hasExclude) return !0;
|
|
420
|
-
if (!e.hasExclude && t.hasExclude) return !1;
|
|
421
|
-
if (e.hasExclude && t.hasExclude) {
|
|
422
|
-
let n = e.excludedValues, r = t.excludedValues;
|
|
423
|
-
if (!this.areSetsEqual(n, r)) return this.isSubset(r, n);
|
|
424
|
-
}
|
|
425
|
-
return !1;
|
|
426
|
-
}
|
|
427
|
-
isSubset(e, t) {
|
|
428
|
-
for (let n of e) if (!t.has(n)) return !1;
|
|
429
|
-
return !0;
|
|
430
|
-
}
|
|
431
|
-
areSetsEqual(e, t) {
|
|
432
|
-
if (e === t) return !0;
|
|
433
|
-
if (!e || !t || e.size !== t.size) return !1;
|
|
434
|
-
for (let n of e) if (!t.has(n)) return !1;
|
|
435
|
-
return !0;
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
//#endregion
|
|
439
|
-
export { d as FilterEngine };
|
package/dist/filter/nested.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { CollectionItem, type FilterCriterion } from "../types";
|
|
2
|
-
import type { FilterNestedCollectionStorage } from "./types";
|
|
3
|
-
export declare class FilterNestedCollection<T extends CollectionItem> {
|
|
4
|
-
private readonly storage;
|
|
5
|
-
private readonly registeredFields;
|
|
6
|
-
private readonly fieldDescriptors;
|
|
7
|
-
constructor(storage?: FilterNestedCollectionStorage<T>);
|
|
8
|
-
registerFields(fieldPaths?: readonly string[]): void;
|
|
9
|
-
hasRegisteredFields(): boolean;
|
|
10
|
-
hasField(fieldPath: string): boolean;
|
|
11
|
-
clearIndexes(): void;
|
|
12
|
-
buildIndexes(data: T[]): void;
|
|
13
|
-
addItems(items: T[]): void;
|
|
14
|
-
removeItem(item: T): void;
|
|
15
|
-
updateItem(nextItem: T, previousItem: T): void;
|
|
16
|
-
filter(sourceData: T[], criteria: FilterCriterion<T>[], dataset: T[]): T[];
|
|
17
|
-
private resolveCriteria;
|
|
18
|
-
private registerField;
|
|
19
|
-
private buildIndex;
|
|
20
|
-
private removeItemFromIndex;
|
|
21
|
-
private addItem;
|
|
22
|
-
private addItemToIndex;
|
|
23
|
-
private updateItemInIndex;
|
|
24
|
-
private collectUniqueValues;
|
|
25
|
-
private areValueSetsEqual;
|
|
26
|
-
private filterByIndexes;
|
|
27
|
-
private getItemsByValues;
|
|
28
|
-
private estimateIndexSize;
|
|
29
|
-
private filterLinearly;
|
|
30
|
-
private applyIndexedExclusions;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=nested.d.ts.map
|