@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
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import { State as e } from "../State.mjs";
|
|
2
|
-
import { MergeEnginesChainBuilder as t } from "./chain.mjs";
|
|
3
|
-
import { createMergeModuleAdapter as n, isRecord as r, resolveMergeModuleName as i } from "./module-adapters.mjs";
|
|
4
|
-
import { MergeEnginesError as a } from "./errors.mjs";
|
|
5
|
-
import { DEFER_FILTER_MUTATION_INDEX_UPDATES_KEY as o, DEFER_SEARCH_MUTATION_INDEX_UPDATES_KEY as s, DEFER_SORT_MUTATION_CACHE_UPDATES_KEY as c, MERGE_SHARED_SCOPE as l } from "../constants.mjs";
|
|
6
|
-
//#region src/merge/merge-engines.ts
|
|
7
|
-
var u = class {
|
|
8
|
-
constructor(r) {
|
|
9
|
-
this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
|
|
10
|
-
let { imports: a, data: u, filterByPreviousResult: d = !1, ...f } = r;
|
|
11
|
-
this.validateFilterByPreviousResultOptions(f.filter), this.state = new e(u, { filterByPreviousResult: d });
|
|
12
|
-
let p = new Set(a), m = null, h = null, g = null;
|
|
13
|
-
for (let e of p) {
|
|
14
|
-
let t = i(e);
|
|
15
|
-
if (!t) continue;
|
|
16
|
-
let r = this.getModuleInitOptions(t, e.name, f), a = n(e, u, this.state, r);
|
|
17
|
-
a && (a.moduleName === "search" && !m && (m = a), a.moduleName === "sort" && !h && (h = a), a.moduleName === "filter" && !g && (g = a));
|
|
18
|
-
}
|
|
19
|
-
this.searchModule = m, this.sortModule = h, this.filterModule = g, this.sortModule && this.state.setScopedValue(l, c, !0), this.searchModule && this.state.setScopedValue(l, s, !0), this.filterModule && this.state.setScopedValue(l, o, !0), this.state.subscribe((e) => this.handleStateMutation(e)), this.chainBuilder = new t({
|
|
20
|
-
search: (e, t) => t === void 0 ? this.search(e) : this.search(e, t),
|
|
21
|
-
sort: (e, t, n) => this.sort(e, t, n),
|
|
22
|
-
filter: (e, t) => this.filter(e, t),
|
|
23
|
-
getOriginData: () => this.getOriginData(),
|
|
24
|
-
add: (e) => this.add(e),
|
|
25
|
-
update: (e) => this.update(e),
|
|
26
|
-
data: (e) => this.data(e),
|
|
27
|
-
clearIndexes: (e) => this.clearIndexes(e),
|
|
28
|
-
clearData: (e) => this.clearData(e)
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
getAdapter(e) {
|
|
32
|
-
return e === "search" ? this.searchModule : e === "sort" ? this.sortModule : this.filterModule;
|
|
33
|
-
}
|
|
34
|
-
getModuleInitOptions(e, t, n) {
|
|
35
|
-
let i = {};
|
|
36
|
-
for (let a of [e, t]) {
|
|
37
|
-
let e = n[a];
|
|
38
|
-
r(e) && Object.assign(i, e);
|
|
39
|
-
}
|
|
40
|
-
return i;
|
|
41
|
-
}
|
|
42
|
-
validateFilterByPreviousResultOptions(e) {
|
|
43
|
-
if (r(e) && Object.prototype.hasOwnProperty.call(e, "filterByPreviousResult")) throw a.invalidFilterByPreviousResultOption();
|
|
44
|
-
}
|
|
45
|
-
isPreviousResultEnabled() {
|
|
46
|
-
return this.state.isFilterByPreviousResultEnabled();
|
|
47
|
-
}
|
|
48
|
-
getPreviousResultInput() {
|
|
49
|
-
return this.isPreviousResultEnabled() ? this.state.getPreviousResult() : null;
|
|
50
|
-
}
|
|
51
|
-
trackPreviousResult(e, t) {
|
|
52
|
-
return this.isPreviousResultEnabled() && this.state.setPreviousResult(e, t), e;
|
|
53
|
-
}
|
|
54
|
-
clearOperationState(e) {
|
|
55
|
-
(!e || e === "search") && (this.previousSearchState = null), (!e || e === "filter") && (this.previousFilterState = null), (!e || e === "sort") && (this.previousSortState = null);
|
|
56
|
-
}
|
|
57
|
-
createSearchCacheKey(e, t) {
|
|
58
|
-
return JSON.stringify([e, t ?? null]);
|
|
59
|
-
}
|
|
60
|
-
createSortCacheKey(e, t) {
|
|
61
|
-
return JSON.stringify({
|
|
62
|
-
descriptors: e,
|
|
63
|
-
inPlace: t ?? !1
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
createFilterCacheKey(e) {
|
|
67
|
-
return JSON.stringify(e);
|
|
68
|
-
}
|
|
69
|
-
handleStateMutation(e) {
|
|
70
|
-
switch (e.type) {
|
|
71
|
-
case "add":
|
|
72
|
-
this.queueSearchCacheMutation(e), this.queueFilterCacheMutation(e), this.queueSortCacheMutation(e);
|
|
73
|
-
return;
|
|
74
|
-
case "update":
|
|
75
|
-
this.queueSearchCacheMutation(e), this.queueFilterCacheMutation(e), this.queueSortCacheMutation(e);
|
|
76
|
-
return;
|
|
77
|
-
case "remove":
|
|
78
|
-
this.previousSearchState = null, this.previousFilterState = null, this.queueSortCacheMutation(e);
|
|
79
|
-
return;
|
|
80
|
-
case "removeMany":
|
|
81
|
-
this.previousSearchState = null, this.previousFilterState = null, this.queueSortCacheMutation(e);
|
|
82
|
-
return;
|
|
83
|
-
case "data":
|
|
84
|
-
case "clearData":
|
|
85
|
-
this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
queueSearchCacheMutation(e) {
|
|
90
|
-
let t = this.previousSearchState;
|
|
91
|
-
if (t !== null) {
|
|
92
|
-
if (!this.canPatchStoredDatasetSearch(t)) {
|
|
93
|
-
this.previousSearchState = null;
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
this.previousSearchState = {
|
|
97
|
-
...t,
|
|
98
|
-
version: this.state.getMutationVersion(),
|
|
99
|
-
pendingMutations: t.pendingMutations.concat(e)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
queueFilterCacheMutation(e) {
|
|
104
|
-
let t = this.previousFilterState;
|
|
105
|
-
if (t !== null) {
|
|
106
|
-
if (!this.canPatchStoredDatasetFilter(t)) {
|
|
107
|
-
this.previousFilterState = null;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.previousFilterState = {
|
|
111
|
-
...t,
|
|
112
|
-
version: this.state.getMutationVersion(),
|
|
113
|
-
pendingMutations: t.pendingMutations.concat(e)
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
queueSortCacheMutation(e) {
|
|
118
|
-
let t = this.previousSortState;
|
|
119
|
-
if (t !== null) {
|
|
120
|
-
if (!this.canPatchStoredDatasetSort(t)) {
|
|
121
|
-
this.previousSortState = null;
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.previousSortState = {
|
|
125
|
-
...t,
|
|
126
|
-
version: this.state.getMutationVersion(),
|
|
127
|
-
pendingMutations: t.pendingMutations.concat(e)
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
resolvePendingSortCache(e) {
|
|
132
|
-
if (e.pendingMutations.length === 0) return e;
|
|
133
|
-
let t = {
|
|
134
|
-
...e,
|
|
135
|
-
pendingMutations: []
|
|
136
|
-
};
|
|
137
|
-
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applySortCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
138
|
-
return t;
|
|
139
|
-
}
|
|
140
|
-
resolvePendingSearchCache(e) {
|
|
141
|
-
if (e.pendingMutations.length === 0) return e;
|
|
142
|
-
let t = {
|
|
143
|
-
...e,
|
|
144
|
-
pendingMutations: []
|
|
145
|
-
};
|
|
146
|
-
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applySearchCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
147
|
-
return t;
|
|
148
|
-
}
|
|
149
|
-
resolvePendingFilterCache(e) {
|
|
150
|
-
if (e.pendingMutations.length === 0) return e;
|
|
151
|
-
let t = {
|
|
152
|
-
...e,
|
|
153
|
-
pendingMutations: []
|
|
154
|
-
};
|
|
155
|
-
for (let n = 0; n < e.pendingMutations.length; n++) if (t = this.applyFilterCacheMutation(t, e.pendingMutations[n]), t === null) return null;
|
|
156
|
-
return t;
|
|
157
|
-
}
|
|
158
|
-
applySortCacheMutation(e, t) {
|
|
159
|
-
switch (t.type) {
|
|
160
|
-
case "add": return this.patchSortCacheForAddedItems(e, t.items);
|
|
161
|
-
case "update": return this.patchSortCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
162
|
-
case "remove": return this.patchSortCacheForRemovedItems(e, [t.removedItem]);
|
|
163
|
-
case "removeMany": return this.patchSortCacheForRemovedItems(e, t.entries.map((e) => e.removedItem));
|
|
164
|
-
case "data":
|
|
165
|
-
case "clearData": return null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
applySearchCacheMutation(e, t) {
|
|
169
|
-
switch (t.type) {
|
|
170
|
-
case "add": return this.patchSearchCacheForAddedItems(e, t.items);
|
|
171
|
-
case "update": return this.patchSearchCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
172
|
-
case "remove":
|
|
173
|
-
case "removeMany":
|
|
174
|
-
case "data":
|
|
175
|
-
case "clearData": return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
applyFilterCacheMutation(e, t) {
|
|
179
|
-
switch (t.type) {
|
|
180
|
-
case "add": return this.patchFilterCacheForAddedItems(e, t.items);
|
|
181
|
-
case "update": return this.patchFilterCacheForUpdatedItem(e, t.previousItem, t.nextItem);
|
|
182
|
-
case "remove":
|
|
183
|
-
case "removeMany":
|
|
184
|
-
case "data":
|
|
185
|
-
case "clearData": return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
canPatchStoredDatasetSearch(e) {
|
|
189
|
-
return e.originData === this.state.getOriginData() && e.field !== null;
|
|
190
|
-
}
|
|
191
|
-
canPatchStoredDatasetFilter(e) {
|
|
192
|
-
if (e.sourceData !== this.state.getOriginData()) return !1;
|
|
193
|
-
for (let t = 0; t < e.criteria.length; t++) if (!this.isPatchableFilterCriterion(e.criteria[t])) return !1;
|
|
194
|
-
return !0;
|
|
195
|
-
}
|
|
196
|
-
canPatchStoredDatasetSort(e) {
|
|
197
|
-
return e.sourceData === this.state.getOriginData();
|
|
198
|
-
}
|
|
199
|
-
compareItemsByDescriptors(e, t, n) {
|
|
200
|
-
for (let r = 0; r < n.length; r++) {
|
|
201
|
-
let { field: i, direction: a } = n[r], o = e[i], s = t[i];
|
|
202
|
-
if (o < s) return a === "asc" ? -1 : 1;
|
|
203
|
-
if (o > s) return a === "asc" ? 1 : -1;
|
|
204
|
-
}
|
|
205
|
-
return (this.state.getItemIndex(e) ?? -1) - (this.state.getItemIndex(t) ?? -1);
|
|
206
|
-
}
|
|
207
|
-
findSortInsertPosition(e, t, n) {
|
|
208
|
-
let r = 0, i = e.length;
|
|
209
|
-
for (; r < i;) {
|
|
210
|
-
let a = r + i >> 1;
|
|
211
|
-
this.compareItemsByDescriptors(e[a], t, n) <= 0 ? r = a + 1 : i = a;
|
|
212
|
-
}
|
|
213
|
-
return r;
|
|
214
|
-
}
|
|
215
|
-
findDatasetInsertPosition(e, t) {
|
|
216
|
-
let n = this.state.getItemIndex(t) ?? 2 ** 53 - 1;
|
|
217
|
-
for (let t = 0; t < e.length; t++) if ((this.state.getItemIndex(e[t]) ?? 2 ** 53 - 1) > n) return t;
|
|
218
|
-
return e.length;
|
|
219
|
-
}
|
|
220
|
-
doesItemMatchSearchCache(e, t) {
|
|
221
|
-
if (e.field === null || e.lowerQuery.length === 0) return !1;
|
|
222
|
-
let n = t[e.field];
|
|
223
|
-
return typeof n == "string" && n.toLowerCase().includes(e.lowerQuery);
|
|
224
|
-
}
|
|
225
|
-
patchSearchCacheForAddedItems(e, t) {
|
|
226
|
-
if (!this.canPatchStoredDatasetSearch(e)) return null;
|
|
227
|
-
let n = e.result.slice();
|
|
228
|
-
for (let r = 0; r < t.length; r++) {
|
|
229
|
-
let i = t[r];
|
|
230
|
-
this.doesItemMatchSearchCache(e, i) && n.push(i);
|
|
231
|
-
}
|
|
232
|
-
return {
|
|
233
|
-
...e,
|
|
234
|
-
result: n,
|
|
235
|
-
pendingMutations: [],
|
|
236
|
-
version: this.state.getMutationVersion()
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
patchSearchCacheForUpdatedItem(e, t, n) {
|
|
240
|
-
if (!this.canPatchStoredDatasetSearch(e)) return null;
|
|
241
|
-
let r = e.result.slice(), i = r.indexOf(t), a = this.doesItemMatchSearchCache(e, n);
|
|
242
|
-
if (i !== -1) a ? r[i] = n : r.splice(i, 1);
|
|
243
|
-
else if (a) {
|
|
244
|
-
let e = this.findDatasetInsertPosition(r, n);
|
|
245
|
-
r.splice(e, 0, n);
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
...e,
|
|
249
|
-
result: r,
|
|
250
|
-
pendingMutations: [],
|
|
251
|
-
version: this.state.getMutationVersion()
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
isPatchableFilterCriterion(e) {
|
|
255
|
-
return !String(e.field).includes(".");
|
|
256
|
-
}
|
|
257
|
-
doesItemMatchFilterCache(e, t) {
|
|
258
|
-
for (let n = 0; n < e.criteria.length; n++) {
|
|
259
|
-
let r = e.criteria[n];
|
|
260
|
-
if (!this.isPatchableFilterCriterion(r)) return !1;
|
|
261
|
-
let i = t[r.field];
|
|
262
|
-
if (r.values !== void 0 && r.values.length > 0 && !r.values.includes(i) || r.exclude !== void 0 && r.exclude.length > 0 && r.exclude.includes(i)) return !1;
|
|
263
|
-
}
|
|
264
|
-
return !0;
|
|
265
|
-
}
|
|
266
|
-
patchFilterCacheForAddedItems(e, t) {
|
|
267
|
-
if (!this.canPatchStoredDatasetFilter(e)) return null;
|
|
268
|
-
let n = e.result.slice();
|
|
269
|
-
for (let r = 0; r < t.length; r++) {
|
|
270
|
-
let i = t[r];
|
|
271
|
-
this.doesItemMatchFilterCache(e, i) && n.push(i);
|
|
272
|
-
}
|
|
273
|
-
return {
|
|
274
|
-
...e,
|
|
275
|
-
result: n,
|
|
276
|
-
pendingMutations: [],
|
|
277
|
-
version: this.state.getMutationVersion()
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
patchFilterCacheForUpdatedItem(e, t, n) {
|
|
281
|
-
if (!this.canPatchStoredDatasetFilter(e)) return null;
|
|
282
|
-
let r = e.result.slice(), i = r.indexOf(t), a = this.doesItemMatchFilterCache(e, n);
|
|
283
|
-
if (i !== -1) a ? r[i] = n : r.splice(i, 1);
|
|
284
|
-
else if (a) {
|
|
285
|
-
let e = this.findDatasetInsertPosition(r, n);
|
|
286
|
-
r.splice(e, 0, n);
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
...e,
|
|
290
|
-
result: r,
|
|
291
|
-
pendingMutations: [],
|
|
292
|
-
version: this.state.getMutationVersion()
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
patchSortCacheForAddedItems(e, t) {
|
|
296
|
-
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
297
|
-
let n = e.result.slice();
|
|
298
|
-
for (let r = 0; r < t.length; r++) {
|
|
299
|
-
let i = t[r], a = this.findSortInsertPosition(n, i, e.descriptors);
|
|
300
|
-
n.splice(a, 0, i);
|
|
301
|
-
}
|
|
302
|
-
return {
|
|
303
|
-
...e,
|
|
304
|
-
result: n,
|
|
305
|
-
pendingMutations: [],
|
|
306
|
-
version: this.state.getMutationVersion()
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
patchSortCacheForUpdatedItem(e, t, n) {
|
|
310
|
-
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
311
|
-
let r = e.result.slice(), i = r.indexOf(t);
|
|
312
|
-
if (i === -1) return e.result.indexOf(n) === -1 ? null : {
|
|
313
|
-
...e,
|
|
314
|
-
pendingMutations: [],
|
|
315
|
-
version: this.state.getMutationVersion()
|
|
316
|
-
};
|
|
317
|
-
if (!e.descriptors.some(({ field: e }) => t[e] !== n[e])) return r[i] = n, {
|
|
318
|
-
...e,
|
|
319
|
-
result: r,
|
|
320
|
-
pendingMutations: [],
|
|
321
|
-
version: this.state.getMutationVersion()
|
|
322
|
-
};
|
|
323
|
-
r.splice(i, 1);
|
|
324
|
-
let a = this.findSortInsertPosition(r, n, e.descriptors);
|
|
325
|
-
return r.splice(a, 0, n), {
|
|
326
|
-
...e,
|
|
327
|
-
result: r,
|
|
328
|
-
pendingMutations: [],
|
|
329
|
-
version: this.state.getMutationVersion()
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
patchSortCacheForRemovedItems(e, t) {
|
|
333
|
-
if (!this.canPatchStoredDatasetSort(e)) return null;
|
|
334
|
-
let n = new Set(t);
|
|
335
|
-
return {
|
|
336
|
-
...e,
|
|
337
|
-
result: Array.prototype.filter.call(e.result, (e) => !n.has(e)),
|
|
338
|
-
pendingMutations: [],
|
|
339
|
-
version: this.state.getMutationVersion()
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
search(e, t) {
|
|
343
|
-
if (!this.searchModule) throw a.unavailableEngine("search");
|
|
344
|
-
let n = this.state.getOriginData(), r = this.state.getMutationVersion(), i = this.createSearchCacheKey(e, t), o = this.previousSearchState;
|
|
345
|
-
if (o?.originData === n && o.key === i && o.version === r) {
|
|
346
|
-
let e = this.resolvePendingSearchCache(o);
|
|
347
|
-
if (e !== null) return this.previousSearchState = e, this.withChain(this.trackPreviousResult(e.result, n));
|
|
348
|
-
this.previousSearchState = null;
|
|
349
|
-
}
|
|
350
|
-
let s = t === void 0 ? this.searchModule.executeSearch(e) : this.searchModule.executeSearch(e, t);
|
|
351
|
-
return this.previousSearchState = {
|
|
352
|
-
key: i,
|
|
353
|
-
originData: n,
|
|
354
|
-
result: s,
|
|
355
|
-
version: r,
|
|
356
|
-
field: t === void 0 ? null : e,
|
|
357
|
-
lowerQuery: (t ?? e).trim().toLowerCase(),
|
|
358
|
-
pendingMutations: []
|
|
359
|
-
}, this.withChain(this.trackPreviousResult(s, n));
|
|
360
|
-
}
|
|
361
|
-
sort(e, t, n) {
|
|
362
|
-
if (!this.sortModule) throw a.unavailableEngine("sort");
|
|
363
|
-
let r, i;
|
|
364
|
-
if (t === void 0 ? (i = e, r = this.getPreviousResultInput() ?? this.state.getOriginData()) : (r = e, i = t), !n) {
|
|
365
|
-
let e = this.state.getMutationVersion(), a = this.createSortCacheKey(i, n), o = this.previousSortState;
|
|
366
|
-
if (o?.sourceData === r && o.key === a && o.version === e) {
|
|
367
|
-
let e = this.resolvePendingSortCache(o);
|
|
368
|
-
if (e !== null) return this.previousSortState = e, this.withChain(this.trackPreviousResult(e.result, r));
|
|
369
|
-
this.previousSortState = null;
|
|
370
|
-
}
|
|
371
|
-
let s = t === void 0 && r === this.state.getOriginData() ? this.sortModule.executeSort(i) : this.sortModule.executeSort(r, i, n);
|
|
372
|
-
return this.previousSortState = {
|
|
373
|
-
key: a,
|
|
374
|
-
sourceData: r,
|
|
375
|
-
result: s,
|
|
376
|
-
version: e,
|
|
377
|
-
descriptors: i,
|
|
378
|
-
pendingMutations: []
|
|
379
|
-
}, this.withChain(this.trackPreviousResult(s, r));
|
|
380
|
-
}
|
|
381
|
-
return this.withChain(this.trackPreviousResult(this.sortModule.executeSort(r, i, n), r));
|
|
382
|
-
}
|
|
383
|
-
filter(e, t) {
|
|
384
|
-
if (!this.filterModule) throw a.unavailableEngine("filter");
|
|
385
|
-
if (t === void 0) {
|
|
386
|
-
let t = this.getPreviousResultInput(), n = t ?? this.state.getOriginData(), r = e, i = this.state.getMutationVersion(), a = this.createFilterCacheKey(r), o = this.previousFilterState;
|
|
387
|
-
if (o?.sourceData === n && o.key === a && o.version === i) {
|
|
388
|
-
let e = this.resolvePendingFilterCache(o);
|
|
389
|
-
if (e !== null) return this.previousFilterState = e, this.withChain(this.trackPreviousResult(e.result, n));
|
|
390
|
-
this.previousFilterState = null;
|
|
391
|
-
}
|
|
392
|
-
let s = t === null ? this.filterModule.executeFilter(r) : this.filterModule.executeFilter(t, r);
|
|
393
|
-
return this.previousFilterState = {
|
|
394
|
-
key: a,
|
|
395
|
-
sourceData: n,
|
|
396
|
-
result: s,
|
|
397
|
-
version: i,
|
|
398
|
-
criteria: r,
|
|
399
|
-
pendingMutations: []
|
|
400
|
-
}, this.withChain(this.trackPreviousResult(s, n));
|
|
401
|
-
}
|
|
402
|
-
let n = e;
|
|
403
|
-
return this.withChain(this.trackPreviousResult(this.filterModule.executeFilter(n, t), n));
|
|
404
|
-
}
|
|
405
|
-
withChain(e) {
|
|
406
|
-
return this.chainBuilder.create(e);
|
|
407
|
-
}
|
|
408
|
-
getOriginData() {
|
|
409
|
-
if (this.searchModule || this.sortModule || this.filterModule) return this.state.getOriginData();
|
|
410
|
-
throw a.unavailableGetOriginData();
|
|
411
|
-
}
|
|
412
|
-
add(e) {
|
|
413
|
-
return e.length === 0 || this.state.add(e), this;
|
|
414
|
-
}
|
|
415
|
-
update(e) {
|
|
416
|
-
return this.state.update(e), this;
|
|
417
|
-
}
|
|
418
|
-
clearIndexes(e) {
|
|
419
|
-
let t = this.getAdapter(e);
|
|
420
|
-
if (t) return t.clearIndexes(), this.clearOperationState(e), this;
|
|
421
|
-
throw a.unavailableEngine(e);
|
|
422
|
-
}
|
|
423
|
-
data(e) {
|
|
424
|
-
return this.state.data(e), this;
|
|
425
|
-
}
|
|
426
|
-
clearData(e) {
|
|
427
|
-
if (this.getAdapter(e)) return this.state.clearData(), this;
|
|
428
|
-
throw a.unavailableEngine(e);
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
//#endregion
|
|
432
|
-
export { u as MergeEngines };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { State } from "../State";
|
|
2
|
-
import type { CollectionItem } from "../types";
|
|
3
|
-
import type { EngineConstructor, MergeModuleAdapter, MergeModuleName } from "./types";
|
|
4
|
-
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
5
|
-
export declare const resolveMergeModuleName: (EngineModule: EngineConstructor) => MergeModuleName | null;
|
|
6
|
-
export declare const createMergeModuleAdapter: <T extends CollectionItem>(EngineModule: EngineConstructor, data: T[], state: State<T>, config: Record<string, unknown>) => MergeModuleAdapter<T> | null;
|
|
7
|
-
//# sourceMappingURL=module-adapters.d.ts.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/merge/module-adapters.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
return typeof e == "object" && !!e;
|
|
4
|
-
}
|
|
5
|
-
function t(t, n) {
|
|
6
|
-
return e(t) && typeof t[n] == "function";
|
|
7
|
-
}
|
|
8
|
-
function n(e) {
|
|
9
|
-
return t(e, "search") && t(e, "getOriginData");
|
|
10
|
-
}
|
|
11
|
-
function r(e) {
|
|
12
|
-
return t(e, "sort") && t(e, "getOriginData");
|
|
13
|
-
}
|
|
14
|
-
function i(e) {
|
|
15
|
-
return t(e, "rawFilter") && t(e, "getOriginData");
|
|
16
|
-
}
|
|
17
|
-
var a = (e) => {
|
|
18
|
-
let { prototype: t } = e;
|
|
19
|
-
return i(t) ? "filter" : r(t) ? "sort" : n(t) ? "search" : null;
|
|
20
|
-
}, o = (e, t, a, o) => {
|
|
21
|
-
let s = new e({
|
|
22
|
-
data: t,
|
|
23
|
-
state: a,
|
|
24
|
-
...o
|
|
25
|
-
});
|
|
26
|
-
return i(s) ? {
|
|
27
|
-
moduleName: "filter",
|
|
28
|
-
executeFilter: (e, t) => t === void 0 ? s.rawFilter(e) : s.rawFilter(e, t),
|
|
29
|
-
clearIndexes: () => s.clearIndexes()
|
|
30
|
-
} : r(s) ? {
|
|
31
|
-
moduleName: "sort",
|
|
32
|
-
executeSort: (e, t, n) => t === void 0 ? s.sort(e) : s.sort(e, t, n),
|
|
33
|
-
clearIndexes: () => s.clearIndexes()
|
|
34
|
-
} : n(s) ? {
|
|
35
|
-
moduleName: "search",
|
|
36
|
-
executeSearch: (e, t) => t === void 0 ? s.search(e) : s.search(e, t),
|
|
37
|
-
clearIndexes: () => s.clearIndexes()
|
|
38
|
-
} : null;
|
|
39
|
-
};
|
|
40
|
-
//#endregion
|
|
41
|
-
export { o as createMergeModuleAdapter, e as isRecord, a as resolveMergeModuleName };
|
package/dist/merge/types.d.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import type { CollectionItem, FilterCriterion, StateMutation, SortDescriptor, UpdateDescriptor } from "../types";
|
|
2
|
-
import type { MergeEngines } from "./merge-engines";
|
|
3
|
-
export type MergeModuleName = "search" | "sort" | "filter";
|
|
4
|
-
export interface MergeSearchOptions<T extends CollectionItem = CollectionItem> {
|
|
5
|
-
data?: T[];
|
|
6
|
-
fields?: (keyof T & string)[];
|
|
7
|
-
nestedFields?: string[];
|
|
8
|
-
minQueryLength?: number;
|
|
9
|
-
filterByPreviousResult?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export interface MergeSortOptions<T extends CollectionItem = CollectionItem> {
|
|
12
|
-
data?: T[];
|
|
13
|
-
fields?: (keyof T & string)[];
|
|
14
|
-
}
|
|
15
|
-
export interface MergeFilterOptions<T extends CollectionItem = CollectionItem> {
|
|
16
|
-
data?: T[];
|
|
17
|
-
mutableExcludeField?: keyof T & string;
|
|
18
|
-
fields?: (keyof T & string)[];
|
|
19
|
-
nestedFields?: string[];
|
|
20
|
-
}
|
|
21
|
-
export interface MergeEnginesChain<T extends CollectionItem> {
|
|
22
|
-
search(query: string): T[] & MergeEnginesChain<T>;
|
|
23
|
-
search(field: (keyof T & string) | (string & {}), query: string): T[] & MergeEnginesChain<T>;
|
|
24
|
-
sort(descriptors: SortDescriptor<T>[]): T[] & MergeEnginesChain<T>;
|
|
25
|
-
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[] & MergeEnginesChain<T>;
|
|
26
|
-
filter(criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
27
|
-
filter(data: T[], criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
28
|
-
getOriginData(): T[];
|
|
29
|
-
add(items: T[]): MergeEngines<T>;
|
|
30
|
-
update(descriptor: UpdateDescriptor<T>): MergeEngines<T>;
|
|
31
|
-
data(data: T[]): MergeEngines<T>;
|
|
32
|
-
clearIndexes(module: MergeModuleName): T[] & MergeEnginesChain<T>;
|
|
33
|
-
clearData(module: MergeModuleName): T[] & MergeEnginesChain<T>;
|
|
34
|
-
}
|
|
35
|
-
export interface EngineConstructor {
|
|
36
|
-
new (options: Record<string, unknown>): object;
|
|
37
|
-
prototype: object;
|
|
38
|
-
name: string;
|
|
39
|
-
}
|
|
40
|
-
export interface EngineApi {
|
|
41
|
-
[methodName: string]: ((...args: unknown[]) => unknown) | undefined;
|
|
42
|
-
}
|
|
43
|
-
export interface MergeEnginesOptions<T extends CollectionItem> {
|
|
44
|
-
imports: EngineConstructor[];
|
|
45
|
-
data: T[];
|
|
46
|
-
filterByPreviousResult?: boolean;
|
|
47
|
-
search?: MergeSearchOptions<T>;
|
|
48
|
-
filter?: MergeFilterOptions<T>;
|
|
49
|
-
sort?: MergeSortOptions<T>;
|
|
50
|
-
[key: string]: unknown;
|
|
51
|
-
}
|
|
52
|
-
export type MergeEnginesChainCallbacks<T extends CollectionItem> = {
|
|
53
|
-
search: (fieldOrQuery: string, maybeQuery?: string) => T[] & MergeEnginesChain<T>;
|
|
54
|
-
sort: (dataOrDescriptors: T[] | SortDescriptor<T>[], descriptors?: SortDescriptor<T>[], inPlace?: boolean) => T[] & MergeEnginesChain<T>;
|
|
55
|
-
filter: (dataOrCriteria: T[] | FilterCriterion<T>[], criteria?: FilterCriterion<T>[]) => T[] & MergeEnginesChain<T>;
|
|
56
|
-
getOriginData: () => T[];
|
|
57
|
-
add: (items: T[]) => MergeEngines<T>;
|
|
58
|
-
update: (descriptor: UpdateDescriptor<T>) => MergeEngines<T>;
|
|
59
|
-
data: (data: T[]) => MergeEngines<T>;
|
|
60
|
-
clearIndexes: (module: MergeModuleName) => MergeEngines<T>;
|
|
61
|
-
clearData: (module: MergeModuleName) => MergeEngines<T>;
|
|
62
|
-
};
|
|
63
|
-
export type BaseModuleAdapter = {
|
|
64
|
-
moduleName: MergeModuleName;
|
|
65
|
-
clearIndexes: () => unknown;
|
|
66
|
-
};
|
|
67
|
-
export type SearchModuleAdapter<T extends CollectionItem> = BaseModuleAdapter & {
|
|
68
|
-
moduleName: "search";
|
|
69
|
-
executeSearch: (fieldOrQuery: string, maybeQuery?: string) => T[];
|
|
70
|
-
};
|
|
71
|
-
export type SortModuleAdapter<T extends CollectionItem> = BaseModuleAdapter & {
|
|
72
|
-
moduleName: "sort";
|
|
73
|
-
executeSort: (dataOrDescriptors: T[] | SortDescriptor<T>[], descriptors?: SortDescriptor<T>[], inPlace?: boolean) => T[];
|
|
74
|
-
};
|
|
75
|
-
export type FilterModuleAdapter<T extends CollectionItem> = BaseModuleAdapter & {
|
|
76
|
-
moduleName: "filter";
|
|
77
|
-
executeFilter: (dataOrCriteria: T[] | FilterCriterion<T>[], criteria?: FilterCriterion<T>[]) => T[];
|
|
78
|
-
};
|
|
79
|
-
export interface MergeModuleAdapterMap<T extends CollectionItem> {
|
|
80
|
-
search: SearchModuleAdapter<T>;
|
|
81
|
-
sort: SortModuleAdapter<T>;
|
|
82
|
-
filter: FilterModuleAdapter<T>;
|
|
83
|
-
}
|
|
84
|
-
export type MergeModuleAdapter<T extends CollectionItem, TModuleName extends MergeModuleName = MergeModuleName> = MergeModuleAdapterMap<T>[TModuleName];
|
|
85
|
-
export interface MergeBaseEngine {
|
|
86
|
-
clearIndexes(): unknown;
|
|
87
|
-
}
|
|
88
|
-
export interface MergeSearchEngine<T extends CollectionItem> extends MergeBaseEngine {
|
|
89
|
-
search(query: string): T[];
|
|
90
|
-
search(field: (keyof T & string) | (string & {}), query: string): T[];
|
|
91
|
-
}
|
|
92
|
-
export interface MergeSortEngine<T extends CollectionItem> extends MergeBaseEngine {
|
|
93
|
-
sort(descriptors: SortDescriptor<T>[]): T[];
|
|
94
|
-
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[];
|
|
95
|
-
}
|
|
96
|
-
export interface MergeFilterEngine<T extends CollectionItem> extends MergeBaseEngine {
|
|
97
|
-
rawFilter(criteria: FilterCriterion<T>[]): T[];
|
|
98
|
-
rawFilter(data: T[], criteria: FilterCriterion<T>[]): T[];
|
|
99
|
-
}
|
|
100
|
-
export type MergeSearchCache<T extends CollectionItem> = {
|
|
101
|
-
key: string;
|
|
102
|
-
originData: T[];
|
|
103
|
-
result: T[];
|
|
104
|
-
version: number;
|
|
105
|
-
field: string | null;
|
|
106
|
-
lowerQuery: string;
|
|
107
|
-
pendingMutations: StateMutation<T>[];
|
|
108
|
-
};
|
|
109
|
-
export type MergeFilterCache<T extends CollectionItem> = {
|
|
110
|
-
key: string;
|
|
111
|
-
sourceData: T[];
|
|
112
|
-
result: T[];
|
|
113
|
-
version: number;
|
|
114
|
-
criteria: FilterCriterion<T>[];
|
|
115
|
-
pendingMutations: StateMutation<T>[];
|
|
116
|
-
};
|
|
117
|
-
export type MergeSortCache<T extends CollectionItem> = {
|
|
118
|
-
key: string;
|
|
119
|
-
sourceData: T[];
|
|
120
|
-
result: T[];
|
|
121
|
-
version: number;
|
|
122
|
-
descriptors: SortDescriptor<T>[];
|
|
123
|
-
pendingMutations: StateMutation<T>[];
|
|
124
|
-
};
|
|
125
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/search/nested.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { CollectionItem } from "../types";
|
|
2
|
-
import type { SearchNestedCollectionStorage } from "./types";
|
|
3
|
-
export declare class SearchNestedCollection<T extends CollectionItem> {
|
|
4
|
-
private readonly storage;
|
|
5
|
-
private readonly registeredFields;
|
|
6
|
-
private readonly fieldDescriptors;
|
|
7
|
-
constructor(storage?: SearchNestedCollectionStorage);
|
|
8
|
-
registerFields(fieldPaths?: readonly string[]): void;
|
|
9
|
-
hasRegisteredFields(): boolean;
|
|
10
|
-
hasField(fieldPath: string): boolean;
|
|
11
|
-
hasIndexes(): boolean;
|
|
12
|
-
clearIndexes(): void;
|
|
13
|
-
buildIndexes(data: T[]): void;
|
|
14
|
-
addItems(items: T[], startIndex: number): void;
|
|
15
|
-
updateItem(item: T, previousItem: T, itemIndex: number): void;
|
|
16
|
-
removeItem(item: T, itemIndex: number): void;
|
|
17
|
-
moveItem(item: T, fromIndex: number, toIndex: number): void;
|
|
18
|
-
/**
|
|
19
|
-
* Returns dataset indices of items matching the query across all registered
|
|
20
|
-
* nested fields. Deduplicates indices that appear in multiple nested fields.
|
|
21
|
-
*/
|
|
22
|
-
searchAllIndexedFieldIndices(lowerQuery: string, uniqueQueryGrams: ReadonlySet<string>, restrictionLookup?: Uint8Array | null, candidateIndices?: readonly number[] | null): number[];
|
|
23
|
-
searchIndexedField(data: T[], fieldPath: string, lowerQuery: string, uniqueQueryGrams: ReadonlySet<string>, restrictionLookup?: Uint8Array | null, candidateIndices?: readonly number[] | null, take?: number): T[];
|
|
24
|
-
/**
|
|
25
|
-
* Core indexed search for a nested field: returns dataset indices of items
|
|
26
|
-
* whose nested values match the query.
|
|
27
|
-
*/
|
|
28
|
-
searchIndexedFieldIndices(fieldPath: string, lowerQuery: string, uniqueQueryGrams: ReadonlySet<string>, restrictionLookup?: Uint8Array | null, candidateIndices?: readonly number[] | null, take?: number): number[];
|
|
29
|
-
searchFieldLinear(data: T[], fieldPath: string, lowerQuery: string): T[];
|
|
30
|
-
searchFieldLinearIndices(data: T[], fieldPath: string, lowerQuery: string, sourceIndices?: readonly number[]): number[];
|
|
31
|
-
matchesAnyField(item: T, lowerQuery: string): boolean;
|
|
32
|
-
private registerField;
|
|
33
|
-
private getNormalizedValues;
|
|
34
|
-
private buildIndex;
|
|
35
|
-
private addItemsToField;
|
|
36
|
-
private updateItemInField;
|
|
37
|
-
private removeItemFromField;
|
|
38
|
-
private moveItemForField;
|
|
39
|
-
private getNormalizedItemValue;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=nested.d.ts.map
|