@devisfuture/mega-collection 2.4.6 → 2.4.7
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/dist/State.d.ts +42 -0
- package/dist/{chunk-BJZg_1dI.mjs → State.mjs} +2 -2
- package/dist/constants.d.ts +5 -0
- package/dist/constants.mjs +4 -0
- package/dist/filter/chain.d.ts +9 -0
- package/dist/filter/chain.mjs +22 -0
- package/dist/filter/constants.d.ts +2 -0
- package/dist/filter/criterion.d.ts +6 -0
- package/dist/filter/criterion.mjs +64 -0
- package/dist/filter/errors.d.ts +7 -0
- package/dist/filter/errors.mjs +17 -0
- package/dist/filter/filter.d.ts +89 -0
- package/dist/filter/filter.mjs +439 -0
- package/dist/filter/index.mjs +2 -891
- package/dist/filter/nested.d.ts +32 -0
- package/dist/filter/nested.mjs +246 -0
- package/dist/filter/types.d.ts +74 -0
- package/dist/filter/utils.d.ts +4 -0
- package/dist/filter/utils.mjs +29 -0
- package/dist/index.mjs +1 -1
- package/dist/indexer.d.ts +41 -0
- package/dist/indexer.mjs +101 -0
- package/dist/internal.d.ts +6 -0
- package/dist/{chunk-C5Zpu_ol.mjs → internal.mjs} +1 -1
- package/dist/merge/chain.d.ts +9 -0
- package/dist/merge/chain.mjs +23 -0
- package/dist/merge/constants.d.ts +6 -0
- package/dist/merge/constants.mjs +8 -0
- package/dist/merge/errors.d.ts +8 -0
- package/dist/merge/errors.mjs +19 -0
- package/dist/merge/index.mjs +1 -1
- package/dist/merge/merge-engines.d.ts +75 -0
- package/dist/{chunk-BURK5sks.mjs → merge/merge-engines.mjs} +35 -108
- package/dist/merge/module-adapters.d.ts +7 -0
- package/dist/merge/module-adapters.mjs +41 -0
- package/dist/merge/types.d.ts +125 -0
- package/dist/search/constants.d.ts +5 -0
- package/dist/search/index.mjs +2 -1010
- package/dist/search/nested.d.ts +41 -0
- package/dist/search/nested.mjs +210 -0
- package/dist/search/ngram.d.ts +23 -0
- package/dist/search/ngram.mjs +96 -0
- package/dist/search/text-search.d.ts +146 -0
- package/dist/search/text-search.mjs +696 -0
- package/dist/search/types.d.ts +93 -0
- package/dist/search/utils.d.ts +4 -0
- package/dist/search/utils.mjs +22 -0
- package/dist/sort/errors.d.ts +5 -0
- package/dist/sort/errors.mjs +11 -0
- package/dist/sort/index.mjs +2 -416
- package/dist/sort/sorter.d.ts +47 -0
- package/dist/sort/sorter.mjs +375 -0
- package/dist/sort/types.d.ts +18 -0
- package/dist/sort/utils.d.ts +17 -0
- package/dist/sort/utils.mjs +38 -0
- package/dist/types.d.ts +73 -0
- package/package.json +11 -34
- /package/dist/filter/{index.d.mts → index.d.ts} +0 -0
- /package/dist/{index.d.mts → index.d.ts} +0 -0
- /package/dist/merge/{index.d.mts → index.d.ts} +0 -0
- /package/dist/search/{index.d.mts → index.d.ts} +0 -0
- /package/dist/sort/{index.d.mts → index.d.ts} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MergeEngines class that provides a unified interface for text search,
|
|
3
|
+
* sorting, and filtering operations on collections.
|
|
4
|
+
*/
|
|
5
|
+
import type { CollectionItem, FilterCriterion, SortDescriptor, UpdateDescriptor } from "../types";
|
|
6
|
+
import { MergeEnginesChain } from "./chain";
|
|
7
|
+
import type { MergeEnginesOptions, MergeModuleName } from "./types";
|
|
8
|
+
export declare class MergeEngines<T extends CollectionItem> {
|
|
9
|
+
private readonly state;
|
|
10
|
+
private previousSearchState;
|
|
11
|
+
private previousFilterState;
|
|
12
|
+
private previousSortState;
|
|
13
|
+
private readonly searchModule;
|
|
14
|
+
private readonly sortModule;
|
|
15
|
+
private readonly filterModule;
|
|
16
|
+
private readonly chainBuilder;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new MergeEngines instance with the given options.
|
|
19
|
+
* Collects all modules from imports.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options: MergeEnginesOptions<T>);
|
|
22
|
+
private getAdapter;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the initialization options for a module.
|
|
25
|
+
*/
|
|
26
|
+
private getModuleInitOptions;
|
|
27
|
+
private validateFilterByPreviousResultOptions;
|
|
28
|
+
private isPreviousResultEnabled;
|
|
29
|
+
private getPreviousResultInput;
|
|
30
|
+
private trackPreviousResult;
|
|
31
|
+
private clearOperationState;
|
|
32
|
+
private createSearchCacheKey;
|
|
33
|
+
private createSortCacheKey;
|
|
34
|
+
private createFilterCacheKey;
|
|
35
|
+
private handleStateMutation;
|
|
36
|
+
private queueSearchCacheMutation;
|
|
37
|
+
private queueFilterCacheMutation;
|
|
38
|
+
private queueSortCacheMutation;
|
|
39
|
+
private resolvePendingSortCache;
|
|
40
|
+
private resolvePendingSearchCache;
|
|
41
|
+
private resolvePendingFilterCache;
|
|
42
|
+
private applySortCacheMutation;
|
|
43
|
+
private applySearchCacheMutation;
|
|
44
|
+
private applyFilterCacheMutation;
|
|
45
|
+
private canPatchStoredDatasetSearch;
|
|
46
|
+
private canPatchStoredDatasetFilter;
|
|
47
|
+
private canPatchStoredDatasetSort;
|
|
48
|
+
private compareItemsByDescriptors;
|
|
49
|
+
private findSortInsertPosition;
|
|
50
|
+
private findDatasetInsertPosition;
|
|
51
|
+
private doesItemMatchSearchCache;
|
|
52
|
+
private patchSearchCacheForAddedItems;
|
|
53
|
+
private patchSearchCacheForUpdatedItem;
|
|
54
|
+
private isPatchableFilterCriterion;
|
|
55
|
+
private doesItemMatchFilterCache;
|
|
56
|
+
private patchFilterCacheForAddedItems;
|
|
57
|
+
private patchFilterCacheForUpdatedItem;
|
|
58
|
+
private patchSortCacheForAddedItems;
|
|
59
|
+
private patchSortCacheForUpdatedItem;
|
|
60
|
+
private patchSortCacheForRemovedItems;
|
|
61
|
+
search(query: string): T[] & MergeEnginesChain<T>;
|
|
62
|
+
search(field: (keyof T & string) | (string & {}), query: string): T[] & MergeEnginesChain<T>;
|
|
63
|
+
sort(descriptors: SortDescriptor<T>[]): T[] & MergeEnginesChain<T>;
|
|
64
|
+
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[] & MergeEnginesChain<T>;
|
|
65
|
+
filter(criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
66
|
+
filter(data: T[], criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
67
|
+
private withChain;
|
|
68
|
+
getOriginData(): T[];
|
|
69
|
+
add(items: T[]): this;
|
|
70
|
+
update(descriptor: UpdateDescriptor<T>): this;
|
|
71
|
+
clearIndexes(module: MergeModuleName): this;
|
|
72
|
+
data(data: T[]): this;
|
|
73
|
+
clearData(module: MergeModuleName): this;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=merge-engines.d.ts.map
|
|
@@ -1,95 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let t = e;
|
|
10
|
-
return Object.defineProperties(t, {
|
|
11
|
-
search: a((e, t) => t === void 0 ? this.callbacks.search(e) : this.callbacks.search(e, t)),
|
|
12
|
-
sort: a((t, n, r) => n === void 0 ? this.callbacks.sort(e, t, r) : this.callbacks.sort(t, n, r)),
|
|
13
|
-
filter: a((t, n) => n === void 0 ? this.callbacks.filter(e, t) : this.callbacks.filter(t, n)),
|
|
14
|
-
add: a((e) => this.callbacks.add(e)),
|
|
15
|
-
update: a((e) => this.callbacks.update(e)),
|
|
16
|
-
clearIndexes: a((t) => (this.callbacks.clearIndexes(t), this.create(e))),
|
|
17
|
-
clearData: a((t) => (this.callbacks.clearData(t), this.create(e))),
|
|
18
|
-
data: a((e) => this.callbacks.data(e)),
|
|
19
|
-
getOriginData: a(() => this.callbacks.getOriginData())
|
|
20
|
-
}), t;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/merge/module-adapters.ts
|
|
25
|
-
function s(e) {
|
|
26
|
-
return typeof e == "object" && !!e;
|
|
27
|
-
}
|
|
28
|
-
function c(e, t) {
|
|
29
|
-
return s(e) && typeof e[t] == "function";
|
|
30
|
-
}
|
|
31
|
-
function l(e) {
|
|
32
|
-
return c(e, "search") && c(e, "getOriginData");
|
|
33
|
-
}
|
|
34
|
-
function u(e) {
|
|
35
|
-
return c(e, "sort") && c(e, "getOriginData");
|
|
36
|
-
}
|
|
37
|
-
function d(e) {
|
|
38
|
-
return c(e, "rawFilter") && c(e, "getOriginData");
|
|
39
|
-
}
|
|
40
|
-
var f = (e) => {
|
|
41
|
-
let { prototype: t } = e;
|
|
42
|
-
return d(t) ? "filter" : u(t) ? "sort" : l(t) ? "search" : null;
|
|
43
|
-
}, p = (e, t, n, r) => {
|
|
44
|
-
let i = new e({
|
|
45
|
-
data: t,
|
|
46
|
-
state: n,
|
|
47
|
-
...r
|
|
48
|
-
});
|
|
49
|
-
return d(i) ? {
|
|
50
|
-
moduleName: "filter",
|
|
51
|
-
executeFilter: (e, t) => t === void 0 ? i.rawFilter(e) : i.rawFilter(e, t),
|
|
52
|
-
clearIndexes: () => i.clearIndexes()
|
|
53
|
-
} : u(i) ? {
|
|
54
|
-
moduleName: "sort",
|
|
55
|
-
executeSort: (e, t, n) => t === void 0 ? i.sort(e) : i.sort(e, t, n),
|
|
56
|
-
clearIndexes: () => i.clearIndexes()
|
|
57
|
-
} : l(i) ? {
|
|
58
|
-
moduleName: "search",
|
|
59
|
-
executeSearch: (e, t) => t === void 0 ? i.search(e) : i.search(e, t),
|
|
60
|
-
clearIndexes: () => i.clearIndexes()
|
|
61
|
-
} : null;
|
|
62
|
-
}, m = {
|
|
63
|
-
search: "TextSearchEngine",
|
|
64
|
-
sort: "SortEngine",
|
|
65
|
-
filter: "FilterEngine"
|
|
66
|
-
}, h = class e extends Error {
|
|
67
|
-
constructor(e) {
|
|
68
|
-
super(e), this.name = "MergeEnginesError";
|
|
69
|
-
}
|
|
70
|
-
static unavailableEngine(t) {
|
|
71
|
-
let n = m[t];
|
|
72
|
-
return new e(`MergeEngines: ${n} is not available.`);
|
|
73
|
-
}
|
|
74
|
-
static unavailableGetOriginData() {
|
|
75
|
-
return new e("MergeEngines: getOriginData is not available.");
|
|
76
|
-
}
|
|
77
|
-
static invalidFilterByPreviousResultOption() {
|
|
78
|
-
return new e("MergeEngines: \"filter.filterByPreviousResult\" is not supported. Configure \"filterByPreviousResult\" on the MergeEngines root options.");
|
|
79
|
-
}
|
|
80
|
-
}, g = class {
|
|
81
|
-
constructor(a) {
|
|
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) {
|
|
82
9
|
this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
|
|
83
|
-
let { imports:
|
|
84
|
-
this.validateFilterByPreviousResultOptions(
|
|
85
|
-
let
|
|
86
|
-
for (let e of
|
|
87
|
-
let t =
|
|
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);
|
|
88
15
|
if (!t) continue;
|
|
89
|
-
let
|
|
90
|
-
|
|
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));
|
|
91
18
|
}
|
|
92
|
-
this.searchModule = m, this.sortModule = h, this.filterModule = g, this.sortModule && this.state.setScopedValue(
|
|
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({
|
|
93
20
|
search: (e, t) => t === void 0 ? this.search(e) : this.search(e, t),
|
|
94
21
|
sort: (e, t, n) => this.sort(e, t, n),
|
|
95
22
|
filter: (e, t) => this.filter(e, t),
|
|
@@ -105,15 +32,15 @@ var f = (e) => {
|
|
|
105
32
|
return e === "search" ? this.searchModule : e === "sort" ? this.sortModule : this.filterModule;
|
|
106
33
|
}
|
|
107
34
|
getModuleInitOptions(e, t, n) {
|
|
108
|
-
let
|
|
109
|
-
for (let
|
|
110
|
-
let e = n[
|
|
111
|
-
|
|
35
|
+
let i = {};
|
|
36
|
+
for (let a of [e, t]) {
|
|
37
|
+
let e = n[a];
|
|
38
|
+
r(e) && Object.assign(i, e);
|
|
112
39
|
}
|
|
113
|
-
return
|
|
40
|
+
return i;
|
|
114
41
|
}
|
|
115
42
|
validateFilterByPreviousResultOptions(e) {
|
|
116
|
-
if (
|
|
43
|
+
if (r(e) && Object.prototype.hasOwnProperty.call(e, "filterByPreviousResult")) throw a.invalidFilterByPreviousResultOption();
|
|
117
44
|
}
|
|
118
45
|
isPreviousResultEnabled() {
|
|
119
46
|
return this.state.isFilterByPreviousResultEnabled();
|
|
@@ -413,26 +340,26 @@ var f = (e) => {
|
|
|
413
340
|
};
|
|
414
341
|
}
|
|
415
342
|
search(e, t) {
|
|
416
|
-
if (!this.searchModule) throw
|
|
417
|
-
let n = this.state.getOriginData(), r = this.state.getMutationVersion(), i = this.createSearchCacheKey(e, t),
|
|
418
|
-
if (
|
|
419
|
-
let e = this.resolvePendingSearchCache(
|
|
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);
|
|
420
347
|
if (e !== null) return this.previousSearchState = e, this.withChain(this.trackPreviousResult(e.result, n));
|
|
421
348
|
this.previousSearchState = null;
|
|
422
349
|
}
|
|
423
|
-
let
|
|
350
|
+
let s = t === void 0 ? this.searchModule.executeSearch(e) : this.searchModule.executeSearch(e, t);
|
|
424
351
|
return this.previousSearchState = {
|
|
425
352
|
key: i,
|
|
426
353
|
originData: n,
|
|
427
|
-
result:
|
|
354
|
+
result: s,
|
|
428
355
|
version: r,
|
|
429
356
|
field: t === void 0 ? null : e,
|
|
430
357
|
lowerQuery: (t ?? e).trim().toLowerCase(),
|
|
431
358
|
pendingMutations: []
|
|
432
|
-
}, this.withChain(this.trackPreviousResult(
|
|
359
|
+
}, this.withChain(this.trackPreviousResult(s, n));
|
|
433
360
|
}
|
|
434
361
|
sort(e, t, n) {
|
|
435
|
-
if (!this.sortModule) throw
|
|
362
|
+
if (!this.sortModule) throw a.unavailableEngine("sort");
|
|
436
363
|
let r, i;
|
|
437
364
|
if (t === void 0 ? (i = e, r = this.getPreviousResultInput() ?? this.state.getOriginData()) : (r = e, i = t), !n) {
|
|
438
365
|
let e = this.state.getMutationVersion(), a = this.createSortCacheKey(i, n), o = this.previousSortState;
|
|
@@ -454,7 +381,7 @@ var f = (e) => {
|
|
|
454
381
|
return this.withChain(this.trackPreviousResult(this.sortModule.executeSort(r, i, n), r));
|
|
455
382
|
}
|
|
456
383
|
filter(e, t) {
|
|
457
|
-
if (!this.filterModule) throw
|
|
384
|
+
if (!this.filterModule) throw a.unavailableEngine("filter");
|
|
458
385
|
if (t === void 0) {
|
|
459
386
|
let t = this.getPreviousResultInput(), n = t ?? this.state.getOriginData(), r = e, i = this.state.getMutationVersion(), a = this.createFilterCacheKey(r), o = this.previousFilterState;
|
|
460
387
|
if (o?.sourceData === n && o.key === a && o.version === i) {
|
|
@@ -480,7 +407,7 @@ var f = (e) => {
|
|
|
480
407
|
}
|
|
481
408
|
getOriginData() {
|
|
482
409
|
if (this.searchModule || this.sortModule || this.filterModule) return this.state.getOriginData();
|
|
483
|
-
throw
|
|
410
|
+
throw a.unavailableGetOriginData();
|
|
484
411
|
}
|
|
485
412
|
add(e) {
|
|
486
413
|
return e.length === 0 || this.state.add(e), this;
|
|
@@ -491,15 +418,15 @@ var f = (e) => {
|
|
|
491
418
|
clearIndexes(e) {
|
|
492
419
|
let t = this.getAdapter(e);
|
|
493
420
|
if (t) return t.clearIndexes(), this.clearOperationState(e), this;
|
|
494
|
-
throw
|
|
421
|
+
throw a.unavailableEngine(e);
|
|
495
422
|
}
|
|
496
423
|
data(e) {
|
|
497
424
|
return this.state.data(e), this;
|
|
498
425
|
}
|
|
499
426
|
clearData(e) {
|
|
500
427
|
if (this.getAdapter(e)) return this.state.clearData(), this;
|
|
501
|
-
throw
|
|
428
|
+
throw a.unavailableEngine(e);
|
|
502
429
|
}
|
|
503
430
|
};
|
|
504
431
|
//#endregion
|
|
505
|
-
export {
|
|
432
|
+
export { u as MergeEngines };
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1,41 @@
|
|
|
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 };
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|