@instantdb/react-common 0.22.144 → 0.22.145-experimental.tab-login.22423317259.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.
@@ -2,7 +2,7 @@ var Ms = Object.defineProperty;
2
2
  var Rs = (n, e, t) => e in n ? Ms(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var h = (n, e, t) => Rs(n, typeof e != "symbol" ? e + "" : e, t);
4
4
  import gr, { useRef as Xe, useCallback as Se, useSyncExternalStore as Kt, useEffect as Pe, useMemo as qt, useState as mr } from "react";
5
- var Wt = { exports: {} }, We = {};
5
+ var Wt = { exports: {} }, ze = {};
6
6
  /**
7
7
  * @license React
8
8
  * react-jsx-runtime.production.min.js
@@ -14,7 +14,7 @@ var Wt = { exports: {} }, We = {};
14
14
  */
15
15
  var xn;
16
16
  function js() {
17
- if (xn) return We;
17
+ if (xn) return ze;
18
18
  xn = 1;
19
19
  var n = gr, e = Symbol.for("react.element"), t = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, s = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = { key: !0, ref: !0, __self: !0, __source: !0 };
20
20
  function o(a, c, u) {
@@ -24,11 +24,11 @@ function js() {
24
24
  if (a && a.defaultProps) for (l in c = a.defaultProps, c) f[l] === void 0 && (f[l] = c[l]);
25
25
  return { $$typeof: e, type: a, key: p, ref: y, props: f, _owner: s.current };
26
26
  }
27
- return We.Fragment = t, We.jsx = o, We.jsxs = o, We;
27
+ return ze.Fragment = t, ze.jsx = o, ze.jsxs = o, ze;
28
28
  }
29
- var ze = {}, Un;
29
+ var Ve = {}, Un;
30
30
  function Ds() {
31
- if (Un) return ze;
31
+ if (Un) return Ve;
32
32
  Un = 1;
33
33
  var n = {};
34
34
  /**
@@ -134,7 +134,7 @@ function Ds() {
134
134
  function ae() {
135
135
  }
136
136
  ae.__reactDisabledLog = !0;
137
- function Ke() {
137
+ function qe() {
138
138
  {
139
139
  if (be === 0) {
140
140
  ve = console.log, At = console.info, O = console.warn, I = console.error, V = console.group, Q = console.groupCollapsed, ee = console.groupEnd;
@@ -224,7 +224,7 @@ function Ds() {
224
224
  var j = Error.prepareStackTrace;
225
225
  Error.prepareStackTrace = void 0;
226
226
  var $;
227
- $ = Ot.current, Ot.current = null, Ke();
227
+ $ = Ot.current, Ot.current = null, qe();
228
228
  try {
229
229
  if (m) {
230
230
  var R = function() {
@@ -318,7 +318,7 @@ function Ds() {
318
318
  }
319
319
  return "";
320
320
  }
321
- var qe = Object.prototype.hasOwnProperty, Sn = {}, vn = _.ReactDebugCurrentFrame;
321
+ var We = Object.prototype.hasOwnProperty, Sn = {}, vn = _.ReactDebugCurrentFrame;
322
322
  function ot(d) {
323
323
  if (d) {
324
324
  var m = d._owner, A = it(d.type, d._source, m ? m.type : null);
@@ -328,7 +328,7 @@ function Ds() {
328
328
  }
329
329
  function us(d, m, A, E, j) {
330
330
  {
331
- var $ = Function.call.bind(qe);
331
+ var $ = Function.call.bind(We);
332
332
  for (var R in d)
333
333
  if ($(d, R)) {
334
334
  var P = void 0;
@@ -376,7 +376,7 @@ function Ds() {
376
376
  __source: !0
377
377
  }, kn, Cn;
378
378
  function ps(d) {
379
- if (qe.call(d, "ref")) {
379
+ if (We.call(d, "ref")) {
380
380
  var m = Object.getOwnPropertyDescriptor(d, "ref").get;
381
381
  if (m && m.isReactWarning)
382
382
  return !1;
@@ -384,7 +384,7 @@ function Ds() {
384
384
  return d.ref !== void 0;
385
385
  }
386
386
  function ys(d) {
387
- if (qe.call(d, "key")) {
387
+ if (We.call(d, "key")) {
388
388
  var m = Object.getOwnPropertyDescriptor(d, "key").get;
389
389
  if (m && m.isReactWarning)
390
390
  return !1;
@@ -450,7 +450,7 @@ function Ds() {
450
450
  var $, R = {}, P = null, J = null;
451
451
  A !== void 0 && (On(A), P = "" + A), ys(m) && (On(m.key), P = "" + m.key), ps(m) && (J = m.ref, bs(m, j));
452
452
  for ($ in m)
453
- qe.call(m, $) && !hs.hasOwnProperty($) && (R[$] = m[$]);
453
+ We.call(m, $) && !hs.hasOwnProperty($) && (R[$] = m[$]);
454
454
  if (d && d.defaultProps) {
455
455
  var K = d.defaultProps;
456
456
  for ($ in K)
@@ -601,7 +601,7 @@ Check the top-level render call using <` + A + ">.");
601
601
  else
602
602
  jn(ce, d);
603
603
  }
604
- if (qe.call(m, "key")) {
604
+ if (We.call(m, "key")) {
605
605
  var Oe = U(d), te = Object.keys(m).filter(function(Ps) {
606
606
  return Ps !== "key";
607
607
  }), Rt = te.length > 0 ? "{key: someKey, " + te.join(": ..., ") + ": ...}" : "{key: someKey}";
@@ -625,8 +625,8 @@ React keys must be passed directly to JSX without using spread:
625
625
  return $n(d, m, A, !1);
626
626
  }
627
627
  var ks = Es, Cs = Os;
628
- ze.Fragment = s, ze.jsx = ks, ze.jsxs = Cs;
629
- }(), ze;
628
+ Ve.Fragment = s, Ve.jsx = ks, Ve.jsxs = Cs;
629
+ }(), Ve;
630
630
  }
631
631
  var $s = {};
632
632
  $s.NODE_ENV === "production" ? Wt.exports = js() : Wt.exports = Ds();
@@ -867,7 +867,7 @@ function ge(n) {
867
867
  function Fn() {
868
868
  throw new Error("Cannot modify frozen object");
869
869
  }
870
- function xe(n, e, t, r, s) {
870
+ function Ue(n, e, t, r, s) {
871
871
  {
872
872
  t = t ?? /* @__PURE__ */ new WeakMap(), r = r ?? [], s = s ?? [];
873
873
  const o = t.has(n) ? t.get(n) : n;
@@ -891,24 +891,24 @@ function xe(n, e, t, r, s) {
891
891
  switch (Re(n)) {
892
892
  case 2:
893
893
  for (const [a, c] of n)
894
- xe(a, a, t, r, s), xe(c, a, t, r, s);
894
+ Ue(a, a, t, r, s), Ue(c, a, t, r, s);
895
895
  n.set = n.clear = n.delete = Fn;
896
896
  break;
897
897
  case 3:
898
898
  for (const a of n)
899
- xe(a, a, t, r, s);
899
+ Ue(a, a, t, r, s);
900
900
  n.add = n.clear = n.delete = Fn;
901
901
  break;
902
902
  case 1:
903
903
  Object.freeze(n);
904
904
  let o = 0;
905
905
  for (const a of n)
906
- xe(a, o, t, r, s), o += 1;
906
+ Ue(a, o, t, r, s), o += 1;
907
907
  break;
908
908
  default:
909
909
  Object.freeze(n), Object.keys(n).forEach((a) => {
910
910
  const c = n[a];
911
- xe(c, a, t, r, s);
911
+ Ue(c, a, t, r, s);
912
912
  });
913
913
  }
914
914
  r.pop(), s.pop();
@@ -1414,7 +1414,7 @@ function Bs(n, e, t, r, s) {
1414
1414
  for (; o.finalities.draft.length > 0; )
1415
1415
  o.finalities.draft.pop()(t, r);
1416
1416
  const u = c ? e[0] : o ? o.operated ? o.copy : o.original : n;
1417
- return o && zt(o), s && xe(u, u, o == null ? void 0 : o.options.updatedValues), [
1417
+ return o && zt(o), s && Ue(u, u, o == null ? void 0 : o.options.updatedValues), [
1418
1418
  u,
1419
1419
  t && c ? [{ op: q.Replace, path: [], value: e[0] }] : t,
1420
1420
  r && c ? [{ op: q.Replace, path: [], value: a }] : r
@@ -2047,7 +2047,7 @@ function bn(n) {
2047
2047
  function _n(n) {
2048
2048
  return n["value-type"] === "blob";
2049
2049
  }
2050
- function Ne(n, e) {
2050
+ function Ke(n, e) {
2051
2051
  return e.reduce((t, r) => t && t.get(r), n);
2052
2052
  }
2053
2053
  function de(n, e) {
@@ -2101,7 +2101,7 @@ function jr(n, e) {
2101
2101
  return new Ie(e.attrs, e.linkIndex);
2102
2102
  }
2103
2103
  function yi(n, e) {
2104
- return Ne(n.eav, [e]) !== void 0;
2104
+ return Ke(n.eav, [e]) !== void 0;
2105
2105
  }
2106
2106
  function Ge(n, e, t, r) {
2107
2107
  const s = Pr(n, e, r);
@@ -2145,7 +2145,7 @@ let bi = 0;
2145
2145
  function $r(n, e, t) {
2146
2146
  const [r, s, i] = t;
2147
2147
  let o;
2148
- const a = Ne(n.eav, [r, s, i]);
2148
+ const a = Ke(n.eav, [r, s, i]);
2149
2149
  return a && (o = a[3]), o || Date.now() * 10 + bi++;
2150
2150
  }
2151
2151
  function xr(n, e, t) {
@@ -2157,7 +2157,7 @@ function xr(n, e, t) {
2157
2157
  if (!a)
2158
2158
  return;
2159
2159
  a["checked-data-type"] === "date" && n.useDateObjects && (o = Tt(o));
2160
- const c = Ne(n.eav, [s, i, o]), u = (c == null ? void 0 : c[3]) ?? $r(n, a, r), l = [s, i, o, u];
2160
+ const c = Ke(n.eav, [s, i, o]), u = (c == null ? void 0 : c[3]) ?? $r(n, a, r), l = [s, i, o, u];
2161
2161
  pi(a) ? (ne(n.eav, [s, i], /* @__PURE__ */ new Map([[o, l]])), ne(n.aev, [i, s], /* @__PURE__ */ new Map([[o, l]]))) : (ne(n.eav, [s, i, o], l), ne(n.aev, [i, s, o], l)), bn(a) && ne(n.vae, [o, i, s], l);
2162
2162
  }
2163
2163
  function _i(n, e, t) {
@@ -2170,7 +2170,7 @@ function _i(n, e, t) {
2170
2170
  return;
2171
2171
  if (!_n(a))
2172
2172
  throw new Error("merge operation is not supported for links");
2173
- const c = Ne(n.eav, [s, i]);
2173
+ const c = Ke(n.eav, [s, i]);
2174
2174
  if (!c)
2175
2175
  return;
2176
2176
  const u = (y = c.values().next()) == null ? void 0 : y.value;
@@ -2395,7 +2395,7 @@ function Ei(n, e, t) {
2395
2395
  return;
2396
2396
  const [s, i, o] = r;
2397
2397
  if (e.getAttr(i))
2398
- return Ne(n.eav, [s, i]);
2398
+ return Ke(n.eav, [s, i]);
2399
2399
  }
2400
2400
  function ki(n, e, t) {
2401
2401
  const r = t.filter(([s, i, o, a, c]) => {
@@ -2490,7 +2490,7 @@ function Ui(n, e, t) {
2490
2490
  return vi(n, gn(t, e));
2491
2491
  }
2492
2492
  const Li = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
2493
- function Le(n) {
2493
+ function Fe(n) {
2494
2494
  return typeof n == "string" && Li.test(n);
2495
2495
  }
2496
2496
  const G = [];
@@ -2561,7 +2561,7 @@ function Ye(n) {
2561
2561
  function St(n, e) {
2562
2562
  return `?${n}-${e}`;
2563
2563
  }
2564
- class Fe extends Error {
2564
+ class Ne extends Error {
2565
2565
  constructor(e) {
2566
2566
  super(e), this.name = "AttrNotFoundError";
2567
2567
  }
@@ -2569,7 +2569,7 @@ class Fe extends Error {
2569
2569
  function Yi(n, e) {
2570
2570
  const t = Fr(n, e);
2571
2571
  if (!t)
2572
- throw new Fe(`Could not find id attr for ${e}`);
2572
+ throw new Ne(`Could not find id attr for ${e}`);
2573
2573
  return t;
2574
2574
  }
2575
2575
  function Gn(n, e, t, r) {
@@ -2589,7 +2589,7 @@ function Xi(n, e, t) {
2589
2589
  function Kr(n, e, t, r, s) {
2590
2590
  const i = z(e, t, s), o = je(e, t, s), a = i || o;
2591
2591
  if (!a)
2592
- throw new Fe(`Could not find attr for ${[t, s]}`);
2592
+ throw new Ne(`Could not find attr for ${[t, s]}`);
2593
2593
  if (a["value-type"] !== "ref")
2594
2594
  throw new Error(`Attr ${a.id} is not a ref`);
2595
2595
  const [c, u] = a["forward-identity"], [l, f] = a["reverse-identity"], p = r + 1, y = i ? [
@@ -2678,11 +2678,11 @@ function eo(n, e) {
2678
2678
  function to(n, e, t, r, s, i) {
2679
2679
  const o = z(e, t, s), a = je(e, t, s), c = o || a;
2680
2680
  if (!c)
2681
- throw new Fe(`No attr for etype = ${t} label = ${s}`);
2681
+ throw new Ne(`No attr for etype = ${t} label = ${s}`);
2682
2682
  if (i != null && i.hasOwnProperty("$isNull")) {
2683
2683
  const u = z(e, t, "id");
2684
2684
  if (!u)
2685
- throw new Fe(`No attr for etype = ${t} label = id`);
2685
+ throw new Ne(`No attr for etype = ${t} label = id`);
2686
2686
  return [
2687
2687
  n(t, r),
2688
2688
  u.id,
@@ -2797,7 +2797,7 @@ function fo(n, e, t, { etype: r, level: s, form: i }, o) {
2797
2797
  }), k = b ? v[0] : v;
2798
2798
  return { [y]: k };
2799
2799
  } catch (_) {
2800
- if (_ instanceof Fe)
2800
+ if (_ instanceof Ne)
2801
2801
  return { [y]: b ? void 0 : [] };
2802
2802
  throw _;
2803
2803
  }
@@ -2915,7 +2915,7 @@ function So(n, e, t) {
2915
2915
  try {
2916
2916
  return To(n, e, t);
2917
2917
  } catch (r) {
2918
- if (r instanceof Fe)
2918
+ if (r instanceof Ne)
2919
2919
  return {};
2920
2920
  throw r;
2921
2921
  }
@@ -4110,7 +4110,7 @@ function or(n) {
4110
4110
  }, e;
4111
4111
  }, {});
4112
4112
  }
4113
- const Xr = "v0.22.144";
4113
+ const Xr = "v0.22.145-experimental.tab-login.22423317259.1";
4114
4114
  function Ta(n, e) {
4115
4115
  return {
4116
4116
  info: n ? (...t) => console.info(...t, e()) : () => {
@@ -4218,7 +4218,7 @@ const ar = [
4218
4218
  default:
4219
4219
  throw new L(`Unknown operator '${n}' for attribute '${r}' in entity '${s}'`, o);
4220
4220
  }
4221
- }, Ue = (n, e, t, r, s) => {
4221
+ }, Le = (n, e, t, r, s) => {
4222
4222
  const i = Sa(t), o = t.valueType === "json";
4223
4223
  if (typeof n == "object" && n !== null && !Array.isArray(n)) {
4224
4224
  if (o)
@@ -4248,23 +4248,23 @@ const ar = [
4248
4248
  if (!c)
4249
4249
  throw new L(`Target entity '${o}' does not exist in schema for dot notation path '${n}'.`, s);
4250
4250
  if (a === "id") {
4251
- if (typeof e == "string" && !Le(e))
4251
+ if (typeof e == "string" && !Fe(e))
4252
4252
  throw new L(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${e}`, s);
4253
- Ue(e, n, new me("string", !1, !0), t, s);
4253
+ Le(e, n, new me("string", !1, !0), t, s);
4254
4254
  return;
4255
4255
  }
4256
4256
  const u = c.attrs[a];
4257
4257
  if (Object.keys(c.links).includes(a)) {
4258
- if (typeof e == "string" && !Le(e))
4258
+ if (typeof e == "string" && !Fe(e))
4259
4259
  throw new L(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${e}`, s);
4260
- Ue(e, n, new me("string", !1, !0), t, s);
4260
+ Le(e, n, new me("string", !1, !0), t, s);
4261
4261
  return;
4262
4262
  }
4263
4263
  if (!u) {
4264
4264
  const l = Object.keys(c.attrs);
4265
4265
  throw new L(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${n}'. Available attributes: ${l.length > 0 ? l.join(", ") + ", id" : "id"}`, s);
4266
4266
  }
4267
- Ue(e, n, u, t, s);
4267
+ Le(e, n, u, t, s);
4268
4268
  }, ts = (n, e, t, r) => {
4269
4269
  for (const [s, i] of Object.entries(n)) {
4270
4270
  if (s === "or" || s === "and") {
@@ -4274,7 +4274,7 @@ const ar = [
4274
4274
  continue;
4275
4275
  }
4276
4276
  if (s === "id") {
4277
- Ue(i, "id", new me("string", !1, !0), e, `${r}.id`);
4277
+ Le(i, "id", new me("string", !1, !0), e, `${r}.id`);
4278
4278
  continue;
4279
4279
  }
4280
4280
  if (s.includes(".")) {
@@ -4290,12 +4290,12 @@ const ar = [
4290
4290
  throw new L(`Attribute or link '${s}' does not exist on entity '${e}'. Available attributes: ${u.length > 0 ? u.join(", ") : "none"}. Available links: ${l.length > 0 ? l.join(", ") : "none"}`, `${r}.${s}`);
4291
4291
  }
4292
4292
  if (a)
4293
- Ue(i, s, a, e, `${r}.${s}`);
4293
+ Le(i, s, a, e, `${r}.${s}`);
4294
4294
  else if (c) {
4295
- if (typeof i == "string" && !Le(i))
4295
+ if (typeof i == "string" && !Fe(i))
4296
4296
  throw new L(`Invalid value for link '${s}' in entity '${e}'. Expected a UUID, but received: ${i}`, `${r}.${s}`);
4297
4297
  const u = new me("string", !1, !0);
4298
- Ue(i, s, u, e, `${r}.${s}`);
4298
+ Le(i, s, u, e, `${r}.${s}`);
4299
4299
  }
4300
4300
  }
4301
4301
  }, Oa = (n, e, t, r, s = 0) => {
@@ -4358,7 +4358,7 @@ const ar = [
4358
4358
  ns(t[r], r, e, r, 0);
4359
4359
  }
4360
4360
  }
4361
- }, ur = (n) => typeof n != "string" ? !1 : wt(n) ? !0 : Le(n);
4361
+ }, ur = (n) => typeof n != "string" ? !1 : wt(n) ? !0 : Fe(n);
4362
4362
  class ue extends Error {
4363
4363
  constructor(e) {
4364
4364
  super(e), this.name = "TransactionValidationError";
@@ -4419,7 +4419,7 @@ const rs = (n) => n.length > 0 ? n.join(", ") : "none", Ea = (n, e) => new ue(`E
4419
4419
  if (!e)
4420
4420
  return;
4421
4421
  const [t, r, s, i] = n;
4422
- if (!Array.isArray(s) && !Le(s))
4422
+ if (!Array.isArray(s) && !Fe(s))
4423
4423
  throw new ue(`Invalid id for entity '${r}'. Expected a UUID, but received: ${s}`);
4424
4424
  if (typeof r != "string")
4425
4425
  throw new ue(`Entity name must be a string, but received: ${typeof r}`);
@@ -4612,7 +4612,7 @@ function dr(n, e, t, r) {
4612
4612
  const s = (o = z(t, n.table, "id")) == null ? void 0 : o.id;
4613
4613
  if (!s)
4614
4614
  return -1;
4615
- const i = Ne(e.eav, [r, s, r]);
4615
+ const i = Ke(e.eav, [r, s, r]);
4616
4616
  return i ? i[3] : -1;
4617
4617
  }
4618
4618
  function hr(n, e, t) {
@@ -5077,8 +5077,8 @@ function Fa({ WStream: n, opts: e, startStream: t, appendStream: r, registerStre
5077
5077
  });
5078
5078
  switch (ee.type) {
5079
5079
  case "ok": {
5080
- const { streamId: ae, offset: Ke } = ee;
5081
- if (Ke !== 0) {
5080
+ const { streamId: ae, offset: qe } = ee;
5081
+ if (qe !== 0) {
5082
5082
  const Ae = new Z("Write stream is corrupted");
5083
5083
  le(O, Ae);
5084
5084
  return;
@@ -5115,10 +5115,10 @@ function Fa({ WStream: n, opts: e, startStream: t, appendStream: r, registerStre
5115
5115
  Ae();
5116
5116
  }, ae = (Ae) => {
5117
5117
  I(Ae), ee();
5118
- }, Ke = () => {
5118
+ }, qe = () => {
5119
5119
  V(new Z("Stream is closed.")), ee();
5120
5120
  };
5121
- Q.push(D(ae)), Q.push(C(Ke));
5121
+ Q.push(D(ae)), Q.push(C(qe));
5122
5122
  });
5123
5123
  }
5124
5124
  }
@@ -5489,7 +5489,7 @@ const _e = {
5489
5489
  }, Wa = 3e4, za = 3e4, Va = 200, Ba = 1e3 * 60, Qa = {
5490
5490
  apiURI: "https://api.instantdb.com",
5491
5491
  websocketURI: "wss://api.instantdb.com/runtime/session"
5492
- }, Lt = "_instant_oauth_redirect", Ve = "currentUser";
5492
+ }, Lt = "_instant_oauth_redirect", xe = "currentUser";
5493
5493
  function Ga({ transportType: n, appId: e, apiURI: t, wsURI: r, EventSourceImpl: s }) {
5494
5494
  if (!s)
5495
5495
  return new fr(`${r}?app_id=${e}`);
@@ -5770,13 +5770,15 @@ class tc {
5770
5770
  if (this._EventSource = i, this.config = { ...Qa, ...e }, this.queryCacheLimit = this.config.queryCacheLimit ?? 10, this._pendingTxCleanupTimeout = this.config.pendingTxCleanupTimeout ?? za, this._pendingMutationCleanupThreshold = this.config.pendingMutationCleanupThreshold ?? Va, this._log = Ta(e.verbose || wn || Jr, () => this._reactorStats()), this.versions = { ...s || {}, "@instantdb/core": Xr }, this.config.schema && (this._linkIndex = or(this.config.schema)), !!Ha()) {
5771
5771
  if (!e.appId)
5772
5772
  throw new Error("Instant must be initialized with an appId.");
5773
- if (!Le(e.appId))
5773
+ if (!Fe(e.appId))
5774
5774
  throw new Error(`Instant must be initialized with a valid appId. \`${e.appId}\` is not a valid uuid.`);
5775
5775
  typeof BroadcastChannel == "function" && (this._broadcastChannel = new BroadcastChannel("@instantdb"), this._broadcastChannel.addEventListener("message", async (o) => {
5776
5776
  var a;
5777
5777
  try {
5778
5778
  if (((a = o.data) == null ? void 0 : a.type) === "auth") {
5779
- const c = await this.getCurrentUser();
5779
+ const c = await this.getCurrentUser({
5780
+ forceReadFromStorage: !0
5781
+ });
5780
5782
  await this.updateUser(c.user).catch((u) => {
5781
5783
  this._log.error("[error] update user", u);
5782
5784
  });
@@ -5859,7 +5861,7 @@ class tc {
5859
5861
  gc: null
5860
5862
  }), this.kv.onKeyLoaded = (t) => {
5861
5863
  t === "pendingMutations" && this.notifyAll();
5862
- }, this.kv.waitForKeyToLoad("pendingMutations"), this.kv.waitForKeyToLoad(Ve), this._beforeUnloadCbs.push(() => {
5864
+ }, this.kv.waitForKeyToLoad("pendingMutations"), this.kv.waitForKeyToLoad(xe), this._beforeUnloadCbs.push(() => {
5863
5865
  this.kv.flush(), this.querySubs.flush();
5864
5866
  });
5865
5867
  }
@@ -6570,7 +6572,7 @@ class tc {
6570
6572
  const { user: e, error: t } = await this.getCurrentUser();
6571
6573
  if (t)
6572
6574
  throw new Z("Could not get current user: " + t.message);
6573
- return e;
6575
+ return e ?? null;
6574
6576
  }
6575
6577
  subscribeConnectionStatus(e) {
6576
6578
  return this.connectionStatusCbs.push(e), () => {
@@ -6599,38 +6601,47 @@ class tc {
6599
6601
  }
6600
6602
  async setCurrentUser(e) {
6601
6603
  this.kv.updateInPlace((t) => {
6602
- t[Ve] = e;
6603
- }), await this.kv.waitForKeyToLoad(Ve);
6604
+ t[xe] = e;
6605
+ }), await this.kv.waitForKeyToLoad(xe);
6604
6606
  }
6605
6607
  getCurrentUserCached() {
6606
6608
  return this._currentUserCached;
6607
6609
  }
6608
- async _getCurrentUser() {
6609
- const e = await this.kv.waitForKeyToLoad(Ve);
6610
- return typeof e == "string" ? JSON.parse(e) : e;
6610
+ /**
6611
+ * @param {{ forceReadFromStorage?: boolean }} [opts]
6612
+ * @returns {Promise<User | undefined>}
6613
+ */
6614
+ async _getCurrentUser(e) {
6615
+ e != null && e.forceReadFromStorage && await this.kv.unloadKey(xe);
6616
+ const t = await this.kv.waitForKeyToLoad(xe);
6617
+ return typeof t == "string" ? JSON.parse(t) : t;
6611
6618
  }
6612
- async getCurrentUser() {
6613
- const e = await this._waitForOAuthCallbackResponse();
6614
- if (e != null && e.error) {
6615
- const t = { error: e.error, user: void 0 };
6616
- return this._currentUserCached = { isLoading: !1, ...t }, t;
6619
+ /**
6620
+ * @param {{ forceReadFromStorage?: boolean }} [opts]
6621
+ * @returns {Promise<AuthState>}
6622
+ */
6623
+ async getCurrentUser(e) {
6624
+ const t = await this._waitForOAuthCallbackResponse();
6625
+ if (t != null && t.error) {
6626
+ const r = { error: t.error, user: void 0 };
6627
+ return this._currentUserCached = { isLoading: !1, ...r }, this._currentUserCached;
6617
6628
  }
6618
6629
  try {
6619
- const r = { user: await this._getCurrentUser(), error: void 0 };
6630
+ const s = { user: await this._getCurrentUser(e), error: void 0 };
6620
6631
  return this._currentUserCached = {
6621
6632
  isLoading: !1,
6622
- ...r
6623
- }, r;
6624
- } catch (t) {
6633
+ ...s
6634
+ }, this._currentUserCached;
6635
+ } catch (r) {
6625
6636
  return {
6626
6637
  user: void 0,
6627
6638
  isLoading: !1,
6628
- error: { message: (t == null ? void 0 : t.message) || "Error loading user" }
6639
+ error: { message: (r == null ? void 0 : r.message) || "Error loading user" }
6629
6640
  };
6630
6641
  }
6631
6642
  }
6632
6643
  async _hasCurrentUser() {
6633
- const e = await this.kv.waitForKeyToLoad(Ve);
6644
+ const e = await this.kv.waitForKeyToLoad(xe);
6634
6645
  return typeof e == "string" ? JSON.parse(e) != null : e != null;
6635
6646
  }
6636
6647
  async changeCurrentUser(e) {
@@ -6639,7 +6650,7 @@ class tc {
6639
6650
  if (!pt(t, e)) {
6640
6651
  await this.setCurrentUser(e), await this.updateUser(e);
6641
6652
  try {
6642
- (r = this._broadcastChannel) == null || r.postMessage({ type: "auth" });
6653
+ await this.kv.flush(), (r = this._broadcastChannel) == null || r.postMessage({ type: "auth" });
6643
6654
  } catch (s) {
6644
6655
  console.error("Error posting message to broadcast channel", s);
6645
6656
  }
@@ -6684,13 +6695,13 @@ class tc {
6684
6695
  });
6685
6696
  }
6686
6697
  async signInWithMagicCode({ email: e, code: t }) {
6687
- var o;
6698
+ var o, a;
6688
6699
  const r = await this.getCurrentUser(), s = ((o = r == null ? void 0 : r.user) == null ? void 0 : o.type) === "guest", i = await ua({
6689
6700
  apiURI: this.config.apiURI,
6690
6701
  appId: this.config.appId,
6691
6702
  email: e,
6692
6703
  code: t,
6693
- refreshToken: s ? r.user.refresh_token : void 0
6704
+ refreshToken: s ? (a = r == null ? void 0 : r.user) == null ? void 0 : a.refresh_token : void 0
6694
6705
  });
6695
6706
  return await this.changeCurrentUser(i.user), i;
6696
6707
  }
@@ -6749,13 +6760,13 @@ class tc {
6749
6760
  * @param {string} [params.codeVerifier] - The code verifier used to generate the code challenge.
6750
6761
  */
6751
6762
  async exchangeCodeForToken({ code: e, codeVerifier: t }) {
6752
- var o;
6763
+ var o, a;
6753
6764
  const r = await this.getCurrentUser(), s = ((o = r == null ? void 0 : r.user) == null ? void 0 : o.type) === "guest", i = await nr({
6754
6765
  apiURI: this.config.apiURI,
6755
6766
  appId: this.config.appId,
6756
6767
  code: e,
6757
6768
  codeVerifier: t,
6758
- refreshToken: s ? r.user.refresh_token : void 0
6769
+ refreshToken: s ? (a = r == null ? void 0 : r.user) == null ? void 0 : a.refresh_token : void 0
6759
6770
  });
6760
6771
  return await this.changeCurrentUser(i.user), i;
6761
6772
  }