@dcupl/common 2.0.0-beta.22 → 2.0.0-beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,47 +1,47 @@
1
- import { cloneDeep as v, get as I, every as z, findIndex as $, size as V, isEqual as H, differenceBy as O, isEqualWith as k, isMatch as q, find as J } from "lodash-es";
2
- function D(n) {
3
- const e = N(n);
1
+ import { cloneDeep as v, get as I, every as _, findIndex as $, size as V, isEqual as H, differenceBy as O, isEqualWith as k, isMatch as G, find as J } from "lodash-es";
2
+ function D(i) {
3
+ const e = E(i);
4
4
  return Z(e);
5
5
  }
6
- function N(n) {
7
- if (typeof n != "object" || n === null)
8
- return String(n);
9
- if (Array.isArray(n))
10
- return "[" + n.map(N).join(",") + "]";
11
- const e = Object.keys(n).sort();
6
+ function E(i) {
7
+ if (typeof i != "object" || i === null)
8
+ return String(i);
9
+ if (Array.isArray(i))
10
+ return "[" + i.map(E).join(",") + "]";
11
+ const e = Object.keys(i).sort();
12
12
  let t = "{";
13
13
  for (let r = 0; r < e.length; r++) {
14
14
  const s = e[r];
15
- t += s + ":" + N(n[s]), r < e.length - 1 && (t += ",");
15
+ t += s + ":" + E(i[s]), r < e.length - 1 && (t += ",");
16
16
  }
17
17
  return t += "}", t;
18
18
  }
19
- function Z(n) {
19
+ function Z(i) {
20
20
  let e = 0;
21
- for (let t = 0; t < n.length; t++) {
22
- const r = n.charCodeAt(t);
21
+ for (let t = 0; t < i.length; t++) {
22
+ const r = i.charCodeAt(t);
23
23
  e = (e << 5) - e + r, e |= 0;
24
24
  }
25
25
  return e.toString(16);
26
26
  }
27
27
  const b = {
28
28
  now: () => typeof performance < "u" && performance.now ? performance.now() : (/* @__PURE__ */ new Date()).getTime(),
29
- mark: (n) => {
30
- typeof performance < "u" && performance.mark && performance.mark(n);
29
+ mark: (i) => {
30
+ typeof performance < "u" && performance.mark && performance.mark(i);
31
31
  },
32
- measure: (n, e, t) => {
33
- typeof performance < "u" && performance.measure && performance.measure(n, e, t);
32
+ measure: (i, e, t) => {
33
+ typeof performance < "u" && performance.measure && performance.measure(i, e, t);
34
34
  },
35
- getEntriesByName(n) {
35
+ getEntriesByName(i) {
36
36
  if (typeof performance < "u" && performance.getEntriesByName)
37
- return performance.getEntriesByName(n);
37
+ return performance.getEntriesByName(i);
38
38
  },
39
- getEntriesByType(n) {
39
+ getEntriesByType(i) {
40
40
  if (typeof performance < "u" && performance.getEntriesByType)
41
- return performance.getEntriesByType(n);
41
+ return performance.getEntriesByType(i);
42
42
  }
43
43
  };
44
- class Fe {
44
+ class qe {
45
45
  data;
46
46
  enabled = !1;
47
47
  constructor() {
@@ -69,7 +69,7 @@ class Fe {
69
69
  const t = this.getKey(e.name, e.context), r = this.data.get(this.getKey(e.start, e.context)), s = this.data.get(this.getKey(e.end, e.context));
70
70
  if (!r || !s)
71
71
  return;
72
- const i = s.value - r.value, o = Math.round(i * 100) / 100, a = this.data.get(t);
72
+ const n = s.value - r.value, o = Math.round(n * 100) / 100, a = this.data.get(t);
73
73
  if (a && e.sum) {
74
74
  const u = a.value + o, f = {
75
75
  ...a,
@@ -118,7 +118,7 @@ class Fe {
118
118
  return e + "_" + r;
119
119
  }
120
120
  }
121
- let X = class j {
121
+ let X = class z {
122
122
  nodes;
123
123
  edges;
124
124
  nodeKinds = /* @__PURE__ */ new Map();
@@ -198,9 +198,9 @@ let X = class j {
198
198
  if (t.has(s))
199
199
  return !0;
200
200
  t.add(s);
201
- const i = this.edges.get(s);
202
- if (i) {
203
- for (let o of i)
201
+ const n = this.edges.get(s);
202
+ if (n) {
203
+ for (let o of n)
204
204
  if (r(o))
205
205
  return !0;
206
206
  }
@@ -217,36 +217,36 @@ let X = class j {
217
217
  * @returns {hasCycle: boolean, path?: string[]} - hasCycle is true if a cycle exists, path contains the cycle nodes
218
218
  */
219
219
  validateNoCycles() {
220
- const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), r = [], s = (i) => {
221
- if (e.has(i))
220
+ const e = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set(), r = [], s = (n) => {
221
+ if (e.has(n))
222
222
  return null;
223
- if (t.has(i)) {
224
- const a = r.indexOf(i);
225
- return r.slice(a).concat([i]);
223
+ if (t.has(n)) {
224
+ const a = r.indexOf(n);
225
+ return r.slice(a).concat([n]);
226
226
  }
227
- t.add(i), r.push(i);
228
- const o = this.edges.get(i);
227
+ t.add(n), r.push(n);
228
+ const o = this.edges.get(n);
229
229
  if (o)
230
230
  for (let a of o) {
231
231
  const c = s(a);
232
232
  if (c)
233
233
  return c;
234
234
  }
235
- return r.pop(), t.delete(i), e.add(i), null;
235
+ return r.pop(), t.delete(n), e.add(n), null;
236
236
  };
237
- for (let i of this.nodes) {
238
- const o = s(i);
237
+ for (let n of this.nodes) {
238
+ const o = s(n);
239
239
  if (o)
240
240
  return { hasCycle: !0, path: o };
241
241
  }
242
242
  return { hasCycle: !1 };
243
243
  }
244
244
  order(e) {
245
- const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = [], i = e?.allowCycles ?? !1, o = (a) => {
245
+ const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = [], n = e?.allowCycles ?? !1, o = (a) => {
246
246
  if (t.has(a))
247
247
  return;
248
248
  if (r.has(a)) {
249
- if (i)
249
+ if (n)
250
250
  return;
251
251
  throw new Error("Graph has a cycle.");
252
252
  }
@@ -331,20 +331,20 @@ let X = class j {
331
331
  for (const a of o) t.set(a, (t.get(a) || 0) + 1);
332
332
  const r = [];
333
333
  let s = Array.from(this.nodes).filter((o) => (t.get(o) || 0) === 0);
334
- const i = /* @__PURE__ */ new Set();
334
+ const n = /* @__PURE__ */ new Set();
335
335
  for (; s.length > 0; ) {
336
336
  const o = s.slice();
337
337
  r.push(o), s = [];
338
338
  for (const a of o) {
339
- if (i.has(a)) continue;
340
- i.add(a);
339
+ if (n.has(a)) continue;
340
+ n.add(a);
341
341
  const c = this.edges.get(a);
342
342
  if (c)
343
343
  for (const u of c)
344
344
  t.set(u, (t.get(u) || 0) - 1), (t.get(u) || 0) === 0 && s.push(u);
345
345
  }
346
346
  }
347
- if (i.size !== this.nodes.size)
347
+ if (n.size !== this.nodes.size)
348
348
  throw new Error("Graph has a cycle.");
349
349
  if (e?.filterKinds && e.filterKinds.length > 0) {
350
350
  const o = new Set(e.filterKinds);
@@ -362,7 +362,7 @@ let X = class j {
362
362
  * - 'both': union of upstream and downstream
363
363
  */
364
364
  getImpactedNodes(e, t = "downstream", r) {
365
- const s = new Set(e), i = (u) => !r || r.length === 0 || r.includes(this.nodeKinds.get(u) ?? void 0), o = () => {
365
+ const s = new Set(e), n = (u) => !r || r.length === 0 || r.includes(this.nodeKinds.get(u) ?? void 0), o = () => {
366
366
  const u = /* @__PURE__ */ new Set(), f = Array.from(s);
367
367
  for (; f.length; ) {
368
368
  const d = f.shift();
@@ -381,7 +381,7 @@ let X = class j {
381
381
  return u;
382
382
  };
383
383
  let c;
384
- return t === "both" ? c = /* @__PURE__ */ new Set([...o(), ...a()]) : t === "upstream" ? c = a() : c = o(), Array.from(c).filter(i);
384
+ return t === "both" ? c = /* @__PURE__ */ new Set([...o(), ...a()]) : t === "upstream" ? c = a() : c = o(), Array.from(c).filter(n);
385
385
  }
386
386
  toJSON() {
387
387
  const e = Array.from(this.nodes).map((r) => ({
@@ -392,7 +392,7 @@ let X = class j {
392
392
  return { nodes: e, edges: t };
393
393
  }
394
394
  static fromJSON(e) {
395
- const t = new j();
395
+ const t = new z();
396
396
  for (const r of e.nodes)
397
397
  t.addNode(r.name, { kind: r.kind, meta: r.meta });
398
398
  for (const r of e.edges)
@@ -400,15 +400,15 @@ let X = class j {
400
400
  return t;
401
401
  }
402
402
  diff(e) {
403
- const t = new Set(this.getNodes()), r = new Set(e.getNodes()), s = Array.from(r).filter((d) => !t.has(d)), i = Array.from(t).filter((d) => !r.has(d)), o = new Set(this.getAllEdges().map((d) => d.join("→"))), a = new Set(e.getAllEdges().map((d) => d.join("→"))), c = Array.from(a).filter((d) => !o.has(d)).map((d) => d.split("→")), u = Array.from(o).filter((d) => !a.has(d)).map((d) => d.split("→")), f = [];
403
+ const t = new Set(this.getNodes()), r = new Set(e.getNodes()), s = Array.from(r).filter((d) => !t.has(d)), n = Array.from(t).filter((d) => !r.has(d)), o = new Set(this.getAllEdges().map((d) => d.join("→"))), a = new Set(e.getAllEdges().map((d) => d.join("→"))), c = Array.from(a).filter((d) => !o.has(d)).map((d) => d.split("→")), u = Array.from(o).filter((d) => !a.has(d)).map((d) => d.split("→")), f = [];
404
404
  for (const d of /* @__PURE__ */ new Set([...t, ...r])) {
405
405
  const l = this.nodeKinds.get(d), h = e.nodeKinds.get(d);
406
406
  l !== h && f.push({ name: d, from: l, to: h });
407
407
  }
408
- return { addedNodes: s, removedNodes: i, addedEdges: c, removedEdges: u, kindChanges: f };
408
+ return { addedNodes: s, removedNodes: n, addedEdges: c, removedEdges: u, kindChanges: f };
409
409
  }
410
410
  };
411
- class Ge {
411
+ class Fe {
412
412
  graph;
413
413
  nodeIndex;
414
414
  constructor() {
@@ -454,8 +454,8 @@ class Ge {
454
454
  * @returns Array of all impacted attribute nodes (including the changed ones)
455
455
  */
456
456
  getImpactedAttributes(e) {
457
- const t = e.map((a) => this.getNodeId(a.modelKey, a.attributeKey)), s = this.graph.getImpactedNodes(t, "downstream").map((a) => this.nodeIndex.get(a)).filter((a) => a !== void 0), i = [...e, ...s], o = /* @__PURE__ */ new Set();
458
- return i.filter((a) => {
457
+ const t = e.map((a) => this.getNodeId(a.modelKey, a.attributeKey)), s = this.graph.getImpactedNodes(t, "downstream").map((a) => this.nodeIndex.get(a)).filter((a) => a !== void 0), n = [...e, ...s], o = /* @__PURE__ */ new Set();
458
+ return n.filter((a) => {
459
459
  const c = this.getNodeId(a.modelKey, a.attributeKey);
460
460
  return o.has(c) ? !1 : (o.add(c), !0);
461
461
  });
@@ -468,11 +468,11 @@ class Ge {
468
468
  * @returns Map<modelKey, Map<processingStep, Set<attributeKeys>>>
469
469
  */
470
470
  getProcessingOrder(e) {
471
- const t = /* @__PURE__ */ new Map(), r = [...e].sort((s, i) => s.processingStep - i.processingStep);
471
+ const t = /* @__PURE__ */ new Map(), r = [...e].sort((s, n) => s.processingStep - n.processingStep);
472
472
  for (const s of r) {
473
- const { modelKey: i, attributeKey: o, processingStep: a } = s;
474
- t.has(i) || t.set(i, /* @__PURE__ */ new Map());
475
- const c = t.get(i);
473
+ const { modelKey: n, attributeKey: o, processingStep: a } = s;
474
+ t.has(n) || t.set(n, /* @__PURE__ */ new Map());
475
+ const c = t.get(n);
476
476
  c.has(a) || c.set(a, /* @__PURE__ */ new Set()), c.get(a).add(o);
477
477
  }
478
478
  return t;
@@ -528,10 +528,10 @@ class Ge {
528
528
  const t = (r, s = /* @__PURE__ */ new Set()) => {
529
529
  if (s.has(r)) return 0;
530
530
  s.add(r);
531
- const i = this.graph.getDependencies(r);
532
- if (i.length === 0) return 1;
531
+ const n = this.graph.getDependencies(r);
532
+ if (n.length === 0) return 1;
533
533
  let o = 0;
534
- for (const a of i) {
534
+ for (const a of n) {
535
535
  const c = t(a, new Set(s));
536
536
  o = Math.max(o, c);
537
537
  }
@@ -554,9 +554,9 @@ class Ge {
554
554
  validateCompleteness(e) {
555
555
  const t = [];
556
556
  for (const [r, s] of e)
557
- for (const i of s) {
558
- const o = this.getNodeId(r, i);
559
- this.hasNode(o) || t.push({ modelKey: r, attributeKey: i });
557
+ for (const n of s) {
558
+ const o = this.getNodeId(r, n);
559
+ this.hasNode(o) || t.push({ modelKey: r, attributeKey: n });
560
560
  }
561
561
  return {
562
562
  isComplete: t.length === 0,
@@ -678,8 +678,8 @@ class g {
678
678
  stack: e.error.stack
679
679
  }), JSON.stringify(o);
680
680
  }
681
- const t = new Date(e.timestamp).toISOString().substring(11, 23), r = e.prefix ? `[${e.prefix}]` : "", s = this.getLevelIcon(e.level), i = e.context ? ` ${JSON.stringify(e.context)}` : "";
682
- return `${t} ${s} ${r} ${e.message}${i}`.trim();
681
+ const t = new Date(e.timestamp).toISOString().substring(11, 23), r = e.prefix ? `[${e.prefix}]` : "", s = this.getLevelIcon(e.level), n = e.context ? ` ${JSON.stringify(e.context)}` : "";
682
+ return `${t} ${s} ${r} ${e.message}${n}`.trim();
683
683
  }
684
684
  getLevelIcon(e) {
685
685
  switch (e) {
@@ -698,7 +698,7 @@ class g {
698
698
  log(e, t, r, s) {
699
699
  if (!this.shouldLog(e))
700
700
  return;
701
- const i = {
701
+ const n = {
702
702
  level: e,
703
703
  message: t,
704
704
  timestamp: Date.now(),
@@ -707,10 +707,10 @@ class g {
707
707
  error: s
708
708
  };
709
709
  if (this.config.onLog) {
710
- this.config.onLog(i);
710
+ this.config.onLog(n);
711
711
  return;
712
712
  }
713
- const o = this.formatMessage(i);
713
+ const o = this.formatMessage(n);
714
714
  if (typeof console < "u")
715
715
  switch (e) {
716
716
  case "error":
@@ -730,8 +730,8 @@ class g {
730
730
  * Log an error message
731
731
  */
732
732
  error(e, t, r) {
733
- const s = t instanceof Error ? t : void 0, i = t instanceof Error ? r : t;
734
- this.log("error", e, i, s);
733
+ const s = t instanceof Error ? t : void 0, n = t instanceof Error ? r : t;
734
+ this.log("error", e, n, s);
735
735
  }
736
736
  /**
737
737
  * Log and track an error (integrates with QualityController)
@@ -800,7 +800,7 @@ class g {
800
800
  }
801
801
  }
802
802
  const Y = new g();
803
- class _e {
803
+ class Pe {
804
804
  constructor(e) {
805
805
  this.enabled = e, this.cache = /* @__PURE__ */ new Map(), this.cacheDependencies = /* @__PURE__ */ new Map();
806
806
  }
@@ -819,8 +819,8 @@ class _e {
819
819
  }
820
820
  set(e, t, r, s) {
821
821
  if (!this.enabled) return;
822
- const i = this.getCacheName(e, t);
823
- this.cache.set(i, r), s ? this.cacheDependencies.set(i, s) : this.log.debug(
822
+ const n = this.getCacheName(e, t);
823
+ this.cache.set(n, r), s ? this.cacheDependencies.set(n, s) : this.log.debug(
824
824
  `Cache entry '${e}' stored without dependencies. This prevents granular invalidation and may cause stale data.`
825
825
  );
826
826
  }
@@ -838,21 +838,21 @@ class _e {
838
838
  if (!this.enabled) return;
839
839
  const t = [];
840
840
  for (const [r, s] of this.cacheDependencies) {
841
- let i = !1;
841
+ let n = !1;
842
842
  for (const [o, a] of e) {
843
843
  if (s.models.has(o))
844
844
  if (s.modelAttributes.has(o)) {
845
845
  const c = s.modelAttributes.get(o);
846
846
  for (const u of a)
847
847
  if (c.has(u)) {
848
- i = !0;
848
+ n = !0;
849
849
  break;
850
850
  }
851
851
  } else
852
- i = !0;
853
- if (i) break;
852
+ n = !0;
853
+ if (n) break;
854
854
  }
855
- i && t.push(r);
855
+ n && t.push(r);
856
856
  }
857
857
  for (const r of t)
858
858
  this.cache.delete(r), this.cacheDependencies.delete(r);
@@ -864,9 +864,9 @@ class _e {
864
864
  invalidateByModels(e) {
865
865
  if (!this.enabled) return;
866
866
  const t = new Set(e), r = [];
867
- for (const [s, i] of this.cacheDependencies)
867
+ for (const [s, n] of this.cacheDependencies)
868
868
  for (const o of t)
869
- if (i.models.has(o)) {
869
+ if (n.models.has(o)) {
870
870
  r.push(s);
871
871
  break;
872
872
  }
@@ -940,44 +940,44 @@ class _e {
940
940
  };
941
941
  }
942
942
  }
943
- const P = (n, e = "") => {
944
- if (!(typeof n != "string" || !n.startsWith("/") || !n.endsWith("/")))
945
- return { pattern: n.slice(1, -1), flags: e };
946
- }, ze = (n, e = "") => `${n}#${e}`, je = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, Pe = (n) => `${n.gt}_${n.gte}_${n.lt}_${n.lte}_${n.eq}_${n.ne}`, Be = (n, e) => {
943
+ const j = (i, e = "") => {
944
+ if (!(typeof i != "string" || !i.startsWith("/") || !i.endsWith("/")))
945
+ return { pattern: i.slice(1, -1), flags: e };
946
+ }, _e = (i, e = "") => `${i}#${e}`, ze = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, je = (i) => `${i.gt}_${i.gte}_${i.lt}_${i.lte}_${i.eq}_${i.ne}`, Be = (i, e) => {
947
947
  const t = typeof e == "function" ? e : (r) => r[e];
948
948
  return [
949
- ...n.reduce((r, s) => {
950
- const i = s == null ? s : t(s);
951
- return r.has(i) || r.set(i, s), r;
949
+ ...i.reduce((r, s) => {
950
+ const n = s == null ? s : t(s);
951
+ return r.has(n) || r.set(n, s), r;
952
952
  }, /* @__PURE__ */ new Map()).values()
953
953
  ];
954
- }, Le = (n, e) => n.reduce(function(t, r) {
954
+ }, Le = (i, e) => i.reduce(function(t, r) {
955
955
  const s = typeof e == "function" ? e(r) : r[e];
956
956
  return Object.prototype.hasOwnProperty.call(t, s) || (t[s] = []), t[s].push(r), t;
957
957
  }, {});
958
- function ee(n = 10) {
958
+ function ee(i = 10) {
959
959
  let e = "";
960
960
  const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
961
- for (let r = 0; r < n; r++) e += t.charAt(Math.floor(Math.random() * t.length));
961
+ for (let r = 0; r < i; r++) e += t.charAt(Math.floor(Math.random() * t.length));
962
962
  return e;
963
963
  }
964
- const Ue = (n) => n.replace(/\/+$/, ""), te = (n) => typeof n != "string" ? "" : n.replace(/[[\]{}()*+?.,\\^$|#]/g, "\\$&"), We = (n) => typeof n != "string" ? "" : n.replace(/\\([[\]{}()*+?.,\\^$|#])/g, "$1"), Ve = (n, e) => {
964
+ const Ue = (i) => i.replace(/\/+$/, ""), te = (i) => typeof i != "string" ? "" : i.replace(/[[\]{}()*+?.,\\^$|#]/g, "\\$&"), We = (i) => typeof i != "string" ? "" : i.replace(/\\([[\]{}()*+?.,\\^$|#])/g, "$1"), Ve = (i, e) => {
965
965
  try {
966
- return re(n, e) >= 0;
966
+ return re(i, e) >= 0;
967
967
  } catch {
968
968
  return !1;
969
969
  }
970
- }, re = (n, e) => {
971
- if (!T(n) || !T(e))
972
- throw new Error(`Invalid version format: v1="${n}", v2="${e}". Expected format: "x.y.z"`);
973
- const t = n.split(".").map(Number), r = e.split(".").map(Number);
970
+ }, re = (i, e) => {
971
+ if (!T(i) || !T(e))
972
+ throw new Error(`Invalid version format: v1="${i}", v2="${e}". Expected format: "x.y.z"`);
973
+ const t = i.split(".").map(Number), r = e.split(".").map(Number);
974
974
  for (let s = 0; s < 3; s++) {
975
- const i = t[s] || 0, o = r[s] || 0;
976
- if (i > o) return 1;
977
- if (i < o) return -1;
975
+ const n = t[s] || 0, o = r[s] || 0;
976
+ if (n > o) return 1;
977
+ if (n < o) return -1;
978
978
  }
979
979
  return 0;
980
- }, T = (n) => /^\d+(\.\d+){0,2}$/.test(n);
980
+ }, T = (i) => /^\d+(\.\d+){0,2}$/.test(i);
981
981
  class He {
982
982
  key;
983
983
  parentCd;
@@ -1014,10 +1014,10 @@ class He {
1014
1014
  };
1015
1015
  }
1016
1016
  }
1017
- const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n) : n, F = (n, e, t, r, s, i) => {
1017
+ const B = (i, e) => e ? typeof structuredClone < "u" ? structuredClone(i) : v(i) : i, q = (i, e, t, r, s, n) => {
1018
1018
  try {
1019
- const o = !!e.dcuplInitOptions.performance?.clone?.enabled && !!t.cloneResult, a = B(i, o);
1020
- if (t.scope === "list" && (t.listKey = n.cdRef?.key || n.key, t.modelKey = n.model?.key || n.modelKey), t.type === "list_created" && t.args[0].listKey.startsWith("__global_list__") || t.listKey?.startsWith("__global_list__"))
1019
+ const o = !!e.dcuplInitOptions.performance?.clone?.enabled && !!t.cloneResult, a = B(n, o);
1020
+ if (t.scope === "list" && (t.listKey = i.cdRef?.key || i.key, t.modelKey = i.model?.key || i.modelKey), t.type === "list_created" && t.args[0].listKey.startsWith("__global_list__") || t.listKey?.startsWith("__global_list__"))
1021
1021
  return a;
1022
1022
  const c = b.now(), u = c - r, f = Math.round(u * 1e3) / 1e3;
1023
1023
  t.duration = f, t.start = r, t.end = c;
@@ -1035,12 +1035,12 @@ const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n)
1035
1035
  detail: d
1036
1036
  }), a;
1037
1037
  } catch {
1038
- return i;
1038
+ return n;
1039
1039
  }
1040
- }, Je = (n) => (t, r, s) => {
1041
- const i = s.value;
1040
+ }, Je = (i) => (t, r, s) => {
1041
+ const n = s.value;
1042
1042
  return s.value = function(...o) {
1043
- const a = b.now(), c = this.cdRef, u = B(n, !0);
1043
+ const a = b.now(), c = this.cdRef, u = B(i, !0);
1044
1044
  u.key || (c.increaseCounter(), u.key = c.getCounter());
1045
1045
  const f = ee();
1046
1046
  c.analyticsController.mark({
@@ -1049,32 +1049,32 @@ const B = (n, e) => e ? typeof structuredClone < "u" ? structuredClone(n) : v(n)
1049
1049
  });
1050
1050
  const d = this.model?.key;
1051
1051
  !u.originCdRefKey && c.key && (u.originCdRefKey = c.key), d && (u.modelKey = d);
1052
- const l = i.apply(this, o);
1053
- return u.method = r, u.args = o, l && typeof l == "object" && "then" in l ? l.then((h) => F(this, c, u, a, f, h)) : F(this, c, u, a, f, l);
1052
+ const l = n.apply(this, o);
1053
+ return u.method = r, u.args = o, l && typeof l == "object" && "then" in l ? l.then((h) => q(this, c, u, a, f, h)) : q(this, c, u, a, f, l);
1054
1054
  }, s;
1055
1055
  };
1056
- function Ze(n, e, t, r) {
1056
+ function Ze(i, e, t, r) {
1057
1057
  t.max || (t.max = 20);
1058
- const s = [], i = t.transform ? r.transformValue(t.value, t.transform) : t.value;
1058
+ const s = [], n = t.transform ? r.transformValue(t.value, t.transform) : t.value;
1059
1059
  for (const [o, a] of e.entries()) {
1060
- const c = Array.from(a).some((f) => n.has(f)), u = t.transform ? r.transformValue(o, t.transform) : o;
1060
+ const c = Array.from(a).some((f) => i.has(f)), u = t.transform ? r.transformValue(o, t.transform) : o;
1061
1061
  if (!(t.excludeUndefineds && typeof o > "u") && !(t.excludeNulls && o === null)) {
1062
- if (c && (i === "" || i === "//")) {
1062
+ if (c && (n === "" || n === "//")) {
1063
1063
  const f = {
1064
1064
  value: o,
1065
1065
  keys: t.calculateResultKeys ? Array.from(a) : []
1066
1066
  };
1067
1067
  s.push(f);
1068
- } else if (c && P(i)) {
1069
- if (r.queryFind(u, i, "some", t.regexFlags)) {
1068
+ } else if (c && j(n)) {
1069
+ if (r.queryFind(u, n, "some", t.regexFlags)) {
1070
1070
  const f = {
1071
1071
  value: o,
1072
1072
  keys: t.calculateResultKeys ? Array.from(a) : []
1073
1073
  };
1074
1074
  s.push(f);
1075
1075
  }
1076
- } else if (c && typeof i == "string") {
1077
- const f = String(u ?? ""), d = i;
1076
+ } else if (c && typeof n == "string") {
1077
+ const f = String(u ?? ""), d = n;
1078
1078
  if (f.toLowerCase().startsWith(d.toLowerCase())) {
1079
1079
  const l = {
1080
1080
  value: o,
@@ -1082,7 +1082,7 @@ function Ze(n, e, t, r) {
1082
1082
  };
1083
1083
  s.push(l);
1084
1084
  }
1085
- } else if (c && r.queryFind(u, i, "some")) {
1085
+ } else if (c && r.queryFind(u, n, "some")) {
1086
1086
  const f = {
1087
1087
  value: o,
1088
1088
  keys: t.calculateResultKeys ? Array.from(a) : []
@@ -1095,11 +1095,11 @@ function Ze(n, e, t, r) {
1095
1095
  }
1096
1096
  return s;
1097
1097
  }
1098
- function se(n) {
1099
- return n instanceof Date;
1098
+ function se(i) {
1099
+ return i instanceof Date;
1100
1100
  }
1101
- function ne(n) {
1102
- return n instanceof Date && !isNaN(n.getTime());
1101
+ function ne(i) {
1102
+ return i instanceof Date && !isNaN(i.getTime());
1103
1103
  }
1104
1104
  const ie = {
1105
1105
  yyyy: { type: "year", pattern: "yyyy", regex: "(\\d{4})" },
@@ -1116,19 +1116,19 @@ const ie = {
1116
1116
  s: { type: "second", pattern: "s", regex: "(\\d{1,2})" },
1117
1117
  SSS: { type: "millisecond", pattern: "SSS", regex: "(\\d{3})" }
1118
1118
  };
1119
- function oe(n) {
1119
+ function oe(i) {
1120
1120
  let e = "^";
1121
1121
  const t = [];
1122
- let r = n;
1123
- const s = Object.entries(ie).sort((i, o) => o[0].length - i[0].length);
1122
+ let r = i;
1123
+ const s = Object.entries(ie).sort((n, o) => o[0].length - n[0].length);
1124
1124
  for (; r.length > 0; ) {
1125
- let i = !1;
1125
+ let n = !1;
1126
1126
  for (const [o, a] of s)
1127
1127
  if (r.startsWith(o)) {
1128
- e += a.regex, t.push({ type: a.type, pattern: o }), r = r.slice(o.length), i = !0;
1128
+ e += a.regex, t.push({ type: a.type, pattern: o }), r = r.slice(o.length), n = !0;
1129
1129
  break;
1130
1130
  }
1131
- if (!i) {
1131
+ if (!n) {
1132
1132
  const o = r[0];
1133
1133
  if (!o)
1134
1134
  break;
@@ -1137,7 +1137,7 @@ function oe(n) {
1137
1137
  }
1138
1138
  return e += "$", { regex: new RegExp(e), tokenOrder: t };
1139
1139
  }
1140
- function ae(n, e) {
1140
+ function ae(i, e) {
1141
1141
  const t = {
1142
1142
  year: 1970,
1143
1143
  month: 1,
@@ -1148,51 +1148,51 @@ function ae(n, e) {
1148
1148
  millisecond: 0
1149
1149
  };
1150
1150
  for (let r = 0; r < e.length; r++) {
1151
- const s = n[r + 1];
1151
+ const s = i[r + 1];
1152
1152
  if (!s)
1153
1153
  continue;
1154
- const i = parseInt(s, 10), o = e[r];
1155
- o && (o.type === "year" && o.pattern === "yy" ? t.year = 2e3 + i : t[o.type] = i);
1154
+ const n = parseInt(s, 10), o = e[r];
1155
+ o && (o.type === "year" && o.pattern === "yy" ? t.year = 2e3 + n : t[o.type] = n);
1156
1156
  }
1157
1157
  return t;
1158
1158
  }
1159
- function ce(n) {
1160
- if (n.month < 1 || n.month > 12)
1159
+ function ce(i) {
1160
+ if (i.month < 1 || i.month > 12)
1161
1161
  return /* @__PURE__ */ new Date(NaN);
1162
- if (n.day < 1 || n.day > 31)
1162
+ if (i.day < 1 || i.day > 31)
1163
1163
  return /* @__PURE__ */ new Date(NaN);
1164
- if (n.hour < 0 || n.hour > 23)
1164
+ if (i.hour < 0 || i.hour > 23)
1165
1165
  return /* @__PURE__ */ new Date(NaN);
1166
- if (n.minute < 0 || n.minute > 59)
1166
+ if (i.minute < 0 || i.minute > 59)
1167
1167
  return /* @__PURE__ */ new Date(NaN);
1168
- if (n.second < 0 || n.second > 59)
1168
+ if (i.second < 0 || i.second > 59)
1169
1169
  return /* @__PURE__ */ new Date(NaN);
1170
- if (n.millisecond < 0 || n.millisecond > 999)
1170
+ if (i.millisecond < 0 || i.millisecond > 999)
1171
1171
  return /* @__PURE__ */ new Date(NaN);
1172
1172
  const e = new Date(
1173
- n.year,
1174
- n.month - 1,
1175
- n.day,
1176
- n.hour,
1177
- n.minute,
1178
- n.second,
1179
- n.millisecond
1173
+ i.year,
1174
+ i.month - 1,
1175
+ i.day,
1176
+ i.hour,
1177
+ i.minute,
1178
+ i.second,
1179
+ i.millisecond
1180
1180
  );
1181
- return ne(e) ? e.getFullYear() !== n.year || e.getMonth() !== n.month - 1 || e.getDate() !== n.day ? /* @__PURE__ */ new Date(NaN) : e : /* @__PURE__ */ new Date(NaN);
1181
+ return ne(e) ? e.getFullYear() !== i.year || e.getMonth() !== i.month - 1 || e.getDate() !== i.day ? /* @__PURE__ */ new Date(NaN) : e : /* @__PURE__ */ new Date(NaN);
1182
1182
  }
1183
- function Xe(n, e, t) {
1184
- if (n = n.trim(), e === "t") {
1185
- const a = Number(n);
1183
+ function Xe(i, e, t) {
1184
+ if (i = i.trim(), e === "t") {
1185
+ const a = Number(i);
1186
1186
  return isNaN(a) ? /* @__PURE__ */ new Date(NaN) : new Date(a * 1e3);
1187
1187
  }
1188
1188
  if (e === "T") {
1189
- const a = Number(n);
1189
+ const a = Number(i);
1190
1190
  return isNaN(a) ? /* @__PURE__ */ new Date(NaN) : new Date(a);
1191
1191
  }
1192
- const { regex: r, tokenOrder: s } = oe(e), i = n.match(r);
1193
- if (!i)
1192
+ const { regex: r, tokenOrder: s } = oe(e), n = i.match(r);
1193
+ if (!n)
1194
1194
  return /* @__PURE__ */ new Date(NaN);
1195
- const o = ae(i, s);
1195
+ const o = ae(n, s);
1196
1196
  return ce(o);
1197
1197
  }
1198
1198
  class ue {
@@ -1248,9 +1248,9 @@ class fe {
1248
1248
  }
1249
1249
  hasCycle(e) {
1250
1250
  if (e.length === 0) return !1;
1251
- const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = (i) => {
1252
- t.add(i), r.add(i);
1253
- const o = this.graph.get(i);
1251
+ const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = (n) => {
1252
+ t.add(n), r.add(n);
1253
+ const o = this.graph.get(n);
1254
1254
  if (o) {
1255
1255
  for (const a of o)
1256
1256
  if (t.has(a)) {
@@ -1259,14 +1259,14 @@ class fe {
1259
1259
  } else if (s(a))
1260
1260
  return !0;
1261
1261
  }
1262
- return r.delete(i), !1;
1262
+ return r.delete(n), !1;
1263
1263
  };
1264
- for (let i = 0; i < e.length - 1; i++) {
1265
- const o = e[i], a = e[i + 1];
1264
+ for (let n = 0; n < e.length - 1; n++) {
1265
+ const o = e[n], a = e[n + 1];
1266
1266
  o && a && this.addDependency(o, a);
1267
1267
  }
1268
- for (const i of e)
1269
- if (!t.has(i) && s(i))
1268
+ for (const n of e)
1269
+ if (!t.has(n) && s(n))
1270
1270
  return !0;
1271
1271
  return !1;
1272
1272
  }
@@ -1305,11 +1305,11 @@ class de {
1305
1305
  return this.cacheHits++, this.parseCache.get(e);
1306
1306
  this.cacheMisses++;
1307
1307
  let t, r;
1308
- const s = e.includes("."), i = e.includes("["), o = s || i;
1308
+ const s = e.includes("."), n = e.includes("["), o = s || n;
1309
1309
  if (o) {
1310
1310
  r = e.split(/[.[]/)[0];
1311
1311
  const c = e.indexOf("."), u = e.indexOf("[");
1312
- if (i && (c === -1 || u < c)) {
1312
+ if (n && (c === -1 || u < c)) {
1313
1313
  const d = e.indexOf("]");
1314
1314
  if (d > -1) {
1315
1315
  const l = e.indexOf(".", d + 1);
@@ -1372,8 +1372,8 @@ class de {
1372
1372
  if (!e || e.trim().length === 0)
1373
1373
  return r.push("Attribute path cannot be empty"), { valid: !1, errors: r };
1374
1374
  (e.startsWith(".") || e.endsWith(".")) && r.push(`Invalid path: Leading or trailing dots are not allowed: ${e}`), e.includes("..") && r.push(`Invalid path: Consecutive dots are not allowed: ${e}`);
1375
- const s = (e.match(/\[/g) || []).length, i = (e.match(/]/g) || []).length;
1376
- s !== i && r.push(`Invalid bracket notation: Mismatched brackets in ${e}`), e.includes("[]") && r.push(`Invalid bracket notation: Empty brackets not allowed: ${e}`);
1375
+ const s = (e.match(/\[/g) || []).length, n = (e.match(/]/g) || []).length;
1376
+ s !== n && r.push(`Invalid bracket notation: Mismatched brackets in ${e}`), e.includes("[]") && r.push(`Invalid bracket notation: Empty brackets not allowed: ${e}`);
1377
1377
  const o = /\[([^\]]+)\]/g;
1378
1378
  let a;
1379
1379
  for (; (a = o.exec(e)) !== null; ) {
@@ -1443,9 +1443,9 @@ class de {
1443
1443
  }
1444
1444
  }
1445
1445
  const m = new de();
1446
- function w(n, e) {
1446
+ function w(i, e) {
1447
1447
  if (e.includes("[*]")) {
1448
- const i = e.indexOf("[*]"), o = e.substring(0, i), a = e.substring(i + 3), c = o ? I(n, o) : n;
1448
+ const n = e.indexOf("[*]"), o = e.substring(0, n), a = e.substring(n + 3), c = o ? I(i, o) : i;
1449
1449
  if (!Array.isArray(c)) return [];
1450
1450
  const u = [];
1451
1451
  for (const f of c)
@@ -1453,80 +1453,80 @@ function w(n, e) {
1453
1453
  return u;
1454
1454
  }
1455
1455
  const t = e.split(".");
1456
- let r = [n];
1457
- for (const i of t) {
1456
+ let r = [i];
1457
+ for (const n of t) {
1458
1458
  const o = [];
1459
1459
  for (const a of r)
1460
1460
  if (a != null)
1461
1461
  if (Array.isArray(a))
1462
1462
  for (const c of a) {
1463
1463
  if (c == null) continue;
1464
- const u = c[i];
1464
+ const u = c[n];
1465
1465
  u !== void 0 && o.push(u);
1466
1466
  }
1467
1467
  else {
1468
- const c = a[i];
1468
+ const c = a[n];
1469
1469
  c !== void 0 && o.push(c);
1470
1470
  }
1471
1471
  if (r = o, r.length === 0) return [];
1472
1472
  }
1473
1473
  const s = [];
1474
- for (const i of r)
1475
- if (Array.isArray(i))
1476
- for (const o of i) o !== void 0 && s.push(o);
1477
- else i !== void 0 && s.push(i);
1474
+ for (const n of r)
1475
+ if (Array.isArray(n))
1476
+ for (const o of n) o !== void 0 && s.push(o);
1477
+ else n !== void 0 && s.push(n);
1478
1478
  return s;
1479
1479
  }
1480
- function M(n) {
1480
+ function Q(i) {
1481
1481
  let e = 0;
1482
- for (let t of n) {
1482
+ for (let t of i) {
1483
1483
  const r = t.toString().split(".")[1];
1484
1484
  r && (e = Math.max(e, r.length));
1485
1485
  }
1486
1486
  return Math.pow(10, e);
1487
1487
  }
1488
- function G(n, e, t) {
1489
- return (n * t + e * t) / t;
1488
+ function F(i, e, t) {
1489
+ return (i * t + e * t) / t;
1490
1490
  }
1491
- function le(n, e, t) {
1492
- return n * t / (e * t);
1491
+ function le(i, e, t) {
1492
+ return i * t / (e * t);
1493
1493
  }
1494
- const C = (n, e, t, r) => {
1494
+ const C = (i, e, t, r) => {
1495
1495
  if (!r)
1496
1496
  throw new Error("Attribute not found");
1497
1497
  const s = {
1498
1498
  attribute: r,
1499
- types: n.types
1499
+ types: i.types
1500
1500
  };
1501
- let i;
1502
- (s.types.includes("sum") || s.types.includes("avg")) && (i = ye(r, e));
1501
+ let n;
1502
+ (s.types.includes("sum") || s.types.includes("avg")) && (n = ye(r, e));
1503
1503
  let o;
1504
- return (s.types.includes("min") || s.types.includes("max")) && (o = pe(r, e)), n.types.forEach((a) => {
1505
- a === "sum" ? s.sum = i?.sum : a === "avg" ? s.avg = i?.average : a === "count" ? s.count = he(r, e) : a === "min" ? s.min = o && o[0] : a === "max" ? s.max = o && o[1] : a === "distinct" ? s.distinct = me(n, e, t) : a === "group" && (s.group = ge(n, e));
1504
+ return (s.types.includes("min") || s.types.includes("max")) && (o = pe(r, e)), i.types.forEach((a) => {
1505
+ a === "sum" ? s.sum = n?.sum : a === "avg" ? s.avg = n?.average : a === "count" ? s.count = he(r, e) : a === "min" ? s.min = o && o[0] : a === "max" ? s.max = o && o[1] : a === "distinct" ? s.distinct = me(i, e, t) : a === "group" && (s.group = ge(i, e));
1506
1506
  }), s;
1507
- }, he = (n, e) => {
1508
- const r = m.parse(n).isDeepQuery;
1507
+ }, he = (i, e) => {
1508
+ const r = m.parse(i).isDeepQuery;
1509
1509
  let s = 0;
1510
- for (const i of e.values())
1511
- if (i)
1510
+ for (const n of e.values())
1511
+ if (n)
1512
1512
  if (r)
1513
- s += w(i, n).filter((o) => o != null).length;
1513
+ s += w(n, i).filter((o) => o != null).length;
1514
1514
  else {
1515
- const o = i[n];
1515
+ const o = n[i];
1516
1516
  if (o == null) continue;
1517
1517
  Array.isArray(o) ? s += o.filter((a) => a != null).length : s++;
1518
1518
  }
1519
1519
  return s;
1520
- }, pe = (n, e) => {
1520
+ }, pe = (i, e) => {
1521
1521
  let t, r;
1522
- const i = m.parse(n).isDeepQuery;
1522
+ const n = m.parse(i).isDeepQuery;
1523
1523
  for (const o of e.values()) {
1524
1524
  if (!o) continue;
1525
1525
  let a;
1526
- if (i)
1527
- a = w(o, n);
1526
+ if (n)
1527
+ a = w(o, i);
1528
1528
  else {
1529
- const c = o[n];
1529
+ const c = o[i];
1530
1530
  c === void 0 ? a = [] : Array.isArray(c) ? a = c.filter((u) => u !== void 0) : a = [c];
1531
1531
  }
1532
1532
  for (const c of a)
@@ -1534,9 +1534,9 @@ const C = (n, e, t, r) => {
1534
1534
  }
1535
1535
  if (!(t === void 0 || r === void 0))
1536
1536
  return [t, r];
1537
- }, ge = (n, e) => {
1537
+ }, ge = (i, e) => {
1538
1538
  const t = [];
1539
- n.groupOptions?.groups?.forEach((o) => {
1539
+ i.groupOptions?.groups?.forEach((o) => {
1540
1540
  t.push({
1541
1541
  option: o,
1542
1542
  count: 0,
@@ -1547,49 +1547,49 @@ const C = (n, e, t, r) => {
1547
1547
  option: { value: ["$dcupl_not_found"] },
1548
1548
  count: 0,
1549
1549
  keys: []
1550
- }, i = m.parse(n.attribute).isDeepQuery;
1550
+ }, n = m.parse(i.attribute).isDeepQuery;
1551
1551
  for (const o of e.values()) {
1552
1552
  let a;
1553
- i ? a = w(o, n.attribute) : a = [o[n.attribute]];
1553
+ n ? a = w(o, i.attribute) : a = [o[i.attribute]];
1554
1554
  let c = !1;
1555
1555
  for (const u of a)
1556
1556
  for (const f of t)
1557
1557
  (typeof f.option.value < "u" && f.option.value.includes(u) || typeof f.option.from < "u" && f.option.from < u && typeof f.option.to < "u" && f.option.to > u) && (f.keys.includes(o.key) || (f.count++, f.keys.push(o.key)), c = !0);
1558
- !c && n?.groupOptions?.calculateNotFound && (r.count++, r.keys.push(o.key));
1558
+ !c && i?.groupOptions?.calculateNotFound && (r.count++, r.keys.push(o.key));
1559
1559
  }
1560
- return n?.groupOptions?.calculateNotFound && t.push(r), t;
1561
- }, ye = (n, e) => {
1560
+ return i?.groupOptions?.calculateNotFound && t.push(r), t;
1561
+ }, ye = (i, e) => {
1562
1562
  let t = 0, r = 0;
1563
- const i = m.parse(n).isDeepQuery;
1563
+ const n = m.parse(i).isDeepQuery;
1564
1564
  for (const a of e.values()) {
1565
1565
  if (!a) continue;
1566
1566
  let c;
1567
- if (i)
1568
- c = w(a, n);
1567
+ if (n)
1568
+ c = w(a, i);
1569
1569
  else {
1570
- const u = a[n];
1570
+ const u = a[i];
1571
1571
  u === void 0 ? c = [] : Array.isArray(u) ? c = u : c = [u];
1572
1572
  }
1573
1573
  for (const u of c)
1574
1574
  if (Array.isArray(u))
1575
1575
  for (const f of u)
1576
- typeof f == "number" && (t = G(t, f, M([t, f])), r++);
1577
- else typeof u == "number" && (t = G(t, u, M([t, u])), r++);
1576
+ typeof f == "number" && (t = F(t, f, Q([t, f])), r++);
1577
+ else typeof u == "number" && (t = F(t, u, Q([t, u])), r++);
1578
1578
  }
1579
1579
  return r === 0 ? void 0 : {
1580
- average: le(t, r, M([t, r])),
1580
+ average: le(t, r, Q([t, r])),
1581
1581
  count: r,
1582
1582
  sum: t
1583
1583
  };
1584
- }, me = (n, e, t) => {
1584
+ }, me = (i, e, t) => {
1585
1585
  const r = [];
1586
- for (const [s, i] of t)
1587
- if (!(n.excludeUndefineds && typeof s > "u") && Array.from(i).find((o) => e.has(o))) {
1586
+ for (const [s, n] of t)
1587
+ if (!(i.excludeUndefineds && typeof s > "u") && Array.from(n).find((o) => e.has(o))) {
1588
1588
  const o = {
1589
1589
  value: s,
1590
- count: i.size
1590
+ count: n.size
1591
1591
  };
1592
- if (n.distinctOptions?.skipKeys || (o.keys = Array.from(i)), r.push(o), n.distinctOptions?.limit && r.length >= n.distinctOptions.limit)
1592
+ if (i.distinctOptions?.skipKeys || (o.keys = Array.from(n)), r.push(o), i.distinctOptions?.limit && r.length >= i.distinctOptions.limit)
1593
1593
  break;
1594
1594
  }
1595
1595
  return r;
@@ -1655,6 +1655,57 @@ class L {
1655
1655
  getQueryGroup(e) {
1656
1656
  return this.currentQuery.queries.find((t) => this.isQueryGroup(t) && t.groupKey === e);
1657
1657
  }
1658
+ /**
1659
+ * Find the group with the given `groupKey` at any nesting depth (#294).
1660
+ *
1661
+ * Unlike {@link getQueryGroup}, which only looks at the top level, this also finds a
1662
+ * keyed group that sits inside a keyless wrapper group — the shape
1663
+ * `apply({ groupType: 'and', queries: [{ groupKey: 'plan', ... }] }, { mode: 'set' })`
1664
+ * produces. Groups on one level are checked before their children, so a top-level
1665
+ * match wins over a nested one; otherwise the first match in query order wins
1666
+ * (groupKeys are expected to be unique).
1667
+ *
1668
+ * @param groupKey - Key of the group to find
1669
+ * @param relevantQuery - Query to search (defaults to the current query)
1670
+ * @returns The matching group, or undefined
1671
+ */
1672
+ findQueryGroup(e, t) {
1673
+ const r = this.locateQueryGroup(e, (t ?? this.currentQuery).queries);
1674
+ return r ? this.groupAtPath(r) : void 0;
1675
+ }
1676
+ /**
1677
+ * Path from the root `queries` array down to a group: each step names the array that
1678
+ * holds a node and the node's index in it; the last step is the group itself.
1679
+ */
1680
+ locateQueryGroup(e, t) {
1681
+ const r = t.findIndex((s) => this.isQueryGroup(s) && s.groupKey === e);
1682
+ if (r > -1)
1683
+ return [{ queries: t, idx: r }];
1684
+ for (const [s, n] of t.entries())
1685
+ if (this.isQueryGroup(n)) {
1686
+ const o = this.locateQueryGroup(e, n.queries);
1687
+ if (o)
1688
+ return [{ queries: t, idx: s }, ...o];
1689
+ }
1690
+ }
1691
+ groupAtPath(e) {
1692
+ const t = e[e.length - 1];
1693
+ return t.queries[t.idx];
1694
+ }
1695
+ /**
1696
+ * Walk a path upwards from its last group and splice every group that has no
1697
+ * queries left, stopping at the first non-empty one. Mirrors the existing
1698
+ * "remove the group when its queries are empty" behaviour for nested wrappers, so
1699
+ * removing the only group inside a keyless wrapper also removes the wrapper.
1700
+ */
1701
+ pruneEmptyGroups(e) {
1702
+ for (let t = e.length - 1; t >= 0; t--) {
1703
+ const { queries: r, idx: s } = e[t];
1704
+ if (r[s].queries.length > 0)
1705
+ break;
1706
+ r.splice(s, 1);
1707
+ }
1708
+ }
1658
1709
  getQuery() {
1659
1710
  return v(this.currentQuery);
1660
1711
  }
@@ -1672,7 +1723,7 @@ class L {
1672
1723
  }
1673
1724
  validate(e) {
1674
1725
  const t = e.queries.map((s) => this.validateQuery(s));
1675
- return { valid: z(t, (s) => s.valid), errors: t.map((s) => s.errors).flat() };
1726
+ return { valid: _(t, (s) => s.valid), errors: t.map((s) => s.errors).flat() };
1676
1727
  }
1677
1728
  applyOptions(e, t = "update") {
1678
1729
  return t === "set" ? (this.currentQuery.count = e.count, this.currentQuery.start = e.start, this.currentQuery.sort = e.sort, this.currentQuery.projection = e.projection) : (typeof e?.sort < "u" && (this.currentQuery.sort = e.sort), typeof e?.count < "u" && (this.currentQuery.count = e.count), typeof e?.start < "u" && (this.currentQuery.start = e?.start), typeof e?.projection < "u" && (this.currentQuery.projection = e?.projection)), this.getQuery();
@@ -1692,8 +1743,20 @@ class L {
1692
1743
  * - {@link replaceQuery} - Replace complete query
1693
1744
  *
1694
1745
  * @param queryToApply - Query, condition, or array to apply
1695
- * @param options - Mode: 'add' (default) or 'set' (replace). In 'add' mode a group
1696
- * without `groupKey` is always appended as a new group, never merged into another.
1746
+ * @param options - Mode: 'add' (default) or 'set'. `set` works per group, not per query:
1747
+ * - Root group (`groupKey: 'root'`): replaces the whole query — all groups plus
1748
+ * `count`/`start`/`sort`/`projection` (the only input that does).
1749
+ * - Keyed group, or an array of groups: each group replaces the group with the same
1750
+ * `groupKey`; every other group is kept. Same as {@link setGroup}.
1751
+ * - Condition: replaces the conditions of the group keyed by its attribute.
1752
+ *
1753
+ * A group without `groupKey` is not the root, even if it carries a `queries` array:
1754
+ * `apply({ groupType: 'and', queries: [...] }, { mode: 'set' })` stores it as a keyless
1755
+ * wrapper group that replaces the first keyless top-level group, and the keyed groups
1756
+ * inside it stay nested there. {@link removeQuery} and `fn.facets` still find them by
1757
+ * `groupKey` at any depth (#294). To replace the whole query, pass `groupKey: 'root'`
1758
+ * or use {@link replaceQuery}. In 'add' mode a group without `groupKey` is always
1759
+ * appended as a new group, never merged into another.
1697
1760
  * @param relevantQuery - Target query (defaults to current)
1698
1761
  * @returns Updated query
1699
1762
  */
@@ -1705,11 +1768,11 @@ class L {
1705
1768
  e.groupType && (r.groupType = e.groupType), t?.mode === "set" ? r.queries = e.queries : r.queries = [...r.queries, ...e.queries], this.applyOptions(e, "set");
1706
1769
  else if (this.isQuery(e)) {
1707
1770
  const s = r.queries.findIndex(
1708
- (i) => this.isQueryGroup(i) && i.groupKey === e.attribute
1771
+ (n) => this.isQueryGroup(n) && n.groupKey === e.attribute
1709
1772
  );
1710
1773
  if (s > -1) {
1711
- const i = r.queries[s];
1712
- t?.mode === "set" ? i.queries = [e] : i.queries.push(e);
1774
+ const n = r.queries[s];
1775
+ t?.mode === "set" ? n.queries = [e] : n.queries.push(e);
1713
1776
  } else
1714
1777
  r.queries.push({
1715
1778
  groupKey: e.attribute,
@@ -1717,12 +1780,12 @@ class L {
1717
1780
  queries: [e]
1718
1781
  });
1719
1782
  } else if (this.isQueryGroup(e)) {
1720
- const i = e.groupKey === void 0 && t?.mode !== "set" ? -1 : r.queries.findIndex(
1783
+ const n = e.groupKey === void 0 && t?.mode !== "set" ? -1 : r.queries.findIndex(
1721
1784
  (o) => this.isQueryGroup(o) && o.groupKey === e.groupKey
1722
1785
  );
1723
- if (i > -1) {
1724
- const o = r.queries[i];
1725
- e.groupType && (o.groupType = e.groupType), t?.mode === "set" ? r.queries[i] = e : o.queries = [...o.queries, ...e.queries];
1786
+ if (n > -1) {
1787
+ const o = r.queries[n];
1788
+ e.groupType && (o.groupType = e.groupType), t?.mode === "set" ? r.queries[n] = e : o.queries = [...o.queries, ...e.queries];
1726
1789
  } else
1727
1790
  r.queries.push({
1728
1791
  groupKey: e.groupKey,
@@ -1745,33 +1808,39 @@ class L {
1745
1808
  /**
1746
1809
  * Remove a specific query or query group.
1747
1810
  *
1811
+ * - A condition (`attribute` set) is removed from the group keyed by its attribute.
1812
+ * - A group with `groupKey` but no `queries` is removed entirely.
1813
+ * - A group with `groupKey` and `queries` has those conditions removed from it.
1814
+ *
1815
+ * The target group is looked up by `groupKey` at any nesting depth (see
1816
+ * {@link findQueryGroup}), so a keyed group inside a keyless wrapper group is found
1817
+ * too (#294). A group left without queries is removed, and so is every wrapper
1818
+ * group that becomes empty as a result.
1819
+ *
1748
1820
  * @param queryToRemove - Query or group to remove (partial match)
1749
1821
  * @param relevantQuery - Target query (defaults to current)
1750
1822
  * @returns Updated query
1751
1823
  */
1752
1824
  removeQuery(e, t) {
1753
1825
  if (t || (t = this.currentQuery), this.isQuery(e)) {
1754
- const r = t.queries.findIndex(
1755
- (s) => this.isQueryGroup(s) && s.groupKey === e.attribute
1756
- );
1757
- if (r > -1) {
1758
- const s = t.queries[r], i = $(s.queries, e);
1759
- i > -1 && s.queries.splice(i, 1), s.queries.length === 0 && t.queries.splice(r, 1);
1826
+ const r = this.locateQueryGroup(e.attribute, t.queries);
1827
+ if (r) {
1828
+ const s = this.groupAtPath(r), n = $(s.queries, e);
1829
+ n > -1 && s.queries.splice(n, 1), this.pruneEmptyGroups(r);
1760
1830
  }
1761
1831
  } else if (this.isQueryGroup(e)) {
1762
- const r = t.queries.findIndex(
1763
- (s) => this.isQueryGroup(s) && s.groupKey === e.groupKey
1764
- );
1765
- if (r > -1)
1766
- if (!e.queries)
1767
- t.queries.splice(r, 1);
1768
- else {
1769
- const s = t.queries[r];
1770
- for (const i of e.queries) {
1771
- const o = $(s.queries, i);
1832
+ const r = this.locateQueryGroup(e.groupKey, t.queries);
1833
+ if (r)
1834
+ if (e.queries) {
1835
+ const s = this.groupAtPath(r);
1836
+ for (const n of e.queries) {
1837
+ const o = $(s.queries, n);
1772
1838
  o > -1 && s.queries.splice(o, 1);
1773
1839
  }
1774
- s.queries.length === 0 && t.queries.splice(r, 1);
1840
+ this.pruneEmptyGroups(r);
1841
+ } else {
1842
+ const s = r[r.length - 1];
1843
+ s.queries.splice(s.idx, 1), this.pruneEmptyGroups(r.slice(0, -1));
1775
1844
  }
1776
1845
  }
1777
1846
  return t;
@@ -1781,8 +1850,8 @@ class L {
1781
1850
  if (this.isQuery(e))
1782
1851
  return e.attribute || t.push(new x("Missing attribute", e)), e.operator || t.push(new x("Missing operator", e)), typeof e.value > "u" && t.push(new x("Missing value", e)), e.operator === "find" && Array.isArray(e.value) && t.push(new x("find operator cannot have array value", e)), e.operator === "in" && typeof e.value < "u" && !Array.isArray(e.value) && t.push(new x("in operator needs an array value", e)), t.length > 0 ? { valid: !1, errors: t } : { valid: !0 };
1783
1852
  if (this.isQueryGroup(e)) {
1784
- const i = e.queries.map((o) => this.validateQuery(o)).filter((o) => !o.valid).map((o) => o.errors).flat();
1785
- return i.length > 0 ? { valid: !1, errors: i } : { valid: !0 };
1853
+ const n = e.queries.map((o) => this.validateQuery(o)).filter((o) => !o.valid).map((o) => o.errors).flat();
1854
+ return n.length > 0 ? { valid: !1, errors: n } : { valid: !0 };
1786
1855
  }
1787
1856
  return t.push(new x("Invalid query definition", e)), { valid: !1, errors: t };
1788
1857
  }
@@ -1794,8 +1863,8 @@ class L {
1794
1863
  * @returns Array of attribute names
1795
1864
  */
1796
1865
  getQueryAttributes(e) {
1797
- const t = [], r = /* @__PURE__ */ new Set(), s = (i) => {
1798
- for (const o of i)
1866
+ const t = [], r = /* @__PURE__ */ new Set(), s = (n) => {
1867
+ for (const o of n)
1799
1868
  this.isQuery(o) ? o.attribute && !r.has(o.attribute) && (t.push(o.attribute), r.add(o.attribute)) : this.isQueryGroup(o) && s(o.queries);
1800
1869
  };
1801
1870
  return s(e?.queries || this.currentQuery.queries), t;
@@ -1808,8 +1877,8 @@ class L {
1808
1877
  * @returns Array of QueryAttributeEntry objects
1809
1878
  */
1810
1879
  extractQueryAttributes(e) {
1811
- const t = [], r = /* @__PURE__ */ new Set(), s = (i) => {
1812
- for (const o of i)
1880
+ const t = [], r = /* @__PURE__ */ new Set(), s = (n) => {
1881
+ for (const o of n)
1813
1882
  if (this.isQuery(o)) {
1814
1883
  if (o.attribute && !r.has(o.attribute)) {
1815
1884
  const a = this.getQueryAttributeForString(o.attribute);
@@ -1856,9 +1925,9 @@ class L {
1856
1925
  t[r.reference] || (t[r.reference] = { $: !0 });
1857
1926
  const s = this.deepQueryService.parse(r.referenceAttribute);
1858
1927
  if (s.isDeepQuery && r.reference) {
1859
- const i = this.getProjectionForAttributeEntries([s]);
1860
- Object.keys(i).forEach((o) => {
1861
- o !== "$" && r.reference && (t[r.reference][o] = i[o]);
1928
+ const n = this.getProjectionForAttributeEntries([s]);
1929
+ Object.keys(n).forEach((o) => {
1930
+ o !== "$" && r.reference && (t[r.reference][o] = n[o]);
1862
1931
  });
1863
1932
  } else r.reference && (t[r.reference][r.referenceAttribute] = !0);
1864
1933
  } else
@@ -1996,9 +2065,11 @@ class L {
1996
2065
  return this.applyQuery(e, { mode: "add" });
1997
2066
  }
1998
2067
  /**
1999
- * Replace query with new condition(s).
2068
+ * Replace the conditions of an attribute group with new condition(s).
2000
2069
  * Accepts single condition or array of conditions.
2001
- * Each condition replaces all existing conditions for its attribute.
2070
+ * Each condition replaces all existing conditions of the group keyed by its attribute
2071
+ * (created if missing); groups for other attributes and the query options are kept.
2072
+ * This does not replace the whole query — see {@link replaceQuery} for that.
2002
2073
  *
2003
2074
  * Clearer alternative to `applyQuery(condition, { mode: 'set' })`.
2004
2075
  *
@@ -2021,8 +2092,16 @@ class L {
2021
2092
  return this.applyQuery(e, { mode: "set" });
2022
2093
  }
2023
2094
  /**
2024
- * Replace a query group with new definition.
2025
- * If group exists, replaces it; otherwise creates new group.
2095
+ * Replace one query group by key (per-group `set`).
2096
+ * The group with the same `groupKey` is replaced by the given definition; if none exists
2097
+ * the group is appended. All other groups and the query options (`count`, `start`,
2098
+ * `sort`, `projection`) are kept. An unkeyed group replaces the first unkeyed top-level
2099
+ * group. Only a group with `groupKey: 'root'` replaces the whole query — equivalent to
2100
+ * `applyQuery(rootGroup, { mode: 'set' })` / {@link replaceQuery}.
2101
+ *
2102
+ * A group without `groupKey` whose `queries` hold keyed groups is stored as a keyless
2103
+ * wrapper; the keyed groups inside it stay nested and are still found by `groupKey`
2104
+ * via {@link findQueryGroup}, {@link removeQuery} and `fn.facets` (#294).
2026
2105
  *
2027
2106
  * @param group - Query group to set
2028
2107
  * @returns Updated query
@@ -2069,7 +2148,10 @@ class L {
2069
2148
  }
2070
2149
  /**
2071
2150
  * Replace the entire current query with a new query.
2072
- * Completely replaces all conditions, groups, and options.
2151
+ * Replaces all conditions and groups, and the root `groupType` when given. The query
2152
+ * options (`count`, `start`, `sort`, `projection`) are kept — use {@link applyOptions}
2153
+ * or `applyQuery({ groupKey: 'root', ... }, { mode: 'set' })` to replace those too.
2154
+ * To replace a single group by key, use {@link setGroup}.
2073
2155
  *
2074
2156
  * @param query - Complete query to replace with
2075
2157
  * @returns Updated query
@@ -2165,13 +2247,13 @@ class L {
2165
2247
  const t = (r) => {
2166
2248
  for (const s of r)
2167
2249
  if (this.isQuery(s)) {
2168
- let i = !0;
2250
+ let n = !0;
2169
2251
  for (const o in e)
2170
2252
  if (s[o] !== e[o]) {
2171
- i = !1;
2253
+ n = !1;
2172
2254
  break;
2173
2255
  }
2174
- if (i) return !0;
2256
+ if (n) return !0;
2175
2257
  } else if (this.isQueryGroup(s) && t(s.queries))
2176
2258
  return !0;
2177
2259
  return !1;
@@ -2292,9 +2374,9 @@ class L {
2292
2374
  return e(this.currentQuery.queries);
2293
2375
  }
2294
2376
  }
2295
- const E = new L();
2296
- function Ye(n, e, t, r, s, i, o) {
2297
- const a = t.excludeGroup ?? s, c = E.removeQuery({ groupKey: a }, v(r)), u = o.queryData(n, c, !1, i), f = e ? [...e.keys()] : [], d = new Set(f), l = i.get(s) ?? /* @__PURE__ */ new Map();
2377
+ const N = new L();
2378
+ function Ye(i, e, t, r, s, n, o) {
2379
+ const a = t.excludeGroup ?? s, c = N.removeQuery({ groupKey: a }, v(r)), u = o.queryData(i, c, !1, n), f = e ? [...e.keys()] : [], d = new Set(f), l = n.get(s) ?? /* @__PURE__ */ new Map();
2298
2380
  if (!t.excludeUnresolved)
2299
2381
  for (const p of l.keys())
2300
2382
  d.add(p);
@@ -2302,7 +2384,7 @@ function Ye(n, e, t, r, s, i, o) {
2302
2384
  const p = [];
2303
2385
  for (const K of d.values())
2304
2386
  p.push(
2305
- _(
2387
+ P(
2306
2388
  K,
2307
2389
  l,
2308
2390
  u,
@@ -2318,7 +2400,7 @@ function Ye(n, e, t, r, s, i, o) {
2318
2400
  }
2319
2401
  const h = [];
2320
2402
  for (const p of d.values()) {
2321
- const y = _(
2403
+ const y = P(
2322
2404
  p,
2323
2405
  l,
2324
2406
  u,
@@ -2336,36 +2418,36 @@ function Ye(n, e, t, r, s, i, o) {
2336
2418
  }
2337
2419
  return h;
2338
2420
  }
2339
- function _(n, e, t, r, s, i, o, a) {
2340
- const c = /* @__PURE__ */ new Map(), u = e.get(n) || /* @__PURE__ */ new Set();
2421
+ function P(i, e, t, r, s, n, o, a) {
2422
+ const c = /* @__PURE__ */ new Map(), u = e.get(i) || /* @__PURE__ */ new Set();
2341
2423
  for (const f of u) {
2342
2424
  const d = t.get(f);
2343
2425
  if (d && (c.set(f, d), !a))
2344
2426
  break;
2345
2427
  }
2346
2428
  return {
2347
- key: String(n),
2348
- value: n,
2349
- selected: we(i, s, n, o),
2429
+ key: String(i),
2430
+ value: i,
2431
+ selected: we(n, s, i, o),
2350
2432
  enabled: c.size > 0,
2351
2433
  size: c.size,
2352
- entry: r?.get(n),
2434
+ entry: r?.get(i),
2353
2435
  resultKeys: Array.from(c.keys())
2354
2436
  };
2355
2437
  }
2356
- function S(n, e) {
2357
- if (n === void 0 && e === void 0) return 0;
2358
- if (n === void 0) return 1;
2438
+ function S(i, e) {
2439
+ if (i === void 0 && e === void 0) return 0;
2440
+ if (i === void 0) return 1;
2359
2441
  if (e === void 0) return -1;
2360
- const t = typeof n, r = typeof e;
2442
+ const t = typeof i, r = typeof e;
2361
2443
  if (t !== r) return t < r ? -1 : 1;
2362
- if (t === "number") return n - e;
2363
- if (t === "string") return n.localeCompare(e);
2364
- const s = String(n), i = String(e);
2365
- return s < i ? -1 : s > i ? 1 : 0;
2444
+ if (t === "number") return i - e;
2445
+ if (t === "string") return i.localeCompare(e);
2446
+ const s = String(i), n = String(e);
2447
+ return s < n ? -1 : s > n ? 1 : 0;
2366
2448
  }
2367
- function ve(n) {
2368
- switch (n) {
2449
+ function ve(i) {
2450
+ switch (i) {
2369
2451
  case "size-desc":
2370
2452
  return (e, t) => t.size - e.size || S(e.value, t.value);
2371
2453
  case "size-asc":
@@ -2376,9 +2458,9 @@ function ve(n) {
2376
2458
  return (e, t) => e.value === void 0 && t.value === void 0 ? 0 : e.value === void 0 ? 1 : t.value === void 0 ? -1 : -S(e.value, t.value);
2377
2459
  }
2378
2460
  }
2379
- const we = (n, e, t, r) => {
2380
- const s = r.queries.findIndex((i) => E.isQueryGroup(i) && i.groupKey === n);
2381
- return s > -1 ? !!r.queries[s].queries.find((o) => E.isQuery(o) ? o.attribute !== e ? !1 : (o.operator === "in" && Array.isArray(o.value) ? o.value : [o.value]).some((c) => (c?.key || c) === t) : !1) : !1;
2461
+ const we = (i, e, t, r) => {
2462
+ const s = N.findQueryGroup(i, r);
2463
+ return s ? !!s.queries.find((n) => N.isQuery(n) ? n.attribute !== e ? !1 : (n.operator === "in" && Array.isArray(n.value) ? n.value : [n.value]).some((a) => (a?.key || a) === t) : !1) : !1;
2382
2464
  };
2383
2465
  class xe {
2384
2466
  indexMap = /* @__PURE__ */ new Map();
@@ -2403,31 +2485,31 @@ class xe {
2403
2485
  let r = this.dataMap.get(e);
2404
2486
  r || (r = /* @__PURE__ */ new Map(), this.dataMap.set(e, r));
2405
2487
  for (const s of t) {
2406
- let i;
2488
+ let n;
2407
2489
  if (typeof s == "object" && s && s.key)
2408
- i = s.key;
2490
+ n = s.key;
2409
2491
  else if (Array.isArray(s)) {
2410
2492
  for (const a of s)
2411
2493
  this.fillDataMap(e, [a]);
2412
2494
  return;
2413
- } else s instanceof Date ? i = s.toISOString() : i = s;
2414
- let o = r.get(i);
2415
- o || (o = { key: i }, this.dataMap.get(e)?.set(i, o));
2495
+ } else s instanceof Date ? n = s.toISOString() : n = s;
2496
+ let o = r.get(n);
2497
+ o || (o = { key: n }, this.dataMap.get(e)?.set(n, o));
2416
2498
  }
2417
2499
  }
2418
2500
  fillInverseIndex(e, t, r) {
2419
2501
  if (!e || !t || !r || !Array.isArray(r))
2420
2502
  return;
2421
2503
  const s = this.indexMap.get(e) || /* @__PURE__ */ new Map();
2422
- for (const i of r) {
2504
+ for (const n of r) {
2423
2505
  let o;
2424
- if (typeof i == "object" && i && i.key)
2425
- o = i.key;
2426
- else if (Array.isArray(i)) {
2427
- for (const c of i)
2506
+ if (typeof n == "object" && n && n.key)
2507
+ o = n.key;
2508
+ else if (Array.isArray(n)) {
2509
+ for (const c of n)
2428
2510
  this.fillInverseIndex(e, t, [c]);
2429
2511
  return;
2430
- } else i instanceof Date ? o = i.toISOString() : o = i;
2512
+ } else n instanceof Date ? o = n.toISOString() : o = n;
2431
2513
  let a = s.get(o);
2432
2514
  a || (a = /* @__PURE__ */ new Set(), s.set(o, a)), a.add(t);
2433
2515
  }
@@ -2443,11 +2525,11 @@ class xe {
2443
2525
  }
2444
2526
  getOrCreateIndex(e, t, r) {
2445
2527
  const s = this.getIndexName(e, r);
2446
- let i = this.getIndex(s);
2528
+ let n = this.getIndex(s);
2447
2529
  const o = this.indexMetadata.get(s);
2448
2530
  if (o)
2449
2531
  o.lastAccessedAt = Date.now();
2450
- else if (!i) {
2532
+ else if (!n) {
2451
2533
  const c = m.parse(e).isDeepQuery ?? !1;
2452
2534
  this.indexMetadata.set(s, {
2453
2535
  createdAt: Date.now(),
@@ -2456,16 +2538,16 @@ class xe {
2456
2538
  type: c ? "deep" : "shallow"
2457
2539
  });
2458
2540
  }
2459
- if (!i) {
2541
+ if (!n) {
2460
2542
  this.reset(s), this.indexMap.set(s, /* @__PURE__ */ new Map());
2461
2543
  const c = m.parse(e).isDeepQuery;
2462
2544
  for (const u of t.values()) {
2463
2545
  let f;
2464
2546
  c ? (f = w(u, e), f.length === 0 && (f = [void 0])) : f = [u[e]], this.fillInverseIndex(s, u.key, f), this.fillDataMap(s, f);
2465
2547
  }
2466
- i = this.getIndex(s) || /* @__PURE__ */ new Map();
2548
+ n = this.getIndex(s) || /* @__PURE__ */ new Map();
2467
2549
  }
2468
- return i;
2550
+ return n;
2469
2551
  }
2470
2552
  getIndexName(e, t) {
2471
2553
  return t ? e + "_" + D(t) : e;
@@ -2480,15 +2562,15 @@ class xe {
2480
2562
  removeFromInverseIndex(e, t, r) {
2481
2563
  const s = this.indexMap.get(e);
2482
2564
  if (s)
2483
- for (const i of r) {
2565
+ for (const n of r) {
2484
2566
  let o;
2485
- if (typeof i == "object" && i && i.key)
2486
- o = i.key;
2487
- else if (Array.isArray(i)) {
2488
- for (const c of i)
2567
+ if (typeof n == "object" && n && n.key)
2568
+ o = n.key;
2569
+ else if (Array.isArray(n)) {
2570
+ for (const c of n)
2489
2571
  this.removeFromInverseIndex(e, t, [c]);
2490
2572
  return;
2491
- } else i instanceof Date ? o = i.toISOString() : o = i;
2573
+ } else n instanceof Date ? o = n.toISOString() : o = n;
2492
2574
  const a = s.get(o);
2493
2575
  a && (a.delete(t), a.size === 0 && s.delete(o));
2494
2576
  }
@@ -2512,15 +2594,15 @@ class xe {
2512
2594
  const r = this.dataMap.get(e);
2513
2595
  if (r)
2514
2596
  for (const s of t) {
2515
- let i;
2597
+ let n;
2516
2598
  if (typeof s == "object" && s && s.key)
2517
- i = s.key;
2599
+ n = s.key;
2518
2600
  else if (Array.isArray(s)) {
2519
2601
  for (const o of s)
2520
2602
  this.removeFromDataMap(e, [o]);
2521
2603
  return;
2522
- } else s instanceof Date ? i = s.toISOString() : i = s;
2523
- r.delete(i);
2604
+ } else s instanceof Date ? n = s.toISOString() : n = s;
2605
+ r.delete(n);
2524
2606
  }
2525
2607
  }
2526
2608
  /**
@@ -2612,8 +2694,8 @@ class xe {
2612
2694
  cleanupStaleIndices(e = 300 * 1e3) {
2613
2695
  const t = Date.now();
2614
2696
  let r = 0;
2615
- for (const [s, i] of this.indexMetadata)
2616
- t - i.lastAccessedAt > e && (this.reset(s), r++);
2697
+ for (const [s, n] of this.indexMetadata)
2698
+ t - n.lastAccessedAt > e && (this.reset(s), r++);
2617
2699
  return r;
2618
2700
  }
2619
2701
  /**
@@ -2627,19 +2709,19 @@ class xe {
2627
2709
  const a = t - o.createdAt;
2628
2710
  r += a, a > s && (s = a);
2629
2711
  }
2630
- const i = this.indexMetadata.size > 0 ? r / this.indexMetadata.size : 0;
2712
+ const n = this.indexMetadata.size > 0 ? r / this.indexMetadata.size : 0;
2631
2713
  return {
2632
2714
  shallow: e.shallow,
2633
2715
  deep: e.deep,
2634
2716
  total: e.total,
2635
2717
  oldestAge: s,
2636
- avgAge: i
2718
+ avgAge: n
2637
2719
  };
2638
2720
  }
2639
2721
  }
2640
2722
  const A = "__";
2641
- function U(n, e, t = { key: "root" }, r = "root", s = new xe(), i) {
2642
- const o = i || n;
2723
+ function U(i, e, t = { key: "root" }, r = "root", s = new xe(), n) {
2724
+ const o = n || i;
2643
2725
  for (const a of e.columns)
2644
2726
  a.attribute && (m.parse(a.attribute), s.getOrCreateIndex(a.attribute, o));
2645
2727
  for (const a of e.rows)
@@ -2648,24 +2730,24 @@ function U(n, e, t = { key: "root" }, r = "root", s = new xe(), i) {
2648
2730
  a.attribute && (m.parse(a.attribute), s.getOrCreateIndex(a.attribute, o));
2649
2731
  if (e.rows && e.rows.length > 0) {
2650
2732
  t.rows = t.rows || [];
2651
- const a = Ae(n, e.rows[0], e, s, r, i);
2733
+ const a = Ae(i, e.rows[0], e, s, r, n);
2652
2734
  t.rows.push(a);
2653
2735
  }
2654
2736
  if (e.columns && e.columns.length > 0) {
2655
2737
  t.columns = t.columns || [];
2656
- const a = W(n, e.columns[0], e, s, r, i);
2738
+ const a = W(i, e.columns[0], e, s, r, n);
2657
2739
  t.columns.push(a);
2658
2740
  }
2659
2741
  if (t.key === "root")
2660
2742
  for (const a of e.values) {
2661
2743
  if (t.values = t.values || [], r === "root" && e.options?.calculateTotals === !1)
2662
2744
  continue;
2663
- const c = C(a, n, s.getIndex(a.attribute), a.attribute);
2745
+ const c = C(a, i, s.getIndex(a.attribute), a.attribute);
2664
2746
  t.values.push(c);
2665
2747
  }
2666
2748
  return t;
2667
2749
  }
2668
- function Ae(n, e, t, r, s = "", i) {
2750
+ function Ae(i, e, t, r, s = "", n) {
2669
2751
  const o = { key: e.attribute }, a = r.getIndex(e.attribute);
2670
2752
  if (!a)
2671
2753
  return o;
@@ -2675,7 +2757,7 @@ function Ae(n, e, t, r, s = "", i) {
2675
2757
  value: c
2676
2758
  }, d = /* @__PURE__ */ new Map();
2677
2759
  for (const l of u)
2678
- n.has(l) && d.set(l, n.get(l));
2760
+ i.has(l) && d.set(l, i.get(l));
2679
2761
  if (d.size) {
2680
2762
  for (const l of t.values) {
2681
2763
  if (f.values = f.values || [], s === "root" && e?.calculateTotals === !1)
@@ -2691,7 +2773,7 @@ function Ae(n, e, t, r, s = "", i) {
2691
2773
  f,
2692
2774
  s + A + e.attribute + A + c,
2693
2775
  r,
2694
- i
2776
+ n
2695
2777
  );
2696
2778
  } else if (t.columns)
2697
2779
  for (const l of t.columns) {
@@ -2702,7 +2784,7 @@ function Ae(n, e, t, r, s = "", i) {
2702
2784
  t,
2703
2785
  r,
2704
2786
  s + A + e.attribute + A + c,
2705
- i
2787
+ n
2706
2788
  );
2707
2789
  f.columns.push(h);
2708
2790
  }
@@ -2710,7 +2792,7 @@ function Ae(n, e, t, r, s = "", i) {
2710
2792
  }
2711
2793
  return o;
2712
2794
  }
2713
- function W(n, e, t, r, s = "", i) {
2795
+ function W(i, e, t, r, s = "", n) {
2714
2796
  const o = { key: e.attribute }, a = r.getIndex(e.attribute);
2715
2797
  if (!a)
2716
2798
  return o;
@@ -2720,7 +2802,7 @@ function W(n, e, t, r, s = "", i) {
2720
2802
  value: c
2721
2803
  }, d = /* @__PURE__ */ new Map();
2722
2804
  for (const l of u)
2723
- n.has(l) && d.set(l, n.get(l));
2805
+ i.has(l) && d.set(l, i.get(l));
2724
2806
  if (d.size) {
2725
2807
  for (const l of t.values) {
2726
2808
  if (f.values = f.values || [], s === "root" && e?.calculateTotals === !1)
@@ -2736,24 +2818,24 @@ function W(n, e, t, r, s = "", i) {
2736
2818
  f,
2737
2819
  s + A + e.attribute + A + c,
2738
2820
  r,
2739
- i
2821
+ n
2740
2822
  );
2741
2823
  }
2742
2824
  }
2743
2825
  }
2744
2826
  return o;
2745
2827
  }
2746
- const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/, Se = /^-?\d+$/, Ie = /^-?\d+\.\d+$/, De = /^\d{1,2}([/.-])\d{1,2}\1\d{2,4}$/, Ke = (n) => n === "true" || n === "false" ? "boolean" : Se.test(n) ? "int" : Ie.test(n) ? "float" : be.test(n) && !Number.isNaN(Date.parse(n)) ? "date" : "string", ke = (n) => De.test(n), Me = (n) => n == null || n === "", Qe = (n) => {
2747
- const e = [...n];
2828
+ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/, Se = /^-?\d+$/, Ie = /^-?\d+\.\d+$/, De = /^\d{1,2}([/.-])\d{1,2}\1\d{2,4}$/, Ke = (i) => i === "true" || i === "false" ? "boolean" : Se.test(i) ? "int" : Ie.test(i) ? "float" : be.test(i) && !Number.isNaN(Date.parse(i)) ? "date" : "string", ke = (i) => De.test(i), Qe = (i) => i == null || i === "", Me = (i) => {
2829
+ const e = [...i];
2748
2830
  return e.length <= 1 ? { type: e[0] ?? "any", conflict: !1 } : e.every((t) => t === "int" || t === "float") ? { type: "float", conflict: !1 } : { type: "any", conflict: !0 };
2749
- }, Ne = (n, e = {}) => {
2750
- const r = e.deep ?? (e.sampleSize !== void 0 && e.sampleSize > 1) ? e.sampleSize ?? 1 / 0 : 1, s = e.coerceStrings ?? !0, i = /* @__PURE__ */ new Map(), o = [], a = Math.min(n.length, r);
2831
+ }, Ee = (i, e = {}) => {
2832
+ const r = e.deep ?? (e.sampleSize !== void 0 && e.sampleSize > 1) ? e.sampleSize ?? 1 / 0 : 1, s = e.coerceStrings ?? !0, n = /* @__PURE__ */ new Map(), o = [], a = Math.min(i.length, r);
2751
2833
  for (let f = 0; f < a; f++) {
2752
- const d = n[f];
2834
+ const d = i[f];
2753
2835
  if (d)
2754
2836
  for (const [l, h] of Object.entries(d)) {
2755
- let p = i.get(l);
2756
- if (p || (p = { observed: /* @__PURE__ */ new Set(), empty: 0, scanned: 0 }, i.set(l, p), o.push(l)), p.scanned++, Me(h)) {
2837
+ let p = n.get(l);
2838
+ if (p || (p = { observed: /* @__PURE__ */ new Set(), empty: 0, scanned: 0 }, n.set(l, p), o.push(l)), p.scanned++, Qe(h)) {
2757
2839
  p.empty++;
2758
2840
  continue;
2759
2841
  }
@@ -2763,7 +2845,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2763
2845
  }
2764
2846
  const c = [], u = [];
2765
2847
  for (const f of o) {
2766
- const d = i.get(f), { type: l, conflict: h } = Qe(d.observed.size ? d.observed : /* @__PURE__ */ new Set(["string"]));
2848
+ const d = n.get(f), { type: l, conflict: h } = Me(d.observed.size ? d.observed : /* @__PURE__ */ new Set(["string"]));
2767
2849
  c.push({ key: f, type: l }), u.push({
2768
2850
  column: f,
2769
2851
  inferredType: l,
@@ -2774,28 +2856,28 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2774
2856
  });
2775
2857
  }
2776
2858
  return { properties: c, diagnostics: u };
2777
- }, et = (n, e = !1) => Ne(n, typeof e == "boolean" ? { deep: e } : e).properties, Ee = (n) => Number(n) === n && n % 1 === 0, Ce = (n) => Number(n) === n && n % 1 !== 0, $e = (n) => {
2778
- switch (typeof n) {
2859
+ }, et = (i, e = !1) => Ee(i, typeof e == "boolean" ? { deep: e } : e).properties, Ne = (i) => Number(i) === i && i % 1 === 0, Ce = (i) => Number(i) === i && i % 1 !== 0, $e = (i) => {
2860
+ switch (typeof i) {
2779
2861
  case "string":
2780
2862
  return "string";
2781
2863
  case "number":
2782
- return Ee(n) ? "int" : Ce(n) ? "float" : "any";
2864
+ return Ne(i) ? "int" : Ce(i) ? "float" : "any";
2783
2865
  case "boolean":
2784
2866
  return "boolean";
2785
2867
  case "object":
2786
- return se(n) ? "date" : "json";
2868
+ return se(i) ? "date" : "json";
2787
2869
  default:
2788
2870
  return "any";
2789
2871
  }
2790
- }, tt = (n, e) => {
2791
- const t = te(n.text || ""), r = e?.attributeKey || n.filterKey;
2872
+ }, tt = (i, e) => {
2873
+ const t = te(i.text || ""), r = e?.attributeKey || i.filterKey;
2792
2874
  let s;
2793
- const i = e?.comparisonType || "containsIgnoreCase";
2794
- return i === "containsIgnoreCase" ? s = {
2795
- groupKey: n.filterKey,
2875
+ const n = e?.comparisonType || "containsIgnoreCase";
2876
+ return n === "containsIgnoreCase" ? s = {
2877
+ groupKey: i.filterKey,
2796
2878
  queries: [
2797
2879
  {
2798
- queryKey: n.text,
2880
+ queryKey: i.text,
2799
2881
  attribute: r,
2800
2882
  value: `/${t}/`,
2801
2883
  operator: "find",
@@ -2804,11 +2886,11 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2804
2886
  }
2805
2887
  }
2806
2888
  ]
2807
- } : i === "containsIgnoreCaseAndWhitespace" ? s = {
2808
- groupKey: n.filterKey,
2889
+ } : n === "containsIgnoreCaseAndWhitespace" ? s = {
2890
+ groupKey: i.filterKey,
2809
2891
  queries: [
2810
2892
  {
2811
- queryKey: n.text,
2893
+ queryKey: i.text,
2812
2894
  attribute: r,
2813
2895
  value: `/${t}/`,
2814
2896
  operator: "find",
@@ -2817,33 +2899,33 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2817
2899
  }
2818
2900
  }
2819
2901
  ]
2820
- } : i === "contains" ? s = {
2821
- groupKey: n.filterKey,
2902
+ } : n === "contains" ? s = {
2903
+ groupKey: i.filterKey,
2822
2904
  queries: [
2823
2905
  {
2824
- queryKey: n.text,
2906
+ queryKey: i.text,
2825
2907
  attribute: r,
2826
2908
  value: `/${t}/`,
2827
2909
  operator: "find"
2828
2910
  }
2829
2911
  ]
2830
- } : i === "equal" ? s = {
2831
- groupKey: n.filterKey,
2912
+ } : n === "equal" ? s = {
2913
+ groupKey: i.filterKey,
2832
2914
  queries: [
2833
2915
  {
2834
- queryKey: n.text,
2916
+ queryKey: i.text,
2835
2917
  attribute: r,
2836
- value: n.text,
2918
+ value: i.text,
2837
2919
  operator: "eq"
2838
2920
  }
2839
2921
  ]
2840
- } : i === "equalIgnoreCase" && (s = {
2841
- groupKey: n.filterKey,
2922
+ } : n === "equalIgnoreCase" && (s = {
2923
+ groupKey: i.filterKey,
2842
2924
  queries: [
2843
2925
  {
2844
- queryKey: n.text,
2926
+ queryKey: i.text,
2845
2927
  attribute: r,
2846
- value: n.text,
2928
+ value: i.text,
2847
2929
  operator: "eq",
2848
2930
  options: {
2849
2931
  transform: ["lowercase"]
@@ -2851,40 +2933,40 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2851
2933
  }
2852
2934
  ]
2853
2935
  }), s;
2854
- }, rt = (n, e) => {
2855
- const t = e?.attributeKey || n.filterKey;
2936
+ }, rt = (i, e) => {
2937
+ const t = e?.attributeKey || i.filterKey;
2856
2938
  return {
2857
- groupKey: n.filterKey,
2939
+ groupKey: i.filterKey,
2858
2940
  queries: [
2859
2941
  {
2860
- queryKey: n.value,
2942
+ queryKey: i.value,
2861
2943
  attribute: t,
2862
- value: n.value,
2944
+ value: i.value,
2863
2945
  operator: "eq"
2864
2946
  }
2865
2947
  ]
2866
2948
  };
2867
- }, st = (n, e) => {
2868
- const t = e?.attributeKey || n.filterKey, r = {
2869
- groupKey: n.filterKey,
2949
+ }, st = (i, e) => {
2950
+ const t = e?.attributeKey || i.filterKey, r = {
2951
+ groupKey: i.filterKey,
2870
2952
  queries: []
2871
2953
  };
2872
- return typeof n.eq < "u" && (r.groupType = "or", Array.isArray(n.eq) ? n.eq.forEach((s) => {
2954
+ return typeof i.eq < "u" && (r.groupType = "or", Array.isArray(i.eq) ? i.eq.forEach((s) => {
2873
2955
  r.queries.push({ attribute: t, value: s, operator: "eq" });
2874
- }) : r.queries.push({ attribute: t, value: n.eq, operator: "eq" })), typeof n.ne < "u" && (r.groupType = "and", Array.isArray(n.ne) ? n.ne.forEach((s) => {
2956
+ }) : r.queries.push({ attribute: t, value: i.eq, operator: "eq" })), typeof i.ne < "u" && (r.groupType = "and", Array.isArray(i.ne) ? i.ne.forEach((s) => {
2875
2957
  r.queries.push({ attribute: t, value: s, operator: "eq", options: { invert: !0 } });
2876
2958
  }) : r.queries.push({
2877
2959
  attribute: t,
2878
- value: n.ne,
2960
+ value: i.ne,
2879
2961
  operator: "eq",
2880
2962
  options: { invert: !0 }
2881
- })), typeof n.gt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: n.gt, operator: "gt" })), typeof n.lt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: n.lt, operator: "lt" })), typeof n.gte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: n.gte, operator: "gte" })), typeof n.lte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: n.lte, operator: "lte" })), r;
2882
- }, nt = (n, e) => {
2883
- const t = e?.attributeKey || n.filterKey, r = {
2884
- groupKey: n.filterKey,
2963
+ })), typeof i.gt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.gt, operator: "gt" })), typeof i.lt < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.lt, operator: "lt" })), typeof i.gte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.gte, operator: "gte" })), typeof i.lte < "u" && (r.groupType = "and", r.queries.push({ attribute: t, value: i.lte, operator: "lte" })), r;
2964
+ }, nt = (i, e) => {
2965
+ const t = e?.attributeKey || i.filterKey, r = {
2966
+ groupKey: i.filterKey,
2885
2967
  queries: []
2886
2968
  };
2887
- return n.itemKeys.forEach((s) => {
2969
+ return i.itemKeys.forEach((s) => {
2888
2970
  r.queries.push({
2889
2971
  queryKey: s,
2890
2972
  attribute: t,
@@ -2892,7 +2974,7 @@ const be = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?
2892
2974
  operator: "eq"
2893
2975
  });
2894
2976
  }), r;
2895
- }, it = (n) => !(typeof n.modelKey != "string" || !Array.isArray(n.queries));
2977
+ }, it = (i) => !(typeof i.modelKey != "string" || !Array.isArray(i.queries));
2896
2978
  class ot {
2897
2979
  constructor(e, t, r) {
2898
2980
  this.scriptController = e, this.globalItemService = t, this.modelParser = r;
@@ -2918,19 +3000,19 @@ class ot {
2918
3000
  let r = e.value;
2919
3001
  const s = e.options?.arrayValueHandling || "some";
2920
3002
  Array.isArray(e.options?.transform) && e.options.transform.length > 0 && (r = this.transformValue(r, e.options.transform));
2921
- let i = this.getAttributeValue(t, e.attribute);
2922
- if (Array.isArray(e.options?.transform) && e.options.transform.length > 0 && (i = this.transformValue(i, e.options.transform)), (typeof i > "u" || i === null) && !["typeof", "isTruthy", "eq", "in"].includes(e.operator))
3003
+ let n = this.getAttributeValue(t, e.attribute);
3004
+ if (Array.isArray(e.options?.transform) && e.options.transform.length > 0 && (n = this.transformValue(n, e.options.transform)), (typeof n > "u" || n === null) && !["typeof", "isTruthy", "eq", "in"].includes(e.operator))
2923
3005
  return !1;
2924
3006
  let o;
2925
3007
  switch (e.operator) {
2926
3008
  case "eq":
2927
- o = this.queryEq(i, r, s);
3009
+ o = this.queryEq(n, r, s);
2928
3010
  break;
2929
3011
  case "in":
2930
- o = this.queryIn(i, r, s);
3012
+ o = this.queryIn(n, r, s);
2931
3013
  break;
2932
3014
  case "find":
2933
- o = this.queryFind(i, r, s, e.options?.regexFlags);
3015
+ o = this.queryFind(n, r, s, e.options?.regexFlags);
2934
3016
  break;
2935
3017
  case "lt":
2936
3018
  case "gt":
@@ -2938,22 +3020,22 @@ class ot {
2938
3020
  case "gte": {
2939
3021
  const a = e.operator;
2940
3022
  o = this.matchValues(
2941
- i,
3023
+ n,
2942
3024
  s,
2943
3025
  (c) => this.compareValue(a, c, r)
2944
3026
  );
2945
3027
  break;
2946
3028
  }
2947
3029
  case "typeof":
2948
- o = this.matchValues(i, s, (a) => typeof a === r);
3030
+ o = this.matchValues(n, s, (a) => typeof a === r);
2949
3031
  break;
2950
3032
  case "isTruthy": {
2951
3033
  const a = r === !0;
2952
- o = this.matchValues(i, s, (c) => !!c === a);
3034
+ o = this.matchValues(n, s, (c) => !!c === a);
2953
3035
  break;
2954
3036
  }
2955
3037
  case "size":
2956
- typeof i == "string" ? o = i.length === r : o = V(i) === r;
3038
+ typeof n == "string" ? o = n.length === r : o = V(n) === r;
2957
3039
  break;
2958
3040
  default:
2959
3041
  if (this.scriptController.hasScript(e.operator))
@@ -2996,12 +3078,12 @@ class ot {
2996
3078
  return I(e, t);
2997
3079
  const r = t.split(".");
2998
3080
  let s = e;
2999
- for (let i = 0; i < r.length; i++) {
3000
- const o = r[i];
3081
+ for (let n = 0; n < r.length; n++) {
3082
+ const o = r[n];
3001
3083
  if (s == null)
3002
3084
  return;
3003
3085
  if (Array.isArray(s) && o !== "length" && !/^\d+$/.test(o))
3004
- return w(s, r.slice(i).join("."));
3086
+ return w(s, r.slice(n).join("."));
3005
3087
  s = s[o];
3006
3088
  }
3007
3089
  return s;
@@ -3029,7 +3111,7 @@ class ot {
3029
3111
  return !Array.isArray(t) || t.length === 0 ? !1 : this.matchValues(
3030
3112
  e,
3031
3113
  r,
3032
- (s) => t.some((i) => this.equalsQueryValue(s, i))
3114
+ (s) => t.some((n) => this.equalsQueryValue(s, n))
3033
3115
  );
3034
3116
  }
3035
3117
  /**
@@ -3058,21 +3140,21 @@ class ot {
3058
3140
  return e.options?.arrayValueHandling !== "every" && !e.options?.transform?.length;
3059
3141
  }
3060
3142
  evaluateEqOperator(e, t, r, s) {
3061
- const i = /* @__PURE__ */ new Map(), o = this.canUseIndex(t) ? s.get(t.attribute) : void 0;
3143
+ const n = /* @__PURE__ */ new Map(), o = this.canUseIndex(t) ? s.get(t.attribute) : void 0;
3062
3144
  if (o) {
3063
3145
  const a = this.getIndexKey(t.value);
3064
3146
  if (typeof a < "u") {
3065
3147
  const c = o.get(a);
3066
3148
  if (c)
3067
3149
  if (c.forEach((u) => {
3068
- r.has(u) && i.set(u, r.get(u));
3150
+ r.has(u) && n.set(u, r.get(u));
3069
3151
  }), t.options?.invert) {
3070
- const u = O(Array.from(r.values()), Array.from(i.values()), "key"), f = /* @__PURE__ */ new Map();
3152
+ const u = O(Array.from(r.values()), Array.from(n.values()), "key"), f = /* @__PURE__ */ new Map();
3071
3153
  return u.forEach((d) => {
3072
3154
  f.set(d.key, d);
3073
3155
  }), f;
3074
3156
  } else
3075
- return i;
3157
+ return n;
3076
3158
  }
3077
3159
  }
3078
3160
  return this.scanDataset(e, t, r);
@@ -3084,12 +3166,12 @@ class ot {
3084
3166
  * the result equals the scan's.
3085
3167
  */
3086
3168
  evaluateInOperator(e, t, r, s) {
3087
- const i = this.canUseIndex(t) ? s.get(t.attribute) : void 0;
3088
- if (!i)
3169
+ const n = this.canUseIndex(t) ? s.get(t.attribute) : void 0;
3170
+ if (!n)
3089
3171
  return this.scanDataset(e, t, r);
3090
3172
  const o = /* @__PURE__ */ new Map(), a = [];
3091
3173
  for (const u of t.value) {
3092
- const f = this.getIndexKey(u), d = typeof f < "u" ? i.get(f) : void 0;
3174
+ const f = this.getIndexKey(u), d = typeof f < "u" ? n.get(f) : void 0;
3093
3175
  if (!d) {
3094
3176
  a.push(u);
3095
3177
  continue;
@@ -3120,7 +3202,7 @@ class ot {
3120
3202
  }
3121
3203
  /** Evaluates `query` on each item, resolving a deep path's references first. */
3122
3204
  scanDataset(e, t, r) {
3123
- const s = /* @__PURE__ */ new Map(), i = this.queryBuilder.extractQueryAttributes({ queries: [t] }).filter((a) => a.isDeepQuery), o = i.length > 0 ? this.queryBuilder.getProjectionForAttributeEntries(i) : void 0;
3205
+ const s = /* @__PURE__ */ new Map(), n = this.queryBuilder.extractQueryAttributes({ queries: [t] }).filter((a) => a.isDeepQuery), o = n.length > 0 ? this.queryBuilder.getProjectionForAttributeEntries(n) : void 0;
3124
3206
  for (let [a, c] of r)
3125
3207
  o && (c = this.globalItemService.getProjectedData(
3126
3208
  o,
@@ -3130,7 +3212,7 @@ class ot {
3130
3212
  return s;
3131
3213
  }
3132
3214
  equalRegexFn(e, t, r) {
3133
- const s = P(t, r);
3215
+ const s = j(t, r);
3134
3216
  if (s)
3135
3217
  try {
3136
3218
  return new RegExp(s.pattern, s.flags).test(e);
@@ -3138,12 +3220,12 @@ class ot {
3138
3220
  return !1;
3139
3221
  }
3140
3222
  else return Array.isArray(e) ? !!e.find(
3141
- (i) => k(i, t, (o, a) => this.equalRegexFn(o, a, r))
3142
- ) : typeof t == "object" ? q(e, t) : e === t;
3223
+ (n) => k(n, t, (o, a) => this.equalRegexFn(o, a, r))
3224
+ ) : typeof t == "object" ? G(e, t) : e === t;
3143
3225
  }
3144
3226
  queryFind(e, t, r, s) {
3145
- const i = (o, a) => this.equalRegexFn(o, a, s);
3146
- return Array.isArray(e) ? typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? this.matchValues(e, r, (o) => k(o, t, i)) : t !== null && typeof t == "object" ? this.matchValues(e, r, (o) => q(o, t)) : !!J(e, t) : k(e, t, i);
3227
+ const n = (o, a) => this.equalRegexFn(o, a, s);
3228
+ return Array.isArray(e) ? typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? this.matchValues(e, r, (o) => k(o, t, n)) : t !== null && typeof t == "object" ? this.matchValues(e, r, (o) => G(o, t)) : !!J(e, t) : k(e, t, n);
3147
3229
  }
3148
3230
  validateQuery(e) {
3149
3231
  if (this.queryBuilder.isQuery(e)) {
@@ -3156,12 +3238,12 @@ class ot {
3156
3238
  return !0;
3157
3239
  } else {
3158
3240
  if (this.queryBuilder.isQueryGroup(e))
3159
- return z(e.queries, (t) => this.validateQuery(t));
3241
+ return _(e.queries, (t) => this.validateQuery(t));
3160
3242
  throw new Error("invalid query - missing query or attribute");
3161
3243
  }
3162
3244
  }
3163
3245
  getEvaluatedQueryDataset(e, t, r, s) {
3164
- const i = /* @__PURE__ */ new Map();
3246
+ const n = /* @__PURE__ */ new Map();
3165
3247
  if (t.attribute.includes("[*]")) {
3166
3248
  const o = t.options?.invert === !0, a = /* @__PURE__ */ new Set();
3167
3249
  for (let c of r.values()) {
@@ -3184,13 +3266,13 @@ class ot {
3184
3266
  d,
3185
3267
  t.options?.arrayValueHandling || "some",
3186
3268
  (h) => this.evaluateQuery(h, c)
3187
- ) && (a.add(c.key), o || i.set(c.key, c));
3269
+ ) && (a.add(c.key), o || n.set(c.key, c));
3188
3270
  }
3189
3271
  if (o)
3190
3272
  for (const [c, u] of r)
3191
- a.has(c) || i.set(c, u);
3273
+ a.has(c) || n.set(c, u);
3192
3274
  } else return t.operator === "eq" ? this.evaluateEqOperator(e, t, r, s) : t.operator === "in" ? this.evaluateInOperator(e, t, r, s) : this.scanDataset(e, t, r);
3193
- return i;
3275
+ return n;
3194
3276
  }
3195
3277
  handleArrayStarQuery(e, t) {
3196
3278
  const r = e.attribute.indexOf("[*]"), s = {
@@ -3199,7 +3281,7 @@ class ot {
3199
3281
  queries: []
3200
3282
  };
3201
3283
  if (r !== -1) {
3202
- const i = e.attribute.substring(0, r), o = i.includes(".") ? I(t, i) : t[i];
3284
+ const n = e.attribute.substring(0, r), o = n.includes(".") ? I(t, n) : t[n];
3203
3285
  if (Array.isArray(o))
3204
3286
  for (let a = 0; a < o.length; a++) {
3205
3287
  const c = e.attribute.replace("[*]", `[${a}]`);
@@ -3213,30 +3295,31 @@ class ot {
3213
3295
  }
3214
3296
  return s;
3215
3297
  }
3216
- evaluateQueryGroup(e, t, r, s, i) {
3298
+ evaluateQueryGroup(e, t, r, s, n) {
3217
3299
  let o = /* @__PURE__ */ new Map(), a = r;
3218
3300
  if (!t.queries || t.queries?.length === 0)
3219
3301
  return a;
3220
- for (const c of t.queries) {
3221
- let u = /* @__PURE__ */ new Map();
3222
- if (this.queryBuilder.isQuery(c) ? u = this.getEvaluatedQueryDataset(e, c, a, i) : u = this.evaluateQueryGroup(e, c, a, s, i), o.size === 0 && (o = u), t.groupType === "or")
3223
- u.forEach((f) => {
3224
- o.set(f.key, f);
3225
- });
3302
+ const c = t.groupType === "or";
3303
+ for (const u of t.queries) {
3304
+ let f = /* @__PURE__ */ new Map();
3305
+ if (this.queryBuilder.isQuery(u) ? f = this.getEvaluatedQueryDataset(e, u, a, n) : f = this.evaluateQueryGroup(e, u, a, s, n), o.size === 0 && (o = f), c)
3306
+ f.forEach((d) => {
3307
+ o.set(d.key, d);
3308
+ }), a = r;
3226
3309
  else {
3227
- const f = O(Array.from(o.values()), Array.from(u.values()), "key");
3228
- for (const d of f)
3229
- o.delete(d.key);
3310
+ const d = O(Array.from(o.values()), Array.from(f.values()), "key");
3311
+ for (const l of d)
3312
+ o.delete(l.key);
3313
+ a = o;
3230
3314
  }
3231
- t.groupType === "and" ? a = o : a = r;
3232
3315
  }
3233
3316
  return o;
3234
3317
  }
3235
3318
  queryData(e, t, r, s) {
3236
3319
  if (t.queries.length === 0)
3237
3320
  return e;
3238
- const i = new Map(e);
3239
- return t.groupKey || (t.groupKey = "root"), t.groupType || (t.groupType = "and"), t.queries || (t.queries = []), this.validateQuery(t), this.evaluateQueryGroup(t, t, i, r, s);
3321
+ const n = new Map(e);
3322
+ return t.groupKey || (t.groupKey = "root"), t.groupType || (t.groupType = "and"), t.queries || (t.queries = []), this.validateQuery(t), this.evaluateQueryGroup(t, t, n, r, s);
3240
3323
  }
3241
3324
  // public getRelevantQueryData(data: any, options: DcuplGlobalQueryOptions<any>, model: DcuplModel<ListItem>) {
3242
3325
  // // detect if any of the query attributes are a deep query.
@@ -3282,43 +3365,43 @@ const Oe = /* @__PURE__ */ new Set([
3282
3365
  "manager-key",
3283
3366
  "sdk-key"
3284
3367
  ]);
3285
- function at(n) {
3286
- const e = n.indexOf("?");
3287
- if (e < 0) return n;
3288
- const t = n.slice(e + 1).split("&").map((r) => {
3368
+ function at(i) {
3369
+ const e = i.indexOf("?");
3370
+ if (e < 0) return i;
3371
+ const t = i.slice(e + 1).split("&").map((r) => {
3289
3372
  const s = r.indexOf("=");
3290
3373
  if (s < 0) return r;
3291
- const i = r.slice(0, s);
3292
- return Oe.has(i.toLowerCase()) ? `${i}=<redacted>` : r;
3374
+ const n = r.slice(0, s);
3375
+ return Oe.has(n.toLowerCase()) ? `${n}=<redacted>` : r;
3293
3376
  }).join("&");
3294
- return `${n.slice(0, e)}?${t}`;
3377
+ return `${i.slice(0, e)}?${t}`;
3295
3378
  }
3296
- const qe = "k:", Re = "h:";
3297
- function Q(n, e = 0) {
3298
- if (n.key)
3299
- return `${qe}${n.key}`;
3379
+ const Ge = "k:", Re = "h:";
3380
+ function M(i, e = 0) {
3381
+ if (i.key)
3382
+ return `${Ge}${i.key}`;
3300
3383
  const t = D({
3301
- type: n.type,
3302
- url: n.rawUrl ?? n.url,
3303
- model: n.model ?? "",
3384
+ type: i.type,
3385
+ url: i.rawUrl ?? i.url,
3386
+ model: i.model ?? "",
3304
3387
  occurrence: e
3305
3388
  });
3306
3389
  return `${Re}${t}`;
3307
3390
  }
3308
- function ct(n) {
3391
+ function ct(i) {
3309
3392
  const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
3310
- return n.map((r) => {
3393
+ return i.map((r) => {
3311
3394
  const s = `${r.key ?? ""}|${r.type}|${r.rawUrl ?? r.url}|${r.model ?? ""}`;
3312
- let i = e.get(s) ?? 0, o = Q(r, i);
3395
+ let n = e.get(s) ?? 0, o = M(r, n);
3313
3396
  for (; t.has(o); )
3314
- i += 1, o = r.key ? `${Q(r)}#${i}` : Q(r, i);
3315
- return e.set(s, i + 1), t.add(o), o;
3397
+ n += 1, o = r.key ? `${M(r)}#${n}` : M(r, n);
3398
+ return e.set(s, n + 1), t.add(o), o;
3316
3399
  });
3317
3400
  }
3318
3401
  function ut() {
3319
- const n = globalThis;
3320
- return typeof n.scheduler?.yield == "function" ? n.scheduler.yield() : typeof n.setImmediate == "function" ? new Promise((e) => n.setImmediate(() => e())) : typeof n.MessageChannel == "function" ? new Promise((e) => {
3321
- const t = new n.MessageChannel();
3402
+ const i = globalThis;
3403
+ return typeof i.scheduler?.yield == "function" ? i.scheduler.yield() : typeof i.setImmediate == "function" ? new Promise((e) => i.setImmediate(() => e())) : typeof i.MessageChannel == "function" ? new Promise((e) => {
3404
+ const t = new i.MessageChannel();
3322
3405
  t.port1.onmessage = () => {
3323
3406
  t.port1.close(), e();
3324
3407
  }, t.port2.postMessage(null);
@@ -3350,8 +3433,8 @@ class ft {
3350
3433
  const r = this.getScript(e);
3351
3434
  if (!r)
3352
3435
  throw new Error(`Script ${e} not found`);
3353
- const s = this.getWrapperScript(r), i = new Function("script_type", ...t, s);
3354
- return this.scriptFunctions.set(e, i), i;
3436
+ const s = this.getWrapperScript(r), n = new Function("script_type", ...t, s);
3437
+ return this.scriptFunctions.set(e, n), n;
3355
3438
  }
3356
3439
  getWrapperScript(e) {
3357
3440
  return `
@@ -3363,13 +3446,13 @@ class ft {
3363
3446
  if (!this.getScript(e))
3364
3447
  throw new Error(`Script ${e} not found`);
3365
3448
  r.context || (r.context = r.options || {});
3366
- const i = Object.keys(r), o = Object.values(r);
3367
- return this.getScriptAsFn(e, i)(t, ...o);
3449
+ const n = Object.keys(r), o = Object.values(r);
3450
+ return this.getScriptAsFn(e, n)(t, ...o);
3368
3451
  }
3369
3452
  }
3370
- const dt = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", lt = (n) => {
3453
+ const dt = (i, e) => i ? (e || (e = {}), i.replace(/\$\{(.*?)\}/g, (t, r) => I(e, r.trim(), ""))) : "", lt = (i) => {
3371
3454
  const e = /* @__PURE__ */ new Set();
3372
- return n.replace(/\$\{(.*?)\}/g, (r, s) => (e.add(s.trim()), "")), { variables: Array.from(e).map((r) => ({ name: r })) };
3455
+ return i.replace(/\$\{(.*?)\}/g, (r, s) => (e.add(s.trim()), "")), { variables: Array.from(e).map((r) => ({ name: r })) };
3373
3456
  }, ht = [
3374
3457
  "any",
3375
3458
  "Array<date>",
@@ -3395,10 +3478,10 @@ const dt = (n, e) => n ? (e || (e = {}), n.replace(/\$\{(.*?)\}/g, (t, r) => I(e
3395
3478
  "size"
3396
3479
  ];
3397
3480
  export {
3398
- qe as AUTHORED_RESOURCE_ID_PREFIX,
3399
- Fe as AnalyticsController,
3400
- Ge as AttributeDependencyGraph,
3401
- _e as CacheController,
3481
+ Ge as AUTHORED_RESOURCE_ID_PREFIX,
3482
+ qe as AnalyticsController,
3483
+ Fe as AttributeDependencyGraph,
3484
+ Pe as CacheController,
3402
3485
  He as ChangeDetector,
3403
3486
  Re as DERIVED_RESOURCE_ID_PREFIX,
3404
3487
  gt as DatePropertyTypes,
@@ -3425,33 +3508,33 @@ export {
3425
3508
  nt as generateReferenceQuery,
3426
3509
  tt as generateTextQuery,
3427
3510
  C as getAggregation,
3428
- Pe as getDateConstraintUid,
3511
+ je as getDateConstraintUid,
3429
3512
  $e as getDcuplPropertyTypeForNativeType,
3430
3513
  w as getDeepPathValues,
3431
3514
  me as getDistinct,
3432
3515
  Ye as getFacets,
3433
- ze as getFilterEntryId,
3434
- je as getNumberConstraintUid,
3516
+ _e as getFilterEntryId,
3517
+ ze as getNumberConstraintUid,
3435
3518
  et as getPropertiesForData,
3436
3519
  Le as groupBy,
3437
3520
  Ve as hasMinimumVersion,
3438
- Ne as inferModel,
3521
+ Ee as inferModel,
3439
3522
  se as isDateInstance,
3440
3523
  Ce as isFloat,
3441
- Ee as isInt,
3524
+ Ne as isInt,
3442
3525
  ne as isValidDate,
3443
3526
  it as isValidQueryStatement,
3444
3527
  T as isValidVersion,
3445
3528
  Y as logger,
3446
3529
  ke as looksDateLike,
3447
3530
  Xe as parseDate,
3448
- P as parseRegexLiteral,
3531
+ j as parseRegexLiteral,
3449
3532
  lt as parseTemplate,
3450
3533
  b as perf,
3451
3534
  U as pivot,
3452
3535
  at as redactUrl,
3453
3536
  Ue as removeTrailingSlash,
3454
- Q as resolveResourceId,
3537
+ M as resolveResourceId,
3455
3538
  ct as resolveResourceIds,
3456
3539
  Je as trigger,
3457
3540
  We as unescapeRegExp,