@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
package/dist/State.mjs DELETED
@@ -1,183 +0,0 @@
1
- //#region src/State.ts
2
- var e = class {
3
- constructor(e = [], t = {}) {
4
- this.itemIndexLookup = /* @__PURE__ */ new WeakMap(), this.mutationVersion = 0, this.namespaceSequence = 0, this.previousResultState = null, this.indexMaps = /* @__PURE__ */ new Map(), this.scopedRegistry = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.originData = e, this.filterByPreviousResult = t.filterByPreviousResult ?? !1, this.rebuildItemIndexLookup();
5
- }
6
- subscribe(e) {
7
- return this.listeners.add(e), () => {
8
- this.listeners.delete(e);
9
- };
10
- }
11
- getOriginData() {
12
- return this.originData;
13
- }
14
- getItemIndex(e) {
15
- return this.itemIndexLookup.get(e);
16
- }
17
- getMutationVersion() {
18
- return this.mutationVersion;
19
- }
20
- isFilterByPreviousResultEnabled() {
21
- return this.filterByPreviousResult;
22
- }
23
- setFilterByPreviousResult(e) {
24
- this.filterByPreviousResult = e, e || this.clearPreviousResult();
25
- }
26
- getPreviousResult() {
27
- return this.getPreviousResultState()?.result ?? null;
28
- }
29
- getPreviousResultState() {
30
- return this.previousResultState === null || this.previousResultState.version !== this.mutationVersion ? null : this.previousResultState;
31
- }
32
- setPreviousResult(e, t) {
33
- this.previousResultState = {
34
- result: e,
35
- sourceData: t,
36
- version: this.mutationVersion
37
- };
38
- }
39
- clearPreviousResult() {
40
- this.previousResultState = null;
41
- }
42
- createNamespace(e = "scope") {
43
- return this.namespaceSequence += 1, `${e}:${this.namespaceSequence}`;
44
- }
45
- getScopedValue(e, t) {
46
- return this.scopedRegistry.get(e)?.get(t);
47
- }
48
- getOrCreateScopedValue(e, t, n) {
49
- let r = this.getScopedValue(e, t);
50
- if (r !== void 0) return r;
51
- let i = this.getOrCreateScope(e), a = n();
52
- return i.set(t, a), a;
53
- }
54
- setScopedValue(e, t, n) {
55
- return this.getOrCreateScope(e).set(t, n), n;
56
- }
57
- deleteScopedValue(e, t) {
58
- let n = this.scopedRegistry.get(e);
59
- n && (n.delete(t), n.size === 0 && this.scopedRegistry.delete(e));
60
- }
61
- clearScope(e) {
62
- this.scopedRegistry.delete(e);
63
- }
64
- data(e) {
65
- this.originData = e, this.bumpMutationVersion(), this.rebuildItemIndexLookup();
66
- for (let e of this.indexMaps.keys()) this.rebuildIndexMap(e);
67
- this.emit({
68
- type: "data",
69
- data: e
70
- });
71
- }
72
- add(e) {
73
- if (e.length === 0) return;
74
- let t = this.originData.length;
75
- for (let n = 0; n < e.length; n++) this.originData.push(e[n]), this.itemIndexLookup.set(e[n], t + n);
76
- this.bumpMutationVersion();
77
- for (let [n, r] of this.indexMaps) for (let i = 0; i < e.length; i++) r.set(e[i][n], t + i);
78
- this.emit({
79
- type: "add",
80
- items: e,
81
- startIndex: t
82
- });
83
- }
84
- update(e) {
85
- let { field: t, data: n } = e, r = n[t];
86
- if (r == null) return;
87
- let i = this.getOrCreateIndexMap(t).get(r);
88
- if (i === void 0) return;
89
- let a = this.originData[i];
90
- this.originData[i] = n, this.itemIndexLookup.delete(a), this.itemIndexLookup.set(n, i), this.bumpMutationVersion();
91
- for (let [e, t] of this.indexMaps) {
92
- let r = a[e], o = n[e];
93
- r !== o && (t.get(r) === i && t.delete(r), t.set(o, i));
94
- }
95
- this.emit({
96
- type: "update",
97
- field: t,
98
- index: i,
99
- previousItem: a,
100
- nextItem: n
101
- });
102
- }
103
- clearData() {
104
- let e = [];
105
- this.originData = e, this.itemIndexLookup = /* @__PURE__ */ new WeakMap(), this.bumpMutationVersion();
106
- for (let e of this.indexMaps.values()) e.clear();
107
- this.emit({
108
- type: "clearData",
109
- data: e
110
- });
111
- }
112
- removeByFieldValue(e, t) {
113
- let n = this.getOrCreateIndexMap(e).get(t);
114
- if (n === void 0) return;
115
- let r = this.originData.length - 1, i = this.originData[n], a = n === r ? null : this.originData[r];
116
- n !== r && a && (this.originData[n] = a, this.itemIndexLookup.set(a, n)), this.originData.pop(), this.itemIndexLookup.delete(i), this.bumpMutationVersion();
117
- for (let [e, t] of this.indexMaps) {
118
- let r = i[e];
119
- t.get(r) === n && t.delete(r), a && t.set(a[e], n);
120
- }
121
- this.emit({
122
- type: "remove",
123
- field: e,
124
- value: t,
125
- removedItem: i,
126
- removedIndex: n,
127
- movedItem: a,
128
- movedFromIndex: a ? r : null
129
- });
130
- }
131
- removeByFieldValues(e, t) {
132
- if (t.length === 0) return;
133
- let n = this.getOrCreateIndexMap(e), r = [];
134
- for (let e = 0; e < t.length; e++) {
135
- let i = t[e], a = n.get(i);
136
- if (a === void 0) continue;
137
- let o = this.originData.length - 1, s = this.originData[a], c = a === o ? null : this.originData[o];
138
- a !== o && c && (this.originData[a] = c, this.itemIndexLookup.set(c, a)), this.originData.pop(), this.itemIndexLookup.delete(s);
139
- for (let [e, t] of this.indexMaps) {
140
- let n = s[e];
141
- t.get(n) === a && t.delete(n), c && t.set(c[e], a);
142
- }
143
- r.push({
144
- value: i,
145
- removedItem: s,
146
- removedIndex: a,
147
- movedItem: c,
148
- movedFromIndex: c ? o : null
149
- });
150
- }
151
- r.length !== 0 && (this.bumpMutationVersion(), this.emit({
152
- type: "removeMany",
153
- field: e,
154
- entries: r
155
- }));
156
- }
157
- emit(e) {
158
- for (let t of this.listeners) t(e);
159
- }
160
- getOrCreateScope(e) {
161
- let t = this.scopedRegistry.get(e);
162
- if (t) return t;
163
- let n = /* @__PURE__ */ new Map();
164
- return this.scopedRegistry.set(e, n), n;
165
- }
166
- bumpMutationVersion() {
167
- this.mutationVersion += 1, this.clearPreviousResult();
168
- }
169
- getOrCreateIndexMap(e) {
170
- return this.indexMaps.get(e) || this.rebuildIndexMap(e);
171
- }
172
- rebuildIndexMap(e) {
173
- let t = /* @__PURE__ */ new Map();
174
- for (let n = 0; n < this.originData.length; n++) t.set(this.originData[n][e], n);
175
- return this.indexMaps.set(e, t), t;
176
- }
177
- rebuildItemIndexLookup() {
178
- this.itemIndexLookup = /* @__PURE__ */ new WeakMap();
179
- for (let e = 0; e < this.originData.length; e++) this.itemIndexLookup.set(this.originData[e], e);
180
- }
181
- };
182
- //#endregion
183
- export { e as State };
@@ -1,5 +0,0 @@
1
- export declare const MERGE_SHARED_SCOPE = "__merge__";
2
- export declare const DEFER_FILTER_MUTATION_INDEX_UPDATES_KEY = "deferFilterMutationIndexUpdates";
3
- export declare const DEFER_SEARCH_MUTATION_INDEX_UPDATES_KEY = "deferSearchMutationIndexUpdates";
4
- export declare const DEFER_SORT_MUTATION_CACHE_UPDATES_KEY = "deferSortMutationCacheUpdates";
5
- //# sourceMappingURL=constants.d.ts.map
@@ -1,4 +0,0 @@
1
- //#region src/constants.ts
2
- var e = "__merge__", t = "deferFilterMutationIndexUpdates", n = "deferSearchMutationIndexUpdates", r = "deferSortMutationCacheUpdates";
3
- //#endregion
4
- export { t as DEFER_FILTER_MUTATION_INDEX_UPDATES_KEY, n as DEFER_SEARCH_MUTATION_INDEX_UPDATES_KEY, r as DEFER_SORT_MUTATION_CACHE_UPDATES_KEY, e as MERGE_SHARED_SCOPE };
@@ -1,9 +0,0 @@
1
- import type { CollectionItem } from "../types";
2
- import type { FilterEngineChain, FilterEngineChainCallbacks } from "./types";
3
- export type { FilterEngineChain } from "./types";
4
- export declare class FilterEngineChainBuilder<T extends CollectionItem> {
5
- private readonly callbacks;
6
- constructor(callbacks: FilterEngineChainCallbacks<T>);
7
- create(result: T[]): T[] & FilterEngineChain<T>;
8
- }
9
- //# sourceMappingURL=chain.d.ts.map
@@ -1,22 +0,0 @@
1
- import { createChainMethodDescriptor as e } from "../internal.mjs";
2
- //#region src/filter/chain.ts
3
- var t = class {
4
- constructor(e) {
5
- this.callbacks = e;
6
- }
7
- create(t) {
8
- let n = t;
9
- return Object.defineProperties(n, {
10
- filter: e((e, n) => n === void 0 ? this.callbacks.filter(t, e) : this.callbacks.filter(e, n)),
11
- add: e((e) => this.callbacks.add(e)),
12
- update: e((e) => this.callbacks.update(e)),
13
- clearIndexes: e(() => this.callbacks.clearIndexes()),
14
- data: e((e) => this.callbacks.data(e)),
15
- getOriginData: e(() => this.callbacks.getOriginData()),
16
- clearData: e(() => this.callbacks.clearData()),
17
- resetFilterState: e(() => this.callbacks.resetFilterState())
18
- }), n;
19
- }
20
- };
21
- //#endregion
22
- export { t as FilterEngineChainBuilder };
@@ -1,2 +0,0 @@
1
- export { DEFER_FILTER_MUTATION_INDEX_UPDATES_KEY } from "../constants";
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1,6 +0,0 @@
1
- import type { CollectionItem, FilterCriterion } from "../types";
2
- import type { ResolvedFilterCriterion } from "./types";
3
- export declare function resolveCriteria<T extends CollectionItem>(criteria: FilterCriterion<T>[]): ResolvedFilterCriterion<T>[];
4
- export declare function matchesCriterionValue<T extends CollectionItem>(criterion: ResolvedFilterCriterion<T>, value: any): boolean;
5
- export declare function isCriterionUnsatisfiable<T extends CollectionItem>(criterion: ResolvedFilterCriterion<T>): boolean;
6
- //# sourceMappingURL=criterion.d.ts.map
@@ -1,64 +0,0 @@
1
- //#region src/filter/criterion.ts
2
- function e(e) {
3
- let t = /* @__PURE__ */ new Map();
4
- for (let n = 0; n < e.length; n++) {
5
- let a = e[n], o = Array.isArray(a.values), s = r(a.exclude), c = s !== null, l = o ? i(a.values, s) : null;
6
- if (!o && !c) continue;
7
- let u = a.field, d = t.get(u);
8
- if (!d) {
9
- t.set(u, {
10
- field: a.field,
11
- values: [],
12
- exclude: [],
13
- hasValues: o,
14
- hasExclude: c,
15
- includedValues: l ? new Set(l) : null,
16
- excludedValues: s ? new Set(s) : null,
17
- cacheKeySegment: ""
18
- });
19
- continue;
20
- }
21
- if (o) if (!d.hasValues) d.hasValues = !0, d.includedValues = new Set(l);
22
- else for (let e of d.includedValues) l.has(e) || d.includedValues.delete(e);
23
- if (c) if (!d.hasExclude) d.hasExclude = !0, d.excludedValues = new Set(s);
24
- else for (let e of s) d.excludedValues.add(e);
25
- }
26
- let n = [...t.values()].sort((e, t) => e.field.localeCompare(t.field));
27
- for (let e = 0; e < n.length; e++) a(n[e]);
28
- return n;
29
- }
30
- function t(e, t) {
31
- return !(e.hasValues && !e.includedValues.has(t) || e.hasExclude && e.excludedValues.has(t));
32
- }
33
- function n(e) {
34
- return e.hasValues && e.values.length === 0;
35
- }
36
- function r(e) {
37
- return !Array.isArray(e) || e.length === 0 ? null : new Set(e);
38
- }
39
- function i(e, t) {
40
- let n = /* @__PURE__ */ new Set();
41
- for (let r = 0; r < e.length; r++) {
42
- let i = e[r];
43
- t?.has(i) || n.add(i);
44
- }
45
- return n;
46
- }
47
- function a(e) {
48
- if (e.hasValues && e.hasExclude) for (let t of e.excludedValues) e.includedValues.delete(t);
49
- e.values = e.includedValues ? [...e.includedValues] : [], e.exclude = e.excludedValues ? [...e.excludedValues] : [], e.cacheKeySegment = o(e);
50
- }
51
- function o(e) {
52
- let t = e.field;
53
- return t += `|hv:${e.hasValues ? "1" : "0"}|v:`, e.hasValues && (t += s(e.values)), t += `|hx:${e.hasExclude ? "1" : "0"}|x:`, e.hasExclude && (t += s(e.exclude)), t;
54
- }
55
- function s(e) {
56
- return e.length === 0 ? "" : e.map((e) => c(e)).sort().join(",");
57
- }
58
- function c(e) {
59
- if (e === null) return "null:null";
60
- let t = typeof e;
61
- return t === "object" ? `object:${JSON.stringify(e)}` : `${t}:${String(e)}`;
62
- }
63
- //#endregion
64
- export { n as isCriterionUnsatisfiable, t as matchesCriterionValue, e as resolveCriteria };
@@ -1,7 +0,0 @@
1
- export declare class FilterEngineError extends Error {
2
- constructor(message: string);
3
- static missingDatasetForBuildIndex(): FilterEngineError;
4
- static missingDatasetForFilter(): FilterEngineError;
5
- static duplicateMutableExcludeField(field: string): FilterEngineError;
6
- }
7
- //# sourceMappingURL=errors.d.ts.map
@@ -1,17 +0,0 @@
1
- //#region src/filter/errors.ts
2
- var e = class e extends Error {
3
- constructor(e) {
4
- super(e), this.name = "FilterEngineError";
5
- }
6
- static missingDatasetForBuildIndex() {
7
- return new e("FilterEngine: no dataset in memory. Call data() or add() before buildIndex().");
8
- }
9
- static missingDatasetForFilter() {
10
- return new e("FilterEngine: no dataset in memory. Call data() or add() before filter().");
11
- }
12
- static duplicateMutableExcludeField(t) {
13
- return new e(`FilterEngine: cannot use mutable exclude on field \`${t}\` because it contains duplicate values.`);
14
- }
15
- };
16
- //#endregion
17
- export { e as FilterEngineError };
@@ -1,89 +0,0 @@
1
- /**
2
- * FilterEngine class for filtering collections by multiple criteria,
3
- * supporting indexed lookups and linear scans for large datasets.
4
- */
5
- import { State } from "../State";
6
- import { CollectionItem, FilterCriterion, type UpdateDescriptor } from "../types";
7
- import { FilterEngineChain } from "./chain";
8
- import type { FilterEngineOptions } from "./types";
9
- export declare class FilterEngine<T extends CollectionItem> {
10
- private readonly indexer;
11
- private readonly filterByPreviousResult;
12
- private readonly mutableExcludeField;
13
- private readonly state;
14
- private readonly namespace;
15
- private readonly nestedCollection;
16
- private readonly chainBuilder;
17
- /**
18
- * Creates a new FilterEngine with optional data and fields to index.
19
- */
20
- constructor(options?: FilterEngineOptions<T> & {
21
- state?: State<T>;
22
- });
23
- private get dataset();
24
- private get runtime();
25
- private get mutableExcludeState();
26
- private get indexedFields();
27
- private get sequentialCache();
28
- private shouldDeferMutationIndexUpdates;
29
- private markDeferredMutationState;
30
- private ensureRuntimeReady;
31
- private rebuildConfiguredIndexes;
32
- /**
33
- * Builds an index for the given field.
34
- */
35
- private buildIndex;
36
- clearIndexes(): this;
37
- resetFilterState(): this;
38
- clearData(): this;
39
- data(data: T[]): this;
40
- add(items: T[]): this;
41
- update(descriptor: UpdateDescriptor<T>): this;
42
- private applyAddedItems;
43
- getOriginData(): T[];
44
- /**
45
- * Filters the data based on the given criteria.
46
- */
47
- filter(criteria: FilterCriterion<T>[]): T[] & FilterEngineChain<T>;
48
- filter(data: T[], criteria: FilterCriterion<T>[]): T[] & FilterEngineChain<T>;
49
- rawFilter(criteria: FilterCriterion<T>[]): T[];
50
- rawFilter(data: T[], criteria: FilterCriterion<T>[]): T[];
51
- private resolveWithSequentialCache;
52
- private withChain;
53
- private handleStateMutation;
54
- private rebuildMutableExcludeState;
55
- private updateMutableExcludeStateForAddedItems;
56
- private applyMutableExclude;
57
- private applyUpdatedItem;
58
- private applyRemovedItem;
59
- private applyRemovedItems;
60
- private updateMutableExcludeStateForUpdatedItem;
61
- private clearMutableExcludeState;
62
- private registerMutableExcludeValue;
63
- private unregisterMutableExcludeValue;
64
- /**
65
- * Filters data linearly without index.
66
- */
67
- private linearFilter;
68
- /**
69
- * Filters data using the index.
70
- */
71
- private filterViaIndex;
72
- /**
73
- * Estimates the size of the index for a criterion.
74
- */
75
- private estimateIndexSize;
76
- private applyIndexedExclusions;
77
- private createEmptyResult;
78
- private storePreviousResult;
79
- private createCriteriaCacheKey;
80
- private createSequentialCacheEntry;
81
- private createSequentialExecutionCriteria;
82
- private hasCriteriaBacktrack;
83
- private canApplySequentiallyToEmptyResult;
84
- private createCriteriaStateMap;
85
- private isCriterionBacktracked;
86
- private isSubset;
87
- private areSetsEqual;
88
- }
89
- //# sourceMappingURL=filter.d.ts.map