@nhtio/swarm 1.20250424.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +9 -0
- package/README.md +5 -0
- package/errors-BsRN4TW4.mjs +82 -0
- package/errors-BsRN4TW4.mjs.map +1 -0
- package/errors-DTZFdRbq.js +4 -0
- package/errors-DTZFdRbq.js.map +1 -0
- package/errors.cjs +2 -0
- package/errors.cjs.map +1 -0
- package/errors.d.ts +59 -0
- package/errors.mjs +7 -0
- package/errors.mjs.map +1 -0
- package/index.cjs +4 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +12 -0
- package/index.mjs +1538 -0
- package/index.mjs.map +1 -0
- package/lib/browser.d.ts +6 -0
- package/lib/class_swarm.d.ts +104 -0
- package/lib/common.d.ts +26 -0
- package/lib/emitter.d.ts +33 -0
- package/lib/logger.d.ts +67 -0
- package/lib/symbols.d.ts +5 -0
- package/package.json +31 -0
- package/tsconfig.json +41 -0
- package/types-C0eRuyk9.js +2 -0
- package/types-C0eRuyk9.js.map +1 -0
- package/types-CBFnAS2P.mjs +7 -0
- package/types-CBFnAS2P.mjs.map +1 -0
- package/types.cjs +2 -0
- package/types.cjs.map +1 -0
- package/types.d.ts +39 -0
- package/types.mjs +2 -0
- package/types.mjs.map +1 -0
package/index.mjs
ADDED
|
@@ -0,0 +1,1538 @@
|
|
|
1
|
+
var lt = Object.defineProperty;
|
|
2
|
+
var ht = Object.getPrototypeOf;
|
|
3
|
+
var pt = Reflect.get;
|
|
4
|
+
var Me = (e) => {
|
|
5
|
+
throw TypeError(e);
|
|
6
|
+
};
|
|
7
|
+
var mt = (e, t, r) => t in e ? lt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
8
|
+
var U = (e, t, r) => mt(e, typeof t != "symbol" ? t + "" : t, r), pe = (e, t, r) => t.has(e) || Me("Cannot " + r);
|
|
9
|
+
var a = (e, t, r) => (pe(e, t, "read from private field"), r ? r.call(e) : t.get(e)), v = (e, t, r) => t.has(e) ? Me("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), g = (e, t, r, n) => (pe(e, t, "write to private field"), n ? n.call(e, r) : t.set(e, r), r), d = (e, t, r) => (pe(e, t, "access private method"), r);
|
|
10
|
+
var Se = (e, t, r) => pt(ht(e), r, t);
|
|
11
|
+
import { t as Qr } from "./types-CBFnAS2P.mjs";
|
|
12
|
+
import { A as gt, U as wt, R as vt } from "./errors-BsRN4TW4.mjs";
|
|
13
|
+
import { e as Yr } from "./errors-BsRN4TW4.mjs";
|
|
14
|
+
const Fe = () => typeof window < "u" && typeof window.navigator < "u" && typeof window.navigator.userAgent < "u", bt = () => typeof ServiceWorkerGlobalScope < "u" && self instanceof ServiceWorkerGlobalScope, yt = () => typeof process < "u" && typeof process.versions < "u" && !!process.versions.node, Et = () => typeof window < "u" && typeof window.navigator < "u" && window.navigator.userAgent.includes("Safari") && !window.navigator.userAgent.includes("Chrome");
|
|
15
|
+
function _t(e) {
|
|
16
|
+
return typeof e == "object" && e !== null && "Math" in e;
|
|
17
|
+
}
|
|
18
|
+
const J = () => {
|
|
19
|
+
const t = [
|
|
20
|
+
typeof window < "u" ? window : void 0,
|
|
21
|
+
typeof self < "u" ? self : void 0,
|
|
22
|
+
typeof global < "u" ? global : void 0
|
|
23
|
+
].filter((r) => _t(r));
|
|
24
|
+
if (t.length === 0)
|
|
25
|
+
throw new Error("No global object found");
|
|
26
|
+
return t[0];
|
|
27
|
+
}, F = (e) => {
|
|
28
|
+
const t = J(), r = new Uint8Array(e);
|
|
29
|
+
if (typeof t.crypto < "u" && typeof t.crypto.getRandomValues == "function")
|
|
30
|
+
t.crypto.getRandomValues(r);
|
|
31
|
+
else
|
|
32
|
+
for (let n = 0; n < e; n++)
|
|
33
|
+
r[n] = Math.floor(Math.random() * 256);
|
|
34
|
+
return Array.from(r).map((n) => n.toString(16).padStart(2, "0")).join("");
|
|
35
|
+
}, K = Symbol("nhtio.swarm"), ie = Symbol("nhtio.swarm.logger"), Lt = {
|
|
36
|
+
EMERG: (e) => [
|
|
37
|
+
`%c${e}`,
|
|
38
|
+
"color: white; background: #FF0000; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
39
|
+
],
|
|
40
|
+
ALERT: (e) => [
|
|
41
|
+
`%c${e}`,
|
|
42
|
+
"color: white; background: #FF5555; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
43
|
+
],
|
|
44
|
+
CRIT: (e) => [
|
|
45
|
+
`%c${e}`,
|
|
46
|
+
"color: white; background: #FF6F00; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
47
|
+
],
|
|
48
|
+
ERROR: (e) => [
|
|
49
|
+
`%c${e}`,
|
|
50
|
+
"color: black; background: #FFA500; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
51
|
+
],
|
|
52
|
+
WARNING: (e) => [
|
|
53
|
+
`%c${e}`,
|
|
54
|
+
"color: black; background: #FFD700; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
55
|
+
],
|
|
56
|
+
NOTICE: (e) => [
|
|
57
|
+
`%c${e}`,
|
|
58
|
+
"color: black; background: #00CED1; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
59
|
+
],
|
|
60
|
+
INFO: (e) => [
|
|
61
|
+
`%c${e}`,
|
|
62
|
+
"color: white; background: #1E90FF; font-weight: normal; padding: 2px 6px; border-radius: 2px"
|
|
63
|
+
],
|
|
64
|
+
DEBUG: (e) => [`%c${e}`, "color: #AAAAAA; font-style: italic; padding: 2px 6px"]
|
|
65
|
+
};
|
|
66
|
+
var P = /* @__PURE__ */ ((e) => (e[e.EMERG = 0] = "EMERG", e[e.ALERT = 1] = "ALERT", e[e.CRIT = 2] = "CRIT", e[e.ERROR = 3] = "ERROR", e[e.WARNING = 4] = "WARNING", e[e.NOTICE = 5] = "NOTICE", e[e.INFO = 6] = "INFO", e[e.DEBUG = 7] = "DEBUG", e))(P || {});
|
|
67
|
+
const Rt = {
|
|
68
|
+
BROWSER: (e) => [
|
|
69
|
+
`%c${e}`,
|
|
70
|
+
"color: white; background: #3949AB; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
71
|
+
],
|
|
72
|
+
WORKER: (e) => [
|
|
73
|
+
`%c${e}`,
|
|
74
|
+
"color: white; background: #5E35B1; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
75
|
+
],
|
|
76
|
+
SSR: (e) => [
|
|
77
|
+
`%c${e}`,
|
|
78
|
+
"color: white; background: #607D8B; font-weight: bold; padding: 2px 6px; border-radius: 2px"
|
|
79
|
+
],
|
|
80
|
+
UNKNOWN: (e) => [
|
|
81
|
+
`%c${e}`,
|
|
82
|
+
"color: black; background: #E0E0E0; font-weight: bold; font-style: italic; padding: 2px 6px; border-radius: 2px"
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
var Ke = /* @__PURE__ */ ((e) => (e.EMERG = "error", e.ALERT = "error", e.CRIT = "error", e.ERROR = "error", e.WARNING = "warn", e.NOTICE = "info", e.INFO = "info", e.DEBUG = "debug", e))(Ke || {}), ee, te, z, re, H, B, w, je, y;
|
|
86
|
+
class Ae {
|
|
87
|
+
constructor(t = 3) {
|
|
88
|
+
v(this, w);
|
|
89
|
+
v(this, ee);
|
|
90
|
+
v(this, te);
|
|
91
|
+
v(this, z);
|
|
92
|
+
v(this, re);
|
|
93
|
+
v(this, H);
|
|
94
|
+
v(this, B);
|
|
95
|
+
g(this, B, t), g(this, ee, Fe()), g(this, te, bt()), g(this, z, yt()), g(this, re, Et());
|
|
96
|
+
}
|
|
97
|
+
get level() {
|
|
98
|
+
return P[a(this, B)];
|
|
99
|
+
}
|
|
100
|
+
set level(t) {
|
|
101
|
+
g(this, B, P[t.toUpperCase()]);
|
|
102
|
+
}
|
|
103
|
+
EMERG(...t) {
|
|
104
|
+
d(this, w, y).call(this, "EMERG", ...t);
|
|
105
|
+
}
|
|
106
|
+
ALERT(...t) {
|
|
107
|
+
d(this, w, y).call(this, "ALERT", ...t);
|
|
108
|
+
}
|
|
109
|
+
CRIT(...t) {
|
|
110
|
+
d(this, w, y).call(this, "CRIT", ...t);
|
|
111
|
+
}
|
|
112
|
+
ERROR(...t) {
|
|
113
|
+
d(this, w, y).call(this, "ERROR", ...t);
|
|
114
|
+
}
|
|
115
|
+
WARNING(...t) {
|
|
116
|
+
d(this, w, y).call(this, "WARNING", ...t);
|
|
117
|
+
}
|
|
118
|
+
NOTICE(...t) {
|
|
119
|
+
d(this, w, y).call(this, "NOTICE", ...t);
|
|
120
|
+
}
|
|
121
|
+
INFO(...t) {
|
|
122
|
+
d(this, w, y).call(this, "INFO", ...t);
|
|
123
|
+
}
|
|
124
|
+
DEBUG(...t) {
|
|
125
|
+
d(this, w, y).call(this, "DEBUG", ...t);
|
|
126
|
+
}
|
|
127
|
+
emerg(...t) {
|
|
128
|
+
d(this, w, y).call(this, "EMERG", ...t);
|
|
129
|
+
}
|
|
130
|
+
alert(...t) {
|
|
131
|
+
d(this, w, y).call(this, "ALERT", ...t);
|
|
132
|
+
}
|
|
133
|
+
crit(...t) {
|
|
134
|
+
d(this, w, y).call(this, "CRIT", ...t);
|
|
135
|
+
}
|
|
136
|
+
error(...t) {
|
|
137
|
+
d(this, w, y).call(this, "ERROR", ...t);
|
|
138
|
+
}
|
|
139
|
+
warning(...t) {
|
|
140
|
+
d(this, w, y).call(this, "WARNING", ...t);
|
|
141
|
+
}
|
|
142
|
+
notice(...t) {
|
|
143
|
+
d(this, w, y).call(this, "NOTICE", ...t);
|
|
144
|
+
}
|
|
145
|
+
info(...t) {
|
|
146
|
+
d(this, w, y).call(this, "INFO", ...t);
|
|
147
|
+
}
|
|
148
|
+
debug(...t) {
|
|
149
|
+
d(this, w, y).call(this, "DEBUG", ...t);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
ee = new WeakMap(), te = new WeakMap(), z = new WeakMap(), re = new WeakMap(), H = new WeakMap(), B = new WeakMap(), w = new WeakSet(), je = function() {
|
|
153
|
+
let t;
|
|
154
|
+
return a(this, ee) ? t = "BROWSER" : a(this, te) ? t = "WORKER" : a(this, z) ? t = "SSR" : t = "UNKNOWN", Rt[t](t);
|
|
155
|
+
}, y = function(t, ...r) {
|
|
156
|
+
t = t.toUpperCase();
|
|
157
|
+
const n = P[t], s = P[a(this, B)];
|
|
158
|
+
if (n > s) return;
|
|
159
|
+
const [o, i] = d(this, w, je).call(this), [u, c] = Lt[t](t), f = [
|
|
160
|
+
`${o}${u}${a(this, H) ? `%c ${a(this, H)}` : ""}`,
|
|
161
|
+
i,
|
|
162
|
+
c
|
|
163
|
+
];
|
|
164
|
+
for (a(this, H) && f.push("color: inherit"), f.push(...r); f[f.length - 1] === void 0; ) f.pop();
|
|
165
|
+
a(this, re) || a(this, z) ? console[Ke[t]](...f) : (console.groupCollapsed(...f), console.debug(new Error("stack").stack.split(`
|
|
166
|
+
`).slice(3).join(`
|
|
167
|
+
`)), console.groupEnd());
|
|
168
|
+
};
|
|
169
|
+
const Tt = () => {
|
|
170
|
+
const e = J();
|
|
171
|
+
return typeof e.SWARM_LOG_LEVEL == "string" && e.SWARM_LOG_LEVEL.toUpperCase() in P ? e.SWARM_LOG_LEVEL : 3;
|
|
172
|
+
}, ze = () => {
|
|
173
|
+
const e = J();
|
|
174
|
+
if (typeof e[ie] < "u" && e[ie] instanceof Ae)
|
|
175
|
+
return e[ie];
|
|
176
|
+
const t = Tt(), r = P[t], n = new Ae(r);
|
|
177
|
+
return e[ie] = n, n;
|
|
178
|
+
}, jr = (e) => {
|
|
179
|
+
const t = J(), r = ze();
|
|
180
|
+
t.SWARM_LOG_LEVEL = e.toUpperCase(), r.level = e;
|
|
181
|
+
};
|
|
182
|
+
var fe = { exports: {} };
|
|
183
|
+
fe.exports;
|
|
184
|
+
function Ee() {
|
|
185
|
+
}
|
|
186
|
+
Ee.prototype = {
|
|
187
|
+
on: function(e, t, r) {
|
|
188
|
+
var n = this.e || (this.e = {});
|
|
189
|
+
return (n[e] || (n[e] = [])).push({
|
|
190
|
+
fn: t,
|
|
191
|
+
ctx: r
|
|
192
|
+
}), this;
|
|
193
|
+
},
|
|
194
|
+
once: function(e, t, r) {
|
|
195
|
+
var n = this;
|
|
196
|
+
function s() {
|
|
197
|
+
n.off(e, s), t.apply(r, arguments);
|
|
198
|
+
}
|
|
199
|
+
return s._ = t, this.on(e, s, r);
|
|
200
|
+
},
|
|
201
|
+
emit: function(e) {
|
|
202
|
+
var t = [].slice.call(arguments, 1), r = ((this.e || (this.e = {}))[e] || []).slice(), n = 0, s = r.length;
|
|
203
|
+
for (n; n < s; n++)
|
|
204
|
+
r[n].fn.apply(r[n].ctx, t);
|
|
205
|
+
return this;
|
|
206
|
+
},
|
|
207
|
+
off: function(e, t) {
|
|
208
|
+
var r = this.e || (this.e = {}), n = r[e], s = [];
|
|
209
|
+
if (n && t)
|
|
210
|
+
for (var o = 0, i = n.length; o < i; o++)
|
|
211
|
+
n[o].fn !== t && n[o].fn._ !== t && s.push(n[o]);
|
|
212
|
+
return s.length ? r[e] = s : delete r[e], this;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
fe.exports = Ee;
|
|
216
|
+
var kt = fe.exports.TinyEmitter = Ee;
|
|
217
|
+
fe.exports;
|
|
218
|
+
class Ne extends kt {
|
|
219
|
+
/**
|
|
220
|
+
* Subscribe to an event with a typed listener.
|
|
221
|
+
*/
|
|
222
|
+
on(t, r, n) {
|
|
223
|
+
return super.on(t, r, n), this;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Subscribe once to an event.
|
|
227
|
+
*/
|
|
228
|
+
once(t, r, n) {
|
|
229
|
+
return super.once(t, r, n), this;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Emit an event, enforcing that the args match Events[E].
|
|
233
|
+
*/
|
|
234
|
+
emit(t, ...r) {
|
|
235
|
+
return super.emit(t, ...r), this;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Remove a listener.
|
|
239
|
+
*/
|
|
240
|
+
off(t, r) {
|
|
241
|
+
return super.off(t, r), this;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function It(e) {
|
|
245
|
+
return e && typeof e.then == "function";
|
|
246
|
+
}
|
|
247
|
+
Promise.resolve(!1);
|
|
248
|
+
var Ct = Promise.resolve(!0), C = Promise.resolve();
|
|
249
|
+
function x(e, t) {
|
|
250
|
+
return e || (e = 0), new Promise(function(r) {
|
|
251
|
+
return setTimeout(function() {
|
|
252
|
+
return r(t);
|
|
253
|
+
}, e);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function Mt(e, t) {
|
|
257
|
+
return Math.floor(Math.random() * (t - e + 1) + e);
|
|
258
|
+
}
|
|
259
|
+
function ne() {
|
|
260
|
+
return Math.random().toString(36).substring(2);
|
|
261
|
+
}
|
|
262
|
+
var me = 0;
|
|
263
|
+
function se() {
|
|
264
|
+
var e = Date.now() * 1e3;
|
|
265
|
+
return e <= me && (e = me + 1), me = e, e;
|
|
266
|
+
}
|
|
267
|
+
function St() {
|
|
268
|
+
return typeof navigator < "u" && typeof navigator.locks < "u" && typeof navigator.locks.request == "function";
|
|
269
|
+
}
|
|
270
|
+
var At = se, Nt = "native";
|
|
271
|
+
function Ot(e) {
|
|
272
|
+
var t = {
|
|
273
|
+
time: se(),
|
|
274
|
+
messagesCallback: null,
|
|
275
|
+
bc: new BroadcastChannel(e),
|
|
276
|
+
subFns: []
|
|
277
|
+
// subscriberFunctions
|
|
278
|
+
};
|
|
279
|
+
return t.bc.onmessage = function(r) {
|
|
280
|
+
t.messagesCallback && t.messagesCallback(r.data);
|
|
281
|
+
}, t;
|
|
282
|
+
}
|
|
283
|
+
function Pt(e) {
|
|
284
|
+
e.bc.close(), e.subFns = [];
|
|
285
|
+
}
|
|
286
|
+
function xt(e, t) {
|
|
287
|
+
try {
|
|
288
|
+
return e.bc.postMessage(t, !1), C;
|
|
289
|
+
} catch (r) {
|
|
290
|
+
return Promise.reject(r);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function Bt(e, t) {
|
|
294
|
+
e.messagesCallback = t;
|
|
295
|
+
}
|
|
296
|
+
function Dt() {
|
|
297
|
+
if (typeof globalThis < "u" && globalThis.Deno && globalThis.Deno.args)
|
|
298
|
+
return !0;
|
|
299
|
+
if ((typeof window < "u" || typeof self < "u") && typeof BroadcastChannel == "function") {
|
|
300
|
+
if (BroadcastChannel._pubkey)
|
|
301
|
+
throw new Error("BroadcastChannel: Do not overwrite window.BroadcastChannel with this module, this is not a polyfill");
|
|
302
|
+
return !0;
|
|
303
|
+
} else
|
|
304
|
+
return !1;
|
|
305
|
+
}
|
|
306
|
+
function $t() {
|
|
307
|
+
return 150;
|
|
308
|
+
}
|
|
309
|
+
var Gt = {
|
|
310
|
+
create: Ot,
|
|
311
|
+
close: Pt,
|
|
312
|
+
onMessage: Bt,
|
|
313
|
+
postMessage: xt,
|
|
314
|
+
canBeUsed: Dt,
|
|
315
|
+
type: Nt,
|
|
316
|
+
averageResponseTime: $t,
|
|
317
|
+
microSeconds: At
|
|
318
|
+
};
|
|
319
|
+
class He {
|
|
320
|
+
constructor(t) {
|
|
321
|
+
U(this, "ttl");
|
|
322
|
+
U(this, "map", /* @__PURE__ */ new Map());
|
|
323
|
+
/**
|
|
324
|
+
* Creating calls to setTimeout() is expensive,
|
|
325
|
+
* so we only do that if there is not timeout already open.
|
|
326
|
+
*/
|
|
327
|
+
U(this, "_to", !1);
|
|
328
|
+
this.ttl = t;
|
|
329
|
+
}
|
|
330
|
+
has(t) {
|
|
331
|
+
return this.map.has(t);
|
|
332
|
+
}
|
|
333
|
+
add(t) {
|
|
334
|
+
this.map.set(t, Je()), this._to || (this._to = !0, setTimeout(() => {
|
|
335
|
+
this._to = !1, Wt(this);
|
|
336
|
+
}, 0));
|
|
337
|
+
}
|
|
338
|
+
clear() {
|
|
339
|
+
this.map.clear();
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function Wt(e) {
|
|
343
|
+
const t = Je() - e.ttl, r = e.map[Symbol.iterator]();
|
|
344
|
+
for (; ; ) {
|
|
345
|
+
const n = r.next().value;
|
|
346
|
+
if (!n)
|
|
347
|
+
return;
|
|
348
|
+
const s = n[0];
|
|
349
|
+
if (n[1] < t)
|
|
350
|
+
e.map.delete(s);
|
|
351
|
+
else
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function Je() {
|
|
356
|
+
return Date.now();
|
|
357
|
+
}
|
|
358
|
+
function _e() {
|
|
359
|
+
var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, t = JSON.parse(JSON.stringify(e));
|
|
360
|
+
return typeof t.webWorkerSupport > "u" && (t.webWorkerSupport = !0), t.idb || (t.idb = {}), t.idb.ttl || (t.idb.ttl = 1e3 * 45), t.idb.fallbackInterval || (t.idb.fallbackInterval = 150), e.idb && typeof e.idb.onclose == "function" && (t.idb.onclose = e.idb.onclose), t.localstorage || (t.localstorage = {}), t.localstorage.removeTimeout || (t.localstorage.removeTimeout = 1e3 * 60), e.methods && (t.methods = e.methods), t.node || (t.node = {}), t.node.ttl || (t.node.ttl = 1e3 * 60 * 2), t.node.maxParallelWrites || (t.node.maxParallelWrites = 2048), typeof t.node.useFastPath > "u" && (t.node.useFastPath = !0), t;
|
|
361
|
+
}
|
|
362
|
+
var Ut = se, Ft = "pubkey.broadcast-channel-0-", M = "messages", de = {
|
|
363
|
+
durability: "relaxed"
|
|
364
|
+
}, Kt = "idb";
|
|
365
|
+
function Qe() {
|
|
366
|
+
if (typeof indexedDB < "u") return indexedDB;
|
|
367
|
+
if (typeof window < "u") {
|
|
368
|
+
if (typeof window.mozIndexedDB < "u") return window.mozIndexedDB;
|
|
369
|
+
if (typeof window.webkitIndexedDB < "u") return window.webkitIndexedDB;
|
|
370
|
+
if (typeof window.msIndexedDB < "u") return window.msIndexedDB;
|
|
371
|
+
}
|
|
372
|
+
return !1;
|
|
373
|
+
}
|
|
374
|
+
function Le(e) {
|
|
375
|
+
e.commit && e.commit();
|
|
376
|
+
}
|
|
377
|
+
function jt(e) {
|
|
378
|
+
var t = Qe(), r = Ft + e, n = t.open(r);
|
|
379
|
+
return n.onupgradeneeded = function(s) {
|
|
380
|
+
var o = s.target.result;
|
|
381
|
+
o.createObjectStore(M, {
|
|
382
|
+
keyPath: "id",
|
|
383
|
+
autoIncrement: !0
|
|
384
|
+
});
|
|
385
|
+
}, new Promise(function(s, o) {
|
|
386
|
+
n.onerror = function(i) {
|
|
387
|
+
return o(i);
|
|
388
|
+
}, n.onsuccess = function() {
|
|
389
|
+
s(n.result);
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
function zt(e, t, r) {
|
|
394
|
+
var n = Date.now(), s = {
|
|
395
|
+
uuid: t,
|
|
396
|
+
time: n,
|
|
397
|
+
data: r
|
|
398
|
+
}, o = e.transaction([M], "readwrite", de);
|
|
399
|
+
return new Promise(function(i, u) {
|
|
400
|
+
o.oncomplete = function() {
|
|
401
|
+
return i();
|
|
402
|
+
}, o.onerror = function(f) {
|
|
403
|
+
return u(f);
|
|
404
|
+
};
|
|
405
|
+
var c = o.objectStore(M);
|
|
406
|
+
c.add(s), Le(o);
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
function Ht(e, t) {
|
|
410
|
+
var r = e.transaction(M, "readonly", de), n = r.objectStore(M), s = [], o = IDBKeyRange.bound(t + 1, 1 / 0);
|
|
411
|
+
if (n.getAll) {
|
|
412
|
+
var i = n.getAll(o);
|
|
413
|
+
return new Promise(function(c, f) {
|
|
414
|
+
i.onerror = function(h) {
|
|
415
|
+
return f(h);
|
|
416
|
+
}, i.onsuccess = function(h) {
|
|
417
|
+
c(h.target.result);
|
|
418
|
+
};
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
function u() {
|
|
422
|
+
try {
|
|
423
|
+
return o = IDBKeyRange.bound(t + 1, 1 / 0), n.openCursor(o);
|
|
424
|
+
} catch {
|
|
425
|
+
return n.openCursor();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return new Promise(function(c, f) {
|
|
429
|
+
var h = u();
|
|
430
|
+
h.onerror = function(p) {
|
|
431
|
+
return f(p);
|
|
432
|
+
}, h.onsuccess = function(p) {
|
|
433
|
+
var m = p.target.result;
|
|
434
|
+
m ? m.value.id < t + 1 ? m.continue(t + 1) : (s.push(m.value), m.continue()) : (Le(r), c(s));
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
function Jt(e, t) {
|
|
439
|
+
if (e.closed)
|
|
440
|
+
return Promise.resolve([]);
|
|
441
|
+
var r = e.db.transaction(M, "readwrite", de), n = r.objectStore(M);
|
|
442
|
+
return Promise.all(t.map(function(s) {
|
|
443
|
+
var o = n.delete(s);
|
|
444
|
+
return new Promise(function(i) {
|
|
445
|
+
o.onsuccess = function() {
|
|
446
|
+
return i();
|
|
447
|
+
};
|
|
448
|
+
});
|
|
449
|
+
}));
|
|
450
|
+
}
|
|
451
|
+
function Qt(e, t) {
|
|
452
|
+
var r = Date.now() - t, n = e.transaction(M, "readonly", de), s = n.objectStore(M), o = [];
|
|
453
|
+
return new Promise(function(i) {
|
|
454
|
+
s.openCursor().onsuccess = function(u) {
|
|
455
|
+
var c = u.target.result;
|
|
456
|
+
if (c) {
|
|
457
|
+
var f = c.value;
|
|
458
|
+
f.time < r ? (o.push(f), c.continue()) : (Le(n), i(o));
|
|
459
|
+
} else
|
|
460
|
+
i(o);
|
|
461
|
+
};
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function qt(e) {
|
|
465
|
+
return Qt(e.db, e.options.idb.ttl).then(function(t) {
|
|
466
|
+
return Jt(e, t.map(function(r) {
|
|
467
|
+
return r.id;
|
|
468
|
+
}));
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
function Yt(e, t) {
|
|
472
|
+
return t = _e(t), jt(e).then(function(r) {
|
|
473
|
+
var n = {
|
|
474
|
+
closed: !1,
|
|
475
|
+
lastCursorId: 0,
|
|
476
|
+
channelName: e,
|
|
477
|
+
options: t,
|
|
478
|
+
uuid: ne(),
|
|
479
|
+
/**
|
|
480
|
+
* emittedMessagesIds
|
|
481
|
+
* contains all messages that have been emitted before
|
|
482
|
+
* @type {ObliviousSet}
|
|
483
|
+
*/
|
|
484
|
+
eMIs: new He(t.idb.ttl * 2),
|
|
485
|
+
// ensures we do not read messages in parallel
|
|
486
|
+
writeBlockPromise: C,
|
|
487
|
+
messagesCallback: null,
|
|
488
|
+
readQueuePromises: [],
|
|
489
|
+
db: r
|
|
490
|
+
};
|
|
491
|
+
return r.onclose = function() {
|
|
492
|
+
n.closed = !0, t.idb.onclose && t.idb.onclose();
|
|
493
|
+
}, qe(n), n;
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
function qe(e) {
|
|
497
|
+
e.closed || Ye(e).then(function() {
|
|
498
|
+
return x(e.options.idb.fallbackInterval);
|
|
499
|
+
}).then(function() {
|
|
500
|
+
return qe(e);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function Vt(e, t) {
|
|
504
|
+
return !(e.uuid === t.uuid || t.eMIs.has(e.id) || e.data.time < t.messagesCallbackTime);
|
|
505
|
+
}
|
|
506
|
+
function Ye(e) {
|
|
507
|
+
return e.closed || !e.messagesCallback ? C : Ht(e.db, e.lastCursorId).then(function(t) {
|
|
508
|
+
var r = t.filter(function(n) {
|
|
509
|
+
return !!n;
|
|
510
|
+
}).map(function(n) {
|
|
511
|
+
return n.id > e.lastCursorId && (e.lastCursorId = n.id), n;
|
|
512
|
+
}).filter(function(n) {
|
|
513
|
+
return Vt(n, e);
|
|
514
|
+
}).sort(function(n, s) {
|
|
515
|
+
return n.time - s.time;
|
|
516
|
+
});
|
|
517
|
+
return r.forEach(function(n) {
|
|
518
|
+
e.messagesCallback && (e.eMIs.add(n.id), e.messagesCallback(n.data));
|
|
519
|
+
}), C;
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function Xt(e) {
|
|
523
|
+
e.closed = !0, e.db.close();
|
|
524
|
+
}
|
|
525
|
+
function Zt(e, t) {
|
|
526
|
+
return e.writeBlockPromise = e.writeBlockPromise.then(function() {
|
|
527
|
+
return zt(e.db, e.uuid, t);
|
|
528
|
+
}).then(function() {
|
|
529
|
+
Mt(0, 10) === 0 && qt(e);
|
|
530
|
+
}), e.writeBlockPromise;
|
|
531
|
+
}
|
|
532
|
+
function er(e, t, r) {
|
|
533
|
+
e.messagesCallbackTime = r, e.messagesCallback = t, Ye(e);
|
|
534
|
+
}
|
|
535
|
+
function tr() {
|
|
536
|
+
return !!Qe();
|
|
537
|
+
}
|
|
538
|
+
function rr(e) {
|
|
539
|
+
return e.idb.fallbackInterval * 2;
|
|
540
|
+
}
|
|
541
|
+
var nr = {
|
|
542
|
+
create: Yt,
|
|
543
|
+
close: Xt,
|
|
544
|
+
onMessage: er,
|
|
545
|
+
postMessage: Zt,
|
|
546
|
+
canBeUsed: tr,
|
|
547
|
+
type: Kt,
|
|
548
|
+
averageResponseTime: rr,
|
|
549
|
+
microSeconds: Ut
|
|
550
|
+
}, sr = se, ir = "pubkey.broadcastChannel-", or = "localstorage";
|
|
551
|
+
function Ve() {
|
|
552
|
+
var e;
|
|
553
|
+
if (typeof window > "u") return null;
|
|
554
|
+
try {
|
|
555
|
+
e = window.localStorage, e = window["ie8-eventlistener/storage"] || window.localStorage;
|
|
556
|
+
} catch {
|
|
557
|
+
}
|
|
558
|
+
return e;
|
|
559
|
+
}
|
|
560
|
+
function Xe(e) {
|
|
561
|
+
return ir + e;
|
|
562
|
+
}
|
|
563
|
+
function ar(e, t) {
|
|
564
|
+
return new Promise(function(r) {
|
|
565
|
+
x().then(function() {
|
|
566
|
+
var n = Xe(e.channelName), s = {
|
|
567
|
+
token: ne(),
|
|
568
|
+
time: Date.now(),
|
|
569
|
+
data: t,
|
|
570
|
+
uuid: e.uuid
|
|
571
|
+
}, o = JSON.stringify(s);
|
|
572
|
+
Ve().setItem(n, o);
|
|
573
|
+
var i = document.createEvent("Event");
|
|
574
|
+
i.initEvent("storage", !0, !0), i.key = n, i.newValue = o, window.dispatchEvent(i), r();
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function ur(e, t) {
|
|
579
|
+
var r = Xe(e), n = function(o) {
|
|
580
|
+
o.key === r && t(JSON.parse(o.newValue));
|
|
581
|
+
};
|
|
582
|
+
return window.addEventListener("storage", n), n;
|
|
583
|
+
}
|
|
584
|
+
function cr(e) {
|
|
585
|
+
window.removeEventListener("storage", e);
|
|
586
|
+
}
|
|
587
|
+
function fr(e, t) {
|
|
588
|
+
if (t = _e(t), !Ze())
|
|
589
|
+
throw new Error("BroadcastChannel: localstorage cannot be used");
|
|
590
|
+
var r = ne(), n = new He(t.localstorage.removeTimeout), s = {
|
|
591
|
+
channelName: e,
|
|
592
|
+
uuid: r,
|
|
593
|
+
eMIs: n
|
|
594
|
+
// emittedMessagesIds
|
|
595
|
+
};
|
|
596
|
+
return s.listener = ur(e, function(o) {
|
|
597
|
+
s.messagesCallback && o.uuid !== r && (!o.token || n.has(o.token) || o.data.time && o.data.time < s.messagesCallbackTime || (n.add(o.token), s.messagesCallback(o.data)));
|
|
598
|
+
}), s;
|
|
599
|
+
}
|
|
600
|
+
function dr(e) {
|
|
601
|
+
cr(e.listener);
|
|
602
|
+
}
|
|
603
|
+
function lr(e, t, r) {
|
|
604
|
+
e.messagesCallbackTime = r, e.messagesCallback = t;
|
|
605
|
+
}
|
|
606
|
+
function Ze() {
|
|
607
|
+
var e = Ve();
|
|
608
|
+
if (!e) return !1;
|
|
609
|
+
try {
|
|
610
|
+
var t = "__broadcastchannel_check";
|
|
611
|
+
e.setItem(t, "works"), e.removeItem(t);
|
|
612
|
+
} catch {
|
|
613
|
+
return !1;
|
|
614
|
+
}
|
|
615
|
+
return !0;
|
|
616
|
+
}
|
|
617
|
+
function hr() {
|
|
618
|
+
var e = 120, t = navigator.userAgent.toLowerCase();
|
|
619
|
+
return t.includes("safari") && !t.includes("chrome") ? e * 2 : e;
|
|
620
|
+
}
|
|
621
|
+
var pr = {
|
|
622
|
+
create: fr,
|
|
623
|
+
close: dr,
|
|
624
|
+
onMessage: lr,
|
|
625
|
+
postMessage: ar,
|
|
626
|
+
canBeUsed: Ze,
|
|
627
|
+
type: or,
|
|
628
|
+
averageResponseTime: hr,
|
|
629
|
+
microSeconds: sr
|
|
630
|
+
}, et = se, mr = "simulate", Re = /* @__PURE__ */ new Set();
|
|
631
|
+
function gr(e) {
|
|
632
|
+
var t = {
|
|
633
|
+
time: et(),
|
|
634
|
+
name: e,
|
|
635
|
+
messagesCallback: null
|
|
636
|
+
};
|
|
637
|
+
return Re.add(t), t;
|
|
638
|
+
}
|
|
639
|
+
function wr(e) {
|
|
640
|
+
Re.delete(e);
|
|
641
|
+
}
|
|
642
|
+
var tt = 5;
|
|
643
|
+
function vr(e, t) {
|
|
644
|
+
return new Promise(function(r) {
|
|
645
|
+
return setTimeout(function() {
|
|
646
|
+
var n = Array.from(Re);
|
|
647
|
+
n.forEach(function(s) {
|
|
648
|
+
s.name === e.name && // has same name
|
|
649
|
+
s !== e && s.messagesCallback && // has subscribers
|
|
650
|
+
s.time < t.time && s.messagesCallback(t);
|
|
651
|
+
}), r();
|
|
652
|
+
}, tt);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
function br(e, t) {
|
|
656
|
+
e.messagesCallback = t;
|
|
657
|
+
}
|
|
658
|
+
function yr() {
|
|
659
|
+
return !0;
|
|
660
|
+
}
|
|
661
|
+
function Er() {
|
|
662
|
+
return tt;
|
|
663
|
+
}
|
|
664
|
+
var _r = {
|
|
665
|
+
create: gr,
|
|
666
|
+
close: wr,
|
|
667
|
+
onMessage: br,
|
|
668
|
+
postMessage: vr,
|
|
669
|
+
canBeUsed: yr,
|
|
670
|
+
type: mr,
|
|
671
|
+
averageResponseTime: Er,
|
|
672
|
+
microSeconds: et
|
|
673
|
+
}, Oe = [
|
|
674
|
+
Gt,
|
|
675
|
+
// fastest
|
|
676
|
+
nr,
|
|
677
|
+
pr
|
|
678
|
+
];
|
|
679
|
+
function Lr(e) {
|
|
680
|
+
var t = [].concat(e.methods, Oe).filter(Boolean);
|
|
681
|
+
if (e.type) {
|
|
682
|
+
if (e.type === "simulate")
|
|
683
|
+
return _r;
|
|
684
|
+
var r = t.find(function(s) {
|
|
685
|
+
return s.type === e.type;
|
|
686
|
+
});
|
|
687
|
+
if (r) return r;
|
|
688
|
+
throw new Error("method-type " + e.type + " not found");
|
|
689
|
+
}
|
|
690
|
+
e.webWorkerSupport || (t = t.filter(function(s) {
|
|
691
|
+
return s.type !== "idb";
|
|
692
|
+
}));
|
|
693
|
+
var n = t.find(function(s) {
|
|
694
|
+
return s.canBeUsed();
|
|
695
|
+
});
|
|
696
|
+
if (n)
|
|
697
|
+
return n;
|
|
698
|
+
throw new Error("No usable method found in " + JSON.stringify(Oe.map(function(s) {
|
|
699
|
+
return s.type;
|
|
700
|
+
})));
|
|
701
|
+
}
|
|
702
|
+
var rt = /* @__PURE__ */ new Set(), Rr = 0, ue = function(t, r) {
|
|
703
|
+
this.id = Rr++, rt.add(this), this.name = t, Pe && (r = Pe), this.options = _e(r), this.method = Lr(this.options), this._iL = !1, this._onML = null, this._addEL = {
|
|
704
|
+
message: [],
|
|
705
|
+
internal: []
|
|
706
|
+
}, this._uMP = /* @__PURE__ */ new Set(), this._befC = [], this._prepP = null, Tr(this);
|
|
707
|
+
};
|
|
708
|
+
ue._pubkey = !0;
|
|
709
|
+
var Pe;
|
|
710
|
+
ue.prototype = {
|
|
711
|
+
postMessage: function(t) {
|
|
712
|
+
if (this.closed)
|
|
713
|
+
throw new Error("BroadcastChannel.postMessage(): Cannot post message after channel has closed " + /**
|
|
714
|
+
* In the past when this error appeared, it was really hard to debug.
|
|
715
|
+
* So now we log the msg together with the error so it at least
|
|
716
|
+
* gives some clue about where in your application this happens.
|
|
717
|
+
*/
|
|
718
|
+
JSON.stringify(t));
|
|
719
|
+
return xe(this, "message", t);
|
|
720
|
+
},
|
|
721
|
+
postInternal: function(t) {
|
|
722
|
+
return xe(this, "internal", t);
|
|
723
|
+
},
|
|
724
|
+
set onmessage(e) {
|
|
725
|
+
var t = this.method.microSeconds(), r = {
|
|
726
|
+
time: t,
|
|
727
|
+
fn: e
|
|
728
|
+
};
|
|
729
|
+
De(this, "message", this._onML), e && typeof e == "function" ? (this._onML = r, Be(this, "message", r)) : this._onML = null;
|
|
730
|
+
},
|
|
731
|
+
addEventListener: function(t, r) {
|
|
732
|
+
var n = this.method.microSeconds(), s = {
|
|
733
|
+
time: n,
|
|
734
|
+
fn: r
|
|
735
|
+
};
|
|
736
|
+
Be(this, t, s);
|
|
737
|
+
},
|
|
738
|
+
removeEventListener: function(t, r) {
|
|
739
|
+
var n = this._addEL[t].find(function(s) {
|
|
740
|
+
return s.fn === r;
|
|
741
|
+
});
|
|
742
|
+
De(this, t, n);
|
|
743
|
+
},
|
|
744
|
+
close: function() {
|
|
745
|
+
var t = this;
|
|
746
|
+
if (!this.closed) {
|
|
747
|
+
rt.delete(this), this.closed = !0;
|
|
748
|
+
var r = this._prepP ? this._prepP : C;
|
|
749
|
+
return this._onML = null, this._addEL.message = [], r.then(function() {
|
|
750
|
+
return Promise.all(Array.from(t._uMP));
|
|
751
|
+
}).then(function() {
|
|
752
|
+
return Promise.all(t._befC.map(function(n) {
|
|
753
|
+
return n();
|
|
754
|
+
}));
|
|
755
|
+
}).then(function() {
|
|
756
|
+
return t.method.close(t._state);
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
get type() {
|
|
761
|
+
return this.method.type;
|
|
762
|
+
},
|
|
763
|
+
get isClosed() {
|
|
764
|
+
return this.closed;
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
function xe(e, t, r) {
|
|
768
|
+
var n = e.method.microSeconds(), s = {
|
|
769
|
+
time: n,
|
|
770
|
+
type: t,
|
|
771
|
+
data: r
|
|
772
|
+
}, o = e._prepP ? e._prepP : C;
|
|
773
|
+
return o.then(function() {
|
|
774
|
+
var i = e.method.postMessage(e._state, s);
|
|
775
|
+
return e._uMP.add(i), i.catch().then(function() {
|
|
776
|
+
return e._uMP.delete(i);
|
|
777
|
+
}), i;
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function Tr(e) {
|
|
781
|
+
var t = e.method.create(e.name, e.options);
|
|
782
|
+
It(t) ? (e._prepP = t, t.then(function(r) {
|
|
783
|
+
e._state = r;
|
|
784
|
+
})) : e._state = t;
|
|
785
|
+
}
|
|
786
|
+
function nt(e) {
|
|
787
|
+
return e._addEL.message.length > 0 || e._addEL.internal.length > 0;
|
|
788
|
+
}
|
|
789
|
+
function Be(e, t, r) {
|
|
790
|
+
e._addEL[t].push(r), kr(e);
|
|
791
|
+
}
|
|
792
|
+
function De(e, t, r) {
|
|
793
|
+
e._addEL[t] = e._addEL[t].filter(function(n) {
|
|
794
|
+
return n !== r;
|
|
795
|
+
}), Ir(e);
|
|
796
|
+
}
|
|
797
|
+
function kr(e) {
|
|
798
|
+
if (!e._iL && nt(e)) {
|
|
799
|
+
var t = function(s) {
|
|
800
|
+
e._addEL[s.type].forEach(function(o) {
|
|
801
|
+
s.time >= o.time && o.fn(s.data);
|
|
802
|
+
});
|
|
803
|
+
}, r = e.method.microSeconds();
|
|
804
|
+
e._prepP ? e._prepP.then(function() {
|
|
805
|
+
e._iL = !0, e.method.onMessage(e._state, t, r);
|
|
806
|
+
}) : (e._iL = !0, e.method.onMessage(e._state, t, r));
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function Ir(e) {
|
|
810
|
+
if (e._iL && !nt(e)) {
|
|
811
|
+
e._iL = !1;
|
|
812
|
+
var t = e.method.microSeconds();
|
|
813
|
+
e.method.onMessage(e._state, null, t);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function Cr(e) {
|
|
817
|
+
if (typeof WorkerGlobalScope == "function" && self instanceof WorkerGlobalScope) {
|
|
818
|
+
var t = self.close.bind(self);
|
|
819
|
+
self.close = function() {
|
|
820
|
+
return e(), t();
|
|
821
|
+
};
|
|
822
|
+
} else {
|
|
823
|
+
if (typeof window.addEventListener != "function")
|
|
824
|
+
return;
|
|
825
|
+
window.addEventListener("beforeunload", function() {
|
|
826
|
+
e();
|
|
827
|
+
}, !0), window.addEventListener("unload", function() {
|
|
828
|
+
e();
|
|
829
|
+
}, !0);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
function Mr(e) {
|
|
833
|
+
process.on("exit", function() {
|
|
834
|
+
return e();
|
|
835
|
+
}), process.on("beforeExit", function() {
|
|
836
|
+
return e().then(function() {
|
|
837
|
+
return process.exit();
|
|
838
|
+
});
|
|
839
|
+
}), process.on("SIGINT", function() {
|
|
840
|
+
return e().then(function() {
|
|
841
|
+
return process.exit();
|
|
842
|
+
});
|
|
843
|
+
}), process.on("uncaughtException", function(t) {
|
|
844
|
+
return e().then(function() {
|
|
845
|
+
console.trace(t), process.exit(101);
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
var Sr = Object.prototype.toString.call(typeof process < "u" ? process : 0) === "[object process]", Ar = Sr ? Mr : Cr, X = /* @__PURE__ */ new Set(), $e = !1;
|
|
850
|
+
function Nr() {
|
|
851
|
+
$e || ($e = !0, Ar(Pr));
|
|
852
|
+
}
|
|
853
|
+
function Or(e) {
|
|
854
|
+
if (Nr(), typeof e != "function")
|
|
855
|
+
throw new Error("Listener is no function");
|
|
856
|
+
X.add(e);
|
|
857
|
+
var t = {
|
|
858
|
+
remove: function() {
|
|
859
|
+
return X.delete(e);
|
|
860
|
+
},
|
|
861
|
+
run: function() {
|
|
862
|
+
return X.delete(e), e();
|
|
863
|
+
}
|
|
864
|
+
};
|
|
865
|
+
return t;
|
|
866
|
+
}
|
|
867
|
+
function Pr() {
|
|
868
|
+
var e = [];
|
|
869
|
+
return X.forEach(function(t) {
|
|
870
|
+
e.push(t()), X.delete(t);
|
|
871
|
+
}), Promise.all(e);
|
|
872
|
+
}
|
|
873
|
+
function W(e, t) {
|
|
874
|
+
var r = {
|
|
875
|
+
context: "leader",
|
|
876
|
+
action: t,
|
|
877
|
+
token: e.token
|
|
878
|
+
};
|
|
879
|
+
return e.broadcastChannel.postInternal(r);
|
|
880
|
+
}
|
|
881
|
+
function st(e) {
|
|
882
|
+
e.isLeader = !0, e._hasLeader = !0;
|
|
883
|
+
var t = Or(function() {
|
|
884
|
+
return e.die();
|
|
885
|
+
});
|
|
886
|
+
e._unl.push(t);
|
|
887
|
+
var r = function(s) {
|
|
888
|
+
s.context === "leader" && s.action === "apply" && W(e, "tell"), s.context === "leader" && s.action === "tell" && !e._dpLC && (e._dpLC = !0, e._dpL(), W(e, "tell"));
|
|
889
|
+
};
|
|
890
|
+
return e.broadcastChannel.addEventListener("internal", r), e._lstns.push(r), W(e, "tell");
|
|
891
|
+
}
|
|
892
|
+
var it = function(t, r) {
|
|
893
|
+
var n = this;
|
|
894
|
+
this.broadcastChannel = t, t._befC.push(function() {
|
|
895
|
+
return n.die();
|
|
896
|
+
}), this._options = r, this.isLeader = !1, this.isDead = !1, this.token = ne(), this._lstns = [], this._unl = [], this._dpL = function() {
|
|
897
|
+
}, this._dpLC = !1, this._wKMC = {}, this.lN = "pubkey-bc||" + t.method.type + "||" + t.name;
|
|
898
|
+
};
|
|
899
|
+
it.prototype = {
|
|
900
|
+
hasLeader: function() {
|
|
901
|
+
var t = this;
|
|
902
|
+
return navigator.locks.query().then(function(r) {
|
|
903
|
+
var n = r.held ? r.held.filter(function(s) {
|
|
904
|
+
return s.name === t.lN;
|
|
905
|
+
}) : [];
|
|
906
|
+
return !!(n && n.length > 0);
|
|
907
|
+
});
|
|
908
|
+
},
|
|
909
|
+
awaitLeadership: function() {
|
|
910
|
+
var t = this;
|
|
911
|
+
if (!this._wLMP) {
|
|
912
|
+
this._wKMC.c = new AbortController();
|
|
913
|
+
var r = new Promise(function(n, s) {
|
|
914
|
+
t._wKMC.res = n, t._wKMC.rej = s;
|
|
915
|
+
});
|
|
916
|
+
this._wLMP = new Promise(function(n) {
|
|
917
|
+
navigator.locks.request(t.lN, {
|
|
918
|
+
signal: t._wKMC.c.signal
|
|
919
|
+
}, function() {
|
|
920
|
+
return t._wKMC.c = void 0, st(t), n(), r;
|
|
921
|
+
}).catch(function() {
|
|
922
|
+
});
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
return this._wLMP;
|
|
926
|
+
},
|
|
927
|
+
set onduplicate(e) {
|
|
928
|
+
},
|
|
929
|
+
die: function() {
|
|
930
|
+
var t = this;
|
|
931
|
+
return this._lstns.forEach(function(r) {
|
|
932
|
+
return t.broadcastChannel.removeEventListener("internal", r);
|
|
933
|
+
}), this._lstns = [], this._unl.forEach(function(r) {
|
|
934
|
+
return r.remove();
|
|
935
|
+
}), this._unl = [], this.isLeader && (this.isLeader = !1), this.isDead = !0, this._wKMC.res && this._wKMC.res(), this._wKMC.c && this._wKMC.c.abort("LeaderElectionWebLock.die() called"), W(this, "death");
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
var ot = function(t, r) {
|
|
939
|
+
var n = this;
|
|
940
|
+
this.broadcastChannel = t, this._options = r, this.isLeader = !1, this._hasLeader = !1, this.isDead = !1, this.token = ne(), this._aplQ = C, this._aplQC = 0, this._unl = [], this._lstns = [], this._dpL = function() {
|
|
941
|
+
}, this._dpLC = !1;
|
|
942
|
+
var s = function(i) {
|
|
943
|
+
i.context === "leader" && (i.action === "death" && (n._hasLeader = !1), i.action === "tell" && (n._hasLeader = !0));
|
|
944
|
+
};
|
|
945
|
+
this.broadcastChannel.addEventListener("internal", s), this._lstns.push(s);
|
|
946
|
+
};
|
|
947
|
+
ot.prototype = {
|
|
948
|
+
hasLeader: function() {
|
|
949
|
+
return Promise.resolve(this._hasLeader);
|
|
950
|
+
},
|
|
951
|
+
/**
|
|
952
|
+
* Returns true if the instance is leader,
|
|
953
|
+
* false if not.
|
|
954
|
+
* @async
|
|
955
|
+
*/
|
|
956
|
+
applyOnce: function(t) {
|
|
957
|
+
var r = this;
|
|
958
|
+
if (this.isLeader)
|
|
959
|
+
return x(0, !0);
|
|
960
|
+
if (this.isDead)
|
|
961
|
+
return x(0, !1);
|
|
962
|
+
if (this._aplQC > 1)
|
|
963
|
+
return this._aplQ;
|
|
964
|
+
var n = function() {
|
|
965
|
+
if (r.isLeader)
|
|
966
|
+
return Ct;
|
|
967
|
+
var o = !1, i, u = new Promise(function(h) {
|
|
968
|
+
i = function() {
|
|
969
|
+
o = !0, h();
|
|
970
|
+
};
|
|
971
|
+
}), c = function(p) {
|
|
972
|
+
p.context === "leader" && p.token != r.token && (p.action === "apply" && p.token > r.token && i(), p.action === "tell" && (i(), r._hasLeader = !0));
|
|
973
|
+
};
|
|
974
|
+
r.broadcastChannel.addEventListener("internal", c);
|
|
975
|
+
var f = t ? r._options.responseTime * 4 : r._options.responseTime;
|
|
976
|
+
return W(r, "apply").then(function() {
|
|
977
|
+
return Promise.race([x(f), u.then(function() {
|
|
978
|
+
return Promise.reject(new Error());
|
|
979
|
+
})]);
|
|
980
|
+
}).then(function() {
|
|
981
|
+
return W(r, "apply");
|
|
982
|
+
}).then(function() {
|
|
983
|
+
return Promise.race([x(f), u.then(function() {
|
|
984
|
+
return Promise.reject(new Error());
|
|
985
|
+
})]);
|
|
986
|
+
}).catch(function() {
|
|
987
|
+
}).then(function() {
|
|
988
|
+
return r.broadcastChannel.removeEventListener("internal", c), o ? !1 : st(r).then(function() {
|
|
989
|
+
return !0;
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
};
|
|
993
|
+
return this._aplQC = this._aplQC + 1, this._aplQ = this._aplQ.then(function() {
|
|
994
|
+
return n();
|
|
995
|
+
}).then(function() {
|
|
996
|
+
r._aplQC = r._aplQC - 1;
|
|
997
|
+
}), this._aplQ.then(function() {
|
|
998
|
+
return r.isLeader;
|
|
999
|
+
});
|
|
1000
|
+
},
|
|
1001
|
+
awaitLeadership: function() {
|
|
1002
|
+
return this._aLP || (this._aLP = xr(this)), this._aLP;
|
|
1003
|
+
},
|
|
1004
|
+
set onduplicate(e) {
|
|
1005
|
+
this._dpL = e;
|
|
1006
|
+
},
|
|
1007
|
+
die: function() {
|
|
1008
|
+
var t = this;
|
|
1009
|
+
return this._lstns.forEach(function(r) {
|
|
1010
|
+
return t.broadcastChannel.removeEventListener("internal", r);
|
|
1011
|
+
}), this._lstns = [], this._unl.forEach(function(r) {
|
|
1012
|
+
return r.remove();
|
|
1013
|
+
}), this._unl = [], this.isLeader && (this._hasLeader = !1, this.isLeader = !1), this.isDead = !0, W(this, "death");
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
function xr(e) {
|
|
1017
|
+
return e.isLeader ? C : new Promise(function(t) {
|
|
1018
|
+
var r = !1;
|
|
1019
|
+
function n() {
|
|
1020
|
+
r || (r = !0, e.broadcastChannel.removeEventListener("internal", o), t(!0));
|
|
1021
|
+
}
|
|
1022
|
+
e.applyOnce().then(function() {
|
|
1023
|
+
e.isLeader && n();
|
|
1024
|
+
});
|
|
1025
|
+
var s = function() {
|
|
1026
|
+
return x(e._options.fallbackInterval).then(function() {
|
|
1027
|
+
if (!(e.isDead || r))
|
|
1028
|
+
if (e.isLeader)
|
|
1029
|
+
n();
|
|
1030
|
+
else
|
|
1031
|
+
return e.applyOnce(!0).then(function() {
|
|
1032
|
+
e.isLeader ? n() : s();
|
|
1033
|
+
});
|
|
1034
|
+
});
|
|
1035
|
+
};
|
|
1036
|
+
s();
|
|
1037
|
+
var o = function(u) {
|
|
1038
|
+
u.context === "leader" && u.action === "death" && (e._hasLeader = !1, e.applyOnce().then(function() {
|
|
1039
|
+
e.isLeader && n();
|
|
1040
|
+
}));
|
|
1041
|
+
};
|
|
1042
|
+
e.broadcastChannel.addEventListener("internal", o), e._lstns.push(o);
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
function Br(e, t) {
|
|
1046
|
+
return e || (e = {}), e = JSON.parse(JSON.stringify(e)), e.fallbackInterval || (e.fallbackInterval = 3e3), e.responseTime || (e.responseTime = t.method.averageResponseTime(t.options)), e;
|
|
1047
|
+
}
|
|
1048
|
+
function Ge(e, t) {
|
|
1049
|
+
if (e._leaderElector)
|
|
1050
|
+
throw new Error("BroadcastChannel already has a leader-elector");
|
|
1051
|
+
t = Br(t, e);
|
|
1052
|
+
var r = St() ? new it(e, t) : new ot(e, t);
|
|
1053
|
+
return e._befC.push(function() {
|
|
1054
|
+
return r.die();
|
|
1055
|
+
}), e._leaderElector = r, r;
|
|
1056
|
+
}
|
|
1057
|
+
const at = -1, le = 0, Z = 1, ce = 2, Te = 3, ke = 4, Ie = 5, Ce = 6, ut = 7, ct = 8, We = typeof self == "object" ? self : globalThis, Dr = (e, t) => {
|
|
1058
|
+
const r = (s, o) => (e.set(o, s), s), n = (s) => {
|
|
1059
|
+
if (e.has(s))
|
|
1060
|
+
return e.get(s);
|
|
1061
|
+
const [o, i] = t[s];
|
|
1062
|
+
switch (o) {
|
|
1063
|
+
case le:
|
|
1064
|
+
case at:
|
|
1065
|
+
return r(i, s);
|
|
1066
|
+
case Z: {
|
|
1067
|
+
const u = r([], s);
|
|
1068
|
+
for (const c of i)
|
|
1069
|
+
u.push(n(c));
|
|
1070
|
+
return u;
|
|
1071
|
+
}
|
|
1072
|
+
case ce: {
|
|
1073
|
+
const u = r({}, s);
|
|
1074
|
+
for (const [c, f] of i)
|
|
1075
|
+
u[n(c)] = n(f);
|
|
1076
|
+
return u;
|
|
1077
|
+
}
|
|
1078
|
+
case Te:
|
|
1079
|
+
return r(new Date(i), s);
|
|
1080
|
+
case ke: {
|
|
1081
|
+
const { source: u, flags: c } = i;
|
|
1082
|
+
return r(new RegExp(u, c), s);
|
|
1083
|
+
}
|
|
1084
|
+
case Ie: {
|
|
1085
|
+
const u = r(/* @__PURE__ */ new Map(), s);
|
|
1086
|
+
for (const [c, f] of i)
|
|
1087
|
+
u.set(n(c), n(f));
|
|
1088
|
+
return u;
|
|
1089
|
+
}
|
|
1090
|
+
case Ce: {
|
|
1091
|
+
const u = r(/* @__PURE__ */ new Set(), s);
|
|
1092
|
+
for (const c of i)
|
|
1093
|
+
u.add(n(c));
|
|
1094
|
+
return u;
|
|
1095
|
+
}
|
|
1096
|
+
case ut: {
|
|
1097
|
+
const { name: u, message: c } = i;
|
|
1098
|
+
return r(new We[u](c), s);
|
|
1099
|
+
}
|
|
1100
|
+
case ct:
|
|
1101
|
+
return r(BigInt(i), s);
|
|
1102
|
+
case "BigInt":
|
|
1103
|
+
return r(Object(BigInt(i)), s);
|
|
1104
|
+
case "ArrayBuffer":
|
|
1105
|
+
return r(new Uint8Array(i).buffer, i);
|
|
1106
|
+
case "DataView": {
|
|
1107
|
+
const { buffer: u } = new Uint8Array(i);
|
|
1108
|
+
return r(new DataView(u), i);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return r(new We[o](i), s);
|
|
1112
|
+
};
|
|
1113
|
+
return n;
|
|
1114
|
+
}, $r = (e) => Dr(/* @__PURE__ */ new Map(), e)(0), j = "", { toString: Gr } = {}, { keys: Wr } = Object, q = (e) => {
|
|
1115
|
+
const t = typeof e;
|
|
1116
|
+
if (t !== "object" || !e)
|
|
1117
|
+
return [le, t];
|
|
1118
|
+
const r = Gr.call(e).slice(8, -1);
|
|
1119
|
+
switch (r) {
|
|
1120
|
+
case "Array":
|
|
1121
|
+
return [Z, j];
|
|
1122
|
+
case "Object":
|
|
1123
|
+
return [ce, j];
|
|
1124
|
+
case "Date":
|
|
1125
|
+
return [Te, j];
|
|
1126
|
+
case "RegExp":
|
|
1127
|
+
return [ke, j];
|
|
1128
|
+
case "Map":
|
|
1129
|
+
return [Ie, j];
|
|
1130
|
+
case "Set":
|
|
1131
|
+
return [Ce, j];
|
|
1132
|
+
case "DataView":
|
|
1133
|
+
return [Z, r];
|
|
1134
|
+
}
|
|
1135
|
+
return r.includes("Array") ? [Z, r] : r.includes("Error") ? [ut, r] : [ce, r];
|
|
1136
|
+
}, oe = ([e, t]) => e === le && (t === "function" || t === "symbol"), Ur = (e, t, r, n) => {
|
|
1137
|
+
const s = (i, u) => {
|
|
1138
|
+
const c = n.push(i) - 1;
|
|
1139
|
+
return r.set(u, c), c;
|
|
1140
|
+
}, o = (i) => {
|
|
1141
|
+
if (r.has(i))
|
|
1142
|
+
return r.get(i);
|
|
1143
|
+
let [u, c] = q(i);
|
|
1144
|
+
switch (u) {
|
|
1145
|
+
case le: {
|
|
1146
|
+
let h = i;
|
|
1147
|
+
switch (c) {
|
|
1148
|
+
case "bigint":
|
|
1149
|
+
u = ct, h = i.toString();
|
|
1150
|
+
break;
|
|
1151
|
+
case "function":
|
|
1152
|
+
case "symbol":
|
|
1153
|
+
if (e)
|
|
1154
|
+
throw new TypeError("unable to serialize " + c);
|
|
1155
|
+
h = null;
|
|
1156
|
+
break;
|
|
1157
|
+
case "undefined":
|
|
1158
|
+
return s([at], i);
|
|
1159
|
+
}
|
|
1160
|
+
return s([u, h], i);
|
|
1161
|
+
}
|
|
1162
|
+
case Z: {
|
|
1163
|
+
if (c) {
|
|
1164
|
+
let m = i;
|
|
1165
|
+
return c === "DataView" ? m = new Uint8Array(i.buffer) : c === "ArrayBuffer" && (m = new Uint8Array(i)), s([c, [...m]], i);
|
|
1166
|
+
}
|
|
1167
|
+
const h = [], p = s([u, h], i);
|
|
1168
|
+
for (const m of i)
|
|
1169
|
+
h.push(o(m));
|
|
1170
|
+
return p;
|
|
1171
|
+
}
|
|
1172
|
+
case ce: {
|
|
1173
|
+
if (c)
|
|
1174
|
+
switch (c) {
|
|
1175
|
+
case "BigInt":
|
|
1176
|
+
return s([c, i.toString()], i);
|
|
1177
|
+
case "Boolean":
|
|
1178
|
+
case "Number":
|
|
1179
|
+
case "String":
|
|
1180
|
+
return s([c, i.valueOf()], i);
|
|
1181
|
+
}
|
|
1182
|
+
if (t && "toJSON" in i)
|
|
1183
|
+
return o(i.toJSON());
|
|
1184
|
+
const h = [], p = s([u, h], i);
|
|
1185
|
+
for (const m of Wr(i))
|
|
1186
|
+
(e || !oe(q(i[m]))) && h.push([o(m), o(i[m])]);
|
|
1187
|
+
return p;
|
|
1188
|
+
}
|
|
1189
|
+
case Te:
|
|
1190
|
+
return s([u, i.toISOString()], i);
|
|
1191
|
+
case ke: {
|
|
1192
|
+
const { source: h, flags: p } = i;
|
|
1193
|
+
return s([u, { source: h, flags: p }], i);
|
|
1194
|
+
}
|
|
1195
|
+
case Ie: {
|
|
1196
|
+
const h = [], p = s([u, h], i);
|
|
1197
|
+
for (const [m, Q] of i)
|
|
1198
|
+
(e || !(oe(q(m)) || oe(q(Q)))) && h.push([o(m), o(Q)]);
|
|
1199
|
+
return p;
|
|
1200
|
+
}
|
|
1201
|
+
case Ce: {
|
|
1202
|
+
const h = [], p = s([u, h], i);
|
|
1203
|
+
for (const m of i)
|
|
1204
|
+
(e || !oe(q(m))) && h.push(o(m));
|
|
1205
|
+
return p;
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
const { message: f } = i;
|
|
1209
|
+
return s([u, { name: c, message: f }], i);
|
|
1210
|
+
};
|
|
1211
|
+
return o;
|
|
1212
|
+
}, Y = (e, { json: t, lossy: r } = {}) => {
|
|
1213
|
+
const n = [];
|
|
1214
|
+
return Ur(!(t || r), !!t, /* @__PURE__ */ new Map(), n)(e), n;
|
|
1215
|
+
}, _ = ze();
|
|
1216
|
+
var D, R, $, A, I, N, k, E, T, O, G, l, ge, we, ve, be, V, ft, ae, dt, ye;
|
|
1217
|
+
const L = class L extends Ne {
|
|
1218
|
+
/** @private */
|
|
1219
|
+
constructor() {
|
|
1220
|
+
const r = J();
|
|
1221
|
+
if (typeof r[K] < "u" && r[K] instanceof L)
|
|
1222
|
+
throw new gt();
|
|
1223
|
+
if (typeof navigator > "u" || !("serviceWorker" in navigator))
|
|
1224
|
+
throw new wt();
|
|
1225
|
+
super();
|
|
1226
|
+
v(this, l);
|
|
1227
|
+
v(this, D);
|
|
1228
|
+
v(this, R);
|
|
1229
|
+
v(this, $);
|
|
1230
|
+
v(this, A);
|
|
1231
|
+
v(this, I);
|
|
1232
|
+
v(this, N);
|
|
1233
|
+
v(this, k);
|
|
1234
|
+
v(this, E);
|
|
1235
|
+
v(this, T);
|
|
1236
|
+
v(this, O);
|
|
1237
|
+
v(this, G);
|
|
1238
|
+
r[K] = this, g(this, D, F(8)), g(this, R, new Ne()), g(this, $, /* @__PURE__ */ new Map()), g(this, A, /* @__PURE__ */ new Map()), g(this, I, /* @__PURE__ */ new Map()), g(this, N, /* @__PURE__ */ new Map()), g(this, k, /* @__PURE__ */ new Map()), g(this, G, 1e3), _.debug(`Swarm instance initialized with ID "${a(this, D)}"`), g(this, O, !1), g(this, E, new ue("nhtio-swarm", {
|
|
1239
|
+
webWorkerSupport: !0,
|
|
1240
|
+
idb: {
|
|
1241
|
+
onclose: () => {
|
|
1242
|
+
_.WARNING("Swarm channel closed, reinitializing..."), a(this, E).close(), d(this, l, ge).call(this, !0);
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
})), g(this, T, Ge(a(this, E))), d(this, l, be).call(this), d(this, l, we).call(this), _.debug("Swarm instance is ready"), d(this, l, dt).call(this), Fe() && r.addEventListener("beforeunload", () => {
|
|
1246
|
+
d(this, l, ae).call(this, L.INTERNAL_OBITUARY, a(this, D));
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* The ID of the current instance.
|
|
1251
|
+
*/
|
|
1252
|
+
get id() {
|
|
1253
|
+
return a(this, D);
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Whether this instance is the leader or not.
|
|
1257
|
+
*/
|
|
1258
|
+
get leader() {
|
|
1259
|
+
return a(this, O);
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Emit an event to all connected peers.
|
|
1263
|
+
* @param event - The name of the event to emit.
|
|
1264
|
+
* @param args - The arguments to pass to the event listeners.
|
|
1265
|
+
* @typeParam E - The name of the event to emit.
|
|
1266
|
+
*/
|
|
1267
|
+
emit(r, ...n) {
|
|
1268
|
+
const s = {
|
|
1269
|
+
id: F(16),
|
|
1270
|
+
event: r,
|
|
1271
|
+
args: n,
|
|
1272
|
+
needsAck: !1,
|
|
1273
|
+
isAck: !1
|
|
1274
|
+
}, o = Y(s);
|
|
1275
|
+
return a(this, E).postMessage(o).catch((i) => {
|
|
1276
|
+
_.error("Got error while sending message", i);
|
|
1277
|
+
}), super.emit(r, ...n), this;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Subscribe to the leadership change event.
|
|
1281
|
+
* @param cb - The callback function to be called when the leadership status changes.
|
|
1282
|
+
*/
|
|
1283
|
+
onLeadershipChange(r) {
|
|
1284
|
+
return a(this, R).on("leadership", r), this;
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Remove the leadership change event listener.
|
|
1288
|
+
* @param cb - The callback function to be removed from the leadership change event.
|
|
1289
|
+
*/
|
|
1290
|
+
offLeadershipChange(r) {
|
|
1291
|
+
return a(this, R).off("leadership", r), this;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Subscribe to the next occurance of a leadership change event.
|
|
1295
|
+
* @param cb - The callback function to be called when the leadership status changes.
|
|
1296
|
+
*/
|
|
1297
|
+
onceLeadershipChange(r) {
|
|
1298
|
+
return a(this, R).once("leadership", r), this;
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Collect responses from all peers for a specific event.
|
|
1302
|
+
* @param event The name of the event to collect responses for.
|
|
1303
|
+
* @param args The arguments which will be passed to the event handler.
|
|
1304
|
+
* @returns A promise that resolves with an array of responses from all peers.
|
|
1305
|
+
* @typeParam R - The type of the response.
|
|
1306
|
+
* @typeParam E - The name of the event to collect responses for.
|
|
1307
|
+
*/
|
|
1308
|
+
collect(r, ...n) {
|
|
1309
|
+
const s = F(16), o = a(this, N).get(r), i = { responses: [], timer: null, resolve: (f) => {
|
|
1310
|
+
} }, u = new Promise((f) => {
|
|
1311
|
+
i.resolve = f, i.timer = setTimeout(() => {
|
|
1312
|
+
a(this, I).delete(s), f(i.responses);
|
|
1313
|
+
}, a(this, G));
|
|
1314
|
+
});
|
|
1315
|
+
a(this, I).set(s, i), o && Promise.resolve(o(...n)).then((f) => {
|
|
1316
|
+
i.responses.push(f), d(this, l, ye).call(this, s);
|
|
1317
|
+
});
|
|
1318
|
+
const c = { id: s, event: r, args: n, needsCollect: !0 };
|
|
1319
|
+
return a(this, E).postMessage(Y(c)).catch((f) => _.error(f)), u;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Register a handler for a specific event which will respond to incoming messages which require a general response
|
|
1323
|
+
* @param event The name of the event to listen for.
|
|
1324
|
+
* @param handler The function to call when the event is emitted.
|
|
1325
|
+
* @typeParam E - The name of the event to listen for.
|
|
1326
|
+
*/
|
|
1327
|
+
onCollect(r, n) {
|
|
1328
|
+
return a(this, N).set(r, n), this;
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* De-register a handler for a specific event which will respond to incoming messages which require a general response
|
|
1332
|
+
* @param event The name of the event to listen for.
|
|
1333
|
+
* @param handler The function to call when the event is emitted.
|
|
1334
|
+
* @typeParam E - The name of the event to listen for.
|
|
1335
|
+
*/
|
|
1336
|
+
offCollect(r) {
|
|
1337
|
+
return a(this, N).delete(r), this;
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Request feedback from the leader for a specific event.
|
|
1341
|
+
* @param event The name of the event to request feedback for.
|
|
1342
|
+
* @param args The arguments to pass to the event handler.
|
|
1343
|
+
* @returns A promise that resolves with the response from the event handler.
|
|
1344
|
+
* @typeParam R - The type of the response.
|
|
1345
|
+
* @typeParam E - The name of the event to request feedback for.
|
|
1346
|
+
*/
|
|
1347
|
+
request(r, ...n) {
|
|
1348
|
+
const s = F(16), i = Y({
|
|
1349
|
+
id: s,
|
|
1350
|
+
event: r,
|
|
1351
|
+
args: n,
|
|
1352
|
+
needsAck: !0
|
|
1353
|
+
});
|
|
1354
|
+
return a(this, E).postMessage(i).catch((u) => {
|
|
1355
|
+
_.error("Error sending request:", u);
|
|
1356
|
+
}), new Promise((u, c) => {
|
|
1357
|
+
const f = setTimeout(() => {
|
|
1358
|
+
a(this, A).delete(s), c(new vt(r));
|
|
1359
|
+
}, a(this, G));
|
|
1360
|
+
a(this, A).set(s, { resolve: u, reject: c, timer: f });
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Register a handler for a specific event which will respond to incoming messages which require a response from the leader
|
|
1365
|
+
* @param event The name of the event to listen for.
|
|
1366
|
+
* @param handler The function to call when the event is emitted.
|
|
1367
|
+
* @typeParam E - The name of the event to listen for.
|
|
1368
|
+
*/
|
|
1369
|
+
onRequest(r, n) {
|
|
1370
|
+
return a(this, $).set(r, n), this;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* De-register a handler for a specific event which will respond to incoming messages which require a response from the leader
|
|
1374
|
+
* @param event The name of the event to listen for.
|
|
1375
|
+
* @param handler The function to call when the event is emitted.
|
|
1376
|
+
* @typeParam E - The name of the event to listen for.
|
|
1377
|
+
*/
|
|
1378
|
+
offRequest(r) {
|
|
1379
|
+
return a(this, $).delete(r), this;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Set the timeout for waiting for a response from `request()` or `collect()`.
|
|
1383
|
+
* @param timeout The timeout in milliseconds to wait for a response.
|
|
1384
|
+
* @returns The current instance of the Swarm class for the current context.
|
|
1385
|
+
*/
|
|
1386
|
+
setAwaitResponseTimeout(r) {
|
|
1387
|
+
return g(this, G, r), this;
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Retreive the current instance of the Swarm class for the current context.
|
|
1391
|
+
* @typeParam Events - The map of events and their arguments that can be emitted and listened to.
|
|
1392
|
+
* @returns The current instance of the Swarm class for the current context.
|
|
1393
|
+
*/
|
|
1394
|
+
static instance() {
|
|
1395
|
+
const r = J();
|
|
1396
|
+
return typeof r[K] < "u" && r[K] instanceof L ? r[K] : new L();
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
D = new WeakMap(), R = new WeakMap(), $ = new WeakMap(), A = new WeakMap(), I = new WeakMap(), N = new WeakMap(), k = new WeakMap(), E = new WeakMap(), T = new WeakMap(), O = new WeakMap(), G = new WeakMap(), l = new WeakSet(), ge = function(r = !1) {
|
|
1400
|
+
a(this, E) && !r || (g(this, E, new ue("nhtio-swarm", {
|
|
1401
|
+
webWorkerSupport: !0,
|
|
1402
|
+
idb: {
|
|
1403
|
+
onclose: () => {
|
|
1404
|
+
a(this, E).close(), d(this, l, ge).call(this, !0);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
})), g(this, T, Ge(a(this, E))), d(this, l, we).call(this));
|
|
1408
|
+
}, we = function() {
|
|
1409
|
+
_.debug("Hooking swarm channel events"), a(this, E).onmessage = (r) => d(this, l, ft).call(this, r), _.debug("Swarm channel events hooked");
|
|
1410
|
+
}, ve = function(r) {
|
|
1411
|
+
a(this, O) !== r && (g(this, O, r), a(this, R).emit("leadership", r), _.debug(`Swarm instance is now ${r ? "the" : "not the"} leader`));
|
|
1412
|
+
}, be = function() {
|
|
1413
|
+
new Promise(async (r) => {
|
|
1414
|
+
await a(this, T).hasLeader() || (_.debug("No leader found, trying to elect one"), await a(this, T).awaitLeadership(), _.debug("Leader elected"), d(this, l, ve).call(this, a(this, T).isLeader)), r(void 0);
|
|
1415
|
+
}).catch((r) => {
|
|
1416
|
+
_.error("Got error while checking for leader", r);
|
|
1417
|
+
}).finally(() => {
|
|
1418
|
+
setTimeout(() => d(this, l, be).call(this), 500);
|
|
1419
|
+
});
|
|
1420
|
+
}, V = function(r) {
|
|
1421
|
+
a(this, E).postMessage(
|
|
1422
|
+
Y({
|
|
1423
|
+
id: F(16),
|
|
1424
|
+
...r
|
|
1425
|
+
})
|
|
1426
|
+
).catch((n) => _.error(n));
|
|
1427
|
+
}, ft = function(r) {
|
|
1428
|
+
const n = $r(r);
|
|
1429
|
+
if (typeof n != "object" || n === null || typeof n.event != "string" && typeof n.event != "number" || !Array.isArray(n.args))
|
|
1430
|
+
return;
|
|
1431
|
+
const {
|
|
1432
|
+
id: s,
|
|
1433
|
+
event: o,
|
|
1434
|
+
args: i,
|
|
1435
|
+
needsAck: u,
|
|
1436
|
+
isAck: c,
|
|
1437
|
+
needsCollect: f,
|
|
1438
|
+
isCollectResponse: h,
|
|
1439
|
+
replyTo: p,
|
|
1440
|
+
result: m,
|
|
1441
|
+
error: Q
|
|
1442
|
+
} = n;
|
|
1443
|
+
if (o === L.INTERNAL_HEARTBEAT) {
|
|
1444
|
+
const [b] = i, S = !a(this, k).has(b);
|
|
1445
|
+
a(this, k).set(b, Date.now()), a(this, R).emit(S ? "peerJoined" : "peerHeartbeat", b);
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
if (o === L.INTERNAL_OBITUARY) {
|
|
1449
|
+
const [b] = i;
|
|
1450
|
+
a(this, k).delete(b) && a(this, R).emit("peerLeft", b);
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
if (c && p) {
|
|
1454
|
+
const b = a(this, A).get(p);
|
|
1455
|
+
b && (clearTimeout(b.timer), a(this, A).delete(p), typeof Q == "string" ? b.reject(new Error(String(Q))) : b.resolve(m));
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
if (u) {
|
|
1459
|
+
a(this, T).hasLeader().then(async (b) => {
|
|
1460
|
+
if (b || (await a(this, T).awaitLeadership(), d(this, l, ve).call(this, a(this, T).isLeader)), a(this, O)) {
|
|
1461
|
+
const S = a(this, $).get(o);
|
|
1462
|
+
S && Promise.resolve(S(...i)).then((he) => {
|
|
1463
|
+
d(this, l, V).call(this, {
|
|
1464
|
+
event: o,
|
|
1465
|
+
args: [],
|
|
1466
|
+
isAck: !0,
|
|
1467
|
+
replyTo: s,
|
|
1468
|
+
result: he
|
|
1469
|
+
});
|
|
1470
|
+
}).catch((he) => {
|
|
1471
|
+
d(this, l, V).call(this, {
|
|
1472
|
+
event: o,
|
|
1473
|
+
args: [],
|
|
1474
|
+
isAck: !0,
|
|
1475
|
+
replyTo: s,
|
|
1476
|
+
error: he.message
|
|
1477
|
+
});
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
});
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
if (h && p) {
|
|
1484
|
+
const b = a(this, I).get(p);
|
|
1485
|
+
b && (b.responses.push(m), d(this, l, ye).call(this, p));
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
if (f) {
|
|
1489
|
+
const b = a(this, N).get(o);
|
|
1490
|
+
b && Promise.resolve(b(...i)).then((S) => {
|
|
1491
|
+
d(this, l, V).call(this, {
|
|
1492
|
+
event: o,
|
|
1493
|
+
args: [],
|
|
1494
|
+
isCollectResponse: !0,
|
|
1495
|
+
replyTo: s,
|
|
1496
|
+
result: S
|
|
1497
|
+
});
|
|
1498
|
+
}).catch((S) => {
|
|
1499
|
+
d(this, l, V).call(this, {
|
|
1500
|
+
event: o,
|
|
1501
|
+
args: [],
|
|
1502
|
+
isCollectResponse: !0,
|
|
1503
|
+
replyTo: s,
|
|
1504
|
+
error: S.message
|
|
1505
|
+
});
|
|
1506
|
+
});
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1509
|
+
Se(L.prototype, this, "emit").call(this, o, ...i);
|
|
1510
|
+
}, ae = function(r, ...n) {
|
|
1511
|
+
const s = { id: F(16), event: r, args: n };
|
|
1512
|
+
a(this, E).postMessage(Y(s)).catch((o) => _.error(o));
|
|
1513
|
+
}, dt = function() {
|
|
1514
|
+
d(this, l, ae).call(this, L.INTERNAL_HEARTBEAT, this.id), setInterval(() => {
|
|
1515
|
+
d(this, l, ae).call(this, L.INTERNAL_HEARTBEAT, this.id);
|
|
1516
|
+
}, 2e3), setInterval(() => {
|
|
1517
|
+
const r = Date.now();
|
|
1518
|
+
for (const [n, s] of a(this, k))
|
|
1519
|
+
r - s > 6e3 && (a(this, k).delete(n), a(this, R).emit("peerLeft", n));
|
|
1520
|
+
}, 2e3);
|
|
1521
|
+
}, ye = function(r) {
|
|
1522
|
+
const n = a(this, I).get(r);
|
|
1523
|
+
if (!n) return;
|
|
1524
|
+
const s = a(this, k).size + 1;
|
|
1525
|
+
n.responses.length >= s && (clearTimeout(n.timer), setTimeout(() => {
|
|
1526
|
+
a(this, I).delete(r) && n.resolve(n.responses);
|
|
1527
|
+
}, 100));
|
|
1528
|
+
}, U(L, "INTERNAL_HEARTBEAT", "__swarm_heartbeat"), U(L, "INTERNAL_OBITUARY", "__swarm_obituary");
|
|
1529
|
+
let Ue = L;
|
|
1530
|
+
const zr = "1.20250424.0";
|
|
1531
|
+
export {
|
|
1532
|
+
Ue as Swarm,
|
|
1533
|
+
Yr as errors,
|
|
1534
|
+
jr as setLogLevel,
|
|
1535
|
+
Qr as types,
|
|
1536
|
+
zr as version
|
|
1537
|
+
};
|
|
1538
|
+
//# sourceMappingURL=index.mjs.map
|