@devisfuture/mega-collection 2.4.4 → 2.4.5

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.
@@ -178,6 +178,6 @@ var e = class {
178
178
  this.itemIndexLookup = /* @__PURE__ */ new WeakMap();
179
179
  for (let e = 0; e < this.originData.length; e++) this.itemIndexLookup.set(this.originData[e], e);
180
180
  }
181
- }, t = "__merge__";
181
+ }, t = "__merge__", n = "deferFilterMutationIndexUpdates", r = "deferSearchMutationIndexUpdates", i = "deferSortMutationCacheUpdates";
182
182
  //#endregion
183
- export { e as n, t };
183
+ export { e as a, t as i, r as n, i as r, n as t };
@@ -1,72 +1,65 @@
1
- import { n as e, t } from "./chunk-BTXXf5A-.mjs";
1
+ import { a as e, i as t, n, r, t as i } from "./chunk-BJZg_1dI.mjs";
2
+ import { t as a } from "./chunk-C5Zpu_ol.mjs";
2
3
  //#region src/merge/chain.ts
3
- function n(e) {
4
- return {
5
- value: e,
6
- enumerable: !1,
7
- configurable: !0,
8
- writable: !0
9
- };
10
- }
11
- var r = class {
4
+ var o = class {
12
5
  constructor(e) {
13
6
  this.callbacks = e;
14
7
  }
15
8
  create(e) {
16
9
  let t = e;
17
10
  return Object.defineProperties(t, {
18
- search: n((e, t) => t === void 0 ? this.callbacks.search(e) : this.callbacks.search(e, t)),
19
- sort: n((t, n, r) => n === void 0 ? this.callbacks.sort(e, t, r) : this.callbacks.sort(t, n, r)),
20
- filter: n((t, n) => n === void 0 ? this.callbacks.filter(e, t) : this.callbacks.filter(t, n)),
21
- add: n((e) => this.callbacks.add(e)),
22
- update: n((e) => this.callbacks.update(e)),
23
- clearIndexes: n((t) => (this.callbacks.clearIndexes(t), this.create(e))),
24
- clearData: n((t) => (this.callbacks.clearData(t), this.create(e))),
25
- data: n((e) => this.callbacks.data(e)),
26
- getOriginData: n(() => this.callbacks.getOriginData())
11
+ search: a((e, t) => t === void 0 ? this.callbacks.search(e) : this.callbacks.search(e, t)),
12
+ sort: a((t, n, r) => n === void 0 ? this.callbacks.sort(e, t, r) : this.callbacks.sort(t, n, r)),
13
+ filter: a((t, n) => n === void 0 ? this.callbacks.filter(e, t) : this.callbacks.filter(t, n)),
14
+ add: a((e) => this.callbacks.add(e)),
15
+ update: a((e) => this.callbacks.update(e)),
16
+ clearIndexes: a((t) => (this.callbacks.clearIndexes(t), this.create(e))),
17
+ clearData: a((t) => (this.callbacks.clearData(t), this.create(e))),
18
+ data: a((e) => this.callbacks.data(e)),
19
+ getOriginData: a(() => this.callbacks.getOriginData())
27
20
  }), t;
28
21
  }
29
22
  };
30
23
  //#endregion
31
24
  //#region src/merge/module-adapters.ts
32
- function i(e) {
25
+ function s(e) {
33
26
  return typeof e == "object" && !!e;
34
27
  }
35
- function a(e, t) {
36
- return i(e) && typeof e[t] == "function";
28
+ function c(e, t) {
29
+ return s(e) && typeof e[t] == "function";
37
30
  }
38
- function o(e) {
39
- return a(e, "search") && a(e, "getOriginData");
31
+ function l(e) {
32
+ return c(e, "search") && c(e, "getOriginData");
40
33
  }
41
- function s(e) {
42
- return a(e, "sort") && a(e, "getOriginData");
34
+ function u(e) {
35
+ return c(e, "sort") && c(e, "getOriginData");
43
36
  }
44
- function c(e) {
45
- return a(e, "rawFilter") && a(e, "getOriginData");
37
+ function d(e) {
38
+ return c(e, "rawFilter") && c(e, "getOriginData");
46
39
  }
47
- var l = (e) => {
40
+ var f = (e) => {
48
41
  let { prototype: t } = e;
49
- return c(t) ? "filter" : s(t) ? "sort" : o(t) ? "search" : null;
50
- }, u = (e, t, n, r) => {
42
+ return d(t) ? "filter" : u(t) ? "sort" : l(t) ? "search" : null;
43
+ }, p = (e, t, n, r) => {
51
44
  let i = new e({
52
45
  data: t,
53
46
  state: n,
54
47
  ...r
55
48
  });
56
- return c(i) ? {
49
+ return d(i) ? {
57
50
  moduleName: "filter",
58
51
  executeFilter: (e, t) => t === void 0 ? i.rawFilter(e) : i.rawFilter(e, t),
59
52
  clearIndexes: () => i.clearIndexes()
60
- } : s(i) ? {
53
+ } : u(i) ? {
61
54
  moduleName: "sort",
62
55
  executeSort: (e, t, n) => t === void 0 ? i.sort(e) : i.sort(e, t, n),
63
56
  clearIndexes: () => i.clearIndexes()
64
- } : o(i) ? {
57
+ } : l(i) ? {
65
58
  moduleName: "search",
66
59
  executeSearch: (e, t) => t === void 0 ? i.search(e) : i.search(e, t),
67
60
  clearIndexes: () => i.clearIndexes()
68
61
  } : null;
69
- }, d = "deferSortMutationCacheUpdates", f = "deferSearchMutationIndexUpdates", p = "deferFilterMutationIndexUpdates", m = {
62
+ }, m = {
70
63
  search: "TextSearchEngine",
71
64
  sort: "SortEngine",
72
65
  filter: "FilterEngine"
@@ -85,18 +78,18 @@ var l = (e) => {
85
78
  return new e("MergeEngines: \"filter.filterByPreviousResult\" is not supported. Configure \"filterByPreviousResult\" on the MergeEngines root options.");
86
79
  }
87
80
  }, g = class {
88
- constructor(n) {
81
+ constructor(a) {
89
82
  this.previousSearchState = null, this.previousFilterState = null, this.previousSortState = null;
90
- let { imports: i, data: a, filterByPreviousResult: o = !1, ...s } = n;
91
- this.validateFilterByPreviousResultOptions(s.filter), this.state = new e(a, { filterByPreviousResult: o });
92
- let c = new Set(i), m = null, h = null, g = null;
93
- for (let e of c) {
94
- let t = l(e);
83
+ let { imports: s, data: c, filterByPreviousResult: l = !1, ...u } = a;
84
+ this.validateFilterByPreviousResultOptions(u.filter), this.state = new e(c, { filterByPreviousResult: l });
85
+ let d = new Set(s), m = null, h = null, g = null;
86
+ for (let e of d) {
87
+ let t = f(e);
95
88
  if (!t) continue;
96
- let n = this.getModuleInitOptions(t, e.name, s), r = u(e, a, this.state, n);
89
+ let n = this.getModuleInitOptions(t, e.name, u), r = p(e, c, this.state, n);
97
90
  r && (r.moduleName === "search" && !m && (m = r), r.moduleName === "sort" && !h && (h = r), r.moduleName === "filter" && !g && (g = r));
98
91
  }
99
- this.searchModule = m, this.sortModule = h, this.filterModule = g, this.sortModule && this.state.setScopedValue(t, d, !0), this.searchModule && this.state.setScopedValue(t, f, !0), this.filterModule && this.state.setScopedValue(t, p, !0), this.state.subscribe((e) => this.handleStateMutation(e)), this.chainBuilder = new r({
92
+ this.searchModule = m, this.sortModule = h, this.filterModule = g, this.sortModule && this.state.setScopedValue(t, r, !0), this.searchModule && this.state.setScopedValue(t, n, !0), this.filterModule && this.state.setScopedValue(t, i, !0), this.state.subscribe((e) => this.handleStateMutation(e)), this.chainBuilder = new o({
100
93
  search: (e, t) => t === void 0 ? this.search(e) : this.search(e, t),
101
94
  sort: (e, t, n) => this.sort(e, t, n),
102
95
  filter: (e, t) => this.filter(e, t),
@@ -113,14 +106,14 @@ var l = (e) => {
113
106
  }
114
107
  getModuleInitOptions(e, t, n) {
115
108
  let r = {};
116
- for (let a of [e, t]) {
117
- let e = n[a];
118
- i(e) && Object.assign(r, e);
109
+ for (let i of [e, t]) {
110
+ let e = n[i];
111
+ s(e) && Object.assign(r, e);
119
112
  }
120
113
  return r;
121
114
  }
122
115
  validateFilterByPreviousResultOptions(e) {
123
- if (i(e) && Object.prototype.hasOwnProperty.call(e, "filterByPreviousResult")) throw h.invalidFilterByPreviousResultOption();
116
+ if (s(e) && Object.prototype.hasOwnProperty.call(e, "filterByPreviousResult")) throw h.invalidFilterByPreviousResultOption();
124
117
  }
125
118
  isPreviousResultEnabled() {
126
119
  return this.state.isFilterByPreviousResultEnabled();
@@ -0,0 +1,18 @@
1
+ //#region src/internal.ts
2
+ function e(e) {
3
+ return {
4
+ value: e,
5
+ enumerable: !1,
6
+ configurable: !0,
7
+ writable: !0
8
+ };
9
+ }
10
+ function t(e) {
11
+ let t = e.indexOf(".");
12
+ return t === -1 ? null : {
13
+ collectionKey: e.substring(0, t),
14
+ nestedKey: e.substring(t + 1)
15
+ };
16
+ }
17
+ //#endregion
18
+ export { t as n, e as t };
@@ -1,6 +1,7 @@
1
- import { n as e, t } from "../chunk-BTXXf5A-.mjs";
1
+ import { a as e, i as t, t as n } from "../chunk-BJZg_1dI.mjs";
2
+ import { n as r, t as i } from "../chunk-C5Zpu_ol.mjs";
2
3
  //#region src/indexer.ts
3
- var n = class {
4
+ var a = class {
4
5
  constructor(e = {
5
6
  indexes: /* @__PURE__ */ new Map(),
6
7
  itemPositions: /* @__PURE__ */ new Map()
@@ -97,43 +98,7 @@ var n = class {
97
98
  let s = /* @__PURE__ */ new WeakMap();
98
99
  s.set(t, 0), i.set(n, s);
99
100
  }
100
- }, r = () => ({
101
- indexedFields: /* @__PURE__ */ new Set(),
102
- indexerStorage: {
103
- indexes: /* @__PURE__ */ new Map(),
104
- itemPositions: /* @__PURE__ */ new Map()
105
- },
106
- nestedStorage: {
107
- indexes: /* @__PURE__ */ new Map(),
108
- itemPositions: /* @__PURE__ */ new Map()
109
- },
110
- deferredMutationVersion: null,
111
- mutableExclude: {
112
- datasetPositions: /* @__PURE__ */ new Map(),
113
- valueCounts: /* @__PURE__ */ new Map(),
114
- duplicateValueCount: 0,
115
- hasDuplicateValues: !1
116
- },
117
- sequentialCache: {
118
- previousResult: null,
119
- previousCriteria: null,
120
- previousCriteriaKey: null,
121
- previousBaseData: null,
122
- previousResultsByCriteria: /* @__PURE__ */ new Map(),
123
- previousResultSet: null
124
- }
125
- });
126
- function i(e) {
127
- return {
128
- value: e,
129
- enumerable: !1,
130
- configurable: !0,
131
- writable: !0
132
- };
133
- }
134
- //#endregion
135
- //#region src/filter/chain.ts
136
- var a = class {
101
+ }, o = class {
137
102
  constructor(e) {
138
103
  this.callbacks = e;
139
104
  }
@@ -150,7 +115,7 @@ var a = class {
150
115
  resetFilterState: i(() => this.callbacks.resetFilterState())
151
116
  }), t;
152
117
  }
153
- }, o = class e extends Error {
118
+ }, s = class e extends Error {
154
119
  constructor(e) {
155
120
  super(e), this.name = "FilterEngineError";
156
121
  }
@@ -166,10 +131,10 @@ var a = class {
166
131
  };
167
132
  //#endregion
168
133
  //#region src/filter/criterion.ts
169
- function s(e) {
134
+ function c(e) {
170
135
  let t = /* @__PURE__ */ new Map();
171
136
  for (let n = 0; n < e.length; n++) {
172
- let r = e[n], i = Array.isArray(r.values), a = u(r.exclude), o = a !== null, s = i ? d(r.values, a) : null;
137
+ let r = e[n], i = Array.isArray(r.values), a = d(r.exclude), o = a !== null, s = i ? f(r.values, a) : null;
173
138
  if (!i && !o) continue;
174
139
  let c = r.field, l = t.get(c);
175
140
  if (!l) {
@@ -191,19 +156,19 @@ function s(e) {
191
156
  else for (let e of a) l.excludedValues.add(e);
192
157
  }
193
158
  let n = [...t.values()].sort((e, t) => e.field.localeCompare(t.field));
194
- for (let e = 0; e < n.length; e++) f(n[e]);
159
+ for (let e = 0; e < n.length; e++) p(n[e]);
195
160
  return n;
196
161
  }
197
- function c(e, t) {
162
+ function l(e, t) {
198
163
  return !(e.hasValues && !e.includedValues.has(t) || e.hasExclude && e.excludedValues.has(t));
199
164
  }
200
- function l(e) {
165
+ function u(e) {
201
166
  return e.hasValues && e.values.length === 0;
202
167
  }
203
- function u(e) {
168
+ function d(e) {
204
169
  return !Array.isArray(e) || e.length === 0 ? null : new Set(e);
205
170
  }
206
- function d(e, t) {
171
+ function f(e, t) {
207
172
  let n = /* @__PURE__ */ new Set();
208
173
  for (let r = 0; r < e.length; r++) {
209
174
  let i = e[r];
@@ -211,25 +176,25 @@ function d(e, t) {
211
176
  }
212
177
  return n;
213
178
  }
214
- function f(e) {
215
- if (e.hasValues && e.hasExclude) for (let t of e.excludedValues) e.includedValues.delete(t);
216
- e.values = e.includedValues ? [...e.includedValues] : [], e.exclude = e.excludedValues ? [...e.excludedValues] : [], e.cacheKeySegment = p(e);
217
- }
218
179
  function p(e) {
219
- let t = e.field;
220
- return t += `|hv:${e.hasValues ? "1" : "0"}|v:`, e.hasValues && (t += m(e.values)), t += `|hx:${e.hasExclude ? "1" : "0"}|x:`, e.hasExclude && (t += m(e.exclude)), t;
180
+ if (e.hasValues && e.hasExclude) for (let t of e.excludedValues) e.includedValues.delete(t);
181
+ e.values = e.includedValues ? [...e.includedValues] : [], e.exclude = e.excludedValues ? [...e.excludedValues] : [], e.cacheKeySegment = m(e);
221
182
  }
222
183
  function m(e) {
223
- return e.length === 0 ? "" : e.map((e) => h(e)).sort().join(",");
184
+ let t = e.field;
185
+ return t += `|hv:${e.hasValues ? "1" : "0"}|v:`, e.hasValues && (t += h(e.values)), t += `|hx:${e.hasExclude ? "1" : "0"}|x:`, e.hasExclude && (t += h(e.exclude)), t;
224
186
  }
225
187
  function h(e) {
188
+ return e.length === 0 ? "" : e.map((e) => g(e)).sort().join(",");
189
+ }
190
+ function g(e) {
226
191
  if (e === null) return "null:null";
227
192
  let t = typeof e;
228
193
  return t === "object" ? `object:${JSON.stringify(e)}` : `${t}:${String(e)}`;
229
194
  }
230
195
  //#endregion
231
- //#region src/filter/constants.ts
232
- var g = "deferFilterMutationIndexUpdates", _ = class {
196
+ //#region src/filter/nested.ts
197
+ var _ = class {
233
198
  constructor(e = {
234
199
  indexes: /* @__PURE__ */ new Map(),
235
200
  itemPositions: /* @__PURE__ */ new Map()
@@ -281,19 +246,12 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
281
246
  resolveCriteria(e) {
282
247
  if (e.length === 0) return [];
283
248
  let t = e[0];
284
- return "hasValues" in t && "hasExclude" in t && "includedValues" in t ? e : s(e);
249
+ return "hasValues" in t && "hasExclude" in t && "includedValues" in t ? e : c(e);
285
250
  }
286
251
  registerField(e) {
287
- let t = this.createDescriptor(e);
252
+ let t = r(e);
288
253
  t && (this.registeredFields.add(e), this.fieldDescriptors.set(e, t));
289
254
  }
290
- createDescriptor(e) {
291
- let t = e.indexOf(".");
292
- return t === -1 ? null : {
293
- collectionKey: e.substring(0, t),
294
- nestedKey: e.substring(t + 1)
295
- };
296
- }
297
255
  buildIndex(e, t) {
298
256
  let n = this.fieldDescriptors.get(t);
299
257
  if (!n) return;
@@ -476,9 +434,34 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
476
434
  }
477
435
  return r;
478
436
  }
479
- }, v = class {
437
+ }, v = () => ({
438
+ indexedFields: /* @__PURE__ */ new Set(),
439
+ indexerStorage: {
440
+ indexes: /* @__PURE__ */ new Map(),
441
+ itemPositions: /* @__PURE__ */ new Map()
442
+ },
443
+ nestedStorage: {
444
+ indexes: /* @__PURE__ */ new Map(),
445
+ itemPositions: /* @__PURE__ */ new Map()
446
+ },
447
+ deferredMutationVersion: null,
448
+ mutableExclude: {
449
+ datasetPositions: /* @__PURE__ */ new Map(),
450
+ valueCounts: /* @__PURE__ */ new Map(),
451
+ duplicateValueCount: 0,
452
+ hasDuplicateValues: !1
453
+ },
454
+ sequentialCache: {
455
+ previousResult: null,
456
+ previousCriteria: null,
457
+ previousCriteriaKey: null,
458
+ previousBaseData: null,
459
+ previousResultsByCriteria: /* @__PURE__ */ new Map(),
460
+ previousResultSet: null
461
+ }
462
+ }), y = class {
480
463
  constructor(t = {}) {
481
- this.chainBuilder = new a({
464
+ this.chainBuilder = new o({
482
465
  filter: (e, t) => t === void 0 ? this.filter(e) : this.filter(e, t),
483
466
  getOriginData: () => this.getOriginData(),
484
467
  add: (e) => this.add(e),
@@ -487,16 +470,16 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
487
470
  clearIndexes: () => this.clearIndexes(),
488
471
  clearData: () => this.clearData(),
489
472
  resetFilterState: () => this.resetFilterState()
490
- }), this.mutableExcludeField = t.mutableExcludeField ?? null, this.state = t.state ?? new e(t.data ?? [], { filterByPreviousResult: t.filterByPreviousResult ?? !1 }), t.state && t.filterByPreviousResult && this.state.setFilterByPreviousResult(!0), this.filterByPreviousResult = this.state.isFilterByPreviousResultEnabled(), this.namespace = this.state.createNamespace("filter"), this.indexer = new n(this.runtime.indexerStorage), this.nestedCollection = new _(this.runtime.nestedStorage), this.nestedCollection.registerFields(t.nestedFields), this.state.subscribe((e) => this.handleStateMutation(e)), this.rebuildMutableExcludeState();
491
- let r = t.fields?.length, i = this.nestedCollection.hasRegisteredFields();
492
- if (r) for (let e of t.fields) this.indexedFields.add(e);
493
- this.dataset.length > 0 && (r || i) && this.rebuildConfiguredIndexes();
473
+ }), this.mutableExcludeField = t.mutableExcludeField ?? null, this.state = t.state ?? new e(t.data ?? [], { filterByPreviousResult: t.filterByPreviousResult ?? !1 }), t.state && t.filterByPreviousResult && this.state.setFilterByPreviousResult(!0), this.filterByPreviousResult = this.state.isFilterByPreviousResultEnabled(), this.namespace = this.state.createNamespace("filter"), this.indexer = new a(this.runtime.indexerStorage), this.nestedCollection = new _(this.runtime.nestedStorage), this.nestedCollection.registerFields(t.nestedFields), this.state.subscribe((e) => this.handleStateMutation(e)), this.rebuildMutableExcludeState();
474
+ let n = t.fields?.length, r = this.nestedCollection.hasRegisteredFields();
475
+ if (n) for (let e of t.fields) this.indexedFields.add(e);
476
+ this.dataset.length > 0 && (n || r) && this.rebuildConfiguredIndexes();
494
477
  }
495
478
  get dataset() {
496
479
  return this.state.getOriginData();
497
480
  }
498
481
  get runtime() {
499
- return this.state.getOrCreateScopedValue(this.namespace, "runtime", r);
482
+ return this.state.getOrCreateScopedValue(this.namespace, "runtime", v);
500
483
  }
501
484
  get mutableExcludeState() {
502
485
  return this.runtime.mutableExclude;
@@ -508,7 +491,7 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
508
491
  return this.runtime.sequentialCache;
509
492
  }
510
493
  shouldDeferMutationIndexUpdates() {
511
- return this.state.getScopedValue(t, g) === !0;
494
+ return this.state.getScopedValue(t, n) === !0;
512
495
  }
513
496
  markDeferredMutationState() {
514
497
  this.runtime.deferredMutationVersion = this.state.getMutationVersion(), this.indexer.clear(), this.nestedCollection.clearIndexes(), this.clearMutableExcludeState(), this.resetFilterState();
@@ -523,7 +506,7 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
523
506
  }
524
507
  buildIndex(e, t) {
525
508
  if (!Array.isArray(e)) {
526
- if (!this.dataset.length) throw o.missingDatasetForBuildIndex();
509
+ if (!this.dataset.length) throw s.missingDatasetForBuildIndex();
527
510
  return this.indexer.buildIndex(this.dataset, e), this;
528
511
  }
529
512
  return this.resetFilterState(), this.rebuildMutableExcludeState(), this.indexer.buildIndex(e, t), this;
@@ -558,26 +541,26 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
558
541
  rawFilter(e, t) {
559
542
  this.ensureRuntimeReady();
560
543
  let n = t === void 0;
561
- if (n && !this.dataset.length) throw o.missingDatasetForFilter();
562
- let r = s(n ? e : t), i = n ? this.dataset : e;
544
+ if (n && !this.dataset.length) throw s.missingDatasetForFilter();
545
+ let r = c(n ? e : t), i = n ? this.dataset : e;
563
546
  if (n) {
564
547
  let e = this.applyMutableExclude(r);
565
548
  if (e !== void 0) return e;
566
549
  }
567
- let a = i, c = r;
550
+ let a = i, o = r;
568
551
  if (this.filterByPreviousResult) {
569
552
  let e = this.resolveWithSequentialCache(i, n, r);
570
553
  if (e.isFromCache) return e.result;
571
- a = e.sourceData, c = e.executionCriteria;
554
+ a = e.sourceData, o = e.executionCriteria;
572
555
  }
573
556
  if (r.length === 0) return this.filterByPreviousResult && this.resetFilterState(), i;
574
- for (let e = 0; e < c.length; e++) if (l(c[e])) return this.createEmptyResult(n, i, r);
575
- let u = [], d = [];
576
- for (let e = 0; e < c.length; e++) {
577
- let t = c[e];
578
- this.nestedCollection.hasField(t.field) ? u.push(t) : d.push(t);
557
+ for (let e = 0; e < o.length; e++) if (u(o[e])) return this.createEmptyResult(n, i, r);
558
+ let l = [], d = [];
559
+ for (let e = 0; e < o.length; e++) {
560
+ let t = o[e];
561
+ this.nestedCollection.hasField(t.field) ? l.push(t) : d.push(t);
579
562
  }
580
- if (u.length > 0 && (a = this.nestedCollection.filter(a, u, this.dataset), a.length === 0)) return this.createEmptyResult(n, i, r);
563
+ if (l.length > 0 && (a = this.nestedCollection.filter(a, l, this.dataset), a.length === 0)) return this.createEmptyResult(n, i, r);
581
564
  if (d.length === 0) return this.storePreviousResult(a, n, i, r), a;
582
565
  let f = [], p = [];
583
566
  for (let e = 0; e < d.length; e++) {
@@ -660,7 +643,7 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
660
643
  if (this.mutableExcludeField === null || e.length !== 1) return;
661
644
  let t = e[0];
662
645
  if (!(t.field !== this.mutableExcludeField || t.hasValues || !t.hasExclude)) {
663
- if (this.mutableExcludeState.hasDuplicateValues) throw o.duplicateMutableExcludeField(this.mutableExcludeField);
646
+ if (this.mutableExcludeState.hasDuplicateValues) throw s.duplicateMutableExcludeField(this.mutableExcludeField);
664
647
  return this.state.removeByFieldValues(this.mutableExcludeField, t.exclude), this.resetFilterState(), this.dataset;
665
648
  }
666
649
  }
@@ -711,7 +694,7 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
711
694
  let i = e[r], a = !0;
712
695
  for (let e = 0; e < t.length; e++) {
713
696
  let n = t[e];
714
- if (!c(n, i[n.field])) {
697
+ if (!l(n, i[n.field])) {
715
698
  a = !1;
716
699
  break;
717
700
  }
@@ -758,15 +741,15 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
758
741
  let t = i[e], n = this.estimateIndexSize(t);
759
742
  n < s && (o = t, s = n);
760
743
  }
761
- let l = this.indexer.getByValues(o.field, o.values);
762
- if (l.length === 0) return [];
744
+ let c = this.indexer.getByValues(o.field, o.values);
745
+ if (c.length === 0) return [];
763
746
  let u = [];
764
- for (let e = 0; e < l.length; e++) {
765
- let t = l[e], n = !0;
747
+ for (let e = 0; e < c.length; e++) {
748
+ let t = c[e], n = !0;
766
749
  if (!(r && !r.has(t))) {
767
750
  for (let e = 0; e < i.length; e++) {
768
751
  let r = i[e];
769
- if (r !== o && !c(r, t[r.field])) {
752
+ if (r !== o && !l(r, t[r.field])) {
770
753
  n = !1;
771
754
  break;
772
755
  }
@@ -905,4 +888,4 @@ var g = "deferFilterMutationIndexUpdates", _ = class {
905
888
  }
906
889
  };
907
890
  //#endregion
908
- export { v as FilterEngine };
891
+ export { y as FilterEngine };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./chunk-l_-R9TTp.mjs";
1
+ import { t as e } from "./chunk-BURK5sks.mjs";
2
2
  export { e as MergeEngines };
@@ -1,2 +1,2 @@
1
- import { t as e } from "../chunk-l_-R9TTp.mjs";
1
+ import { t as e } from "../chunk-BURK5sks.mjs";
2
2
  export { e as MergeEngines };
@@ -1,9 +1,7 @@
1
- import { n as e, t } from "../chunk-BTXXf5A-.mjs";
2
- //#region src/search/constants.ts
3
- var n = "deferSearchMutationIndexUpdates";
4
- //#endregion
1
+ import { a as e, i as t, n } from "../chunk-BJZg_1dI.mjs";
2
+ import { n as r } from "../chunk-C5Zpu_ol.mjs";
5
3
  //#region src/search/ngram.ts
6
- function r(e) {
4
+ function i(e) {
7
5
  for (let t = 0; t < e.length - 1; t++) {
8
6
  let n = t;
9
7
  for (let r = t + 1; r < e.length; r++) e[r].size < e[n].size && (n = r);
@@ -13,41 +11,41 @@ function r(e) {
13
11
  }
14
12
  }
15
13
  }
16
- function i(e, t) {
14
+ function a(e, t) {
17
15
  let n = [];
18
16
  for (let r of t) {
19
17
  let t = e.get(r);
20
18
  if (!t) return null;
21
19
  n.push(t);
22
20
  }
23
- return r(n), n;
21
+ return i(n), n;
24
22
  }
25
- function a(e, t) {
23
+ function o(e, t) {
26
24
  for (let n = 0; n < t.length; n++) if (!t[n].has(e)) return !1;
27
25
  return !0;
28
26
  }
29
- function o(e, t, n, r) {
30
- let o = i(e, t);
31
- if (o === null) return null;
32
- let s = o[0];
27
+ function s(e, t, n, r) {
28
+ let i = a(e, t);
29
+ if (i === null) return null;
30
+ let s = i[0];
33
31
  return {
34
32
  smallestPostingList: s,
35
- matches: (e) => s.has(e) && a(e, o) && !!n[e]?.includes(r)
33
+ matches: (e) => s.has(e) && o(e, i) && !!n[e]?.includes(r)
36
34
  };
37
35
  }
38
- function s(e) {
36
+ function c(e) {
39
37
  let t = Math.min(3, Math.max(2, e.length)), n = e.length - t + 1, r = Array(n);
40
38
  for (let i = 0; i < n; i++) r[i] = e.substring(i, i + t);
41
39
  return r;
42
40
  }
43
- function c(e, t) {
41
+ function l(e, t) {
44
42
  let n = e.get(t);
45
43
  if (n) return n;
46
44
  let r = /* @__PURE__ */ new Set();
47
45
  return e.set(t, r), r;
48
46
  }
49
- function l(e) {
50
- let t = s(e);
47
+ function u(e) {
48
+ let t = c(e);
51
49
  if (t.length <= 12) return new Set(t);
52
50
  let n = /* @__PURE__ */ new Set(), r = t.length - 1;
53
51
  for (let e = 0; e <= 11; e++) {
@@ -56,37 +54,37 @@ function l(e) {
56
54
  }
57
55
  return n;
58
56
  }
59
- function u(e, t, n) {
57
+ function d(e, t, n) {
60
58
  let r = Math.min(3, t.length);
61
59
  for (let i = 2; i <= r; i++) {
62
60
  let r = t.length - i;
63
- for (let a = 0; a <= r; a++) c(e, t.substring(a, a + i)).add(n);
61
+ for (let a = 0; a <= r; a++) l(e, t.substring(a, a + i)).add(n);
64
62
  }
65
63
  }
66
- function d(e, t, n, r, i = {}) {
67
- let { restrictionLookup: a = null, take: s = Infinity } = i, c = o(e, t, n, r);
64
+ function f(e, t, n, r, i = {}) {
65
+ let { restrictionLookup: a = null, take: o = Infinity } = i, c = s(e, t, n, r);
68
66
  if (c === null) return [];
69
67
  let l = [];
70
- for (let e of c.smallestPostingList) if (!(a !== null && !a[e]) && c.matches(e) && (l.push(e), l.length >= s)) break;
68
+ for (let e of c.smallestPostingList) if (!(a !== null && !a[e]) && c.matches(e) && (l.push(e), l.length >= o)) break;
71
69
  return l;
72
70
  }
73
- function f(e, t, n, r, i) {
74
- let { candidateIndices: a, restrictionLookup: s = null, take: c = Infinity } = i;
71
+ function p(e, t, n, r, i) {
72
+ let { candidateIndices: a, restrictionLookup: o = null, take: c = Infinity } = i;
75
73
  if (a.length === 0) return [];
76
- let l = o(e, t, n, r);
74
+ let l = s(e, t, n, r);
77
75
  if (l === null) return [];
78
76
  let u = [];
79
- if (s === null || a.length <= l.smallestPostingList.size) {
77
+ if (o === null || a.length <= l.smallestPostingList.size) {
80
78
  for (let e = 0; e < a.length; e++) {
81
79
  let t = a[e];
82
80
  if (l.matches(t) && (u.push(t), u.length >= c)) break;
83
81
  }
84
82
  return u;
85
83
  }
86
- for (let e of l.smallestPostingList) if (s[e] && l.matches(e) && (u.push(e), u.length >= c)) break;
84
+ for (let e of l.smallestPostingList) if (o[e] && l.matches(e) && (u.push(e), u.length >= c)) break;
87
85
  return u;
88
86
  }
89
- function p(e, t, n) {
87
+ function m(e, t, n) {
90
88
  let r = Math.min(3, t.length);
91
89
  for (let i = 2; i <= r; i++) {
92
90
  let r = t.length - i;
@@ -98,7 +96,7 @@ function p(e, t, n) {
98
96
  }
99
97
  //#endregion
100
98
  //#region src/search/nested.ts
101
- var m = class {
99
+ var h = class {
102
100
  constructor(e = {
103
101
  ngramIndexes: /* @__PURE__ */ new Map(),
104
102
  normalizedFieldValues: /* @__PURE__ */ new Map()
@@ -153,10 +151,10 @@ var m = class {
153
151
  let o = this.storage.ngramIndexes.get(e);
154
152
  if (!o) return [];
155
153
  let s = this.storage.normalizedFieldValues.get(e) ?? [];
156
- return i == null ? d(o, n, s, t, {
154
+ return i == null ? f(o, n, s, t, {
157
155
  restrictionLookup: r,
158
156
  take: a
159
- }) : f(o, n, s, t, {
157
+ }) : p(o, n, s, t, {
160
158
  candidateIndices: i,
161
159
  restrictionLookup: r,
162
160
  take: a
@@ -218,16 +216,9 @@ var m = class {
218
216
  return !1;
219
217
  }
220
218
  registerField(e) {
221
- let t = this.createDescriptor(e);
219
+ let t = r(e);
222
220
  t && (this.registeredFields.add(e), this.fieldDescriptors.set(e, t));
223
221
  }
224
- createDescriptor(e) {
225
- let t = e.indexOf(".");
226
- return t === -1 ? null : {
227
- collectionKey: e.substring(0, t),
228
- nestedKey: e.substring(t + 1)
229
- };
230
- }
231
222
  getNormalizedValues(e) {
232
223
  let t = this.storage.normalizedFieldValues.get(e);
233
224
  if (t) return t;
@@ -248,7 +239,7 @@ var m = class {
248
239
  }
249
240
  if (s.length === 0) continue;
250
241
  let c = s.join("\n");
251
- o[t] = c, u(a, c, t);
242
+ o[t] = c, d(a, c, t);
252
243
  }
253
244
  this.storage.ngramIndexes.set(t, a), this.storage.normalizedFieldValues.set(t, o);
254
245
  }
@@ -265,8 +256,8 @@ var m = class {
265
256
  typeof t == "string" && c.push(t.toLowerCase());
266
257
  }
267
258
  if (c.length === 0) continue;
268
- let d = c.join("\n");
269
- a[l] = d, u(i, d, l);
259
+ let u = c.join("\n");
260
+ a[l] = u, d(i, u, l);
270
261
  }
271
262
  }
272
263
  updateItemInField(e, t, n, r) {
@@ -274,18 +265,18 @@ var m = class {
274
265
  if (!i) return;
275
266
  let a = this.getNormalizedValues(e), o = this.getNormalizedItemValue(e, n), s = this.getNormalizedItemValue(e, t);
276
267
  if (o !== s) {
277
- if (o && p(i, o, r), !s) {
268
+ if (o && m(i, o, r), !s) {
278
269
  delete a[r];
279
270
  return;
280
271
  }
281
- a[r] = s, u(i, s, r);
272
+ a[r] = s, d(i, s, r);
282
273
  }
283
274
  }
284
275
  removeItemFromField(e, t, n) {
285
276
  let r = this.storage.ngramIndexes.get(e);
286
277
  if (!r) return;
287
278
  let i = this.getNormalizedValues(e), a = i[n] ?? this.getNormalizedItemValue(e, t);
288
- a && p(r, a, n), delete i[n];
279
+ a && m(r, a, n), delete i[n];
289
280
  }
290
281
  moveItemForField(e, t, n, r) {
291
282
  let i = this.storage.ngramIndexes.get(e);
@@ -295,7 +286,7 @@ var m = class {
295
286
  delete a[n];
296
287
  return;
297
288
  }
298
- p(i, o, n), u(i, o, r), a[r] = o, delete a[n];
289
+ m(i, o, n), d(i, o, r), a[r] = o, delete a[n];
299
290
  }
300
291
  getNormalizedItemValue(e, t) {
301
292
  let n = this.fieldDescriptors.get(e);
@@ -309,7 +300,7 @@ var m = class {
309
300
  }
310
301
  return o.length === 0 ? null : o.join("\n");
311
302
  }
312
- }, h = () => ({
303
+ }, g = () => ({
313
304
  indexedFields: /* @__PURE__ */ new Set(),
314
305
  flatIndexes: /* @__PURE__ */ new Map(),
315
306
  nestedStorage: {
@@ -327,9 +318,9 @@ var m = class {
327
318
  fallbackQueries: 0,
328
319
  fallbackFields: /* @__PURE__ */ new Map()
329
320
  }
330
- }), g = class {
321
+ }), _ = class {
331
322
  constructor(t = {}) {
332
- this.cachedIndexedFieldsList = null, this.cachedLinearSearchFieldsList = null, this.emittedWarningKeys = /* @__PURE__ */ new Set(), this.warnings = [], this.normalizedValuesCache = /* @__PURE__ */ new Map(), this.combinedNormalizedValuesCache = null, this.minQueryLength = t.minQueryLength ?? 1, this.silent = t.silent ?? !1, this.state = t.state ?? new e(t.data ?? []), this.namespace = this.state.createNamespace("search"), this.nestedCollection = new m(this.runtime.nestedStorage), this.nestedCollection.registerFields(t.nestedFields), this.state.subscribe((e) => this.handleStateMutation(e)), t.filterByPreviousResult && (this.runtime.filterByPreviousResult = !0);
323
+ this.cachedIndexedFieldsList = null, this.cachedLinearSearchFieldsList = null, this.emittedWarningKeys = /* @__PURE__ */ new Set(), this.warnings = [], this.normalizedValuesCache = /* @__PURE__ */ new Map(), this.combinedNormalizedValuesCache = null, this.minQueryLength = t.minQueryLength ?? 1, this.silent = t.silent ?? !1, this.state = t.state ?? new e(t.data ?? []), this.namespace = this.state.createNamespace("search"), this.nestedCollection = new h(this.runtime.nestedStorage), this.nestedCollection.registerFields(t.nestedFields), this.state.subscribe((e) => this.handleStateMutation(e)), t.filterByPreviousResult && (this.runtime.filterByPreviousResult = !0);
333
324
  let n = t.fields?.length, r = this.nestedCollection.hasRegisteredFields();
334
325
  if (n) for (let e of t.fields) this.indexedFields.add(e);
335
326
  this.dataset.length > 0 && (n || r) && this.rebuildConfiguredIndexes();
@@ -338,7 +329,7 @@ var m = class {
338
329
  return this.state.getOriginData();
339
330
  }
340
331
  get runtime() {
341
- return this.state.getOrCreateScopedValue(this.namespace, "runtime", h);
332
+ return this.state.getOrCreateScopedValue(this.namespace, "runtime", g);
342
333
  }
343
334
  get flatIndexes() {
344
335
  return this.runtime.flatIndexes;
@@ -366,7 +357,7 @@ var m = class {
366
357
  let a = e[n][t];
367
358
  if (typeof a != "string") continue;
368
359
  let o = a.toLowerCase();
369
- i[n] = o, u(r, o, n);
360
+ i[n] = o, d(r, o, n);
370
361
  }
371
362
  this.flatIndexes.set(t, {
372
363
  ngramMap: r,
@@ -491,7 +482,7 @@ var m = class {
491
482
  return n && n.version !== t && this.dataset.length > 0 && (this.buildIndexFromData(this.dataset, e), n = this.flatIndexes.get(e)), n;
492
483
  }
493
484
  getQueryGrams(e) {
494
- let t = l(e);
485
+ let t = u(e);
495
486
  return t.size > 0 ? t : null;
496
487
  }
497
488
  searchAllFields(e, t) {
@@ -556,31 +547,31 @@ var m = class {
556
547
  for (let n of this.flatIndexes.keys()) {
557
548
  let r = this.getResolvedFlatIndex(n);
558
549
  if (!r) continue;
559
- let i = o(r.ngramMap, t, r.normalizedValues, e);
550
+ let i = s(r.ngramMap, t, r.normalizedValues, e);
560
551
  i !== null && a.push(i.matches);
561
552
  }
562
553
  if (a.length === 0) return {
563
554
  items: [],
564
555
  indices: []
565
556
  };
566
- let s = [], c = 0;
557
+ let o = [], c = 0;
567
558
  for (let e = 0; e < i.length; e++) {
568
559
  let t = i[e];
569
560
  if (r !== null && !r[t]) continue;
570
- let o = !1;
561
+ let s = !1;
571
562
  for (let e = 0; e < a.length; e++) if (a[e](t)) {
572
- o = !0;
563
+ s = !0;
573
564
  break;
574
565
  }
575
- if (o) {
566
+ if (s) {
576
567
  if (c < n.offset) {
577
568
  c += 1;
578
569
  continue;
579
570
  }
580
- if (s.push(t), c += 1, this.hasReachedWindowLimit(n, s.length)) break;
571
+ if (o.push(t), c += 1, this.hasReachedWindowLimit(n, o.length)) break;
581
572
  }
582
573
  }
583
- return this.materializeIndicesResult(s);
574
+ return this.materializeIndicesResult(o);
584
575
  }
585
576
  searchField(e, t, n) {
586
577
  let r = this.normalizeQuery(t), i = this.normalizeSearchWindow(n), a = `field "${e}"`;
@@ -641,10 +632,10 @@ var m = class {
641
632
  let o = this.getResolvedFlatIndex(e);
642
633
  if (!o) return [];
643
634
  let { ngramMap: s, normalizedValues: c } = o;
644
- return i === null ? d(s, n, c, t, {
635
+ return i === null ? f(s, n, c, t, {
645
636
  restrictionLookup: r,
646
637
  take: a
647
- }) : f(s, n, c, t, {
638
+ }) : p(s, n, c, t, {
648
639
  candidateIndices: i,
649
640
  restrictionLookup: r,
650
641
  take: a
@@ -965,7 +956,7 @@ var m = class {
965
956
  let o = t[r][e];
966
957
  if (typeof o != "string") continue;
967
958
  let s = o.toLowerCase(), c = n + r;
968
- a[c] = s, u(i, s, c);
959
+ a[c] = s, d(i, s, c);
969
960
  }
970
961
  r.version = this.state.getMutationVersion();
971
962
  }
@@ -985,19 +976,19 @@ var m = class {
985
976
  return;
986
977
  }
987
978
  let { ngramMap: a, normalizedValues: o } = i, s = this.getNormalizedFieldValue(n, e);
988
- s && p(a, s, t);
979
+ s && m(a, s, t);
989
980
  let c = this.getNormalizedFieldValue(r, e);
990
981
  if (!c) {
991
982
  delete o[t], i.version = this.state.getMutationVersion();
992
983
  return;
993
984
  }
994
- o[t] = c, u(a, c, t), i.version = this.state.getMutationVersion();
985
+ o[t] = c, d(a, c, t), i.version = this.state.getMutationVersion();
995
986
  }
996
987
  removeIndexedFieldValue(e, t, n) {
997
988
  let r = this.flatIndexes.get(e);
998
989
  if (!r) return;
999
990
  let { ngramMap: i, normalizedValues: a } = r, o = this.getNormalizedFieldValue(t, e);
1000
- o && p(i, o, n), delete a[n], r.version = this.state.getMutationVersion();
991
+ o && m(i, o, n), delete a[n], r.version = this.state.getMutationVersion();
1001
992
  }
1002
993
  moveIndexedFieldValue(e, t, n, r) {
1003
994
  if (n === r) return;
@@ -1008,7 +999,7 @@ var m = class {
1008
999
  delete o[n], i.version = this.state.getMutationVersion();
1009
1000
  return;
1010
1001
  }
1011
- p(a, s, n), u(a, s, r), o[r] = s, delete o[n], i.version = this.state.getMutationVersion();
1002
+ m(a, s, n), d(a, s, r), o[r] = s, delete o[n], i.version = this.state.getMutationVersion();
1012
1003
  }
1013
1004
  getNormalizedFieldValue(e, t) {
1014
1005
  let n = e[t];
@@ -1016,4 +1007,4 @@ var m = class {
1016
1007
  }
1017
1008
  };
1018
1009
  //#endregion
1019
- export { g as TextSearchEngine };
1010
+ export { _ as TextSearchEngine };
@@ -1,13 +1,13 @@
1
- import { n as e, t } from "../chunk-BTXXf5A-.mjs";
1
+ import { a as e, i as t, r as n } from "../chunk-BJZg_1dI.mjs";
2
2
  //#region src/sort/errors.ts
3
- var n = class e extends Error {
3
+ var r = class e extends Error {
4
4
  constructor(e) {
5
5
  super(e), this.name = "SortEngineError";
6
6
  }
7
7
  static missingDatasetForSort() {
8
8
  return new e("SortEngine: no dataset in memory.");
9
9
  }
10
- }, r = "deferSortMutationCacheUpdates";
10
+ };
11
11
  //#endregion
12
12
  //#region src/sort/utils.ts
13
13
  function i(e, t) {
@@ -64,7 +64,7 @@ var o = () => ({
64
64
  return this.runtime.indexedFields;
65
65
  }
66
66
  shouldDeferMutationCacheUpdates() {
67
- return this.state.getScopedValue(t, r) === !0;
67
+ return this.state.getScopedValue(t, n) === !0;
68
68
  }
69
69
  invalidateCachedIndexes() {
70
70
  for (let e of this.indexedFields) this.cache.delete(e);
@@ -159,10 +159,10 @@ var o = () => ({
159
159
  return;
160
160
  }
161
161
  }
162
- sort(e, t, r = !1) {
162
+ sort(e, t, n = !1) {
163
163
  let i = t === void 0, a, o;
164
164
  if (i) {
165
- if (!this.dataset.length) throw n.missingDatasetForSort();
165
+ if (!this.dataset.length) throw r.missingDatasetForSort();
166
166
  a = this.dataset, o = e;
167
167
  } else a = e, o = t;
168
168
  if (o.length === 0 || a.length === 0) return a;
@@ -172,9 +172,9 @@ var o = () => ({
172
172
  let n = this.cache.get(e), r = this.state.getMutationVersion();
173
173
  return (!n || n.version !== r) && (this.buildIndexForDataset(e), n = this.cache.get(e)), this.getCachedSortedItems(n, t);
174
174
  }
175
- return this.sortNumericFastPath(a, e, t, r);
175
+ return this.sortNumericFastPath(a, e, t, n);
176
176
  }
177
- return this.sortMultiField(a, o, r, i);
177
+ return this.sortMultiField(a, o, n, i);
178
178
  }
179
179
  sortNumericFastPath(e, t, n, r) {
180
180
  if (e.length === 0 || typeof e[0][t] != "number") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devisfuture/mega-collection",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
4
4
  "description": "High-performance search, filter & sort engine for 100K+ item collections in JavaScript/TypeScript",
5
5
  "exports": {
6
6
  ".": {