gun-es
Version:
ES version of GunJS Database
982 lines (981 loc) • 39.8 kB
JavaScript
import { r as P, c as re, a as z } from "./min-CbkhEbZY.js";
import { g as we, s as he } from "./min-CbkhEbZY.js";
var U = {}, Y;
function ie() {
if (Y) return U;
Y = 1;
var y = typeof window < "u" ? window.Gun : P();
return y.chain.promise = function(r) {
var i = this, r = r || function(S) {
return S;
};
return new Promise(function(S, g) {
i.once(function(T, d) {
S({ put: T, get: d, gun: this });
});
}).then(r);
}, y.chain.then = function(j) {
var i = this, r = new Promise((S, g) => {
i.once(function(T, d) {
S(T, d);
});
});
return j ? r.then(j) : r;
}, U;
}
ie();
var E = { exports: {} }, M;
function _() {
return M || (M = 1, function() {
function y() {
var g = function(T, d, l) {
if (g.unit = 0, !l && r !== d && (g.last = "" + T < g.last ? g.last : "" + T, delete (g.$ || {})[S]), l = l || g.$ || (g.$ = {}), !T && Object.keys(l).length)
return l;
T = "" + T;
for (var n = 0, p = T.length - 1, h = T[n], e, k; !(e = l[h]) && n < p; )
h += T[++n];
if (e)
if (n == p) {
if (r === d)
return r === (k = e[""]) ? e : (g.unit = 1) && k;
e[""] = d;
} else
return r !== d && delete e[S], g(T.slice(++n), d, e || (e = {}));
else {
if (!j(l, function(C, v) {
var s = 0, t = "";
if ((v || "").length)
for (; v[s] == T[s]; )
t += v[s++];
if (t) {
if (r === d)
return s <= p ? void 0 : ((k || (k = {}))[v.slice(s)] = C, C);
var f = {};
if (f[v.slice(s)] = C, s = T.slice(s), s === "" ? f[""] = d : (f[s] = {})[""] = d, l[t] = f, y.debug && "" + t == "undefined") {
console.log(0, t);
debugger;
}
return delete l[v], !0;
}
})) {
if (r === d)
return;
if ((l[h] || (l[h] = {}))[""] = d, y.debug && "" + h == "undefined") {
console.log(1, h);
debugger;
}
}
if (r === d)
return k;
}
};
return g;
}
if (y.map = function g(T, d, l, n) {
try {
n = n || [];
var p = typeof T == "function" ? T.$ || {} : T;
//!opt && console.log("WHAT IS T?", JSON.stringify(t).length);
if (!p)
return;
if (typeof p == "string") {
if (y.debug)
throw ["BUG:", T, d, l, n];
return;
}
var h = (p[S] || i).sort || (p[S] = function u() {
return u.sort = Object.keys(p).sort(), u;
}()).sort, e;
l = l === !0 ? { branch: !0 } : l || {}, (e = l.reverse) && (h = h.slice(0).reverse());
for (var k = l.start, C = l.end, v = "", s = 0, t = h.length; s < t; s++) {
var f = h[s], c = p[f], a, o, w;
if (!(!c || f === "" || S === f || f === "undefined") && (o = n.slice(0), o.push(f), w = o.join(""), !(r !== k && w < (k || "").slice(0, w.length)) && !(r !== C && (C || v) < w))) {
if (e && (a = g(c, d, l, o), r !== a))
return a;
if (r !== (a = c[""])) {
var m = 1;
if (r !== k && w < (k || "") && (m = 0), r !== C && w > (C || v) && (m = 0), m && (a = d(a, w, f, n), r !== a))
return a;
} else if (l.branch && (a = d(r, w, f, n), r !== a))
return a;
if (n = o, !e && (a = g(c, d, l, n), r !== a))
return a;
n.pop();
}
}
} catch (u) {
console.error(u);
}
}, typeof window < "u")
window.Radix = y;
else
try {
E.exports = y;
} catch {
}
var j = y.object = function(g, T, d) {
for (var l in g)
if (g.hasOwnProperty(l) && (d = T(g[l], l)) !== r)
return d;
}, i = {}, r, S = "";
}()), E.exports;
}
_();
var Q = { exports: {} }, W = { exports: {} }, V;
function ae() {
return V || (V = 1, function(y) {
(function() {
var j = {}, i, r = setTimeout.turn || typeof setImmediate != "" + i && setImmediate || setTimeout;
j.parseAsync = function(g, T, d, l) {
if (typeof g != "string") {
try {
T(i, JSON.parse(g));
} catch (h) {
T(h);
}
return;
}
var n = { i: 0, text: g, done: T, l: g.length, up: [] };
l = l || 1024 * 32, p();
function p() {
for (var h = n.text, e = n.i, k = n.l, C = 0, v = n.w, s, t; C++ < l; ) {
var f = h[e++];
if (e > k) {
n.end = !0;
break;
}
if (v) {
for (e = h.indexOf('"', e - 1), f = h[e], t = 0; h[e - ++t] == "\\"; )
;
t = !(t % 2), s = s || t, f == '"' && !t && (v = i, t = n.s, n.a ? (t = h.slice(n.sl, e), (s || 1 + t.indexOf("\\")) && (t = JSON.parse('"' + t + '"')), n.at instanceof Array ? n.at.push(n.s = t) : (n.at || (n.end = C = l, t = i), (n.at || {})[n.s] = n.s = t), n.s = i) : (n.s = h.slice(n.sl, e), (s || 1 + n.s.indexOf("\\")) && (n.s = JSON.parse('"' + n.s + '"'))), n.a = s = i), ++e;
} else
switch (f) {
case '"':
n.sl = e, v = !0;
break;
case ":":
n.ai = e, n.a = !0;
break;
case ",":
(n.a || n.at instanceof Array) && (t = h.slice(n.ai, e - 1)) && i !== (t = S(t)) && (n.at instanceof Array ? n.at.push(t) : n.at[n.s] = t), n.a = i, n.at instanceof Array && (n.a = !0, n.ai = e);
break;
case "{":
n.up.push(n.at || (n.at = {})), n.at instanceof Array ? n.at.push(n.at = {}) : i !== (t = n.s) && (n.at[t] = n.at = {}), n.a = i;
break;
case "}":
n.a && (t = h.slice(n.ai, e - 1)) && i !== (t = S(t)) && (n.at instanceof Array ? n.at.push(t) : (n.at || (n.end = C = l, t = i), (n.at || {})[n.s] = t)), n.a = i, n.at = n.up.pop();
break;
case "[":
i !== (t = n.s) ? (n.up.push(n.at), n.at[t] = n.at = []) : n.at || n.up.push(n.at = []), n.a = !0, n.ai = e;
break;
case "]":
n.a && (t = h.slice(n.ai, e - 1)) && i !== (t = S(t)) && (n.at instanceof Array ? n.at.push(t) : n.at[n.s] = t), n.a = i, n.at = n.up.pop();
break;
}
}
if (n.s = i, n.i = e, n.w = v, n.end) {
if (t = n.at, i === t)
try {
t = JSON.parse(g);
} catch (c) {
return n.done(c);
}
n.done(i, t);
} else
r(p);
}
};
function S(g) {
var T = parseFloat(g);
if (!isNaN(T))
return T;
if (g = g.trim(), g == "true")
return !0;
if (g == "false")
return !1;
if (g == "null")
return null;
}
j.stringifyAsync = function(g, T, d, l, n) {
n = n || {}, n.text = n.text || "", n.up = [n.at = { d: g }], n.done = T, n.i = 0;
var p = 0;
h();
function h() {
var e = n.at, k = e.d, C = "", v;
switch (e.i && e.i - e.j > 0 && (C += ","), i !== (v = e.k) && (C += JSON.stringify(v) + ":"), typeof k) {
case "boolean":
C += "" + k;
break;
case "string":
C += JSON.stringify(k);
break;
case "number":
C += isNaN(k) ? "null" : k;
break;
case "object":
if (!k) {
C += "null";
break;
}
if (k instanceof Array) {
C += "[", e = { i: -1, as: k, up: e, j: 0 }, e.l = k.length, n.up.push(n.at = e);
break;
}
if (typeof (k || "").toJSON != "function") {
C += "{", e = { i: -1, ok: Object.keys(k).sort(), as: k, up: e, j: 0 }, e.l = e.ok.length, n.up.push(n.at = e);
break;
}
if (v = k.toJSON()) {
C += v;
break;
}
// let this & below pass into default case...
case "function":
if (e.as instanceof Array) {
C += "null";
break;
}
default:
C = "", e.j++;
}
for (n.text += C; 1 + e.i >= e.l; )
n.text += e.ok ? "}" : "]", e = n.at = e.up;
if (++e.i < e.l) {
if ((v = e.ok) ? e.d = e.as[e.k = v[e.i]] : e.d = e.as[e.i], ++p < 9)
return h();
p = 0, r(h);
return;
}
n.done(i, n.text);
}
}, typeof window != "" + i && (window.YSON = j);
try {
"" + i != "object" && (y.exports = j);
} catch {
}
typeof JSON != "" + i && (JSON.parseAsync = j.parseAsync, JSON.stringifyAsync = j.stringifyAsync);
})();
}(W)), W.exports;
}
var F, H;
function fe() {
return H || (H = 1, F = function(y) {
var j = _();
y.find("a", function() {
var i = [];
j.map(y.list, function(g, T) {
T.indexOf("%1B") + 1 && g && i.push([T, g]);
}), i.length && console.log(`
! ! ! WARNING ! ! !
RAD v0.2020.x has detected OLD v0.2019.x data & automatically migrating. Automatic migration will be turned OFF in future versions! If you are just developing/testing, we recommend you reset your data. Please contact us if you have any concerns.
This message should only log once.`);
var r, S;
i.forEach(function(g) {
r = g[0], S = g[1], y.list(decodeURIComponent(r), S), y.list(r, 0);
}), r && y.find.bad(r);
});
}), F;
}
var K;
function ne() {
return K || (K = 1, function() {
function y(r) {
r = r || {}, r.log = r.log || console.log, r.file = String(r.file || "radata");
var S = (y.has || (y.has = {}))[r.file];
if (S)
return S;
r.max = r.max || (r.memory ? r.memory * 999 * 999 : 3e8) * 0.3, r.until = r.until || r.wait || 250, r.batch = r.batch || 10 * 1e3, r.chunk = r.chunk || 1024 * 1024 * 1, r.code = r.code || {}, r.code.from = r.code.from || "!", r.jsonify = !0;
function g(s) {
return encodeURIComponent(s).replace(/\*/g, "%2A");
}
function T(s) {
return v !== s && (!s || typeof s != "object");
}
var d = "" + v == typeof setImmediate ? setTimeout : setImmediate, l = setTimeout.turn || d, v, n = i.object, p = 0;
if (!r.store)
return r.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
if (!r.store.put)
return r.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
if (!r.store.get)
return r.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
r.store.list, "" + v != typeof re && ae();
var h = JSON.parseAsync || function(s, t, f) {
var c;
try {
t(c, JSON.parse(s, f));
} catch (a) {
t(a);
}
}, e = function(s, t, f, c, a) {
if (typeof t == "function") {
var o = f || {};
f = t, e.read(s, f, o, a || c);
return;
}
e.save(s, t, f, c, a);
};
e.save = function(s, t, f, c, a) {
var o = { key: s }, w, m;
o.find = function(u) {
var A;
if (o.file = u || (u = r.code.from), a && (a = a[u] = a[u] || {}), a && (a.sf = a.sf || +/* @__PURE__ */ new Date()), A = e.disk[u]) {
o.mix(v, A);
return;
}
e.parse(u, o.mix, v, a);
}, o.mix = function(u, A) {
if (a && (a.sml = +/* @__PURE__ */ new Date()), a && (a.sm = a.sm || +/* @__PURE__ */ new Date()), o.err = u || o.err) {
f(u);
return;
}
var R = o.file = (A || "").file || o.file, x;
if (!A && R !== r.code.from) {
e.find.bad(R), e.save(s, t, f, c);
return;
}
if ((A = e.disk[R] || (e.disk[R] = A || i())).file || (A.file = R), r.compare && (t = r.compare(A(s), t, s, R), v === t)) {
f(u, -1);
return;
}
if ((o.disk = A)(s, t), c && ((x = (x = A.tags || (A.tags = {}))[c] || (x[c] = e.tags[c] || (e.tags[c] = {})))[R] || (x[R] = e.one[c] || (e.one[c] = f)), f = null), a && (a.st = a.st || +/* @__PURE__ */ new Date()), A.Q) {
f && A.Q.push(f);
return;
}
A.Q = f ? [f] : [], A.to = setTimeout(o.write, r.until);
}, o.write = function() {
a && (a.sto = a.sto || +/* @__PURE__ */ new Date());
var u = w = o.file, A = o.disk;
m = o.q = A.Q, o.tags = A.tags, delete A.Q, delete e.disk[u], delete A.tags, e.write(u, A, o.ack, v, a);
}, o.ack = function(u, A) {
a && (a.sa = a.sa || +/* @__PURE__ */ new Date()), a && (a.sal = m.length);
var R, x;
for (var b in e.tags)
if (e.tags.hasOwnProperty(b)) {
var O = e.tags[b];
if (!((x = e.disk[w]) && (x = x.tags) && x[O])) {
R = O[w], delete O[w];
var N;
for (var q in O)
if (O.hasOwnProperty(q)) {
N = !0;
break;
}
N || (delete e.tags[O], R && R(u, A));
}
}
!m && (m = "");
for (var I = m.length, D = 0, J = +/* @__PURE__ */ new Date(); D < I; D++)
(R = m[D]) && R(u, A);
console.STAT && console.STAT(J, +/* @__PURE__ */ new Date() - J, "rad acks", g(o.file)), console.STAT && console.STAT(J, m.length, "rad acks #", g(o.file));
}, f || (f = function(u, A) {
}), e.find(s, o.find);
}, e.disk = {}, e.one = {}, e.tags = {};
var k = 0;
e.write = function(s, t, f, c, a) {
if (!t) {
f("No radix!");
return;
}
c = typeof c == "object" ? c : { force: c };
var o = function() {
}, w, m;
if (o.text = "", o.file = s = t.file || (t.file = s), !s) {
f("What file?");
return;
}
if (o.write = function() {
var u = t.raw = o.text;
e.disk[s = t.file || o.file || s] = t;
var A = +/* @__PURE__ */ new Date();
a && (a.wd = A), e.find.add(s, function(x) {
if (a && (a.wa = +/* @__PURE__ */ new Date()), x) {
f(x);
return;
}
r.store.put(g(s), u, function(O, N) {
a && (a.wp = +/* @__PURE__ */ new Date()), console.STAT && console.STAT(A, p = +/* @__PURE__ */ new Date() - A, "wrote disk", JSON.stringify(s), ++k, "total all writes."), f(O, N || 1), t.Q || delete e.disk[s];
});
});
}, o.split = function() {
var u = +/* @__PURE__ */ new Date();
a && (a.wf = u), o.text = "", o.count || (o.count = 0, i.map(t, function() {
o.count++;
})), a && (a.wfc = o.count), o.limit = Math.ceil(o.count / 2);
var A = o.count;
return o.count = 0, a && (a.wf1 = +/* @__PURE__ */ new Date()), o.sub = i(), i.map(t, o.slice, { reverse: 1 }), a && (a.wf2 = +/* @__PURE__ */ new Date()), e.write(o.end, o.sub, o.both, c), a && (a.wf3 = +/* @__PURE__ */ new Date()), o.hub = i(), i.map(t, o.stop), a && (a.wf4 = +/* @__PURE__ */ new Date()), e.write(t.file, o.hub, o.both, c), a && (a.wf5 = +/* @__PURE__ */ new Date()), console.STAT && console.STAT(u, +/* @__PURE__ */ new Date() - u, "rad split", g(t.file), A), !0;
}, o.slice = function(u, A) {
if (o.sub(o.end = A, u), o.limit <= ++o.count)
return !0;
}, o.stop = function(u, A) {
if (A >= o.end)
return !0;
o.hub(A, u);
}, o.both = function(u, A) {
if (a && (a.wfd = +/* @__PURE__ */ new Date()), m) {
f(u || m);
return;
}
if (w) {
f(u, A);
return;
}
w = !0, m = u;
}, o.each = function(u, A, R, x) {
if (v !== u && o.count++, r.max <= (u || "").length)
return f("Data too big!"), !0;
var b = y.encode(x.length) + "#" + y.encode(R) + (v === u ? "" : ":" + y.encode(u)) + `
`;
if (r.chunk < o.text.length + b.length && 1 < o.count && !c.force)
return o.split();
o.text += b;
}, r.jsonify) {
e.write.jsonify(o, t, f, c, a);
return;
}
i.map(t, o.each, !0) || o.write();
}, e.write.jsonify = function(s, t, f, c, a) {
var o, w = +/* @__PURE__ */ new Date();
a && (a.w = w);
try {
o = JSON.stringify(t.$);
} catch {
f("Cannot radisk!");
return;
}
if (a && (a.ws = +/* @__PURE__ */ new Date()), console.STAT && console.STAT(w, +/* @__PURE__ */ new Date() - w, "rad stringified JSON"), r.chunk < o.length && !c.force) {
var m = 0;
if (i.map(t, function() {
if (m++)
return !0;
}), m > 1)
return s.split();
}
s.text = o, s.write();
}, e.range = function(s, t) {
if (!(!s || !t)) {
if (v === t.start && v === t.end || T(s))
return s;
var f = i();
return i.map(s, function(c, a) {
f(a, c);
}, t), f("");
}
}, function() {
e.read = function(s, t, f, c) {
f = f || {};
var a = { key: s };
a.find = function(o) {
var w;
if (a.file = o || (o = r.code.from), c && (c = c[o] = c[o] || {}), c && (c.rf = c.rf || +/* @__PURE__ */ new Date()), w = e.disk[a.file = o]) {
a.check(v, w);
return;
}
e.parse(o, a.check, v, c);
}, a.get = function(o, w, m) {
if (c && (c.rgl = +/* @__PURE__ */ new Date()), c && (c.rg = c.rg || +/* @__PURE__ */ new Date()), a.err = o || a.err) {
t(o);
return;
}
var u = a.file = (w || "").file || a.file;
if (!w && u !== r.code.from) {
e.find.bad(u), e.read(s, t, f);
return;
}
if (w = e.disk[u] || (e.disk[u] = w), !w) {
t(u === r.code.from ? v : "No file!");
return;
}
w.file || (w.file = u);
var A = e.range(w(s), f);
if (c && (c.rr = +/* @__PURE__ */ new Date()), f.unit = w.unit, f.chunks = (f.chunks || 0) + 1, f.parsed = (f.parsed || 0) + ((m || "").parsed || f.chunks * r.chunk), f.more = 1, f.next = v, i.map(e.list, function(O, N) {
if (!(!O || u === N))
return f.next = N, 1;
}, f.reverse ? { reverse: 1, end: u } : { start: u }), c && (c.rl = +/* @__PURE__ */ new Date()), f.next || (f.more = 0), f.next && (!f.reverse && (s < f.next && f.next.indexOf(s) != 0 || v !== f.end && (f.end || "") < f.next) && (f.more = 0), f.reverse && (s > f.next && s.indexOf(f.next) != 0 || v !== f.start && (f.start || "") > f.next && u <= f.start) && (f.more = 0)), !f.more) {
t(a.err, A, f);
return;
}
if (A && t(a.err, A, f), !(f.parsed >= f.limit)) {
var R = +/* @__PURE__ */ new Date();
c && (c.rm = R);
var x = f.next;
d(function() {
console.STAT && console.STAT(R, +/* @__PURE__ */ new Date() - R, "rad more"), e.parse(x, a.check);
}, 0);
}
}, a.check = function(o, w, m) {
if (a.get(o, w, m), !(!w || w.check)) {
w.check = 1;
var u = +/* @__PURE__ */ new Date();
(m || (m = {})).file || (m.file = a.file), i.map(w, function(A, R) {
e.find(R, function(x) {
if ((x || (x = r.code.from)) !== m.file) {
var b = ("" + Math.random()).slice(-3);
l(function() {
e.save(R, A, function O(N, q) {
if (N) {
e.save(R, A, O);
return;
}
console.STAT && console.STAT("MISLOCATED DATA CORRECTED", b, g(R), g(m.file), g(x));
});
}, 0);
}
});
}), console.STAT && console.STAT(u, +/* @__PURE__ */ new Date() - u, "rad check");
}
}, e.find(s || (f.reverse ? f.end || "" : f.start || ""), a.find);
};
}(), function() {
var s = 0, t = {}, f = "";
e.parse = function(c, a, o, w) {
var m;
if (!c)
return a();
if (m = t[c]) {
m.push(a);
return;
}
m = t[c] = [a];
var u = function() {
}, A = { file: c };
(u.disk = i()).file = c, u.read = function(x, b) {
if (w && (w.rpg = +/* @__PURE__ */ new Date()), console.STAT && console.STAT(R, +/* @__PURE__ */ new Date() - R, "read disk", JSON.stringify(c), ++s, "total all parses."), (u.err = x) || (u.not = !b)) {
delete t[c], u.map(m, u.ack);
return;
}
if (typeof b != "string") {
try {
r.max <= b.length ? u.err = "Chunk too big!" : b = b.toString();
} catch (O) {
u.err = O;
}
if (u.err) {
delete t[c], u.map(m, u.ack);
return;
}
}
if (A.parsed = b.length, w && (w.rpl = A.parsed), w && (w.rpa = m.length), R = +/* @__PURE__ */ new Date(), !(r.jsonify || b[0] === "{")) {
u.radec(x, b);
return;
}
h(b, function(O, N) {
if (!O) {
delete t[c], u.disk.$ = N, console.STAT && (p = +/* @__PURE__ */ new Date() - R) > 9 && console.STAT(R, p, "rad parsed JSON"), w && (w.rpd = +/* @__PURE__ */ new Date()), u.map(m, u.ack);
return;
}
if (b[0] === "{") {
delete t[c], u.err = "JSON error!", u.map(m, u.ack);
return;
}
u.radec(O, b);
});
}, u.map = function() {
if (!(!m || !m.length)) {
for (var x = +/* @__PURE__ */ new Date(), b = u.err, O = u.not ? v : u.disk, N = 0, q; N < 9 && (q = m[N++]); )
q(b, O, A);
console.STAT && console.STAT(x, +/* @__PURE__ */ new Date() - x, "rad packs", g(c)), console.STAT && console.STAT(x, N, "rad packs #", g(c)), (m = m.slice(N)).length && l(u.map, 0);
}
}, u.ack = function(x) {
if (x) {
if (u.err || u.not) {
x(u.err, v, A);
return;
}
x(v, u.disk, A);
}
}, u.radec = function(x, b) {
delete t[c], R = +/* @__PURE__ */ new Date();
var O = u.split(b), N = [], q, I, D;
if (!O || O[1] !== 0) {
u.err = "File '" + c + "' does not have root radix! ", u.map(m, u.ack);
return;
}
for (; O; )
I = D = v, q = O[1], O = u.split(O[2]) || "", O[0] == "#" && (I = O[1], N = N.slice(0, q), q <= N.length && N.push(I)), O = u.split(O[2]) || "", O[0] != `
` && ((O[0] == "=" || O[0] == ":") && (D = O[1]), v !== I && v !== D && u.disk(N.join(""), D), O = u.split(O[2]));
console.STAT && console.STAT(R, +/* @__PURE__ */ new Date() - R, "parsed RAD"), u.map(m, u.ack);
}, u.split = function(x) {
if (x) {
var b = [], O = {}, N = -1, q = "";
if (N = x.indexOf(f), !!x[N])
return q = x.slice(0, N), b[0] = q, b[1] = y.decode(x.slice(N), O), b[2] = x.slice(N + O.i), b;
}
}, e.disk && (o || (o = (e.disk[c] || "").raw));
var R = +/* @__PURE__ */ new Date();
if (w && (w.rp = R), o)
return l(function() {
u.read(v, o);
}, 0);
r.store.get(g(c), u.read);
};
}(), function() {
var s, t = "", f;
e.find = function(o, w) {
if (!s) {
if (f) {
f.push([o, w]);
return;
}
f = [[o, w]], e.parse(t, c);
return;
}
i.map(e.list = s, function(m, u) {
if (m)
return w(u) || !0;
}, { reverse: 1, end: o }) || w(r.code.from);
}, e.find.add = function(o, w) {
var m = s(o);
if (m || o === t) {
w(v, 1);
return;
}
s(o, 1), w.found = (w.found || 0) + 1, e.write(t, s, function(u, A) {
if (u) {
w(u);
return;
}
w.found = (w.found || 0) - 1, w.found === 0 && w(v, 1);
}, !0);
}, e.find.bad = function(o, w) {
s(o, 0), e.write(t, s, w || C);
};
function c(o, w) {
if (o) {
r.log("list", o), setTimeout(function() {
e.parse(t, c);
}, 1e3);
return;
}
if (w) {
a(w);
return;
}
if (s = s || w || i(), !r.store.list) {
a(s);
return;
}
r.store.list(function(m) {
if (!m) {
a(s);
return;
}
e.find.add(m, C);
});
}
function a(o, w) {
s = s || o, s.file = t, w = f, f = null, n(w, function(m) {
e.find(m[0], m[1]);
});
}
}();
try {
!j.window && fe()(e);
} catch {
}
var C = function() {
}, v;
return y.has[r.file] = e, e;
}
if (function() {
var r = "";
y.encode = function(S, g, T) {
T = T || r;
var d = T, l;
if (typeof S == "string") {
for (var n = S.indexOf(T); n != -1; )
d += T, n = S.indexOf(T, n + 1);
return d + '"' + S + T;
} else {
if (S && S["#"] && Object.keys(S).length == 1)
return d + "#" + l + d;
if (typeof S == "number")
return d + "+" + (S || 0) + d;
if (S === null)
return d + " " + d;
if (S === !0)
return d + "+" + d;
if (S === !1)
return d + "-" + d;
}
}, y.decode = function(S, g, T) {
T = T || r;
var d = "", l = -1, n = 0, p, h;
if (T === S[0]) {
for (; T === S[++l]; )
++n;
for (h = S[p = n] || !0; --n >= 0; )
l = S.indexOf(T, l + 1);
if (l == -1 && (l = S.length), d = S.slice(p + 1, l), g && (g.i = l + 1), h === '"')
return d;
if (h === "#")
return { "#": d };
if (h === "+")
return d.length === 0 ? !0 : parseFloat(d);
if (h === " ")
return null;
if (h === "-")
return !1;
}
};
}(), typeof window < "u") {
var j = window.Gun, i = window.Radix;
window.Radisk = y;
} else {
var j = P(), i = _();
try {
Q.exports = y;
} catch {
}
}
y.Radix = i;
}()), Q.exports;
}
ne();
var X = {}, Z;
function oe() {
if (Z) return X;
Z = 1;
var y = typeof window < "u" ? window.Gun : P();
return y.on("create", function(j) {
y.TESTING && (j.opt.file = "radatatest"), this.to.next(j);
var i = j.opt, r;
if (!(i.rad === !1 || i.radisk === !1) && !(r + "" != typeof process && "" + (process.env || "").RAD == "false")) {
var S = y.window && y.window.Radisk || ne(), g = S.Radix, T = S(i), d = "\x1B", l = 0;
j.on("put", function(p) {
if (this.to.next(p), !(p._ || "").rad) {
var h = p["#"], e = p.put, k = e["#"], C = e["."], v = e[":"], s = e[">"], t = (p._ || "").DBG;
t && (t.sp = t.sp || +/* @__PURE__ */ new Date());
var f = (p._ || "").RPS || ((p._ || "").RPS = +/* @__PURE__ */ new Date());
T(k + d + C, { ":": v, ">": s }, function(c, a) {
if (t && (t.spd = t.spd || +/* @__PURE__ */ new Date()), console.STAT && console.STAT(f, +/* @__PURE__ */ new Date() - f, "put"), c) {
j.on("in", { "@": h, err: c, DBG: t });
return;
}
j.on("in", { "@": h, ok: a, DBG: t });
}, !1, t && (t.r = t.r || {})), t && (t.sps = t.sps || +/* @__PURE__ */ new Date());
}
}), j.on("get", function(p) {
this.to.next(p);
var h = p._ || "", e = h.DBG = p.DBG;
e && (e.sg = +/* @__PURE__ */ new Date());
var k = p["#"], C = p.get, v = p.get["#"], s = p.get["."] || "", t = {}, f, c, a, o;
if (typeof v == "string" ? c = v : v && (r !== (a = v["*"]) && (t.limit = o = 1), r !== v[">"] && (t.start = v[">"]), r !== v["<"] && (t.end = v["<"]), c = o ? "" + a : a || v["="], o = null), c && !t.limit && (typeof s == "string" ? c = c + d + (t.atom = s) : s && (r !== s[">"] && (t.start = s[">"], t.limit = 1), r !== s["<"] && (t.end = s["<"], t.limit = 1), r !== (a = s["*"]) && (t.limit = o = 1), c && (c = c + d + (o ? "" + (a || "") : a || (t.atom = s["="] || ""))))), ((a = C["%"]) || t.limit) && (t.limit = a <= (t.pack || 1e3 * 100) ? a : 1), (s["-"] || (v || {})["-"] || C["-"]) && (t.reverse = !0), (a = (j.next || "")[v]) && a.put) {
if (t.atom) {
if (a = (a.next || "")[t.atom], a && a.root && a.root.graph && a.root.graph[v] && a.root.graph[v][t.atom])
return;
} else if (a && a.rad)
return;
}
var w = y.state(), m = +/* @__PURE__ */ new Date(), u = 0;
e && (e.sgm = m), T(c || "", function(R, x, b) {
e && (e.sgr = +/* @__PURE__ */ new Date()), e && (e.sgi = b);
try {
i.store.stats.get.time[n % 50] = +/* @__PURE__ */ new Date() - m, ++n, i.store.stats.get.count++, R && (i.store.stats.get.err = R);
} catch {
}
console.STAT && console.STAT(m, +/* @__PURE__ */ new Date() - m, "got", JSON.stringify(c)), m = +/* @__PURE__ */ new Date(), b = b || "";
var O, N;
if (b.unit && x && r !== (O = x[":"]) && r !== (N = x[">"])) {
var q = c.split(d), I = q[0], D = q[1];
(f = f || {})[I] = y.state.ify(f[I], D, N, O, I), j.$.get(I).get(D)._.rad = w;
} else
x && (typeof x != "string" && (t.atom ? x = r : g.map(x, A, t)), !f && x && A(x, ""), !t.atom && !s & typeof v == "string" && !t.limit && !t.more && (j.$.get(v)._.rad = w));
e && (e.sgp = +/* @__PURE__ */ new Date()), console.STAT && (l = +/* @__PURE__ */ new Date() - m) > 9 && (console.STAT(m, l, "got prep time"), console.STAT(m, u, "got prep #")), u = 0, m = +/* @__PURE__ */ new Date();
var J = function() {
};
J.faith = !0, J.rad = C, j.on("in", { "@": k, put: f, "%": b.more ? 1 : r, err: R || r, _: J, DBG: e }), console.STAT && (l = +/* @__PURE__ */ new Date() - m) > 9 && console.STAT(m, l, "got emit", Object.keys(f || {}).length), f = r;
}, t, e && (e.r = e.r || {})), e && (e.sgd = +/* @__PURE__ */ new Date()), console.STAT && (l = +/* @__PURE__ */ new Date() - m) > 9 && console.STAT(m, l, "get call");
function A(R, x, b, O) {
if (u++, !!R) {
x = (c + x).split(d);
var N = x.slice(0, 1)[0];
if (x = x.slice(-1)[0], t.limit && t.limit <= t.count)
return !0;
var q, I, D = N, J = x;
if (typeof R != "string") {
q = R[":"], I = R[">"], (f = f || {})[D] = y.state.ify(f[D], J, I, q, D), t.count = (t.count || 0) + ((q || "").length || 9);
return;
}
t.count = (t.count || 0) + R.length;
var $ = R.lastIndexOf(">"), te = S.decode(R.slice($ + 1), null, d);
R = S.decode(R.slice(0, $), null, d), (f = f || {})[N] = y.state.ify(f[N], x, te, R, N);
}
}
}), y.valid, (i.store || {}).stats = { get: { time: {}, count: 0 }, put: { time: {}, count: 0 } };
var n = 0;
}
}), X;
}
oe();
var L = { exports: {} }, G;
function ue() {
return G || (G = 1, function() {
function y(i) {
i = i || {}, i.file = String(i.file || "radata");
var r = y[i.file], S = null, g;
if (r)
return console.log("Warning: reusing same IndexedDB store and options as 1st."), y[i.file];
r = y[i.file] = function() {
};
try {
i.indexedDB = i.indexedDB || y.indexedDB || indexedDB;
} catch {
}
try {
if (!i.indexedDB || location.protocol == "file:") {
var T = r.d || (r.d = {});
return r.put = function(d, l, n) {
T[d] = l, setTimeout(function() {
n(null, 1);
}, 250);
}, r.get = function(d, l) {
setTimeout(function() {
l(null, T[d] || g);
}, 5);
}, console.log("Warning: No indexedDB exists to persist data to!"), r;
}
} catch {
}
return r.start = function() {
var d = indexedDB.open(i.file, 1);
d.onupgradeneeded = function(l) {
l.target.result.createObjectStore(i.file);
}, d.onsuccess = function() {
S = d.result;
}, d.onerror = function(l) {
console.log(l || 1);
};
}, r.start(), r.put = function(d, l, n) {
if (!S) {
setTimeout(function() {
r.put(d, l, n);
}, 1);
return;
}
var p = S.transaction([i.file], "readwrite"), h = p.objectStore(i.file), e = h.put(l, "" + d);
e.onsuccess = h.onsuccess = p.onsuccess = function() {
n(null, 1);
}, e.onabort = h.onabort = p.onabort = function(k) {
n(k || "put.tx.abort");
}, e.onerror = h.onerror = p.onerror = function(k) {
n(k || "put.tx.error");
};
}, r.get = function(d, l) {
if (!S) {
setTimeout(function() {
r.get(d, l);
}, 9);
return;
}
var n = S.transaction([i.file], "readonly"), p = n.objectStore(i.file), h = p.get("" + d);
h.onsuccess = function() {
l(null, h.result);
}, h.onabort = function(e) {
l(e || 4);
}, h.onerror = function(e) {
l(e || 5);
};
}, setInterval(function() {
S && S.close(), S = null, r.start();
}, 1e3 * 15), r;
}
if (typeof window < "u")
(y.window = window).RindexedDB = y, y.indexedDB = window.indexedDB;
else
try {
L.exports = y;
} catch {
}
try {
var j = y.window.Gun || P();
j.on("create", function(i) {
this.to.next(i), i.opt.store = i.opt.store || y(i.opt);
});
} catch {
}
}()), L.exports;
}
ue();
var B = {}, ee;
function se() {
return ee || (ee = 1, function() {
var y = typeof window < "u" ? window.Gun : P();
y.on("opt", function(j) {
this.to.next(j);
var i = j.opt;
if (j.once || !y.Mesh || i.RTCPeerConnection === !1)
return;
var r;
typeof window < "u" && (r = window), typeof z < "u" && (r = z), r = r || {};
var S = i.RTCPeerConnection || r.RTCPeerConnection || r.webkitRTCPeerConnection || r.mozRTCPeerConnection, g = i.RTCSessionDescription || r.RTCSessionDescription || r.webkitRTCSessionDescription || r.mozRTCSessionDescription, T = i.RTCIceCandidate || r.RTCIceCandidate || r.webkitRTCIceCandidate || r.mozRTCIceCandidate;
if (!S || !g || !T)
return;
i.RTCPeerConnection = S, i.RTCSessionDescription = g, i.RTCIceCandidate = T, i.rtc = i.rtc || { iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "stun:stun.sipgate.net:3478" }
/*,
{urls: "stun:stun.stunprotocol.org"},
{urls: "stun:stun.sipgate.net:10000"},
{urls: "stun:217.10.68.152:10000"},
{urls: 'stun:stun.services.mozilla.com'}*/
] }, i.rtc.dataChannel = i.rtc.dataChannel || { ordered: !1, maxRetransmits: 2 }, i.rtc.sdp = i.rtc.sdp || { mandatory: { OfferToReceiveAudio: !1, OfferToReceiveVideo: !1 } }, i.rtc.max = i.rtc.max || 55, i.rtc.room = i.rtc.room || y.window && (location.hash.slice(1) || location.pathname.slice(1)), i.announce = function(n) {
i.rtc.start = +/* @__PURE__ */ new Date(), j.$.get("/RTC/" + i.rtc.room + "<?99").get("+").put(i.pid, function(p) {
!p.ok || !p.ok.rtc || l(p);
}, { acks: i.rtc.max }).on(function(p, h, e) {
p === i.pid || i.rtc.start > e.put[">"] || l({ "#": "" + e["#"], ok: { rtc: { id: p } } });
});
};
var d = i.mesh = i.mesh || y.Mesh(j);
j.on("create", function(n) {
this.to.next(n), setTimeout(i.announce, 1);
});
function l(n) {
if (this && this.off && this.off(), !!n.ok) {
var p = n.ok.rtc, h, e;
if (!(!p || !p.id || p.id === i.pid)) {
if (e = p.answer)
return !(h = i.peers[p.id] || l[p.id]) || h.remoteSet ? void 0 : (e.sdp = e.sdp.replace(/\\r\\n/g, `\r
`), h.setRemoteDescription(h.remoteSet = new i.RTCSessionDescription(e)));
if (e = p.candidate)
return h = i.peers[p.id] || l[p.id] || l({ ok: { rtc: { id: p.id } } }), h.addIceCandidate(new i.RTCIceCandidate(e));
if (!l[p.id]) {
(h = new i.RTCPeerConnection(i.rtc)).id = p.id;
var k = h.wire = h.createDataChannel("dc", i.rtc.dataChannel);
if (l[p.id] = h, k.to = setTimeout(function() {
delete l[p.id];
}, 1e3 * 60), k.onclose = function() {
d.bye(h);
}, k.onerror = function(C) {
}, k.onopen = function(C) {
delete l[p.id], d.hi(h);
}, k.onmessage = function(C) {
C && d.hear(C.data || C, h);
}, h.onicecandidate = function(C) {
C.candidate && j.on("out", { "@": n["#"], ok: { rtc: { candidate: C.candidate, id: i.pid } } });
}, h.ondatachannel = function(C) {
var v = C.channel;
v.onmessage = k.onmessage, v.onopen = k.onopen, v.onclose = k.onclose;
}, e = p.offer) {
p.offer.sdp = p.offer.sdp.replace(/\\r\\n/g, `\r
`), h.setRemoteDescription(new i.RTCSessionDescription(e)), h.createAnswer(function(C) {
h.setLocalDescription(C), j.on("out", { "@": n["#"], ok: { rtc: { answer: C, id: i.pid } } });
}, function() {
}, i.rtc.sdp);
return;
}
return h.createOffer(function(C) {
h.setLocalDescription(C), j.on("out", { "@": n["#"], "#": j.ask(l), ok: { rtc: { offer: C, id: i.pid } } });
}, function() {
}, i.rtc.sdp), h;
}
}
}
}
});
}()), B;
}
se();
export {
we as Gun,
he as SEA
};