@sidekickdb/resumable-stream 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,53 +1,53 @@
1
- var Wn = Object.defineProperty;
2
- var qt = (e) => {
1
+ var ns = Object.defineProperty;
2
+ var nn = (e) => {
3
3
  throw TypeError(e);
4
4
  };
5
- var Kn = (e, t, n) => t in e ? Wn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
6
- var d = (e, t, n) => Kn(e, typeof t != "symbol" ? t + "" : t, n), wt = (e, t, n) => t.has(e) || qt("Cannot " + n);
7
- var f = (e, t, n) => (wt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), k = (e, t, n) => t.has(e) ? qt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), S = (e, t, n, s) => (wt(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), O = (e, t, n) => (wt(e, t, "access private method"), n);
8
- const Vn = /^(?:[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;
9
- function Fe(e) {
10
- return typeof e == "string" && Vn.test(e);
5
+ var ss = (e, t, n) => t in e ? ns(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
6
+ var l = (e, t, n) => ss(e, typeof t != "symbol" ? t + "" : t, n), Ot = (e, t, n) => t.has(e) || nn("Cannot " + n);
7
+ var f = (e, t, n) => (Ot(e, t, "read from private field"), n ? n.call(e) : t.get(e)), k = (e, t, n) => t.has(e) ? nn("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), I = (e, t, n, s) => (Ot(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), E = (e, t, n) => (Ot(e, t, "access private method"), n);
8
+ const rs = /^(?:[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;
9
+ function ze(e) {
10
+ return typeof e == "string" && rs.test(e);
11
11
  }
12
12
  const L = [];
13
13
  for (let e = 0; e < 256; ++e)
14
14
  L.push((e + 256).toString(16).slice(1));
15
- function Jn(e, t = 0) {
15
+ function is(e, t = 0) {
16
16
  return (L[e[t + 0]] + L[e[t + 1]] + L[e[t + 2]] + L[e[t + 3]] + "-" + L[e[t + 4]] + L[e[t + 5]] + "-" + L[e[t + 6]] + L[e[t + 7]] + "-" + L[e[t + 8]] + L[e[t + 9]] + "-" + L[e[t + 10]] + L[e[t + 11]] + L[e[t + 12]] + L[e[t + 13]] + L[e[t + 14]] + L[e[t + 15]]).toLowerCase();
17
17
  }
18
- let St;
19
- const Hn = new Uint8Array(16);
20
- function qn() {
21
- if (!St) {
18
+ let Et;
19
+ const os = new Uint8Array(16);
20
+ function as() {
21
+ if (!Et) {
22
22
  if (typeof crypto > "u" || !crypto.getRandomValues)
23
23
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
24
- St = crypto.getRandomValues.bind(crypto);
24
+ Et = crypto.getRandomValues.bind(crypto);
25
25
  }
26
- return St(Hn);
26
+ return Et(os);
27
27
  }
28
- const Bn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Bt = { randomUUID: Bn };
29
- function Qn(e, t, n) {
28
+ const cs = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), sn = { randomUUID: cs };
29
+ function us(e, t, n) {
30
30
  var r;
31
- if (Bt.randomUUID && !e)
32
- return Bt.randomUUID();
31
+ if (sn.randomUUID && !e)
32
+ return sn.randomUUID();
33
33
  e = e || {};
34
- const s = e.random ?? ((r = e.rng) == null ? void 0 : r.call(e)) ?? qn();
34
+ const s = e.random ?? ((r = e.rng) == null ? void 0 : r.call(e)) ?? as();
35
35
  if (s.length < 16)
36
36
  throw new Error("Random bytes length must be >= 16");
37
- return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, Jn(s);
37
+ return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, is(s);
38
38
  }
39
39
  const M = {
40
40
  Remove: "remove",
41
41
  Replace: "replace",
42
42
  Add: "add"
43
- }, pn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), tt = Symbol.iterator, re = {
43
+ }, xn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), ot = Symbol.iterator, re = {
44
44
  mutable: "mutable",
45
45
  immutable: "immutable"
46
- }, Nt = {};
47
- function Ke(e, t) {
46
+ }, Bt = {};
47
+ function He(e, t) {
48
48
  return e instanceof Map ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
49
49
  }
50
- function Qt(e, t) {
50
+ function rn(e, t) {
51
51
  if (t in e) {
52
52
  let n = Reflect.getPrototypeOf(e);
53
53
  for (; n; ) {
@@ -58,84 +58,84 @@ function Qt(e, t) {
58
58
  }
59
59
  }
60
60
  }
61
- function yn(e) {
61
+ function Tn(e) {
62
62
  return Object.getPrototypeOf(e) === Set.prototype;
63
63
  }
64
- function mn(e) {
64
+ function _n(e) {
65
65
  return Object.getPrototypeOf(e) === Map.prototype;
66
66
  }
67
67
  function X(e) {
68
68
  var t;
69
69
  return (t = e.copy) !== null && t !== void 0 ? t : e.original;
70
70
  }
71
- function Et(e) {
72
- return !!E(e);
71
+ function Rt(e) {
72
+ return !!C(e);
73
73
  }
74
- function E(e) {
75
- return typeof e != "object" ? null : e == null ? void 0 : e[pn];
74
+ function C(e) {
75
+ return typeof e != "object" ? null : e == null ? void 0 : e[xn];
76
76
  }
77
- function Lt(e) {
77
+ function qt(e) {
78
78
  var t;
79
- const n = E(e);
79
+ const n = C(e);
80
80
  return n ? (t = n.copy) !== null && t !== void 0 ? t : n.original : e;
81
81
  }
82
- function Te(e, t) {
82
+ function _e(e, t) {
83
83
  if (!e || typeof e != "object")
84
84
  return !1;
85
85
  let n;
86
86
  return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!(t != null && t.mark) && ((n = t.mark(e, re)) === re.immutable || typeof n == "function");
87
87
  }
88
- function bn(e, t = []) {
88
+ function An(e, t = []) {
89
89
  if (Object.hasOwnProperty.call(e, "key")) {
90
- const n = e.parent.copy, s = E(me(n, e.key));
90
+ const n = e.parent.copy, s = C(be(n, e.key));
91
91
  if (s !== null && (s == null ? void 0 : s.original) !== e.original)
92
92
  return null;
93
93
  const r = e.parent.type === 3, i = r ? Array.from(e.parent.setMap.keys()).indexOf(e.key) : e.key;
94
- if (!(r && n.size > i || Ke(n, i)))
94
+ if (!(r && n.size > i || He(n, i)))
95
95
  return null;
96
96
  t.push(i);
97
97
  }
98
98
  if (e.parent)
99
- return bn(e.parent, t);
99
+ return An(e.parent, t);
100
100
  t.reverse();
101
101
  try {
102
- Gn(e.copy, t);
102
+ fs(e.copy, t);
103
103
  } catch {
104
104
  return null;
105
105
  }
106
106
  return t;
107
107
  }
108
- function Xe(e) {
108
+ function tt(e) {
109
109
  return Array.isArray(e) ? 1 : e instanceof Map ? 2 : e instanceof Set ? 3 : 0;
110
110
  }
111
- function me(e, t) {
112
- return Xe(e) === 2 ? e.get(t) : e[t];
111
+ function be(e, t) {
112
+ return tt(e) === 2 ? e.get(t) : e[t];
113
113
  }
114
- function Ft(e, t, n) {
115
- Xe(e) === 2 ? e.set(t, n) : e[t] = n;
114
+ function Qt(e, t, n) {
115
+ tt(e) === 2 ? e.set(t, n) : e[t] = n;
116
116
  }
117
- function It(e, t) {
118
- const n = E(e);
117
+ function Ct(e, t) {
118
+ const n = C(e);
119
119
  return (n ? X(n) : e)[t];
120
120
  }
121
- function Ce(e, t) {
121
+ function xe(e, t) {
122
122
  return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
123
123
  }
124
- function we(e, t) {
124
+ function Se(e, t) {
125
125
  return t ? e : [""].concat(e).map((n) => {
126
126
  const s = `${n}`;
127
127
  return s.indexOf("/") === -1 && s.indexOf("~") === -1 ? s : s.replace(/~/g, "~0").replace(/\//g, "~1");
128
128
  }).join("/");
129
129
  }
130
- function Gn(e, t) {
130
+ function fs(e, t) {
131
131
  for (let n = 0; n < t.length - 1; n += 1) {
132
132
  const s = t[n];
133
- if (e = me(Xe(e) === 3 ? Array.from(e) : e, s), typeof e != "object")
133
+ if (e = be(tt(e) === 3 ? Array.from(e) : e, s), typeof e != "object")
134
134
  throw new Error(`Cannot resolve patch at '${t.join("/")}'.`);
135
135
  }
136
136
  return e;
137
137
  }
138
- function Xn(e) {
138
+ function ds(e) {
139
139
  const t = Object.create(Object.getPrototypeOf(e));
140
140
  return Reflect.ownKeys(e).forEach((n) => {
141
141
  let s = Reflect.getOwnPropertyDescriptor(e, n);
@@ -151,26 +151,26 @@ function Xn(e) {
151
151
  }), Reflect.defineProperty(t, n, s);
152
152
  }), t;
153
153
  }
154
- const Yn = Object.prototype.propertyIsEnumerable;
155
- function Zn(e, t) {
154
+ const ls = Object.prototype.propertyIsEnumerable;
155
+ function hs(e, t) {
156
156
  let n;
157
157
  if (Array.isArray(e))
158
158
  return Array.prototype.concat.call(e);
159
159
  if (e instanceof Set) {
160
- if (!yn(e)) {
160
+ if (!Tn(e)) {
161
161
  const s = Object.getPrototypeOf(e).constructor;
162
162
  return new s(e.values());
163
163
  }
164
164
  return Set.prototype.difference ? Set.prototype.difference.call(e, /* @__PURE__ */ new Set()) : new Set(e.values());
165
165
  } else if (e instanceof Map) {
166
- if (!mn(e)) {
166
+ if (!_n(e)) {
167
167
  const s = Object.getPrototypeOf(e).constructor;
168
168
  return new s(e);
169
169
  }
170
170
  return new Map(e);
171
171
  } else if (t != null && t.mark && (n = t.mark(e, re), n !== void 0) && n !== re.mutable) {
172
172
  if (n === re.immutable)
173
- return Xn(e);
173
+ return ds(e);
174
174
  if (typeof n == "function") {
175
175
  if (t.enablePatches || t.enableAutoFreeze)
176
176
  throw new Error("You can't use mark and patches or auto freeze together.");
@@ -182,33 +182,33 @@ function Zn(e, t) {
182
182
  return Object.keys(e).forEach((r) => {
183
183
  s[r] = e[r];
184
184
  }), Object.getOwnPropertySymbols(e).forEach((r) => {
185
- Yn.call(e, r) && (s[r] = e[r]);
185
+ ls.call(e, r) && (s[r] = e[r]);
186
186
  }), s;
187
187
  } else
188
188
  throw new Error("Please check mark() to ensure that it is a stable marker draftable function.");
189
189
  }
190
- function q(e) {
191
- e.copy || (e.copy = Zn(e.original, e.options));
190
+ function B(e) {
191
+ e.copy || (e.copy = hs(e.original, e.options));
192
192
  }
193
- function ze(e) {
194
- if (!Te(e))
195
- return Lt(e);
193
+ function Ve(e) {
194
+ if (!_e(e))
195
+ return qt(e);
196
196
  if (Array.isArray(e))
197
- return e.map(ze);
197
+ return e.map(Ve);
198
198
  if (e instanceof Map) {
199
199
  const n = Array.from(e.entries()).map(([s, r]) => [
200
200
  s,
201
- ze(r)
201
+ Ve(r)
202
202
  ]);
203
- if (!mn(e)) {
203
+ if (!_n(e)) {
204
204
  const s = Object.getPrototypeOf(e).constructor;
205
205
  return new s(n);
206
206
  }
207
207
  return new Map(n);
208
208
  }
209
209
  if (e instanceof Set) {
210
- const n = Array.from(e).map(ze);
211
- if (!yn(e)) {
210
+ const n = Array.from(e).map(Ve);
211
+ if (!Tn(e)) {
212
212
  const s = Object.getPrototypeOf(e).constructor;
213
213
  return new s(n);
214
214
  }
@@ -216,18 +216,18 @@ function ze(e) {
216
216
  }
217
217
  const t = Object.create(Object.getPrototypeOf(e));
218
218
  for (const n in e)
219
- t[n] = ze(e[n]);
219
+ t[n] = Ve(e[n]);
220
220
  return t;
221
221
  }
222
- function nt(e) {
223
- return Et(e) ? ze(e) : e;
222
+ function at(e) {
223
+ return Rt(e) ? Ve(e) : e;
224
224
  }
225
225
  function ie(e) {
226
226
  var t;
227
227
  e.assignedMap = (t = e.assignedMap) !== null && t !== void 0 ? t : /* @__PURE__ */ new Map(), e.operated || (e.operated = !0, e.parent && ie(e.parent));
228
228
  }
229
- function es(e, t) {
230
- const n = Xe(e);
229
+ function ps(e, t) {
230
+ const n = tt(e);
231
231
  if (n === 0)
232
232
  Reflect.ownKeys(e).forEach((s) => {
233
233
  t(s, e[s], e);
@@ -239,19 +239,19 @@ function es(e, t) {
239
239
  } else
240
240
  e.forEach((s, r) => t(r, s, e));
241
241
  }
242
- function gn(e, t, n) {
243
- if (Et(e) || !Te(e, n) || t.has(e) || Object.isFrozen(e))
242
+ function Rn(e, t, n) {
243
+ if (Rt(e) || !_e(e, n) || t.has(e) || Object.isFrozen(e))
244
244
  return;
245
245
  const s = e instanceof Set, r = s ? /* @__PURE__ */ new Map() : void 0;
246
- if (t.add(e), es(e, (i, o) => {
246
+ if (t.add(e), ps(e, (i, o) => {
247
247
  var a;
248
- if (Et(o)) {
249
- const c = E(o);
250
- q(c);
248
+ if (Rt(o)) {
249
+ const c = C(o);
250
+ B(c);
251
251
  const u = !((a = c.assignedMap) === null || a === void 0) && a.size || c.operated ? c.copy : c.original;
252
- Ft(s ? r : e, i, u);
252
+ Qt(s ? r : e, i, u);
253
253
  } else
254
- gn(o, t, n);
254
+ Rn(o, t, n);
255
255
  }), r) {
256
256
  const i = e, o = Array.from(i);
257
257
  i.clear(), o.forEach((a) => {
@@ -259,77 +259,77 @@ function gn(e, t, n) {
259
259
  });
260
260
  }
261
261
  }
262
- function ts(e, t) {
262
+ function ys(e, t) {
263
263
  const n = e.type === 3 ? e.setMap : e.copy;
264
- e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && gn(me(n, t), e.finalities.handledSet, e.options);
264
+ e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && Rn(be(n, t), e.finalities.handledSet, e.options);
265
265
  }
266
- function Ct(e) {
266
+ function Pt(e) {
267
267
  e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
268
- e.copy.add(Lt(t));
268
+ e.copy.add(qt(t));
269
269
  }));
270
270
  }
271
- function xt(e, t, n, s) {
271
+ function jt(e, t, n, s) {
272
272
  if (e.operated && e.assignedMap && e.assignedMap.size > 0 && !e.finalized) {
273
273
  if (n && s) {
274
- const i = bn(e);
274
+ const i = An(e);
275
275
  i && t(e, i, n, s);
276
276
  }
277
277
  e.finalized = !0;
278
278
  }
279
279
  }
280
- function zt(e, t, n, s) {
281
- const r = E(n);
280
+ function Gt(e, t, n, s) {
281
+ const r = C(n);
282
282
  r && (r.callbacks || (r.callbacks = []), r.callbacks.push((i, o) => {
283
283
  var a;
284
284
  const c = e.type === 3 ? e.setMap : e.copy;
285
- if (Ce(me(c, t), n)) {
285
+ if (xe(be(c, t), n)) {
286
286
  let u = r.original;
287
- r.copy && (u = r.copy), Ct(e), xt(e, s, i, o), e.options.enableAutoFreeze && (e.options.updatedValues = (a = e.options.updatedValues) !== null && a !== void 0 ? a : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(u, r.original)), Ft(c, t, u);
287
+ r.copy && (u = r.copy), Pt(e), jt(e, s, i, o), e.options.enableAutoFreeze && (e.options.updatedValues = (a = e.options.updatedValues) !== null && a !== void 0 ? a : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(u, r.original)), Qt(c, t, u);
288
288
  }
289
- }), e.options.enableAutoFreeze && r.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), Te(n, e.options) && e.finalities.draft.push(() => {
289
+ }), e.options.enableAutoFreeze && r.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), _e(n, e.options) && e.finalities.draft.push(() => {
290
290
  const i = e.type === 3 ? e.setMap : e.copy;
291
- Ce(me(i, t), n) && ts(e, t);
291
+ xe(be(i, t), n) && ys(e, t);
292
292
  });
293
293
  }
294
- function ns(e, t, n, s, r) {
294
+ function ms(e, t, n, s, r) {
295
295
  let { original: i, assignedMap: o, options: a } = e, c = e.copy;
296
296
  c.length < i.length && ([i, c] = [c, i], [n, s] = [s, n]);
297
297
  for (let u = 0; u < i.length; u += 1)
298
298
  if (o.get(u.toString()) && c[u] !== i[u]) {
299
- const h = t.concat([u]), l = we(h, r);
299
+ const p = t.concat([u]), d = Se(p, r);
300
300
  n.push({
301
301
  op: M.Replace,
302
- path: l,
302
+ path: d,
303
303
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
304
- value: nt(c[u])
304
+ value: at(c[u])
305
305
  }), s.push({
306
306
  op: M.Replace,
307
- path: l,
307
+ path: d,
308
308
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
309
- value: nt(i[u])
309
+ value: at(i[u])
310
310
  });
311
311
  }
312
312
  for (let u = i.length; u < c.length; u += 1) {
313
- const h = t.concat([u]), l = we(h, r);
313
+ const p = t.concat([u]), d = Se(p, r);
314
314
  n.push({
315
315
  op: M.Add,
316
- path: l,
316
+ path: d,
317
317
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
318
- value: nt(c[u])
318
+ value: at(c[u])
319
319
  });
320
320
  }
321
321
  if (i.length < c.length) {
322
322
  const { arrayLengthAssignment: u = !0 } = a.enablePatches;
323
323
  if (u) {
324
- const h = t.concat(["length"]), l = we(h, r);
324
+ const p = t.concat(["length"]), d = Se(p, r);
325
325
  s.push({
326
326
  op: M.Replace,
327
- path: l,
327
+ path: d,
328
328
  value: i.length
329
329
  });
330
330
  } else
331
- for (let h = c.length; i.length < h; h -= 1) {
332
- const l = t.concat([h - 1]), y = we(l, r);
331
+ for (let p = c.length; i.length < p; p -= 1) {
332
+ const d = t.concat([p - 1]), y = Se(d, r);
333
333
  s.push({
334
334
  op: M.Remove,
335
335
  path: y
@@ -337,20 +337,20 @@ function ns(e, t, n, s, r) {
337
337
  }
338
338
  }
339
339
  }
340
- function ss({ original: e, copy: t, assignedMap: n }, s, r, i, o) {
340
+ function bs({ original: e, copy: t, assignedMap: n }, s, r, i, o) {
341
341
  n.forEach((a, c) => {
342
- const u = me(e, c), h = nt(me(t, c)), l = a ? Ke(e, c) ? M.Replace : M.Add : M.Remove;
343
- if (Ce(u, h) && l === M.Replace)
342
+ const u = be(e, c), p = at(be(t, c)), d = a ? He(e, c) ? M.Replace : M.Add : M.Remove;
343
+ if (xe(u, p) && d === M.Replace)
344
344
  return;
345
- const y = s.concat(c), m = we(y, o);
346
- r.push(l === M.Remove ? { op: l, path: m } : { op: l, path: m, value: h }), i.push(l === M.Add ? { op: M.Remove, path: m } : l === M.Remove ? { op: M.Add, path: m, value: u } : { op: M.Replace, path: m, value: u });
345
+ const y = s.concat(c), m = Se(y, o);
346
+ r.push(d === M.Remove ? { op: d, path: m } : { op: d, path: m, value: p }), i.push(d === M.Add ? { op: M.Remove, path: m } : d === M.Remove ? { op: M.Add, path: m, value: u } : { op: M.Replace, path: m, value: u });
347
347
  });
348
348
  }
349
- function rs({ original: e, copy: t }, n, s, r, i) {
349
+ function gs({ original: e, copy: t }, n, s, r, i) {
350
350
  let o = 0;
351
351
  e.forEach((a) => {
352
352
  if (!t.has(a)) {
353
- const c = n.concat([o]), u = we(c, i);
353
+ const c = n.concat([o]), u = Se(c, i);
354
354
  s.push({
355
355
  op: M.Remove,
356
356
  path: u,
@@ -364,7 +364,7 @@ function rs({ original: e, copy: t }, n, s, r, i) {
364
364
  o += 1;
365
365
  }), o = 0, t.forEach((a) => {
366
366
  if (!e.has(a)) {
367
- const c = n.concat([o]), u = we(c, i);
367
+ const c = n.concat([o]), u = Se(c, i);
368
368
  s.push({
369
369
  op: M.Add,
370
370
  path: u,
@@ -378,74 +378,74 @@ function rs({ original: e, copy: t }, n, s, r, i) {
378
378
  o += 1;
379
379
  });
380
380
  }
381
- function Ve(e, t, n, s) {
381
+ function Be(e, t, n, s) {
382
382
  const { pathAsArray: r = !0 } = e.options.enablePatches;
383
383
  switch (e.type) {
384
384
  case 0:
385
385
  case 2:
386
- return ss(e, t, n, s, r);
386
+ return bs(e, t, n, s, r);
387
387
  case 1:
388
- return ns(e, t, n, s, r);
388
+ return ms(e, t, n, s, r);
389
389
  case 3:
390
- return rs(e, t, n, s, r);
390
+ return gs(e, t, n, s, r);
391
391
  }
392
392
  }
393
- const it = (e, t, n = !1) => {
394
- if (typeof e == "object" && e !== null && (!Te(e, t) || n))
393
+ const ft = (e, t, n = !1) => {
394
+ if (typeof e == "object" && e !== null && (!_e(e, t) || n))
395
395
  throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
396
- }, Tt = {
396
+ }, Ut = {
397
397
  get size() {
398
- return X(E(this)).size;
398
+ return X(C(this)).size;
399
399
  },
400
400
  has(e) {
401
- return X(E(this)).has(e);
401
+ return X(C(this)).has(e);
402
402
  },
403
403
  set(e, t) {
404
- const n = E(this), s = X(n);
405
- return (!s.has(e) || !Ce(s.get(e), t)) && (q(n), ie(n), n.assignedMap.set(e, !0), n.copy.set(e, t), zt(n, e, t, Ve)), this;
404
+ const n = C(this), s = X(n);
405
+ return (!s.has(e) || !xe(s.get(e), t)) && (B(n), ie(n), n.assignedMap.set(e, !0), n.copy.set(e, t), Gt(n, e, t, Be)), this;
406
406
  },
407
407
  delete(e) {
408
408
  if (!this.has(e))
409
409
  return !1;
410
- const t = E(this);
411
- return q(t), ie(t), t.original.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.copy.delete(e), !0;
410
+ const t = C(this);
411
+ return B(t), ie(t), t.original.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.copy.delete(e), !0;
412
412
  },
413
413
  clear() {
414
- const e = E(this);
414
+ const e = C(this);
415
415
  if (this.size) {
416
- q(e), ie(e), e.assignedMap = /* @__PURE__ */ new Map();
416
+ B(e), ie(e), e.assignedMap = /* @__PURE__ */ new Map();
417
417
  for (const [t] of e.original)
418
418
  e.assignedMap.set(t, !1);
419
419
  e.copy.clear();
420
420
  }
421
421
  },
422
422
  forEach(e, t) {
423
- const n = E(this);
423
+ const n = C(this);
424
424
  X(n).forEach((s, r) => {
425
425
  e.call(t, this.get(r), r, this);
426
426
  });
427
427
  },
428
428
  get(e) {
429
429
  var t, n;
430
- const s = E(this), r = X(s).get(e), i = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, r, re)) === re.mutable;
431
- if (s.options.strict && it(r, s.options, i), i || s.finalized || !Te(r, s.options) || r !== s.original.get(e))
430
+ const s = C(this), r = X(s).get(e), i = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, r, re)) === re.mutable;
431
+ if (s.options.strict && ft(r, s.options, i), i || s.finalized || !_e(r, s.options) || r !== s.original.get(e))
432
432
  return r;
433
- const o = Nt.createDraft({
433
+ const o = Bt.createDraft({
434
434
  original: r,
435
435
  parentDraft: s,
436
436
  key: e,
437
437
  finalities: s.finalities,
438
438
  options: s.options
439
439
  });
440
- return q(s), s.copy.set(e, o), o;
440
+ return B(s), s.copy.set(e, o), o;
441
441
  },
442
442
  keys() {
443
- return X(E(this)).keys();
443
+ return X(C(this)).keys();
444
444
  },
445
445
  values() {
446
446
  const e = this.keys();
447
447
  return {
448
- [tt]: () => this.values(),
448
+ [ot]: () => this.values(),
449
449
  next: () => {
450
450
  const t = e.next();
451
451
  return t.done ? t : {
@@ -458,7 +458,7 @@ const it = (e, t, n = !1) => {
458
458
  entries() {
459
459
  const e = this.keys();
460
460
  return {
461
- [tt]: () => this.entries(),
461
+ [ot]: () => this.entries(),
462
462
  next: () => {
463
463
  const t = e.next();
464
464
  if (t.done)
@@ -471,80 +471,80 @@ const it = (e, t, n = !1) => {
471
471
  }
472
472
  };
473
473
  },
474
- [tt]() {
474
+ [ot]() {
475
475
  return this.entries();
476
476
  }
477
- }, is = Reflect.ownKeys(Tt), Gt = (e, t, { isValuesIterator: n }) => () => {
477
+ }, ws = Reflect.ownKeys(Ut), on = (e, t, { isValuesIterator: n }) => () => {
478
478
  var s, r;
479
479
  const i = t.next();
480
480
  if (i.done)
481
481
  return i;
482
482
  const o = i.value;
483
483
  let a = e.setMap.get(o);
484
- const c = E(a), u = ((r = (s = e.options).mark) === null || r === void 0 ? void 0 : r.call(s, a, re)) === re.mutable;
485
- if (e.options.strict && it(o, e.options, u), !u && !c && Te(o, e.options) && !e.finalized && e.original.has(o)) {
486
- const h = Nt.createDraft({
484
+ const c = C(a), u = ((r = (s = e.options).mark) === null || r === void 0 ? void 0 : r.call(s, a, re)) === re.mutable;
485
+ if (e.options.strict && ft(o, e.options, u), !u && !c && _e(o, e.options) && !e.finalized && e.original.has(o)) {
486
+ const p = Bt.createDraft({
487
487
  original: o,
488
488
  parentDraft: e,
489
489
  key: o,
490
490
  finalities: e.finalities,
491
491
  options: e.options
492
492
  });
493
- e.setMap.set(o, h), a = h;
493
+ e.setMap.set(o, p), a = p;
494
494
  } else c && (a = c.proxy);
495
495
  return {
496
496
  done: !1,
497
497
  value: n ? a : [a, a]
498
498
  };
499
- }, ot = {
499
+ }, dt = {
500
500
  get size() {
501
- return E(this).setMap.size;
501
+ return C(this).setMap.size;
502
502
  },
503
503
  has(e) {
504
- const t = E(this);
504
+ const t = C(this);
505
505
  if (t.setMap.has(e))
506
506
  return !0;
507
- q(t);
508
- const n = E(e);
507
+ B(t);
508
+ const n = C(e);
509
509
  return !!(n && t.setMap.has(n.original));
510
510
  },
511
511
  add(e) {
512
- const t = E(this);
513
- return this.has(e) || (q(t), ie(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), zt(t, e, e, Ve)), this;
512
+ const t = C(this);
513
+ return this.has(e) || (B(t), ie(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), Gt(t, e, e, Be)), this;
514
514
  },
515
515
  delete(e) {
516
516
  if (!this.has(e))
517
517
  return !1;
518
- const t = E(this);
519
- q(t), ie(t);
520
- const n = E(e);
518
+ const t = C(this);
519
+ B(t), ie(t);
520
+ const n = C(e);
521
521
  return n && t.setMap.has(n.original) ? (t.assignedMap.set(n.original, !1), t.setMap.delete(n.original)) : (!n && t.setMap.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.setMap.delete(e));
522
522
  },
523
523
  clear() {
524
524
  if (!this.size)
525
525
  return;
526
- const e = E(this);
527
- q(e), ie(e);
526
+ const e = C(this);
527
+ B(e), ie(e);
528
528
  for (const t of e.original)
529
529
  e.assignedMap.set(t, !1);
530
530
  e.setMap.clear();
531
531
  },
532
532
  values() {
533
- const e = E(this);
534
- q(e);
533
+ const e = C(this);
534
+ B(e);
535
535
  const t = e.setMap.keys();
536
536
  return {
537
537
  [Symbol.iterator]: () => this.values(),
538
- next: Gt(e, t, { isValuesIterator: !0 })
538
+ next: on(e, t, { isValuesIterator: !0 })
539
539
  };
540
540
  },
541
541
  entries() {
542
- const e = E(this);
543
- q(e);
542
+ const e = C(this);
543
+ B(e);
544
544
  const t = e.setMap.keys();
545
545
  return {
546
546
  [Symbol.iterator]: () => this.entries(),
547
- next: Gt(e, t, {
547
+ next: on(e, t, {
548
548
  isValuesIterator: !1
549
549
  })
550
550
  };
@@ -552,7 +552,7 @@ const it = (e, t, n = !1) => {
552
552
  keys() {
553
553
  return this.values();
554
554
  },
555
- [tt]() {
555
+ [ot]() {
556
556
  return this.values();
557
557
  },
558
558
  forEach(e, t) {
@@ -562,7 +562,7 @@ const it = (e, t, n = !1) => {
562
562
  e.call(t, s.value, s.value, this), s = n.next();
563
563
  }
564
564
  };
565
- Set.prototype.difference && Object.assign(ot, {
565
+ Set.prototype.difference && Object.assign(dt, {
566
566
  intersection(e) {
567
567
  return Set.prototype.intersection.call(new Set(this.values()), e);
568
568
  },
@@ -585,55 +585,55 @@ Set.prototype.difference && Object.assign(ot, {
585
585
  return Set.prototype.isDisjointFrom.call(new Set(this.values()), e);
586
586
  }
587
587
  });
588
- const os = Reflect.ownKeys(ot), wn = /* @__PURE__ */ new WeakSet(), Sn = {
588
+ const Ss = Reflect.ownKeys(dt), Pn = /* @__PURE__ */ new WeakSet(), jn = {
589
589
  get(e, t, n) {
590
590
  var s, r;
591
591
  const i = (s = e.copy) === null || s === void 0 ? void 0 : s[t];
592
- if (i && wn.has(i))
592
+ if (i && Pn.has(i))
593
593
  return i;
594
- if (t === pn)
594
+ if (t === xn)
595
595
  return e;
596
596
  let o;
597
597
  if (e.options.mark) {
598
598
  const u = t === "size" && (e.original instanceof Map || e.original instanceof Set) ? Reflect.get(e.original, t) : Reflect.get(e.original, t, n);
599
599
  if (o = e.options.mark(u, re), o === re.mutable)
600
- return e.options.strict && it(u, e.options, !0), u;
600
+ return e.options.strict && ft(u, e.options, !0), u;
601
601
  }
602
602
  const a = X(e);
603
- if (a instanceof Map && is.includes(t)) {
603
+ if (a instanceof Map && ws.includes(t)) {
604
604
  if (t === "size")
605
- return Object.getOwnPropertyDescriptor(Tt, "size").get.call(e.proxy);
606
- const u = Tt[t];
605
+ return Object.getOwnPropertyDescriptor(Ut, "size").get.call(e.proxy);
606
+ const u = Ut[t];
607
607
  if (u)
608
608
  return u.bind(e.proxy);
609
609
  }
610
- if (a instanceof Set && os.includes(t)) {
610
+ if (a instanceof Set && Ss.includes(t)) {
611
611
  if (t === "size")
612
- return Object.getOwnPropertyDescriptor(ot, "size").get.call(e.proxy);
613
- const u = ot[t];
612
+ return Object.getOwnPropertyDescriptor(dt, "size").get.call(e.proxy);
613
+ const u = dt[t];
614
614
  if (u)
615
615
  return u.bind(e.proxy);
616
616
  }
617
- if (!Ke(a, t)) {
618
- const u = Qt(a, t);
617
+ if (!He(a, t)) {
618
+ const u = rn(a, t);
619
619
  return u ? "value" in u ? u.value : (
620
620
  // !case: support for getter
621
621
  (r = u.get) === null || r === void 0 ? void 0 : r.call(e.proxy)
622
622
  ) : void 0;
623
623
  }
624
624
  const c = a[t];
625
- if (e.options.strict && it(c, e.options), e.finalized || !Te(c, e.options))
625
+ if (e.options.strict && ft(c, e.options), e.finalized || !_e(c, e.options))
626
626
  return c;
627
- if (c === It(e.original, t)) {
628
- if (q(e), e.copy[t] = In({
627
+ if (c === Ct(e.original, t)) {
628
+ if (B(e), e.copy[t] = Un({
629
629
  original: e.original[t],
630
630
  parentDraft: e,
631
631
  key: e.type === 1 ? Number(t) : t,
632
632
  finalities: e.finalities,
633
633
  options: e.options
634
634
  }), typeof o == "function") {
635
- const u = E(e.copy[t]);
636
- return q(u), ie(u), u.copy;
635
+ const u = C(e.copy[t]);
636
+ return B(u), ie(u), u.copy;
637
637
  }
638
638
  return e.copy[t];
639
639
  }
@@ -646,11 +646,11 @@ const os = Reflect.ownKeys(ot), wn = /* @__PURE__ */ new WeakSet(), Sn = {
646
646
  let r;
647
647
  if (e.type === 1 && t !== "length" && !(Number.isInteger(r = Number(t)) && r >= 0 && (t === 0 || r === 0 || String(r) === String(t))))
648
648
  throw new Error("Only supports setting array indices and the 'length' property.");
649
- const i = Qt(X(e), t);
649
+ const i = rn(X(e), t);
650
650
  if (i != null && i.set)
651
651
  return i.set.call(e.proxy, n), !0;
652
- const o = It(X(e), t), a = E(o);
653
- return a && Ce(a.original, n) ? (e.copy[t] = n, e.assignedMap = (s = e.assignedMap) !== null && s !== void 0 ? s : /* @__PURE__ */ new Map(), e.assignedMap.set(t, !1), !0) : (Ce(n, o) && (n !== void 0 || Ke(e.original, t)) || (q(e), ie(e), Ke(e.original, t) && Ce(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, zt(e, t, n, Ve)), !0);
652
+ const o = Ct(X(e), t), a = C(o);
653
+ return a && xe(a.original, n) ? (e.copy[t] = n, e.assignedMap = (s = e.assignedMap) !== null && s !== void 0 ? s : /* @__PURE__ */ new Map(), e.assignedMap.set(t, !1), !0) : (xe(n, o) && (n !== void 0 || He(e.original, t)) || (B(e), ie(e), He(e.original, t) && xe(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, Gt(e, t, n, Be)), !0);
654
654
  },
655
655
  has(e, t) {
656
656
  return t in X(e);
@@ -678,11 +678,11 @@ const os = Reflect.ownKeys(ot), wn = /* @__PURE__ */ new WeakSet(), Sn = {
678
678
  },
679
679
  deleteProperty(e, t) {
680
680
  var n;
681
- return e.type === 1 ? Sn.set.call(this, e, t, void 0, e.proxy) : (It(e.original, t) !== void 0 || t in e.original ? (q(e), ie(e), e.assignedMap.set(t, !1)) : (e.assignedMap = (n = e.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), e.assignedMap.delete(t)), e.copy && delete e.copy[t], !0);
681
+ return e.type === 1 ? jn.set.call(this, e, t, void 0, e.proxy) : (Ct(e.original, t) !== void 0 || t in e.original ? (B(e), ie(e), e.assignedMap.set(t, !1)) : (e.assignedMap = (n = e.assignedMap) !== null && n !== void 0 ? n : /* @__PURE__ */ new Map(), e.assignedMap.delete(t)), e.copy && delete e.copy[t], !0);
682
682
  }
683
683
  };
684
- function In(e) {
685
- const { original: t, parentDraft: n, key: s, finalities: r, options: i } = e, o = Xe(t), a = {
684
+ function Un(e) {
685
+ const { original: t, parentDraft: n, key: s, finalities: r, options: i } = e, o = tt(t), a = {
686
686
  type: o,
687
687
  finalized: !1,
688
688
  parent: n,
@@ -695,40 +695,40 @@ function In(e) {
695
695
  setMap: o === 3 ? new Map(t.entries()) : void 0
696
696
  };
697
697
  (s || "key" in e) && (a.key = s);
698
- const { proxy: c, revoke: u } = Proxy.revocable(o === 1 ? Object.assign([], a) : a, Sn);
699
- if (r.revoke.push(u), wn.add(c), a.proxy = c, n) {
700
- const h = n;
701
- h.finalities.draft.push((l, y) => {
702
- var m, g;
703
- const w = E(c);
704
- let p = h.type === 3 ? h.setMap : h.copy;
705
- const $ = me(p, s), v = E($);
706
- if (v) {
707
- let F = v.original;
708
- v.operated && (F = Lt($)), Ct(v), xt(v, Ve, l, y), h.options.enableAutoFreeze && (h.options.updatedValues = (m = h.options.updatedValues) !== null && m !== void 0 ? m : /* @__PURE__ */ new WeakMap(), h.options.updatedValues.set(F, v.original)), Ft(p, s, F);
698
+ const { proxy: c, revoke: u } = Proxy.revocable(o === 1 ? Object.assign([], a) : a, jn);
699
+ if (r.revoke.push(u), Pn.add(c), a.proxy = c, n) {
700
+ const p = n;
701
+ p.finalities.draft.push((d, y) => {
702
+ var m, w;
703
+ const b = C(c);
704
+ let h = p.type === 3 ? p.setMap : p.copy;
705
+ const S = be(h, s), $ = C(S);
706
+ if ($) {
707
+ let F = $.original;
708
+ $.operated && (F = qt(S)), Pt($), jt($, Be, d, y), p.options.enableAutoFreeze && (p.options.updatedValues = (m = p.options.updatedValues) !== null && m !== void 0 ? m : /* @__PURE__ */ new WeakMap(), p.options.updatedValues.set(F, $.original)), Qt(h, s, F);
709
709
  }
710
- (g = w.callbacks) === null || g === void 0 || g.forEach((F) => {
711
- F(l, y);
710
+ (w = b.callbacks) === null || w === void 0 || w.forEach((F) => {
711
+ F(d, y);
712
712
  });
713
713
  });
714
714
  } else {
715
- const h = E(c);
716
- h.finalities.draft.push((l, y) => {
717
- Ct(h), xt(h, Ve, l, y);
715
+ const p = C(c);
716
+ p.finalities.draft.push((d, y) => {
717
+ Pt(p), jt(p, Be, d, y);
718
718
  });
719
719
  }
720
720
  return c;
721
721
  }
722
- Nt.createDraft = In;
722
+ Bt.createDraft = Un;
723
723
  Object.prototype.constructor.toString();
724
- function Ae() {
725
- return Qn();
724
+ function je() {
725
+ return us();
726
726
  }
727
- function as(e, t) {
727
+ function ks(e, t) {
728
728
  return e.localeCompare(t);
729
729
  }
730
- function cs() {
731
- let e = as;
730
+ function Is() {
731
+ let e = ks;
732
732
  if (typeof Intl == "object" && Intl.hasOwnProperty("Collator"))
733
733
  try {
734
734
  e = Intl.Collator("en-US").compare;
@@ -736,8 +736,8 @@ function cs() {
736
736
  }
737
737
  return e;
738
738
  }
739
- cs();
740
- function us() {
739
+ Is();
740
+ function vs() {
741
741
  const t = {
742
742
  __etype: 1,
743
743
  __ops: 1,
@@ -751,8 +751,8 @@ function us() {
751
751
  };
752
752
  return new Set(Object.keys(t));
753
753
  }
754
- const fs = us();
755
- function st(e, t, n) {
754
+ const $s = vs();
755
+ function ct(e, t, n) {
756
756
  const s = {
757
757
  __etype: e,
758
758
  __ops: n
@@ -763,85 +763,85 @@ function st(e, t, n) {
763
763
  return n;
764
764
  if (i === "__etype")
765
765
  return e;
766
- if (fs.has(i))
767
- return (o, a) => st(e, t, [
766
+ if ($s.has(i))
767
+ return (o, a) => ct(e, t, [
768
768
  ...n,
769
769
  a ? [i, e, t, o, a] : [i, e, t, o]
770
770
  ]);
771
771
  }
772
772
  });
773
773
  }
774
- function ds(e, t) {
774
+ function Os(e, t) {
775
775
  return `lookup__${e}__${JSON.stringify(t)}`;
776
776
  }
777
- function kn(e) {
777
+ function Mn(e) {
778
778
  return e.startsWith("lookup__");
779
779
  }
780
- function Xt(e) {
780
+ function an(e) {
781
781
  const [t, n, ...s] = e.split("__");
782
782
  return [n, JSON.parse(s.join("__"))];
783
783
  }
784
- function ls(e) {
784
+ function Es(e) {
785
785
  return new Proxy({
786
786
  __etype: e
787
787
  }, {
788
788
  get(t, n) {
789
789
  if (n === "lookup")
790
- return (r, i) => st(e, Xt(ds(r, i)), []);
790
+ return (r, i) => ct(e, an(Os(r, i)), []);
791
791
  if (n === "__etype")
792
792
  return e;
793
793
  const s = n;
794
- return kn(s) ? st(e, Xt(s), []) : st(e, s, []);
794
+ return Mn(s) ? ct(e, an(s), []) : ct(e, s, []);
795
795
  }
796
796
  });
797
797
  }
798
- function $n() {
798
+ function Dn() {
799
799
  return new Proxy({}, {
800
800
  get(e, t) {
801
- return ls(t);
801
+ return Es(t);
802
802
  }
803
803
  });
804
804
  }
805
- $n();
806
- function hs(e) {
805
+ Dn();
806
+ function Cs(e) {
807
807
  return e.__ops;
808
808
  }
809
- class x extends Error {
809
+ class O extends Error {
810
810
  constructor(n, s, r) {
811
811
  super(n);
812
- d(this, "hint");
813
- d(this, "traceId");
812
+ l(this, "hint");
813
+ l(this, "traceId");
814
814
  this.hint = s, r && (this.traceId = r);
815
815
  const i = new.target.prototype;
816
- Object.setPrototypeOf && Object.setPrototypeOf(this, i), Error.captureStackTrace && Error.captureStackTrace(this, x), this.name = "InstantError";
816
+ Object.setPrototypeOf && Object.setPrototypeOf(this, i), Error.captureStackTrace && Error.captureStackTrace(this, O), this.name = "SidekickError";
817
817
  }
818
818
  get [Symbol.toStringTag]() {
819
- return "InstantError";
819
+ return "SidekickError";
820
820
  }
821
821
  }
822
- class ue extends x {
822
+ class fe extends O {
823
823
  constructor(n) {
824
824
  var i, o;
825
825
  const s = ((i = n.body) == null ? void 0 : i.message) || `API Error (${n.status})`;
826
826
  super(s, n.body.hint, ((o = n.body) == null ? void 0 : o.traceId) || n.body["trace-id"]);
827
- d(this, "body");
828
- d(this, "status");
827
+ l(this, "body");
828
+ l(this, "status");
829
829
  const r = new.target.prototype;
830
- Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, ue), this.name = "InstantAPIError", this.status = n.status, this.body = n.body;
830
+ Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, fe), this.name = "SidekickAPIError", this.status = n.status, this.body = n.body;
831
831
  }
832
832
  get [Symbol.toStringTag]() {
833
- return "InstantAPIError";
833
+ return "SidekickAPIError";
834
834
  }
835
835
  }
836
- typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
837
- const xe = "v2.0.0";
838
- class ce {
836
+ typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__sidekickLogging"), window.localStorage.getItem("__devtoolLocalDash"));
837
+ const Te = "v3.0.0";
838
+ class ue {
839
839
  constructor(t, n, s, r = { indexed: !1, unique: !1 }) {
840
- d(this, "valueType");
841
- d(this, "required");
842
- d(this, "isIndexed");
843
- d(this, "config");
844
- d(this, "metadata", {});
840
+ l(this, "valueType");
841
+ l(this, "required");
842
+ l(this, "isIndexed");
843
+ l(this, "config");
844
+ l(this, "metadata", {});
845
845
  this.valueType = t, this.required = n, this.isIndexed = s, this.config = r;
846
846
  }
847
847
  /**
@@ -850,19 +850,19 @@ class ce {
850
850
  * and enforced for backend
851
851
  */
852
852
  clientRequired() {
853
- return new ce(this.valueType, !1, this.isIndexed, this.config);
853
+ return new ue(this.valueType, !1, this.isIndexed, this.config);
854
854
  }
855
855
  optional() {
856
- return new ce(this.valueType, !1, this.isIndexed, this.config);
856
+ return new ue(this.valueType, !1, this.isIndexed, this.config);
857
857
  }
858
858
  unique() {
859
- return new ce(this.valueType, this.required, this.isIndexed, {
859
+ return new ue(this.valueType, this.required, this.isIndexed, {
860
860
  ...this.config,
861
861
  unique: !0
862
862
  });
863
863
  }
864
864
  indexed() {
865
- return new ce(this.valueType, this.required, !0, {
865
+ return new ue(this.valueType, this.required, !0, {
866
866
  ...this.config,
867
867
  indexed: !0
868
868
  });
@@ -874,7 +874,7 @@ class _ extends Error {
874
874
  super(s), this.name = "QueryValidationError";
875
875
  }
876
876
  }
877
- const Yt = [
877
+ const cn = [
878
878
  "where",
879
879
  "order",
880
880
  "limit",
@@ -887,7 +887,7 @@ const Yt = [
887
887
  "beforeInclusive",
888
888
  "fields",
889
889
  "aggregate"
890
- ], ps = (e) => e.valueType || "unknown", vn = (e, t, n = !1) => {
890
+ ], xs = (e) => e.valueType || "unknown", Nn = (e, t, n = !1) => {
891
891
  if (n || e == null)
892
892
  return !0;
893
893
  switch (t) {
@@ -902,10 +902,10 @@ const Yt = [
902
902
  default:
903
903
  return !0;
904
904
  }
905
- }, ys = (e, t, n, s, r, i, o) => {
906
- const a = i.valueType === "json", c = (u, h, l) => {
907
- if (!vn(l, h, a))
908
- throw new _(`Invalid value for operator '${u}' on attribute '${s}' in entity '${r}'. Expected ${h}, but received: ${typeof l}`, o);
905
+ }, Ts = (e, t, n, s, r, i, o) => {
906
+ const a = i.valueType === "json", c = (u, p, d) => {
907
+ if (!Nn(d, p, a))
908
+ throw new _(`Invalid value for operator '${u}' on attribute '${s}' in entity '${r}'. Expected ${p}, but received: ${typeof d}`, o);
909
909
  };
910
910
  switch (e) {
911
911
  case "in":
@@ -934,29 +934,29 @@ const Yt = [
934
934
  default:
935
935
  throw new _(`Unknown operator '${e}' for attribute '${s}' in entity '${r}'`, o);
936
936
  }
937
- }, Pe = (e, t, n, s, r) => {
938
- const i = ps(n), o = n.valueType === "json";
937
+ }, Ue = (e, t, n, s, r) => {
938
+ const i = xs(n), o = n.valueType === "json";
939
939
  if (typeof e == "object" && e !== null && !Array.isArray(e)) {
940
940
  if (o)
941
941
  return;
942
942
  const c = e;
943
- for (const [u, h] of Object.entries(c))
944
- ys(u, h, i, t, s, n, `${r}.${u}`);
945
- } else if (!vn(e, i, o))
943
+ for (const [u, p] of Object.entries(c))
944
+ Ts(u, p, i, t, s, n, `${r}.${u}`);
945
+ } else if (!Nn(e, i, o))
946
946
  throw new _(`Invalid value for attribute '${t}' in entity '${s}'. Expected ${i}, but received: ${typeof e}`, r);
947
- }, ms = (e, t, n, s, r) => {
947
+ }, _s = (e, t, n, s, r) => {
948
948
  const i = e.split(".");
949
949
  if (i.length < 2)
950
950
  throw new _(`Invalid dot notation path '${e}'. Must contain at least one dot.`, r);
951
951
  let o = n;
952
- for (let h = 0; h < i.length - 1; h++) {
953
- const l = i[h], y = s.entities[o];
952
+ for (let p = 0; p < i.length - 1; p++) {
953
+ const d = i[p], y = s.entities[o];
954
954
  if (!y)
955
955
  throw new _(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`, r);
956
- const m = y.links[l];
956
+ const m = y.links[d];
957
957
  if (!m) {
958
- const g = Object.keys(y.links);
959
- throw new _(`Link '${l}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${g.length > 0 ? g.join(", ") : "none"}`, r);
958
+ const w = Object.keys(y.links);
959
+ throw new _(`Link '${d}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${w.length > 0 ? w.join(", ") : "none"}`, r);
960
960
  }
961
961
  o = m.entityName;
962
962
  }
@@ -964,37 +964,37 @@ const Yt = [
964
964
  if (!c)
965
965
  throw new _(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`, r);
966
966
  if (a === "id") {
967
- if (typeof t == "string" && !Fe(t))
967
+ if (typeof t == "string" && !ze(t))
968
968
  throw new _(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`, r);
969
- Pe(t, e, new ce("string", !1, !0), n, r);
969
+ Ue(t, e, new ue("string", !1, !0), n, r);
970
970
  return;
971
971
  }
972
972
  const u = c.attrs[a];
973
973
  if (Object.keys(c.links).includes(a)) {
974
- if (typeof t == "string" && !Fe(t))
974
+ if (typeof t == "string" && !ze(t))
975
975
  throw new _(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`, r);
976
- Pe(t, e, new ce("string", !1, !0), n, r);
976
+ Ue(t, e, new ue("string", !1, !0), n, r);
977
977
  return;
978
978
  }
979
979
  if (!u) {
980
- const h = Object.keys(c.attrs);
981
- throw new _(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${h.length > 0 ? h.join(", ") + ", id" : "id"}`, r);
980
+ const p = Object.keys(c.attrs);
981
+ throw new _(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${p.length > 0 ? p.join(", ") + ", id" : "id"}`, r);
982
982
  }
983
- Pe(t, e, u, n, r);
984
- }, On = (e, t, n, s) => {
983
+ Ue(t, e, u, n, r);
984
+ }, Ln = (e, t, n, s) => {
985
985
  for (const [r, i] of Object.entries(e)) {
986
986
  if (r === "or" || r === "and") {
987
987
  if (Array.isArray(i))
988
988
  for (const u of i)
989
- typeof u == "object" && u !== null && On(u, t, n, `${s}.${r}[${u}]`);
989
+ typeof u == "object" && u !== null && Ln(u, t, n, `${s}.${r}[${u}]`);
990
990
  continue;
991
991
  }
992
992
  if (r === "id") {
993
- Pe(i, "id", new ce("string", !1, !0), t, `${s}.id`);
993
+ Ue(i, "id", new ue("string", !1, !0), t, `${s}.id`);
994
994
  continue;
995
995
  }
996
996
  if (r.includes(".")) {
997
- ms(r, i, t, n, `${s}.${r}`);
997
+ _s(r, i, t, n, `${s}.${r}`);
998
998
  continue;
999
999
  }
1000
1000
  const o = n.entities[t];
@@ -1002,22 +1002,22 @@ const Yt = [
1002
1002
  continue;
1003
1003
  const a = o.attrs[r], c = o.links[r];
1004
1004
  if (!a && !c) {
1005
- const u = Object.keys(o.attrs), h = Object.keys(o.links);
1006
- throw new _(`Attribute or link '${r}' does not exist on entity '${t}'. Available attributes: ${u.length > 0 ? u.join(", ") : "none"}. Available links: ${h.length > 0 ? h.join(", ") : "none"}`, `${s}.${r}`);
1005
+ const u = Object.keys(o.attrs), p = Object.keys(o.links);
1006
+ throw new _(`Attribute or link '${r}' does not exist on entity '${t}'. Available attributes: ${u.length > 0 ? u.join(", ") : "none"}. Available links: ${p.length > 0 ? p.join(", ") : "none"}`, `${s}.${r}`);
1007
1007
  }
1008
1008
  if (a)
1009
- Pe(i, r, a, t, `${s}.${r}`);
1009
+ Ue(i, r, a, t, `${s}.${r}`);
1010
1010
  else if (c) {
1011
- if (typeof i == "string" && !Fe(i))
1011
+ if (typeof i == "string" && !ze(i))
1012
1012
  throw new _(`Invalid value for link '${r}' in entity '${t}'. Expected a UUID, but received: ${i}`, `${s}.${r}`);
1013
- const u = new ce("string", !1, !0);
1014
- Pe(i, r, u, t, `${s}.${r}`);
1013
+ const u = new ue("string", !1, !0);
1014
+ Ue(i, r, u, t, `${s}.${r}`);
1015
1015
  }
1016
1016
  }
1017
- }, bs = (e, t, n, s, r = 0) => {
1017
+ }, As = (e, t, n, s, r = 0) => {
1018
1018
  for (const o of Object.keys(e))
1019
- if (!Yt.includes(o))
1020
- throw new _(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Yt.join(", ")}. Found: ${o}`, s);
1019
+ if (!cn.includes(o))
1020
+ throw new _(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${cn.join(", ")}. Found: ${o}`, s);
1021
1021
  const i = [
1022
1022
  // 'limit', // only supported client side
1023
1023
  "offset",
@@ -1034,9 +1034,9 @@ const Yt = [
1034
1034
  if (e.where && n) {
1035
1035
  if (typeof e.where != "object" || e.where === null)
1036
1036
  throw new _(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`, s ? `${s}.where` : void 0);
1037
- On(e.where, t, n, s ? `${s}.where` : "where");
1037
+ Ln(e.where, t, n, s ? `${s}.where` : "where");
1038
1038
  }
1039
- }, En = (e, t, n, s, r = 0) => {
1039
+ }, Fn = (e, t, n, s, r = 0) => {
1040
1040
  var i;
1041
1041
  if (!e || typeof e != "object")
1042
1042
  throw new _(`Query part for entity '${t}' must be an object, but received: ${typeof e}`, s);
@@ -1049,15 +1049,15 @@ const Yt = [
1049
1049
  const a = e[o];
1050
1050
  if (typeof a == "object" && a !== null) {
1051
1051
  const c = (i = n == null ? void 0 : n.entities[t].links[o]) == null ? void 0 : i.entityName;
1052
- c && En(a, c, n, `${s}.${o}`, r + 1);
1052
+ c && Fn(a, c, n, `${s}.${o}`, r + 1);
1053
1053
  }
1054
1054
  } else {
1055
1055
  const a = e[o];
1056
1056
  if (typeof a != "object" || a === null)
1057
1057
  throw new _(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`, `${s}.$`);
1058
- bs(a, t, n, `${s}.$`, r);
1058
+ As(a, t, n, `${s}.$`, r);
1059
1059
  }
1060
- }, Zt = (e, t) => {
1060
+ }, un = (e, t) => {
1061
1061
  if (typeof e != "object" || e === null)
1062
1062
  throw new _(`Query must be an object, but received: ${typeof e}${e === null ? " (null)" : ""}`);
1063
1063
  if (Array.isArray(e))
@@ -1073,77 +1073,77 @@ const Yt = [
1073
1073
  const r = Object.keys(t.entities);
1074
1074
  throw new _(`Entity '${s}' does not exist in schema. Available entities: ${r.length > 0 ? r.join(", ") : "none"}`, s);
1075
1075
  }
1076
- En(n[s], s, t, s, 0);
1076
+ Fn(n[s], s, t, s, 0);
1077
1077
  }
1078
1078
  }
1079
- }, en = (e) => typeof e != "string" ? !1 : kn(e) ? !0 : Fe(e);
1079
+ }, fn = (e) => typeof e != "string" ? !1 : Mn(e) ? !0 : ze(e);
1080
1080
  class Z extends Error {
1081
1081
  constructor(t) {
1082
1082
  super(t), this.name = "TransactionValidationError";
1083
1083
  }
1084
1084
  }
1085
- const Cn = (e) => e.length > 0 ? e.join(", ") : "none", gs = (e, t) => new Z(`Entity '${e}' does not exist in schema. Available entities: ${Cn(t)}`), kt = {
1085
+ const Wn = (e) => e.length > 0 ? e.join(", ") : "none", Rs = (e, t) => new Z(`Entity '${e}' does not exist in schema. Available entities: ${Wn(t)}`), xt = {
1086
1086
  string: (e) => typeof e == "string",
1087
1087
  number: (e) => typeof e == "number" && !isNaN(e),
1088
1088
  boolean: (e) => typeof e == "boolean",
1089
1089
  date: (e) => e instanceof Date || typeof e == "string" || typeof e == "number",
1090
1090
  json: () => !0
1091
- }, ws = (e, t) => {
1091
+ }, Ps = (e, t) => {
1092
1092
  var n;
1093
- return e == null ? !0 : ((n = kt[t.valueType]) == null ? void 0 : n.call(kt, e)) ?? !1;
1094
- }, xn = (e, t) => {
1093
+ return e == null ? !0 : ((n = xt[t.valueType]) == null ? void 0 : n.call(xt, e)) ?? !1;
1094
+ }, zn = (e, t) => {
1095
1095
  const n = t.entities[e];
1096
1096
  if (!n)
1097
- throw gs(e, Object.keys(t.entities));
1097
+ throw Rs(e, Object.keys(t.entities));
1098
1098
  return n;
1099
- }, $t = (e, t, n) => {
1100
- const s = xn(e, n);
1099
+ }, Tt = (e, t, n) => {
1100
+ const s = zn(e, n);
1101
1101
  if (typeof t != "object" || t === null)
1102
1102
  throw new Z(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);
1103
1103
  for (const [r, i] of Object.entries(t)) {
1104
1104
  if (r === "id")
1105
1105
  continue;
1106
1106
  const o = s.attrs[r];
1107
- if (o && !ws(i, o))
1107
+ if (o && !Ps(i, o))
1108
1108
  throw new Z(`Invalid value for attribute '${r}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof i}`);
1109
1109
  }
1110
- }, tn = (e, t, n) => {
1111
- const s = xn(e, n);
1110
+ }, dn = (e, t, n) => {
1111
+ const s = zn(e, n);
1112
1112
  if (typeof t != "object" || t === null)
1113
1113
  throw new Z(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);
1114
1114
  for (const [r, i] of Object.entries(t)) {
1115
1115
  if (!s.links[r]) {
1116
1116
  const a = Object.keys(s.links);
1117
- throw new Z(`Link '${r}' does not exist on entity '${e}'. Available links: ${Cn(a)}`);
1117
+ throw new Z(`Link '${r}' does not exist on entity '${e}'. Available links: ${Wn(a)}`);
1118
1118
  }
1119
1119
  if (i != null) {
1120
1120
  if (Array.isArray(i)) {
1121
1121
  for (const a of i)
1122
- if (!en(a))
1122
+ if (!fn(a))
1123
1123
  throw new Z(`Invalid entity ID in link '${r}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`);
1124
- } else if (!en(i))
1124
+ } else if (!fn(i))
1125
1125
  throw new Z(`Invalid UUID in link '${r}' for entity '${e}'. Expected a UUID, but received: ${i}`);
1126
1126
  }
1127
1127
  }
1128
- }, Ss = {
1129
- create: $t,
1130
- update: $t,
1131
- merge: $t,
1132
- link: tn,
1133
- unlink: tn,
1128
+ }, js = {
1129
+ create: Tt,
1130
+ update: Tt,
1131
+ merge: Tt,
1132
+ link: dn,
1133
+ unlink: dn,
1134
1134
  delete: () => {
1135
1135
  }
1136
- }, Is = (e, t) => {
1136
+ }, Us = (e, t) => {
1137
1137
  if (!t)
1138
1138
  return;
1139
1139
  const [n, s, r, i] = e;
1140
- if (!Array.isArray(r) && !Fe(r))
1140
+ if (!Array.isArray(r) && !ze(r))
1141
1141
  throw new Z(`Invalid id for entity '${s}'. Expected a UUID, but received: ${r}`);
1142
1142
  if (typeof s != "string")
1143
1143
  throw new Z(`Entity name must be a string, but received: ${typeof s}`);
1144
- const o = Ss[n];
1144
+ const o = js[n];
1145
1145
  o && i !== void 0 && o(s, i, t);
1146
- }, ks = (e, t) => {
1146
+ }, Ms = (e, t) => {
1147
1147
  const n = Array.isArray(e) ? e : [e];
1148
1148
  for (const s of n) {
1149
1149
  if (!s || typeof s != "object")
@@ -1153,37 +1153,43 @@ const Cn = (e) => e.length > 0 ? e.join(", ") : "none", gs = (e, t) => new Z(`En
1153
1153
  for (const r of s.__ops) {
1154
1154
  if (!Array.isArray(r))
1155
1155
  throw new Z(`Transaction operation must be an array, but received: ${typeof r}`);
1156
- Is(r, t);
1156
+ Us(r, t);
1157
1157
  }
1158
1158
  }
1159
1159
  };
1160
- let $s = 0;
1161
- class vs {
1160
+ let Ds = 0;
1161
+ function Ns(e, t) {
1162
+ for (const n of e)
1163
+ try {
1164
+ t(n);
1165
+ } catch (s) {
1166
+ setTimeout(() => {
1167
+ throw s;
1168
+ });
1169
+ }
1170
+ }
1171
+ class Ls {
1162
1172
  constructor(t, n, s) {
1163
- d(this, "type", "sse");
1164
- d(this, "initParams", null);
1165
- d(this, "sendQueue", []);
1166
- d(this, "sendPromise");
1167
- d(this, "closeFired", !1);
1168
- d(this, "sseInitTimeout");
1169
- d(this, "ES");
1170
- d(this, "messageUrl");
1171
- d(this, "conn");
1172
- d(this, "url");
1173
- d(this, "id");
1174
- d(this, "onopen");
1175
- d(this, "onmessage");
1176
- d(this, "onclose");
1177
- d(this, "onerror");
1178
- this.id = `${this.type}_${$s++}`, this.url = n, this.messageUrl = s || this.url, this.ES = t, this.conn = new t(n), this.sseInitTimeout = setTimeout(() => {
1173
+ l(this, "type", "sse");
1174
+ l(this, "initParams", null);
1175
+ l(this, "sendQueue", []);
1176
+ l(this, "sendPromise");
1177
+ l(this, "closeFired", !1);
1178
+ l(this, "sseInitTimeout");
1179
+ l(this, "ES");
1180
+ l(this, "messageUrl");
1181
+ l(this, "conn");
1182
+ l(this, "url");
1183
+ l(this, "id");
1184
+ l(this, "onopen");
1185
+ l(this, "onmessage");
1186
+ l(this, "onclose");
1187
+ l(this, "onerror");
1188
+ this.id = `${this.type}_${Ds++}`, this.url = n, this.messageUrl = s || this.url, this.ES = t, this.conn = new t(n), this.sseInitTimeout = setTimeout(() => {
1179
1189
  this.initParams || this.handleError();
1180
1190
  }, 1e4), this.conn.onmessage = (r) => {
1181
1191
  const i = JSON.parse(r.data);
1182
- if (Array.isArray(i))
1183
- for (const o of i)
1184
- this.handleMessage(o);
1185
- else
1186
- this.handleMessage(i);
1192
+ Array.isArray(i) ? Ns(i, (o) => this.handleMessage(o)) : this.handleMessage(i);
1187
1193
  }, this.conn.onerror = (r) => {
1188
1194
  this.handleError();
1189
1195
  };
@@ -1255,86 +1261,86 @@ class vs {
1255
1261
  this.handleClose();
1256
1262
  }
1257
1263
  }
1258
- var nn;
1264
+ var ln;
1259
1265
  (function(e) {
1260
1266
  e.InitialSyncBatch = "InitialSyncBatch", e.InitialSyncComplete = "InitialSyncComplete", e.LoadFromStorage = "LoadFromStorage", e.SyncTransaction = "SyncTransaction", e.Error = "Error";
1261
- })(nn || (nn = {}));
1262
- function Os({ WStream: e, opts: t, startStream: n, appendStream: s, registerStream: r }) {
1267
+ })(ln || (ln = {}));
1268
+ function Fs({ WStream: e, opts: t, startStream: n, appendStream: s, registerStream: r }) {
1263
1269
  const i = t.clientId;
1264
1270
  let o = null, a = null, c = null;
1265
- const u = Ae();
1266
- let h = !1, l = !1;
1267
- const y = [], m = [], g = [];
1268
- let w = !1, p = 0, $ = 0;
1269
- const v = [], F = new TextEncoder();
1270
- function be() {
1271
- l = !0;
1272
- for (const b of y)
1273
- b(a ?? void 0);
1274
- }
1275
- function bt(b) {
1276
- return y.push(b), l && b(a ?? void 0), () => {
1277
- const I = y.indexOf(b);
1278
- I !== -1 && y.splice(I, 1);
1271
+ const u = je();
1272
+ let p = !1, d = !1;
1273
+ const y = [], m = [], w = [];
1274
+ let b = !1, h = 0, S = 0;
1275
+ const $ = [], F = new TextEncoder();
1276
+ function ge() {
1277
+ d = !0;
1278
+ for (const g of y)
1279
+ g(a ?? void 0);
1280
+ }
1281
+ function vt(g) {
1282
+ return y.push(g), d && g(a ?? void 0), () => {
1283
+ const v = y.indexOf(g);
1284
+ v !== -1 && y.splice(v, 1);
1279
1285
  };
1280
1286
  }
1281
- function Jt(b) {
1282
- return g.push(b), () => {
1283
- const I = g.indexOf(b);
1284
- I !== -1 && g.splice(I, 1);
1287
+ function en(g) {
1288
+ return w.push(g), () => {
1289
+ const v = w.indexOf(g);
1290
+ v !== -1 && w.splice(v, 1);
1285
1291
  };
1286
1292
  }
1287
- t.waitUntil && t.waitUntil(new Promise((b) => {
1288
- g.push(b);
1293
+ t.waitUntil && t.waitUntil(new Promise((g) => {
1294
+ w.push(g);
1289
1295
  }));
1290
- function R() {
1291
- for (const b of g)
1296
+ function A() {
1297
+ for (const g of w)
1292
1298
  try {
1293
- b();
1299
+ g();
1294
1300
  } catch {
1295
1301
  }
1296
1302
  }
1297
- function C(b) {
1298
- return m.push(b), o && b(o), () => {
1299
- const I = m.indexOf(b);
1300
- I !== -1 && m.splice(I, 1);
1303
+ function x(g) {
1304
+ return m.push(g), o && g(o), () => {
1305
+ const v = m.indexOf(g);
1306
+ v !== -1 && m.splice(v, 1);
1301
1307
  };
1302
1308
  }
1303
- function ee(b) {
1304
- o = b;
1305
- for (const I of m)
1306
- I(o);
1309
+ function ee(g) {
1310
+ o = g;
1311
+ for (const v of m)
1312
+ v(o);
1307
1313
  }
1308
1314
  function T() {
1309
- w = !0;
1315
+ b = !0;
1310
1316
  }
1311
- function U(b) {
1312
- let I = p, N = 0, Q = 0;
1313
- for (const { byteLen: te } of v) {
1314
- const oe = I + te;
1315
- if (oe > b)
1317
+ function U(g) {
1318
+ let v = h, N = 0, Q = 0;
1319
+ for (const { byteLen: te } of $) {
1320
+ const oe = v + te;
1321
+ if (oe > g)
1316
1322
  break;
1317
- I = oe, N++, Q += te;
1323
+ v = oe, N++, Q += te;
1318
1324
  }
1319
- N > 0 && (p += Q, $ -= Q, v.splice(0, N));
1325
+ N > 0 && (h += Q, S -= Q, $.splice(0, N));
1320
1326
  }
1321
- function j(b, I) {
1322
- a = I, be(), b.error(I), R();
1327
+ function j(g, v) {
1328
+ a = v, ge(), g.error(v), A();
1323
1329
  }
1324
1330
  async function Y() {
1325
- const b = await n({
1331
+ const g = await n({
1326
1332
  clientId: i,
1327
1333
  reconnectToken: u,
1328
1334
  ruleParams: t.ruleParams
1329
1335
  });
1330
- switch (b.type) {
1336
+ switch (g.type) {
1331
1337
  case "ok": {
1332
- const { streamId: I, offset: N } = b;
1333
- o = I, U(N), v.length && s({
1334
- streamId: I,
1335
- chunks: v.map((Q) => Q.chunk),
1336
- offset: p
1337
- }), w = !1;
1338
+ const { streamId: v, offset: N } = g;
1339
+ o = v, U(N), $.length && s({
1340
+ streamId: v,
1341
+ chunks: $.map((Q) => Q.chunk),
1342
+ offset: h
1343
+ }), b = !1;
1338
1344
  break;
1339
1345
  }
1340
1346
  case "disconnect": {
@@ -1342,26 +1348,26 @@ function Os({ WStream: e, opts: t, startStream: n, appendStream: s, registerStre
1342
1348
  break;
1343
1349
  }
1344
1350
  case "error": {
1345
- c && j(c, b.error);
1351
+ c && j(c, g.error);
1346
1352
  break;
1347
1353
  }
1348
1354
  }
1349
1355
  }
1350
- function z() {
1356
+ function W() {
1351
1357
  T(), Y();
1352
1358
  }
1353
- function Ye({ offset: b, done: I }) {
1354
- U(b), I && (h = !0, R());
1359
+ function nt({ offset: g, done: v }) {
1360
+ U(g), v && (p = !0, A());
1355
1361
  }
1356
- function Ht(b) {
1357
- return h ? (j(b, new x("Stream has been closed.")), null) : o || (j(b, new x("Stream has not been initialized.")), null);
1362
+ function tn(g) {
1363
+ return p ? (j(g, new O("Stream has been closed.")), null) : o || (j(g, new O("Stream has not been initialized.")), null);
1358
1364
  }
1359
- async function _e(b) {
1360
- c = b;
1361
- let I = !0, N = 0;
1362
- for (; I; ) {
1365
+ async function Ae(g) {
1366
+ c = g;
1367
+ let v = !0, N = 0;
1368
+ for (; v; ) {
1363
1369
  let Q = Date.now() + Math.min(15e3, 500 * (N - 1));
1364
- I = !1;
1370
+ v = !1;
1365
1371
  const te = await n({
1366
1372
  clientId: t.clientId,
1367
1373
  reconnectToken: u,
@@ -1369,100 +1375,100 @@ function Os({ WStream: e, opts: t, startStream: n, appendStream: s, registerStre
1369
1375
  });
1370
1376
  switch (te.type) {
1371
1377
  case "ok": {
1372
- const { streamId: oe, offset: gt } = te;
1373
- if (gt !== 0) {
1374
- const ge = new x("Write stream is corrupted");
1375
- j(b, ge);
1378
+ const { streamId: oe, offset: $t } = te;
1379
+ if ($t !== 0) {
1380
+ const we = new O("Write stream is corrupted");
1381
+ j(g, we);
1376
1382
  return;
1377
1383
  }
1378
1384
  ee(oe), r(oe, {
1379
1385
  onDisconnect: T,
1380
- onFlush: Ye,
1386
+ onFlush: nt,
1381
1387
  onConnectionReconnect: Y,
1382
- onAppendFailed: z
1383
- }), w = !1;
1388
+ onAppendFailed: W
1389
+ }), b = !1;
1384
1390
  return;
1385
1391
  }
1386
1392
  case "disconnect": {
1387
- I = !0, T(), N++, await new Promise((oe) => {
1393
+ v = !0, T(), N++, await new Promise((oe) => {
1388
1394
  setTimeout(oe, Math.max(0, Q - Date.now()));
1389
1395
  });
1390
1396
  break;
1391
1397
  }
1392
1398
  case "error": {
1393
- j(b, te.error);
1399
+ j(g, te.error);
1394
1400
  return;
1395
1401
  }
1396
1402
  }
1397
1403
  }
1398
1404
  }
1399
- class de extends e {
1400
- constructor(I, N) {
1401
- super(I, N);
1405
+ class le extends e {
1406
+ constructor(v, N) {
1407
+ super(v, N);
1402
1408
  }
1403
1409
  async streamId() {
1404
- return o || new Promise((I, N) => {
1410
+ return o || new Promise((v, N) => {
1405
1411
  const Q = [], te = () => {
1406
- for (const ge of Q)
1407
- ge();
1408
- }, oe = (ge) => {
1409
- I(ge), te();
1410
- }, gt = (ge) => {
1411
- N(ge || new x("Stream is closed.")), te();
1412
+ for (const we of Q)
1413
+ we();
1414
+ }, oe = (we) => {
1415
+ v(we), te();
1416
+ }, $t = (we) => {
1417
+ N(we || new O("Stream is closed.")), te();
1412
1418
  };
1413
- Q.push(C(oe)), Q.push(bt(gt));
1419
+ Q.push(x(oe)), Q.push(vt($t));
1414
1420
  });
1415
1421
  }
1416
1422
  }
1417
1423
  return {
1418
- stream: new de({
1424
+ stream: new le({
1419
1425
  // TODO(dww): accept a storage so that write streams can survive across
1420
1426
  // browser restarts
1421
- async start(b) {
1427
+ async start(g) {
1422
1428
  try {
1423
- await _e(b);
1424
- } catch (I) {
1425
- j(b, I);
1429
+ await Ae(g);
1430
+ } catch (v) {
1431
+ j(g, v);
1426
1432
  }
1427
1433
  },
1428
- write(b, I) {
1429
- const N = Ht(I);
1434
+ write(g, v) {
1435
+ const N = tn(v);
1430
1436
  if (N) {
1431
- const Q = F.encode(b).length;
1432
- v.push({ chunk: b, byteLen: Q });
1433
- const te = p + $;
1434
- $ += Q, w || s({ streamId: N, chunks: [b], offset: te });
1437
+ const Q = F.encode(g).length;
1438
+ $.push({ chunk: g, byteLen: Q });
1439
+ const te = h + S;
1440
+ S += Q, b || s({ streamId: N, chunks: [g], offset: te });
1435
1441
  }
1436
1442
  },
1437
1443
  close() {
1438
1444
  o ? s({
1439
1445
  streamId: o,
1440
1446
  chunks: [],
1441
- offset: p + $,
1447
+ offset: h + S,
1442
1448
  isDone: !0
1443
- }) : R(), be();
1449
+ }) : A(), ge();
1444
1450
  },
1445
- abort(b) {
1451
+ abort(g) {
1446
1452
  o ? s({
1447
1453
  streamId: o,
1448
1454
  chunks: [],
1449
- offset: p + $,
1455
+ offset: h + S,
1450
1456
  isDone: !0,
1451
- abortReason: b
1452
- }) : R(), be();
1457
+ abortReason: g
1458
+ }) : A(), ge();
1453
1459
  }
1454
1460
  }),
1455
- addCompleteCb: Jt,
1461
+ addCompleteCb: en,
1456
1462
  closed() {
1457
- return l;
1463
+ return d;
1458
1464
  }
1459
1465
  };
1460
1466
  }
1461
- class Es {
1467
+ class Ws {
1462
1468
  constructor() {
1463
- d(this, "items", []);
1464
- d(this, "resolvers", []);
1465
- d(this, "isClosed", !1);
1469
+ l(this, "items", []);
1470
+ l(this, "resolvers", []);
1471
+ l(this, "isClosed", !1);
1466
1472
  }
1467
1473
  push(t) {
1468
1474
  if (this.isClosed)
@@ -1492,51 +1498,51 @@ class Es {
1492
1498
  }
1493
1499
  }
1494
1500
  }
1495
- function Cs({ RStream: e, opts: t, startStream: n, cancelStream: s }) {
1501
+ function zs({ RStream: e, opts: t, startStream: n, cancelStream: s }) {
1496
1502
  let r = t.byteOffset || 0, i = !1;
1497
1503
  const o = new TextDecoder("utf-8"), a = new TextEncoder();
1498
1504
  let c, u = !1;
1499
- const h = [], l = [];
1505
+ const p = [], d = [];
1500
1506
  let y = null, m = null;
1501
- function g(R) {
1507
+ function w(A) {
1502
1508
  u = !0;
1503
- for (const C of h)
1504
- C(R);
1509
+ for (const x of p)
1510
+ x(A);
1505
1511
  }
1506
- function w(R) {
1507
- return h.push(R), () => {
1508
- const C = h.indexOf(R);
1509
- C !== -1 && h.splice(C, 1);
1512
+ function b(A) {
1513
+ return p.push(A), () => {
1514
+ const x = p.indexOf(A);
1515
+ x !== -1 && p.splice(x, 1);
1510
1516
  };
1511
1517
  }
1512
- function p(R) {
1513
- return l.push(R), y && R(y), () => {
1514
- const C = l.indexOf(R);
1515
- C !== -1 && l.splice(C, 1);
1518
+ function h(A) {
1519
+ return d.push(A), y && A(y), () => {
1520
+ const x = d.indexOf(A);
1521
+ x !== -1 && d.splice(x, 1);
1516
1522
  };
1517
1523
  }
1518
- function $(R, C) {
1519
- m = C, R.error(C), g(C);
1524
+ function S(A, x) {
1525
+ m = x, A.error(x), w(x);
1520
1526
  }
1521
- let v = 0;
1522
- async function F(R, C) {
1523
- c = Ae();
1524
- const ee = { ...R || {}, eventId: c };
1527
+ let $ = 0;
1528
+ async function F(A, x) {
1529
+ c = je();
1530
+ const ee = { ...A || {}, eventId: c };
1525
1531
  for await (const T of n(ee)) {
1526
1532
  if (i)
1527
1533
  return;
1528
1534
  if (T.type === "reconnect")
1529
1535
  return { retry: !0 };
1530
1536
  if (T.type === "error") {
1531
- $(C, T.error);
1537
+ S(x, T.error);
1532
1538
  return;
1533
1539
  }
1534
1540
  if (T.offset > r) {
1535
- $(C, new x("Stream is corrupted.")), i = !0;
1541
+ S(x, new O("Stream is corrupted.")), i = !0;
1536
1542
  return;
1537
1543
  }
1538
1544
  y = T.streamId;
1539
- for (const j of l)
1545
+ for (const j of d)
1540
1546
  j(y);
1541
1547
  let U = r - T.offset;
1542
1548
  if (T.files && T.files.length) {
@@ -1544,126 +1550,126 @@ function Cs({ RStream: e, opts: t, startStream: n, cancelStream: s }) {
1544
1550
  let Y = fetch(T.files[0].url, {
1545
1551
  signal: j.signal
1546
1552
  });
1547
- for (let z = 0; z < T.files.length; z++) {
1548
- const Ye = T.files[z + 1], _e = await Y;
1549
- if (Ye && (Y = fetch(Ye.url, { signal: j.signal })), !_e.ok) {
1550
- if (v++, v > 10) {
1551
- $(C, new x("Unable to process stream."));
1553
+ for (let W = 0; W < T.files.length; W++) {
1554
+ const nt = T.files[W + 1], Ae = await Y;
1555
+ if (nt && (Y = fetch(nt.url, { signal: j.signal })), !Ae.ok) {
1556
+ if ($++, $ > 10) {
1557
+ S(x, new O("Unable to process stream."));
1552
1558
  return;
1553
1559
  }
1554
1560
  return { retry: !0 };
1555
1561
  }
1556
- if (_e.body) {
1557
- const de = _e.body.getReader();
1562
+ if (Ae.body) {
1563
+ const le = Ae.body.getReader();
1558
1564
  try {
1559
1565
  for (; ; ) {
1560
- const { done: le, value: b } = await de.read();
1561
- if (le)
1566
+ const { done: he, value: g } = await le.read();
1567
+ if (he)
1562
1568
  break;
1563
1569
  if (i) {
1564
1570
  j.abort();
1565
1571
  return;
1566
1572
  }
1567
- let I = b;
1568
- if (U > 0 && (I = b.subarray(U), U -= b.length - I.length), !I.length)
1573
+ let v = g;
1574
+ if (U > 0 && (v = g.subarray(U), U -= g.length - v.length), !v.length)
1569
1575
  continue;
1570
- r += I.length;
1571
- const N = o.decode(I);
1572
- C.enqueue(N);
1576
+ r += v.length;
1577
+ const N = o.decode(v);
1578
+ x.enqueue(N);
1573
1579
  }
1574
1580
  } finally {
1575
- de.releaseLock();
1581
+ le.releaseLock();
1576
1582
  }
1577
1583
  } else {
1578
- const de = await _e.arrayBuffer();
1579
- let le = de;
1584
+ const le = await Ae.arrayBuffer();
1585
+ let he = le;
1580
1586
  if (i) {
1581
1587
  j.abort();
1582
1588
  return;
1583
1589
  }
1584
- if (U > 0 && (le = new Uint8Array(de).subarray(U), U -= de.byteLength - le.length), !le.byteLength)
1590
+ if (U > 0 && (he = new Uint8Array(le).subarray(U), U -= le.byteLength - he.length), !he.byteLength)
1585
1591
  continue;
1586
- r += le.byteLength;
1587
- const b = o.decode(le);
1588
- C.enqueue(b);
1592
+ r += he.byteLength;
1593
+ const g = o.decode(he);
1594
+ x.enqueue(g);
1589
1595
  }
1590
1596
  }
1591
1597
  }
1592
- if (v = 0, T.content) {
1598
+ if ($ = 0, T.content) {
1593
1599
  let j = T.content, Y = a.encode(T.content);
1594
1600
  if (U > 0) {
1595
- const z = Y.subarray(U);
1596
- if (U -= Y.length - z.length, !z.length)
1601
+ const W = Y.subarray(U);
1602
+ if (U -= Y.length - W.length, !W.length)
1597
1603
  continue;
1598
- Y = z, j = o.decode(z);
1604
+ Y = W, j = o.decode(W);
1599
1605
  }
1600
- r += Y.length, C.enqueue(j);
1606
+ r += Y.length, x.enqueue(j);
1601
1607
  }
1602
1608
  }
1603
1609
  }
1604
- async function be(R) {
1605
- let C = !0, ee = 0;
1606
- for (; C; ) {
1607
- C = !1;
1610
+ async function ge(A) {
1611
+ let x = !0, ee = 0;
1612
+ for (; x; ) {
1613
+ x = !1;
1608
1614
  let T = Date.now() + Math.min(15e3, 500 * (ee - 1));
1609
- const U = await F({ ...t, offset: r }, R);
1610
- U != null && U.retry && (C = !0, ee++, T < Date.now() - 3e5 && (ee = 0), await new Promise((j) => {
1615
+ const U = await F({ ...t, offset: r }, A);
1616
+ U != null && U.retry && (x = !0, ee++, T < Date.now() - 3e5 && (ee = 0), await new Promise((j) => {
1611
1617
  setTimeout(j, Math.max(0, T - Date.now()));
1612
1618
  }));
1613
1619
  }
1614
- !i && !u && (R.close(), g());
1620
+ !i && !u && (A.close(), w());
1615
1621
  }
1616
- class bt extends e {
1617
- constructor(C, ee) {
1618
- super(C, ee);
1622
+ class vt extends e {
1623
+ constructor(x, ee) {
1624
+ super(x, ee);
1619
1625
  }
1620
1626
  async streamId() {
1621
1627
  if (y)
1622
1628
  return y;
1623
1629
  if (m)
1624
1630
  throw m;
1625
- return new Promise((C, ee) => {
1631
+ return new Promise((x, ee) => {
1626
1632
  const T = [], U = () => {
1627
- for (const z of T)
1628
- z();
1629
- }, j = (z) => {
1630
- C(z), U();
1631
- }, Y = (z) => {
1632
- ee(z || new x("Stream is closed.")), U();
1633
+ for (const W of T)
1634
+ W();
1635
+ }, j = (W) => {
1636
+ x(W), U();
1637
+ }, Y = (W) => {
1638
+ ee(W || new O("Stream is closed.")), U();
1633
1639
  };
1634
- T.push(p(j)), T.push(w(Y));
1640
+ T.push(h(j)), T.push(b(Y));
1635
1641
  });
1636
1642
  }
1637
1643
  }
1638
1644
  return {
1639
- stream: new bt({
1640
- start(R) {
1641
- be(R);
1645
+ stream: new vt({
1646
+ start(A) {
1647
+ ge(A);
1642
1648
  },
1643
- cancel(R) {
1644
- i = !0, c && s({ eventId: c }), g();
1649
+ cancel(A) {
1650
+ i = !0, c && s({ eventId: c }), w();
1645
1651
  }
1646
1652
  }),
1647
- addCloseCb: w,
1653
+ addCloseCb: b,
1648
1654
  closed() {
1649
1655
  return u;
1650
1656
  }
1651
1657
  };
1652
1658
  }
1653
- class xs {
1659
+ class Ks {
1654
1660
  constructor({ WStream: t, RStream: n, trySend: s, log: r }) {
1655
- d(this, "trySend");
1656
- d(this, "WStream");
1657
- d(this, "RStream");
1658
- d(this, "writeStreams", {});
1659
- d(this, "startWriteStreamCbs", {});
1660
- d(this, "readStreamIterators", {});
1661
- d(this, "log");
1662
- d(this, "activeStreams", /* @__PURE__ */ new Set());
1661
+ l(this, "trySend");
1662
+ l(this, "WStream");
1663
+ l(this, "RStream");
1664
+ l(this, "writeStreams", {});
1665
+ l(this, "startWriteStreamCbs", {});
1666
+ l(this, "readStreamIterators", {});
1667
+ l(this, "log");
1668
+ l(this, "activeStreams", /* @__PURE__ */ new Set());
1663
1669
  this.WStream = t, this.RStream = n, this.trySend = s, this.log = r;
1664
1670
  }
1665
1671
  createWriteStream(t) {
1666
- const { stream: n, addCompleteCb: s } = Os({
1672
+ const { stream: n, addCompleteCb: s } = Fs({
1667
1673
  WStream: this.WStream,
1668
1674
  startStream: this.startWriteStream.bind(this),
1669
1675
  appendStream: this.appendStream.bind(this),
@@ -1675,7 +1681,7 @@ class xs {
1675
1681
  }), n;
1676
1682
  }
1677
1683
  createReadStream(t) {
1678
- const { stream: n, addCloseCb: s } = Cs({
1684
+ const { stream: n, addCloseCb: s } = zs({
1679
1685
  RStream: this.RStream,
1680
1686
  opts: t,
1681
1687
  startStream: this.startReadStream.bind(this),
@@ -1686,7 +1692,7 @@ class xs {
1686
1692
  }), n;
1687
1693
  }
1688
1694
  startWriteStream(t) {
1689
- const n = Ae();
1695
+ const n = je();
1690
1696
  let s = null;
1691
1697
  const r = new Promise((o) => {
1692
1698
  s = o;
@@ -1710,7 +1716,7 @@ class xs {
1710
1716
  offset: r,
1711
1717
  done: !!s
1712
1718
  };
1713
- i && (o["abort-reason"] = i), this.trySend(Ae(), o);
1719
+ i && (o["abort-reason"] = i), this.trySend(je(), o);
1714
1720
  }
1715
1721
  onAppendFailed(t) {
1716
1722
  const n = this.writeStreams[t["stream-id"]];
@@ -1737,7 +1743,7 @@ class xs {
1737
1743
  if (!s && !n)
1738
1744
  throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");
1739
1745
  s && (o["stream-id"] = s), n && (o["client-id"] = n), r && (o.offset = r), i && (o["rule-params"] = i);
1740
- const a = new Es();
1746
+ const a = new Ws();
1741
1747
  return this.readStreamIterators[t] = a, this.trySend(t, o), a;
1742
1748
  }
1743
1749
  cancelReadStream({ eventId: t }) {
@@ -1745,7 +1751,7 @@ class xs {
1745
1751
  op: "unsubscribe-stream",
1746
1752
  "subscribe-event-id": t
1747
1753
  };
1748
- this.trySend(Ae(), n), delete this.readStreamIterators[t];
1754
+ this.trySend(je(), n), delete this.readStreamIterators[t];
1749
1755
  }
1750
1756
  onStreamAppend(t) {
1751
1757
  const n = t["client-event-id"], s = this.readStreamIterators[n];
@@ -1756,7 +1762,7 @@ class xs {
1756
1762
  if (t.error) {
1757
1763
  t.retry ? s.push({ type: "reconnect" }) : s.push({
1758
1764
  type: "error",
1759
- error: new x(t.error)
1765
+ error: new O(t.error)
1760
1766
  }), s.close(), delete this.readStreamIterators[n];
1761
1767
  return;
1762
1768
  }
@@ -1771,7 +1777,7 @@ class xs {
1771
1777
  onConnectionStatusChange(t) {
1772
1778
  for (const n of Object.values(this.startWriteStreamCbs))
1773
1779
  n({ type: "disconnect" });
1774
- if (this.startWriteStreamCbs = {}, t !== Ts.AUTHENTICATED)
1780
+ if (this.startWriteStreamCbs = {}, t !== Vs.AUTHENTICATED)
1775
1781
  for (const { onDisconnect: n } of Object.values(this.writeStreams))
1776
1782
  n();
1777
1783
  else {
@@ -1794,7 +1800,7 @@ class xs {
1794
1800
  const s = t["client-event-id"], r = this.startWriteStreamCbs[s];
1795
1801
  r && (r({
1796
1802
  type: "error",
1797
- error: new x(t.message || "Unknown error", t.hint)
1803
+ error: new O(t.message || "Unknown error", t.hint)
1798
1804
  }), delete this.startWriteStreamCbs[s]);
1799
1805
  break;
1800
1806
  }
@@ -1802,7 +1808,7 @@ class xs {
1802
1808
  const s = t["client-event-id"], r = this.readStreamIterators[s];
1803
1809
  r && (r.push({
1804
1810
  type: "error",
1805
- error: new x(t.message || "Unknown error", t.hint)
1811
+ error: new O(t.message || "Unknown error", t.hint)
1806
1812
  }), r.close(), delete this.readStreamIterators[s]);
1807
1813
  break;
1808
1814
  }
@@ -1812,10 +1818,10 @@ class xs {
1812
1818
  return this.activeStreams.size > 0;
1813
1819
  }
1814
1820
  }
1815
- const Ts = {
1821
+ const Vs = {
1816
1822
  AUTHENTICATED: "authenticated"
1817
1823
  };
1818
- class _s extends x {
1824
+ class Js extends O {
1819
1825
  constructor(t) {
1820
1826
  super(t), this.name = "MissingApiURIError";
1821
1827
  }
@@ -1823,23 +1829,23 @@ class _s extends x {
1823
1829
  return "MissingApiURIError";
1824
1830
  }
1825
1831
  }
1826
- function Rs({ target: e, option: t = "apiURI", envVar: n }) {
1832
+ function Hs({ target: e, option: t = "apiURI", envVar: n }) {
1827
1833
  return `No SidekickDB server URL configured. ${n ? `Pass \`${t}\` to ${e} or set the ${n} environment variable` : `Pass \`${t}\` to ${e}`}, for example ${t}: 'https://sidekick.example.com'. SidekickDB has no default server.`;
1828
1834
  }
1829
- function Wt(e, t) {
1835
+ function Xt(e, t) {
1830
1836
  if (typeof e == "string" && e.trim() !== "")
1831
1837
  return e;
1832
- throw new _s(Rs(t));
1838
+ throw new Js(Hs(t));
1833
1839
  }
1834
- function As() {
1835
- return globalThis.__instantDbSchemaHashStore = globalThis.__instantDbSchemaHashStore ?? /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
1840
+ function Bs() {
1841
+ return globalThis.__sidekickDbSchemaHashStore = globalThis.__sidekickDbSchemaHashStore ?? /* @__PURE__ */ new WeakMap(), globalThis.__sidekickDbSchemaHashStore;
1836
1842
  }
1837
- function Ps() {
1838
- return globalThis.__instantDbStore = globalThis.__instantDbStore ?? {}, globalThis.__instantDbStore;
1843
+ function qs() {
1844
+ return globalThis.__sidekickDbStore = globalThis.__sidekickDbStore ?? {}, globalThis.__sidekickDbStore;
1839
1845
  }
1840
- Ps();
1841
- As();
1842
- class sn extends Event {
1846
+ qs();
1847
+ Bs();
1848
+ class hn extends Event {
1843
1849
  /**
1844
1850
  * Constructs a new `ErrorEvent` instance. This is typically not called directly,
1845
1851
  * but rather emitted by the `EventSource` object when an error occurs.
@@ -1855,14 +1861,14 @@ class sn extends Event {
1855
1861
  *
1856
1862
  * @public
1857
1863
  */
1858
- d(this, "code");
1864
+ l(this, "code");
1859
1865
  /**
1860
1866
  * Optional message attached to the error.
1861
1867
  * Note: this is not part of the spec, but is included for better error handling.
1862
1868
  *
1863
1869
  * @public
1864
1870
  */
1865
- d(this, "message");
1871
+ l(this, "message");
1866
1872
  this.code = (s == null ? void 0 : s.code) ?? void 0, this.message = (s == null ? void 0 : s.message) ?? void 0;
1867
1873
  }
1868
1874
  /**
@@ -1878,7 +1884,7 @@ class sn extends Event {
1878
1884
  * @returns A string representation of the error
1879
1885
  */
1880
1886
  [Symbol.for("nodejs.util.inspect.custom")](n, s, r) {
1881
- return r(rn(this), s);
1887
+ return r(pn(this), s);
1882
1888
  }
1883
1889
  /**
1884
1890
  * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
@@ -1892,17 +1898,17 @@ class sn extends Event {
1892
1898
  * @returns A string representation of the error
1893
1899
  */
1894
1900
  [Symbol.for("Deno.customInspect")](n, s) {
1895
- return n(rn(this), s);
1901
+ return n(pn(this), s);
1896
1902
  }
1897
1903
  }
1898
- function js(e) {
1904
+ function Qs(e) {
1899
1905
  const t = globalThis.DOMException;
1900
1906
  return typeof t == "function" ? new t(e, "SyntaxError") : new SyntaxError(e);
1901
1907
  }
1902
- function _t(e) {
1903
- return e instanceof Error ? "errors" in e && Array.isArray(e.errors) ? e.errors.map(_t).join(", ") : "cause" in e && e.cause instanceof Error ? `${e}: ${_t(e.cause)}` : e.message : `${e}`;
1908
+ function Mt(e) {
1909
+ return e instanceof Error ? "errors" in e && Array.isArray(e.errors) ? e.errors.map(Mt).join(", ") : "cause" in e && e.cause instanceof Error ? `${e}: ${Mt(e.cause)}` : e.message : `${e}`;
1904
1910
  }
1905
- function rn(e) {
1911
+ function pn(e) {
1906
1912
  return {
1907
1913
  type: e.type,
1908
1914
  message: e.message,
@@ -1912,69 +1918,69 @@ function rn(e) {
1912
1918
  timeStamp: e.timeStamp
1913
1919
  };
1914
1920
  }
1915
- class on extends Error {
1921
+ class yn extends Error {
1916
1922
  constructor(t, n) {
1917
1923
  super(t), this.name = "ParseError", this.type = n.type, this.field = n.field, this.value = n.value, this.line = n.line;
1918
1924
  }
1919
1925
  }
1920
- function vt(e) {
1926
+ function _t(e) {
1921
1927
  }
1922
- function Us(e) {
1928
+ function Gs(e) {
1923
1929
  if (typeof e == "function")
1924
1930
  throw new TypeError(
1925
1931
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
1926
1932
  );
1927
- const { onEvent: t = vt, onError: n = vt, onRetry: s = vt, onComment: r } = e;
1933
+ const { onEvent: t = _t, onError: n = _t, onRetry: s = _t, onComment: r } = e;
1928
1934
  let i = "", o = !0, a, c = "", u = "";
1929
- function h(w) {
1930
- const p = o ? w.replace(/^\xEF\xBB\xBF/, "") : w, [$, v] = Ms(`${i}${p}`);
1931
- for (const F of $)
1932
- l(F);
1933
- i = v, o = !1;
1934
- }
1935
- function l(w) {
1936
- if (w === "") {
1935
+ function p(b) {
1936
+ const h = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [S, $] = Xs(`${i}${h}`);
1937
+ for (const F of S)
1938
+ d(F);
1939
+ i = $, o = !1;
1940
+ }
1941
+ function d(b) {
1942
+ if (b === "") {
1937
1943
  m();
1938
1944
  return;
1939
1945
  }
1940
- if (w.startsWith(":")) {
1941
- r && r(w.slice(w.startsWith(": ") ? 2 : 1));
1946
+ if (b.startsWith(":")) {
1947
+ r && r(b.slice(b.startsWith(": ") ? 2 : 1));
1942
1948
  return;
1943
1949
  }
1944
- const p = w.indexOf(":");
1945
- if (p !== -1) {
1946
- const $ = w.slice(0, p), v = w[p + 1] === " " ? 2 : 1, F = w.slice(p + v);
1947
- y($, F, w);
1950
+ const h = b.indexOf(":");
1951
+ if (h !== -1) {
1952
+ const S = b.slice(0, h), $ = b[h + 1] === " " ? 2 : 1, F = b.slice(h + $);
1953
+ y(S, F, b);
1948
1954
  return;
1949
1955
  }
1950
- y(w, "", w);
1956
+ y(b, "", b);
1951
1957
  }
1952
- function y(w, p, $) {
1953
- switch (w) {
1958
+ function y(b, h, S) {
1959
+ switch (b) {
1954
1960
  case "event":
1955
- u = p;
1961
+ u = h;
1956
1962
  break;
1957
1963
  case "data":
1958
- c = `${c}${p}
1964
+ c = `${c}${h}
1959
1965
  `;
1960
1966
  break;
1961
1967
  case "id":
1962
- a = p.includes("\0") ? void 0 : p;
1968
+ a = h.includes("\0") ? void 0 : h;
1963
1969
  break;
1964
1970
  case "retry":
1965
- /^\d+$/.test(p) ? s(parseInt(p, 10)) : n(
1966
- new on(`Invalid \`retry\` value: "${p}"`, {
1971
+ /^\d+$/.test(h) ? s(parseInt(h, 10)) : n(
1972
+ new yn(`Invalid \`retry\` value: "${h}"`, {
1967
1973
  type: "invalid-retry",
1968
- value: p,
1969
- line: $
1974
+ value: h,
1975
+ line: S
1970
1976
  })
1971
1977
  );
1972
1978
  break;
1973
1979
  default:
1974
1980
  n(
1975
- new on(
1976
- `Unknown field "${w.length > 20 ? `${w.slice(0, 20)}…` : w}"`,
1977
- { type: "unknown-field", field: w, value: p, line: $ }
1981
+ new yn(
1982
+ `Unknown field "${b.length > 20 ? `${b.slice(0, 20)}…` : b}"`,
1983
+ { type: "unknown-field", field: b, value: h, line: S }
1978
1984
  )
1979
1985
  );
1980
1986
  break;
@@ -1990,12 +1996,12 @@ function Us(e) {
1990
1996
  `) ? c.slice(0, -1) : c
1991
1997
  }), a = void 0, c = "", u = "";
1992
1998
  }
1993
- function g(w = {}) {
1994
- i && w.consume && l(i), o = !0, a = void 0, c = "", u = "", i = "";
1999
+ function w(b = {}) {
2000
+ i && b.consume && d(i), o = !0, a = void 0, c = "", u = "", i = "";
1995
2001
  }
1996
- return { feed: h, reset: g };
2002
+ return { feed: p, reset: w };
1997
2003
  }
1998
- function Ms(e) {
2004
+ function Xs(e) {
1999
2005
  const t = [];
2000
2006
  let n = "", s = 0;
2001
2007
  for (; s < e.length; ) {
@@ -2013,29 +2019,29 @@ function Ms(e) {
2013
2019
  }
2014
2020
  return [t, n];
2015
2021
  }
2016
- var K, ye, Se, Je, He, qe, je, Ie, Ue, ae, ke, $e, ve, Me, B, Rt, at, ct, Tn, ut, ft, We, At, dt;
2022
+ var K, me, ke, qe, Qe, Ge, Me, Ie, De, ae, ve, $e, Oe, Ne, q, Dt, ht, pt, Kn, yt, mt, Je, Nt, bt;
2017
2023
  class se extends EventTarget {
2018
2024
  constructor(n, s) {
2019
2025
  super();
2020
- k(this, B);
2026
+ k(this, q);
2021
2027
  /**
2022
2028
  * ReadyState representing an EventSource currently trying to connect
2023
2029
  *
2024
2030
  * @public
2025
2031
  */
2026
- d(this, "CONNECTING", 0);
2032
+ l(this, "CONNECTING", 0);
2027
2033
  /**
2028
2034
  * ReadyState representing an EventSource connection that is open (eg connected)
2029
2035
  *
2030
2036
  * @public
2031
2037
  */
2032
- d(this, "OPEN", 1);
2038
+ l(this, "OPEN", 1);
2033
2039
  /**
2034
2040
  * ReadyState representing an EventSource connection that is closed (eg disconnected)
2035
2041
  *
2036
2042
  * @public
2037
2043
  */
2038
- d(this, "CLOSED", 2);
2044
+ l(this, "CLOSED", 2);
2039
2045
  // PRIVATES FOLLOW
2040
2046
  /**
2041
2047
  * Current connection state
@@ -2050,37 +2056,37 @@ class se extends EventTarget {
2050
2056
  *
2051
2057
  * @internal
2052
2058
  */
2053
- k(this, ye);
2059
+ k(this, me);
2054
2060
  /**
2055
2061
  * The destination URL after a redirect. Is reset on reconnection.
2056
2062
  *
2057
2063
  * @internal
2058
2064
  */
2059
- k(this, Se);
2065
+ k(this, ke);
2060
2066
  /**
2061
2067
  * Whether to include credentials in the request
2062
2068
  *
2063
2069
  * @internal
2064
2070
  */
2065
- k(this, Je);
2071
+ k(this, qe);
2066
2072
  /**
2067
2073
  * The fetch implementation to use
2068
2074
  *
2069
2075
  * @internal
2070
2076
  */
2071
- k(this, He);
2077
+ k(this, Qe);
2072
2078
  /**
2073
2079
  * The MessageEvent constructor to use
2074
2080
  *
2075
2081
  * @internal
2076
2082
  */
2077
- k(this, qe);
2083
+ k(this, Ge);
2078
2084
  /**
2079
2085
  * The reconnection time in milliseconds
2080
2086
  *
2081
2087
  * @internal
2082
2088
  */
2083
- k(this, je);
2089
+ k(this, Me);
2084
2090
  /**
2085
2091
  * Reference to an ongoing reconnect attempt, if any
2086
2092
  *
@@ -2093,7 +2099,7 @@ class se extends EventTarget {
2093
2099
  *
2094
2100
  * @internal
2095
2101
  */
2096
- k(this, Ue, null);
2102
+ k(this, De, null);
2097
2103
  /**
2098
2104
  * The AbortController instance used to abort the fetch request
2099
2105
  *
@@ -2105,7 +2111,7 @@ class se extends EventTarget {
2105
2111
  *
2106
2112
  * @internal
2107
2113
  */
2108
- k(this, ke);
2114
+ k(this, ve);
2109
2115
  /**
2110
2116
  * Holds the current error handler, attached through `onerror` property directly.
2111
2117
  * Note that `addEventListener('error', …)` will not be stored here.
@@ -2119,50 +2125,50 @@ class se extends EventTarget {
2119
2125
  *
2120
2126
  * @internal
2121
2127
  */
2122
- k(this, ve, null);
2128
+ k(this, Oe, null);
2123
2129
  /**
2124
2130
  * Holds the current open handler, attached through `onopen` property directly.
2125
2131
  * Note that `addEventListener('open', …)` will not be stored here.
2126
2132
  *
2127
2133
  * @internal
2128
2134
  */
2129
- k(this, Me, null);
2135
+ k(this, Ne, null);
2130
2136
  /**
2131
2137
  * Handles the fetch response
2132
2138
  *
2133
2139
  * @param response - The Fetch(ish) response
2134
2140
  * @internal
2135
2141
  */
2136
- k(this, at, async (n) => {
2142
+ k(this, ht, async (n) => {
2137
2143
  var y;
2138
- f(this, ke).reset();
2144
+ f(this, ve).reset();
2139
2145
  const { body: s, redirected: r, status: i, headers: o } = n;
2140
2146
  if (i === 204) {
2141
- O(this, B, We).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
2147
+ E(this, q, Je).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
2142
2148
  return;
2143
2149
  }
2144
- if (r ? S(this, Se, new URL(n.url)) : S(this, Se, void 0), i !== 200) {
2145
- O(this, B, We).call(this, `Non-200 status code (${i})`, i);
2150
+ if (r ? I(this, ke, new URL(n.url)) : I(this, ke, void 0), i !== 200) {
2151
+ E(this, q, Je).call(this, `Non-200 status code (${i})`, i);
2146
2152
  return;
2147
2153
  }
2148
2154
  if (!(o.get("content-type") || "").startsWith("text/event-stream")) {
2149
- O(this, B, We).call(this, 'Invalid content type, expected "text/event-stream"', i);
2155
+ E(this, q, Je).call(this, 'Invalid content type, expected "text/event-stream"', i);
2150
2156
  return;
2151
2157
  }
2152
2158
  if (f(this, K) === this.CLOSED)
2153
2159
  return;
2154
- S(this, K, this.OPEN);
2160
+ I(this, K, this.OPEN);
2155
2161
  const c = new Event("open");
2156
- if ((y = f(this, Me)) == null || y.call(this, c), this.dispatchEvent(c), typeof s != "object" || !s || !("getReader" in s)) {
2157
- O(this, B, We).call(this, "Invalid response body, expected a web ReadableStream", i), this.close();
2162
+ if ((y = f(this, Ne)) == null || y.call(this, c), this.dispatchEvent(c), typeof s != "object" || !s || !("getReader" in s)) {
2163
+ E(this, q, Je).call(this, "Invalid response body, expected a web ReadableStream", i), this.close();
2158
2164
  return;
2159
2165
  }
2160
- const u = new TextDecoder(), h = s.getReader();
2161
- let l = !0;
2166
+ const u = new TextDecoder(), p = s.getReader();
2167
+ let d = !0;
2162
2168
  do {
2163
- const { done: m, value: g } = await h.read();
2164
- g && f(this, ke).feed(u.decode(g, { stream: !m })), m && (l = !1, f(this, ke).reset(), O(this, B, At).call(this));
2165
- } while (l);
2169
+ const { done: m, value: w } = await p.read();
2170
+ w && f(this, ve).feed(u.decode(w, { stream: !m })), m && (d = !1, f(this, ve).reset(), E(this, q, Nt).call(this));
2171
+ } while (d);
2166
2172
  });
2167
2173
  /**
2168
2174
  * Handles rejected requests for the EventSource endpoint
@@ -2170,8 +2176,8 @@ class se extends EventTarget {
2170
2176
  * @param err - The error from `fetch()`
2171
2177
  * @internal
2172
2178
  */
2173
- k(this, ct, (n) => {
2174
- S(this, ae, void 0), !(n.name === "AbortError" || n.type === "aborted") && O(this, B, At).call(this, _t(n));
2179
+ k(this, pt, (n) => {
2180
+ I(this, ae, void 0), !(n.name === "AbortError" || n.type === "aborted") && E(this, q, Nt).call(this, Mt(n));
2175
2181
  });
2176
2182
  /**
2177
2183
  * Called by EventSourceParser instance when an event has successfully been parsed
@@ -2180,14 +2186,14 @@ class se extends EventTarget {
2180
2186
  * @param event - The parsed event
2181
2187
  * @internal
2182
2188
  */
2183
- k(this, ut, (n) => {
2184
- typeof n.id == "string" && S(this, Ue, n.id);
2185
- const s = new (f(this, qe))(n.event || "message", {
2189
+ k(this, yt, (n) => {
2190
+ typeof n.id == "string" && I(this, De, n.id);
2191
+ const s = new (f(this, Ge))(n.event || "message", {
2186
2192
  data: n.data,
2187
- origin: f(this, Se) ? f(this, Se).origin : f(this, ye).origin,
2193
+ origin: f(this, ke) ? f(this, ke).origin : f(this, me).origin,
2188
2194
  lastEventId: n.id || ""
2189
2195
  });
2190
- f(this, ve) && (!n.event || n.event === "message") && f(this, ve).call(this, s), this.dispatchEvent(s);
2196
+ f(this, Oe) && (!n.event || n.event === "message") && f(this, Oe).call(this, s), this.dispatchEvent(s);
2191
2197
  });
2192
2198
  /**
2193
2199
  * Called by EventSourceParser instance when a new reconnection interval is received
@@ -2196,31 +2202,31 @@ class se extends EventTarget {
2196
2202
  * @param value - The new reconnection interval in milliseconds
2197
2203
  * @internal
2198
2204
  */
2199
- k(this, ft, (n) => {
2200
- S(this, je, n);
2205
+ k(this, mt, (n) => {
2206
+ I(this, Me, n);
2201
2207
  });
2202
2208
  /**
2203
2209
  * Reconnects to the EventSource endpoint after a disconnect/failure
2204
2210
  *
2205
2211
  * @internal
2206
2212
  */
2207
- k(this, dt, () => {
2208
- S(this, Ie, void 0), f(this, K) === this.CONNECTING && O(this, B, Rt).call(this);
2213
+ k(this, bt, () => {
2214
+ I(this, Ie, void 0), f(this, K) === this.CONNECTING && E(this, q, Dt).call(this);
2209
2215
  });
2210
2216
  try {
2211
2217
  if (n instanceof URL)
2212
- S(this, ye, n);
2218
+ I(this, me, n);
2213
2219
  else if (typeof n == "string")
2214
- S(this, ye, new URL(n, Ds()));
2220
+ I(this, me, new URL(n, Ys()));
2215
2221
  else
2216
2222
  throw new Error("Invalid URL");
2217
2223
  } catch {
2218
- throw js("An invalid or illegal string was specified");
2224
+ throw Qs("An invalid or illegal string was specified");
2219
2225
  }
2220
- S(this, ke, Us({
2221
- onEvent: f(this, ut),
2222
- onRetry: f(this, ft)
2223
- })), S(this, K, this.CONNECTING), S(this, je, 3e3), S(this, He, (s == null ? void 0 : s.fetch) ?? globalThis.fetch), S(this, qe, (s == null ? void 0 : s.messageEvent) ?? globalThis.MessageEvent), S(this, Je, (s == null ? void 0 : s.withCredentials) ?? !1), O(this, B, Rt).call(this);
2226
+ I(this, ve, Gs({
2227
+ onEvent: f(this, yt),
2228
+ onRetry: f(this, mt)
2229
+ })), I(this, K, this.CONNECTING), I(this, Me, 3e3), I(this, Qe, (s == null ? void 0 : s.fetch) ?? globalThis.fetch), I(this, Ge, (s == null ? void 0 : s.messageEvent) ?? globalThis.MessageEvent), I(this, qe, (s == null ? void 0 : s.withCredentials) ?? !1), E(this, q, Dt).call(this);
2224
2230
  }
2225
2231
  /**
2226
2232
  * Returns the state of this EventSource object's connection. It can have the values described below.
@@ -2243,7 +2249,7 @@ class se extends EventTarget {
2243
2249
  * @public
2244
2250
  */
2245
2251
  get url() {
2246
- return f(this, ye).href;
2252
+ return f(this, me).href;
2247
2253
  }
2248
2254
  /**
2249
2255
  * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
@@ -2251,28 +2257,28 @@ class se extends EventTarget {
2251
2257
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
2252
2258
  */
2253
2259
  get withCredentials() {
2254
- return f(this, Je);
2260
+ return f(this, qe);
2255
2261
  }
2256
2262
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
2257
2263
  get onerror() {
2258
2264
  return f(this, $e);
2259
2265
  }
2260
2266
  set onerror(n) {
2261
- S(this, $e, n);
2267
+ I(this, $e, n);
2262
2268
  }
2263
2269
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
2264
2270
  get onmessage() {
2265
- return f(this, ve);
2271
+ return f(this, Oe);
2266
2272
  }
2267
2273
  set onmessage(n) {
2268
- S(this, ve, n);
2274
+ I(this, Oe, n);
2269
2275
  }
2270
2276
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
2271
2277
  get onopen() {
2272
- return f(this, Me);
2278
+ return f(this, Ne);
2273
2279
  }
2274
2280
  set onopen(n) {
2275
- S(this, Me, n);
2281
+ I(this, Ne, n);
2276
2282
  }
2277
2283
  addEventListener(n, s, r) {
2278
2284
  const i = s;
@@ -2290,45 +2296,45 @@ class se extends EventTarget {
2290
2296
  * @public
2291
2297
  */
2292
2298
  close() {
2293
- f(this, Ie) && clearTimeout(f(this, Ie)), f(this, K) !== this.CLOSED && (f(this, ae) && f(this, ae).abort(), S(this, K, this.CLOSED), S(this, ae, void 0));
2299
+ f(this, Ie) && clearTimeout(f(this, Ie)), f(this, K) !== this.CLOSED && (f(this, ae) && f(this, ae).abort(), I(this, K, this.CLOSED), I(this, ae, void 0));
2294
2300
  }
2295
2301
  }
2296
- K = new WeakMap(), ye = new WeakMap(), Se = new WeakMap(), Je = new WeakMap(), He = new WeakMap(), qe = new WeakMap(), je = new WeakMap(), Ie = new WeakMap(), Ue = new WeakMap(), ae = new WeakMap(), ke = new WeakMap(), $e = new WeakMap(), ve = new WeakMap(), Me = new WeakMap(), B = new WeakSet(), /**
2302
+ K = new WeakMap(), me = new WeakMap(), ke = new WeakMap(), qe = new WeakMap(), Qe = new WeakMap(), Ge = new WeakMap(), Me = new WeakMap(), Ie = new WeakMap(), De = new WeakMap(), ae = new WeakMap(), ve = new WeakMap(), $e = new WeakMap(), Oe = new WeakMap(), Ne = new WeakMap(), q = new WeakSet(), /**
2297
2303
  * Connect to the given URL and start receiving events
2298
2304
  *
2299
2305
  * @internal
2300
2306
  */
2301
- Rt = function() {
2302
- S(this, K, this.CONNECTING), S(this, ae, new AbortController()), f(this, He)(f(this, ye), O(this, B, Tn).call(this)).then(f(this, at)).catch(f(this, ct));
2303
- }, at = new WeakMap(), ct = new WeakMap(), /**
2307
+ Dt = function() {
2308
+ I(this, K, this.CONNECTING), I(this, ae, new AbortController()), f(this, Qe)(f(this, me), E(this, q, Kn).call(this)).then(f(this, ht)).catch(f(this, pt));
2309
+ }, ht = new WeakMap(), pt = new WeakMap(), /**
2304
2310
  * Get request options for the `fetch()` request
2305
2311
  *
2306
2312
  * @returns The request options
2307
2313
  * @internal
2308
2314
  */
2309
- Tn = function() {
2315
+ Kn = function() {
2310
2316
  var r;
2311
2317
  const s = {
2312
2318
  // [spec] Let `corsAttributeState` be `Anonymous`…
2313
2319
  // [spec] …will have their mode set to "cors"…
2314
2320
  mode: "cors",
2315
2321
  redirect: "follow",
2316
- headers: { Accept: "text/event-stream", ...f(this, Ue) ? { "Last-Event-ID": f(this, Ue) } : void 0 },
2322
+ headers: { Accept: "text/event-stream", ...f(this, De) ? { "Last-Event-ID": f(this, De) } : void 0 },
2317
2323
  cache: "no-store",
2318
2324
  signal: (r = f(this, ae)) == null ? void 0 : r.signal
2319
2325
  };
2320
2326
  return "window" in globalThis && (s.credentials = this.withCredentials ? "include" : "same-origin"), s;
2321
- }, ut = new WeakMap(), ft = new WeakMap(), /**
2327
+ }, yt = new WeakMap(), mt = new WeakMap(), /**
2322
2328
  * Handles the process referred to in the EventSource specification as "failing a connection".
2323
2329
  *
2324
2330
  * @param error - The error causing the connection to fail
2325
2331
  * @param code - The HTTP status code, if available
2326
2332
  * @internal
2327
2333
  */
2328
- We = function(n, s) {
2334
+ Je = function(n, s) {
2329
2335
  var i;
2330
- f(this, K) !== this.CLOSED && S(this, K, this.CLOSED);
2331
- const r = new sn("error", { code: s, message: n });
2336
+ f(this, K) !== this.CLOSED && I(this, K, this.CLOSED);
2337
+ const r = new hn("error", { code: s, message: n });
2332
2338
  (i = f(this, $e)) == null || i.call(this, r), this.dispatchEvent(r);
2333
2339
  }, /**
2334
2340
  * Schedules a reconnection attempt against the EventSource endpoint.
@@ -2337,57 +2343,57 @@ We = function(n, s) {
2337
2343
  * @param code - The HTTP status code, if available
2338
2344
  * @internal
2339
2345
  */
2340
- At = function(n, s) {
2346
+ Nt = function(n, s) {
2341
2347
  var i;
2342
2348
  if (f(this, K) === this.CLOSED)
2343
2349
  return;
2344
- S(this, K, this.CONNECTING);
2345
- const r = new sn("error", { code: s, message: n });
2346
- (i = f(this, $e)) == null || i.call(this, r), this.dispatchEvent(r), S(this, Ie, setTimeout(f(this, dt), f(this, je)));
2347
- }, dt = new WeakMap(), /**
2350
+ I(this, K, this.CONNECTING);
2351
+ const r = new hn("error", { code: s, message: n });
2352
+ (i = f(this, $e)) == null || i.call(this, r), this.dispatchEvent(r), I(this, Ie, setTimeout(f(this, bt), f(this, Me)));
2353
+ }, bt = new WeakMap(), /**
2348
2354
  * ReadyState representing an EventSource currently trying to connect
2349
2355
  *
2350
2356
  * @public
2351
2357
  */
2352
- d(se, "CONNECTING", 0), /**
2358
+ l(se, "CONNECTING", 0), /**
2353
2359
  * ReadyState representing an EventSource connection that is open (eg connected)
2354
2360
  *
2355
2361
  * @public
2356
2362
  */
2357
- d(se, "OPEN", 1), /**
2363
+ l(se, "OPEN", 1), /**
2358
2364
  * ReadyState representing an EventSource connection that is closed (eg disconnected)
2359
2365
  *
2360
2366
  * @public
2361
2367
  */
2362
- d(se, "CLOSED", 2);
2368
+ l(se, "CLOSED", 2);
2363
2369
  Object.defineProperty(se, Symbol.for("eventsource.supports-fetch-override"), {
2364
2370
  value: !0,
2365
2371
  writable: !1,
2366
2372
  configurable: !1,
2367
2373
  enumerable: !1
2368
2374
  });
2369
- function Ds() {
2375
+ function Ys() {
2370
2376
  const e = "document" in globalThis ? globalThis.document : void 0;
2371
2377
  return e && typeof e == "object" && "baseURI" in e && typeof e.baseURI == "string" ? e.baseURI : void 0;
2372
2378
  }
2373
- class _n extends Event {
2379
+ class Vn extends Event {
2374
2380
  constructor(n, s) {
2375
2381
  super(n);
2376
- d(this, "data");
2377
- d(this, "origin");
2378
- d(this, "lastEventId");
2379
- d(this, "source");
2380
- d(this, "ports");
2382
+ l(this, "data");
2383
+ l(this, "origin");
2384
+ l(this, "lastEventId");
2385
+ l(this, "source");
2386
+ l(this, "ports");
2381
2387
  this.data = (s == null ? void 0 : s.data) ?? null, this.origin = (s == null ? void 0 : s.origin) ?? "", this.lastEventId = (s == null ? void 0 : s.lastEventId) ?? "", this.source = (s == null ? void 0 : s.source) ?? null, this.ports = (s == null ? void 0 : s.ports) ?? [];
2382
2388
  }
2383
2389
  /** @deprecated */
2384
2390
  initMessageEvent(n, s, r, i, o, a, c, u) {
2385
2391
  }
2386
2392
  }
2387
- function Ns(e, t, n, s) {
2393
+ function Zs(e, t, n, s) {
2388
2394
  let r = null, i = !1;
2389
- const o = [], a = (l) => {
2390
- o.push(l), o.length > 100 && o.shift(), r && (r(), r = null);
2395
+ const o = [], a = (d) => {
2396
+ o.push(d), o.length > 100 && o.shift(), r && (r(), r = null);
2391
2397
  };
2392
2398
  e(a);
2393
2399
  const c = () => (n(a), Promise.resolve({ done: !0, value: void 0 }));
@@ -2398,24 +2404,24 @@ function Ns(e, t, n, s) {
2398
2404
  for (; ; ) {
2399
2405
  if (s() === "closed" || i)
2400
2406
  return c();
2401
- const l = o.shift();
2402
- if (l)
2403
- return { value: l, done: !1 };
2407
+ const d = o.shift();
2408
+ if (d)
2409
+ return { value: d, done: !1 };
2404
2410
  await new Promise((m) => {
2405
2411
  r = m;
2406
2412
  });
2407
2413
  }
2408
2414
  },
2409
2415
  return: c,
2410
- throw(l) {
2411
- return n(a), Promise.reject(l);
2416
+ throw(d) {
2417
+ return n(a), Promise.reject(d);
2412
2418
  },
2413
2419
  [Symbol.asyncIterator]() {
2414
2420
  return this;
2415
2421
  }
2416
2422
  };
2417
2423
  }
2418
- function he(e) {
2424
+ function pe(e) {
2419
2425
  switch (e.readyState) {
2420
2426
  case e.CLOSED:
2421
2427
  return "closed";
@@ -2427,7 +2433,7 @@ function he(e) {
2427
2433
  return "connecting";
2428
2434
  }
2429
2435
  }
2430
- function Ls(e) {
2436
+ function er(e) {
2431
2437
  let t = null;
2432
2438
  return {
2433
2439
  ...e,
@@ -2439,7 +2445,7 @@ function Ls(e) {
2439
2445
  }
2440
2446
  };
2441
2447
  }
2442
- function an(e) {
2448
+ function mn(e) {
2443
2449
  if (!e)
2444
2450
  return;
2445
2451
  const t = {};
@@ -2452,65 +2458,65 @@ function an(e) {
2452
2458
  };
2453
2459
  return t;
2454
2460
  }
2455
- function Fs(e, t, n) {
2461
+ function tr(e, t, n) {
2456
2462
  let s, r = !1;
2457
- const i = Ae(), o = new se(`${n.apiURI}/admin/subscribe-query?local_connection_id=${i}`, {
2458
- messageEvent: _n,
2459
- fetch(p, $) {
2460
- return s = null, fetch(p, {
2461
- ...$,
2463
+ const i = je(), o = new se(`${n.apiURI}/admin/subscribe-query?local_connection_id=${i}`, {
2464
+ messageEvent: Vn,
2465
+ fetch(h, S) {
2466
+ return s = null, fetch(h, {
2467
+ ...S,
2462
2468
  method: "POST",
2463
2469
  headers: n.headers,
2464
2470
  body: JSON.stringify({
2465
2471
  query: e,
2466
2472
  "inference?": n.inference,
2467
2473
  versions: {
2468
- "@instantdb/admin": xe,
2469
- "@instantdb/core": xe
2474
+ "@sidekickdb/admin": Te,
2475
+ "@sidekickdb/core": Te
2470
2476
  }
2471
2477
  })
2472
- }).then((v) => (v.ok || (s = Ls(v)), v));
2478
+ }).then(($) => ($.ok || (s = er($)), $));
2473
2479
  }
2474
- }), a = [], c = [], u = (p) => {
2475
- a.push(p);
2476
- }, h = (p) => {
2477
- a.splice(a.indexOf(p), 1);
2478
- }, l = (p) => {
2479
- c.push(p);
2480
+ }), a = [], c = [], u = (h) => {
2481
+ a.push(h);
2482
+ }, p = (h) => {
2483
+ a.splice(a.indexOf(h), 1);
2484
+ }, d = (h) => {
2485
+ c.push(h);
2480
2486
  };
2481
2487
  t && u(t);
2482
2488
  let y = null;
2483
- function m(p) {
2489
+ function m(h) {
2484
2490
  if (!r)
2485
- for (const $ of a)
2491
+ for (const S of a)
2486
2492
  try {
2487
- $(p);
2488
- } catch (v) {
2489
- console.error("Error in subscribeQuery callback", v);
2493
+ S(h);
2494
+ } catch ($) {
2495
+ console.error("Error in subscribeQuery callback", $);
2490
2496
  }
2491
2497
  }
2492
- function g(p) {
2493
- var $, v;
2494
- switch (p.op) {
2498
+ function w(h) {
2499
+ var S, $;
2500
+ switch (h.op) {
2495
2501
  case "sse-init": {
2496
- const F = p["machine-id"], be = p["session-id"];
2497
- y = { machineId: F, sessionId: be };
2502
+ const F = h["machine-id"], ge = h["session-id"];
2503
+ y = { machineId: F, sessionId: ge };
2498
2504
  break;
2499
2505
  }
2500
2506
  case "add-query-ok": {
2501
2507
  m({
2502
2508
  type: "ok",
2503
- data: p.result,
2504
- pageInfo: an(($ = p["result-meta"]) == null ? void 0 : $["page-info"]),
2509
+ data: h.result,
2510
+ pageInfo: mn((S = h["result-meta"]) == null ? void 0 : S["page-info"]),
2505
2511
  sessionInfo: y
2506
2512
  });
2507
2513
  break;
2508
2514
  }
2509
2515
  case "refresh-ok": {
2510
- p.computations.length && m({
2516
+ h.computations.length && m({
2511
2517
  type: "ok",
2512
- data: p.computations[0]["instaql-result"],
2513
- pageInfo: an((v = p.computations[0]["result-meta"]) == null ? void 0 : v["page-info"]),
2518
+ data: h.computations[0]["sideql-result"],
2519
+ pageInfo: mn(($ = h.computations[0]["result-meta"]) == null ? void 0 : $["page-info"]),
2514
2520
  sessionInfo: y
2515
2521
  });
2516
2522
  break;
@@ -2518,12 +2524,12 @@ function Fs(e, t, n) {
2518
2524
  case "error": {
2519
2525
  m({
2520
2526
  type: "error",
2521
- error: new ue({ body: p, status: p.status }),
2527
+ error: new fe({ body: h, status: h.status }),
2522
2528
  get readyState() {
2523
- return he(o);
2529
+ return pe(o);
2524
2530
  },
2525
2531
  get isClosed() {
2526
- return he(o) === "closed";
2532
+ return pe(o) === "closed";
2527
2533
  },
2528
2534
  sessionInfo: y
2529
2535
  });
@@ -2531,67 +2537,67 @@ function Fs(e, t, n) {
2531
2537
  }
2532
2538
  }
2533
2539
  }
2534
- return o.onerror = (p) => {
2540
+ return o.onerror = (h) => {
2535
2541
  if (s)
2536
- s.text().then(($) => {
2537
- let v = { type: void 0, message: $ };
2542
+ s.text().then((S) => {
2543
+ let $ = { type: void 0, message: S };
2538
2544
  try {
2539
- v = JSON.parse($);
2545
+ $ = JSON.parse(S);
2540
2546
  } catch {
2541
2547
  }
2542
2548
  m({
2543
2549
  type: "error",
2544
- error: new ue({
2550
+ error: new fe({
2545
2551
  status: s.status,
2546
- body: v
2552
+ body: $
2547
2553
  }),
2548
2554
  get readyState() {
2549
- return he(o);
2555
+ return pe(o);
2550
2556
  },
2551
2557
  get isClosed() {
2552
- return he(o) === "closed";
2558
+ return pe(o) === "closed";
2553
2559
  },
2554
2560
  sessionInfo: y
2555
2561
  });
2556
2562
  });
2557
2563
  else {
2558
- const $ = () => {
2564
+ const S = () => {
2559
2565
  m({
2560
2566
  type: "error",
2561
- error: new ue({
2562
- status: p.code || 500,
2567
+ error: new fe({
2568
+ status: h.code || 500,
2563
2569
  body: {
2564
2570
  type: void 0,
2565
- message: p.message || "Unknown error in subscribe query."
2571
+ message: h.message || "Unknown error in subscribe query."
2566
2572
  }
2567
2573
  }),
2568
2574
  get readyState() {
2569
- return he(o);
2575
+ return pe(o);
2570
2576
  },
2571
2577
  get isClosed() {
2572
- return he(o) === "closed";
2578
+ return pe(o) === "closed";
2573
2579
  },
2574
2580
  sessionInfo: y
2575
2581
  });
2576
2582
  };
2577
2583
  if (o.readyState === se.CLOSED) {
2578
- $();
2584
+ S();
2579
2585
  return;
2580
2586
  }
2581
2587
  setTimeout(() => {
2582
- o.readyState !== se.OPEN && $();
2588
+ o.readyState !== se.OPEN && S();
2583
2589
  }, 5e3);
2584
2590
  }
2585
- }, o.onmessage = (p) => {
2586
- g(JSON.parse(p.data));
2591
+ }, o.onmessage = (h) => {
2592
+ w(JSON.parse(h.data));
2587
2593
  }, {
2588
2594
  close: () => {
2589
2595
  r = !0;
2590
- for (const p of c)
2596
+ for (const h of c)
2591
2597
  try {
2592
- p();
2593
- } catch ($) {
2594
- console.error("Error in onClose callback", $);
2598
+ h();
2599
+ } catch (S) {
2600
+ console.error("Error in onClose callback", S);
2595
2601
  }
2596
2602
  o.close();
2597
2603
  },
@@ -2602,70 +2608,70 @@ function Fs(e, t, n) {
2602
2608
  return y;
2603
2609
  },
2604
2610
  get readyState() {
2605
- return he(o);
2611
+ return pe(o);
2606
2612
  },
2607
2613
  get isClosed() {
2608
- return he(o) === "closed";
2614
+ return pe(o) === "closed";
2609
2615
  },
2610
- [Symbol.asyncIterator]: Ns.bind(this, u, l, h, () => 1)
2616
+ [Symbol.asyncIterator]: Zs.bind(this, u, d, p, () => 1)
2611
2617
  };
2612
2618
  }
2613
- var fe = {};
2614
- Object.defineProperty(fe, "__esModule", { value: !0 });
2615
- var zs = fe.parseCookie = Pn;
2616
- fe.parse = Pn;
2617
- fe.stringifyCookie = qs;
2618
- fe.stringifySetCookie = mt;
2619
- fe.serialize = mt;
2620
- fe.parseSetCookie = Bs;
2621
- fe.stringifySetCookie = mt;
2622
- fe.serialize = mt;
2623
- const Rn = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, An = /^[\u0021-\u003A\u003C-\u007E]*$/, Ws = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i, Ks = /^[\u0020-\u003A\u003D-\u007E]*$/, Vs = /^-?\d+$/, Js = Object.prototype.toString, Hs = /* @__PURE__ */ (() => {
2619
+ var de = {};
2620
+ Object.defineProperty(de, "__esModule", { value: !0 });
2621
+ var nr = de.parseCookie = Bn;
2622
+ de.parse = Bn;
2623
+ de.stringifyCookie = cr;
2624
+ de.stringifySetCookie = It;
2625
+ de.serialize = It;
2626
+ de.parseSetCookie = ur;
2627
+ de.stringifySetCookie = It;
2628
+ de.serialize = It;
2629
+ const Jn = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, Hn = /^[\u0021-\u003A\u003C-\u007E]*$/, sr = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i, rr = /^[\u0020-\u003A\u003D-\u007E]*$/, ir = /^-?\d+$/, or = Object.prototype.toString, ar = /* @__PURE__ */ (() => {
2624
2630
  const e = function() {
2625
2631
  };
2626
2632
  return e.prototype = /* @__PURE__ */ Object.create(null), e;
2627
2633
  })();
2628
- function Pn(e, t) {
2629
- const n = new Hs(), s = e.length;
2634
+ function Bn(e, t) {
2635
+ const n = new ar(), s = e.length;
2630
2636
  if (s < 2)
2631
2637
  return n;
2632
- const r = (t == null ? void 0 : t.decode) || jn;
2638
+ const r = (t == null ? void 0 : t.decode) || qn;
2633
2639
  let i = 0;
2634
2640
  do {
2635
- const o = jt(e, i, s);
2641
+ const o = Ft(e, i, s);
2636
2642
  if (o === -1)
2637
2643
  break;
2638
- const a = Pt(e, i, s);
2644
+ const a = Lt(e, i, s);
2639
2645
  if (o > a) {
2640
2646
  i = e.lastIndexOf(";", o - 1) + 1;
2641
2647
  continue;
2642
2648
  }
2643
- const c = pe(e, i, o);
2644
- n[c] === void 0 && (n[c] = r(pe(e, o + 1, a))), i = a + 1;
2649
+ const c = ye(e, i, o);
2650
+ n[c] === void 0 && (n[c] = r(ye(e, o + 1, a))), i = a + 1;
2645
2651
  } while (i < s);
2646
2652
  return n;
2647
2653
  }
2648
- function qs(e, t) {
2654
+ function cr(e, t) {
2649
2655
  const n = (t == null ? void 0 : t.encode) || encodeURIComponent, s = [];
2650
2656
  for (const r of Object.keys(e)) {
2651
2657
  const i = e[r];
2652
2658
  if (i === void 0)
2653
2659
  continue;
2654
- if (!Rn.test(r))
2660
+ if (!Jn.test(r))
2655
2661
  throw new TypeError(`cookie name is invalid: ${r}`);
2656
2662
  const o = n(i);
2657
- if (!An.test(o))
2663
+ if (!Hn.test(o))
2658
2664
  throw new TypeError(`cookie val is invalid: ${i}`);
2659
2665
  s.push(`${r}=${o}`);
2660
2666
  }
2661
2667
  return s.join("; ");
2662
2668
  }
2663
- function mt(e, t, n) {
2669
+ function It(e, t, n) {
2664
2670
  const s = typeof e == "object" ? e : { ...n, name: e, value: String(t) }, r = typeof t == "object" ? t : n, i = (r == null ? void 0 : r.encode) || encodeURIComponent;
2665
- if (!Rn.test(s.name))
2671
+ if (!Jn.test(s.name))
2666
2672
  throw new TypeError(`argument name is invalid: ${s.name}`);
2667
2673
  const o = s.value ? i(s.value) : "";
2668
- if (!An.test(o))
2674
+ if (!Hn.test(o))
2669
2675
  throw new TypeError(`argument val is invalid: ${s.value}`);
2670
2676
  let a = s.name + "=" + o;
2671
2677
  if (s.maxAge !== void 0) {
@@ -2674,17 +2680,17 @@ function mt(e, t, n) {
2674
2680
  a += "; Max-Age=" + s.maxAge;
2675
2681
  }
2676
2682
  if (s.domain) {
2677
- if (!Ws.test(s.domain))
2683
+ if (!sr.test(s.domain))
2678
2684
  throw new TypeError(`option domain is invalid: ${s.domain}`);
2679
2685
  a += "; Domain=" + s.domain;
2680
2686
  }
2681
2687
  if (s.path) {
2682
- if (!Ks.test(s.path))
2688
+ if (!rr.test(s.path))
2683
2689
  throw new TypeError(`option path is invalid: ${s.path}`);
2684
2690
  a += "; Path=" + s.path;
2685
2691
  }
2686
2692
  if (s.expires) {
2687
- if (!Qs(s.expires) || !Number.isFinite(s.expires.valueOf()))
2693
+ if (!fr(s.expires) || !Number.isFinite(s.expires.valueOf()))
2688
2694
  throw new TypeError(`option expires is invalid: ${s.expires}`);
2689
2695
  a += "; Expires=" + s.expires.toUTCString();
2690
2696
  }
@@ -2719,15 +2725,15 @@ function mt(e, t, n) {
2719
2725
  }
2720
2726
  return a;
2721
2727
  }
2722
- function Bs(e, t) {
2723
- const n = (t == null ? void 0 : t.decode) || jn, s = e.length, r = Pt(e, 0, s), i = jt(e, 0, r), o = i === -1 ? { name: "", value: n(pe(e, 0, r)) } : {
2724
- name: pe(e, 0, i),
2725
- value: n(pe(e, i + 1, r))
2728
+ function ur(e, t) {
2729
+ const n = (t == null ? void 0 : t.decode) || qn, s = e.length, r = Lt(e, 0, s), i = Ft(e, 0, r), o = i === -1 ? { name: "", value: n(ye(e, 0, r)) } : {
2730
+ name: ye(e, 0, i),
2731
+ value: n(ye(e, i + 1, r))
2726
2732
  };
2727
2733
  let a = r + 1;
2728
2734
  for (; a < s; ) {
2729
- const c = Pt(e, a, s), u = jt(e, a, c), h = u === -1 ? pe(e, a, c) : pe(e, a, u), l = u === -1 ? void 0 : pe(e, u + 1, c);
2730
- switch (h.toLowerCase()) {
2735
+ const c = Lt(e, a, s), u = Ft(e, a, c), p = u === -1 ? ye(e, a, c) : ye(e, a, u), d = u === -1 ? void 0 : ye(e, u + 1, c);
2736
+ switch (p.toLowerCase()) {
2731
2737
  case "httponly":
2732
2738
  o.httpOnly = !0;
2733
2739
  break;
@@ -2738,46 +2744,46 @@ function Bs(e, t) {
2738
2744
  o.partitioned = !0;
2739
2745
  break;
2740
2746
  case "domain":
2741
- o.domain = l;
2747
+ o.domain = d;
2742
2748
  break;
2743
2749
  case "path":
2744
- o.path = l;
2750
+ o.path = d;
2745
2751
  break;
2746
2752
  case "max-age":
2747
- l && Vs.test(l) && (o.maxAge = Number(l));
2753
+ d && ir.test(d) && (o.maxAge = Number(d));
2748
2754
  break;
2749
2755
  case "expires":
2750
- if (!l)
2756
+ if (!d)
2751
2757
  break;
2752
- const y = new Date(l);
2758
+ const y = new Date(d);
2753
2759
  Number.isFinite(y.valueOf()) && (o.expires = y);
2754
2760
  break;
2755
2761
  case "priority":
2756
- if (!l)
2762
+ if (!d)
2757
2763
  break;
2758
- const m = l.toLowerCase();
2764
+ const m = d.toLowerCase();
2759
2765
  (m === "low" || m === "medium" || m === "high") && (o.priority = m);
2760
2766
  break;
2761
2767
  case "samesite":
2762
- if (!l)
2768
+ if (!d)
2763
2769
  break;
2764
- const g = l.toLowerCase();
2765
- (g === "lax" || g === "strict" || g === "none") && (o.sameSite = g);
2770
+ const w = d.toLowerCase();
2771
+ (w === "lax" || w === "strict" || w === "none") && (o.sameSite = w);
2766
2772
  break;
2767
2773
  }
2768
2774
  a = c + 1;
2769
2775
  }
2770
2776
  return o;
2771
2777
  }
2772
- function Pt(e, t, n) {
2778
+ function Lt(e, t, n) {
2773
2779
  const s = e.indexOf(";", t);
2774
2780
  return s === -1 ? n : s;
2775
2781
  }
2776
- function jt(e, t, n) {
2782
+ function Ft(e, t, n) {
2777
2783
  const s = e.indexOf("=", t);
2778
2784
  return s < n ? s : -1;
2779
2785
  }
2780
- function pe(e, t, n) {
2786
+ function ye(e, t, n) {
2781
2787
  let s = t, r = n;
2782
2788
  do {
2783
2789
  const i = e.charCodeAt(s);
@@ -2792,7 +2798,7 @@ function pe(e, t, n) {
2792
2798
  }
2793
2799
  return e.slice(s, r);
2794
2800
  }
2795
- function jn(e) {
2801
+ function qn(e) {
2796
2802
  if (e.indexOf("%") === -1)
2797
2803
  return e;
2798
2804
  try {
@@ -2801,22 +2807,10 @@ function jn(e) {
2801
2807
  return e;
2802
2808
  }
2803
2809
  }
2804
- function Qs(e) {
2805
- return Js.call(e) === "[object Date]";
2810
+ function fr(e) {
2811
+ return or.call(e) === "[object Date]";
2806
2812
  }
2807
- const Gs = {
2808
- "https://api.instantdb.com": {
2809
- keys: [
2810
- {
2811
- kty: "OKP",
2812
- crv: "Ed25519",
2813
- alg: "EdDSA",
2814
- use: "sig",
2815
- kid: "1034696293",
2816
- x: "N-C41432STKAKkXAWmeIOXMnZcGRR1b9u1L3bTVqI_o"
2817
- }
2818
- ]
2819
- },
2813
+ const dr = Object.assign(/* @__PURE__ */ Object.create(null), {
2820
2814
  "http://localhost:8888": {
2821
2815
  keys: [
2822
2816
  {
@@ -2829,8 +2823,8 @@ const Gs = {
2829
2823
  }
2830
2824
  ]
2831
2825
  }
2832
- };
2833
- function Xs(e) {
2826
+ });
2827
+ function lr(e) {
2834
2828
  if (e.kty === "OKP" && e.crv === "Ed25519")
2835
2829
  return { name: "Ed25519" };
2836
2830
  if (e.kty === "EC")
@@ -2846,20 +2840,20 @@ function Xs(e) {
2846
2840
  };
2847
2841
  throw new Error(`Unsupported JWK configuration: kty=${e.kty}, crv=${e.crv}`);
2848
2842
  }
2849
- async function Ys(e) {
2850
- const t = Xs(e), n = await crypto.subtle.importKey("jwk", e, t, !1, ["verify"]);
2843
+ async function bn(e) {
2844
+ const t = lr(e), n = await crypto.subtle.importKey("jwk", e, t, !1, ["verify"]);
2851
2845
  return { alg: t, key: n };
2852
2846
  }
2853
- function Zs(e, t, n, s) {
2847
+ function hr(e, t, n, s) {
2854
2848
  return crypto.subtle.verify(e, t, n, s);
2855
2849
  }
2856
- function er(e) {
2850
+ function pr(e) {
2857
2851
  const t = new Uint8Array(Math.ceil(e.length / 2));
2858
2852
  for (let n = 0; n < t.length; n++)
2859
2853
  t[n] = parseInt(e.substring(n * 2, n * 2 + 2), 16);
2860
2854
  return t;
2861
2855
  }
2862
- function tr(e) {
2856
+ function yr(e) {
2863
2857
  let t, n, s;
2864
2858
  for (const i of e.split(",")) {
2865
2859
  const [o, a] = i.split("=");
@@ -2880,41 +2874,150 @@ function tr(e) {
2880
2874
  }
2881
2875
  const r = [];
2882
2876
  if (t || r.push("t"), n || r.push("kid"), s || r.push("v1"), r.length || !t || !n || !s)
2883
- throw new x("Invalid Instant-Signature header.", {
2877
+ throw new O("Invalid Sidekick-Signature header.", {
2884
2878
  header: e,
2885
2879
  missingKeys: r
2886
2880
  });
2887
2881
  return { t, kid: n, v1: s };
2888
2882
  }
2889
- function nr(e, t, n) {
2890
- if (Math.floor(e.getTime() / 1e3) - parseInt(t, 10) > n)
2891
- throw new x("Webhook signature is too old", {
2883
+ function mr(e, t, n) {
2884
+ if (!/^[0-9]{1,12}$/.test(t))
2885
+ throw new O("Invalid timestamp in Sidekick-Signature header.", {
2886
+ t
2887
+ });
2888
+ const s = Math.floor(e.getTime() / 1e3) - Number(t);
2889
+ if (s > n)
2890
+ throw new O("Webhook signature is too old", {
2891
+ tolerance: n,
2892
+ receivedAt: e,
2893
+ t
2894
+ });
2895
+ if (-s > n)
2896
+ throw new O("Webhook signature timestamp is in the future", {
2892
2897
  tolerance: n,
2893
2898
  receivedAt: e,
2894
2899
  t
2895
2900
  });
2896
2901
  }
2897
- const cn = {}, sr = 300;
2898
- async function rr(e, t) {
2902
+ const lt = /* @__PURE__ */ new Map();
2903
+ function br(e, t) {
2904
+ var n;
2905
+ return (n = lt.get(e)) == null ? void 0 : n.get(t);
2906
+ }
2907
+ function gn(e, t, n) {
2908
+ let s = lt.get(e);
2909
+ s || (s = /* @__PURE__ */ new Map(), lt.set(e, s)), s.set(t, n);
2910
+ }
2911
+ function gr(e, t, n) {
2912
+ const s = lt.get(e);
2913
+ (s == null ? void 0 : s.get(t)) === n && s.delete(t);
2914
+ }
2915
+ const wr = 300, Sr = 10 * 6e4, kr = 6 * 60 * 6e4, wn = /* @__PURE__ */ new Map(), Ir = 6e4, Ke = 5e3, vr = 1e4, $r = 3, Wt = 8e3, Or = 6e4;
2916
+ function ce() {
2917
+ var e, t;
2918
+ return ((t = (e = globalThis.performance) == null ? void 0 : e.now) == null ? void 0 : t.call(e)) ?? Date.now();
2919
+ }
2920
+ function Pe(e, t, n) {
2921
+ return e >= t && e - t < n;
2922
+ }
2923
+ function Er(e, t) {
2924
+ t < e.seen && (e.fullAt = t), e.seen = t;
2925
+ const n = Math.max(e.fullAt, t);
2926
+ return n - t > ($r - 1) * Wt ? !1 : (e.fullAt = n + Wt, !0);
2927
+ }
2928
+ function Sn(e, t) {
2929
+ let n;
2930
+ const s = new Promise((r) => {
2931
+ n = setTimeout(r, t);
2932
+ });
2933
+ return Promise.race([
2934
+ e.then((r) => ({ value: r }), (r) => ({ error: r })),
2935
+ s
2936
+ ]).finally(() => clearTimeout(n));
2937
+ }
2938
+ function st(e) {
2939
+ return new O("Could not fetch signing keys, try again later", {
2940
+ apiURI: e
2941
+ });
2942
+ }
2943
+ function zt(e) {
2944
+ let t = wn.get(e);
2945
+ return t || (t = { limit: { fullAt: -1 / 0, seen: -1 / 0 } }, wn.set(e, t)), t;
2946
+ }
2947
+ class kn extends Error {
2948
+ }
2949
+ function In(e) {
2950
+ return new O("Could not confirm the signing key, try again later", { kid: e });
2951
+ }
2952
+ async function vn(e, t) {
2953
+ const n = zt(e), s = () => n.ok && Pe(ce(), n.ok.at, Ir) ? n.ok : void 0, r = s();
2954
+ if (r)
2955
+ return r;
2956
+ const i = ce();
2957
+ let o = i + Ke, a = !1, c, u, p = 0;
2958
+ for (; ; ) {
2959
+ const b = n.pending, h = ce();
2960
+ if (!b || b === c || !Pe(h, b.at, Ke)) {
2961
+ if (a)
2962
+ throw u ?? st(e);
2963
+ break;
2964
+ }
2965
+ if (!a && b.at + Ke > o && (a = !0, o = b.at + Ke), !(h >= i && h < o))
2966
+ throw st(e);
2967
+ c = b, u = void 0;
2968
+ const S = await Sn(b.keys, Math.min(b.at + Ke, o) - h);
2969
+ if (S && "value" in S)
2970
+ return S.value;
2971
+ const $ = s();
2972
+ if ($)
2973
+ return $;
2974
+ if (S && (u = S.error, ++p >= 2))
2975
+ throw S.error;
2976
+ }
2977
+ const d = ce();
2978
+ if (d < i || !Er(n.limit, d))
2979
+ throw st(e);
2980
+ const y = t().then((b) => {
2981
+ if (!Array.isArray(b == null ? void 0 : b.keys))
2982
+ throw new O("The signing key set has no keys array", {
2983
+ apiURI: e
2984
+ });
2985
+ const h = { at: d, keys: b.keys };
2986
+ return n.recheckFailing = !1, (!s() || d >= n.ok.at) && (n.ok = h), h;
2987
+ });
2988
+ y.catch(() => {
2989
+ }), n.pending = { at: d, keys: y };
2990
+ const m = await Sn(y, i + vr - d);
2991
+ if (m && "value" in m)
2992
+ return m.value;
2993
+ const w = s();
2994
+ if (w)
2995
+ return w;
2996
+ throw m ? m.error : st(e);
2997
+ }
2998
+ function Cr(e, t) {
2999
+ return ["kty", "crv", "alg", "x", "y", "n", "e"].every((n) => e[n] === t[n]);
3000
+ }
3001
+ async function xr(e, t) {
2899
3002
  const n = await t.text();
2900
3003
  try {
2901
3004
  const s = JSON.parse(n);
2902
- return e(new ue({ status: t.status, body: s }));
3005
+ return e(new fe({ status: t.status, body: s }));
2903
3006
  } catch {
2904
- return e(new ue({
3007
+ return e(new fe({
2905
3008
  status: t.status,
2906
3009
  body: { type: void 0, message: n }
2907
3010
  }));
2908
3011
  }
2909
3012
  }
2910
- const ir = async (e, t) => {
3013
+ const Tr = async (e, t) => {
2911
3014
  const n = {
2912
3015
  ...(t == null ? void 0 : t.headers) || {},
2913
- "Instant-Core-Version": xe
3016
+ "Sidekick-Core-Version": Te
2914
3017
  }, s = await fetch(e, { ...t, headers: n });
2915
- return s.status === 200 ? s.json() : rr((r) => Promise.reject(r), s);
3018
+ return s.status === 200 ? s.json() : xr((r) => Promise.reject(r), s);
2916
3019
  };
2917
- function Un(e) {
3020
+ function Qn(e) {
2918
3021
  return e ? new Date(e) : null;
2919
3022
  }
2920
3023
  function Re(e) {
@@ -2929,9 +3032,9 @@ function Re(e) {
2929
3032
  updatedAt: new Date(e.updated_at)
2930
3033
  };
2931
3034
  }
2932
- function or(e) {
3035
+ function _r(e) {
2933
3036
  return {
2934
- attemptAt: Un(e["attempt-at"]),
3037
+ attemptAt: Qn(e["attempt-at"]),
2935
3038
  durationMs: e["duration-ms"] ?? null,
2936
3039
  success: e["success?"] ?? null,
2937
3040
  statusCode: e["status-code"] ?? null,
@@ -2940,33 +3043,33 @@ function or(e) {
2940
3043
  errorMessage: e["error-message"] ?? null
2941
3044
  };
2942
3045
  }
2943
- function Ot(e) {
3046
+ function At(e) {
2944
3047
  return {
2945
3048
  isn: e.isn,
2946
3049
  status: e.status,
2947
- attempts: e.attempts ? e.attempts.map(or) : null,
2948
- nextAttemptAfter: Un(e.next_attempt_after),
3050
+ attempts: e.attempts ? e.attempts.map(_r) : null,
3051
+ nextAttemptAfter: Qn(e.next_attempt_after),
2949
3052
  createdAt: new Date(e.created_at),
2950
3053
  updatedAt: new Date(e.updated_at)
2951
3054
  };
2952
3055
  }
2953
- var V, Be, De, Ne, Qe, G, ne;
2954
- class ar {
3056
+ var V, Xe, Le, Fe, Ye, G, ne;
3057
+ class Ar {
2955
3058
  constructor(t) {
2956
3059
  k(this, G);
2957
3060
  k(this, V);
2958
- k(this, Be);
2959
- k(this, De);
2960
- k(this, Ne);
2961
- k(this, Qe);
2962
- S(this, V, t.appId), S(this, Be, t.apiURI), S(this, De, t.token), S(this, Ne, t.withAuth), S(this, Qe, t.jsonFetch);
3061
+ k(this, Xe);
3062
+ k(this, Le);
3063
+ k(this, Fe);
3064
+ k(this, Ye);
3065
+ I(this, V, t.appId), I(this, Xe, t.apiURI), I(this, Le, t.token), I(this, Fe, t.withAuth), I(this, Ye, t.jsonFetch);
2963
3066
  }
2964
3067
  /**
2965
3068
  * Returns every webhook configured on the app, newest first. Includes both
2966
3069
  * active and disabled webhooks.
2967
3070
  */
2968
3071
  async list() {
2969
- return ((await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks`)).webhooks || []).map(Re);
3072
+ return ((await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks`)).webhooks || []).map(Re);
2970
3073
  }
2971
3074
  /**
2972
3075
  * Creates a new webhook. The webhook is created in the `active` state and
@@ -2981,13 +3084,13 @@ class ar {
2981
3084
  *
2982
3085
  * @example
2983
3086
  * const webhook = await db.webhooks.manager.create({
2984
- * url: 'https://example.com/instant',
3087
+ * url: 'https://example.com/sidekick',
2985
3088
  * namespaces: ['posts', 'comments'],
2986
3089
  * actions: ['create', 'update'],
2987
3090
  * });
2988
3091
  */
2989
3092
  async create(t) {
2990
- const n = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks`, {
3093
+ const n = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks`, {
2991
3094
  method: "POST",
2992
3095
  body: t
2993
3096
  });
@@ -3001,7 +3104,7 @@ class ar {
3001
3104
  * {@link disable} for that.
3002
3105
  */
3003
3106
  async update(t, n) {
3004
- const s = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}`, { method: "POST", body: n });
3107
+ const s = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}`, { method: "POST", body: n });
3005
3108
  return Re(s.webhook);
3006
3109
  }
3007
3110
  /**
@@ -3009,7 +3112,7 @@ class ar {
3009
3112
  * webhook as it looked just before deletion.
3010
3113
  */
3011
3114
  async delete(t) {
3012
- const n = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}`, { method: "DELETE" });
3115
+ const n = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}`, { method: "DELETE" });
3013
3116
  return Re(n.webhook);
3014
3117
  }
3015
3118
  /**
@@ -3020,7 +3123,7 @@ class ar {
3020
3123
  * delivered.
3021
3124
  */
3022
3125
  async enable(t) {
3023
- const n = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/enable`, { method: "POST", body: {} });
3126
+ const n = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/enable`, { method: "POST", body: {} });
3024
3127
  return Re(n.webhook);
3025
3128
  }
3026
3129
  /**
@@ -3032,7 +3135,7 @@ class ar {
3032
3135
  * and surfaced in the dashboard.
3033
3136
  */
3034
3137
  async disable(t, n) {
3035
- const s = n != null && n.reason ? { reason: n.reason } : {}, r = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/disable`, { method: "POST", body: s });
3138
+ const s = n != null && n.reason ? { reason: n.reason } : {}, r = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/disable`, { method: "POST", body: s });
3036
3139
  return Re(r.webhook);
3037
3140
  }
3038
3141
  /**
@@ -3044,9 +3147,9 @@ class ar {
3044
3147
  */
3045
3148
  async listEvents(t, n) {
3046
3149
  var i, o, a;
3047
- const s = n != null && n.after ? `?after=${encodeURIComponent(n.after)}` : "", r = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events${s}`);
3150
+ const s = n != null && n.after ? `?after=${encodeURIComponent(n.after)}` : "", r = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events${s}`);
3048
3151
  return {
3049
- events: (r.events || []).map(Ot),
3152
+ events: (r.events || []).map(At),
3050
3153
  pageInfo: {
3051
3154
  startCursor: ((i = r.pageInfo) == null ? void 0 : i.startCursor) ?? null,
3052
3155
  endCursor: ((o = r.pageInfo) == null ? void 0 : o.endCursor) ?? null,
@@ -3058,12 +3161,12 @@ class ar {
3058
3161
  * Fetches a single webhook event by its `isn`.
3059
3162
  */
3060
3163
  async getEvent(t, n) {
3061
- const s = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events/${n}`);
3062
- return Ot(s.event);
3164
+ const s = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events/${n}`);
3165
+ return At(s.event);
3063
3166
  }
3064
3167
  /** Returns the full payload for an event. */
3065
3168
  async getPayload(t, n) {
3066
- return O(this, G, ne).call(this, `/webhooks/payload/${f(this, V)}/${t}/${n}`);
3169
+ return E(this, G, ne).call(this, `/webhooks/payload/${f(this, V)}/${t}/${n}`);
3067
3170
  }
3068
3171
  /**
3069
3172
  * Re-queues an event for delivery, regardless of its current status. Use
@@ -3074,13 +3177,13 @@ class ar {
3074
3177
  * again in about a minute.
3075
3178
  */
3076
3179
  async resendEvent(t, n) {
3077
- const s = await O(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events/${n}`, { method: "POST", body: {} });
3078
- return Ot(s.event);
3180
+ const s = await E(this, G, ne).call(this, `/dash/apps/${f(this, V)}/webhooks/${t}/events/${n}`, { method: "POST", body: {} });
3181
+ return At(s.event);
3079
3182
  }
3080
3183
  }
3081
- V = new WeakMap(), Be = new WeakMap(), De = new WeakMap(), Ne = new WeakMap(), Qe = new WeakMap(), G = new WeakSet(), ne = function(t, n) {
3184
+ V = new WeakMap(), Xe = new WeakMap(), Le = new WeakMap(), Fe = new WeakMap(), Ye = new WeakMap(), G = new WeakSet(), ne = function(t, n) {
3082
3185
  if (!f(this, V))
3083
- throw new x("appId is required to manage webhooks. Pass it to the Webhooks constructor.");
3186
+ throw new O("appId is required to manage webhooks. Pass it to the Webhooks constructor.");
3084
3187
  const s = (r) => {
3085
3188
  const i = {
3086
3189
  method: n == null ? void 0 : n.method,
@@ -3089,33 +3192,34 @@ V = new WeakMap(), Be = new WeakMap(), De = new WeakMap(), Ne = new WeakMap(), Q
3089
3192
  "content-type": "application/json"
3090
3193
  }
3091
3194
  };
3092
- return (n == null ? void 0 : n.body) !== void 0 && (i.body = JSON.stringify(n.body)), f(this, Qe).call(this, `${f(this, Be)}${t}`, i);
3195
+ return (n == null ? void 0 : n.body) !== void 0 && (i.body = JSON.stringify(n.body)), f(this, Ye).call(this, `${f(this, Xe)}${t}`, i);
3093
3196
  };
3094
- if (f(this, Ne))
3095
- return f(this, Ne).call(this, s);
3096
- if (!f(this, De))
3097
- throw new x("A token is required to manage webhooks. Pass `adminToken` or `token` to the Webhooks constructor.");
3098
- return s(f(this, De));
3197
+ if (f(this, Fe))
3198
+ return f(this, Fe).call(this, s);
3199
+ if (!f(this, Le))
3200
+ throw new O("A token is required to manage webhooks. Pass `adminToken` or `token` to the Webhooks constructor.");
3201
+ return s(f(this, Le));
3099
3202
  };
3100
- var Ge, Oe;
3101
- const Kt = class Kt {
3203
+ var Ze, Ee, et, Vt;
3204
+ const Yt = class Yt {
3102
3205
  constructor(t, n) {
3206
+ k(this, et);
3103
3207
  /** App this instance is bound to. */
3104
- d(this, "appId");
3208
+ l(this, "appId");
3105
3209
  /** Schema used to type webhook payloads and handler records. */
3106
- d(this, "schema");
3107
- k(this, Ge);
3108
- /** Base URL for the Instant API. */
3109
- d(this, "apiURI");
3110
- k(this, Oe);
3210
+ l(this, "schema");
3211
+ k(this, Ze);
3212
+ /** Base URL for the SidekickDB API. */
3213
+ l(this, "apiURI");
3214
+ k(this, Ee);
3111
3215
  /** Manage webhook subscriptions and inspect delivery events. */
3112
- d(this, "manager");
3113
- this.appId = t.appId, this.schema = t.schema, S(this, Ge, t.adminToken || t.token), this.apiURI = Wt(t.apiURI, { target: "new Webhooks()" }), S(this, Oe, n || ir), this.manager = new ar({
3216
+ l(this, "manager");
3217
+ this.appId = t.appId, this.schema = t.schema, I(this, Ze, t.adminToken || t.token), this.apiURI = Xt(t.apiURI, { target: "new Webhooks()" }), I(this, Ee, n || Tr), this.manager = new Ar({
3114
3218
  appId: this.appId,
3115
3219
  apiURI: this.apiURI,
3116
- token: f(this, Ge),
3220
+ token: f(this, Ze),
3117
3221
  withAuth: t.withAuth,
3118
- jsonFetch: f(this, Oe)
3222
+ jsonFetch: f(this, Ee)
3119
3223
  });
3120
3224
  }
3121
3225
  /**
@@ -3165,62 +3269,91 @@ const Kt = class Kt {
3165
3269
  * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
3166
3270
  */
3167
3271
  helpers() {
3168
- return Kt.helpers();
3272
+ return Yt.helpers();
3169
3273
  }
3170
- /** Fetches Instant's JWK set for verifying webhook signatures. */
3274
+ /** Fetches the server's JWK set for verifying webhook signatures. */
3171
3275
  async fetchJwks() {
3172
- return await f(this, Oe).call(this, `${this.apiURI}/.well-known/webhooks/jwks.json`);
3276
+ return await f(this, Ee).call(this, `${this.apiURI}/.well-known/webhooks/jwks.json`);
3173
3277
  }
3174
3278
  /**
3175
3279
  * Resolves a `kid` to an imported {@link CryptoKey}, hitting a
3176
3280
  * process-wide cache on repeat calls. Falls back to {@link fetchJwks} if
3177
- * the key isn't already known.
3281
+ * the key isn't already known. A key set fetched successfully in the last
3282
+ * minute is reused instead of fetching again. A cached key is checked
3283
+ * against the published key set again 10 minutes after it was last
3284
+ * confirmed, and rejected once the server no longer publishes it.
3178
3285
  */
3179
3286
  async keyOfKid(t) {
3180
- var o, a, c;
3181
- const n = `${this.apiURI}:${t}`, s = cn[n];
3182
- if (s)
3183
- return s;
3184
- const r = ((o = Gs[this.apiURI]) == null ? void 0 : o.keys.find((u) => u.kid === t)) || ((c = (a = await this.fetchJwks()) == null ? void 0 : a.keys) == null ? void 0 : c.find((u) => u.kid === t));
3185
- if (!r)
3186
- throw new x("Could not find matching signing key", { kid: t });
3187
- const i = await Ys(r);
3188
- return cn[n] = i, i;
3287
+ var a;
3288
+ const n = br(this.apiURI, t);
3289
+ if (n && (n.confirmedAt === void 0 || Pe(ce(), n.confirmedAt, Sr)))
3290
+ return n;
3291
+ if (n) {
3292
+ const c = zt(this.apiURI), u = ce(), p = () => Pe(ce(), n.confirmedAt, kr), d = c.recheckFailing && Pe(u, c.recheckAt, Or), y = !d || !Pe(u, c.recheckAt, Wt);
3293
+ if (d && p())
3294
+ return y && E(this, et, Vt).call(this, t, n).catch(() => {
3295
+ }), n;
3296
+ if (!y)
3297
+ throw In(t);
3298
+ try {
3299
+ return await E(this, et, Vt).call(this, t, n);
3300
+ } catch (m) {
3301
+ if (!(m instanceof kn))
3302
+ throw m;
3303
+ if (p())
3304
+ return n;
3305
+ throw In(t);
3306
+ }
3307
+ }
3308
+ const s = (a = dr[this.apiURI]) == null ? void 0 : a.keys.find((c) => c.kid === t), r = s ? void 0 : await vn(this.apiURI, () => this.fetchJwks()), i = s || r.keys.find((c) => (c == null ? void 0 : c.kid) === t);
3309
+ if (!i)
3310
+ throw new O("Could not find matching signing key", { kid: t });
3311
+ const o = { ...await bn(i), jwk: i, confirmedAt: r == null ? void 0 : r.at };
3312
+ return gn(this.apiURI, t, o), o;
3189
3313
  }
3190
3314
  /**
3191
- * Verifies an `Instant-Signature` header against a body and returns the
3315
+ * Verifies a `Sidekick-Signature` header against a body and returns the
3192
3316
  * parsed {@link WebhookBody} (containing the `payloadUrl` and a JWT
3193
3317
  * `token` for fetching the records).
3194
3318
  *
3195
- * Throws if the signature doesn't validate, the signature is older than
3196
- * `opts.tolerance` (default 300 seconds), or the body doesn't decode to
3197
- * the expected shape.
3319
+ * Throws if `opts.tolerance` is not a finite number of 0 or more, the
3320
+ * signature doesn't validate, its timestamp is not whole
3321
+ * seconds or is more than `opts.tolerance` (default 300 seconds) before or
3322
+ * after `receivedAt`, or the body doesn't decode to the expected shape.
3198
3323
  *
3199
3324
  * @param body Either the raw body string, or a function returning it.
3200
3325
  * Use a function to defer reading the body until after the
3201
3326
  * header has been parsed.
3202
3327
  */
3203
3328
  async validate(t, n, s) {
3204
- const r = (s == null ? void 0 : s.receivedAt) || /* @__PURE__ */ new Date(), { t: i, kid: o, v1: a } = tr(t), c = (s == null ? void 0 : s.tolerance) ?? sr;
3205
- nr(r, i, c);
3206
- const { alg: u, key: h } = await this.keyOfKid(o), l = typeof n == "function" ? await n() : n, y = new TextEncoder().encode(`${i}.${l}`);
3207
- if (!await Zs(u, h, er(a), y))
3208
- throw new x("Instant Signature did not validate", {
3329
+ const r = (s == null ? void 0 : s.tolerance) ?? wr;
3330
+ if (typeof r != "number" || !Number.isFinite(r) || r < 0)
3331
+ throw new O("Invalid tolerance option: expected a finite number of seconds, 0 or more", { tolerance: r });
3332
+ const i = (s == null ? void 0 : s.receivedAt) ?? /* @__PURE__ */ new Date();
3333
+ if (!(i instanceof Date) || !Number.isFinite(i.getTime()))
3334
+ throw new O("Invalid receivedAt option: expected a valid Date", {
3335
+ receivedAt: i
3336
+ });
3337
+ const { t: o, kid: a, v1: c } = yr(t);
3338
+ mr(i, o, r);
3339
+ const { alg: u, key: p } = await this.keyOfKid(a), d = typeof n == "function" ? await n() : n, y = new TextEncoder().encode(`${o}.${d}`);
3340
+ if (!await hr(u, p, pr(c), y))
3341
+ throw new O("Sidekick Signature did not validate", {
3209
3342
  header: t
3210
3343
  });
3211
- const g = JSON.parse(l);
3212
- if (typeof g != "object" || typeof g.payloadUrl != "string" || typeof g.token != "string")
3213
- throw new x("Invalid webhook body, expected an object with payloadUrl and token fields", { body: g });
3214
- return g;
3344
+ const w = JSON.parse(d);
3345
+ if (typeof w != "object" || typeof w.payloadUrl != "string" || typeof w.token != "string")
3346
+ throw new O("Invalid webhook body, expected an object with payloadUrl and token fields", { body: w });
3347
+ return w;
3215
3348
  }
3216
3349
  /**
3217
- * Pulls the `Instant-Signature` header and body from a `Request` and
3350
+ * Pulls the `Sidekick-Signature` header and body from a `Request` and
3218
3351
  * delegates to {@link validate}. Throws if the header is missing.
3219
3352
  */
3220
3353
  async validateRequest(t, n) {
3221
- const s = t.headers.get("instant-signature");
3354
+ const s = t.headers.get("sidekick-signature");
3222
3355
  if (!s)
3223
- throw new x("Request is missing Instant-Signature header");
3356
+ throw new O("Request is missing Sidekick-Signature header");
3224
3357
  return this.validate(s, () => t.text(), n);
3225
3358
  }
3226
3359
  /**
@@ -3228,7 +3361,7 @@ const Kt = class Kt {
3228
3361
  * {@link WebhookBody}, authenticating with the JWT `token` it carries.
3229
3362
  */
3230
3363
  fetchPayloads({ payloadUrl: t, token: n }) {
3231
- return f(this, Oe).call(this, t, {
3364
+ return f(this, Ee).call(this, t, {
3232
3365
  headers: { Authorization: `Bearer ${n}`, accept: "application/json" }
3233
3366
  });
3234
3367
  }
@@ -3240,7 +3373,7 @@ const Kt = class Kt {
3240
3373
  *
3241
3374
  * Handlers run concurrently. If any handler rejects, the call rejects so
3242
3375
  * the caller (e.g. {@link processRequest}) can return a non-2xx response
3243
- * and let Instant retry the event.
3376
+ * and let the server retry the event.
3244
3377
  */
3245
3378
  async processPayload(t, n) {
3246
3379
  var r, i;
@@ -3335,12 +3468,12 @@ const Kt = class Kt {
3335
3468
  * const app = express();
3336
3469
  *
3337
3470
  * app.use((req, res, next) => {
3338
- * if (req.originalUrl === '/webhooks/instant') return next();
3471
+ * if (req.originalUrl === '/webhooks/sidekick') return next();
3339
3472
  * express.json()(req, res, next);
3340
3473
  * });
3341
3474
  *
3342
3475
  * app.post(
3343
- * '/webhooks/instant',
3476
+ * '/webhooks/sidekick',
3344
3477
  * express.raw({ type: 'application/json' }),
3345
3478
  * async (req, res) => {
3346
3479
  * try {
@@ -3362,7 +3495,7 @@ const Kt = class Kt {
3362
3495
  *
3363
3496
  * const router = new Router();
3364
3497
  *
3365
- * router.post('/webhooks/instant', async (ctx) => {
3498
+ * router.post('/webhooks/sidekick', async (ctx) => {
3366
3499
  * try {
3367
3500
  * await db.webhooks.processNodeRequest(handlers, ctx.req, {
3368
3501
  * body: rawBody(ctx.req), // adapter awaits the Promise
@@ -3382,7 +3515,7 @@ const Kt = class Kt {
3382
3515
  *
3383
3516
  * @Controller('webhooks')
3384
3517
  * export class WebhooksController {
3385
- * @Post('instant')
3518
+ * @Post('sidekick')
3386
3519
  * @HttpCode(200)
3387
3520
  * async handle(@Req() req: Request) {
3388
3521
  * await db.webhooks.processNodeRequest(handlers, req);
@@ -3401,103 +3534,123 @@ const Kt = class Kt {
3401
3534
  try {
3402
3535
  r = JSON.stringify(o), i = !0;
3403
3536
  } catch {
3404
- throw new x("Webhook request body has already been parsed and could not be re-serialized. Configure this route to receive the raw request body instead of parsed JSON.");
3537
+ throw new O("Webhook request body has already been parsed and could not be re-serialized. Configure this route to receive the raw request body instead of parsed JSON.");
3405
3538
  }
3406
3539
  else if (n[Symbol.asyncIterator]) {
3407
- const l = new TextEncoder(), y = [];
3408
- for await (const p of n)
3409
- y.push(typeof p == "string" ? l.encode(p) : p);
3540
+ const d = new TextEncoder(), y = [];
3541
+ for await (const h of n)
3542
+ y.push(typeof h == "string" ? d.encode(h) : h);
3410
3543
  let m = 0;
3411
- for (const p of y)
3412
- m += p.byteLength;
3413
- const g = new Uint8Array(m);
3414
- let w = 0;
3415
- for (const p of y)
3416
- g.set(p, w), w += p.byteLength;
3417
- r = new TextDecoder("utf-8").decode(g);
3544
+ for (const h of y)
3545
+ m += h.byteLength;
3546
+ const w = new Uint8Array(m);
3547
+ let b = 0;
3548
+ for (const h of y)
3549
+ w.set(h, b), b += h.byteLength;
3550
+ r = new TextDecoder("utf-8").decode(w);
3418
3551
  } else
3419
- throw new x("Could not read the webhook request body. Pass a Node IncomingMessage with an unconsumed stream, or set `req.body` to the raw bytes (Buffer/Uint8Array) or string.");
3552
+ throw new O("Could not read the webhook request body. Pass a Node IncomingMessage with an unconsumed stream, or set `req.body` to the raw bytes (Buffer/Uint8Array) or string.");
3420
3553
  const a = typeof n.headers.host == "string" ? n.headers.host : "localhost", c = new URL(n.url ?? "/", `https://${a}`), u = new Headers();
3421
- for (const [l, y] of Object.entries(n.headers))
3422
- typeof y == "string" ? u.set(l, y) : Array.isArray(y) && u.set(l, y.join(", "));
3423
- const h = new Request(c, {
3554
+ for (const [d, y] of Object.entries(n.headers))
3555
+ typeof y == "string" ? u.set(d, y) : Array.isArray(y) && u.set(d, y.join(", "));
3556
+ const p = new Request(c, {
3424
3557
  method: n.method ?? "POST",
3425
3558
  headers: u,
3426
3559
  body: r
3427
3560
  });
3428
3561
  try {
3429
- await this.processRequest(t, h, s);
3430
- } catch (l) {
3431
- throw i && l instanceof x && l.message === "Instant Signature did not validate" ? new x("Webhook signature did not validate. The request body was re-serialized from a parsed JSON object, which can produce different bytes than the server signed. Configure this route to receive the raw request body instead of parsed JSON.", { hint: l.hint }) : l;
3562
+ await this.processRequest(t, p, s);
3563
+ } catch (d) {
3564
+ throw i && d instanceof O && d.message === "Sidekick Signature did not validate" ? new O("Webhook signature did not validate. The request body was re-serialized from a parsed JSON object, which can produce different bytes than the server signed. Configure this route to receive the raw request body instead of parsed JSON.", { hint: d.hint }) : d;
3432
3565
  }
3433
3566
  }
3434
3567
  };
3435
- Ge = new WeakMap(), Oe = new WeakMap();
3436
- let Ut = Kt;
3437
- const cr = { target: "init() in @sidekickdb/admin" };
3438
- function ur(e) {
3568
+ Ze = new WeakMap(), Ee = new WeakMap(), et = new WeakSet(), Vt = async function(t, n) {
3569
+ const s = zt(this.apiURI);
3570
+ s.recheckAt = ce();
3571
+ let r;
3572
+ try {
3573
+ r = await vn(this.apiURI, () => this.fetchJwks());
3574
+ } catch {
3575
+ throw s.recheckFailing = !0, s.recheckAt = ce(), new kn();
3576
+ }
3577
+ const i = r.keys.find((a) => (a == null ? void 0 : a.kid) === t);
3578
+ if (i && Cr(i, n.jwk))
3579
+ return n.confirmedAt = r.at, n;
3580
+ if (gr(this.apiURI, t, n), !i)
3581
+ throw new O("Signing key is no longer published", { kid: t });
3582
+ const o = {
3583
+ ...await bn(i),
3584
+ jwk: i,
3585
+ confirmedAt: r.at
3586
+ };
3587
+ return gn(this.apiURI, t, o), o;
3588
+ };
3589
+ let Kt = Yt;
3590
+ const Rr = { target: "init() in @sidekickdb/admin" };
3591
+ function Pr(e) {
3439
3592
  return {
3440
3593
  ...e,
3441
- apiURI: Wt(e.apiURI, cr)
3594
+ apiURI: Xt(e.apiURI, Rr)
3442
3595
  };
3443
3596
  }
3444
- function fr(e, t) {
3597
+ function jr(e, t) {
3445
3598
  return "email" in t ? e["as-email"] = t.email : "token" in t ? e["as-token"] = t.token : "guest" in t && (e["as-guest"] = "true"), e;
3446
3599
  }
3447
- function dr(e, t) {
3600
+ function Ur(e, t) {
3448
3601
  if (!(t && ("token" in t || "guest" in t)) && !e.adminToken)
3449
3602
  throw t && "email" in t ? new Error("Admin token required. To impersonate users with an email you must pass `adminToken` to `init`.") : new Error("Admin token required. To run this operation pass `adminToken` to `init`, or use `db.asUser`.");
3450
3603
  }
3451
3604
  function P(e, t) {
3452
- dr(e, t);
3605
+ Ur(e, t);
3453
3606
  const { adminToken: n, appId: s } = e, r = {
3454
3607
  "content-type": "application/json",
3455
3608
  "app-id": s
3456
3609
  };
3457
- return n && (r.authorization = `Bearer ${n}`), t ? fr(r, t) : r;
3610
+ return n && (r.authorization = `Bearer ${n}`), t ? jr(r, t) : r;
3458
3611
  }
3459
- function lr() {
3612
+ function Mr() {
3460
3613
  return (
3461
3614
  // NextJS 13 onwards added a `__nextPatched` property to the fetch function
3462
3615
  fetch.__nextPatched && // NextJS 15 onwards _also_ added a global `next-patch` symbol.
3463
3616
  !globalThis[Symbol.for("next-patch")]
3464
3617
  );
3465
3618
  }
3466
- function hr() {
3467
- return lr() ? { cache: "no-store" } : {};
3619
+ function Dr() {
3620
+ return Mr() ? { cache: "no-store" } : {};
3468
3621
  }
3469
- async function pr(e, t) {
3622
+ async function Nr(e, t) {
3470
3623
  const n = await t.text();
3471
3624
  try {
3472
3625
  const s = JSON.parse(n);
3473
- return e(new ue({ status: t.status, body: s }));
3626
+ return e(new fe({ status: t.status, body: s }));
3474
3627
  } catch {
3475
- return e(new ue({
3628
+ return e(new fe({
3476
3629
  status: t.status,
3477
3630
  body: { type: void 0, message: n }
3478
3631
  }));
3479
3632
  }
3480
3633
  }
3481
- async function A(e, t) {
3482
- const n = hr(), s = {
3634
+ async function R(e, t) {
3635
+ const n = Dr(), s = {
3483
3636
  ...(t == null ? void 0 : t.headers) || {},
3484
- "Instant-Admin-Version": xe,
3485
- "Instant-Core-Version": xe
3637
+ "Sidekick-Admin-Version": Te,
3638
+ "Sidekick-Core-Version": Te
3486
3639
  }, r = await fetch(e, { ...n, ...t, headers: s });
3487
3640
  if (r.status === 200) {
3488
3641
  const i = await r.json();
3489
3642
  return Promise.resolve(i);
3490
3643
  }
3491
- return pr((i) => Promise.reject(i), r);
3644
+ return Nr((i) => Promise.reject(i), r);
3492
3645
  }
3493
- function yr(e) {
3494
- var t, n, Mn;
3646
+ function Lr(e) {
3647
+ var t, n, Gn;
3495
3648
  return t = class {
3496
3649
  constructor(i) {
3497
3650
  k(this, n);
3498
- d(this, "source");
3499
- d(this, "url");
3500
- this.url = i, this.source = O(this, n, Mn).call(this, i);
3651
+ l(this, "source");
3652
+ l(this, "url");
3653
+ this.url = i, this.source = E(this, n, Gn).call(this, i);
3501
3654
  }
3502
3655
  get onopen() {
3503
3656
  return this.source.onopen;
@@ -3523,9 +3676,9 @@ function yr(e) {
3523
3676
  close() {
3524
3677
  this.source.close();
3525
3678
  }
3526
- }, n = new WeakSet(), Mn = function(i) {
3679
+ }, n = new WeakSet(), Gn = function(i) {
3527
3680
  return new se(i, {
3528
- messageEvent: _n,
3681
+ messageEvent: Vn,
3529
3682
  fetch(a, c) {
3530
3683
  return fetch(a, {
3531
3684
  ...c,
@@ -3534,44 +3687,44 @@ function yr(e) {
3534
3687
  body: JSON.stringify({
3535
3688
  "inference?": e.inference,
3536
3689
  versions: {
3537
- "@instantdb/admin": xe,
3538
- "@instantdb/core": xe
3690
+ "@sidekickdb/admin": Te,
3691
+ "@sidekickdb/core": Te
3539
3692
  }
3540
3693
  })
3541
3694
  });
3542
3695
  }
3543
3696
  });
3544
- }, d(t, "OPEN", se.OPEN), d(t, "CONNECTING", se.CONNECTING), d(t, "CLOSED", se.CLOSED), t;
3697
+ }, l(t, "OPEN", se.OPEN), l(t, "CONNECTING", se.CONNECTING), l(t, "CLOSED", se.CLOSED), t;
3545
3698
  }
3546
- function mr(e) {
3699
+ function Fr(e) {
3547
3700
  var n, s;
3548
- (!e.appId || !Fe(e.appId)) && console.warn("warning: SidekickDB Admin DB must be initialized with a valid appId. Received: " + JSON.stringify(e.appId));
3701
+ (!e.appId || !ze(e.appId)) && console.warn("warning: SidekickDB Admin DB must be initialized with a valid appId. Received: " + JSON.stringify(e.appId));
3549
3702
  const t = {
3550
3703
  ...e,
3551
3704
  appId: (n = e.appId) == null ? void 0 : n.trim(),
3552
3705
  adminToken: (s = e.adminToken) == null ? void 0 : s.trim(),
3553
3706
  useDateObjects: e.useDateObjects ?? !1
3554
3707
  };
3555
- return new Mt(t);
3708
+ return new Jt(t);
3556
3709
  }
3557
- function un(e) {
3558
- return (Array.isArray(e) ? e : [e]).flatMap(hs);
3710
+ function $n(e) {
3711
+ return (Array.isArray(e) ? e : [e]).flatMap(Cs);
3559
3712
  }
3560
- class br {
3713
+ class Wr {
3561
3714
  constructor(t) {
3562
- d(this, "config");
3715
+ l(this, "config");
3563
3716
  this.config = t;
3564
3717
  }
3565
3718
  async getPresence(t, n) {
3566
- return (await A(`${this.config.apiURI}/admin/rooms/presence?app_id=${this.config.appId}&room-type=${String(t)}&room-id=${n}`, {
3719
+ return (await R(`${this.config.apiURI}/admin/rooms/presence?app_id=${this.config.appId}&room-type=${String(t)}&room-id=${n}`, {
3567
3720
  method: "GET",
3568
3721
  headers: P(this.config)
3569
3722
  })).sessions || {};
3570
3723
  }
3571
3724
  }
3572
- class gr {
3725
+ class zr {
3573
3726
  constructor(t) {
3574
- d(this, "config");
3727
+ l(this, "config");
3575
3728
  /**
3576
3729
  * Generates a magic code for the user with the given email.
3577
3730
  * This is useful if you want to use your own email provider
@@ -3585,14 +3738,14 @@ class gr {
3585
3738
  *
3586
3739
  * @see https://sidekickdb.co/docs/backend#custom-magic-codes
3587
3740
  */
3588
- d(this, "generateMagicCode", async (t) => A(`${this.config.apiURI}/admin/magic_code?app_id=${this.config.appId}`, {
3741
+ l(this, "generateMagicCode", async (t) => R(`${this.config.apiURI}/admin/magic_code?app_id=${this.config.appId}`, {
3589
3742
  method: "POST",
3590
3743
  headers: P(this.config),
3591
3744
  body: JSON.stringify({ email: t })
3592
3745
  }));
3593
3746
  /**
3594
3747
  * Sends a magic code to the user with the given email.
3595
- * This uses Instant's built-in email provider.
3748
+ * This uses the server's built-in email provider.
3596
3749
  *
3597
3750
  * @example
3598
3751
  * // Send an email to user with magic code
@@ -3600,7 +3753,7 @@ class gr {
3600
3753
  *
3601
3754
  * @see https://sidekickdb.co/docs/backend#custom-magic-codes
3602
3755
  */
3603
- d(this, "sendMagicCode", async (t) => A(`${this.config.apiURI}/admin/send_magic_code?app_id=${this.config.appId}`, {
3756
+ l(this, "sendMagicCode", async (t) => R(`${this.config.apiURI}/admin/send_magic_code?app_id=${this.config.appId}`, {
3604
3757
  method: "POST",
3605
3758
  headers: P(this.config),
3606
3759
  body: JSON.stringify({ email: t })
@@ -3611,8 +3764,8 @@ class gr {
3611
3764
  *
3612
3765
  * @see https://sidekickdb.co/docs/backend#custom-magic-codes
3613
3766
  */
3614
- d(this, "verifyMagicCode", async (t, n) => {
3615
- const { user: s } = await A(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
3767
+ l(this, "verifyMagicCode", async (t, n) => {
3768
+ const { user: s } = await R(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
3616
3769
  method: "POST",
3617
3770
  headers: P(this.config),
3618
3771
  body: JSON.stringify({ email: t, code: n })
@@ -3633,8 +3786,8 @@ class gr {
3633
3786
  *
3634
3787
  * @see https://sidekickdb.co/docs/backend#custom-magic-codes
3635
3788
  */
3636
- d(this, "checkMagicCode", async (t, n, s) => {
3637
- const r = await A(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
3789
+ l(this, "checkMagicCode", async (t, n, s) => {
3790
+ const r = await R(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
3638
3791
  method: "POST",
3639
3792
  headers: P(this.config),
3640
3793
  body: JSON.stringify({
@@ -3659,9 +3812,9 @@ class gr {
3659
3812
  * }
3660
3813
  * // ...
3661
3814
  * })
3662
- * @see https://sidekickdb.co/docs/backend#custom-endpoints
3815
+ * @see https://sidekickdb.co/docs/backend#2-backend-auth-verify-token
3663
3816
  */
3664
- d(this, "verifyToken", async (t) => (await A(`${this.config.apiURI}/runtime/auth/verify_refresh_token?app_id=${this.config.appId}`, {
3817
+ l(this, "verifyToken", async (t) => (await R(`${this.config.apiURI}/runtime/auth/verify_refresh_token?app_id=${this.config.appId}`, {
3665
3818
  method: "POST",
3666
3819
  headers: { "content-type": "application/json" },
3667
3820
  body: JSON.stringify({
@@ -3684,9 +3837,9 @@ class gr {
3684
3837
  *
3685
3838
  * @see https://sidekickdb.co/docs/backend#retrieve-a-user
3686
3839
  */
3687
- d(this, "getUser", async (t) => {
3840
+ l(this, "getUser", async (t) => {
3688
3841
  const n = new URLSearchParams(Object.entries(t)).toString();
3689
- return (await A(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
3842
+ return (await R(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
3690
3843
  method: "GET",
3691
3844
  headers: P(this.config)
3692
3845
  })).user;
@@ -3709,22 +3862,22 @@ class gr {
3709
3862
  *
3710
3863
  * @see https://sidekickdb.co/docs/backend#delete-a-user
3711
3864
  */
3712
- d(this, "deleteUser", async (t) => {
3865
+ l(this, "deleteUser", async (t) => {
3713
3866
  const n = new URLSearchParams(Object.entries(t)).toString();
3714
- return (await A(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
3867
+ return (await R(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
3715
3868
  method: "DELETE",
3716
3869
  headers: P(this.config)
3717
3870
  })).deleted;
3718
3871
  });
3719
3872
  /**
3720
- * Get instant user from Request
3873
+ * Get the SidekickDB user from a Request
3721
3874
  *
3722
3875
  * Reads cookies and gets a validated user
3723
- * @param req The request containing a cookie synced with createInstantRouteHandler
3876
+ * @param req The request containing a cookie synced with createSidekickRouteHandler
3724
3877
  * @param opts Allow disabling validation of refresh token
3725
3878
  */
3726
- d(this, "getUserFromRequest", async (t, n) => {
3727
- const s = t.headers.get("cookie") || "", r = zs(s), i = "instant_user_" + this.config.appId;
3879
+ l(this, "getUserFromRequest", async (t, n) => {
3880
+ const s = t.headers.get("cookie") || "", r = nr(s), i = "sidekick_user_" + this.config.appId;
3728
3881
  if (!r[i])
3729
3882
  return null;
3730
3883
  const o = r[i], a = JSON.parse(o);
@@ -3734,7 +3887,7 @@ class gr {
3734
3887
  }
3735
3888
  async createToken(t) {
3736
3889
  const n = typeof t == "string" ? { email: t } : t;
3737
- return (await A(`${this.config.apiURI}/admin/refresh_tokens?app_id=${this.config.appId}`, {
3890
+ return (await R(`${this.config.apiURI}/admin/refresh_tokens?app_id=${this.config.appId}`, {
3738
3891
  method: "POST",
3739
3892
  headers: P(this.config),
3740
3893
  body: JSON.stringify(n)
@@ -3742,21 +3895,21 @@ class gr {
3742
3895
  }
3743
3896
  async signOut(t) {
3744
3897
  const n = typeof t == "string" ? { email: t } : t, s = this.config;
3745
- await A(`${s.apiURI}/admin/sign_out?app_id=${this.config.appId}`, {
3898
+ await R(`${s.apiURI}/admin/sign_out?app_id=${this.config.appId}`, {
3746
3899
  method: "POST",
3747
3900
  headers: P(s),
3748
3901
  body: JSON.stringify(n)
3749
3902
  });
3750
3903
  }
3751
3904
  }
3752
- const fn = (e) => e && typeof e == "object" && typeof e.pipe == "function" && typeof e.read == "function", wr = (e) => e && typeof e.getReader == "function";
3753
- function dn(e) {
3905
+ const On = (e) => e && typeof e == "object" && typeof e.pipe == "function" && typeof e.read == "function", Kr = (e) => e && typeof e.getReader == "function";
3906
+ function En(e) {
3754
3907
  return /^[\x20-\x7e\xa0-\xff]*$/.test(e);
3755
3908
  }
3756
- class ln {
3909
+ class Cn {
3757
3910
  constructor(t, n) {
3758
- d(this, "config");
3759
- d(this, "impersonationOpts");
3911
+ l(this, "config");
3912
+ l(this, "impersonationOpts");
3760
3913
  /**
3761
3914
  * Uploads file at the provided path. Accepts a Buffer or a Readable stream.
3762
3915
  *
@@ -3765,13 +3918,13 @@ class ln {
3765
3918
  * const buffer = fs.readFileSync('demo.png');
3766
3919
  * const isSuccess = await db.storage.uploadFile('photos/demo.png', buffer);
3767
3920
  */
3768
- d(this, "uploadFile", async (t, n, s = {}) => {
3921
+ l(this, "uploadFile", async (t, n, s = {}) => {
3769
3922
  const r = {
3770
3923
  ...P(this.config, this.impersonationOpts)
3771
3924
  };
3772
- dn(t) && (r.path = t), s.contentDisposition && dn(s.contentDisposition) && (r["content-disposition"] = s.contentDisposition), delete r["content-type"], s.contentType && (r["content-type"] = s.contentType);
3925
+ En(t) && (r.path = t), s.contentDisposition && En(s.contentDisposition) && (r["content-disposition"] = s.contentDisposition), delete r["content-type"], s.contentType && (r["content-type"] = s.contentType);
3773
3926
  let i;
3774
- if (fn(n) && (i = "half"), fn(n) || wr(n)) {
3927
+ if (On(n) && (i = "half"), On(n) || Kr(n)) {
3775
3928
  if (!s.fileSize)
3776
3929
  throw new Error("fileSize is required in metadata when uploading streams");
3777
3930
  r["content-length"] = s.fileSize.toString();
@@ -3782,7 +3935,7 @@ class ln {
3782
3935
  body: n,
3783
3936
  ...i && { duplex: i }
3784
3937
  }, a = `${this.config.apiURI}/admin/storage/upload?app_id=${encodeURIComponent(this.config.appId)}&path=${encodeURIComponent(t)}`;
3785
- return s.contentDisposition && (a += `&content-disposition=${encodeURIComponent(s.contentDisposition)}`), A(a, o);
3938
+ return s.contentDisposition && (a += `&content-disposition=${encodeURIComponent(s.contentDisposition)}`), R(a, o);
3786
3939
  });
3787
3940
  /**
3788
3941
  * Deletes a file by its path name (e.g. "photos/demo.png").
@@ -3797,7 +3950,7 @@ class ln {
3797
3950
  *
3798
3951
  * @see https://sidekickdb.co/docs/storage
3799
3952
  */
3800
- d(this, "delete", async (t) => A(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
3953
+ l(this, "delete", async (t) => R(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
3801
3954
  method: "DELETE",
3802
3955
  headers: P(this.config, this.impersonationOpts)
3803
3956
  }));
@@ -3812,7 +3965,7 @@ class ln {
3812
3965
  *
3813
3966
  * @see https://sidekickdb.co/docs/storage
3814
3967
  */
3815
- d(this, "deleteMany", async (t) => A(`${this.config.apiURI}/admin/storage/files/delete?app_id=${this.config.appId}`, {
3968
+ l(this, "deleteMany", async (t) => R(`${this.config.apiURI}/admin/storage/files/delete?app_id=${this.config.appId}`, {
3816
3969
  method: "POST",
3817
3970
  headers: P(this.config, this.impersonationOpts),
3818
3971
  body: JSON.stringify({ filenames: t })
@@ -3821,8 +3974,8 @@ class ln {
3821
3974
  * @deprecated. This method will be removed in the future. Use `uploadFile`
3822
3975
  * instead
3823
3976
  */
3824
- d(this, "upload", async (t, n, s = {}) => {
3825
- const { data: r } = await A(`${this.config.apiURI}/admin/storage/signed-upload-url?app_id=${this.config.appId}`, {
3977
+ l(this, "upload", async (t, n, s = {}) => {
3978
+ const { data: r } = await R(`${this.config.apiURI}/admin/storage/signed-upload-url?app_id=${this.config.appId}`, {
3826
3979
  method: "POST",
3827
3980
  headers: P(this.config),
3828
3981
  body: JSON.stringify({
@@ -3843,8 +3996,8 @@ class ln {
3843
3996
  * @example
3844
3997
  * const files = await db.query({ $files: {}})
3845
3998
  */
3846
- d(this, "list", async () => {
3847
- const { data: t } = await A(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}`, {
3999
+ l(this, "list", async () => {
4000
+ const { data: t } = await R(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}`, {
3848
4001
  method: "GET",
3849
4002
  headers: P(this.config)
3850
4003
  });
@@ -3864,8 +4017,8 @@ class ln {
3864
4017
  * }
3865
4018
  * })
3866
4019
  */
3867
- d(this, "getDownloadUrl", async (t) => {
3868
- const { data: n } = await A(`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
4020
+ l(this, "getDownloadUrl", async (t) => {
4021
+ const { data: n } = await R(`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
3869
4022
  method: "GET",
3870
4023
  headers: P(this.config)
3871
4024
  });
@@ -3874,10 +4027,10 @@ class ln {
3874
4027
  this.config = t, this.impersonationOpts = n;
3875
4028
  }
3876
4029
  }
3877
- var Le;
3878
- class Sr {
4030
+ var We;
4031
+ class Vr {
3879
4032
  constructor(t) {
3880
- k(this, Le);
4033
+ k(this, We);
3881
4034
  /**
3882
4035
  * Creates a new ReadableStream for the given clientId.
3883
4036
  *
@@ -3887,7 +4040,7 @@ class Sr {
3887
4040
  * console.log(chunk);
3888
4041
  * }
3889
4042
  */
3890
- d(this, "createReadStream", (t) => f(this, Le).call(this).createReadStream(t));
4043
+ l(this, "createReadStream", (t) => f(this, We).call(this).createReadStream(t));
3891
4044
  /**
3892
4045
  * Creates a new WritableStream for the given clientId.
3893
4046
  *
@@ -3897,12 +4050,12 @@ class Sr {
3897
4050
  * writer.write('Hello world');
3898
4051
  * writer.close();
3899
4052
  */
3900
- d(this, "createWriteStream", (t) => f(this, Le).call(this).createWriteStream(t));
3901
- S(this, Le, t);
4053
+ l(this, "createWriteStream", (t) => f(this, We).call(this).createWriteStream(t));
4054
+ I(this, We, t);
3902
4055
  }
3903
4056
  }
3904
- Le = new WeakMap();
3905
- function Ir(e, t = console) {
4057
+ We = new WeakMap();
4058
+ function Jr(e, t = console) {
3906
4059
  return {
3907
4060
  info: e ? (...n) => t.info(...n) : () => {
3908
4061
  },
@@ -3912,22 +4065,22 @@ function Ir(e, t = console) {
3912
4065
  }
3913
4066
  };
3914
4067
  }
3915
- var W, Ee, J, H, D, Dn, rt, Nn, Ln, Fn, lt, ht, pt, Dt, zn, yt;
3916
- const Vt = class Vt {
4068
+ var z, Ce, J, H, D, Xn, ut, Yn, Zn, es, gt, wt, St, Ht, ts, kt;
4069
+ const Zt = class Zt {
3917
4070
  constructor(t) {
3918
4071
  k(this, D);
3919
- d(this, "config");
3920
- d(this, "auth");
3921
- d(this, "storage");
3922
- d(this, "streams");
3923
- d(this, "rooms");
3924
- d(this, "impersonationOpts");
3925
- d(this, "webhooks");
3926
- k(this, W, null);
3927
- k(this, Ee, 0);
4072
+ l(this, "config");
4073
+ l(this, "auth");
4074
+ l(this, "storage");
4075
+ l(this, "streams");
4076
+ l(this, "rooms");
4077
+ l(this, "impersonationOpts");
4078
+ l(this, "webhooks");
4079
+ k(this, z, null);
4080
+ k(this, Ce, 0);
3928
4081
  k(this, J, null);
3929
4082
  k(this, H);
3930
- d(this, "tx", $n());
4083
+ l(this, "tx", Dn());
3931
4084
  /**
3932
4085
  * Sometimes you want to scope queries to a specific user.
3933
4086
  *
@@ -3935,18 +4088,18 @@ const Vt = class Vt {
3935
4088
  *
3936
4089
  * @see https://sidekickdb.co/docs/backend#impersonating-users
3937
4090
  * @example
3938
- * await db.asUser({email: "stopa@example.com"}).query({ goals: {} })
4091
+ * await db.asUser({email: "ava@example.com"}).query({ goals: {} })
3939
4092
  */
3940
- d(this, "asUser", (t) => {
3941
- const n = new Vt({
4093
+ l(this, "asUser", (t) => {
4094
+ const n = new Zt({
3942
4095
  ...this.config
3943
4096
  });
3944
- return n.impersonationOpts = t, n.storage = new ln(this.config, t), n;
4097
+ return n.impersonationOpts = t, n.storage = new Cn(this.config, t), n;
3945
4098
  });
3946
4099
  /**
3947
4100
  * Use this to query your data!
3948
4101
  *
3949
- * @see https://sidekickdb.co/docs/instaql
4102
+ * @see https://sidekickdb.co/docs/sideql
3950
4103
  *
3951
4104
  * @example
3952
4105
  * // fetch all goals
@@ -3958,10 +4111,10 @@ const Vt = class Vt {
3958
4111
  * // all goals, _alongside_ their todos
3959
4112
  * await db.query({ goals: { todos: {} } })
3960
4113
  */
3961
- d(this, "query", (t, n = {}) => {
3962
- t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t }), this.config.disableValidation || Zt(t, this.config.schema);
4114
+ l(this, "query", (t, n = {}) => {
4115
+ t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t }), this.config.disableValidation || un(t, this.config.schema);
3963
4116
  const s = n.fetchOpts || {}, r = s.headers || {};
3964
- return A(`${this.config.apiURI}/admin/query?app_id=${this.config.appId}`, {
4117
+ return R(`${this.config.apiURI}/admin/query?app_id=${this.config.appId}`, {
3965
4118
  ...s,
3966
4119
  method: "POST",
3967
4120
  headers: {
@@ -3977,7 +4130,7 @@ const Vt = class Vt {
3977
4130
  /**
3978
4131
  * Use this to write data! You can create, update, delete, and link objects
3979
4132
  *
3980
- * @see https://sidekickdb.co/docs/instaml
4133
+ * @see https://sidekickdb.co/docs/sideml
3981
4134
  *
3982
4135
  * @example
3983
4136
  * // Create a new object in the `goals` namespace
@@ -3997,11 +4150,11 @@ const Vt = class Vt {
3997
4150
  * db.tx.goals[goalId].link({todos: todoId}),
3998
4151
  * ])
3999
4152
  */
4000
- d(this, "transact", (t) => (this.config.disableValidation || ks(t, this.config.schema), A(`${this.config.apiURI}/admin/transact?app_id=${this.config.appId}`, {
4153
+ l(this, "transact", (t) => (this.config.disableValidation || Ms(t, this.config.schema), R(`${this.config.apiURI}/admin/transact?app_id=${this.config.appId}`, {
4001
4154
  method: "POST",
4002
4155
  headers: P(this.config, this.impersonationOpts),
4003
4156
  body: JSON.stringify({
4004
- steps: un(t),
4157
+ steps: $n(t),
4005
4158
  "throw-on-missing-attrs?": !!this.config.schema
4006
4159
  })
4007
4160
  })));
@@ -4018,7 +4171,7 @@ const Vt = class Vt {
4018
4171
  * Accepts an optional configuration object with a `rules` key.
4019
4172
  * The provided rules will override the rules in the database for the query.
4020
4173
  *
4021
- * @see https://sidekickdb.co/docs/instaql
4174
+ * @see https://sidekickdb.co/docs/sideql
4022
4175
  *
4023
4176
  * @example
4024
4177
  * await db.asUser({ guest: true }).debugQuery(
@@ -4026,7 +4179,7 @@ const Vt = class Vt {
4026
4179
  * { rules: { goals: { allow: { read: "auth.id != null" } } }
4027
4180
  * )
4028
4181
  */
4029
- d(this, "debugQuery", async (t, n) => {
4182
+ l(this, "debugQuery", async (t, n) => {
4030
4183
  t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t });
4031
4184
  const s = {
4032
4185
  query: t,
@@ -4034,7 +4187,7 @@ const Vt = class Vt {
4034
4187
  "inference?": (n == null ? void 0 : n.cardinalityInference) ?? !!this.config.schema
4035
4188
  };
4036
4189
  n != null && n.ip && (s["ip-override"] = n.ip), n != null && n.origin && (s["origin-override"] = n.origin);
4037
- const r = await A(`${this.config.apiURI}/admin/query_perms_check?app_id=${this.config.appId}`, {
4190
+ const r = await R(`${this.config.apiURI}/admin/query_perms_check?app_id=${this.config.appId}`, {
4038
4191
  method: "POST",
4039
4192
  headers: P(this.config, this.impersonationOpts),
4040
4193
  body: JSON.stringify(s)
@@ -4062,46 +4215,46 @@ const Vt = class Vt {
4062
4215
  * { rules: { goals: { allow: { update: "auth.id != null" } } }
4063
4216
  * )
4064
4217
  */
4065
- d(this, "debugTransact", (t, n) => {
4218
+ l(this, "debugTransact", (t, n) => {
4066
4219
  const s = {
4067
- steps: un(t),
4220
+ steps: $n(t),
4068
4221
  "rules-override": n == null ? void 0 : n.rules,
4069
4222
  // @ts-expect-error because we're using a private API (for now)
4070
4223
  "dangerously-commit-tx": n == null ? void 0 : n.__dangerouslyCommit
4071
4224
  };
4072
- return n != null && n.ip && (s["ip-override"] = n.ip), n != null && n.origin && (s["origin-override"] = n.origin), A(`${this.config.apiURI}/admin/transact_perms_check?app_id=${this.config.appId}`, {
4225
+ return n != null && n.ip && (s["ip-override"] = n.ip), n != null && n.origin && (s["origin-override"] = n.origin), R(`${this.config.apiURI}/admin/transact_perms_check?app_id=${this.config.appId}`, {
4073
4226
  method: "POST",
4074
4227
  headers: P(this.config, this.impersonationOpts),
4075
4228
  body: JSON.stringify(s)
4076
4229
  });
4077
4230
  });
4078
- k(this, lt, (t) => {
4231
+ k(this, gt, (t) => {
4079
4232
  var n;
4080
- if (t.target !== f(this, W)) {
4233
+ if (t.target !== f(this, z)) {
4081
4234
  f(this, H).info("[socket][open]", t.target.id, "skip; this is no longer the current transport");
4082
4235
  return;
4083
4236
  }
4084
- f(this, H).info("[socket][open]", t.target.id), S(this, Ee, 0), (n = f(this, J)) == null || n.onConnectionStatusChange("authenticated");
4237
+ f(this, H).info("[socket][open]", t.target.id), I(this, Ce, 0), (n = f(this, J)) == null || n.onConnectionStatusChange("authenticated");
4085
4238
  });
4086
- k(this, ht, (t) => {
4239
+ k(this, wt, (t) => {
4087
4240
  var n;
4088
- if (t.target !== f(this, W)) {
4241
+ if (t.target !== f(this, z)) {
4089
4242
  f(this, H).info("[socket][close]", t.target.id, "skip; this is no longer the current transport");
4090
4243
  return;
4091
4244
  }
4092
- f(this, H).info("[socket][close]", t.target.id), (n = f(this, J)) == null || n.onConnectionStatusChange("closed"), f(this, W) && (S(this, W, null), O(this, D, Dt).call(this) || (setTimeout(() => O(this, D, rt).call(this), f(this, Ee)), S(this, Ee, Math.min(15e3, Math.max(f(this, Ee), 500) * 2))));
4245
+ f(this, H).info("[socket][close]", t.target.id), (n = f(this, J)) == null || n.onConnectionStatusChange("closed"), f(this, z) && (I(this, z, null), E(this, D, Ht).call(this) || (setTimeout(() => E(this, D, ut).call(this), f(this, Ce)), I(this, Ce, Math.min(15e3, Math.max(f(this, Ce), 500) * 2))));
4093
4246
  });
4094
- k(this, pt, (t) => {
4247
+ k(this, St, (t) => {
4095
4248
  var n;
4096
- if (t.target !== f(this, W)) {
4249
+ if (t.target !== f(this, z)) {
4097
4250
  f(this, H).info("[socket][error]", t.target.id, "skip; this is no longer the current transport");
4098
4251
  return;
4099
4252
  }
4100
4253
  f(this, H).info("[socket][error]", t.target.id), (n = f(this, J)) == null || n.onConnectionStatusChange("closed");
4101
4254
  });
4102
- k(this, yt, (t) => {
4255
+ k(this, kt, (t) => {
4103
4256
  var s, r, i, o, a, c;
4104
- if (t.target !== f(this, W)) {
4257
+ if (t.target !== f(this, z)) {
4105
4258
  f(this, H).info("[socket][message]", t.target.id, "skip; this is no longer the current transport");
4106
4259
  return;
4107
4260
  }
@@ -4136,9 +4289,9 @@ const Vt = class Vt {
4136
4289
  break;
4137
4290
  }
4138
4291
  }
4139
- O(this, D, zn).call(this);
4292
+ E(this, D, ts).call(this);
4140
4293
  });
4141
- this.config = ur(t), this.auth = new gr(this.config), this.storage = new ln(this.config, this.impersonationOpts), this.streams = new Sr(O(this, D, Fn).bind(this)), this.rooms = new br(this.config), this.webhooks = new Ut(this.config, A), S(this, H, Ir(!!this.config.verbose, this.config.logger));
4294
+ this.config = Pr(t), this.auth = new zr(this.config), this.storage = new Cn(this.config, this.impersonationOpts), this.streams = new Vr(E(this, D, es).bind(this)), this.rooms = new Wr(this.config), this.webhooks = new Kt(this.config, R), I(this, H, Jr(!!this.config.verbose, this.config.logger));
4142
4295
  }
4143
4296
  /**
4144
4297
  * Use this to to get a live view of your data!
@@ -4176,55 +4329,55 @@ const Vt = class Vt {
4176
4329
  * });
4177
4330
  */
4178
4331
  subscribeQuery(t, n, s = {}) {
4179
- t && s && "ruleParams" in s && (t = { $$ruleParams: s.ruleParams, ...t }), this.config.disableValidation || Zt(t, this.config.schema);
4332
+ t && s && "ruleParams" in s && (t = { $$ruleParams: s.ruleParams, ...t }), this.config.disableValidation || un(t, this.config.schema);
4180
4333
  const o = {
4181
4334
  ...(s.fetchOpts || {}).headers || {},
4182
4335
  ...P(this.config, this.impersonationOpts)
4183
4336
  }, a = !!this.config.schema;
4184
- return Fs(t, n, {
4337
+ return tr(t, n, {
4185
4338
  headers: o,
4186
4339
  inference: a,
4187
4340
  apiURI: this.config.apiURI
4188
4341
  });
4189
4342
  }
4190
4343
  };
4191
- W = new WeakMap(), Ee = new WeakMap(), J = new WeakMap(), H = new WeakMap(), D = new WeakSet(), Dn = function() {
4192
- f(this, W) && f(this, W).close();
4344
+ z = new WeakMap(), Ce = new WeakMap(), J = new WeakMap(), H = new WeakMap(), D = new WeakSet(), Xn = function() {
4345
+ f(this, z) && f(this, z).close();
4193
4346
  const t = {
4194
4347
  ...P(this.config, this.impersonationOpts)
4195
- }, n = !!this.config.schema, s = yr({ headers: t, inference: n }), r = new vs(s, `${this.config.apiURI}/admin/sse?app_id=${this.config.appId}`, `${this.config.apiURI}/admin/sse/push?app_id=${this.config.appId}`);
4196
- return r.onopen = f(this, lt), r.onmessage = f(this, yt), r.onclose = f(this, ht), r.onerror = f(this, pt), S(this, W, r), r;
4197
- }, rt = function() {
4198
- return f(this, W) || O(this, D, Dn).call(this);
4199
- }, Nn = function(t, n) {
4200
- const s = O(this, D, rt).call(this);
4348
+ }, n = !!this.config.schema, s = Lr({ headers: t, inference: n }), r = new Ls(s, `${this.config.apiURI}/admin/sse?app_id=${this.config.appId}`, `${this.config.apiURI}/admin/sse/push?app_id=${this.config.appId}`);
4349
+ return r.onopen = f(this, gt), r.onmessage = f(this, kt), r.onclose = f(this, wt), r.onerror = f(this, St), I(this, z, r), r;
4350
+ }, ut = function() {
4351
+ return f(this, z) || E(this, D, Xn).call(this);
4352
+ }, Yn = function(t, n) {
4353
+ const s = E(this, D, ut).call(this);
4201
4354
  f(this, H).info("[send]", t, n, {
4202
4355
  isOpen: s.isOpen()
4203
4356
  }), s.isOpen() && s.send({ "client-event-id": t, ...n });
4204
- }, Ln = function() {
4205
- O(this, D, rt).call(this);
4206
- const t = new xs({
4357
+ }, Zn = function() {
4358
+ E(this, D, ut).call(this);
4359
+ const t = new Ks({
4207
4360
  WStream: this.config.WritableStream || WritableStream,
4208
4361
  RStream: this.config.ReadableStream || ReadableStream,
4209
4362
  trySend: (n, s) => {
4210
- O(this, D, Nn).call(this, n, s);
4363
+ E(this, D, Yn).call(this, n, s);
4211
4364
  },
4212
4365
  log: f(this, H)
4213
4366
  });
4214
- return S(this, J, t), t;
4215
- }, Fn = function() {
4216
- return f(this, J) || O(this, D, Ln).call(this);
4217
- }, lt = new WeakMap(), ht = new WeakMap(), pt = new WeakMap(), Dt = function() {
4367
+ return I(this, J, t), t;
4368
+ }, es = function() {
4369
+ return f(this, J) || E(this, D, Zn).call(this);
4370
+ }, gt = new WeakMap(), wt = new WeakMap(), St = new WeakMap(), Ht = function() {
4218
4371
  return !f(this, J) || !f(this, J).hasActiveStreams();
4219
- }, zn = function() {
4220
- if (f(this, W) && O(this, D, Dt).call(this)) {
4221
- const t = f(this, W);
4222
- f(this, H).info("cleaning up unused socket", t.id), S(this, W, null), t.close();
4223
- }
4224
- }, yt = new WeakMap();
4225
- let Mt = Vt;
4226
- var hn = {};
4227
- function Ze(e) {
4372
+ }, ts = function() {
4373
+ if (f(this, z) && E(this, D, Ht).call(this)) {
4374
+ const t = f(this, z);
4375
+ f(this, H).info("cleaning up unused socket", t.id), I(this, z, null), t.close();
4376
+ }
4377
+ }, kt = new WeakMap();
4378
+ let Jt = Zt;
4379
+ var Hr = {};
4380
+ function rt(e) {
4228
4381
  let t = e;
4229
4382
  return new TransformStream({
4230
4383
  transform(n, s) {
@@ -4241,74 +4394,72 @@ function Ze(e) {
4241
4394
  }
4242
4395
  });
4243
4396
  }
4244
- function et(e) {
4245
- return [
4246
- hn[e],
4247
- hn[e.replace("SIDEKICK_", "INSTANT_")]
4248
- ].find((t) => t == null ? void 0 : t.trim());
4397
+ function it(e) {
4398
+ const t = Hr[e];
4399
+ return t != null && t.trim() ? t : void 0;
4249
4400
  }
4250
- function vr(e) {
4251
- const t = e.appId || et("SIDEKICK_APP_ID") || et("NEXT_PUBLIC_SIDEKICK_APP_ID");
4401
+ function Qr(e) {
4402
+ const t = e.appId || it("SIDEKICK_APP_ID") || it("NEXT_PUBLIC_SIDEKICK_APP_ID");
4252
4403
  if (!t)
4253
4404
  throw new Error(
4254
4405
  "Missing appId. Pass it as an argument to createResumableStreamContext or set either the SIDEKICK_APP_ID or NEXT_PUBLIC_SIDEKICK_APP_ID environment variable."
4255
4406
  );
4256
- const n = e.adminToken || et("SIDEKICK_APP_ADMIN_TOKEN");
4407
+ const n = e.adminToken || it("SIDEKICK_APP_ADMIN_TOKEN");
4257
4408
  if (!n)
4258
4409
  throw new Error(
4259
4410
  "Missing adminToken. Pass it as an argument to createResumableStreamContext or set the SIDEKICK_APP_ADMIN_TOKEN environment variable."
4260
4411
  );
4261
- const s = Wt(e.apiURI || et("SIDEKICK_API_URI"), {
4412
+ const s = Xt(e.apiURI || it("SIDEKICK_API_URI"), {
4262
4413
  target: "createResumableStreamContext()",
4263
4414
  envVar: "SIDEKICK_API_URI"
4264
4415
  }), r = { appId: t, adminToken: n, apiURI: s };
4265
4416
  e.verbose && (r.verbose = e.verbose);
4266
- const i = mr(r);
4267
- async function o(h, l, y) {
4417
+ const i = Fr(r);
4418
+ async function o(p, d, y) {
4268
4419
  const m = i.streams.createWriteStream({
4269
- clientId: h,
4420
+ clientId: p,
4270
4421
  waitUntil: e.waitUntil ?? void 0
4271
4422
  });
4272
4423
  try {
4273
- const g = await m.streamId();
4274
- l().pipeTo(m);
4275
- const p = i.streams.createReadStream({ streamId: g });
4276
- return y ? p.pipeThrough(
4277
- Ze(y)
4278
- ) : p;
4424
+ const w = await m.streamId();
4425
+ d().pipeTo(m);
4426
+ const h = i.streams.createReadStream({ streamId: w });
4427
+ return y ? h.pipeThrough(
4428
+ rt(y)
4429
+ ) : h;
4279
4430
  } catch {
4280
- const w = i.streams.createReadStream({ clientId: h });
4281
- return y ? w.pipeThrough(
4282
- Ze(y)
4283
- ) : w;
4431
+ const b = i.streams.createReadStream({ clientId: p });
4432
+ return y ? b.pipeThrough(
4433
+ rt(y)
4434
+ ) : b;
4284
4435
  }
4285
4436
  }
4286
- async function a(h, l) {
4287
- var m, g, w;
4288
- const y = i.streams.createReadStream({ clientId: h });
4437
+ async function a(p, d) {
4438
+ var m, w, b;
4439
+ const y = i.streams.createReadStream({ clientId: p });
4289
4440
  try {
4290
4441
  await y.streamId();
4291
- } catch (p) {
4292
- if (p instanceof x && ((w = (g = (m = p.hint) == null ? void 0 : m.errors) == null ? void 0 : g[0]) == null ? void 0 : w.message) === "Stream is missing.")
4442
+ } catch (h) {
4443
+ if (h instanceof O && ((b = (w = (m = h.hint) == null ? void 0 : m.errors) == null ? void 0 : w[0]) == null ? void 0 : b.message) === "Stream is missing.")
4293
4444
  return;
4294
- throw p;
4445
+ throw h;
4295
4446
  }
4296
- return l ? y.pipeThrough(Ze(l)) : y;
4447
+ return d ? y.pipeThrough(rt(d)) : y;
4297
4448
  }
4298
- async function c(h, l, y) {
4299
- const m = l(), g = i.streams.createWriteStream({
4300
- clientId: h,
4449
+ async function c(p, d, y) {
4450
+ const m = d(), w = i.streams.createWriteStream({
4451
+ clientId: p,
4301
4452
  waitUntil: e.waitUntil ?? void 0
4302
4453
  });
4303
- await g.streamId(), m.pipeTo(g);
4304
- const w = i.streams.createReadStream({ clientId: h });
4305
- return y ? w.pipeThrough(Ze(y)) : w;
4454
+ await w.streamId(), m.pipeTo(w);
4455
+ const b = i.streams.createReadStream({ clientId: p });
4456
+ return y ? b.pipeThrough(rt(y)) : b;
4306
4457
  }
4307
- async function u(h) {
4458
+ async function u(p) {
4308
4459
  var m;
4309
- const l = await i.query({
4310
- $streams: { $: { where: { clientId: h } } }
4311
- }), y = (m = l == null ? void 0 : l.$streams) == null ? void 0 : m[0];
4460
+ const d = await i.query({
4461
+ $streams: { $: { where: { clientId: p } } }
4462
+ }), y = (m = d == null ? void 0 : d.$streams) == null ? void 0 : m[0];
4312
4463
  return y != null && y.done ? "DONE" : y ? !0 : null;
4313
4464
  }
4314
4465
  return {
@@ -4319,5 +4470,5 @@ function vr(e) {
4319
4470
  };
4320
4471
  }
4321
4472
  export {
4322
- vr as createResumableStreamContext
4473
+ Qr as createResumableStreamContext
4323
4474
  };