@instantdb/react 0.22.56-experimental.persisted-object-2.19485585806.1 → 0.22.56-experimental.persisted-object-2.19512376560.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.
@@ -37,7 +37,7 @@ function V(t) {
37
37
  }
38
38
  return V(String(t));
39
39
  }
40
- const D = {
40
+ const U = {
41
41
  Remove: "remove",
42
42
  Replace: "replace",
43
43
  Add: "add"
@@ -228,9 +228,9 @@ function Je(t) {
228
228
  function mt(t) {
229
229
  return Ce(t) ? Je(t) : t;
230
230
  }
231
- function de(t) {
231
+ function fe(t) {
232
232
  var e;
233
- t.assignedMap = (e = t.assignedMap) !== null && e !== void 0 ? e : /* @__PURE__ */ new Map(), t.operated || (t.operated = !0, t.parent && de(t.parent));
233
+ t.assignedMap = (e = t.assignedMap) !== null && e !== void 0 ? e : /* @__PURE__ */ new Map(), t.operated || (t.operated = !0, t.parent && fe(t.parent));
234
234
  }
235
235
  function wr() {
236
236
  throw new Error("Cannot modify frozen object");
@@ -353,12 +353,12 @@ function Is(t, e, n, r, i) {
353
353
  if (o.get(c.toString()) && u[c] !== s[c]) {
354
354
  const d = e.concat([c]), f = Ae(d, i);
355
355
  n.push({
356
- op: D.Replace,
356
+ op: U.Replace,
357
357
  path: f,
358
358
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
359
359
  value: mt(u[c])
360
360
  }), r.push({
361
- op: D.Replace,
361
+ op: U.Replace,
362
362
  path: f,
363
363
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
364
364
  value: mt(s[c])
@@ -367,7 +367,7 @@ function Is(t, e, n, r, i) {
367
367
  for (let c = s.length; c < u.length; c += 1) {
368
368
  const d = e.concat([c]), f = Ae(d, i);
369
369
  n.push({
370
- op: D.Add,
370
+ op: U.Add,
371
371
  path: f,
372
372
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
373
373
  value: mt(u[c])
@@ -378,7 +378,7 @@ function Is(t, e, n, r, i) {
378
378
  if (c) {
379
379
  const d = e.concat(["length"]), f = Ae(d, i);
380
380
  r.push({
381
- op: D.Replace,
381
+ op: U.Replace,
382
382
  path: f,
383
383
  value: s.length
384
384
  });
@@ -386,7 +386,7 @@ function Is(t, e, n, r, i) {
386
386
  for (let d = u.length; s.length < d; d -= 1) {
387
387
  const f = e.concat([d - 1]), l = Ae(f, i);
388
388
  r.push({
389
- op: D.Remove,
389
+ op: U.Remove,
390
390
  path: l
391
391
  });
392
392
  }
@@ -394,11 +394,11 @@ function Is(t, e, n, r, i) {
394
394
  }
395
395
  function Ms({ original: t, copy: e, assignedMap: n }, r, i, s, o) {
396
396
  n.forEach((a, u) => {
397
- const c = be(t, u), d = mt(be(e, u)), f = a ? nt(t, u) ? D.Replace : D.Add : D.Remove;
398
- if (ye(c, d) && f === D.Replace)
397
+ const c = be(t, u), d = mt(be(e, u)), f = a ? nt(t, u) ? U.Replace : U.Add : U.Remove;
398
+ if (ye(c, d) && f === U.Replace)
399
399
  return;
400
400
  const l = r.concat(u), p = Ae(l, o);
401
- i.push(f === D.Remove ? { op: f, path: p } : { op: f, path: p, value: d }), s.push(f === D.Add ? { op: D.Remove, path: p } : f === D.Remove ? { op: D.Add, path: p, value: c } : { op: D.Replace, path: p, value: c });
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
404
  function Rs({ original: t, copy: e }, n, r, i, s) {
@@ -407,11 +407,11 @@ function Rs({ original: t, copy: e }, n, r, i, s) {
407
407
  if (!e.has(a)) {
408
408
  const u = n.concat([o]), c = Ae(u, s);
409
409
  r.push({
410
- op: D.Remove,
410
+ op: U.Remove,
411
411
  path: c,
412
412
  value: a
413
413
  }), i.unshift({
414
- op: D.Add,
414
+ op: U.Add,
415
415
  path: c,
416
416
  value: a
417
417
  });
@@ -421,11 +421,11 @@ function Rs({ original: t, copy: e }, n, r, i, s) {
421
421
  if (!t.has(a)) {
422
422
  const u = n.concat([o]), c = Ae(u, s);
423
423
  r.push({
424
- op: D.Add,
424
+ op: U.Add,
425
425
  path: c,
426
426
  value: a
427
427
  }), i.unshift({
428
- op: D.Remove,
428
+ op: U.Remove,
429
429
  path: c,
430
430
  value: a
431
431
  });
@@ -457,18 +457,18 @@ const kt = (t, e, n = !1) => {
457
457
  },
458
458
  set(t, e) {
459
459
  const n = j(this), r = te(n);
460
- return (!r.has(t) || !ye(r.get(t), e)) && (Q(n), de(n), n.assignedMap.set(t, !0), n.copy.set(t, e), Ln(n, t, e, ot)), this;
460
+ return (!r.has(t) || !ye(r.get(t), e)) && (Q(n), fe(n), n.assignedMap.set(t, !0), n.copy.set(t, e), Ln(n, t, e, ot)), this;
461
461
  },
462
462
  delete(t) {
463
463
  if (!this.has(t))
464
464
  return !1;
465
465
  const e = j(this);
466
- return Q(e), de(e), e.original.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.copy.delete(t), !0;
466
+ return Q(e), fe(e), e.original.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.copy.delete(t), !0;
467
467
  },
468
468
  clear() {
469
469
  const t = j(this);
470
470
  if (this.size) {
471
- Q(t), de(t), t.assignedMap = /* @__PURE__ */ new Map();
471
+ Q(t), fe(t), t.assignedMap = /* @__PURE__ */ new Map();
472
472
  for (const [e] of t.original)
473
473
  t.assignedMap.set(e, !1);
474
474
  t.copy.clear();
@@ -565,13 +565,13 @@ const kt = (t, e, n = !1) => {
565
565
  },
566
566
  add(t) {
567
567
  const e = j(this);
568
- return this.has(t) || (Q(e), de(e), e.assignedMap.set(t, !0), e.setMap.set(t, t), Ln(e, t, t, ot)), this;
568
+ return this.has(t) || (Q(e), fe(e), e.assignedMap.set(t, !0), e.setMap.set(t, t), Ln(e, t, t, ot)), this;
569
569
  },
570
570
  delete(t) {
571
571
  if (!this.has(t))
572
572
  return !1;
573
573
  const e = j(this);
574
- Q(e), de(e);
574
+ Q(e), fe(e);
575
575
  const n = j(t);
576
576
  return n && e.setMap.has(n.original) ? (e.assignedMap.set(n.original, !1), e.setMap.delete(n.original)) : (!n && e.setMap.has(t) ? e.assignedMap.set(t, !1) : e.assignedMap.delete(t), e.setMap.delete(t));
577
577
  },
@@ -579,7 +579,7 @@ const kt = (t, e, n = !1) => {
579
579
  if (!this.size)
580
580
  return;
581
581
  const t = j(this);
582
- Q(t), de(t);
582
+ Q(t), fe(t);
583
583
  for (const e of t.original)
584
584
  t.assignedMap.set(e, !1);
585
585
  t.setMap.clear();
@@ -688,7 +688,7 @@ const $s = Reflect.ownKeys(jt), hi = /* @__PURE__ */ new WeakSet(), pi = {
688
688
  options: t.options
689
689
  }), typeof o == "function") {
690
690
  const c = j(t.copy[e]);
691
- return Q(c), de(c), c.copy;
691
+ return Q(c), fe(c), c.copy;
692
692
  }
693
693
  return t.copy[e];
694
694
  }
@@ -705,7 +705,7 @@ const $s = Reflect.ownKeys(jt), hi = /* @__PURE__ */ new WeakSet(), pi = {
705
705
  if (s != null && s.set)
706
706
  return s.set.call(t.proxy, n), !0;
707
707
  const o = Qt(te(t), e), a = j(o);
708
- return a && ye(a.original, n) ? (t.copy[e] = n, t.assignedMap = (r = t.assignedMap) !== null && r !== void 0 ? r : /* @__PURE__ */ new Map(), t.assignedMap.set(e, !1), !0) : (ye(n, o) && (n !== void 0 || nt(t.original, e)) || (Q(t), de(t), nt(t.original, e) && ye(n, t.original[e]) ? t.assignedMap.delete(e) : t.assignedMap.set(e, !0), t.copy[e] = n, Ln(t, e, n, ot)), !0);
708
+ return a && ye(a.original, n) ? (t.copy[e] = n, t.assignedMap = (r = t.assignedMap) !== null && r !== void 0 ? r : /* @__PURE__ */ new Map(), t.assignedMap.set(e, !1), !0) : (ye(n, o) && (n !== void 0 || nt(t.original, e)) || (Q(t), fe(t), nt(t.original, e) && ye(n, t.original[e]) ? t.assignedMap.delete(e) : t.assignedMap.set(e, !0), t.copy[e] = n, Ln(t, e, n, ot)), !0);
709
709
  },
710
710
  has(t, e) {
711
711
  return e in te(t);
@@ -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), de(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 ? 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);
737
737
  }
738
738
  };
739
739
  function Fn(t) {
@@ -784,8 +784,8 @@ function Ds(t, e, n, r, i) {
784
784
  const c = u ? e[0] : o ? o.operated ? o.copy : o.original : t;
785
785
  return o && sn(o), i && Re(c, c, o == null ? void 0 : o.options.updatedValues), [
786
786
  c,
787
- n && u ? [{ op: D.Replace, path: [], value: e[0] }] : n,
788
- r && u ? [{ op: D.Replace, path: [], value: a }] : r
787
+ n && u ? [{ op: U.Replace, path: [], value: e[0] }] : n,
788
+ r && u ? [{ op: U.Replace, path: [], value: a }] : r
789
789
  ];
790
790
  }
791
791
  function Us(t, e) {
@@ -867,7 +867,7 @@ const Ls = (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) {
870
- return e(S, (U) => n.call(this, U, ...I), r);
870
+ return e(S, (x) => n.call(this, x, ...I), r);
871
871
  };
872
872
  const u = n, c = r;
873
873
  let d = i;
@@ -875,12 +875,12 @@ const Ls = (t) => function e(n, r, i) {
875
875
  throw new Error(`Invalid options: ${d}, 'options' should be an object.`);
876
876
  d = Object.assign(Object.assign({}, t), d);
877
877
  const f = Ce(u) ? vr(u) : u, l = Array.isArray(d.mark) ? (S, I) => {
878
- for (const U of d.mark) {
879
- if (typeof U != "function")
880
- throw new Error(`Invalid mark: ${U}, 'mark' should be a function.`);
881
- const W = U(S, I);
882
- if (W)
883
- return W;
878
+ for (const x of d.mark) {
879
+ if (typeof x != "function")
880
+ throw new Error(`Invalid mark: ${x}, 'mark' should be a function.`);
881
+ const q = x(S, I);
882
+ if (q)
883
+ return q;
884
884
  }
885
885
  } : d.mark, p = (s = d.enablePatches) !== null && s !== void 0 ? s : !1, y = (o = d.strict) !== null && o !== void 0 ? o : !1, g = {
886
886
  enableAutoFreeze: (a = d.enableAutoFreeze) !== null && a !== void 0 ? a : !1,
@@ -907,9 +907,9 @@ 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 W = S == null ? void 0 : S[As];
911
- if (W) {
912
- const we = W[0];
910
+ const q = S == null ? void 0 : S[As];
911
+ if (q) {
912
+ const we = q[0];
913
913
  return g.strict && typeof S == "object" && S !== null && cn({
914
914
  rootDraft: I,
915
915
  value: S,
@@ -921,9 +921,9 @@ const Ls = (t) => function e(n, r, i) {
921
921
  }
922
922
  if (S === w || S === void 0)
923
923
  return T([]);
924
- const U = j(S);
925
- if (g === U.options) {
926
- if (U.operated)
924
+ const x = j(S);
925
+ if (g === x.options) {
926
+ if (x.operated)
927
927
  throw new Error("Cannot return a modified child draft.");
928
928
  return T([vr(S)]);
929
929
  }
@@ -1203,10 +1203,10 @@ 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 Ws(t) {
1206
+ function qs(t) {
1207
1207
  return new Date(t);
1208
1208
  }
1209
- function qs(t) {
1209
+ function Ws(t) {
1210
1210
  return /* @__PURE__ */ new Date(t + "Z");
1211
1211
  }
1212
1212
  const zs = /^(\d+)[\./-](\d+)[\./-](\d+)$/;
@@ -1275,10 +1275,10 @@ const eo = [
1275
1275
  Hs,
1276
1276
  Js,
1277
1277
  Qs,
1278
- qs,
1278
+ Ws,
1279
1279
  Ys,
1280
1280
  Gs,
1281
- Ws,
1281
+ qs,
1282
1282
  Zs,
1283
1283
  Xs
1284
1284
  ];
@@ -1328,10 +1328,10 @@ function ro(t) {
1328
1328
  function Kn(t) {
1329
1329
  return t["value-type"] === "ref";
1330
1330
  }
1331
- function Wn(t) {
1331
+ function qn(t) {
1332
1332
  return t["value-type"] === "blob";
1333
1333
  }
1334
- function qe(t, e) {
1334
+ function We(t, e) {
1335
1335
  return t[e];
1336
1336
  }
1337
1337
  function ze(t, e) {
@@ -1362,7 +1362,7 @@ function Ti(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;
1365
- const f = qe(t, u);
1365
+ const f = We(t, u);
1366
1366
  if (!f) {
1367
1367
  console.warn("no such attr", a, t);
1368
1368
  continue;
@@ -1375,7 +1375,7 @@ function wi(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"];
1378
- if (Z(r, [u, c], s), Wn(s) && Z(e, [u, c], s), s["primary?"] && Z(n, [u], s), d) {
1378
+ if (Z(r, [u, c], s), qn(s) && Z(e, [u, c], s), s["primary?"] && Z(n, [u], s), d) {
1379
1379
  const [f, l, p] = d;
1380
1380
  Z(i, [l, p], s);
1381
1381
  }
@@ -1398,7 +1398,7 @@ function vi(t) {
1398
1398
  function io(t, e) {
1399
1399
  return ze(t.eav, [e]) !== void 0;
1400
1400
  }
1401
- function qn(t) {
1401
+ function Wn(t) {
1402
1402
  t.attrIndexes = wi(t.attrs);
1403
1403
  }
1404
1404
  function St(t, e, n, r, i) {
@@ -1436,7 +1436,7 @@ function Si(t, e) {
1436
1436
  const n = ut(t, e);
1437
1437
  if (!n)
1438
1438
  return;
1439
- const [r, i, s] = n, o = qe(t.attrs, i);
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
1442
  let so = 0;
@@ -1452,7 +1452,7 @@ function Ei(t, e) {
1452
1452
  if (!r)
1453
1453
  return;
1454
1454
  let [i, s, o] = r;
1455
- const a = qe(t.attrs, s);
1455
+ const a = We(t.attrs, s);
1456
1456
  if (!a)
1457
1457
  return;
1458
1458
  a["checked-data-type"] === "date" && t.useDateObjects && (o = Rt(o));
@@ -1464,10 +1464,10 @@ function oo(t, e) {
1464
1464
  const r = ut(t, e);
1465
1465
  if (!r)
1466
1466
  return;
1467
- const [i, s, o] = r, a = qe(t.attrs, s);
1467
+ const [i, s, o] = r, a = We(t.attrs, s);
1468
1468
  if (!a)
1469
1469
  return;
1470
- if (!Wn(a))
1470
+ if (!qn(a))
1471
1471
  throw new Error("merge operation is not supported for links");
1472
1472
  const u = ze(t.eav, [i, s]);
1473
1473
  if (!u)
@@ -1517,7 +1517,7 @@ function Ai(t, e) {
1517
1517
  });
1518
1518
  }
1519
1519
  function ao(t, [e]) {
1520
- t.attrs[e.id] = e, qn(t);
1520
+ t.attrs[e.id] = e, Wn(t);
1521
1521
  }
1522
1522
  function ki(t) {
1523
1523
  return X(t.eav, 3);
@@ -1526,11 +1526,11 @@ function uo(t, [e]) {
1526
1526
  if (!t.attrs[e])
1527
1527
  return;
1528
1528
  const n = ki(t).filter(([r, i]) => i !== e);
1529
- delete t.attrs[e], qn(t), Ai(t, n);
1529
+ delete t.attrs[e], Wn(t), Ai(t, n);
1530
1530
  }
1531
1531
  function co(t, [e]) {
1532
1532
  const n = t.attrs[e.id];
1533
- n && (t.attrs[e.id] = Object.assign(Object.assign({}, n), e), qn(t), Ai(t, ki(t)));
1533
+ n && (t.attrs[e.id] = Object.assign(Object.assign({}, n), e), Wn(t), Ai(t, ki(t)));
1534
1534
  }
1535
1535
  function fo(t, e) {
1536
1536
  const [n, ...r] = e;
@@ -1692,7 +1692,7 @@ function bo(t, e) {
1692
1692
  if (!n)
1693
1693
  return;
1694
1694
  const [r, i, s] = n;
1695
- if (qe(t.attrs, i))
1695
+ if (We(t.attrs, i))
1696
1696
  return ze(t.eav, [r, i]);
1697
1697
  }
1698
1698
  function _o(t, e) {
@@ -1703,7 +1703,7 @@ function _o(t, e) {
1703
1703
  if (u !== "create" && u !== "update")
1704
1704
  return !0;
1705
1705
  let c = !1;
1706
- const d = qe(t.attrs, s);
1706
+ const d = We(t.attrs, s);
1707
1707
  if (d) {
1708
1708
  const f = Ci(t, d["forward-identity"][1]);
1709
1709
  c = !!bo(t, [i, f.id, i]);
@@ -1782,11 +1782,11 @@ const jo = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a
1782
1782
  function Ne(t) {
1783
1783
  return typeof t == "string" && jo.test(t);
1784
1784
  }
1785
- const q = [];
1785
+ const W = [];
1786
1786
  for (let t = 0; t < 256; ++t)
1787
- q.push((t + 256).toString(16).slice(1));
1787
+ W.push((t + 256).toString(16).slice(1));
1788
1788
  function Co(t, e = 0) {
1789
- return (q[t[e + 0]] + q[t[e + 1]] + q[t[e + 2]] + q[t[e + 3]] + "-" + q[t[e + 4]] + q[t[e + 5]] + "-" + q[t[e + 6]] + q[t[e + 7]] + "-" + q[t[e + 8]] + q[t[e + 9]] + "-" + q[t[e + 10]] + q[t[e + 11]] + q[t[e + 12]] + q[t[e + 13]] + q[t[e + 14]] + q[t[e + 15]]).toLowerCase();
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
1792
  const Po = new Uint8Array(16);
@@ -1872,7 +1872,7 @@ function Ko(t, e, n, r) {
1872
1872
  t("time", r)
1873
1873
  ];
1874
1874
  }
1875
- function Wo(t, e, n) {
1875
+ function qo(t, e, n) {
1876
1876
  return t.map((r) => r === e ? n : r);
1877
1877
  }
1878
1878
  function Ii(t, e, n, r, i) {
@@ -1904,7 +1904,7 @@ function Pr(t, e) {
1904
1904
  return typeof o != "string" ? !1 : i.test(o);
1905
1905
  };
1906
1906
  }
1907
- function qo(t, e) {
1907
+ function Wo(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";
@@ -1982,7 +1982,7 @@ function zo(t, e, n, r, i, s) {
1982
1982
  return o ? [
1983
1983
  t(n, r),
1984
1984
  u.id,
1985
- qo(u, s),
1985
+ Wo(u, s),
1986
1986
  rt("time")
1987
1987
  ] : [s, u.id, t(n, r), rt("time")];
1988
1988
  }
@@ -2066,7 +2066,7 @@ function Zo(t, e, n) {
2066
2066
  return [t(e, n), t("time", n)];
2067
2067
  }
2068
2068
  function Xo(t, e, n, r, i, s) {
2069
- const [o, a, u, c, d] = Ii(t, e, n, r, i), f = Wo(u, t(n, r), s);
2069
+ const [o, a, u, c, d] = Ii(t, e, n, r, i), f = qo(u, t(n, r), s);
2070
2070
  return [o, a, f, c, d];
2071
2071
  }
2072
2072
  function ea(t, e, { etype: n, level: r, form: i }, s) {
@@ -2134,7 +2134,7 @@ function oa(t, e, n) {
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];
2137
- u && Wn(a) && s.set(u, a);
2137
+ u && qn(a) && s.set(u, a);
2138
2138
  }
2139
2139
  if (!s.has("id")) {
2140
2140
  const o = Te(t, e, "id"), a = (i = o == null ? void 0 : o["forward-identity"]) === null || i === void 0 ? void 0 : i[2];
@@ -2151,8 +2151,8 @@ function aa(t, { etype: e, pageInfo: n, dq: r, form: i }) {
2151
2151
  const b = l["checked-data-type"] === "date", g = l.id;
2152
2152
  d = d.map(([w]) => {
2153
2153
  var T, m, E, S, I;
2154
- let U = (I = (S = (E = (m = (T = t.eav.get(w)) === null || T === void 0 ? void 0 : T.get(g)) === null || m === void 0 ? void 0 : m.values()) === null || E === void 0 ? void 0 : E.next()) === null || S === void 0 ? void 0 : S.value) === null || I === void 0 ? void 0 : I[2];
2155
- return b && (U = pn(U)), [w, U];
2154
+ let x = (I = (S = (E = (m = (T = t.eav.get(w)) === null || T === void 0 ? void 0 : T.get(g)) === null || m === void 0 ? void 0 : m.values()) === null || E === void 0 ? void 0 : E.next()) === null || S === void 0 ? void 0 : S.value) === null || I === void 0 ? void 0 : I[2];
2155
+ return b && (x = pn(x)), [w, x];
2156
2156
  });
2157
2157
  }
2158
2158
  d.sort(c === "asc" ? function(g, w) {
@@ -2267,7 +2267,7 @@ function yn(t, e, n) {
2267
2267
  }
2268
2268
  });
2269
2269
  }
2270
- function xc(t, e) {
2270
+ function Dc(t, e) {
2271
2271
  return `lookup__${t}__${JSON.stringify(e)}`;
2272
2272
  }
2273
2273
  function It(t) {
@@ -2296,7 +2296,7 @@ function Vn() {
2296
2296
  }
2297
2297
  });
2298
2298
  }
2299
- const $c = Vn();
2299
+ const Uc = Vn();
2300
2300
  function ya(t) {
2301
2301
  return t.__ops;
2302
2302
  }
@@ -2673,8 +2673,13 @@ var pe = function(t, e, n, r) {
2673
2673
  c((r = r.apply(t, e || [])).next());
2674
2674
  });
2675
2675
  };
2676
- const Ka = 6, Wa = ["kv", "querySubs", "syncSubs"];
2677
- function qa(t) {
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
+ };
2681
+ }
2682
+ function za(t) {
2678
2683
  return pe(this, void 0, void 0, function* () {
2679
2684
  return new Promise((e) => {
2680
2685
  const n = indexedDB.open(t);
@@ -2689,7 +2694,7 @@ function qa(t) {
2689
2694
  });
2690
2695
  });
2691
2696
  }
2692
- function za(t, e, n) {
2697
+ function Va(t, e, n) {
2693
2698
  return pe(this, void 0, void 0, function* () {
2694
2699
  const r = (
2695
2700
  // Backwards compatibility for older versions where we JSON.stringified before storing
@@ -2712,7 +2717,7 @@ function za(t, e, n) {
2712
2717
  });
2713
2718
  });
2714
2719
  }
2715
- function Va(t, e, n) {
2720
+ function Ga(t, e, n) {
2716
2721
  return pe(this, void 0, void 0, function* () {
2717
2722
  const r = n.put(e, t);
2718
2723
  return new Promise((i, s) => {
@@ -2720,9 +2725,9 @@ function Va(t, e, n) {
2720
2725
  });
2721
2726
  });
2722
2727
  }
2723
- function Ga(t, e) {
2728
+ function Ba(t, e) {
2724
2729
  return pe(this, void 0, void 0, function* () {
2725
- const n = yield qa(`instant_${t}_4`);
2730
+ const n = yield za(`instant_${t}_5`);
2726
2731
  if (!n)
2727
2732
  return;
2728
2733
  const r = e.objectStore("kv"), i = e.objectStore("querySubs");
@@ -2738,12 +2743,12 @@ function Ga(t, e) {
2738
2743
  const l = f.key, p = f.value;
2739
2744
  switch (l) {
2740
2745
  case "querySubs": {
2741
- const y = za(l, p, i);
2746
+ const y = Va(l, p, i);
2742
2747
  d.push(y);
2743
2748
  break;
2744
2749
  }
2745
2750
  default: {
2746
- const y = Va(l, p, r);
2751
+ const y = Ga(l, p, r);
2747
2752
  d.push(y);
2748
2753
  break;
2749
2754
  }
@@ -2771,10 +2776,10 @@ class Fi {
2771
2776
  }
2772
2777
  _upgradeStore(e) {
2773
2778
  const n = e.target, r = n.result;
2774
- for (const s of Wa)
2779
+ for (const s of qa)
2775
2780
  r.objectStoreNames.contains(s) || r.createObjectStore(s);
2776
2781
  const i = n.transaction;
2777
- Ga(this._appId, i);
2782
+ Ba(this._appId, i).catch(Wa("Error upgrading store from version 5 to 6."));
2778
2783
  }
2779
2784
  getItem(e) {
2780
2785
  return pe(this, void 0, void 0, function* () {
@@ -2848,7 +2853,7 @@ class Fi {
2848
2853
  });
2849
2854
  }
2850
2855
  }
2851
- var Ba = function(t, e, n, r) {
2856
+ var Qa = function(t, e, n, r) {
2852
2857
  function i(s) {
2853
2858
  return s instanceof n ? s : new n(function(o) {
2854
2859
  o(s);
@@ -2877,7 +2882,7 @@ var Ba = function(t, e, n, r) {
2877
2882
  };
2878
2883
  class Ni {
2879
2884
  static getIsOnline() {
2880
- return Ba(this, void 0, void 0, function* () {
2885
+ return Qa(this, void 0, void 0, function* () {
2881
2886
  return navigator.onLine;
2882
2887
  });
2883
2888
  }
@@ -2892,17 +2897,17 @@ class Ni {
2892
2897
  };
2893
2898
  }
2894
2899
  }
2895
- class We extends Error {
2900
+ class qe extends Error {
2896
2901
  constructor(e, n) {
2897
2902
  super(e), this.hint = n;
2898
2903
  const r = new.target.prototype;
2899
- Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, We), this.name = "InstantError";
2904
+ Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, qe), this.name = "InstantError";
2900
2905
  }
2901
2906
  get [Symbol.toStringTag]() {
2902
2907
  return "InstantError";
2903
2908
  }
2904
2909
  }
2905
- var Qa = function(t, e, n, r) {
2910
+ var Ha = function(t, e, n, r) {
2906
2911
  function i(s) {
2907
2912
  return s instanceof n ? s : new n(function(o) {
2908
2913
  o(s);
@@ -2929,7 +2934,7 @@ var Qa = function(t, e, n, r) {
2929
2934
  c((r = r.apply(t, e || [])).next());
2930
2935
  });
2931
2936
  };
2932
- class $t extends We {
2937
+ class $t extends qe {
2933
2938
  constructor(e) {
2934
2939
  var n;
2935
2940
  const r = ((n = e.body) === null || n === void 0 ? void 0 : n.message) || `API Error (${e.status})`;
@@ -2942,7 +2947,7 @@ class $t extends We {
2942
2947
  }
2943
2948
  }
2944
2949
  function ue(t, e) {
2945
- return Qa(this, void 0, void 0, function* () {
2950
+ return Ha(this, void 0, void 0, function* () {
2946
2951
  const n = yield fetch(t, e), r = yield n.json();
2947
2952
  return n.status === 200 ? Promise.resolve(r) : Promise.reject(new $t({ status: n.status, body: r }));
2948
2953
  });
@@ -2974,14 +2979,14 @@ var Ve = function(t, e, n, r) {
2974
2979
  c((r = r.apply(t, e || [])).next());
2975
2980
  });
2976
2981
  };
2977
- function Ha({ apiURI: t, appId: e, email: n }) {
2982
+ function Ya({ apiURI: t, appId: e, email: n }) {
2978
2983
  return ue(`${t}/runtime/auth/send_magic_code`, {
2979
2984
  method: "POST",
2980
2985
  headers: { "content-type": "application/json" },
2981
2986
  body: JSON.stringify({ "app-id": e, email: n })
2982
2987
  });
2983
2988
  }
2984
- function Ya(t) {
2989
+ function Ja(t) {
2985
2990
  return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, email: r, code: i, refreshToken: s }) {
2986
2991
  return yield ue(`${e}/runtime/auth/verify_magic_code`, {
2987
2992
  method: "POST",
@@ -2994,7 +2999,7 @@ function Ya(t) {
2994
2999
  });
2995
3000
  });
2996
3001
  }
2997
- function Ja(t) {
3002
+ function Za(t) {
2998
3003
  return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
2999
3004
  return yield ue(`${e}/runtime/auth/verify_refresh_token`, {
3000
3005
  method: "POST",
@@ -3006,7 +3011,7 @@ function Ja(t) {
3006
3011
  });
3007
3012
  });
3008
3013
  }
3009
- function Za(t) {
3014
+ function Xa(t) {
3010
3015
  return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n }) {
3011
3016
  return yield ue(`${e}/runtime/auth/sign_in_guest`, {
3012
3017
  method: "POST",
@@ -3031,7 +3036,7 @@ function xr(t) {
3031
3036
  });
3032
3037
  });
3033
3038
  }
3034
- function Xa(t) {
3039
+ function eu(t) {
3035
3040
  return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, nonce: r, idToken: i, clientName: s, refreshToken: o }) {
3036
3041
  return yield ue(`${e}/runtime/oauth/id_token`, {
3037
3042
  method: "POST",
@@ -3046,7 +3051,7 @@ function Xa(t) {
3046
3051
  });
3047
3052
  });
3048
3053
  }
3049
- function eu(t) {
3054
+ function tu(t) {
3050
3055
  return Ve(this, arguments, void 0, function* ({ apiURI: e, appId: n, refreshToken: r }) {
3051
3056
  return yield ue(`${e}/runtime/signout`, {
3052
3057
  method: "POST",
@@ -3087,7 +3092,7 @@ var ct = function(t, e, n, r) {
3087
3092
  c((r = r.apply(t, e || [])).next());
3088
3093
  });
3089
3094
  };
3090
- function tu(t) {
3095
+ function nu(t) {
3091
3096
  return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, file: i, refreshToken: s, contentType: o, contentDisposition: a }) {
3092
3097
  const u = {
3093
3098
  app_id: n,
@@ -3102,7 +3107,7 @@ function tu(t) {
3102
3107
  });
3103
3108
  });
3104
3109
  }
3105
- function nu(t) {
3110
+ function ru(t) {
3106
3111
  return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3107
3112
  const { data: s } = yield ue(`${e}/storage/files?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3108
3113
  method: "DELETE",
@@ -3114,7 +3119,7 @@ function nu(t) {
3114
3119
  return s;
3115
3120
  });
3116
3121
  }
3117
- function ru(t) {
3122
+ function iu(t) {
3118
3123
  return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, fileName: r, refreshToken: i, metadata: s = {} }) {
3119
3124
  const { data: o } = yield ue(`${e}/storage/signed-upload-url`, {
3120
3125
  method: "POST",
@@ -3130,7 +3135,7 @@ function ru(t) {
3130
3135
  return o;
3131
3136
  });
3132
3137
  }
3133
- function iu(t, e) {
3138
+ function su(t, e) {
3134
3139
  return ct(this, void 0, void 0, function* () {
3135
3140
  return (yield fetch(t, {
3136
3141
  method: "PUT",
@@ -3141,7 +3146,7 @@ function iu(t, e) {
3141
3146
  })).ok;
3142
3147
  });
3143
3148
  }
3144
- function su(t) {
3149
+ function ou(t) {
3145
3150
  return ct(this, arguments, void 0, function* ({ apiURI: e, appId: n, path: r, refreshToken: i }) {
3146
3151
  const { data: s } = yield ue(`${e}/storage/signed-download-url?app_id=${n}&filename=${encodeURIComponent(r)}`, {
3147
3152
  method: "GET",
@@ -3153,8 +3158,8 @@ function su(t) {
3153
3158
  return s;
3154
3159
  });
3155
3160
  }
3156
- let Gn = !1, Ki = !1, Wi = !1;
3157
- typeof window < "u" && typeof window.localStorage < "u" && (Gn = !!window.localStorage.getItem("devBackend"), Ki = !!window.localStorage.getItem("__instantLogging"), Wi = !!window.localStorage.getItem("__devtoolLocalDash"));
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"));
3158
3163
  function $r(t, e) {
3159
3164
  if (!e)
3160
3165
  return t;
@@ -3163,7 +3168,7 @@ function $r(t, e) {
3163
3168
  n[r] = t[r];
3164
3169
  }), n;
3165
3170
  }
3166
- function ou(t, e, n) {
3171
+ function au(t, e, n) {
3167
3172
  var r, i;
3168
3173
  const s = {
3169
3174
  peers: {}
@@ -3181,7 +3186,7 @@ function ou(t, e, n) {
3181
3186
  }
3182
3187
  return s;
3183
3188
  }
3184
- function au(t, e) {
3189
+ function uu(t, e) {
3185
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))
3186
3191
  return !0;
3187
3192
  for (const r of Object.keys(t.peers))
@@ -3202,7 +3207,7 @@ class Dr {
3202
3207
  this._reject(e);
3203
3208
  }
3204
3209
  }
3205
- var fe = function(t, e, n, r) {
3210
+ var de = function(t, e, n, r) {
3206
3211
  function i(s) {
3207
3212
  return s instanceof n ? s : new n(function(o) {
3208
3213
  o(s);
@@ -3245,25 +3250,33 @@ class wn {
3245
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);
3246
3251
  }
3247
3252
  _initMeta() {
3248
- return fe(this, void 0, void 0, function* () {
3253
+ return de(this, void 0, void 0, function* () {
3254
+ var e, n, r;
3249
3255
  this._meta.loadingPromise && (yield this._meta.loadingPromise);
3250
3256
  try {
3251
- const e = this._persister.getItem(Yt);
3252
- this._meta.loadingPromise = e;
3253
- const n = yield e;
3254
- this._meta.isLoading = !1, this._meta.error = null, this._meta.value = n || { objects: {} };
3255
- } catch (e) {
3256
- this._meta.error = e, this._meta.attempts++, this._meta.loadingPromise = null;
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;
3257
3265
  }
3258
3266
  });
3259
3267
  }
3260
3268
  _getMeta() {
3261
- return fe(this, void 0, void 0, function* () {
3269
+ return de(this, void 0, void 0, function* () {
3262
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);
3263
3271
  });
3264
3272
  }
3273
+ _refreshMeta() {
3274
+ return de(this, void 0, void 0, function* () {
3275
+ return yield this._initMeta(), this._meta.value;
3276
+ });
3277
+ }
3265
3278
  _preloadEntries(e) {
3266
- return fe(this, void 0, void 0, function* () {
3279
+ return de(this, void 0, void 0, function* () {
3267
3280
  const n = yield this.waitForMetaToLoad(), r = Object.entries(n.objects);
3268
3281
  r.sort(([i, s], [o, a]) => a.updatedAt - s.updatedAt);
3269
3282
  for (const [i] of r.slice(0, e))
@@ -3271,7 +3284,7 @@ class wn {
3271
3284
  });
3272
3285
  }
3273
3286
  _getFromStorage(e) {
3274
- return fe(this, void 0, void 0, function* () {
3287
+ return de(this, void 0, void 0, function* () {
3275
3288
  try {
3276
3289
  const n = yield this._persister.getItem(e);
3277
3290
  return n && this.parse(e, n);
@@ -3281,13 +3294,13 @@ class wn {
3281
3294
  });
3282
3295
  }
3283
3296
  waitForKeyToLoad(e) {
3284
- return fe(this, void 0, void 0, function* () {
3297
+ return de(this, void 0, void 0, function* () {
3285
3298
  return this._loadedKeys.has(e) ? this.currentValue[e] : (yield this._loadingKeys[e] || this._loadKey(e), this.currentValue[e]);
3286
3299
  });
3287
3300
  }
3288
3301
  // Used for tests
3289
3302
  waitForMetaToLoad() {
3290
- return fe(this, void 0, void 0, function* () {
3303
+ return de(this, void 0, void 0, function* () {
3291
3304
  return this._getMeta();
3292
3305
  });
3293
3306
  }
@@ -3297,7 +3310,7 @@ class wn {
3297
3310
  this._loadedKeys.delete(e), delete this._loadingKeys[e], delete this.currentValue[e];
3298
3311
  }
3299
3312
  _loadKey(e) {
3300
- return fe(this, void 0, void 0, function* () {
3313
+ return de(this, void 0, void 0, function* () {
3301
3314
  if (this._loadedKeys.has(e) || e in this._loadingKeys)
3302
3315
  return;
3303
3316
  const n = this._getFromStorage(e);
@@ -3357,12 +3370,12 @@ class wn {
3357
3370
  return s || this.gc(), Promise.all(i).then((p) => p.reduce((y, b) => y + b, 0));
3358
3371
  }
3359
3372
  flush() {
3360
- return fe(this, void 0, void 0, function* () {
3373
+ return de(this, void 0, void 0, function* () {
3361
3374
  return this._nextSave ? (clearTimeout(this._nextSave), this._nextSave = null, this._writeToStorage()) : void 0;
3362
3375
  });
3363
3376
  }
3364
3377
  _gc() {
3365
- return fe(this, void 0, void 0, function* () {
3378
+ return de(this, void 0, void 0, function* () {
3366
3379
  const e = new Set(yield this._persister.getAllKeys());
3367
3380
  e.delete(Yt);
3368
3381
  const n = new Set(Object.keys(this.currentValue));
@@ -3370,7 +3383,7 @@ class wn {
3370
3383
  n.add(l);
3371
3384
  for (const l of this._loadedKeys)
3372
3385
  n.add(l);
3373
- const r = yield this._getMeta();
3386
+ const r = yield this._refreshMeta();
3374
3387
  if (!r) {
3375
3388
  this._log.info("Could not gc because we were not able to load meta");
3376
3389
  return;
@@ -3456,18 +3469,18 @@ class wn {
3456
3469
  };
3457
3470
  }
3458
3471
  }
3459
- function qi(t, e = []) {
3472
+ function Wi(t, e = []) {
3460
3473
  t.forEach((n) => {
3461
3474
  const { data: r } = n, { "datalog-result": i } = r, { "join-rows": s } = i;
3462
3475
  for (const o of s)
3463
3476
  for (const a of o)
3464
3477
  e.push(a);
3465
- qi(n["child-nodes"], e);
3478
+ Wi(n["child-nodes"], e);
3466
3479
  });
3467
3480
  }
3468
3481
  function Lr(t) {
3469
3482
  const e = [];
3470
- return qi(t, e), e;
3483
+ return Wi(t, e), e;
3471
3484
  }
3472
3485
  function Fr(t) {
3473
3486
  return Object.values(t.links).reduce((e, n) => {
@@ -3483,8 +3496,8 @@ function Fr(t) {
3483
3496
  }, e;
3484
3497
  }, {});
3485
3498
  }
3486
- const Bn = "v0.22.56-experimental.persisted-object-2.19485585806.1";
3487
- function uu(t, e) {
3499
+ const Bn = "v0.22.56-experimental.persisted-object-2.19512376560.1";
3500
+ function cu(t, e) {
3488
3501
  return {
3489
3502
  info: t ? (...n) => console.info(...n, e()) : () => {
3490
3503
  },
@@ -3568,7 +3581,7 @@ const Nr = [
3568
3581
  "before",
3569
3582
  "fields",
3570
3583
  "aggregate"
3571
- ], cu = (t) => t.valueType || "unknown", zi = (t, e, n = !1) => {
3584
+ ], du = (t) => t.valueType || "unknown", zi = (t, e, n = !1) => {
3572
3585
  if (n || t == null)
3573
3586
  return !0;
3574
3587
  switch (e) {
@@ -3583,7 +3596,7 @@ const Nr = [
3583
3596
  default:
3584
3597
  return !0;
3585
3598
  }
3586
- }, du = (t, e, n, r, i, s, o) => {
3599
+ }, fu = (t, e, n, r, i, s, o) => {
3587
3600
  const a = s.valueType === "json", u = (c, d, f) => {
3588
3601
  if (!zi(f, d, a))
3589
3602
  throw new R(`Invalid value for operator '${c}' on attribute '${r}' in entity '${i}'. Expected ${d}, but received: ${typeof f}`, o);
@@ -3616,16 +3629,16 @@ const Nr = [
3616
3629
  throw new R(`Unknown operator '${t}' for attribute '${r}' in entity '${i}'`, o);
3617
3630
  }
3618
3631
  }, Le = (t, e, n, r, i) => {
3619
- const s = cu(n), o = n.valueType === "json";
3632
+ const s = du(n), o = n.valueType === "json";
3620
3633
  if (typeof t == "object" && t !== null && !Array.isArray(t)) {
3621
3634
  if (o)
3622
3635
  return;
3623
3636
  const u = t;
3624
3637
  for (const [c, d] of Object.entries(u))
3625
- du(c, d, s, e, r, n, `${i}.${c}`);
3638
+ fu(c, d, s, e, r, n, `${i}.${c}`);
3626
3639
  } else if (!zi(t, s, o))
3627
3640
  throw new R(`Invalid value for attribute '${e}' in entity '${r}'. Expected ${s}, but received: ${typeof t}`, i);
3628
- }, fu = (t, e, n, r, i) => {
3641
+ }, lu = (t, e, n, r, i) => {
3629
3642
  const s = t.split(".");
3630
3643
  if (s.length < 2)
3631
3644
  throw new R(`Invalid dot notation path '${t}'. Must contain at least one dot.`, i);
@@ -3675,7 +3688,7 @@ const Nr = [
3675
3688
  continue;
3676
3689
  }
3677
3690
  if (i.includes(".")) {
3678
- fu(i, s, e, n, `${r}.${i}`);
3691
+ lu(i, s, e, n, `${r}.${i}`);
3679
3692
  continue;
3680
3693
  }
3681
3694
  const o = n.entities[e];
@@ -3695,7 +3708,7 @@ const Nr = [
3695
3708
  Le(s, i, c, e, `${r}.${i}`);
3696
3709
  }
3697
3710
  }
3698
- }, lu = (t, e, n, r, i = 0) => {
3711
+ }, hu = (t, e, n, r, i = 0) => {
3699
3712
  for (const o of Object.keys(t))
3700
3713
  if (!Nr.includes(o))
3701
3714
  throw new R(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Nr.join(", ")}. Found: ${o}`, r);
@@ -3734,7 +3747,7 @@ const Nr = [
3734
3747
  const a = t[o];
3735
3748
  if (typeof a != "object" || a === null)
3736
3749
  throw new R(`Query parameter '$' must be an object in entity '${e}', but received: ${typeof a}`, `${r}.$`);
3737
- lu(a, e, n, `${r}.$`, i);
3750
+ hu(a, e, n, `${r}.$`, i);
3738
3751
  }
3739
3752
  }, Kr = (t, e) => {
3740
3753
  if (typeof t != "object" || t === null)
@@ -3755,25 +3768,25 @@ const Nr = [
3755
3768
  Gi(n[r], r, e, r, 0);
3756
3769
  }
3757
3770
  }
3758
- }, Wr = (t) => typeof t != "string" ? !1 : It(t) ? !0 : Ne(t);
3771
+ }, qr = (t) => typeof t != "string" ? !1 : It(t) ? !0 : Ne(t);
3759
3772
  class ie extends Error {
3760
3773
  constructor(e) {
3761
3774
  super(e), this.name = "TransactionValidationError";
3762
3775
  }
3763
3776
  }
3764
- const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`Entity '${t}' does not exist in schema. Available entities: ${Bi(e)}`), qr = {
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 = {
3765
3778
  string: (t) => typeof t == "string",
3766
3779
  number: (t) => typeof t == "number" && !isNaN(t),
3767
3780
  boolean: (t) => typeof t == "boolean",
3768
3781
  date: (t) => t instanceof Date || typeof t == "string" || typeof t == "number",
3769
3782
  json: () => !0
3770
- }, pu = (t, e) => {
3783
+ }, yu = (t, e) => {
3771
3784
  var n, r;
3772
- return t == null ? !0 : (r = (n = qr[e.valueType]) === null || n === void 0 ? void 0 : n.call(qr, t)) !== null && r !== void 0 ? r : !1;
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;
3773
3786
  }, Qi = (t, e) => {
3774
3787
  const n = e.entities[t];
3775
3788
  if (!n)
3776
- throw hu(t, Object.keys(e.entities));
3789
+ throw pu(t, Object.keys(e.entities));
3777
3790
  return n;
3778
3791
  }, Jt = (t, e, n) => {
3779
3792
  const r = Qi(t, n);
@@ -3783,7 +3796,7 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`E
3783
3796
  if (i === "id")
3784
3797
  continue;
3785
3798
  const o = r.attrs[i];
3786
- if (o && !pu(s, o))
3799
+ if (o && !yu(s, o))
3787
3800
  throw new ie(`Invalid value for attribute '${i}' in entity '${t}'. Expected ${o.valueType}, but received: ${typeof s}`);
3788
3801
  }
3789
3802
  }, zr = (t, e, n) => {
@@ -3798,13 +3811,13 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`E
3798
3811
  if (s != null) {
3799
3812
  if (Array.isArray(s)) {
3800
3813
  for (const a of s)
3801
- if (!Wr(a))
3814
+ if (!qr(a))
3802
3815
  throw new ie(`Invalid entity ID in link '${i}' for entity '${t}'. Expected a UUID or a lookup, but received: ${a}`);
3803
- } else if (!Wr(s))
3816
+ } else if (!qr(s))
3804
3817
  throw new ie(`Invalid UUID in link '${i}' for entity '${t}'. Expected a UUID, but received: ${s}`);
3805
3818
  }
3806
3819
  }
3807
- }, yu = {
3820
+ }, bu = {
3808
3821
  create: Jt,
3809
3822
  update: Jt,
3810
3823
  merge: Jt,
@@ -3812,7 +3825,7 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`E
3812
3825
  unlink: zr,
3813
3826
  delete: () => {
3814
3827
  }
3815
- }, bu = (t, e) => {
3828
+ }, _u = (t, e) => {
3816
3829
  if (!e)
3817
3830
  return;
3818
3831
  const [n, r, i, s] = t;
@@ -3820,9 +3833,9 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`E
3820
3833
  throw new ie(`Invalid id for entity '${r}'. Expected a UUID, but received: ${i}`);
3821
3834
  if (typeof r != "string")
3822
3835
  throw new ie(`Entity name must be a string, but received: ${typeof r}`);
3823
- const o = yu[n];
3836
+ const o = bu[n];
3824
3837
  o && s !== void 0 && o(r, s, e);
3825
- }, _u = (t, e) => {
3838
+ }, gu = (t, e) => {
3826
3839
  const n = Array.isArray(t) ? t : [t];
3827
3840
  for (const r of n) {
3828
3841
  if (!r || typeof r != "object")
@@ -3832,7 +3845,7 @@ const Bi = (t) => t.length > 0 ? t.join(", ") : "none", hu = (t, e) => new ie(`E
3832
3845
  for (const i of r.__ops) {
3833
3846
  if (!Array.isArray(i))
3834
3847
  throw new ie(`Transaction operation must be an array, but received: ${typeof i}`);
3835
- bu(i, e);
3848
+ _u(i, e);
3836
3849
  }
3837
3850
  }
3838
3851
  };
@@ -3892,7 +3905,7 @@ class Gr {
3892
3905
  return this.conn.send(JSON.stringify(e));
3893
3906
  }
3894
3907
  }
3895
- class gu {
3908
+ class Tu {
3896
3909
  constructor(e, n) {
3897
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(() => {
3898
3911
  this.initParams || this.handleError();
@@ -3997,14 +4010,14 @@ var Br = function(t, e, n, r) {
3997
4010
  c((r = r.apply(t, e || [])).next());
3998
4011
  });
3999
4012
  };
4000
- function Tu(t, e) {
4013
+ function wu(t, e) {
4001
4014
  const n = t.values;
4002
4015
  if (n)
4003
4016
  for (const r of n.entities || [])
4004
4017
  r.store.useDateObjects = e, r.store.attrs = n.attrs, r.store = vi(r.store);
4005
4018
  return t;
4006
4019
  }
4007
- function wu(t, e) {
4020
+ function mu(t, e) {
4008
4021
  var n, r;
4009
4022
  if (!((n = e.values) === null || n === void 0) && n.entities) {
4010
4023
  const i = [];
@@ -4016,7 +4029,7 @@ function wu(t, e) {
4016
4029
  } else
4017
4030
  return e;
4018
4031
  }
4019
- function mu(t, e, n) {
4032
+ function vu(t, e, n) {
4020
4033
  const r = e == null ? void 0 : e.state.txId, i = n == null ? void 0 : n.state.txId;
4021
4034
  return r && (!i || r > i) ? e : i && (!r || i > r) ? n : e || n;
4022
4035
  }
@@ -4042,7 +4055,7 @@ function Hr(t, e) {
4042
4055
  break;
4043
4056
  }
4044
4057
  }
4045
- function vu(t, e) {
4058
+ function Su(t, e) {
4046
4059
  var n, r, i, s;
4047
4060
  const o = {};
4048
4061
  for (const { action: a, triple: u } of e) {
@@ -4066,7 +4079,7 @@ function vu(t, e) {
4066
4079
  function gt(t, e) {
4067
4080
  return { [t.table]: e.map((n) => n.entity) };
4068
4081
  }
4069
- function Su(t, e) {
4082
+ function Ou(t, e) {
4070
4083
  const n = t.orderFieldType;
4071
4084
  if (t.orderField === "serverCreatedAt") {
4072
4085
  e.sort(t.orderDirection === "asc" ? function(s, o) {
@@ -4087,9 +4100,9 @@ var Se;
4087
4100
  (function(t) {
4088
4101
  t.InitialSyncBatch = "InitialSyncBatch", t.InitialSyncComplete = "InitialSyncComplete", t.LoadFromStorage = "LoadFromStorage", t.SyncTransaction = "SyncTransaction", t.Error = "Error";
4089
4102
  })(Se || (Se = {}));
4090
- class Ou {
4103
+ class Eu {
4091
4104
  constructor(e, n, r, i, s) {
4092
- this.callbacks = {}, this.idToHash = {}, this.trySend = e, this.config = r, this.log = i, this.createStore = s, this.subs = new wn(n, mu, wu, (o, a) => Tu(a, this.config.useDateObjects), (o) => {
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) => {
4093
4106
  var a;
4094
4107
  return ((a = o.values) === null || a === void 0 ? void 0 : a.entities.length) || 0;
4095
4108
  }, i, {
@@ -4223,8 +4236,8 @@ class Ou {
4223
4236
  serverCreatedAt: Qr(a, f, l.id)
4224
4237
  }), o.push(l);
4225
4238
  }
4226
- a.updatedAt = Date.now(), this.subs.updateInPlace((d) => {
4227
- d[s] = a;
4239
+ this.subs.updateInPlace((d) => {
4240
+ d[s] = a, d[s].updatedAt = Date.now();
4228
4241
  }), a.values && this.notifyCbs(s, {
4229
4242
  type: Se.InitialSyncBatch,
4230
4243
  data: gt(a, a.values.entities),
@@ -4291,9 +4304,9 @@ class Ou {
4291
4304
  for (const [m, E] of Object.entries(p))
4292
4305
  if (io(E.store, w)) {
4293
4306
  Hr(E.store, T);
4294
- const S = Zt(a, E.store), I = vu(E.store, T)[w];
4295
- for (const [U, { oldValue: W, newValue: we }] of Object.entries(I || {}))
4296
- W === we && delete I[U];
4307
+ const S = Zt(a, E.store), I = Su(E.store, T)[w];
4308
+ for (const [x, { oldValue: q, newValue: we }] of Object.entries(I || {}))
4309
+ q === we && delete I[x];
4297
4310
  S ? (y.push({
4298
4311
  oldEntity: E.entity,
4299
4312
  newEntity: S,
@@ -4323,16 +4336,16 @@ class Ou {
4323
4336
  const g = [];
4324
4337
  for (const w of d.sort().reverse())
4325
4338
  g.push(p[w].entity), p.splice(w, 1);
4326
- Su(a, p), this.notifyCbs(o, {
4339
+ Ou(a, p), this.notifyCbs(o, {
4327
4340
  type: Se.SyncTransaction,
4328
4341
  data: gt(a, (i = a.values) === null || i === void 0 ? void 0 : i.entities),
4329
4342
  added: b,
4330
4343
  removed: g,
4331
4344
  updated: y
4332
- }), a.updatedAt = Date.now();
4345
+ });
4333
4346
  }
4334
4347
  this.subs.updateInPlace((c) => {
4335
- c[o] = a;
4348
+ c[o] = a, c[o].updatedAt = Date.now();
4336
4349
  });
4337
4350
  }
4338
4351
  clearSubscriptionData(e, n) {
@@ -4390,7 +4403,7 @@ var F = function(t, e, n, r) {
4390
4403
  }
4391
4404
  c((r = r.apply(t, e || [])).next());
4392
4405
  });
4393
- }, Eu = function(t, e) {
4406
+ }, Au = function(t, e) {
4394
4407
  var n = {};
4395
4408
  for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && e.indexOf(r) < 0 && (n[r] = t[r]);
4396
4409
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
@@ -4404,23 +4417,23 @@ const le = {
4404
4417
  AUTHENTICATED: "authenticated",
4405
4418
  CLOSED: "closed",
4406
4419
  ERRORED: "errored"
4407
- }, Au = 3e4, ku = 3e4, ju = 200, Cu = {
4420
+ }, ku = 3e4, ju = 3e4, Cu = 200, Pu = {
4408
4421
  apiURI: "https://api.instantdb.com",
4409
4422
  websocketURI: "wss://api.instantdb.com/runtime/session"
4410
4423
  }, Xt = "_instant_oauth_redirect", Qe = "currentUser";
4411
- function Pu({ transportType: t, appId: e, apiURI: n, wsURI: r, EventSourceImpl: i }) {
4424
+ function Iu({ transportType: t, appId: e, apiURI: n, wsURI: r, EventSourceImpl: i }) {
4412
4425
  if (!i)
4413
4426
  return new Gr(`${r}?app_id=${e}`);
4414
4427
  switch (t) {
4415
4428
  case "ws":
4416
4429
  return new Gr(`${r}?app_id=${e}`);
4417
4430
  case "sse":
4418
- return new gu(i, `${n}/runtime/sse?app_id=${e}`);
4431
+ return new Tu(i, `${n}/runtime/sse?app_id=${e}`);
4419
4432
  default:
4420
4433
  throw new Error("Unknown transport type " + t);
4421
4434
  }
4422
4435
  }
4423
- function Iu() {
4436
+ function Mu() {
4424
4437
  return typeof window < "u" || typeof chrome < "u";
4425
4438
  }
4426
4439
  const Yr = {
@@ -4429,7 +4442,7 @@ const Yr = {
4429
4442
  "refresh-presence": !0,
4430
4443
  "patch-presence": !0
4431
4444
  };
4432
- function Mu(t, e) {
4445
+ function Ru(t, e) {
4433
4446
  var n;
4434
4447
  const r = typeof t == "string" ? JSON.parse(t) : t;
4435
4448
  if (!((n = r == null ? void 0 : r.result) === null || n === void 0) && n.store) {
@@ -4438,12 +4451,12 @@ function Mu(t, e) {
4438
4451
  }
4439
4452
  return r;
4440
4453
  }
4441
- function Ru(t, e) {
4454
+ function xu(t, e) {
4442
4455
  var n;
4443
4456
  const r = Object.assign({}, e);
4444
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;
4445
4458
  }
4446
- function xu(t, e) {
4459
+ function $u(t, e) {
4447
4460
  switch (t) {
4448
4461
  case "pendingMutations":
4449
4462
  return new Map(typeof e == "string" ? JSON.parse(e) : e);
@@ -4451,7 +4464,7 @@ function xu(t, e) {
4451
4464
  return e;
4452
4465
  }
4453
4466
  }
4454
- function $u(t, e) {
4467
+ function Du(t, e) {
4455
4468
  switch (t) {
4456
4469
  case "pendingMutations":
4457
4470
  return [...e.entries()];
@@ -4459,19 +4472,20 @@ function $u(t, e) {
4459
4472
  return e;
4460
4473
  }
4461
4474
  }
4475
+ function Uu(t, e, n) {
4476
+ const r = e == null ? void 0 : e.result, i = n == null ? void 0 : n.result;
4477
+ return r && !i && n && (n.result = r), n || e;
4478
+ }
4462
4479
  function Jr(t) {
4463
4480
  return [...t].sort((e, n) => {
4464
4481
  const [r, i] = e, [s, o] = n, a = i.order || 0, u = o.order || 0;
4465
4482
  return a == u ? r < s ? -1 : r > s ? 1 : 0 : a - u;
4466
4483
  });
4467
4484
  }
4468
- class Du {
4485
+ class Lu {
4469
4486
  constructor(e, n = Fi, r = Ni, i, s) {
4470
4487
  var o, a, u;
4471
- 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._onMergeQuerySub = (c, d, f) => {
4472
- const l = d == null ? void 0 : d.result, p = f == null ? void 0 : f.result;
4473
- return l && !p && f && (f.result = l), f || d;
4474
- }, this._onMergeKv = (c, d, f) => {
4488
+ 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) => {
4475
4489
  var l, p;
4476
4490
  switch (c) {
4477
4491
  case "pendingMutations": {
@@ -4482,7 +4496,7 @@ class Du {
4482
4496
  }), g;
4483
4497
  }
4484
4498
  default:
4485
- return d || f;
4499
+ return f || d;
4486
4500
  }
4487
4501
  }, this.getPreviousResult = (c) => {
4488
4502
  const d = V(c);
@@ -4500,13 +4514,11 @@ class Du {
4500
4514
  }, this.notifyQueryError = (c, d) => {
4501
4515
  (this.queryCbs[c] || []).forEach((l) => l.cb({ error: d }));
4502
4516
  }, this.pushTx = (c) => {
4503
- this.config.disableValidation || _u(c, this.config.schema);
4517
+ this.config.disableValidation || gu(c, this.config.schema);
4504
4518
  try {
4505
4519
  const d = Na({
4506
4520
  attrs: this.optimisticAttrs(),
4507
4521
  schema: this.config.schema,
4508
- // XXX: How are we going to do this?
4509
- // XXX: This should only look at currently active subs
4510
4522
  stores: Object.values(this.querySubs.currentValue).map((f) => {
4511
4523
  var l;
4512
4524
  return (l = f == null ? void 0 : f.result) === null || l === void 0 ? void 0 : l.store;
@@ -4589,7 +4601,7 @@ class Du {
4589
4601
  return;
4590
4602
  }
4591
4603
  this._log.info("[socket][close]", d.id, "schedule reconnect, ms =", this._reconnectTimeoutMs), this._scheduleReconnect();
4592
- }, this._EventSource = s, this.config = Object.assign(Object.assign({}, Cu), e), this.queryCacheLimit = (o = this.config.queryCacheLimit) !== null && o !== void 0 ? o : 10, this._pendingTxCleanupTimeout = (a = this.config.pendingTxCleanupTimeout) !== null && a !== void 0 ? a : ku, this._pendingMutationCleanupThreshold = (u = this.config.pendingMutationCleanupThreshold) !== null && u !== void 0 ? u : ju, this._log = uu(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)), !!Iu()) {
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()) {
4593
4605
  if (!e.appId)
4594
4606
  throw new Error("Instant must be initialized with an appId.");
4595
4607
  if (!Ne(e.appId))
@@ -4604,7 +4616,7 @@ class Du {
4604
4616
  } catch (f) {
4605
4617
  this._log.error("[error] handle broadcast channel", f);
4606
4618
  }
4607
- }))), this._initStorage(n), this._syncTable = new Ou(this._trySendAuthed.bind(this), new n(this.config.appId, "syncSubs"), {
4619
+ }))), this._initStorage(n), this._syncTable = new Eu(this._trySendAuthed.bind(this), new n(this.config.appId, "syncSubs"), {
4608
4620
  useDateObjects: this.config.useDateObjects
4609
4621
  }, 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) => {
4610
4622
  this._isOnline = c, this._startSocket(), r.listen((d) => {
@@ -4629,9 +4641,9 @@ class Du {
4629
4641
  _initStorage(e) {
4630
4642
  this.querySubs = new wn(
4631
4643
  new e(this.config.appId, "querySubs"),
4632
- this._onMergeQuerySub,
4633
- Ru,
4634
- (n, r) => Mu(r, this.config.useDateObjects),
4644
+ Uu,
4645
+ xu,
4646
+ (n, r) => Ru(r, this.config.useDateObjects),
4635
4647
  // objectSize
4636
4648
  (n) => {
4637
4649
  var r, i, s, o;
@@ -4649,7 +4661,7 @@ class Du {
4649
4661
  // 1 million triples
4650
4662
  }
4651
4663
  }
4652
- ), this.querySubs.onKeyLoaded = (n) => this._onQuerySubLoaded(n), this.kv = new wn(new e(this.config.appId, "kv"), this._onMergeKv, $u, xu, () => 0, this._log, {
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, {
4653
4665
  saveThrottleMs: 100,
4654
4666
  idleCallbackMaxWaitMs: 100,
4655
4667
  gc: {
@@ -4681,14 +4693,14 @@ class Du {
4681
4693
  if (s)
4682
4694
  i.resolve({ status: e, eventId: n });
4683
4695
  else if (r.type) {
4684
- const { status: o } = r, a = Eu(r, ["status"]);
4696
+ const { status: o } = r, a = Au(r, ["status"]);
4685
4697
  i.reject(new $t({
4686
4698
  // @ts-expect-error body.type is not constant typed
4687
4699
  body: a,
4688
4700
  status: o
4689
4701
  }));
4690
4702
  } else
4691
- i.reject(new We(r.message, r.hint));
4703
+ i.reject(new qe(r.message, r.hint));
4692
4704
  }
4693
4705
  _setStatus(e, n) {
4694
4706
  this.status = e, this._errorMessage = n, this.notifyConnectionStatusSubs(e);
@@ -4723,12 +4735,18 @@ class Du {
4723
4735
  if (!this._hasQueryListeners() && !this.querySubs.currentValue[y])
4724
4736
  break;
4725
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);
4726
- this.querySubs.updateInPlace((m) => (m[y].result = {
4727
- store: T,
4728
- pageInfo: b,
4729
- aggregate: g,
4730
- processedTxId: n["processed-tx-id"]
4731
- }, m)), this._cleanupPendingMutationsQueries(), this.notifyOne(y), this.notifyOneQueryOnce(y), this._cleanupPendingMutationsTimeout();
4738
+ this.querySubs.updateInPlace((m) => {
4739
+ if (!m[y]) {
4740
+ this._log.error("Missing value in querySubs", { hash: y, q: l });
4741
+ return;
4742
+ }
4743
+ m[y].result = {
4744
+ store: T,
4745
+ pageInfo: b,
4746
+ aggregate: g,
4747
+ processedTxId: n["processed-tx-id"]
4748
+ };
4749
+ }), this._cleanupPendingMutationsQueries(), this.notifyOne(y), this.notifyOneQueryOnce(y), this._cleanupPendingMutationsTimeout();
4732
4750
  break;
4733
4751
  }
4734
4752
  case "start-sync-ok": {
@@ -4756,11 +4774,17 @@ class Du {
4756
4774
  });
4757
4775
  const g = Jr(b.entries()), w = l.map((T) => {
4758
4776
  var m, E, S, I;
4759
- const U = T["instaql-query"], W = T["instaql-result"], we = V(U), dt = Lr(W), Lt = St(this.attrs, dt, c, this._linkIndex, this.config.useDateObjects), Ft = this._applyOptimisticUpdates(Lt, g, y), ft = (E = (m = W == null ? void 0 : W[0]) === null || m === void 0 ? void 0 : m.data) === null || E === void 0 ? void 0 : E["page-info"], ce = (I = (S = W == null ? void 0 : W[0]) === null || S === void 0 ? void 0 : S.data) === null || I === void 0 ? void 0 : I.aggregate;
4760
- return { hash: we, store: Ft, pageInfo: ft, aggregate: ce };
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;
4778
+ return { q: x, hash: we, store: Ft, pageInfo: ft, aggregate: ce };
4761
4779
  });
4762
- w.forEach(({ hash: T, store: m, pageInfo: E, aggregate: S }) => {
4763
- this.querySubs.updateInPlace((I) => (I[T].result = { store: m, pageInfo: E, aggregate: S, processedTxId: y }, I));
4780
+ w.forEach(({ hash: T, q: m, store: E, pageInfo: S, aggregate: I }) => {
4781
+ this.querySubs.updateInPlace((x) => {
4782
+ if (!x[T]) {
4783
+ this._log.error("Missing value in querySubs", { hash: T, q: m });
4784
+ return;
4785
+ }
4786
+ x[T].result = { store: E, pageInfo: S, aggregate: I, processedTxId: y };
4787
+ });
4764
4788
  }), this._cleanupPendingMutationsQueries(), w.forEach(({ hash: T }) => {
4765
4789
  this.notifyOne(T);
4766
4790
  });
@@ -4837,15 +4861,14 @@ class Du {
4837
4861
  * @param {{message: string, type?: string, status?: number, hint?: unknown}} errorMsg
4838
4862
  */
4839
4863
  _handleMutationError(e, n, r) {
4840
- var i;
4841
- const s = (i = this.kv.currentValue.pendingMutations) === null || i === void 0 ? void 0 : i.get(n);
4842
- if (s && (e !== "timeout" || !s["tx-id"])) {
4843
- this._updatePendingMutations((a) => (a.delete(n), a)), this._inFlightMutationEventIds.delete(n);
4844
- const o = {
4864
+ const i = this._pendingMutations().get(n);
4865
+ if (i && (e !== "timeout" || !i["tx-id"])) {
4866
+ this._updatePendingMutations((o) => (o.delete(n), o)), this._inFlightMutationEventIds.delete(n);
4867
+ const s = {
4845
4868
  message: r.message,
4846
4869
  hint: r.hint
4847
4870
  };
4848
- this.notifyAll(), this.notifyAttrsSubs(), this.notifyMutationErrorSubs(o), this._finishTransaction(e, n, r);
4871
+ this.notifyAll(), this.notifyAttrsSubs(), this.notifyMutationErrorSubs(s), this._finishTransaction(e, n, r);
4849
4872
  }
4850
4873
  }
4851
4874
  _handleReceiveError(e) {
@@ -4929,7 +4952,7 @@ class Du {
4929
4952
  if (!this.querySubs)
4930
4953
  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;
4931
4954
  const s = V(e), o = this._startQuerySub(e, s);
4932
- 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")), Au), i.promise;
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;
4933
4956
  }
4934
4957
  _completeQueryOnce(e, n, r) {
4935
4958
  this.queryOnceDfds[n] && (this.queryOnceDfds[n] = this.queryOnceDfds[n].filter((i) => i.dfd !== r), this._cleanupQuery(e, n));
@@ -5048,12 +5071,11 @@ class Du {
5048
5071
  /** Re-compute all subscriptions */
5049
5072
  notifyAll() {
5050
5073
  Object.keys(this.queryCbs).forEach((e) => {
5051
- this.notifyOne(e);
5074
+ this.querySubs.waitForKeyToLoad(e).then(() => this.notifyOne(e)).catch(() => this.notifyOne(e));
5052
5075
  });
5053
5076
  }
5054
- // XXX: This will have to be more targeted to just the hashes that have been loaded
5055
5077
  loadedNotifyAll() {
5056
- this.notifyAll();
5078
+ this.kv.waitForKeyToLoad("pendingMutations").then(() => this.notifyAll()).catch(() => this.notifyAll());
5057
5079
  }
5058
5080
  shutdown() {
5059
5081
  var e;
@@ -5152,7 +5174,7 @@ class Du {
5152
5174
  return;
5153
5175
  }
5154
5176
  const e = this._transport;
5155
- this._transport = Pu({
5177
+ this._transport = Iu({
5156
5178
  transportType: this._transportType,
5157
5179
  appId: this.config.appId,
5158
5180
  apiURI: this.config.apiURI,
@@ -5262,7 +5284,7 @@ class Du {
5262
5284
  return F(this, void 0, void 0, function* () {
5263
5285
  const { user: e, error: n } = yield this.getCurrentUser();
5264
5286
  if (n)
5265
- throw new We("Could not get current user: " + n.message);
5287
+ throw new qe("Could not get current user: " + n.message);
5266
5288
  return e;
5267
5289
  });
5268
5290
  }
@@ -5311,11 +5333,19 @@ class Du {
5311
5333
  return F(this, void 0, void 0, function* () {
5312
5334
  const e = yield this._waitForOAuthCallbackResponse();
5313
5335
  if (e != null && e.error) {
5314
- const i = { error: e.error, user: void 0 };
5315
- return this._currentUserCached = Object.assign({ isLoading: !1 }, i), i;
5336
+ const n = { error: e.error, user: void 0 };
5337
+ return this._currentUserCached = Object.assign({ isLoading: !1 }, n), n;
5338
+ }
5339
+ try {
5340
+ const r = { user: yield this._getCurrentUser(), error: void 0 };
5341
+ return this._currentUserCached = Object.assign({ isLoading: !1 }, r), r;
5342
+ } catch (n) {
5343
+ return {
5344
+ user: void 0,
5345
+ isLoading: !1,
5346
+ error: { message: (n == null ? void 0 : n.message) || "Error loading user" }
5347
+ };
5316
5348
  }
5317
- const r = { user: yield this._getCurrentUser(), error: void 0 };
5318
- return this._currentUserCached = Object.assign({ isLoading: !1 }, r), r;
5319
5349
  });
5320
5350
  }
5321
5351
  _hasCurrentUser() {
@@ -5347,7 +5377,7 @@ class Du {
5347
5377
  }), this._reconnectTimeoutMs = 0, this._transport.close(), this._oauthCallbackResponse = null, this.notifyAuthSubs(n);
5348
5378
  }
5349
5379
  sendMagicCode({ email: e }) {
5350
- return Ha({
5380
+ return Ya({
5351
5381
  apiURI: this.config.apiURI,
5352
5382
  appId: this.config.appId,
5353
5383
  email: e
@@ -5356,7 +5386,7 @@ class Du {
5356
5386
  signInWithMagicCode(e) {
5357
5387
  return F(this, arguments, void 0, function* ({ email: n, code: r }) {
5358
5388
  var i;
5359
- const s = yield this.getCurrentUser(), o = ((i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.type) === "guest", a = yield Ya({
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({
5360
5390
  apiURI: this.config.apiURI,
5361
5391
  appId: this.config.appId,
5362
5392
  email: n,
@@ -5368,7 +5398,7 @@ class Du {
5368
5398
  }
5369
5399
  signInWithCustomToken(e) {
5370
5400
  return F(this, void 0, void 0, function* () {
5371
- const n = yield Ja({
5401
+ const n = yield Za({
5372
5402
  apiURI: this.config.apiURI,
5373
5403
  appId: this.config.appId,
5374
5404
  refreshToken: e
@@ -5378,7 +5408,7 @@ class Du {
5378
5408
  }
5379
5409
  signInAsGuest() {
5380
5410
  return F(this, void 0, void 0, function* () {
5381
- const e = yield Za({
5411
+ const e = yield Xa({
5382
5412
  apiURI: this.config.apiURI,
5383
5413
  appId: this.config.appId
5384
5414
  });
@@ -5394,7 +5424,7 @@ class Du {
5394
5424
  this._log.info("[auth-invalidate] skipped invalidateToken");
5395
5425
  return;
5396
5426
  }
5397
- eu({
5427
+ tu({
5398
5428
  apiURI: this.config.apiURI,
5399
5429
  appId: this.config.appId,
5400
5430
  refreshToken: i
@@ -5452,7 +5482,7 @@ class Du {
5452
5482
  signInWithIdToken(e) {
5453
5483
  return F(this, arguments, void 0, function* ({ idToken: n, clientName: r, nonce: i }) {
5454
5484
  var s;
5455
- const o = yield this.getCurrentUser(), a = (s = o == null ? void 0 : o.user) === null || s === void 0 ? void 0 : s.refresh_token, u = yield Xa({
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({
5456
5486
  apiURI: this.config.apiURI,
5457
5487
  appId: this.config.appId,
5458
5488
  idToken: n,
@@ -5493,7 +5523,7 @@ class Du {
5493
5523
  // TODO: look into typing again
5494
5524
  getPresence(e, n, r = {}) {
5495
5525
  const i = this._rooms[n], s = this._presence[n];
5496
- return !i || !s || !s.result ? null : Object.assign(Object.assign({}, ou(s.result, r, this._sessionId)), { isLoading: !i.isConnected, error: i.error });
5526
+ return !i || !s || !s.result ? null : Object.assign(Object.assign({}, au(s.result, r, this._sessionId)), { isLoading: !i.isConnected, error: i.error });
5497
5527
  }
5498
5528
  // TODO: look into typing again
5499
5529
  publishPresence(e, n, r) {
@@ -5543,7 +5573,7 @@ class Du {
5543
5573
  }
5544
5574
  _notifyPresenceSub(e, n) {
5545
5575
  const r = this.getPresence("", e, n);
5546
- r && (n.prev && !au(r, n.prev) || (n.prev = r, n.cb(r)));
5576
+ r && (n.prev && !uu(r, n.prev) || (n.prev = r, n.cb(r)));
5547
5577
  }
5548
5578
  _patchPresencePeers(e, n) {
5549
5579
  var r, i, s;
@@ -5617,14 +5647,14 @@ class Du {
5617
5647
  return F(this, void 0, void 0, function* () {
5618
5648
  var i;
5619
5649
  const s = yield this.getCurrentUser(), o = (i = s == null ? void 0 : s.user) === null || i === void 0 ? void 0 : i.refresh_token;
5620
- return tu(Object.assign(Object.assign({}, r), { apiURI: this.config.apiURI, appId: this.config.appId, path: e, file: n, refreshToken: o }));
5650
+ return nu(Object.assign(Object.assign({}, r), { apiURI: this.config.apiURI, appId: this.config.appId, path: e, file: n, refreshToken: o }));
5621
5651
  });
5622
5652
  }
5623
5653
  deleteFile(e) {
5624
5654
  return F(this, void 0, void 0, function* () {
5625
5655
  var n;
5626
5656
  const r = yield this.getCurrentUser(), i = (n = r == null ? void 0 : r.user) === null || n === void 0 ? void 0 : n.refresh_token;
5627
- return yield nu({
5657
+ return yield ru({
5628
5658
  apiURI: this.config.apiURI,
5629
5659
  appId: this.config.appId,
5630
5660
  path: e,
@@ -5637,20 +5667,20 @@ class Du {
5637
5667
  upload(e, n) {
5638
5668
  return F(this, void 0, void 0, function* () {
5639
5669
  var r;
5640
- 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 ru({
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({
5641
5671
  apiURI: this.config.apiURI,
5642
5672
  appId: this.config.appId,
5643
5673
  fileName: o,
5644
5674
  refreshToken: s
5645
5675
  });
5646
- return yield iu(a, n);
5676
+ return yield su(a, n);
5647
5677
  });
5648
5678
  }
5649
5679
  getDownloadUrl(e) {
5650
5680
  return F(this, void 0, void 0, function* () {
5651
5681
  var n;
5652
5682
  const r = yield this.getCurrentUser(), i = (n = r == null ? void 0 : r.user) === null || n === void 0 ? void 0 : n.refresh_token;
5653
- return yield su({
5683
+ return yield ou({
5654
5684
  apiURI: this.config.apiURI,
5655
5685
  appId: this.config.appId,
5656
5686
  path: e,
@@ -5659,7 +5689,7 @@ class Du {
5659
5689
  });
5660
5690
  }
5661
5691
  }
5662
- function Uu(t, e) {
5692
+ function Fu(t, e) {
5663
5693
  return new Ut(
5664
5694
  Yi(t, e),
5665
5695
  // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the
@@ -5671,25 +5701,25 @@ function Uu(t, e) {
5671
5701
  void 0
5672
5702
  );
5673
5703
  }
5674
- function Lu(t) {
5704
+ function Nu(t) {
5675
5705
  return new Dt(t, {});
5676
5706
  }
5677
- function Fu() {
5707
+ function Ku() {
5678
5708
  return new H("string", !0, !1);
5679
5709
  }
5680
- function Nu() {
5710
+ function qu() {
5681
5711
  return new H("number", !0, !1);
5682
5712
  }
5683
- function Ku() {
5713
+ function Wu() {
5684
5714
  return new H("boolean", !0, !1);
5685
5715
  }
5686
- function Wu() {
5716
+ function zu() {
5687
5717
  return new H("date", !0, !1);
5688
5718
  }
5689
- function qu() {
5719
+ function Vu() {
5690
5720
  return new H("json", !0, !1);
5691
5721
  }
5692
- function zu() {
5722
+ function Gu() {
5693
5723
  return new H("json", !0, !1);
5694
5724
  }
5695
5725
  function Yi(t, e) {
@@ -5708,7 +5738,7 @@ function Yi(t, e) {
5708
5738
  new Dt(c.attrs, Object.assign(Object.assign({}, o.fwd[u]), o.rev[u]))
5709
5739
  ]));
5710
5740
  }
5711
- function Vu({ entities: t, links: e, rooms: n }) {
5741
+ function Bu({ entities: t, links: e, rooms: n }) {
5712
5742
  const r = e ?? {}, i = n ?? {};
5713
5743
  return new Ut(
5714
5744
  Yi(t, r),
@@ -5721,23 +5751,23 @@ function Vu({ entities: t, links: e, rooms: n }) {
5721
5751
  i
5722
5752
  );
5723
5753
  }
5724
- const Dc = {
5754
+ const Lc = {
5725
5755
  // constructs
5726
- graph: Uu,
5727
- schema: Vu,
5728
- entity: Lu,
5756
+ graph: Fu,
5757
+ schema: Bu,
5758
+ entity: Nu,
5729
5759
  // value types
5730
- string: Fu,
5731
- number: Nu,
5732
- boolean: Ku,
5733
- date: Wu,
5734
- json: qu,
5735
- any: zu
5760
+ string: Ku,
5761
+ number: qu,
5762
+ boolean: Wu,
5763
+ date: zu,
5764
+ json: Vu,
5765
+ any: Gu
5736
5766
  };
5737
5767
  let Tt;
5738
- function Gu(t, e) {
5768
+ function Qu(t, e) {
5739
5769
  Tt == null || Tt.dispose();
5740
- const n = Zu(e), r = Hu(e, a), i = Qu(Bu(t));
5770
+ const n = ec(e), r = Ju(e, a), i = Yu(Hu(t));
5741
5771
  function s(d) {
5742
5772
  var f;
5743
5773
  d.source === i.element.contentWindow && ((f = d.data) === null || f === void 0 ? void 0 : f.type) === "close" && n.isVisible() && a();
@@ -5759,10 +5789,10 @@ function Gu(t, e) {
5759
5789
  }
5760
5790
  return c();
5761
5791
  }
5762
- function Bu(t) {
5763
- return `${Gn || Wi ? "http://localhost:3000" : "https://instantdb.com"}/_devtool?appId=${t}`;
5792
+ function Hu(t) {
5793
+ return `${Gn || qi ? "http://localhost:3000" : "https://instantdb.com"}/_devtool?appId=${t}`;
5764
5794
  }
5765
- function Qu(t) {
5795
+ function Yu(t) {
5766
5796
  const e = document.createElement("iframe");
5767
5797
  return e.src = t, e.className = "instant-devtool-iframe", Object.assign(e.style, {
5768
5798
  width: "100%",
@@ -5771,7 +5801,7 @@ function Qu(t) {
5771
5801
  border: "none"
5772
5802
  }), { element: e };
5773
5803
  }
5774
- function Hu(t, e) {
5804
+ function Ju(t, e) {
5775
5805
  const n = `
5776
5806
  <svg width="32" height="32" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
5777
5807
  <rect width="512" height="512" fill="black"/>
@@ -5781,7 +5811,7 @@ function Hu(t, e) {
5781
5811
  return r.innerHTML = n, r.className = "instant-devtool-toggler", Object.assign(r.style, Object.assign(Object.assign({
5782
5812
  // pos
5783
5813
  position: "fixed"
5784
- }, Yu(t.position)), {
5814
+ }, Zu(t.position)), {
5785
5815
  height: "32px",
5786
5816
  width: "32px",
5787
5817
  // layout
@@ -5796,7 +5826,7 @@ function Hu(t, e) {
5796
5826
  cursor: "pointer"
5797
5827
  })), r.addEventListener("click", e), { element: r };
5798
5828
  }
5799
- function Yu(t) {
5829
+ function Zu(t) {
5800
5830
  switch (t) {
5801
5831
  case "bottom-left":
5802
5832
  return { bottom: "24px", left: "24px" };
@@ -5808,7 +5838,7 @@ function Yu(t) {
5808
5838
  return { top: "24px", left: "24px" };
5809
5839
  }
5810
5840
  }
5811
- function Ju(t) {
5841
+ function Xu(t) {
5812
5842
  switch (t) {
5813
5843
  case "bottom-left":
5814
5844
  return { bottom: "24px", right: "24px", left: "60px", top: "72px" };
@@ -5820,23 +5850,23 @@ function Ju(t) {
5820
5850
  return { top: "24px", right: "24px", left: "60px", bottom: "72px" };
5821
5851
  }
5822
5852
  }
5823
- function Zu(t) {
5853
+ function ec(t) {
5824
5854
  const e = document.createElement("div");
5825
- Object.assign(e.style, Object.assign(Object.assign({ position: "fixed" }, Ju(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";
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";
5826
5856
  function n() {
5827
5857
  return e.style.display !== "none";
5828
5858
  }
5829
5859
  return { element: e, isVisible: n };
5830
5860
  }
5831
- const Xu = {
5861
+ const tc = {
5832
5862
  apiURI: "https://api.instantdb.com",
5833
5863
  websocketURI: "wss://api.instantdb.com/runtime/session"
5834
5864
  };
5835
- function ec() {
5865
+ function nc() {
5836
5866
  var t;
5837
5867
  return globalThis.__instantDbSchemaHashStore = (t = globalThis.__instantDbSchemaHashStore) !== null && t !== void 0 ? t : /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
5838
5868
  }
5839
- function tc() {
5869
+ function rc() {
5840
5870
  var t;
5841
5871
  return globalThis.__instantDbStore = (t = globalThis.__instantDbStore) !== null && t !== void 0 ? t : {}, globalThis.__instantDbStore;
5842
5872
  }
@@ -5844,23 +5874,23 @@ function mn(t) {
5844
5874
  const e = t.__adminToken;
5845
5875
  return t.appId + "_" + (t.websocketURI || "default_ws_uri") + "_" + (t.apiURI || "default_api_uri") + "_" + (e || "client_only") + "_" + t.useDateObjects;
5846
5876
  }
5847
- const vn = tc(), en = ec();
5848
- class nc {
5877
+ const vn = rc(), en = nc();
5878
+ class ic {
5849
5879
  constructor(e) {
5850
5880
  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);
5851
5881
  }
5852
5882
  }
5853
- class rc {
5883
+ class sc {
5854
5884
  constructor(e) {
5855
5885
  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);
5856
5886
  }
5857
5887
  }
5858
- function ic(t) {
5888
+ function oc(t) {
5859
5889
  return JSON.parse(JSON.stringify(t));
5860
5890
  }
5861
- class sc {
5891
+ class ac {
5862
5892
  constructor(e) {
5863
- this.tx = Vn(), this._reactor = e, this.auth = new nc(this._reactor), this.storage = new rc(this._reactor);
5893
+ this.tx = Vn(), this._reactor = e, this.auth = new ic(this._reactor), this.storage = new sc(this._reactor);
5864
5894
  }
5865
5895
  /**
5866
5896
  * Use this to write data! You can create, update, delete, and link objects
@@ -6042,21 +6072,21 @@ function Zr(t) {
6042
6072
  const e = V(t);
6043
6073
  return en.set(t, e), e;
6044
6074
  }
6045
- function oc(t, e) {
6075
+ function uc(t, e) {
6046
6076
  return Zr(t._reactor.config.schema) !== Zr(e);
6047
6077
  }
6048
- function ac(t, e, n, r, i) {
6078
+ function cc(t, e, n, r, i) {
6049
6079
  const s = vn[mn(t)];
6050
6080
  if (s)
6051
- return oc(s, t.schema) && s._reactor.updateSchema(t.schema), s;
6052
- const o = new Du(Object.assign(Object.assign(Object.assign({}, Xu), t), { cardinalityInference: !!t.schema }), e || Fi, n || Ni, Object.assign(Object.assign({}, r || {}), { "@instantdb/core": Bn }), i), a = new sc(o);
6053
- return vn[mn(t)] = a, uc(t.appId, t.devtool), a;
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;
6054
6084
  }
6055
- function uc(t, e) {
6085
+ function dc(t, e) {
6056
6086
  if (typeof window > "u" || typeof window.location > "u" || typeof document > "u" || typeof e == "boolean" && !e)
6057
6087
  return;
6058
6088
  const n = Object.assign({ position: "bottom-right", allowedHosts: ["localhost"] }, typeof e == "object" ? e : {});
6059
- n.allowedHosts.includes(window.location.hostname) && Gu(t, n);
6089
+ n.allowedHosts.includes(window.location.hostname) && Qu(t, n);
6060
6090
  }
6061
6091
  var Sn = { exports: {} }, He = {};
6062
6092
  /**
@@ -6069,7 +6099,7 @@ var Sn = { exports: {} }, He = {};
6069
6099
  * LICENSE file in the root directory of this source tree.
6070
6100
  */
6071
6101
  var Xr;
6072
- function cc() {
6102
+ function fc() {
6073
6103
  if (Xr) return He;
6074
6104
  Xr = 1;
6075
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 };
@@ -6083,7 +6113,7 @@ function cc() {
6083
6113
  return He.Fragment = n, He.jsx = o, He.jsxs = o, He;
6084
6114
  }
6085
6115
  var Ye = {}, ei;
6086
- function dc() {
6116
+ function lc() {
6087
6117
  if (ei) return Ye;
6088
6118
  ei = 1;
6089
6119
  var t = {};
@@ -6122,10 +6152,10 @@ function dc() {
6122
6152
  M.unshift("Warning: " + _), Function.prototype.apply.call(console[h], console, M);
6123
6153
  }
6124
6154
  }
6125
- var S = !1, I = !1, U = !1, W = !1, we = !1, dt;
6155
+ var S = !1, I = !1, x = !1, q = !1, we = !1, dt;
6126
6156
  dt = Symbol.for("react.module.reference");
6127
6157
  function Lt(h) {
6128
- return !!(typeof h == "string" || typeof h == "function" || h === i || h === o || we || h === s || h === d || h === f || W || h === y || S || I || U || typeof h == "object" && h !== null && (h.$$typeof === p || h.$$typeof === l || h.$$typeof === a || h.$$typeof === u || h.$$typeof === c || // This needs to include all possible module reference object
6158
+ return !!(typeof h == "string" || typeof h == "function" || h === i || h === o || we || h === s || h === d || h === f || q || h === y || S || I || x || typeof h == "object" && h !== null && (h.$$typeof === p || h.$$typeof === l || h.$$typeof === a || h.$$typeof === u || h.$$typeof === c || // This needs to include all possible module reference object
6129
6159
  // types supported by any Flight configuration anywhere since
6130
6160
  // we don't know which Flight build this will end up being used
6131
6161
  // with.
@@ -6262,13 +6292,13 @@ function dc() {
6262
6292
  ` + Kt + h;
6263
6293
  }
6264
6294
  }
6265
- var Wt = !1, ht;
6295
+ var qt = !1, ht;
6266
6296
  {
6267
6297
  var es = typeof WeakMap == "function" ? WeakMap : Map;
6268
6298
  ht = new es();
6269
6299
  }
6270
6300
  function ir(h, _) {
6271
- if (!h || Wt)
6301
+ if (!h || qt)
6272
6302
  return "";
6273
6303
  {
6274
6304
  var v = ht.get(h);
@@ -6276,7 +6306,7 @@ function dc() {
6276
6306
  return v;
6277
6307
  }
6278
6308
  var O;
6279
- Wt = !0;
6309
+ qt = !0;
6280
6310
  var P = Error.prepareStackTrace;
6281
6311
  Error.prepareStackTrace = void 0;
6282
6312
  var M;
@@ -6317,23 +6347,23 @@ function dc() {
6317
6347
  if (Y && O && typeof Y.stack == "string") {
6318
6348
  for (var k = Y.stack.split(`
6319
6349
  `), B = O.stack.split(`
6320
- `), $ = k.length - 1, L = B.length - 1; $ >= 1 && L >= 0 && k[$] !== B[L]; )
6350
+ `), D = k.length - 1, L = B.length - 1; D >= 1 && L >= 0 && k[D] !== B[L]; )
6321
6351
  L--;
6322
- for (; $ >= 1 && L >= 0; $--, L--)
6323
- if (k[$] !== B[L]) {
6324
- if ($ !== 1 || L !== 1)
6352
+ for (; D >= 1 && L >= 0; D--, L--)
6353
+ if (k[D] !== B[L]) {
6354
+ if (D !== 1 || L !== 1)
6325
6355
  do
6326
- if ($--, L--, L < 0 || k[$] !== B[L]) {
6356
+ if (D--, L--, L < 0 || k[D] !== B[L]) {
6327
6357
  var re = `
6328
- ` + k[$].replace(" at new ", " at ");
6358
+ ` + k[D].replace(" at new ", " at ");
6329
6359
  return h.displayName && re.includes("<anonymous>") && (re = re.replace("<anonymous>", h.displayName)), typeof h == "function" && ht.set(h, re), re;
6330
6360
  }
6331
- while ($ >= 1 && L >= 0);
6361
+ while (D >= 1 && L >= 0);
6332
6362
  break;
6333
6363
  }
6334
6364
  }
6335
6365
  } finally {
6336
- Wt = !1, Nt.current = M, Xi(), Error.prepareStackTrace = P;
6366
+ qt = !1, Nt.current = M, Xi(), Error.prepareStackTrace = P;
6337
6367
  }
6338
6368
  var Me = h ? h.displayName || h.name : "", ve = Me ? lt(Me) : "";
6339
6369
  return typeof h == "function" && ht.set(h, ve), ve;
@@ -6394,15 +6424,15 @@ function dc() {
6394
6424
  throw B.name = "Invariant Violation", B;
6395
6425
  }
6396
6426
  k = h[C](_, C, O, v, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
6397
- } catch ($) {
6398
- k = $;
6427
+ } catch (D) {
6428
+ k = D;
6399
6429
  }
6400
6430
  k && !(k instanceof Error) && (yt(P), m("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", O || "React class", v, C, typeof k), yt(null)), k instanceof Error && !(k.message in sr) && (sr[k.message] = !0, yt(P), m("Failed %s type: %s", v, k.message), yt(null));
6401
6431
  }
6402
6432
  }
6403
6433
  }
6404
6434
  var is = Array.isArray;
6405
- function qt(h) {
6435
+ function Wt(h) {
6406
6436
  return is(h);
6407
6437
  }
6408
6438
  function ss(h) {
@@ -6508,9 +6538,9 @@ function dc() {
6508
6538
  for (M in _)
6509
6539
  Be.call(_, M) && !as.hasOwnProperty(M) && (C[M] = _[M]);
6510
6540
  if (h && h.defaultProps) {
6511
- var $ = h.defaultProps;
6512
- for (M in $)
6513
- C[M] === void 0 && (C[M] = $[M]);
6541
+ var D = h.defaultProps;
6542
+ for (M in D)
6543
+ C[M] === void 0 && (C[M] = D[M]);
6514
6544
  }
6515
6545
  if (k || B) {
6516
6546
  var L = typeof h == "function" ? h.displayName || h.name || "Unknown" : h;
@@ -6577,7 +6607,7 @@ Check the top-level render call using <` + v + ">.");
6577
6607
  {
6578
6608
  if (typeof h != "object")
6579
6609
  return;
6580
- if (qt(h))
6610
+ if (Wt(h))
6581
6611
  for (var v = 0; v < h.length; v++) {
6582
6612
  var O = h[v];
6583
6613
  Gt(O) && yr(O, _);
@@ -6638,8 +6668,8 @@ Check the top-level render call using <` + v + ">.");
6638
6668
  (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.");
6639
6669
  var B = ys();
6640
6670
  B ? k += B : k += hr();
6641
- var $;
6642
- h === null ? $ = "null" : qt(h) ? $ = "array" : h !== void 0 && h.$$typeof === n ? ($ = "<" + (ce(h.type) || "Unknown") + " />", k = " Did you accidentally export a JSX literal instead of a component?") : $ = 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", $, k);
6671
+ var D;
6672
+ 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);
6643
6673
  }
6644
6674
  var L = ps(h, _, v, P, M);
6645
6675
  if (L == null)
@@ -6648,7 +6678,7 @@ Check the top-level render call using <` + v + ">.");
6648
6678
  var re = _.children;
6649
6679
  if (re !== void 0)
6650
6680
  if (O)
6651
- if (qt(re)) {
6681
+ if (Wt(re)) {
6652
6682
  for (var Me = 0; Me < re.length; Me++)
6653
6683
  br(re[Me], h);
6654
6684
  Object.freeze && Object.freeze(re);
@@ -6684,10 +6714,10 @@ React keys must be passed directly to JSX without using spread:
6684
6714
  Ye.Fragment = i, Ye.jsx = ms, Ye.jsxs = vs;
6685
6715
  }(), Ye;
6686
6716
  }
6687
- var fc = {};
6688
- fc.NODE_ENV === "production" ? Sn.exports = cc() : Sn.exports = dc();
6717
+ var hc = {};
6718
+ hc.NODE_ENV === "production" ? Sn.exports = fc() : Sn.exports = lc();
6689
6719
  var z = Sn.exports;
6690
- const lc = {
6720
+ const pc = {
6691
6721
  isLoading: !0,
6692
6722
  data: void 0,
6693
6723
  pageInfo: void 0,
@@ -6696,9 +6726,9 @@ const lc = {
6696
6726
  function ti(t) {
6697
6727
  return Object.assign({ isLoading: !t, data: void 0, pageInfo: void 0, error: void 0 }, t || {});
6698
6728
  }
6699
- function hc(t, e, n) {
6729
+ function yc(t, e, n) {
6700
6730
  e && n && "ruleParams" in n && (e = Object.assign({ $$ruleParams: n.ruleParams }, e));
6701
- const r = e ? ic(e) : null, i = V(r), s = At(ti(t._reactor.getPreviousResult(r))), o = ge(
6731
+ const r = e ? oc(e) : null, i = V(r), s = At(ti(t._reactor.getPreviousResult(r))), o = ge(
6702
6732
  (u) => (s.current = ti(t._reactor.getPreviousResult(r)), r ? t.subscribeQuery(r, (d) => {
6703
6733
  s.current = Object.assign({ isLoading: !d, data: void 0, pageInfo: void 0, error: void 0 }, d), u();
6704
6734
  }) : () => {
@@ -6706,9 +6736,9 @@ function hc(t, e, n) {
6706
6736
  // Build a new subscribe function if the query changes
6707
6737
  [i]
6708
6738
  );
6709
- return { state: nn(o, () => s.current, () => lc), query: r };
6739
+ return { state: nn(o, () => s.current, () => pc), query: r };
6710
6740
  }
6711
- function pc() {
6741
+ function bc() {
6712
6742
  const t = At(null);
6713
6743
  je(() => {
6714
6744
  n();
@@ -6721,13 +6751,13 @@ function pc() {
6721
6751
  }
6722
6752
  return { set: e, clear: n };
6723
6753
  }
6724
- const yc = 1e3;
6725
- function bc(t, e, n) {
6754
+ const _c = 1e3;
6755
+ function gc(t, e, n) {
6726
6756
  je(() => t.core._reactor.subscribeTopic(t.id, e, (i, s) => {
6727
6757
  n(i, s);
6728
6758
  }), [t.id, e]);
6729
6759
  }
6730
- function _c(t, e) {
6760
+ function Tc(t, e) {
6731
6761
  return je(() => t.core._reactor.joinRoom(t.id), [t.id]), ge((r) => {
6732
6762
  t.core._reactor.publishTopic({
6733
6763
  roomType: t.type,
@@ -6737,7 +6767,7 @@ function _c(t, e) {
6737
6767
  });
6738
6768
  }, [t.id, e]);
6739
6769
  }
6740
- function gc(t, e = {}) {
6770
+ function wc(t, e = {}) {
6741
6771
  var n, r;
6742
6772
  const [i, s] = ui(() => {
6743
6773
  var u;
@@ -6754,11 +6784,11 @@ function gc(t, e = {}) {
6754
6784
  }, [t.type, t.id]);
6755
6785
  return rn(() => Object.assign(Object.assign({}, i), { publishPresence: o }), [i, o]);
6756
6786
  }
6757
- function Tc(t, e, n) {
6787
+ function mc(t, e, n) {
6758
6788
  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)]);
6759
6789
  }
6760
- function wc(t, e, n = {}) {
6761
- const r = pc(), i = Oe.usePresence(t, {
6790
+ function vc(t, e, n = {}) {
6791
+ const r = bc(), i = Oe.usePresence(t, {
6762
6792
  keys: [e]
6763
6793
  }), s = rn(() => {
6764
6794
  var d;
@@ -6768,7 +6798,7 @@ function wc(t, e, n = {}) {
6768
6798
  var f;
6769
6799
  t.core._reactor.publishPresence(t.type, t.id, {
6770
6800
  [e]: d
6771
- }), 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 : yc, () => {
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, () => {
6772
6802
  t.core._reactor.publishPresence(t.type, t.id, {
6773
6803
  [e]: null
6774
6804
  });
@@ -6786,20 +6816,20 @@ function wc(t, e, n = {}) {
6786
6816
  };
6787
6817
  }
6788
6818
  const Oe = {
6789
- useTopicEffect: bc,
6790
- usePublishTopic: _c,
6791
- usePresence: gc,
6792
- useSyncPresence: Tc,
6793
- useTypingIndicator: wc
6819
+ useTopicEffect: gc,
6820
+ usePublishTopic: Tc,
6821
+ usePresence: wc,
6822
+ useSyncPresence: mc,
6823
+ useTypingIndicator: vc
6794
6824
  };
6795
- class mc {
6825
+ class Sc {
6796
6826
  constructor(e, n, r) {
6797
6827
  this.useTopicEffect = (i, s) => {
6798
6828
  Oe.useTopicEffect(this, i, s);
6799
6829
  }, 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;
6800
6830
  }
6801
6831
  }
6802
- var vc = function(t, e, n, r) {
6832
+ var Oc = function(t, e, n, r) {
6803
6833
  function i(s) {
6804
6834
  return s instanceof n ? s : new n(function(o) {
6805
6835
  o(s);
@@ -6826,30 +6856,30 @@ var vc = function(t, e, n, r) {
6826
6856
  c((r = r.apply(t, e || [])).next());
6827
6857
  });
6828
6858
  };
6829
- const Sc = {
6859
+ const Ec = {
6830
6860
  isLoading: !0,
6831
6861
  user: void 0,
6832
6862
  error: void 0
6833
6863
  };
6834
- class Oc {
6864
+ class Ac {
6835
6865
  constructor(e, n) {
6836
6866
  this.tx = Vn(), this.getLocalId = (r) => this.core.getLocalId(r), this.useLocalId = (r) => {
6837
6867
  const [i, s] = ui(null);
6838
6868
  return je(() => {
6839
- vc(this, void 0, void 0, function* () {
6869
+ Oc(this, void 0, void 0, function* () {
6840
6870
  const a = yield this.getLocalId(r);
6841
6871
  s(a);
6842
6872
  });
6843
6873
  }, [r]), i;
6844
- }, this.rooms = Oe, this.transact = (r) => this.core.transact(r), this.useQuery = (r, i) => hc(this.core, r, i).state, this.useAuth = () => {
6874
+ }, this.rooms = Oe, this.transact = (r) => this.core.transact(r), this.useQuery = (r, i) => yc(this.core, r, i).state, this.useAuth = () => {
6845
6875
  const r = At(this.core._reactor._currentUserCached), i = ge((o) => this.core.subscribeAuth((u) => {
6846
6876
  r.current = Object.assign({ isLoading: !1 }, u), o();
6847
6877
  }), []);
6848
- return nn(i, () => r.current, () => Sc);
6878
+ return nn(i, () => r.current, () => Ec);
6849
6879
  }, this.useUser = () => {
6850
6880
  const { user: r } = this.useAuth();
6851
6881
  if (!r)
6852
- throw new We("useUser must be used within an auth-protected route");
6882
+ throw new qe("useUser must be used within an auth-protected route");
6853
6883
  return r;
6854
6884
  }, this.useConnectionStatus = () => {
6855
6885
  const r = At(this.core._reactor.status), i = ge((o) => this.core.subscribeConnectionStatus((u) => {
@@ -6867,7 +6897,7 @@ class Oc {
6867
6897
  }, this.SignedOut = ({ children: r }) => {
6868
6898
  const i = this.useAuth();
6869
6899
  return i.isLoading || i.error || i.user ? null : z.jsx(z.Fragment, { children: r });
6870
- }, this.core = ac(
6900
+ }, this.core = cc(
6871
6901
  e,
6872
6902
  // @ts-expect-error because TS can't resolve subclass statics
6873
6903
  this.constructor.Storage,
@@ -6891,7 +6921,7 @@ class Oc {
6891
6921
  * const { peers } = db.rooms.usePresence(room);
6892
6922
  */
6893
6923
  room(e = "_defaultRoomType", n = "_defaultRoomId") {
6894
- return new mc(this.core, e, n);
6924
+ return new Sc(this.core, e, n);
6895
6925
  }
6896
6926
  /**
6897
6927
  * One time query for the logged in state. This is useful
@@ -6914,7 +6944,7 @@ class ni extends Error {
6914
6944
  }
6915
6945
  function tn(t) {
6916
6946
  }
6917
- function Ec(t) {
6947
+ function kc(t) {
6918
6948
  if (typeof t == "function")
6919
6949
  throw new TypeError(
6920
6950
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
@@ -6922,7 +6952,7 @@ function Ec(t) {
6922
6952
  const { onEvent: e = tn, onError: n = tn, onRetry: r = tn, onComment: i } = t;
6923
6953
  let s = "", o = !0, a, u = "", c = "";
6924
6954
  function d(b) {
6925
- const g = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [w, T] = Ac(`${s}${g}`);
6955
+ const g = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [w, T] = jc(`${s}${g}`);
6926
6956
  for (const m of w)
6927
6957
  f(m);
6928
6958
  s = T, o = !1;
@@ -6990,7 +7020,7 @@ function Ec(t) {
6990
7020
  }
6991
7021
  return { feed: d, reset: y };
6992
7022
  }
6993
- function Ac(t) {
7023
+ function jc(t) {
6994
7024
  const e = [];
6995
7025
  let n = "", r = 0;
6996
7026
  for (; r < t.length; ) {
@@ -7050,7 +7080,7 @@ class ri extends Event {
7050
7080
  return e(ii(this), n);
7051
7081
  }
7052
7082
  }
7053
- function kc(t) {
7083
+ function Cc(t) {
7054
7084
  const e = globalThis.DOMException;
7055
7085
  return typeof e == "function" ? new e(t, "SyntaxError") : new SyntaxError(t);
7056
7086
  }
@@ -7069,7 +7099,7 @@ function ii(t) {
7069
7099
  }
7070
7100
  var Ji = (t) => {
7071
7101
  throw TypeError(t);
7072
- }, 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), x = (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;
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;
7073
7103
  class Et extends EventTarget {
7074
7104
  constructor(e, n) {
7075
7105
  var r, i;
@@ -7081,7 +7111,7 @@ class Et extends EventTarget {
7081
7111
  he(this, se, tt).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
7082
7112
  return;
7083
7113
  }
7084
- if (u ? x(this, xe, new URL(s.url)) : x(this, xe, void 0), c !== 200) {
7114
+ if (u ? $(this, xe, new URL(s.url)) : $(this, xe, void 0), c !== 200) {
7085
7115
  he(this, se, tt).call(this, `Non-200 status code (${c})`, c);
7086
7116
  return;
7087
7117
  }
@@ -7091,7 +7121,7 @@ class Et extends EventTarget {
7091
7121
  }
7092
7122
  if (A(this, J) === this.CLOSED)
7093
7123
  return;
7094
- x(this, J, this.OPEN);
7124
+ $(this, J, this.OPEN);
7095
7125
  const f = new Event("open");
7096
7126
  if ((o = A(this, et)) == null || o.call(this, f), this.dispatchEvent(f), typeof a != "object" || !a || !("getReader" in a)) {
7097
7127
  he(this, se, tt).call(this, "Invalid response body, expected a web ReadableStream", c), this.close();
@@ -7104,9 +7134,9 @@ class Et extends EventTarget {
7104
7134
  g && A(this, $e).feed(l.decode(g, { stream: !b })), b && (y = !1, A(this, $e).reset(), he(this, se, Pn).call(this));
7105
7135
  } while (y);
7106
7136
  }), N(this, kn, (s) => {
7107
- x(this, _e, void 0), !(s.name === "AbortError" || s.type === "aborted") && he(this, se, Pn).call(this, On(s));
7137
+ $(this, _e, void 0), !(s.name === "AbortError" || s.type === "aborted") && he(this, se, Pn).call(this, On(s));
7108
7138
  }), N(this, jn, (s) => {
7109
- typeof s.id == "string" && x(this, st, s.id);
7139
+ typeof s.id == "string" && $(this, st, s.id);
7110
7140
  const o = new MessageEvent(s.event || "message", {
7111
7141
  data: s.data,
7112
7142
  origin: A(this, xe) ? A(this, xe).origin : A(this, Ee).origin,
@@ -7114,24 +7144,24 @@ class Et extends EventTarget {
7114
7144
  });
7115
7145
  A(this, De) && (!s.event || s.event === "message") && A(this, De).call(this, o), this.dispatchEvent(o);
7116
7146
  }), N(this, Cn, (s) => {
7117
- x(this, it, s);
7147
+ $(this, it, s);
7118
7148
  }), N(this, In, () => {
7119
- x(this, Ue, void 0), A(this, J) === this.CONNECTING && he(this, se, En).call(this);
7149
+ $(this, Ue, void 0), A(this, J) === this.CONNECTING && he(this, se, En).call(this);
7120
7150
  });
7121
7151
  try {
7122
7152
  if (e instanceof URL)
7123
- x(this, Ee, e);
7153
+ $(this, Ee, e);
7124
7154
  else if (typeof e == "string")
7125
- x(this, Ee, new URL(e, jc()));
7155
+ $(this, Ee, new URL(e, Pc()));
7126
7156
  else
7127
7157
  throw new Error("Invalid URL");
7128
7158
  } catch {
7129
- throw kc("An invalid or illegal string was specified");
7159
+ throw Cc("An invalid or illegal string was specified");
7130
7160
  }
7131
- x(this, $e, Ec({
7161
+ $(this, $e, kc({
7132
7162
  onEvent: A(this, jn),
7133
7163
  onRetry: A(this, Cn)
7134
- })), x(this, J, this.CONNECTING), x(this, it, 3e3), x(this, Mt, (r = n == null ? void 0 : n.fetch) != null ? r : globalThis.fetch), x(this, Ot, (i = n == null ? void 0 : n.withCredentials) != null ? i : !1), he(this, se, En).call(this);
7164
+ })), $(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);
7135
7165
  }
7136
7166
  /**
7137
7167
  * Returns the state of this EventSource object's connection. It can have the values described below.
@@ -7169,21 +7199,21 @@ class Et extends EventTarget {
7169
7199
  return A(this, Fe);
7170
7200
  }
7171
7201
  set onerror(e) {
7172
- x(this, Fe, e);
7202
+ $(this, Fe, e);
7173
7203
  }
7174
7204
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
7175
7205
  get onmessage() {
7176
7206
  return A(this, De);
7177
7207
  }
7178
7208
  set onmessage(e) {
7179
- x(this, De, e);
7209
+ $(this, De, e);
7180
7210
  }
7181
7211
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
7182
7212
  get onopen() {
7183
7213
  return A(this, et);
7184
7214
  }
7185
7215
  set onopen(e) {
7186
- x(this, et, e);
7216
+ $(this, et, e);
7187
7217
  }
7188
7218
  addEventListener(e, n, r) {
7189
7219
  const i = n;
@@ -7201,7 +7231,7 @@ class Et extends EventTarget {
7201
7231
  * @public
7202
7232
  */
7203
7233
  close() {
7204
- A(this, Ue) && clearTimeout(A(this, Ue)), A(this, J) !== this.CLOSED && (A(this, _e) && A(this, _e).abort(), x(this, J, this.CLOSED), x(this, _e, void 0));
7234
+ A(this, Ue) && clearTimeout(A(this, Ue)), A(this, J) !== this.CLOSED && (A(this, _e) && A(this, _e).abort(), $(this, J, this.CLOSED), $(this, _e, void 0));
7205
7235
  }
7206
7236
  }
7207
7237
  J = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), xe = /* @__PURE__ */ new WeakMap(), Ot = /* @__PURE__ */ new WeakMap(), Mt = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap(), Ue = /* @__PURE__ */ new WeakMap(), st = /* @__PURE__ */ new WeakMap(), _e = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), Fe = /* @__PURE__ */ new WeakMap(), De = /* @__PURE__ */ new WeakMap(), et = /* @__PURE__ */ new WeakMap(), se = /* @__PURE__ */ new WeakSet(), /**
@@ -7210,7 +7240,7 @@ J = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), xe = /* @
7210
7240
  * @internal
7211
7241
  */
7212
7242
  En = function() {
7213
- x(this, J, this.CONNECTING), x(this, _e, new AbortController()), A(this, Mt)(A(this, Ee), he(this, se, si).call(this)).then(A(this, An)).catch(A(this, kn));
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));
7214
7244
  }, An = /* @__PURE__ */ new WeakMap(), kn = /* @__PURE__ */ new WeakMap(), /**
7215
7245
  * Get request options for the `fetch()` request
7216
7246
  *
@@ -7238,7 +7268,7 @@ si = function() {
7238
7268
  */
7239
7269
  tt = function(t, e) {
7240
7270
  var n;
7241
- A(this, J) !== this.CLOSED && x(this, J, this.CLOSED);
7271
+ A(this, J) !== this.CLOSED && $(this, J, this.CLOSED);
7242
7272
  const r = new ri("error", { code: e, message: t });
7243
7273
  (n = A(this, Fe)) == null || n.call(this, r), this.dispatchEvent(r);
7244
7274
  }, /**
@@ -7252,9 +7282,9 @@ Pn = function(t, e) {
7252
7282
  var n;
7253
7283
  if (A(this, J) === this.CLOSED)
7254
7284
  return;
7255
- x(this, J, this.CONNECTING);
7285
+ $(this, J, this.CONNECTING);
7256
7286
  const r = new ri("error", { code: e, message: t });
7257
- (n = A(this, Fe)) == null || n.call(this, r), this.dispatchEvent(r), x(this, Ue, setTimeout(A(this, In), A(this, it)));
7287
+ (n = A(this, Fe)) == null || n.call(this, r), this.dispatchEvent(r), $(this, Ue, setTimeout(A(this, In), A(this, it)));
7258
7288
  }, In = /* @__PURE__ */ new WeakMap(), /**
7259
7289
  * ReadyState representing an EventSource currently trying to connect
7260
7290
  *
@@ -7271,15 +7301,15 @@ Et.OPEN = 1, /**
7271
7301
  * @public
7272
7302
  */
7273
7303
  Et.CLOSED = 2;
7274
- function jc() {
7304
+ function Pc() {
7275
7305
  const t = "document" in globalThis ? globalThis.document : void 0;
7276
7306
  return t && typeof t == "object" && "baseURI" in t && typeof t.baseURI == "string" ? t.baseURI : void 0;
7277
7307
  }
7278
- const Hn = class Hn extends Oc {
7308
+ const Hn = class Hn extends Ac {
7279
7309
  };
7280
7310
  Hn.EventSourceImpl = Et;
7281
7311
  let Mn = Hn;
7282
- function Cc(t) {
7312
+ function Ic(t) {
7283
7313
  return new Mn(
7284
7314
  t,
7285
7315
  {
@@ -7287,8 +7317,8 @@ function Cc(t) {
7287
7317
  }
7288
7318
  );
7289
7319
  }
7290
- const Uc = Cc;
7291
- function Lc({
7320
+ const Fc = Ic;
7321
+ function Nc({
7292
7322
  as: t = "div",
7293
7323
  spaceId: e,
7294
7324
  room: n,
@@ -7304,13 +7334,13 @@ function Lc({
7304
7334
  keys: [d]
7305
7335
  }), l = n._core._reactor.getPresence(n.type, n.id);
7306
7336
  function p(T, m) {
7307
- const E = m.clientX, S = m.clientY, I = (E - T.left) / T.width * 100, U = (S - T.top) / T.height * 100;
7337
+ const E = m.clientX, S = m.clientY, I = (E - T.left) / T.width * 100, x = (S - T.top) / T.height * 100;
7308
7338
  f.publishPresence({
7309
7339
  [d]: {
7310
7340
  x: E,
7311
7341
  y: S,
7312
7342
  xPercent: I,
7313
- yPercent: U,
7343
+ yPercent: x,
7314
7344
  color: s
7315
7345
  }
7316
7346
  });
@@ -7360,8 +7390,8 @@ function Lc({
7360
7390
  {
7361
7391
  style: {
7362
7392
  ...oi,
7363
- ...Ic,
7364
- zIndex: c !== void 0 ? c : Mc
7393
+ ...Rc,
7394
+ zIndex: c !== void 0 ? c : xc
7365
7395
  },
7366
7396
  children: Object.entries(f.peers).map(([T, m]) => {
7367
7397
  const E = m[d];
@@ -7377,7 +7407,7 @@ function Lc({
7377
7407
  children: a ? a({
7378
7408
  color: E.color,
7379
7409
  presence: l.peers[T]
7380
- }) : /* @__PURE__ */ z.jsx(Pc, { ...E })
7410
+ }) : /* @__PURE__ */ z.jsx(Mc, { ...E })
7381
7411
  },
7382
7412
  T
7383
7413
  ) : null;
@@ -7388,7 +7418,7 @@ function Lc({
7388
7418
  ]
7389
7419
  );
7390
7420
  }
7391
- function Pc({ color: t }) {
7421
+ function Mc({ color: t }) {
7392
7422
  const n = t || "black";
7393
7423
  return /* @__PURE__ */ z.jsxs(
7394
7424
  "svg",
@@ -7441,21 +7471,21 @@ const oi = {
7441
7471
  left: 0,
7442
7472
  bottom: 0,
7443
7473
  right: 0
7444
- }, Ic = {
7474
+ }, Rc = {
7445
7475
  overflow: "hidden",
7446
7476
  pointerEvents: "none",
7447
7477
  userSelect: "none"
7448
- }, Mc = 99999;
7478
+ }, xc = 99999;
7449
7479
  export {
7450
- Lc as Cursors,
7480
+ Nc as Cursors,
7451
7481
  $t as InstantAPIError,
7452
- Oc as InstantReactAbstractDatabase,
7482
+ Ac as InstantReactAbstractDatabase,
7453
7483
  Mn as InstantReactWebDatabase,
7454
7484
  Se as SyncTableCallbackEventType,
7455
- Dc as i,
7485
+ Lc as i,
7456
7486
  K as id,
7457
- Cc as init,
7458
- Uc as init_experimental,
7459
- xc as lookup,
7460
- $c as tx
7487
+ Ic as init,
7488
+ Fc as init_experimental,
7489
+ Dc as lookup,
7490
+ Uc as tx
7461
7491
  };