@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.
Files changed (66) hide show
  1. package/README.md +93 -75
  2. package/dist/{State.d.ts → State-CYIe-3He.d.ts} +5 -3
  3. package/dist/chunks/constants-DK9S0Db0.mjs +1 -0
  4. package/dist/chunks/merge-C6intZSe.mjs +1 -0
  5. package/dist/filter/index.d.ts +114 -4
  6. package/dist/filter/index.mjs +1 -2
  7. package/dist/index.d.ts +2 -4
  8. package/dist/index.mjs +1 -2
  9. package/dist/merge/index.d.ts +131 -4
  10. package/dist/merge/index.mjs +1 -2
  11. package/dist/search/index.d.ts +191 -4
  12. package/dist/search/index.mjs +1 -2
  13. package/dist/sort/index.d.ts +57 -4
  14. package/dist/sort/index.mjs +1 -2
  15. package/dist/types-DONld7xY.d.ts +74 -0
  16. package/package.json +6 -2
  17. package/dist/State.mjs +0 -183
  18. package/dist/constants.d.ts +0 -5
  19. package/dist/constants.mjs +0 -4
  20. package/dist/filter/chain.d.ts +0 -9
  21. package/dist/filter/chain.mjs +0 -22
  22. package/dist/filter/constants.d.ts +0 -2
  23. package/dist/filter/criterion.d.ts +0 -6
  24. package/dist/filter/criterion.mjs +0 -64
  25. package/dist/filter/errors.d.ts +0 -7
  26. package/dist/filter/errors.mjs +0 -17
  27. package/dist/filter/filter.d.ts +0 -89
  28. package/dist/filter/filter.mjs +0 -439
  29. package/dist/filter/nested.d.ts +0 -32
  30. package/dist/filter/nested.mjs +0 -246
  31. package/dist/filter/types.d.ts +0 -74
  32. package/dist/filter/utils.d.ts +0 -4
  33. package/dist/filter/utils.mjs +0 -29
  34. package/dist/indexer.d.ts +0 -41
  35. package/dist/indexer.mjs +0 -101
  36. package/dist/internal.d.ts +0 -6
  37. package/dist/internal.mjs +0 -18
  38. package/dist/merge/chain.d.ts +0 -9
  39. package/dist/merge/chain.mjs +0 -23
  40. package/dist/merge/constants.d.ts +0 -6
  41. package/dist/merge/constants.mjs +0 -8
  42. package/dist/merge/errors.d.ts +0 -8
  43. package/dist/merge/errors.mjs +0 -19
  44. package/dist/merge/merge-engines.d.ts +0 -75
  45. package/dist/merge/merge-engines.mjs +0 -432
  46. package/dist/merge/module-adapters.d.ts +0 -7
  47. package/dist/merge/module-adapters.mjs +0 -41
  48. package/dist/merge/types.d.ts +0 -125
  49. package/dist/search/constants.d.ts +0 -5
  50. package/dist/search/nested.d.ts +0 -41
  51. package/dist/search/nested.mjs +0 -210
  52. package/dist/search/ngram.d.ts +0 -23
  53. package/dist/search/ngram.mjs +0 -96
  54. package/dist/search/text-search.d.ts +0 -146
  55. package/dist/search/text-search.mjs +0 -696
  56. package/dist/search/types.d.ts +0 -93
  57. package/dist/search/utils.d.ts +0 -4
  58. package/dist/search/utils.mjs +0 -22
  59. package/dist/sort/errors.d.ts +0 -5
  60. package/dist/sort/errors.mjs +0 -11
  61. package/dist/sort/sorter.d.ts +0 -47
  62. package/dist/sort/sorter.mjs +0 -375
  63. package/dist/sort/types.d.ts +0 -18
  64. package/dist/sort/utils.d.ts +0 -17
  65. package/dist/sort/utils.mjs +0 -38
  66. package/dist/types.d.ts +0 -73
@@ -1,4 +1,131 @@
1
- export { MergeEngines } from "./merge-engines";
2
- export type { MergeEnginesOptions, EngineApi, EngineConstructor, MergeEnginesChain, MergeFilterOptions, MergeModuleName, MergeSearchOptions, MergeSortOptions, } from "./types";
3
- export type { CollectionItem, IndexableKey, FilterCriterion, SortDescriptor, SortDirection, } from "../types";
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { C as CollectionItem, d as SortDescriptor, F as FilterCriterion, I as IndexableKey, U as UpdateDescriptor } from '../types-DONld7xY.js';
2
+ export { 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
+ fields?: (keyof T & string)[];
19
+ nestedFields?: string[];
20
+ }
21
+ 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
+ delete(field: IndexableKey<T> & string, value: T[IndexableKey<T> & string]): MergeEngines<T>;
31
+ delete(field: IndexableKey<T> & string, values: T[IndexableKey<T> & string][]): MergeEngines<T>;
32
+ update(descriptor: UpdateDescriptor<T>): MergeEngines<T>;
33
+ data(data: T[]): MergeEngines<T>;
34
+ clearIndexes(module: MergeModuleName): T[] & MergeEnginesChain<T>;
35
+ clearData(module: MergeModuleName): T[] & MergeEnginesChain<T>;
36
+ }
37
+ interface EngineConstructor {
38
+ new (options: Record<string, unknown>): object;
39
+ prototype: object;
40
+ name: string;
41
+ }
42
+ interface EngineApi {
43
+ [methodName: string]: ((...args: unknown[]) => unknown) | undefined;
44
+ }
45
+ interface MergeEnginesOptions<T extends CollectionItem> {
46
+ imports: EngineConstructor[];
47
+ data: T[];
48
+ filterByPreviousResult?: boolean;
49
+ search?: MergeSearchOptions<T>;
50
+ filter?: MergeFilterOptions<T>;
51
+ sort?: MergeSortOptions<T>;
52
+ [key: string]: unknown;
53
+ }
54
+
55
+ /**
56
+ * MergeEngines class that provides a unified interface for text search,
57
+ * sorting, and filtering operations on collections.
58
+ */
59
+
60
+ declare class MergeEngines<T extends CollectionItem> {
61
+ private readonly state;
62
+ private previousSearchState;
63
+ private previousFilterState;
64
+ private previousSortState;
65
+ private readonly searchModule;
66
+ private readonly sortModule;
67
+ private readonly filterModule;
68
+ private readonly chainBuilder;
69
+ /**
70
+ * Creates a new MergeEngines instance with the given options.
71
+ * Collects all modules from imports.
72
+ */
73
+ constructor(options: MergeEnginesOptions<T>);
74
+ private getAdapter;
75
+ /**
76
+ * Gets the initialization options for a module.
77
+ */
78
+ private getModuleInitOptions;
79
+ private validateFilterByPreviousResultOptions;
80
+ private isPreviousResultEnabled;
81
+ private getPreviousResultInput;
82
+ private trackPreviousResult;
83
+ private clearOperationState;
84
+ private createSearchCacheKey;
85
+ private createSortCacheKey;
86
+ private createFilterCacheKey;
87
+ private handleStateMutation;
88
+ private queueSearchCacheMutation;
89
+ private queueFilterCacheMutation;
90
+ private queueSortCacheMutation;
91
+ private resolvePendingSortCache;
92
+ private resolvePendingSearchCache;
93
+ private resolvePendingFilterCache;
94
+ private applySortCacheMutation;
95
+ private applySearchCacheMutation;
96
+ private applyFilterCacheMutation;
97
+ private canPatchStoredDatasetSearch;
98
+ private canPatchStoredDatasetFilter;
99
+ private canPatchStoredDatasetSort;
100
+ private compareItemsByDescriptors;
101
+ private findSortInsertPosition;
102
+ private findDatasetInsertPosition;
103
+ private doesItemMatchSearchCache;
104
+ private patchSearchCacheForAddedItems;
105
+ private patchSearchCacheForUpdatedItem;
106
+ private isPatchableFilterCriterion;
107
+ private doesItemMatchFilterCache;
108
+ private patchFilterCacheForAddedItems;
109
+ private patchFilterCacheForUpdatedItem;
110
+ private patchSortCacheForAddedItems;
111
+ private patchSortCacheForUpdatedItem;
112
+ private patchSortCacheForRemovedItems;
113
+ search(query: string): T[] & MergeEnginesChain<T>;
114
+ search(field: (keyof T & string) | (string & {}), query: string): T[] & MergeEnginesChain<T>;
115
+ sort(descriptors: SortDescriptor<T>[]): T[] & MergeEnginesChain<T>;
116
+ sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[] & MergeEnginesChain<T>;
117
+ filter(criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
118
+ filter(data: T[], criteria: FilterCriterion<T>[]): T[] & MergeEnginesChain<T>;
119
+ private withChain;
120
+ getOriginData(): T[];
121
+ add(items: T[]): this;
122
+ delete(field: IndexableKey<T> & string, value: T[IndexableKey<T> & string]): this;
123
+ delete(field: IndexableKey<T> & string, values: T[IndexableKey<T> & string][]): this;
124
+ update(descriptor: UpdateDescriptor<T>): this;
125
+ clearIndexes(module: MergeModuleName): this;
126
+ data(data: T[]): this;
127
+ clearData(module: MergeModuleName): this;
128
+ }
129
+
130
+ export { CollectionItem, FilterCriterion, IndexableKey, MergeEngines, SortDescriptor };
131
+ export type { EngineApi, EngineConstructor, MergeEnginesChain, MergeEnginesOptions, MergeFilterOptions, MergeModuleName, MergeSearchOptions, MergeSortOptions };
@@ -1,2 +1 @@
1
- import { MergeEngines as e } from "./merge-engines.mjs";
2
- export { e as MergeEngines };
1
+ import{t as m}from"../chunks/merge-C6intZSe.mjs";export{m as MergeEngines};
@@ -1,4 +1,191 @@
1
- export { TextSearchEngine } from "./text-search";
2
- export type { SearchQueryOptions, TextSearchEngineOptions, TextSearchEngineStats, } from "./types";
3
- export type { CollectionItem, IndexableKey } from "../types";
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { S as State } from '../State-CYIe-3He.js';
2
+ import { C as CollectionItem, I as IndexableKey, U as UpdateDescriptor } from '../types-DONld7xY.js';
3
+
4
+ interface TextSearchEngineOptions<T extends CollectionItem = CollectionItem> {
5
+ data?: T[];
6
+ fields?: (keyof T & string)[];
7
+ nestedFields?: string[];
8
+ /**
9
+ * Minimum query length required to trigger a search. Defaults to `1`.
10
+ *
11
+ * Queries shorter than the trigram length (3) always use a linear scan even
12
+ * when an index is configured, because the index only stores trigrams. Set
13
+ * `minQueryLength` to `3` or higher to skip sub-trigram queries entirely and
14
+ * guarantee that every accepted query hits the index.
15
+ */
16
+ minQueryLength?: number;
17
+ /**
18
+ * When `true`, each search narrows its source to the previous result if the
19
+ * new query includes the previous query as a prefix/substring. Useful for
20
+ * search-as-you-type scenarios where the user incrementally refines the query.
21
+ *
22
+ * Call {@link TextSearchEngine.resetSearchState} to discard the saved result
23
+ * and force the next search to scan the full dataset.
24
+ */
25
+ filterByPreviousResult?: boolean;
26
+ /**
27
+ * Suppresses non-production fallback warnings.
28
+ * Diagnostic warnings also stop accumulating in {@link TextSearchEngine.getWarnings}.
29
+ */
30
+ silent?: boolean;
31
+ }
32
+ interface SearchQueryOptions {
33
+ limit?: number;
34
+ offset?: number;
35
+ }
36
+ interface TextSearchEngineStats {
37
+ totalQueries: number;
38
+ indexedQueries: number;
39
+ fallbackQueries: number;
40
+ fallbackRate: number;
41
+ fallbackFields: Record<string, number>;
42
+ }
43
+
44
+ /**
45
+ * TextSearchEngine class for performing fast substring search on string fields
46
+ * using n-gram indexing and intersection.
47
+ */
48
+
49
+ declare class TextSearchEngine<T extends CollectionItem> {
50
+ private readonly state;
51
+ private readonly namespace;
52
+ private readonly nestedCollection;
53
+ private readonly minQueryLength;
54
+ private readonly silent;
55
+ private cachedIndexedFieldsList;
56
+ private cachedLinearSearchFieldsList;
57
+ private readonly emittedWarningKeys;
58
+ private readonly warnings;
59
+ /**
60
+ * Lightweight normalizedValues-only cache for fields without n-gram index.
61
+ * Built lazily on first full-dataset linear scan for non-indexed fields.
62
+ */
63
+ private normalizedValuesCache;
64
+ private combinedNormalizedValuesCache;
65
+ /**
66
+ * Creates a new TextSearchEngine with optional data and fields to index.
67
+ */
68
+ constructor(options?: TextSearchEngineOptions<T> & {
69
+ state?: State<T>;
70
+ });
71
+ private get dataset();
72
+ private get runtime();
73
+ private get flatIndexes();
74
+ private get indexedFields();
75
+ private shouldDeferMutationIndexUpdates;
76
+ private markDeferredMutationState;
77
+ private ensureConfiguredIndexesReady;
78
+ private rebuildConfiguredIndexes;
79
+ /**
80
+ * Builds an n-gram index for the given field from arbitrary data.
81
+ */
82
+ private buildIndexFromData;
83
+ search(query: string, options?: SearchQueryOptions): T[];
84
+ search(field: (keyof T & string) | (string & {}), query: string, options?: SearchQueryOptions): T[];
85
+ searchAll(query: string, options?: SearchQueryOptions): T[];
86
+ private normalizeQuery;
87
+ private normalizeSearchWindow;
88
+ private shouldTrackPreviousResult;
89
+ private hasReachedWindowLimit;
90
+ private sliceItems;
91
+ private collectItemsFromIndices;
92
+ private createLookup;
93
+ private getRestrictionLookup;
94
+ /**
95
+ * Returns the data source for search based on filterByPreviousResult setting.
96
+ * When the new query narrows the previous one, returns previousResult with indices.
97
+ * Otherwise resets previous state and returns the full dataset.
98
+ */
99
+ private getSearchSource;
100
+ /**
101
+ * Saves the search result for potential reuse on subsequent narrowing queries.
102
+ */
103
+ private saveSearchResult;
104
+ private persistSearchResult;
105
+ /**
106
+ * Resets the previous search result, forcing the next search to use the full dataset.
107
+ *
108
+ * @see {@link TextSearchEngineOptions.filterByPreviousResult}
109
+ */
110
+ resetSearchState(): this;
111
+ getWarnings(): string[];
112
+ getStats(): TextSearchEngineStats;
113
+ resetStats(): this;
114
+ private clearPreviousSearchState;
115
+ private recordIndexedQuery;
116
+ private recordFallbackQuery;
117
+ private shouldEmitFallbackWarning;
118
+ private warnAboutFallback;
119
+ private getResolvedFlatIndex;
120
+ private getQueryGrams;
121
+ /**
122
+ * Searches all indexed fields.
123
+ */
124
+ private searchAllFields;
125
+ private searchAllFieldsIndexed;
126
+ private searchAllFieldsIndexedInCandidates;
127
+ /**
128
+ * Searches a specific field.
129
+ */
130
+ private searchField;
131
+ /**
132
+ * Searches a field using prepared query grams, returning matched items and indices.
133
+ * Delegates to searchFieldWithPreparedQueryIndices for the core intersection logic.
134
+ */
135
+ private searchFieldWithPreparedQuery;
136
+ /**
137
+ * Core indexed search: returns dataset indices of matching items.
138
+ * If the cached index is stale (version mismatch), rebuilds it lazily.
139
+ */
140
+ private searchFieldWithPreparedQueryIndices;
141
+ /**
142
+ * Returns the cached list of indexed field names, rebuilding if stale.
143
+ */
144
+ private getIndexedFieldsList;
145
+ private materializeIndicesResult;
146
+ private getLinearSearchFields;
147
+ /**
148
+ * Eagerly builds normalizedValues for a field without n-gram overhead.
149
+ * Stores in a lightweight cache so subsequent linear scans reuse it.
150
+ */
151
+ private buildNormalizedValuesOnly;
152
+ private buildCombinedNormalizedValues;
153
+ private buildCombinedNormalizedValue;
154
+ private getCombinedNormalizedValues;
155
+ /**
156
+ * Updates only the entry at `index` in every cached normalizedValues array,
157
+ * avoiding a full O(n) rebuild when a single item is updated.
158
+ */
159
+ private invalidateNormalizedValuesCacheEntry;
160
+ /**
161
+ * Searches all fields linearly, using pre-normalized values when available.
162
+ * When `sourceIndices` is provided, iterates only those dataset positions
163
+ * (previousResult narrowing path) and resolves items via this.dataset[idx].
164
+ */
165
+ private searchLinearAllFields;
166
+ /**
167
+ * Searches a specific field linearly, using pre-normalized values when available.
168
+ * When `sourceIndices` is provided, resolves items via this.dataset[idx].
169
+ */
170
+ private searchLinearSingleField;
171
+ clearIndexes(): this;
172
+ getOriginData(): T[];
173
+ data(data: T[]): this;
174
+ add(items: T[]): this;
175
+ delete(field: IndexableKey<T> & string, value: T[IndexableKey<T> & string]): this;
176
+ delete(field: IndexableKey<T> & string, values: T[IndexableKey<T> & string][]): this;
177
+ update(descriptor: UpdateDescriptor<T>): this;
178
+ private applyAddedItems;
179
+ clearData(): this;
180
+ private handleStateMutation;
181
+ private addItemsToField;
182
+ private applyUpdatedItem;
183
+ private applyRemovedItem;
184
+ private updateIndexedField;
185
+ private removeIndexedFieldValue;
186
+ private moveIndexedFieldValue;
187
+ private getNormalizedFieldValue;
188
+ }
189
+
190
+ export { CollectionItem, IndexableKey, TextSearchEngine };
191
+ export type { SearchQueryOptions, TextSearchEngineOptions, TextSearchEngineStats };
@@ -1,2 +1 @@
1
- import { TextSearchEngine as e } from "./text-search.mjs";
2
- export { e as TextSearchEngine };
1
+ import{c as e,i as t,l as s,n as i,o as n,s as r,u as l}from"../chunks/constants-DK9S0Db0.mjs";function a(e,t,s,i){const n=function(e,t){const s=[];for(const i of t){const t=e.get(i);if(!t)return null;s.push(t)}return function(e){for(let t=0;t<e.length-1;t++){let s=t;for(let i=t+1;i<e.length;i++)e[i].size<e[s].size&&(s=i);if(s!==t){const i=e[t];e[t]=e[s],e[s]=i}}}(s),s}(e,t);if(null===n)return null;const r=n[0];return{smallestPostingList:r,matches:e=>r.has(e)&&function(e,t){for(let s=0;s<t.length;s++)if(!t[s].has(e))return!1;return!0}(e,n)&&Boolean(s[e]?.includes(i))}}function o(e,t){const s=e.get(t);if(s)return s;const i=/* @__PURE__ */new Set;return e.set(t,i),i}function d(e,t,s){const i=Math.min(3,t.length);for(let n=2;n<=i;n++){const i=t.length-n;for(let r=0;r<=i;r++)o(e,t.substring(r,r+n)).add(s)}}function h(e,t,s,i,n={}){const{restrictionLookup:r=null,take:l=Number.POSITIVE_INFINITY}=n,o=a(e,t,s,i);if(null===o)return[];const d=[];for(const a of o.smallestPostingList)if((null===r||r[a])&&o.matches(a)&&(d.push(a),d.length>=l))break;return d}function u(e,t,s,i,n){const{candidateIndices:r,restrictionLookup:l=null,take:o=Number.POSITIVE_INFINITY}=n;if(0===r.length)return[];const d=a(e,t,s,i);if(null===d)return[];const h=[];if(null===l||r.length<=d.smallestPostingList.size){for(let e=0;e<r.length;e++){const t=r[e];if(d.matches(t)&&(h.push(t),h.length>=o))break}return h}for(const a of d.smallestPostingList)if(l[a]&&d.matches(a)&&(h.push(a),h.length>=o))break;return h}function c(e,t,s){const i=Math.min(3,t.length);for(let n=2;n<=i;n++){const i=t.length-n;for(let r=0;r<=i;r++){const i=t.substring(r,r+n),l=e.get(i);l&&(l.delete(s),0===l.size&&e.delete(i))}}}var f=class{constructor(e={ngramIndexes:/* @__PURE__ */new Map,normalizedFieldValues:/* @__PURE__ */new Map}){this.storage=e,this.registeredFields=/* @__PURE__ */new Set,this.fieldDescriptors=/* @__PURE__ */new Map}registerFields(e){if(e?.length)for(const t of e)this.registerField(t)}hasRegisteredFields(){return this.registeredFields.size>0}hasField(e){return this.registeredFields.has(e)}hasIndexes(){return this.storage.ngramIndexes.size>0}clearIndexes(){this.storage.ngramIndexes.clear(),this.storage.normalizedFieldValues.clear()}buildIndexes(e){this.clearIndexes();for(const t of this.registeredFields)this.buildIndex(e,t)}addItems(e,t){if(0!==e.length&&0!==this.storage.ngramIndexes.size)for(const s of this.storage.ngramIndexes.keys())this.addItemsToField(s,e,t)}updateItem(e,t,s){if(0!==this.storage.ngramIndexes.size)for(const i of this.storage.ngramIndexes.keys())this.updateItemInField(i,e,t,s)}removeItem(e,t){if(0!==this.storage.ngramIndexes.size)for(const s of this.storage.ngramIndexes.keys())this.removeItemFromField(s,e,t)}moveItem(e,t,s){if(0!==this.storage.ngramIndexes.size&&t!==s)for(const i of this.storage.ngramIndexes.keys())this.moveItemForField(i,e,t,s)}searchAllIndexedFieldIndices(e,t,s,i){const n=/* @__PURE__ */new Set,r=[];for(const l of this.storage.ngramIndexes.keys())for(const a of this.searchIndexedFieldIndices(l,e,t,s,i))n.has(a)||(n.add(a),r.push(a));return r}searchIndexedField(e,t,s,i,n,r,l=Number.POSITIVE_INFINITY){const a=this.searchIndexedFieldIndices(t,s,i,n,r,l),o=[];for(let d=0;d<a.length;d++){const t=e[a[d]];t&&o.push(t)}return o}searchIndexedFieldIndices(e,t,s,i,n,r=Number.POSITIVE_INFINITY){const l=this.storage.ngramIndexes.get(e);if(!l)return[];const a=this.storage.normalizedFieldValues.get(e)??[];return null!=n?u(l,s,a,t,{candidateIndices:n,restrictionLookup:i,take:r}):h(l,s,a,t,{restrictionLookup:i,take:r})}searchFieldLinear(e,t,s){const i=this.searchFieldLinearIndices(e,t,s),n=[];for(let r=0;r<i.length;r++){const t=e[i[r]];t&&n.push(t)}return n}searchFieldLinearIndices(e,t,s,i){const n=this.fieldDescriptors.get(t);if(!n)return[];const{collectionKey:r,nestedKey:l}=n,a=[];if(i){for(let t=0;t<i.length;t++){const n=i[t],o=e[n][r];if(!Array.isArray(o))continue;let d=!1;for(let e=0;e<o.length;e++){const t=o[e][l];if("string"==typeof t&&t.toLowerCase().includes(s)){d=!0;break}}d&&a.push(n)}return a}for(let o=0;o<e.length;o++){const t=e[o][r];if(!Array.isArray(t))continue;let i=!1;for(let e=0;e<t.length;e++){const n=t[e][l];if("string"==typeof n&&n.toLowerCase().includes(s)){i=!0;break}}i&&a.push(o)}return a}matchesAnyField(e,t){for(const s of this.registeredFields){const i=this.fieldDescriptors.get(s);if(!i)continue;const{collectionKey:n,nestedKey:r}=i,l=e[n];if(Array.isArray(l))for(let e=0;e<l.length;e++){const s=l[e][r];if("string"==typeof s&&s.toLowerCase().includes(t))return!0}}return!1}registerField(e){const t=n(e);t&&(this.registeredFields.add(e),this.fieldDescriptors.set(e,t))}getNormalizedValues(e){const t=this.storage.normalizedFieldValues.get(e);if(t)return t;const s=[];return this.storage.normalizedFieldValues.set(e,s),s}buildIndex(e,t){const s=this.fieldDescriptors.get(t);if(!s)return;const{collectionKey:i,nestedKey:n}=s,r=/* @__PURE__ */new Map,l=new Array(e.length);for(let a=0,o=e.length;a<o;a++){const t=e[a][i];if(!Array.isArray(t))continue;const s=[];for(let e=0;e<t.length;e++){const i=t[e][n];"string"==typeof i&&s.push(i.toLowerCase())}if(0===s.length)continue;const o=s.join("\n");l[a]=o,d(r,o,a)}this.storage.ngramIndexes.set(t,r),this.storage.normalizedFieldValues.set(t,l)}addItemsToField(e,t,s){const i=this.fieldDescriptors.get(e),n=this.storage.ngramIndexes.get(e);if(!i||!n)return;const r=this.getNormalizedValues(e),{collectionKey:l,nestedKey:a}=i;for(let o=0;o<t.length;o++){const e=t[o][l];if(!Array.isArray(e))continue;const i=[],h=s+o;for(let t=0;t<e.length;t++){const s=e[t][a];"string"==typeof s&&i.push(s.toLowerCase())}if(0===i.length)continue;const u=i.join("\n");r[h]=u,d(n,u,h)}}updateItemInField(e,t,s,i){const n=this.storage.ngramIndexes.get(e);if(!n)return;const r=this.getNormalizedValues(e),l=this.getNormalizedItemValue(e,s),a=this.getNormalizedItemValue(e,t);l!==a&&(l&&c(n,l,i),a?(r[i]=a,d(n,a,i)):delete r[i])}removeItemFromField(e,t,s){const i=this.storage.ngramIndexes.get(e);if(!i)return;const n=this.getNormalizedValues(e),r=n[s]??this.getNormalizedItemValue(e,t);r&&c(i,r,s),delete n[s]}moveItemForField(e,t,s,i){const n=this.storage.ngramIndexes.get(e);if(!n)return;const r=this.getNormalizedValues(e),l=r[s]??this.getNormalizedItemValue(e,t);l?(c(n,l,s),d(n,l,i),r[i]=l,delete r[s]):delete r[s]}getNormalizedItemValue(e,t){const s=this.fieldDescriptors.get(e);if(!s)return null;const{collectionKey:i,nestedKey:n}=s,r=t[i];if(!Array.isArray(r))return null;const l=[];for(let a=0;a<r.length;a++){const e=r[a][n];"string"==typeof e&&l.push(e.toLowerCase())}return 0===l.length?null:l.join("\n")}},m=()=>({indexedFields:/* @__PURE__ */new Set,flatIndexes:/* @__PURE__ */new Map,nestedStorage:{ngramIndexes:/* @__PURE__ */new Map,normalizedFieldValues:/* @__PURE__ */new Map},deferredMutationVersion:null,filterByPreviousResult:!1,previousResultIndices:null,previousResultLookup:null,previousQuery:null,stats:{totalQueries:0,indexedQueries:0,fallbackQueries:0,fallbackFields:/* @__PURE__ */new Map}}),g=class{constructor(e={}){this.cachedIndexedFieldsList=null,this.cachedLinearSearchFieldsList=null,this.emittedWarningKeys=/* @__PURE__ */new Set,this.warnings=[],this.normalizedValuesCache=/* @__PURE__ */new Map,this.combinedNormalizedValuesCache=null,this.minQueryLength=e.minQueryLength??1,this.silent=e.silent??!1,this.state=e.state??new l(e.data??[]),this.namespace=this.state.createNamespace("search"),this.nestedCollection=new f(this.runtime.nestedStorage),this.nestedCollection.registerFields(e.nestedFields),this.state.subscribe(e=>this.handleStateMutation(e)),e.filterByPreviousResult&&(this.runtime.filterByPreviousResult=!0);const t=e.fields?.length,s=this.nestedCollection.hasRegisteredFields();if(t)for(const i of e.fields)this.indexedFields.add(i);this.dataset.length>0&&(t||s)&&this.rebuildConfiguredIndexes()}get dataset(){return this.state.getOriginData()}get runtime(){return this.state.getOrCreateScopedValue(this.namespace,"runtime",m)}get flatIndexes(){return this.runtime.flatIndexes}get indexedFields(){return this.runtime.indexedFields}shouldDeferMutationIndexUpdates(){return!0===this.state.getScopedValue(t,i)}markDeferredMutationState(){this.runtime.deferredMutationVersion=this.state.getMutationVersion(),this.flatIndexes.clear(),this.nestedCollection.clearIndexes(),this.cachedIndexedFieldsList=null,this.cachedLinearSearchFieldsList=null,this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null,this.clearPreviousSearchState()}ensureConfiguredIndexesReady(){null!==this.runtime.deferredMutationVersion&&(this.runtime.deferredMutationVersion=null,this.dataset.length>0&&(this.indexedFields.size>0||this.nestedCollection.hasRegisteredFields())&&this.rebuildConfiguredIndexes())}rebuildConfiguredIndexes(){this.flatIndexes.clear(),this.nestedCollection.clearIndexes(),this.cachedIndexedFieldsList=null,this.cachedLinearSearchFieldsList=null,this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null;for(const e of this.indexedFields)this.buildIndexFromData(this.dataset,e);this.nestedCollection.hasRegisteredFields()&&this.nestedCollection.buildIndexes(this.dataset)}buildIndexFromData(e,t){const s=this.state.getMutationVersion(),i=/* @__PURE__ */new Map,n=new Array(e.length);for(let r=0,l=e.length;r<l;r++){const s=e[r][t];if("string"!=typeof s)continue;const l=s.toLowerCase();n[r]=l,d(i,l,r)}this.flatIndexes.set(t,{ngramMap:i,normalizedValues:n,version:s})}search(e,t,s){return"string"==typeof t?this.searchField(e,t,s):this.searchAll(e,t)}searchAll(e,t){return this.searchAllFields(e,t)}normalizeQuery(e){return e.trim().toLowerCase()}normalizeSearchWindow(e){const t=Math.max(0,Math.trunc(e?.offset??0)),s=e?.limit,i=void 0===s?Number.POSITIVE_INFINITY:Math.max(0,Math.trunc(s));return{offset:t,limit:i,take:Number.isFinite(i)?t+i:Number.POSITIVE_INFINITY,hasWindow:t>0||Number.isFinite(i)}}shouldTrackPreviousResult(e){return!e.hasWindow}hasReachedWindowLimit(e,t){return Number.isFinite(e.limit)&&t>=e.limit}sliceItems(e,t){return t.hasWindow?e.slice(t.offset,t.take):e}collectItemsFromIndices(e,t){const s=t.hasWindow&&e.length>0?e.slice(t.offset,t.take):e,i=[];for(let n=0;n<s.length;n++){const e=this.dataset[s[n]];e&&i.push(e)}return{items:i,indices:s}}createLookup(e){const t=new Uint8Array(this.dataset.length);for(let s=0;s<e.length;s++)t[e[s]]=1;return t}getRestrictionLookup(e){const t=this.runtime.previousResultLookup;if(null!==t&&this.runtime.previousResultIndices===e&&t.length===this.dataset.length)return t;const s=this.createLookup(e);return this.runtime.previousResultLookup=s,s}getSearchSource(e){const{runtime:t}=this;return t.filterByPreviousResult?null!==t.previousQuery&&null!==t.previousResultIndices&&e.includes(t.previousQuery)?{indices:t.previousResultIndices,lookup:this.getRestrictionLookup(t.previousResultIndices)}:(t.previousResultIndices=null,t.previousResultLookup=null,t.previousQuery=null,{indices:null,lookup:null}):{indices:null,lookup:null}}saveSearchResult(e,t){const{runtime:s}=this;s.filterByPreviousResult&&(s.previousResultIndices=e,s.previousResultLookup=null,s.previousQuery=t)}persistSearchResult(e,t,s){s&&this.saveSearchResult(e.indices,t)}resetSearchState(){return this.clearPreviousSearchState(),this}getWarnings(){return[...this.warnings]}getStats(){const{totalQueries:e,indexedQueries:t,fallbackQueries:s,fallbackFields:i}=this.runtime.stats;return{totalQueries:e,indexedQueries:t,fallbackQueries:s,fallbackRate:0===e?0:s/e,fallbackFields:Object.fromEntries(i)}}resetStats(){const{stats:e}=this.runtime;return e.totalQueries=0,e.indexedQueries=0,e.fallbackQueries=0,e.fallbackFields.clear(),this}clearPreviousSearchState(){const{runtime:e}=this;e.previousResultIndices=null,e.previousResultLookup=null,e.previousQuery=null}recordIndexedQuery(){const{stats:e}=this.runtime;e.totalQueries+=1,e.indexedQueries+=1}recordFallbackQuery(e){const{stats:t}=this.runtime;t.totalQueries+=1,t.fallbackQueries+=1,t.fallbackFields.set(e,(t.fallbackFields.get(e)??0)+1)}shouldEmitFallbackWarning(e){return!this.silent&&e.length>=2}warnAboutFallback(e,t,s){if(!this.shouldEmitFallbackWarning(t))return;const i=`${e}\0${t}\0${s}`;if(this.emittedWarningKeys.has(i))return;this.emittedWarningKeys.add(i);const n=`[TextSearchEngine] warn: query "${t}" on ${e} used linear fallback. ${s}. Add the field(s) to the index schema to enable indexed search.`;this.warnings.push(n),"undefined"!=typeof process&&"production"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV&&console.warn(n)}getResolvedFlatIndex(e){const t=this.state.getMutationVersion();let s=this.flatIndexes.get(e);return s&&s.version!==t&&this.dataset.length>0&&(this.buildIndexFromData(this.dataset,e),s=this.flatIndexes.get(e)),s}getQueryGrams(e){const t=function(e){const t=function(e){const t=Math.min(3,Math.max(2,e.length)),s=e.length-t+1,i=new Array(s);for(let n=0;n<s;n++)i[n]=e.substring(n,n+t);return i}(e);if(t.length<=12)return new Set(t);const s=/* @__PURE__ */new Set,i=t.length-1;for(let n=0;n<=11;n++){const e=Math.round(n*i/11);s.add(t[e])}return s}(e);return t.size>0?t:null}searchAllFields(e,t){const s=this.normalizeQuery(e),i=this.normalizeSearchWindow(t),n="all fields";if(0===i.limit)return[];if(!s||s.length<this.minQueryLength)return this.sliceItems(this.dataset,i);s.length>=2&&this.ensureConfiguredIndexesReady();const r=this.shouldTrackPreviousResult(i),{indices:l,lookup:a}=this.getSearchSource(s);let o;const d=()=>(void 0!==o||(o=s.length>=2?this.getQueryGrams(s):null),o);if(null!==l){const e=d();if(null!==e&&(this.flatIndexes.size>0||this.nestedCollection.hasIndexes())){this.recordIndexedQuery();const t=this.searchAllFieldsIndexed(s,e,i,a,l);return this.persistSearchResult(t,s,r),t.items}this.recordFallbackQuery(n);const t=this.searchLinearAllFields(this.dataset,s,l,i);return this.persistSearchResult(t,s,r),t.items}if(!this.flatIndexes.size&&!this.nestedCollection.hasIndexes()){this.warnAboutFallback(n,s,this.indexedFields.size>0?"configured indexes are not currently built":"no indexed fields are configured"),this.recordFallbackQuery(n);const e=this.searchLinearAllFields(this.dataset,s,null,i);return this.persistSearchResult(e,s,r),e.items}const h=d();if(null===h){this.recordFallbackQuery(n);const e=this.searchLinearAllFields(this.dataset,s,null,i);return this.persistSearchResult(e,s,r),e.items}this.recordIndexedQuery();const u=this.searchAllFieldsIndexed(s,h,i,null);return this.persistSearchResult(u,s,r),u.items}searchAllFieldsIndexed(e,t,s,i,n=null){if(null!==n&&!this.nestedCollection.hasRegisteredFields()&&this.flatIndexes.size>0)return this.searchAllFieldsIndexedInCandidates(e,t,s,i,n);const r=this.dataset,l=new Uint8Array(r.length),a=[];let o=0;for(const d of this.flatIndexes.keys()){const r=this.searchFieldWithPreparedQueryIndices(d,e,t,i,n);for(let e=0;e<r.length;e++){const t=r[e];if(!l[t])if(l[t]=1,o<s.offset)o+=1;else if(a.push(t),o+=1,this.hasReachedWindowLimit(s,a.length))return this.materializeIndicesResult(a)}}for(const d of this.nestedCollection.searchAllIndexedFieldIndices(e,t,i,n))if(!l[d])if(l[d]=1,o<s.offset)o+=1;else if(a.push(d),o+=1,this.hasReachedWindowLimit(s,a.length))return this.materializeIndicesResult(a);return this.materializeIndicesResult(a)}searchAllFieldsIndexedInCandidates(e,t,s,i,n){const r=[];for(const d of this.flatIndexes.keys()){const s=this.getResolvedFlatIndex(d);if(!s)continue;const i=a(s.ngramMap,t,s.normalizedValues,e);null!==i&&r.push(i.matches)}if(0===r.length)return{items:[],indices:[]};const l=[];let o=0;for(let a=0;a<n.length;a++){const e=n[a];if(null!==i&&!i[e])continue;let t=!1;for(let s=0;s<r.length;s++)if(r[s](e)){t=!0;break}if(t)if(o<s.offset)o+=1;else if(l.push(e),o+=1,this.hasReachedWindowLimit(s,l.length))break}return this.materializeIndicesResult(l)}searchField(e,t,s){const i=this.normalizeQuery(t),n=this.normalizeSearchWindow(s),r=`field "${e}"`;if(0===n.limit)return[];if(!i||i.length<this.minQueryLength)return this.sliceItems(this.dataset,n);i.length>=2&&this.ensureConfiguredIndexesReady();const l=this.shouldTrackPreviousResult(n),{indices:a,lookup:o}=this.getSearchSource(i),d=this.nestedCollection.hasField(e);let h;const u=()=>(void 0!==h||(h=i.length>=2?this.getQueryGrams(i):null),h);if(null!==a){const t=u();if(d){if(null!==t&&this.nestedCollection.hasIndexes()){this.recordIndexedQuery();const s=this.nestedCollection.searchIndexedFieldIndices(e,i,t,o,a,n.take),r=this.collectItemsFromIndices(s,n);return this.persistSearchResult(r,i,l),r.items}this.recordFallbackQuery(r);const s=this.searchLinearSingleField(this.dataset,e,i,a,n);return this.persistSearchResult(s,i,l),s.items}if(null!==t&&this.flatIndexes.has(e)){this.recordIndexedQuery();const s=this.searchFieldWithPreparedQuery(e,i,t,n,o,a);return this.persistSearchResult(s,i,l),s.items}this.recordFallbackQuery(r);const s=this.searchLinearSingleField(this.dataset,e,i,a,n);return this.persistSearchResult(s,i,l),s.items}if(d){if(i.length>=2&&this.nestedCollection.hasIndexes()){const t=this.getQueryGrams(i);if(null===t)return[];this.recordIndexedQuery();const s=this.nestedCollection.searchIndexedFieldIndices(e,i,t,null,null,n.take),r=this.collectItemsFromIndices(s,n);return this.persistSearchResult(r,i,l),r.items}this.recordFallbackQuery(r);const t=this.searchLinearSingleField(this.dataset,e,i,null,n);return this.persistSearchResult(t,i,l),t.items}this.flatIndexes.size||this.warnAboutFallback(r,i,this.indexedFields.size>0?`field "${e}" is not backed by an active index`:"no indexed fields are configured");const c=u();if(this.flatIndexes.size>0&&null!==c){if(!this.flatIndexes.has(e))return[];this.recordIndexedQuery();const t=this.searchFieldWithPreparedQuery(e,i,c,n);return this.persistSearchResult(t,i,l),t.items}this.recordFallbackQuery(r);const f=this.searchLinearSingleField(this.dataset,e,i,null,n);return this.persistSearchResult(f,i,l),f.items}searchFieldWithPreparedQuery(e,t,s,i,n=null,r=null){const l=this.searchFieldWithPreparedQueryIndices(e,t,s,n,r,i.take);return this.collectItemsFromIndices(l,i)}searchFieldWithPreparedQueryIndices(e,t,s,i=null,n=null,r=Number.POSITIVE_INFINITY){const l=this.getResolvedFlatIndex(e);if(!l)return[];const{ngramMap:a,normalizedValues:o}=l;return null!==n?u(a,s,o,t,{candidateIndices:n,restrictionLookup:i,take:r}):h(a,s,o,t,{restrictionLookup:i,take:r})}getIndexedFieldsList(){return null===this.cachedIndexedFieldsList&&(this.cachedIndexedFieldsList=Array.from(this.indexedFields)),this.cachedIndexedFieldsList}materializeIndicesResult(e){const t=[];for(let s=0;s<e.length;s++){const i=this.dataset[e[s]];i&&t.push(i)}return{items:t,indices:e}}getLinearSearchFields(e){const t=this.getIndexedFieldsList();return t.length>0?t:(null!==this.cachedLinearSearchFieldsList||(this.cachedLinearSearchFieldsList=e.length?Object.keys(e[0]).filter(t=>"string"==typeof e[0][t]):[]),this.cachedLinearSearchFieldsList)}buildNormalizedValuesOnly(e,t){const s=new Array(e.length);for(let i=0,n=e.length;i<n;i++){const n=e[i][t];"string"==typeof n&&(s[i]=n.toLowerCase())}return this.normalizedValuesCache.set(t,s),s}buildCombinedNormalizedValues(e,t){const s=new Array(e.length);for(let i=0;i<e.length;i++)s[i]=this.buildCombinedNormalizedValue(e[i],t);return this.combinedNormalizedValuesCache={fieldsKey:t.join("\0"),values:s},s}buildCombinedNormalizedValue(e,t){let s="";for(let i=0;i<t.length;i++){const n=e[t[i]];"string"==typeof n&&(s&&(s+="\n"),s+=n.toLowerCase())}return s}getCombinedNormalizedValues(e,t){if(e!==this.dataset)return null;const s=t.join("\0");return this.combinedNormalizedValuesCache?.fieldsKey===s?this.combinedNormalizedValuesCache.values:this.buildCombinedNormalizedValues(e,t)}invalidateNormalizedValuesCacheEntry(e,t){for(const[s,i]of this.normalizedValuesCache){const n=t[s];i[e]="string"==typeof n?n.toLowerCase():""}if(null!==this.combinedNormalizedValuesCache){const s=this.combinedNormalizedValuesCache.fieldsKey.split("\0");this.combinedNormalizedValuesCache.values[e]=this.buildCombinedNormalizedValue(t,s)}}searchLinearAllFields(e,t,s,i){if(!e.length)return{items:[],indices:[]};const n=this.getLinearSearchFields(e),r=e===this.dataset,l=n.length,a=new Array(l);for(let f=0;f<l;f++){const t=n[f],s=this.flatIndexes.get(t);if(s)a[f]=s.normalizedValues;else{const s=this.normalizedValuesCache.get(t);a[f]=s||(r?this.buildNormalizedValuesOnly(e,t):null)}}const o=this.nestedCollection.hasRegisteredFields(),d=o?null:this.getCombinedNormalizedValues(e,n),h=!o&&a.every(e=>null!==e),u=[];let c=0;if(null!==s){const e=this.dataset;if(null!==d){for(let e=0;e<s.length;e++){const n=s[e];if(d[n]?.includes(t))if(c<i.offset)c+=1;else if(u.push(n),c+=1,this.hasReachedWindowLimit(i,u.length))break}return this.materializeIndicesResult(u)}if(h){for(let e=0;e<s.length;e++){const n=s[e];let r=!1;for(let e=0;e<l;e++){const s=a[e][n];if(s&&s.includes(t)){r=!0;break}}if(r)if(c<i.offset)c+=1;else if(u.push(n),c+=1,this.hasReachedWindowLimit(i,u.length))break}return this.materializeIndicesResult(u)}for(let r=0;r<s.length;r++){const d=s[r],h=e[d];let f=!1;for(let e=0;e<l;e++){const s=a[e];if(s){const e=s[d];if(e&&e.includes(t)){f=!0;break}}else{const s=h[n[e]];if("string"==typeof s&&s.toLowerCase().includes(t)){f=!0;break}}}if(!f&&o&&(f=this.nestedCollection.matchesAnyField(h,t)),f)if(c<i.offset)c+=1;else if(u.push(d),c+=1,this.hasReachedWindowLimit(i,u.length))break}return this.materializeIndicesResult(u)}if(null!==d){for(let s=0;s<e.length;s++)if(d[s]?.includes(t))if(c<i.offset)c+=1;else if(u.push(s),c+=1,this.hasReachedWindowLimit(i,u.length))break;return this.materializeIndicesResult(u)}if(h){for(let s=0;s<e.length;s++){let e=!1;for(let i=0;i<l;i++){const n=a[i][s];if(n&&n.includes(t)){e=!0;break}}if(e)if(c<i.offset)c+=1;else if(u.push(s),c+=1,this.hasReachedWindowLimit(i,u.length))break}return this.materializeIndicesResult(u)}for(let f=0;f<e.length;f++){const s=e[f];let r=!1;for(let e=0;e<l;e++){const i=a[e];if(i){const e=i[f];if(e&&e.includes(t)){r=!0;break}}else{const i=s[n[e]];if("string"==typeof i&&i.toLowerCase().includes(t)){r=!0;break}}}if(!r&&o&&(r=this.nestedCollection.matchesAnyField(s,t)),r)if(c<i.offset)c+=1;else if(u.push(f),c+=1,this.hasReachedWindowLimit(i,u.length))break}return this.materializeIndicesResult(u)}searchLinearSingleField(e,t,s,i,n){if(!e.length)return{items:[],indices:[]};if(this.nestedCollection.hasField(t)){const r=this.nestedCollection.searchFieldLinearIndices(e,t,s,i??void 0);return this.collectItemsFromIndices(r,n)}const r=[],l=this.flatIndexes.get(t),a=l?l.normalizedValues:this.normalizedValuesCache.get(t)??(e===this.dataset?this.buildNormalizedValuesOnly(e,t):null);let o=0;if(null!==i){const e=this.dataset;if(a){for(let e=0;e<i.length;e++){const t=i[e];if(a[t]?.includes(s))if(o<n.offset)o+=1;else if(r.push(t),o+=1,this.hasReachedWindowLimit(n,r.length))break}return this.materializeIndicesResult(r)}for(let l=0;l<i.length;l++){const a=i[l],d=e[a];if("string"==typeof d[t]&&d[t].toLowerCase().includes(s))if(o<n.offset)o+=1;else if(r.push(a),o+=1,this.hasReachedWindowLimit(n,r.length))break}return this.materializeIndicesResult(r)}if(a){for(let t=0;t<e.length;t++)if(a[t]?.includes(s))if(o<n.offset)o+=1;else if(r.push(t),o+=1,this.hasReachedWindowLimit(n,r.length))break;return this.materializeIndicesResult(r)}for(let d=0;d<e.length;d++)if("string"==typeof e[d][t]&&e[d][t].toLowerCase().includes(s))if(o<n.offset)o+=1;else if(r.push(d),o+=1,this.hasReachedWindowLimit(n,r.length))break;return this.materializeIndicesResult(r)}clearIndexes(){return this.flatIndexes.clear(),this.nestedCollection.clearIndexes(),this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null,this}getOriginData(){return this.state.getOriginData()}data(e){return this.state.data(e),this}add(e){return this.state.add(e),this}delete(t,i){const n=s(i);if(0===n.length)return this;const l=e(this.dataset,t,n);if(l.length>0)throw new Error(r("TextSearchEngine",t,l));return 1===n.length?(this.state.removeByFieldValue(t,n[0]),this):(this.state.removeByFieldValues(t,n),this)}update(e){return this.state.update(e),this}applyAddedItems(e,t){if(0===e.length)return this;for(const s of this.indexedFields)this.addItemsToField(s,e,t);return this.nestedCollection.addItems(e,t),this}clearData(){return this.state.clearData(),this}handleStateMutation(e){if(!this.shouldDeferMutationIndexUpdates()||"add"!==e.type&&"update"!==e.type)switch(e.type){case"add":this.applyAddedItems(e.items,e.startIndex);for(const[t,s]of this.normalizedValuesCache)for(let i=0;i<e.items.length;i++){const n=e.items[i][t];s[e.startIndex+i]="string"==typeof n?n.toLowerCase():""}return this.combinedNormalizedValuesCache=null,void this.clearPreviousSearchState();case"update":return this.applyUpdatedItem(e.index,e.previousItem,e.nextItem),this.invalidateNormalizedValuesCacheEntry(e.index,e.nextItem),void this.clearPreviousSearchState();case"data":return this.runtime.deferredMutationVersion=null,this.rebuildConfiguredIndexes(),this.combinedNormalizedValuesCache=null,void this.clearPreviousSearchState();case"clearData":return this.runtime.deferredMutationVersion=null,this.flatIndexes.clear(),this.nestedCollection.clearIndexes(),this.cachedLinearSearchFieldsList=null,this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null,void this.clearPreviousSearchState();case"remove":return this.applyRemovedItem(e.removedItem,e.removedIndex,e.movedItem,e.movedFromIndex),this.cachedLinearSearchFieldsList=null,this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null,void this.clearPreviousSearchState();case"removeMany":for(let t=0;t<e.entries.length;t++){const s=e.entries[t];this.applyRemovedItem(s.removedItem,s.removedIndex,s.movedItem,s.movedFromIndex)}return this.cachedLinearSearchFieldsList=null,this.normalizedValuesCache.clear(),this.combinedNormalizedValuesCache=null,void this.clearPreviousSearchState()}else this.markDeferredMutationState()}addItemsToField(e,t,s){const i=this.flatIndexes.get(e);if(!i)return;const{ngramMap:n,normalizedValues:r}=i;for(let l=0;l<t.length;l++){const i=t[l][e];if("string"!=typeof i)continue;const a=i.toLowerCase(),o=s+l;r[o]=a,d(n,a,o)}i.version=this.state.getMutationVersion()}applyUpdatedItem(e,t,s){for(const i of this.indexedFields)this.updateIndexedField(i,e,t,s);this.nestedCollection.updateItem(s,t,e)}applyRemovedItem(e,t,s,i){for(const n of this.indexedFields)this.removeIndexedFieldValue(n,e,t),null!==s&&null!==i&&this.moveIndexedFieldValue(n,s,i,t);this.nestedCollection.removeItem(e,t),null!==s&&null!==i&&this.nestedCollection.moveItem(s,i,t)}updateIndexedField(e,t,s,i){const n=this.flatIndexes.get(e);if(!n)return;if(s[e]===i[e])return void(n.version=this.state.getMutationVersion());const{ngramMap:r,normalizedValues:l}=n,a=this.getNormalizedFieldValue(s,e);a&&c(r,a,t);const o=this.getNormalizedFieldValue(i,e);if(!o)return delete l[t],void(n.version=this.state.getMutationVersion());l[t]=o,d(r,o,t),n.version=this.state.getMutationVersion()}removeIndexedFieldValue(e,t,s){const i=this.flatIndexes.get(e);if(!i)return;const{ngramMap:n,normalizedValues:r}=i,l=this.getNormalizedFieldValue(t,e);l&&c(n,l,s),delete r[s],i.version=this.state.getMutationVersion()}moveIndexedFieldValue(e,t,s,i){if(s===i)return;const n=this.flatIndexes.get(e);if(!n)return;const{ngramMap:r,normalizedValues:l}=n,a=l[s]??this.getNormalizedFieldValue(t,e);if(!a)return delete l[s],void(n.version=this.state.getMutationVersion());c(r,a,s),d(r,a,i),l[i]=a,delete l[s],n.version=this.state.getMutationVersion()}getNormalizedFieldValue(e,t){const s=e[t];return"string"==typeof s?s.toLowerCase():null}};export{g as TextSearchEngine};
@@ -1,4 +1,57 @@
1
- export { SortEngine } from "./sorter";
2
- export type { SortEngineOptions } from "./types";
3
- export type { CollectionItem, SortDescriptor, SortDirection } from "../types";
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { S as State } from '../State-CYIe-3He.js';
2
+ import { C as CollectionItem, I as IndexableKey, U as UpdateDescriptor, d as SortDescriptor } from '../types-DONld7xY.js';
3
+ export { e as SortDirection } from '../types-DONld7xY.js';
4
+
5
+ interface SortEngineOptions<T extends CollectionItem = CollectionItem> {
6
+ data?: T[];
7
+ fields?: (keyof T & string)[];
8
+ }
9
+
10
+ declare class SortEngine<T extends CollectionItem> {
11
+ private readonly state;
12
+ private readonly namespace;
13
+ constructor(options?: SortEngineOptions<T> & {
14
+ state?: State<T>;
15
+ });
16
+ private get dataset();
17
+ private get runtime();
18
+ private get cache();
19
+ private get indexedFields();
20
+ private shouldDeferMutationCacheUpdates;
21
+ private invalidateCachedIndexes;
22
+ private rebuildConfiguredIndexes;
23
+ private buildIndexForDataset;
24
+ private buildIndexFromData;
25
+ clearIndexes(): this;
26
+ clearData(): this;
27
+ data(data: T[]): this;
28
+ add(items: T[]): this;
29
+ delete(field: IndexableKey<T> & string, value: T[IndexableKey<T> & string]): this;
30
+ delete(field: IndexableKey<T> & string, values: T[IndexableKey<T> & string][]): this;
31
+ update(descriptor: UpdateDescriptor<T>): this;
32
+ private applyAddedItems;
33
+ getOriginData(): T[];
34
+ private handleStateMutation;
35
+ sort(descriptors: SortDescriptor<T>[]): T[];
36
+ sort(data: T[], descriptors: SortDescriptor<T>[], inPlace?: boolean): T[];
37
+ private sortNumericFastPath;
38
+ private sortMultiField;
39
+ private sortTieGroups;
40
+ private materializeItemsFromIndexes;
41
+ private getCachedSortedItems;
42
+ private shouldMaintainIncrementally;
43
+ private hasDuplicateValuesForIndexes;
44
+ private compareIndexesByField;
45
+ private applyUpdatedItem;
46
+ private updateCachedIndexForUpdatedItem;
47
+ private updateCachedIndexForAddedItems;
48
+ private applyRemovedItem;
49
+ private applyRemovedItemsBatch;
50
+ private updateCachedIndexForRemovedItem;
51
+ private updateUniqueCachedIndexForRemovedItem;
52
+ private updateUniqueCachedIndexForRemovedItems;
53
+ private buildComparator;
54
+ }
55
+
56
+ export { CollectionItem, SortDescriptor, SortEngine };
57
+ export type { SortEngineOptions };
@@ -1,2 +1 @@
1
- import { SortEngine as e } from "./sorter.mjs";
2
- export { e as SortEngine };
1
+ import{c as e,i as t,l as s,r as n,s as i,u as a}from"../chunks/constants-DK9S0Db0.mjs";var r=class e extends Error{constructor(e){super(e),this.name="SortEngineError"}static missingDatasetForSort(){return new e("SortEngine: no dataset in memory.")}};function d(e,t){for(let s=0;s<t;s++){const t=e[s];if(t!==t>>>0)return!1}return!0}function o(e,t,s){const n=new Uint32Array(s),i=new Uint32Array(65536);for(let r=0;r<s;r++)i[65535&t[e[r]]]++;let a=0;for(let r=0;r<65536;r++){const e=i[r];i[r]=a,a+=e}for(let r=0;r<s;r++)n[i[65535&t[e[r]]]++]=e[r];i.fill(0);for(let r=0;r<s;r++)i[t[n[r]]>>>16&65535]++;a=0;for(let r=0;r<65536;r++){const e=i[r];i[r]=a,a+=e}for(let r=0;r<s;r++)e[i[t[n[r]]>>>16&65535]++]=n[r]}var l=()=>({indexedFields:/* @__PURE__ */new Set,cache:/* @__PURE__ */new Map}),h=class{constructor(e={}){if(this.state=e.state??new a(e.data??[]),this.namespace=this.state.createNamespace("sort"),this.state.subscribe(e=>this.handleStateMutation(e)),e.fields?.length){for(const t of e.fields)this.indexedFields.add(t);this.dataset.length>0&&this.rebuildConfiguredIndexes()}}get dataset(){return this.state.getOriginData()}get runtime(){return this.state.getOrCreateScopedValue(this.namespace,"runtime",l)}get cache(){return this.runtime.cache}get indexedFields(){return this.runtime.indexedFields}shouldDeferMutationCacheUpdates(){return!0===this.state.getScopedValue(t,n)}invalidateCachedIndexes(){for(const e of this.indexedFields)this.cache.delete(e)}rebuildConfiguredIndexes(){this.cache.clear();for(const e of this.indexedFields)this.buildIndexForDataset(e)}buildIndexForDataset(e){this.dataset.length&&this.buildIndexFromData(this.dataset,e)}buildIndexFromData(e,t){const s=e.length,n=new Uint32Array(s);for(let r=0;r<s;r++)n[r]=r;let i=0;for(;i<s&&null==e[i][t];)i++;if(i<s&&"number"==typeof e[i][t]){const i=new Float64Array(s);for(let n=0;n<s;n++)i[n]=e[n][t];d(i,s)?o(n,i,s):n.sort((e,t)=>i[e]-i[t])}else{const i=new Array(s);for(let n=0;n<s;n++)i[n]=e[n][t];n.sort((e,t)=>{const s=i[e],n=i[t];return s<n?-1:s>n?1:0})}const a=new Uint32Array(s);for(let r=0;r<s;r++)a[n[r]]=r;this.cache.set(t,{indexes:n,reverseIndex:a,ascItems:null,descItems:null,hasDuplicateValues:this.hasDuplicateValuesForIndexes(e,n,t),version:this.state.getMutationVersion()})}clearIndexes(){return this.cache.clear(),this}clearData(){return this.state.clearData(),this}data(e){return this.state.data(e),this}add(e){return this.state.add(e),this}delete(t,n){const a=s(n);if(0===a.length)return this;const r=e(this.dataset,t,a);if(r.length>0)throw new Error(i("SortEngine",t,r));return 1===a.length?(this.state.removeByFieldValue(t,a[0]),this):(this.state.removeByFieldValues(t,a),this)}update(e){return this.state.update(e),this}applyAddedItems(e,t){if(0===t)return this;if(this.shouldDeferMutationCacheUpdates())return this.invalidateCachedIndexes(),this;for(const s of this.indexedFields){const n=this.cache.get(s);n&&(this.shouldMaintainIncrementally(n)?this.updateCachedIndexForAddedItems(s,e,t):this.cache.delete(s))}return this}getOriginData(){return this.state.getOriginData()}handleStateMutation(e){switch(e.type){case"add":return void this.applyAddedItems(e.startIndex,e.items.length);case"update":return void this.applyUpdatedItem(e.index,e.previousItem,e.nextItem);case"data":return void this.rebuildConfiguredIndexes();case"clearData":return void this.cache.clear();case"remove":return void this.applyRemovedItem(e.removedIndex,e.movedFromIndex);case"removeMany":return void this.applyRemovedItemsBatch(e.entries)}}sort(e,t,s=!1){const n=void 0===t;let i,a;if(n){if(!this.dataset.length)throw r.missingDatasetForSort();i=this.dataset,a=e}else i=e,a=t;if(0===a.length||0===i.length)return i;if(1===a.length){const{field:e,direction:t}=a[0];if(n&&this.indexedFields.has(e)){let s=this.cache.get(e);const n=this.state.getMutationVersion();return s&&s.version===n||(this.buildIndexForDataset(e),s=this.cache.get(e)),this.getCachedSortedItems(s,t)}return this.sortNumericFastPath(i,e,t,s)}return this.sortMultiField(i,a,s,n)}sortNumericFastPath(e,t,s,n){if(0===e.length||"number"!=typeof e[0][t]){const i=n?e:e.slice();return i.sort((e,n)=>{const i=e[t],a=n[t],r=i<a?-1:i>a?1:0;return"asc"===s?r:-r}),i}const i=e.length,a=new Float64Array(i);for(let d=0;d<i;d++)a[d]=e[d][t];const r=new Uint32Array(i);for(let d=0;d<i;d++)r[d]=d;return d(a,i)?o(r,a,i):r.sort((e,t)=>a[e]-a[t]),this.materializeItemsFromIndexes(e,r,s)}sortMultiField(e,t,s,n){const[i,...a]=t;if(n&&this.indexedFields.has(i.field)){let e=this.cache.get(i.field);const t=this.state.getMutationVersion();e&&e.version===t||(this.buildIndexForDataset(i.field),e=this.cache.get(i.field));const s=e.hasDuplicateValues?this.getCachedSortedItems(e,i.direction).slice():this.getCachedSortedItems(e,i.direction);return e.hasDuplicateValues?this.sortTieGroups(s,i.field,a):s}const r=s?e:e.slice(),d=this.buildComparator(t);return r.sort(d),r}sortTieGroups(e,t,s){if(0===s.length)return e;const n=this.buildComparator(s),i=e.length;let a=0;for(;a<i;){let s=a+1;const r=e[a][t];for(;s<i&&e[s][t]===r;)s++;if(s-a>1){const t=e.slice(a,s);t.sort(n);for(let n=a;n<s;n++)e[n]=t[n-a]}a=s}return e}materializeItemsFromIndexes(e,t,s){const n=t.length,i=new Array(n);if("asc"===s){for(let s=0;s<n;s++)i[s]=e[t[s]];return i}for(let a=0;a<n;a++)i[a]=e[t[n-1-a]];return i}getCachedSortedItems(e,t){return"asc"===t?(null===e.ascItems&&(e.ascItems=this.materializeItemsFromIndexes(this.dataset,e.indexes,"asc")),e.ascItems):(null!==e.descItems||(e.descItems=this.getCachedSortedItems(e,"asc").slice().reverse()),e.descItems)}shouldMaintainIncrementally(e){return null!==e.ascItems||null!==e.descItems}hasDuplicateValuesForIndexes(e,t,s){for(let n=1;n<t.length;n++)if(e[t[n-1]][s]===e[t[n]][s])return!0;return!1}compareIndexesByField(e,t,s){const n=this.dataset[t][e],i=this.dataset[s][e];if("number"==typeof n&&"number"==typeof i){const e=n-i;if(0!==e)return e}else{if(n<i)return-1;if(n>i)return 1}return t-s}applyUpdatedItem(e,t,s){if(this.shouldDeferMutationCacheUpdates())this.invalidateCachedIndexes();else for(const n of this.indexedFields){if(t[n]===s[n])continue;const i=this.cache.get(n);i&&(this.shouldMaintainIncrementally(i)?this.updateCachedIndexForUpdatedItem(n,e):this.cache.delete(n))}}updateCachedIndexForUpdatedItem(e,t){const s=this.cache.get(e);if(!s)return;const{indexes:n,reverseIndex:i}=s,a=n.length,r=i[t];if(r>=a||n[r]!==t)return void this.cache.delete(e);n.copyWithin(r,r+1);const d=a-1;let o=0,l=d;for(;o<l;){const s=o+l>>1;this.compareIndexesByField(e,n[s],t)<=0?o=s+1:l=s}const h=o;n.copyWithin(h+1,h,d),n[h]=t,null!==s.ascItems&&(s.ascItems.copyWithin(r,r+1),s.ascItems.copyWithin(h+1,h,d),s.ascItems[h]=this.dataset[t]);const c=Math.min(r,h),u=Math.max(r,h);for(let m=c;m<=u;m++)i[n[m]]=m;if(s.descItems=null,!s.hasDuplicateValues){const i=h>0?n[h-1]:-1,r=h+1<a?n[h+1]:-1;s.hasDuplicateValues=-1!==i&&this.dataset[i][e]===this.dataset[t][e]||-1!==r&&this.dataset[r][e]===this.dataset[t][e]}s.version=this.state.getMutationVersion()}updateCachedIndexForAddedItems(e,t,s){const n=this.cache.get(e);if(!n)return;const i=new Array(s);for(let u=0;u<s;u++)i[u]=t+u;i.sort((t,s)=>this.compareIndexesByField(e,t,s));const a=new Uint32Array(n.indexes.length+s);let r=-1,d=n.hasDuplicateValues,o=0,l=0,h=0;for(;o<n.indexes.length&&l<i.length;){const t=this.compareIndexesByField(e,n.indexes[o],i[l])<=0?n.indexes[o++]:i[l++];a[h]=t,d||-1===r||this.dataset[r][e]!==this.dataset[t][e]||(d=!0),r=t,h+=1}for(;o<n.indexes.length;){const t=n.indexes[o++];a[h]=t,d||-1===r||this.dataset[r][e]!==this.dataset[t][e]||(d=!0),r=t,h+=1}for(;l<i.length;){const t=i[l++];a[h]=t,d||-1===r||this.dataset[r][e]!==this.dataset[t][e]||(d=!0),r=t,h+=1}const c=new Uint32Array(a.length);for(let u=0;u<a.length;u++)c[a[u]]=u;n.indexes=a,n.reverseIndex=c,n.ascItems=n.ascItems?this.materializeItemsFromIndexes(this.dataset,a,"asc"):null,n.descItems=null,n.hasDuplicateValues=d,n.version=this.state.getMutationVersion()}applyRemovedItem(e,t){if(this.shouldDeferMutationCacheUpdates())this.invalidateCachedIndexes();else for(const s of this.indexedFields){const n=this.cache.get(s);n&&(this.shouldMaintainIncrementally(n)?this.updateCachedIndexForRemovedItem(s,e,t):this.cache.delete(s))}}applyRemovedItemsBatch(e){if(this.shouldDeferMutationCacheUpdates())this.invalidateCachedIndexes();else for(const t of this.indexedFields){const s=this.cache.get(t);s&&(this.shouldMaintainIncrementally(s)?s.hasDuplicateValues?this.cache.delete(t):(this.updateUniqueCachedIndexForRemovedItems(s,e),s.version=this.state.getMutationVersion()):this.cache.delete(t))}}updateCachedIndexForRemovedItem(e,t,s){const n=this.cache.get(e);if(!n)return;if(!n.hasDuplicateValues)return this.updateUniqueCachedIndexForRemovedItem(n,t,s),void(n.version=this.state.getMutationVersion());const i=[];for(let d=0;d<n.indexes.length;d++){const e=n.indexes[d];e!==t&&e!==s&&i.push(e)}if(null!==s&&s!==t){let s=0,n=i.length;for(;s<n;){const a=s+n>>1;this.compareIndexesByField(e,i[a],t)<=0?s=a+1:n=a}i.splice(s,0,t)}const a=Uint32Array.from(i),r=new Uint32Array(this.dataset.length);for(let d=0;d<a.length;d++)r[a[d]]=d;n.indexes=a,n.reverseIndex=r,n.ascItems=n.ascItems?this.materializeItemsFromIndexes(this.dataset,a,"asc"):null,n.descItems=null,n.hasDuplicateValues=!!n.hasDuplicateValues&&this.hasDuplicateValuesForIndexes(this.dataset,a,e),n.version=this.state.getMutationVersion()}updateUniqueCachedIndexForRemovedItem(e,t,s){const n=e.indexes.length-1,i=new Uint32Array(n),a=new Uint32Array(this.dataset.length),r=null!==e.ascItems?new Array(n):null;let d=0;for(let o=0;o<e.indexes.length;o++){const n=e.indexes[o];if(n===t)continue;const l=null!==s&&n===s?t:n;i[d]=l,a[l]=d,null!==r&&(r[d]=this.dataset[l]),d+=1}e.indexes=i,e.reverseIndex=a,e.ascItems=r,e.descItems=null}updateUniqueCachedIndexForRemovedItems(e,t){const s=e.indexes.length,n=new Uint32Array(s),i=new Int32Array(s);for(let h=0;h<s;h++)n[h]=h,i[h]=-1;let a=s;for(let h=0;h<t.length;h++){const e=t[h];null!==e.movedFromIndex&&(n[e.removedIndex]=n[e.movedFromIndex]),a-=1}const r=new Uint32Array(a),d=new Uint32Array(a),o=null!==e.ascItems?new Array(a):null;for(let h=0;h<a;h++)i[n[h]]=h;let l=0;for(let h=0;h<e.indexes.length;h++){const t=i[e.indexes[h]];-1!==t&&(r[l]=t,d[t]=l,null!==o&&(o[l]=this.dataset[t]),l+=1)}e.indexes=r,e.reverseIndex=d,e.ascItems=o,e.descItems=null}buildComparator(e){const t=e.map(({field:e})=>e),s=e.map(({direction:e})=>"asc"===e?1:-1),n=t.length;return(e,i)=>{for(let a=0;a<n;a++){const n=t[a],r=e[n],d=i[n];if(r<d)return-s[a];if(r>d)return s[a]}return 0}}};export{h as SortEngine};
@@ -0,0 +1,74 @@
1
+ type CollectionItem = Record<string, any>;
2
+ type IndexableKey<T> = {
3
+ [K in keyof T]: T[K] extends string | number ? K : never;
4
+ }[keyof T];
5
+ interface UpdateDescriptor<T extends CollectionItem> {
6
+ field: IndexableKey<T> & string;
7
+ data: T;
8
+ }
9
+ interface FilterCriterion<T extends CollectionItem> {
10
+ field: (keyof T & string) | (string & {});
11
+ values?: any[];
12
+ exclude?: any[];
13
+ }
14
+ type SortDirection = "asc" | "desc";
15
+ interface SortDescriptor<T extends CollectionItem> {
16
+ field: keyof T & string;
17
+ direction: SortDirection;
18
+ }
19
+ type StateListener<T extends CollectionItem> = (mutation: StateMutation<T>) => void;
20
+ interface StateRegistryFactory<TValue> {
21
+ (): TValue;
22
+ }
23
+ interface StateOptions {
24
+ filterByPreviousResult?: boolean;
25
+ }
26
+ interface StatePreviousResult<T extends CollectionItem> {
27
+ result: T[];
28
+ sourceData: T[];
29
+ version: number;
30
+ }
31
+ type StateAddMutation<T extends CollectionItem> = {
32
+ type: "add";
33
+ items: T[];
34
+ startIndex: number;
35
+ };
36
+ type StateUpdateMutation<T extends CollectionItem> = {
37
+ type: "update";
38
+ field: IndexableKey<T> & string;
39
+ index: number;
40
+ previousItem: T;
41
+ nextItem: T;
42
+ };
43
+ type StateDataMutation<T extends CollectionItem> = {
44
+ type: "data";
45
+ data: T[];
46
+ };
47
+ type StateClearMutation<T extends CollectionItem> = {
48
+ type: "clearData";
49
+ data: T[];
50
+ };
51
+ type StateRemoveMutation<T extends CollectionItem> = {
52
+ type: "remove";
53
+ field: IndexableKey<T> & string;
54
+ value: T[IndexableKey<T> & string];
55
+ removedItem: T;
56
+ removedIndex: number;
57
+ movedItem: T | null;
58
+ movedFromIndex: number | null;
59
+ };
60
+ type StateRemoveManyEntry<T extends CollectionItem> = {
61
+ value: T[IndexableKey<T> & string];
62
+ removedItem: T;
63
+ removedIndex: number;
64
+ movedItem: T | null;
65
+ movedFromIndex: number | null;
66
+ };
67
+ type StateRemoveManyMutation<T extends CollectionItem> = {
68
+ type: "removeMany";
69
+ field: IndexableKey<T> & string;
70
+ entries: StateRemoveManyEntry<T>[];
71
+ };
72
+ type StateMutation<T extends CollectionItem> = StateAddMutation<T> | StateUpdateMutation<T> | StateDataMutation<T> | StateClearMutation<T> | StateRemoveMutation<T> | StateRemoveManyMutation<T>;
73
+
74
+ export type { CollectionItem as C, FilterCriterion as F, IndexableKey as I, StateOptions as S, UpdateDescriptor as U, StateListener as a, StatePreviousResult as b, StateRegistryFactory as c, SortDescriptor as d, SortDirection as e };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devisfuture/mega-collection",
3
- "version": "2.4.7",
3
+ "version": "2.5.0",
4
4
  "description": "High-performance search, filter & sort engine for 100K+ item collections in JavaScript/TypeScript",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "sideEffects": false,
35
35
  "scripts": {
36
- "build:types": "tsc --emitDeclarationOnly",
36
+ "build:types": "rollup -c rollup.types.config.mjs",
37
37
  "build": "vite build && npm run build:types",
38
38
  "build:watch": "vite build --watch",
39
39
  "dev": "vite build --watch",
@@ -41,6 +41,7 @@
41
41
  "test:watch": "vitest",
42
42
  "sort-bench": "npx tsx ./benchmarks/sorter.bench.ts",
43
43
  "filter-bench": "npx tsx ./benchmarks/filter.bench.ts",
44
+ "filter-remove-bench": "npx tsx ./benchmarks/filter-remove.bench.ts",
44
45
  "search-bench": "npx tsx ./benchmarks/search.bench.ts",
45
46
  "controls-bench": "npx tsx ./benchmarks/controls.bench.ts",
46
47
  "test:coverage": "vitest run --coverage",
@@ -84,6 +85,9 @@
84
85
  "devDependencies": {
85
86
  "@types/node": "^25.5.0",
86
87
  "@vitest/coverage-v8": "^4.1.0",
88
+ "rollup": "^4.52.3",
89
+ "rollup-plugin-dts": "^6.2.3",
90
+ "terser": "^5.46.1",
87
91
  "typescript": "^5.3.0",
88
92
  "vite": "^8.0.0",
89
93
  "vitest": "^4.1.0"