use-abcd 1.6.2 → 1.6.3

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/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { useMemo as le, useSyncExternalStore as v, useCallback as S } from "react";
2
- import { b as oe, c as G, d as bt, e as fe, f as Je, h as he, j as Ye, S as ze, i as W, k as Ge, l as mt, n as Xe, o as gt, p as V, q as St, r as wt, s as vt, t as Mt, u as Ct, v as Ze, w as xt, x as ke, y as Ot, z as Pt, A as Rt, B as de, C as Et, D as It, E as Nt, F as zt, a as z, m as K, g as be } from "./chunks/utils-C2wXstxP.js";
3
- import { H as Ds, G as Ts } from "./chunks/utils-C2wXstxP.js";
4
- import { c as Qs } from "./chunks/client-lHRDCo64.js";
1
+ import { useMemo as le, useSyncExternalStore as v, useCallback as g } from "react";
2
+ import { b as oe, c as G, d as bt, e as fe, f as Je, h as he, j as Ye, S as ze, i as W, k as Ge, l as mt, n as Xe, o as St, p as V, q as gt, r as wt, s as vt, t as Ct, u as Mt, v as Ze, w as xt, x as ke, y as Ot, z as Pt, A as Rt, B as de, C as Et, D as It, E as Nt, F as zt, a as z, m as K, g as be } from "./chunks/utils-C2wXstxP.js";
3
+ import { H as Ts, G as qs } from "./chunks/utils-C2wXstxP.js";
4
+ import { c as $s } from "./chunks/client-lHRDCo64.js";
5
5
  const b = {
6
6
  Remove: "remove",
7
7
  Replace: "replace",
8
8
  Add: "add"
9
- }, et = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), At = Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"), ee = Symbol.iterator, x = {
9
+ }, et = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), At = Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"), ee = Symbol.iterator, O = {
10
10
  mutable: "mutable",
11
11
  immutable: "immutable"
12
12
  }, xe = {};
@@ -30,7 +30,7 @@ function Oe(e) {
30
30
  function Pe(e) {
31
31
  return Object.getPrototypeOf(e) === Map.prototype;
32
32
  }
33
- function C(e) {
33
+ function x(e) {
34
34
  var t;
35
35
  return (t = e.copy) !== null && t !== void 0 ? t : e.original;
36
36
  }
@@ -49,7 +49,7 @@ function R(e, t) {
49
49
  if (!e || typeof e != "object")
50
50
  return !1;
51
51
  let n;
52
- return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!t?.mark && ((n = t.mark(e, x)) === x.immutable || typeof n == "function");
52
+ return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!t?.mark && ((n = t.mark(e, O)) === O.immutable || typeof n == "function");
53
53
  }
54
54
  function tt(e, t = []) {
55
55
  if (Object.hasOwnProperty.call(e, "key")) {
@@ -82,7 +82,7 @@ function Z(e, t, n) {
82
82
  }
83
83
  function pe(e, t) {
84
84
  const n = h(e);
85
- return (n ? C(n) : e)[t];
85
+ return (n ? x(n) : e)[t];
86
86
  }
87
87
  function A(e, t) {
88
88
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
@@ -139,8 +139,8 @@ function nt(e, t) {
139
139
  return new s(e);
140
140
  }
141
141
  return new Map(e);
142
- } else if (t?.mark && (n = t.mark(e, x), n !== void 0) && n !== x.mutable) {
143
- if (n === x.immutable)
142
+ } else if (t?.mark && (n = t.mark(e, O), n !== void 0) && n !== O.mutable) {
143
+ if (n === O.immutable)
144
144
  return jt(e);
145
145
  if (typeof n == "function") {
146
146
  if (t.enablePatches || t.enableAutoFreeze)
@@ -283,12 +283,12 @@ function Tt(e, t) {
283
283
  const n = e.type === 3 ? e.setMap : e.copy;
284
284
  e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && st(F(n, t), e.finalities.handledSet, e.options);
285
285
  }
286
- function ge(e) {
286
+ function Se(e) {
287
287
  e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
288
288
  e.copy.add(Re(t));
289
289
  }));
290
290
  }
291
- function Se(e, t, n, s) {
291
+ function ge(e, t, n, s) {
292
292
  if (e.operated && e.assignedMap && e.assignedMap.size > 0 && !e.finalized) {
293
293
  if (n && s) {
294
294
  const r = tt(e);
@@ -304,7 +304,7 @@ function Ie(e, t, n, s) {
304
304
  const a = e.type === 3 ? e.setMap : e.copy;
305
305
  if (A(F(a, t), n)) {
306
306
  let u = i.original;
307
- i.copy && (u = i.copy), ge(e), Se(e, s, r, o), e.options.enableAutoFreeze && (e.options.updatedValues = (c = e.options.updatedValues) !== null && c !== void 0 ? c : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(u, i.original)), Z(a, t, u);
307
+ i.copy && (u = i.copy), Se(e), ge(e, s, r, o), e.options.enableAutoFreeze && (e.options.updatedValues = (c = e.options.updatedValues) !== null && c !== void 0 ? c : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(u, i.original)), Z(a, t, u);
308
308
  }
309
309
  }), e.options.enableAutoFreeze && i.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), R(n, e.options) && e.finalities.draft.push(() => {
310
310
  const r = e.type === 3 ? e.setMap : e.copy;
@@ -415,13 +415,13 @@ const ce = (e, t, n = !1) => {
415
415
  throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
416
416
  }, we = {
417
417
  get size() {
418
- return C(h(this)).size;
418
+ return x(h(this)).size;
419
419
  },
420
420
  has(e) {
421
- return C(h(this)).has(e);
421
+ return x(h(this)).has(e);
422
422
  },
423
423
  set(e, t) {
424
- const n = h(this), s = C(n);
424
+ const n = h(this), s = x(n);
425
425
  return (!s.has(e) || !A(s.get(e), t)) && (w(n), E(n), n.assignedMap.set(e, !0), n.copy.set(e, t), Ie(n, e, t, X)), this;
426
426
  },
427
427
  delete(e) {
@@ -441,13 +441,13 @@ const ce = (e, t, n = !1) => {
441
441
  },
442
442
  forEach(e, t) {
443
443
  const n = h(this);
444
- C(n).forEach((s, i) => {
444
+ x(n).forEach((s, i) => {
445
445
  e.call(t, this.get(i), i, this);
446
446
  });
447
447
  },
448
448
  get(e) {
449
449
  var t, n;
450
- const s = h(this), i = C(s).get(e), r = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, i, x)) === x.mutable;
450
+ const s = h(this), i = x(s).get(e), r = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, i, O)) === O.mutable;
451
451
  if (s.options.strict && ce(i, s.options, r), r || s.finalized || !R(i, s.options) || i !== s.original.get(e))
452
452
  return i;
453
453
  const o = xe.createDraft({
@@ -460,7 +460,7 @@ const ce = (e, t, n = !1) => {
460
460
  return w(s), s.copy.set(e, o), o;
461
461
  },
462
462
  keys() {
463
- return C(h(this)).keys();
463
+ return x(h(this)).keys();
464
464
  },
465
465
  values() {
466
466
  const e = this.keys();
@@ -501,7 +501,7 @@ const ce = (e, t, n = !1) => {
501
501
  return r;
502
502
  const o = r.value;
503
503
  let c = e.setMap.get(o);
504
- const a = h(c), u = ((i = (s = e.options).mark) === null || i === void 0 ? void 0 : i.call(s, c, x)) === x.mutable;
504
+ const a = h(c), u = ((i = (s = e.options).mark) === null || i === void 0 ? void 0 : i.call(s, c, O)) === O.mutable;
505
505
  if (e.options.strict && ce(o, e.options, u), !u && !a && R(o, e.options) && !e.finalized && e.original.has(o)) {
506
506
  const l = xe.createDraft({
507
507
  original: o,
@@ -616,10 +616,10 @@ const Bt = Reflect.ownKeys(ae), it = {
616
616
  let o;
617
617
  if (e.options.mark) {
618
618
  const u = t === "size" && (e.original instanceof Map || e.original instanceof Set) ? Reflect.get(e.original, t) : Reflect.get(e.original, t, n);
619
- if (o = e.options.mark(u, x), o === x.mutable)
619
+ if (o = e.options.mark(u, O), o === O.mutable)
620
620
  return e.options.strict && ce(u, e.options, !0), u;
621
621
  }
622
- const c = C(e);
622
+ const c = x(e);
623
623
  if (c instanceof Map && Ht.includes(t))
624
624
  return t === "size" ? Object.getOwnPropertyDescriptor(we, "size").get.call(e.proxy) : we[t].bind(e.proxy);
625
625
  if (c instanceof Set && Bt.includes(t))
@@ -656,20 +656,20 @@ const Bt = Reflect.ownKeys(ae), it = {
656
656
  let i;
657
657
  if (e.type === 1 && t !== "length" && !(Number.isInteger(i = Number(t)) && i >= 0 && (t === 0 || i === 0 || String(i) === String(t))))
658
658
  throw new Error("Only supports setting array indices and the 'length' property.");
659
- const r = Ae(C(e), t);
659
+ const r = Ae(x(e), t);
660
660
  if (r?.set)
661
661
  return r.set.call(e.proxy, n), !0;
662
- const o = pe(C(e), t), c = h(o);
662
+ const o = pe(x(e), t), c = h(o);
663
663
  return c && A(c.original, n) ? (e.copy[t] = n, e.assignedMap = (s = e.assignedMap) !== null && s !== void 0 ? s : /* @__PURE__ */ new Map(), e.assignedMap.set(t, !1), !0) : (A(n, o) && (n !== void 0 || Y(e.original, t)) || (w(e), E(e), Y(e.original, t) && A(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, Ie(e, t, n, X)), !0);
664
664
  },
665
665
  has(e, t) {
666
- return t in C(e);
666
+ return t in x(e);
667
667
  },
668
668
  ownKeys(e) {
669
- return Reflect.ownKeys(C(e));
669
+ return Reflect.ownKeys(x(e));
670
670
  },
671
671
  getOwnPropertyDescriptor(e, t) {
672
- const n = C(e), s = Reflect.getOwnPropertyDescriptor(n, t);
672
+ const n = x(e), s = Reflect.getOwnPropertyDescriptor(n, t);
673
673
  return s && {
674
674
  writable: !0,
675
675
  configurable: e.type !== 1 || t !== "length",
@@ -711,11 +711,11 @@ function Ne(e) {
711
711
  l.finalities.draft.push((f, y) => {
712
712
  var p, I;
713
713
  const $ = h(a);
714
- let M = l.type === 3 ? l.setMap : l.copy;
715
- const m = F(M, s), g = h(m);
716
- if (g) {
717
- let _ = g.original;
718
- g.operated && (_ = Re(m)), ge(g), Se(g, X, f, y), l.options.enableAutoFreeze && (l.options.updatedValues = (p = l.options.updatedValues) !== null && p !== void 0 ? p : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(_, g.original)), Z(M, s, _);
714
+ let C = l.type === 3 ? l.setMap : l.copy;
715
+ const m = F(C, s), S = h(m);
716
+ if (S) {
717
+ let _ = S.original;
718
+ S.operated && (_ = Re(m)), Se(S), ge(S, X, f, y), l.options.enableAutoFreeze && (l.options.updatedValues = (p = l.options.updatedValues) !== null && p !== void 0 ? p : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(_, S.original)), Z(C, s, _);
719
719
  }
720
720
  (I = $.callbacks) === null || I === void 0 || I.forEach((_) => {
721
721
  _(f, y);
@@ -724,7 +724,7 @@ function Ne(e) {
724
724
  } else {
725
725
  const l = h(a);
726
726
  l.finalities.draft.push((f, y) => {
727
- ge(l), Se(l, X, f, y);
727
+ Se(l), ge(l, X, f, y);
728
728
  });
729
729
  }
730
730
  return a;
@@ -753,7 +753,7 @@ function Kt(e, t) {
753
753
  };
754
754
  let i, r;
755
755
  t.enablePatches && (i = [], r = []);
756
- const c = ((n = t.mark) === null || n === void 0 ? void 0 : n.call(t, e, x)) === x.mutable || !R(e, t) ? e : Ne({
756
+ const c = ((n = t.mark) === null || n === void 0 ? void 0 : n.call(t, e, O)) === O.mutable || !R(e, t) ? e : Ne({
757
757
  original: e,
758
758
  parentDraft: null,
759
759
  finalities: s,
@@ -838,19 +838,19 @@ const Wt = (e) => function t(n, s, i) {
838
838
  if (L)
839
839
  return L;
840
840
  }
841
- }) : l.mark, p = (r = l.enablePatches) !== null && r !== void 0 ? r : !1, I = (o = l.strict) !== null && o !== void 0 ? o : !1, M = {
841
+ }) : l.mark, p = (r = l.enablePatches) !== null && r !== void 0 ? r : !1, I = (o = l.strict) !== null && o !== void 0 ? o : !1, C = {
842
842
  enableAutoFreeze: (c = l.enableAutoFreeze) !== null && c !== void 0 ? c : !1,
843
843
  mark: y,
844
844
  strict: I,
845
845
  enablePatches: p
846
846
  };
847
- if (!R(f, M) && typeof f == "object" && f !== null)
847
+ if (!R(f, C) && typeof f == "object" && f !== null)
848
848
  throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
849
- const [m, g] = Kt(f, M);
849
+ const [m, S] = Kt(f, C);
850
850
  if (typeof s != "function") {
851
- if (!R(f, M))
851
+ if (!R(f, C))
852
852
  throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
853
- return [m, g];
853
+ return [m, S];
854
854
  }
855
855
  let _;
856
856
  try {
@@ -866,24 +866,24 @@ const Wt = (e) => function t(n, s, i) {
866
866
  const L = d?.[At];
867
867
  if (L) {
868
868
  const yt = L[0];
869
- return M.strict && typeof d == "object" && d !== null && ve({
869
+ return C.strict && typeof d == "object" && d !== null && ve({
870
870
  rootDraft: N,
871
871
  value: d,
872
872
  useRawReturn: !0
873
- }), g([yt]);
873
+ }), S([yt]);
874
874
  }
875
875
  if (d !== void 0)
876
- return typeof d == "object" && d !== null && ve({ rootDraft: N, value: d }), g([d]);
876
+ return typeof d == "object" && d !== null && ve({ rootDraft: N, value: d }), S([d]);
877
877
  }
878
878
  if (d === m || d === void 0)
879
- return g([]);
879
+ return S([]);
880
880
  const D = h(d);
881
- if (M === D.options) {
881
+ if (C === D.options) {
882
882
  if (D.operated)
883
883
  throw new Error("Cannot return a modified child draft.");
884
- return g([De(d)]);
884
+ return S([De(d)]);
885
885
  }
886
- return g([d]);
886
+ return S([d]);
887
887
  };
888
888
  return _ instanceof Promise ? _.then(j, (d) => {
889
889
  throw me(h(m)), d;
@@ -1020,12 +1020,12 @@ function $e(e, t, n) {
1020
1020
  return (s == "number" ? he(n) && Ye(t, n.length) : s == "string" && t in n) ? Je(n[t], e) : !1;
1021
1021
  }
1022
1022
  var He = ze ? ze.isConcatSpreadable : void 0;
1023
- function gn(e) {
1023
+ function Sn(e) {
1024
1024
  return W(e) || Ge(e) || !!(He && e && e[He]);
1025
1025
  }
1026
- function Sn(e, t, n, s, i) {
1026
+ function gn(e, t, n, s, i) {
1027
1027
  var r = -1, o = e.length;
1028
- for (n || (n = gn), i || (i = []); ++r < o; ) {
1028
+ for (n || (n = Sn), i || (i = []); ++r < o; ) {
1029
1029
  var c = e[r];
1030
1030
  n(c) ? mt(i, c) : i[i.length] = c;
1031
1031
  }
@@ -1038,7 +1038,7 @@ function wn(e, t, n) {
1038
1038
  r[s] = e[s + t];
1039
1039
  return r;
1040
1040
  }
1041
- var vn = "\\ud800-\\udfff", Mn = "\\u0300-\\u036f", Cn = "\\ufe20-\\ufe2f", xn = "\\u20d0-\\u20ff", On = Mn + Cn + xn, Pn = "\\ufe0e\\ufe0f", Rn = "\\u200d", En = RegExp("[" + Rn + vn + On + Pn + "]");
1041
+ var vn = "\\ud800-\\udfff", Cn = "\\u0300-\\u036f", Mn = "\\ufe20-\\ufe2f", xn = "\\u20d0-\\u20ff", On = Cn + Mn + xn, Pn = "\\ufe0e\\ufe0f", Rn = "\\u200d", En = RegExp("[" + Rn + vn + On + Pn + "]");
1042
1042
  function In(e) {
1043
1043
  return En.test(e);
1044
1044
  }
@@ -1062,7 +1062,7 @@ function Fn(e, t) {
1062
1062
  }), n;
1063
1063
  }
1064
1064
  function se(e, t) {
1065
- var n = W(e) ? gt : Fn;
1065
+ var n = W(e) ? St : Fn;
1066
1066
  return n(e, V(t));
1067
1067
  }
1068
1068
  function jn(e) {
@@ -1070,7 +1070,7 @@ function jn(e) {
1070
1070
  var i = Object(t);
1071
1071
  if (!he(t)) {
1072
1072
  var r = V(n);
1073
- t = St(t), n = function(c) {
1073
+ t = gt(t), n = function(c) {
1074
1074
  return r(i[c], c, i);
1075
1075
  };
1076
1076
  }
@@ -1101,7 +1101,7 @@ var Hn = "[object Map]", Bn = "[object Set]", Un = Object.prototype, Kn = Un.has
1101
1101
  function Wn(e) {
1102
1102
  if (e == null)
1103
1103
  return !0;
1104
- if (he(e) && (W(e) || typeof e == "string" || typeof e.splice == "function" || Mt(e) || Ct(e) || Ge(e)))
1104
+ if (he(e) && (W(e) || typeof e == "string" || typeof e.splice == "function" || Ct(e) || Mt(e) || Ge(e)))
1105
1105
  return !e.length;
1106
1106
  var t = Ze(e);
1107
1107
  if (t == Hn || t == Bn)
@@ -1199,7 +1199,7 @@ function es(e, t, n) {
1199
1199
  return kn(r, o, n);
1200
1200
  });
1201
1201
  }
1202
- var ts = zt("length"), ut = "\\ud800-\\udfff", ns = "\\u0300-\\u036f", ss = "\\ufe20-\\ufe2f", is = "\\u20d0-\\u20ff", rs = ns + ss + is, os = "\\ufe0e\\ufe0f", cs = "[" + ut + "]", Me = "[" + rs + "]", Ce = "\\ud83c[\\udffb-\\udfff]", as = "(?:" + Me + "|" + Ce + ")", lt = "[^" + ut + "]", ft = "(?:\\ud83c[\\udde6-\\uddff]){2}", ht = "[\\ud800-\\udbff][\\udc00-\\udfff]", us = "\\u200d", dt = as + "?", pt = "[" + os + "]?", ls = "(?:" + us + "(?:" + [lt, ft, ht].join("|") + ")" + pt + dt + ")*", fs = pt + dt + ls, hs = "(?:" + [lt + Me + "?", Me, ft, ht, cs].join("|") + ")", Ke = RegExp(Ce + "(?=" + Ce + ")|" + hs + fs, "g");
1202
+ var ts = zt("length"), ut = "\\ud800-\\udfff", ns = "\\u0300-\\u036f", ss = "\\ufe20-\\ufe2f", is = "\\u20d0-\\u20ff", rs = ns + ss + is, os = "\\ufe0e\\ufe0f", cs = "[" + ut + "]", Ce = "[" + rs + "]", Me = "\\ud83c[\\udffb-\\udfff]", as = "(?:" + Ce + "|" + Me + ")", lt = "[^" + ut + "]", ft = "(?:\\ud83c[\\udde6-\\uddff]){2}", ht = "[\\ud800-\\udbff][\\udc00-\\udfff]", us = "\\u200d", dt = as + "?", pt = "[" + os + "]?", ls = "(?:" + us + "(?:" + [lt, ft, ht].join("|") + ")" + pt + dt + ")*", fs = pt + dt + ls, hs = "(?:" + [lt + Ce + "?", Ce, ft, ht, cs].join("|") + ")", Ke = RegExp(Me + "(?=" + Me + ")|" + hs + fs, "g");
1203
1203
  function ds(e) {
1204
1204
  for (var t = Ke.lastIndex = 0; Ke.test(e); )
1205
1205
  ++t;
@@ -1224,13 +1224,13 @@ var re = mn(function(e, t) {
1224
1224
  if (e == null)
1225
1225
  return [];
1226
1226
  var n = t.length;
1227
- return n > 1 && $e(e, t[0], t[1]) ? t = [] : n > 2 && $e(t[0], t[1], t[2]) && (t = [t[0]]), es(e, Sn(t), []);
1227
+ return n > 1 && $e(e, t[0], t[1]) ? t = [] : n > 2 && $e(t[0], t[1], t[2]) && (t = [t[0]]), es(e, gn(t), []);
1228
1228
  });
1229
1229
  function ms(e, t, n) {
1230
1230
  return e && e.length ? (t = t === void 0 ? 1 : ot(t), wn(e, 0, t < 0 ? 0 : t)) : [];
1231
1231
  }
1232
- const gs = (e, t) => e ? e.type === "create" && t.type === "delete" ? null : e.type === "create" && t.type === "update" ? { ...e, data: t.data } : (e.type === "update" && t.type === "update" || e.type === "update" && t.type === "delete", t) : t;
1233
- class Ss {
1232
+ const Ss = (e, t) => e ? e.type === "create" && t.type === "delete" ? null : e.type === "create" && t.type === "update" ? { ...e, data: t.data } : (e.type === "update" && t.type === "update" || e.type === "update" && t.type === "delete", t) : t;
1233
+ class gs {
1234
1234
  _config;
1235
1235
  _state;
1236
1236
  _subscribers = /* @__PURE__ */ new Set();
@@ -1247,7 +1247,7 @@ class Ss {
1247
1247
  }
1248
1248
  enqueue(t) {
1249
1249
  this._updateState((n) => {
1250
- const s = n.queue.get(t.id), i = gs(s, t);
1250
+ const s = n.queue.get(t.id), i = Ss(s, t);
1251
1251
  i ? n.queue.set(t.id, i) : n.queue.delete(t.id), n.errors.delete(t.id);
1252
1252
  }), this._scheduleFlush();
1253
1253
  }
@@ -1429,15 +1429,28 @@ class vs {
1429
1429
  async fetch(t) {
1430
1430
  const n = this._getCacheKey(t), s = this._cache.get(n);
1431
1431
  if (s !== null)
1432
- return this._currentContext = t, this._setState({ status: "idle", items: s, error: void 0, retryCount: void 0 }), s;
1432
+ return this._currentContext = t, this._setState({
1433
+ status: "idle",
1434
+ items: s.items,
1435
+ serverState: s.serverState,
1436
+ error: void 0,
1437
+ retryCount: void 0
1438
+ }), s;
1433
1439
  this._abortController?.abort("New fetch request started");
1434
1440
  const i = new AbortController();
1435
1441
  this._abortController = i, this._currentContext = t, this._setState({ status: "fetching", error: void 0, retryCount: void 0 });
1436
1442
  try {
1437
1443
  const r = await this._fetchWithRetry(t, i.signal);
1438
- return this._cache.set(n, r), this._abortController = null, this._setState({ status: "idle", items: r, error: void 0, retryCount: void 0 }), r;
1444
+ return this._cache.set(n, r), this._abortController = null, this._setState({
1445
+ status: "idle",
1446
+ items: r.items,
1447
+ serverState: r.serverState,
1448
+ error: void 0,
1449
+ retryCount: void 0
1450
+ }), r;
1439
1451
  } catch (r) {
1440
- if (i.signal.aborted) return this._state.items;
1452
+ if (i.signal.aborted)
1453
+ return { items: this._state.items, serverState: this._state.serverState };
1441
1454
  throw this._abortController = null, this._setState({
1442
1455
  status: "error",
1443
1456
  error: r instanceof Error ? r.message : String(r)
@@ -1497,12 +1510,12 @@ class We {
1497
1510
  return this._collection;
1498
1511
  }
1499
1512
  }
1500
- const Ms = ".";
1513
+ const Cs = ".";
1501
1514
  function H(e, t) {
1502
1515
  const n = e.lastIndexOf(t);
1503
1516
  return n === -1 ? null : e.slice(0, n);
1504
1517
  }
1505
- function Cs(e, t, n) {
1518
+ function Ms(e, t, n) {
1506
1519
  return e.startsWith(t + n) ? !e.slice(t.length + 1).includes(n) : !1;
1507
1520
  }
1508
1521
  function ye(e, t, n) {
@@ -1519,7 +1532,7 @@ class Le {
1519
1532
  this._collection = t, this._id = n;
1520
1533
  }
1521
1534
  get _separator() {
1522
- return this._collection.config.nodeSeparator ?? Ms;
1535
+ return this._collection.config.nodeSeparator ?? Cs;
1523
1536
  }
1524
1537
  get id() {
1525
1538
  return this._id;
@@ -1551,7 +1564,7 @@ class Le {
1551
1564
  }
1552
1565
  getChildren() {
1553
1566
  const t = [...this._collection.items.entries()], n = K(
1554
- se(t, ([i]) => Cs(i, this._id, this._separator)),
1567
+ se(t, ([i]) => Ms(i, this._id, this._separator)),
1555
1568
  ([i, r]) => ({ id: i, position: r.position })
1556
1569
  ), s = re(n, "position");
1557
1570
  return K(s, (i) => this._collection.getNode(i.id));
@@ -1766,23 +1779,23 @@ function _t(e) {
1766
1779
  fetchError: void 0
1767
1780
  };
1768
1781
  }
1769
- class O {
1782
+ class M {
1770
1783
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1771
1784
  static _cache = /* @__PURE__ */ new Map();
1772
1785
  static get(t) {
1773
- const n = O._cache.get(t.id);
1786
+ const n = M._cache.get(t.id);
1774
1787
  if (n) return n;
1775
- const s = new O(t);
1776
- return O._cache.set(t.id, s), s;
1788
+ const s = new M(t);
1789
+ return M._cache.set(t.id, s), s;
1777
1790
  }
1778
1791
  static clear(t) {
1779
- O._cache.get(t)?.destroy();
1792
+ M._cache.get(t)?.destroy();
1780
1793
  }
1781
1794
  static clearAll() {
1782
- O._cache.forEach((t) => t.destroy());
1795
+ M._cache.forEach((t) => t.destroy());
1783
1796
  }
1784
1797
  static getById(t) {
1785
- return O._cache.get(t);
1798
+ return M._cache.get(t);
1786
1799
  }
1787
1800
  id;
1788
1801
  config;
@@ -1798,7 +1811,10 @@ class O {
1798
1811
  _batchMode = !1;
1799
1812
  constructor(t) {
1800
1813
  this.id = t.id, this.config = t;
1801
- const n = t.handler ? (o, c) => t.handler({ query: o }, c).then((a) => a.items ?? []) : async () => [], s = t.handler ? (o, c, a) => t.handler({ changes: o }, a) : async (o) => ({
1814
+ const n = t.handler ? (o, c) => t.handler({ query: o }, c).then((a) => ({
1815
+ items: a.items ?? [],
1816
+ serverState: a.serverState
1817
+ })) : async () => ({ items: [] }), s = t.handler ? (o, c, a) => t.handler({ changes: o }, a) : async (o) => ({
1802
1818
  syncResults: K(o, (c) => ({
1803
1819
  status: "success",
1804
1820
  id: c.id,
@@ -1807,7 +1823,7 @@ class O {
1807
1823
  })),
1808
1824
  serverSyncedAt: ""
1809
1825
  });
1810
- this._syncQueue = new Ss({
1826
+ this._syncQueue = new gs({
1811
1827
  debounce: t.syncDebounce ?? 300,
1812
1828
  maxRetries: t.syncRetries ?? 3,
1813
1829
  getContext: () => this._state.context,
@@ -1954,7 +1970,7 @@ class O {
1954
1970
  t ? this._syncQueue.retry(t) : this._syncQueue.retryAll();
1955
1971
  }
1956
1972
  destroy() {
1957
- this._syncQueue.destroy(), this._fetchHandler.destroy(), this._subscribers.clear(), O._cache.delete(this.id);
1973
+ this._syncQueue.destroy(), this._fetchHandler.destroy(), this._subscribers.clear(), M._cache.delete(this.id);
1958
1974
  }
1959
1975
  async _initialFetch() {
1960
1976
  if (!this._hasInitialized) {
@@ -1974,7 +1990,7 @@ class O {
1974
1990
  _onFetchChange() {
1975
1991
  const t = this._fetchHandler.getState();
1976
1992
  this._state = P(this._state, (n) => {
1977
- n.fetchStatus = t.status, n.fetchError = t.error, n.loading = t.status === "fetching", n.syncState = this._computeSyncState(t.status, n.syncQueue.isSyncing);
1993
+ n.fetchStatus = t.status, n.fetchError = t.error, n.serverState = t.serverState, n.loading = t.status === "fetching", n.syncState = this._computeSyncState(t.status, n.syncQueue.isSyncing);
1978
1994
  const s = /* @__PURE__ */ new Map();
1979
1995
  for (const i of t.items)
1980
1996
  s.set(i.id, i);
@@ -1996,7 +2012,7 @@ class O {
1996
2012
  }
1997
2013
  }
1998
2014
  function Es(e) {
1999
- const t = O.get(e), n = le(() => _t(e), [e.id]), s = v(
2015
+ const t = M.get(e), n = le(() => _t(e), [e.id]), s = v(
2000
2016
  (i) => t.subscribe(i),
2001
2017
  () => t.getState(),
2002
2018
  () => n
@@ -2011,6 +2027,7 @@ function Es(e) {
2011
2027
  syncing: s.syncing,
2012
2028
  fetchStatus: s.fetchStatus,
2013
2029
  fetchError: s.fetchError,
2030
+ serverState: s.serverState,
2014
2031
  // Item operations
2015
2032
  create: (i) => t.create({ ...i, id: be() }),
2016
2033
  update: (i, r) => t.update(i, r),
@@ -2027,7 +2044,7 @@ function Es(e) {
2027
2044
  };
2028
2045
  }
2029
2046
  function Is(e) {
2030
- const t = e, n = O.get(t), s = le(() => _t(t), [e.id]), i = v(
2047
+ const t = e, n = M.get(t), s = le(() => _t(t), [e.id]), i = v(
2031
2048
  (u) => n.subscribe(u),
2032
2049
  () => n.getState(),
2033
2050
  () => s
@@ -2043,19 +2060,19 @@ function Is(e) {
2043
2060
  (u) => n.subscribe(u),
2044
2061
  () => n.selectedNode,
2045
2062
  () => null
2046
- ), a = S(() => {
2063
+ ), a = g(() => {
2047
2064
  const u = e.nodeSeparator ?? ".", l = (y, p) => y.startsWith(p + u) ? !y.slice(p.length + 1).includes(u) : !1, f = (y) => {
2048
2065
  const p = i.items.get(y);
2049
2066
  if (!p) return null;
2050
2067
  const I = K(
2051
2068
  se([...i.items.entries()], ([m]) => l(m, y)),
2052
- ([m, g]) => ({ id: m, position: g.position })
2053
- ), $ = re(I, "position"), M = K($, (m) => f(m.id)).filter(Boolean);
2069
+ ([m, S]) => ({ id: m, position: S.position })
2070
+ ), $ = re(I, "position"), C = K($, (m) => f(m.id)).filter(Boolean);
2054
2071
  return {
2055
2072
  id: p.id,
2056
2073
  type: p.type,
2057
2074
  value: p.value,
2058
- ...M.length > 0 ? { children: M } : {}
2075
+ ...C.length > 0 ? { children: C } : {}
2059
2076
  };
2060
2077
  };
2061
2078
  return f(e.rootId);
@@ -2072,6 +2089,7 @@ function Is(e) {
2072
2089
  syncing: i.syncing,
2073
2090
  fetchStatus: i.fetchStatus,
2074
2091
  fetchError: i.fetchError,
2092
+ serverState: i.serverState,
2075
2093
  // Node operations
2076
2094
  getNode: (u) => n.getNode(u),
2077
2095
  getNodeStatus: (u) => n.getItemStatus(u),
@@ -2104,11 +2122,11 @@ function Ns(e) {
2104
2122
  (o) => e.collection.subscribe(o),
2105
2123
  () => e.exists(),
2106
2124
  () => e.exists()
2107
- ), i = S((o) => e.update(o), [e]), r = S(() => e.remove(), [e]);
2125
+ ), i = g((o) => e.update(o), [e]), r = g(() => e.remove(), [e]);
2108
2126
  return { data: t, status: n, update: i, remove: r, exists: s };
2109
2127
  }
2110
2128
  function xs(e) {
2111
- const t = S((_) => e.collection.subscribe(_), [e]), n = v(
2129
+ const t = g((_) => e.collection.subscribe(_), [e]), n = v(
2112
2130
  t,
2113
2131
  () => e.data,
2114
2132
  () => e.data
@@ -2124,13 +2142,13 @@ function xs(e) {
2124
2142
  t,
2125
2143
  () => e.collection.selectedNodeId === e.id,
2126
2144
  () => e.collection.selectedNodeId === e.id
2127
- ), o = le(() => e.getChildren(), [n, e]), c = S(() => e.getParent(), [e]), a = S((_, j) => e.append(_, j), [e]), u = S((_, j) => e.prepend(_, j), [e]), l = S(
2145
+ ), o = le(() => e.getChildren(), [n, e]), c = g(() => e.getParent(), [e]), a = g((_, j) => e.append(_, j), [e]), u = g((_, j) => e.prepend(_, j), [e]), l = g(
2128
2146
  (_, j) => e.move(_, j),
2129
2147
  [e]
2130
- ), f = S(() => e.moveUp(), [e]), y = S(() => e.moveDown(), [e]), p = S((_) => e.setPosition(_), [e]), I = S(() => e.clone(), [e]), $ = S(
2148
+ ), f = g(() => e.moveUp(), [e]), y = g(() => e.moveDown(), [e]), p = g((_) => e.setPosition(_), [e]), I = g(() => e.clone(), [e]), $ = g(
2131
2149
  (_) => e.updateProp(_),
2132
2150
  [e]
2133
- ), M = S(() => e.remove(), [e]), m = S(() => e.select(), [e]), g = S(() => e.collection.deselectNode(), [e]);
2151
+ ), C = g(() => e.remove(), [e]), m = g(() => e.select(), [e]), S = g(() => e.collection.deselectNode(), [e]);
2134
2152
  return {
2135
2153
  isPresent: !0,
2136
2154
  data: n,
@@ -2148,9 +2166,9 @@ function xs(e) {
2148
2166
  setPosition: p,
2149
2167
  clone: I,
2150
2168
  updateProp: $,
2151
- remove: M,
2169
+ remove: C,
2152
2170
  select: m,
2153
- deselect: g
2171
+ deselect: S
2154
2172
  };
2155
2173
  }
2156
2174
  const Os = {
@@ -2183,7 +2201,7 @@ const Os = {
2183
2201
  }
2184
2202
  };
2185
2203
  function zs(e) {
2186
- const t = O.getById(e);
2204
+ const t = M.getById(e);
2187
2205
  if (!t)
2188
2206
  throw new Error(
2189
2207
  `Collection with id "${e}" not found. Make sure useCrud is called first.`
@@ -2196,7 +2214,7 @@ function zs(e) {
2196
2214
  return n ? i : Os;
2197
2215
  }
2198
2216
  function As(e) {
2199
- const t = O.getById(e);
2217
+ const t = M.getById(e);
2200
2218
  if (!t)
2201
2219
  throw new Error(
2202
2220
  `Collection with id "${e}" not found. Make sure useCrud is called first.`
@@ -2216,23 +2234,36 @@ function As(e) {
2216
2234
  isSyncing: n.syncQueue.isSyncing
2217
2235
  };
2218
2236
  }
2237
+ function Fs(e, t) {
2238
+ const n = M.getById(e);
2239
+ if (!n)
2240
+ throw new Error(
2241
+ `Collection with id "${e}" not found. Make sure useCrud is called first.`
2242
+ );
2243
+ return v(
2244
+ (i) => n.subscribe(i),
2245
+ () => n.getState(),
2246
+ () => n.getState()
2247
+ ).serverState ?? t;
2248
+ }
2219
2249
  export {
2220
2250
  ws as Cache,
2221
- O as Collection,
2251
+ M as Collection,
2222
2252
  vs as FetchHandler,
2223
2253
  We as Item,
2224
2254
  Le as Node,
2225
- Ss as SyncQueue,
2255
+ gs as SyncQueue,
2226
2256
  _t as buildServerSnapshot,
2227
- Ds as compareTimeIds,
2228
- Qs as createSyncClient,
2257
+ Ts as compareTimeIds,
2258
+ $s as createSyncClient,
2229
2259
  be as getIdFromTime,
2230
- Ts as getTimeFromId,
2260
+ qs as getTimeFromId,
2231
2261
  Es as useCrud,
2232
2262
  Is as useCrudTree,
2233
2263
  Ns as useItem,
2234
2264
  xs as useNode,
2235
2265
  zs as useSelectedNode,
2266
+ Fs as useServerState,
2236
2267
  As as useSyncState
2237
2268
  };
2238
2269
  //# sourceMappingURL=index.js.map