@devisfuture/mega-collection 2.4.6 → 2.4.8
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-CYIe-3He.d.ts +44 -0
- package/dist/chunks/constants-BXQI1M5E.mjs +1 -0
- package/dist/chunks/internal-COJC3Ik3.mjs +1 -0
- package/dist/chunks/merge-BRXHTBZ0.mjs +1 -0
- package/dist/filter/index.d.ts +111 -0
- package/dist/filter/index.mjs +1 -891
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -2
- package/dist/merge/index.d.ts +128 -0
- package/dist/merge/index.mjs +1 -2
- package/dist/search/index.d.ts +190 -0
- package/dist/search/index.mjs +1 -1010
- package/dist/sort/index.d.ts +55 -0
- package/dist/sort/index.mjs +1 -416
- package/dist/types-DONld7xY.d.ts +74 -0
- package/package.json +14 -34
- package/dist/chunk-BJZg_1dI.mjs +0 -183
- package/dist/chunk-BURK5sks.mjs +0 -505
- package/dist/chunk-C5Zpu_ol.mjs +0 -18
- package/dist/filter/index.d.mts +0 -4
- package/dist/index.d.mts +0 -4
- package/dist/merge/index.d.mts +0 -4
- package/dist/search/index.d.mts +0 -4
- package/dist/sort/index.d.mts +0 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { EngineApi, EngineConstructor, MergeEngines, MergeEnginesChain, MergeEnginesOptions, MergeModuleName } from './merge/index.js';
|
|
2
|
+
export { C as CollectionItem, F as FilterCriterion, I as IndexableKey, d as SortDescriptor, e as SortDirection, U as UpdateDescriptor } from './types-DONld7xY.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { e as MergeEngines };
|
|
1
|
+
import{t as m}from"./chunks/merge-BRXHTBZ0.mjs";export{m as MergeEngines};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { C as CollectionItem, d as SortDescriptor, F as FilterCriterion, U as UpdateDescriptor } from '../types-DONld7xY.js';
|
|
2
|
+
export { I as IndexableKey, e as SortDirection } from '../types-DONld7xY.js';
|
|
3
|
+
|
|
4
|
+
type MergeModuleName = "search" | "sort" | "filter";
|
|
5
|
+
interface MergeSearchOptions<T extends CollectionItem = CollectionItem> {
|
|
6
|
+
data?: T[];
|
|
7
|
+
fields?: (keyof T & string)[];
|
|
8
|
+
nestedFields?: string[];
|
|
9
|
+
minQueryLength?: number;
|
|
10
|
+
filterByPreviousResult?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface MergeSortOptions<T extends CollectionItem = CollectionItem> {
|
|
13
|
+
data?: T[];
|
|
14
|
+
fields?: (keyof T & string)[];
|
|
15
|
+
}
|
|
16
|
+
interface MergeFilterOptions<T extends CollectionItem = CollectionItem> {
|
|
17
|
+
data?: T[];
|
|
18
|
+
mutableExcludeField?: keyof T & string;
|
|
19
|
+
fields?: (keyof T & string)[];
|
|
20
|
+
nestedFields?: string[];
|
|
21
|
+
}
|
|
22
|
+
interface MergeEnginesChain<T extends CollectionItem> {
|
|
23
|
+
search(query: string): T[] & MergeEnginesChain<T>;
|
|
24
|
+
search(field: (keyof T & string) | (string & {}), query: string): T[] & MergeEnginesChain<T>;
|
|
25
|
+
sort(descriptors: SortDescriptor<T>[]): T[] & MergeEnginesChain<T>;
|
|
26
|
+
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[] & MergeEnginesChain<T>;
|
|
27
|
+
filter(criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
28
|
+
filter(data: T[], criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
29
|
+
getOriginData(): T[];
|
|
30
|
+
add(items: T[]): MergeEngines<T>;
|
|
31
|
+
update(descriptor: UpdateDescriptor<T>): MergeEngines<T>;
|
|
32
|
+
data(data: T[]): MergeEngines<T>;
|
|
33
|
+
clearIndexes(module: MergeModuleName): T[] & MergeEnginesChain<T>;
|
|
34
|
+
clearData(module: MergeModuleName): T[] & MergeEnginesChain<T>;
|
|
35
|
+
}
|
|
36
|
+
interface EngineConstructor {
|
|
37
|
+
new (options: Record<string, unknown>): object;
|
|
38
|
+
prototype: object;
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
interface EngineApi {
|
|
42
|
+
[methodName: string]: ((...args: unknown[]) => unknown) | undefined;
|
|
43
|
+
}
|
|
44
|
+
interface MergeEnginesOptions<T extends CollectionItem> {
|
|
45
|
+
imports: EngineConstructor[];
|
|
46
|
+
data: T[];
|
|
47
|
+
filterByPreviousResult?: boolean;
|
|
48
|
+
search?: MergeSearchOptions<T>;
|
|
49
|
+
filter?: MergeFilterOptions<T>;
|
|
50
|
+
sort?: MergeSortOptions<T>;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* MergeEngines class that provides a unified interface for text search,
|
|
56
|
+
* sorting, and filtering operations on collections.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
declare class MergeEngines<T extends CollectionItem> {
|
|
60
|
+
private readonly state;
|
|
61
|
+
private previousSearchState;
|
|
62
|
+
private previousFilterState;
|
|
63
|
+
private previousSortState;
|
|
64
|
+
private readonly searchModule;
|
|
65
|
+
private readonly sortModule;
|
|
66
|
+
private readonly filterModule;
|
|
67
|
+
private readonly chainBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new MergeEngines instance with the given options.
|
|
70
|
+
* Collects all modules from imports.
|
|
71
|
+
*/
|
|
72
|
+
constructor(options: MergeEnginesOptions<T>);
|
|
73
|
+
private getAdapter;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the initialization options for a module.
|
|
76
|
+
*/
|
|
77
|
+
private getModuleInitOptions;
|
|
78
|
+
private validateFilterByPreviousResultOptions;
|
|
79
|
+
private isPreviousResultEnabled;
|
|
80
|
+
private getPreviousResultInput;
|
|
81
|
+
private trackPreviousResult;
|
|
82
|
+
private clearOperationState;
|
|
83
|
+
private createSearchCacheKey;
|
|
84
|
+
private createSortCacheKey;
|
|
85
|
+
private createFilterCacheKey;
|
|
86
|
+
private handleStateMutation;
|
|
87
|
+
private queueSearchCacheMutation;
|
|
88
|
+
private queueFilterCacheMutation;
|
|
89
|
+
private queueSortCacheMutation;
|
|
90
|
+
private resolvePendingSortCache;
|
|
91
|
+
private resolvePendingSearchCache;
|
|
92
|
+
private resolvePendingFilterCache;
|
|
93
|
+
private applySortCacheMutation;
|
|
94
|
+
private applySearchCacheMutation;
|
|
95
|
+
private applyFilterCacheMutation;
|
|
96
|
+
private canPatchStoredDatasetSearch;
|
|
97
|
+
private canPatchStoredDatasetFilter;
|
|
98
|
+
private canPatchStoredDatasetSort;
|
|
99
|
+
private compareItemsByDescriptors;
|
|
100
|
+
private findSortInsertPosition;
|
|
101
|
+
private findDatasetInsertPosition;
|
|
102
|
+
private doesItemMatchSearchCache;
|
|
103
|
+
private patchSearchCacheForAddedItems;
|
|
104
|
+
private patchSearchCacheForUpdatedItem;
|
|
105
|
+
private isPatchableFilterCriterion;
|
|
106
|
+
private doesItemMatchFilterCache;
|
|
107
|
+
private patchFilterCacheForAddedItems;
|
|
108
|
+
private patchFilterCacheForUpdatedItem;
|
|
109
|
+
private patchSortCacheForAddedItems;
|
|
110
|
+
private patchSortCacheForUpdatedItem;
|
|
111
|
+
private patchSortCacheForRemovedItems;
|
|
112
|
+
search(query: string): T[] & MergeEnginesChain<T>;
|
|
113
|
+
search(field: (keyof T & string) | (string & {}), query: string): T[] & MergeEnginesChain<T>;
|
|
114
|
+
sort(descriptors: SortDescriptor<T>[]): T[] & MergeEnginesChain<T>;
|
|
115
|
+
sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[] & MergeEnginesChain<T>;
|
|
116
|
+
filter(criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
117
|
+
filter(data: T[], criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
|
|
118
|
+
private withChain;
|
|
119
|
+
getOriginData(): T[];
|
|
120
|
+
add(items: T[]): this;
|
|
121
|
+
update(descriptor: UpdateDescriptor<T>): this;
|
|
122
|
+
clearIndexes(module: MergeModuleName): this;
|
|
123
|
+
data(data: T[]): this;
|
|
124
|
+
clearData(module: MergeModuleName): this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { CollectionItem, FilterCriterion, MergeEngines, SortDescriptor };
|
|
128
|
+
export type { EngineApi, EngineConstructor, MergeEnginesChain, MergeEnginesOptions, MergeFilterOptions, MergeModuleName, MergeSearchOptions, MergeSortOptions };
|
package/dist/merge/index.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { e as MergeEngines };
|
|
1
|
+
import{t as m}from"../chunks/merge-BRXHTBZ0.mjs";export{m as MergeEngines};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { S as State } from '../State-CYIe-3He.js';
|
|
2
|
+
import { C as CollectionItem, U as UpdateDescriptor } from '../types-DONld7xY.js';
|
|
3
|
+
export { I as IndexableKey } from '../types-DONld7xY.js';
|
|
4
|
+
|
|
5
|
+
interface TextSearchEngineOptions<T extends CollectionItem = CollectionItem> {
|
|
6
|
+
data?: T[];
|
|
7
|
+
fields?: (keyof T & string)[];
|
|
8
|
+
nestedFields?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Minimum query length required to trigger a search. Defaults to `1`.
|
|
11
|
+
*
|
|
12
|
+
* Queries shorter than the trigram length (3) always use a linear scan even
|
|
13
|
+
* when an index is configured, because the index only stores trigrams. Set
|
|
14
|
+
* `minQueryLength` to `3` or higher to skip sub-trigram queries entirely and
|
|
15
|
+
* guarantee that every accepted query hits the index.
|
|
16
|
+
*/
|
|
17
|
+
minQueryLength?: number;
|
|
18
|
+
/**
|
|
19
|
+
* When `true`, each search narrows its source to the previous result if the
|
|
20
|
+
* new query includes the previous query as a prefix/substring. Useful for
|
|
21
|
+
* search-as-you-type scenarios where the user incrementally refines the query.
|
|
22
|
+
*
|
|
23
|
+
* Call {@link TextSearchEngine.resetSearchState} to discard the saved result
|
|
24
|
+
* and force the next search to scan the full dataset.
|
|
25
|
+
*/
|
|
26
|
+
filterByPreviousResult?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Suppresses non-production fallback warnings.
|
|
29
|
+
* Diagnostic warnings also stop accumulating in {@link TextSearchEngine.getWarnings}.
|
|
30
|
+
*/
|
|
31
|
+
silent?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface SearchQueryOptions {
|
|
34
|
+
limit?: number;
|
|
35
|
+
offset?: number;
|
|
36
|
+
}
|
|
37
|
+
interface TextSearchEngineStats {
|
|
38
|
+
totalQueries: number;
|
|
39
|
+
indexedQueries: number;
|
|
40
|
+
fallbackQueries: number;
|
|
41
|
+
fallbackRate: number;
|
|
42
|
+
fallbackFields: Record<string, number>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* TextSearchEngine class for performing fast substring search on string fields
|
|
47
|
+
* using n-gram indexing and intersection.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
declare class TextSearchEngine<T extends CollectionItem> {
|
|
51
|
+
private readonly state;
|
|
52
|
+
private readonly namespace;
|
|
53
|
+
private readonly nestedCollection;
|
|
54
|
+
private readonly minQueryLength;
|
|
55
|
+
private readonly silent;
|
|
56
|
+
private cachedIndexedFieldsList;
|
|
57
|
+
private cachedLinearSearchFieldsList;
|
|
58
|
+
private readonly emittedWarningKeys;
|
|
59
|
+
private readonly warnings;
|
|
60
|
+
/**
|
|
61
|
+
* Lightweight normalizedValues-only cache for fields without n-gram index.
|
|
62
|
+
* Built lazily on first full-dataset linear scan for non-indexed fields.
|
|
63
|
+
*/
|
|
64
|
+
private normalizedValuesCache;
|
|
65
|
+
private combinedNormalizedValuesCache;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new TextSearchEngine with optional data and fields to index.
|
|
68
|
+
*/
|
|
69
|
+
constructor(options?: TextSearchEngineOptions<T> & {
|
|
70
|
+
state?: State<T>;
|
|
71
|
+
});
|
|
72
|
+
private get dataset();
|
|
73
|
+
private get runtime();
|
|
74
|
+
private get flatIndexes();
|
|
75
|
+
private get indexedFields();
|
|
76
|
+
private shouldDeferMutationIndexUpdates;
|
|
77
|
+
private markDeferredMutationState;
|
|
78
|
+
private ensureConfiguredIndexesReady;
|
|
79
|
+
private rebuildConfiguredIndexes;
|
|
80
|
+
/**
|
|
81
|
+
* Builds an n-gram index for the given field from arbitrary data.
|
|
82
|
+
*/
|
|
83
|
+
private buildIndexFromData;
|
|
84
|
+
search(query: string, options?: SearchQueryOptions): T[];
|
|
85
|
+
search(field: (keyof T & string) | (string & {}), query: string, options?: SearchQueryOptions): T[];
|
|
86
|
+
searchAll(query: string, options?: SearchQueryOptions): T[];
|
|
87
|
+
private normalizeQuery;
|
|
88
|
+
private normalizeSearchWindow;
|
|
89
|
+
private shouldTrackPreviousResult;
|
|
90
|
+
private hasReachedWindowLimit;
|
|
91
|
+
private sliceItems;
|
|
92
|
+
private collectItemsFromIndices;
|
|
93
|
+
private createLookup;
|
|
94
|
+
private getRestrictionLookup;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the data source for search based on filterByPreviousResult setting.
|
|
97
|
+
* When the new query narrows the previous one, returns previousResult with indices.
|
|
98
|
+
* Otherwise resets previous state and returns the full dataset.
|
|
99
|
+
*/
|
|
100
|
+
private getSearchSource;
|
|
101
|
+
/**
|
|
102
|
+
* Saves the search result for potential reuse on subsequent narrowing queries.
|
|
103
|
+
*/
|
|
104
|
+
private saveSearchResult;
|
|
105
|
+
private persistSearchResult;
|
|
106
|
+
/**
|
|
107
|
+
* Resets the previous search result, forcing the next search to use the full dataset.
|
|
108
|
+
*
|
|
109
|
+
* @see {@link TextSearchEngineOptions.filterByPreviousResult}
|
|
110
|
+
*/
|
|
111
|
+
resetSearchState(): this;
|
|
112
|
+
getWarnings(): string[];
|
|
113
|
+
getStats(): TextSearchEngineStats;
|
|
114
|
+
resetStats(): this;
|
|
115
|
+
private clearPreviousSearchState;
|
|
116
|
+
private recordIndexedQuery;
|
|
117
|
+
private recordFallbackQuery;
|
|
118
|
+
private shouldEmitFallbackWarning;
|
|
119
|
+
private warnAboutFallback;
|
|
120
|
+
private getResolvedFlatIndex;
|
|
121
|
+
private getQueryGrams;
|
|
122
|
+
/**
|
|
123
|
+
* Searches all indexed fields.
|
|
124
|
+
*/
|
|
125
|
+
private searchAllFields;
|
|
126
|
+
private searchAllFieldsIndexed;
|
|
127
|
+
private searchAllFieldsIndexedInCandidates;
|
|
128
|
+
/**
|
|
129
|
+
* Searches a specific field.
|
|
130
|
+
*/
|
|
131
|
+
private searchField;
|
|
132
|
+
/**
|
|
133
|
+
* Searches a field using prepared query grams, returning matched items and indices.
|
|
134
|
+
* Delegates to searchFieldWithPreparedQueryIndices for the core intersection logic.
|
|
135
|
+
*/
|
|
136
|
+
private searchFieldWithPreparedQuery;
|
|
137
|
+
/**
|
|
138
|
+
* Core indexed search: returns dataset indices of matching items.
|
|
139
|
+
* If the cached index is stale (version mismatch), rebuilds it lazily.
|
|
140
|
+
*/
|
|
141
|
+
private searchFieldWithPreparedQueryIndices;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the cached list of indexed field names, rebuilding if stale.
|
|
144
|
+
*/
|
|
145
|
+
private getIndexedFieldsList;
|
|
146
|
+
private materializeIndicesResult;
|
|
147
|
+
private getLinearSearchFields;
|
|
148
|
+
/**
|
|
149
|
+
* Eagerly builds normalizedValues for a field without n-gram overhead.
|
|
150
|
+
* Stores in a lightweight cache so subsequent linear scans reuse it.
|
|
151
|
+
*/
|
|
152
|
+
private buildNormalizedValuesOnly;
|
|
153
|
+
private buildCombinedNormalizedValues;
|
|
154
|
+
private buildCombinedNormalizedValue;
|
|
155
|
+
private getCombinedNormalizedValues;
|
|
156
|
+
/**
|
|
157
|
+
* Updates only the entry at `index` in every cached normalizedValues array,
|
|
158
|
+
* avoiding a full O(n) rebuild when a single item is updated.
|
|
159
|
+
*/
|
|
160
|
+
private invalidateNormalizedValuesCacheEntry;
|
|
161
|
+
/**
|
|
162
|
+
* Searches all fields linearly, using pre-normalized values when available.
|
|
163
|
+
* When `sourceIndices` is provided, iterates only those dataset positions
|
|
164
|
+
* (previousResult narrowing path) and resolves items via this.dataset[idx].
|
|
165
|
+
*/
|
|
166
|
+
private searchLinearAllFields;
|
|
167
|
+
/**
|
|
168
|
+
* Searches a specific field linearly, using pre-normalized values when available.
|
|
169
|
+
* When `sourceIndices` is provided, resolves items via this.dataset[idx].
|
|
170
|
+
*/
|
|
171
|
+
private searchLinearSingleField;
|
|
172
|
+
clearIndexes(): this;
|
|
173
|
+
getOriginData(): T[];
|
|
174
|
+
data(data: T[]): this;
|
|
175
|
+
add(items: T[]): this;
|
|
176
|
+
update(descriptor: UpdateDescriptor<T>): this;
|
|
177
|
+
private applyAddedItems;
|
|
178
|
+
clearData(): this;
|
|
179
|
+
private handleStateMutation;
|
|
180
|
+
private addItemsToField;
|
|
181
|
+
private applyUpdatedItem;
|
|
182
|
+
private applyRemovedItem;
|
|
183
|
+
private updateIndexedField;
|
|
184
|
+
private removeIndexedFieldValue;
|
|
185
|
+
private moveIndexedFieldValue;
|
|
186
|
+
private getNormalizedFieldValue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { CollectionItem, TextSearchEngine };
|
|
190
|
+
export type { SearchQueryOptions, TextSearchEngineOptions, TextSearchEngineStats };
|