@instantdb/resumable-stream 1.0.30 → 1.0.31

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 Tn = Object.defineProperty;
2
- var Dt = (e) => {
1
+ var Hn = Object.defineProperty;
2
+ var Xt = (e) => {
3
3
  throw TypeError(e);
4
4
  };
5
- var Rn = (e, t, n) => t in e ? Tn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
6
- var f = (e, t, n) => Rn(e, typeof t != "symbol" ? t + "" : t, n), ct = (e, t, n) => t.has(e) || Dt("Cannot " + n);
7
- var g = (e, t, n) => (ct(e, t, "read from private field"), n ? n.call(e) : t.get(e)), K = (e, t, n) => t.has(e) ? Dt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), oe = (e, t, n, s) => (ct(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), X = (e, t, n) => (ct(e, t, "access private method"), n);
8
- const Pn = /^(?:[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 Ae(e) {
10
- return typeof e == "string" && Pn.test(e);
11
- }
12
- const D = [];
5
+ var Kn = (e, t, n) => t in e ? Hn(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) || Xt("Cannot " + n);
7
+ var y = (e, t, n) => (wt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), j = (e, t, n) => t.has(e) ? Xt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), J = (e, t, n, s) => (wt(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), R = (e, t, n) => (wt(e, t, "access private method"), n);
8
+ const qn = /^(?:[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" && qn.test(e);
11
+ }
12
+ const F = [];
13
13
  for (let e = 0; e < 256; ++e)
14
- D.push((e + 256).toString(16).slice(1));
15
- function An(e, t = 0) {
16
- return (D[e[t + 0]] + D[e[t + 1]] + D[e[t + 2]] + D[e[t + 3]] + "-" + D[e[t + 4]] + D[e[t + 5]] + "-" + D[e[t + 6]] + D[e[t + 7]] + "-" + D[e[t + 8]] + D[e[t + 9]] + "-" + D[e[t + 10]] + D[e[t + 11]] + D[e[t + 12]] + D[e[t + 13]] + D[e[t + 14]] + D[e[t + 15]]).toLowerCase();
17
- }
18
- let ut;
19
- const Mn = new Uint8Array(16);
20
- function jn() {
21
- if (!ut) {
14
+ F.push((e + 256).toString(16).slice(1));
15
+ function Bn(e, t = 0) {
16
+ return (F[e[t + 0]] + F[e[t + 1]] + F[e[t + 2]] + F[e[t + 3]] + "-" + F[e[t + 4]] + F[e[t + 5]] + "-" + F[e[t + 6]] + F[e[t + 7]] + "-" + F[e[t + 8]] + F[e[t + 9]] + "-" + F[e[t + 10]] + F[e[t + 11]] + F[e[t + 12]] + F[e[t + 13]] + F[e[t + 14]] + F[e[t + 15]]).toLowerCase();
17
+ }
18
+ let gt;
19
+ const Qn = new Uint8Array(16);
20
+ function Gn() {
21
+ if (!gt) {
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
- ut = crypto.getRandomValues.bind(crypto);
24
+ gt = crypto.getRandomValues.bind(crypto);
25
25
  }
26
- return ut(Mn);
26
+ return gt(Qn);
27
27
  }
28
- const Un = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Lt = { randomUUID: Un };
29
- function Nn(e, t, n) {
30
- var i;
31
- if (Lt.randomUUID && !e)
32
- return Lt.randomUUID();
28
+ const Xn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Yt = { randomUUID: Xn };
29
+ function Yn(e, t, n) {
30
+ var r;
31
+ if (Yt.randomUUID && !e)
32
+ return Yt.randomUUID();
33
33
  e = e || {};
34
- const s = e.random ?? ((i = e.rng) == null ? void 0 : i.call(e)) ?? jn();
34
+ const s = e.random ?? ((r = e.rng) == null ? void 0 : r.call(e)) ?? Gn();
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, An(s);
37
+ return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, Bn(s);
38
38
  }
39
- const j = {
39
+ const N = {
40
40
  Remove: "remove",
41
41
  Replace: "replace",
42
42
  Add: "add"
43
- }, nn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), Ge = Symbol.iterator, se = {
43
+ }, bn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), nt = Symbol.iterator, ae = {
44
44
  mutable: "mutable",
45
45
  immutable: "immutable"
46
- }, Tt = {};
47
- function De(e, t) {
46
+ }, zt = {};
47
+ function He(e, t) {
48
48
  return e instanceof Map ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
49
49
  }
50
- function Wt(e, t) {
50
+ function Zt(e, t) {
51
51
  if (t in e) {
52
52
  let n = Reflect.getPrototypeOf(e);
53
53
  for (; n; ) {
@@ -58,84 +58,84 @@ function Wt(e, t) {
58
58
  }
59
59
  }
60
60
  }
61
- function sn(e) {
61
+ function wn(e) {
62
62
  return Object.getPrototypeOf(e) === Set.prototype;
63
63
  }
64
- function rn(e) {
64
+ function gn(e) {
65
65
  return Object.getPrototypeOf(e) === Map.prototype;
66
66
  }
67
- function B(e) {
67
+ function Z(e) {
68
68
  var t;
69
69
  return (t = e.copy) !== null && t !== void 0 ? t : e.original;
70
70
  }
71
- function pt(e) {
72
- return !!O(e);
71
+ function Ot(e) {
72
+ return !!$(e);
73
73
  }
74
- function O(e) {
75
- return typeof e != "object" ? null : e == null ? void 0 : e[nn];
74
+ function $(e) {
75
+ return typeof e != "object" ? null : e == null ? void 0 : e[bn];
76
76
  }
77
- function Rt(e) {
77
+ function Vt(e) {
78
78
  var t;
79
- const n = O(e);
79
+ const n = $(e);
80
80
  return n ? (t = n.copy) !== null && t !== void 0 ? t : n.original : e;
81
81
  }
82
- function Ee(e, t) {
82
+ function Ce(e, t) {
83
83
  if (!e || typeof e != "object")
84
84
  return !1;
85
85
  let n;
86
- return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!(t != null && t.mark) && ((n = t.mark(e, se)) === se.immutable || typeof n == "function");
86
+ return Object.getPrototypeOf(e) === Object.prototype || Array.isArray(e) || e instanceof Map || e instanceof Set || !!(t != null && t.mark) && ((n = t.mark(e, ae)) === ae.immutable || typeof n == "function");
87
87
  }
88
- function on(e, t = []) {
88
+ function Sn(e, t = []) {
89
89
  if (Object.hasOwnProperty.call(e, "key")) {
90
- const n = e.parent.copy, s = O(me(n, e.key));
90
+ const n = e.parent.copy, s = $(ge(n, e.key));
91
91
  if (s !== null && (s == null ? void 0 : s.original) !== e.original)
92
92
  return null;
93
- const i = e.parent.type === 3, r = i ? Array.from(e.parent.setMap.keys()).indexOf(e.key) : e.key;
94
- if (!(i && n.size > r || De(n, r)))
93
+ const r = e.parent.type === 3, o = r ? Array.from(e.parent.setMap.keys()).indexOf(e.key) : e.key;
94
+ if (!(r && n.size > o || He(n, o)))
95
95
  return null;
96
- t.push(r);
96
+ t.push(o);
97
97
  }
98
98
  if (e.parent)
99
- return on(e.parent, t);
99
+ return Sn(e.parent, t);
100
100
  t.reverse();
101
101
  try {
102
- Dn(e.copy, t);
102
+ Zn(e.copy, t);
103
103
  } catch {
104
104
  return null;
105
105
  }
106
106
  return t;
107
107
  }
108
- function ze(e) {
108
+ function Ye(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 ze(e) === 2 ? e.get(t) : e[t];
111
+ function ge(e, t) {
112
+ return Ye(e) === 2 ? e.get(t) : e[t];
113
113
  }
114
- function Pt(e, t, n) {
115
- ze(e) === 2 ? e.set(t, n) : e[t] = n;
114
+ function Jt(e, t, n) {
115
+ Ye(e) === 2 ? e.set(t, n) : e[t] = n;
116
116
  }
117
- function ft(e, t) {
118
- const n = O(e);
119
- return (n ? B(n) : e)[t];
117
+ function St(e, t) {
118
+ const n = $(e);
119
+ return (n ? Z(n) : e)[t];
120
120
  }
121
- function Ie(e, t) {
121
+ function Ee(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 ve(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 Dn(e, t) {
130
+ function Zn(e, t) {
131
131
  for (let n = 0; n < t.length - 1; n += 1) {
132
132
  const s = t[n];
133
- if (e = me(ze(e) === 3 ? Array.from(e) : e, s), typeof e != "object")
133
+ if (e = ge(Ye(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 Ln(e) {
138
+ function es(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 Ln(e) {
151
151
  }), Reflect.defineProperty(t, n, s);
152
152
  }), t;
153
153
  }
154
- const Wn = Object.prototype.propertyIsEnumerable;
155
- function Fn(e, t) {
154
+ const ts = Object.prototype.propertyIsEnumerable;
155
+ function ns(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 (!sn(e)) {
160
+ if (!wn(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 (!rn(e)) {
166
+ if (!gn(e)) {
167
167
  const s = Object.getPrototypeOf(e).constructor;
168
168
  return new s(e);
169
169
  }
170
170
  return new Map(e);
171
- } else if (t != null && t.mark && (n = t.mark(e, se), n !== void 0) && n !== se.mutable) {
172
- if (n === se.immutable)
173
- return Ln(e);
171
+ } else if (t != null && t.mark && (n = t.mark(e, ae), n !== void 0) && n !== ae.mutable) {
172
+ if (n === ae.immutable)
173
+ return es(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.");
@@ -179,36 +179,36 @@ function Fn(e, t) {
179
179
  throw new Error(`Unsupported mark result: ${n}`);
180
180
  } else if (typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype) {
181
181
  const s = {};
182
- return Object.keys(e).forEach((i) => {
183
- s[i] = e[i];
184
- }), Object.getOwnPropertySymbols(e).forEach((i) => {
185
- Wn.call(e, i) && (s[i] = e[i]);
182
+ return Object.keys(e).forEach((r) => {
183
+ s[r] = e[r];
184
+ }), Object.getOwnPropertySymbols(e).forEach((r) => {
185
+ ts.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 J(e) {
191
- e.copy || (e.copy = Fn(e.original, e.options));
190
+ function Q(e) {
191
+ e.copy || (e.copy = ns(e.original, e.options));
192
192
  }
193
- function je(e) {
194
- if (!Ee(e))
195
- return Rt(e);
193
+ function ze(e) {
194
+ if (!Ce(e))
195
+ return Vt(e);
196
196
  if (Array.isArray(e))
197
- return e.map(je);
197
+ return e.map(ze);
198
198
  if (e instanceof Map) {
199
- const n = Array.from(e.entries()).map(([s, i]) => [
199
+ const n = Array.from(e.entries()).map(([s, r]) => [
200
200
  s,
201
- je(i)
201
+ ze(r)
202
202
  ]);
203
- if (!rn(e)) {
203
+ if (!gn(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(je);
211
- if (!sn(e)) {
210
+ const n = Array.from(e).map(ze);
211
+ if (!wn(e)) {
212
212
  const s = Object.getPrototypeOf(e).constructor;
213
213
  return new s(n);
214
214
  }
@@ -216,236 +216,236 @@ function je(e) {
216
216
  }
217
217
  const t = Object.create(Object.getPrototypeOf(e));
218
218
  for (const n in e)
219
- t[n] = je(e[n]);
219
+ t[n] = ze(e[n]);
220
220
  return t;
221
221
  }
222
- function He(e) {
223
- return pt(e) ? je(e) : e;
222
+ function st(e) {
223
+ return Ot(e) ? ze(e) : e;
224
224
  }
225
- function ie(e) {
225
+ function ce(e) {
226
226
  var t;
227
- e.assignedMap = (t = e.assignedMap) !== null && t !== void 0 ? t : /* @__PURE__ */ new Map(), e.operated || (e.operated = !0, e.parent && ie(e.parent));
227
+ e.assignedMap = (t = e.assignedMap) !== null && t !== void 0 ? t : /* @__PURE__ */ new Map(), e.operated || (e.operated = !0, e.parent && ce(e.parent));
228
228
  }
229
- function zn(e, t) {
230
- const n = ze(e);
229
+ function ss(e, t) {
230
+ const n = Ye(e);
231
231
  if (n === 0)
232
232
  Reflect.ownKeys(e).forEach((s) => {
233
233
  t(s, e[s], e);
234
234
  });
235
235
  else if (n === 1) {
236
236
  let s = 0;
237
- for (const i of e)
238
- t(s, i, e), s += 1;
237
+ for (const r of e)
238
+ t(s, r, e), s += 1;
239
239
  } else
240
- e.forEach((s, i) => t(i, s, e));
240
+ e.forEach((s, r) => t(r, s, e));
241
241
  }
242
- function an(e, t, n) {
243
- if (pt(e) || !Ee(e, n) || t.has(e) || Object.isFrozen(e))
242
+ function In(e, t, n) {
243
+ if (Ot(e) || !Ce(e, n) || t.has(e) || Object.isFrozen(e))
244
244
  return;
245
- const s = e instanceof Set, i = s ? /* @__PURE__ */ new Map() : void 0;
246
- if (t.add(e), zn(e, (r, o) => {
245
+ const s = e instanceof Set, r = s ? /* @__PURE__ */ new Map() : void 0;
246
+ if (t.add(e), ss(e, (o, i) => {
247
247
  var a;
248
- if (pt(o)) {
249
- const c = O(o);
250
- J(c);
248
+ if (Ot(i)) {
249
+ const c = $(i);
250
+ Q(c);
251
251
  const u = !((a = c.assignedMap) === null || a === void 0) && a.size || c.operated ? c.copy : c.original;
252
- Pt(s ? i : e, r, u);
252
+ Jt(s ? r : e, o, u);
253
253
  } else
254
- an(o, t, n);
255
- }), i) {
256
- const r = e, o = Array.from(r);
257
- r.clear(), o.forEach((a) => {
258
- r.add(i.has(a) ? i.get(a) : a);
254
+ In(i, t, n);
255
+ }), r) {
256
+ const o = e, i = Array.from(o);
257
+ o.clear(), i.forEach((a) => {
258
+ o.add(r.has(a) ? r.get(a) : a);
259
259
  });
260
260
  }
261
261
  }
262
- function Vn(e, t) {
262
+ function rs(e, t) {
263
263
  const n = e.type === 3 ? e.setMap : e.copy;
264
- e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && an(me(n, t), e.finalities.handledSet, e.options);
264
+ e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && In(ge(n, t), e.finalities.handledSet, e.options);
265
265
  }
266
- function mt(e) {
266
+ function Et(e) {
267
267
  e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
268
- e.copy.add(Rt(t));
268
+ e.copy.add(Vt(t));
269
269
  }));
270
270
  }
271
- function yt(e, t, n, s) {
271
+ function _t(e, t, n, s) {
272
272
  if (e.operated && e.assignedMap && e.assignedMap.size > 0 && !e.finalized) {
273
273
  if (n && s) {
274
- const r = on(e);
275
- r && t(e, r, n, s);
274
+ const o = Sn(e);
275
+ o && t(e, o, n, s);
276
276
  }
277
277
  e.finalized = !0;
278
278
  }
279
279
  }
280
- function At(e, t, n, s) {
281
- const i = O(n);
282
- i && (i.callbacks || (i.callbacks = []), i.callbacks.push((r, o) => {
280
+ function Ht(e, t, n, s) {
281
+ const r = $(n);
282
+ r && (r.callbacks || (r.callbacks = []), r.callbacks.push((o, i) => {
283
283
  var a;
284
284
  const c = e.type === 3 ? e.setMap : e.copy;
285
- if (Ie(me(c, t), n)) {
286
- let u = i.original;
287
- i.copy && (u = i.copy), mt(e), yt(e, s, r, o), e.options.enableAutoFreeze && (e.options.updatedValues = (a = e.options.updatedValues) !== null && a !== void 0 ? a : /* @__PURE__ */ new WeakMap(), e.options.updatedValues.set(u, i.original)), Pt(c, t, u);
285
+ if (Ee(ge(c, t), n)) {
286
+ let u = r.original;
287
+ r.copy && (u = r.copy), Et(e), _t(e, s, o, i), 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)), Jt(c, t, u);
288
288
  }
289
- }), e.options.enableAutoFreeze && i.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), Ee(n, e.options) && e.finalities.draft.push(() => {
290
- const r = e.type === 3 ? e.setMap : e.copy;
291
- Ie(me(r, t), n) && Vn(e, t);
289
+ }), e.options.enableAutoFreeze && r.finalities !== e.finalities && (e.options.enableAutoFreeze = !1)), Ce(n, e.options) && e.finalities.draft.push(() => {
290
+ const o = e.type === 3 ? e.setMap : e.copy;
291
+ Ee(ge(o, t), n) && rs(e, t);
292
292
  });
293
293
  }
294
- function Jn(e, t, n, s, i) {
295
- let { original: r, assignedMap: o, options: a } = e, c = e.copy;
296
- c.length < r.length && ([r, c] = [c, r], [n, s] = [s, n]);
297
- for (let u = 0; u < r.length; u += 1)
298
- if (o.get(u.toString()) && c[u] !== r[u]) {
299
- const l = t.concat([u]), d = we(l, i);
294
+ function is(e, t, n, s, r) {
295
+ let { original: o, assignedMap: i, options: a } = e, c = e.copy;
296
+ c.length < o.length && ([o, c] = [c, o], [n, s] = [s, n]);
297
+ for (let u = 0; u < o.length; u += 1)
298
+ if (i.get(u.toString()) && c[u] !== o[u]) {
299
+ const l = t.concat([u]), f = ve(l, r);
300
300
  n.push({
301
- op: j.Replace,
302
- path: d,
301
+ op: N.Replace,
302
+ path: f,
303
303
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
304
- value: He(c[u])
304
+ value: st(c[u])
305
305
  }), s.push({
306
- op: j.Replace,
307
- path: d,
306
+ op: N.Replace,
307
+ path: f,
308
308
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
309
- value: He(r[u])
309
+ value: st(o[u])
310
310
  });
311
311
  }
312
- for (let u = r.length; u < c.length; u += 1) {
313
- const l = t.concat([u]), d = we(l, i);
312
+ for (let u = o.length; u < c.length; u += 1) {
313
+ const l = t.concat([u]), f = ve(l, r);
314
314
  n.push({
315
- op: j.Add,
316
- path: d,
315
+ op: N.Add,
316
+ path: f,
317
317
  // If it is a draft, it needs to be deep cloned, and it may also be non-draft.
318
- value: He(c[u])
318
+ value: st(c[u])
319
319
  });
320
320
  }
321
- if (r.length < c.length) {
321
+ if (o.length < c.length) {
322
322
  const { arrayLengthAssignment: u = !0 } = a.enablePatches;
323
323
  if (u) {
324
- const l = t.concat(["length"]), d = we(l, i);
324
+ const l = t.concat(["length"]), f = ve(l, r);
325
325
  s.push({
326
- op: j.Replace,
327
- path: d,
328
- value: r.length
326
+ op: N.Replace,
327
+ path: f,
328
+ value: o.length
329
329
  });
330
330
  } else
331
- for (let l = c.length; r.length < l; l -= 1) {
332
- const d = t.concat([l - 1]), p = we(d, i);
331
+ for (let l = c.length; o.length < l; l -= 1) {
332
+ const f = t.concat([l - 1]), p = ve(f, r);
333
333
  s.push({
334
- op: j.Remove,
334
+ op: N.Remove,
335
335
  path: p
336
336
  });
337
337
  }
338
338
  }
339
339
  }
340
- function Qn({ original: e, copy: t, assignedMap: n }, s, i, r, o) {
340
+ function os({ original: e, copy: t, assignedMap: n }, s, r, o, i) {
341
341
  n.forEach((a, c) => {
342
- const u = me(e, c), l = He(me(t, c)), d = a ? De(e, c) ? j.Replace : j.Add : j.Remove;
343
- if (Ie(u, l) && d === j.Replace)
342
+ const u = ge(e, c), l = st(ge(t, c)), f = a ? He(e, c) ? N.Replace : N.Add : N.Remove;
343
+ if (Ee(u, l) && f === N.Replace)
344
344
  return;
345
- const p = s.concat(c), y = we(p, o);
346
- i.push(d === j.Remove ? { op: d, path: y } : { op: d, path: y, value: l }), r.push(d === j.Add ? { op: j.Remove, path: y } : d === j.Remove ? { op: j.Add, path: y, value: u } : { op: j.Replace, path: y, value: u });
345
+ const p = s.concat(c), m = ve(p, i);
346
+ r.push(f === N.Remove ? { op: f, path: m } : { op: f, path: m, value: l }), o.push(f === N.Add ? { op: N.Remove, path: m } : f === N.Remove ? { op: N.Add, path: m, value: u } : { op: N.Replace, path: m, value: u });
347
347
  });
348
348
  }
349
- function Gn({ original: e, copy: t }, n, s, i, r) {
350
- let o = 0;
349
+ function as({ original: e, copy: t }, n, s, r, o) {
350
+ let i = 0;
351
351
  e.forEach((a) => {
352
352
  if (!t.has(a)) {
353
- const c = n.concat([o]), u = we(c, r);
353
+ const c = n.concat([i]), u = ve(c, o);
354
354
  s.push({
355
- op: j.Remove,
355
+ op: N.Remove,
356
356
  path: u,
357
357
  value: a
358
- }), i.unshift({
359
- op: j.Add,
358
+ }), r.unshift({
359
+ op: N.Add,
360
360
  path: u,
361
361
  value: a
362
362
  });
363
363
  }
364
- o += 1;
365
- }), o = 0, t.forEach((a) => {
364
+ i += 1;
365
+ }), i = 0, t.forEach((a) => {
366
366
  if (!e.has(a)) {
367
- const c = n.concat([o]), u = we(c, r);
367
+ const c = n.concat([i]), u = ve(c, o);
368
368
  s.push({
369
- op: j.Add,
369
+ op: N.Add,
370
370
  path: u,
371
371
  value: a
372
- }), i.unshift({
373
- op: j.Remove,
372
+ }), r.unshift({
373
+ op: N.Remove,
374
374
  path: u,
375
375
  value: a
376
376
  });
377
377
  }
378
- o += 1;
378
+ i += 1;
379
379
  });
380
380
  }
381
- function Fe(e, t, n, s) {
382
- const { pathAsArray: i = !0 } = e.options.enablePatches;
381
+ function Be(e, t, n, s) {
382
+ const { pathAsArray: r = !0 } = e.options.enablePatches;
383
383
  switch (e.type) {
384
384
  case 0:
385
385
  case 2:
386
- return Qn(e, t, n, s, i);
386
+ return os(e, t, n, s, r);
387
387
  case 1:
388
- return Jn(e, t, n, s, i);
388
+ return is(e, t, n, s, r);
389
389
  case 3:
390
- return Gn(e, t, n, s, i);
390
+ return as(e, t, n, s, r);
391
391
  }
392
392
  }
393
- const Ye = (e, t, n = !1) => {
394
- if (typeof e == "object" && e !== null && (!Ee(e, t) || n))
393
+ const ct = (e, t, n = !1) => {
394
+ if (typeof e == "object" && e !== null && (!Ce(e, t) || n))
395
395
  throw new Error("Strict mode: Mutable data cannot be accessed directly, please use 'unsafe(callback)' wrap.");
396
- }, bt = {
396
+ }, Ct = {
397
397
  get size() {
398
- return B(O(this)).size;
398
+ return Z($(this)).size;
399
399
  },
400
400
  has(e) {
401
- return B(O(this)).has(e);
401
+ return Z($(this)).has(e);
402
402
  },
403
403
  set(e, t) {
404
- const n = O(this), s = B(n);
405
- return (!s.has(e) || !Ie(s.get(e), t)) && (J(n), ie(n), n.assignedMap.set(e, !0), n.copy.set(e, t), At(n, e, t, Fe)), this;
404
+ const n = $(this), s = Z(n);
405
+ return (!s.has(e) || !Ee(s.get(e), t)) && (Q(n), ce(n), n.assignedMap.set(e, !0), n.copy.set(e, t), Ht(n, e, t, Be)), this;
406
406
  },
407
407
  delete(e) {
408
408
  if (!this.has(e))
409
409
  return !1;
410
- const t = O(this);
411
- return J(t), ie(t), t.original.has(e) ? t.assignedMap.set(e, !1) : t.assignedMap.delete(e), t.copy.delete(e), !0;
410
+ const t = $(this);
411
+ return Q(t), ce(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 = O(this);
414
+ const e = $(this);
415
415
  if (this.size) {
416
- J(e), ie(e), e.assignedMap = /* @__PURE__ */ new Map();
416
+ Q(e), ce(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 = O(this);
424
- B(n).forEach((s, i) => {
425
- e.call(t, this.get(i), i, this);
423
+ const n = $(this);
424
+ Z(n).forEach((s, r) => {
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 = O(this), i = B(s).get(e), r = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, i, se)) === se.mutable;
431
- if (s.options.strict && Ye(i, s.options, r), r || s.finalized || !Ee(i, s.options) || i !== s.original.get(e))
432
- return i;
433
- const o = Tt.createDraft({
434
- original: i,
430
+ const s = $(this), r = Z(s).get(e), o = ((n = (t = s.options).mark) === null || n === void 0 ? void 0 : n.call(t, r, ae)) === ae.mutable;
431
+ if (s.options.strict && ct(r, s.options, o), o || s.finalized || !Ce(r, s.options) || r !== s.original.get(e))
432
+ return r;
433
+ const i = zt.createDraft({
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 J(s), s.copy.set(e, o), o;
440
+ return Q(s), s.copy.set(e, i), i;
441
441
  },
442
442
  keys() {
443
- return B(O(this)).keys();
443
+ return Z($(this)).keys();
444
444
  },
445
445
  values() {
446
446
  const e = this.keys();
447
447
  return {
448
- [Ge]: () => this.values(),
448
+ [nt]: () => this.values(),
449
449
  next: () => {
450
450
  const t = e.next();
451
451
  return t.done ? t : {
@@ -458,7 +458,7 @@ const Ye = (e, t, n = !1) => {
458
458
  entries() {
459
459
  const e = this.keys();
460
460
  return {
461
- [Ge]: () => this.entries(),
461
+ [nt]: () => this.entries(),
462
462
  next: () => {
463
463
  const t = e.next();
464
464
  if (t.done)
@@ -471,80 +471,80 @@ const Ye = (e, t, n = !1) => {
471
471
  }
472
472
  };
473
473
  },
474
- [Ge]() {
474
+ [nt]() {
475
475
  return this.entries();
476
476
  }
477
- }, Hn = Reflect.ownKeys(bt), Ft = (e, t, { isValuesIterator: n }) => () => {
478
- var s, i;
479
- const r = t.next();
480
- if (r.done)
481
- return r;
482
- const o = r.value;
483
- let a = e.setMap.get(o);
484
- const c = O(a), u = ((i = (s = e.options).mark) === null || i === void 0 ? void 0 : i.call(s, a, se)) === se.mutable;
485
- if (e.options.strict && Ye(o, e.options, u), !u && !c && Ee(o, e.options) && !e.finalized && e.original.has(o)) {
486
- const l = Tt.createDraft({
487
- original: o,
477
+ }, cs = Reflect.ownKeys(Ct), en = (e, t, { isValuesIterator: n }) => () => {
478
+ var s, r;
479
+ const o = t.next();
480
+ if (o.done)
481
+ return o;
482
+ const i = o.value;
483
+ let a = e.setMap.get(i);
484
+ const c = $(a), u = ((r = (s = e.options).mark) === null || r === void 0 ? void 0 : r.call(s, a, ae)) === ae.mutable;
485
+ if (e.options.strict && ct(i, e.options, u), !u && !c && Ce(i, e.options) && !e.finalized && e.original.has(i)) {
486
+ const l = zt.createDraft({
487
+ original: i,
488
488
  parentDraft: e,
489
- key: o,
489
+ key: i,
490
490
  finalities: e.finalities,
491
491
  options: e.options
492
492
  });
493
- e.setMap.set(o, l), a = l;
493
+ e.setMap.set(i, l), a = l;
494
494
  } else c && (a = c.proxy);
495
495
  return {
496
496
  done: !1,
497
497
  value: n ? a : [a, a]
498
498
  };
499
- }, Ze = {
499
+ }, ut = {
500
500
  get size() {
501
- return O(this).setMap.size;
501
+ return $(this).setMap.size;
502
502
  },
503
503
  has(e) {
504
- const t = O(this);
504
+ const t = $(this);
505
505
  if (t.setMap.has(e))
506
506
  return !0;
507
- J(t);
508
- const n = O(e);
507
+ Q(t);
508
+ const n = $(e);
509
509
  return !!(n && t.setMap.has(n.original));
510
510
  },
511
511
  add(e) {
512
- const t = O(this);
513
- return this.has(e) || (J(t), ie(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), At(t, e, e, Fe)), this;
512
+ const t = $(this);
513
+ return this.has(e) || (Q(t), ce(t), t.assignedMap.set(e, !0), t.setMap.set(e, e), Ht(t, e, e, Be)), this;
514
514
  },
515
515
  delete(e) {
516
516
  if (!this.has(e))
517
517
  return !1;
518
- const t = O(this);
519
- J(t), ie(t);
520
- const n = O(e);
518
+ const t = $(this);
519
+ Q(t), ce(t);
520
+ const n = $(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 = O(this);
527
- J(e), ie(e);
526
+ const e = $(this);
527
+ Q(e), ce(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 = O(this);
534
- J(e);
533
+ const e = $(this);
534
+ Q(e);
535
535
  const t = e.setMap.keys();
536
536
  return {
537
537
  [Symbol.iterator]: () => this.values(),
538
- next: Ft(e, t, { isValuesIterator: !0 })
538
+ next: en(e, t, { isValuesIterator: !0 })
539
539
  };
540
540
  },
541
541
  entries() {
542
- const e = O(this);
543
- J(e);
542
+ const e = $(this);
543
+ Q(e);
544
544
  const t = e.setMap.keys();
545
545
  return {
546
546
  [Symbol.iterator]: () => this.entries(),
547
- next: Ft(e, t, {
547
+ next: en(e, t, {
548
548
  isValuesIterator: !1
549
549
  })
550
550
  };
@@ -552,7 +552,7 @@ const Ye = (e, t, n = !1) => {
552
552
  keys() {
553
553
  return this.values();
554
554
  },
555
- [Ge]() {
555
+ [nt]() {
556
556
  return this.values();
557
557
  },
558
558
  forEach(e, t) {
@@ -562,7 +562,7 @@ const Ye = (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(Ze, {
565
+ Set.prototype.difference && Object.assign(ut, {
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(Ze, {
585
585
  return Set.prototype.isDisjointFrom.call(new Set(this.values()), e);
586
586
  }
587
587
  });
588
- const Bn = Reflect.ownKeys(Ze), cn = /* @__PURE__ */ new WeakSet(), un = {
588
+ const us = Reflect.ownKeys(ut), kn = /* @__PURE__ */ new WeakSet(), vn = {
589
589
  get(e, t, n) {
590
- var s, i;
591
- const r = (s = e.copy) === null || s === void 0 ? void 0 : s[t];
592
- if (r && cn.has(r))
593
- return r;
594
- if (t === nn)
590
+ var s, r;
591
+ const o = (s = e.copy) === null || s === void 0 ? void 0 : s[t];
592
+ if (o && kn.has(o))
593
+ return o;
594
+ if (t === bn)
595
595
  return e;
596
- let o;
596
+ let i;
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
- if (o = e.options.mark(u, se), o === se.mutable)
600
- return e.options.strict && Ye(u, e.options, !0), u;
599
+ if (i = e.options.mark(u, ae), i === ae.mutable)
600
+ return e.options.strict && ct(u, e.options, !0), u;
601
601
  }
602
- const a = B(e);
603
- if (a instanceof Map && Hn.includes(t)) {
602
+ const a = Z(e);
603
+ if (a instanceof Map && cs.includes(t)) {
604
604
  if (t === "size")
605
- return Object.getOwnPropertyDescriptor(bt, "size").get.call(e.proxy);
606
- const u = bt[t];
605
+ return Object.getOwnPropertyDescriptor(Ct, "size").get.call(e.proxy);
606
+ const u = Ct[t];
607
607
  if (u)
608
608
  return u.bind(e.proxy);
609
609
  }
610
- if (a instanceof Set && Bn.includes(t)) {
610
+ if (a instanceof Set && us.includes(t)) {
611
611
  if (t === "size")
612
- return Object.getOwnPropertyDescriptor(Ze, "size").get.call(e.proxy);
613
- const u = Ze[t];
612
+ return Object.getOwnPropertyDescriptor(ut, "size").get.call(e.proxy);
613
+ const u = ut[t];
614
614
  if (u)
615
615
  return u.bind(e.proxy);
616
616
  }
617
- if (!De(a, t)) {
618
- const u = Wt(a, t);
617
+ if (!He(a, t)) {
618
+ const u = Zt(a, t);
619
619
  return u ? "value" in u ? u.value : (
620
620
  // !case: support for getter
621
- (i = u.get) === null || i === void 0 ? void 0 : i.call(e.proxy)
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 && Ye(c, e.options), e.finalized || !Ee(c, e.options))
625
+ if (e.options.strict && ct(c, e.options), e.finalized || !Ce(c, e.options))
626
626
  return c;
627
- if (c === ft(e.original, t)) {
628
- if (J(e), e.copy[t] = fn({
627
+ if (c === St(e.original, t)) {
628
+ if (Q(e), e.copy[t] = $n({
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
- }), typeof o == "function") {
635
- const u = O(e.copy[t]);
636
- return J(u), ie(u), u.copy;
634
+ }), typeof i == "function") {
635
+ const u = $(e.copy[t]);
636
+ return Q(u), ce(u), u.copy;
637
637
  }
638
638
  return e.copy[t];
639
639
  }
@@ -643,23 +643,23 @@ const Bn = Reflect.ownKeys(Ze), cn = /* @__PURE__ */ new WeakSet(), un = {
643
643
  var s;
644
644
  if (e.type === 3 || e.type === 2)
645
645
  throw new Error("Map/Set draft does not support any property assignment.");
646
- let i;
647
- if (e.type === 1 && t !== "length" && !(Number.isInteger(i = Number(t)) && i >= 0 && (t === 0 || i === 0 || String(i) === String(t))))
646
+ let r;
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 r = Wt(B(e), t);
650
- if (r != null && r.set)
651
- return r.set.call(e.proxy, n), !0;
652
- const o = ft(B(e), t), a = O(o);
653
- return a && Ie(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) : (Ie(n, o) && (n !== void 0 || De(e.original, t)) || (J(e), ie(e), De(e.original, t) && Ie(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, At(e, t, n, Fe)), !0);
649
+ const o = Zt(Z(e), t);
650
+ if (o != null && o.set)
651
+ return o.set.call(e.proxy, n), !0;
652
+ const i = St(Z(e), t), a = $(i);
653
+ return a && Ee(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) : (Ee(n, i) && (n !== void 0 || He(e.original, t)) || (Q(e), ce(e), He(e.original, t) && Ee(n, e.original[t]) ? e.assignedMap.delete(t) : e.assignedMap.set(t, !0), e.copy[t] = n, Ht(e, t, n, Be)), !0);
654
654
  },
655
655
  has(e, t) {
656
- return t in B(e);
656
+ return t in Z(e);
657
657
  },
658
658
  ownKeys(e) {
659
- return Reflect.ownKeys(B(e));
659
+ return Reflect.ownKeys(Z(e));
660
660
  },
661
661
  getOwnPropertyDescriptor(e, t) {
662
- const n = B(e), s = Reflect.getOwnPropertyDescriptor(n, t);
662
+ const n = Z(e), s = Reflect.getOwnPropertyDescriptor(n, t);
663
663
  return s && {
664
664
  writable: !0,
665
665
  configurable: e.type !== 1 || t !== "length",
@@ -678,57 +678,57 @@ const Bn = Reflect.ownKeys(Ze), cn = /* @__PURE__ */ new WeakSet(), un = {
678
678
  },
679
679
  deleteProperty(e, t) {
680
680
  var n;
681
- return e.type === 1 ? un.set.call(this, e, t, void 0, e.proxy) : (ft(e.original, t) !== void 0 || t in e.original ? (J(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 ? vn.set.call(this, e, t, void 0, e.proxy) : (St(e.original, t) !== void 0 || t in e.original ? (Q(e), ce(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 fn(e) {
685
- const { original: t, parentDraft: n, key: s, finalities: i, options: r } = e, o = ze(t), a = {
686
- type: o,
684
+ function $n(e) {
685
+ const { original: t, parentDraft: n, key: s, finalities: r, options: o } = e, i = Ye(t), a = {
686
+ type: i,
687
687
  finalized: !1,
688
688
  parent: n,
689
689
  original: t,
690
690
  copy: null,
691
691
  proxy: null,
692
- finalities: i,
693
- options: r,
692
+ finalities: r,
693
+ options: o,
694
694
  // Mapping of draft Set items to their corresponding draft values.
695
- setMap: o === 3 ? new Map(t.entries()) : void 0
695
+ setMap: i === 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, un);
699
- if (i.revoke.push(u), cn.add(c), a.proxy = c, n) {
698
+ const { proxy: c, revoke: u } = Proxy.revocable(i === 1 ? Object.assign([], a) : a, vn);
699
+ if (r.revoke.push(u), kn.add(c), a.proxy = c, n) {
700
700
  const l = n;
701
- l.finalities.draft.push((d, p) => {
702
- var y, v;
703
- const b = O(c);
701
+ l.finalities.draft.push((f, p) => {
702
+ var m, g;
703
+ const w = $(c);
704
704
  let h = l.type === 3 ? l.setMap : l.copy;
705
- const I = me(h, s), E = O(I);
706
- if (E) {
707
- let L = E.original;
708
- E.operated && (L = Rt(I)), mt(E), yt(E, Fe, d, p), l.options.enableAutoFreeze && (l.options.updatedValues = (y = l.options.updatedValues) !== null && y !== void 0 ? y : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(L, E.original)), Pt(h, s, L);
705
+ const k = ge(h, s), v = $(k);
706
+ if (v) {
707
+ let z = v.original;
708
+ v.operated && (z = Vt(k)), Et(v), _t(v, Be, f, p), l.options.enableAutoFreeze && (l.options.updatedValues = (m = l.options.updatedValues) !== null && m !== void 0 ? m : /* @__PURE__ */ new WeakMap(), l.options.updatedValues.set(z, v.original)), Jt(h, s, z);
709
709
  }
710
- (v = b.callbacks) === null || v === void 0 || v.forEach((L) => {
711
- L(d, p);
710
+ (g = w.callbacks) === null || g === void 0 || g.forEach((z) => {
711
+ z(f, p);
712
712
  });
713
713
  });
714
714
  } else {
715
- const l = O(c);
716
- l.finalities.draft.push((d, p) => {
717
- mt(l), yt(l, Fe, d, p);
715
+ const l = $(c);
716
+ l.finalities.draft.push((f, p) => {
717
+ Et(l), _t(l, Be, f, p);
718
718
  });
719
719
  }
720
720
  return c;
721
721
  }
722
- Tt.createDraft = fn;
722
+ zt.createDraft = $n;
723
723
  Object.prototype.constructor.toString();
724
- function xe() {
725
- return Nn();
724
+ function je() {
725
+ return Yn();
726
726
  }
727
- function qn(e, t) {
727
+ function fs(e, t) {
728
728
  return e.localeCompare(t);
729
729
  }
730
- function Kn() {
731
- let e = qn;
730
+ function ds() {
731
+ let e = fs;
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 Kn() {
736
736
  }
737
737
  return e;
738
738
  }
739
- Kn();
740
- function Xn() {
739
+ ds();
740
+ function ls() {
741
741
  const t = {
742
742
  __etype: 1,
743
743
  __ops: 1,
@@ -751,98 +751,98 @@ function Xn() {
751
751
  };
752
752
  return new Set(Object.keys(t));
753
753
  }
754
- const Yn = Xn();
755
- function Be(e, t, n) {
754
+ const hs = ls();
755
+ function rt(e, t, n) {
756
756
  const s = {
757
757
  __etype: e,
758
758
  __ops: n
759
759
  };
760
760
  return new Proxy(s, {
761
- get: (i, r) => {
762
- if (r === "__ops")
761
+ get: (r, o) => {
762
+ if (o === "__ops")
763
763
  return n;
764
- if (r === "__etype")
764
+ if (o === "__etype")
765
765
  return e;
766
- if (Yn.has(r))
767
- return (o, a) => Be(e, t, [
766
+ if (hs.has(o))
767
+ return (i, a) => rt(e, t, [
768
768
  ...n,
769
- a ? [r, e, t, o, a] : [r, e, t, o]
769
+ a ? [o, e, t, i, a] : [o, e, t, i]
770
770
  ]);
771
771
  }
772
772
  });
773
773
  }
774
- function Zn(e, t) {
774
+ function ps(e, t) {
775
775
  return `lookup__${e}__${JSON.stringify(t)}`;
776
776
  }
777
- function ln(e) {
777
+ function On(e) {
778
778
  return e.startsWith("lookup__");
779
779
  }
780
- function zt(e) {
780
+ function tn(e) {
781
781
  const [t, n, ...s] = e.split("__");
782
782
  return [n, JSON.parse(s.join("__"))];
783
783
  }
784
- function es(e) {
784
+ function ys(e) {
785
785
  return new Proxy({
786
786
  __etype: e
787
787
  }, {
788
788
  get(t, n) {
789
789
  if (n === "lookup")
790
- return (i, r) => Be(e, zt(Zn(i, r)), []);
790
+ return (r, o) => rt(e, tn(ps(r, o)), []);
791
791
  if (n === "__etype")
792
792
  return e;
793
793
  const s = n;
794
- return ln(s) ? Be(e, zt(s), []) : Be(e, s, []);
794
+ return On(s) ? rt(e, tn(s), []) : rt(e, s, []);
795
795
  }
796
796
  });
797
797
  }
798
- function dn() {
798
+ function En() {
799
799
  return new Proxy({}, {
800
800
  get(e, t) {
801
- return es(t);
801
+ return ys(t);
802
802
  }
803
803
  });
804
804
  }
805
- dn();
806
- function ts(e) {
805
+ En();
806
+ function ms(e) {
807
807
  return e.__ops;
808
808
  }
809
- class H extends Error {
810
- constructor(n, s, i) {
809
+ class _ extends Error {
810
+ constructor(n, s, r) {
811
811
  super(n);
812
- f(this, "hint");
813
- f(this, "traceId");
814
- this.hint = s, i && (this.traceId = i);
815
- const r = new.target.prototype;
816
- Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, H), this.name = "InstantError";
812
+ d(this, "hint");
813
+ d(this, "traceId");
814
+ this.hint = s, r && (this.traceId = r);
815
+ const o = new.target.prototype;
816
+ Object.setPrototypeOf && Object.setPrototypeOf(this, o), Error.captureStackTrace && Error.captureStackTrace(this, _), this.name = "InstantError";
817
817
  }
818
818
  get [Symbol.toStringTag]() {
819
819
  return "InstantError";
820
820
  }
821
821
  }
822
- class ve extends H {
822
+ class le extends _ {
823
823
  constructor(n) {
824
- var r, o;
825
- const s = ((r = n.body) == null ? void 0 : r.message) || `API Error (${n.status})`;
826
- super(s, n.body.hint, ((o = n.body) == null ? void 0 : o.traceId) || n.body["trace-id"]);
827
- f(this, "body");
828
- f(this, "status");
829
- const i = new.target.prototype;
830
- Object.setPrototypeOf && Object.setPrototypeOf(this, i), Error.captureStackTrace && Error.captureStackTrace(this, ve), this.name = "InstantAPIError", this.status = n.status, this.body = n.body;
824
+ var o, i;
825
+ const s = ((o = n.body) == null ? void 0 : o.message) || `API Error (${n.status})`;
826
+ super(s, n.body.hint, ((i = n.body) == null ? void 0 : i.traceId) || n.body["trace-id"]);
827
+ d(this, "body");
828
+ d(this, "status");
829
+ const r = new.target.prototype;
830
+ Object.setPrototypeOf && Object.setPrototypeOf(this, r), Error.captureStackTrace && Error.captureStackTrace(this, le), this.name = "InstantAPIError", this.status = n.status, this.body = n.body;
831
831
  }
832
832
  get [Symbol.toStringTag]() {
833
833
  return "InstantAPIError";
834
834
  }
835
835
  }
836
836
  typeof window < "u" && typeof window.localStorage < "u" && (window.localStorage.getItem("devBackend"), window.localStorage.getItem("__instantLogging"), window.localStorage.getItem("__devtoolLocalDash"));
837
- const Me = "v1.0.30";
838
- class ce {
839
- constructor(t, n, s, i = { indexed: !1, unique: !1 }) {
840
- f(this, "valueType");
841
- f(this, "required");
842
- f(this, "isIndexed");
843
- f(this, "config");
844
- f(this, "metadata", {});
845
- this.valueType = t, this.required = n, this.isIndexed = s, this.config = i;
837
+ const _e = "v1.0.31";
838
+ class de {
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", {});
845
+ this.valueType = t, this.required = n, this.isIndexed = s, this.config = r;
846
846
  }
847
847
  /**
848
848
  * @deprecated Only use this temporarily for attributes that you want
@@ -850,31 +850,31 @@ 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 de(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 de(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 de(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 de(this.valueType, this.required, !0, {
866
866
  ...this.config,
867
867
  indexed: !0
868
868
  });
869
869
  }
870
870
  }
871
- class C extends Error {
871
+ class T extends Error {
872
872
  constructor(t, n) {
873
873
  const s = n ? `At path '${n}': ${t}` : t;
874
874
  super(s), this.name = "QueryValidationError";
875
875
  }
876
876
  }
877
- const Vt = [
877
+ const nn = [
878
878
  "where",
879
879
  "order",
880
880
  "limit",
@@ -887,7 +887,7 @@ const Vt = [
887
887
  "beforeInclusive",
888
888
  "fields",
889
889
  "aggregate"
890
- ], ns = (e) => e.valueType || "unknown", hn = (e, t, n = !1) => {
890
+ ], bs = (e) => e.valueType || "unknown", _n = (e, t, n = !1) => {
891
891
  if (n || e == null)
892
892
  return !0;
893
893
  switch (t) {
@@ -902,16 +902,16 @@ const Vt = [
902
902
  default:
903
903
  return !0;
904
904
  }
905
- }, ss = (e, t, n, s, i, r, o) => {
906
- const a = r.valueType === "json", c = (u, l, d) => {
907
- if (!hn(d, l, a))
908
- throw new C(`Invalid value for operator '${u}' on attribute '${s}' in entity '${i}'. Expected ${l}, but received: ${typeof d}`, o);
905
+ }, ws = (e, t, n, s, r, o, i) => {
906
+ const a = o.valueType === "json", c = (u, l, f) => {
907
+ if (!_n(f, l, a))
908
+ throw new T(`Invalid value for operator '${u}' on attribute '${s}' in entity '${r}'. Expected ${l}, but received: ${typeof f}`, i);
909
909
  };
910
910
  switch (e) {
911
911
  case "in":
912
912
  case "$in":
913
913
  if (!Array.isArray(t))
914
- throw new C(`Operator '${e}' for attribute '${s}' in entity '${i}' must be an array, but received: ${typeof t}`, o);
914
+ throw new T(`Operator '${e}' for attribute '${s}' in entity '${r}' must be an array, but received: ${typeof t}`, i);
915
915
  for (const u of t)
916
916
  c(e, n, u);
917
917
  break;
@@ -925,100 +925,100 @@ const Vt = [
925
925
  break;
926
926
  case "$like":
927
927
  case "$ilike":
928
- if (c(e, "string", t), e === "$ilike" && !r.isIndexed)
929
- throw new C(`Operator '${e}' can only be used with indexed attributes, but '${s}' in entity '${i}' is not indexed`, o);
928
+ if (c(e, "string", t), e === "$ilike" && !o.isIndexed)
929
+ throw new T(`Operator '${e}' can only be used with indexed attributes, but '${s}' in entity '${r}' is not indexed`, i);
930
930
  break;
931
931
  case "$isNull":
932
932
  c(e, "boolean", t);
933
933
  break;
934
934
  default:
935
- throw new C(`Unknown operator '${e}' for attribute '${s}' in entity '${i}'`, o);
935
+ throw new T(`Unknown operator '${e}' for attribute '${s}' in entity '${r}'`, i);
936
936
  }
937
- }, Te = (e, t, n, s, i) => {
938
- const r = ns(n), o = n.valueType === "json";
937
+ }, Ue = (e, t, n, s, r) => {
938
+ const o = bs(n), i = n.valueType === "json";
939
939
  if (typeof e == "object" && e !== null && !Array.isArray(e)) {
940
- if (o)
940
+ if (i)
941
941
  return;
942
942
  const c = e;
943
943
  for (const [u, l] of Object.entries(c))
944
- ss(u, l, r, t, s, n, `${i}.${u}`);
945
- } else if (!hn(e, r, o))
946
- throw new C(`Invalid value for attribute '${t}' in entity '${s}'. Expected ${r}, but received: ${typeof e}`, i);
947
- }, is = (e, t, n, s, i) => {
948
- const r = e.split(".");
949
- if (r.length < 2)
950
- throw new C(`Invalid dot notation path '${e}'. Must contain at least one dot.`, i);
951
- let o = n;
952
- for (let l = 0; l < r.length - 1; l++) {
953
- const d = r[l], p = s.entities[o];
944
+ ws(u, l, o, t, s, n, `${r}.${u}`);
945
+ } else if (!_n(e, o, i))
946
+ throw new T(`Invalid value for attribute '${t}' in entity '${s}'. Expected ${o}, but received: ${typeof e}`, r);
947
+ }, gs = (e, t, n, s, r) => {
948
+ const o = e.split(".");
949
+ if (o.length < 2)
950
+ throw new T(`Invalid dot notation path '${e}'. Must contain at least one dot.`, r);
951
+ let i = n;
952
+ for (let l = 0; l < o.length - 1; l++) {
953
+ const f = o[l], p = s.entities[i];
954
954
  if (!p)
955
- throw new C(`Entity '${o}' does not exist in schema while traversing dot notation path '${e}'.`, i);
956
- const y = p.links[d];
957
- if (!y) {
958
- const v = Object.keys(p.links);
959
- throw new C(`Link '${d}' does not exist on entity '${o}' in dot notation path '${e}'. Available links: ${v.length > 0 ? v.join(", ") : "none"}`, i);
955
+ throw new T(`Entity '${i}' does not exist in schema while traversing dot notation path '${e}'.`, r);
956
+ const m = p.links[f];
957
+ if (!m) {
958
+ const g = Object.keys(p.links);
959
+ throw new T(`Link '${f}' does not exist on entity '${i}' in dot notation path '${e}'. Available links: ${g.length > 0 ? g.join(", ") : "none"}`, r);
960
960
  }
961
- o = y.entityName;
961
+ i = m.entityName;
962
962
  }
963
- const a = r[r.length - 1], c = s.entities[o];
963
+ const a = o[o.length - 1], c = s.entities[i];
964
964
  if (!c)
965
- throw new C(`Target entity '${o}' does not exist in schema for dot notation path '${e}'.`, i);
965
+ throw new T(`Target entity '${i}' does not exist in schema for dot notation path '${e}'.`, r);
966
966
  if (a === "id") {
967
- if (typeof t == "string" && !Ae(t))
968
- throw new C(`Invalid value for id field in entity '${o}'. Expected a UUID, but received: ${t}`, i);
969
- Te(t, e, new ce("string", !1, !0), n, i);
967
+ if (typeof t == "string" && !Fe(t))
968
+ throw new T(`Invalid value for id field in entity '${i}'. Expected a UUID, but received: ${t}`, r);
969
+ Ue(t, e, new de("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" && !Ae(t))
975
- throw new C(`Invalid value for link '${a}' in entity '${o}'. Expected a UUID, but received: ${t}`, i);
976
- Te(t, e, new ce("string", !1, !0), n, i);
974
+ if (typeof t == "string" && !Fe(t))
975
+ throw new T(`Invalid value for link '${a}' in entity '${i}'. Expected a UUID, but received: ${t}`, r);
976
+ Ue(t, e, new de("string", !1, !0), n, r);
977
977
  return;
978
978
  }
979
979
  if (!u) {
980
980
  const l = Object.keys(c.attrs);
981
- throw new C(`Attribute '${a}' does not exist on entity '${o}' in dot notation path '${e}'. Available attributes: ${l.length > 0 ? l.join(", ") + ", id" : "id"}`, i);
982
- }
983
- Te(t, e, u, n, i);
984
- }, pn = (e, t, n, s) => {
985
- for (const [i, r] of Object.entries(e)) {
986
- if (i === "or" || i === "and") {
987
- if (Array.isArray(r))
988
- for (const u of r)
989
- typeof u == "object" && u !== null && pn(u, t, n, `${s}.${i}[${u}]`);
981
+ throw new T(`Attribute '${a}' does not exist on entity '${i}' in dot notation path '${e}'. Available attributes: ${l.length > 0 ? l.join(", ") + ", id" : "id"}`, r);
982
+ }
983
+ Ue(t, e, u, n, r);
984
+ }, Cn = (e, t, n, s) => {
985
+ for (const [r, o] of Object.entries(e)) {
986
+ if (r === "or" || r === "and") {
987
+ if (Array.isArray(o))
988
+ for (const u of o)
989
+ typeof u == "object" && u !== null && Cn(u, t, n, `${s}.${r}[${u}]`);
990
990
  continue;
991
991
  }
992
- if (i === "id") {
993
- Te(r, "id", new ce("string", !1, !0), t, `${s}.id`);
992
+ if (r === "id") {
993
+ Ue(o, "id", new de("string", !1, !0), t, `${s}.id`);
994
994
  continue;
995
995
  }
996
- if (i.includes(".")) {
997
- is(i, r, t, n, `${s}.${i}`);
996
+ if (r.includes(".")) {
997
+ gs(r, o, t, n, `${s}.${r}`);
998
998
  continue;
999
999
  }
1000
- const o = n.entities[t];
1001
- if (!o)
1000
+ const i = n.entities[t];
1001
+ if (!i)
1002
1002
  continue;
1003
- const a = o.attrs[i], c = o.links[i];
1003
+ const a = i.attrs[r], c = i.links[r];
1004
1004
  if (!a && !c) {
1005
- const u = Object.keys(o.attrs), l = Object.keys(o.links);
1006
- throw new C(`Attribute or link '${i}' does not exist on entity '${t}'. Available attributes: ${u.length > 0 ? u.join(", ") : "none"}. Available links: ${l.length > 0 ? l.join(", ") : "none"}`, `${s}.${i}`);
1005
+ const u = Object.keys(i.attrs), l = Object.keys(i.links);
1006
+ throw new T(`Attribute or link '${r}' does not exist on entity '${t}'. Available attributes: ${u.length > 0 ? u.join(", ") : "none"}. Available links: ${l.length > 0 ? l.join(", ") : "none"}`, `${s}.${r}`);
1007
1007
  }
1008
1008
  if (a)
1009
- Te(r, i, a, t, `${s}.${i}`);
1009
+ Ue(o, r, a, t, `${s}.${r}`);
1010
1010
  else if (c) {
1011
- if (typeof r == "string" && !Ae(r))
1012
- throw new C(`Invalid value for link '${i}' in entity '${t}'. Expected a UUID, but received: ${r}`, `${s}.${i}`);
1013
- const u = new ce("string", !1, !0);
1014
- Te(r, i, u, t, `${s}.${i}`);
1011
+ if (typeof o == "string" && !Fe(o))
1012
+ throw new T(`Invalid value for link '${r}' in entity '${t}'. Expected a UUID, but received: ${o}`, `${s}.${r}`);
1013
+ const u = new de("string", !1, !0);
1014
+ Ue(o, r, u, t, `${s}.${r}`);
1015
1015
  }
1016
1016
  }
1017
- }, rs = (e, t, n, s, i = 0) => {
1018
- for (const o of Object.keys(e))
1019
- if (!Vt.includes(o))
1020
- throw new C(`Invalid query parameter '${o}' in $ object. Valid parameters are: ${Vt.join(", ")}. Found: ${o}`, s);
1021
- const r = [
1017
+ }, Ss = (e, t, n, s, r = 0) => {
1018
+ for (const i of Object.keys(e))
1019
+ if (!nn.includes(i))
1020
+ throw new T(`Invalid query parameter '${i}' in $ object. Valid parameters are: ${nn.join(", ")}. Found: ${i}`, s);
1021
+ const o = [
1022
1022
  // 'limit', // only supported client side
1023
1023
  "offset",
1024
1024
  "before",
@@ -1028,163 +1028,163 @@ const Vt = [
1028
1028
  "first",
1029
1029
  "last"
1030
1030
  ];
1031
- for (const o of r)
1032
- if (e[o] !== void 0 && i > 0)
1033
- throw new C(`'${o}' can only be used on top-level namespaces. It cannot be used in nested queries.`, s);
1031
+ for (const i of o)
1032
+ if (e[i] !== void 0 && r > 0)
1033
+ throw new T(`'${i}' can only be used on top-level namespaces. It cannot be used in nested queries.`, s);
1034
1034
  if (e.where && n) {
1035
1035
  if (typeof e.where != "object" || e.where === null)
1036
- throw new C(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`, s ? `${s}.where` : void 0);
1037
- pn(e.where, t, n, s ? `${s}.where` : "where");
1036
+ throw new T(`'where' clause must be an object in entity '${t}', but received: ${typeof e.where}`, s ? `${s}.where` : void 0);
1037
+ Cn(e.where, t, n, s ? `${s}.where` : "where");
1038
1038
  }
1039
- }, mn = (e, t, n, s, i = 0) => {
1040
- var r;
1039
+ }, Tn = (e, t, n, s, r = 0) => {
1040
+ var o;
1041
1041
  if (!e || typeof e != "object")
1042
- throw new C(`Query part for entity '${t}' must be an object, but received: ${typeof e}`, s);
1043
- for (const o of Object.keys(e))
1044
- if (o !== "$") {
1045
- if (n && !(o in n.entities[t].links)) {
1042
+ throw new T(`Query part for entity '${t}' must be an object, but received: ${typeof e}`, s);
1043
+ for (const i of Object.keys(e))
1044
+ if (i !== "$") {
1045
+ if (n && !(i in n.entities[t].links)) {
1046
1046
  const c = Object.keys(n.entities[t].links);
1047
- throw new C(`Link '${o}' does not exist on entity '${t}'. Available links: ${c.length > 0 ? c.join(", ") : "none"}`, `${s}.${o}`);
1047
+ throw new T(`Link '${i}' does not exist on entity '${t}'. Available links: ${c.length > 0 ? c.join(", ") : "none"}`, `${s}.${i}`);
1048
1048
  }
1049
- const a = e[o];
1049
+ const a = e[i];
1050
1050
  if (typeof a == "object" && a !== null) {
1051
- const c = (r = n == null ? void 0 : n.entities[t].links[o]) == null ? void 0 : r.entityName;
1052
- c && mn(a, c, n, `${s}.${o}`, i + 1);
1051
+ const c = (o = n == null ? void 0 : n.entities[t].links[i]) == null ? void 0 : o.entityName;
1052
+ c && Tn(a, c, n, `${s}.${i}`, r + 1);
1053
1053
  }
1054
1054
  } else {
1055
- const a = e[o];
1055
+ const a = e[i];
1056
1056
  if (typeof a != "object" || a === null)
1057
- throw new C(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`, `${s}.$`);
1058
- rs(a, t, n, `${s}.$`, i);
1057
+ throw new T(`Query parameter '$' must be an object in entity '${t}', but received: ${typeof a}`, `${s}.$`);
1058
+ Ss(a, t, n, `${s}.$`, r);
1059
1059
  }
1060
- }, Jt = (e, t) => {
1060
+ }, sn = (e, t) => {
1061
1061
  if (typeof e != "object" || e === null)
1062
- throw new C(`Query must be an object, but received: ${typeof e}${e === null ? " (null)" : ""}`);
1062
+ throw new T(`Query must be an object, but received: ${typeof e}${e === null ? " (null)" : ""}`);
1063
1063
  if (Array.isArray(e))
1064
- throw new C(`Query must be an object, but received: ${typeof e}`);
1064
+ throw new T(`Query must be an object, but received: ${typeof e}`);
1065
1065
  const n = e;
1066
1066
  for (const s of Object.keys(n)) {
1067
1067
  if (Array.isArray(e[s]))
1068
- throw new C(`Query keys must be strings, but found key of type: ${typeof s}`, s);
1068
+ throw new T(`Query keys must be strings, but found key of type: ${typeof s}`, s);
1069
1069
  if (typeof s != "string")
1070
- throw new C(`Query keys must be strings, but found key of type: ${typeof s}`, s);
1070
+ throw new T(`Query keys must be strings, but found key of type: ${typeof s}`, s);
1071
1071
  if (s !== "$$ruleParams") {
1072
1072
  if (t && !t.entities[s]) {
1073
- const i = Object.keys(t.entities);
1074
- throw new C(`Entity '${s}' does not exist in schema. Available entities: ${i.length > 0 ? i.join(", ") : "none"}`, s);
1073
+ const r = Object.keys(t.entities);
1074
+ throw new T(`Entity '${s}' does not exist in schema. Available entities: ${r.length > 0 ? r.join(", ") : "none"}`, s);
1075
1075
  }
1076
- mn(n[s], s, t, s, 0);
1076
+ Tn(n[s], s, t, s, 0);
1077
1077
  }
1078
1078
  }
1079
- }, Qt = (e) => typeof e != "string" ? !1 : ln(e) ? !0 : Ae(e);
1080
- class Y extends Error {
1079
+ }, rn = (e) => typeof e != "string" ? !1 : On(e) ? !0 : Fe(e);
1080
+ class te extends Error {
1081
1081
  constructor(t) {
1082
1082
  super(t), this.name = "TransactionValidationError";
1083
1083
  }
1084
1084
  }
1085
- const yn = (e) => e.length > 0 ? e.join(", ") : "none", os = (e, t) => new Y(`Entity '${e}' does not exist in schema. Available entities: ${yn(t)}`), lt = {
1085
+ const xn = (e) => e.length > 0 ? e.join(", ") : "none", Is = (e, t) => new te(`Entity '${e}' does not exist in schema. Available entities: ${xn(t)}`), It = {
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
- }, as = (e, t) => {
1091
+ }, ks = (e, t) => {
1092
1092
  var n;
1093
- return e == null ? !0 : ((n = lt[t.valueType]) == null ? void 0 : n.call(lt, e)) ?? !1;
1094
- }, bn = (e, t) => {
1093
+ return e == null ? !0 : ((n = It[t.valueType]) == null ? void 0 : n.call(It, e)) ?? !1;
1094
+ }, Rn = (e, t) => {
1095
1095
  const n = t.entities[e];
1096
1096
  if (!n)
1097
- throw os(e, Object.keys(t.entities));
1097
+ throw Is(e, Object.keys(t.entities));
1098
1098
  return n;
1099
- }, dt = (e, t, n) => {
1100
- const s = bn(e, n);
1099
+ }, kt = (e, t, n) => {
1100
+ const s = Rn(e, n);
1101
1101
  if (typeof t != "object" || t === null)
1102
- throw new Y(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);
1103
- for (const [i, r] of Object.entries(t)) {
1104
- if (i === "id")
1102
+ throw new te(`Arguments for data operation on entity '${e}' must be an object, but received: ${typeof t}`);
1103
+ for (const [r, o] of Object.entries(t)) {
1104
+ if (r === "id")
1105
1105
  continue;
1106
- const o = s.attrs[i];
1107
- if (o && !as(r, o))
1108
- throw new Y(`Invalid value for attribute '${i}' in entity '${e}'. Expected ${o.valueType}, but received: ${typeof r}`);
1106
+ const i = s.attrs[r];
1107
+ if (i && !ks(o, i))
1108
+ throw new te(`Invalid value for attribute '${r}' in entity '${e}'. Expected ${i.valueType}, but received: ${typeof o}`);
1109
1109
  }
1110
- }, Gt = (e, t, n) => {
1111
- const s = bn(e, n);
1110
+ }, on = (e, t, n) => {
1111
+ const s = Rn(e, n);
1112
1112
  if (typeof t != "object" || t === null)
1113
- throw new Y(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);
1114
- for (const [i, r] of Object.entries(t)) {
1115
- if (!s.links[i]) {
1113
+ throw new te(`Arguments for link operation on entity '${e}' must be an object, but received: ${typeof t}`);
1114
+ for (const [r, o] of Object.entries(t)) {
1115
+ if (!s.links[r]) {
1116
1116
  const a = Object.keys(s.links);
1117
- throw new Y(`Link '${i}' does not exist on entity '${e}'. Available links: ${yn(a)}`);
1118
- }
1119
- if (r != null) {
1120
- if (Array.isArray(r)) {
1121
- for (const a of r)
1122
- if (!Qt(a))
1123
- throw new Y(`Invalid entity ID in link '${i}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`);
1124
- } else if (!Qt(r))
1125
- throw new Y(`Invalid UUID in link '${i}' for entity '${e}'. Expected a UUID, but received: ${r}`);
1126
- }
1127
- }
1128
- }, cs = {
1129
- create: dt,
1130
- update: dt,
1131
- merge: dt,
1132
- link: Gt,
1133
- unlink: Gt,
1117
+ throw new te(`Link '${r}' does not exist on entity '${e}'. Available links: ${xn(a)}`);
1118
+ }
1119
+ if (o != null) {
1120
+ if (Array.isArray(o)) {
1121
+ for (const a of o)
1122
+ if (!rn(a))
1123
+ throw new te(`Invalid entity ID in link '${r}' for entity '${e}'. Expected a UUID or a lookup, but received: ${a}`);
1124
+ } else if (!rn(o))
1125
+ throw new te(`Invalid UUID in link '${r}' for entity '${e}'. Expected a UUID, but received: ${o}`);
1126
+ }
1127
+ }
1128
+ }, vs = {
1129
+ create: kt,
1130
+ update: kt,
1131
+ merge: kt,
1132
+ link: on,
1133
+ unlink: on,
1134
1134
  delete: () => {
1135
1135
  }
1136
- }, us = (e, t) => {
1136
+ }, $s = (e, t) => {
1137
1137
  if (!t)
1138
1138
  return;
1139
- const [n, s, i, r] = e;
1140
- if (!Array.isArray(i) && !Ae(i))
1141
- throw new Y(`Invalid id for entity '${s}'. Expected a UUID, but received: ${i}`);
1139
+ const [n, s, r, o] = e;
1140
+ if (!Array.isArray(r) && !Fe(r))
1141
+ throw new te(`Invalid id for entity '${s}'. Expected a UUID, but received: ${r}`);
1142
1142
  if (typeof s != "string")
1143
- throw new Y(`Entity name must be a string, but received: ${typeof s}`);
1144
- const o = cs[n];
1145
- o && r !== void 0 && o(s, r, t);
1146
- }, fs = (e, t) => {
1143
+ throw new te(`Entity name must be a string, but received: ${typeof s}`);
1144
+ const i = vs[n];
1145
+ i && o !== void 0 && i(s, o, t);
1146
+ }, Os = (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")
1150
- throw new Y(`Transaction chunk must be an object, but received: ${typeof s}`);
1150
+ throw new te(`Transaction chunk must be an object, but received: ${typeof s}`);
1151
1151
  if (!Array.isArray(s.__ops))
1152
- throw new Y(`Transaction chunk must have __ops array, but received: ${typeof s.__ops}`);
1153
- for (const i of s.__ops) {
1154
- if (!Array.isArray(i))
1155
- throw new Y(`Transaction operation must be an array, but received: ${typeof i}`);
1156
- us(i, t);
1152
+ throw new te(`Transaction chunk must have __ops array, but received: ${typeof s.__ops}`);
1153
+ for (const r of s.__ops) {
1154
+ if (!Array.isArray(r))
1155
+ throw new te(`Transaction operation must be an array, but received: ${typeof r}`);
1156
+ $s(r, t);
1157
1157
  }
1158
1158
  }
1159
1159
  };
1160
- let ls = 0;
1161
- class ds {
1160
+ let Es = 0;
1161
+ class _s {
1162
1162
  constructor(t, n, s) {
1163
- f(this, "type", "sse");
1164
- f(this, "initParams", null);
1165
- f(this, "sendQueue", []);
1166
- f(this, "sendPromise");
1167
- f(this, "closeFired", !1);
1168
- f(this, "sseInitTimeout");
1169
- f(this, "ES");
1170
- f(this, "messageUrl");
1171
- f(this, "conn");
1172
- f(this, "url");
1173
- f(this, "id");
1174
- f(this, "onopen");
1175
- f(this, "onmessage");
1176
- f(this, "onclose");
1177
- f(this, "onerror");
1178
- this.id = `${this.type}_${ls++}`, this.url = n, this.messageUrl = s || this.url, this.ES = t, this.conn = new t(n), this.sseInitTimeout = setTimeout(() => {
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}_${Es++}`, this.url = n, this.messageUrl = s || this.url, this.ES = t, this.conn = new t(n), this.sseInitTimeout = setTimeout(() => {
1179
1179
  this.initParams || this.handleError();
1180
- }, 1e4), this.conn.onmessage = (i) => {
1181
- const r = JSON.parse(i.data);
1182
- if (Array.isArray(r))
1183
- for (const o of r)
1184
- this.handleMessage(o);
1180
+ }, 1e4), this.conn.onmessage = (r) => {
1181
+ const o = JSON.parse(r.data);
1182
+ if (Array.isArray(o))
1183
+ for (const i of o)
1184
+ this.handleMessage(i);
1185
1185
  else
1186
- this.handleMessage(r);
1187
- }, this.conn.onerror = (i) => {
1186
+ this.handleMessage(o);
1187
+ }, this.conn.onerror = (r) => {
1188
1188
  this.handleError();
1189
1189
  };
1190
1190
  }
@@ -1214,7 +1214,7 @@ class ds {
1214
1214
  this.conn.close(), this.onclose && !this.closeFired && (this.closeFired = !0, this.onclose({ target: this }));
1215
1215
  }
1216
1216
  async postMessages(t) {
1217
- var n, s, i;
1217
+ var n, s, r;
1218
1218
  try {
1219
1219
  (await fetch(this.messageUrl, {
1220
1220
  method: "POST",
@@ -1222,7 +1222,7 @@ class ds {
1222
1222
  body: JSON.stringify({
1223
1223
  machine_id: (n = this.initParams) == null ? void 0 : n.machineId,
1224
1224
  session_id: (s = this.initParams) == null ? void 0 : s.sessionId,
1225
- sse_token: (i = this.initParams) == null ? void 0 : i.sseToken,
1225
+ sse_token: (r = this.initParams) == null ? void 0 : r.sseToken,
1226
1226
  messages: t
1227
1227
  })
1228
1228
  })).ok || this.handleError();
@@ -1255,214 +1255,214 @@ class ds {
1255
1255
  this.handleClose();
1256
1256
  }
1257
1257
  }
1258
- var Ht;
1258
+ var an;
1259
1259
  (function(e) {
1260
1260
  e.InitialSyncBatch = "InitialSyncBatch", e.InitialSyncComplete = "InitialSyncComplete", e.LoadFromStorage = "LoadFromStorage", e.SyncTransaction = "SyncTransaction", e.Error = "Error";
1261
- })(Ht || (Ht = {}));
1262
- function hs({ WStream: e, opts: t, startStream: n, appendStream: s, registerStream: i }) {
1263
- const r = t.clientId;
1264
- let o = null, a = null, c = null;
1265
- const u = xe();
1266
- let l = !1, d = !1;
1267
- const p = [], y = [], v = [];
1268
- let b = !1, h = 0, I = 0;
1269
- const E = [], L = new TextEncoder();
1270
- function ye() {
1271
- d = !0;
1272
- for (const m of p)
1273
- m(a ?? void 0);
1274
- }
1275
- function ot(m) {
1276
- return p.push(m), d && m(a ?? void 0), () => {
1277
- const w = p.indexOf(m);
1278
- w !== -1 && p.splice(w, 1);
1261
+ })(an || (an = {}));
1262
+ function Cs({ WStream: e, opts: t, startStream: n, appendStream: s, registerStream: r }) {
1263
+ const o = t.clientId;
1264
+ let i = null, a = null, c = null;
1265
+ const u = je();
1266
+ let l = !1, f = !1;
1267
+ const p = [], m = [], g = [];
1268
+ let w = !1, h = 0, k = 0;
1269
+ const v = [], z = new TextEncoder();
1270
+ function Se() {
1271
+ f = !0;
1272
+ for (const b of p)
1273
+ b(a ?? void 0);
1274
+ }
1275
+ function mt(b) {
1276
+ return p.push(b), f && b(a ?? void 0), () => {
1277
+ const S = p.indexOf(b);
1278
+ S !== -1 && p.splice(S, 1);
1279
1279
  };
1280
1280
  }
1281
- function Ut(m) {
1282
- return v.push(m), () => {
1283
- const w = v.indexOf(m);
1284
- w !== -1 && v.splice(w, 1);
1281
+ function Qt(b) {
1282
+ return g.push(b), () => {
1283
+ const S = g.indexOf(b);
1284
+ S !== -1 && g.splice(S, 1);
1285
1285
  };
1286
1286
  }
1287
- t.waitUntil && t.waitUntil(new Promise((m) => {
1288
- v.push(m);
1287
+ t.waitUntil && t.waitUntil(new Promise((b) => {
1288
+ g.push(b);
1289
1289
  }));
1290
1290
  function x() {
1291
- for (const m of v)
1291
+ for (const b of g)
1292
1292
  try {
1293
- m();
1293
+ b();
1294
1294
  } catch {
1295
1295
  }
1296
1296
  }
1297
- function $(m) {
1298
- return y.push(m), o && m(o), () => {
1299
- const w = y.indexOf(m);
1300
- w !== -1 && y.splice(w, 1);
1297
+ function O(b) {
1298
+ return m.push(b), i && b(i), () => {
1299
+ const S = m.indexOf(b);
1300
+ S !== -1 && m.splice(S, 1);
1301
1301
  };
1302
1302
  }
1303
- function Z(m) {
1304
- o = m;
1305
- for (const w of y)
1306
- w(o);
1303
+ function ne(b) {
1304
+ i = b;
1305
+ for (const S of m)
1306
+ S(i);
1307
1307
  }
1308
- function k() {
1309
- b = !0;
1308
+ function E() {
1309
+ w = !0;
1310
1310
  }
1311
- function M(m) {
1312
- let w = h, N = 0, Q = 0;
1313
- for (const { byteLen: ee } of E) {
1314
- const re = w + ee;
1315
- if (re > m)
1311
+ function D(b) {
1312
+ let S = h, L = 0, G = 0;
1313
+ for (const { byteLen: se } of v) {
1314
+ const ue = S + se;
1315
+ if (ue > b)
1316
1316
  break;
1317
- w = re, N++, Q += ee;
1317
+ S = ue, L++, G += se;
1318
1318
  }
1319
- N > 0 && (h += Q, I -= Q, E.splice(0, N));
1319
+ L > 0 && (h += G, k -= G, v.splice(0, L));
1320
1320
  }
1321
- function R(m, w) {
1322
- a = w, ye(), m.error(w), x();
1321
+ function M(b, S) {
1322
+ a = S, Se(), b.error(S), x();
1323
1323
  }
1324
- async function q() {
1325
- const m = await n({
1326
- clientId: r,
1324
+ async function ee() {
1325
+ const b = await n({
1326
+ clientId: o,
1327
1327
  reconnectToken: u,
1328
1328
  ruleParams: t.ruleParams
1329
1329
  });
1330
- switch (m.type) {
1330
+ switch (b.type) {
1331
1331
  case "ok": {
1332
- const { streamId: w, offset: N } = m;
1333
- o = w, M(N), E.length && s({
1334
- streamId: w,
1335
- chunks: E.map((Q) => Q.chunk),
1332
+ const { streamId: S, offset: L } = b;
1333
+ i = S, D(L), v.length && s({
1334
+ streamId: S,
1335
+ chunks: v.map((G) => G.chunk),
1336
1336
  offset: h
1337
- }), b = !1;
1337
+ }), w = !1;
1338
1338
  break;
1339
1339
  }
1340
1340
  case "disconnect": {
1341
- k();
1341
+ E();
1342
1342
  break;
1343
1343
  }
1344
1344
  case "error": {
1345
- c && R(c, m.error);
1345
+ c && M(c, b.error);
1346
1346
  break;
1347
1347
  }
1348
1348
  }
1349
1349
  }
1350
- function W() {
1351
- k(), q();
1350
+ function V() {
1351
+ E(), ee();
1352
1352
  }
1353
- function Ve({ offset: m, done: w }) {
1354
- M(m), w && (l = !0, x());
1353
+ function Ze({ offset: b, done: S }) {
1354
+ D(b), S && (l = !0, x());
1355
1355
  }
1356
- function Nt(m) {
1357
- return l ? (R(m, new H("Stream has been closed.")), null) : o || (R(m, new H("Stream has not been initialized.")), null);
1356
+ function Gt(b) {
1357
+ return l ? (M(b, new _("Stream has been closed.")), null) : i || (M(b, new _("Stream has not been initialized.")), null);
1358
1358
  }
1359
- async function Oe(m) {
1360
- c = m;
1361
- let w = !0, N = 0;
1362
- for (; w; ) {
1363
- let Q = Date.now() + Math.min(15e3, 500 * (N - 1));
1364
- w = !1;
1365
- const ee = await n({
1359
+ async function Te(b) {
1360
+ c = b;
1361
+ let S = !0, L = 0;
1362
+ for (; S; ) {
1363
+ let G = Date.now() + Math.min(15e3, 500 * (L - 1));
1364
+ S = !1;
1365
+ const se = await n({
1366
1366
  clientId: t.clientId,
1367
1367
  reconnectToken: u,
1368
1368
  ruleParams: t.ruleParams
1369
1369
  });
1370
- switch (ee.type) {
1370
+ switch (se.type) {
1371
1371
  case "ok": {
1372
- const { streamId: re, offset: at } = ee;
1373
- if (at !== 0) {
1374
- const be = new H("Write stream is corrupted");
1375
- R(m, be);
1372
+ const { streamId: ue, offset: bt } = se;
1373
+ if (bt !== 0) {
1374
+ const Ie = new _("Write stream is corrupted");
1375
+ M(b, Ie);
1376
1376
  return;
1377
1377
  }
1378
- Z(re), i(re, {
1379
- onDisconnect: k,
1380
- onFlush: Ve,
1381
- onConnectionReconnect: q,
1382
- onAppendFailed: W
1383
- }), b = !1;
1378
+ ne(ue), r(ue, {
1379
+ onDisconnect: E,
1380
+ onFlush: Ze,
1381
+ onConnectionReconnect: ee,
1382
+ onAppendFailed: V
1383
+ }), w = !1;
1384
1384
  return;
1385
1385
  }
1386
1386
  case "disconnect": {
1387
- w = !0, k(), N++, await new Promise((re) => {
1388
- setTimeout(re, Math.max(0, Q - Date.now()));
1387
+ S = !0, E(), L++, await new Promise((ue) => {
1388
+ setTimeout(ue, Math.max(0, G - Date.now()));
1389
1389
  });
1390
1390
  break;
1391
1391
  }
1392
1392
  case "error": {
1393
- R(m, ee.error);
1393
+ M(b, se.error);
1394
1394
  return;
1395
1395
  }
1396
1396
  }
1397
1397
  }
1398
1398
  }
1399
- class fe extends e {
1400
- constructor(w, N) {
1401
- super(w, N);
1399
+ class pe extends e {
1400
+ constructor(S, L) {
1401
+ super(S, L);
1402
1402
  }
1403
1403
  async streamId() {
1404
- return o || new Promise((w, N) => {
1405
- const Q = [], ee = () => {
1406
- for (const be of Q)
1407
- be();
1408
- }, re = (be) => {
1409
- w(be), ee();
1410
- }, at = (be) => {
1411
- N(be || new H("Stream is closed.")), ee();
1404
+ return i || new Promise((S, L) => {
1405
+ const G = [], se = () => {
1406
+ for (const Ie of G)
1407
+ Ie();
1408
+ }, ue = (Ie) => {
1409
+ S(Ie), se();
1410
+ }, bt = (Ie) => {
1411
+ L(Ie || new _("Stream is closed.")), se();
1412
1412
  };
1413
- Q.push($(re)), Q.push(ot(at));
1413
+ G.push(O(ue)), G.push(mt(bt));
1414
1414
  });
1415
1415
  }
1416
1416
  }
1417
1417
  return {
1418
- stream: new fe({
1418
+ stream: new pe({
1419
1419
  // TODO(dww): accept a storage so that write streams can survive across
1420
1420
  // browser restarts
1421
- async start(m) {
1421
+ async start(b) {
1422
1422
  try {
1423
- await Oe(m);
1424
- } catch (w) {
1425
- R(m, w);
1423
+ await Te(b);
1424
+ } catch (S) {
1425
+ M(b, S);
1426
1426
  }
1427
1427
  },
1428
- write(m, w) {
1429
- const N = Nt(w);
1430
- if (N) {
1431
- const Q = L.encode(m).length;
1432
- E.push({ chunk: m, byteLen: Q });
1433
- const ee = h + I;
1434
- I += Q, b || s({ streamId: N, chunks: [m], offset: ee });
1428
+ write(b, S) {
1429
+ const L = Gt(S);
1430
+ if (L) {
1431
+ const G = z.encode(b).length;
1432
+ v.push({ chunk: b, byteLen: G });
1433
+ const se = h + k;
1434
+ k += G, w || s({ streamId: L, chunks: [b], offset: se });
1435
1435
  }
1436
1436
  },
1437
1437
  close() {
1438
- o ? s({
1439
- streamId: o,
1438
+ i ? s({
1439
+ streamId: i,
1440
1440
  chunks: [],
1441
- offset: h + I,
1441
+ offset: h + k,
1442
1442
  isDone: !0
1443
- }) : x(), ye();
1443
+ }) : x(), Se();
1444
1444
  },
1445
- abort(m) {
1446
- o ? s({
1447
- streamId: o,
1445
+ abort(b) {
1446
+ i ? s({
1447
+ streamId: i,
1448
1448
  chunks: [],
1449
- offset: h + I,
1449
+ offset: h + k,
1450
1450
  isDone: !0,
1451
- abortReason: m
1452
- }) : x(), ye();
1451
+ abortReason: b
1452
+ }) : x(), Se();
1453
1453
  }
1454
1454
  }),
1455
- addCompleteCb: Ut,
1455
+ addCompleteCb: Qt,
1456
1456
  closed() {
1457
- return d;
1457
+ return f;
1458
1458
  }
1459
1459
  };
1460
1460
  }
1461
- class ps {
1461
+ class Ts {
1462
1462
  constructor() {
1463
- f(this, "items", []);
1464
- f(this, "resolvers", []);
1465
- f(this, "isClosed", !1);
1463
+ d(this, "items", []);
1464
+ d(this, "resolvers", []);
1465
+ d(this, "isClosed", !1);
1466
1466
  }
1467
1467
  push(t) {
1468
1468
  if (this.isClosed)
@@ -1492,178 +1492,178 @@ class ps {
1492
1492
  }
1493
1493
  }
1494
1494
  }
1495
- function ms({ RStream: e, opts: t, startStream: n, cancelStream: s }) {
1496
- let i = t.byteOffset || 0, r = !1;
1497
- const o = new TextDecoder("utf-8"), a = new TextEncoder();
1495
+ function xs({ RStream: e, opts: t, startStream: n, cancelStream: s }) {
1496
+ let r = t.byteOffset || 0, o = !1;
1497
+ const i = new TextDecoder("utf-8"), a = new TextEncoder();
1498
1498
  let c, u = !1;
1499
- const l = [], d = [];
1500
- let p = null, y = null;
1501
- function v(x) {
1499
+ const l = [], f = [];
1500
+ let p = null, m = null;
1501
+ function g(x) {
1502
1502
  u = !0;
1503
- for (const $ of l)
1504
- $(x);
1503
+ for (const O of l)
1504
+ O(x);
1505
1505
  }
1506
- function b(x) {
1506
+ function w(x) {
1507
1507
  return l.push(x), () => {
1508
- const $ = l.indexOf(x);
1509
- $ !== -1 && l.splice($, 1);
1508
+ const O = l.indexOf(x);
1509
+ O !== -1 && l.splice(O, 1);
1510
1510
  };
1511
1511
  }
1512
1512
  function h(x) {
1513
- return d.push(x), p && x(p), () => {
1514
- const $ = d.indexOf(x);
1515
- $ !== -1 && d.splice($, 1);
1513
+ return f.push(x), p && x(p), () => {
1514
+ const O = f.indexOf(x);
1515
+ O !== -1 && f.splice(O, 1);
1516
1516
  };
1517
1517
  }
1518
- function I(x, $) {
1519
- y = $, x.error($), v($);
1518
+ function k(x, O) {
1519
+ m = O, x.error(O), g(O);
1520
1520
  }
1521
- let E = 0;
1522
- async function L(x, $) {
1523
- c = xe();
1524
- const Z = { ...x || {}, eventId: c };
1525
- for await (const k of n(Z)) {
1526
- if (r)
1521
+ let v = 0;
1522
+ async function z(x, O) {
1523
+ c = je();
1524
+ const ne = { ...x || {}, eventId: c };
1525
+ for await (const E of n(ne)) {
1526
+ if (o)
1527
1527
  return;
1528
- if (k.type === "reconnect")
1528
+ if (E.type === "reconnect")
1529
1529
  return { retry: !0 };
1530
- if (k.type === "error") {
1531
- I($, k.error);
1530
+ if (E.type === "error") {
1531
+ k(O, E.error);
1532
1532
  return;
1533
1533
  }
1534
- if (k.offset > i) {
1535
- I($, new H("Stream is corrupted.")), r = !0;
1534
+ if (E.offset > r) {
1535
+ k(O, new _("Stream is corrupted.")), o = !0;
1536
1536
  return;
1537
1537
  }
1538
- p = k.streamId;
1539
- for (const R of d)
1540
- R(p);
1541
- let M = i - k.offset;
1542
- if (k.files && k.files.length) {
1543
- const R = new AbortController();
1544
- let q = fetch(k.files[0].url, {
1545
- signal: R.signal
1538
+ p = E.streamId;
1539
+ for (const M of f)
1540
+ M(p);
1541
+ let D = r - E.offset;
1542
+ if (E.files && E.files.length) {
1543
+ const M = new AbortController();
1544
+ let ee = fetch(E.files[0].url, {
1545
+ signal: M.signal
1546
1546
  });
1547
- for (let W = 0; W < k.files.length; W++) {
1548
- const Ve = k.files[W + 1], Oe = await q;
1549
- if (Ve && (q = fetch(Ve.url, { signal: R.signal })), !Oe.ok) {
1550
- if (E++, E > 10) {
1551
- I($, new H("Unable to process stream."));
1547
+ for (let V = 0; V < E.files.length; V++) {
1548
+ const Ze = E.files[V + 1], Te = await ee;
1549
+ if (Ze && (ee = fetch(Ze.url, { signal: M.signal })), !Te.ok) {
1550
+ if (v++, v > 10) {
1551
+ k(O, new _("Unable to process stream."));
1552
1552
  return;
1553
1553
  }
1554
1554
  return { retry: !0 };
1555
1555
  }
1556
- if (Oe.body) {
1557
- const fe = Oe.body.getReader();
1556
+ if (Te.body) {
1557
+ const pe = Te.body.getReader();
1558
1558
  try {
1559
1559
  for (; ; ) {
1560
- const { done: le, value: m } = await fe.read();
1561
- if (le)
1560
+ const { done: ye, value: b } = await pe.read();
1561
+ if (ye)
1562
1562
  break;
1563
- if (r) {
1564
- R.abort();
1563
+ if (o) {
1564
+ M.abort();
1565
1565
  return;
1566
1566
  }
1567
- let w = m;
1568
- if (M > 0 && (w = m.subarray(M), M -= m.length - w.length), !w.length)
1567
+ let S = b;
1568
+ if (D > 0 && (S = b.subarray(D), D -= b.length - S.length), !S.length)
1569
1569
  continue;
1570
- i += w.length;
1571
- const N = o.decode(w);
1572
- $.enqueue(N);
1570
+ r += S.length;
1571
+ const L = i.decode(S);
1572
+ O.enqueue(L);
1573
1573
  }
1574
1574
  } finally {
1575
- fe.releaseLock();
1575
+ pe.releaseLock();
1576
1576
  }
1577
1577
  } else {
1578
- const fe = await Oe.arrayBuffer();
1579
- let le = fe;
1580
- if (r) {
1581
- R.abort();
1578
+ const pe = await Te.arrayBuffer();
1579
+ let ye = pe;
1580
+ if (o) {
1581
+ M.abort();
1582
1582
  return;
1583
1583
  }
1584
- if (M > 0 && (le = new Uint8Array(fe).subarray(M), M -= fe.byteLength - le.length), !le.byteLength)
1584
+ if (D > 0 && (ye = new Uint8Array(pe).subarray(D), D -= pe.byteLength - ye.length), !ye.byteLength)
1585
1585
  continue;
1586
- i += le.byteLength;
1587
- const m = o.decode(le);
1588
- $.enqueue(m);
1586
+ r += ye.byteLength;
1587
+ const b = i.decode(ye);
1588
+ O.enqueue(b);
1589
1589
  }
1590
1590
  }
1591
1591
  }
1592
- if (E = 0, k.content) {
1593
- let R = k.content, q = a.encode(k.content);
1594
- if (M > 0) {
1595
- const W = q.subarray(M);
1596
- if (M -= q.length - W.length, !W.length)
1592
+ if (v = 0, E.content) {
1593
+ let M = E.content, ee = a.encode(E.content);
1594
+ if (D > 0) {
1595
+ const V = ee.subarray(D);
1596
+ if (D -= ee.length - V.length, !V.length)
1597
1597
  continue;
1598
- q = W, R = o.decode(W);
1598
+ ee = V, M = i.decode(V);
1599
1599
  }
1600
- i += q.length, $.enqueue(R);
1600
+ r += ee.length, O.enqueue(M);
1601
1601
  }
1602
1602
  }
1603
1603
  }
1604
- async function ye(x) {
1605
- let $ = !0, Z = 0;
1606
- for (; $; ) {
1607
- $ = !1;
1608
- let k = Date.now() + Math.min(15e3, 500 * (Z - 1));
1609
- const M = await L({ ...t, offset: i }, x);
1610
- M != null && M.retry && ($ = !0, Z++, k < Date.now() - 3e5 && (Z = 0), await new Promise((R) => {
1611
- setTimeout(R, Math.max(0, k - Date.now()));
1604
+ async function Se(x) {
1605
+ let O = !0, ne = 0;
1606
+ for (; O; ) {
1607
+ O = !1;
1608
+ let E = Date.now() + Math.min(15e3, 500 * (ne - 1));
1609
+ const D = await z({ ...t, offset: r }, x);
1610
+ D != null && D.retry && (O = !0, ne++, E < Date.now() - 3e5 && (ne = 0), await new Promise((M) => {
1611
+ setTimeout(M, Math.max(0, E - Date.now()));
1612
1612
  }));
1613
1613
  }
1614
- !r && !u && (x.close(), v());
1614
+ !o && !u && (x.close(), g());
1615
1615
  }
1616
- class ot extends e {
1617
- constructor($, Z) {
1618
- super($, Z);
1616
+ class mt extends e {
1617
+ constructor(O, ne) {
1618
+ super(O, ne);
1619
1619
  }
1620
1620
  async streamId() {
1621
1621
  if (p)
1622
1622
  return p;
1623
- if (y)
1624
- throw y;
1625
- return new Promise(($, Z) => {
1626
- const k = [], M = () => {
1627
- for (const W of k)
1628
- W();
1629
- }, R = (W) => {
1630
- $(W), M();
1631
- }, q = (W) => {
1632
- Z(W || new H("Stream is closed.")), M();
1623
+ if (m)
1624
+ throw m;
1625
+ return new Promise((O, ne) => {
1626
+ const E = [], D = () => {
1627
+ for (const V of E)
1628
+ V();
1629
+ }, M = (V) => {
1630
+ O(V), D();
1631
+ }, ee = (V) => {
1632
+ ne(V || new _("Stream is closed.")), D();
1633
1633
  };
1634
- k.push(h(R)), k.push(b(q));
1634
+ E.push(h(M)), E.push(w(ee));
1635
1635
  });
1636
1636
  }
1637
1637
  }
1638
1638
  return {
1639
- stream: new ot({
1639
+ stream: new mt({
1640
1640
  start(x) {
1641
- ye(x);
1641
+ Se(x);
1642
1642
  },
1643
1643
  cancel(x) {
1644
- r = !0, c && s({ eventId: c }), v();
1644
+ o = !0, c && s({ eventId: c }), g();
1645
1645
  }
1646
1646
  }),
1647
- addCloseCb: b,
1647
+ addCloseCb: w,
1648
1648
  closed() {
1649
1649
  return u;
1650
1650
  }
1651
1651
  };
1652
1652
  }
1653
- class ys {
1654
- constructor({ WStream: t, RStream: n, trySend: s, log: i }) {
1655
- f(this, "trySend");
1656
- f(this, "WStream");
1657
- f(this, "RStream");
1658
- f(this, "writeStreams", {});
1659
- f(this, "startWriteStreamCbs", {});
1660
- f(this, "readStreamIterators", {});
1661
- f(this, "log");
1662
- f(this, "activeStreams", /* @__PURE__ */ new Set());
1663
- this.WStream = t, this.RStream = n, this.trySend = s, this.log = i;
1653
+ class Rs {
1654
+ 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());
1663
+ this.WStream = t, this.RStream = n, this.trySend = s, this.log = r;
1664
1664
  }
1665
1665
  createWriteStream(t) {
1666
- const { stream: n, addCompleteCb: s } = hs({
1666
+ const { stream: n, addCompleteCb: s } = Cs({
1667
1667
  WStream: this.WStream,
1668
1668
  startStream: this.startWriteStream.bind(this),
1669
1669
  appendStream: this.appendStream.bind(this),
@@ -1675,7 +1675,7 @@ class ys {
1675
1675
  }), n;
1676
1676
  }
1677
1677
  createReadStream(t) {
1678
- const { stream: n, addCloseCb: s } = ms({
1678
+ const { stream: n, addCloseCb: s } = xs({
1679
1679
  RStream: this.RStream,
1680
1680
  opts: t,
1681
1681
  startStream: this.startReadStream.bind(this),
@@ -1686,31 +1686,31 @@ class ys {
1686
1686
  }), n;
1687
1687
  }
1688
1688
  startWriteStream(t) {
1689
- const n = xe();
1689
+ const n = je();
1690
1690
  let s = null;
1691
- const i = new Promise((o) => {
1692
- s = o;
1691
+ const r = new Promise((i) => {
1692
+ s = i;
1693
1693
  });
1694
1694
  this.startWriteStreamCbs[n] = s;
1695
- const r = {
1695
+ const o = {
1696
1696
  op: "start-stream",
1697
1697
  "client-id": t.clientId,
1698
1698
  "reconnect-token": t.reconnectToken
1699
1699
  };
1700
- return t.ruleParams && (r["rule-params"] = t.ruleParams), this.trySend(n, r), i;
1700
+ return t.ruleParams && (o["rule-params"] = t.ruleParams), this.trySend(n, o), r;
1701
1701
  }
1702
1702
  registerWriteStream(t, n) {
1703
1703
  this.writeStreams[t] = n;
1704
1704
  }
1705
- appendStream({ streamId: t, chunks: n, isDone: s, offset: i, abortReason: r }) {
1706
- const o = {
1705
+ appendStream({ streamId: t, chunks: n, isDone: s, offset: r, abortReason: o }) {
1706
+ const i = {
1707
1707
  op: "append-stream",
1708
1708
  "stream-id": t,
1709
1709
  chunks: n,
1710
- offset: i,
1710
+ offset: r,
1711
1711
  done: !!s
1712
1712
  };
1713
- r && (o["abort-reason"] = r), this.trySend(xe(), o);
1713
+ o && (i["abort-reason"] = o), this.trySend(je(), i);
1714
1714
  }
1715
1715
  onAppendFailed(t) {
1716
1716
  const n = this.writeStreams[t["stream-id"]];
@@ -1732,20 +1732,20 @@ class ys {
1732
1732
  }
1733
1733
  s.onFlush({ offset: t.offset, done: t.done }), t.done && delete this.writeStreams[n];
1734
1734
  }
1735
- startReadStream({ eventId: t, clientId: n, streamId: s, offset: i, ruleParams: r }) {
1736
- const o = { op: "subscribe-stream" };
1735
+ startReadStream({ eventId: t, clientId: n, streamId: s, offset: r, ruleParams: o }) {
1736
+ const i = { op: "subscribe-stream" };
1737
1737
  if (!s && !n)
1738
1738
  throw new Error("Must provide one of streamId or clientId to subscribe to the stream.");
1739
- s && (o["stream-id"] = s), n && (o["client-id"] = n), i && (o.offset = i), r && (o["rule-params"] = r);
1740
- const a = new ps();
1741
- return this.readStreamIterators[t] = a, this.trySend(t, o), a;
1739
+ s && (i["stream-id"] = s), n && (i["client-id"] = n), r && (i.offset = r), o && (i["rule-params"] = o);
1740
+ const a = new Ts();
1741
+ return this.readStreamIterators[t] = a, this.trySend(t, i), a;
1742
1742
  }
1743
1743
  cancelReadStream({ eventId: t }) {
1744
1744
  const n = {
1745
1745
  op: "unsubscribe-stream",
1746
1746
  "subscribe-event-id": t
1747
1747
  };
1748
- this.trySend(xe(), n), delete this.readStreamIterators[t];
1748
+ this.trySend(je(), n), delete this.readStreamIterators[t];
1749
1749
  }
1750
1750
  onStreamAppend(t) {
1751
1751
  const n = t["client-event-id"], s = this.readStreamIterators[n];
@@ -1756,7 +1756,7 @@ class ys {
1756
1756
  if (t.error) {
1757
1757
  t.retry ? s.push({ type: "reconnect" }) : s.push({
1758
1758
  type: "error",
1759
- error: new H(t.error)
1759
+ error: new _(t.error)
1760
1760
  }), s.close(), delete this.readStreamIterators[n];
1761
1761
  return;
1762
1762
  }
@@ -1771,7 +1771,7 @@ class ys {
1771
1771
  onConnectionStatusChange(t) {
1772
1772
  for (const n of Object.values(this.startWriteStreamCbs))
1773
1773
  n({ type: "disconnect" });
1774
- if (this.startWriteStreamCbs = {}, t !== bs.AUTHENTICATED)
1774
+ if (this.startWriteStreamCbs = {}, t !== As.AUTHENTICATED)
1775
1775
  for (const { onDisconnect: n } of Object.values(this.writeStreams))
1776
1776
  n();
1777
1777
  else {
@@ -1786,24 +1786,24 @@ class ys {
1786
1786
  const n = t["original-event"];
1787
1787
  switch (n.op) {
1788
1788
  case "append-stream": {
1789
- const s = n["stream-id"], i = this.writeStreams[s];
1790
- i == null || i.onAppendFailed();
1789
+ const s = n["stream-id"], r = this.writeStreams[s];
1790
+ r == null || r.onAppendFailed();
1791
1791
  break;
1792
1792
  }
1793
1793
  case "start-stream": {
1794
- const s = t["client-event-id"], i = this.startWriteStreamCbs[s];
1795
- i && (i({
1794
+ const s = t["client-event-id"], r = this.startWriteStreamCbs[s];
1795
+ r && (r({
1796
1796
  type: "error",
1797
- error: new H(t.message || "Unknown error", t.hint)
1797
+ error: new _(t.message || "Unknown error", t.hint)
1798
1798
  }), delete this.startWriteStreamCbs[s]);
1799
1799
  break;
1800
1800
  }
1801
1801
  case "subscribe-stream": {
1802
- const s = t["client-event-id"], i = this.readStreamIterators[s];
1803
- i && (i.push({
1802
+ const s = t["client-event-id"], r = this.readStreamIterators[s];
1803
+ r && (r.push({
1804
1804
  type: "error",
1805
- error: new H(t.message || "Unknown error", t.hint)
1806
- }), i.close(), delete this.readStreamIterators[s]);
1805
+ error: new _(t.message || "Unknown error", t.hint)
1806
+ }), r.close(), delete this.readStreamIterators[s]);
1807
1807
  break;
1808
1808
  }
1809
1809
  }
@@ -1812,56 +1812,56 @@ class ys {
1812
1812
  return this.activeStreams.size > 0;
1813
1813
  }
1814
1814
  }
1815
- const bs = {
1815
+ const As = {
1816
1816
  AUTHENTICATED: "authenticated"
1817
1817
  };
1818
- function gs() {
1818
+ function Ps() {
1819
1819
  return globalThis.__instantDbSchemaHashStore = globalThis.__instantDbSchemaHashStore ?? /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
1820
1820
  }
1821
- function ws() {
1821
+ function Ms() {
1822
1822
  return globalThis.__instantDbStore = globalThis.__instantDbStore ?? {}, globalThis.__instantDbStore;
1823
1823
  }
1824
- ws();
1825
- gs();
1826
- class Bt extends Error {
1824
+ Ms();
1825
+ Ps();
1826
+ class cn extends Error {
1827
1827
  constructor(t, n) {
1828
1828
  super(t), this.name = "ParseError", this.type = n.type, this.field = n.field, this.value = n.value, this.line = n.line;
1829
1829
  }
1830
1830
  }
1831
- function ht(e) {
1831
+ function vt(e) {
1832
1832
  }
1833
- function Ss(e) {
1833
+ function js(e) {
1834
1834
  if (typeof e == "function")
1835
1835
  throw new TypeError(
1836
1836
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
1837
1837
  );
1838
- const { onEvent: t = ht, onError: n = ht, onRetry: s = ht, onComment: i } = e;
1839
- let r = "", o = !0, a, c = "", u = "";
1840
- function l(b) {
1841
- const h = o ? b.replace(/^\xEF\xBB\xBF/, "") : b, [I, E] = Is(`${r}${h}`);
1842
- for (const L of I)
1843
- d(L);
1844
- r = E, o = !1;
1845
- }
1846
- function d(b) {
1847
- if (b === "") {
1848
- y();
1838
+ const { onEvent: t = vt, onError: n = vt, onRetry: s = vt, onComment: r } = e;
1839
+ let o = "", i = !0, a, c = "", u = "";
1840
+ function l(w) {
1841
+ const h = i ? w.replace(/^\xEF\xBB\xBF/, "") : w, [k, v] = Us(`${o}${h}`);
1842
+ for (const z of k)
1843
+ f(z);
1844
+ o = v, i = !1;
1845
+ }
1846
+ function f(w) {
1847
+ if (w === "") {
1848
+ m();
1849
1849
  return;
1850
1850
  }
1851
- if (b.startsWith(":")) {
1852
- i && i(b.slice(b.startsWith(": ") ? 2 : 1));
1851
+ if (w.startsWith(":")) {
1852
+ r && r(w.slice(w.startsWith(": ") ? 2 : 1));
1853
1853
  return;
1854
1854
  }
1855
- const h = b.indexOf(":");
1855
+ const h = w.indexOf(":");
1856
1856
  if (h !== -1) {
1857
- const I = b.slice(0, h), E = b[h + 1] === " " ? 2 : 1, L = b.slice(h + E);
1858
- p(I, L, b);
1857
+ const k = w.slice(0, h), v = w[h + 1] === " " ? 2 : 1, z = w.slice(h + v);
1858
+ p(k, z, w);
1859
1859
  return;
1860
1860
  }
1861
- p(b, "", b);
1861
+ p(w, "", w);
1862
1862
  }
1863
- function p(b, h, I) {
1864
- switch (b) {
1863
+ function p(w, h, k) {
1864
+ switch (w) {
1865
1865
  case "event":
1866
1866
  u = h;
1867
1867
  break;
@@ -1874,24 +1874,24 @@ function Ss(e) {
1874
1874
  break;
1875
1875
  case "retry":
1876
1876
  /^\d+$/.test(h) ? s(parseInt(h, 10)) : n(
1877
- new Bt(`Invalid \`retry\` value: "${h}"`, {
1877
+ new cn(`Invalid \`retry\` value: "${h}"`, {
1878
1878
  type: "invalid-retry",
1879
1879
  value: h,
1880
- line: I
1880
+ line: k
1881
1881
  })
1882
1882
  );
1883
1883
  break;
1884
1884
  default:
1885
1885
  n(
1886
- new Bt(
1887
- `Unknown field "${b.length > 20 ? `${b.slice(0, 20)}…` : b}"`,
1888
- { type: "unknown-field", field: b, value: h, line: I }
1886
+ new cn(
1887
+ `Unknown field "${w.length > 20 ? `${w.slice(0, 20)}…` : w}"`,
1888
+ { type: "unknown-field", field: w, value: h, line: k }
1889
1889
  )
1890
1890
  );
1891
1891
  break;
1892
1892
  }
1893
1893
  }
1894
- function y() {
1894
+ function m() {
1895
1895
  c.length > 0 && t({
1896
1896
  id: a,
1897
1897
  event: u || void 0,
@@ -1901,30 +1901,30 @@ function Ss(e) {
1901
1901
  `) ? c.slice(0, -1) : c
1902
1902
  }), a = void 0, c = "", u = "";
1903
1903
  }
1904
- function v(b = {}) {
1905
- r && b.consume && d(r), o = !0, a = void 0, c = "", u = "", r = "";
1904
+ function g(w = {}) {
1905
+ o && w.consume && f(o), i = !0, a = void 0, c = "", u = "", o = "";
1906
1906
  }
1907
- return { feed: l, reset: v };
1907
+ return { feed: l, reset: g };
1908
1908
  }
1909
- function Is(e) {
1909
+ function Us(e) {
1910
1910
  const t = [];
1911
1911
  let n = "", s = 0;
1912
1912
  for (; s < e.length; ) {
1913
- const i = e.indexOf("\r", s), r = e.indexOf(`
1913
+ const r = e.indexOf("\r", s), o = e.indexOf(`
1914
1914
  `, s);
1915
- let o = -1;
1916
- if (i !== -1 && r !== -1 ? o = Math.min(i, r) : i !== -1 ? i === e.length - 1 ? o = -1 : o = i : r !== -1 && (o = r), o === -1) {
1915
+ let i = -1;
1916
+ if (r !== -1 && o !== -1 ? i = Math.min(r, o) : r !== -1 ? r === e.length - 1 ? i = -1 : i = r : o !== -1 && (i = o), i === -1) {
1917
1917
  n = e.slice(s);
1918
1918
  break;
1919
1919
  } else {
1920
- const a = e.slice(s, o);
1921
- t.push(a), s = o + 1, e[s - 1] === "\r" && e[s] === `
1920
+ const a = e.slice(s, i);
1921
+ t.push(a), s = i + 1, e[s - 1] === "\r" && e[s] === `
1922
1922
  ` && s++;
1923
1923
  }
1924
1924
  }
1925
1925
  return [t, n];
1926
1926
  }
1927
- class qt extends Event {
1927
+ class un extends Event {
1928
1928
  /**
1929
1929
  * Constructs a new `ErrorEvent` instance. This is typically not called directly,
1930
1930
  * but rather emitted by the `EventSource` object when an error occurs.
@@ -1933,8 +1933,8 @@ class qt extends Event {
1933
1933
  * @param errorEventInitDict - Optional properties to include in the error event
1934
1934
  */
1935
1935
  constructor(t, n) {
1936
- var s, i;
1937
- super(t), this.code = (s = n == null ? void 0 : n.code) != null ? s : void 0, this.message = (i = n == null ? void 0 : n.message) != null ? i : void 0;
1936
+ var s, r;
1937
+ super(t), this.code = (s = n == null ? void 0 : n.code) != null ? s : void 0, this.message = (r = n == null ? void 0 : n.message) != null ? r : void 0;
1938
1938
  }
1939
1939
  /**
1940
1940
  * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
@@ -1949,7 +1949,7 @@ class qt extends Event {
1949
1949
  * @returns A string representation of the error
1950
1950
  */
1951
1951
  [Symbol.for("nodejs.util.inspect.custom")](t, n, s) {
1952
- return s(Kt(this), n);
1952
+ return s(fn(this), n);
1953
1953
  }
1954
1954
  /**
1955
1955
  * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
@@ -1963,17 +1963,17 @@ class qt extends Event {
1963
1963
  * @returns A string representation of the error
1964
1964
  */
1965
1965
  [Symbol.for("Deno.customInspect")](t, n) {
1966
- return t(Kt(this), n);
1966
+ return t(fn(this), n);
1967
1967
  }
1968
1968
  }
1969
- function vs(e) {
1969
+ function Ds(e) {
1970
1970
  const t = globalThis.DOMException;
1971
1971
  return typeof t == "function" ? new t(e, "SyntaxError") : new SyntaxError(e);
1972
1972
  }
1973
- function gt(e) {
1974
- return e instanceof Error ? "errors" in e && Array.isArray(e.errors) ? e.errors.map(gt).join(", ") : "cause" in e && e.cause instanceof Error ? `${e}: ${gt(e.cause)}` : e.message : `${e}`;
1973
+ function Tt(e) {
1974
+ return e instanceof Error ? "errors" in e && Array.isArray(e.errors) ? e.errors.map(Tt).join(", ") : "cause" in e && e.cause instanceof Error ? `${e}: ${Tt(e.cause)}` : e.message : `${e}`;
1975
1975
  }
1976
- function Kt(e) {
1976
+ function fn(e) {
1977
1977
  return {
1978
1978
  type: e.type,
1979
1979
  message: e.message,
@@ -1983,71 +1983,71 @@ function Kt(e) {
1983
1983
  timeStamp: e.timeStamp
1984
1984
  };
1985
1985
  }
1986
- var gn = (e) => {
1986
+ var An = (e) => {
1987
1987
  throw TypeError(e);
1988
- }, Mt = (e, t, n) => t.has(e) || gn("Cannot " + n), S = (e, t, n) => (Mt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), P = (e, t, n) => t.has(e) ? gn("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), _ = (e, t, n, s) => (Mt(e, t, "write to private field"), t.set(e, n), n), ae = (e, t, n) => (Mt(e, t, "access private method"), n), G, ge, $e, qe, et, Ke, Le, Ce, We, pe, ke, Re, _e, Ue, te, wt, St, It, Xt, vt, Et, Ne, Ot, $t;
1989
- class ne extends EventTarget {
1988
+ }, Kt = (e, t, n) => t.has(e) || An("Cannot " + n), I = (e, t, n) => (Kt(e, t, "read from private field"), n ? n.call(e) : t.get(e)), U = (e, t, n) => t.has(e) ? An("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), C = (e, t, n, s) => (Kt(e, t, "write to private field"), t.set(e, n), n), fe = (e, t, n) => (Kt(e, t, "access private method"), n), X, ke, Re, it, ft, ot, Ke, Me, qe, we, Ae, De, Pe, Ve, ie, xt, Rt, At, dn, Pt, Mt, Je, jt, Ut;
1989
+ class oe extends EventTarget {
1990
1990
  constructor(t, n) {
1991
- var s, i, r;
1992
- super(), P(this, te), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, P(this, G), P(this, ge), P(this, $e), P(this, qe), P(this, et), P(this, Ke), P(this, Le), P(this, Ce), P(this, We, null), P(this, pe), P(this, ke), P(this, Re, null), P(this, _e, null), P(this, Ue, null), P(this, St, async (o) => {
1991
+ var s, r, o;
1992
+ super(), U(this, ie), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, U(this, X), U(this, ke), U(this, Re), U(this, it), U(this, ft), U(this, ot), U(this, Ke), U(this, Me), U(this, qe, null), U(this, we), U(this, Ae), U(this, De, null), U(this, Pe, null), U(this, Ve, null), U(this, Rt, async (i) => {
1993
1993
  var a;
1994
- S(this, ke).reset();
1995
- const { body: c, redirected: u, status: l, headers: d } = o;
1994
+ I(this, Ae).reset();
1995
+ const { body: c, redirected: u, status: l, headers: f } = i;
1996
1996
  if (l === 204) {
1997
- ae(this, te, Ne).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
1997
+ fe(this, ie, Je).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
1998
1998
  return;
1999
1999
  }
2000
- if (u ? _(this, $e, new URL(o.url)) : _(this, $e, void 0), l !== 200) {
2001
- ae(this, te, Ne).call(this, `Non-200 status code (${l})`, l);
2000
+ if (u ? C(this, Re, new URL(i.url)) : C(this, Re, void 0), l !== 200) {
2001
+ fe(this, ie, Je).call(this, `Non-200 status code (${l})`, l);
2002
2002
  return;
2003
2003
  }
2004
- if (!(d.get("content-type") || "").startsWith("text/event-stream")) {
2005
- ae(this, te, Ne).call(this, 'Invalid content type, expected "text/event-stream"', l);
2004
+ if (!(f.get("content-type") || "").startsWith("text/event-stream")) {
2005
+ fe(this, ie, Je).call(this, 'Invalid content type, expected "text/event-stream"', l);
2006
2006
  return;
2007
2007
  }
2008
- if (S(this, G) === this.CLOSED)
2008
+ if (I(this, X) === this.CLOSED)
2009
2009
  return;
2010
- _(this, G, this.OPEN);
2010
+ C(this, X, this.OPEN);
2011
2011
  const p = new Event("open");
2012
- if ((a = S(this, Ue)) == null || a.call(this, p), this.dispatchEvent(p), typeof c != "object" || !c || !("getReader" in c)) {
2013
- ae(this, te, Ne).call(this, "Invalid response body, expected a web ReadableStream", l), this.close();
2012
+ if ((a = I(this, Ve)) == null || a.call(this, p), this.dispatchEvent(p), typeof c != "object" || !c || !("getReader" in c)) {
2013
+ fe(this, ie, Je).call(this, "Invalid response body, expected a web ReadableStream", l), this.close();
2014
2014
  return;
2015
2015
  }
2016
- const y = new TextDecoder(), v = c.getReader();
2017
- let b = !0;
2016
+ const m = new TextDecoder(), g = c.getReader();
2017
+ let w = !0;
2018
2018
  do {
2019
- const { done: h, value: I } = await v.read();
2020
- I && S(this, ke).feed(y.decode(I, { stream: !h })), h && (b = !1, S(this, ke).reset(), ae(this, te, Ot).call(this));
2021
- } while (b);
2022
- }), P(this, It, (o) => {
2023
- _(this, pe, void 0), !(o.name === "AbortError" || o.type === "aborted") && ae(this, te, Ot).call(this, gt(o));
2024
- }), P(this, vt, (o) => {
2025
- typeof o.id == "string" && _(this, We, o.id);
2026
- const a = new (S(this, Ke))(o.event || "message", {
2027
- data: o.data,
2028
- origin: S(this, $e) ? S(this, $e).origin : S(this, ge).origin,
2029
- lastEventId: o.id || ""
2019
+ const { done: h, value: k } = await g.read();
2020
+ k && I(this, Ae).feed(m.decode(k, { stream: !h })), h && (w = !1, I(this, Ae).reset(), fe(this, ie, jt).call(this));
2021
+ } while (w);
2022
+ }), U(this, At, (i) => {
2023
+ C(this, we, void 0), !(i.name === "AbortError" || i.type === "aborted") && fe(this, ie, jt).call(this, Tt(i));
2024
+ }), U(this, Pt, (i) => {
2025
+ typeof i.id == "string" && C(this, qe, i.id);
2026
+ const a = new (I(this, ot))(i.event || "message", {
2027
+ data: i.data,
2028
+ origin: I(this, Re) ? I(this, Re).origin : I(this, ke).origin,
2029
+ lastEventId: i.id || ""
2030
2030
  });
2031
- S(this, _e) && (!o.event || o.event === "message") && S(this, _e).call(this, a), this.dispatchEvent(a);
2032
- }), P(this, Et, (o) => {
2033
- _(this, Le, o);
2034
- }), P(this, $t, () => {
2035
- _(this, Ce, void 0), S(this, G) === this.CONNECTING && ae(this, te, wt).call(this);
2031
+ I(this, Pe) && (!i.event || i.event === "message") && I(this, Pe).call(this, a), this.dispatchEvent(a);
2032
+ }), U(this, Mt, (i) => {
2033
+ C(this, Ke, i);
2034
+ }), U(this, Ut, () => {
2035
+ C(this, Me, void 0), I(this, X) === this.CONNECTING && fe(this, ie, xt).call(this);
2036
2036
  });
2037
2037
  try {
2038
2038
  if (t instanceof URL)
2039
- _(this, ge, t);
2039
+ C(this, ke, t);
2040
2040
  else if (typeof t == "string")
2041
- _(this, ge, new URL(t, Es()));
2041
+ C(this, ke, new URL(t, Ns()));
2042
2042
  else
2043
2043
  throw new Error("Invalid URL");
2044
2044
  } catch {
2045
- throw vs("An invalid or illegal string was specified");
2045
+ throw Ds("An invalid or illegal string was specified");
2046
2046
  }
2047
- _(this, ke, Ss({
2048
- onEvent: S(this, vt),
2049
- onRetry: S(this, Et)
2050
- })), _(this, G, this.CONNECTING), _(this, Le, 3e3), _(this, et, (s = n == null ? void 0 : n.fetch) != null ? s : globalThis.fetch), _(this, Ke, (i = n == null ? void 0 : n.messageEvent) != null ? i : globalThis.MessageEvent), _(this, qe, (r = n == null ? void 0 : n.withCredentials) != null ? r : !1), ae(this, te, wt).call(this);
2047
+ C(this, Ae, js({
2048
+ onEvent: I(this, Pt),
2049
+ onRetry: I(this, Mt)
2050
+ })), C(this, X, this.CONNECTING), C(this, Ke, 3e3), C(this, ft, (s = n == null ? void 0 : n.fetch) != null ? s : globalThis.fetch), C(this, ot, (r = n == null ? void 0 : n.messageEvent) != null ? r : globalThis.MessageEvent), C(this, it, (o = n == null ? void 0 : n.withCredentials) != null ? o : !1), fe(this, ie, xt).call(this);
2051
2051
  }
2052
2052
  /**
2053
2053
  * Returns the state of this EventSource object's connection. It can have the values described below.
@@ -2060,7 +2060,7 @@ class ne extends EventTarget {
2060
2060
  * @public
2061
2061
  */
2062
2062
  get readyState() {
2063
- return S(this, G);
2063
+ return I(this, X);
2064
2064
  }
2065
2065
  /**
2066
2066
  * Returns the URL providing the event stream.
@@ -2070,7 +2070,7 @@ class ne extends EventTarget {
2070
2070
  * @public
2071
2071
  */
2072
2072
  get url() {
2073
- return S(this, ge).href;
2073
+ return I(this, ke).href;
2074
2074
  }
2075
2075
  /**
2076
2076
  * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
@@ -2078,36 +2078,36 @@ class ne extends EventTarget {
2078
2078
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
2079
2079
  */
2080
2080
  get withCredentials() {
2081
- return S(this, qe);
2081
+ return I(this, it);
2082
2082
  }
2083
2083
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
2084
2084
  get onerror() {
2085
- return S(this, Re);
2085
+ return I(this, De);
2086
2086
  }
2087
2087
  set onerror(t) {
2088
- _(this, Re, t);
2088
+ C(this, De, t);
2089
2089
  }
2090
2090
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
2091
2091
  get onmessage() {
2092
- return S(this, _e);
2092
+ return I(this, Pe);
2093
2093
  }
2094
2094
  set onmessage(t) {
2095
- _(this, _e, t);
2095
+ C(this, Pe, t);
2096
2096
  }
2097
2097
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
2098
2098
  get onopen() {
2099
- return S(this, Ue);
2099
+ return I(this, Ve);
2100
2100
  }
2101
2101
  set onopen(t) {
2102
- _(this, Ue, t);
2102
+ C(this, Ve, t);
2103
2103
  }
2104
2104
  addEventListener(t, n, s) {
2105
- const i = n;
2106
- super.addEventListener(t, i, s);
2105
+ const r = n;
2106
+ super.addEventListener(t, r, s);
2107
2107
  }
2108
2108
  removeEventListener(t, n, s) {
2109
- const i = n;
2110
- super.removeEventListener(t, i, s);
2109
+ const r = n;
2110
+ super.removeEventListener(t, r, s);
2111
2111
  }
2112
2112
  /**
2113
2113
  * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
@@ -2117,46 +2117,46 @@ class ne extends EventTarget {
2117
2117
  * @public
2118
2118
  */
2119
2119
  close() {
2120
- S(this, Ce) && clearTimeout(S(this, Ce)), S(this, G) !== this.CLOSED && (S(this, pe) && S(this, pe).abort(), _(this, G, this.CLOSED), _(this, pe, void 0));
2120
+ I(this, Me) && clearTimeout(I(this, Me)), I(this, X) !== this.CLOSED && (I(this, we) && I(this, we).abort(), C(this, X, this.CLOSED), C(this, we, void 0));
2121
2121
  }
2122
2122
  }
2123
- G = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakMap(), $e = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), et = /* @__PURE__ */ new WeakMap(), Ke = /* @__PURE__ */ new WeakMap(), Le = /* @__PURE__ */ new WeakMap(), Ce = /* @__PURE__ */ new WeakMap(), We = /* @__PURE__ */ new WeakMap(), pe = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), Re = /* @__PURE__ */ new WeakMap(), _e = /* @__PURE__ */ new WeakMap(), Ue = /* @__PURE__ */ new WeakMap(), te = /* @__PURE__ */ new WeakSet(), /**
2123
+ X = /* @__PURE__ */ new WeakMap(), ke = /* @__PURE__ */ new WeakMap(), Re = /* @__PURE__ */ new WeakMap(), it = /* @__PURE__ */ new WeakMap(), ft = /* @__PURE__ */ new WeakMap(), ot = /* @__PURE__ */ new WeakMap(), Ke = /* @__PURE__ */ new WeakMap(), Me = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), we = /* @__PURE__ */ new WeakMap(), Ae = /* @__PURE__ */ new WeakMap(), De = /* @__PURE__ */ new WeakMap(), Pe = /* @__PURE__ */ new WeakMap(), Ve = /* @__PURE__ */ new WeakMap(), ie = /* @__PURE__ */ new WeakSet(), /**
2124
2124
  * Connect to the given URL and start receiving events
2125
2125
  *
2126
2126
  * @internal
2127
2127
  */
2128
- wt = function() {
2129
- _(this, G, this.CONNECTING), _(this, pe, new AbortController()), S(this, et)(S(this, ge), ae(this, te, Xt).call(this)).then(S(this, St)).catch(S(this, It));
2130
- }, St = /* @__PURE__ */ new WeakMap(), It = /* @__PURE__ */ new WeakMap(), /**
2128
+ xt = function() {
2129
+ C(this, X, this.CONNECTING), C(this, we, new AbortController()), I(this, ft)(I(this, ke), fe(this, ie, dn).call(this)).then(I(this, Rt)).catch(I(this, At));
2130
+ }, Rt = /* @__PURE__ */ new WeakMap(), At = /* @__PURE__ */ new WeakMap(), /**
2131
2131
  * Get request options for the `fetch()` request
2132
2132
  *
2133
2133
  * @returns The request options
2134
2134
  * @internal
2135
2135
  */
2136
- Xt = function() {
2136
+ dn = function() {
2137
2137
  var e;
2138
2138
  const t = {
2139
2139
  // [spec] Let `corsAttributeState` be `Anonymous`…
2140
2140
  // [spec] …will have their mode set to "cors"…
2141
2141
  mode: "cors",
2142
2142
  redirect: "follow",
2143
- headers: { Accept: "text/event-stream", ...S(this, We) ? { "Last-Event-ID": S(this, We) } : void 0 },
2143
+ headers: { Accept: "text/event-stream", ...I(this, qe) ? { "Last-Event-ID": I(this, qe) } : void 0 },
2144
2144
  cache: "no-store",
2145
- signal: (e = S(this, pe)) == null ? void 0 : e.signal
2145
+ signal: (e = I(this, we)) == null ? void 0 : e.signal
2146
2146
  };
2147
2147
  return "window" in globalThis && (t.credentials = this.withCredentials ? "include" : "same-origin"), t;
2148
- }, vt = /* @__PURE__ */ new WeakMap(), Et = /* @__PURE__ */ new WeakMap(), /**
2148
+ }, Pt = /* @__PURE__ */ new WeakMap(), Mt = /* @__PURE__ */ new WeakMap(), /**
2149
2149
  * Handles the process referred to in the EventSource specification as "failing a connection".
2150
2150
  *
2151
2151
  * @param error - The error causing the connection to fail
2152
2152
  * @param code - The HTTP status code, if available
2153
2153
  * @internal
2154
2154
  */
2155
- Ne = function(e, t) {
2155
+ Je = function(e, t) {
2156
2156
  var n;
2157
- S(this, G) !== this.CLOSED && _(this, G, this.CLOSED);
2158
- const s = new qt("error", { code: t, message: e });
2159
- (n = S(this, Re)) == null || n.call(this, s), this.dispatchEvent(s);
2157
+ I(this, X) !== this.CLOSED && C(this, X, this.CLOSED);
2158
+ const s = new un("error", { code: t, message: e });
2159
+ (n = I(this, De)) == null || n.call(this, s), this.dispatchEvent(s);
2160
2160
  }, /**
2161
2161
  * Schedules a reconnection attempt against the EventSource endpoint.
2162
2162
  *
@@ -2164,85 +2164,85 @@ Ne = function(e, t) {
2164
2164
  * @param code - The HTTP status code, if available
2165
2165
  * @internal
2166
2166
  */
2167
- Ot = function(e, t) {
2167
+ jt = function(e, t) {
2168
2168
  var n;
2169
- if (S(this, G) === this.CLOSED)
2169
+ if (I(this, X) === this.CLOSED)
2170
2170
  return;
2171
- _(this, G, this.CONNECTING);
2172
- const s = new qt("error", { code: t, message: e });
2173
- (n = S(this, Re)) == null || n.call(this, s), this.dispatchEvent(s), _(this, Ce, setTimeout(S(this, $t), S(this, Le)));
2174
- }, $t = /* @__PURE__ */ new WeakMap(), /**
2171
+ C(this, X, this.CONNECTING);
2172
+ const s = new un("error", { code: t, message: e });
2173
+ (n = I(this, De)) == null || n.call(this, s), this.dispatchEvent(s), C(this, Me, setTimeout(I(this, Ut), I(this, Ke)));
2174
+ }, Ut = /* @__PURE__ */ new WeakMap(), /**
2175
2175
  * ReadyState representing an EventSource currently trying to connect
2176
2176
  *
2177
2177
  * @public
2178
2178
  */
2179
- ne.CONNECTING = 0, /**
2179
+ oe.CONNECTING = 0, /**
2180
2180
  * ReadyState representing an EventSource connection that is open (eg connected)
2181
2181
  *
2182
2182
  * @public
2183
2183
  */
2184
- ne.OPEN = 1, /**
2184
+ oe.OPEN = 1, /**
2185
2185
  * ReadyState representing an EventSource connection that is closed (eg disconnected)
2186
2186
  *
2187
2187
  * @public
2188
2188
  */
2189
- ne.CLOSED = 2;
2190
- Object.defineProperty(ne, Symbol.for("eventsource.supports-fetch-override"), {
2189
+ oe.CLOSED = 2;
2190
+ Object.defineProperty(oe, Symbol.for("eventsource.supports-fetch-override"), {
2191
2191
  value: !0,
2192
2192
  writable: !1,
2193
2193
  configurable: !1,
2194
2194
  enumerable: !1
2195
2195
  });
2196
- function Es() {
2196
+ function Ns() {
2197
2197
  const e = "document" in globalThis ? globalThis.document : void 0;
2198
2198
  return e && typeof e == "object" && "baseURI" in e && typeof e.baseURI == "string" ? e.baseURI : void 0;
2199
2199
  }
2200
- class wn extends Event {
2200
+ class Pn extends Event {
2201
2201
  constructor(n, s) {
2202
2202
  super(n);
2203
- f(this, "data");
2204
- f(this, "origin");
2205
- f(this, "lastEventId");
2206
- f(this, "source");
2207
- f(this, "ports");
2203
+ d(this, "data");
2204
+ d(this, "origin");
2205
+ d(this, "lastEventId");
2206
+ d(this, "source");
2207
+ d(this, "ports");
2208
2208
  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) ?? [];
2209
2209
  }
2210
2210
  /** @deprecated */
2211
- initMessageEvent(n, s, i, r, o, a, c, u) {
2211
+ initMessageEvent(n, s, r, o, i, a, c, u) {
2212
2212
  }
2213
2213
  }
2214
- function Os(e, t, n, s) {
2215
- let i = null, r = !1;
2216
- const o = [], a = (d) => {
2217
- o.push(d), o.length > 100 && o.shift(), i && (i(), i = null);
2214
+ function Ws(e, t, n, s) {
2215
+ let r = null, o = !1;
2216
+ const i = [], a = (f) => {
2217
+ i.push(f), i.length > 100 && i.shift(), r && (r(), r = null);
2218
2218
  };
2219
2219
  e(a);
2220
2220
  const c = () => (n(a), Promise.resolve({ done: !0, value: void 0 }));
2221
2221
  return t(() => {
2222
- r = !0, i && i(), c();
2222
+ o = !0, r && r(), c();
2223
2223
  }), {
2224
2224
  next: async () => {
2225
2225
  for (; ; ) {
2226
- if (s() === "closed" || r)
2226
+ if (s() === "closed" || o)
2227
2227
  return c();
2228
- const d = o.shift();
2229
- if (d)
2230
- return { value: d, done: !1 };
2231
- await new Promise((y) => {
2232
- i = y;
2228
+ const f = i.shift();
2229
+ if (f)
2230
+ return { value: f, done: !1 };
2231
+ await new Promise((m) => {
2232
+ r = m;
2233
2233
  });
2234
2234
  }
2235
2235
  },
2236
2236
  return: c,
2237
- throw(d) {
2238
- return n(a), Promise.reject(d);
2237
+ throw(f) {
2238
+ return n(a), Promise.reject(f);
2239
2239
  },
2240
2240
  [Symbol.asyncIterator]() {
2241
2241
  return this;
2242
2242
  }
2243
2243
  };
2244
2244
  }
2245
- function de(e) {
2245
+ function me(e) {
2246
2246
  switch (e.readyState) {
2247
2247
  case e.CLOSED:
2248
2248
  return "closed";
@@ -2254,7 +2254,7 @@ function de(e) {
2254
2254
  return "connecting";
2255
2255
  }
2256
2256
  }
2257
- function $s(e) {
2257
+ function Ls(e) {
2258
2258
  let t = null;
2259
2259
  return {
2260
2260
  ...e,
@@ -2266,7 +2266,7 @@ function $s(e) {
2266
2266
  }
2267
2267
  };
2268
2268
  }
2269
- function Yt(e) {
2269
+ function ln(e) {
2270
2270
  if (!e)
2271
2271
  return;
2272
2272
  const t = {};
@@ -2279,78 +2279,78 @@ function Yt(e) {
2279
2279
  };
2280
2280
  return t;
2281
2281
  }
2282
- function ks(e, t, n) {
2283
- let s, i = !1;
2284
- const r = xe(), o = new ne(`${n.apiURI}/admin/subscribe-query?local_connection_id=${r}`, {
2285
- messageEvent: wn,
2286
- fetch(h, I) {
2282
+ function Fs(e, t, n) {
2283
+ let s, r = !1;
2284
+ const o = je(), i = new oe(`${n.apiURI}/admin/subscribe-query?local_connection_id=${o}`, {
2285
+ messageEvent: Pn,
2286
+ fetch(h, k) {
2287
2287
  return s = null, fetch(h, {
2288
- ...I,
2288
+ ...k,
2289
2289
  method: "POST",
2290
2290
  headers: n.headers,
2291
2291
  body: JSON.stringify({
2292
2292
  query: e,
2293
2293
  "inference?": n.inference,
2294
2294
  versions: {
2295
- "@instantdb/admin": Me,
2296
- "@instantdb/core": Me
2295
+ "@instantdb/admin": _e,
2296
+ "@instantdb/core": _e
2297
2297
  }
2298
2298
  })
2299
- }).then((E) => (E.ok || (s = $s(E)), E));
2299
+ }).then((v) => (v.ok || (s = Ls(v)), v));
2300
2300
  }
2301
2301
  }), a = [], c = [], u = (h) => {
2302
2302
  a.push(h);
2303
2303
  }, l = (h) => {
2304
2304
  a.splice(a.indexOf(h), 1);
2305
- }, d = (h) => {
2305
+ }, f = (h) => {
2306
2306
  c.push(h);
2307
2307
  };
2308
2308
  t && u(t);
2309
2309
  let p = null;
2310
- function y(h) {
2311
- if (!i)
2312
- for (const I of a)
2310
+ function m(h) {
2311
+ if (!r)
2312
+ for (const k of a)
2313
2313
  try {
2314
- I(h);
2315
- } catch (E) {
2316
- console.error("Error in subscribeQuery callback", E);
2314
+ k(h);
2315
+ } catch (v) {
2316
+ console.error("Error in subscribeQuery callback", v);
2317
2317
  }
2318
2318
  }
2319
- function v(h) {
2320
- var I, E;
2319
+ function g(h) {
2320
+ var k, v;
2321
2321
  switch (h.op) {
2322
2322
  case "sse-init": {
2323
- const L = h["machine-id"], ye = h["session-id"];
2324
- p = { machineId: L, sessionId: ye };
2323
+ const z = h["machine-id"], Se = h["session-id"];
2324
+ p = { machineId: z, sessionId: Se };
2325
2325
  break;
2326
2326
  }
2327
2327
  case "add-query-ok": {
2328
- y({
2328
+ m({
2329
2329
  type: "ok",
2330
2330
  data: h.result,
2331
- pageInfo: Yt((I = h["result-meta"]) == null ? void 0 : I["page-info"]),
2331
+ pageInfo: ln((k = h["result-meta"]) == null ? void 0 : k["page-info"]),
2332
2332
  sessionInfo: p
2333
2333
  });
2334
2334
  break;
2335
2335
  }
2336
2336
  case "refresh-ok": {
2337
- h.computations.length && y({
2337
+ h.computations.length && m({
2338
2338
  type: "ok",
2339
2339
  data: h.computations[0]["instaql-result"],
2340
- pageInfo: Yt((E = h.computations[0]["result-meta"]) == null ? void 0 : E["page-info"]),
2340
+ pageInfo: ln((v = h.computations[0]["result-meta"]) == null ? void 0 : v["page-info"]),
2341
2341
  sessionInfo: p
2342
2342
  });
2343
2343
  break;
2344
2344
  }
2345
2345
  case "error": {
2346
- y({
2346
+ m({
2347
2347
  type: "error",
2348
- error: new ve({ body: h, status: h.status }),
2348
+ error: new le({ body: h, status: h.status }),
2349
2349
  get readyState() {
2350
- return de(o);
2350
+ return me(i);
2351
2351
  },
2352
2352
  get isClosed() {
2353
- return de(o) === "closed";
2353
+ return me(i) === "closed";
2354
2354
  },
2355
2355
  sessionInfo: p
2356
2356
  });
@@ -2358,34 +2358,34 @@ function ks(e, t, n) {
2358
2358
  }
2359
2359
  }
2360
2360
  }
2361
- return o.onerror = (h) => {
2361
+ return i.onerror = (h) => {
2362
2362
  if (s)
2363
- s.text().then((I) => {
2364
- let E = { type: void 0, message: I };
2363
+ s.text().then((k) => {
2364
+ let v = { type: void 0, message: k };
2365
2365
  try {
2366
- E = JSON.parse(I);
2366
+ v = JSON.parse(k);
2367
2367
  } catch {
2368
2368
  }
2369
- y({
2369
+ m({
2370
2370
  type: "error",
2371
- error: new ve({
2371
+ error: new le({
2372
2372
  status: s.status,
2373
- body: E
2373
+ body: v
2374
2374
  }),
2375
2375
  get readyState() {
2376
- return de(o);
2376
+ return me(i);
2377
2377
  },
2378
2378
  get isClosed() {
2379
- return de(o) === "closed";
2379
+ return me(i) === "closed";
2380
2380
  },
2381
2381
  sessionInfo: p
2382
2382
  });
2383
2383
  });
2384
2384
  else {
2385
- const I = () => {
2386
- y({
2385
+ const k = () => {
2386
+ m({
2387
2387
  type: "error",
2388
- error: new ve({
2388
+ error: new le({
2389
2389
  status: h.code || 500,
2390
2390
  body: {
2391
2391
  type: void 0,
@@ -2393,34 +2393,34 @@ function ks(e, t, n) {
2393
2393
  }
2394
2394
  }),
2395
2395
  get readyState() {
2396
- return de(o);
2396
+ return me(i);
2397
2397
  },
2398
2398
  get isClosed() {
2399
- return de(o) === "closed";
2399
+ return me(i) === "closed";
2400
2400
  },
2401
2401
  sessionInfo: p
2402
2402
  });
2403
2403
  };
2404
- if (o.readyState === ne.CLOSED) {
2405
- I();
2404
+ if (i.readyState === oe.CLOSED) {
2405
+ k();
2406
2406
  return;
2407
2407
  }
2408
2408
  setTimeout(() => {
2409
- o.readyState !== ne.OPEN && I();
2409
+ i.readyState !== oe.OPEN && k();
2410
2410
  }, 5e3);
2411
2411
  }
2412
- }, o.onmessage = (h) => {
2413
- v(JSON.parse(h.data));
2412
+ }, i.onmessage = (h) => {
2413
+ g(JSON.parse(h.data));
2414
2414
  }, {
2415
2415
  close: () => {
2416
- i = !0;
2416
+ r = !0;
2417
2417
  for (const h of c)
2418
2418
  try {
2419
2419
  h();
2420
- } catch (I) {
2421
- console.error("Error in onClose callback", I);
2420
+ } catch (k) {
2421
+ console.error("Error in onClose callback", k);
2422
2422
  }
2423
- o.close();
2423
+ i.close();
2424
2424
  },
2425
2425
  [Symbol.iterator]: () => {
2426
2426
  throw new Error("subscribeQuery does not support synchronous iteration. Use `for await` instead.");
@@ -2429,89 +2429,89 @@ function ks(e, t, n) {
2429
2429
  return p;
2430
2430
  },
2431
2431
  get readyState() {
2432
- return de(o);
2432
+ return me(i);
2433
2433
  },
2434
2434
  get isClosed() {
2435
- return de(o) === "closed";
2435
+ return me(i) === "closed";
2436
2436
  },
2437
- [Symbol.asyncIterator]: Os.bind(this, u, d, l, () => 1)
2437
+ [Symbol.asyncIterator]: Ws.bind(this, u, f, l, () => 1)
2438
2438
  };
2439
2439
  }
2440
- var ue = {};
2441
- Object.defineProperty(ue, "__esModule", { value: !0 });
2442
- var _s = ue.parseCookie = vn;
2443
- ue.parse = vn;
2444
- ue.stringifyCookie = As;
2445
- ue.stringifySetCookie = rt;
2446
- ue.serialize = rt;
2447
- ue.parseSetCookie = Ms;
2448
- ue.stringifySetCookie = rt;
2449
- ue.serialize = rt;
2450
- const Sn = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, In = /^[\u0021-\u003A\u003C-\u007E]*$/, Cs = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i, xs = /^[\u0020-\u003A\u003D-\u007E]*$/, Ts = /^-?\d+$/, Rs = Object.prototype.toString, Ps = /* @__PURE__ */ (() => {
2440
+ var he = {};
2441
+ Object.defineProperty(he, "__esModule", { value: !0 });
2442
+ var zs = he.parseCookie = Un;
2443
+ he.parse = Un;
2444
+ he.stringifyCookie = Bs;
2445
+ he.stringifySetCookie = yt;
2446
+ he.serialize = yt;
2447
+ he.parseSetCookie = Qs;
2448
+ he.stringifySetCookie = yt;
2449
+ he.serialize = yt;
2450
+ const Mn = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/, jn = /^[\u0021-\u003A\u003C-\u007E]*$/, Vs = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i, Js = /^[\u0020-\u003A\u003D-\u007E]*$/, Hs = /^-?\d+$/, Ks = Object.prototype.toString, qs = /* @__PURE__ */ (() => {
2451
2451
  const e = function() {
2452
2452
  };
2453
2453
  return e.prototype = /* @__PURE__ */ Object.create(null), e;
2454
2454
  })();
2455
- function vn(e, t) {
2456
- const n = new Ps(), s = e.length;
2455
+ function Un(e, t) {
2456
+ const n = new qs(), s = e.length;
2457
2457
  if (s < 2)
2458
2458
  return n;
2459
- const i = (t == null ? void 0 : t.decode) || En;
2460
- let r = 0;
2459
+ const r = (t == null ? void 0 : t.decode) || Dn;
2460
+ let o = 0;
2461
2461
  do {
2462
- const o = _t(e, r, s);
2463
- if (o === -1)
2462
+ const i = Nt(e, o, s);
2463
+ if (i === -1)
2464
2464
  break;
2465
- const a = kt(e, r, s);
2466
- if (o > a) {
2467
- r = e.lastIndexOf(";", o - 1) + 1;
2465
+ const a = Dt(e, o, s);
2466
+ if (i > a) {
2467
+ o = e.lastIndexOf(";", i - 1) + 1;
2468
2468
  continue;
2469
2469
  }
2470
- const c = he(e, r, o);
2471
- n[c] === void 0 && (n[c] = i(he(e, o + 1, a))), r = a + 1;
2472
- } while (r < s);
2470
+ const c = be(e, o, i);
2471
+ n[c] === void 0 && (n[c] = r(be(e, i + 1, a))), o = a + 1;
2472
+ } while (o < s);
2473
2473
  return n;
2474
2474
  }
2475
- function As(e, t) {
2475
+ function Bs(e, t) {
2476
2476
  const n = (t == null ? void 0 : t.encode) || encodeURIComponent, s = [];
2477
- for (const i of Object.keys(e)) {
2478
- const r = e[i];
2479
- if (r === void 0)
2477
+ for (const r of Object.keys(e)) {
2478
+ const o = e[r];
2479
+ if (o === void 0)
2480
2480
  continue;
2481
- if (!Sn.test(i))
2482
- throw new TypeError(`cookie name is invalid: ${i}`);
2483
- const o = n(r);
2484
- if (!In.test(o))
2485
- throw new TypeError(`cookie val is invalid: ${r}`);
2486
- s.push(`${i}=${o}`);
2481
+ if (!Mn.test(r))
2482
+ throw new TypeError(`cookie name is invalid: ${r}`);
2483
+ const i = n(o);
2484
+ if (!jn.test(i))
2485
+ throw new TypeError(`cookie val is invalid: ${o}`);
2486
+ s.push(`${r}=${i}`);
2487
2487
  }
2488
2488
  return s.join("; ");
2489
2489
  }
2490
- function rt(e, t, n) {
2491
- const s = typeof e == "object" ? e : { ...n, name: e, value: String(t) }, i = typeof t == "object" ? t : n, r = (i == null ? void 0 : i.encode) || encodeURIComponent;
2492
- if (!Sn.test(s.name))
2490
+ function yt(e, t, n) {
2491
+ const s = typeof e == "object" ? e : { ...n, name: e, value: String(t) }, r = typeof t == "object" ? t : n, o = (r == null ? void 0 : r.encode) || encodeURIComponent;
2492
+ if (!Mn.test(s.name))
2493
2493
  throw new TypeError(`argument name is invalid: ${s.name}`);
2494
- const o = s.value ? r(s.value) : "";
2495
- if (!In.test(o))
2494
+ const i = s.value ? o(s.value) : "";
2495
+ if (!jn.test(i))
2496
2496
  throw new TypeError(`argument val is invalid: ${s.value}`);
2497
- let a = s.name + "=" + o;
2497
+ let a = s.name + "=" + i;
2498
2498
  if (s.maxAge !== void 0) {
2499
2499
  if (!Number.isInteger(s.maxAge))
2500
2500
  throw new TypeError(`option maxAge is invalid: ${s.maxAge}`);
2501
2501
  a += "; Max-Age=" + s.maxAge;
2502
2502
  }
2503
2503
  if (s.domain) {
2504
- if (!Cs.test(s.domain))
2504
+ if (!Vs.test(s.domain))
2505
2505
  throw new TypeError(`option domain is invalid: ${s.domain}`);
2506
2506
  a += "; Domain=" + s.domain;
2507
2507
  }
2508
2508
  if (s.path) {
2509
- if (!xs.test(s.path))
2509
+ if (!Js.test(s.path))
2510
2510
  throw new TypeError(`option path is invalid: ${s.path}`);
2511
2511
  a += "; Path=" + s.path;
2512
2512
  }
2513
2513
  if (s.expires) {
2514
- if (!js(s.expires) || !Number.isFinite(s.expires.valueOf()))
2514
+ if (!Gs(s.expires) || !Number.isFinite(s.expires.valueOf()))
2515
2515
  throw new TypeError(`option expires is invalid: ${s.expires}`);
2516
2516
  a += "; Expires=" + s.expires.toUTCString();
2517
2517
  }
@@ -2546,80 +2546,80 @@ function rt(e, t, n) {
2546
2546
  }
2547
2547
  return a;
2548
2548
  }
2549
- function Ms(e, t) {
2550
- const n = (t == null ? void 0 : t.decode) || En, s = e.length, i = kt(e, 0, s), r = _t(e, 0, i), o = r === -1 ? { name: "", value: n(he(e, 0, i)) } : {
2551
- name: he(e, 0, r),
2552
- value: n(he(e, r + 1, i))
2549
+ function Qs(e, t) {
2550
+ const n = (t == null ? void 0 : t.decode) || Dn, s = e.length, r = Dt(e, 0, s), o = Nt(e, 0, r), i = o === -1 ? { name: "", value: n(be(e, 0, r)) } : {
2551
+ name: be(e, 0, o),
2552
+ value: n(be(e, o + 1, r))
2553
2553
  };
2554
- let a = i + 1;
2554
+ let a = r + 1;
2555
2555
  for (; a < s; ) {
2556
- const c = kt(e, a, s), u = _t(e, a, c), l = u === -1 ? he(e, a, c) : he(e, a, u), d = u === -1 ? void 0 : he(e, u + 1, c);
2556
+ const c = Dt(e, a, s), u = Nt(e, a, c), l = u === -1 ? be(e, a, c) : be(e, a, u), f = u === -1 ? void 0 : be(e, u + 1, c);
2557
2557
  switch (l.toLowerCase()) {
2558
2558
  case "httponly":
2559
- o.httpOnly = !0;
2559
+ i.httpOnly = !0;
2560
2560
  break;
2561
2561
  case "secure":
2562
- o.secure = !0;
2562
+ i.secure = !0;
2563
2563
  break;
2564
2564
  case "partitioned":
2565
- o.partitioned = !0;
2565
+ i.partitioned = !0;
2566
2566
  break;
2567
2567
  case "domain":
2568
- o.domain = d;
2568
+ i.domain = f;
2569
2569
  break;
2570
2570
  case "path":
2571
- o.path = d;
2571
+ i.path = f;
2572
2572
  break;
2573
2573
  case "max-age":
2574
- d && Ts.test(d) && (o.maxAge = Number(d));
2574
+ f && Hs.test(f) && (i.maxAge = Number(f));
2575
2575
  break;
2576
2576
  case "expires":
2577
- if (!d)
2577
+ if (!f)
2578
2578
  break;
2579
- const p = new Date(d);
2580
- Number.isFinite(p.valueOf()) && (o.expires = p);
2579
+ const p = new Date(f);
2580
+ Number.isFinite(p.valueOf()) && (i.expires = p);
2581
2581
  break;
2582
2582
  case "priority":
2583
- if (!d)
2583
+ if (!f)
2584
2584
  break;
2585
- const y = d.toLowerCase();
2586
- (y === "low" || y === "medium" || y === "high") && (o.priority = y);
2585
+ const m = f.toLowerCase();
2586
+ (m === "low" || m === "medium" || m === "high") && (i.priority = m);
2587
2587
  break;
2588
2588
  case "samesite":
2589
- if (!d)
2589
+ if (!f)
2590
2590
  break;
2591
- const v = d.toLowerCase();
2592
- (v === "lax" || v === "strict" || v === "none") && (o.sameSite = v);
2591
+ const g = f.toLowerCase();
2592
+ (g === "lax" || g === "strict" || g === "none") && (i.sameSite = g);
2593
2593
  break;
2594
2594
  }
2595
2595
  a = c + 1;
2596
2596
  }
2597
- return o;
2597
+ return i;
2598
2598
  }
2599
- function kt(e, t, n) {
2599
+ function Dt(e, t, n) {
2600
2600
  const s = e.indexOf(";", t);
2601
2601
  return s === -1 ? n : s;
2602
2602
  }
2603
- function _t(e, t, n) {
2603
+ function Nt(e, t, n) {
2604
2604
  const s = e.indexOf("=", t);
2605
2605
  return s < n ? s : -1;
2606
2606
  }
2607
- function he(e, t, n) {
2608
- let s = t, i = n;
2607
+ function be(e, t, n) {
2608
+ let s = t, r = n;
2609
2609
  do {
2610
- const r = e.charCodeAt(s);
2611
- if (r !== 32 && r !== 9)
2610
+ const o = e.charCodeAt(s);
2611
+ if (o !== 32 && o !== 9)
2612
2612
  break;
2613
- } while (++s < i);
2614
- for (; i > s; ) {
2615
- const r = e.charCodeAt(i - 1);
2616
- if (r !== 32 && r !== 9)
2613
+ } while (++s < r);
2614
+ for (; r > s; ) {
2615
+ const o = e.charCodeAt(r - 1);
2616
+ if (o !== 32 && o !== 9)
2617
2617
  break;
2618
- i--;
2618
+ r--;
2619
2619
  }
2620
- return e.slice(s, i);
2620
+ return e.slice(s, r);
2621
2621
  }
2622
- function En(e) {
2622
+ function Dn(e) {
2623
2623
  if (e.indexOf("%") === -1)
2624
2624
  return e;
2625
2625
  try {
@@ -2628,90 +2628,720 @@ function En(e) {
2628
2628
  return e;
2629
2629
  }
2630
2630
  }
2631
- function js(e) {
2632
- return Rs.call(e) === "[object Date]";
2631
+ function Gs(e) {
2632
+ return Ks.call(e) === "[object Date]";
2633
2633
  }
2634
- function Us(e) {
2634
+ const Xs = {
2635
+ "https://api.instantdb.com": {
2636
+ keys: [
2637
+ {
2638
+ kty: "OKP",
2639
+ crv: "Ed25519",
2640
+ alg: "EdDSA",
2641
+ use: "sig",
2642
+ kid: "1034696293",
2643
+ x: "N-C41432STKAKkXAWmeIOXMnZcGRR1b9u1L3bTVqI_o"
2644
+ }
2645
+ ]
2646
+ },
2647
+ "http://localhost:8888": {
2648
+ keys: [
2649
+ {
2650
+ kty: "OKP",
2651
+ crv: "Ed25519",
2652
+ alg: "EdDSA",
2653
+ use: "sig",
2654
+ kid: "503090235",
2655
+ x: "qrSkwDaMITRMF9nOgpueqxgaAiuFmJperYE3mkyl8Ow"
2656
+ }
2657
+ ]
2658
+ }
2659
+ };
2660
+ function Ys(e) {
2661
+ if (e.kty === "OKP" && e.crv === "Ed25519")
2662
+ return { name: "Ed25519" };
2663
+ if (e.kty === "EC")
2664
+ return { name: "ECDSA", namedCurve: e.crv };
2665
+ if (e.kty === "RSA")
2666
+ return {
2667
+ name: "RSASSA-PKCS1-v1_5",
2668
+ hash: {
2669
+ RS256: "SHA-256",
2670
+ RS384: "SHA-384",
2671
+ RS512: "SHA-512"
2672
+ }[e.alg] || "SHA-256"
2673
+ };
2674
+ throw new Error(`Unsupported JWK configuration: kty=${e.kty}, crv=${e.crv}`);
2675
+ }
2676
+ async function Zs(e) {
2677
+ const t = Ys(e), n = await crypto.subtle.importKey("jwk", e, t, !1, ["verify"]);
2678
+ return { alg: t, key: n };
2679
+ }
2680
+ function er(e, t, n, s) {
2681
+ return crypto.subtle.verify(e, t, n, s);
2682
+ }
2683
+ function tr(e) {
2684
+ const t = new Uint8Array(Math.ceil(e.length / 2));
2685
+ for (let n = 0; n < t.length; n++)
2686
+ t[n] = parseInt(e.substring(n * 2, n * 2 + 2), 16);
2687
+ return t;
2688
+ }
2689
+ function nr(e) {
2690
+ let t, n, s;
2691
+ for (const o of e.split(",")) {
2692
+ const [i, a] = o.split("=");
2693
+ switch (i) {
2694
+ case "t": {
2695
+ t = a;
2696
+ break;
2697
+ }
2698
+ case "kid": {
2699
+ n = a;
2700
+ break;
2701
+ }
2702
+ case "v1": {
2703
+ s = a;
2704
+ break;
2705
+ }
2706
+ }
2707
+ }
2708
+ const r = [];
2709
+ if (t || r.push("t"), n || r.push("kid"), s || r.push("v1"), r.length || !t || !n || !s)
2710
+ throw new _("Invalid Instant-Signature header.", {
2711
+ header: e,
2712
+ missingKeys: r
2713
+ });
2714
+ return { t, kid: n, v1: s };
2715
+ }
2716
+ function sr(e, t, n) {
2717
+ if (Math.floor(e.getTime() / 1e3) - parseInt(t, 10) > n)
2718
+ throw new _("Webhook signature is too old", {
2719
+ tolerance: n,
2720
+ receivedAt: e,
2721
+ t
2722
+ });
2723
+ }
2724
+ const hn = {}, rr = 300;
2725
+ async function ir(e, t) {
2726
+ const n = await t.text();
2727
+ try {
2728
+ const s = JSON.parse(n);
2729
+ return e(new le({ status: t.status, body: s }));
2730
+ } catch {
2731
+ return e(new le({
2732
+ status: t.status,
2733
+ body: { type: void 0, message: n }
2734
+ }));
2735
+ }
2736
+ }
2737
+ const or = async (e, t) => {
2738
+ const n = {
2739
+ ...(t == null ? void 0 : t.headers) || {},
2740
+ "Instant-Core-Version": _e
2741
+ }, s = await fetch(e, { ...t, headers: n });
2742
+ return s.status === 200 ? s.json() : ir((r) => Promise.reject(r), s);
2743
+ };
2744
+ function Nn(e) {
2745
+ return e ? new Date(e) : null;
2746
+ }
2747
+ function xe(e) {
2748
+ return {
2749
+ id: e.id,
2750
+ sink: e.sink,
2751
+ etypes: e.etypes ?? [],
2752
+ actions: e.actions,
2753
+ status: e.status,
2754
+ disabledReason: e.disabled_reason ?? null,
2755
+ createdAt: new Date(e.created_at),
2756
+ updatedAt: new Date(e.updated_at)
2757
+ };
2758
+ }
2759
+ function ar(e) {
2760
+ return {
2761
+ attemptAt: Nn(e["attempt-at"]),
2762
+ durationMs: e["duration-ms"] ?? null,
2763
+ success: e["success?"] ?? null,
2764
+ statusCode: e["status-code"] ?? null,
2765
+ responseText: e["response-text"] ?? null,
2766
+ errorType: e["error-type"] ?? null,
2767
+ errorMessage: e["error-message"] ?? null
2768
+ };
2769
+ }
2770
+ function $t(e) {
2771
+ return {
2772
+ isn: e.isn,
2773
+ status: e.status,
2774
+ attempts: e.attempts ? e.attempts.map(ar) : null,
2775
+ nextAttemptAfter: Nn(e.next_attempt_after),
2776
+ createdAt: new Date(e.created_at),
2777
+ updatedAt: new Date(e.updated_at)
2778
+ };
2779
+ }
2780
+ var K, Qe, Ne, We, Ge, Y, re;
2781
+ class cr {
2782
+ constructor(t) {
2783
+ j(this, Y);
2784
+ j(this, K);
2785
+ j(this, Qe);
2786
+ j(this, Ne);
2787
+ j(this, We);
2788
+ j(this, Ge);
2789
+ J(this, K, t.appId), J(this, Qe, t.apiURI), J(this, Ne, t.token), J(this, We, t.withAuth), J(this, Ge, t.jsonFetch);
2790
+ }
2791
+ /**
2792
+ * Returns every webhook configured on the app, newest first. Includes both
2793
+ * active and disabled webhooks.
2794
+ */
2795
+ async list() {
2796
+ return ((await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks`)).webhooks || []).map(xe);
2797
+ }
2798
+ /**
2799
+ * Creates a new webhook. The webhook is created in the `active` state and
2800
+ * starts receiving matching events immediately.
2801
+ *
2802
+ * The server rejects the request if `url` is not an HTTPS URL pointing at a
2803
+ * public host, if `etypes` doesn't reference any entity in the app's
2804
+ * schema, if `actions` is empty, or if the app has hit its webhook limit.
2805
+ *
2806
+ * An app may have at most **100 active webhooks** at a time; {@link delete}
2807
+ * a webhook to free up a slot before creating another.
2808
+ *
2809
+ * @example
2810
+ * const webhook = await db.webhooks.manager.create({
2811
+ * url: 'https://example.com/instant',
2812
+ * etypes: ['posts', 'comments'],
2813
+ * actions: ['create', 'update'],
2814
+ * });
2815
+ */
2816
+ async create(t) {
2817
+ const n = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks`, {
2818
+ method: "POST",
2819
+ body: t
2820
+ });
2821
+ return xe(n.webhook);
2822
+ }
2823
+ /**
2824
+ * Updates a webhook's `url`, `etypes`, and/or `actions`. Pass only the
2825
+ * fields you want to change; omitted fields keep their current value.
2826
+ *
2827
+ * Does not affect the webhook's status — use {@link enable} or
2828
+ * {@link disable} for that.
2829
+ */
2830
+ async update(t, n) {
2831
+ const s = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}`, { method: "POST", body: n });
2832
+ return xe(s.webhook);
2833
+ }
2834
+ /**
2835
+ * Deletes a webhook. No further events will be queued for it. Returns the
2836
+ * webhook as it looked just before deletion.
2837
+ */
2838
+ async delete(t) {
2839
+ const n = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}`, { method: "DELETE" });
2840
+ return xe(n.webhook);
2841
+ }
2842
+ /**
2843
+ * Re-enables a disabled webhook. Clears `disabledReason` and resumes
2844
+ * delivery for new events. Has no effect if the webhook is already active.
2845
+ *
2846
+ * Events that occurred while the webhook was disabled are not retroactively
2847
+ * delivered.
2848
+ */
2849
+ async enable(t) {
2850
+ const n = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}/enable`, { method: "POST", body: {} });
2851
+ return xe(n.webhook);
2852
+ }
2853
+ /**
2854
+ * Disables a webhook. No new events will be queued until it is re-enabled
2855
+ * via {@link enable}. In-flight events already being processed will still
2856
+ * complete.
2857
+ *
2858
+ * @param opts.reason Optional human-readable note stored on the webhook
2859
+ * and surfaced in the dashboard.
2860
+ */
2861
+ async disable(t, n) {
2862
+ const s = n != null && n.reason ? { reason: n.reason } : {}, r = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}/disable`, { method: "POST", body: s });
2863
+ return xe(r.webhook);
2864
+ }
2865
+ /**
2866
+ * Returns a page of events for a webhook, newest first.
2867
+ *
2868
+ * Events are retained for ~60 days. To paginate, pass the previous page's
2869
+ * `pageInfo.endCursor` as `opts.after`; stop when `pageInfo.hasNextPage`
2870
+ * is `false`.
2871
+ */
2872
+ async listEvents(t, n) {
2873
+ var o, i, a;
2874
+ const s = n != null && n.after ? `?after=${encodeURIComponent(n.after)}` : "", r = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}/events${s}`);
2875
+ return {
2876
+ events: (r.events || []).map($t),
2877
+ pageInfo: {
2878
+ startCursor: ((o = r.pageInfo) == null ? void 0 : o.startCursor) ?? null,
2879
+ endCursor: ((i = r.pageInfo) == null ? void 0 : i.endCursor) ?? null,
2880
+ hasNextPage: !!((a = r.pageInfo) != null && a.hasNextPage)
2881
+ }
2882
+ };
2883
+ }
2884
+ /**
2885
+ * Fetches a single webhook event by its `isn`.
2886
+ */
2887
+ async getEvent(t, n) {
2888
+ const s = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}/events/${n}`);
2889
+ return $t(s.event);
2890
+ }
2891
+ /** Returns the full payload for an event. */
2892
+ async getPayload(t, n) {
2893
+ return R(this, Y, re).call(this, `/webhooks/payload/${y(this, K)}/${t}/${n}`);
2894
+ }
2895
+ /**
2896
+ * Re-queues an event for delivery, regardless of its current status. Use
2897
+ * this to retry a `failed` event or force a redelivery of a `success` one.
2898
+ *
2899
+ * The server rate-limits resends; if the event was queued or resent very
2900
+ * recently the call will fail with a validation error asking you to try
2901
+ * again in about a minute.
2902
+ */
2903
+ async resendEvent(t, n) {
2904
+ const s = await R(this, Y, re).call(this, `/dash/apps/${y(this, K)}/webhooks/${t}/events/${n}`, { method: "POST", body: {} });
2905
+ return $t(s.event);
2906
+ }
2907
+ }
2908
+ K = new WeakMap(), Qe = new WeakMap(), Ne = new WeakMap(), We = new WeakMap(), Ge = new WeakMap(), Y = new WeakSet(), re = function(t, n) {
2909
+ if (!y(this, K))
2910
+ throw new _("appId is required to manage webhooks. Pass it to the Webhooks constructor.");
2911
+ const s = (r) => {
2912
+ const o = {
2913
+ method: n == null ? void 0 : n.method,
2914
+ headers: {
2915
+ authorization: `Bearer ${r}`,
2916
+ "content-type": "application/json"
2917
+ }
2918
+ };
2919
+ return (n == null ? void 0 : n.body) !== void 0 && (o.body = JSON.stringify(n.body)), y(this, Ge).call(this, `${y(this, Qe)}${t}`, o);
2920
+ };
2921
+ if (y(this, We))
2922
+ return y(this, We).call(this, s);
2923
+ if (!y(this, Ne))
2924
+ throw new _("A token is required to manage webhooks. Pass `adminToken` or `token` to the Webhooks constructor.");
2925
+ return s(y(this, Ne));
2926
+ };
2927
+ var Xe, $e;
2928
+ const qt = class qt {
2929
+ constructor(t, n) {
2930
+ /** App this instance is bound to. */
2931
+ d(this, "appId");
2932
+ /** Schema used to type webhook payloads and handler records. */
2933
+ d(this, "schema");
2934
+ j(this, Xe);
2935
+ /** Base URL for the Instant API. */
2936
+ d(this, "apiURI");
2937
+ j(this, $e);
2938
+ /** Manage webhook subscriptions and inspect delivery events. */
2939
+ d(this, "manager");
2940
+ this.appId = t.appId, this.schema = t.schema, J(this, Xe, t.adminToken || t.token), this.apiURI = t.apiURI || "https://api.instantdb.com", J(this, $e, n || or), this.manager = new cr({
2941
+ appId: this.appId,
2942
+ apiURI: this.apiURI,
2943
+ token: y(this, Xe),
2944
+ withAuth: t.withAuth,
2945
+ jsonFetch: y(this, $e)
2946
+ });
2947
+ }
2948
+ /**
2949
+ * Schema-bound helpers for building typed handler maps.
2950
+ *
2951
+ * - `typedHandlers(etype, action, handler)` builds a single typed entry.
2952
+ * Pass `'$default'` for `etype` to register a catch-all handler.
2953
+ * - `combineHandlers(...entries)` merges entries into a
2954
+ * {@link WebhookHandlers} object suitable for {@link processPayload} and
2955
+ * {@link processRequest}.
2956
+ *
2957
+ * If you already have a {@link Webhooks} instance, prefer the instance
2958
+ * form (`db.webhooks.helpers()`) — it infers `Schema` automatically.
2959
+ *
2960
+ * @example
2961
+ * const { typedHandlers, combineHandlers } = Webhooks.helpers<typeof schema>();
2962
+ * const handlers = combineHandlers(
2963
+ * typedHandlers('posts', 'create', (record) => { ... }),
2964
+ * typedHandlers('comments', '$default', (record) => { ... }),
2965
+ * typedHandlers('$default', (record) => { ... }),
2966
+ * );
2967
+ */
2968
+ static helpers() {
2969
+ function t(...s) {
2970
+ if (s.length === 2)
2971
+ return { $default: s[1] };
2972
+ const [r, o, i] = s;
2973
+ return { [r]: { [o]: i } };
2974
+ }
2975
+ function n(...s) {
2976
+ const r = {};
2977
+ for (const o of s)
2978
+ for (const i of Object.keys(o))
2979
+ i === "$default" ? r.$default = o.$default : r[i] = { ...r[i], ...o[i] };
2980
+ return r;
2981
+ }
2982
+ return {
2983
+ typedHandlers: t,
2984
+ combineHandlers: n
2985
+ };
2986
+ }
2987
+ /**
2988
+ * Instance form of {@link Webhooks.helpers} that infers `Schema` from this
2989
+ * instance — no `<typeof schema>` type argument required.
2990
+ *
2991
+ * @example
2992
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
2993
+ */
2994
+ helpers() {
2995
+ return qt.helpers();
2996
+ }
2997
+ /** Fetches Instant's JWK set for verifying webhook signatures. */
2998
+ async fetchJwks() {
2999
+ return await y(this, $e).call(this, `${this.apiURI}/.well-known/webhooks/jwks.json`);
3000
+ }
3001
+ /**
3002
+ * Resolves a `kid` to an imported {@link CryptoKey}, hitting a
3003
+ * process-wide cache on repeat calls. Falls back to {@link fetchJwks} if
3004
+ * the key isn't already known.
3005
+ */
3006
+ async keyOfKid(t) {
3007
+ var i, a, c;
3008
+ const n = `${this.apiURI}:${t}`, s = hn[n];
3009
+ if (s)
3010
+ return s;
3011
+ const r = ((i = Xs[this.apiURI]) == null ? void 0 : i.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));
3012
+ if (!r)
3013
+ throw new _("Could not find matching signing key", { kid: t });
3014
+ const o = await Zs(r);
3015
+ return hn[n] = o, o;
3016
+ }
3017
+ /**
3018
+ * Verifies an `Instant-Signature` header against a body and returns the
3019
+ * parsed {@link WebhookBody} (containing the `payloadUrl` and a JWT
3020
+ * `token` for fetching the records).
3021
+ *
3022
+ * Throws if the signature doesn't validate, the signature is older than
3023
+ * `opts.tolerance` (default 300 seconds), or the body doesn't decode to
3024
+ * the expected shape.
3025
+ *
3026
+ * @param body Either the raw body string, or a function returning it.
3027
+ * Use a function to defer reading the body until after the
3028
+ * header has been parsed.
3029
+ */
3030
+ async validate(t, n, s) {
3031
+ const r = (s == null ? void 0 : s.receivedAt) || /* @__PURE__ */ new Date(), { t: o, kid: i, v1: a } = nr(t), c = (s == null ? void 0 : s.tolerance) ?? rr;
3032
+ sr(r, o, c);
3033
+ const { alg: u, key: l } = await this.keyOfKid(i), f = typeof n == "function" ? await n() : n, p = new TextEncoder().encode(`${o}.${f}`);
3034
+ if (!await er(u, l, tr(a), p))
3035
+ throw new _("Instant Signature did not validate", {
3036
+ header: t
3037
+ });
3038
+ const g = JSON.parse(f);
3039
+ if (typeof g != "object" || typeof g.payloadUrl != "string" || typeof g.token != "string")
3040
+ throw new _("Invalid webhook body, expected an object with payloadUrl and token fields", { body: g });
3041
+ return g;
3042
+ }
3043
+ /**
3044
+ * Pulls the `Instant-Signature` header and body from a `Request` and
3045
+ * delegates to {@link validate}. Throws if the header is missing.
3046
+ */
3047
+ async validateRequest(t, n) {
3048
+ const s = t.headers.get("instant-signature");
3049
+ if (!s)
3050
+ throw new _("Request is missing Instant-Signature header");
3051
+ return this.validate(s, () => t.text(), n);
3052
+ }
3053
+ /**
3054
+ * Fetches the records and `idempotencyKey` for a validated
3055
+ * {@link WebhookBody}, authenticating with the JWT `token` it carries.
3056
+ */
3057
+ fetchPayloads({ payloadUrl: t, token: n }) {
3058
+ return y(this, $e).call(this, t, {
3059
+ headers: { Authorization: `Bearer ${n}`, accept: "application/json" }
3060
+ });
3061
+ }
3062
+ /**
3063
+ * Dispatches each record in `payload` to its matching handler in
3064
+ * `handlers`. Resolution order per record: exact `etype` + `action` →
3065
+ * `etype`'s `$default` → top-level `$default`. Records with no matching
3066
+ * handler are skipped.
3067
+ *
3068
+ * Handlers run concurrently. If any handler rejects, the call rejects so
3069
+ * the caller (e.g. {@link processRequest}) can return a non-2xx response
3070
+ * and let Instant retry the event.
3071
+ */
3072
+ async processPayload(t, n) {
3073
+ var r, o;
3074
+ const s = [];
3075
+ for (const i of n.data) {
3076
+ const { etype: a, action: c } = i, u = ((r = t == null ? void 0 : t[a]) == null ? void 0 : r[c]) || ((o = t == null ? void 0 : t[a]) == null ? void 0 : o.$default) || (t == null ? void 0 : t.$default);
3077
+ u && s.push(u(i));
3078
+ }
3079
+ await Promise.all(s);
3080
+ }
3081
+ /**
3082
+ * The one-liner for handling webhooks. Hand it your handlers and the
3083
+ * incoming `Request` — it verifies the signature, fetches the records, and
3084
+ * dispatches each one to your code.
3085
+ *
3086
+ * Async handlers are executed in parallel, the return promise will resolve once
3087
+ * all handlers complete and will reject if any of the handlers fails.
3088
+ *
3089
+ * @example
3090
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
3091
+ *
3092
+ * const handlers = combineHandlers(
3093
+ * typedHandlers('posts', 'create', async (record) => {
3094
+ * await sendNewPostEmail(record.after);
3095
+ * }),
3096
+ * typedHandlers('$default', (record) => {
3097
+ * console.log('webhook event', record);
3098
+ * }),
3099
+ * );
3100
+ *
3101
+ * export async function POST(req: Request) {
3102
+ * await db.webhooks.processRequest(handlers, req);
3103
+ * return new Response('ok');
3104
+ * }
3105
+ */
3106
+ async processRequest(t, n, s) {
3107
+ const r = await this.validateRequest(n, s), o = await this.fetchPayloads(r);
3108
+ await this.processPayload(t, o);
3109
+ }
3110
+ /**
3111
+ * Adapter for frameworks that hand you a Node-style `http.IncomingMessage`
3112
+ * (Next.js Pages Router, Express, Koa, etc.) instead of a Web `Request`.
3113
+ * Wraps the request in a Web `Request` and delegates to
3114
+ * {@link processRequest}. You still send the HTTP response yourself.
3115
+ *
3116
+ * The raw body is required for signature verification. The adapter picks
3117
+ * it up from one of:
3118
+ *
3119
+ * - `req.body` if it's a `Buffer` or `Uint8Array` (set by middleware like
3120
+ * `express.raw({ type: 'application/json' })`)
3121
+ * - `req.body` if it's a string (set by middleware like `express.text()`)
3122
+ * - otherwise the unconsumed request stream
3123
+ *
3124
+ * Don't use a JSON body parser on this route — `express.json()` and
3125
+ * `bodyParser: true` in Next.js both parse the body into an object,
3126
+ * destroying the raw bytes the signature was computed over.
3127
+ *
3128
+ * @example
3129
+ * // Next.js Pages Router (`pages/api/webhooks.ts`)
3130
+ * import type { NextApiRequest, NextApiResponse } from 'next';
3131
+ *
3132
+ * export const config = { api: { bodyParser: false } };
3133
+ *
3134
+ * const { typedHandlers, combineHandlers } = db.webhooks.helpers();
3135
+ *
3136
+ * const handlers = combineHandlers(
3137
+ * typedHandlers('posts', 'create', async (record) => {
3138
+ * await sendNewPostEmail(record.after);
3139
+ * }),
3140
+ * typedHandlers('$default', (record) => {
3141
+ * console.log('unhandled record', record);
3142
+ * }),
3143
+ * );
3144
+ *
3145
+ * export default async function handler(
3146
+ * req: NextApiRequest,
3147
+ * res: NextApiResponse,
3148
+ * ) {
3149
+ * try {
3150
+ * await db.webhooks.processNodeRequest(handlers, req);
3151
+ * res.status(200).end();
3152
+ * } catch (e) {
3153
+ * res.status(400).json({ error: String(e) });
3154
+ * }
3155
+ * }
3156
+ *
3157
+ * @example
3158
+ * // Express — skip the JSON body parser on the webhook route and use
3159
+ * // `express.raw()` so `req.body` arrives as a Buffer.
3160
+ * import express from 'express';
3161
+ *
3162
+ * const app = express();
3163
+ *
3164
+ * app.use((req, res, next) => {
3165
+ * if (req.originalUrl === '/webhooks/instant') return next();
3166
+ * express.json()(req, res, next);
3167
+ * });
3168
+ *
3169
+ * app.post(
3170
+ * '/webhooks/instant',
3171
+ * express.raw({ type: 'application/json' }),
3172
+ * async (req, res) => {
3173
+ * try {
3174
+ * await db.webhooks.processNodeRequest(handlers, req);
3175
+ * res.status(200).end();
3176
+ * } catch (e) {
3177
+ * res.status(400).json({ error: String(e) });
3178
+ * }
3179
+ * },
3180
+ * );
3181
+ *
3182
+ * @example
3183
+ * // Koa — `ctx.req` is the raw IncomingMessage. If `koa-bodyparser` (or
3184
+ * // similar) runs on this route it consumes the stream, so either skip it
3185
+ * // here or pull the raw body yourself and shim it onto the request:
3186
+ * import Koa from 'koa';
3187
+ * import Router from '@koa/router';
3188
+ * import rawBody from 'raw-body';
3189
+ *
3190
+ * const router = new Router();
3191
+ *
3192
+ * router.post('/webhooks/instant', async (ctx) => {
3193
+ * try {
3194
+ * await db.webhooks.processNodeRequest(handlers, ctx.req, {
3195
+ * body: rawBody(ctx.req), // adapter awaits the Promise
3196
+ * });
3197
+ * ctx.status = 200;
3198
+ * } catch (e) {
3199
+ * ctx.status = 400;
3200
+ * ctx.body = { error: String(e) };
3201
+ * }
3202
+ * });
3203
+ *
3204
+ * @example
3205
+ * // NestJS (Express adapter). With `rawBody: true` on the factory, Nest
3206
+ * // populates `req.rawBody` itself — just pass `req`.
3207
+ * import { Controller, Post, Req, HttpCode } from '@nestjs/common';
3208
+ * import type { Request } from 'express';
3209
+ *
3210
+ * @Controller('webhooks')
3211
+ * export class WebhooksController {
3212
+ * @Post('instant')
3213
+ * @HttpCode(200)
3214
+ * async handle(@Req() req: Request) {
3215
+ * await db.webhooks.processNodeRequest(handlers, req);
3216
+ * }
3217
+ * }
3218
+ *
3219
+ * // (Pair with `NestFactory.create(AppModule, { rawBody: true })` in main.ts.)
3220
+ */
3221
+ async processNodeRequest(t, n, s) {
3222
+ let r, o = !1, i = (s == null ? void 0 : s.body) ?? n.rawBody ?? n.body;
3223
+ if (i != null && typeof i.then == "function" && (i = await i), typeof i == "string")
3224
+ r = i;
3225
+ else if (i instanceof Uint8Array)
3226
+ r = new TextDecoder("utf-8").decode(i);
3227
+ else if (i != null && typeof i == "object")
3228
+ try {
3229
+ r = JSON.stringify(i), o = !0;
3230
+ } catch {
3231
+ throw new _("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.");
3232
+ }
3233
+ else if (n[Symbol.asyncIterator]) {
3234
+ const f = new TextEncoder(), p = [];
3235
+ for await (const h of n)
3236
+ p.push(typeof h == "string" ? f.encode(h) : h);
3237
+ let m = 0;
3238
+ for (const h of p)
3239
+ m += h.byteLength;
3240
+ const g = new Uint8Array(m);
3241
+ let w = 0;
3242
+ for (const h of p)
3243
+ g.set(h, w), w += h.byteLength;
3244
+ r = new TextDecoder("utf-8").decode(g);
3245
+ } else
3246
+ throw new _("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.");
3247
+ const a = typeof n.headers.host == "string" ? n.headers.host : "localhost", c = new URL(n.url ?? "/", `https://${a}`), u = new Headers();
3248
+ for (const [f, p] of Object.entries(n.headers))
3249
+ typeof p == "string" ? u.set(f, p) : Array.isArray(p) && u.set(f, p.join(", "));
3250
+ const l = new Request(c, {
3251
+ method: n.method ?? "POST",
3252
+ headers: u,
3253
+ body: r
3254
+ });
3255
+ try {
3256
+ await this.processRequest(t, l, s);
3257
+ } catch (f) {
3258
+ throw o && f instanceof _ && f.message === "Instant Signature did not validate" ? new _("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: f.hint }) : f;
3259
+ }
3260
+ }
3261
+ };
3262
+ Xe = new WeakMap(), $e = new WeakMap();
3263
+ let Wt = qt;
3264
+ function ur(e) {
2635
3265
  const t = {
2636
3266
  apiURI: "https://api.instantdb.com"
2637
3267
  }, n = { ...t, ...e };
2638
3268
  return n.apiURI || (n.apiURI = t.apiURI), n;
2639
3269
  }
2640
- function Ns(e, t) {
3270
+ function fr(e, t) {
2641
3271
  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;
2642
3272
  }
2643
- function Ds(e, t) {
3273
+ function dr(e, t) {
2644
3274
  if (!(t && ("token" in t || "guest" in t)) && !e.adminToken)
2645
3275
  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`.");
2646
3276
  }
2647
- function T(e, t) {
2648
- Ds(e, t);
2649
- const { adminToken: n, appId: s } = e, i = {
3277
+ function P(e, t) {
3278
+ dr(e, t);
3279
+ const { adminToken: n, appId: s } = e, r = {
2650
3280
  "content-type": "application/json",
2651
3281
  "app-id": s
2652
3282
  };
2653
- return n && (i.authorization = `Bearer ${n}`), t ? Ns(i, t) : i;
3283
+ return n && (r.authorization = `Bearer ${n}`), t ? fr(r, t) : r;
2654
3284
  }
2655
- function Ls() {
3285
+ function lr() {
2656
3286
  return (
2657
3287
  // NextJS 13 onwards added a `__nextPatched` property to the fetch function
2658
3288
  fetch.__nextPatched && // NextJS 15 onwards _also_ added a global `next-patch` symbol.
2659
3289
  !globalThis[Symbol.for("next-patch")]
2660
3290
  );
2661
3291
  }
2662
- function Ws() {
2663
- return Ls() ? { cache: "no-store" } : {};
3292
+ function hr() {
3293
+ return lr() ? { cache: "no-store" } : {};
2664
3294
  }
2665
- async function Fs(e, t) {
3295
+ async function pr(e, t) {
2666
3296
  const n = await t.text();
2667
3297
  try {
2668
3298
  const s = JSON.parse(n);
2669
- return e(new ve({ status: t.status, body: s }));
3299
+ return e(new le({ status: t.status, body: s }));
2670
3300
  } catch {
2671
- return e(new ve({
3301
+ return e(new le({
2672
3302
  status: t.status,
2673
3303
  body: { type: void 0, message: n }
2674
3304
  }));
2675
3305
  }
2676
3306
  }
2677
3307
  async function A(e, t) {
2678
- const n = Ws(), s = {
3308
+ const n = hr(), s = {
2679
3309
  ...(t == null ? void 0 : t.headers) || {},
2680
- "Instant-Admin-Version": Me,
2681
- "Instant-Core-Version": Me
2682
- }, i = await fetch(e, { ...n, ...t, headers: s });
2683
- if (i.status === 200) {
2684
- const r = await i.json();
2685
- return Promise.resolve(r);
2686
- }
2687
- return Fs((r) => Promise.reject(r), i);
3310
+ "Instant-Admin-Version": _e,
3311
+ "Instant-Core-Version": _e
3312
+ }, r = await fetch(e, { ...n, ...t, headers: s });
3313
+ if (r.status === 200) {
3314
+ const o = await r.json();
3315
+ return Promise.resolve(o);
3316
+ }
3317
+ return pr((o) => Promise.reject(o), r);
2688
3318
  }
2689
- function zs(e) {
2690
- var t, n, On;
3319
+ function yr(e) {
3320
+ var t, n, Wn;
2691
3321
  return t = class {
2692
- constructor(r) {
2693
- K(this, n);
2694
- f(this, "source");
2695
- f(this, "url");
2696
- this.url = r, this.source = X(this, n, On).call(this, r);
3322
+ constructor(o) {
3323
+ j(this, n);
3324
+ d(this, "source");
3325
+ d(this, "url");
3326
+ this.url = o, this.source = R(this, n, Wn).call(this, o);
2697
3327
  }
2698
3328
  get onopen() {
2699
3329
  return this.source.onopen;
2700
3330
  }
2701
- set onopen(r) {
2702
- this.source.onopen = r;
3331
+ set onopen(o) {
3332
+ this.source.onopen = o;
2703
3333
  }
2704
3334
  get onmessage() {
2705
3335
  return this.source.onmessage;
2706
3336
  }
2707
- set onmessage(r) {
2708
- this.source.onmessage = r;
3337
+ set onmessage(o) {
3338
+ this.source.onmessage = o;
2709
3339
  }
2710
3340
  get onerror() {
2711
3341
  return this.source.onerror;
2712
3342
  }
2713
- set onerror(r) {
2714
- this.source.onerror = r;
3343
+ set onerror(o) {
3344
+ this.source.onerror = o;
2715
3345
  }
2716
3346
  get readyState() {
2717
3347
  return this.source.readyState;
@@ -2719,9 +3349,9 @@ function zs(e) {
2719
3349
  close() {
2720
3350
  this.source.close();
2721
3351
  }
2722
- }, n = new WeakSet(), On = function(r) {
2723
- return new ne(r, {
2724
- messageEvent: wn,
3352
+ }, n = new WeakSet(), Wn = function(o) {
3353
+ return new oe(o, {
3354
+ messageEvent: Pn,
2725
3355
  fetch(a, c) {
2726
3356
  return fetch(a, {
2727
3357
  ...c,
@@ -2730,44 +3360,44 @@ function zs(e) {
2730
3360
  body: JSON.stringify({
2731
3361
  "inference?": e.inference,
2732
3362
  versions: {
2733
- "@instantdb/admin": Me,
2734
- "@instantdb/core": Me
3363
+ "@instantdb/admin": _e,
3364
+ "@instantdb/core": _e
2735
3365
  }
2736
3366
  })
2737
3367
  });
2738
3368
  }
2739
3369
  });
2740
- }, f(t, "OPEN", ne.OPEN), f(t, "CONNECTING", ne.CONNECTING), f(t, "CLOSED", ne.CLOSED), t;
3370
+ }, d(t, "OPEN", oe.OPEN), d(t, "CONNECTING", oe.CONNECTING), d(t, "CLOSED", oe.CLOSED), t;
2741
3371
  }
2742
- function Vs(e) {
3372
+ function mr(e) {
2743
3373
  var n, s;
2744
- (!e.appId || !Ae(e.appId)) && console.warn("warning: Instant Admin DB must be initialized with a valid appId. Received: " + JSON.stringify(e.appId));
3374
+ (!e.appId || !Fe(e.appId)) && console.warn("warning: Instant Admin DB must be initialized with a valid appId. Received: " + JSON.stringify(e.appId));
2745
3375
  const t = {
2746
3376
  ...e,
2747
3377
  appId: (n = e.appId) == null ? void 0 : n.trim(),
2748
3378
  adminToken: (s = e.adminToken) == null ? void 0 : s.trim(),
2749
3379
  useDateObjects: e.useDateObjects ?? !1
2750
3380
  };
2751
- return new Ct(t);
3381
+ return new Lt(t);
2752
3382
  }
2753
- function Zt(e) {
2754
- return (Array.isArray(e) ? e : [e]).flatMap(ts);
3383
+ function pn(e) {
3384
+ return (Array.isArray(e) ? e : [e]).flatMap(ms);
2755
3385
  }
2756
- class Js {
3386
+ class br {
2757
3387
  constructor(t) {
2758
- f(this, "config");
3388
+ d(this, "config");
2759
3389
  this.config = t;
2760
3390
  }
2761
3391
  async getPresence(t, n) {
2762
3392
  return (await A(`${this.config.apiURI}/admin/rooms/presence?app_id=${this.config.appId}&room-type=${String(t)}&room-id=${n}`, {
2763
3393
  method: "GET",
2764
- headers: T(this.config)
3394
+ headers: P(this.config)
2765
3395
  })).sessions || {};
2766
3396
  }
2767
3397
  }
2768
- class Qs {
3398
+ class wr {
2769
3399
  constructor(t) {
2770
- f(this, "config");
3400
+ d(this, "config");
2771
3401
  /**
2772
3402
  * Generates a magic code for the user with the given email.
2773
3403
  * This is useful if you want to use your own email provider
@@ -2781,9 +3411,9 @@ class Qs {
2781
3411
  *
2782
3412
  * @see https://instantdb.com/docs/backend#custom-magic-codes
2783
3413
  */
2784
- f(this, "generateMagicCode", async (t) => A(`${this.config.apiURI}/admin/magic_code?app_id=${this.config.appId}`, {
3414
+ d(this, "generateMagicCode", async (t) => A(`${this.config.apiURI}/admin/magic_code?app_id=${this.config.appId}`, {
2785
3415
  method: "POST",
2786
- headers: T(this.config),
3416
+ headers: P(this.config),
2787
3417
  body: JSON.stringify({ email: t })
2788
3418
  }));
2789
3419
  /**
@@ -2796,9 +3426,9 @@ class Qs {
2796
3426
  *
2797
3427
  * @see https://instantdb.com/docs/backend#custom-magic-codes
2798
3428
  */
2799
- f(this, "sendMagicCode", async (t) => A(`${this.config.apiURI}/admin/send_magic_code?app_id=${this.config.appId}`, {
3429
+ d(this, "sendMagicCode", async (t) => A(`${this.config.apiURI}/admin/send_magic_code?app_id=${this.config.appId}`, {
2800
3430
  method: "POST",
2801
- headers: T(this.config),
3431
+ headers: P(this.config),
2802
3432
  body: JSON.stringify({ email: t })
2803
3433
  }));
2804
3434
  /**
@@ -2807,10 +3437,10 @@ class Qs {
2807
3437
  *
2808
3438
  * @see https://instantdb.com/docs/backend#custom-magic-codes
2809
3439
  */
2810
- f(this, "verifyMagicCode", async (t, n) => {
3440
+ d(this, "verifyMagicCode", async (t, n) => {
2811
3441
  const { user: s } = await A(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
2812
3442
  method: "POST",
2813
- headers: T(this.config),
3443
+ headers: P(this.config),
2814
3444
  body: JSON.stringify({ email: t, code: n })
2815
3445
  });
2816
3446
  return s;
@@ -2829,17 +3459,17 @@ class Qs {
2829
3459
  *
2830
3460
  * @see https://instantdb.com/docs/backend#custom-magic-codes
2831
3461
  */
2832
- f(this, "checkMagicCode", async (t, n, s) => {
2833
- const i = await A(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
3462
+ d(this, "checkMagicCode", async (t, n, s) => {
3463
+ const r = await A(`${this.config.apiURI}/admin/verify_magic_code?app_id=${this.config.appId}`, {
2834
3464
  method: "POST",
2835
- headers: T(this.config),
3465
+ headers: P(this.config),
2836
3466
  body: JSON.stringify({
2837
3467
  email: t,
2838
3468
  code: n,
2839
3469
  ...s != null && s.extraFields ? { "extra-fields": s.extraFields } : {}
2840
3470
  })
2841
3471
  });
2842
- return { user: i.user, created: i.created };
3472
+ return { user: r.user, created: r.created };
2843
3473
  });
2844
3474
  /**
2845
3475
  * Verifies a given token and returns the associated user.
@@ -2857,7 +3487,7 @@ class Qs {
2857
3487
  * })
2858
3488
  * @see https://instantdb.com/docs/backend#custom-endpoints
2859
3489
  */
2860
- f(this, "verifyToken", async (t) => (await A(`${this.config.apiURI}/runtime/auth/verify_refresh_token?app_id=${this.config.appId}`, {
3490
+ d(this, "verifyToken", async (t) => (await A(`${this.config.apiURI}/runtime/auth/verify_refresh_token?app_id=${this.config.appId}`, {
2861
3491
  method: "POST",
2862
3492
  headers: { "content-type": "application/json" },
2863
3493
  body: JSON.stringify({
@@ -2878,11 +3508,11 @@ class Qs {
2878
3508
  *
2879
3509
  * @see https://instantdb.com/docs/backend#retrieve-a-user
2880
3510
  */
2881
- f(this, "getUser", async (t) => {
2882
- const n = Object.entries(t).map(([i, r]) => `${i}=${encodeURIComponent(r)}`).join("&");
3511
+ d(this, "getUser", async (t) => {
3512
+ const n = Object.entries(t).map(([r, o]) => `${r}=${encodeURIComponent(o)}`).join("&");
2883
3513
  return (await A(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
2884
3514
  method: "GET",
2885
- headers: T(this.config)
3515
+ headers: P(this.config)
2886
3516
  })).user;
2887
3517
  });
2888
3518
  /**
@@ -2901,11 +3531,11 @@ class Qs {
2901
3531
  *
2902
3532
  * @see https://instantdb.com/docs/backend#delete-a-user
2903
3533
  */
2904
- f(this, "deleteUser", async (t) => {
2905
- const n = Object.entries(t).map(([i, r]) => `${i}=${r}`);
3534
+ d(this, "deleteUser", async (t) => {
3535
+ const n = Object.entries(t).map(([r, o]) => `${r}=${o}`);
2906
3536
  return (await A(`${this.config.apiURI}/admin/users?app_id=${this.config.appId}&${n}`, {
2907
3537
  method: "DELETE",
2908
- headers: T(this.config)
3538
+ headers: P(this.config)
2909
3539
  })).deleted;
2910
3540
  });
2911
3541
  /**
@@ -2915,11 +3545,11 @@ class Qs {
2915
3545
  * @param req The request containing a cookie synced with createInstantRouteHandler
2916
3546
  * @param opts Allow disabling validation of refresh token
2917
3547
  */
2918
- f(this, "getUserFromRequest", async (t, n) => {
2919
- const s = t.headers.get("cookie") || "", i = _s(s), r = "instant_user_" + this.config.appId;
2920
- if (!i[r])
3548
+ d(this, "getUserFromRequest", async (t, n) => {
3549
+ const s = t.headers.get("cookie") || "", r = zs(s), o = "instant_user_" + this.config.appId;
3550
+ if (!r[o])
2921
3551
  return null;
2922
- const o = i[r], a = JSON.parse(o);
3552
+ const i = r[o], a = JSON.parse(i);
2923
3553
  return a != null && a.refresh_token ? n != null && n.disableValidation ? a : await this.verifyToken(a.refresh_token) : null;
2924
3554
  });
2925
3555
  this.config = t, this.createToken = this.createToken.bind(this);
@@ -2928,7 +3558,7 @@ class Qs {
2928
3558
  const n = typeof t == "string" ? { email: t } : t;
2929
3559
  return (await A(`${this.config.apiURI}/admin/refresh_tokens?app_id=${this.config.appId}`, {
2930
3560
  method: "POST",
2931
- headers: T(this.config),
3561
+ headers: P(this.config),
2932
3562
  body: JSON.stringify(n)
2933
3563
  })).user.refresh_token;
2934
3564
  }
@@ -2936,16 +3566,16 @@ class Qs {
2936
3566
  const n = typeof t == "string" ? { email: t } : t, s = this.config;
2937
3567
  await A(`${s.apiURI}/admin/sign_out?app_id=${this.config.appId}`, {
2938
3568
  method: "POST",
2939
- headers: T(s),
3569
+ headers: P(s),
2940
3570
  body: JSON.stringify(n)
2941
3571
  });
2942
3572
  }
2943
3573
  }
2944
- const en = (e) => e && typeof e == "object" && typeof e.pipe == "function" && typeof e.read == "function", Gs = (e) => e && typeof e.getReader == "function";
2945
- class tn {
3574
+ const yn = (e) => e && typeof e == "object" && typeof e.pipe == "function" && typeof e.read == "function", gr = (e) => e && typeof e.getReader == "function";
3575
+ class mn {
2946
3576
  constructor(t, n) {
2947
- f(this, "config");
2948
- f(this, "impersonationOpts");
3577
+ d(this, "config");
3578
+ d(this, "impersonationOpts");
2949
3579
  /**
2950
3580
  * Uploads file at the provided path. Accepts a Buffer or a Readable stream.
2951
3581
  *
@@ -2954,25 +3584,25 @@ class tn {
2954
3584
  * const buffer = fs.readFileSync('demo.png');
2955
3585
  * const isSuccess = await db.storage.uploadFile('photos/demo.png', buffer);
2956
3586
  */
2957
- f(this, "uploadFile", async (t, n, s = {}) => {
2958
- const i = {
2959
- ...T(this.config, this.impersonationOpts),
3587
+ d(this, "uploadFile", async (t, n, s = {}) => {
3588
+ const r = {
3589
+ ...P(this.config, this.impersonationOpts),
2960
3590
  path: t
2961
3591
  };
2962
- s.contentDisposition && (i["content-disposition"] = s.contentDisposition), delete i["content-type"], s.contentType && (i["content-type"] = s.contentType);
2963
- let r;
2964
- if (en(n) && (r = "half"), en(n) || Gs(n)) {
3592
+ s.contentDisposition && (r["content-disposition"] = s.contentDisposition), delete r["content-type"], s.contentType && (r["content-type"] = s.contentType);
3593
+ let o;
3594
+ if (yn(n) && (o = "half"), yn(n) || gr(n)) {
2965
3595
  if (!s.fileSize)
2966
3596
  throw new Error("fileSize is required in metadata when uploading streams");
2967
- i["content-length"] = s.fileSize.toString();
3597
+ r["content-length"] = s.fileSize.toString();
2968
3598
  }
2969
- let o = {
3599
+ let i = {
2970
3600
  method: "PUT",
2971
- headers: i,
3601
+ headers: r,
2972
3602
  body: n,
2973
- ...r && { duplex: r }
3603
+ ...o && { duplex: o }
2974
3604
  };
2975
- return A(`${this.config.apiURI}/admin/storage/upload?app_id=${this.config.appId}`, o);
3605
+ return A(`${this.config.apiURI}/admin/storage/upload?app_id=${this.config.appId}`, i);
2976
3606
  });
2977
3607
  /**
2978
3608
  * Deletes a file by its path name (e.g. "photos/demo.png").
@@ -2987,9 +3617,9 @@ class tn {
2987
3617
  *
2988
3618
  * @see https://instantdb.com/docs/storage
2989
3619
  */
2990
- f(this, "delete", async (t) => A(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
3620
+ d(this, "delete", async (t) => A(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
2991
3621
  method: "DELETE",
2992
- headers: T(this.config, this.impersonationOpts)
3622
+ headers: P(this.config, this.impersonationOpts)
2993
3623
  }));
2994
3624
  /**
2995
3625
  * Deletes multiple files by their path names.
@@ -3002,29 +3632,29 @@ class tn {
3002
3632
  *
3003
3633
  * @see https://instantdb.com/docs/storage
3004
3634
  */
3005
- f(this, "deleteMany", async (t) => A(`${this.config.apiURI}/admin/storage/files/delete?app_id=${this.config.appId}`, {
3635
+ d(this, "deleteMany", async (t) => A(`${this.config.apiURI}/admin/storage/files/delete?app_id=${this.config.appId}`, {
3006
3636
  method: "POST",
3007
- headers: T(this.config, this.impersonationOpts),
3637
+ headers: P(this.config, this.impersonationOpts),
3008
3638
  body: JSON.stringify({ filenames: t })
3009
3639
  }));
3010
3640
  /**
3011
3641
  * @deprecated. This method will be removed in the future. Use `uploadFile`
3012
3642
  * instead
3013
3643
  */
3014
- f(this, "upload", async (t, n, s = {}) => {
3015
- const { data: i } = await A(`${this.config.apiURI}/admin/storage/signed-upload-url?app_id=${this.config.appId}`, {
3644
+ d(this, "upload", async (t, n, s = {}) => {
3645
+ const { data: r } = await A(`${this.config.apiURI}/admin/storage/signed-upload-url?app_id=${this.config.appId}`, {
3016
3646
  method: "POST",
3017
- headers: T(this.config),
3647
+ headers: P(this.config),
3018
3648
  body: JSON.stringify({
3019
3649
  app_id: this.config.appId,
3020
3650
  filename: t
3021
3651
  })
3022
- }), r = {}, o = s.contentType;
3023
- o && (r["Content-Type"] = o);
3024
- const { ok: a } = await fetch(i, {
3652
+ }), o = {}, i = s.contentType;
3653
+ i && (o["Content-Type"] = i);
3654
+ const { ok: a } = await fetch(r, {
3025
3655
  method: "PUT",
3026
3656
  body: n,
3027
- headers: r
3657
+ headers: o
3028
3658
  });
3029
3659
  return a;
3030
3660
  });
@@ -3033,10 +3663,10 @@ class tn {
3033
3663
  * @example
3034
3664
  * const files = await db.query({ $files: {}})
3035
3665
  */
3036
- f(this, "list", async () => {
3666
+ d(this, "list", async () => {
3037
3667
  const { data: t } = await A(`${this.config.apiURI}/admin/storage/files?app_id=${this.config.appId}`, {
3038
3668
  method: "GET",
3039
- headers: T(this.config)
3669
+ headers: P(this.config)
3040
3670
  });
3041
3671
  return t;
3042
3672
  });
@@ -3054,20 +3684,20 @@ class tn {
3054
3684
  * }
3055
3685
  * })
3056
3686
  */
3057
- f(this, "getDownloadUrl", async (t) => {
3687
+ d(this, "getDownloadUrl", async (t) => {
3058
3688
  const { data: n } = await A(`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(t)}`, {
3059
3689
  method: "GET",
3060
- headers: T(this.config)
3690
+ headers: P(this.config)
3061
3691
  });
3062
3692
  return n;
3063
3693
  });
3064
3694
  this.config = t, this.impersonationOpts = n;
3065
3695
  }
3066
3696
  }
3067
- var Pe;
3068
- class Hs {
3697
+ var Le;
3698
+ class Sr {
3069
3699
  constructor(t) {
3070
- K(this, Pe);
3700
+ j(this, Le);
3071
3701
  /**
3072
3702
  * Creates a new ReadableStream for the given clientId.
3073
3703
  *
@@ -3077,7 +3707,7 @@ class Hs {
3077
3707
  * console.log(chunk);
3078
3708
  * }
3079
3709
  */
3080
- f(this, "createReadStream", (t) => g(this, Pe).call(this).createReadStream(t));
3710
+ d(this, "createReadStream", (t) => y(this, Le).call(this).createReadStream(t));
3081
3711
  /**
3082
3712
  * Creates a new WritableStream for the given clientId.
3083
3713
  *
@@ -3087,12 +3717,12 @@ class Hs {
3087
3717
  * writer.write('Hello world');
3088
3718
  * writer.close();
3089
3719
  */
3090
- f(this, "createWriteStream", (t) => g(this, Pe).call(this).createWriteStream(t));
3091
- oe(this, Pe, t);
3720
+ d(this, "createWriteStream", (t) => y(this, Le).call(this).createWriteStream(t));
3721
+ J(this, Le, t);
3092
3722
  }
3093
3723
  }
3094
- Pe = new WeakMap();
3095
- function Bs(e) {
3724
+ Le = new WeakMap();
3725
+ function Ir(e) {
3096
3726
  return {
3097
3727
  info: e ? (...t) => console.info(...t) : () => {
3098
3728
  },
@@ -3102,21 +3732,22 @@ function Bs(e) {
3102
3732
  }
3103
3733
  };
3104
3734
  }
3105
- var F, Se, z, V, U, $n, Xe, kn, _n, Cn, tt, nt, st, xt, xn, it;
3106
- const jt = class jt {
3735
+ var H, Oe, q, B, W, Ln, at, Fn, zn, Vn, dt, lt, ht, Ft, Jn, pt;
3736
+ const Bt = class Bt {
3107
3737
  constructor(t) {
3108
- K(this, U);
3109
- f(this, "config");
3110
- f(this, "auth");
3111
- f(this, "storage");
3112
- f(this, "streams");
3113
- f(this, "rooms");
3114
- f(this, "impersonationOpts");
3115
- K(this, F, null);
3116
- K(this, Se, 0);
3117
- K(this, z, null);
3118
- K(this, V);
3119
- f(this, "tx", dn());
3738
+ j(this, W);
3739
+ d(this, "config");
3740
+ d(this, "auth");
3741
+ d(this, "storage");
3742
+ d(this, "streams");
3743
+ d(this, "rooms");
3744
+ d(this, "impersonationOpts");
3745
+ d(this, "webhooks");
3746
+ j(this, H, null);
3747
+ j(this, Oe, 0);
3748
+ j(this, q, null);
3749
+ j(this, B);
3750
+ d(this, "tx", En());
3120
3751
  /**
3121
3752
  * Sometimes you want to scope queries to a specific user.
3122
3753
  *
@@ -3126,11 +3757,11 @@ const jt = class jt {
3126
3757
  * @example
3127
3758
  * await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
3128
3759
  */
3129
- f(this, "asUser", (t) => {
3130
- const n = new jt({
3760
+ d(this, "asUser", (t) => {
3761
+ const n = new Bt({
3131
3762
  ...this.config
3132
3763
  });
3133
- return n.impersonationOpts = t, n.storage = new tn(this.config, t), n;
3764
+ return n.impersonationOpts = t, n.storage = new mn(this.config, t), n;
3134
3765
  });
3135
3766
  /**
3136
3767
  * Use this to query your data!
@@ -3147,15 +3778,15 @@ const jt = class jt {
3147
3778
  * // all goals, _alongside_ their todos
3148
3779
  * await db.query({ goals: { todos: {} } })
3149
3780
  */
3150
- f(this, "query", (t, n = {}) => {
3151
- t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t }), this.config.disableValidation || Jt(t, this.config.schema);
3152
- const s = n.fetchOpts || {}, i = s.headers || {};
3781
+ d(this, "query", (t, n = {}) => {
3782
+ t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t }), this.config.disableValidation || sn(t, this.config.schema);
3783
+ const s = n.fetchOpts || {}, r = s.headers || {};
3153
3784
  return A(`${this.config.apiURI}/admin/query?app_id=${this.config.appId}`, {
3154
3785
  ...s,
3155
3786
  method: "POST",
3156
3787
  headers: {
3157
- ...i,
3158
- ...T(this.config, this.impersonationOpts)
3788
+ ...r,
3789
+ ...P(this.config, this.impersonationOpts)
3159
3790
  },
3160
3791
  body: JSON.stringify({
3161
3792
  query: t,
@@ -3186,11 +3817,11 @@ const jt = class jt {
3186
3817
  * db.tx.goals[goalId].link({todos: todoId}),
3187
3818
  * ])
3188
3819
  */
3189
- f(this, "transact", (t) => (this.config.disableValidation || fs(t, this.config.schema), A(`${this.config.apiURI}/admin/transact?app_id=${this.config.appId}`, {
3820
+ d(this, "transact", (t) => (this.config.disableValidation || Os(t, this.config.schema), A(`${this.config.apiURI}/admin/transact?app_id=${this.config.appId}`, {
3190
3821
  method: "POST",
3191
- headers: T(this.config, this.impersonationOpts),
3822
+ headers: P(this.config, this.impersonationOpts),
3192
3823
  body: JSON.stringify({
3193
- steps: Zt(t),
3824
+ steps: pn(t),
3194
3825
  "throw-on-missing-attrs?": !!this.config.schema
3195
3826
  })
3196
3827
  })));
@@ -3215,7 +3846,7 @@ const jt = class jt {
3215
3846
  * { rules: { goals: { allow: { read: "auth.id != null" } } }
3216
3847
  * )
3217
3848
  */
3218
- f(this, "debugQuery", async (t, n) => {
3849
+ d(this, "debugQuery", async (t, n) => {
3219
3850
  t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t });
3220
3851
  const s = {
3221
3852
  query: t,
@@ -3223,14 +3854,14 @@ const jt = class jt {
3223
3854
  "inference?": (n == null ? void 0 : n.cardinalityInference) ?? !!this.config.schema
3224
3855
  };
3225
3856
  n != null && n.ip && (s["ip-override"] = n.ip), n != null && n.origin && (s["origin-override"] = n.origin);
3226
- const i = await A(`${this.config.apiURI}/admin/query_perms_check?app_id=${this.config.appId}`, {
3857
+ const r = await A(`${this.config.apiURI}/admin/query_perms_check?app_id=${this.config.appId}`, {
3227
3858
  method: "POST",
3228
- headers: T(this.config, this.impersonationOpts),
3859
+ headers: P(this.config, this.impersonationOpts),
3229
3860
  body: JSON.stringify(s)
3230
3861
  });
3231
3862
  return {
3232
- result: i.result,
3233
- checkResults: i["check-results"]
3863
+ result: r.result,
3864
+ checkResults: r["check-results"]
3234
3865
  };
3235
3866
  });
3236
3867
  /**
@@ -3251,65 +3882,65 @@ const jt = class jt {
3251
3882
  * { rules: { goals: { allow: { update: "auth.id != null" } } }
3252
3883
  * )
3253
3884
  */
3254
- f(this, "debugTransact", (t, n) => {
3885
+ d(this, "debugTransact", (t, n) => {
3255
3886
  const s = {
3256
- steps: Zt(t),
3887
+ steps: pn(t),
3257
3888
  "rules-override": n == null ? void 0 : n.rules,
3258
3889
  // @ts-expect-error because we're using a private API (for now)
3259
3890
  "dangerously-commit-tx": n == null ? void 0 : n.__dangerouslyCommit
3260
3891
  };
3261
3892
  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}`, {
3262
3893
  method: "POST",
3263
- headers: T(this.config, this.impersonationOpts),
3894
+ headers: P(this.config, this.impersonationOpts),
3264
3895
  body: JSON.stringify(s)
3265
3896
  });
3266
3897
  });
3267
- K(this, tt, (t) => {
3898
+ j(this, dt, (t) => {
3268
3899
  var n;
3269
- if (t.target !== g(this, F)) {
3270
- g(this, V).info("[socket][open]", t.target.id, "skip; this is no longer the current transport");
3900
+ if (t.target !== y(this, H)) {
3901
+ y(this, B).info("[socket][open]", t.target.id, "skip; this is no longer the current transport");
3271
3902
  return;
3272
3903
  }
3273
- g(this, V).info("[socket][open]", t.target.id), oe(this, Se, 0), (n = g(this, z)) == null || n.onConnectionStatusChange("authenticated");
3904
+ y(this, B).info("[socket][open]", t.target.id), J(this, Oe, 0), (n = y(this, q)) == null || n.onConnectionStatusChange("authenticated");
3274
3905
  });
3275
- K(this, nt, (t) => {
3906
+ j(this, lt, (t) => {
3276
3907
  var n;
3277
- if (t.target !== g(this, F)) {
3278
- g(this, V).info("[socket][close]", t.target.id, "skip; this is no longer the current transport");
3908
+ if (t.target !== y(this, H)) {
3909
+ y(this, B).info("[socket][close]", t.target.id, "skip; this is no longer the current transport");
3279
3910
  return;
3280
3911
  }
3281
- g(this, V).info("[socket][close]", t.target.id), (n = g(this, z)) == null || n.onConnectionStatusChange("closed"), g(this, F) && (oe(this, F, null), X(this, U, xt).call(this) || (setTimeout(() => X(this, U, Xe).call(this), g(this, Se)), oe(this, Se, Math.min(15e3, Math.max(g(this, Se), 500) * 2))));
3912
+ y(this, B).info("[socket][close]", t.target.id), (n = y(this, q)) == null || n.onConnectionStatusChange("closed"), y(this, H) && (J(this, H, null), R(this, W, Ft).call(this) || (setTimeout(() => R(this, W, at).call(this), y(this, Oe)), J(this, Oe, Math.min(15e3, Math.max(y(this, Oe), 500) * 2))));
3282
3913
  });
3283
- K(this, st, (t) => {
3914
+ j(this, ht, (t) => {
3284
3915
  var n;
3285
- if (t.target !== g(this, F)) {
3286
- g(this, V).info("[socket][error]", t.target.id, "skip; this is no longer the current transport");
3916
+ if (t.target !== y(this, H)) {
3917
+ y(this, B).info("[socket][error]", t.target.id, "skip; this is no longer the current transport");
3287
3918
  return;
3288
3919
  }
3289
- g(this, V).info("[socket][error]", t.target.id), (n = g(this, z)) == null || n.onConnectionStatusChange("closed");
3920
+ y(this, B).info("[socket][error]", t.target.id), (n = y(this, q)) == null || n.onConnectionStatusChange("closed");
3290
3921
  });
3291
- K(this, it, (t) => {
3292
- var s, i, r, o, a, c;
3293
- if (t.target !== g(this, F)) {
3294
- g(this, V).info("[socket][message]", t.target.id, "skip; this is no longer the current transport");
3922
+ j(this, pt, (t) => {
3923
+ var s, r, o, i, a, c;
3924
+ if (t.target !== y(this, H)) {
3925
+ y(this, B).info("[socket][message]", t.target.id, "skip; this is no longer the current transport");
3295
3926
  return;
3296
3927
  }
3297
3928
  const n = t.message;
3298
- switch (g(this, V).info("[receive]", n), n.op) {
3929
+ switch (y(this, B).info("[receive]", n), n.op) {
3299
3930
  case "start-stream-ok": {
3300
- (s = g(this, z)) == null || s.onStartStreamOk(n);
3931
+ (s = y(this, q)) == null || s.onStartStreamOk(n);
3301
3932
  break;
3302
3933
  }
3303
3934
  case "stream-flushed": {
3304
- (i = g(this, z)) == null || i.onStreamFlushed(n);
3935
+ (r = y(this, q)) == null || r.onStreamFlushed(n);
3305
3936
  break;
3306
3937
  }
3307
3938
  case "append-failed": {
3308
- (r = g(this, z)) == null || r.onAppendFailed(n);
3939
+ (o = y(this, q)) == null || o.onAppendFailed(n);
3309
3940
  break;
3310
3941
  }
3311
3942
  case "stream-append": {
3312
- (o = g(this, z)) == null || o.onStreamAppend(n);
3943
+ (i = y(this, q)) == null || i.onStreamAppend(n);
3313
3944
  break;
3314
3945
  }
3315
3946
  case "error": {
@@ -3318,16 +3949,16 @@ const jt = class jt {
3318
3949
  case "append-stream":
3319
3950
  case "subscribe-stream":
3320
3951
  case "unsubscribe-stream": {
3321
- (c = g(this, z)) == null || c.onRecieveError(n);
3952
+ (c = y(this, q)) == null || c.onRecieveError(n);
3322
3953
  break;
3323
3954
  }
3324
3955
  }
3325
3956
  break;
3326
3957
  }
3327
3958
  }
3328
- X(this, U, xn).call(this);
3959
+ R(this, W, Jn).call(this);
3329
3960
  });
3330
- this.config = Us(t), this.auth = new Qs(this.config), this.storage = new tn(this.config, this.impersonationOpts), this.streams = new Hs(X(this, U, Cn).bind(this)), this.rooms = new Js(this.config), oe(this, V, Bs(!!this.config.verbose));
3961
+ this.config = ur(t), this.auth = new wr(this.config), this.storage = new mn(this.config, this.impersonationOpts), this.streams = new Sr(R(this, W, Vn).bind(this)), this.rooms = new br(this.config), this.webhooks = new Wt(this.config, A), J(this, B, Ir(!!this.config.verbose));
3331
3962
  }
3332
3963
  /**
3333
3964
  * Use this to to get a live view of your data!
@@ -3365,55 +3996,55 @@ const jt = class jt {
3365
3996
  * });
3366
3997
  */
3367
3998
  subscribeQuery(t, n, s = {}) {
3368
- t && s && "ruleParams" in s && (t = { $$ruleParams: s.ruleParams, ...t }), this.config.disableValidation || Jt(t, this.config.schema);
3369
- const o = {
3999
+ t && s && "ruleParams" in s && (t = { $$ruleParams: s.ruleParams, ...t }), this.config.disableValidation || sn(t, this.config.schema);
4000
+ const i = {
3370
4001
  ...(s.fetchOpts || {}).headers || {},
3371
- ...T(this.config, this.impersonationOpts)
4002
+ ...P(this.config, this.impersonationOpts)
3372
4003
  }, a = !!this.config.schema;
3373
- return ks(t, n, {
3374
- headers: o,
4004
+ return Fs(t, n, {
4005
+ headers: i,
3375
4006
  inference: a,
3376
4007
  apiURI: this.config.apiURI
3377
4008
  });
3378
4009
  }
3379
4010
  };
3380
- F = new WeakMap(), Se = new WeakMap(), z = new WeakMap(), V = new WeakMap(), U = new WeakSet(), $n = function() {
3381
- g(this, F) && g(this, F).close();
4011
+ H = new WeakMap(), Oe = new WeakMap(), q = new WeakMap(), B = new WeakMap(), W = new WeakSet(), Ln = function() {
4012
+ y(this, H) && y(this, H).close();
3382
4013
  const t = {
3383
- ...T(this.config, this.impersonationOpts)
3384
- }, n = !!this.config.schema, s = zs({ headers: t, inference: n }), i = new ds(s, `${this.config.apiURI}/admin/sse?app_id=${this.config.appId}`, `${this.config.apiURI}/admin/sse/push?app_id=${this.config.appId}`);
3385
- return i.onopen = g(this, tt), i.onmessage = g(this, it), i.onclose = g(this, nt), i.onerror = g(this, st), oe(this, F, i), i;
3386
- }, Xe = function() {
3387
- return g(this, F) || X(this, U, $n).call(this);
3388
- }, kn = function(t, n) {
3389
- const s = X(this, U, Xe).call(this);
3390
- g(this, V).info("[send]", t, n, {
4014
+ ...P(this.config, this.impersonationOpts)
4015
+ }, n = !!this.config.schema, s = yr({ headers: t, inference: n }), r = new _s(s, `${this.config.apiURI}/admin/sse?app_id=${this.config.appId}`, `${this.config.apiURI}/admin/sse/push?app_id=${this.config.appId}`);
4016
+ return r.onopen = y(this, dt), r.onmessage = y(this, pt), r.onclose = y(this, lt), r.onerror = y(this, ht), J(this, H, r), r;
4017
+ }, at = function() {
4018
+ return y(this, H) || R(this, W, Ln).call(this);
4019
+ }, Fn = function(t, n) {
4020
+ const s = R(this, W, at).call(this);
4021
+ y(this, B).info("[send]", t, n, {
3391
4022
  isOpen: s.isOpen()
3392
4023
  }), s.isOpen() && s.send({ "client-event-id": t, ...n });
3393
- }, _n = function() {
3394
- X(this, U, Xe).call(this);
3395
- const t = new ys({
4024
+ }, zn = function() {
4025
+ R(this, W, at).call(this);
4026
+ const t = new Rs({
3396
4027
  WStream: this.config.WritableStream || WritableStream,
3397
4028
  RStream: this.config.ReadableStream || ReadableStream,
3398
4029
  trySend: (n, s) => {
3399
- X(this, U, kn).call(this, n, s);
4030
+ R(this, W, Fn).call(this, n, s);
3400
4031
  },
3401
- log: g(this, V)
4032
+ log: y(this, B)
3402
4033
  });
3403
- return oe(this, z, t), t;
3404
- }, Cn = function() {
3405
- return g(this, z) || X(this, U, _n).call(this);
3406
- }, tt = new WeakMap(), nt = new WeakMap(), st = new WeakMap(), xt = function() {
3407
- return !g(this, z) || !g(this, z).hasActiveStreams();
3408
- }, xn = function() {
3409
- if (g(this, F) && X(this, U, xt).call(this)) {
3410
- const t = g(this, F);
3411
- g(this, V).info("cleaning up unused socket", t.id), oe(this, F, null), t.close();
3412
- }
3413
- }, it = new WeakMap();
3414
- let Ct = jt;
3415
- var Je = {};
3416
- function Qe(e) {
4034
+ return J(this, q, t), t;
4035
+ }, Vn = function() {
4036
+ return y(this, q) || R(this, W, zn).call(this);
4037
+ }, dt = new WeakMap(), lt = new WeakMap(), ht = new WeakMap(), Ft = function() {
4038
+ return !y(this, q) || !y(this, q).hasActiveStreams();
4039
+ }, Jn = function() {
4040
+ if (y(this, H) && R(this, W, Ft).call(this)) {
4041
+ const t = y(this, H);
4042
+ y(this, B).info("cleaning up unused socket", t.id), J(this, H, null), t.close();
4043
+ }
4044
+ }, pt = new WeakMap();
4045
+ let Lt = Bt;
4046
+ var et = {};
4047
+ function tt(e) {
3417
4048
  let t = e;
3418
4049
  return new TransformStream({
3419
4050
  transform(n, s) {
@@ -3425,79 +4056,79 @@ function Qe(e) {
3425
4056
  t -= n.length;
3426
4057
  return;
3427
4058
  }
3428
- const i = n.slice(t);
3429
- t = 0, s.enqueue(i);
4059
+ const r = n.slice(t);
4060
+ t = 0, s.enqueue(r);
3430
4061
  }
3431
4062
  });
3432
4063
  }
3433
- function Xs(e) {
3434
- const t = e.appId || Je.INSTANT_APP_ID || Je.NEXT_PUBLIC_INSTANT_APP_ID;
4064
+ function $r(e) {
4065
+ const t = e.appId || et.INSTANT_APP_ID || et.NEXT_PUBLIC_INSTANT_APP_ID;
3435
4066
  if (!t)
3436
4067
  throw new Error(
3437
4068
  "Missing appId. Pass it as an argument to createResumableStreamContext or set either the INSTANT_APP_ID or NEXT_PUBLIC_INSTANT_APP_ID environment variable."
3438
4069
  );
3439
- const n = e.adminToken || Je.INSTANT_APP_ADMIN_TOKEN;
4070
+ const n = e.adminToken || et.INSTANT_APP_ADMIN_TOKEN;
3440
4071
  if (!n)
3441
4072
  throw new Error(
3442
4073
  "Missing adminToken. Pass it as an argument to createResumableStreamContext or set the INSTANT_APP_ADMIN_TOKEN environment variable."
3443
4074
  );
3444
- const s = { appId: t, adminToken: n }, i = e.apiURI || Je.INSTANT_API_URI;
3445
- i && (s.apiURI = i), e.verbose && (s.verbose = e.verbose);
3446
- const r = Vs(s);
3447
- async function o(l, d, p) {
3448
- const y = r.streams.createWriteStream({
4075
+ const s = { appId: t, adminToken: n }, r = e.apiURI || et.INSTANT_API_URI;
4076
+ r && (s.apiURI = r), e.verbose && (s.verbose = e.verbose);
4077
+ const o = mr(s);
4078
+ async function i(l, f, p) {
4079
+ const m = o.streams.createWriteStream({
3449
4080
  clientId: l,
3450
4081
  waitUntil: e.waitUntil ?? void 0
3451
4082
  });
3452
4083
  try {
3453
- const v = await y.streamId();
3454
- d().pipeTo(y);
3455
- const h = r.streams.createReadStream({ streamId: v });
4084
+ const g = await m.streamId();
4085
+ f().pipeTo(m);
4086
+ const h = o.streams.createReadStream({ streamId: g });
3456
4087
  return p ? h.pipeThrough(
3457
- Qe(p)
4088
+ tt(p)
3458
4089
  ) : h;
3459
4090
  } catch {
3460
- const b = r.streams.createReadStream({ clientId: l });
3461
- return p ? b.pipeThrough(
3462
- Qe(p)
3463
- ) : b;
4091
+ const w = o.streams.createReadStream({ clientId: l });
4092
+ return p ? w.pipeThrough(
4093
+ tt(p)
4094
+ ) : w;
3464
4095
  }
3465
4096
  }
3466
- async function a(l, d) {
3467
- var y, v, b;
3468
- const p = r.streams.createReadStream({ clientId: l });
4097
+ async function a(l, f) {
4098
+ var m, g, w;
4099
+ const p = o.streams.createReadStream({ clientId: l });
3469
4100
  try {
3470
4101
  await p.streamId();
3471
4102
  } catch (h) {
3472
- if (h instanceof H && ((b = (v = (y = h.hint) == null ? void 0 : y.errors) == null ? void 0 : v[0]) == null ? void 0 : b.message) === "Stream is missing.")
4103
+ if (h instanceof _ && ((w = (g = (m = h.hint) == null ? void 0 : m.errors) == null ? void 0 : g[0]) == null ? void 0 : w.message) === "Stream is missing.")
3473
4104
  return;
3474
4105
  throw h;
3475
4106
  }
3476
- return d ? p.pipeThrough(Qe(d)) : p;
4107
+ return f ? p.pipeThrough(tt(f)) : p;
3477
4108
  }
3478
- async function c(l, d, p) {
3479
- const y = d(), v = r.streams.createWriteStream({
4109
+ async function c(l, f, p) {
4110
+ const m = f(), g = o.streams.createWriteStream({
3480
4111
  clientId: l,
3481
4112
  waitUntil: e.waitUntil ?? void 0
3482
4113
  });
3483
- await v.streamId(), y.pipeTo(v);
3484
- const b = r.streams.createReadStream({ clientId: l });
3485
- return p ? b.pipeThrough(Qe(p)) : b;
4114
+ await g.streamId(), m.pipeTo(g);
4115
+ const w = o.streams.createReadStream({ clientId: l });
4116
+ return p ? w.pipeThrough(tt(p)) : w;
3486
4117
  }
3487
4118
  async function u(l) {
3488
- var y;
3489
- const d = await r.query({
4119
+ var m;
4120
+ const f = await o.query({
3490
4121
  $streams: { $: { where: { clientId: l } } }
3491
- }), p = (y = d == null ? void 0 : d.$streams) == null ? void 0 : y[0];
4122
+ }), p = (m = f == null ? void 0 : f.$streams) == null ? void 0 : m[0];
3492
4123
  return p != null && p.done ? "DONE" : p ? !0 : null;
3493
4124
  }
3494
4125
  return {
3495
- resumableStream: o,
4126
+ resumableStream: i,
3496
4127
  resumeExistingStream: a,
3497
4128
  createNewResumableStream: c,
3498
4129
  hasExistingStream: u
3499
4130
  };
3500
4131
  }
3501
4132
  export {
3502
- Xs as createResumableStreamContext
4133
+ $r as createResumableStreamContext
3503
4134
  };