@instantdb/react 0.22.56-experimental.persisted-object-2.19512376560.1 → 0.22.56-experimental.persisted-object-2.19516307571.1

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.
@@ -1,4 +1,4 @@
1
- import ai, { useRef as At, useCallback as ge, useSyncExternalStore as nn, useEffect as je, useMemo as rn, useState as ui, createElement as Es } from "react";
1
+ import ui, { useRef as At, useCallback as ge, useSyncExternalStore as nn, useEffect as je, useMemo as rn, useState as ci, createElement as As } from "react";
2
2
  function V(t) {
3
3
  if (typeof t == "number")
4
4
  return (Math.abs(t * 2654435761) >>> 0).toString(16);
@@ -41,7 +41,7 @@ const U = {
41
41
  Remove: "remove",
42
42
  Replace: "replace",
43
43
  Add: "add"
44
- }, ci = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), As = Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"), wt = Symbol.iterator, ne = {
44
+ }, di = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), ks = Symbol("__MUTATIVE_RAW_RETURN_SYMBOL__"), wt = Symbol.iterator, ne = {
45
45
  mutable: "mutable",
46
46
  immutable: "immutable"
47
47
  }, Rn = {};
@@ -73,7 +73,7 @@ function Ce(t) {
73
73
  return !!j(t);
74
74
  }
75
75
  function j(t) {
76
- return typeof t != "object" ? null : t == null ? void 0 : t[ci];
76
+ return typeof t != "object" ? null : t == null ? void 0 : t[di];
77
77
  }
78
78
  function Dn(t) {
79
79
  var e;
@@ -86,7 +86,7 @@ function ae(t, e) {
86
86
  let n;
87
87
  return Object.getPrototypeOf(t) === Object.prototype || Array.isArray(t) || t instanceof Map || t instanceof Set || !!(e != null && e.mark) && ((n = e.mark(t, ne)) === ne.immutable || typeof n == "function");
88
88
  }
89
- function di(t, e = []) {
89
+ function fi(t, e = []) {
90
90
  if (Object.hasOwnProperty.call(t, "key")) {
91
91
  const n = t.parent.copy, r = j(be(n, t.key));
92
92
  if (r !== null && (r == null ? void 0 : r.original) !== t.original)
@@ -97,10 +97,10 @@ function di(t, e = []) {
97
97
  e.push(s);
98
98
  }
99
99
  if (t.parent)
100
- return di(t.parent, e);
100
+ return fi(t.parent, e);
101
101
  e.reverse();
102
102
  try {
103
- ks(t.copy, e);
103
+ js(t.copy, e);
104
104
  } catch {
105
105
  return null;
106
106
  }
@@ -133,7 +133,7 @@ function Ae(t, e) {
133
133
  return r.indexOf("/") === -1 && r.indexOf("~") === -1 ? r : r.replace(/~/g, "~0").replace(/\//g, "~1");
134
134
  }).join("/");
135
135
  }
136
- function ks(t, e) {
136
+ function js(t, e) {
137
137
  for (let n = 0; n < e.length - 1; n += 1) {
138
138
  const r = e[n];
139
139
  if (t = be(Pe(t) === 3 ? Array.from(t) : t, r), typeof t != "object")
@@ -141,7 +141,7 @@ function ks(t, e) {
141
141
  }
142
142
  return t;
143
143
  }
144
- function js(t) {
144
+ function Cs(t) {
145
145
  const e = Object.create(Object.getPrototypeOf(t));
146
146
  return Reflect.ownKeys(t).forEach((n) => {
147
147
  let r = Reflect.getOwnPropertyDescriptor(t, n);
@@ -157,8 +157,8 @@ function js(t) {
157
157
  }), Reflect.defineProperty(e, n, r);
158
158
  }), e;
159
159
  }
160
- const Cs = Object.prototype.propertyIsEnumerable;
161
- function fi(t, e) {
160
+ const Ps = Object.prototype.propertyIsEnumerable;
161
+ function li(t, e) {
162
162
  let n;
163
163
  if (Array.isArray(t))
164
164
  return Array.prototype.concat.call(t);
@@ -176,7 +176,7 @@ function fi(t, e) {
176
176
  return new Map(t);
177
177
  } else if (e != null && e.mark && (n = e.mark(t, ne), n !== void 0) && n !== ne.mutable) {
178
178
  if (n === ne.immutable)
179
- return js(t);
179
+ return Cs(t);
180
180
  if (typeof n == "function") {
181
181
  if (e.enablePatches || e.enableAutoFreeze)
182
182
  throw new Error("You can't use mark and patches or auto freeze together.");
@@ -188,13 +188,13 @@ function fi(t, e) {
188
188
  return Object.keys(t).forEach((i) => {
189
189
  r[i] = t[i];
190
190
  }), Object.getOwnPropertySymbols(t).forEach((i) => {
191
- Cs.call(t, i) && (r[i] = t[i]);
191
+ Ps.call(t, i) && (r[i] = t[i]);
192
192
  }), r;
193
193
  } else
194
194
  throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
195
195
  }
196
196
  function Q(t) {
197
- t.copy || (t.copy = fi(t.original, t.options));
197
+ t.copy || (t.copy = li(t.original, t.options));
198
198
  }
199
199
  function Je(t) {
200
200
  if (!ae(t))
@@ -294,7 +294,7 @@ function Un(t, e) {
294
294
  } else
295
295
  t.forEach((r, i) => e(i, r, t));
296
296
  }
297
- function li(t, e, n) {
297
+ function hi(t, e, n) {
298
298
  if (Ce(t) || !ae(t, n) || e.has(t) || Object.isFrozen(t))
299
299
  return;
300
300
  const r = t instanceof Set, i = r ? /* @__PURE__ */ new Map() : void 0;
@@ -306,7 +306,7 @@ function li(t, e, n) {
306
306
  const c = !((a = u.assignedMap) === null || a === void 0) && a.size || u.operated ? u.copy : u.original;
307
307
  at(r ? i : t, s, c);
308
308
  } else
309
- li(o, e, n);
309
+ hi(o, e, n);
310
310
  }), i) {
311
311
  const s = t, o = Array.from(s);
312
312
  s.clear(), o.forEach((a) => {
@@ -314,9 +314,9 @@ function li(t, e, n) {
314
314
  });
315
315
  }
316
316
  }
317
- function Ps(t, e) {
317
+ function Is(t, e) {
318
318
  const n = t.type === 3 ? t.setMap : t.copy;
319
- t.finalities.revoke.length > 1 && t.assignedMap.get(e) && n && li(be(n, e), t.finalities.handledSet, t.options);
319
+ t.finalities.revoke.length > 1 && t.assignedMap.get(e) && n && hi(be(n, e), t.finalities.handledSet, t.options);
320
320
  }
321
321
  function on(t) {
322
322
  t.type === 3 && t.copy && (t.copy.clear(), t.setMap.forEach((e) => {
@@ -326,7 +326,7 @@ function on(t) {
326
326
  function an(t, e, n, r) {
327
327
  if (t.operated && t.assignedMap && t.assignedMap.size > 0 && !t.finalized) {
328
328
  if (n && r) {
329
- const s = di(t);
329
+ const s = fi(t);
330
330
  s && e(t, s, n, r);
331
331
  }
332
332
  t.finalized = !0;
@@ -343,10 +343,10 @@ function Ln(t, e, n, r) {
343
343
  }
344
344
  }), t.options.enableAutoFreeze && i.finalities !== t.finalities && (t.options.enableAutoFreeze = !1)), ae(n, t.options) && t.finalities.draft.push(() => {
345
345
  const s = t.type === 3 ? t.setMap : t.copy;
346
- ye(be(s, e), n) && Ps(t, e);
346
+ ye(be(s, e), n) && Is(t, e);
347
347
  });
348
348
  }
349
- function Is(t, e, n, r, i) {
349
+ function Ms(t, e, n, r, i) {
350
350
  let { original: s, assignedMap: o, options: a } = t, u = t.copy;
351
351
  u.length < s.length && ([s, u] = [u, s], [n, r] = [r, n]);
352
352
  for (let c = 0; c < s.length; c += 1)
@@ -392,7 +392,7 @@ function Is(t, e, n, r, i) {
392
392
  }
393
393
  }
394
394
  }
395
- function Ms({ original: t, copy: e, assignedMap: n }, r, i, s, o) {
395
+ function Rs({ original: t, copy: e, assignedMap: n }, r, i, s, o) {
396
396
  n.forEach((a, u) => {
397
397
  const c = be(t, u), d = mt(be(e, u)), f = a ? nt(t, u) ? U.Replace : U.Add : U.Remove;
398
398
  if (ye(c, d) && f === U.Replace)
@@ -401,7 +401,7 @@ function Ms({ original: t, copy: e, assignedMap: n }, r, i, s, o) {
401
401
  i.push(f === U.Remove ? { op: f, path: p } : { op: f, path: p, value: d }), s.push(f === U.Add ? { op: U.Remove, path: p } : f === U.Remove ? { op: U.Add, path: p, value: c } : { op: U.Replace, path: p, value: c });
402
402
  });
403
403
  }
404
- function Rs({ original: t, copy: e }, n, r, i, s) {
404
+ function xs({ original: t, copy: e }, n, r, i, s) {
405
405
  let o = 0;
406
406
  t.forEach((a) => {
407
407
  if (!e.has(a)) {
@@ -438,11 +438,11 @@ function ot(t, e, n, r) {
438
438
  switch (t.type) {
439
439
  case 0:
440
440
  case 2:
441
- return Ms(t, e, n, r, i);
441
+ return Rs(t, e, n, r, i);
442
442
  case 1:
443
- return Is(t, e, n, r, i);
443
+ return Ms(t, e, n, r, i);
444
444
  case 3:
445
- return Rs(t, e, n, r, i);
445
+ return xs(t, e, n, r, i);
446
446
  }
447
447
  }
448
448
  const kt = (t, e, n = !1) => {
@@ -529,7 +529,7 @@ const kt = (t, e, n = !1) => {
529
529
  [wt]() {
530
530
  return this.entries();
531
531
  }
532
- }, xs = Reflect.ownKeys(un), mr = (t, e, { isValuesIterator: n }) => () => {
532
+ }, $s = Reflect.ownKeys(un), mr = (t, e, { isValuesIterator: n }) => () => {
533
533
  var r, i;
534
534
  const s = e.next();
535
535
  if (s.done)
@@ -640,13 +640,13 @@ Set.prototype.difference && Object.assign(jt, {
640
640
  return Set.prototype.isDisjointFrom.call(new Set(this.values()), t);
641
641
  }
642
642
  });
643
- const $s = Reflect.ownKeys(jt), hi = /* @__PURE__ */ new WeakSet(), pi = {
643
+ const Ds = Reflect.ownKeys(jt), pi = /* @__PURE__ */ new WeakSet(), yi = {
644
644
  get(t, e, n) {
645
645
  var r, i;
646
646
  const s = (r = t.copy) === null || r === void 0 ? void 0 : r[e];
647
- if (s && hi.has(s))
647
+ if (s && pi.has(s))
648
648
  return s;
649
- if (e === ci)
649
+ if (e === di)
650
650
  return t;
651
651
  let o;
652
652
  if (t.options.mark) {
@@ -655,14 +655,14 @@ const $s = Reflect.ownKeys(jt), hi = /* @__PURE__ */ new WeakSet(), pi = {
655
655
  return t.options.strict && kt(c, t.options, !0), c;
656
656
  }
657
657
  const a = te(t);
658
- if (a instanceof Map && xs.includes(e)) {
658
+ if (a instanceof Map && $s.includes(e)) {
659
659
  if (e === "size")
660
660
  return Object.getOwnPropertyDescriptor(un, "size").get.call(t.proxy);
661
661
  const c = un[e];
662
662
  if (c)
663
663
  return c.bind(t.proxy);
664
664
  }
665
- if (a instanceof Set && $s.includes(e)) {
665
+ if (a instanceof Set && Ds.includes(e)) {
666
666
  if (e === "size")
667
667
  return Object.getOwnPropertyDescriptor(jt, "size").get.call(t.proxy);
668
668
  const c = jt[e];
@@ -733,7 +733,7 @@ const $s = Reflect.ownKeys(jt), hi = /* @__PURE__ */ new WeakSet(), pi = {
733
733
  },
734
734
  deleteProperty(t, e) {
735
735
  var n;
736
- return t.type === 1 ? pi.set.call(this, t, e, void 0, t.proxy) : (Qt(t.original, e) !== void 0 || e in t.original ? (Q(t), fe(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
736
+ return t.type === 1 ? yi.set.call(this, t, e, void 0, t.proxy) : (Qt(t.original, e) !== void 0 || e in t.original ? (Q(t), fe(t), t.assignedMap.set(e, !1)) : (t.assignedMap = (n = t.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), t.assignedMap.delete(e)), t.copy && delete t.copy[e], !0);
737
737
  }
738
738
  };
739
739
  function Fn(t) {
@@ -750,8 +750,8 @@ function Fn(t) {
750
750
  setMap: o === 3 ? new Map(e.entries()) : void 0
751
751
  };
752
752
  (r || "key" in t) && (a.key = r);
753
- const { proxy: u, revoke: c } = Proxy.revocable(o === 1 ? Object.assign([], a) : a, pi);
754
- if (i.revoke.push(c), hi.add(u), a.proxy = u, n) {
753
+ const { proxy: u, revoke: c } = Proxy.revocable(o === 1 ? Object.assign([], a) : a, yi);
754
+ if (i.revoke.push(c), pi.add(u), a.proxy = u, n) {
755
755
  const d = n;
756
756
  d.finalities.draft.push((f, l) => {
757
757
  var p, y;
@@ -775,7 +775,7 @@ function Fn(t) {
775
775
  return u;
776
776
  }
777
777
  Rn.createDraft = Fn;
778
- function Ds(t, e, n, r, i) {
778
+ function Us(t, e, n, r, i) {
779
779
  var s;
780
780
  const o = j(t), a = (s = o == null ? void 0 : o.original) !== null && s !== void 0 ? s : t, u = !!e.length;
781
781
  if (o != null && o.operated)
@@ -788,7 +788,7 @@ function Ds(t, e, n, r, i) {
788
788
  r && u ? [{ op: U.Replace, path: [], value: a }] : r
789
789
  ];
790
790
  }
791
- function Us(t, e) {
791
+ function Ls(t, e) {
792
792
  var n;
793
793
  const r = {
794
794
  draft: [],
@@ -806,7 +806,7 @@ function Us(t, e) {
806
806
  return [
807
807
  a,
808
808
  (u = []) => {
809
- const [c, d, f] = Ds(a, u, i, s, e.enableAutoFreeze);
809
+ const [c, d, f] = Us(a, u, i, s, e.enableAutoFreeze);
810
810
  return e.enablePatches ? [c, d, f] : c;
811
811
  }
812
812
  ];
@@ -826,7 +826,7 @@ function cn(t) {
826
826
  } else typeof o == "object" && o !== null && (t.value = o, t.isRoot = !1, cn(t));
827
827
  }), i && (t.isContainDraft || console.warn("The return value does not contain any draft, please use 'rawReturn()' to wrap the return value to improve performance."), r && console.warn("The return value contains drafts, please don't use 'rawReturn()' to wrap the return value."));
828
828
  }
829
- function yi(t) {
829
+ function bi(t) {
830
830
  var e;
831
831
  const n = j(t);
832
832
  if (!ae(t, n == null ? void 0 : n.options))
@@ -836,7 +836,7 @@ function yi(t) {
836
836
  return n.original;
837
837
  let i;
838
838
  function s() {
839
- i = r === 2 ? $n(t) ? new Map(t) : new (Object.getPrototypeOf(t)).constructor(t) : r === 3 ? Array.from(n.setMap.values()) : fi(t, n == null ? void 0 : n.options);
839
+ i = r === 2 ? $n(t) ? new Map(t) : new (Object.getPrototypeOf(t)).constructor(t) : r === 3 ? Array.from(n.setMap.values()) : li(t, n == null ? void 0 : n.options);
840
840
  }
841
841
  if (n) {
842
842
  n.finalized = !0;
@@ -850,7 +850,7 @@ function yi(t) {
850
850
  if (Un(i, (o, a) => {
851
851
  if (n && ye(be(n.original, o), a))
852
852
  return;
853
- const u = yi(a);
853
+ const u = bi(a);
854
854
  u !== a && (i === t && s(), at(i, o, u));
855
855
  }), r === 3) {
856
856
  const o = (e = n == null ? void 0 : n.original) !== null && e !== void 0 ? e : i;
@@ -861,9 +861,9 @@ function yi(t) {
861
861
  function vr(t) {
862
862
  if (!Ce(t))
863
863
  throw new Error(`current() is only used for Draft, parameter: ${t}`);
864
- return yi(t);
864
+ return bi(t);
865
865
  }
866
- const Ls = (t) => function e(n, r, i) {
866
+ const Fs = (t) => function e(n, r, i) {
867
867
  var s, o, a;
868
868
  if (typeof n == "function" && typeof r != "function")
869
869
  return function(S, ...I) {
@@ -890,7 +890,7 @@ const Ls = (t) => function e(n, r, i) {
890
890
  };
891
891
  if (!ae(f, g) && typeof f == "object" && f !== null)
892
892
  throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
893
- const [w, T] = Us(f, g);
893
+ const [w, T] = Ls(f, g);
894
894
  if (typeof r != "function") {
895
895
  if (!ae(f, g))
896
896
  throw new Error("Invalid base state: create() only supports plain objects, arrays, Set, Map or using mark() to mark the state as immutable.");
@@ -907,7 +907,7 @@ const Ls = (t) => function e(n, r, i) {
907
907
  if (!Ce(S)) {
908
908
  if (S !== void 0 && !ye(S, w) && (I != null && I.operated))
909
909
  throw new Error("Either the value is returned as a new non-draft value, or only the draft is modified without returning any value.");
910
- const q = S == null ? void 0 : S[As];
910
+ const q = S == null ? void 0 : S[ks];
911
911
  if (q) {
912
912
  const we = q[0];
913
913
  return g.strict && typeof S == "object" && S !== null && cn({
@@ -932,9 +932,9 @@ const Ls = (t) => function e(n, r, i) {
932
932
  return m instanceof Promise ? m.then(E, (S) => {
933
933
  throw sn(j(w)), S;
934
934
  }) : E(m);
935
- }, Ct = Ls();
935
+ }, Ct = Fs();
936
936
  Object.prototype.constructor.toString();
937
- function bi(t, e) {
937
+ function _i(t, e) {
938
938
  const n = Object.keys(t), r = Object.keys(e);
939
939
  return n.length === r.length && Object.keys(t).every((i) => e.hasOwnProperty(i));
940
940
  }
@@ -942,7 +942,7 @@ function Sr(t, e) {
942
942
  return Object.keys(t).length === Object.keys(e).length && Object.keys(t).every((n) => e.hasOwnProperty(n) && t[n] === e[n]);
943
943
  }
944
944
  function vt(t, e) {
945
- return typeof t != "object" || typeof e != "object" || t === null || e === null ? t === e : bi(t, e) ? Object.keys(t).every((n) => vt(t[n], e[n])) : !1;
945
+ return typeof t != "object" || typeof e != "object" || t === null || e === null ? t === e : _i(t, e) ? Object.keys(t).every((n) => vt(t[n], e[n])) : !1;
946
946
  }
947
947
  function Nn(t) {
948
948
  if (!Ze(t))
@@ -952,7 +952,7 @@ function Nn(t) {
952
952
  r !== void 0 && (e[n] = r);
953
953
  return e;
954
954
  }
955
- function _i(t, e) {
955
+ function gi(t, e) {
956
956
  if (!Ze(t) || !Ze(e))
957
957
  return e;
958
958
  const n = Object.assign({}, t);
@@ -964,14 +964,14 @@ function _i(t, e) {
964
964
  continue;
965
965
  }
966
966
  const i = Ze(t[r]) && Ze(e[r]);
967
- n[r] = i ? _i(t[r], e[r]) : e[r];
967
+ n[r] = i ? gi(t[r], e[r]) : e[r];
968
968
  }
969
969
  return n;
970
970
  }
971
971
  function Ze(t) {
972
972
  return typeof t == "object" && t !== null && !Array.isArray(t);
973
973
  }
974
- function Fs(t, e, n) {
974
+ function Ns(t, e, n) {
975
975
  if (!t || e.length === 0)
976
976
  return;
977
977
  let r = t || {};
@@ -992,7 +992,7 @@ function Or(t, e, n) {
992
992
  }
993
993
  r[e[e.length - 1]] = n;
994
994
  }
995
- function gi(t, e) {
995
+ function Ti(t, e) {
996
996
  if (!t || e.length === 0)
997
997
  return;
998
998
  const [n, ...r] = e;
@@ -1001,13 +1001,13 @@ function gi(t, e) {
1001
1001
  Array.isArray(t) ? t.splice(n, 1) : delete t[n];
1002
1002
  return;
1003
1003
  }
1004
- gi(t[n], r), Ns(t[n]) && delete t[n];
1004
+ Ti(t[n], r), Ks(t[n]) && delete t[n];
1005
1005
  }
1006
1006
  }
1007
- function Ns(t) {
1007
+ function Ks(t) {
1008
1008
  return t && Object.keys(t).length === 0;
1009
1009
  }
1010
- const Er = /ZULU|YEKT|YEKST|YAPT|YAKT|YAKST|XJT|WGT|WGST|WFT|WETDST|WET|WDT|WAT|WAST|WAKT|WADT|VUT|VOLT|VLAT|VLAST|VET|UZT|UZST|UYT|UYST|UTC|UT|ULAT|ULAST|UCT|TVT|TRUT|TOT|TMT|TKT|TJT|TFT|TAHT|SGT|SCT|SAST|SADT|RET|PYT|PYST|PWT|PST|PONT|PMST|PMDT|PKT|PKST|PHT|PGT|PETT|PETST|PET|PDT|OMST|OMSST|NZT|NZST|NZDT|NUT|NST|NPT|NOVT|NOVST|NFT|NDT|MYT|MVT|MUT|MUST|MST|MSK|MSD|MPT|MMT|MHT|MEZ|METDST|MET|MESZ|MEST|MDT|MAWT|MART|MAGT|MAGST|LKT|LINT|LIGT|LHST|LHDT|KST|KRAT|KRAST|KOST|KGT|KGST|KDT|JST|JAYT|IST|IRT|IRKT|IRKST|IOT|IDT|ICT|HST|HKT|GYT|GMT|GILT|GFT|GET|GEST|GAMT|GALT|FNT|FNST|FKT|FKST|FJT|FJST|FET|EST|EGT|EGST|EETDST|EET|EEST|EDT|EAT|EAST|EASST|DDUT|DAVT|CXT|CST|COT|CLT|CLST|CKT|CHUT|CHAST|CHADT|CETDST|CET|CEST|CDT|CCT|CAST|CADT|BTT|BST|BRT|BRST|BRA|BOT|BORT|BNT|BDT|BDST|AZT|AZST|AZOT|AZOST|AWST|AWSST|AST|ART|ARST|ANAT|ANAST|AMT|AMST|ALMT|ALMST|AKST|AKDT|AFT|AEST|AESST|AEDT|ADT|ACWST|ACT|ACST|ACSST|ACDT$/, Ks = {
1010
+ const Er = /ZULU|YEKT|YEKST|YAPT|YAKT|YAKST|XJT|WGT|WGST|WFT|WETDST|WET|WDT|WAT|WAST|WAKT|WADT|VUT|VOLT|VLAT|VLAST|VET|UZT|UZST|UYT|UYST|UTC|UT|ULAT|ULAST|UCT|TVT|TRUT|TOT|TMT|TKT|TJT|TFT|TAHT|SGT|SCT|SAST|SADT|RET|PYT|PYST|PWT|PST|PONT|PMST|PMDT|PKT|PKST|PHT|PGT|PETT|PETST|PET|PDT|OMST|OMSST|NZT|NZST|NZDT|NUT|NST|NPT|NOVT|NOVST|NFT|NDT|MYT|MVT|MUT|MUST|MST|MSK|MSD|MPT|MMT|MHT|MEZ|METDST|MET|MESZ|MEST|MDT|MAWT|MART|MAGT|MAGST|LKT|LINT|LIGT|LHST|LHDT|KST|KRAT|KRAST|KOST|KGT|KGST|KDT|JST|JAYT|IST|IRT|IRKT|IRKST|IOT|IDT|ICT|HST|HKT|GYT|GMT|GILT|GFT|GET|GEST|GAMT|GALT|FNT|FNST|FKT|FKST|FJT|FJST|FET|EST|EGT|EGST|EETDST|EET|EEST|EDT|EAT|EAST|EASST|DDUT|DAVT|CXT|CST|COT|CLT|CLST|CKT|CHUT|CHAST|CHADT|CETDST|CET|CEST|CDT|CCT|CAST|CADT|BTT|BST|BRT|BRST|BRA|BOT|BORT|BNT|BDT|BDST|AZT|AZST|AZOT|AZOST|AWST|AWSST|AST|ART|ARST|ANAT|ANAST|AMT|AMST|ALMT|ALMST|AKST|AKDT|AFT|AEST|AESST|AEDT|ADT|ACWST|ACT|ACST|ACSST|ACDT$/, qs = {
1011
1011
  ZULU: 0,
1012
1012
  YEKT: 18e3,
1013
1013
  YEKST: 21600,
@@ -1203,39 +1203,39 @@ const Er = /ZULU|YEKT|YEKST|YAPT|YAKT|YAKST|XJT|WGT|WGST|WFT|WETDST|WET|WDT|WAT|
1203
1203
  ACSST: 37800,
1204
1204
  ACDT: 37800
1205
1205
  };
1206
- function qs(t) {
1206
+ function Ws(t) {
1207
1207
  return new Date(t);
1208
1208
  }
1209
- function Ws(t) {
1209
+ function zs(t) {
1210
1210
  return /* @__PURE__ */ new Date(t + "Z");
1211
1211
  }
1212
- const zs = /^(\d+)[\./-](\d+)[\./-](\d+)$/;
1213
- function Vs(t) {
1214
- const e = t.match(zs);
1212
+ const Vs = /^(\d+)[\./-](\d+)[\./-](\d+)$/;
1213
+ function Gs(t) {
1214
+ const e = t.match(Vs);
1215
1215
  if (!e)
1216
1216
  return null;
1217
1217
  const [n, r, i, s] = e;
1218
1218
  return r <= 0 || i <= 0 || s <= 0 ? null : r > 999 ? new Date(Date.UTC(r, i - 1, s, 0, 0, 0, 0)) : new Date(Date.UTC(s, r - 1, i, 0, 0, 0, 0));
1219
1219
  }
1220
- function Gs(t) {
1220
+ function Bs(t) {
1221
1221
  const [e, n] = t.split(" ");
1222
1222
  return /* @__PURE__ */ new Date(e + "T" + n + "Z");
1223
1223
  }
1224
- function Bs(t) {
1224
+ function Qs(t) {
1225
1225
  const [e, n] = t.split(" ");
1226
1226
  return /* @__PURE__ */ new Date(e + "T" + n + "Z");
1227
1227
  }
1228
- function Qs(t) {
1228
+ function Hs(t) {
1229
1229
  return new Date(t);
1230
1230
  }
1231
- function Hs(t) {
1231
+ function Ys(t) {
1232
1232
  const e = /^(\w{3}) (\w{3}) (\d{2}) (\d{4})$/;
1233
1233
  if (!t.match(e))
1234
1234
  throw new Error(`Unable to parse \`${t}\` as a date.`);
1235
1235
  const r = /* @__PURE__ */ new Date(t + " UTC");
1236
1236
  return new Date(Date.UTC(r.getUTCFullYear(), r.getUTCMonth(), r.getUTCDate(), 0, 0, 0, 0));
1237
1237
  }
1238
- function Ys(t) {
1238
+ function Js(t) {
1239
1239
  const e = /^(.+T.+)([+-])(\d{2})$/, n = t.match(e);
1240
1240
  if (n) {
1241
1241
  const [, r, i, s] = n, o = `${r}${i}${s}:00`;
@@ -1243,14 +1243,14 @@ function Ys(t) {
1243
1243
  }
1244
1244
  return null;
1245
1245
  }
1246
- function Js(t) {
1246
+ function Zs(t) {
1247
1247
  const [e, n] = t.split(", "), [r, i, s] = e.split("/").map(Number), o = n.match(/(\d{1,2}):(\d{2}):(\d{2}) (AM|PM)/);
1248
1248
  if (!o)
1249
1249
  throw new Error(`Unable to parse time from: ${t}`);
1250
1250
  let [, a, u, c, d] = o;
1251
1251
  return a = Number(a), u = Number(u), c = Number(c), d === "PM" && a !== 12 ? a += 12 : d === "AM" && a === 12 && (a = 0), new Date(Date.UTC(s, r - 1, i, a, u, c));
1252
1252
  }
1253
- function Zs(t) {
1253
+ function Xs(t) {
1254
1254
  switch (t) {
1255
1255
  case "epoch":
1256
1256
  return /* @__PURE__ */ new Date(0);
@@ -1262,27 +1262,27 @@ function Zs(t) {
1262
1262
  return null;
1263
1263
  }
1264
1264
  }
1265
- function Xs(t) {
1265
+ function eo(t) {
1266
1266
  const e = t.match(Er);
1267
1267
  if (!e)
1268
1268
  return null;
1269
- const [n] = e, r = Ks[n], i = new Date(t.replace(Er, "Z"));
1269
+ const [n] = e, r = qs[n], i = new Date(t.replace(Er, "Z"));
1270
1270
  return new Date(i.getTime() - r * 1e3);
1271
1271
  }
1272
- const eo = [
1273
- Vs,
1274
- Bs,
1275
- Hs,
1276
- Js,
1272
+ const to = [
1273
+ Gs,
1277
1274
  Qs,
1278
- Ws,
1279
1275
  Ys,
1280
- Gs,
1281
- qs,
1282
1276
  Zs,
1283
- Xs
1277
+ Hs,
1278
+ zs,
1279
+ Js,
1280
+ Bs,
1281
+ Ws,
1282
+ Xs,
1283
+ eo
1284
1284
  ];
1285
- function to(t, e) {
1285
+ function no(t, e) {
1286
1286
  try {
1287
1287
  const n = t(e);
1288
1288
  return n instanceof Date && !isNaN(n.getTime()) ? n : null;
@@ -1291,14 +1291,14 @@ function to(t, e) {
1291
1291
  }
1292
1292
  }
1293
1293
  function dn(t) {
1294
- for (const e of eo) {
1295
- const n = to(e, t);
1294
+ for (const e of to) {
1295
+ const n = no(e, t);
1296
1296
  if (n)
1297
1297
  return n;
1298
1298
  }
1299
1299
  return null;
1300
1300
  }
1301
- function no(t) {
1301
+ function ro(t) {
1302
1302
  try {
1303
1303
  const e = JSON.parse(t);
1304
1304
  return typeof e == "string" ? dn(e) : null;
@@ -1313,7 +1313,7 @@ function Rt(t) {
1313
1313
  if (t instanceof Date)
1314
1314
  return t;
1315
1315
  if (typeof t == "string") {
1316
- const e = dn(t) || no(t) || dn(t.trim());
1316
+ const e = dn(t) || ro(t) || dn(t.trim());
1317
1317
  if (!e)
1318
1318
  throw new Error(`Unable to parse \`${t}\` as a date.`);
1319
1319
  return e;
@@ -1322,7 +1322,7 @@ function Rt(t) {
1322
1322
  throw new Error(`Invalid date value \`${t}\`. Expected a date, number, or string, got type ${typeof t}.`);
1323
1323
  }
1324
1324
  }
1325
- function ro(t) {
1325
+ function io(t) {
1326
1326
  return t.cardinality === "one";
1327
1327
  }
1328
1328
  function Kn(t) {
@@ -1358,7 +1358,7 @@ function Z(t, e, n) {
1358
1358
  let s = t.get(r);
1359
1359
  s || (s = /* @__PURE__ */ new Map(), t.set(r, s)), Z(s, i, n);
1360
1360
  }
1361
- function Ti(t, e, n) {
1361
+ function wi(t, e, n) {
1362
1362
  const r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
1363
1363
  for (const o of e) {
1364
1364
  let [a, u, c, d] = o;
@@ -1371,7 +1371,7 @@ function Ti(t, e, n) {
1371
1371
  }
1372
1372
  return { eav: r, aev: i, vae: s };
1373
1373
  }
1374
- function wi(t) {
1374
+ function mi(t) {
1375
1375
  const e = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
1376
1376
  for (const s of Object.values(t)) {
1377
1377
  const o = s["forward-identity"], [a, u, c] = o, d = s["reverse-identity"];
@@ -1382,7 +1382,7 @@ function wi(t) {
1382
1382
  }
1383
1383
  return { blobAttrs: e, primaryKeys: n, forwardIdents: r, revIdents: i };
1384
1384
  }
1385
- function mi(t) {
1385
+ function vi(t) {
1386
1386
  return {
1387
1387
  __type: t.__type,
1388
1388
  attrs: t.attrs,
@@ -1392,18 +1392,18 @@ function mi(t) {
1392
1392
  useDateObjects: t.useDateObjects
1393
1393
  };
1394
1394
  }
1395
- function vi(t) {
1395
+ function Si(t) {
1396
1396
  return St(t.attrs, t.triples, t.cardinalityInference, t.linkIndex, t.useDateObjects);
1397
1397
  }
1398
- function io(t, e) {
1398
+ function so(t, e) {
1399
1399
  return ze(t.eav, [e]) !== void 0;
1400
1400
  }
1401
1401
  function Wn(t) {
1402
- t.attrIndexes = wi(t.attrs);
1402
+ t.attrIndexes = mi(t.attrs);
1403
1403
  }
1404
1404
  function St(t, e, n, r, i) {
1405
- const s = Ti(t, e, i);
1406
- return s.useDateObjects = i, s.attrs = t, s.attrIndexes = wi(t), s.cardinalityInference = n, s.linkIndex = r, s.__type = "store", s;
1405
+ const s = wi(t, e, i);
1406
+ return s.useDateObjects = i, s.attrs = t, s.attrIndexes = mi(t), s.cardinalityInference = n, s.linkIndex = r, s.__type = "store", s;
1407
1407
  }
1408
1408
  function ut(t, e) {
1409
1409
  var n, r;
@@ -1432,21 +1432,21 @@ function ut(t, e) {
1432
1432
  return [i, ...a];
1433
1433
  }
1434
1434
  }
1435
- function Si(t, e) {
1435
+ function Oi(t, e) {
1436
1436
  const n = ut(t, e);
1437
1437
  if (!n)
1438
1438
  return;
1439
1439
  const [r, i, s] = n, o = We(t.attrs, i);
1440
1440
  o && (oe(t.eav, [r, i, s]), oe(t.aev, [i, r, s]), Kn(o) && oe(t.vae, [s, i, r]));
1441
1441
  }
1442
- let so = 0;
1443
- function Oi(t, e, n) {
1442
+ let oo = 0;
1443
+ function Ei(t, e, n) {
1444
1444
  const [r, i, s] = n;
1445
1445
  let o;
1446
1446
  const a = ze(t.ea, [r, i, s]);
1447
- return a && (o = a[3]), o || Date.now() * 10 + so++;
1447
+ return a && (o = a[3]), o || Date.now() * 10 + oo++;
1448
1448
  }
1449
- function Ei(t, e) {
1449
+ function Ai(t, e) {
1450
1450
  var n;
1451
1451
  const r = ut(t, e);
1452
1452
  if (!r)
@@ -1456,10 +1456,10 @@ function Ei(t, e) {
1456
1456
  if (!a)
1457
1457
  return;
1458
1458
  a["checked-data-type"] === "date" && t.useDateObjects && (o = Rt(o));
1459
- const u = ze(t.eav, [i, s, o]), c = (n = u == null ? void 0 : u[3]) !== null && n !== void 0 ? n : Oi(t, a, r), d = [i, s, o, c];
1460
- ro(a) ? (Z(t.eav, [i, s], /* @__PURE__ */ new Map([[o, d]])), Z(t.aev, [s, i], /* @__PURE__ */ new Map([[o, d]]))) : (Z(t.eav, [i, s, o], d), Z(t.aev, [s, i, o], d)), Kn(a) && Z(t.vae, [o, s, i], d);
1459
+ const u = ze(t.eav, [i, s, o]), c = (n = u == null ? void 0 : u[3]) !== null && n !== void 0 ? n : Ei(t, a, r), d = [i, s, o, c];
1460
+ io(a) ? (Z(t.eav, [i, s], /* @__PURE__ */ new Map([[o, d]])), Z(t.aev, [s, i], /* @__PURE__ */ new Map([[o, d]]))) : (Z(t.eav, [i, s, o], d), Z(t.aev, [s, i, o], d)), Kn(a) && Z(t.vae, [o, s, i], d);
1461
1461
  }
1462
- function oo(t, e) {
1462
+ function ao(t, e) {
1463
1463
  var n;
1464
1464
  const r = ut(t, e);
1465
1465
  if (!r)
@@ -1475,11 +1475,11 @@ function oo(t, e) {
1475
1475
  const c = (n = u.values().next()) === null || n === void 0 ? void 0 : n.value;
1476
1476
  if (!c)
1477
1477
  return;
1478
- const d = c[2], f = _i(d, o), l = [
1478
+ const d = c[2], f = gi(d, o), l = [
1479
1479
  i,
1480
1480
  s,
1481
1481
  f,
1482
- Oi(t, a, c)
1482
+ Ei(t, a, c)
1483
1483
  ];
1484
1484
  Z(t.eav, [i, s], /* @__PURE__ */ new Map([[f, l]]));
1485
1485
  }
@@ -1510,51 +1510,51 @@ function fn(t, e) {
1510
1510
  (!s || !w || ((f = w["reverse-identity"]) === null || f === void 0 ? void 0 : f[1]) === s) && (oe(t.eav, [y, b, g]), oe(t.aev, [b, y, g]), oe(t.vae, [g, b, y])), w && w["on-delete"] === "cascade" && ((l = w["reverse-identity"]) === null || l === void 0 ? void 0 : l[1]) === s && fn(t, [y, (p = w["forward-identity"]) === null || p === void 0 ? void 0 : p[1]]);
1511
1511
  }), ((r = t.vae.get(a)) === null || r === void 0 ? void 0 : r.size) === 0 && oe(t.vae, [a]);
1512
1512
  }
1513
- function Ai(t, e) {
1514
- const n = Ti(t.attrs, e, t.useDateObjects);
1513
+ function ki(t, e) {
1514
+ const n = wi(t.attrs, e, t.useDateObjects);
1515
1515
  Object.keys(n).forEach((r) => {
1516
1516
  t[r] = n[r];
1517
1517
  });
1518
1518
  }
1519
- function ao(t, [e]) {
1519
+ function uo(t, [e]) {
1520
1520
  t.attrs[e.id] = e, Wn(t);
1521
1521
  }
1522
- function ki(t) {
1522
+ function ji(t) {
1523
1523
  return X(t.eav, 3);
1524
1524
  }
1525
- function uo(t, [e]) {
1525
+ function co(t, [e]) {
1526
1526
  if (!t.attrs[e])
1527
1527
  return;
1528
- const n = ki(t).filter(([r, i]) => i !== e);
1529
- delete t.attrs[e], Wn(t), Ai(t, n);
1528
+ const n = ji(t).filter(([r, i]) => i !== e);
1529
+ delete t.attrs[e], Wn(t), ki(t, n);
1530
1530
  }
1531
- function co(t, [e]) {
1531
+ function fo(t, [e]) {
1532
1532
  const n = t.attrs[e.id];
1533
- n && (t.attrs[e.id] = Object.assign(Object.assign({}, n), e), Wn(t), Ai(t, ki(t)));
1533
+ n && (t.attrs[e.id] = Object.assign(Object.assign({}, n), e), Wn(t), ki(t, ji(t)));
1534
1534
  }
1535
- function fo(t, e) {
1535
+ function lo(t, e) {
1536
1536
  const [n, ...r] = e;
1537
1537
  switch (n) {
1538
1538
  case "add-triple":
1539
- Ei(t, r);
1539
+ Ai(t, r);
1540
1540
  break;
1541
1541
  case "deep-merge-triple":
1542
- oo(t, r);
1542
+ ao(t, r);
1543
1543
  break;
1544
1544
  case "retract-triple":
1545
- Si(t, r);
1545
+ Oi(t, r);
1546
1546
  break;
1547
1547
  case "delete-entity":
1548
1548
  fn(t, r);
1549
1549
  break;
1550
1550
  case "add-attr":
1551
- ao(t, r);
1551
+ uo(t, r);
1552
1552
  break;
1553
1553
  case "delete-attr":
1554
- uo(t, r);
1554
+ co(t, r);
1555
1555
  break;
1556
1556
  case "update-attr":
1557
- co(t, r);
1557
+ fo(t, r);
1558
1558
  break;
1559
1559
  case "restore-attr":
1560
1560
  break;
@@ -1609,13 +1609,13 @@ function bt(t, e, n) {
1609
1609
  }
1610
1610
  return s;
1611
1611
  }
1612
- function lo(t, e, n) {
1612
+ function ho(t, e, n) {
1613
1613
  let r = "";
1614
1614
  return t !== void 0 && (r += "e"), e !== void 0 && (r += "a"), n !== void 0 && (r += "v"), r;
1615
1615
  }
1616
- function ho(t, [e, n, r]) {
1616
+ function po(t, [e, n, r]) {
1617
1617
  var i, s;
1618
- switch (lo(e, n, r)) {
1618
+ switch (ho(e, n, r)) {
1619
1619
  case "e": {
1620
1620
  const a = t.eav.get(e);
1621
1621
  return X(a, 2);
@@ -1661,7 +1661,7 @@ function ho(t, [e, n, r]) {
1661
1661
  return X(t.eav, 3);
1662
1662
  }
1663
1663
  }
1664
- function po(t, e, n) {
1664
+ function yo(t, e, n) {
1665
1665
  var r;
1666
1666
  const i = {};
1667
1667
  for (const [s, o] of e.entries()) {
@@ -1675,19 +1675,19 @@ function Te(t, e, n) {
1675
1675
  var r;
1676
1676
  return (r = t.attrIndexes.forwardIdents.get(e)) === null || r === void 0 ? void 0 : r.get(n);
1677
1677
  }
1678
- function ji(t, e, n) {
1678
+ function Ci(t, e, n) {
1679
1679
  var r;
1680
1680
  return (r = t.attrIndexes.revIdents.get(e)) === null || r === void 0 ? void 0 : r.get(n);
1681
1681
  }
1682
- function yo(t, e) {
1682
+ function bo(t, e) {
1683
1683
  return t.attrIndexes.blobAttrs.get(e);
1684
1684
  }
1685
- function Ci(t, e) {
1685
+ function Pi(t, e) {
1686
1686
  var n;
1687
1687
  const r = t.attrIndexes.primaryKeys.get(e);
1688
1688
  return r || ((n = t.attrIndexes.forwardIdents.get(e)) === null || n === void 0 ? void 0 : n.get("id"));
1689
1689
  }
1690
- function bo(t, e) {
1690
+ function _o(t, e) {
1691
1691
  const n = ut(t, e);
1692
1692
  if (!n)
1693
1693
  return;
@@ -1695,7 +1695,7 @@ function bo(t, e) {
1695
1695
  if (We(t.attrs, i))
1696
1696
  return ze(t.eav, [r, i]);
1697
1697
  }
1698
- function _o(t, e) {
1698
+ function go(t, e) {
1699
1699
  const n = e.filter(([r, i, s, o, a]) => {
1700
1700
  if (r !== "add-triple" && r !== "deep-merge-triple")
1701
1701
  return !0;
@@ -1705,39 +1705,39 @@ function _o(t, e) {
1705
1705
  let c = !1;
1706
1706
  const d = We(t.attrs, s);
1707
1707
  if (d) {
1708
- const f = Ci(t, d["forward-identity"][1]);
1709
- c = !!bo(t, [i, f.id, i]);
1708
+ const f = Pi(t, d["forward-identity"][1]);
1709
+ c = !!_o(t, [i, f.id, i]);
1710
1710
  }
1711
1711
  return !(u === "create" && c || u === "update" && !c);
1712
1712
  });
1713
1713
  return Ct(t, (r) => {
1714
1714
  n.forEach((i) => {
1715
- fo(r, i);
1715
+ lo(r, i);
1716
1716
  });
1717
1717
  });
1718
1718
  }
1719
- function go(t) {
1719
+ function To(t) {
1720
1720
  return typeof t == "string" && t.startsWith("?");
1721
1721
  }
1722
- function To(t, e, n) {
1722
+ function wo(t, e, n) {
1723
1723
  if (n.hasOwnProperty(t)) {
1724
1724
  const r = n[t];
1725
- return Pi(r, e, n);
1725
+ return Ii(r, e, n);
1726
1726
  }
1727
1727
  return Object.assign(Object.assign({}, n), { [t]: e });
1728
1728
  }
1729
1729
  function Ar(t, e, n) {
1730
1730
  return t === e ? n : null;
1731
1731
  }
1732
- function wo(t) {
1732
+ function mo(t) {
1733
1733
  switch (typeof t) {
1734
1734
  case "string":
1735
- return t.startsWith("?") ? To : Ar;
1735
+ return t.startsWith("?") ? wo : Ar;
1736
1736
  default:
1737
1737
  return Ar;
1738
1738
  }
1739
1739
  }
1740
- const mo = [
1740
+ const vo = [
1741
1741
  "in",
1742
1742
  "$in",
1743
1743
  "$not",
@@ -1745,69 +1745,69 @@ const mo = [
1745
1745
  "$comparator"
1746
1746
  // covers all of $gt, $lt, etc.
1747
1747
  ];
1748
- function vo(t) {
1749
- for (const e of mo)
1748
+ function So(t) {
1749
+ for (const e of vo)
1750
1750
  if (t.hasOwnProperty(e))
1751
1751
  return !0;
1752
1752
  return !1;
1753
1753
  }
1754
- function Pi(t, e, n) {
1755
- return n ? typeof t == "object" ? vo(t) ? n : null : wo(t)(t, e, n) : null;
1754
+ function Ii(t, e, n) {
1755
+ return n ? typeof t == "object" ? So(t) ? n : null : mo(t)(t, e, n) : null;
1756
1756
  }
1757
- function So(t, e, n) {
1757
+ function Oo(t, e, n) {
1758
1758
  return t.reduce((r, i, s) => {
1759
1759
  const o = e[s];
1760
- return Pi(i, o, r);
1760
+ return Ii(i, o, r);
1761
1761
  }, n);
1762
1762
  }
1763
- function Oo(t, e, n) {
1764
- return ko(t, e, n).map((r) => So(e, r, n)).filter((r) => r);
1765
- }
1766
1763
  function Eo(t, e, n) {
1767
- return e.or ? e.or.patterns.flatMap((r) => ln(t, r, n)) : e.and ? e.and.patterns.reduce((r, i) => ln(t, i, r), n) : n.flatMap((r) => Oo(t, e, r));
1764
+ return jo(t, e, n).map((r) => Oo(e, r, n)).filter((r) => r);
1765
+ }
1766
+ function Ao(t, e, n) {
1767
+ return e.or ? e.or.patterns.flatMap((r) => ln(t, r, n)) : e.and ? e.and.patterns.reduce((r, i) => ln(t, i, r), n) : n.flatMap((r) => Eo(t, e, r));
1768
1768
  }
1769
1769
  function ln(t, e, n = [{}]) {
1770
- return e.reduce((r, i) => Eo(t, i, r), n);
1770
+ return e.reduce((r, i) => Ao(t, i, r), n);
1771
1771
  }
1772
1772
  function zn(t, e) {
1773
- return Array.isArray(e) ? e.map((n) => zn(t, n)) : go(e) ? t[e] : e;
1773
+ return Array.isArray(e) ? e.map((n) => zn(t, n)) : To(e) ? t[e] : e;
1774
1774
  }
1775
- function Ao(t, { find: e, where: n }) {
1775
+ function ko(t, { find: e, where: n }) {
1776
1776
  return ln(t, n).map((i) => zn(i, e));
1777
1777
  }
1778
- function ko(t, e, n) {
1779
- return ho(t, zn(n, e));
1778
+ function jo(t, e, n) {
1779
+ return po(t, zn(n, e));
1780
1780
  }
1781
- const jo = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
1781
+ const Co = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
1782
1782
  function Ne(t) {
1783
- return typeof t == "string" && jo.test(t);
1783
+ return typeof t == "string" && Co.test(t);
1784
1784
  }
1785
1785
  const W = [];
1786
1786
  for (let t = 0; t < 256; ++t)
1787
1787
  W.push((t + 256).toString(16).slice(1));
1788
- function Co(t, e = 0) {
1788
+ function Po(t, e = 0) {
1789
1789
  return (W[t[e + 0]] + W[t[e + 1]] + W[t[e + 2]] + W[t[e + 3]] + "-" + W[t[e + 4]] + W[t[e + 5]] + "-" + W[t[e + 6]] + W[t[e + 7]] + "-" + W[t[e + 8]] + W[t[e + 9]] + "-" + W[t[e + 10]] + W[t[e + 11]] + W[t[e + 12]] + W[t[e + 13]] + W[t[e + 14]] + W[t[e + 15]]).toLowerCase();
1790
1790
  }
1791
1791
  let Ht;
1792
- const Po = new Uint8Array(16);
1793
- function Io() {
1792
+ const Io = new Uint8Array(16);
1793
+ function Mo() {
1794
1794
  if (!Ht) {
1795
1795
  if (typeof crypto > "u" || !crypto.getRandomValues)
1796
1796
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1797
1797
  Ht = crypto.getRandomValues.bind(crypto);
1798
1798
  }
1799
- return Ht(Po);
1799
+ return Ht(Io);
1800
1800
  }
1801
- const Mo = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), kr = { randomUUID: Mo };
1802
- function Ro(t, e, n) {
1801
+ const Ro = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), kr = { randomUUID: Ro };
1802
+ function xo(t, e, n) {
1803
1803
  var i;
1804
1804
  if (kr.randomUUID && !t)
1805
1805
  return kr.randomUUID();
1806
1806
  t = t || {};
1807
- const r = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? Io();
1807
+ const r = t.random ?? ((i = t.rng) == null ? void 0 : i.call(t)) ?? Mo();
1808
1808
  if (r.length < 16)
1809
1809
  throw new Error("Random bytes length must be >= 16");
1810
- return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Co(r);
1810
+ return r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, Po(r);
1811
1811
  }
1812
1812
  function jr(t) {
1813
1813
  const e = t.replace(/-/g, ""), n = [];
@@ -1815,7 +1815,7 @@ function jr(t) {
1815
1815
  n.push(parseInt(e.substring(r, r + 2), 16));
1816
1816
  return n;
1817
1817
  }
1818
- function xo(t, e) {
1818
+ function $o(t, e) {
1819
1819
  for (let n = 0; n < t.length; n++) {
1820
1820
  if (t[n] < e[n])
1821
1821
  return -1;
@@ -1824,17 +1824,17 @@ function xo(t, e) {
1824
1824
  }
1825
1825
  return 0;
1826
1826
  }
1827
- function $o(t, e) {
1828
- return xo(jr(t), jr(e));
1827
+ function Do(t, e) {
1828
+ return $o(jr(t), jr(e));
1829
1829
  }
1830
1830
  function K() {
1831
- return Ro();
1831
+ return xo();
1832
1832
  }
1833
- function Do(t, e) {
1833
+ function Uo(t, e) {
1834
1834
  return t.localeCompare(e);
1835
1835
  }
1836
- function Uo() {
1837
- let t = Do;
1836
+ function Lo() {
1837
+ let t = Uo;
1838
1838
  if (typeof Intl == "object" && Intl.hasOwnProperty("Collator"))
1839
1839
  try {
1840
1840
  t = Intl.Collator("en-US").compare;
@@ -1842,10 +1842,10 @@ function Uo() {
1842
1842
  }
1843
1843
  return t;
1844
1844
  }
1845
- const Lo = Uo();
1846
- let Fo = 0;
1845
+ const Fo = Lo();
1846
+ let No = 0;
1847
1847
  function rt(t) {
1848
- return xt(`_${t}`, Fo++);
1848
+ return xt(`_${t}`, No++);
1849
1849
  }
1850
1850
  function xt(t, e) {
1851
1851
  return `?${t}-${e}`;
@@ -1855,28 +1855,28 @@ class Ke extends Error {
1855
1855
  super(e), this.name = "AttrNotFoundError";
1856
1856
  }
1857
1857
  }
1858
- function No(t, e) {
1859
- const n = Ci(t, e);
1858
+ function Ko(t, e) {
1859
+ const n = Pi(t, e);
1860
1860
  if (!n)
1861
1861
  throw new Ke(`Could not find id attr for ${e}`);
1862
1862
  return n;
1863
1863
  }
1864
1864
  function Cr(t, e, n, r) {
1865
- return [Ko(t, e, n, r)];
1865
+ return [qo(t, e, n, r)];
1866
1866
  }
1867
- function Ko(t, e, n, r) {
1867
+ function qo(t, e, n, r) {
1868
1868
  return [
1869
1869
  t(n, r),
1870
- No(e, n).id,
1870
+ Ko(e, n).id,
1871
1871
  t(n, r),
1872
1872
  t("time", r)
1873
1873
  ];
1874
1874
  }
1875
- function qo(t, e, n) {
1875
+ function Wo(t, e, n) {
1876
1876
  return t.map((r) => r === e ? n : r);
1877
1877
  }
1878
- function Ii(t, e, n, r, i) {
1879
- const s = Te(e, n, i), o = ji(e, n, i), a = s || o;
1878
+ function Mi(t, e, n, r, i) {
1879
+ const s = Te(e, n, i), o = Ci(e, n, i), a = s || o;
1880
1880
  if (!a)
1881
1881
  throw new Ke(`Could not find attr for ${[n, i]}`);
1882
1882
  if (a["value-type"] !== "ref")
@@ -1904,7 +1904,7 @@ function Pr(t, e) {
1904
1904
  return typeof o != "string" ? !1 : i.test(o);
1905
1905
  };
1906
1906
  }
1907
- function Wo(t, e) {
1907
+ function zo(t, e) {
1908
1908
  if (typeof e != "object" || e.hasOwnProperty("$in") || e.hasOwnProperty("in"))
1909
1909
  return e;
1910
1910
  const n = t["checked-data-type"] === "date";
@@ -1964,8 +1964,8 @@ function Wo(t, e) {
1964
1964
  }
1965
1965
  return e;
1966
1966
  }
1967
- function zo(t, e, n, r, i, s) {
1968
- const o = Te(e, n, i), a = ji(e, n, i), u = o || a;
1967
+ function Vo(t, e, n, r, i, s) {
1968
+ const o = Te(e, n, i), a = Ci(e, n, i), u = o || a;
1969
1969
  if (!u)
1970
1970
  throw new Ke(`No attr for etype = ${n} label = ${i}`);
1971
1971
  if (s != null && s.hasOwnProperty("$isNull")) {
@@ -1982,31 +1982,31 @@ function zo(t, e, n, r, i, s) {
1982
1982
  return o ? [
1983
1983
  t(n, r),
1984
1984
  u.id,
1985
- Wo(u, s),
1985
+ zo(u, s),
1986
1986
  rt("time")
1987
1987
  ] : [s, u.id, t(n, r), rt("time")];
1988
1988
  }
1989
- function Vo(t, e, n, r, i) {
1989
+ function Go(t, e, n, r, i) {
1990
1990
  const [s, o, a] = i.reduce((u, c) => {
1991
- const [d, f, l] = u, [p, y, b] = Ii(t, e, d, f, c);
1991
+ const [d, f, l] = u, [p, y, b] = Mi(t, e, d, f, c);
1992
1992
  return [p, y, [...l, b]];
1993
1993
  }, [n, r, []]);
1994
1994
  return [s, o, a];
1995
1995
  }
1996
1996
  function hn(t, e, n, r, i, s) {
1997
- const o = i.slice(0, i.length - 1), a = i[i.length - 1], [u, c, d] = Vo(t, e, n, r, o), f = zo(t, e, u, c, a, s);
1997
+ const o = i.slice(0, i.length - 1), a = i[i.length - 1], [u, c, d] = Go(t, e, n, r, o), f = Vo(t, e, u, c, a, s);
1998
1998
  return d.concat([f]);
1999
1999
  }
2000
- function Go(t, e) {
2000
+ function Bo(t, e) {
2001
2001
  return e ? [e].concat(t) : t;
2002
2002
  }
2003
- function Bo([t, e]) {
2003
+ function Qo([t, e]) {
2004
2004
  return t === "or" && Array.isArray(e);
2005
2005
  }
2006
- function Qo([t, e]) {
2006
+ function Ho([t, e]) {
2007
2007
  return t === "and" && Array.isArray(e);
2008
2008
  }
2009
- function Ho(t, e, n) {
2009
+ function Yo(t, e, n) {
2010
2010
  return (r, i) => {
2011
2011
  const s = t(r, i);
2012
2012
  return e == s ? s : `${s}-${n}`;
@@ -2014,25 +2014,25 @@ function Ho(t, e, n) {
2014
2014
  }
2015
2015
  function Ir(t, e, n, r, i, s) {
2016
2016
  const o = t(r, i), a = s.map((u, c) => {
2017
- const d = Ho(t, o, c);
2018
- return Mi(d, n, r, i, u);
2017
+ const d = Yo(t, o, c);
2018
+ return Ri(d, n, r, i, u);
2019
2019
  });
2020
2020
  return { [e]: { patterns: a, joinSym: o } };
2021
2021
  }
2022
- function Yo(t) {
2022
+ function Jo(t) {
2023
2023
  const e = [];
2024
2024
  for (let n = 1; n <= t.length; n++)
2025
2025
  e.push(t.slice(0, n));
2026
2026
  return e;
2027
2027
  }
2028
2028
  function Mr(t, e, n, r, i) {
2029
- return Yo(i).map((s) => hn(t, e, n, r, s, { $isNull: !0 }));
2029
+ return Jo(i).map((s) => hn(t, e, n, r, s, { $isNull: !0 }));
2030
2030
  }
2031
- function Mi(t, e, n, r, i) {
2031
+ function Ri(t, e, n, r, i) {
2032
2032
  return Object.entries(i).flatMap(([s, o]) => {
2033
- if (Bo([s, o]))
2034
- return Ir(t, "or", e, n, r, o);
2035
2033
  if (Qo([s, o]))
2034
+ return Ir(t, "or", e, n, r, o);
2035
+ if (Ho([s, o]))
2036
2036
  return Ir(t, "and", e, n, r, o);
2037
2037
  if (s === "$entityIdStartsWith")
2038
2038
  return [];
@@ -2058,25 +2058,25 @@ function Mi(t, e, n, r, i) {
2058
2058
  ] : hn(t, e, n, r, a, o);
2059
2059
  });
2060
2060
  }
2061
- function Jo(t, e, n, r) {
2061
+ function Zo(t, e, n, r) {
2062
2062
  const i = xt;
2063
- return r ? Mi(i, t, e, n, r).concat(Cr(i, t, e, n)) : Cr(i, t, e, n);
2063
+ return r ? Ri(i, t, e, n, r).concat(Cr(i, t, e, n)) : Cr(i, t, e, n);
2064
2064
  }
2065
- function Zo(t, e, n) {
2065
+ function Xo(t, e, n) {
2066
2066
  return [t(e, n), t("time", n)];
2067
2067
  }
2068
- function Xo(t, e, n, r, i, s) {
2069
- const [o, a, u, c, d] = Ii(t, e, n, r, i), f = qo(u, t(n, r), s);
2068
+ function ea(t, e, n, r, i, s) {
2069
+ const [o, a, u, c, d] = Mi(t, e, n, r, i), f = Wo(u, t(n, r), s);
2070
2070
  return [o, a, f, c, d];
2071
2071
  }
2072
- function ea(t, e, { etype: n, level: r, form: i }, s) {
2072
+ function ta(t, e, { etype: n, level: r, form: i }, s) {
2073
2073
  const o = Object.keys(i).filter((a) => a !== "$");
2074
2074
  return o.length ? Object.entries(s).map(function([u, c]) {
2075
2075
  return o.map(function(l) {
2076
2076
  var p, y, b;
2077
2077
  const g = !!(e.cardinalityInference && (!((b = (y = (p = e.linkIndex) === null || p === void 0 ? void 0 : p[n]) === null || y === void 0 ? void 0 : y[l]) === null || b === void 0) && b.isSingular));
2078
2078
  try {
2079
- const [w, T, m] = Xo(t, e, n, r, l, u), E = xi(e, {
2079
+ const [w, T, m] = ea(t, e, n, r, l, u), E = $i(e, {
2080
2080
  etype: w,
2081
2081
  level: T,
2082
2082
  form: i[l],
@@ -2093,11 +2093,11 @@ function ea(t, e, { etype: n, level: r, form: i }, s) {
2093
2093
  }, c);
2094
2094
  }) : Object.values(s);
2095
2095
  }
2096
- function ta(t, e, n) {
2097
- return n === "string" ? Lo(t, e) : t > e ? 1 : -1;
2096
+ function na(t, e, n) {
2097
+ return n === "string" ? Fo(t, e) : t > e ? 1 : -1;
2098
2098
  }
2099
2099
  function Xe(t, e, n, r, i) {
2100
- return e === r || e == null && r == null ? $o(t, n) : r == null ? 1 : e == null ? -1 : ta(e, r, i);
2100
+ return e === r || e == null && r == null ? Do(t, n) : r == null ? 1 : e == null ? -1 : na(e, r, i);
2101
2101
  }
2102
2102
  function Pt([t, e], [n, r], i) {
2103
2103
  return Xe(t, e, n, r, i);
@@ -2105,7 +2105,7 @@ function Pt([t, e], [n, r], i) {
2105
2105
  function pn(t) {
2106
2106
  return t == null ? t : new Date(t).getTime();
2107
2107
  }
2108
- function na(t, e, n, r) {
2108
+ function ra(t, e, n, r) {
2109
2109
  var i;
2110
2110
  const [s, o, a, u] = t, c = n === "desc" ? 1 : -1;
2111
2111
  if (((i = e["forward-identity"]) === null || i === void 0 ? void 0 : i[2]) === "id")
@@ -2113,24 +2113,24 @@ function na(t, e, n, r) {
2113
2113
  const [d, f] = r, l = e["checked-data-type"], p = l === "date" ? pn(f) : f, y = l === "date" ? pn(a) : a;
2114
2114
  return Pt([d, p], [s, y], l) === c;
2115
2115
  }
2116
- function ra(t, e) {
2116
+ function ia(t, e) {
2117
2117
  const n = e[1];
2118
2118
  return t.attrs[n];
2119
2119
  }
2120
- function ia(t, e, n) {
2120
+ function sa(t, e, n) {
2121
2121
  const r = Object.keys(n)[0];
2122
2122
  return Te(t, e, r);
2123
2123
  }
2124
- function sa(t, e, n, r) {
2124
+ function oa(t, e, n, r) {
2125
2125
  if (n)
2126
- return ra(t, n);
2126
+ return ia(t, n);
2127
2127
  if (r)
2128
- return ia(t, e, r);
2128
+ return sa(t, e, r);
2129
2129
  }
2130
- function oa(t, e, n) {
2130
+ function aa(t, e, n) {
2131
2131
  var r, i;
2132
2132
  if (!Array.isArray(n.fields))
2133
- return yo(t, e);
2133
+ return bo(t, e);
2134
2134
  const s = /* @__PURE__ */ new Map();
2135
2135
  for (const o of n.fields) {
2136
2136
  const a = Te(t, e, o), u = (r = a == null ? void 0 : a["forward-identity"]) === null || r === void 0 ? void 0 : r[2];
@@ -2142,11 +2142,11 @@ function oa(t, e, n) {
2142
2142
  }
2143
2143
  return s;
2144
2144
  }
2145
- function aa(t, { etype: e, pageInfo: n, dq: r, form: i }) {
2145
+ function ua(t, { etype: e, pageInfo: n, dq: r, form: i }) {
2146
2146
  var s, o;
2147
- const a = (s = i == null ? void 0 : i.$) === null || s === void 0 ? void 0 : s.order, u = Ri(i), c = ua(i);
2148
- let d = Ao(t, r);
2149
- const f = n == null ? void 0 : n["start-cursor"], l = sa(t, e, f, a);
2147
+ const a = (s = i == null ? void 0 : i.$) === null || s === void 0 ? void 0 : s.order, u = xi(i), c = ca(i);
2148
+ let d = ko(t, r);
2149
+ const f = n == null ? void 0 : n["start-cursor"], l = oa(t, e, f, a);
2150
2150
  if (l && ((o = l == null ? void 0 : l["forward-identity"]) === null || o === void 0 ? void 0 : o[2]) !== "id") {
2151
2151
  const b = l["checked-data-type"] === "date", g = l.id;
2152
2152
  d = d.map(([w]) => {
@@ -2161,31 +2161,31 @@ function aa(t, { etype: e, pageInfo: n, dq: r, form: i }) {
2161
2161
  return Pt(w, g, l == null ? void 0 : l["checked-data-type"]);
2162
2162
  });
2163
2163
  let p = {};
2164
- const y = oa(t, e, r);
2164
+ const y = aa(t, e, r);
2165
2165
  for (const b of d) {
2166
2166
  const [g] = b;
2167
- if (p[g] || !u && f && l && na(f, l, c, b))
2167
+ if (p[g] || !u && f && l && ra(f, l, c, b))
2168
2168
  continue;
2169
- const w = po(t, y, g);
2169
+ const w = yo(t, y, g);
2170
2170
  w && (p[g] = w);
2171
2171
  }
2172
2172
  return p;
2173
2173
  }
2174
- function ua(t) {
2174
+ function ca(t) {
2175
2175
  var e;
2176
2176
  const n = (e = t.$) === null || e === void 0 ? void 0 : e.order;
2177
2177
  return n && n[Object.keys(n)[0]] || "asc";
2178
2178
  }
2179
- function Ri(t) {
2179
+ function xi(t) {
2180
2180
  var e, n, r;
2181
2181
  const i = (e = t.$) === null || e === void 0 ? void 0 : e.offset, s = (n = t.$) === null || n === void 0 ? void 0 : n.before, o = (r = t.$) === null || r === void 0 ? void 0 : r.after;
2182
2182
  return !i && !s && !o;
2183
2183
  }
2184
- function ca(t, { etype: e, level: n, form: r, join: i, pageInfo: s }) {
2184
+ function da(t, { etype: e, level: n, form: r, join: i, pageInfo: s }) {
2185
2185
  var o, a, u, c, d;
2186
- if (!Ri(r) && (!s || !s["start-cursor"]))
2186
+ if (!xi(r) && (!s || !s["start-cursor"]))
2187
2187
  return [];
2188
- const f = Go(Jo(t, e, n, (o = r.$) === null || o === void 0 ? void 0 : o.where), i), l = Zo(xt, e, n), p = (a = r.$) === null || a === void 0 ? void 0 : a.fields, y = aa(t, {
2188
+ const f = Bo(Zo(t, e, n, (o = r.$) === null || o === void 0 ? void 0 : o.where), i), l = Xo(xt, e, n), p = (a = r.$) === null || a === void 0 ? void 0 : a.fields, y = ua(t, {
2189
2189
  etype: e,
2190
2190
  pageInfo: s,
2191
2191
  form: r,
@@ -2198,20 +2198,20 @@ function ca(t, { etype: e, level: n, form: r, join: i, pageInfo: s }) {
2198
2198
  }
2199
2199
  return y;
2200
2200
  }
2201
- function da(t, e) {
2201
+ function fa(t, e) {
2202
2202
  try {
2203
- return ca(t, e);
2203
+ return da(t, e);
2204
2204
  } catch (n) {
2205
2205
  if (n instanceof Ke)
2206
2206
  return {};
2207
2207
  throw n;
2208
2208
  }
2209
2209
  }
2210
- function xi(t, e) {
2211
- const n = da(t, e);
2212
- return ea(xt, t, e, n);
2210
+ function $i(t, e) {
2211
+ const n = fa(t, e);
2212
+ return ta(xt, t, e, n);
2213
2213
  }
2214
- function fa(t) {
2214
+ function la(t) {
2215
2215
  const e = {};
2216
2216
  for (const [n, r] of Object.entries(t))
2217
2217
  e[n] = {
@@ -2222,18 +2222,18 @@ function fa(t) {
2222
2222
  };
2223
2223
  return e;
2224
2224
  }
2225
- function $i({ store: t, pageInfo: e, aggregate: n }, r) {
2225
+ function Di({ store: t, pageInfo: e, aggregate: n }, r) {
2226
2226
  const s = { data: Object.keys(r).reduce(function(a, u) {
2227
- return n != null && n[u] || u === "$$ruleParams" || (a[u] = xi(t, {
2227
+ return n != null && n[u] || u === "$$ruleParams" || (a[u] = $i(t, {
2228
2228
  etype: u,
2229
2229
  form: r[u],
2230
2230
  level: 0,
2231
2231
  pageInfo: e == null ? void 0 : e[u]
2232
2232
  })), a;
2233
2233
  }, {}) };
2234
- return e && (s.pageInfo = fa(e)), n && (s.aggregate = n), s;
2234
+ return e && (s.pageInfo = la(e)), n && (s.aggregate = n), s;
2235
2235
  }
2236
- function la() {
2236
+ function ha() {
2237
2237
  const e = {
2238
2238
  __etype: 1,
2239
2239
  __ops: 1,
@@ -2247,7 +2247,7 @@ function la() {
2247
2247
  };
2248
2248
  return new Set(Object.keys(e));
2249
2249
  }
2250
- const ha = la();
2250
+ const pa = ha();
2251
2251
  function yn(t, e, n) {
2252
2252
  const r = {
2253
2253
  __etype: t,
@@ -2259,7 +2259,7 @@ function yn(t, e, n) {
2259
2259
  return n;
2260
2260
  if (s === "__etype")
2261
2261
  return t;
2262
- if (ha.has(s))
2262
+ if (pa.has(s))
2263
2263
  return (o, a) => yn(t, e, [
2264
2264
  ...n,
2265
2265
  a ? [s, t, e, o, a] : [s, t, e, o]
@@ -2267,17 +2267,17 @@ function yn(t, e, n) {
2267
2267
  }
2268
2268
  });
2269
2269
  }
2270
- function Dc(t, e) {
2270
+ function Lc(t, e) {
2271
2271
  return `lookup__${t}__${JSON.stringify(e)}`;
2272
2272
  }
2273
2273
  function It(t) {
2274
2274
  return t.startsWith("lookup__");
2275
2275
  }
2276
- function Di(t) {
2276
+ function Ui(t) {
2277
2277
  const [e, n, ...r] = t.split("__");
2278
2278
  return [n, JSON.parse(r.join("__"))];
2279
2279
  }
2280
- function pa(t) {
2280
+ function ya(t) {
2281
2281
  return new Proxy({
2282
2282
  __etype: t
2283
2283
  }, {
@@ -2285,22 +2285,22 @@ function pa(t) {
2285
2285
  if (n === "__etype")
2286
2286
  return t;
2287
2287
  const r = n;
2288
- return It(r) ? yn(t, Di(r), []) : yn(t, r, []);
2288
+ return It(r) ? yn(t, Ui(r), []) : yn(t, r, []);
2289
2289
  }
2290
2290
  });
2291
2291
  }
2292
2292
  function Vn() {
2293
2293
  return new Proxy({}, {
2294
2294
  get(t, e) {
2295
- return pa(e);
2295
+ return ya(e);
2296
2296
  }
2297
2297
  });
2298
2298
  }
2299
- const Uc = Vn();
2300
- function ya(t) {
2299
+ const Fc = Vn();
2300
+ function ba(t) {
2301
2301
  return t.__ops;
2302
2302
  }
2303
- function ba(t, e) {
2303
+ function _a(t, e) {
2304
2304
  const { attrIdMap: n, refSwapAttrIds: r } = t, i = [];
2305
2305
  for (const o of e) {
2306
2306
  const a = n[o];
@@ -2334,7 +2334,7 @@ function ke(t, e, n) {
2334
2334
  return o === e && a === n;
2335
2335
  });
2336
2336
  }
2337
- function _a(t) {
2337
+ function ga(t) {
2338
2338
  if (Array.isArray(t))
2339
2339
  return t;
2340
2340
  const e = Object.entries(t);
@@ -2353,7 +2353,7 @@ function _n(t) {
2353
2353
  throw new Error(`${t} is not a valid lookup attribute.`);
2354
2354
  return e;
2355
2355
  }
2356
- function ga(t, e, n) {
2356
+ function Ta(t, e, n) {
2357
2357
  if (!bn(t, e, n))
2358
2358
  return G(t, e, n);
2359
2359
  const r = _n(n), i = G(t, e, r) || ke(t, e, r);
@@ -2362,18 +2362,18 @@ function ga(t, e, n) {
2362
2362
  return i;
2363
2363
  }
2364
2364
  function gn(t) {
2365
- return typeof t == "string" && !It(t) ? null : typeof t == "string" && It(t) ? Di(t) : _a(t);
2365
+ return typeof t == "string" && !It(t) ? null : typeof t == "string" && It(t) ? Ui(t) : ga(t);
2366
2366
  }
2367
2367
  function ee(t, e, n) {
2368
2368
  const r = gn(n);
2369
2369
  if (r === null)
2370
2370
  return n;
2371
- const [i, s] = r, o = ga(t, e, i);
2371
+ const [i, s] = r, o = Ta(t, e, i);
2372
2372
  if (!o || !o["unique?"])
2373
2373
  throw new Error(`${i} is not a unique attribute.`);
2374
2374
  return [o.id, s];
2375
2375
  }
2376
- function Ui(t, e, n, r) {
2376
+ function Li(t, e, n, r) {
2377
2377
  const i = ee(t, e, n);
2378
2378
  return Array.isArray(i) ? [[
2379
2379
  "add-triple",
@@ -2382,7 +2382,7 @@ function Ui(t, e, n, r) {
2382
2382
  i
2383
2383
  ]].concat(r) : r;
2384
2384
  }
2385
- function Ta({ attrs: t }, [e, n, r]) {
2385
+ function wa({ attrs: t }, [e, n, r]) {
2386
2386
  const i = Object.entries(r).flatMap(([s, o]) => {
2387
2387
  const a = Array.isArray(o) ? o : [o], u = G(t, e, s), c = ke(t, e, s);
2388
2388
  return a.map((d) => u ? [
@@ -2397,9 +2397,9 @@ function Ta({ attrs: t }, [e, n, r]) {
2397
2397
  ee(t, e, n)
2398
2398
  ]);
2399
2399
  });
2400
- return Ui(t, e, n, i);
2400
+ return Li(t, e, n, i);
2401
2401
  }
2402
- function wa({ attrs: t }, [e, n, r]) {
2402
+ function ma({ attrs: t }, [e, n, r]) {
2403
2403
  const i = Object.entries(r).flatMap(([s, o]) => {
2404
2404
  const a = Array.isArray(o) ? o : [o], u = G(t, e, s), c = ke(t, e, s);
2405
2405
  return a.map((d) => u ? [
@@ -2414,9 +2414,9 @@ function wa({ attrs: t }, [e, n, r]) {
2414
2414
  ee(t, e, n)
2415
2415
  ]);
2416
2416
  });
2417
- return Ui(t, e, n, i);
2417
+ return Li(t, e, n, i);
2418
2418
  }
2419
- function ma(t, e, n) {
2419
+ function va(t, e, n) {
2420
2420
  if (Array.isArray(n)) {
2421
2421
  const [r, i] = n;
2422
2422
  for (const s of t || []) {
@@ -2438,18 +2438,18 @@ function ma(t, e, n) {
2438
2438
  }
2439
2439
  return !1;
2440
2440
  }
2441
- function Li({ stores: t, attrs: e }, [n, r, i, s]) {
2442
- return (s == null ? void 0 : s.upsert) === !1 ? { mode: "update" } : (s == null ? void 0 : s.upsert) === !0 ? null : ma(t, n, r) ? { mode: "update" } : null;
2441
+ function Fi({ stores: t, attrs: e }, [n, r, i, s]) {
2442
+ return (s == null ? void 0 : s.upsert) === !1 ? { mode: "update" } : (s == null ? void 0 : s.upsert) === !0 ? null : va(t, n, r) ? { mode: "update" } : null;
2443
2443
  }
2444
- function va(t, e) {
2444
+ function Sa(t, e) {
2445
2445
  const { stores: n, attrs: r } = t, [i, s, o, a] = e, u = Nn(o), c = ee(r, i, s);
2446
2446
  return [["id", c]].concat(Object.entries(u)).map(([f, l]) => {
2447
2447
  const p = G(r, i, f);
2448
2448
  return p["checked-data-type"] === "date" && t.useDateObjects && (l = Rt(l)), ["add-triple", c, p.id, l, { mode: "create" }];
2449
2449
  });
2450
2450
  }
2451
- function Sa(t, e) {
2452
- const { stores: n, attrs: r } = t, [i, s, o, a] = e, u = Nn(o), c = ee(r, i, s), d = Li(t, [i, c, o, a]);
2451
+ function Oa(t, e) {
2452
+ const { stores: n, attrs: r } = t, [i, s, o, a] = e, u = Nn(o), c = ee(r, i, s), d = Fi(t, [i, c, o, a]);
2453
2453
  return [["id", c]].concat(Object.entries(u)).map(([l, p]) => {
2454
2454
  const y = G(r, i, l);
2455
2455
  return y["checked-data-type"] === "date" && t.useDateObjects && (p = Rt(p)), [
@@ -2461,11 +2461,11 @@ function Sa(t, e) {
2461
2461
  ];
2462
2462
  });
2463
2463
  }
2464
- function Oa({ attrs: t }, [e, n]) {
2464
+ function Ea({ attrs: t }, [e, n]) {
2465
2465
  return [["delete-entity", ee(t, e, n), e]];
2466
2466
  }
2467
- function Ea(t, e) {
2468
- const { stores: n, attrs: r } = t, [i, s, o, a] = e, u = Nn(o), c = ee(r, i, s), d = Li(t, [i, c, o, a]), f = Object.entries(u).map(([p, y]) => {
2467
+ function Aa(t, e) {
2468
+ const { stores: n, attrs: r } = t, [i, s, o, a] = e, u = Nn(o), c = ee(r, i, s), d = Fi(t, [i, c, o, a]), f = Object.entries(u).map(([p, y]) => {
2469
2469
  const b = G(r, i, p);
2470
2470
  return [
2471
2471
  "deep-merge-triple",
@@ -2483,38 +2483,38 @@ function Ea(t, e) {
2483
2483
  ...d ? [d] : []
2484
2484
  ]].concat(f);
2485
2485
  }
2486
- function Aa({ attrs: t }, [e, n, r]) {
2486
+ function ka({ attrs: t }, [e, n, r]) {
2487
2487
  return [["rule-params", ee(t, e, n), e, r]];
2488
2488
  }
2489
- function ka(t) {
2489
+ function ja(t) {
2490
2490
  const [e, n, r, i, s] = t;
2491
2491
  if (!i)
2492
2492
  return t;
2493
2493
  const o = Object.assign({}, i);
2494
2494
  return delete o.id, [e, n, r, o, ...s ? [s] : []];
2495
2495
  }
2496
- function ja(t, e) {
2497
- const [n, ...r] = ka(e);
2496
+ function Ca(t, e) {
2497
+ const [n, ...r] = ja(e);
2498
2498
  switch (n) {
2499
2499
  case "merge":
2500
- return Ea(t, r);
2500
+ return Aa(t, r);
2501
2501
  case "create":
2502
- return va(t, r);
2503
- case "update":
2504
2502
  return Sa(t, r);
2503
+ case "update":
2504
+ return Oa(t, r);
2505
2505
  case "link":
2506
- return Ta(t, r);
2507
- case "unlink":
2508
2506
  return wa(t, r);
2507
+ case "unlink":
2508
+ return ma(t, r);
2509
2509
  case "delete":
2510
- return Oa(t, r);
2510
+ return Ea(t, r);
2511
2511
  case "ruleParams":
2512
- return Aa(t, r);
2512
+ return ka(t, r);
2513
2513
  default:
2514
2514
  throw new Error(`unsupported action ${n}`);
2515
2515
  }
2516
2516
  }
2517
- function Ca(t) {
2517
+ function Pa(t) {
2518
2518
  switch (t) {
2519
2519
  case "string":
2520
2520
  case "date":
@@ -2525,14 +2525,14 @@ function Ca(t) {
2525
2525
  return;
2526
2526
  }
2527
2527
  }
2528
- function Pa(t, e, n) {
2528
+ function Ia(t, e, n) {
2529
2529
  var r, i;
2530
2530
  const s = (i = (r = t.entities[e]) === null || r === void 0 ? void 0 : r.attrs) === null || i === void 0 ? void 0 : i[n];
2531
2531
  if (n === "id")
2532
2532
  return null;
2533
2533
  if (!s)
2534
2534
  throw new Error(`${e}.${n} does not exist in your schema`);
2535
- const { unique: o, indexed: a } = s == null ? void 0 : s.config, u = Ca(s == null ? void 0 : s.valueType);
2535
+ const { unique: o, indexed: a } = s == null ? void 0 : s.config, u = Pa(s == null ? void 0 : s.valueType);
2536
2536
  return {
2537
2537
  "index?": a,
2538
2538
  "unique?": o,
@@ -2540,14 +2540,14 @@ function Pa(t, e, n) {
2540
2540
  };
2541
2541
  }
2542
2542
  function _t(t, e, n, r) {
2543
- const i = t ? Pa(t, e, n) : null, s = K(), a = [K(), e, n];
2543
+ const i = t ? Ia(t, e, n) : null, s = K(), a = [K(), e, n];
2544
2544
  return Object.assign(Object.assign({ id: s, "forward-identity": a, "value-type": "blob", cardinality: "one", "unique?": !1, "index?": !1, isUnsynced: !0 }, i || {}), r || {});
2545
2545
  }
2546
- function Ia(t, e, n) {
2546
+ function Ma(t, e, n) {
2547
2547
  return Object.values(t.links).find((i) => i.forward.on === e && i.forward.label === n || i.reverse.on === e && i.reverse.label === n);
2548
2548
  }
2549
- function Ma(t, e, n) {
2550
- const r = Ia(t, e, n);
2549
+ function Ra(t, e, n) {
2550
+ const r = Ma(t, e, n);
2551
2551
  if (!r)
2552
2552
  throw new Error(`Couldn't find the link ${e}.${n} in your schema`);
2553
2553
  const { forward: i, reverse: s } = r;
@@ -2561,10 +2561,10 @@ function Ma(t, e, n) {
2561
2561
  };
2562
2562
  }
2563
2563
  function Rr(t, e, n, r) {
2564
- const i = t ? Ma(t, e, n) : null, s = K(), o = [K(), e, n], a = [K(), n, e];
2564
+ const i = t ? Ra(t, e, n) : null, s = K(), o = [K(), e, n], a = [K(), n, e];
2565
2565
  return Object.assign(Object.assign({ id: s, "forward-identity": o, "reverse-identity": a, "value-type": "ref", cardinality: "many", "unique?": !1, "index?": !1, isUnsynced: !0 }, i || {}), r || {});
2566
2566
  }
2567
- const Ra = /* @__PURE__ */ new Set(["create", "update", "merge", "link", "unlink"]), xa = /* @__PURE__ */ new Set(["link", "unlink"]), $a = /* @__PURE__ */ new Set(["create", "update", "merge"]), Da = /* @__PURE__ */ new Set([
2567
+ const xa = /* @__PURE__ */ new Set(["create", "update", "merge", "link", "unlink"]), $a = /* @__PURE__ */ new Set(["link", "unlink"]), Da = /* @__PURE__ */ new Set(["create", "update", "merge"]), Ua = /* @__PURE__ */ new Set([
2568
2568
  "link",
2569
2569
  "unlink",
2570
2570
  "create",
@@ -2572,10 +2572,10 @@ const Ra = /* @__PURE__ */ new Set(["create", "update", "merge", "link", "unlink
2572
2572
  "merge",
2573
2573
  "delete",
2574
2574
  "ruleParams"
2575
- ]), Tn = { "unique?": !0, "index?": !0 }, Ua = Object.assign(Object.assign({}, Tn), { cardinality: "one" });
2576
- function La(t) {
2575
+ ]), Tn = { "unique?": !0, "index?": !0 }, La = Object.assign(Object.assign({}, Tn), { cardinality: "one" });
2576
+ function Fa(t) {
2577
2577
  const e = [], [n, r, i, s] = t;
2578
- if (!Da.has(n))
2578
+ if (!Ua.has(n))
2579
2579
  return e;
2580
2580
  const o = gn(i);
2581
2581
  if (o && e.push({ etype: r, lookupPair: o }), n === "link")
@@ -2592,7 +2592,7 @@ function La(t) {
2592
2592
  }
2593
2593
  return e;
2594
2594
  }
2595
- function Fa({ attrs: t, schema: e }, n) {
2595
+ function Na({ attrs: t, schema: e }, n) {
2596
2596
  var r, i;
2597
2597
  const [s, o, a] = [/* @__PURE__ */ new Set(), Object.assign({}, t), []];
2598
2598
  function u(f) {
@@ -2603,10 +2603,10 @@ function Fa({ attrs: t, schema: e }, n) {
2603
2603
  }
2604
2604
  function d(f, l) {
2605
2605
  const p = G(o, f, l), y = ke(o, f, l);
2606
- c(p), c(y), !p && !y && u(Rr(e, f, l, Ua));
2606
+ c(p), c(y), !p && !y && u(Rr(e, f, l, La));
2607
2607
  }
2608
2608
  for (const f of n)
2609
- for (const { etype: l, lookupPair: p, linkLabel: y } of La(f)) {
2609
+ for (const { etype: l, lookupPair: p, linkLabel: y } of Fa(f)) {
2610
2610
  const b = p[0];
2611
2611
  if (y) {
2612
2612
  d(l, y);
@@ -2628,12 +2628,12 @@ function Fa({ attrs: t, schema: e }, n) {
2628
2628
  }
2629
2629
  for (const f of n) {
2630
2630
  const [l, p, y, b] = f;
2631
- if (Ra.has(l)) {
2631
+ if (xa.has(l)) {
2632
2632
  const g = G(o, p, "id");
2633
2633
  c(g), g || u(_t(e, p, "id", { "unique?": !0 }));
2634
2634
  for (const w of Object.keys(b)) {
2635
2635
  const T = G(o, p, w);
2636
- if (c(T), $a.has(l) && (T || u(_t(e, p, w, w === "id" ? { "unique?": !0 } : null))), xa.has(l)) {
2636
+ if (c(T), Da.has(l) && (T || u(_t(e, p, w, w === "id" ? { "unique?": !0 } : null))), $a.has(l)) {
2637
2637
  const m = ke(o, p, w);
2638
2638
  !T && !m && u(Rr(e, p, w)), c(m);
2639
2639
  }
@@ -2642,11 +2642,11 @@ function Fa({ attrs: t, schema: e }, n) {
2642
2642
  }
2643
2643
  return [o, a];
2644
2644
  }
2645
- function Na(t, e) {
2646
- const r = (Array.isArray(e) ? e : [e]).flatMap((u) => ya(u)), [i, s] = Fa(t, r), o = Object.assign(Object.assign({}, t), { attrs: i }), a = r.flatMap((u) => ja(o, u));
2645
+ function Ka(t, e) {
2646
+ const r = (Array.isArray(e) ? e : [e]).flatMap((u) => ba(u)), [i, s] = Na(t, r), o = Object.assign(Object.assign({}, t), { attrs: i }), a = r.flatMap((u) => Ca(o, u));
2647
2647
  return [...s, ...a];
2648
2648
  }
2649
- var pe = function(t, e, n, r) {
2649
+ var de = function(t, e, n, r) {
2650
2650
  function i(s) {
2651
2651
  return s instanceof n ? s : new n(function(o) {
2652
2652
  o(s);
@@ -2673,286 +2673,251 @@ var pe = function(t, e, n, r) {
2673
2673
  c((r = r.apply(t, e || [])).next());
2674
2674
  });
2675
2675
  };
2676
- const Ka = 6, qa = ["kv", "querySubs", "syncSubs"];
2677
- function Wa(t) {
2678
- return function(n) {
2679
- console.error("Error in IndexedDB event", { source: t, event: n });
2680
- };
2676
+ function xr(t, e) {
2677
+ typeof requestIdleCallback > "u" ? t() : requestIdleCallback(t, { timeout: e });
2681
2678
  }
2682
- function za(t) {
2683
- return pe(this, void 0, void 0, function* () {
2684
- return new Promise((e) => {
2685
- const n = indexedDB.open(t);
2686
- n.onerror = (r) => {
2687
- e(null);
2688
- }, n.onsuccess = (r) => {
2689
- const s = r.target.result;
2690
- e(s);
2691
- }, n.onupgradeneeded = (r) => {
2692
- r.target.transaction.abort(), e(null);
2693
- };
2694
- });
2695
- });
2679
+ const Yt = "__meta";
2680
+ class qa {
2681
+ constructor(e, n) {
2682
+ }
2696
2683
  }
2697
- function Va(t, e, n) {
2698
- return pe(this, void 0, void 0, function* () {
2699
- const r = (
2700
- // Backwards compatibility for older versions where we JSON.stringified before storing
2701
- typeof e == "string" ? JSON.parse(e) : e
2702
- );
2703
- if (!r)
2704
- return;
2705
- const i = /* @__PURE__ */ new Set();
2706
- return new Promise((s, o) => {
2707
- for (const [a, u] of Object.entries(r)) {
2708
- const c = n.put(u, a);
2709
- i.add(c);
2684
+ class wn {
2685
+ constructor(e, n, r, i, s, o, a) {
2686
+ var u, c;
2687
+ this._subs = [], this._nextSave = null, this._nextGc = null, this._pendingSaveKeys = /* @__PURE__ */ new Set(), this._loadedKeys = /* @__PURE__ */ new Set(), this._version = 0, this._meta = {
2688
+ isLoading: !0,
2689
+ onLoadCbs: [],
2690
+ value: null,
2691
+ error: null,
2692
+ attempts: 0
2693
+ }, this._persister = e, this._onMerge = n, this.serialize = r, this.parse = i, this._objectSize = s, this._log = o, this._saveThrottleMs = (u = a.saveThrottleMs) !== null && u !== void 0 ? u : 100, this._idleCallbackMaxWaitMs = (c = a.idleCallbackMaxWaitMs) !== null && c !== void 0 ? c : 1e3, this._gcOpts = a.gc, this.currentValue = {}, this._loadedKeys = /* @__PURE__ */ new Set(), this._loadingKeys = {}, this._initMeta(), a.preloadEntryCount && this._preloadEntries(a.preloadEntryCount);
2694
+ }
2695
+ _initMeta() {
2696
+ return de(this, void 0, void 0, function* () {
2697
+ var e, n, r;
2698
+ this._meta.loadingPromise && (yield this._meta.loadingPromise);
2699
+ try {
2700
+ const i = this._persister.getItem(Yt);
2701
+ this._meta.loadingPromise = i;
2702
+ const s = yield i;
2703
+ this._meta.isLoading = !1, this._meta.error = null, this._meta.loadingPromise = null, this._meta.attempts = 0;
2704
+ const o = (n = (e = this._meta.value) === null || e === void 0 ? void 0 : e.objects) !== null && n !== void 0 ? n : {}, a = s ?? {}, u = (r = a.objects) !== null && r !== void 0 ? r : {};
2705
+ this._meta.value = Object.assign(Object.assign({}, a), { objects: Object.assign(Object.assign({}, o), u) });
2706
+ } catch (i) {
2707
+ this._meta.error = i, this._meta.attempts++, this._meta.loadingPromise = null;
2710
2708
  }
2711
- for (const a of i)
2712
- a.onsuccess = () => {
2713
- i.delete(a), i.size === 0 && s();
2714
- }, a.onerror = (u) => {
2715
- o(u);
2716
- };
2717
- });
2718
- });
2719
- }
2720
- function Ga(t, e, n) {
2721
- return pe(this, void 0, void 0, function* () {
2722
- const r = n.put(e, t);
2723
- return new Promise((i, s) => {
2724
- r.onsuccess = () => i(), r.onerror = (o) => s(o);
2725
2709
  });
2726
- });
2727
- }
2728
- function Ba(t, e) {
2729
- return pe(this, void 0, void 0, function* () {
2730
- const n = yield za(`instant_${t}_5`);
2731
- if (!n)
2732
- return;
2733
- const r = e.objectStore("kv"), i = e.objectStore("querySubs");
2734
- return new Promise((s, o) => {
2735
- const c = n.transaction(["kv"], "readwrite").objectStore("kv").openCursor();
2736
- c.onerror = (f) => {
2737
- o(f);
2738
- };
2739
- const d = [];
2740
- c.onsuccess = () => {
2741
- const f = c.result;
2742
- if (f) {
2743
- const l = f.key, p = f.value;
2744
- switch (l) {
2745
- case "querySubs": {
2746
- const y = Va(l, p, i);
2747
- d.push(y);
2748
- break;
2749
- }
2750
- default: {
2751
- const y = Ga(l, p, r);
2752
- d.push(y);
2753
- break;
2754
- }
2755
- }
2756
- } else
2757
- Promise.all(d).then(() => s()).catch(o);
2758
- };
2710
+ }
2711
+ _getMeta() {
2712
+ return de(this, void 0, void 0, function* () {
2713
+ return this._meta.value ? this._meta.value : this._meta.loadingPromise ? (yield this._meta.loadingPromise, this._meta.value) : (this._initMeta(), yield this._meta.loadingPromise, this._meta.value);
2759
2714
  });
2760
- });
2761
- }
2762
- class Fi {
2763
- constructor(e, n) {
2764
- this.dbName = `instant_${e}_${Ka}`, this._storeName = n, this._appId = e, this._dbPromise = this._init();
2765
2715
  }
2766
- _init() {
2767
- return new Promise((e, n) => {
2768
- const r = indexedDB.open(this.dbName, 1);
2769
- r.onerror = (i) => {
2770
- n(i);
2771
- }, r.onsuccess = (i) => {
2772
- const o = i.target.result;
2773
- e(o);
2774
- }, r.onupgradeneeded = (i) => this._upgradeStore(i);
2716
+ _refreshMeta() {
2717
+ return de(this, void 0, void 0, function* () {
2718
+ return yield this._initMeta(), this._meta.value;
2775
2719
  });
2776
2720
  }
2777
- _upgradeStore(e) {
2778
- const n = e.target, r = n.result;
2779
- for (const s of qa)
2780
- r.objectStoreNames.contains(s) || r.createObjectStore(s);
2781
- const i = n.transaction;
2782
- Ba(this._appId, i).catch(Wa("Error upgrading store from version 5 to 6."));
2721
+ _preloadEntries(e) {
2722
+ return de(this, void 0, void 0, function* () {
2723
+ const n = yield this.waitForMetaToLoad(), r = Object.entries(n.objects);
2724
+ r.sort(([i, s], [o, a]) => a.updatedAt - s.updatedAt);
2725
+ for (const [i] of r.slice(0, e))
2726
+ this._loadKey(i);
2727
+ });
2783
2728
  }
2784
- getItem(e) {
2785
- return pe(this, void 0, void 0, function* () {
2786
- const n = yield this._dbPromise;
2787
- return new Promise((r, i) => {
2788
- const a = n.transaction([this._storeName], "readonly").objectStore(this._storeName).get(e);
2789
- a.onerror = (u) => {
2790
- i(u);
2791
- }, a.onsuccess = (u) => {
2792
- a.result ? r(a.result) : r(null);
2793
- };
2794
- });
2729
+ _getFromStorage(e) {
2730
+ return de(this, void 0, void 0, function* () {
2731
+ try {
2732
+ const n = yield this._persister.getItem(e);
2733
+ return n && this.parse(e, n);
2734
+ } catch (n) {
2735
+ return console.error(`Unable to read from storage for key=${e}`, n), null;
2736
+ }
2795
2737
  });
2796
2738
  }
2797
- setItem(e, n) {
2798
- return pe(this, void 0, void 0, function* () {
2799
- const r = yield this._dbPromise;
2800
- return new Promise((i, s) => {
2801
- const u = r.transaction([this._storeName], "readwrite").objectStore(this._storeName).put(n, e);
2802
- u.onerror = (c) => {
2803
- s(c);
2804
- }, u.onsuccess = (c) => {
2805
- i();
2806
- };
2807
- });
2739
+ waitForKeyToLoad(e) {
2740
+ return de(this, void 0, void 0, function* () {
2741
+ return this._loadedKeys.has(e) ? this.currentValue[e] : (yield this._loadingKeys[e] || this._loadKey(e), this.currentValue[e]);
2808
2742
  });
2809
2743
  }
2810
- // Performs all writes in a transaction so that all succeed or none succeed.
2811
- multiSet(e) {
2812
- return pe(this, void 0, void 0, function* () {
2813
- const n = yield this._dbPromise;
2814
- return new Promise((r, i) => {
2815
- const s = n.transaction([this._storeName], "readwrite"), o = s.objectStore(this._storeName), a = /* @__PURE__ */ new Set();
2816
- for (const [u, c] of e) {
2817
- const d = o.put(c, u);
2818
- a.add(d);
2819
- }
2820
- for (const u of a)
2821
- u.onerror = (c) => {
2822
- s.abort(), i(c);
2823
- }, u.onsuccess = (c) => {
2824
- a.delete(u), a.size === 0 && r();
2825
- };
2826
- });
2744
+ // Used for tests
2745
+ waitForMetaToLoad() {
2746
+ return de(this, void 0, void 0, function* () {
2747
+ return this._getMeta();
2827
2748
  });
2828
2749
  }
2829
- removeItem(e) {
2830
- return pe(this, void 0, void 0, function* () {
2831
- const n = yield this._dbPromise;
2832
- return new Promise((r, i) => {
2833
- const a = n.transaction([this._storeName], "readwrite").objectStore(this._storeName).delete(e);
2834
- a.onerror = (u) => {
2835
- i(u);
2836
- }, a.onsuccess = (u) => {
2837
- r();
2838
- };
2839
- });
2750
+ // Unloads the key so that it can be garbage collected, but does not
2751
+ // delete it. Removes the key from currentValue.
2752
+ unloadKey(e) {
2753
+ this._loadedKeys.delete(e), delete this._loadingKeys[e], delete this.currentValue[e];
2754
+ }
2755
+ _loadKey(e) {
2756
+ return de(this, void 0, void 0, function* () {
2757
+ if (this._loadedKeys.has(e) || e in this._loadingKeys)
2758
+ return;
2759
+ const n = this._getFromStorage(e);
2760
+ this._loadingKeys[e] = n;
2761
+ const r = yield n;
2762
+ if (delete this._loadingKeys[e], this._loadedKeys.add(e), r) {
2763
+ const i = this._onMerge(e, r, this.currentValue[e]);
2764
+ i && (this.currentValue[e] = i);
2765
+ }
2766
+ this.onKeyLoaded && this.onKeyLoaded(e);
2840
2767
  });
2841
2768
  }
2842
- getAllKeys() {
2843
- return pe(this, void 0, void 0, function* () {
2844
- const e = yield this._dbPromise;
2845
- return new Promise((n, r) => {
2846
- const o = e.transaction([this._storeName], "readwrite").objectStore(this._storeName).getAllKeys();
2847
- o.onerror = (a) => {
2848
- r(a);
2849
- }, o.onsuccess = (a) => {
2850
- n(o.result.filter((u) => typeof u == "string"));
2851
- };
2769
+ // Returns a promise with a number so that we can wait for flush
2770
+ // to finish in the tests. The number is the number of operations
2771
+ // it performed, but it's mostly there so that typescript will warn
2772
+ // us if we forget to retun the promise from the function.
2773
+ _writeToStorage(e) {
2774
+ var n, r;
2775
+ const i = [], s = e == null ? void 0 : e.skipGc;
2776
+ if (this._meta.isLoading) {
2777
+ const p = new Promise((y, b) => {
2778
+ var g;
2779
+ setTimeout(() => this._enqueuePersist(e ? Object.assign(Object.assign({}, e), { attempts: (e.attempts || 0) + 1 }) : { attempts: 1 }).then(y).catch(b), 10 + ((g = e == null ? void 0 : e.attempts) !== null && g !== void 0 ? g : 0) * 1e3);
2852
2780
  });
2853
- });
2781
+ return i.push(p), Promise.all(i).then((y) => y.reduce((b, g) => b + g, 0));
2782
+ }
2783
+ const o = this._meta.value;
2784
+ if (!o)
2785
+ return Promise.resolve(0);
2786
+ const a = [], u = [];
2787
+ for (const p of this._pendingSaveKeys)
2788
+ p in this.currentValue ? u.push(p) : (a.push(p), delete o.objects[p]);
2789
+ for (const p of a) {
2790
+ const y = this._persister.removeItem(p);
2791
+ i.push(y.then(() => 1)), this._loadedKeys.delete(p), this._pendingSaveKeys.delete(p);
2792
+ }
2793
+ const c = [], d = [[Yt, o]], f = (n = o.objects) !== null && n !== void 0 ? n : {};
2794
+ o.objects = f;
2795
+ for (const p of u)
2796
+ if (this._loadedKeys.has(p)) {
2797
+ const y = this.serialize(p, this.currentValue[p]);
2798
+ d.push([p, y]);
2799
+ const b = this._objectSize(y), g = (r = f[p]) !== null && r !== void 0 ? r : {
2800
+ createdAt: Date.now(),
2801
+ updatedAt: Date.now(),
2802
+ size: b
2803
+ };
2804
+ g.updatedAt = Date.now(), g.size = b, f[p] = g, this._pendingSaveKeys.delete(p);
2805
+ } else
2806
+ c.push(p);
2807
+ const l = this._persister.multiSet(d);
2808
+ i.push(l.then(() => 1));
2809
+ for (const p of c) {
2810
+ const y = this._loadKey(p).then(() => this._enqueuePersist(e));
2811
+ i.push(y);
2812
+ }
2813
+ return s || this.gc(), Promise.all(i).then((p) => p.reduce((y, b) => y + b, 0));
2854
2814
  }
2855
- }
2856
- var Qa = function(t, e, n, r) {
2857
- function i(s) {
2858
- return s instanceof n ? s : new n(function(o) {
2859
- o(s);
2815
+ flush() {
2816
+ return de(this, void 0, void 0, function* () {
2817
+ return this._nextSave ? (clearTimeout(this._nextSave), this._nextSave = null, this._writeToStorage()) : void 0;
2860
2818
  });
2861
2819
  }
2862
- return new (n || (n = Promise))(function(s, o) {
2863
- function a(d) {
2864
- try {
2865
- c(r.next(d));
2866
- } catch (f) {
2867
- o(f);
2820
+ _gc() {
2821
+ return de(this, void 0, void 0, function* () {
2822
+ const e = new Set(yield this._persister.getAllKeys());
2823
+ e.delete(Yt);
2824
+ const n = new Set(Object.keys(this.currentValue));
2825
+ for (const l of Object.keys(this._loadingKeys))
2826
+ n.add(l);
2827
+ for (const l of this._loadedKeys)
2828
+ n.add(l);
2829
+ const r = yield this._refreshMeta();
2830
+ if (!r) {
2831
+ this._log.info("Could not gc because we were not able to load meta");
2832
+ return;
2868
2833
  }
2869
- }
2870
- function u(d) {
2871
- try {
2872
- c(r.throw(d));
2873
- } catch (f) {
2874
- o(f);
2834
+ const i = [], s = {
2835
+ gcOpts: this._gcOpts,
2836
+ keys: e,
2837
+ sacredKeys: n,
2838
+ removed: [],
2839
+ metaRemoved: [],
2840
+ removedMissingCount: 0,
2841
+ removedOldCount: 0,
2842
+ removedThresholdCount: 0,
2843
+ removedSizeCount: 0
2844
+ };
2845
+ for (const l of e)
2846
+ n.has(l) || l in r.objects || (this._log.info("Lost track of key in meta", l), i.push(this._persister.removeItem(l)), s.removed.push(l), s.removedMissingCount++);
2847
+ const o = Date.now();
2848
+ for (const [l, p] of Object.entries(r.objects))
2849
+ !n.has(l) && p.updatedAt < o - this._gcOpts.maxAgeMs && (i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedOldCount++);
2850
+ const a = Object.entries(r.objects);
2851
+ a.sort(([l, p], [y, b]) => p.updatedAt - b.updatedAt);
2852
+ const u = a.filter(([l]) => !n.has(l));
2853
+ if (a.length > this._gcOpts.maxEntries)
2854
+ for (const [l] of u.slice(0, a.length - this._gcOpts.maxEntries))
2855
+ i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedThresholdCount++;
2856
+ const c = Object.entries(r.objects);
2857
+ c.sort(([l, p], [y, b]) => p.updatedAt - b.updatedAt);
2858
+ const d = c.filter(([l]) => !n.has(l));
2859
+ let f = c.reduce((l, [p, y]) => l + y.size, 0);
2860
+ for (; f > 0 && f > this._gcOpts.maxSize && d.length; ) {
2861
+ const [[l, p]] = d.splice(0, 1);
2862
+ f -= p.size, i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedSizeCount++;
2875
2863
  }
2876
- }
2877
- function c(d) {
2878
- d.done ? s(d.value) : i(d.value).then(a, u);
2879
- }
2880
- c((r = r.apply(t, e || [])).next());
2881
- });
2882
- };
2883
- class Ni {
2884
- static getIsOnline() {
2885
- return Qa(this, void 0, void 0, function* () {
2886
- return navigator.onLine;
2864
+ for (const l of Object.keys(r.objects))
2865
+ !e.has(l) && !n.has(l) && delete r.objects[l];
2866
+ return (s.removed.length || s.metaRemoved.length) && i.push(this._enqueuePersist({ skipGc: !0 })), this._log.info("Completed GC", s), yield Promise.all(i), s;
2887
2867
  });
2888
2868
  }
2889
- static listen(e) {
2890
- const n = () => {
2891
- e(!0);
2892
- }, r = () => {
2893
- e(!1);
2894
- };
2895
- return addEventListener("online", n), addEventListener("offline", r), () => {
2896
- removeEventListener("online", n), removeEventListener("offline", r);
2897
- };
2869
+ // Schedules a GC to run in one minute (unless it is already scheduled)
2870
+ gc() {
2871
+ this._nextGc || (this._nextGc = setTimeout(
2872
+ () => {
2873
+ xr(() => {
2874
+ this._nextGc = null, this._gc();
2875
+ }, 30 * 1e3);
2876
+ },
2877
+ // 1 minute + some jitter to keep multiple tabs from running at same time
2878
+ 1e3 * 60 + Math.random() * 500
2879
+ ));
2898
2880
  }
2899
- }
2900
- class qe extends Error {
2901
- constructor(e, n) {
2902
- super(e), this.hint = n;
2903
- const r = new.target.prototype;
2904
- Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, qe), this.name = "InstantError";
2881
+ _enqueuePersist(e) {
2882
+ return new Promise((n, r) => {
2883
+ if (this._nextSave) {
2884
+ n(0);
2885
+ return;
2886
+ }
2887
+ this._nextSave = setTimeout(() => {
2888
+ xr(() => {
2889
+ this._nextSave = null, this._writeToStorage(e).then(n).catch(r);
2890
+ }, this._idleCallbackMaxWaitMs);
2891
+ }, this._saveThrottleMs);
2892
+ });
2905
2893
  }
2906
- get [Symbol.toStringTag]() {
2907
- return "InstantError";
2894
+ version() {
2895
+ return this._version;
2908
2896
  }
2909
- }
2910
- var Ha = function(t, e, n, r) {
2911
- function i(s) {
2912
- return s instanceof n ? s : new n(function(o) {
2913
- o(s);
2897
+ updateInPlace(e) {
2898
+ this._version++;
2899
+ const [n, r] = Ct(this.currentValue, e, {
2900
+ enablePatches: !0
2914
2901
  });
2915
- }
2916
- return new (n || (n = Promise))(function(s, o) {
2917
- function a(d) {
2918
- try {
2919
- c(r.next(d));
2920
- } catch (f) {
2921
- o(f);
2922
- }
2923
- }
2924
- function u(d) {
2925
- try {
2926
- c(r.throw(d));
2927
- } catch (f) {
2928
- o(f);
2929
- }
2930
- }
2931
- function c(d) {
2932
- d.done ? s(d.value) : i(d.value).then(a, u);
2902
+ for (const i of r) {
2903
+ const s = i.path[0];
2904
+ s && typeof s == "string" && (this._pendingSaveKeys.add(s), this._loadedKeys.has(s) || this._loadKey(s));
2933
2905
  }
2934
- c((r = r.apply(t, e || [])).next());
2935
- });
2936
- };
2937
- class $t extends qe {
2938
- constructor(e) {
2939
- var n;
2940
- const r = ((n = e.body) === null || n === void 0 ? void 0 : n.message) || `API Error (${e.status})`;
2941
- super(r, e.body.hint);
2942
- const i = new.target.prototype;
2943
- Object.setPrototypeOf && Object.setPrototypeOf(this, i), Error.captureStackTrace && Error.captureStackTrace(this, $t), this.name = "InstantAPIError", this.status = e.status, this.body = e.body;
2906
+ for (const i of Object.keys(n))
2907
+ if (!n[i])
2908
+ debugger;
2909
+ this.currentValue = n, this._enqueuePersist();
2910
+ for (const i of this._subs)
2911
+ i(this.currentValue);
2912
+ return n;
2944
2913
  }
2945
- get [Symbol.toStringTag]() {
2946
- return "InstantAPIError";
2914
+ subscribe(e) {
2915
+ return this._subs.push(e), e(this.currentValue), () => {
2916
+ this._subs = this._subs.filter((n) => n !== e);
2917
+ };
2947
2918
  }
2948
2919
  }
2949
- function ue(t, e) {
2950
- return Ha(this, void 0, void 0, function* () {
2951
- const n = yield fetch(t, e), r = yield n.json();
2952
- return n.status === 200 ? Promise.resolve(r) : Promise.reject(new $t({ status: n.status, body: r }));
2953
- });
2954
- }
2955
- var Ve = function(t, e, n, r) {
2920
+ var pe = function(t, e, n, r) {
2956
2921
  function i(s) {
2957
2922
  return s instanceof n ? s : new n(function(o) {
2958
2923
  o(s);
@@ -2979,93 +2944,203 @@ var Ve = function(t, e, n, r) {
2979
2944
  c((r = r.apply(t, e || [])).next());
2980
2945
  });
2981
2946
  };
2982
- function Ya({ apiURI: t, appId: e, email: n }) {
2983
- return ue(`${t}/runtime/auth/send_magic_code`, {
2984
- method: "POST",
2985
- headers: { "content-type": "application/json" },
2986
- body: JSON.stringify({ "app-id": e, email: n })
2987
- });
2947
+ const Wa = 6, za = ["kv", "querySubs", "syncSubs"];
2948
+ function Va(t) {
2949
+ return function(n) {
2950
+ console.error("Error in IndexedDB event", { source: t, event: n });
2951
+ };
2988
2952
  }
2989
- function Ja(t) {
2990
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, email: r, code: i, refreshToken: s }) {
2991
- return yield ue(`${e}/runtime/auth/verify_magic_code`, {
2992
- method: "POST",
2993
- headers: { "content-type": "application/json" },
2994
- body: JSON.stringify(Object.assign({
2995
- "app-id": n,
2996
- email: r,
2997
- code: i
2998
- }, s ? { "refresh-token": s } : {}))
2953
+ function Ga(t) {
2954
+ return pe(this, void 0, void 0, function* () {
2955
+ return new Promise((e) => {
2956
+ const n = indexedDB.open(t);
2957
+ n.onerror = (r) => {
2958
+ e(null);
2959
+ }, n.onsuccess = (r) => {
2960
+ const s = r.target.result;
2961
+ e(s);
2962
+ }, n.onupgradeneeded = (r) => {
2963
+ r.target.transaction.abort(), e(null);
2964
+ };
2999
2965
  });
3000
2966
  });
3001
2967
  }
3002
- function Za(t) {
3003
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
3004
- return yield ue(`${e}/runtime/auth/verify_refresh_token`, {
3005
- method: "POST",
3006
- headers: { "content-type": "application/json" },
3007
- body: JSON.stringify({
3008
- "app-id": n,
3009
- "refresh-token": r
3010
- })
2968
+ function Ba(t, e, n) {
2969
+ return pe(this, void 0, void 0, function* () {
2970
+ const r = (
2971
+ // Backwards compatibility for older versions where we JSON.stringified before storing
2972
+ typeof e == "string" ? JSON.parse(e) : e
2973
+ );
2974
+ if (!r)
2975
+ return;
2976
+ const i = /* @__PURE__ */ new Set();
2977
+ return new Promise((s, o) => {
2978
+ for (const [a, u] of Object.entries(r)) {
2979
+ const c = n.put(u, a);
2980
+ i.add(c);
2981
+ }
2982
+ for (const a of i)
2983
+ a.onsuccess = () => {
2984
+ i.delete(a), i.size === 0 && s();
2985
+ }, a.onerror = (u) => {
2986
+ o(u);
2987
+ };
3011
2988
  });
3012
2989
  });
3013
2990
  }
3014
- function Xa(t) {
3015
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n }) {
3016
- return yield ue(`${e}/runtime/auth/sign_in_guest`, {
3017
- method: "POST",
3018
- headers: { "content-type": "application/json" },
3019
- body: JSON.stringify({
3020
- "app-id": n
3021
- })
2991
+ function Qa(t, e, n) {
2992
+ return pe(this, void 0, void 0, function* () {
2993
+ const r = n.put(e, t);
2994
+ return new Promise((i, s) => {
2995
+ r.onsuccess = () => i(), r.onerror = (o) => s(o);
3022
2996
  });
3023
2997
  });
3024
2998
  }
3025
- function xr(t) {
3026
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, code: r, codeVerifier: i, refreshToken: s }) {
3027
- return yield ue(`${e}/runtime/oauth/token`, {
3028
- method: "POST",
3029
- headers: { "content-type": "application/json" },
3030
- body: JSON.stringify({
3031
- app_id: n,
3032
- code: r,
3033
- code_verifier: i,
3034
- refresh_token: s
3035
- })
2999
+ function Ha(t, e) {
3000
+ return pe(this, void 0, void 0, function* () {
3001
+ const n = yield Ga(`instant_${t}_5`);
3002
+ if (!n)
3003
+ return;
3004
+ const r = yield new Promise((u, c) => {
3005
+ const l = n.transaction(["kv"], "readonly").objectStore("kv").openCursor();
3006
+ l.onerror = (y) => {
3007
+ c(y);
3008
+ };
3009
+ const p = [];
3010
+ l.onsuccess = () => {
3011
+ const y = l.result;
3012
+ if (y) {
3013
+ const b = y.key, g = y.value;
3014
+ p.push([b, g]), y.continue();
3015
+ } else
3016
+ u(p);
3017
+ }, l.onerror = (y) => {
3018
+ c(y);
3019
+ };
3020
+ }), i = e.transaction(["kv", "querySubs"], "readwrite"), s = i.objectStore("kv"), o = i.objectStore("querySubs"), a = [];
3021
+ for (const [u, c] of r)
3022
+ switch (u) {
3023
+ case "querySubs": {
3024
+ const d = Ba(u, c, o);
3025
+ a.push(d);
3026
+ break;
3027
+ }
3028
+ default: {
3029
+ const d = Qa(u, c, s);
3030
+ a.push(d);
3031
+ break;
3032
+ }
3033
+ }
3034
+ yield Promise.all(a), yield new Promise((u, c) => {
3035
+ i.oncomplete = (d) => u(d), i.onerror = (d) => c(d), i.onabort = (d) => c(d);
3036
3036
  });
3037
3037
  });
3038
3038
  }
3039
- function eu(t) {
3040
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, nonce: r, idToken: i, clientName: s, refreshToken: o }) {
3041
- return yield ue(`${e}/runtime/oauth/id_token`, {
3042
- method: "POST",
3043
- headers: { "content-type": "application/json" },
3044
- body: JSON.stringify({
3045
- app_id: n,
3046
- nonce: r,
3047
- id_token: i,
3048
- client_name: s,
3049
- refresh_token: o
3050
- })
3039
+ const $r = /* @__PURE__ */ new Map();
3040
+ class Ni extends qa {
3041
+ constructor(e, n) {
3042
+ super(e, n), this.dbName = `instant_${e}_${Wa}`, this._storeName = n, this._appId = e, this._dbPromise = this._init();
3043
+ }
3044
+ _init() {
3045
+ return new Promise((e, n) => {
3046
+ let r = !1;
3047
+ const i = indexedDB.open(this.dbName, 1);
3048
+ i.onerror = (s) => {
3049
+ n(s);
3050
+ }, i.onsuccess = (s) => {
3051
+ const a = s.target.result;
3052
+ if (r) {
3053
+ const u = Ha(this._appId, a).catch((c) => {
3054
+ Va("Error upgrading store from version 5 to 6.")(c);
3055
+ });
3056
+ $r.set(this.dbName, u), u.then(() => e(a)).catch(() => e(a));
3057
+ } else {
3058
+ const u = $r.get(this.dbName);
3059
+ u ? u.then(() => e(a)).catch(() => e(a)) : e(a);
3060
+ }
3061
+ }, i.onupgradeneeded = (s) => {
3062
+ r = !0, this._upgradeStore(s);
3063
+ };
3051
3064
  });
3052
- });
3053
- }
3054
- function tu(t) {
3055
- return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
3056
- return yield ue(`${e}/runtime/signout`, {
3057
- method: "POST",
3058
- headers: {
3059
- "content-type": "application/json"
3060
- },
3061
- body: JSON.stringify({
3062
- app_id: n,
3063
- refresh_token: r
3064
- })
3065
+ }
3066
+ _upgradeStore(e) {
3067
+ const r = e.target.result;
3068
+ for (const i of za)
3069
+ r.objectStoreNames.contains(i) || r.createObjectStore(i);
3070
+ }
3071
+ getItem(e) {
3072
+ return pe(this, void 0, void 0, function* () {
3073
+ const n = yield this._dbPromise;
3074
+ return new Promise((r, i) => {
3075
+ const a = n.transaction([this._storeName], "readonly").objectStore(this._storeName).get(e);
3076
+ a.onerror = (u) => {
3077
+ i(u);
3078
+ }, a.onsuccess = (u) => {
3079
+ a.result ? r(a.result) : r(null);
3080
+ };
3081
+ });
3065
3082
  });
3066
- });
3083
+ }
3084
+ setItem(e, n) {
3085
+ return pe(this, void 0, void 0, function* () {
3086
+ const r = yield this._dbPromise;
3087
+ return new Promise((i, s) => {
3088
+ const u = r.transaction([this._storeName], "readwrite").objectStore(this._storeName).put(n, e);
3089
+ u.onerror = (c) => {
3090
+ s(c);
3091
+ }, u.onsuccess = (c) => {
3092
+ i();
3093
+ };
3094
+ });
3095
+ });
3096
+ }
3097
+ // Performs all writes in a transaction so that all succeed or none succeed.
3098
+ multiSet(e) {
3099
+ return pe(this, void 0, void 0, function* () {
3100
+ const n = yield this._dbPromise;
3101
+ return new Promise((r, i) => {
3102
+ const s = n.transaction([this._storeName], "readwrite"), o = s.objectStore(this._storeName), a = /* @__PURE__ */ new Set();
3103
+ for (const [u, c] of e) {
3104
+ const d = o.put(c, u);
3105
+ a.add(d);
3106
+ }
3107
+ for (const u of a)
3108
+ u.onerror = (c) => {
3109
+ s.abort(), i(c);
3110
+ }, u.onsuccess = (c) => {
3111
+ a.delete(u), a.size === 0 && r();
3112
+ };
3113
+ });
3114
+ });
3115
+ }
3116
+ removeItem(e) {
3117
+ return pe(this, void 0, void 0, function* () {
3118
+ const n = yield this._dbPromise;
3119
+ return new Promise((r, i) => {
3120
+ const a = n.transaction([this._storeName], "readwrite").objectStore(this._storeName).delete(e);
3121
+ a.onerror = (u) => {
3122
+ i(u);
3123
+ }, a.onsuccess = (u) => {
3124
+ r();
3125
+ };
3126
+ });
3127
+ });
3128
+ }
3129
+ getAllKeys() {
3130
+ return pe(this, void 0, void 0, function* () {
3131
+ const e = yield this._dbPromise;
3132
+ return new Promise((n, r) => {
3133
+ const o = e.transaction([this._storeName], "readwrite").objectStore(this._storeName).getAllKeys();
3134
+ o.onerror = (a) => {
3135
+ r(a);
3136
+ }, o.onsuccess = (a) => {
3137
+ n(o.result.filter((u) => typeof u == "string"));
3138
+ };
3139
+ });
3140
+ });
3141
+ }
3067
3142
  }
3068
- var ct = function(t, e, n, r) {
3143
+ var Ya = function(t, e, n, r) {
3069
3144
  function i(s) {
3070
3145
  return s instanceof n ? s : new n(function(o) {
3071
3146
  o(s);
@@ -3092,122 +3167,79 @@ var ct = function(t, e, n, r) {
3092
3167
  c((r = r.apply(t, e || [])).next());
3093
3168
  });
3094
3169
  };
3095
- function nu(t) {
3096
- return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, file: i, refreshToken: s, contentType: o, contentDisposition: a }) {
3097
- const u = {
3098
- app_id: n,
3099
- path: r,
3100
- authorization: `Bearer ${s}`,
3101
- "content-type": o || i.type
3102
- };
3103
- return a && (u["content-disposition"] = a), yield ue(`${e}/storage/upload`, {
3104
- method: "PUT",
3105
- headers: u,
3106
- body: i
3170
+ class Ki {
3171
+ static getIsOnline() {
3172
+ return Ya(this, void 0, void 0, function* () {
3173
+ return navigator.onLine;
3107
3174
  });
3108
- });
3175
+ }
3176
+ static listen(e) {
3177
+ const n = () => {
3178
+ e(!0);
3179
+ }, r = () => {
3180
+ e(!1);
3181
+ };
3182
+ return addEventListener("online", n), addEventListener("offline", r), () => {
3183
+ removeEventListener("online", n), removeEventListener("offline", r);
3184
+ };
3185
+ }
3109
3186
  }
3110
- function ru(t) {
3111
- return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3112
- const { data: s } = yield ue(`${e}/storage/files?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3113
- method: "DELETE",
3114
- headers: {
3115
- "content-type": "application/json",
3116
- authorization: `Bearer ${i}`
3117
- }
3118
- });
3119
- return s;
3120
- });
3187
+ class qe extends Error {
3188
+ constructor(e, n) {
3189
+ super(e), this.hint = n;
3190
+ const r = new.target.prototype;
3191
+ Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, qe), this.name = "InstantError";
3192
+ }
3193
+ get [Symbol.toStringTag]() {
3194
+ return "InstantError";
3195
+ }
3121
3196
  }
3122
- function iu(t) {
3123
- return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, fileName: r, refreshToken: i, metadata: s = {} }) {
3124
- const { data: o } = yield ue(`${e}/storage/signed-upload-url`, {
3125
- method: "POST",
3126
- headers: {
3127
- "content-type": "application/json",
3128
- authorization: `Bearer ${i}`
3129
- },
3130
- body: JSON.stringify({
3131
- app_id: n,
3132
- filename: r
3133
- })
3197
+ var Ja = function(t, e, n, r) {
3198
+ function i(s) {
3199
+ return s instanceof n ? s : new n(function(o) {
3200
+ o(s);
3134
3201
  });
3135
- return o;
3136
- });
3137
- }
3138
- function su(t, e) {
3139
- return ct(this, void 0, void 0, function* () {
3140
- return (yield fetch(t, {
3141
- method: "PUT",
3142
- body: e,
3143
- headers: {
3144
- "Content-Type": e.type
3145
- }
3146
- })).ok;
3147
- });
3148
- }
3149
- function ou(t) {
3150
- return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3151
- const { data: s } = yield ue(`${e}/storage/signed-download-url?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3152
- method: "GET",
3153
- headers: {
3154
- "content-type": "application/json",
3155
- authorization: `Bearer ${i}`
3202
+ }
3203
+ return new (n || (n = Promise))(function(s, o) {
3204
+ function a(d) {
3205
+ try {
3206
+ c(r.next(d));
3207
+ } catch (f) {
3208
+ o(f);
3156
3209
  }
3157
- });
3158
- return s;
3210
+ }
3211
+ function u(d) {
3212
+ try {
3213
+ c(r.throw(d));
3214
+ } catch (f) {
3215
+ o(f);
3216
+ }
3217
+ }
3218
+ function c(d) {
3219
+ d.done ? s(d.value) : i(d.value).then(a, u);
3220
+ }
3221
+ c((r = r.apply(t, e || [])).next());
3159
3222
  });
3160
- }
3161
- let Gn = !1, Ki = !1, qi = !1;
3162
- typeof window < "u" && typeof window.localStorage < "u" && (Gn = !!window.localStorage.getItem("devBackend"), Ki = !!window.localStorage.getItem("__instantLogging"), qi = !!window.localStorage.getItem("__devtoolLocalDash"));
3163
- function $r(t, e) {
3164
- if (!e)
3165
- return t;
3166
- const n = {};
3167
- return e.forEach((r) => {
3168
- n[r] = t[r];
3169
- }), n;
3170
- }
3171
- function au(t, e, n) {
3172
- var r, i;
3173
- const s = {
3174
- peers: {}
3175
- };
3176
- if (e && "user" in e ? e.user : !0) {
3177
- const a = $r((r = t.user) !== null && r !== void 0 ? r : {}, e == null ? void 0 : e.keys);
3178
- s.user = Object.assign(Object.assign({}, a), { peerId: n });
3223
+ };
3224
+ class $t extends qe {
3225
+ constructor(e) {
3226
+ var n;
3227
+ const r = ((n = e.body) === null || n === void 0 ? void 0 : n.message) || `API Error (${e.status})`;
3228
+ super(r, e.body.hint);
3229
+ const i = new.target.prototype;
3230
+ Object.setPrototypeOf && Object.setPrototypeOf(this, i), Error.captureStackTrace && Error.captureStackTrace(this, $t), this.name = "InstantAPIError", this.status = e.status, this.body = e.body;
3179
3231
  }
3180
- for (const a of Object.keys((i = t.peers) !== null && i !== void 0 ? i : {})) {
3181
- const u = (e == null ? void 0 : e.peers) === void 0, c = Array.isArray(e == null ? void 0 : e.peers) && (e == null ? void 0 : e.peers.includes(a));
3182
- if (u || c) {
3183
- const d = $r(t.peers[a], e == null ? void 0 : e.keys);
3184
- s.peers[a] = Object.assign(Object.assign({}, d), { peerId: a });
3185
- }
3232
+ get [Symbol.toStringTag]() {
3233
+ return "InstantAPIError";
3186
3234
  }
3187
- return s;
3188
3235
  }
3189
- function uu(t, e) {
3190
- if (t.isLoading !== e.isLoading || t.error !== e.error || (t.user || e.user) && (!t.user || !e.user || !Sr(t.user, e.user)) || !bi(t.peers, e.peers))
3191
- return !0;
3192
- for (const r of Object.keys(t.peers))
3193
- if (!Sr(t.peers[r], e.peers[r]))
3194
- return !0;
3195
- return !1;
3196
- }
3197
- class Dr {
3198
- constructor() {
3199
- this.promise = new Promise((e, n) => {
3200
- this._resolve = e, this._reject = n;
3201
- });
3202
- }
3203
- resolve(e) {
3204
- this._resolve(e);
3205
- }
3206
- reject(e) {
3207
- this._reject(e);
3208
- }
3236
+ function ue(t, e) {
3237
+ return Ja(this, void 0, void 0, function* () {
3238
+ const n = yield fetch(t, e), r = yield n.json();
3239
+ return n.status === 200 ? Promise.resolve(r) : Promise.reject(new $t({ status: n.status, body: r }));
3240
+ });
3209
3241
  }
3210
- var de = function(t, e, n, r) {
3242
+ var Ve = function(t, e, n, r) {
3211
3243
  function i(s) {
3212
3244
  return s instanceof n ? s : new n(function(o) {
3213
3245
  o(s);
@@ -3234,255 +3266,248 @@ var de = function(t, e, n, r) {
3234
3266
  c((r = r.apply(t, e || [])).next());
3235
3267
  });
3236
3268
  };
3237
- function Ur(t, e) {
3238
- typeof requestIdleCallback > "u" ? t() : requestIdleCallback(t, { timeout: e });
3269
+ function Za({ apiURI: t, appId: e, email: n }) {
3270
+ return ue(`${t}/runtime/auth/send_magic_code`, {
3271
+ method: "POST",
3272
+ headers: { "content-type": "application/json" },
3273
+ body: JSON.stringify({ "app-id": e, email: n })
3274
+ });
3239
3275
  }
3240
- const Yt = "__meta";
3241
- class wn {
3242
- constructor(e, n, r, i, s, o, a) {
3243
- var u, c;
3244
- this._subs = [], this._nextSave = null, this._nextGc = null, this._pendingSaveKeys = /* @__PURE__ */ new Set(), this._loadedKeys = /* @__PURE__ */ new Set(), this._version = 0, this._meta = {
3245
- isLoading: !0,
3246
- onLoadCbs: [],
3247
- value: null,
3248
- error: null,
3249
- attempts: 0
3250
- }, this._persister = e, this._onMerge = n, this.serialize = r, this.parse = i, this._objectSize = s, this._log = o, this._saveThrottleMs = (u = a.saveThrottleMs) !== null && u !== void 0 ? u : 100, this._idleCallbackMaxWaitMs = (c = a.idleCallbackMaxWaitMs) !== null && c !== void 0 ? c : 1e3, this._gcOpts = a.gc, this.currentValue = {}, this._loadedKeys = /* @__PURE__ */ new Set(), this._loadingKeys = {}, this._initMeta(), a.preloadEntryCount && this._preloadEntries(a.preloadEntryCount);
3251
- }
3252
- _initMeta() {
3253
- return de(this, void 0, void 0, function* () {
3254
- var e, n, r;
3255
- this._meta.loadingPromise && (yield this._meta.loadingPromise);
3256
- try {
3257
- const i = this._persister.getItem(Yt);
3258
- this._meta.loadingPromise = i;
3259
- const s = yield i;
3260
- this._meta.isLoading = !1, this._meta.error = null, this._meta.loadingPromise = null, this._meta.attempts = 0;
3261
- const o = (n = (e = this._meta.value) === null || e === void 0 ? void 0 : e.objects) !== null && n !== void 0 ? n : {}, a = s ?? {}, u = (r = a.objects) !== null && r !== void 0 ? r : {};
3262
- this._meta.value = Object.assign(Object.assign({}, a), { objects: Object.assign(Object.assign({}, o), u) });
3263
- } catch (i) {
3264
- this._meta.error = i, this._meta.attempts++, this._meta.loadingPromise = null;
3265
- }
3266
- });
3267
- }
3268
- _getMeta() {
3269
- return de(this, void 0, void 0, function* () {
3270
- return this._meta.value ? this._meta.value : this._meta.loadingPromise ? (yield this._meta.loadingPromise, this._meta.value) : (this._initMeta(), yield this._meta.loadingPromise, this._meta.value);
3271
- });
3272
- }
3273
- _refreshMeta() {
3274
- return de(this, void 0, void 0, function* () {
3275
- return yield this._initMeta(), this._meta.value;
3276
- });
3277
- }
3278
- _preloadEntries(e) {
3279
- return de(this, void 0, void 0, function* () {
3280
- const n = yield this.waitForMetaToLoad(), r = Object.entries(n.objects);
3281
- r.sort(([i, s], [o, a]) => a.updatedAt - s.updatedAt);
3282
- for (const [i] of r.slice(0, e))
3283
- this._loadKey(i);
3276
+ function Xa(t) {
3277
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, email: r, code: i, refreshToken: s }) {
3278
+ return yield ue(`${e}/runtime/auth/verify_magic_code`, {
3279
+ method: "POST",
3280
+ headers: { "content-type": "application/json" },
3281
+ body: JSON.stringify(Object.assign({
3282
+ "app-id": n,
3283
+ email: r,
3284
+ code: i
3285
+ }, s ? { "refresh-token": s } : {}))
3284
3286
  });
3285
- }
3286
- _getFromStorage(e) {
3287
- return de(this, void 0, void 0, function* () {
3288
- try {
3289
- const n = yield this._persister.getItem(e);
3290
- return n && this.parse(e, n);
3291
- } catch (n) {
3292
- return console.error(`Unable to read from storage for key=${e}`, n), null;
3293
- }
3287
+ });
3288
+ }
3289
+ function eu(t) {
3290
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
3291
+ return yield ue(`${e}/runtime/auth/verify_refresh_token`, {
3292
+ method: "POST",
3293
+ headers: { "content-type": "application/json" },
3294
+ body: JSON.stringify({
3295
+ "app-id": n,
3296
+ "refresh-token": r
3297
+ })
3294
3298
  });
3295
- }
3296
- waitForKeyToLoad(e) {
3297
- return de(this, void 0, void 0, function* () {
3298
- return this._loadedKeys.has(e) ? this.currentValue[e] : (yield this._loadingKeys[e] || this._loadKey(e), this.currentValue[e]);
3299
+ });
3300
+ }
3301
+ function tu(t) {
3302
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n }) {
3303
+ return yield ue(`${e}/runtime/auth/sign_in_guest`, {
3304
+ method: "POST",
3305
+ headers: { "content-type": "application/json" },
3306
+ body: JSON.stringify({
3307
+ "app-id": n
3308
+ })
3299
3309
  });
3300
- }
3301
- // Used for tests
3302
- waitForMetaToLoad() {
3303
- return de(this, void 0, void 0, function* () {
3304
- return this._getMeta();
3310
+ });
3311
+ }
3312
+ function Dr(t) {
3313
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, code: r, codeVerifier: i, refreshToken: s }) {
3314
+ return yield ue(`${e}/runtime/oauth/token`, {
3315
+ method: "POST",
3316
+ headers: { "content-type": "application/json" },
3317
+ body: JSON.stringify({
3318
+ app_id: n,
3319
+ code: r,
3320
+ code_verifier: i,
3321
+ refresh_token: s
3322
+ })
3305
3323
  });
3306
- }
3307
- // Unloads the key so that it can be garbage collected, but does not
3308
- // delete it. Removes the key from currentValue.
3309
- unloadKey(e) {
3310
- this._loadedKeys.delete(e), delete this._loadingKeys[e], delete this.currentValue[e];
3311
- }
3312
- _loadKey(e) {
3313
- return de(this, void 0, void 0, function* () {
3314
- if (this._loadedKeys.has(e) || e in this._loadingKeys)
3315
- return;
3316
- const n = this._getFromStorage(e);
3317
- this._loadingKeys[e] = n;
3318
- const r = yield n;
3319
- if (delete this._loadingKeys[e], this._loadedKeys.add(e), r) {
3320
- const i = this._onMerge(e, r, this.currentValue[e]);
3321
- i && (this.currentValue[e] = i);
3322
- }
3323
- this.onKeyLoaded && this.onKeyLoaded(e);
3324
+ });
3325
+ }
3326
+ function nu(t) {
3327
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, nonce: r, idToken: i, clientName: s, refreshToken: o }) {
3328
+ return yield ue(`${e}/runtime/oauth/id_token`, {
3329
+ method: "POST",
3330
+ headers: { "content-type": "application/json" },
3331
+ body: JSON.stringify({
3332
+ app_id: n,
3333
+ nonce: r,
3334
+ id_token: i,
3335
+ client_name: s,
3336
+ refresh_token: o
3337
+ })
3324
3338
  });
3325
- }
3326
- // Returns a promise with a number so that we can wait for flush
3327
- // to finish in the tests. The number is the number of operations
3328
- // it performed, but it's mostly there so that typescript will warn
3329
- // us if we forget to retun the promise from the function.
3330
- _writeToStorage(e) {
3331
- var n, r;
3332
- const i = [], s = e == null ? void 0 : e.skipGc;
3333
- if (this._meta.isLoading) {
3334
- const p = new Promise((y, b) => {
3335
- var g;
3336
- setTimeout(() => this._enqueuePersist(e ? Object.assign(Object.assign({}, e), { attempts: (e.attempts || 0) + 1 }) : { attempts: 1 }).then(y).catch(b), 10 + ((g = e == null ? void 0 : e.attempts) !== null && g !== void 0 ? g : 0) * 1e3);
3337
- });
3338
- return i.push(p), Promise.all(i).then((y) => y.reduce((b, g) => b + g, 0));
3339
- }
3340
- const o = this._meta.value;
3341
- if (!o)
3342
- return Promise.resolve(0);
3343
- const a = [], u = [];
3344
- for (const p of this._pendingSaveKeys)
3345
- p in this.currentValue ? u.push(p) : (a.push(p), delete o.objects[p]);
3346
- for (const p of a) {
3347
- const y = this._persister.removeItem(p);
3348
- i.push(y.then(() => 1)), this._loadedKeys.delete(p), this._pendingSaveKeys.delete(p);
3349
- }
3350
- const c = [], d = [[Yt, o]], f = (n = o.objects) !== null && n !== void 0 ? n : {};
3351
- o.objects = f;
3352
- for (const p of u)
3353
- if (this._loadedKeys.has(p)) {
3354
- const y = this.serialize(p, this.currentValue[p]);
3355
- d.push([p, y]);
3356
- const b = this._objectSize(y), g = (r = f[p]) !== null && r !== void 0 ? r : {
3357
- createdAt: Date.now(),
3358
- updatedAt: Date.now(),
3359
- size: b
3360
- };
3361
- g.updatedAt = Date.now(), g.size = b, f[p] = g, this._pendingSaveKeys.delete(p);
3362
- } else
3363
- c.push(p);
3364
- const l = this._persister.multiSet(d);
3365
- i.push(l.then(() => 1));
3366
- for (const p of c) {
3367
- const y = this._loadKey(p).then(() => this._enqueuePersist(e));
3368
- i.push(y);
3369
- }
3370
- return s || this.gc(), Promise.all(i).then((p) => p.reduce((y, b) => y + b, 0));
3371
- }
3372
- flush() {
3373
- return de(this, void 0, void 0, function* () {
3374
- return this._nextSave ? (clearTimeout(this._nextSave), this._nextSave = null, this._writeToStorage()) : void 0;
3339
+ });
3340
+ }
3341
+ function ru(t) {
3342
+ return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
3343
+ return yield ue(`${e}/runtime/signout`, {
3344
+ method: "POST",
3345
+ headers: {
3346
+ "content-type": "application/json"
3347
+ },
3348
+ body: JSON.stringify({
3349
+ app_id: n,
3350
+ refresh_token: r
3351
+ })
3352
+ });
3353
+ });
3354
+ }
3355
+ var ct = function(t, e, n, r) {
3356
+ function i(s) {
3357
+ return s instanceof n ? s : new n(function(o) {
3358
+ o(s);
3375
3359
  });
3376
3360
  }
3377
- _gc() {
3378
- return de(this, void 0, void 0, function* () {
3379
- const e = new Set(yield this._persister.getAllKeys());
3380
- e.delete(Yt);
3381
- const n = new Set(Object.keys(this.currentValue));
3382
- for (const l of Object.keys(this._loadingKeys))
3383
- n.add(l);
3384
- for (const l of this._loadedKeys)
3385
- n.add(l);
3386
- const r = yield this._refreshMeta();
3387
- if (!r) {
3388
- this._log.info("Could not gc because we were not able to load meta");
3389
- return;
3361
+ return new (n || (n = Promise))(function(s, o) {
3362
+ function a(d) {
3363
+ try {
3364
+ c(r.next(d));
3365
+ } catch (f) {
3366
+ o(f);
3390
3367
  }
3391
- const i = [], s = {
3392
- gcOpts: this._gcOpts,
3393
- keys: e,
3394
- sacredKeys: n,
3395
- removed: [],
3396
- metaRemoved: [],
3397
- removedMissingCount: 0,
3398
- removedOldCount: 0,
3399
- removedThresholdCount: 0,
3400
- removedSizeCount: 0
3401
- };
3402
- for (const l of e)
3403
- n.has(l) || l in r.objects || (this._log.info("Lost track of key in meta", l), i.push(this._persister.removeItem(l)), s.removed.push(l), s.removedMissingCount++);
3404
- const o = Date.now();
3405
- for (const [l, p] of Object.entries(r.objects))
3406
- !n.has(l) && p.updatedAt < o - this._gcOpts.maxAgeMs && (i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedOldCount++);
3407
- const a = Object.entries(r.objects);
3408
- a.sort(([l, p], [y, b]) => p.updatedAt - b.updatedAt);
3409
- const u = a.filter(([l]) => !n.has(l));
3410
- if (a.length > this._gcOpts.maxEntries)
3411
- for (const [l] of u.slice(0, a.length - this._gcOpts.maxEntries))
3412
- i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedThresholdCount++;
3413
- const c = Object.entries(r.objects);
3414
- c.sort(([l, p], [y, b]) => p.updatedAt - b.updatedAt);
3415
- const d = c.filter(([l]) => !n.has(l));
3416
- let f = c.reduce((l, [p, y]) => l + y.size, 0);
3417
- for (; f > 0 && f > this._gcOpts.maxSize && d.length; ) {
3418
- const [[l, p]] = d.splice(0, 1);
3419
- f -= p.size, i.push(this._persister.removeItem(l)), delete r.objects[l], s.removed.push(l), s.removedSizeCount++;
3368
+ }
3369
+ function u(d) {
3370
+ try {
3371
+ c(r.throw(d));
3372
+ } catch (f) {
3373
+ o(f);
3420
3374
  }
3421
- for (const l of Object.keys(r.objects))
3422
- !e.has(l) && !n.has(l) && delete r.objects[l];
3423
- return (s.removed.length || s.metaRemoved.length) && i.push(this._enqueuePersist({ skipGc: !0 })), this._log.info("Completed GC", s), yield Promise.all(i), s;
3375
+ }
3376
+ function c(d) {
3377
+ d.done ? s(d.value) : i(d.value).then(a, u);
3378
+ }
3379
+ c((r = r.apply(t, e || [])).next());
3380
+ });
3381
+ };
3382
+ function iu(t) {
3383
+ return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, file: i, refreshToken: s, contentType: o, contentDisposition: a }) {
3384
+ const u = {
3385
+ app_id: n,
3386
+ path: r,
3387
+ authorization: `Bearer ${s}`,
3388
+ "content-type": o || i.type
3389
+ };
3390
+ return a && (u["content-disposition"] = a), yield ue(`${e}/storage/upload`, {
3391
+ method: "PUT",
3392
+ headers: u,
3393
+ body: i
3424
3394
  });
3425
- }
3426
- gc() {
3427
- this._nextGc || (this._nextGc = setTimeout(() => {
3428
- Ur(() => {
3429
- this._nextGc = null, this._gc();
3430
- }, 30 * 1e3);
3431
- }, 1e3 * 60));
3432
- }
3433
- _enqueuePersist(e) {
3434
- return new Promise((n, r) => {
3435
- if (this._nextSave) {
3436
- n(0);
3437
- return;
3395
+ });
3396
+ }
3397
+ function su(t) {
3398
+ return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3399
+ const { data: s } = yield ue(`${e}/storage/files?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3400
+ method: "DELETE",
3401
+ headers: {
3402
+ "content-type": "application/json",
3403
+ authorization: `Bearer ${i}`
3404
+ }
3405
+ });
3406
+ return s;
3407
+ });
3408
+ }
3409
+ function ou(t) {
3410
+ return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, fileName: r, refreshToken: i, metadata: s = {} }) {
3411
+ const { data: o } = yield ue(`${e}/storage/signed-upload-url`, {
3412
+ method: "POST",
3413
+ headers: {
3414
+ "content-type": "application/json",
3415
+ authorization: `Bearer ${i}`
3416
+ },
3417
+ body: JSON.stringify({
3418
+ app_id: n,
3419
+ filename: r
3420
+ })
3421
+ });
3422
+ return o;
3423
+ });
3424
+ }
3425
+ function au(t, e) {
3426
+ return ct(this, void 0, void 0, function* () {
3427
+ return (yield fetch(t, {
3428
+ method: "PUT",
3429
+ body: e,
3430
+ headers: {
3431
+ "Content-Type": e.type
3432
+ }
3433
+ })).ok;
3434
+ });
3435
+ }
3436
+ function uu(t) {
3437
+ return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3438
+ const { data: s } = yield ue(`${e}/storage/signed-download-url?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3439
+ method: "GET",
3440
+ headers: {
3441
+ "content-type": "application/json",
3442
+ authorization: `Bearer ${i}`
3438
3443
  }
3439
- this._nextSave = setTimeout(() => {
3440
- Ur(() => {
3441
- this._nextSave = null, this._writeToStorage(e).then(n).catch(r);
3442
- }, this._idleCallbackMaxWaitMs);
3443
- }, this._saveThrottleMs);
3444
3444
  });
3445
+ return s;
3446
+ });
3447
+ }
3448
+ let Gn = !1, qi = !1, Wi = !1;
3449
+ typeof window < "u" && typeof window.localStorage < "u" && (Gn = !!window.localStorage.getItem("devBackend"), qi = !!window.localStorage.getItem("__instantLogging"), Wi = !!window.localStorage.getItem("__devtoolLocalDash"));
3450
+ function Ur(t, e) {
3451
+ if (!e)
3452
+ return t;
3453
+ const n = {};
3454
+ return e.forEach((r) => {
3455
+ n[r] = t[r];
3456
+ }), n;
3457
+ }
3458
+ function cu(t, e, n) {
3459
+ var r, i;
3460
+ const s = {
3461
+ peers: {}
3462
+ };
3463
+ if (e && "user" in e ? e.user : !0) {
3464
+ const a = Ur((r = t.user) !== null && r !== void 0 ? r : {}, e == null ? void 0 : e.keys);
3465
+ s.user = Object.assign(Object.assign({}, a), { peerId: n });
3445
3466
  }
3446
- version() {
3447
- return this._version;
3467
+ for (const a of Object.keys((i = t.peers) !== null && i !== void 0 ? i : {})) {
3468
+ const u = (e == null ? void 0 : e.peers) === void 0, c = Array.isArray(e == null ? void 0 : e.peers) && (e == null ? void 0 : e.peers.includes(a));
3469
+ if (u || c) {
3470
+ const d = Ur(t.peers[a], e == null ? void 0 : e.keys);
3471
+ s.peers[a] = Object.assign(Object.assign({}, d), { peerId: a });
3472
+ }
3448
3473
  }
3449
- updateInPlace(e) {
3450
- this._version++;
3451
- const [n, r] = Ct(this.currentValue, e, {
3452
- enablePatches: !0
3474
+ return s;
3475
+ }
3476
+ function du(t, e) {
3477
+ if (t.isLoading !== e.isLoading || t.error !== e.error || (t.user || e.user) && (!t.user || !e.user || !Sr(t.user, e.user)) || !_i(t.peers, e.peers))
3478
+ return !0;
3479
+ for (const r of Object.keys(t.peers))
3480
+ if (!Sr(t.peers[r], e.peers[r]))
3481
+ return !0;
3482
+ return !1;
3483
+ }
3484
+ class Lr {
3485
+ constructor() {
3486
+ this.promise = new Promise((e, n) => {
3487
+ this._resolve = e, this._reject = n;
3453
3488
  });
3454
- for (const i of r) {
3455
- const s = i.path[0];
3456
- s && typeof s == "string" && (this._pendingSaveKeys.add(s), this._loadedKeys.has(s) || this._loadKey(s));
3457
- }
3458
- for (const i of Object.keys(n))
3459
- if (!n[i])
3460
- debugger;
3461
- this.currentValue = n, this._enqueuePersist();
3462
- for (const i of this._subs)
3463
- i(this.currentValue);
3464
- return n;
3465
3489
  }
3466
- subscribe(e) {
3467
- return this._subs.push(e), e(this.currentValue), () => {
3468
- this._subs = this._subs.filter((n) => n !== e);
3469
- };
3490
+ resolve(e) {
3491
+ this._resolve(e);
3492
+ }
3493
+ reject(e) {
3494
+ this._reject(e);
3470
3495
  }
3471
3496
  }
3472
- function Wi(t, e = []) {
3497
+ function zi(t, e = []) {
3473
3498
  t.forEach((n) => {
3474
3499
  const { data: r } = n, { "datalog-result": i } = r, { "join-rows": s } = i;
3475
3500
  for (const o of s)
3476
3501
  for (const a of o)
3477
3502
  e.push(a);
3478
- Wi(n["child-nodes"], e);
3503
+ zi(n["child-nodes"], e);
3479
3504
  });
3480
3505
  }
3481
- function Lr(t) {
3506
+ function Fr(t) {
3482
3507
  const e = [];
3483
- return Wi(t, e), e;
3508
+ return zi(t, e), e;
3484
3509
  }
3485
- function Fr(t) {
3510
+ function Nr(t) {
3486
3511
  return Object.values(t.links).reduce((e, n) => {
3487
3512
  var r, i, s, o;
3488
3513
  return (r = e[s = n.forward.on]) !== null && r !== void 0 || (e[s] = {}), e[n.forward.on][n.forward.label] = {
@@ -3496,8 +3521,8 @@ function Fr(t) {
3496
3521
  }, e;
3497
3522
  }, {});
3498
3523
  }
3499
- const Bn = "v0.22.56-experimental.persisted-object-2.19512376560.1";
3500
- function cu(t, e) {
3524
+ const Bn = "v0.22.56-experimental.persisted-object-2.19516307571.1";
3525
+ function fu(t, e) {
3501
3526
  return {
3502
3527
  info: t ? (...n) => console.info(...n, e()) : () => {
3503
3528
  },
@@ -3570,7 +3595,7 @@ class R extends Error {
3570
3595
  super(r), this.name = "QueryValidationError";
3571
3596
  }
3572
3597
  }
3573
- const Nr = [
3598
+ const Kr = [
3574
3599
  "where",
3575
3600
  "order",
3576
3601
  "limit",
@@ -3581,7 +3606,7 @@ const Nr = [
3581
3606
  "before",
3582
3607
  "fields",
3583
3608
  "aggregate"
3584
- ], du = (t) => t.valueType || "unknown", zi = (t, e, n = !1) => {
3609
+ ], lu = (t) => t.valueType || "unknown", Vi = (t, e, n = !1) => {
3585
3610
  if (n || t == null)
3586
3611
  return !0;
3587
3612
  switch (e) {
@@ -3596,9 +3621,9 @@ const Nr = [
3596
3621
  default:
3597
3622
  return !0;
3598
3623
  }
3599
- }, fu = (t, e, n, r, i, s, o) => {
3624
+ }, hu = (t, e, n, r, i, s, o) => {
3600
3625
  const a = s.valueType === "json", u = (c, d, f) => {
3601
- if (!zi(f, d, a))
3626
+ if (!Vi(f, d, a))
3602
3627
  throw new R(`Invalid value for operator '${c}' on attribute '${r}' in entity '${i}'. Expected ${d}, but received: ${typeof f}`, o);
3603
3628
  };
3604
3629
  switch (t) {
@@ -3629,16 +3654,16 @@ const Nr = [
3629
3654
  throw new R(`Unknown operator '${t}' for attribute '${r}' in entity '${i}'`, o);
3630
3655
  }
3631
3656
  }, Le = (t, e, n, r, i) => {
3632
- const s = du(n), o = n.valueType === "json";
3657
+ const s = lu(n), o = n.valueType === "json";
3633
3658
  if (typeof t == "object" && t !== null && !Array.isArray(t)) {
3634
3659
  if (o)
3635
3660
  return;
3636
3661
  const u = t;
3637
3662
  for (const [c, d] of Object.entries(u))
3638
- fu(c, d, s, e, r, n, `${i}.${c}`);
3639
- } else if (!zi(t, s, o))
3663
+ hu(c, d, s, e, r, n, `${i}.${c}`);
3664
+ } else if (!Vi(t, s, o))
3640
3665
  throw new R(`Invalid value for attribute '${e}' in entity '${r}'. Expected ${s}, but received: ${typeof t}`, i);
3641
- }, lu = (t, e, n, r, i) => {
3666
+ }, pu = (t, e, n, r, i) => {
3642
3667
  const s = t.split(".");
3643
3668
  if (s.length < 2)
3644
3669
  throw new R(`Invalid dot notation path '${t}'. Must contain at least one dot.`, i);
@@ -3675,12 +3700,12 @@ const Nr = [
3675
3700
  throw new R(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${t}'. Available attributes: ${d.length > 0 ? d.join(", ") + ", id" : "id"}`, i);
3676
3701
  }
3677
3702
  Le(e, t, c, n, i);
3678
- }, Vi = (t, e, n, r) => {
3703
+ }, Gi = (t, e, n, r) => {
3679
3704
  for (const [i, s] of Object.entries(t)) {
3680
3705
  if (i === "or" || i === "and") {
3681
3706
  if (Array.isArray(s))
3682
3707
  for (const c of s)
3683
- typeof c == "object" && c !== null && Vi(c, e, n, `${r}.${i}[${c}]`);
3708
+ typeof c == "object" && c !== null && Gi(c, e, n, `${r}.${i}[${c}]`);
3684
3709
  continue;
3685
3710
  }
3686
3711
  if (i === "id") {
@@ -3688,7 +3713,7 @@ const Nr = [
3688
3713
  continue;
3689
3714
  }
3690
3715
  if (i.includes(".")) {
3691
- lu(i, s, e, n, `${r}.${i}`);
3716
+ pu(i, s, e, n, `${r}.${i}`);
3692
3717
  continue;
3693
3718
  }
3694
3719
  const o = n.entities[e];
@@ -3708,10 +3733,10 @@ const Nr = [
3708
3733
  Le(s, i, c, e, `${r}.${i}`);
3709
3734
  }
3710
3735
  }
3711
- }, hu = (t, e, n, r, i = 0) => {
3736
+ }, yu = (t, e, n, r, i = 0) => {
3712
3737
  for (const o of Object.keys(t))
3713
- if (!Nr.includes(o))
3714
- throw new R(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Nr.join(", ")}. Found: ${o}`, r);
3738
+ if (!Kr.includes(o))
3739
+ throw new R(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Kr.join(", ")}. Found: ${o}`, r);
3715
3740
  const s = [
3716
3741
  // 'limit', // only supported client side
3717
3742
  "offset",
@@ -3726,9 +3751,9 @@ const Nr = [
3726
3751
  if (t.where && n) {
3727
3752
  if (typeof t.where != "object" || t.where === null)
3728
3753
  throw new R(`'where' clause must be an object in entity '${e}', but received: ${typeof t.where}`, r ? `${r}.where` : void 0);
3729
- Vi(t.where, e, n, r ? `${r}.where` : "where");
3754
+ Gi(t.where, e, n, r ? `${r}.where` : "where");
3730
3755
  }
3731
- }, Gi = (t, e, n, r, i = 0) => {
3756
+ }, Bi = (t, e, n, r, i = 0) => {
3732
3757
  var s;
3733
3758
  if (!t || typeof t != "object")
3734
3759
  throw new R(`Query part for entity '${e}' must be an object, but received: ${typeof t}`, r);
@@ -3741,15 +3766,15 @@ const Nr = [
3741
3766
  const a = t[o];
3742
3767
  if (typeof a == "object" && a !== null) {
3743
3768
  const u = (s = n == null ? void 0 : n.entities[e].links[o]) === null || s === void 0 ? void 0 : s.entityName;
3744
- u && Gi(a, u, n, `${r}.${o}`, i + 1);
3769
+ u && Bi(a, u, n, `${r}.${o}`, i + 1);
3745
3770
  }
3746
3771
  } else {
3747
3772
  const a = t[o];
3748
3773
  if (typeof a != "object" || a === null)
3749
3774
  throw new R(`Query parameter '$' must be an object in entity '${e}', but received: ${typeof a}`, `${r}.$`);
3750
- hu(a, e, n, `${r}.$`, i);
3775
+ yu(a, e, n, `${r}.$`, i);
3751
3776
  }
3752
- }, Kr = (t, e) => {
3777
+ }, qr = (t, e) => {
3753
3778
  if (typeof t != "object" || t === null)
3754
3779
  throw new R(`Query must be an object, but received: ${typeof t}${t === null ? " (null)" : ""}`);
3755
3780
  if (Array.isArray(t))
@@ -3765,67 +3790,67 @@ const Nr = [
3765
3790
  const i = Object.keys(e.entities);
3766
3791
  throw new R(`Entity '${r}' does not exist in schema. Available entities: ${i.length > 0 ? i.join(", ") : "none"}`, r);
3767
3792
  }
3768
- Gi(n[r], r, e, r, 0);
3793
+ Bi(n[r], r, e, r, 0);
3769
3794
  }
3770
3795
  }
3771
- }, qr = (t) => typeof t != "string" ? !1 : It(t) ? !0 : Ne(t);
3796
+ }, Wr = (t) => typeof t != "string" ? !1 : It(t) ? !0 : Ne(t);
3772
3797
  class ie extends Error {
3773
3798
  constructor(e) {
3774
3799
  super(e), this.name = "TransactionValidationError";
3775
3800
  }
3776
3801
  }
3777
- const Bi = (t) => t.length > 0 ? t.join(", ") : "none", pu = (t, e) => new ie(`Entity '${t}' does not exist in schema. Available entities: ${Bi(e)}`), Wr = {
3802
+ const Qi = (t) => t.length > 0 ? t.join(", ") : "none", bu = (t, e) => new ie(`Entity '${t}' does not exist in schema. Available entities: ${Qi(e)}`), zr = {
3778
3803
  string: (t) => typeof t == "string",
3779
3804
  number: (t) => typeof t == "number" && !isNaN(t),
3780
3805
  boolean: (t) => typeof t == "boolean",
3781
3806
  date: (t) => t instanceof Date || typeof t == "string" || typeof t == "number",
3782
3807
  json: () => !0
3783
- }, yu = (t, e) => {
3808
+ }, _u = (t, e) => {
3784
3809
  var n, r;
3785
- return t == null ? !0 : (r = (n = Wr[e.valueType]) === null || n === void 0 ? void 0 : n.call(Wr, t)) !== null && r !== void 0 ? r : !1;
3786
- }, Qi = (t, e) => {
3810
+ return t == null ? !0 : (r = (n = zr[e.valueType]) === null || n === void 0 ? void 0 : n.call(zr, t)) !== null && r !== void 0 ? r : !1;
3811
+ }, Hi = (t, e) => {
3787
3812
  const n = e.entities[t];
3788
3813
  if (!n)
3789
- throw pu(t, Object.keys(e.entities));
3814
+ throw bu(t, Object.keys(e.entities));
3790
3815
  return n;
3791
3816
  }, Jt = (t, e, n) => {
3792
- const r = Qi(t, n);
3817
+ const r = Hi(t, n);
3793
3818
  if (typeof e != "object" || e === null)
3794
3819
  throw new ie(`Arguments for data operation on entity '${t}' must be an object, but received: ${typeof e}`);
3795
3820
  for (const [i, s] of Object.entries(e)) {
3796
3821
  if (i === "id")
3797
3822
  continue;
3798
3823
  const o = r.attrs[i];
3799
- if (o && !yu(s, o))
3824
+ if (o && !_u(s, o))
3800
3825
  throw new ie(`Invalid value for attribute '${i}' in entity '${t}'. Expected ${o.valueType}, but received: ${typeof s}`);
3801
3826
  }
3802
- }, zr = (t, e, n) => {
3803
- const r = Qi(t, n);
3827
+ }, Vr = (t, e, n) => {
3828
+ const r = Hi(t, n);
3804
3829
  if (typeof e != "object" || e === null)
3805
3830
  throw new ie(`Arguments for link operation on entity '${t}' must be an object, but received: ${typeof e}`);
3806
3831
  for (const [i, s] of Object.entries(e)) {
3807
3832
  if (!r.links[i]) {
3808
3833
  const a = Object.keys(r.links);
3809
- throw new ie(`Link '${i}' does not exist on entity '${t}'. Available links: ${Bi(a)}`);
3834
+ throw new ie(`Link '${i}' does not exist on entity '${t}'. Available links: ${Qi(a)}`);
3810
3835
  }
3811
3836
  if (s != null) {
3812
3837
  if (Array.isArray(s)) {
3813
3838
  for (const a of s)
3814
- if (!qr(a))
3839
+ if (!Wr(a))
3815
3840
  throw new ie(`Invalid entity ID in link '${i}' for entity '${t}'. Expected a UUID or a lookup, but received: ${a}`);
3816
- } else if (!qr(s))
3841
+ } else if (!Wr(s))
3817
3842
  throw new ie(`Invalid UUID in link '${i}' for entity '${t}'. Expected a UUID, but received: ${s}`);
3818
3843
  }
3819
3844
  }
3820
- }, bu = {
3845
+ }, gu = {
3821
3846
  create: Jt,
3822
3847
  update: Jt,
3823
3848
  merge: Jt,
3824
- link: zr,
3825
- unlink: zr,
3849
+ link: Vr,
3850
+ unlink: Vr,
3826
3851
  delete: () => {
3827
3852
  }
3828
- }, _u = (t, e) => {
3853
+ }, Tu = (t, e) => {
3829
3854
  if (!e)
3830
3855
  return;
3831
3856
  const [n, r, i, s] = t;
@@ -3833,9 +3858,9 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", pu = (t, e) => new ie(`E
3833
3858
  throw new ie(`Invalid id for entity '${r}'. Expected a UUID, but received: ${i}`);
3834
3859
  if (typeof r != "string")
3835
3860
  throw new ie(`Entity name must be a string, but received: ${typeof r}`);
3836
- const o = bu[n];
3861
+ const o = gu[n];
3837
3862
  o && s !== void 0 && o(r, s, e);
3838
- }, gu = (t, e) => {
3863
+ }, wu = (t, e) => {
3839
3864
  const n = Array.isArray(t) ? t : [t];
3840
3865
  for (const r of n) {
3841
3866
  if (!r || typeof r != "object")
@@ -3845,11 +3870,11 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", pu = (t, e) => new ie(`E
3845
3870
  for (const i of r.__ops) {
3846
3871
  if (!Array.isArray(i))
3847
3872
  throw new ie(`Transaction operation must be an array, but received: ${typeof i}`);
3848
- _u(i, e);
3873
+ Tu(i, e);
3849
3874
  }
3850
3875
  }
3851
3876
  };
3852
- var Vr = function(t, e, n, r) {
3877
+ var Gr = function(t, e, n, r) {
3853
3878
  function i(s) {
3854
3879
  return s instanceof n ? s : new n(function(o) {
3855
3880
  o(s);
@@ -3876,10 +3901,10 @@ var Vr = function(t, e, n, r) {
3876
3901
  c((r = r.apply(t, e || [])).next());
3877
3902
  });
3878
3903
  };
3879
- let Hi = 0;
3880
- class Gr {
3904
+ let Yi = 0;
3905
+ class Br {
3881
3906
  constructor(e) {
3882
- this.type = "ws", this.id = `${this.type}_${Hi++}`, this.conn = new WebSocket(e), this.conn.onopen = (n) => {
3907
+ this.type = "ws", this.id = `${this.type}_${Yi++}`, this.conn = new WebSocket(e), this.conn.onopen = (n) => {
3883
3908
  this.onopen && this.onopen({ target: this });
3884
3909
  }, this.conn.onmessage = (n) => {
3885
3910
  this.onmessage && this.onmessage({
@@ -3905,9 +3930,9 @@ class Gr {
3905
3930
  return this.conn.send(JSON.stringify(e));
3906
3931
  }
3907
3932
  }
3908
- class Tu {
3933
+ class mu {
3909
3934
  constructor(e, n) {
3910
- this.type = "sse", this.initParams = null, this.sendQueue = [], this.closeFired = !1, this.sseInitTimeout = null, this.id = `${this.type}_${Hi++}`, this.url = n, this.ES = e, this.conn = new e(n), this.sseInitTimeout = setTimeout(() => {
3935
+ this.type = "sse", this.initParams = null, this.sendQueue = [], this.closeFired = !1, this.sseInitTimeout = null, this.id = `${this.type}_${Yi++}`, this.url = n, this.ES = e, this.conn = new e(n), this.sseInitTimeout = setTimeout(() => {
3911
3936
  this.initParams || this.handleError();
3912
3937
  }, 1e4), this.conn.onmessage = (r) => {
3913
3938
  const i = JSON.parse(r.data);
@@ -3939,7 +3964,7 @@ class Tu {
3939
3964
  this.conn.close(), this.onclose && !this.closeFired && (this.closeFired = !0, this.onclose({ target: this }));
3940
3965
  }
3941
3966
  postMessages(e) {
3942
- return Vr(this, void 0, void 0, function* () {
3967
+ return Gr(this, void 0, void 0, function* () {
3943
3968
  try {
3944
3969
  (yield fetch(this.url, {
3945
3970
  method: "POST",
@@ -3957,7 +3982,7 @@ class Tu {
3957
3982
  });
3958
3983
  }
3959
3984
  flushQueue() {
3960
- return Vr(this, void 0, void 0, function* () {
3985
+ return Gr(this, void 0, void 0, function* () {
3961
3986
  if (this.sendPromise || !this.sendQueue.length)
3962
3987
  return;
3963
3988
  const e = this.sendQueue;
@@ -3983,7 +4008,7 @@ class Tu {
3983
4008
  this.handleClose();
3984
4009
  }
3985
4010
  }
3986
- var Br = function(t, e, n, r) {
4011
+ var Qr = function(t, e, n, r) {
3987
4012
  function i(s) {
3988
4013
  return s instanceof n ? s : new n(function(o) {
3989
4014
  o(s);
@@ -4010,33 +4035,33 @@ var Br = function(t, e, n, r) {
4010
4035
  c((r = r.apply(t, e || [])).next());
4011
4036
  });
4012
4037
  };
4013
- function wu(t, e) {
4038
+ function vu(t, e) {
4014
4039
  const n = t.values;
4015
4040
  if (n)
4016
4041
  for (const r of n.entities || [])
4017
- r.store.useDateObjects = e, r.store.attrs = n.attrs, r.store = vi(r.store);
4042
+ r.store.useDateObjects = e, r.store.attrs = n.attrs, r.store = Si(r.store);
4018
4043
  return t;
4019
4044
  }
4020
- function mu(t, e) {
4045
+ function Su(t, e) {
4021
4046
  var n, r;
4022
4047
  if (!((n = e.values) === null || n === void 0) && n.entities) {
4023
4048
  const i = [];
4024
4049
  for (const s of (r = e.values) === null || r === void 0 ? void 0 : r.entities) {
4025
- const o = mi(s.store);
4050
+ const o = vi(s.store);
4026
4051
  delete o.attrs, i.push(Object.assign(Object.assign({}, s), { store: o }));
4027
4052
  }
4028
4053
  return Object.assign(Object.assign({}, e), { values: Object.assign(Object.assign({}, e.values), { entities: i }) });
4029
4054
  } else
4030
4055
  return e;
4031
4056
  }
4032
- function vu(t, e, n) {
4057
+ function Ou(t, e, n) {
4033
4058
  const r = e == null ? void 0 : e.state.txId, i = n == null ? void 0 : n.state.txId;
4034
4059
  return r && (!i || r > i) ? e : i && (!r || i > r) ? n : e || n;
4035
4060
  }
4036
4061
  function Zt(t, e) {
4037
- return $i({ store: e, pageInfo: null, aggregate: null }, t.query).data[t.table][0];
4062
+ return Di({ store: e, pageInfo: null, aggregate: null }, t.query).data[t.table][0];
4038
4063
  }
4039
- function Qr(t, e, n) {
4064
+ function Hr(t, e, n) {
4040
4065
  var r;
4041
4066
  const i = (r = Te(e, t.table, "id")) === null || r === void 0 ? void 0 : r.id;
4042
4067
  if (!i)
@@ -4044,18 +4069,18 @@ function Qr(t, e, n) {
4044
4069
  const s = ze(e.eav, [n, i, n]);
4045
4070
  return s ? s[3] : -1;
4046
4071
  }
4047
- function Hr(t, e) {
4072
+ function Yr(t, e) {
4048
4073
  for (const { action: n, triple: r } of e)
4049
4074
  switch (n) {
4050
4075
  case "added":
4051
- Ei(t, r);
4076
+ Ai(t, r);
4052
4077
  break;
4053
4078
  case "removed":
4054
- Si(t, r);
4079
+ Oi(t, r);
4055
4080
  break;
4056
4081
  }
4057
4082
  }
4058
- function Su(t, e) {
4083
+ function Eu(t, e) {
4059
4084
  var n, r, i, s;
4060
4085
  const o = {};
4061
4086
  for (const { action: a, triple: u } of e) {
@@ -4079,7 +4104,7 @@ function Su(t, e) {
4079
4104
  function gt(t, e) {
4080
4105
  return { [t.table]: e.map((n) => n.entity) };
4081
4106
  }
4082
- function Ou(t, e) {
4107
+ function Au(t, e) {
4083
4108
  const n = t.orderFieldType;
4084
4109
  if (t.orderField === "serverCreatedAt") {
4085
4110
  e.sort(t.orderDirection === "asc" ? function(s, o) {
@@ -4100,9 +4125,9 @@ var Se;
4100
4125
  (function(t) {
4101
4126
  t.InitialSyncBatch = "InitialSyncBatch", t.InitialSyncComplete = "InitialSyncComplete", t.LoadFromStorage = "LoadFromStorage", t.SyncTransaction = "SyncTransaction", t.Error = "Error";
4102
4127
  })(Se || (Se = {}));
4103
- class Eu {
4128
+ class ku {
4104
4129
  constructor(e, n, r, i, s) {
4105
- this.callbacks = {}, this.idToHash = {}, this.trySend = e, this.config = r, this.log = i, this.createStore = s, this.subs = new wn(n, vu, mu, (o, a) => wu(a, this.config.useDateObjects), (o) => {
4130
+ this.callbacks = {}, this.idToHash = {}, this.trySend = e, this.config = r, this.log = i, this.createStore = s, this.subs = new wn(n, Ou, Su, (o, a) => vu(a, this.config.useDateObjects), (o) => {
4106
4131
  var a;
4107
4132
  return ((a = o.values) === null || a === void 0 ? void 0 : a.entities.length) || 0;
4108
4133
  }, i, {
@@ -4157,7 +4182,7 @@ class Eu {
4157
4182
  });
4158
4183
  }
4159
4184
  initSubscription(e, n, r) {
4160
- return Br(this, void 0, void 0, function* () {
4185
+ return Qr(this, void 0, void 0, function* () {
4161
4186
  var i, s, o, a, u;
4162
4187
  yield this.subs.waitForKeyToLoad(n);
4163
4188
  const c = this.subs.currentValue[n];
@@ -4184,7 +4209,7 @@ class Eu {
4184
4209
  });
4185
4210
  }
4186
4211
  flushPending() {
4187
- return Br(this, void 0, void 0, function* () {
4212
+ return Qr(this, void 0, void 0, function* () {
4188
4213
  for (const e of Object.keys(this.callbacks)) {
4189
4214
  yield this.subs.waitForKeyToLoad(e);
4190
4215
  const n = this.subs.currentValue[e];
@@ -4233,7 +4258,7 @@ class Eu {
4233
4258
  c.push({
4234
4259
  store: f,
4235
4260
  entity: l,
4236
- serverCreatedAt: Qr(a, f, l.id)
4261
+ serverCreatedAt: Hr(a, f, l.id)
4237
4262
  }), o.push(l);
4238
4263
  }
4239
4264
  this.subs.updateInPlace((d) => {
@@ -4302,9 +4327,9 @@ class Eu {
4302
4327
  const y = [];
4303
4328
  e: for (const [w, T] of Object.entries(f))
4304
4329
  for (const [m, E] of Object.entries(p))
4305
- if (io(E.store, w)) {
4306
- Hr(E.store, T);
4307
- const S = Zt(a, E.store), I = Su(E.store, T)[w];
4330
+ if (so(E.store, w)) {
4331
+ Yr(E.store, T);
4332
+ const S = Zt(a, E.store), I = Eu(E.store, T)[w];
4308
4333
  for (const [x, { oldValue: q, newValue: we }] of Object.entries(I || {}))
4309
4334
  q === we && delete I[x];
4310
4335
  S ? (y.push({
@@ -4317,7 +4342,7 @@ class Eu {
4317
4342
  const b = [];
4318
4343
  for (const [w, T] of Object.entries(f)) {
4319
4344
  const m = this.createStore([]);
4320
- l.attrs = m.attrs, Hr(m, T);
4345
+ l.attrs = m.attrs, Yr(m, T);
4321
4346
  const E = Zt(a, m);
4322
4347
  if (!E) {
4323
4348
  this.log.error("No entity found after applying change", {
@@ -4330,13 +4355,13 @@ class Eu {
4330
4355
  p.push({
4331
4356
  store: m,
4332
4357
  entity: E,
4333
- serverCreatedAt: Qr(a, m, E.id)
4358
+ serverCreatedAt: Hr(a, m, E.id)
4334
4359
  }), b.push(E);
4335
4360
  }
4336
4361
  const g = [];
4337
4362
  for (const w of d.sort().reverse())
4338
4363
  g.push(p[w].entity), p.splice(w, 1);
4339
- Ou(a, p), this.notifyCbs(o, {
4364
+ Au(a, p), this.notifyCbs(o, {
4340
4365
  type: Se.SyncTransaction,
4341
4366
  data: gt(a, (i = a.values) === null || i === void 0 ? void 0 : i.entities),
4342
4367
  added: b,
@@ -4403,7 +4428,7 @@ var F = function(t, e, n, r) {
4403
4428
  }
4404
4429
  c((r = r.apply(t, e || [])).next());
4405
4430
  });
4406
- }, Au = function(t, e) {
4431
+ }, ju = function(t, e) {
4407
4432
  var n = {};
4408
4433
  for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
4409
4434
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
@@ -4417,46 +4442,46 @@ const le = {
4417
4442
  AUTHENTICATED: "authenticated",
4418
4443
  CLOSED: "closed",
4419
4444
  ERRORED: "errored"
4420
- }, ku = 3e4, ju = 3e4, Cu = 200, Pu = {
4445
+ }, Cu = 3e4, Pu = 3e4, Iu = 200, Mu = {
4421
4446
  apiURI: "https://api.instantdb.com",
4422
4447
  websocketURI: "wss://api.instantdb.com/runtime/session"
4423
4448
  }, Xt = "_instant_oauth_redirect", Qe = "currentUser";
4424
- function Iu({ transportType: t, appId: e, apiURI: n, wsURI: r, EventSourceImpl: i }) {
4449
+ function Ru({ transportType: t, appId: e, apiURI: n, wsURI: r, EventSourceImpl: i }) {
4425
4450
  if (!i)
4426
- return new Gr(`${r}?app_id=${e}`);
4451
+ return new Br(`${r}?app_id=${e}`);
4427
4452
  switch (t) {
4428
4453
  case "ws":
4429
- return new Gr(`${r}?app_id=${e}`);
4454
+ return new Br(`${r}?app_id=${e}`);
4430
4455
  case "sse":
4431
- return new Tu(i, `${n}/runtime/sse?app_id=${e}`);
4456
+ return new mu(i, `${n}/runtime/sse?app_id=${e}`);
4432
4457
  default:
4433
4458
  throw new Error("Unknown transport type " + t);
4434
4459
  }
4435
4460
  }
4436
- function Mu() {
4461
+ function xu() {
4437
4462
  return typeof window < "u" || typeof chrome < "u";
4438
4463
  }
4439
- const Yr = {
4464
+ const Jr = {
4440
4465
  "set-presence": !0,
4441
4466
  "set-presence-ok": !0,
4442
4467
  "refresh-presence": !0,
4443
4468
  "patch-presence": !0
4444
4469
  };
4445
- function Ru(t, e) {
4470
+ function $u(t, e) {
4446
4471
  var n;
4447
4472
  const r = typeof t == "string" ? JSON.parse(t) : t;
4448
4473
  if (!((n = r == null ? void 0 : r.result) === null || n === void 0) && n.store) {
4449
4474
  const i = r.result.store;
4450
- r.result.store = vi(Object.assign(Object.assign({}, i), { useDateObjects: e }));
4475
+ r.result.store = Si(Object.assign(Object.assign({}, i), { useDateObjects: e }));
4451
4476
  }
4452
4477
  return r;
4453
4478
  }
4454
- function xu(t, e) {
4479
+ function Du(t, e) {
4455
4480
  var n;
4456
4481
  const r = Object.assign({}, e);
4457
- return !((n = e.result) === null || n === void 0) && n.store && (r.result = Object.assign(Object.assign({}, e.result), { store: mi(e.result.store) })), r;
4482
+ return !((n = e.result) === null || n === void 0) && n.store && (r.result = Object.assign(Object.assign({}, e.result), { store: vi(e.result.store) })), r;
4458
4483
  }
4459
- function $u(t, e) {
4484
+ function Uu(t, e) {
4460
4485
  switch (t) {
4461
4486
  case "pendingMutations":
4462
4487
  return new Map(typeof e == "string" ? JSON.parse(e) : e);
@@ -4464,7 +4489,7 @@ function $u(t, e) {
4464
4489
  return e;
4465
4490
  }
4466
4491
  }
4467
- function Du(t, e) {
4492
+ function Lu(t, e) {
4468
4493
  switch (t) {
4469
4494
  case "pendingMutations":
4470
4495
  return [...e.entries()];
@@ -4472,18 +4497,18 @@ function Du(t, e) {
4472
4497
  return e;
4473
4498
  }
4474
4499
  }
4475
- function Uu(t, e, n) {
4500
+ function Fu(t, e, n) {
4476
4501
  const r = e == null ? void 0 : e.result, i = n == null ? void 0 : n.result;
4477
4502
  return r && !i && n && (n.result = r), n || e;
4478
4503
  }
4479
- function Jr(t) {
4504
+ function Zr(t) {
4480
4505
  return [...t].sort((e, n) => {
4481
4506
  const [r, i] = e, [s, o] = n, a = i.order || 0, u = o.order || 0;
4482
4507
  return a == u ? r < s ? -1 : r > s ? 1 : 0 : a - u;
4483
4508
  });
4484
4509
  }
4485
- class Lu {
4486
- constructor(e, n = Fi, r = Ni, i, s) {
4510
+ class Nu {
4511
+ constructor(e, n = Ni, r = Ki, i, s) {
4487
4512
  var o, a, u;
4488
4513
  if (this._isOnline = !0, this._isShutdown = !1, this.status = le.CONNECTING, this.queryCbs = {}, this.queryOnceDfds = {}, this.authCbs = [], this.attrsCbs = [], this.mutationErrorCbs = [], this.connectionStatusCbs = [], this.mutationDeferredStore = /* @__PURE__ */ new Map(), this._reconnectTimeoutId = null, this._reconnectTimeoutMs = 0, this._transportType = "ws", this._wsOk = null, this._localIdPromises = {}, this._errorMessage = null, this._oauthCallbackResponse = null, this._linkIndex = null, this._rooms = {}, this._roomsPendingLeave = {}, this._presence = {}, this._broadcastQueue = [], this._broadcastSubs = {}, this._currentUserCached = { isLoading: !0, error: void 0, user: void 0 }, this._beforeUnloadCbs = [], this._dataForQueryCache = {}, this._inFlightMutationEventIds = /* @__PURE__ */ new Set(), this._onMergeKv = (c, d, f) => {
4489
4514
  var l, p;
@@ -4514,9 +4539,9 @@ class Lu {
4514
4539
  }, this.notifyQueryError = (c, d) => {
4515
4540
  (this.queryCbs[c] || []).forEach((l) => l.cb({ error: d }));
4516
4541
  }, this.pushTx = (c) => {
4517
- this.config.disableValidation || gu(c, this.config.schema);
4542
+ this.config.disableValidation || wu(c, this.config.schema);
4518
4543
  try {
4519
- const d = Na({
4544
+ const d = Ka({
4520
4545
  attrs: this.optimisticAttrs(),
4521
4546
  schema: this.config.schema,
4522
4547
  stores: Object.values(this.querySubs.currentValue).map((f) => {
@@ -4540,7 +4565,7 @@ class Lu {
4540
4565
  this._updatePendingMutations((g) => {
4541
4566
  g.set(f, y);
4542
4567
  });
4543
- const b = new Dr();
4568
+ const b = new Lr();
4544
4569
  return this.mutationDeferredStore.set(f, b), this._sendMutation(f, y), this.notifyAll(), b.promise;
4545
4570
  }, this._transportOnOpen = (c) => {
4546
4571
  const d = c.target;
@@ -4601,7 +4626,7 @@ class Lu {
4601
4626
  return;
4602
4627
  }
4603
4628
  this._log.info("[socket][close]", d.id, "schedule reconnect, ms =", this._reconnectTimeoutMs), this._scheduleReconnect();
4604
- }, this._EventSource = s, this.config = Object.assign(Object.assign({}, Pu), e), this.queryCacheLimit = (o = this.config.queryCacheLimit) !== null && o !== void 0 ? o : 10, this._pendingTxCleanupTimeout = (a = this.config.pendingTxCleanupTimeout) !== null && a !== void 0 ? a : ju, this._pendingMutationCleanupThreshold = (u = this.config.pendingMutationCleanupThreshold) !== null && u !== void 0 ? u : Cu, this._log = cu(e.verbose || Gn || Ki, () => this._reactorStats()), this.versions = Object.assign(Object.assign({}, i || {}), { "@instantdb/core": Bn }), this.config.schema && (this._linkIndex = Fr(this.config.schema)), !!Mu()) {
4629
+ }, this._EventSource = s, this.config = Object.assign(Object.assign({}, Mu), e), this.queryCacheLimit = (o = this.config.queryCacheLimit) !== null && o !== void 0 ? o : 10, this._pendingTxCleanupTimeout = (a = this.config.pendingTxCleanupTimeout) !== null && a !== void 0 ? a : Pu, this._pendingMutationCleanupThreshold = (u = this.config.pendingMutationCleanupThreshold) !== null && u !== void 0 ? u : Iu, this._log = fu(e.verbose || Gn || qi, () => this._reactorStats()), this.versions = Object.assign(Object.assign({}, i || {}), { "@instantdb/core": Bn }), this.config.schema && (this._linkIndex = Nr(this.config.schema)), !!xu()) {
4605
4630
  if (!e.appId)
4606
4631
  throw new Error("Instant must be initialized with an appId.");
4607
4632
  if (!Ne(e.appId))
@@ -4616,7 +4641,7 @@ class Lu {
4616
4641
  } catch (f) {
4617
4642
  this._log.error("[error] handle broadcast channel", f);
4618
4643
  }
4619
- }))), this._initStorage(n), this._syncTable = new Eu(this._trySendAuthed.bind(this), new n(this.config.appId, "syncSubs"), {
4644
+ }))), this._initStorage(n), this._syncTable = new ku(this._trySendAuthed.bind(this), new n(this.config.appId, "syncSubs"), {
4620
4645
  useDateObjects: this.config.useDateObjects
4621
4646
  }, this._log, (c) => St(this.attrs, c, this.config.enableCardinalityInference, this._linkIndex, this.config.useDateObjects)), this._oauthCallbackResponse = this._oauthLoginInit(), this.getCurrentUser(), r.getIsOnline().then((c) => {
4622
4647
  this._isOnline = c, this._startSocket(), r.listen((d) => {
@@ -4626,7 +4651,7 @@ class Lu {
4626
4651
  }
4627
4652
  }
4628
4653
  updateSchema(e) {
4629
- this.config = Object.assign(Object.assign({}, this.config), { schema: e, cardinalityInference: !!e }), this._linkIndex = e ? Fr(this.config.schema) : null;
4654
+ this.config = Object.assign(Object.assign({}, this.config), { schema: e, cardinalityInference: !!e }), this._linkIndex = e ? Nr(this.config.schema) : null;
4630
4655
  }
4631
4656
  _reactorStats() {
4632
4657
  return {
@@ -4641,9 +4666,9 @@ class Lu {
4641
4666
  _initStorage(e) {
4642
4667
  this.querySubs = new wn(
4643
4668
  new e(this.config.appId, "querySubs"),
4644
- Uu,
4645
- xu,
4646
- (n, r) => Ru(r, this.config.useDateObjects),
4669
+ Fu,
4670
+ Du,
4671
+ (n, r) => $u(r, this.config.useDateObjects),
4647
4672
  // objectSize
4648
4673
  (n) => {
4649
4674
  var r, i, s, o;
@@ -4661,7 +4686,7 @@ class Lu {
4661
4686
  // 1 million triples
4662
4687
  }
4663
4688
  }
4664
- ), this.querySubs.onKeyLoaded = (n) => this._onQuerySubLoaded(n), this.kv = new wn(new e(this.config.appId, "kv"), this._onMergeKv, Du, $u, () => 0, this._log, {
4689
+ ), this.querySubs.onKeyLoaded = (n) => this._onQuerySubLoaded(n), this.kv = new wn(new e(this.config.appId, "kv"), this._onMergeKv, Lu, Uu, () => 0, this._log, {
4665
4690
  saveThrottleMs: 100,
4666
4691
  idleCallbackMaxWaitMs: 100,
4667
4692
  gc: {
@@ -4693,7 +4718,7 @@ class Lu {
4693
4718
  if (s)
4694
4719
  i.resolve({ status: e, eventId: n });
4695
4720
  else if (r.type) {
4696
- const { status: o } = r, a = Au(r, ["status"]);
4721
+ const { status: o } = r, a = ju(r, ["status"]);
4697
4722
  i.reject(new $t({
4698
4723
  // @ts-expect-error body.type is not constant typed
4699
4724
  body: a,
@@ -4717,7 +4742,7 @@ class Lu {
4717
4742
  _handleReceive(e, n) {
4718
4743
  var r, i, s, o, a, u;
4719
4744
  const c = !!this.config.schema && ("cardinalityInference" in this.config ? !!this.config.cardinalityInference : !0);
4720
- switch (Yr[n.op] || this._log.info("[receive]", e, n.op, n), n.op) {
4745
+ switch (Jr[n.op] || this._log.info("[receive]", e, n.op, n), n.op) {
4721
4746
  case "init-ok": {
4722
4747
  this._setStatus(le.AUTHENTICATED), this._reconnectTimeoutMs = 0, this._setAttrs(n.attrs), this._flushPendingMessages(), this._sessionId = n["session-id"];
4723
4748
  for (const l of Object.keys(this._rooms)) {
@@ -4734,7 +4759,7 @@ class Lu {
4734
4759
  const { q: l, result: p } = n, y = V(l);
4735
4760
  if (!this._hasQueryListeners() && !this.querySubs.currentValue[y])
4736
4761
  break;
4737
- const b = (o = (s = p == null ? void 0 : p[0]) === null || s === void 0 ? void 0 : s.data) === null || o === void 0 ? void 0 : o["page-info"], g = (u = (a = p == null ? void 0 : p[0]) === null || a === void 0 ? void 0 : a.data) === null || u === void 0 ? void 0 : u.aggregate, w = Lr(p), T = St(this.attrs, w, c, this._linkIndex, this.config.useDateObjects);
4762
+ const b = (o = (s = p == null ? void 0 : p[0]) === null || s === void 0 ? void 0 : s.data) === null || o === void 0 ? void 0 : o["page-info"], g = (u = (a = p == null ? void 0 : p[0]) === null || a === void 0 ? void 0 : a.data) === null || u === void 0 ? void 0 : u.aggregate, w = Fr(p), T = St(this.attrs, w, c, this._linkIndex, this.config.useDateObjects);
4738
4763
  this.querySubs.updateInPlace((m) => {
4739
4764
  if (!m[y]) {
4740
4765
  this._log.error("Missing value in querySubs", { hash: y, q: l });
@@ -4772,9 +4797,9 @@ class Lu {
4772
4797
  b !== this._pendingMutations() && this.kv.updateInPlace((T) => {
4773
4798
  T.pendingMutations = b;
4774
4799
  });
4775
- const g = Jr(b.entries()), w = l.map((T) => {
4800
+ const g = Zr(b.entries()), w = l.map((T) => {
4776
4801
  var m, E, S, I;
4777
- const x = T["instaql-query"], q = T["instaql-result"], we = V(x), dt = Lr(q), Lt = St(this.attrs, dt, c, this._linkIndex, this.config.useDateObjects), Ft = this._applyOptimisticUpdates(Lt, g, y), ft = (E = (m = q == null ? void 0 : q[0]) === null || m === void 0 ? void 0 : m.data) === null || E === void 0 ? void 0 : E["page-info"], ce = (I = (S = q == null ? void 0 : q[0]) === null || S === void 0 ? void 0 : S.data) === null || I === void 0 ? void 0 : I.aggregate;
4802
+ const x = T["instaql-query"], q = T["instaql-result"], we = V(x), dt = Fr(q), Lt = St(this.attrs, dt, c, this._linkIndex, this.config.useDateObjects), Ft = this._applyOptimisticUpdates(Lt, g, y), ft = (E = (m = q == null ? void 0 : q[0]) === null || m === void 0 ? void 0 : m.data) === null || E === void 0 ? void 0 : E["page-info"], ce = (I = (S = q == null ? void 0 : q[0]) === null || S === void 0 ? void 0 : S.data) === null || I === void 0 ? void 0 : I.aggregate;
4778
4803
  return { q: x, hash: we, store: Ft, pageInfo: ft, aggregate: ce };
4779
4804
  });
4780
4805
  w.forEach(({ hash: T, q: m, store: E, pageInfo: S, aggregate: I }) => {
@@ -4937,7 +4962,7 @@ class Lu {
4937
4962
  */
4938
4963
  subscribeQuery(e, n, r) {
4939
4964
  var i;
4940
- this.config.disableValidation || Kr(e, this.config.schema), r && "ruleParams" in r && (e = Object.assign({ $$ruleParams: r.ruleParams }, e));
4965
+ this.config.disableValidation || qr(e, this.config.schema), r && "ruleParams" in r && (e = Object.assign({ $$ruleParams: r.ruleParams }, e));
4941
4966
  const s = V(e), o = this.getPreviousResult(e);
4942
4967
  return o && n(o), this.queryCbs[s] = (i = this.queryCbs[s]) !== null && i !== void 0 ? i : [], this.queryCbs[s].push({ q: e, cb: n }), this._startQuerySub(e, s), () => {
4943
4968
  this._unsubQuery(e, s, n);
@@ -4945,14 +4970,14 @@ class Lu {
4945
4970
  }
4946
4971
  queryOnce(e, n) {
4947
4972
  var r;
4948
- this.config.disableValidation || Kr(e, this.config.schema), n && "ruleParams" in n && (e = Object.assign({ $$ruleParams: n.ruleParams }, e));
4949
- const i = new Dr();
4973
+ this.config.disableValidation || qr(e, this.config.schema), n && "ruleParams" in n && (e = Object.assign({ $$ruleParams: n.ruleParams }, e));
4974
+ const i = new Lr();
4950
4975
  if (!this._isOnline)
4951
4976
  return i.reject(new Error("We can't run `queryOnce`, because the device is offline.")), i.promise;
4952
4977
  if (!this.querySubs)
4953
4978
  return i.reject(new Error("We can't run `queryOnce` on the backend. Use adminAPI.query instead: https://www.instantdb.com/docs/backend#query")), i.promise;
4954
4979
  const s = V(e), o = this._startQuerySub(e, s);
4955
- return this.queryOnceDfds[s] = (r = this.queryOnceDfds[s]) !== null && r !== void 0 ? r : [], this.queryOnceDfds[s].push({ q: e, dfd: i, eventId: o }), setTimeout(() => i.reject(new Error("Query timed out")), ku), i.promise;
4980
+ return this.queryOnceDfds[s] = (r = this.queryOnceDfds[s]) !== null && r !== void 0 ? r : [], this.queryOnceDfds[s].push({ q: e, dfd: i, eventId: o }), setTimeout(() => i.reject(new Error("Query timed out")), Cu), i.promise;
4956
4981
  }
4957
4982
  _completeQueryOnce(e, n, r) {
4958
4983
  this.queryOnceDfds[n] && (this.queryOnceDfds[n] = this.queryOnceDfds[n].filter((i) => i.dfd !== r), this._cleanupQuery(e, n));
@@ -5013,7 +5038,7 @@ class Lu {
5013
5038
  a = !0;
5014
5039
  continue;
5015
5040
  }
5016
- const b = a ? ba(o, p) : p;
5041
+ const b = a ? _a(o, p) : p;
5017
5042
  l.push(b);
5018
5043
  }
5019
5044
  return a ? l : d;
@@ -5023,7 +5048,7 @@ class Lu {
5023
5048
  return a ? c : n;
5024
5049
  }
5025
5050
  _rewriteMutationsSorted(e, n) {
5026
- return Jr(this._rewriteMutations(e, n).entries());
5051
+ return Zr(this._rewriteMutations(e, n).entries());
5027
5052
  }
5028
5053
  // ---------------------------
5029
5054
  // Transact
@@ -5056,7 +5081,7 @@ class Lu {
5056
5081
  const c = this._dataForQueryCache[e];
5057
5082
  if (c && r === c.querySubVersion && s === c.pendingMutationsVersion)
5058
5083
  return c.data;
5059
- const { store: d, pageInfo: f, aggregate: l, processedTxId: p } = u, y = this._rewriteMutationsSorted(d.attrs, o), b = this._applyOptimisticUpdates(d, y, p), g = $i({ store: b, pageInfo: f, aggregate: l }, a);
5084
+ const { store: d, pageInfo: f, aggregate: l, processedTxId: p } = u, y = this._rewriteMutationsSorted(d.attrs, o), b = this._applyOptimisticUpdates(d, y, p), g = Di({ store: b, pageInfo: f, aggregate: l }, a);
5060
5085
  return this._dataForQueryCache[e] = {
5061
5086
  querySubVersion: r,
5062
5087
  pendingMutationsVersion: s,
@@ -5065,7 +5090,7 @@ class Lu {
5065
5090
  }
5066
5091
  _applyOptimisticUpdates(e, n, r) {
5067
5092
  for (const [i, s] of n)
5068
- (!s["tx-id"] || r && s["tx-id"] > r) && (e = _o(e, s["tx-steps"]));
5093
+ (!s["tx-id"] || r && s["tx-id"] > r) && (e = go(e, s["tx-steps"]));
5069
5094
  return e;
5070
5095
  }
5071
5096
  /** Re-compute all subscriptions */
@@ -5153,7 +5178,7 @@ class Lu {
5153
5178
  }
5154
5179
  _trySend(e, n, r) {
5155
5180
  if (this._transport.isOpen()) {
5156
- switch (Yr[n.op] || this._log.info("[send]", this._transport.id, n.op, n), n.op) {
5181
+ switch (Jr[n.op] || this._log.info("[send]", this._transport.id, n.op, n), n.op) {
5157
5182
  case "transact": {
5158
5183
  this._inFlightMutationEventIds.add(e);
5159
5184
  break;
@@ -5174,7 +5199,7 @@ class Lu {
5174
5199
  return;
5175
5200
  }
5176
5201
  const e = this._transport;
5177
- this._transport = Iu({
5202
+ this._transport = Ru({
5178
5203
  transportType: this._transportType,
5179
5204
  appId: this.config.appId,
5180
5205
  apiURI: this.config.apiURI,
@@ -5247,7 +5272,7 @@ class Lu {
5247
5272
  return null;
5248
5273
  this._replaceUrlAfterOAuth();
5249
5274
  try {
5250
- const u = yield this._getCurrentUser(), c = (u == null ? void 0 : u.type) === "guest", { user: d } = yield xr({
5275
+ const u = yield this._getCurrentUser(), c = (u == null ? void 0 : u.type) === "guest", { user: d } = yield Dr({
5251
5276
  apiURI: this.config.apiURI,
5252
5277
  appId: this.config.appId,
5253
5278
  code: a,
@@ -5377,7 +5402,7 @@ class Lu {
5377
5402
  }), this._reconnectTimeoutMs = 0, this._transport.close(), this._oauthCallbackResponse = null, this.notifyAuthSubs(n);
5378
5403
  }
5379
5404
  sendMagicCode({ email: e }) {
5380
- return Ya({
5405
+ return Za({
5381
5406
  apiURI: this.config.apiURI,
5382
5407
  appId: this.config.appId,
5383
5408
  email: e
@@ -5386,7 +5411,7 @@ class Lu {
5386
5411
  signInWithMagicCode(e) {
5387
5412
  return F(this, arguments, void 0, function* ({ email: n, code: r }) {
5388
5413
  var i;
5389
- const s = yield this.getCurrentUser(), o = ((i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.type) === "guest", a = yield Ja({
5414
+ const s = yield this.getCurrentUser(), o = ((i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.type) === "guest", a = yield Xa({
5390
5415
  apiURI: this.config.apiURI,
5391
5416
  appId: this.config.appId,
5392
5417
  email: n,
@@ -5398,7 +5423,7 @@ class Lu {
5398
5423
  }
5399
5424
  signInWithCustomToken(e) {
5400
5425
  return F(this, void 0, void 0, function* () {
5401
- const n = yield Za({
5426
+ const n = yield eu({
5402
5427
  apiURI: this.config.apiURI,
5403
5428
  appId: this.config.appId,
5404
5429
  refreshToken: e
@@ -5408,7 +5433,7 @@ class Lu {
5408
5433
  }
5409
5434
  signInAsGuest() {
5410
5435
  return F(this, void 0, void 0, function* () {
5411
- const e = yield Xa({
5436
+ const e = yield tu({
5412
5437
  apiURI: this.config.apiURI,
5413
5438
  appId: this.config.appId
5414
5439
  });
@@ -5424,7 +5449,7 @@ class Lu {
5424
5449
  this._log.info("[auth-invalidate] skipped invalidateToken");
5425
5450
  return;
5426
5451
  }
5427
- tu({
5452
+ ru({
5428
5453
  apiURI: this.config.apiURI,
5429
5454
  appId: this.config.appId,
5430
5455
  refreshToken: i
@@ -5459,7 +5484,7 @@ class Lu {
5459
5484
  exchangeCodeForToken(e) {
5460
5485
  return F(this, arguments, void 0, function* ({ code: n, codeVerifier: r }) {
5461
5486
  var i;
5462
- const s = yield this.getCurrentUser(), o = ((i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.type) === "guest", a = yield xr({
5487
+ const s = yield this.getCurrentUser(), o = ((i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.type) === "guest", a = yield Dr({
5463
5488
  apiURI: this.config.apiURI,
5464
5489
  appId: this.config.appId,
5465
5490
  code: n,
@@ -5482,7 +5507,7 @@ class Lu {
5482
5507
  signInWithIdToken(e) {
5483
5508
  return F(this, arguments, void 0, function* ({ idToken: n, clientName: r, nonce: i }) {
5484
5509
  var s;
5485
- const o = yield this.getCurrentUser(), a = (s = o == null ? void 0 : o.user) === null || s === void 0 ? void 0 : s.refresh_token, u = yield eu({
5510
+ const o = yield this.getCurrentUser(), a = (s = o == null ? void 0 : o.user) === null || s === void 0 ? void 0 : s.refresh_token, u = yield nu({
5486
5511
  apiURI: this.config.apiURI,
5487
5512
  appId: this.config.appId,
5488
5513
  idToken: n,
@@ -5523,7 +5548,7 @@ class Lu {
5523
5548
  // TODO: look into typing again
5524
5549
  getPresence(e, n, r = {}) {
5525
5550
  const i = this._rooms[n], s = this._presence[n];
5526
- return !i || !s || !s.result ? null : Object.assign(Object.assign({}, au(s.result, r, this._sessionId)), { isLoading: !i.isConnected, error: i.error });
5551
+ return !i || !s || !s.result ? null : Object.assign(Object.assign({}, cu(s.result, r, this._sessionId)), { isLoading: !i.isConnected, error: i.error });
5527
5552
  }
5528
5553
  // TODO: look into typing again
5529
5554
  publishPresence(e, n, r) {
@@ -5573,7 +5598,7 @@ class Lu {
5573
5598
  }
5574
5599
  _notifyPresenceSub(e, n) {
5575
5600
  const r = this.getPresence("", e, n);
5576
- r && (n.prev && !uu(r, n.prev) || (n.prev = r, n.cb(r)));
5601
+ r && (n.prev && !du(r, n.prev) || (n.prev = r, n.cb(r)));
5577
5602
  }
5578
5603
  _patchPresencePeers(e, n) {
5579
5604
  var r, i, s;
@@ -5584,13 +5609,13 @@ class Lu {
5584
5609
  for (let [d, f, l] of n)
5585
5610
  switch (f) {
5586
5611
  case "+":
5587
- Fs(c, d, l);
5612
+ Ns(c, d, l);
5588
5613
  break;
5589
5614
  case "r":
5590
5615
  Or(c, d, l);
5591
5616
  break;
5592
5617
  case "-":
5593
- gi(c, d);
5618
+ Ti(c, d);
5594
5619
  break;
5595
5620
  }
5596
5621
  delete c[this._sessionId];
@@ -5647,14 +5672,14 @@ class Lu {
5647
5672
  return F(this, void 0, void 0, function* () {
5648
5673
  var i;
5649
5674
  const s = yield this.getCurrentUser(), o = (i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.refresh_token;
5650
- return nu(Object.assign(Object.assign({}, r), { apiURI: this.config.apiURI, appId: this.config.appId, path: e, file: n, refreshToken: o }));
5675
+ return iu(Object.assign(Object.assign({}, r), { apiURI: this.config.apiURI, appId: this.config.appId, path: e, file: n, refreshToken: o }));
5651
5676
  });
5652
5677
  }
5653
5678
  deleteFile(e) {
5654
5679
  return F(this, void 0, void 0, function* () {
5655
5680
  var n;
5656
5681
  const r = yield this.getCurrentUser(), i = (n = r == null ? void 0 : r.user) === null || n === void 0 ? void 0 : n.refresh_token;
5657
- return yield ru({
5682
+ return yield su({
5658
5683
  apiURI: this.config.apiURI,
5659
5684
  appId: this.config.appId,
5660
5685
  path: e,
@@ -5667,20 +5692,20 @@ class Lu {
5667
5692
  upload(e, n) {
5668
5693
  return F(this, void 0, void 0, function* () {
5669
5694
  var r;
5670
- const i = yield this.getCurrentUser(), s = (r = i == null ? void 0 : i.user) === null || r === void 0 ? void 0 : r.refresh_token, o = e || n.name, a = yield iu({
5695
+ const i = yield this.getCurrentUser(), s = (r = i == null ? void 0 : i.user) === null || r === void 0 ? void 0 : r.refresh_token, o = e || n.name, a = yield ou({
5671
5696
  apiURI: this.config.apiURI,
5672
5697
  appId: this.config.appId,
5673
5698
  fileName: o,
5674
5699
  refreshToken: s
5675
5700
  });
5676
- return yield su(a, n);
5701
+ return yield au(a, n);
5677
5702
  });
5678
5703
  }
5679
5704
  getDownloadUrl(e) {
5680
5705
  return F(this, void 0, void 0, function* () {
5681
5706
  var n;
5682
5707
  const r = yield this.getCurrentUser(), i = (n = r == null ? void 0 : r.user) === null || n === void 0 ? void 0 : n.refresh_token;
5683
- return yield ou({
5708
+ return yield uu({
5684
5709
  apiURI: this.config.apiURI,
5685
5710
  appId: this.config.appId,
5686
5711
  path: e,
@@ -5689,9 +5714,9 @@ class Lu {
5689
5714
  });
5690
5715
  }
5691
5716
  }
5692
- function Fu(t, e) {
5717
+ function Ku(t, e) {
5693
5718
  return new Ut(
5694
- Yi(t, e),
5719
+ Ji(t, e),
5695
5720
  // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the
5696
5721
  // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
5697
5722
  // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are
@@ -5701,28 +5726,28 @@ function Fu(t, e) {
5701
5726
  void 0
5702
5727
  );
5703
5728
  }
5704
- function Nu(t) {
5729
+ function qu(t) {
5705
5730
  return new Dt(t, {});
5706
5731
  }
5707
- function Ku() {
5732
+ function Wu() {
5708
5733
  return new H("string", !0, !1);
5709
5734
  }
5710
- function qu() {
5735
+ function zu() {
5711
5736
  return new H("number", !0, !1);
5712
5737
  }
5713
- function Wu() {
5738
+ function Vu() {
5714
5739
  return new H("boolean", !0, !1);
5715
5740
  }
5716
- function zu() {
5741
+ function Gu() {
5717
5742
  return new H("date", !0, !1);
5718
5743
  }
5719
- function Vu() {
5744
+ function Bu() {
5720
5745
  return new H("json", !0, !1);
5721
5746
  }
5722
- function Gu() {
5747
+ function Qu() {
5723
5748
  return new H("json", !0, !1);
5724
5749
  }
5725
- function Yi(t, e) {
5750
+ function Ji(t, e) {
5726
5751
  var n, r, i, s;
5727
5752
  const o = { fwd: {}, rev: {} };
5728
5753
  for (const u of Object.values(e))
@@ -5738,10 +5763,10 @@ function Yi(t, e) {
5738
5763
  new Dt(c.attrs, Object.assign(Object.assign({}, o.fwd[u]), o.rev[u]))
5739
5764
  ]));
5740
5765
  }
5741
- function Bu({ entities: t, links: e, rooms: n }) {
5766
+ function Hu({ entities: t, links: e, rooms: n }) {
5742
5767
  const r = e ?? {}, i = n ?? {};
5743
5768
  return new Ut(
5744
- Yi(t, r),
5769
+ Ji(t, r),
5745
5770
  // (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the
5746
5771
  // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
5747
5772
  // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are
@@ -5751,23 +5776,23 @@ function Bu({ entities: t, links: e, rooms: n }) {
5751
5776
  i
5752
5777
  );
5753
5778
  }
5754
- const Lc = {
5779
+ const Nc = {
5755
5780
  // constructs
5756
- graph: Fu,
5757
- schema: Bu,
5758
- entity: Nu,
5781
+ graph: Ku,
5782
+ schema: Hu,
5783
+ entity: qu,
5759
5784
  // value types
5760
- string: Ku,
5761
- number: qu,
5762
- boolean: Wu,
5763
- date: zu,
5764
- json: Vu,
5765
- any: Gu
5785
+ string: Wu,
5786
+ number: zu,
5787
+ boolean: Vu,
5788
+ date: Gu,
5789
+ json: Bu,
5790
+ any: Qu
5766
5791
  };
5767
5792
  let Tt;
5768
- function Qu(t, e) {
5793
+ function Yu(t, e) {
5769
5794
  Tt == null || Tt.dispose();
5770
- const n = ec(e), r = Ju(e, a), i = Yu(Hu(t));
5795
+ const n = nc(e), r = Xu(e, a), i = Zu(Ju(t));
5771
5796
  function s(d) {
5772
5797
  var f;
5773
5798
  d.source === i.element.contentWindow && ((f = d.data) === null || f === void 0 ? void 0 : f.type) === "close" && n.isVisible() && a();
@@ -5789,10 +5814,10 @@ function Qu(t, e) {
5789
5814
  }
5790
5815
  return c();
5791
5816
  }
5792
- function Hu(t) {
5793
- return `${Gn || qi ? "http://localhost:3000" : "https://instantdb.com"}/_devtool?appId=${t}`;
5817
+ function Ju(t) {
5818
+ return `${Gn || Wi ? "http://localhost:3000" : "https://instantdb.com"}/_devtool?appId=${t}`;
5794
5819
  }
5795
- function Yu(t) {
5820
+ function Zu(t) {
5796
5821
  const e = document.createElement("iframe");
5797
5822
  return e.src = t, e.className = "instant-devtool-iframe", Object.assign(e.style, {
5798
5823
  width: "100%",
@@ -5801,7 +5826,7 @@ function Yu(t) {
5801
5826
  border: "none"
5802
5827
  }), { element: e };
5803
5828
  }
5804
- function Ju(t, e) {
5829
+ function Xu(t, e) {
5805
5830
  const n = `
5806
5831
  <svg width="32" height="32" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
5807
5832
  <rect width="512" height="512" fill="black"/>
@@ -5811,7 +5836,7 @@ function Ju(t, e) {
5811
5836
  return r.innerHTML = n, r.className = "instant-devtool-toggler", Object.assign(r.style, Object.assign(Object.assign({
5812
5837
  // pos
5813
5838
  position: "fixed"
5814
- }, Zu(t.position)), {
5839
+ }, ec(t.position)), {
5815
5840
  height: "32px",
5816
5841
  width: "32px",
5817
5842
  // layout
@@ -5826,7 +5851,7 @@ function Ju(t, e) {
5826
5851
  cursor: "pointer"
5827
5852
  })), r.addEventListener("click", e), { element: r };
5828
5853
  }
5829
- function Zu(t) {
5854
+ function ec(t) {
5830
5855
  switch (t) {
5831
5856
  case "bottom-left":
5832
5857
  return { bottom: "24px", left: "24px" };
@@ -5838,7 +5863,7 @@ function Zu(t) {
5838
5863
  return { top: "24px", left: "24px" };
5839
5864
  }
5840
5865
  }
5841
- function Xu(t) {
5866
+ function tc(t) {
5842
5867
  switch (t) {
5843
5868
  case "bottom-left":
5844
5869
  return { bottom: "24px", right: "24px", left: "60px", top: "72px" };
@@ -5850,23 +5875,23 @@ function Xu(t) {
5850
5875
  return { top: "24px", right: "24px", left: "60px", bottom: "72px" };
5851
5876
  }
5852
5877
  }
5853
- function ec(t) {
5878
+ function nc(t) {
5854
5879
  const e = document.createElement("div");
5855
- Object.assign(e.style, Object.assign(Object.assign({ position: "fixed" }, Xu(t.position)), { display: "block", borderRadius: "4px", border: "1px #ccc solid", boxShadow: "0px 0px 8px #00000044", backgroundColor: "#eee", zIndex: "999990" })), e.style.display = "none", e.className = "instant-devtool-container";
5880
+ Object.assign(e.style, Object.assign(Object.assign({ position: "fixed" }, tc(t.position)), { display: "block", borderRadius: "4px", border: "1px #ccc solid", boxShadow: "0px 0px 8px #00000044", backgroundColor: "#eee", zIndex: "999990" })), e.style.display = "none", e.className = "instant-devtool-container";
5856
5881
  function n() {
5857
5882
  return e.style.display !== "none";
5858
5883
  }
5859
5884
  return { element: e, isVisible: n };
5860
5885
  }
5861
- const tc = {
5886
+ const rc = {
5862
5887
  apiURI: "https://api.instantdb.com",
5863
5888
  websocketURI: "wss://api.instantdb.com/runtime/session"
5864
5889
  };
5865
- function nc() {
5890
+ function ic() {
5866
5891
  var t;
5867
5892
  return globalThis.__instantDbSchemaHashStore = (t = globalThis.__instantDbSchemaHashStore) !== null && t !== void 0 ? t : /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
5868
5893
  }
5869
- function rc() {
5894
+ function sc() {
5870
5895
  var t;
5871
5896
  return globalThis.__instantDbStore = (t = globalThis.__instantDbStore) !== null && t !== void 0 ? t : {}, globalThis.__instantDbStore;
5872
5897
  }
@@ -5874,23 +5899,23 @@ function mn(t) {
5874
5899
  const e = t.__adminToken;
5875
5900
  return t.appId + "_" + (t.websocketURI || "default_ws_uri") + "_" + (t.apiURI || "default_api_uri") + "_" + (e || "client_only") + "_" + t.useDateObjects;
5876
5901
  }
5877
- const vn = rc(), en = nc();
5878
- class ic {
5902
+ const vn = sc(), en = ic();
5903
+ class oc {
5879
5904
  constructor(e) {
5880
5905
  this.db = e, this.sendMagicCode = (n) => this.db.sendMagicCode(n), this.signInWithMagicCode = (n) => this.db.signInWithMagicCode(n), this.signInWithToken = (n) => this.db.signInWithCustomToken(n), this.signInAsGuest = () => this.db.signInAsGuest(), this.createAuthorizationURL = (n) => this.db.createAuthorizationURL(n), this.signInWithIdToken = (n) => this.db.signInWithIdToken(n), this.exchangeOAuthCode = (n) => this.db.exchangeCodeForToken(n), this.issuerURI = () => this.db.issuerURI(), this.signOut = (n = { invalidateToken: !0 }) => this.db.signOut(n);
5881
5906
  }
5882
5907
  }
5883
- class sc {
5908
+ class ac {
5884
5909
  constructor(e) {
5885
5910
  this.db = e, this.uploadFile = (n, r, i = {}) => this.db.uploadFile(n, r, i), this.delete = (n) => this.db.deleteFile(n), this.upload = (n, r) => this.db.upload(n, r), this.put = this.upload, this.getDownloadUrl = (n) => this.db.getDownloadUrl(n);
5886
5911
  }
5887
5912
  }
5888
- function oc(t) {
5913
+ function uc(t) {
5889
5914
  return JSON.parse(JSON.stringify(t));
5890
5915
  }
5891
- class ac {
5916
+ class cc {
5892
5917
  constructor(e) {
5893
- this.tx = Vn(), this._reactor = e, this.auth = new ic(this._reactor), this.storage = new sc(this._reactor);
5918
+ this.tx = Vn(), this._reactor = e, this.auth = new oc(this._reactor), this.storage = new ac(this._reactor);
5894
5919
  }
5895
5920
  /**
5896
5921
  * Use this to write data! You can create, update, delete, and link objects
@@ -6064,7 +6089,7 @@ class ac {
6064
6089
  return this._reactor.subscribeTable(e, n);
6065
6090
  }
6066
6091
  }
6067
- function Zr(t) {
6092
+ function Xr(t) {
6068
6093
  if (!t)
6069
6094
  return "0";
6070
6095
  if (en.get(t))
@@ -6072,21 +6097,21 @@ function Zr(t) {
6072
6097
  const e = V(t);
6073
6098
  return en.set(t, e), e;
6074
6099
  }
6075
- function uc(t, e) {
6076
- return Zr(t._reactor.config.schema) !== Zr(e);
6100
+ function dc(t, e) {
6101
+ return Xr(t._reactor.config.schema) !== Xr(e);
6077
6102
  }
6078
- function cc(t, e, n, r, i) {
6103
+ function fc(t, e, n, r, i) {
6079
6104
  const s = vn[mn(t)];
6080
6105
  if (s)
6081
- return uc(s, t.schema) && s._reactor.updateSchema(t.schema), s;
6082
- const o = new Lu(Object.assign(Object.assign(Object.assign({}, tc), t), { cardinalityInference: !!t.schema }), e || Fi, n || Ni, Object.assign(Object.assign({}, r || {}), { "@instantdb/core": Bn }), i), a = new ac(o);
6083
- return vn[mn(t)] = a, dc(t.appId, t.devtool), a;
6106
+ return dc(s, t.schema) && s._reactor.updateSchema(t.schema), s;
6107
+ const o = new Nu(Object.assign(Object.assign(Object.assign({}, rc), t), { cardinalityInference: !!t.schema }), e || Ni, n || Ki, Object.assign(Object.assign({}, r || {}), { "@instantdb/core": Bn }), i), a = new cc(o);
6108
+ return vn[mn(t)] = a, lc(t.appId, t.devtool), a;
6084
6109
  }
6085
- function dc(t, e) {
6110
+ function lc(t, e) {
6086
6111
  if (typeof window > "u" || typeof window.location > "u" || typeof document > "u" || typeof e == "boolean" && !e)
6087
6112
  return;
6088
6113
  const n = Object.assign({ position: "bottom-right", allowedHosts: ["localhost"] }, typeof e == "object" ? e : {});
6089
- n.allowedHosts.includes(window.location.hostname) && Qu(t, n);
6114
+ n.allowedHosts.includes(window.location.hostname) && Yu(t, n);
6090
6115
  }
6091
6116
  var Sn = { exports: {} }, He = {};
6092
6117
  /**
@@ -6098,11 +6123,11 @@ var Sn = { exports: {} }, He = {};
6098
6123
  * This source code is licensed under the MIT license found in the
6099
6124
  * LICENSE file in the root directory of this source tree.
6100
6125
  */
6101
- var Xr;
6102
- function fc() {
6103
- if (Xr) return He;
6104
- Xr = 1;
6105
- var t = ai, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, i = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 };
6126
+ var ei;
6127
+ function hc() {
6128
+ if (ei) return He;
6129
+ ei = 1;
6130
+ var t = ui, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, i = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 };
6106
6131
  function o(a, u, c) {
6107
6132
  var d, f = {}, l = null, p = null;
6108
6133
  c !== void 0 && (l = "" + c), u.key !== void 0 && (l = "" + u.key), u.ref !== void 0 && (p = u.ref);
@@ -6112,10 +6137,10 @@ function fc() {
6112
6137
  }
6113
6138
  return He.Fragment = n, He.jsx = o, He.jsxs = o, He;
6114
6139
  }
6115
- var Ye = {}, ei;
6116
- function lc() {
6117
- if (ei) return Ye;
6118
- ei = 1;
6140
+ var Ye = {}, ti;
6141
+ function pc() {
6142
+ if (ti) return Ye;
6143
+ ti = 1;
6119
6144
  var t = {};
6120
6145
  /**
6121
6146
  * @license React
@@ -6127,7 +6152,7 @@ function lc() {
6127
6152
  * LICENSE file in the root directory of this source tree.
6128
6153
  */
6129
6154
  return t.NODE_ENV !== "production" && function() {
6130
- var e = ai, n = Symbol.for("react.element"), r = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), o = Symbol.for("react.profiler"), a = Symbol.for("react.provider"), u = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), d = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), l = Symbol.for("react.memo"), p = Symbol.for("react.lazy"), y = Symbol.for("react.offscreen"), b = Symbol.iterator, g = "@@iterator";
6155
+ var e = ui, n = Symbol.for("react.element"), r = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), o = Symbol.for("react.profiler"), a = Symbol.for("react.provider"), u = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), d = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), l = Symbol.for("react.memo"), p = Symbol.for("react.lazy"), y = Symbol.for("react.offscreen"), b = Symbol.iterator, g = "@@iterator";
6131
6156
  function w(h) {
6132
6157
  if (h === null || typeof h != "object")
6133
6158
  return null;
@@ -6220,7 +6245,7 @@ function lc() {
6220
6245
  function rr() {
6221
6246
  }
6222
6247
  rr.__reactDisabledLog = !0;
6223
- function Zi() {
6248
+ function Xi() {
6224
6249
  {
6225
6250
  if (Ge === 0) {
6226
6251
  Yn = console.log, Jn = console.info, Zn = console.warn, Xn = console.error, er = console.group, tr = console.groupCollapsed, nr = console.groupEnd;
@@ -6243,7 +6268,7 @@ function lc() {
6243
6268
  Ge++;
6244
6269
  }
6245
6270
  }
6246
- function Xi() {
6271
+ function es() {
6247
6272
  {
6248
6273
  if (Ge--, Ge === 0) {
6249
6274
  var h = {
@@ -6294,8 +6319,8 @@ function lc() {
6294
6319
  }
6295
6320
  var qt = !1, ht;
6296
6321
  {
6297
- var es = typeof WeakMap == "function" ? WeakMap : Map;
6298
- ht = new es();
6322
+ var ts = typeof WeakMap == "function" ? WeakMap : Map;
6323
+ ht = new ts();
6299
6324
  }
6300
6325
  function ir(h, _) {
6301
6326
  if (!h || qt)
@@ -6310,7 +6335,7 @@ function lc() {
6310
6335
  var P = Error.prepareStackTrace;
6311
6336
  Error.prepareStackTrace = void 0;
6312
6337
  var M;
6313
- M = Nt.current, Nt.current = null, Zi();
6338
+ M = Nt.current, Nt.current = null, Xi();
6314
6339
  try {
6315
6340
  if (_) {
6316
6341
  var C = function() {
@@ -6363,15 +6388,15 @@ function lc() {
6363
6388
  }
6364
6389
  }
6365
6390
  } finally {
6366
- qt = !1, Nt.current = M, Xi(), Error.prepareStackTrace = P;
6391
+ qt = !1, Nt.current = M, es(), Error.prepareStackTrace = P;
6367
6392
  }
6368
6393
  var Me = h ? h.displayName || h.name : "", ve = Me ? lt(Me) : "";
6369
6394
  return typeof h == "function" && ht.set(h, ve), ve;
6370
6395
  }
6371
- function ts(h, _, v) {
6396
+ function ns(h, _, v) {
6372
6397
  return ir(h, !1);
6373
6398
  }
6374
- function ns(h) {
6399
+ function rs(h) {
6375
6400
  var _ = h.prototype;
6376
6401
  return !!(_ && _.isReactComponent);
6377
6402
  }
@@ -6379,7 +6404,7 @@ function lc() {
6379
6404
  if (h == null)
6380
6405
  return "";
6381
6406
  if (typeof h == "function")
6382
- return ir(h, ns(h));
6407
+ return ir(h, rs(h));
6383
6408
  if (typeof h == "string")
6384
6409
  return lt(h);
6385
6410
  switch (h) {
@@ -6391,7 +6416,7 @@ function lc() {
6391
6416
  if (typeof h == "object")
6392
6417
  switch (h.$$typeof) {
6393
6418
  case c:
6394
- return ts(h.render);
6419
+ return ns(h.render);
6395
6420
  case l:
6396
6421
  return pt(h.type, _, v);
6397
6422
  case p: {
@@ -6412,7 +6437,7 @@ function lc() {
6412
6437
  } else
6413
6438
  or.setExtraStackFrame(null);
6414
6439
  }
6415
- function rs(h, _, v, O, P) {
6440
+ function is(h, _, v, O, P) {
6416
6441
  {
6417
6442
  var M = Function.call.bind(Be);
6418
6443
  for (var C in h)
@@ -6431,17 +6456,17 @@ function lc() {
6431
6456
  }
6432
6457
  }
6433
6458
  }
6434
- var is = Array.isArray;
6459
+ var ss = Array.isArray;
6435
6460
  function Wt(h) {
6436
- return is(h);
6461
+ return ss(h);
6437
6462
  }
6438
- function ss(h) {
6463
+ function os(h) {
6439
6464
  {
6440
6465
  var _ = typeof Symbol == "function" && Symbol.toStringTag, v = _ && h[Symbol.toStringTag] || h.constructor.name || "Object";
6441
6466
  return v;
6442
6467
  }
6443
6468
  }
6444
- function os(h) {
6469
+ function as(h) {
6445
6470
  try {
6446
6471
  return ar(h), !1;
6447
6472
  } catch {
@@ -6452,16 +6477,16 @@ function lc() {
6452
6477
  return "" + h;
6453
6478
  }
6454
6479
  function ur(h) {
6455
- if (os(h))
6456
- return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ss(h)), ar(h);
6480
+ if (as(h))
6481
+ return m("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", os(h)), ar(h);
6457
6482
  }
6458
- var cr = T.ReactCurrentOwner, as = {
6483
+ var cr = T.ReactCurrentOwner, us = {
6459
6484
  key: !0,
6460
6485
  ref: !0,
6461
6486
  __self: !0,
6462
6487
  __source: !0
6463
6488
  }, dr, fr;
6464
- function us(h) {
6489
+ function cs(h) {
6465
6490
  if (Be.call(h, "ref")) {
6466
6491
  var _ = Object.getOwnPropertyDescriptor(h, "ref").get;
6467
6492
  if (_ && _.isReactWarning)
@@ -6469,7 +6494,7 @@ function lc() {
6469
6494
  }
6470
6495
  return h.ref !== void 0;
6471
6496
  }
6472
- function cs(h) {
6497
+ function ds(h) {
6473
6498
  if (Be.call(h, "key")) {
6474
6499
  var _ = Object.getOwnPropertyDescriptor(h, "key").get;
6475
6500
  if (_ && _.isReactWarning)
@@ -6477,10 +6502,10 @@ function lc() {
6477
6502
  }
6478
6503
  return h.key !== void 0;
6479
6504
  }
6480
- function ds(h, _) {
6505
+ function fs(h, _) {
6481
6506
  typeof h.ref == "string" && cr.current;
6482
6507
  }
6483
- function fs(h, _) {
6508
+ function ls(h, _) {
6484
6509
  {
6485
6510
  var v = function() {
6486
6511
  dr || (dr = !0, m("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", _));
@@ -6491,7 +6516,7 @@ function lc() {
6491
6516
  });
6492
6517
  }
6493
6518
  }
6494
- function ls(h, _) {
6519
+ function hs(h, _) {
6495
6520
  {
6496
6521
  var v = function() {
6497
6522
  fr || (fr = !0, m("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", _));
@@ -6502,7 +6527,7 @@ function lc() {
6502
6527
  });
6503
6528
  }
6504
6529
  }
6505
- var hs = function(h, _, v, O, P, M, C) {
6530
+ var ps = function(h, _, v, O, P, M, C) {
6506
6531
  var k = {
6507
6532
  // This tag allows us to uniquely identify this as a React Element
6508
6533
  $$typeof: n,
@@ -6531,12 +6556,12 @@ function lc() {
6531
6556
  value: P
6532
6557
  }), Object.freeze && (Object.freeze(k.props), Object.freeze(k)), k;
6533
6558
  };
6534
- function ps(h, _, v, O, P) {
6559
+ function ys(h, _, v, O, P) {
6535
6560
  {
6536
6561
  var M, C = {}, k = null, B = null;
6537
- v !== void 0 && (ur(v), k = "" + v), cs(_) && (ur(_.key), k = "" + _.key), us(_) && (B = _.ref, ds(_, P));
6562
+ v !== void 0 && (ur(v), k = "" + v), ds(_) && (ur(_.key), k = "" + _.key), cs(_) && (B = _.ref, fs(_, P));
6538
6563
  for (M in _)
6539
- Be.call(_, M) && !as.hasOwnProperty(M) && (C[M] = _[M]);
6564
+ Be.call(_, M) && !us.hasOwnProperty(M) && (C[M] = _[M]);
6540
6565
  if (h && h.defaultProps) {
6541
6566
  var D = h.defaultProps;
6542
6567
  for (M in D)
@@ -6544,9 +6569,9 @@ function lc() {
6544
6569
  }
6545
6570
  if (k || B) {
6546
6571
  var L = typeof h == "function" ? h.displayName || h.name || "Unknown" : h;
6547
- k && fs(C, L), B && ls(C, L);
6572
+ k && ls(C, L), B && hs(C, L);
6548
6573
  }
6549
- return hs(h, k, B, P, O, cr.current, C);
6574
+ return ps(h, k, B, P, O, cr.current, C);
6550
6575
  }
6551
6576
  }
6552
6577
  var zt = T.ReactCurrentOwner, lr = T.ReactDebugCurrentFrame;
@@ -6574,11 +6599,11 @@ Check the render method of \`` + h + "`.";
6574
6599
  return "";
6575
6600
  }
6576
6601
  }
6577
- function ys(h) {
6602
+ function bs(h) {
6578
6603
  return "";
6579
6604
  }
6580
6605
  var pr = {};
6581
- function bs(h) {
6606
+ function _s(h) {
6582
6607
  {
6583
6608
  var _ = hr();
6584
6609
  if (!_) {
@@ -6595,7 +6620,7 @@ Check the top-level render call using <` + v + ">.");
6595
6620
  if (!h._store || h._store.validated || h.key != null)
6596
6621
  return;
6597
6622
  h._store.validated = !0;
6598
- var v = bs(_);
6623
+ var v = _s(_);
6599
6624
  if (pr[v])
6600
6625
  return;
6601
6626
  pr[v] = !0;
@@ -6622,7 +6647,7 @@ Check the top-level render call using <` + v + ">.");
6622
6647
  }
6623
6648
  }
6624
6649
  }
6625
- function _s(h) {
6650
+ function gs(h) {
6626
6651
  {
6627
6652
  var _ = h.type;
6628
6653
  if (_ == null || typeof _ == "string")
@@ -6638,7 +6663,7 @@ Check the top-level render call using <` + v + ">.");
6638
6663
  return;
6639
6664
  if (v) {
6640
6665
  var O = ce(_);
6641
- rs(v, h.props, "prop", O, h);
6666
+ is(v, h.props, "prop", O, h);
6642
6667
  } else if (_.PropTypes !== void 0 && !Vt) {
6643
6668
  Vt = !0;
6644
6669
  var P = ce(_);
@@ -6647,7 +6672,7 @@ Check the top-level render call using <` + v + ">.");
6647
6672
  typeof _.getDefaultProps == "function" && !_.getDefaultProps.isReactClassApproved && m("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
6648
6673
  }
6649
6674
  }
6650
- function gs(h) {
6675
+ function Ts(h) {
6651
6676
  {
6652
6677
  for (var _ = Object.keys(h.props), v = 0; v < _.length; v++) {
6653
6678
  var O = _[v];
@@ -6666,12 +6691,12 @@ Check the top-level render call using <` + v + ">.");
6666
6691
  if (!C) {
6667
6692
  var k = "";
6668
6693
  (h === void 0 || typeof h == "object" && h !== null && Object.keys(h).length === 0) && (k += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
6669
- var B = ys();
6694
+ var B = bs();
6670
6695
  B ? k += B : k += hr();
6671
6696
  var D;
6672
6697
  h === null ? D = "null" : Wt(h) ? D = "array" : h !== void 0 && h.$$typeof === n ? (D = "<" + (ce(h.type) || "Unknown") + " />", k = " Did you accidentally export a JSX literal instead of a component?") : D = typeof h, m("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", D, k);
6673
6698
  }
6674
- var L = ps(h, _, v, P, M);
6699
+ var L = ys(h, _, v, P, M);
6675
6700
  if (L == null)
6676
6701
  return L;
6677
6702
  if (C) {
@@ -6688,57 +6713,57 @@ Check the top-level render call using <` + v + ">.");
6688
6713
  br(re, h);
6689
6714
  }
6690
6715
  if (Be.call(_, "key")) {
6691
- var ve = ce(h), Y = Object.keys(_).filter(function(Os) {
6692
- return Os !== "key";
6716
+ var ve = ce(h), Y = Object.keys(_).filter(function(Es) {
6717
+ return Es !== "key";
6693
6718
  }), Bt = Y.length > 0 ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}";
6694
6719
  if (!_r[ve + Bt]) {
6695
- var Ss = Y.length > 0 ? "{" + Y.join(": ..., ") + ": ...}" : "{}";
6720
+ var Os = Y.length > 0 ? "{" + Y.join(": ..., ") + ": ...}" : "{}";
6696
6721
  m(`A props object containing a "key" prop is being spread into JSX:
6697
6722
  let props = %s;
6698
6723
  <%s {...props} />
6699
6724
  React keys must be passed directly to JSX without using spread:
6700
6725
  let props = %s;
6701
- <%s key={someKey} {...props} />`, Bt, ve, Ss, ve), _r[ve + Bt] = !0;
6726
+ <%s key={someKey} {...props} />`, Bt, ve, Os, ve), _r[ve + Bt] = !0;
6702
6727
  }
6703
6728
  }
6704
- return h === i ? gs(L) : _s(L), L;
6729
+ return h === i ? Ts(L) : gs(L), L;
6705
6730
  }
6706
6731
  }
6707
- function Ts(h, _, v) {
6732
+ function ws(h, _, v) {
6708
6733
  return gr(h, _, v, !0);
6709
6734
  }
6710
- function ws(h, _, v) {
6735
+ function ms(h, _, v) {
6711
6736
  return gr(h, _, v, !1);
6712
6737
  }
6713
- var ms = ws, vs = Ts;
6714
- Ye.Fragment = i, Ye.jsx = ms, Ye.jsxs = vs;
6738
+ var vs = ms, Ss = ws;
6739
+ Ye.Fragment = i, Ye.jsx = vs, Ye.jsxs = Ss;
6715
6740
  }(), Ye;
6716
6741
  }
6717
- var hc = {};
6718
- hc.NODE_ENV === "production" ? Sn.exports = fc() : Sn.exports = lc();
6742
+ var yc = {};
6743
+ yc.NODE_ENV === "production" ? Sn.exports = hc() : Sn.exports = pc();
6719
6744
  var z = Sn.exports;
6720
- const pc = {
6745
+ const bc = {
6721
6746
  isLoading: !0,
6722
6747
  data: void 0,
6723
6748
  pageInfo: void 0,
6724
6749
  error: void 0
6725
6750
  };
6726
- function ti(t) {
6751
+ function ni(t) {
6727
6752
  return Object.assign({ isLoading: !t, data: void 0, pageInfo: void 0, error: void 0 }, t || {});
6728
6753
  }
6729
- function yc(t, e, n) {
6754
+ function _c(t, e, n) {
6730
6755
  e && n && "ruleParams" in n && (e = Object.assign({ $$ruleParams: n.ruleParams }, e));
6731
- const r = e ? oc(e) : null, i = V(r), s = At(ti(t._reactor.getPreviousResult(r))), o = ge(
6732
- (u) => (s.current = ti(t._reactor.getPreviousResult(r)), r ? t.subscribeQuery(r, (d) => {
6756
+ const r = e ? uc(e) : null, i = V(r), s = At(ni(t._reactor.getPreviousResult(r))), o = ge(
6757
+ (u) => (s.current = ni(t._reactor.getPreviousResult(r)), r ? t.subscribeQuery(r, (d) => {
6733
6758
  s.current = Object.assign({ isLoading: !d, data: void 0, pageInfo: void 0, error: void 0 }, d), u();
6734
6759
  }) : () => {
6735
6760
  }),
6736
6761
  // Build a new subscribe function if the query changes
6737
6762
  [i]
6738
6763
  );
6739
- return { state: nn(o, () => s.current, () => pc), query: r };
6764
+ return { state: nn(o, () => s.current, () => bc), query: r };
6740
6765
  }
6741
- function bc() {
6766
+ function gc() {
6742
6767
  const t = At(null);
6743
6768
  je(() => {
6744
6769
  n();
@@ -6751,13 +6776,13 @@ function bc() {
6751
6776
  }
6752
6777
  return { set: e, clear: n };
6753
6778
  }
6754
- const _c = 1e3;
6755
- function gc(t, e, n) {
6779
+ const Tc = 1e3;
6780
+ function wc(t, e, n) {
6756
6781
  je(() => t.core._reactor.subscribeTopic(t.id, e, (i, s) => {
6757
6782
  n(i, s);
6758
6783
  }), [t.id, e]);
6759
6784
  }
6760
- function Tc(t, e) {
6785
+ function mc(t, e) {
6761
6786
  return je(() => t.core._reactor.joinRoom(t.id), [t.id]), ge((r) => {
6762
6787
  t.core._reactor.publishTopic({
6763
6788
  roomType: t.type,
@@ -6767,9 +6792,9 @@ function Tc(t, e) {
6767
6792
  });
6768
6793
  }, [t.id, e]);
6769
6794
  }
6770
- function wc(t, e = {}) {
6795
+ function vc(t, e = {}) {
6771
6796
  var n, r;
6772
- const [i, s] = ui(() => {
6797
+ const [i, s] = ci(() => {
6773
6798
  var u;
6774
6799
  return (u = t.core._reactor.getPresence(t.type, t.id, e)) !== null && u !== void 0 ? u : {
6775
6800
  peers: {},
@@ -6784,11 +6809,11 @@ function wc(t, e = {}) {
6784
6809
  }, [t.type, t.id]);
6785
6810
  return rn(() => Object.assign(Object.assign({}, i), { publishPresence: o }), [i, o]);
6786
6811
  }
6787
- function mc(t, e, n) {
6812
+ function Sc(t, e, n) {
6788
6813
  je(() => t.core._reactor.joinRoom(t.id, e), [t.id]), je(() => t.core._reactor.publishPresence(t.type, t.id, e), [t.type, t.id, n ?? JSON.stringify(e)]);
6789
6814
  }
6790
- function vc(t, e, n = {}) {
6791
- const r = bc(), i = Oe.usePresence(t, {
6815
+ function Oc(t, e, n = {}) {
6816
+ const r = gc(), i = Oe.usePresence(t, {
6792
6817
  keys: [e]
6793
6818
  }), s = rn(() => {
6794
6819
  var d;
@@ -6798,7 +6823,7 @@ function vc(t, e, n = {}) {
6798
6823
  var f;
6799
6824
  t.core._reactor.publishPresence(t.type, t.id, {
6800
6825
  [e]: d
6801
- }), d && ((n == null ? void 0 : n.timeout) === null || (n == null ? void 0 : n.timeout) === 0 || r.set((f = n == null ? void 0 : n.timeout) !== null && f !== void 0 ? f : _c, () => {
6826
+ }), d && ((n == null ? void 0 : n.timeout) === null || (n == null ? void 0 : n.timeout) === 0 || r.set((f = n == null ? void 0 : n.timeout) !== null && f !== void 0 ? f : Tc, () => {
6802
6827
  t.core._reactor.publishPresence(t.type, t.id, {
6803
6828
  [e]: null
6804
6829
  });
@@ -6816,20 +6841,20 @@ function vc(t, e, n = {}) {
6816
6841
  };
6817
6842
  }
6818
6843
  const Oe = {
6819
- useTopicEffect: gc,
6820
- usePublishTopic: Tc,
6821
- usePresence: wc,
6822
- useSyncPresence: mc,
6823
- useTypingIndicator: vc
6844
+ useTopicEffect: wc,
6845
+ usePublishTopic: mc,
6846
+ usePresence: vc,
6847
+ useSyncPresence: Sc,
6848
+ useTypingIndicator: Oc
6824
6849
  };
6825
- class Sc {
6850
+ class Ec {
6826
6851
  constructor(e, n, r) {
6827
6852
  this.useTopicEffect = (i, s) => {
6828
6853
  Oe.useTopicEffect(this, i, s);
6829
6854
  }, this.usePublishTopic = (i) => Oe.usePublishTopic(this, i), this.usePresence = (i = {}) => Oe.usePresence(this, i), this.useSyncPresence = (i, s) => Oe.useSyncPresence(this, i, s), this.useTypingIndicator = (i, s = {}) => Oe.useTypingIndicator(this, i, s), this.core = e, this._core = this.core, this.type = n, this.id = r;
6830
6855
  }
6831
6856
  }
6832
- var Oc = function(t, e, n, r) {
6857
+ var Ac = function(t, e, n, r) {
6833
6858
  function i(s) {
6834
6859
  return s instanceof n ? s : new n(function(o) {
6835
6860
  o(s);
@@ -6856,26 +6881,26 @@ var Oc = function(t, e, n, r) {
6856
6881
  c((r = r.apply(t, e || [])).next());
6857
6882
  });
6858
6883
  };
6859
- const Ec = {
6884
+ const kc = {
6860
6885
  isLoading: !0,
6861
6886
  user: void 0,
6862
6887
  error: void 0
6863
6888
  };
6864
- class Ac {
6889
+ class jc {
6865
6890
  constructor(e, n) {
6866
6891
  this.tx = Vn(), this.getLocalId = (r) => this.core.getLocalId(r), this.useLocalId = (r) => {
6867
- const [i, s] = ui(null);
6892
+ const [i, s] = ci(null);
6868
6893
  return je(() => {
6869
- Oc(this, void 0, void 0, function* () {
6894
+ Ac(this, void 0, void 0, function* () {
6870
6895
  const a = yield this.getLocalId(r);
6871
6896
  s(a);
6872
6897
  });
6873
6898
  }, [r]), i;
6874
- }, this.rooms = Oe, this.transact = (r) => this.core.transact(r), this.useQuery = (r, i) => yc(this.core, r, i).state, this.useAuth = () => {
6899
+ }, this.rooms = Oe, this.transact = (r) => this.core.transact(r), this.useQuery = (r, i) => _c(this.core, r, i).state, this.useAuth = () => {
6875
6900
  const r = At(this.core._reactor._currentUserCached), i = ge((o) => this.core.subscribeAuth((u) => {
6876
6901
  r.current = Object.assign({ isLoading: !1 }, u), o();
6877
6902
  }), []);
6878
- return nn(i, () => r.current, () => Ec);
6903
+ return nn(i, () => r.current, () => kc);
6879
6904
  }, this.useUser = () => {
6880
6905
  const { user: r } = this.useAuth();
6881
6906
  if (!r)
@@ -6897,7 +6922,7 @@ class Ac {
6897
6922
  }, this.SignedOut = ({ children: r }) => {
6898
6923
  const i = this.useAuth();
6899
6924
  return i.isLoading || i.error || i.user ? null : z.jsx(z.Fragment, { children: r });
6900
- }, this.core = cc(
6925
+ }, this.core = fc(
6901
6926
  e,
6902
6927
  // @ts-expect-error because TS can't resolve subclass statics
6903
6928
  this.constructor.Storage,
@@ -6921,7 +6946,7 @@ class Ac {
6921
6946
  * const { peers } = db.rooms.usePresence(room);
6922
6947
  */
6923
6948
  room(e = "_defaultRoomType", n = "_defaultRoomId") {
6924
- return new Sc(this.core, e, n);
6949
+ return new Ec(this.core, e, n);
6925
6950
  }
6926
6951
  /**
6927
6952
  * One time query for the logged in state. This is useful
@@ -6937,14 +6962,14 @@ class Ac {
6937
6962
  return this.core.getAuth();
6938
6963
  }
6939
6964
  }
6940
- class ni extends Error {
6965
+ class ri extends Error {
6941
6966
  constructor(e, n) {
6942
6967
  super(e), this.name = "ParseError", this.type = n.type, this.field = n.field, this.value = n.value, this.line = n.line;
6943
6968
  }
6944
6969
  }
6945
6970
  function tn(t) {
6946
6971
  }
6947
- function kc(t) {
6972
+ function Cc(t) {
6948
6973
  if (typeof t == "function")
6949
6974
  throw new TypeError(
6950
6975
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
@@ -6952,7 +6977,7 @@ function kc(t) {
6952
6977
  const { onEvent: e = tn, onError: n = tn, onRetry: r = tn, onComment: i } = t;
6953
6978
  let s = "", o = !0, a, u = "", c = "";
6954
6979
  function d(b) {
6955
- const g = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [w, T] = jc(`${s}${g}`);
6980
+ const g = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [w, T] = Pc(`${s}${g}`);
6956
6981
  for (const m of w)
6957
6982
  f(m);
6958
6983
  s = T, o = !1;
@@ -6988,7 +7013,7 @@ function kc(t) {
6988
7013
  break;
6989
7014
  case "retry":
6990
7015
  /^\d+$/.test(g) ? r(parseInt(g, 10)) : n(
6991
- new ni(`Invalid \`retry\` value: "${g}"`, {
7016
+ new ri(`Invalid \`retry\` value: "${g}"`, {
6992
7017
  type: "invalid-retry",
6993
7018
  value: g,
6994
7019
  line: w
@@ -6997,7 +7022,7 @@ function kc(t) {
6997
7022
  break;
6998
7023
  default:
6999
7024
  n(
7000
- new ni(
7025
+ new ri(
7001
7026
  `Unknown field "${b.length > 20 ? `${b.slice(0, 20)}…` : b}"`,
7002
7027
  { type: "unknown-field", field: b, value: g, line: w }
7003
7028
  )
@@ -7020,7 +7045,7 @@ function kc(t) {
7020
7045
  }
7021
7046
  return { feed: d, reset: y };
7022
7047
  }
7023
- function jc(t) {
7048
+ function Pc(t) {
7024
7049
  const e = [];
7025
7050
  let n = "", r = 0;
7026
7051
  for (; r < t.length; ) {
@@ -7038,7 +7063,7 @@ function jc(t) {
7038
7063
  }
7039
7064
  return [e, n];
7040
7065
  }
7041
- class ri extends Event {
7066
+ class ii extends Event {
7042
7067
  /**
7043
7068
  * Constructs a new `ErrorEvent` instance. This is typically not called directly,
7044
7069
  * but rather emitted by the `EventSource` object when an error occurs.
@@ -7063,7 +7088,7 @@ class ri extends Event {
7063
7088
  * @returns A string representation of the error
7064
7089
  */
7065
7090
  [Symbol.for("nodejs.util.inspect.custom")](e, n, r) {
7066
- return r(ii(this), n);
7091
+ return r(si(this), n);
7067
7092
  }
7068
7093
  /**
7069
7094
  * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
@@ -7077,17 +7102,17 @@ class ri extends Event {
7077
7102
  * @returns A string representation of the error
7078
7103
  */
7079
7104
  [Symbol.for("Deno.customInspect")](e, n) {
7080
- return e(ii(this), n);
7105
+ return e(si(this), n);
7081
7106
  }
7082
7107
  }
7083
- function Cc(t) {
7108
+ function Ic(t) {
7084
7109
  const e = globalThis.DOMException;
7085
7110
  return typeof e == "function" ? new e(t, "SyntaxError") : new SyntaxError(t);
7086
7111
  }
7087
7112
  function On(t) {
7088
7113
  return t instanceof Error ? "errors" in t && Array.isArray(t.errors) ? t.errors.map(On).join(", ") : "cause" in t && t.cause instanceof Error ? `${t}: ${On(t.cause)}` : t.message : `${t}`;
7089
7114
  }
7090
- function ii(t) {
7115
+ function si(t) {
7091
7116
  return {
7092
7117
  type: t.type,
7093
7118
  message: t.message,
@@ -7097,9 +7122,9 @@ function ii(t) {
7097
7122
  timeStamp: t.timeStamp
7098
7123
  };
7099
7124
  }
7100
- var Ji = (t) => {
7125
+ var Zi = (t) => {
7101
7126
  throw TypeError(t);
7102
- }, Qn = (t, e, n) => e.has(t) || Ji("Cannot " + n), A = (t, e, n) => (Qn(t, e, "read from private field"), n ? n.call(t) : e.get(t)), N = (t, e, n) => e.has(t) ? Ji("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), $ = (t, e, n, r) => (Qn(t, e, "write to private field"), e.set(t, n), n), he = (t, e, n) => (Qn(t, e, "access private method"), n), J, Ee, xe, Ot, Mt, it, Ue, st, _e, $e, Fe, De, et, se, En, An, kn, si, jn, Cn, tt, Pn, In;
7127
+ }, Qn = (t, e, n) => e.has(t) || Zi("Cannot " + n), A = (t, e, n) => (Qn(t, e, "read from private field"), n ? n.call(t) : e.get(t)), N = (t, e, n) => e.has(t) ? Zi("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), $ = (t, e, n, r) => (Qn(t, e, "write to private field"), e.set(t, n), n), he = (t, e, n) => (Qn(t, e, "access private method"), n), J, Ee, xe, Ot, Mt, it, Ue, st, _e, $e, Fe, De, et, se, En, An, kn, oi, jn, Cn, tt, Pn, In;
7103
7128
  class Et extends EventTarget {
7104
7129
  constructor(e, n) {
7105
7130
  var r, i;
@@ -7152,13 +7177,13 @@ class Et extends EventTarget {
7152
7177
  if (e instanceof URL)
7153
7178
  $(this, Ee, e);
7154
7179
  else if (typeof e == "string")
7155
- $(this, Ee, new URL(e, Pc()));
7180
+ $(this, Ee, new URL(e, Mc()));
7156
7181
  else
7157
7182
  throw new Error("Invalid URL");
7158
7183
  } catch {
7159
- throw Cc("An invalid or illegal string was specified");
7184
+ throw Ic("An invalid or illegal string was specified");
7160
7185
  }
7161
- $(this, $e, kc({
7186
+ $(this, $e, Cc({
7162
7187
  onEvent: A(this, jn),
7163
7188
  onRetry: A(this, Cn)
7164
7189
  })), $(this, J, this.CONNECTING), $(this, it, 3e3), $(this, Mt, (r = n == null ? void 0 : n.fetch) != null ? r : globalThis.fetch), $(this, Ot, (i = n == null ? void 0 : n.withCredentials) != null ? i : !1), he(this, se, En).call(this);
@@ -7240,14 +7265,14 @@ J = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), xe = /* @
7240
7265
  * @internal
7241
7266
  */
7242
7267
  En = function() {
7243
- $(this, J, this.CONNECTING), $(this, _e, new AbortController()), A(this, Mt)(A(this, Ee), he(this, se, si).call(this)).then(A(this, An)).catch(A(this, kn));
7268
+ $(this, J, this.CONNECTING), $(this, _e, new AbortController()), A(this, Mt)(A(this, Ee), he(this, se, oi).call(this)).then(A(this, An)).catch(A(this, kn));
7244
7269
  }, An = /* @__PURE__ */ new WeakMap(), kn = /* @__PURE__ */ new WeakMap(), /**
7245
7270
  * Get request options for the `fetch()` request
7246
7271
  *
7247
7272
  * @returns The request options
7248
7273
  * @internal
7249
7274
  */
7250
- si = function() {
7275
+ oi = function() {
7251
7276
  var t;
7252
7277
  const e = {
7253
7278
  // [spec] Let `corsAttributeState` be `Anonymous`…
@@ -7269,7 +7294,7 @@ si = function() {
7269
7294
  tt = function(t, e) {
7270
7295
  var n;
7271
7296
  A(this, J) !== this.CLOSED && $(this, J, this.CLOSED);
7272
- const r = new ri("error", { code: e, message: t });
7297
+ const r = new ii("error", { code: e, message: t });
7273
7298
  (n = A(this, Fe)) == null || n.call(this, r), this.dispatchEvent(r);
7274
7299
  }, /**
7275
7300
  * Schedules a reconnection attempt against the EventSource endpoint.
@@ -7283,7 +7308,7 @@ Pn = function(t, e) {
7283
7308
  if (A(this, J) === this.CLOSED)
7284
7309
  return;
7285
7310
  $(this, J, this.CONNECTING);
7286
- const r = new ri("error", { code: e, message: t });
7311
+ const r = new ii("error", { code: e, message: t });
7287
7312
  (n = A(this, Fe)) == null || n.call(this, r), this.dispatchEvent(r), $(this, Ue, setTimeout(A(this, In), A(this, it)));
7288
7313
  }, In = /* @__PURE__ */ new WeakMap(), /**
7289
7314
  * ReadyState representing an EventSource currently trying to connect
@@ -7301,15 +7326,15 @@ Et.OPEN = 1, /**
7301
7326
  * @public
7302
7327
  */
7303
7328
  Et.CLOSED = 2;
7304
- function Pc() {
7329
+ function Mc() {
7305
7330
  const t = "document" in globalThis ? globalThis.document : void 0;
7306
7331
  return t && typeof t == "object" && "baseURI" in t && typeof t.baseURI == "string" ? t.baseURI : void 0;
7307
7332
  }
7308
- const Hn = class Hn extends Ac {
7333
+ const Hn = class Hn extends jc {
7309
7334
  };
7310
7335
  Hn.EventSourceImpl = Et;
7311
7336
  let Mn = Hn;
7312
- function Ic(t) {
7337
+ function Rc(t) {
7313
7338
  return new Mn(
7314
7339
  t,
7315
7340
  {
@@ -7317,8 +7342,8 @@ function Ic(t) {
7317
7342
  }
7318
7343
  );
7319
7344
  }
7320
- const Fc = Ic;
7321
- function Nc({
7345
+ const Kc = Rc;
7346
+ function qc({
7322
7347
  as: t = "div",
7323
7348
  spaceId: e,
7324
7349
  room: n,
@@ -7370,7 +7395,7 @@ function Nc({
7370
7395
  [d]: void 0
7371
7396
  });
7372
7397
  }
7373
- return Es(
7398
+ return As(
7374
7399
  t,
7375
7400
  {
7376
7401
  onMouseMove: y,
@@ -7389,9 +7414,9 @@ function Nc({
7389
7414
  "div",
7390
7415
  {
7391
7416
  style: {
7392
- ...oi,
7393
- ...Rc,
7394
- zIndex: c !== void 0 ? c : xc
7417
+ ...ai,
7418
+ ...$c,
7419
+ zIndex: c !== void 0 ? c : Dc
7395
7420
  },
7396
7421
  children: Object.entries(f.peers).map(([T, m]) => {
7397
7422
  const E = m[d];
@@ -7399,7 +7424,7 @@ function Nc({
7399
7424
  "div",
7400
7425
  {
7401
7426
  style: {
7402
- ...oi,
7427
+ ...ai,
7403
7428
  transform: `translate(${E.xPercent}%, ${E.yPercent}%)`,
7404
7429
  transformOrigin: "0 0",
7405
7430
  transition: "transform 100ms"
@@ -7407,7 +7432,7 @@ function Nc({
7407
7432
  children: a ? a({
7408
7433
  color: E.color,
7409
7434
  presence: l.peers[T]
7410
- }) : /* @__PURE__ */ z.jsx(Mc, { ...E })
7435
+ }) : /* @__PURE__ */ z.jsx(xc, { ...E })
7411
7436
  },
7412
7437
  T
7413
7438
  ) : null;
@@ -7418,7 +7443,7 @@ function Nc({
7418
7443
  ]
7419
7444
  );
7420
7445
  }
7421
- function Mc({ color: t }) {
7446
+ function xc({ color: t }) {
7422
7447
  const n = t || "black";
7423
7448
  return /* @__PURE__ */ z.jsxs(
7424
7449
  "svg",
@@ -7465,27 +7490,27 @@ function Mc({ color: t }) {
7465
7490
  }
7466
7491
  );
7467
7492
  }
7468
- const oi = {
7493
+ const ai = {
7469
7494
  position: "absolute",
7470
7495
  top: 0,
7471
7496
  left: 0,
7472
7497
  bottom: 0,
7473
7498
  right: 0
7474
- }, Rc = {
7499
+ }, $c = {
7475
7500
  overflow: "hidden",
7476
7501
  pointerEvents: "none",
7477
7502
  userSelect: "none"
7478
- }, xc = 99999;
7503
+ }, Dc = 99999;
7479
7504
  export {
7480
- Nc as Cursors,
7505
+ qc as Cursors,
7481
7506
  $t as InstantAPIError,
7482
- Ac as InstantReactAbstractDatabase,
7507
+ jc as InstantReactAbstractDatabase,
7483
7508
  Mn as InstantReactWebDatabase,
7484
7509
  Se as SyncTableCallbackEventType,
7485
- Lc as i,
7510
+ Nc as i,
7486
7511
  K as id,
7487
- Ic as init,
7488
- Fc as init_experimental,
7489
- Dc as lookup,
7490
- Uc as tx
7512
+ Rc as init,
7513
+ Kc as init_experimental,
7514
+ Lc as lookup,
7515
+ Fc as tx
7491
7516
  };