@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.
- package/.turbo/turbo-build.log +9 -9
- package/dist/standalone/index.js +1918 -1287
- package/dist/standalone/index.umd.cjs +5 -5
- package/package.json +2 -2
package/dist/standalone/index.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Hn = Object.defineProperty;
|
|
2
|
+
var Xt = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
return typeof e == "string" &&
|
|
11
|
-
}
|
|
12
|
-
const
|
|
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
|
-
|
|
15
|
-
function
|
|
16
|
-
return (
|
|
17
|
-
}
|
|
18
|
-
let
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
if (!
|
|
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
|
-
|
|
24
|
+
gt = crypto.getRandomValues.bind(crypto);
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return gt(Qn);
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
function
|
|
30
|
-
var
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
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 ?? ((
|
|
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,
|
|
37
|
+
return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, Bn(s);
|
|
38
38
|
}
|
|
39
|
-
const
|
|
39
|
+
const N = {
|
|
40
40
|
Remove: "remove",
|
|
41
41
|
Replace: "replace",
|
|
42
42
|
Add: "add"
|
|
43
|
-
},
|
|
43
|
+
}, bn = Symbol.for("__MUTATIVE_PROXY_DRAFT__"), nt = Symbol.iterator, ae = {
|
|
44
44
|
mutable: "mutable",
|
|
45
45
|
immutable: "immutable"
|
|
46
|
-
},
|
|
47
|
-
function
|
|
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
|
|
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
|
|
61
|
+
function wn(e) {
|
|
62
62
|
return Object.getPrototypeOf(e) === Set.prototype;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function gn(e) {
|
|
65
65
|
return Object.getPrototypeOf(e) === Map.prototype;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
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
|
|
72
|
-
return
|
|
71
|
+
function Ot(e) {
|
|
72
|
+
return !!$(e);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
return typeof e != "object" ? null : e == null ? void 0 : e[
|
|
74
|
+
function $(e) {
|
|
75
|
+
return typeof e != "object" ? null : e == null ? void 0 : e[bn];
|
|
76
76
|
}
|
|
77
|
-
function
|
|
77
|
+
function Vt(e) {
|
|
78
78
|
var t;
|
|
79
|
-
const n =
|
|
79
|
+
const n = $(e);
|
|
80
80
|
return n ? (t = n.copy) !== null && t !== void 0 ? t : n.original : e;
|
|
81
81
|
}
|
|
82
|
-
function
|
|
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,
|
|
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
|
|
88
|
+
function Sn(e, t = []) {
|
|
89
89
|
if (Object.hasOwnProperty.call(e, "key")) {
|
|
90
|
-
const n = e.parent.copy, s =
|
|
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
|
|
94
|
-
if (!(
|
|
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(
|
|
96
|
+
t.push(o);
|
|
97
97
|
}
|
|
98
98
|
if (e.parent)
|
|
99
|
-
return
|
|
99
|
+
return Sn(e.parent, t);
|
|
100
100
|
t.reverse();
|
|
101
101
|
try {
|
|
102
|
-
|
|
102
|
+
Zn(e.copy, t);
|
|
103
103
|
} catch {
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
return t;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function Ye(e) {
|
|
109
109
|
return Array.isArray(e) ? 1 : e instanceof Map ? 2 : e instanceof Set ? 3 : 0;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
111
|
+
function ge(e, t) {
|
|
112
|
+
return Ye(e) === 2 ? e.get(t) : e[t];
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
114
|
+
function Jt(e, t, n) {
|
|
115
|
+
Ye(e) === 2 ? e.set(t, n) : e[t] = n;
|
|
116
116
|
}
|
|
117
|
-
function
|
|
118
|
-
const n =
|
|
119
|
-
return (n ?
|
|
117
|
+
function St(e, t) {
|
|
118
|
+
const n = $(e);
|
|
119
|
+
return (n ? Z(n) : e)[t];
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function Ee(e, t) {
|
|
122
122
|
return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t;
|
|
123
123
|
}
|
|
124
|
-
function
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
155
|
-
function
|
|
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 (!
|
|
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 (!
|
|
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,
|
|
172
|
-
if (n ===
|
|
173
|
-
return
|
|
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((
|
|
183
|
-
s[
|
|
184
|
-
}), Object.getOwnPropertySymbols(e).forEach((
|
|
185
|
-
|
|
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
|
|
191
|
-
e.copy || (e.copy =
|
|
190
|
+
function Q(e) {
|
|
191
|
+
e.copy || (e.copy = ns(e.original, e.options));
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
if (!
|
|
195
|
-
return
|
|
193
|
+
function ze(e) {
|
|
194
|
+
if (!Ce(e))
|
|
195
|
+
return Vt(e);
|
|
196
196
|
if (Array.isArray(e))
|
|
197
|
-
return e.map(
|
|
197
|
+
return e.map(ze);
|
|
198
198
|
if (e instanceof Map) {
|
|
199
|
-
const n = Array.from(e.entries()).map(([s,
|
|
199
|
+
const n = Array.from(e.entries()).map(([s, r]) => [
|
|
200
200
|
s,
|
|
201
|
-
|
|
201
|
+
ze(r)
|
|
202
202
|
]);
|
|
203
|
-
if (!
|
|
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(
|
|
211
|
-
if (!
|
|
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] =
|
|
219
|
+
t[n] = ze(e[n]);
|
|
220
220
|
return t;
|
|
221
221
|
}
|
|
222
|
-
function
|
|
223
|
-
return
|
|
222
|
+
function st(e) {
|
|
223
|
+
return Ot(e) ? ze(e) : e;
|
|
224
224
|
}
|
|
225
|
-
function
|
|
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 &&
|
|
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
|
|
230
|
-
const n =
|
|
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
|
|
238
|
-
t(s,
|
|
237
|
+
for (const r of e)
|
|
238
|
+
t(s, r, e), s += 1;
|
|
239
239
|
} else
|
|
240
|
-
e.forEach((s,
|
|
240
|
+
e.forEach((s, r) => t(r, s, e));
|
|
241
241
|
}
|
|
242
|
-
function
|
|
243
|
-
if (
|
|
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,
|
|
246
|
-
if (t.add(e),
|
|
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 (
|
|
249
|
-
const c =
|
|
250
|
-
|
|
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
|
-
|
|
252
|
+
Jt(s ? r : e, o, u);
|
|
253
253
|
} else
|
|
254
|
-
|
|
255
|
-
}),
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
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
|
|
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 &&
|
|
264
|
+
e.finalities.revoke.length > 1 && e.assignedMap.get(t) && n && In(ge(n, t), e.finalities.handledSet, e.options);
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function Et(e) {
|
|
267
267
|
e.type === 3 && e.copy && (e.copy.clear(), e.setMap.forEach((t) => {
|
|
268
|
-
e.copy.add(
|
|
268
|
+
e.copy.add(Vt(t));
|
|
269
269
|
}));
|
|
270
270
|
}
|
|
271
|
-
function
|
|
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
|
|
275
|
-
|
|
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
|
|
281
|
-
const
|
|
282
|
-
|
|
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 (
|
|
286
|
-
let u =
|
|
287
|
-
|
|
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 &&
|
|
290
|
-
const
|
|
291
|
-
|
|
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
|
|
295
|
-
let { original:
|
|
296
|
-
c.length <
|
|
297
|
-
for (let u = 0; u <
|
|
298
|
-
if (
|
|
299
|
-
const l = t.concat([u]),
|
|
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:
|
|
302
|
-
path:
|
|
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:
|
|
304
|
+
value: st(c[u])
|
|
305
305
|
}), s.push({
|
|
306
|
-
op:
|
|
307
|
-
path:
|
|
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:
|
|
309
|
+
value: st(o[u])
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
-
for (let u =
|
|
313
|
-
const l = t.concat([u]),
|
|
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:
|
|
316
|
-
path:
|
|
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:
|
|
318
|
+
value: st(c[u])
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
|
-
if (
|
|
321
|
+
if (o.length < c.length) {
|
|
322
322
|
const { arrayLengthAssignment: u = !0 } = a.enablePatches;
|
|
323
323
|
if (u) {
|
|
324
|
-
const l = t.concat(["length"]),
|
|
324
|
+
const l = t.concat(["length"]), f = ve(l, r);
|
|
325
325
|
s.push({
|
|
326
|
-
op:
|
|
327
|
-
path:
|
|
328
|
-
value:
|
|
326
|
+
op: N.Replace,
|
|
327
|
+
path: f,
|
|
328
|
+
value: o.length
|
|
329
329
|
});
|
|
330
330
|
} else
|
|
331
|
-
for (let l = c.length;
|
|
332
|
-
const
|
|
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:
|
|
334
|
+
op: N.Remove,
|
|
335
335
|
path: p
|
|
336
336
|
});
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
-
function
|
|
340
|
+
function os({ original: e, copy: t, assignedMap: n }, s, r, o, i) {
|
|
341
341
|
n.forEach((a, c) => {
|
|
342
|
-
const u =
|
|
343
|
-
if (
|
|
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),
|
|
346
|
-
|
|
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
|
|
350
|
-
let
|
|
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([
|
|
353
|
+
const c = n.concat([i]), u = ve(c, o);
|
|
354
354
|
s.push({
|
|
355
|
-
op:
|
|
355
|
+
op: N.Remove,
|
|
356
356
|
path: u,
|
|
357
357
|
value: a
|
|
358
|
-
}),
|
|
359
|
-
op:
|
|
358
|
+
}), r.unshift({
|
|
359
|
+
op: N.Add,
|
|
360
360
|
path: u,
|
|
361
361
|
value: a
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
|
-
|
|
365
|
-
}),
|
|
364
|
+
i += 1;
|
|
365
|
+
}), i = 0, t.forEach((a) => {
|
|
366
366
|
if (!e.has(a)) {
|
|
367
|
-
const c = n.concat([
|
|
367
|
+
const c = n.concat([i]), u = ve(c, o);
|
|
368
368
|
s.push({
|
|
369
|
-
op:
|
|
369
|
+
op: N.Add,
|
|
370
370
|
path: u,
|
|
371
371
|
value: a
|
|
372
|
-
}),
|
|
373
|
-
op:
|
|
372
|
+
}), r.unshift({
|
|
373
|
+
op: N.Remove,
|
|
374
374
|
path: u,
|
|
375
375
|
value: a
|
|
376
376
|
});
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
i += 1;
|
|
379
379
|
});
|
|
380
380
|
}
|
|
381
|
-
function
|
|
382
|
-
const { pathAsArray:
|
|
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
|
|
386
|
+
return os(e, t, n, s, r);
|
|
387
387
|
case 1:
|
|
388
|
-
return
|
|
388
|
+
return is(e, t, n, s, r);
|
|
389
389
|
case 3:
|
|
390
|
-
return
|
|
390
|
+
return as(e, t, n, s, r);
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
const
|
|
394
|
-
if (typeof e == "object" && e !== null && (!
|
|
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
|
-
},
|
|
396
|
+
}, Ct = {
|
|
397
397
|
get size() {
|
|
398
|
-
return
|
|
398
|
+
return Z($(this)).size;
|
|
399
399
|
},
|
|
400
400
|
has(e) {
|
|
401
|
-
return
|
|
401
|
+
return Z($(this)).has(e);
|
|
402
402
|
},
|
|
403
403
|
set(e, t) {
|
|
404
|
-
const n =
|
|
405
|
-
return (!s.has(e) || !
|
|
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 =
|
|
411
|
-
return
|
|
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 =
|
|
414
|
+
const e = $(this);
|
|
415
415
|
if (this.size) {
|
|
416
|
-
|
|
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 =
|
|
424
|
-
|
|
425
|
-
e.call(t, this.get(
|
|
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 =
|
|
431
|
-
if (s.options.strict &&
|
|
432
|
-
return
|
|
433
|
-
const
|
|
434
|
-
original:
|
|
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
|
|
440
|
+
return Q(s), s.copy.set(e, i), i;
|
|
441
441
|
},
|
|
442
442
|
keys() {
|
|
443
|
-
return
|
|
443
|
+
return Z($(this)).keys();
|
|
444
444
|
},
|
|
445
445
|
values() {
|
|
446
446
|
const e = this.keys();
|
|
447
447
|
return {
|
|
448
|
-
[
|
|
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
|
-
[
|
|
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
|
-
[
|
|
474
|
+
[nt]() {
|
|
475
475
|
return this.entries();
|
|
476
476
|
}
|
|
477
|
-
},
|
|
478
|
-
var s,
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
481
|
-
return
|
|
482
|
-
const
|
|
483
|
-
let a = e.setMap.get(
|
|
484
|
-
const c =
|
|
485
|
-
if (e.options.strict &&
|
|
486
|
-
const l =
|
|
487
|
-
original:
|
|
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:
|
|
489
|
+
key: i,
|
|
490
490
|
finalities: e.finalities,
|
|
491
491
|
options: e.options
|
|
492
492
|
});
|
|
493
|
-
e.setMap.set(
|
|
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
|
-
},
|
|
499
|
+
}, ut = {
|
|
500
500
|
get size() {
|
|
501
|
-
return
|
|
501
|
+
return $(this).setMap.size;
|
|
502
502
|
},
|
|
503
503
|
has(e) {
|
|
504
|
-
const t =
|
|
504
|
+
const t = $(this);
|
|
505
505
|
if (t.setMap.has(e))
|
|
506
506
|
return !0;
|
|
507
|
-
|
|
508
|
-
const n =
|
|
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 =
|
|
513
|
-
return this.has(e) || (
|
|
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 =
|
|
519
|
-
|
|
520
|
-
const n =
|
|
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 =
|
|
527
|
-
|
|
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 =
|
|
534
|
-
|
|
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:
|
|
538
|
+
next: en(e, t, { isValuesIterator: !0 })
|
|
539
539
|
};
|
|
540
540
|
},
|
|
541
541
|
entries() {
|
|
542
|
-
const e =
|
|
543
|
-
|
|
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:
|
|
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
|
-
[
|
|
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(
|
|
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
|
|
588
|
+
const us = Reflect.ownKeys(ut), kn = /* @__PURE__ */ new WeakSet(), vn = {
|
|
589
589
|
get(e, t, n) {
|
|
590
|
-
var s,
|
|
591
|
-
const
|
|
592
|
-
if (
|
|
593
|
-
return
|
|
594
|
-
if (t ===
|
|
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
|
|
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 (
|
|
600
|
-
return e.options.strict &&
|
|
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 =
|
|
603
|
-
if (a instanceof Map &&
|
|
602
|
+
const a = Z(e);
|
|
603
|
+
if (a instanceof Map && cs.includes(t)) {
|
|
604
604
|
if (t === "size")
|
|
605
|
-
return Object.getOwnPropertyDescriptor(
|
|
606
|
-
const u =
|
|
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 &&
|
|
610
|
+
if (a instanceof Set && us.includes(t)) {
|
|
611
611
|
if (t === "size")
|
|
612
|
-
return Object.getOwnPropertyDescriptor(
|
|
613
|
-
const u =
|
|
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 (!
|
|
618
|
-
const u =
|
|
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
|
-
(
|
|
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 &&
|
|
625
|
+
if (e.options.strict && ct(c, e.options), e.finalized || !Ce(c, e.options))
|
|
626
626
|
return c;
|
|
627
|
-
if (c ===
|
|
628
|
-
if (
|
|
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
|
|
635
|
-
const u =
|
|
636
|
-
return
|
|
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
|
|
647
|
-
if (e.type === 1 && t !== "length" && !(Number.isInteger(
|
|
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
|
|
650
|
-
if (
|
|
651
|
-
return
|
|
652
|
-
const
|
|
653
|
-
return a &&
|
|
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
|
|
656
|
+
return t in Z(e);
|
|
657
657
|
},
|
|
658
658
|
ownKeys(e) {
|
|
659
|
-
return Reflect.ownKeys(
|
|
659
|
+
return Reflect.ownKeys(Z(e));
|
|
660
660
|
},
|
|
661
661
|
getOwnPropertyDescriptor(e, t) {
|
|
662
|
-
const n =
|
|
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 ?
|
|
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
|
|
685
|
-
const { original: t, parentDraft: n, key: s, finalities:
|
|
686
|
-
type:
|
|
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:
|
|
693
|
-
options:
|
|
692
|
+
finalities: r,
|
|
693
|
+
options: o,
|
|
694
694
|
// Mapping of draft Set items to their corresponding draft values.
|
|
695
|
-
setMap:
|
|
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(
|
|
699
|
-
if (
|
|
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((
|
|
702
|
-
var
|
|
703
|
-
const
|
|
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
|
|
706
|
-
if (
|
|
707
|
-
let
|
|
708
|
-
|
|
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
|
-
(
|
|
711
|
-
|
|
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 =
|
|
716
|
-
l.finalities.draft.push((
|
|
717
|
-
|
|
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
|
-
|
|
722
|
+
zt.createDraft = $n;
|
|
723
723
|
Object.prototype.constructor.toString();
|
|
724
|
-
function
|
|
725
|
-
return
|
|
724
|
+
function je() {
|
|
725
|
+
return Yn();
|
|
726
726
|
}
|
|
727
|
-
function
|
|
727
|
+
function fs(e, t) {
|
|
728
728
|
return e.localeCompare(t);
|
|
729
729
|
}
|
|
730
|
-
function
|
|
731
|
-
let e =
|
|
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
|
-
|
|
740
|
-
function
|
|
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
|
|
755
|
-
function
|
|
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: (
|
|
762
|
-
if (
|
|
761
|
+
get: (r, o) => {
|
|
762
|
+
if (o === "__ops")
|
|
763
763
|
return n;
|
|
764
|
-
if (
|
|
764
|
+
if (o === "__etype")
|
|
765
765
|
return e;
|
|
766
|
-
if (
|
|
767
|
-
return (
|
|
766
|
+
if (hs.has(o))
|
|
767
|
+
return (i, a) => rt(e, t, [
|
|
768
768
|
...n,
|
|
769
|
-
a ? [
|
|
769
|
+
a ? [o, e, t, i, a] : [o, e, t, i]
|
|
770
770
|
]);
|
|
771
771
|
}
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
|
-
function
|
|
774
|
+
function ps(e, t) {
|
|
775
775
|
return `lookup__${e}__${JSON.stringify(t)}`;
|
|
776
776
|
}
|
|
777
|
-
function
|
|
777
|
+
function On(e) {
|
|
778
778
|
return e.startsWith("lookup__");
|
|
779
779
|
}
|
|
780
|
-
function
|
|
780
|
+
function tn(e) {
|
|
781
781
|
const [t, n, ...s] = e.split("__");
|
|
782
782
|
return [n, JSON.parse(s.join("__"))];
|
|
783
783
|
}
|
|
784
|
-
function
|
|
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 (
|
|
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
|
|
794
|
+
return On(s) ? rt(e, tn(s), []) : rt(e, s, []);
|
|
795
795
|
}
|
|
796
796
|
});
|
|
797
797
|
}
|
|
798
|
-
function
|
|
798
|
+
function En() {
|
|
799
799
|
return new Proxy({}, {
|
|
800
800
|
get(e, t) {
|
|
801
|
-
return
|
|
801
|
+
return ys(t);
|
|
802
802
|
}
|
|
803
803
|
});
|
|
804
804
|
}
|
|
805
|
-
|
|
806
|
-
function
|
|
805
|
+
En();
|
|
806
|
+
function ms(e) {
|
|
807
807
|
return e.__ops;
|
|
808
808
|
}
|
|
809
|
-
class
|
|
810
|
-
constructor(n, s,
|
|
809
|
+
class _ extends Error {
|
|
810
|
+
constructor(n, s, r) {
|
|
811
811
|
super(n);
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
this.hint = s,
|
|
815
|
-
const
|
|
816
|
-
Object.setPrototypeOf && Object.setPrototypeOf(this,
|
|
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
|
|
822
|
+
class le extends _ {
|
|
823
823
|
constructor(n) {
|
|
824
|
-
var
|
|
825
|
-
const s = ((
|
|
826
|
-
super(s, n.body.hint, ((
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
const
|
|
830
|
-
Object.setPrototypeOf && Object.setPrototypeOf(this,
|
|
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
|
|
838
|
-
class
|
|
839
|
-
constructor(t, n, s,
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
this.valueType = t, this.required = n, this.isIndexed = s, this.config =
|
|
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
|
|
853
|
+
return new de(this.valueType, !1, this.isIndexed, this.config);
|
|
854
854
|
}
|
|
855
855
|
optional() {
|
|
856
|
-
return new
|
|
856
|
+
return new de(this.valueType, !1, this.isIndexed, this.config);
|
|
857
857
|
}
|
|
858
858
|
unique() {
|
|
859
|
-
return new
|
|
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
|
|
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
|
|
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
|
|
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
|
-
],
|
|
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
|
-
},
|
|
906
|
-
const a =
|
|
907
|
-
if (!
|
|
908
|
-
throw new
|
|
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
|
|
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" && !
|
|
929
|
-
throw new
|
|
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
|
|
935
|
+
throw new T(`Unknown operator '${e}' for attribute '${s}' in entity '${r}'`, i);
|
|
936
936
|
}
|
|
937
|
-
},
|
|
938
|
-
const
|
|
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 (
|
|
940
|
+
if (i)
|
|
941
941
|
return;
|
|
942
942
|
const c = e;
|
|
943
943
|
for (const [u, l] of Object.entries(c))
|
|
944
|
-
|
|
945
|
-
} else if (!
|
|
946
|
-
throw new
|
|
947
|
-
},
|
|
948
|
-
const
|
|
949
|
-
if (
|
|
950
|
-
throw new
|
|
951
|
-
let
|
|
952
|
-
for (let l = 0; l <
|
|
953
|
-
const
|
|
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
|
|
956
|
-
const
|
|
957
|
-
if (!
|
|
958
|
-
const
|
|
959
|
-
throw new
|
|
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
|
-
|
|
961
|
+
i = m.entityName;
|
|
962
962
|
}
|
|
963
|
-
const a =
|
|
963
|
+
const a = o[o.length - 1], c = s.entities[i];
|
|
964
964
|
if (!c)
|
|
965
|
-
throw new
|
|
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" && !
|
|
968
|
-
throw new
|
|
969
|
-
|
|
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" && !
|
|
975
|
-
throw new
|
|
976
|
-
|
|
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
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
},
|
|
985
|
-
for (const [
|
|
986
|
-
if (
|
|
987
|
-
if (Array.isArray(
|
|
988
|
-
for (const u of
|
|
989
|
-
typeof u == "object" && u !== null &&
|
|
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 (
|
|
993
|
-
|
|
992
|
+
if (r === "id") {
|
|
993
|
+
Ue(o, "id", new de("string", !1, !0), t, `${s}.id`);
|
|
994
994
|
continue;
|
|
995
995
|
}
|
|
996
|
-
if (
|
|
997
|
-
|
|
996
|
+
if (r.includes(".")) {
|
|
997
|
+
gs(r, o, t, n, `${s}.${r}`);
|
|
998
998
|
continue;
|
|
999
999
|
}
|
|
1000
|
-
const
|
|
1001
|
-
if (!
|
|
1000
|
+
const i = n.entities[t];
|
|
1001
|
+
if (!i)
|
|
1002
1002
|
continue;
|
|
1003
|
-
const a =
|
|
1003
|
+
const a = i.attrs[r], c = i.links[r];
|
|
1004
1004
|
if (!a && !c) {
|
|
1005
|
-
const u = Object.keys(
|
|
1006
|
-
throw new
|
|
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
|
-
|
|
1009
|
+
Ue(o, r, a, t, `${s}.${r}`);
|
|
1010
1010
|
else if (c) {
|
|
1011
|
-
if (typeof
|
|
1012
|
-
throw new
|
|
1013
|
-
const u = new
|
|
1014
|
-
|
|
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
|
-
},
|
|
1018
|
-
for (const
|
|
1019
|
-
if (!
|
|
1020
|
-
throw new
|
|
1021
|
-
const
|
|
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
|
|
1032
|
-
if (e[
|
|
1033
|
-
throw new
|
|
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
|
|
1037
|
-
|
|
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
|
-
},
|
|
1040
|
-
var
|
|
1039
|
+
}, Tn = (e, t, n, s, r = 0) => {
|
|
1040
|
+
var o;
|
|
1041
1041
|
if (!e || typeof e != "object")
|
|
1042
|
-
throw new
|
|
1043
|
-
for (const
|
|
1044
|
-
if (
|
|
1045
|
-
if (n && !(
|
|
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
|
|
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[
|
|
1049
|
+
const a = e[i];
|
|
1050
1050
|
if (typeof a == "object" && a !== null) {
|
|
1051
|
-
const c = (
|
|
1052
|
-
c &&
|
|
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[
|
|
1055
|
+
const a = e[i];
|
|
1056
1056
|
if (typeof a != "object" || a === null)
|
|
1057
|
-
throw new
|
|
1058
|
-
|
|
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
|
-
},
|
|
1060
|
+
}, sn = (e, t) => {
|
|
1061
1061
|
if (typeof e != "object" || e === null)
|
|
1062
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1074
|
-
throw new
|
|
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
|
-
|
|
1076
|
+
Tn(n[s], s, t, s, 0);
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
|
-
},
|
|
1080
|
-
class
|
|
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
|
|
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
|
-
},
|
|
1091
|
+
}, ks = (e, t) => {
|
|
1092
1092
|
var n;
|
|
1093
|
-
return e == null ? !0 : ((n =
|
|
1094
|
-
},
|
|
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
|
|
1097
|
+
throw Is(e, Object.keys(t.entities));
|
|
1098
1098
|
return n;
|
|
1099
|
-
},
|
|
1100
|
-
const s =
|
|
1099
|
+
}, kt = (e, t, n) => {
|
|
1100
|
+
const s = Rn(e, n);
|
|
1101
1101
|
if (typeof t != "object" || t === null)
|
|
1102
|
-
throw new
|
|
1103
|
-
for (const [
|
|
1104
|
-
if (
|
|
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
|
|
1107
|
-
if (
|
|
1108
|
-
throw new
|
|
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
|
-
},
|
|
1111
|
-
const s =
|
|
1110
|
+
}, on = (e, t, n) => {
|
|
1111
|
+
const s = Rn(e, n);
|
|
1112
1112
|
if (typeof t != "object" || t === null)
|
|
1113
|
-
throw new
|
|
1114
|
-
for (const [
|
|
1115
|
-
if (!s.links[
|
|
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
|
|
1118
|
-
}
|
|
1119
|
-
if (
|
|
1120
|
-
if (Array.isArray(
|
|
1121
|
-
for (const a of
|
|
1122
|
-
if (!
|
|
1123
|
-
throw new
|
|
1124
|
-
} else if (!
|
|
1125
|
-
throw new
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
},
|
|
1129
|
-
create:
|
|
1130
|
-
update:
|
|
1131
|
-
merge:
|
|
1132
|
-
link:
|
|
1133
|
-
unlink:
|
|
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
|
-
},
|
|
1136
|
+
}, $s = (e, t) => {
|
|
1137
1137
|
if (!t)
|
|
1138
1138
|
return;
|
|
1139
|
-
const [n, s,
|
|
1140
|
-
if (!Array.isArray(
|
|
1141
|
-
throw new
|
|
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
|
|
1144
|
-
const
|
|
1145
|
-
|
|
1146
|
-
},
|
|
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
|
|
1150
|
+
throw new te(`Transaction chunk must be an object, but received: ${typeof s}`);
|
|
1151
1151
|
if (!Array.isArray(s.__ops))
|
|
1152
|
-
throw new
|
|
1153
|
-
for (const
|
|
1154
|
-
if (!Array.isArray(
|
|
1155
|
-
throw new
|
|
1156
|
-
|
|
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
|
|
1161
|
-
class
|
|
1160
|
+
let Es = 0;
|
|
1161
|
+
class _s {
|
|
1162
1162
|
constructor(t, n, s) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
this.id = `${this.type}_${
|
|
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 = (
|
|
1181
|
-
const
|
|
1182
|
-
if (Array.isArray(
|
|
1183
|
-
for (const
|
|
1184
|
-
this.handleMessage(
|
|
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(
|
|
1187
|
-
}, this.conn.onerror = (
|
|
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,
|
|
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: (
|
|
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
|
|
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
|
-
})(
|
|
1262
|
-
function
|
|
1263
|
-
const
|
|
1264
|
-
let
|
|
1265
|
-
const u =
|
|
1266
|
-
let l = !1,
|
|
1267
|
-
const p = [],
|
|
1268
|
-
let
|
|
1269
|
-
const
|
|
1270
|
-
function
|
|
1271
|
-
|
|
1272
|
-
for (const
|
|
1273
|
-
|
|
1274
|
-
}
|
|
1275
|
-
function
|
|
1276
|
-
return p.push(
|
|
1277
|
-
const
|
|
1278
|
-
|
|
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
|
|
1282
|
-
return
|
|
1283
|
-
const
|
|
1284
|
-
|
|
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((
|
|
1288
|
-
|
|
1287
|
+
t.waitUntil && t.waitUntil(new Promise((b) => {
|
|
1288
|
+
g.push(b);
|
|
1289
1289
|
}));
|
|
1290
1290
|
function x() {
|
|
1291
|
-
for (const
|
|
1291
|
+
for (const b of g)
|
|
1292
1292
|
try {
|
|
1293
|
-
|
|
1293
|
+
b();
|
|
1294
1294
|
} catch {
|
|
1295
1295
|
}
|
|
1296
1296
|
}
|
|
1297
|
-
function
|
|
1298
|
-
return
|
|
1299
|
-
const
|
|
1300
|
-
|
|
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
|
|
1304
|
-
|
|
1305
|
-
for (const
|
|
1306
|
-
|
|
1303
|
+
function ne(b) {
|
|
1304
|
+
i = b;
|
|
1305
|
+
for (const S of m)
|
|
1306
|
+
S(i);
|
|
1307
1307
|
}
|
|
1308
|
-
function
|
|
1309
|
-
|
|
1308
|
+
function E() {
|
|
1309
|
+
w = !0;
|
|
1310
1310
|
}
|
|
1311
|
-
function
|
|
1312
|
-
let
|
|
1313
|
-
for (const { byteLen:
|
|
1314
|
-
const
|
|
1315
|
-
if (
|
|
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
|
-
|
|
1317
|
+
S = ue, L++, G += se;
|
|
1318
1318
|
}
|
|
1319
|
-
|
|
1319
|
+
L > 0 && (h += G, k -= G, v.splice(0, L));
|
|
1320
1320
|
}
|
|
1321
|
-
function
|
|
1322
|
-
a =
|
|
1321
|
+
function M(b, S) {
|
|
1322
|
+
a = S, Se(), b.error(S), x();
|
|
1323
1323
|
}
|
|
1324
|
-
async function
|
|
1325
|
-
const
|
|
1326
|
-
clientId:
|
|
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 (
|
|
1330
|
+
switch (b.type) {
|
|
1331
1331
|
case "ok": {
|
|
1332
|
-
const { streamId:
|
|
1333
|
-
|
|
1334
|
-
streamId:
|
|
1335
|
-
chunks:
|
|
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
|
-
}),
|
|
1337
|
+
}), w = !1;
|
|
1338
1338
|
break;
|
|
1339
1339
|
}
|
|
1340
1340
|
case "disconnect": {
|
|
1341
|
-
|
|
1341
|
+
E();
|
|
1342
1342
|
break;
|
|
1343
1343
|
}
|
|
1344
1344
|
case "error": {
|
|
1345
|
-
c &&
|
|
1345
|
+
c && M(c, b.error);
|
|
1346
1346
|
break;
|
|
1347
1347
|
}
|
|
1348
1348
|
}
|
|
1349
1349
|
}
|
|
1350
|
-
function
|
|
1351
|
-
|
|
1350
|
+
function V() {
|
|
1351
|
+
E(), ee();
|
|
1352
1352
|
}
|
|
1353
|
-
function
|
|
1354
|
-
|
|
1353
|
+
function Ze({ offset: b, done: S }) {
|
|
1354
|
+
D(b), S && (l = !0, x());
|
|
1355
1355
|
}
|
|
1356
|
-
function
|
|
1357
|
-
return l ? (
|
|
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
|
|
1360
|
-
c =
|
|
1361
|
-
let
|
|
1362
|
-
for (;
|
|
1363
|
-
let
|
|
1364
|
-
|
|
1365
|
-
const
|
|
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 (
|
|
1370
|
+
switch (se.type) {
|
|
1371
1371
|
case "ok": {
|
|
1372
|
-
const { streamId:
|
|
1373
|
-
if (
|
|
1374
|
-
const
|
|
1375
|
-
|
|
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
|
-
|
|
1379
|
-
onDisconnect:
|
|
1380
|
-
onFlush:
|
|
1381
|
-
onConnectionReconnect:
|
|
1382
|
-
onAppendFailed:
|
|
1383
|
-
}),
|
|
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
|
-
|
|
1388
|
-
setTimeout(
|
|
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
|
-
|
|
1393
|
+
M(b, se.error);
|
|
1394
1394
|
return;
|
|
1395
1395
|
}
|
|
1396
1396
|
}
|
|
1397
1397
|
}
|
|
1398
1398
|
}
|
|
1399
|
-
class
|
|
1400
|
-
constructor(
|
|
1401
|
-
super(
|
|
1399
|
+
class pe extends e {
|
|
1400
|
+
constructor(S, L) {
|
|
1401
|
+
super(S, L);
|
|
1402
1402
|
}
|
|
1403
1403
|
async streamId() {
|
|
1404
|
-
return
|
|
1405
|
-
const
|
|
1406
|
-
for (const
|
|
1407
|
-
|
|
1408
|
-
},
|
|
1409
|
-
|
|
1410
|
-
},
|
|
1411
|
-
|
|
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
|
-
|
|
1413
|
+
G.push(O(ue)), G.push(mt(bt));
|
|
1414
1414
|
});
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
return {
|
|
1418
|
-
stream: new
|
|
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(
|
|
1421
|
+
async start(b) {
|
|
1422
1422
|
try {
|
|
1423
|
-
await
|
|
1424
|
-
} catch (
|
|
1425
|
-
|
|
1423
|
+
await Te(b);
|
|
1424
|
+
} catch (S) {
|
|
1425
|
+
M(b, S);
|
|
1426
1426
|
}
|
|
1427
1427
|
},
|
|
1428
|
-
write(
|
|
1429
|
-
const
|
|
1430
|
-
if (
|
|
1431
|
-
const
|
|
1432
|
-
|
|
1433
|
-
const
|
|
1434
|
-
|
|
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
|
-
|
|
1439
|
-
streamId:
|
|
1438
|
+
i ? s({
|
|
1439
|
+
streamId: i,
|
|
1440
1440
|
chunks: [],
|
|
1441
|
-
offset: h +
|
|
1441
|
+
offset: h + k,
|
|
1442
1442
|
isDone: !0
|
|
1443
|
-
}) : x(),
|
|
1443
|
+
}) : x(), Se();
|
|
1444
1444
|
},
|
|
1445
|
-
abort(
|
|
1446
|
-
|
|
1447
|
-
streamId:
|
|
1445
|
+
abort(b) {
|
|
1446
|
+
i ? s({
|
|
1447
|
+
streamId: i,
|
|
1448
1448
|
chunks: [],
|
|
1449
|
-
offset: h +
|
|
1449
|
+
offset: h + k,
|
|
1450
1450
|
isDone: !0,
|
|
1451
|
-
abortReason:
|
|
1452
|
-
}) : x(),
|
|
1451
|
+
abortReason: b
|
|
1452
|
+
}) : x(), Se();
|
|
1453
1453
|
}
|
|
1454
1454
|
}),
|
|
1455
|
-
addCompleteCb:
|
|
1455
|
+
addCompleteCb: Qt,
|
|
1456
1456
|
closed() {
|
|
1457
|
-
return
|
|
1457
|
+
return f;
|
|
1458
1458
|
}
|
|
1459
1459
|
};
|
|
1460
1460
|
}
|
|
1461
|
-
class
|
|
1461
|
+
class Ts {
|
|
1462
1462
|
constructor() {
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
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
|
|
1496
|
-
let
|
|
1497
|
-
const
|
|
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 = [],
|
|
1500
|
-
let p = null,
|
|
1501
|
-
function
|
|
1499
|
+
const l = [], f = [];
|
|
1500
|
+
let p = null, m = null;
|
|
1501
|
+
function g(x) {
|
|
1502
1502
|
u = !0;
|
|
1503
|
-
for (const
|
|
1504
|
-
|
|
1503
|
+
for (const O of l)
|
|
1504
|
+
O(x);
|
|
1505
1505
|
}
|
|
1506
|
-
function
|
|
1506
|
+
function w(x) {
|
|
1507
1507
|
return l.push(x), () => {
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1508
|
+
const O = l.indexOf(x);
|
|
1509
|
+
O !== -1 && l.splice(O, 1);
|
|
1510
1510
|
};
|
|
1511
1511
|
}
|
|
1512
1512
|
function h(x) {
|
|
1513
|
-
return
|
|
1514
|
-
const
|
|
1515
|
-
|
|
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
|
|
1519
|
-
|
|
1518
|
+
function k(x, O) {
|
|
1519
|
+
m = O, x.error(O), g(O);
|
|
1520
1520
|
}
|
|
1521
|
-
let
|
|
1522
|
-
async function
|
|
1523
|
-
c =
|
|
1524
|
-
const
|
|
1525
|
-
for await (const
|
|
1526
|
-
if (
|
|
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 (
|
|
1528
|
+
if (E.type === "reconnect")
|
|
1529
1529
|
return { retry: !0 };
|
|
1530
|
-
if (
|
|
1531
|
-
|
|
1530
|
+
if (E.type === "error") {
|
|
1531
|
+
k(O, E.error);
|
|
1532
1532
|
return;
|
|
1533
1533
|
}
|
|
1534
|
-
if (
|
|
1535
|
-
|
|
1534
|
+
if (E.offset > r) {
|
|
1535
|
+
k(O, new _("Stream is corrupted.")), o = !0;
|
|
1536
1536
|
return;
|
|
1537
1537
|
}
|
|
1538
|
-
p =
|
|
1539
|
-
for (const
|
|
1540
|
-
|
|
1541
|
-
let
|
|
1542
|
-
if (
|
|
1543
|
-
const
|
|
1544
|
-
let
|
|
1545
|
-
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
|
|
1548
|
-
const
|
|
1549
|
-
if (
|
|
1550
|
-
if (
|
|
1551
|
-
|
|
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 (
|
|
1557
|
-
const
|
|
1556
|
+
if (Te.body) {
|
|
1557
|
+
const pe = Te.body.getReader();
|
|
1558
1558
|
try {
|
|
1559
1559
|
for (; ; ) {
|
|
1560
|
-
const { done:
|
|
1561
|
-
if (
|
|
1560
|
+
const { done: ye, value: b } = await pe.read();
|
|
1561
|
+
if (ye)
|
|
1562
1562
|
break;
|
|
1563
|
-
if (
|
|
1564
|
-
|
|
1563
|
+
if (o) {
|
|
1564
|
+
M.abort();
|
|
1565
1565
|
return;
|
|
1566
1566
|
}
|
|
1567
|
-
let
|
|
1568
|
-
if (
|
|
1567
|
+
let S = b;
|
|
1568
|
+
if (D > 0 && (S = b.subarray(D), D -= b.length - S.length), !S.length)
|
|
1569
1569
|
continue;
|
|
1570
|
-
|
|
1571
|
-
const
|
|
1572
|
-
|
|
1570
|
+
r += S.length;
|
|
1571
|
+
const L = i.decode(S);
|
|
1572
|
+
O.enqueue(L);
|
|
1573
1573
|
}
|
|
1574
1574
|
} finally {
|
|
1575
|
-
|
|
1575
|
+
pe.releaseLock();
|
|
1576
1576
|
}
|
|
1577
1577
|
} else {
|
|
1578
|
-
const
|
|
1579
|
-
let
|
|
1580
|
-
if (
|
|
1581
|
-
|
|
1578
|
+
const pe = await Te.arrayBuffer();
|
|
1579
|
+
let ye = pe;
|
|
1580
|
+
if (o) {
|
|
1581
|
+
M.abort();
|
|
1582
1582
|
return;
|
|
1583
1583
|
}
|
|
1584
|
-
if (
|
|
1584
|
+
if (D > 0 && (ye = new Uint8Array(pe).subarray(D), D -= pe.byteLength - ye.length), !ye.byteLength)
|
|
1585
1585
|
continue;
|
|
1586
|
-
|
|
1587
|
-
const
|
|
1588
|
-
|
|
1586
|
+
r += ye.byteLength;
|
|
1587
|
+
const b = i.decode(ye);
|
|
1588
|
+
O.enqueue(b);
|
|
1589
1589
|
}
|
|
1590
1590
|
}
|
|
1591
1591
|
}
|
|
1592
|
-
if (
|
|
1593
|
-
let
|
|
1594
|
-
if (
|
|
1595
|
-
const
|
|
1596
|
-
if (
|
|
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
|
-
|
|
1598
|
+
ee = V, M = i.decode(V);
|
|
1599
1599
|
}
|
|
1600
|
-
|
|
1600
|
+
r += ee.length, O.enqueue(M);
|
|
1601
1601
|
}
|
|
1602
1602
|
}
|
|
1603
1603
|
}
|
|
1604
|
-
async function
|
|
1605
|
-
let
|
|
1606
|
-
for (;
|
|
1607
|
-
|
|
1608
|
-
let
|
|
1609
|
-
const
|
|
1610
|
-
|
|
1611
|
-
setTimeout(
|
|
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
|
-
!
|
|
1614
|
+
!o && !u && (x.close(), g());
|
|
1615
1615
|
}
|
|
1616
|
-
class
|
|
1617
|
-
constructor(
|
|
1618
|
-
super(
|
|
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 (
|
|
1624
|
-
throw
|
|
1625
|
-
return new Promise((
|
|
1626
|
-
const
|
|
1627
|
-
for (const
|
|
1628
|
-
|
|
1629
|
-
},
|
|
1630
|
-
|
|
1631
|
-
},
|
|
1632
|
-
|
|
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
|
-
|
|
1634
|
+
E.push(h(M)), E.push(w(ee));
|
|
1635
1635
|
});
|
|
1636
1636
|
}
|
|
1637
1637
|
}
|
|
1638
1638
|
return {
|
|
1639
|
-
stream: new
|
|
1639
|
+
stream: new mt({
|
|
1640
1640
|
start(x) {
|
|
1641
|
-
|
|
1641
|
+
Se(x);
|
|
1642
1642
|
},
|
|
1643
1643
|
cancel(x) {
|
|
1644
|
-
|
|
1644
|
+
o = !0, c && s({ eventId: c }), g();
|
|
1645
1645
|
}
|
|
1646
1646
|
}),
|
|
1647
|
-
addCloseCb:
|
|
1647
|
+
addCloseCb: w,
|
|
1648
1648
|
closed() {
|
|
1649
1649
|
return u;
|
|
1650
1650
|
}
|
|
1651
1651
|
};
|
|
1652
1652
|
}
|
|
1653
|
-
class
|
|
1654
|
-
constructor({ WStream: t, RStream: n, trySend: s, log:
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
this.WStream = t, this.RStream = n, this.trySend = s, this.log =
|
|
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 } =
|
|
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 } =
|
|
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 =
|
|
1689
|
+
const n = je();
|
|
1690
1690
|
let s = null;
|
|
1691
|
-
const
|
|
1692
|
-
s =
|
|
1691
|
+
const r = new Promise((i) => {
|
|
1692
|
+
s = i;
|
|
1693
1693
|
});
|
|
1694
1694
|
this.startWriteStreamCbs[n] = s;
|
|
1695
|
-
const
|
|
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 && (
|
|
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:
|
|
1706
|
-
const
|
|
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:
|
|
1710
|
+
offset: r,
|
|
1711
1711
|
done: !!s
|
|
1712
1712
|
};
|
|
1713
|
-
|
|
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:
|
|
1736
|
-
const
|
|
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 && (
|
|
1740
|
-
const a = new
|
|
1741
|
-
return this.readStreamIterators[t] = a, this.trySend(t,
|
|
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(
|
|
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
|
|
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 !==
|
|
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"],
|
|
1790
|
-
|
|
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"],
|
|
1795
|
-
|
|
1794
|
+
const s = t["client-event-id"], r = this.startWriteStreamCbs[s];
|
|
1795
|
+
r && (r({
|
|
1796
1796
|
type: "error",
|
|
1797
|
-
error: new
|
|
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"],
|
|
1803
|
-
|
|
1802
|
+
const s = t["client-event-id"], r = this.readStreamIterators[s];
|
|
1803
|
+
r && (r.push({
|
|
1804
1804
|
type: "error",
|
|
1805
|
-
error: new
|
|
1806
|
-
}),
|
|
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
|
|
1815
|
+
const As = {
|
|
1816
1816
|
AUTHENTICATED: "authenticated"
|
|
1817
1817
|
};
|
|
1818
|
-
function
|
|
1818
|
+
function Ps() {
|
|
1819
1819
|
return globalThis.__instantDbSchemaHashStore = globalThis.__instantDbSchemaHashStore ?? /* @__PURE__ */ new WeakMap(), globalThis.__instantDbSchemaHashStore;
|
|
1820
1820
|
}
|
|
1821
|
-
function
|
|
1821
|
+
function Ms() {
|
|
1822
1822
|
return globalThis.__instantDbStore = globalThis.__instantDbStore ?? {}, globalThis.__instantDbStore;
|
|
1823
1823
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
class
|
|
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
|
|
1831
|
+
function vt(e) {
|
|
1832
1832
|
}
|
|
1833
|
-
function
|
|
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 =
|
|
1839
|
-
let
|
|
1840
|
-
function l(
|
|
1841
|
-
const h =
|
|
1842
|
-
for (const
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
function
|
|
1847
|
-
if (
|
|
1848
|
-
|
|
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 (
|
|
1852
|
-
|
|
1851
|
+
if (w.startsWith(":")) {
|
|
1852
|
+
r && r(w.slice(w.startsWith(": ") ? 2 : 1));
|
|
1853
1853
|
return;
|
|
1854
1854
|
}
|
|
1855
|
-
const h =
|
|
1855
|
+
const h = w.indexOf(":");
|
|
1856
1856
|
if (h !== -1) {
|
|
1857
|
-
const
|
|
1858
|
-
p(
|
|
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(
|
|
1861
|
+
p(w, "", w);
|
|
1862
1862
|
}
|
|
1863
|
-
function p(
|
|
1864
|
-
switch (
|
|
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
|
|
1877
|
+
new cn(`Invalid \`retry\` value: "${h}"`, {
|
|
1878
1878
|
type: "invalid-retry",
|
|
1879
1879
|
value: h,
|
|
1880
|
-
line:
|
|
1880
|
+
line: k
|
|
1881
1881
|
})
|
|
1882
1882
|
);
|
|
1883
1883
|
break;
|
|
1884
1884
|
default:
|
|
1885
1885
|
n(
|
|
1886
|
-
new
|
|
1887
|
-
`Unknown field "${
|
|
1888
|
-
{ type: "unknown-field", field:
|
|
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
|
|
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
|
|
1905
|
-
|
|
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:
|
|
1907
|
+
return { feed: l, reset: g };
|
|
1908
1908
|
}
|
|
1909
|
-
function
|
|
1909
|
+
function Us(e) {
|
|
1910
1910
|
const t = [];
|
|
1911
1911
|
let n = "", s = 0;
|
|
1912
1912
|
for (; s < e.length; ) {
|
|
1913
|
-
const
|
|
1913
|
+
const r = e.indexOf("\r", s), o = e.indexOf(`
|
|
1914
1914
|
`, s);
|
|
1915
|
-
let
|
|
1916
|
-
if (
|
|
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,
|
|
1921
|
-
t.push(a), 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
|
|
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,
|
|
1937
|
-
super(t), this.code = (s = n == null ? void 0 : n.code) != null ? s : void 0, this.message = (
|
|
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(
|
|
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(
|
|
1966
|
+
return t(fn(this), n);
|
|
1967
1967
|
}
|
|
1968
1968
|
}
|
|
1969
|
-
function
|
|
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
|
|
1974
|
-
return e instanceof Error ? "errors" in e && Array.isArray(e.errors) ? e.errors.map(
|
|
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
|
|
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
|
|
1986
|
+
var An = (e) => {
|
|
1987
1987
|
throw TypeError(e);
|
|
1988
|
-
},
|
|
1989
|
-
class
|
|
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,
|
|
1992
|
-
super(),
|
|
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
|
-
|
|
1995
|
-
const { body: c, redirected: u, status: l, headers:
|
|
1994
|
+
I(this, Ae).reset();
|
|
1995
|
+
const { body: c, redirected: u, status: l, headers: f } = i;
|
|
1996
1996
|
if (l === 204) {
|
|
1997
|
-
|
|
1997
|
+
fe(this, ie, Je).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
|
|
1998
1998
|
return;
|
|
1999
1999
|
}
|
|
2000
|
-
if (u ?
|
|
2001
|
-
|
|
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 (!(
|
|
2005
|
-
|
|
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 (
|
|
2008
|
+
if (I(this, X) === this.CLOSED)
|
|
2009
2009
|
return;
|
|
2010
|
-
|
|
2010
|
+
C(this, X, this.OPEN);
|
|
2011
2011
|
const p = new Event("open");
|
|
2012
|
-
if ((a =
|
|
2013
|
-
|
|
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
|
|
2017
|
-
let
|
|
2016
|
+
const m = new TextDecoder(), g = c.getReader();
|
|
2017
|
+
let w = !0;
|
|
2018
2018
|
do {
|
|
2019
|
-
const { done: h, value:
|
|
2020
|
-
|
|
2021
|
-
} while (
|
|
2022
|
-
}),
|
|
2023
|
-
|
|
2024
|
-
}),
|
|
2025
|
-
typeof
|
|
2026
|
-
const a = new (
|
|
2027
|
-
data:
|
|
2028
|
-
origin:
|
|
2029
|
-
lastEventId:
|
|
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
|
-
|
|
2032
|
-
}),
|
|
2033
|
-
|
|
2034
|
-
}),
|
|
2035
|
-
|
|
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
|
-
|
|
2039
|
+
C(this, ke, t);
|
|
2040
2040
|
else if (typeof t == "string")
|
|
2041
|
-
|
|
2041
|
+
C(this, ke, new URL(t, Ns()));
|
|
2042
2042
|
else
|
|
2043
2043
|
throw new Error("Invalid URL");
|
|
2044
2044
|
} catch {
|
|
2045
|
-
throw
|
|
2045
|
+
throw Ds("An invalid or illegal string was specified");
|
|
2046
2046
|
}
|
|
2047
|
-
|
|
2048
|
-
onEvent:
|
|
2049
|
-
onRetry:
|
|
2050
|
-
})),
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2085
|
+
return I(this, De);
|
|
2086
2086
|
}
|
|
2087
2087
|
set onerror(t) {
|
|
2088
|
-
|
|
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
|
|
2092
|
+
return I(this, Pe);
|
|
2093
2093
|
}
|
|
2094
2094
|
set onmessage(t) {
|
|
2095
|
-
|
|
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
|
|
2099
|
+
return I(this, Ve);
|
|
2100
2100
|
}
|
|
2101
2101
|
set onopen(t) {
|
|
2102
|
-
|
|
2102
|
+
C(this, Ve, t);
|
|
2103
2103
|
}
|
|
2104
2104
|
addEventListener(t, n, s) {
|
|
2105
|
-
const
|
|
2106
|
-
super.addEventListener(t,
|
|
2105
|
+
const r = n;
|
|
2106
|
+
super.addEventListener(t, r, s);
|
|
2107
2107
|
}
|
|
2108
2108
|
removeEventListener(t, n, s) {
|
|
2109
|
-
const
|
|
2110
|
-
super.removeEventListener(t,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2129
|
-
|
|
2130
|
-
},
|
|
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
|
-
|
|
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", ...
|
|
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 =
|
|
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
|
-
},
|
|
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
|
-
|
|
2155
|
+
Je = function(e, t) {
|
|
2156
2156
|
var n;
|
|
2157
|
-
|
|
2158
|
-
const s = new
|
|
2159
|
-
(n =
|
|
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
|
-
|
|
2167
|
+
jt = function(e, t) {
|
|
2168
2168
|
var n;
|
|
2169
|
-
if (
|
|
2169
|
+
if (I(this, X) === this.CLOSED)
|
|
2170
2170
|
return;
|
|
2171
|
-
|
|
2172
|
-
const s = new
|
|
2173
|
-
(n =
|
|
2174
|
-
},
|
|
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
|
-
|
|
2179
|
+
oe.CONNECTING = 0, /**
|
|
2180
2180
|
* ReadyState representing an EventSource connection that is open (eg connected)
|
|
2181
2181
|
*
|
|
2182
2182
|
* @public
|
|
2183
2183
|
*/
|
|
2184
|
-
|
|
2184
|
+
oe.OPEN = 1, /**
|
|
2185
2185
|
* ReadyState representing an EventSource connection that is closed (eg disconnected)
|
|
2186
2186
|
*
|
|
2187
2187
|
* @public
|
|
2188
2188
|
*/
|
|
2189
|
-
|
|
2190
|
-
Object.defineProperty(
|
|
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
|
|
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
|
|
2200
|
+
class Pn extends Event {
|
|
2201
2201
|
constructor(n, s) {
|
|
2202
2202
|
super(n);
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
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,
|
|
2211
|
+
initMessageEvent(n, s, r, o, i, a, c, u) {
|
|
2212
2212
|
}
|
|
2213
2213
|
}
|
|
2214
|
-
function
|
|
2215
|
-
let
|
|
2216
|
-
const
|
|
2217
|
-
|
|
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
|
-
|
|
2222
|
+
o = !0, r && r(), c();
|
|
2223
2223
|
}), {
|
|
2224
2224
|
next: async () => {
|
|
2225
2225
|
for (; ; ) {
|
|
2226
|
-
if (s() === "closed" ||
|
|
2226
|
+
if (s() === "closed" || o)
|
|
2227
2227
|
return c();
|
|
2228
|
-
const
|
|
2229
|
-
if (
|
|
2230
|
-
return { value:
|
|
2231
|
-
await new Promise((
|
|
2232
|
-
|
|
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(
|
|
2238
|
-
return n(a), Promise.reject(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
2283
|
-
let s,
|
|
2284
|
-
const
|
|
2285
|
-
messageEvent:
|
|
2286
|
-
fetch(h,
|
|
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
|
-
...
|
|
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":
|
|
2296
|
-
"@instantdb/core":
|
|
2295
|
+
"@instantdb/admin": _e,
|
|
2296
|
+
"@instantdb/core": _e
|
|
2297
2297
|
}
|
|
2298
2298
|
})
|
|
2299
|
-
}).then((
|
|
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
|
-
},
|
|
2305
|
+
}, f = (h) => {
|
|
2306
2306
|
c.push(h);
|
|
2307
2307
|
};
|
|
2308
2308
|
t && u(t);
|
|
2309
2309
|
let p = null;
|
|
2310
|
-
function
|
|
2311
|
-
if (!
|
|
2312
|
-
for (const
|
|
2310
|
+
function m(h) {
|
|
2311
|
+
if (!r)
|
|
2312
|
+
for (const k of a)
|
|
2313
2313
|
try {
|
|
2314
|
-
|
|
2315
|
-
} catch (
|
|
2316
|
-
console.error("Error in subscribeQuery callback",
|
|
2314
|
+
k(h);
|
|
2315
|
+
} catch (v) {
|
|
2316
|
+
console.error("Error in subscribeQuery callback", v);
|
|
2317
2317
|
}
|
|
2318
2318
|
}
|
|
2319
|
-
function
|
|
2320
|
-
var
|
|
2319
|
+
function g(h) {
|
|
2320
|
+
var k, v;
|
|
2321
2321
|
switch (h.op) {
|
|
2322
2322
|
case "sse-init": {
|
|
2323
|
-
const
|
|
2324
|
-
p = { machineId:
|
|
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
|
-
|
|
2328
|
+
m({
|
|
2329
2329
|
type: "ok",
|
|
2330
2330
|
data: h.result,
|
|
2331
|
-
pageInfo:
|
|
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 &&
|
|
2337
|
+
h.computations.length && m({
|
|
2338
2338
|
type: "ok",
|
|
2339
2339
|
data: h.computations[0]["instaql-result"],
|
|
2340
|
-
pageInfo:
|
|
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
|
-
|
|
2346
|
+
m({
|
|
2347
2347
|
type: "error",
|
|
2348
|
-
error: new
|
|
2348
|
+
error: new le({ body: h, status: h.status }),
|
|
2349
2349
|
get readyState() {
|
|
2350
|
-
return
|
|
2350
|
+
return me(i);
|
|
2351
2351
|
},
|
|
2352
2352
|
get isClosed() {
|
|
2353
|
-
return
|
|
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
|
|
2361
|
+
return i.onerror = (h) => {
|
|
2362
2362
|
if (s)
|
|
2363
|
-
s.text().then((
|
|
2364
|
-
let
|
|
2363
|
+
s.text().then((k) => {
|
|
2364
|
+
let v = { type: void 0, message: k };
|
|
2365
2365
|
try {
|
|
2366
|
-
|
|
2366
|
+
v = JSON.parse(k);
|
|
2367
2367
|
} catch {
|
|
2368
2368
|
}
|
|
2369
|
-
|
|
2369
|
+
m({
|
|
2370
2370
|
type: "error",
|
|
2371
|
-
error: new
|
|
2371
|
+
error: new le({
|
|
2372
2372
|
status: s.status,
|
|
2373
|
-
body:
|
|
2373
|
+
body: v
|
|
2374
2374
|
}),
|
|
2375
2375
|
get readyState() {
|
|
2376
|
-
return
|
|
2376
|
+
return me(i);
|
|
2377
2377
|
},
|
|
2378
2378
|
get isClosed() {
|
|
2379
|
-
return
|
|
2379
|
+
return me(i) === "closed";
|
|
2380
2380
|
},
|
|
2381
2381
|
sessionInfo: p
|
|
2382
2382
|
});
|
|
2383
2383
|
});
|
|
2384
2384
|
else {
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2385
|
+
const k = () => {
|
|
2386
|
+
m({
|
|
2387
2387
|
type: "error",
|
|
2388
|
-
error: new
|
|
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
|
|
2396
|
+
return me(i);
|
|
2397
2397
|
},
|
|
2398
2398
|
get isClosed() {
|
|
2399
|
-
return
|
|
2399
|
+
return me(i) === "closed";
|
|
2400
2400
|
},
|
|
2401
2401
|
sessionInfo: p
|
|
2402
2402
|
});
|
|
2403
2403
|
};
|
|
2404
|
-
if (
|
|
2405
|
-
|
|
2404
|
+
if (i.readyState === oe.CLOSED) {
|
|
2405
|
+
k();
|
|
2406
2406
|
return;
|
|
2407
2407
|
}
|
|
2408
2408
|
setTimeout(() => {
|
|
2409
|
-
|
|
2409
|
+
i.readyState !== oe.OPEN && k();
|
|
2410
2410
|
}, 5e3);
|
|
2411
2411
|
}
|
|
2412
|
-
},
|
|
2413
|
-
|
|
2412
|
+
}, i.onmessage = (h) => {
|
|
2413
|
+
g(JSON.parse(h.data));
|
|
2414
2414
|
}, {
|
|
2415
2415
|
close: () => {
|
|
2416
|
-
|
|
2416
|
+
r = !0;
|
|
2417
2417
|
for (const h of c)
|
|
2418
2418
|
try {
|
|
2419
2419
|
h();
|
|
2420
|
-
} catch (
|
|
2421
|
-
console.error("Error in onClose callback",
|
|
2420
|
+
} catch (k) {
|
|
2421
|
+
console.error("Error in onClose callback", k);
|
|
2422
2422
|
}
|
|
2423
|
-
|
|
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
|
|
2432
|
+
return me(i);
|
|
2433
2433
|
},
|
|
2434
2434
|
get isClosed() {
|
|
2435
|
-
return
|
|
2435
|
+
return me(i) === "closed";
|
|
2436
2436
|
},
|
|
2437
|
-
[Symbol.asyncIterator]:
|
|
2437
|
+
[Symbol.asyncIterator]: Ws.bind(this, u, f, l, () => 1)
|
|
2438
2438
|
};
|
|
2439
2439
|
}
|
|
2440
|
-
var
|
|
2441
|
-
Object.defineProperty(
|
|
2442
|
-
var
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
const
|
|
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
|
|
2456
|
-
const n = new
|
|
2455
|
+
function Un(e, t) {
|
|
2456
|
+
const n = new qs(), s = e.length;
|
|
2457
2457
|
if (s < 2)
|
|
2458
2458
|
return n;
|
|
2459
|
-
const
|
|
2460
|
-
let
|
|
2459
|
+
const r = (t == null ? void 0 : t.decode) || Dn;
|
|
2460
|
+
let o = 0;
|
|
2461
2461
|
do {
|
|
2462
|
-
const
|
|
2463
|
-
if (
|
|
2462
|
+
const i = Nt(e, o, s);
|
|
2463
|
+
if (i === -1)
|
|
2464
2464
|
break;
|
|
2465
|
-
const a =
|
|
2466
|
-
if (
|
|
2467
|
-
|
|
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 =
|
|
2471
|
-
n[c] === void 0 && (n[c] =
|
|
2472
|
-
} while (
|
|
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
|
|
2475
|
+
function Bs(e, t) {
|
|
2476
2476
|
const n = (t == null ? void 0 : t.encode) || encodeURIComponent, s = [];
|
|
2477
|
-
for (const
|
|
2478
|
-
const
|
|
2479
|
-
if (
|
|
2477
|
+
for (const r of Object.keys(e)) {
|
|
2478
|
+
const o = e[r];
|
|
2479
|
+
if (o === void 0)
|
|
2480
2480
|
continue;
|
|
2481
|
-
if (!
|
|
2482
|
-
throw new TypeError(`cookie name is invalid: ${
|
|
2483
|
-
const
|
|
2484
|
-
if (!
|
|
2485
|
-
throw new TypeError(`cookie val is invalid: ${
|
|
2486
|
-
s.push(`${
|
|
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
|
|
2491
|
-
const s = typeof e == "object" ? e : { ...n, name: e, value: String(t) },
|
|
2492
|
-
if (!
|
|
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
|
|
2495
|
-
if (!
|
|
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 + "=" +
|
|
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 (!
|
|
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 (!
|
|
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 (!
|
|
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
|
|
2550
|
-
const n = (t == null ? void 0 : t.decode) ||
|
|
2551
|
-
name:
|
|
2552
|
-
value: n(
|
|
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 =
|
|
2554
|
+
let a = r + 1;
|
|
2555
2555
|
for (; a < s; ) {
|
|
2556
|
-
const 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
|
-
|
|
2559
|
+
i.httpOnly = !0;
|
|
2560
2560
|
break;
|
|
2561
2561
|
case "secure":
|
|
2562
|
-
|
|
2562
|
+
i.secure = !0;
|
|
2563
2563
|
break;
|
|
2564
2564
|
case "partitioned":
|
|
2565
|
-
|
|
2565
|
+
i.partitioned = !0;
|
|
2566
2566
|
break;
|
|
2567
2567
|
case "domain":
|
|
2568
|
-
|
|
2568
|
+
i.domain = f;
|
|
2569
2569
|
break;
|
|
2570
2570
|
case "path":
|
|
2571
|
-
|
|
2571
|
+
i.path = f;
|
|
2572
2572
|
break;
|
|
2573
2573
|
case "max-age":
|
|
2574
|
-
|
|
2574
|
+
f && Hs.test(f) && (i.maxAge = Number(f));
|
|
2575
2575
|
break;
|
|
2576
2576
|
case "expires":
|
|
2577
|
-
if (!
|
|
2577
|
+
if (!f)
|
|
2578
2578
|
break;
|
|
2579
|
-
const p = new Date(
|
|
2580
|
-
Number.isFinite(p.valueOf()) && (
|
|
2579
|
+
const p = new Date(f);
|
|
2580
|
+
Number.isFinite(p.valueOf()) && (i.expires = p);
|
|
2581
2581
|
break;
|
|
2582
2582
|
case "priority":
|
|
2583
|
-
if (!
|
|
2583
|
+
if (!f)
|
|
2584
2584
|
break;
|
|
2585
|
-
const
|
|
2586
|
-
(
|
|
2585
|
+
const m = f.toLowerCase();
|
|
2586
|
+
(m === "low" || m === "medium" || m === "high") && (i.priority = m);
|
|
2587
2587
|
break;
|
|
2588
2588
|
case "samesite":
|
|
2589
|
-
if (!
|
|
2589
|
+
if (!f)
|
|
2590
2590
|
break;
|
|
2591
|
-
const
|
|
2592
|
-
(
|
|
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
|
|
2597
|
+
return i;
|
|
2598
2598
|
}
|
|
2599
|
-
function
|
|
2599
|
+
function Dt(e, t, n) {
|
|
2600
2600
|
const s = e.indexOf(";", t);
|
|
2601
2601
|
return s === -1 ? n : s;
|
|
2602
2602
|
}
|
|
2603
|
-
function
|
|
2603
|
+
function Nt(e, t, n) {
|
|
2604
2604
|
const s = e.indexOf("=", t);
|
|
2605
2605
|
return s < n ? s : -1;
|
|
2606
2606
|
}
|
|
2607
|
-
function
|
|
2608
|
-
let s = t,
|
|
2607
|
+
function be(e, t, n) {
|
|
2608
|
+
let s = t, r = n;
|
|
2609
2609
|
do {
|
|
2610
|
-
const
|
|
2611
|
-
if (
|
|
2610
|
+
const o = e.charCodeAt(s);
|
|
2611
|
+
if (o !== 32 && o !== 9)
|
|
2612
2612
|
break;
|
|
2613
|
-
} while (++s <
|
|
2614
|
-
for (;
|
|
2615
|
-
const
|
|
2616
|
-
if (
|
|
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
|
-
|
|
2618
|
+
r--;
|
|
2619
2619
|
}
|
|
2620
|
-
return e.slice(s,
|
|
2620
|
+
return e.slice(s, r);
|
|
2621
2621
|
}
|
|
2622
|
-
function
|
|
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
|
|
2632
|
-
return
|
|
2631
|
+
function Gs(e) {
|
|
2632
|
+
return Ks.call(e) === "[object Date]";
|
|
2633
2633
|
}
|
|
2634
|
-
|
|
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
|
|
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
|
|
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
|
|
2648
|
-
|
|
2649
|
-
const { adminToken: n, appId: s } = e,
|
|
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 && (
|
|
3283
|
+
return n && (r.authorization = `Bearer ${n}`), t ? fr(r, t) : r;
|
|
2654
3284
|
}
|
|
2655
|
-
function
|
|
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
|
|
2663
|
-
return
|
|
3292
|
+
function hr() {
|
|
3293
|
+
return lr() ? { cache: "no-store" } : {};
|
|
2664
3294
|
}
|
|
2665
|
-
async function
|
|
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
|
|
3299
|
+
return e(new le({ status: t.status, body: s }));
|
|
2670
3300
|
} catch {
|
|
2671
|
-
return e(new
|
|
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 =
|
|
3308
|
+
const n = hr(), s = {
|
|
2679
3309
|
...(t == null ? void 0 : t.headers) || {},
|
|
2680
|
-
"Instant-Admin-Version":
|
|
2681
|
-
"Instant-Core-Version":
|
|
2682
|
-
},
|
|
2683
|
-
if (
|
|
2684
|
-
const
|
|
2685
|
-
return Promise.resolve(
|
|
2686
|
-
}
|
|
2687
|
-
return
|
|
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
|
|
2690
|
-
var t, n,
|
|
3319
|
+
function yr(e) {
|
|
3320
|
+
var t, n, Wn;
|
|
2691
3321
|
return t = class {
|
|
2692
|
-
constructor(
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
this.url =
|
|
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(
|
|
2702
|
-
this.source.onopen =
|
|
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(
|
|
2708
|
-
this.source.onmessage =
|
|
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(
|
|
2714
|
-
this.source.onerror =
|
|
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(),
|
|
2723
|
-
return new
|
|
2724
|
-
messageEvent:
|
|
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":
|
|
2734
|
-
"@instantdb/core":
|
|
3363
|
+
"@instantdb/admin": _e,
|
|
3364
|
+
"@instantdb/core": _e
|
|
2735
3365
|
}
|
|
2736
3366
|
})
|
|
2737
3367
|
});
|
|
2738
3368
|
}
|
|
2739
3369
|
});
|
|
2740
|
-
},
|
|
3370
|
+
}, d(t, "OPEN", oe.OPEN), d(t, "CONNECTING", oe.CONNECTING), d(t, "CLOSED", oe.CLOSED), t;
|
|
2741
3371
|
}
|
|
2742
|
-
function
|
|
3372
|
+
function mr(e) {
|
|
2743
3373
|
var n, s;
|
|
2744
|
-
(!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
|
|
3381
|
+
return new Lt(t);
|
|
2752
3382
|
}
|
|
2753
|
-
function
|
|
2754
|
-
return (Array.isArray(e) ? e : [e]).flatMap(
|
|
3383
|
+
function pn(e) {
|
|
3384
|
+
return (Array.isArray(e) ? e : [e]).flatMap(ms);
|
|
2755
3385
|
}
|
|
2756
|
-
class
|
|
3386
|
+
class br {
|
|
2757
3387
|
constructor(t) {
|
|
2758
|
-
|
|
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:
|
|
3394
|
+
headers: P(this.config)
|
|
2765
3395
|
})).sessions || {};
|
|
2766
3396
|
}
|
|
2767
3397
|
}
|
|
2768
|
-
class
|
|
3398
|
+
class wr {
|
|
2769
3399
|
constructor(t) {
|
|
2770
|
-
|
|
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
|
-
|
|
3414
|
+
d(this, "generateMagicCode", async (t) => A(`${this.config.apiURI}/admin/magic_code?app_id=${this.config.appId}`, {
|
|
2785
3415
|
method: "POST",
|
|
2786
|
-
headers:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
2833
|
-
const
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
2882
|
-
const n = Object.entries(t).map(([
|
|
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:
|
|
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
|
-
|
|
2905
|
-
const n = Object.entries(t).map(([
|
|
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:
|
|
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
|
-
|
|
2919
|
-
const s = t.headers.get("cookie") || "",
|
|
2920
|
-
if (!
|
|
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
|
|
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:
|
|
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:
|
|
3569
|
+
headers: P(s),
|
|
2940
3570
|
body: JSON.stringify(n)
|
|
2941
3571
|
});
|
|
2942
3572
|
}
|
|
2943
3573
|
}
|
|
2944
|
-
const
|
|
2945
|
-
class
|
|
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
|
-
|
|
2948
|
-
|
|
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
|
-
|
|
2958
|
-
const
|
|
2959
|
-
...
|
|
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 && (
|
|
2963
|
-
let
|
|
2964
|
-
if (
|
|
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
|
-
|
|
3597
|
+
r["content-length"] = s.fileSize.toString();
|
|
2968
3598
|
}
|
|
2969
|
-
let
|
|
3599
|
+
let i = {
|
|
2970
3600
|
method: "PUT",
|
|
2971
|
-
headers:
|
|
3601
|
+
headers: r,
|
|
2972
3602
|
body: n,
|
|
2973
|
-
...
|
|
3603
|
+
...o && { duplex: o }
|
|
2974
3604
|
};
|
|
2975
|
-
return A(`${this.config.apiURI}/admin/storage/upload?app_id=${this.config.appId}`,
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
3015
|
-
const { data:
|
|
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:
|
|
3647
|
+
headers: P(this.config),
|
|
3018
3648
|
body: JSON.stringify({
|
|
3019
3649
|
app_id: this.config.appId,
|
|
3020
3650
|
filename: t
|
|
3021
3651
|
})
|
|
3022
|
-
}),
|
|
3023
|
-
|
|
3024
|
-
const { ok: a } = await fetch(
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
|
3068
|
-
class
|
|
3697
|
+
var Le;
|
|
3698
|
+
class Sr {
|
|
3069
3699
|
constructor(t) {
|
|
3070
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3091
|
-
|
|
3720
|
+
d(this, "createWriteStream", (t) => y(this, Le).call(this).createWriteStream(t));
|
|
3721
|
+
J(this, Le, t);
|
|
3092
3722
|
}
|
|
3093
3723
|
}
|
|
3094
|
-
|
|
3095
|
-
function
|
|
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
|
|
3106
|
-
const
|
|
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
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
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
|
-
|
|
3130
|
-
const n = new
|
|
3760
|
+
d(this, "asUser", (t) => {
|
|
3761
|
+
const n = new Bt({
|
|
3131
3762
|
...this.config
|
|
3132
3763
|
});
|
|
3133
|
-
return n.impersonationOpts = t, n.storage = new
|
|
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
|
-
|
|
3151
|
-
t && n && "ruleParams" in n && (t = { $$ruleParams: n.ruleParams, ...t }), this.config.disableValidation ||
|
|
3152
|
-
const s = n.fetchOpts || {},
|
|
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
|
-
...
|
|
3158
|
-
...
|
|
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
|
-
|
|
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:
|
|
3822
|
+
headers: P(this.config, this.impersonationOpts),
|
|
3192
3823
|
body: JSON.stringify({
|
|
3193
|
-
steps:
|
|
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
|
-
|
|
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
|
|
3857
|
+
const r = await A(`${this.config.apiURI}/admin/query_perms_check?app_id=${this.config.appId}`, {
|
|
3227
3858
|
method: "POST",
|
|
3228
|
-
headers:
|
|
3859
|
+
headers: P(this.config, this.impersonationOpts),
|
|
3229
3860
|
body: JSON.stringify(s)
|
|
3230
3861
|
});
|
|
3231
3862
|
return {
|
|
3232
|
-
result:
|
|
3233
|
-
checkResults:
|
|
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
|
-
|
|
3885
|
+
d(this, "debugTransact", (t, n) => {
|
|
3255
3886
|
const s = {
|
|
3256
|
-
steps:
|
|
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:
|
|
3894
|
+
headers: P(this.config, this.impersonationOpts),
|
|
3264
3895
|
body: JSON.stringify(s)
|
|
3265
3896
|
});
|
|
3266
3897
|
});
|
|
3267
|
-
|
|
3898
|
+
j(this, dt, (t) => {
|
|
3268
3899
|
var n;
|
|
3269
|
-
if (t.target !==
|
|
3270
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3906
|
+
j(this, lt, (t) => {
|
|
3276
3907
|
var n;
|
|
3277
|
-
if (t.target !==
|
|
3278
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3914
|
+
j(this, ht, (t) => {
|
|
3284
3915
|
var n;
|
|
3285
|
-
if (t.target !==
|
|
3286
|
-
|
|
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
|
-
|
|
3920
|
+
y(this, B).info("[socket][error]", t.target.id), (n = y(this, q)) == null || n.onConnectionStatusChange("closed");
|
|
3290
3921
|
});
|
|
3291
|
-
|
|
3292
|
-
var s,
|
|
3293
|
-
if (t.target !==
|
|
3294
|
-
|
|
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 (
|
|
3929
|
+
switch (y(this, B).info("[receive]", n), n.op) {
|
|
3299
3930
|
case "start-stream-ok": {
|
|
3300
|
-
(s =
|
|
3931
|
+
(s = y(this, q)) == null || s.onStartStreamOk(n);
|
|
3301
3932
|
break;
|
|
3302
3933
|
}
|
|
3303
3934
|
case "stream-flushed": {
|
|
3304
|
-
(
|
|
3935
|
+
(r = y(this, q)) == null || r.onStreamFlushed(n);
|
|
3305
3936
|
break;
|
|
3306
3937
|
}
|
|
3307
3938
|
case "append-failed": {
|
|
3308
|
-
(
|
|
3939
|
+
(o = y(this, q)) == null || o.onAppendFailed(n);
|
|
3309
3940
|
break;
|
|
3310
3941
|
}
|
|
3311
3942
|
case "stream-append": {
|
|
3312
|
-
(
|
|
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 =
|
|
3952
|
+
(c = y(this, q)) == null || c.onRecieveError(n);
|
|
3322
3953
|
break;
|
|
3323
3954
|
}
|
|
3324
3955
|
}
|
|
3325
3956
|
break;
|
|
3326
3957
|
}
|
|
3327
3958
|
}
|
|
3328
|
-
|
|
3959
|
+
R(this, W, Jn).call(this);
|
|
3329
3960
|
});
|
|
3330
|
-
this.config =
|
|
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 ||
|
|
3369
|
-
const
|
|
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
|
-
...
|
|
4002
|
+
...P(this.config, this.impersonationOpts)
|
|
3372
4003
|
}, a = !!this.config.schema;
|
|
3373
|
-
return
|
|
3374
|
-
headers:
|
|
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
|
-
|
|
3381
|
-
|
|
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
|
-
...
|
|
3384
|
-
}, n = !!this.config.schema, s =
|
|
3385
|
-
return
|
|
3386
|
-
},
|
|
3387
|
-
return
|
|
3388
|
-
},
|
|
3389
|
-
const s =
|
|
3390
|
-
|
|
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
|
-
},
|
|
3394
|
-
|
|
3395
|
-
const t = new
|
|
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
|
-
|
|
4030
|
+
R(this, W, Fn).call(this, n, s);
|
|
3400
4031
|
},
|
|
3401
|
-
log:
|
|
4032
|
+
log: y(this, B)
|
|
3402
4033
|
});
|
|
3403
|
-
return
|
|
3404
|
-
},
|
|
3405
|
-
return
|
|
3406
|
-
},
|
|
3407
|
-
return !
|
|
3408
|
-
},
|
|
3409
|
-
if (
|
|
3410
|
-
const t =
|
|
3411
|
-
|
|
3412
|
-
}
|
|
3413
|
-
},
|
|
3414
|
-
let
|
|
3415
|
-
var
|
|
3416
|
-
function
|
|
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
|
|
3429
|
-
t = 0, s.enqueue(
|
|
4059
|
+
const r = n.slice(t);
|
|
4060
|
+
t = 0, s.enqueue(r);
|
|
3430
4061
|
}
|
|
3431
4062
|
});
|
|
3432
4063
|
}
|
|
3433
|
-
function
|
|
3434
|
-
const t = e.appId ||
|
|
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 ||
|
|
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 },
|
|
3445
|
-
|
|
3446
|
-
const
|
|
3447
|
-
async function
|
|
3448
|
-
const
|
|
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
|
|
3454
|
-
|
|
3455
|
-
const h =
|
|
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
|
-
|
|
4088
|
+
tt(p)
|
|
3458
4089
|
) : h;
|
|
3459
4090
|
} catch {
|
|
3460
|
-
const
|
|
3461
|
-
return p ?
|
|
3462
|
-
|
|
3463
|
-
) :
|
|
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,
|
|
3467
|
-
var
|
|
3468
|
-
const p =
|
|
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
|
|
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
|
|
4107
|
+
return f ? p.pipeThrough(tt(f)) : p;
|
|
3477
4108
|
}
|
|
3478
|
-
async function c(l,
|
|
3479
|
-
const
|
|
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
|
|
3484
|
-
const
|
|
3485
|
-
return p ?
|
|
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
|
|
3489
|
-
const
|
|
4119
|
+
var m;
|
|
4120
|
+
const f = await o.query({
|
|
3490
4121
|
$streams: { $: { where: { clientId: l } } }
|
|
3491
|
-
}), p = (
|
|
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:
|
|
4126
|
+
resumableStream: i,
|
|
3496
4127
|
resumeExistingStream: a,
|
|
3497
4128
|
createNewResumableStream: c,
|
|
3498
4129
|
hasExistingStream: u
|
|
3499
4130
|
};
|
|
3500
4131
|
}
|
|
3501
4132
|
export {
|
|
3502
|
-
|
|
4133
|
+
$r as createResumableStreamContext
|
|
3503
4134
|
};
|