holosphere 2.0.0-alpha2 → 2.0.0-alpha4

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.
Files changed (98) hide show
  1. package/dist/2019-D2OG2idw.js +6680 -0
  2. package/dist/2019-D2OG2idw.js.map +1 -0
  3. package/dist/2019-EION3wKo.cjs +8 -0
  4. package/dist/2019-EION3wKo.cjs.map +1 -0
  5. package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
  6. package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
  7. package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
  8. package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
  9. package/dist/browser-BSniCNqO.js +3058 -0
  10. package/dist/browser-BSniCNqO.js.map +1 -0
  11. package/dist/browser-Cq59Ij19.cjs +2 -0
  12. package/dist/browser-Cq59Ij19.cjs.map +1 -0
  13. package/dist/cjs/holosphere.cjs +1 -1
  14. package/dist/esm/holosphere.js +50 -53
  15. package/dist/index-BB_vVJgv.cjs +5 -0
  16. package/dist/index-BB_vVJgv.cjs.map +1 -0
  17. package/dist/index-CBitK71M.cjs +12 -0
  18. package/dist/index-CBitK71M.cjs.map +1 -0
  19. package/dist/index-CV0eOogK.js +37423 -0
  20. package/dist/index-CV0eOogK.js.map +1 -0
  21. package/dist/index-Cz-PLCUR.js +15104 -0
  22. package/dist/index-Cz-PLCUR.js.map +1 -0
  23. package/dist/indexeddb-storage-CRsZyB2f.cjs +2 -0
  24. package/dist/indexeddb-storage-CRsZyB2f.cjs.map +1 -0
  25. package/dist/{indexeddb-storage-CMW4qRQS.js → indexeddb-storage-DZaGlY_a.js} +49 -13
  26. package/dist/indexeddb-storage-DZaGlY_a.js.map +1 -0
  27. package/dist/{memory-storage-DQzcAZlf.js → memory-storage-BkUi6sZG.js} +6 -2
  28. package/dist/memory-storage-BkUi6sZG.js.map +1 -0
  29. package/dist/{memory-storage-DmePEP2q.cjs → memory-storage-C0DuUsdY.cjs} +2 -2
  30. package/dist/memory-storage-C0DuUsdY.cjs.map +1 -0
  31. package/dist/secp256k1-0kPdAVkK.cjs +12 -0
  32. package/dist/secp256k1-0kPdAVkK.cjs.map +1 -0
  33. package/dist/{secp256k1-vOXp40Fx.js → secp256k1-DN4FVXcv.js} +2 -393
  34. package/dist/secp256k1-DN4FVXcv.js.map +1 -0
  35. package/docs/CONTRACTS.md +797 -0
  36. package/examples/demo.html +47 -0
  37. package/package.json +10 -5
  38. package/src/contracts/abis/Appreciative.json +1280 -0
  39. package/src/contracts/abis/AppreciativeFactory.json +101 -0
  40. package/src/contracts/abis/Bundle.json +1435 -0
  41. package/src/contracts/abis/BundleFactory.json +106 -0
  42. package/src/contracts/abis/Holon.json +881 -0
  43. package/src/contracts/abis/Holons.json +330 -0
  44. package/src/contracts/abis/Managed.json +1262 -0
  45. package/src/contracts/abis/ManagedFactory.json +149 -0
  46. package/src/contracts/abis/Membrane.json +261 -0
  47. package/src/contracts/abis/Splitter.json +1624 -0
  48. package/src/contracts/abis/SplitterFactory.json +220 -0
  49. package/src/contracts/abis/TestToken.json +321 -0
  50. package/src/contracts/abis/Zoned.json +1461 -0
  51. package/src/contracts/abis/ZonedFactory.json +154 -0
  52. package/src/contracts/chain-manager.js +375 -0
  53. package/src/contracts/deployer.js +443 -0
  54. package/src/contracts/event-listener.js +507 -0
  55. package/src/contracts/holon-contracts.js +344 -0
  56. package/src/contracts/index.js +83 -0
  57. package/src/contracts/networks.js +224 -0
  58. package/src/contracts/operations.js +670 -0
  59. package/src/contracts/queries.js +589 -0
  60. package/src/core/holosphere.js +453 -1
  61. package/src/crypto/nostr-utils.js +263 -0
  62. package/src/federation/handshake.js +455 -0
  63. package/src/federation/hologram.js +1 -1
  64. package/src/hierarchical/upcast.js +6 -5
  65. package/src/index.js +463 -1939
  66. package/src/lib/ai-methods.js +308 -0
  67. package/src/lib/contract-methods.js +293 -0
  68. package/src/lib/errors.js +23 -0
  69. package/src/lib/federation-methods.js +238 -0
  70. package/src/lib/index.js +26 -0
  71. package/src/spatial/h3-operations.js +2 -2
  72. package/src/storage/backends/gundb-backend.js +377 -46
  73. package/src/storage/global-tables.js +28 -1
  74. package/src/storage/gun-auth.js +303 -0
  75. package/src/storage/gun-federation.js +776 -0
  76. package/src/storage/gun-references.js +198 -0
  77. package/src/storage/gun-schema.js +291 -0
  78. package/src/storage/gun-wrapper.js +347 -31
  79. package/src/storage/indexeddb-storage.js +49 -11
  80. package/src/storage/memory-storage.js +5 -0
  81. package/src/storage/nostr-async.js +45 -23
  82. package/src/storage/nostr-client.js +11 -5
  83. package/src/storage/persistent-storage.js +6 -1
  84. package/src/storage/unified-storage.js +119 -0
  85. package/src/subscriptions/manager.js +1 -1
  86. package/types/index.d.ts +133 -0
  87. package/dist/index-CDfIuXew.js +0 -15974
  88. package/dist/index-CDfIuXew.js.map +0 -1
  89. package/dist/index-ifOgtDvd.cjs +0 -3
  90. package/dist/index-ifOgtDvd.cjs.map +0 -1
  91. package/dist/indexeddb-storage-CMW4qRQS.js.map +0 -1
  92. package/dist/indexeddb-storage-DLZOgetM.cjs +0 -2
  93. package/dist/indexeddb-storage-DLZOgetM.cjs.map +0 -1
  94. package/dist/memory-storage-DQzcAZlf.js.map +0 -1
  95. package/dist/memory-storage-DmePEP2q.cjs.map +0 -1
  96. package/dist/secp256k1-CP0ZkpAx.cjs +0 -13
  97. package/dist/secp256k1-CP0ZkpAx.cjs.map +0 -1
  98. package/dist/secp256k1-vOXp40Fx.js.map +0 -1
@@ -0,0 +1,3058 @@
1
+ import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-CUmg6egw.js";
2
+ function _mergeNamespaces(n, m) {
3
+ for (var i = 0; i < m.length; i++) {
4
+ const e = m[i];
5
+ if (typeof e !== "string" && !Array.isArray(e)) {
6
+ for (const k in e) {
7
+ if (k !== "default" && !(k in n)) {
8
+ const d = Object.getOwnPropertyDescriptor(e, k);
9
+ if (d) {
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: () => e[k]
13
+ });
14
+ }
15
+ }
16
+ }
17
+ }
18
+ }
19
+ return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
20
+ }
21
+ function commonjsRequire(path) {
22
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
23
+ }
24
+ var gun = { exports: {} };
25
+ gun.exports;
26
+ (function(module) {
27
+ (function() {
28
+ function USE(arg, req) {
29
+ return req ? commonjsRequire(arg) : arg.slice ? USE[R(arg)] : function(mod, path) {
30
+ arg(mod = { exports: {} });
31
+ USE[R(path)] = mod.exports;
32
+ };
33
+ function R(p) {
34
+ return p.split("/").slice(-1).toString().replace(".js", "");
35
+ }
36
+ }
37
+ {
38
+ var MODULE = module;
39
+ }
40
+ USE(function(module2) {
41
+ String.random = function(l, c) {
42
+ var s = "";
43
+ l = l || 24;
44
+ c = c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";
45
+ while (l-- > 0) {
46
+ s += c.charAt(Math.floor(Math.random() * c.length));
47
+ }
48
+ return s;
49
+ };
50
+ String.match = function(t, o) {
51
+ var tmp, u;
52
+ if ("string" !== typeof t) {
53
+ return false;
54
+ }
55
+ if ("string" == typeof o) {
56
+ o = { "=": o };
57
+ }
58
+ o = o || {};
59
+ tmp = o["="] || o["*"] || o[">"] || o["<"];
60
+ if (t === tmp) {
61
+ return true;
62
+ }
63
+ if (u !== o["="]) {
64
+ return false;
65
+ }
66
+ tmp = o["*"] || o[">"];
67
+ if (t.slice(0, (tmp || "").length) === tmp) {
68
+ return true;
69
+ }
70
+ if (u !== o["*"]) {
71
+ return false;
72
+ }
73
+ if (u !== o[">"] && u !== o["<"]) {
74
+ return t >= o[">"] && t <= o["<"] ? true : false;
75
+ }
76
+ if (u !== o[">"] && t >= o[">"]) {
77
+ return true;
78
+ }
79
+ if (u !== o["<"] && t <= o["<"]) {
80
+ return true;
81
+ }
82
+ return false;
83
+ };
84
+ String.hash = function(s, c) {
85
+ if (typeof s !== "string") {
86
+ return;
87
+ }
88
+ c = c || 0;
89
+ if (!s.length) {
90
+ return c;
91
+ }
92
+ for (var i = 0, l = s.length, n; i < l; ++i) {
93
+ n = s.charCodeAt(i);
94
+ c = (c << 5) - c + n;
95
+ c |= 0;
96
+ }
97
+ return c;
98
+ };
99
+ var has = Object.prototype.hasOwnProperty;
100
+ Object.plain = function(o) {
101
+ return o ? o instanceof Object && o.constructor === Object || Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] === "Object" : false;
102
+ };
103
+ Object.empty = function(o, n) {
104
+ for (var k in o) {
105
+ if (has.call(o, k) && (!n || -1 == n.indexOf(k))) {
106
+ return false;
107
+ }
108
+ }
109
+ return true;
110
+ };
111
+ Object.keys = Object.keys || function(o) {
112
+ var l = [];
113
+ for (var k in o) {
114
+ if (has.call(o, k)) {
115
+ l.push(k);
116
+ }
117
+ }
118
+ return l;
119
+ };
120
+ (function() {
121
+ var u, sT = setTimeout, l = 0, c = 0, sI = typeof setImmediate !== "" + u && setImmediate || function(c2, f) {
122
+ if (typeof MessageChannel == "" + u) {
123
+ return sT;
124
+ }
125
+ (c2 = new MessageChannel()).port1.onmessage = function(e) {
126
+ "" == e.data && f();
127
+ };
128
+ return function(q) {
129
+ f = q;
130
+ c2.port2.postMessage("");
131
+ };
132
+ }(), check = sT.check = sT.check || typeof performance !== "" + u && performance || { now: function() {
133
+ return +/* @__PURE__ */ new Date();
134
+ } };
135
+ sT.hold = sT.hold || 9;
136
+ sT.poll = sT.poll || function(f) {
137
+ if (sT.hold >= check.now() - l && c++ < 3333) {
138
+ f();
139
+ return;
140
+ }
141
+ sI(function() {
142
+ l = check.now();
143
+ f();
144
+ }, c = 0);
145
+ };
146
+ })();
147
+ (function() {
148
+ var sT = setTimeout, t = sT.turn = sT.turn || function(f2) {
149
+ 1 == s.push(f2) && p(T);
150
+ }, s = t.s = [], p = sT.poll, i = 0, f, T = function() {
151
+ if (f = s[i++]) {
152
+ f();
153
+ }
154
+ if (i == s.length || 99 == i) {
155
+ s = t.s = s.slice(i);
156
+ i = 0;
157
+ }
158
+ if (s.length) {
159
+ p(T);
160
+ }
161
+ };
162
+ })();
163
+ (function() {
164
+ var u, sT = setTimeout, T = sT.turn;
165
+ (sT.each = sT.each || function(l, f, e, S) {
166
+ S = S || 9;
167
+ (function t(s, L, r) {
168
+ if (L = (s = (l || []).splice(0, S)).length) {
169
+ for (var i = 0; i < L; i++) {
170
+ if (u !== (r = f(s[i]))) {
171
+ break;
172
+ }
173
+ }
174
+ if (u === r) {
175
+ T(t);
176
+ return;
177
+ }
178
+ }
179
+ e && e(r);
180
+ })();
181
+ })();
182
+ })();
183
+ })(USE, "./shim");
184
+ USE(function(module2) {
185
+ module2.exports = function onto(tag, arg, as) {
186
+ if (!tag) {
187
+ return { to: onto };
188
+ }
189
+ var u, f = "function" == typeof arg, tag = (this.tag || (this.tag = {}))[tag] || f && (this.tag[tag] = { tag, to: onto._ = { next: function(arg2) {
190
+ var tmp;
191
+ if (tmp = this.to) {
192
+ tmp.next(arg2);
193
+ }
194
+ } } });
195
+ if (f) {
196
+ var be = {
197
+ off: onto.off || (onto.off = function() {
198
+ if (this.next === onto._.next) {
199
+ return true;
200
+ }
201
+ if (this === this.the.last) {
202
+ this.the.last = this.back;
203
+ }
204
+ this.to.back = this.back;
205
+ this.next = onto._.next;
206
+ this.back.to = this.to;
207
+ if (this.the.last === this.the) {
208
+ delete this.on.tag[this.the.tag];
209
+ }
210
+ }),
211
+ to: onto._,
212
+ next: arg,
213
+ the: tag,
214
+ on: this,
215
+ as
216
+ };
217
+ (be.back = tag.last || tag).to = be;
218
+ return tag.last = be;
219
+ }
220
+ if ((tag = tag.to) && u !== arg) {
221
+ tag.next(arg);
222
+ }
223
+ return tag;
224
+ };
225
+ })(USE, "./onto");
226
+ USE(function(module2) {
227
+ module2.exports = function(v) {
228
+ return v === null || "string" === typeof v || "boolean" === typeof v || // we want +/- Infinity to be, but JSON does not support it, sad face.
229
+ // can you guess what v === v checks for? ;)
230
+ "number" === typeof v && v != Infinity && v != -Infinity && v === v || !!v && "string" == typeof v["#"] && Object.keys(v).length === 1 && v["#"];
231
+ };
232
+ })(USE, "./valid");
233
+ USE(function(module2) {
234
+ USE("./shim");
235
+ function State() {
236
+ var t = +/* @__PURE__ */ new Date();
237
+ if (last < t) {
238
+ return N = 0, last = t + State.drift;
239
+ }
240
+ return last = t + (N += 1) / D + State.drift;
241
+ }
242
+ State.drift = 0;
243
+ var NI = -Infinity, N = 0, D = 999, last = NI, u;
244
+ State.is = function(n, k, o) {
245
+ var tmp = k && n && n._ && n._[">"] || o;
246
+ if (!tmp) {
247
+ return;
248
+ }
249
+ return "number" == typeof (tmp = tmp[k]) ? tmp : NI;
250
+ };
251
+ State.ify = function(n, k, s, v, soul) {
252
+ (n = n || {})._ = n._ || {};
253
+ if (soul) {
254
+ n._["#"] = soul;
255
+ }
256
+ var tmp = n._[">"] || (n._[">"] = {});
257
+ if (u !== k && k !== "_") {
258
+ if ("number" == typeof s) {
259
+ tmp[k] = s;
260
+ }
261
+ if (u !== v) {
262
+ n[k] = v;
263
+ }
264
+ }
265
+ return n;
266
+ };
267
+ module2.exports = State;
268
+ })(USE, "./state");
269
+ USE(function(module2) {
270
+ USE("./shim");
271
+ function Dup(opt) {
272
+ var dup = { s: {} }, s = dup.s;
273
+ opt = opt || { max: 999, age: 1e3 * 9 };
274
+ dup.check = function(id) {
275
+ if (!s[id]) {
276
+ return false;
277
+ }
278
+ return dt(id);
279
+ };
280
+ var dt = dup.track = function(id) {
281
+ var it = s[id] || (s[id] = {});
282
+ it.was = dup.now = +/* @__PURE__ */ new Date();
283
+ if (!dup.to) {
284
+ dup.to = setTimeout(dup.drop, opt.age + 9);
285
+ }
286
+ if (dt.ed) {
287
+ dt.ed(id);
288
+ }
289
+ return it;
290
+ };
291
+ dup.drop = function(age) {
292
+ dup.to = null;
293
+ dup.now = +/* @__PURE__ */ new Date();
294
+ var l = Object.keys(s);
295
+ console.STAT && console.STAT(dup.now, +/* @__PURE__ */ new Date() - dup.now, "dup drop keys");
296
+ setTimeout.each(l, function(id) {
297
+ var it = s[id];
298
+ if (it && (age || opt.age) > dup.now - it.was) {
299
+ return;
300
+ }
301
+ delete s[id];
302
+ }, 0, 99);
303
+ };
304
+ return dup;
305
+ }
306
+ module2.exports = Dup;
307
+ })(USE, "./dup");
308
+ USE(function(module2) {
309
+ USE("./onto");
310
+ module2.exports = function ask(cb, as) {
311
+ if (!this.on) {
312
+ return;
313
+ }
314
+ var lack = (this.opt || {}).lack || 9e3;
315
+ if (!("function" == typeof cb)) {
316
+ if (!cb) {
317
+ return;
318
+ }
319
+ var id = cb["#"] || cb, tmp = (this.tag || "")[id];
320
+ if (!tmp) {
321
+ return;
322
+ }
323
+ if (as) {
324
+ tmp = this.on(id, as);
325
+ clearTimeout(tmp.err);
326
+ tmp.err = setTimeout(function() {
327
+ tmp.off();
328
+ }, lack);
329
+ }
330
+ return true;
331
+ }
332
+ var id = as && as["#"] || random(9);
333
+ if (!cb) {
334
+ return id;
335
+ }
336
+ var to = this.on(id, cb, as);
337
+ to.err = to.err || setTimeout(function() {
338
+ to.off();
339
+ to.next({ err: "Error: No ACK yet.", lack: true });
340
+ }, lack);
341
+ return id;
342
+ };
343
+ var random = String.random || function() {
344
+ return Math.random().toString(36).slice(2);
345
+ };
346
+ })(USE, "./ask");
347
+ USE(function(module2) {
348
+ function Gun2(o) {
349
+ if (o instanceof Gun2) {
350
+ return (this._ = { $: this }).$;
351
+ }
352
+ if (!(this instanceof Gun2)) {
353
+ return new Gun2(o);
354
+ }
355
+ return Gun2.create(this._ = { $: this, opt: o });
356
+ }
357
+ Gun2.is = function($) {
358
+ return $ instanceof Gun2 || $ && $._ && $ === $._.$ || false;
359
+ };
360
+ Gun2.version = 0.202;
361
+ Gun2.chain = Gun2.prototype;
362
+ Gun2.chain.toJSON = function() {
363
+ };
364
+ USE("./shim");
365
+ Gun2.valid = USE("./valid");
366
+ Gun2.state = USE("./state");
367
+ Gun2.on = USE("./onto");
368
+ Gun2.dup = USE("./dup");
369
+ Gun2.ask = USE("./ask");
370
+ (function() {
371
+ Gun2.create = function(at) {
372
+ at.root = at.root || at;
373
+ at.graph = at.graph || {};
374
+ at.on = at.on || Gun2.on;
375
+ at.ask = at.ask || Gun2.ask;
376
+ at.dup = at.dup || Gun2.dup();
377
+ var gun2 = at.$.opt(at.opt);
378
+ if (!at.once) {
379
+ at.on("in", universe, at);
380
+ at.on("out", universe, at);
381
+ at.on("put", map, at);
382
+ Gun2.on("create", at);
383
+ at.on("create", at);
384
+ }
385
+ at.once = 1;
386
+ return gun2;
387
+ };
388
+ function universe(msg) {
389
+ if (!msg) {
390
+ return;
391
+ }
392
+ if (msg.out === universe) {
393
+ this.to.next(msg);
394
+ return;
395
+ }
396
+ var eve = this, as = eve.as, at = as.at || as, gun2 = at.$, dup = at.dup, tmp, DBG = msg.DBG;
397
+ (tmp = msg["#"]) || (tmp = msg["#"] = text_rand(9));
398
+ if (dup.check(tmp)) {
399
+ return;
400
+ }
401
+ dup.track(tmp);
402
+ tmp = msg._;
403
+ msg._ = "function" == typeof tmp ? tmp : function() {
404
+ };
405
+ msg.$ && msg.$ === (msg.$._ || "").$ || (msg.$ = gun2);
406
+ if (msg["@"] && !msg.put) {
407
+ ack(msg);
408
+ }
409
+ if (!at.ask(msg["@"], msg)) {
410
+ DBG && (DBG.u = +/* @__PURE__ */ new Date());
411
+ if (msg.put) {
412
+ put(msg);
413
+ return;
414
+ } else if (msg.get) {
415
+ Gun2.on.get(msg, gun2);
416
+ }
417
+ }
418
+ DBG && (DBG.uc = +/* @__PURE__ */ new Date());
419
+ eve.to.next(msg);
420
+ DBG && (DBG.ua = +/* @__PURE__ */ new Date());
421
+ if (msg.nts || msg.NTS) {
422
+ return;
423
+ }
424
+ msg.out = universe;
425
+ at.on("out", msg);
426
+ DBG && (DBG.ue = +/* @__PURE__ */ new Date());
427
+ }
428
+ function put(msg) {
429
+ if (!msg) {
430
+ return;
431
+ }
432
+ var ctx = msg._ || "", root = ctx.root = ((ctx.$ = msg.$ || "")._ || "").root;
433
+ if (msg["@"] && ctx.faith && !ctx.miss) {
434
+ msg.out = universe;
435
+ root.on("out", msg);
436
+ return;
437
+ }
438
+ ctx.latch = root.hatch;
439
+ ctx.match = root.hatch = [];
440
+ var put2 = msg.put;
441
+ var DBG = ctx.DBG = msg.DBG, S = +/* @__PURE__ */ new Date();
442
+ CT = CT || S;
443
+ if (put2["#"] && put2["."]) {
444
+ return;
445
+ }
446
+ DBG && (DBG.p = S);
447
+ ctx["#"] = msg["#"];
448
+ ctx.msg = msg;
449
+ ctx.all = 0;
450
+ ctx.stun = 1;
451
+ var nl = Object.keys(put2);
452
+ console.STAT && console.STAT(S, ((DBG || ctx).pk = +/* @__PURE__ */ new Date()) - S, "put sort");
453
+ var ni = 0, nj, kl, soul, node, states, err, tmp;
454
+ (function pop(o) {
455
+ if (nj != ni) {
456
+ nj = ni;
457
+ if (!(soul = nl[ni])) {
458
+ console.STAT && console.STAT(S, ((DBG || ctx).pd = +/* @__PURE__ */ new Date()) - S, "put");
459
+ fire(ctx);
460
+ return;
461
+ }
462
+ if (!(node = put2[soul])) {
463
+ err = ERR + cut(soul) + "no node.";
464
+ } else if (!(tmp = node._)) {
465
+ err = ERR + cut(soul) + "no meta.";
466
+ } else if (soul !== tmp["#"]) {
467
+ err = ERR + cut(soul) + "soul not same.";
468
+ } else if (!(states = tmp[">"])) {
469
+ err = ERR + cut(soul) + "no state.";
470
+ }
471
+ kl = Object.keys(node || {});
472
+ }
473
+ if (err) {
474
+ msg.err = ctx.err = err;
475
+ fire(ctx);
476
+ return;
477
+ }
478
+ var i = 0, key;
479
+ o = o || 0;
480
+ while (o++ < 9 && (key = kl[i++])) {
481
+ if ("_" === key) {
482
+ continue;
483
+ }
484
+ var val = node[key], state = states[key];
485
+ if (u === state) {
486
+ err = ERR + cut(key) + "on" + cut(soul) + "no state.";
487
+ break;
488
+ }
489
+ if (!valid(val)) {
490
+ err = ERR + cut(key) + "on" + cut(soul) + "bad " + typeof val + cut(val);
491
+ break;
492
+ }
493
+ ham(val, key, soul, state, msg);
494
+ ++C2;
495
+ }
496
+ if ((kl = kl.slice(i)).length) {
497
+ turn(pop);
498
+ return;
499
+ }
500
+ ++ni;
501
+ kl = null;
502
+ pop(o);
503
+ })();
504
+ }
505
+ Gun2.on.put = put;
506
+ function ham(val, key, soul, state, msg) {
507
+ var ctx = msg._ || "", root = ctx.root, graph = root.graph, tmp;
508
+ var vertex = graph[soul] || empty, was = state_is(vertex, key, 1), known = vertex[key];
509
+ var DBG = ctx.DBG;
510
+ if (tmp = console.STAT) {
511
+ if (!graph[soul] || !known) {
512
+ tmp.has = (tmp.has || 0) + 1;
513
+ }
514
+ }
515
+ var now = State();
516
+ if (state > now) {
517
+ setTimeout(function() {
518
+ ham(val, key, soul, state, msg);
519
+ }, (tmp = state - now) > MD ? MD : tmp);
520
+ console.STAT && console.STAT((DBG || ctx).Hf = +/* @__PURE__ */ new Date(), tmp, "future");
521
+ return;
522
+ }
523
+ if (state < was) {
524
+ {
525
+ return;
526
+ }
527
+ }
528
+ if (!ctx.faith) {
529
+ if (state === was && (val === known || L(val) <= L(known))) {
530
+ if (!ctx.miss) {
531
+ return;
532
+ }
533
+ }
534
+ }
535
+ ctx.stun++;
536
+ var aid = msg["#"] + ctx.all++, id = { toString: function() {
537
+ return aid;
538
+ }, _: ctx };
539
+ id.toJSON = id.toString;
540
+ root.dup.track(id)["#"] = msg["#"];
541
+ DBG && (DBG.ph = DBG.ph || +/* @__PURE__ */ new Date());
542
+ root.on("put", { "#": id, "@": msg["@"], put: { "#": soul, ".": key, ":": val, ">": state }, ok: msg.ok, _: ctx });
543
+ }
544
+ function map(msg) {
545
+ var DBG;
546
+ if (DBG = (msg._ || "").DBG) {
547
+ DBG.pa = +/* @__PURE__ */ new Date();
548
+ DBG.pm = DBG.pm || +/* @__PURE__ */ new Date();
549
+ }
550
+ var eve = this, root = eve.as, graph = root.graph, ctx = msg._, put2 = msg.put, soul = put2["#"], key = put2["."], val = put2[":"], state = put2[">"];
551
+ msg["#"];
552
+ var tmp;
553
+ if ((tmp = ctx.msg) && (tmp = tmp.put) && (tmp = tmp[soul])) {
554
+ state_ify(tmp, key, state, val, soul);
555
+ }
556
+ graph[soul] = state_ify(graph[soul], key, state, val, soul);
557
+ if (tmp = (root.next || "")[soul]) {
558
+ tmp.on("in", msg);
559
+ }
560
+ fire(ctx);
561
+ eve.to.next(msg);
562
+ }
563
+ function fire(ctx, msg) {
564
+ var root;
565
+ if (ctx.stop) {
566
+ return;
567
+ }
568
+ if (!ctx.err && 0 < --ctx.stun) {
569
+ return;
570
+ }
571
+ ctx.stop = 1;
572
+ if (!(root = ctx.root)) {
573
+ return;
574
+ }
575
+ var tmp = ctx.match;
576
+ tmp.end = 1;
577
+ if (tmp === root.hatch) {
578
+ if (!(tmp = ctx.latch) || tmp.end) {
579
+ delete root.hatch;
580
+ } else {
581
+ root.hatch = tmp;
582
+ }
583
+ }
584
+ ctx.hatch && ctx.hatch();
585
+ setTimeout.each(ctx.match, function(cb) {
586
+ cb && cb();
587
+ });
588
+ if (!(msg = ctx.msg) || ctx.err || msg.err) {
589
+ return;
590
+ }
591
+ msg.out = universe;
592
+ ctx.root.on("out", msg);
593
+ CF();
594
+ }
595
+ function ack(msg) {
596
+ var id = msg["@"] || "", ctx;
597
+ if (!(ctx = id._)) {
598
+ var dup = (dup = msg.$) && (dup = dup._) && (dup = dup.root) && (dup = dup.dup);
599
+ if (!(dup = dup.check(id))) {
600
+ return;
601
+ }
602
+ msg["@"] = dup["#"] || msg["@"];
603
+ return;
604
+ }
605
+ ctx.acks = (ctx.acks || 0) + 1;
606
+ if (ctx.err = msg.err) {
607
+ msg["@"] = ctx["#"];
608
+ fire(ctx);
609
+ }
610
+ ctx.ok = msg.ok || ctx.ok;
611
+ if (!ctx.stop && !ctx.crack) {
612
+ ctx.crack = ctx.match && ctx.match.push(function() {
613
+ back(ctx);
614
+ });
615
+ }
616
+ back(ctx);
617
+ }
618
+ function back(ctx) {
619
+ if (!ctx || !ctx.root) {
620
+ return;
621
+ }
622
+ if (ctx.stun || ctx.acks !== ctx.all) {
623
+ return;
624
+ }
625
+ ctx.root.on("in", { "@": ctx["#"], err: ctx.err, ok: ctx.err ? u : ctx.ok || { "": 1 } });
626
+ }
627
+ var ERR = "Error: Invalid graph!";
628
+ var cut = function(s) {
629
+ return " '" + ("" + s).slice(0, 9) + "...' ";
630
+ };
631
+ var L = JSON.stringify, MD = 2147483647, State = Gun2.state;
632
+ var C2 = 0, CT, CF = function() {
633
+ if (C2 > 999 && C2 / -(CT - (CT = +/* @__PURE__ */ new Date())) > 1) {
634
+ Gun2.window && console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query.");
635
+ CF = function() {
636
+ C2 = 0;
637
+ };
638
+ }
639
+ };
640
+ })();
641
+ (function() {
642
+ Gun2.on.get = function(msg, gun2) {
643
+ var root = gun2._, get = msg.get, soul = get["#"], node = root.graph[soul], has = get["."];
644
+ var next = root.next || (root.next = {}), at = next[soul];
645
+ var ctx = msg._ || {}, DBG = ctx.DBG = msg.DBG;
646
+ DBG && (DBG.g = +/* @__PURE__ */ new Date());
647
+ if (!node) {
648
+ return root.on("get", msg);
649
+ }
650
+ if (has) {
651
+ if ("string" != typeof has || u === node[has]) {
652
+ if (!((at || "").next || "")[has]) {
653
+ root.on("get", msg);
654
+ return;
655
+ }
656
+ }
657
+ node = state_ify({}, has, state_is(node, has), node[has], soul);
658
+ }
659
+ node && ack(msg, node);
660
+ root.on("get", msg);
661
+ };
662
+ function ack(msg, node) {
663
+ var S = +/* @__PURE__ */ new Date(), ctx = msg._ || {}, DBG = ctx.DBG = msg.DBG;
664
+ var to = msg["#"], id = text_rand(9), keys = Object.keys(node || "").sort(), soul = ((node || "")._ || "")["#"];
665
+ keys.length;
666
+ var root = msg.$._.root, F = node === root.graph[soul];
667
+ console.STAT && console.STAT(S, ((DBG || ctx).gk = +/* @__PURE__ */ new Date()) - S, "got keys");
668
+ node && function go() {
669
+ S = +/* @__PURE__ */ new Date();
670
+ var i = 0, k, put = {}, tmp;
671
+ while (i < 9 && (k = keys[i++])) {
672
+ state_ify(put, k, state_is(node, k), node[k], soul);
673
+ }
674
+ keys = keys.slice(i);
675
+ (tmp = {})[soul] = put;
676
+ put = tmp;
677
+ var faith;
678
+ if (F) {
679
+ faith = function() {
680
+ };
681
+ faith.ram = faith.faith = true;
682
+ }
683
+ tmp = keys.length;
684
+ console.STAT && console.STAT(S, -(S - (S = +/* @__PURE__ */ new Date())), "got copied some");
685
+ DBG && (DBG.ga = +/* @__PURE__ */ new Date());
686
+ root.on("in", { "@": to, "#": id, put, "%": tmp ? id = text_rand(9) : u, $: root.$, _: faith, DBG, FOO: 1 });
687
+ console.STAT && console.STAT(S, +/* @__PURE__ */ new Date() - S, "got in");
688
+ if (!tmp) {
689
+ return;
690
+ }
691
+ setTimeout.turn(go);
692
+ }();
693
+ if (!node) {
694
+ root.on("in", { "@": msg["#"] });
695
+ }
696
+ }
697
+ Gun2.on.get.ack = ack;
698
+ })();
699
+ (function() {
700
+ Gun2.chain.opt = function(opt) {
701
+ opt = opt || {};
702
+ var gun2 = this, at = gun2._, tmp = opt.peers || opt;
703
+ if (!Object.plain(opt)) {
704
+ opt = {};
705
+ }
706
+ if (!Object.plain(at.opt)) {
707
+ at.opt = opt;
708
+ }
709
+ if ("string" == typeof tmp) {
710
+ tmp = [tmp];
711
+ }
712
+ if (!Object.plain(at.opt.peers)) {
713
+ at.opt.peers = {};
714
+ }
715
+ if (tmp instanceof Array) {
716
+ opt.peers = {};
717
+ tmp.forEach(function(url) {
718
+ var p = {};
719
+ p.id = p.url = url;
720
+ opt.peers[url] = at.opt.peers[url] = at.opt.peers[url] || p;
721
+ });
722
+ }
723
+ obj_each(opt, function each(k) {
724
+ var v = this[k];
725
+ if (this && this.hasOwnProperty(k) || "string" == typeof v || Object.empty(v)) {
726
+ this[k] = v;
727
+ return;
728
+ }
729
+ if (v && v.constructor !== Object && !(v instanceof Array)) {
730
+ return;
731
+ }
732
+ obj_each(v, each);
733
+ });
734
+ at.opt.from = opt;
735
+ Gun2.on("opt", at);
736
+ at.opt.uuid = at.opt.uuid || function uuid(l) {
737
+ return Gun2.state().toString(36).replace(".", "") + String.random(l || 12);
738
+ };
739
+ return gun2;
740
+ };
741
+ })();
742
+ var obj_each = function(o, f) {
743
+ Object.keys(o).forEach(f, o);
744
+ }, text_rand = String.random, turn = setTimeout.turn, valid = Gun2.valid, state_is = Gun2.state.is, state_ify = Gun2.state.ify, u, empty = {}, C;
745
+ Gun2.log = function() {
746
+ return !Gun2.log.off && C.log.apply(C, arguments), [].slice.call(arguments).join(" ");
747
+ };
748
+ Gun2.log.once = function(w, s, o) {
749
+ return (o = Gun2.log.once)[w] = o[w] || 0, o[w]++ || Gun2.log(s);
750
+ };
751
+ if (typeof window !== "undefined") {
752
+ (window.GUN = window.Gun = Gun2).window = window;
753
+ }
754
+ try {
755
+ if (typeof MODULE !== "undefined") {
756
+ MODULE.exports = Gun2;
757
+ }
758
+ } catch (e) {
759
+ }
760
+ module2.exports = Gun2;
761
+ (Gun2.window || {}).console = (Gun2.window || {}).console || { log: function() {
762
+ } };
763
+ (C = console).only = function(i, s) {
764
+ return C.only.i && i === C.only.i && C.only.i++ && (C.log.apply(C, arguments) || s);
765
+ };
766
+ Gun2.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!");
767
+ })(USE, "./root");
768
+ USE(function(module2) {
769
+ var Gun2 = USE("./root");
770
+ Gun2.chain.back = function(n, opt) {
771
+ var tmp;
772
+ n = n || 1;
773
+ if (-1 === n || Infinity === n) {
774
+ return this._.root.$;
775
+ } else if (1 === n) {
776
+ return (this._.back || this._).$;
777
+ }
778
+ var gun2 = this, at = gun2._;
779
+ if (typeof n === "string") {
780
+ n = n.split(".");
781
+ }
782
+ if (n instanceof Array) {
783
+ var i = 0, l = n.length, tmp = at;
784
+ for (i; i < l; i++) {
785
+ tmp = (tmp || empty)[n[i]];
786
+ }
787
+ if (u !== tmp) {
788
+ return opt ? gun2 : tmp;
789
+ } else if (tmp = at.back) {
790
+ return tmp.$.back(n, opt);
791
+ }
792
+ return;
793
+ }
794
+ if ("function" == typeof n) {
795
+ var yes, tmp = { back: at };
796
+ while ((tmp = tmp.back) && u === (yes = n(tmp, opt))) {
797
+ }
798
+ return yes;
799
+ }
800
+ if ("number" == typeof n) {
801
+ return (at.back || at).$.back(n - 1);
802
+ }
803
+ return this;
804
+ };
805
+ var empty = {}, u;
806
+ })(USE, "./back");
807
+ USE(function(module2) {
808
+ var Gun2 = USE("./root");
809
+ Gun2.chain.chain = function(sub) {
810
+ var gun2 = this, at = gun2._, chain = new (sub || gun2).constructor(gun2), cat = chain._, root;
811
+ cat.root = root = at.root;
812
+ cat.id = ++root.once;
813
+ cat.back = gun2._;
814
+ cat.on = Gun2.on;
815
+ cat.on("in", Gun2.on.in, cat);
816
+ cat.on("out", Gun2.on.out, cat);
817
+ return chain;
818
+ };
819
+ function output(msg) {
820
+ var get, at = this.as, back = at.back, root = at.root, tmp;
821
+ if (!msg.$) {
822
+ msg.$ = at.$;
823
+ }
824
+ this.to.next(msg);
825
+ if (at.err) {
826
+ at.on("in", { put: at.put = u, $: at.$ });
827
+ return;
828
+ }
829
+ if (get = msg.get) {
830
+ if (root.pass) {
831
+ root.pass[at.id] = at;
832
+ }
833
+ if (at.lex) {
834
+ Object.keys(at.lex).forEach(function(k) {
835
+ tmp[k] = at.lex[k];
836
+ }, tmp = msg.get = msg.get || {});
837
+ }
838
+ if (get["#"] || at.soul) {
839
+ get["#"] = get["#"] || at.soul;
840
+ msg["#"] || (msg["#"] = text_rand(9));
841
+ back = root.$.get(get["#"])._;
842
+ if (!(get = get["."])) {
843
+ tmp = back.ask && back.ask[""];
844
+ (back.ask || (back.ask = {}))[""] = back;
845
+ if (u !== back.put) {
846
+ back.on("in", back);
847
+ if (tmp) {
848
+ return;
849
+ }
850
+ }
851
+ msg.$ = back.$;
852
+ } else if (obj_has(back.put, get)) {
853
+ tmp = back.ask && back.ask[get];
854
+ (back.ask || (back.ask = {}))[get] = back.$.get(get)._;
855
+ back.on("in", { get, put: { "#": back.soul, ".": get, ":": back.put[get], ">": state_is(root.graph[back.soul], get) } });
856
+ if (tmp) {
857
+ return;
858
+ }
859
+ }
860
+ root.ask(ack, msg);
861
+ return root.on("in", msg);
862
+ }
863
+ if (get["."]) {
864
+ if (at.get) {
865
+ msg = { get: { ".": at.get }, $: at.$ };
866
+ (back.ask || (back.ask = {}))[at.get] = msg.$._;
867
+ return back.on("out", msg);
868
+ }
869
+ msg = { get: at.lex ? msg.get : {}, $: at.$ };
870
+ return back.on("out", msg);
871
+ }
872
+ (at.ask || (at.ask = {}))[""] = at;
873
+ if (at.get) {
874
+ get["."] = at.get;
875
+ (back.ask || (back.ask = {}))[at.get] = msg.$._;
876
+ return back.on("out", msg);
877
+ }
878
+ }
879
+ return back.on("out", msg);
880
+ }
881
+ Gun2.on.out = output;
882
+ function input(msg, cat) {
883
+ cat = cat || this.as;
884
+ var root = cat.root, gun2 = msg.$ || (msg.$ = cat.$), at = (gun2 || "")._ || empty, tmp = msg.put || "", soul = tmp["#"], key = tmp["."], change = u !== tmp["="] ? tmp["="] : tmp[":"], state2 = tmp[">"] || -Infinity, sat;
885
+ if (u !== msg.put && (u === tmp["#"] || u === tmp["."] || u === tmp[":"] && u === tmp["="] || u === tmp[">"])) {
886
+ if (!valid(tmp)) {
887
+ if (!(soul = ((tmp || "")._ || "")["#"])) {
888
+ console.log("chain not yet supported for", tmp, "...", msg, cat);
889
+ return;
890
+ }
891
+ gun2 = cat.root.$.get(soul);
892
+ return setTimeout.each(Object.keys(tmp).sort(), function(k) {
893
+ if ("_" == k || u === (state2 = state_is(tmp, k))) {
894
+ return;
895
+ }
896
+ cat.on("in", { $: gun2, put: { "#": soul, ".": k, "=": tmp[k], ">": state2 }, VIA: msg });
897
+ });
898
+ }
899
+ cat.on("in", { $: at.back.$, put: { "#": soul = at.back.soul, ".": key = at.has || at.get, "=": tmp, ">": state_is(at.back.put, key) }, via: msg });
900
+ return;
901
+ }
902
+ if ((msg.seen || "")[cat.id]) {
903
+ return;
904
+ }
905
+ (msg.seen || (msg.seen = function() {
906
+ }))[cat.id] = cat;
907
+ if (cat !== at) {
908
+ Object.keys(msg).forEach(function(k) {
909
+ tmp[k] = msg[k];
910
+ }, tmp = {});
911
+ tmp.get = cat.get || tmp.get;
912
+ if (!cat.soul && !cat.has) {
913
+ tmp.$$$ = tmp.$$$ || cat.$;
914
+ } else if (at.soul) {
915
+ tmp.$ = cat.$;
916
+ tmp.$$ = tmp.$$ || at.$;
917
+ }
918
+ msg = tmp;
919
+ }
920
+ unlink(msg, cat);
921
+ if ((cat.soul || msg.$$) && state2 >= state_is(root.graph[soul], key)) {
922
+ (tmp = root.$.get(soul)._).put = state_ify(tmp.put, key, state2, change, soul);
923
+ }
924
+ if (!at.soul && state2 >= state_is(root.graph[soul], key) && (sat = (root.$.get(soul)._.next || "")[key])) {
925
+ sat.put = change;
926
+ if ("string" == typeof (tmp = valid(change))) {
927
+ sat.put = root.$.get(tmp)._.put || change;
928
+ }
929
+ }
930
+ this.to && this.to.next(msg);
931
+ cat.any && setTimeout.each(Object.keys(cat.any), function(any) {
932
+ (any = cat.any[any]) && any(msg);
933
+ }, 0, 99);
934
+ cat.echo && setTimeout.each(Object.keys(cat.echo), function(lat) {
935
+ (lat = cat.echo[lat]) && lat.on("in", msg);
936
+ }, 0, 99);
937
+ if (((msg.$$ || "")._ || at).soul) {
938
+ if ((sat = cat.next) && (sat = sat[key])) {
939
+ tmp = {};
940
+ Object.keys(msg).forEach(function(k) {
941
+ tmp[k] = msg[k];
942
+ });
943
+ tmp.$ = (msg.$$ || msg.$).get(tmp.get = key);
944
+ delete tmp.$$;
945
+ delete tmp.$$$;
946
+ sat.on("in", tmp);
947
+ }
948
+ }
949
+ link(msg, cat);
950
+ }
951
+ Gun2.on.in = input;
952
+ function link(msg, cat) {
953
+ cat = cat || this.as || msg.$._;
954
+ if (msg.$$ && this !== Gun2.on) {
955
+ return;
956
+ }
957
+ if (!msg.put || cat.soul) {
958
+ return;
959
+ }
960
+ var put = msg.put || "", link2 = put["="] || put[":"], tmp;
961
+ var root = cat.root, tat = root.$.get(put["#"]).get(put["."])._;
962
+ if ("string" != typeof (link2 = valid(link2))) {
963
+ if (this === Gun2.on) {
964
+ (tat.echo || (tat.echo = {}))[cat.id] = cat;
965
+ }
966
+ return;
967
+ }
968
+ if ((tat.echo || (tat.echo = {}))[cat.id] && !(root.pass || "")[cat.id]) {
969
+ return;
970
+ }
971
+ if (tmp = root.pass) {
972
+ if (tmp[link2 + cat.id]) {
973
+ return;
974
+ }
975
+ tmp[link2 + cat.id] = 1;
976
+ }
977
+ (tat.echo || (tat.echo = {}))[cat.id] = cat;
978
+ if (cat.has) {
979
+ cat.link = link2;
980
+ }
981
+ var sat = root.$.get(tat.link = link2)._;
982
+ (sat.echo || (sat.echo = {}))[tat.id] = tat;
983
+ var tmp = cat.ask || "";
984
+ if (tmp[""] || cat.lex) {
985
+ sat.on("out", { get: { "#": link2 } });
986
+ }
987
+ setTimeout.each(Object.keys(tmp), function(get, sat2) {
988
+ if (!get || !(sat2 = tmp[get])) {
989
+ return;
990
+ }
991
+ sat2.on("out", { get: { "#": link2, ".": get } });
992
+ }, 0, 99);
993
+ }
994
+ Gun2.on.link = link;
995
+ function unlink(msg, cat) {
996
+ var put = msg.put || "", change = u !== put["="] ? put["="] : put[":"], root = cat.root, link2, tmp;
997
+ if (u === change) {
998
+ if (cat.soul && u !== cat.put) {
999
+ return;
1000
+ }
1001
+ tmp = (msg.$$ || msg.$ || "")._ || "";
1002
+ if (msg["@"] && (u !== tmp.put || u !== cat.put)) {
1003
+ return;
1004
+ }
1005
+ if (link2 = cat.link || msg.linked) {
1006
+ delete (root.$.get(link2)._.echo || "")[cat.id];
1007
+ }
1008
+ if (cat.has) {
1009
+ cat.link = null;
1010
+ }
1011
+ cat.put = u;
1012
+ setTimeout.each(Object.keys(cat.next || ""), function(get, sat) {
1013
+ if (!(sat = cat.next[get])) {
1014
+ return;
1015
+ }
1016
+ if (link2) {
1017
+ delete (root.$.get(link2).get(get)._.echo || "")[sat.id];
1018
+ }
1019
+ sat.on("in", { get, put: u, $: sat.$ });
1020
+ }, 0, 99);
1021
+ return;
1022
+ }
1023
+ if (cat.soul) {
1024
+ return;
1025
+ }
1026
+ if (msg.$$) {
1027
+ return;
1028
+ }
1029
+ link2 = valid(change);
1030
+ tmp = msg.$._ || "";
1031
+ if (link2 === tmp.link || cat.has && !tmp.link) {
1032
+ if ((root.pass || "")[cat.id] && "string" !== typeof link2) ;
1033
+ else {
1034
+ return;
1035
+ }
1036
+ }
1037
+ delete (tmp.echo || "")[cat.id];
1038
+ unlink({ get: cat.get, put: u, $: msg.$, linked: msg.linked = msg.linked || tmp.link }, cat);
1039
+ }
1040
+ Gun2.on.unlink = unlink;
1041
+ function ack(msg, ev) {
1042
+ var as = this.as, at = as.$._;
1043
+ at.root;
1044
+ var get = as.get || "", tmp = (msg.put || "")[get["#"]] || "";
1045
+ if (!msg.put || "string" == typeof get["."] && u === tmp[get["."]]) {
1046
+ if (u !== at.put) {
1047
+ return;
1048
+ }
1049
+ if (!at.soul && !at.has) {
1050
+ return;
1051
+ }
1052
+ at.ack = (at.ack || 0) + 1;
1053
+ at.on("in", {
1054
+ get: at.get,
1055
+ put: at.put = u,
1056
+ $: at.$,
1057
+ "@": msg["@"]
1058
+ });
1059
+ return;
1060
+ }
1061
+ (msg._ || {}).miss = 1;
1062
+ Gun2.on.put(msg);
1063
+ return;
1064
+ }
1065
+ var empty = {}, u, text_rand = String.random, valid = Gun2.valid, obj_has = function(o, k) {
1066
+ return o && Object.prototype.hasOwnProperty.call(o, k);
1067
+ }, state = Gun2.state, state_is = state.is, state_ify = state.ify;
1068
+ })(USE, "./chain");
1069
+ USE(function(module2) {
1070
+ var Gun2 = USE("./root");
1071
+ Gun2.chain.get = function(key, cb, as) {
1072
+ var gun2, tmp;
1073
+ if (typeof key === "string") {
1074
+ if (key.length == 0) {
1075
+ (gun2 = this.chain())._.err = { err: Gun2.log("0 length key!", key) };
1076
+ if (cb) {
1077
+ cb.call(gun2, gun2._.err);
1078
+ }
1079
+ return gun2;
1080
+ }
1081
+ var back = this, cat = back._;
1082
+ var next = cat.next || empty;
1083
+ if (!(gun2 = next[key])) {
1084
+ gun2 = key && cache(key, back);
1085
+ }
1086
+ gun2 = gun2 && gun2.$;
1087
+ } else if ("function" == typeof key) {
1088
+ let any = function(msg, eve, f) {
1089
+ if (any.stun) {
1090
+ return;
1091
+ }
1092
+ if ((tmp2 = root.pass) && !tmp2[id]) {
1093
+ return;
1094
+ }
1095
+ var at = msg.$._, sat = (msg.$$ || "")._, data = (sat || at).put, odd = !at.has && !at.soul, test = {}, tmp2;
1096
+ if (odd || u === data) {
1097
+ data = u === ((tmp2 = msg.put) || "")["="] ? u === (tmp2 || "")[":"] ? tmp2 : tmp2[":"] : tmp2["="];
1098
+ }
1099
+ if ("string" == typeof (tmp2 = Gun2.valid(data))) {
1100
+ data = u === (tmp2 = root.$.get(tmp2)._.put) ? opt.not ? u : data : tmp2;
1101
+ }
1102
+ if (opt.not && u === data) {
1103
+ return;
1104
+ }
1105
+ if (u === opt.stun) {
1106
+ if ((tmp2 = root.stun) && tmp2.on) {
1107
+ cat.$.back(function(a) {
1108
+ tmp2.on("" + a.id, test = {});
1109
+ if ((test.run || 0) < any.id) {
1110
+ return test;
1111
+ }
1112
+ });
1113
+ !test.run && tmp2.on("" + at.id, test = {});
1114
+ !test.run && sat && tmp2.on("" + sat.id, test = {});
1115
+ if (any.id > test.run) {
1116
+ if (!test.stun || test.stun.end) {
1117
+ test.stun = tmp2.on("stun");
1118
+ test.stun = test.stun && test.stun.last;
1119
+ }
1120
+ if (test.stun && !test.stun.end) {
1121
+ (test.stun.add || (test.stun.add = {}))[id] = function() {
1122
+ any(msg, eve, 1);
1123
+ };
1124
+ return;
1125
+ }
1126
+ }
1127
+ }
1128
+ if (
1129
+ /*odd &&*/
1130
+ u === data
1131
+ ) {
1132
+ f = 0;
1133
+ }
1134
+ if ((tmp2 = root.hatch) && !tmp2.end && u === opt.hatch && !f) {
1135
+ if (wait[at.$._.id]) {
1136
+ return;
1137
+ }
1138
+ wait[at.$._.id] = 1;
1139
+ tmp2.push(function() {
1140
+ any(msg, eve, 1);
1141
+ });
1142
+ return;
1143
+ }
1144
+ wait = {};
1145
+ }
1146
+ if (root.pass) {
1147
+ if (root.pass[id + at.id]) {
1148
+ return;
1149
+ }
1150
+ root.pass[id + at.id] = 1;
1151
+ }
1152
+ if (opt.on) {
1153
+ opt.ok.call(at.$, data, at.get, msg, eve || any);
1154
+ return;
1155
+ }
1156
+ if (opt.v2020) {
1157
+ opt.ok(msg, eve || any);
1158
+ return;
1159
+ }
1160
+ Object.keys(msg).forEach(function(k) {
1161
+ tmp2[k] = msg[k];
1162
+ }, tmp2 = {});
1163
+ msg = tmp2;
1164
+ msg.put = data;
1165
+ opt.ok.call(opt.as, msg, eve || any);
1166
+ };
1167
+ if (true === cb) {
1168
+ return soul(this, key, cb, as), this;
1169
+ }
1170
+ gun2 = this;
1171
+ var cat = gun2._, opt = cb || {}, root = cat.root, id;
1172
+ opt.at = cat;
1173
+ opt.ok = key;
1174
+ var wait = {};
1175
+ any.at = cat;
1176
+ (cat.any || (cat.any = {}))[id = String.random(7)] = any;
1177
+ any.off = function() {
1178
+ any.stun = 1;
1179
+ if (!cat.any) {
1180
+ return;
1181
+ }
1182
+ delete cat.any[id];
1183
+ };
1184
+ any.rid = rid;
1185
+ any.id = opt.run || ++root.once;
1186
+ tmp = root.pass;
1187
+ (root.pass = {})[id] = 1;
1188
+ opt.out = opt.out || { get: {} };
1189
+ cat.on("out", opt.out);
1190
+ root.pass = tmp;
1191
+ return gun2;
1192
+ } else if ("number" == typeof key) {
1193
+ return this.get("" + key, cb, as);
1194
+ } else if ("string" == typeof (tmp = valid(key))) {
1195
+ return this.get(tmp, cb, as);
1196
+ } else if (tmp = this.get.next) {
1197
+ gun2 = tmp(this, key);
1198
+ }
1199
+ if (!gun2) {
1200
+ (gun2 = this.chain())._.err = { err: Gun2.log("Invalid get request!", key) };
1201
+ if (cb) {
1202
+ cb.call(gun2, gun2._.err);
1203
+ }
1204
+ return gun2;
1205
+ }
1206
+ if (cb && "function" == typeof cb) {
1207
+ gun2.get(cb, as);
1208
+ }
1209
+ return gun2;
1210
+ };
1211
+ function cache(key, back) {
1212
+ var cat = back._, next = cat.next, gun2 = back.chain(), at = gun2._;
1213
+ if (!next) {
1214
+ next = cat.next = {};
1215
+ }
1216
+ next[at.get = key] = at;
1217
+ if (back === cat.root.$) {
1218
+ at.soul = key;
1219
+ } else if (cat.soul || cat.has) {
1220
+ at.has = key;
1221
+ }
1222
+ return at;
1223
+ }
1224
+ function soul(gun2, cb, opt, as) {
1225
+ var cat = gun2._, acks = 0, tmp;
1226
+ if (tmp = cat.soul || cat.link) {
1227
+ return cb(tmp, as, cat);
1228
+ }
1229
+ if (cat.jam) {
1230
+ return cat.jam.push([cb, as]);
1231
+ }
1232
+ cat.jam = [[cb, as]];
1233
+ gun2.get(function go(msg, eve) {
1234
+ if (u === msg.put && !cat.root.opt.super && (tmp = Object.keys(cat.root.opt.peers).length) && ++acks <= tmp) {
1235
+ return;
1236
+ }
1237
+ eve.rid(msg);
1238
+ var at = (at = msg.$) && at._ || {}, i = 0, as2;
1239
+ tmp = cat.jam;
1240
+ delete cat.jam;
1241
+ while (as2 = tmp[i++]) {
1242
+ var cb2 = as2[0];
1243
+ as2 = as2[1];
1244
+ cb2 && cb2(at.link || at.soul || Gun2.valid(msg.put) || ((msg.put || {})._ || {})["#"], as2, msg, eve);
1245
+ }
1246
+ }, { out: { get: { ".": true } } });
1247
+ return gun2;
1248
+ }
1249
+ function rid(at) {
1250
+ var cat = this.at || this.on;
1251
+ if (!at || cat.soul || cat.has) {
1252
+ return this.off();
1253
+ }
1254
+ if (!(at = (at = (at = at.$ || at)._ || at).id)) {
1255
+ return;
1256
+ }
1257
+ cat.map;
1258
+ var seen;
1259
+ if ((seen = this.seen || (this.seen = {}))[at]) {
1260
+ return true;
1261
+ }
1262
+ seen[at] = true;
1263
+ return;
1264
+ }
1265
+ var empty = {}, valid = Gun2.valid, u;
1266
+ })(USE, "./get");
1267
+ USE(function(module2) {
1268
+ var Gun2 = USE("./root");
1269
+ Gun2.chain.put = function(data, cb, as) {
1270
+ var gun2 = this, at = gun2._, root = at.root;
1271
+ as = as || {};
1272
+ as.root = at.root;
1273
+ as.run || (as.run = root.once);
1274
+ stun(as, at.id);
1275
+ as.ack = as.ack || cb;
1276
+ as.via = as.via || gun2;
1277
+ as.data = as.data || data;
1278
+ as.soul || (as.soul = at.soul || "string" == typeof cb && cb);
1279
+ var s = as.state = as.state || Gun2.state();
1280
+ if ("function" == typeof data) {
1281
+ data(function(d) {
1282
+ as.data = d;
1283
+ gun2.put(u, u, as);
1284
+ });
1285
+ return gun2;
1286
+ }
1287
+ if (!as.soul) {
1288
+ return get(as), gun2;
1289
+ }
1290
+ as.$ = root.$.get(as.soul);
1291
+ as.todo = [{ it: as.data, ref: as.$ }];
1292
+ as.turn = as.turn || turn;
1293
+ as.ran = as.ran || ran;
1294
+ (function walk() {
1295
+ var to = as.todo, at2 = to.pop(), d = at2.it;
1296
+ at2.ref && at2.ref._.id;
1297
+ var v, k, cat, tmp, g;
1298
+ stun(as, at2.ref);
1299
+ if (tmp = at2.todo) {
1300
+ k = tmp.pop();
1301
+ d = d[k];
1302
+ if (tmp.length) {
1303
+ to.push(at2);
1304
+ }
1305
+ }
1306
+ k && (to.path || (to.path = [])).push(k);
1307
+ if (!(v = valid(d)) && !(g = Gun2.is(d))) {
1308
+ if (!Object.plain(d)) {
1309
+ ran.err(as, "Invalid data: " + check(d) + " at " + (as.via.back(function(at3) {
1310
+ at3.get && tmp.push(at3.get);
1311
+ }, tmp = []) || tmp.join(".")) + "." + (to.path || []).join("."));
1312
+ return;
1313
+ }
1314
+ var seen = as.seen || (as.seen = []), i = seen.length;
1315
+ while (i--) {
1316
+ if (d === (tmp = seen[i]).it) {
1317
+ v = d = tmp.link;
1318
+ break;
1319
+ }
1320
+ }
1321
+ }
1322
+ if (k && v) {
1323
+ at2.node = state_ify(at2.node, k, s, d);
1324
+ } else {
1325
+ let resolve = function(msg, eve) {
1326
+ var end = cat.link["#"];
1327
+ if (eve) {
1328
+ eve.off();
1329
+ eve.rid(msg);
1330
+ }
1331
+ var soul = end || msg.soul || (tmp = (msg.$$ || msg.$)._ || "").soul || tmp.link || ((tmp = tmp.put || "")._ || "")["#"] || tmp["#"] || ((tmp = msg.put || "") && msg.$$ ? tmp["#"] : (tmp["="] || tmp[":"] || "")["#"]);
1332
+ !end && stun(as, msg.$);
1333
+ if (!soul && !at2.link["#"]) {
1334
+ (at2.wait || (at2.wait = [])).push(function() {
1335
+ resolve(msg, eve);
1336
+ });
1337
+ return;
1338
+ }
1339
+ if (!soul) {
1340
+ soul = [];
1341
+ (msg.$$ || msg.$).back(function(at3) {
1342
+ if (tmp = at3.soul || at3.link) {
1343
+ return soul.push(tmp);
1344
+ }
1345
+ soul.push(at3.get);
1346
+ });
1347
+ soul = soul.reverse().join("/");
1348
+ }
1349
+ cat.link["#"] = soul;
1350
+ !g && (((as.graph || (as.graph = {}))[soul] = cat.node || (cat.node = { _: {} }))._["#"] = soul);
1351
+ delete as.wait[id];
1352
+ cat.wait && setTimeout.each(cat.wait, function(cb2) {
1353
+ cb2 && cb2();
1354
+ });
1355
+ as.ran(as);
1356
+ };
1357
+ if (!as.seen) {
1358
+ ran.err(as, "Data at root of graph must be a node (an object).");
1359
+ return;
1360
+ }
1361
+ as.seen.push(cat = { it: d, link: {}, todo: g ? [] : Object.keys(d).sort().reverse(), path: (to.path || []).slice(), up: at2 });
1362
+ at2.node = state_ify(at2.node, k, s, cat.link);
1363
+ !g && cat.todo.length && to.push(cat);
1364
+ var id = as.seen.length;
1365
+ (as.wait || (as.wait = {}))[id] = "";
1366
+ tmp = (cat.ref = g ? d : k ? at2.ref.get(k) : at2.ref)._;
1367
+ (tmp = d && (d._ || "")["#"] || tmp.soul || tmp.link) ? resolve({ soul: tmp }) : cat.ref.get(resolve, {
1368
+ run: as.run,
1369
+ /*hatch: 0,*/
1370
+ v2020: 1,
1371
+ out: { get: { ".": " " } }
1372
+ });
1373
+ }
1374
+ if (!to.length) {
1375
+ return as.ran(as);
1376
+ }
1377
+ as.turn(walk);
1378
+ })();
1379
+ return gun2;
1380
+ };
1381
+ function stun(as, id) {
1382
+ if (!id) {
1383
+ return;
1384
+ }
1385
+ id = (id._ || "").id || id;
1386
+ var run = as.root.stun || (as.root.stun = { on: Gun2.on }), test = {}, tmp;
1387
+ as.stun || (as.stun = run.on("stun", function() {
1388
+ }));
1389
+ if (tmp = run.on("" + id)) {
1390
+ tmp.the.last.next(test);
1391
+ }
1392
+ if (test.run >= as.run) {
1393
+ return;
1394
+ }
1395
+ run.on("" + id, function(test2) {
1396
+ if (as.stun.end) {
1397
+ this.off();
1398
+ this.to.next(test2);
1399
+ return;
1400
+ }
1401
+ test2.run = test2.run || as.run;
1402
+ test2.stun = test2.stun || as.stun;
1403
+ return;
1404
+ });
1405
+ }
1406
+ function ran(as) {
1407
+ if (as.err) {
1408
+ ran.end(as.stun, as.root);
1409
+ return;
1410
+ }
1411
+ if (as.todo.length || as.end || !Object.empty(as.wait)) {
1412
+ return;
1413
+ }
1414
+ as.end = 1;
1415
+ var cat = as.$.back(-1)._, root = cat.root, ask = cat.ask(function(ack) {
1416
+ root.on("ack", ack);
1417
+ if (ack.err && !ack.lack) {
1418
+ Gun2.log(ack);
1419
+ }
1420
+ if (++acks > (as.acks || 0)) {
1421
+ this.off();
1422
+ }
1423
+ if (!as.ack) {
1424
+ return;
1425
+ }
1426
+ as.ack(ack, this);
1427
+ }, as.opt), acks = 0, stun2 = as.stun, tmp;
1428
+ (tmp = function() {
1429
+ if (!stun2) {
1430
+ return;
1431
+ }
1432
+ ran.end(stun2, root);
1433
+ setTimeout.each(Object.keys(stun2 = stun2.add || ""), function(cb) {
1434
+ if (cb = stun2[cb]) {
1435
+ cb();
1436
+ }
1437
+ });
1438
+ }).hatch = tmp;
1439
+ if (as.ack && !as.ok) {
1440
+ as.ok = as.acks || 9;
1441
+ }
1442
+ as.via._.on("out", { put: as.out = as.graph, ok: as.ok && { "@": as.ok + 1 }, opt: as.opt, "#": ask, _: tmp });
1443
+ }
1444
+ ran.end = function(stun2, root) {
1445
+ stun2.end = noop;
1446
+ if (stun2.the.to === stun2 && stun2 === stun2.the.last) {
1447
+ delete root.stun;
1448
+ }
1449
+ stun2.off();
1450
+ };
1451
+ ran.err = function(as, err) {
1452
+ (as.ack || noop).call(as, as.out = { err: as.err = Gun2.log(err) });
1453
+ as.ran(as);
1454
+ };
1455
+ function get(as) {
1456
+ var at = as.via._, tmp;
1457
+ as.via = as.via.back(function(at2) {
1458
+ if (at2.soul || !at2.get) {
1459
+ return at2.$;
1460
+ }
1461
+ tmp = as.data;
1462
+ (as.data = {})[at2.get] = tmp;
1463
+ });
1464
+ if (!as.via || !as.via._.soul) {
1465
+ as.via = at.root.$.get(((as.data || "")._ || "")["#"] || at.$.back("opt.uuid")());
1466
+ }
1467
+ as.via.put(as.data, as.ack, as);
1468
+ return;
1469
+ }
1470
+ function check(d, tmp) {
1471
+ return d && (tmp = d.constructor) && tmp.name || typeof d;
1472
+ }
1473
+ var u, noop = function() {
1474
+ }, turn = setTimeout.turn, valid = Gun2.valid, state_ify = Gun2.state.ify;
1475
+ })(USE, "./put");
1476
+ USE(function(module2) {
1477
+ var Gun2 = USE("./root");
1478
+ USE("./chain");
1479
+ USE("./back");
1480
+ USE("./put");
1481
+ USE("./get");
1482
+ module2.exports = Gun2;
1483
+ })(USE, "./index");
1484
+ USE(function(module2) {
1485
+ var Gun2 = USE("./index");
1486
+ Gun2.chain.on = function(tag, arg, eas, as) {
1487
+ var gun2 = this, cat = gun2._;
1488
+ cat.root;
1489
+ var act;
1490
+ if (typeof tag === "string") {
1491
+ if (!arg) {
1492
+ return cat.on(tag);
1493
+ }
1494
+ act = cat.on(tag, arg, eas || cat, as);
1495
+ if (eas && eas.$) {
1496
+ (eas.subs || (eas.subs = [])).push(act);
1497
+ }
1498
+ return gun2;
1499
+ }
1500
+ var opt = arg;
1501
+ (opt = true === opt ? { change: true } : opt || {}).not = 1;
1502
+ opt.on = 1;
1503
+ gun2.get(tag, opt);
1504
+ return gun2;
1505
+ };
1506
+ Gun2.chain.once = function(cb, opt) {
1507
+ opt = opt || {};
1508
+ if (!cb) {
1509
+ return none(this);
1510
+ }
1511
+ var gun2 = this, cat = gun2._, root = cat.root;
1512
+ cat.put;
1513
+ var id = String.random(7), tmp;
1514
+ gun2.get(function(data, key, msg, eve) {
1515
+ var $ = this, at = $._, one = at.one || (at.one = {});
1516
+ if (eve.stun) {
1517
+ return;
1518
+ }
1519
+ if ("" === one[id]) {
1520
+ return;
1521
+ }
1522
+ if (true === (tmp = Gun2.valid(data))) {
1523
+ once();
1524
+ return;
1525
+ }
1526
+ if ("string" == typeof tmp) {
1527
+ return;
1528
+ }
1529
+ clearTimeout((cat.one || "")[id]);
1530
+ clearTimeout(one[id]);
1531
+ one[id] = setTimeout(once, opt.wait || 99);
1532
+ function once(f) {
1533
+ if (!at.has && !at.soul) {
1534
+ at = { put: data, get: key };
1535
+ }
1536
+ if (u === (tmp = at.put)) {
1537
+ tmp = ((msg.$$ || "")._ || "").put;
1538
+ }
1539
+ if ("string" == typeof Gun2.valid(tmp)) {
1540
+ tmp = root.$.get(tmp)._.put;
1541
+ if (tmp === u && !f) {
1542
+ one[id] = setTimeout(function() {
1543
+ once(1);
1544
+ }, opt.wait || 99);
1545
+ return;
1546
+ }
1547
+ }
1548
+ if (eve.stun) {
1549
+ return;
1550
+ }
1551
+ if ("" === one[id]) {
1552
+ return;
1553
+ }
1554
+ one[id] = "";
1555
+ if (cat.soul || cat.has) {
1556
+ eve.off();
1557
+ }
1558
+ cb.call($, tmp, at.get);
1559
+ clearTimeout(one[id]);
1560
+ }
1561
+ }, { on: 1 });
1562
+ return gun2;
1563
+ };
1564
+ function none(gun2, opt, chain) {
1565
+ Gun2.log.once("valonce", "Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
1566
+ (chain = gun2.chain())._.nix = gun2.once(function(data, key) {
1567
+ chain._.on("in", this._);
1568
+ });
1569
+ chain._.lex = gun2._.lex;
1570
+ return chain;
1571
+ }
1572
+ Gun2.chain.off = function() {
1573
+ var gun2 = this, at = gun2._, tmp;
1574
+ var cat = at.back;
1575
+ if (!cat) {
1576
+ return;
1577
+ }
1578
+ at.ack = 0;
1579
+ if (tmp = cat.next) {
1580
+ if (tmp[at.get]) {
1581
+ delete tmp[at.get];
1582
+ }
1583
+ }
1584
+ if (tmp = cat.any) {
1585
+ delete cat.any;
1586
+ cat.any = {};
1587
+ }
1588
+ if (tmp = cat.ask) {
1589
+ delete tmp[at.get];
1590
+ }
1591
+ if (tmp = cat.put) {
1592
+ delete tmp[at.get];
1593
+ }
1594
+ if (tmp = at.soul) {
1595
+ delete cat.root.graph[tmp];
1596
+ }
1597
+ if (tmp = at.map) {
1598
+ Object.keys(tmp).forEach(function(i, at2) {
1599
+ at2 = tmp[i];
1600
+ if (at2.link) {
1601
+ cat.root.$.get(at2.link).off();
1602
+ }
1603
+ });
1604
+ }
1605
+ if (tmp = at.next) {
1606
+ Object.keys(tmp).forEach(function(i, neat) {
1607
+ neat = tmp[i];
1608
+ neat.$.off();
1609
+ });
1610
+ }
1611
+ at.on("off", {});
1612
+ return gun2;
1613
+ };
1614
+ var u;
1615
+ })(USE, "./on");
1616
+ USE(function(module2) {
1617
+ var Gun2 = USE("./index"), next = Gun2.chain.get.next;
1618
+ Gun2.chain.get.next = function(gun2, lex) {
1619
+ var tmp;
1620
+ if (!Object.plain(lex)) {
1621
+ return (next || noop)(gun2, lex);
1622
+ }
1623
+ if (tmp = ((tmp = lex["#"]) || "")["="] || tmp) {
1624
+ return gun2.get(tmp);
1625
+ }
1626
+ (tmp = gun2.chain()._).lex = lex;
1627
+ gun2.on("in", function(eve) {
1628
+ if (String.match(eve.get || (eve.put || "")["."], lex["."] || lex["#"] || lex)) {
1629
+ tmp.on("in", eve);
1630
+ }
1631
+ this.to.next(eve);
1632
+ });
1633
+ return tmp.$;
1634
+ };
1635
+ Gun2.chain.map = function(cb, opt, t) {
1636
+ var gun2 = this, cat = gun2._, lex, chain;
1637
+ if (Object.plain(cb)) {
1638
+ lex = cb["."] ? cb : { ".": cb };
1639
+ cb = u;
1640
+ }
1641
+ if (!cb) {
1642
+ if (chain = cat.each) {
1643
+ return chain;
1644
+ }
1645
+ (cat.each = chain = gun2.chain())._.lex = lex || chain._.lex || cat.lex;
1646
+ chain._.nix = gun2.back("nix");
1647
+ gun2.on("in", map, chain._);
1648
+ return chain;
1649
+ }
1650
+ Gun2.log.once("mapfn", "Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it.");
1651
+ chain = gun2.chain();
1652
+ gun2.map().on(function(data, key, msg, eve) {
1653
+ var next2 = (cb || noop).call(this, data, key, msg, eve);
1654
+ if (u === next2) {
1655
+ return;
1656
+ }
1657
+ if (data === next2) {
1658
+ return chain._.on("in", msg);
1659
+ }
1660
+ if (Gun2.is(next2)) {
1661
+ return chain._.on("in", next2._);
1662
+ }
1663
+ var tmp = {};
1664
+ Object.keys(msg.put).forEach(function(k) {
1665
+ tmp[k] = msg.put[k];
1666
+ }, tmp);
1667
+ tmp["="] = next2;
1668
+ chain._.on("in", { get: key, put: tmp });
1669
+ });
1670
+ return chain;
1671
+ };
1672
+ function map(msg) {
1673
+ this.to.next(msg);
1674
+ var cat = this.as, gun2 = msg.$, at = gun2._, put = msg.put, tmp;
1675
+ if (!at.soul && !msg.$$) {
1676
+ return;
1677
+ }
1678
+ if ((tmp = cat.lex) && !String.match(msg.get || (put || "")["."], tmp["."] || tmp["#"] || tmp)) {
1679
+ return;
1680
+ }
1681
+ Gun2.on.link(msg, cat);
1682
+ }
1683
+ var noop = function() {
1684
+ }, u;
1685
+ })(USE, "./map");
1686
+ USE(function(module2) {
1687
+ var Gun2 = USE("./index");
1688
+ Gun2.chain.set = function(item, cb, opt) {
1689
+ var gun2 = this, root = gun2.back(-1), soul, tmp;
1690
+ cb = cb || function() {
1691
+ };
1692
+ opt = opt || {};
1693
+ opt.item = opt.item || item;
1694
+ if (soul = ((item || "")._ || "")["#"]) {
1695
+ (item = {})["#"] = soul;
1696
+ }
1697
+ if ("string" == typeof (tmp = Gun2.valid(item))) {
1698
+ return gun2.get(soul = tmp).put(item, cb, opt);
1699
+ }
1700
+ if (!Gun2.is(item)) {
1701
+ if (Object.plain(item)) {
1702
+ item = root.get(soul = gun2.back("opt.uuid")()).put(item);
1703
+ }
1704
+ return gun2.get(soul || root.back("opt.uuid")(7)).put(item, cb, opt);
1705
+ }
1706
+ gun2.put(function(go) {
1707
+ item.get(function(soul2, o, msg) {
1708
+ if (!soul2) {
1709
+ return cb.call(gun2, { err: Gun2.log('Only a node can be linked! Not "' + msg.put + '"!') });
1710
+ }
1711
+ (tmp = {})[soul2] = { "#": soul2 };
1712
+ go(tmp);
1713
+ }, true);
1714
+ });
1715
+ return item;
1716
+ };
1717
+ })(USE, "./set");
1718
+ USE(function(module2) {
1719
+ USE("./shim");
1720
+ var noop = function() {
1721
+ };
1722
+ var parse = JSON.parseAsync || function(t, cb, r) {
1723
+ var u2, d = +/* @__PURE__ */ new Date();
1724
+ try {
1725
+ cb(u2, JSON.parse(t, r), json.sucks(+/* @__PURE__ */ new Date() - d));
1726
+ } catch (e) {
1727
+ cb(e);
1728
+ }
1729
+ };
1730
+ var json = JSON.stringifyAsync || function(v, cb, r, s) {
1731
+ var u2, d = +/* @__PURE__ */ new Date();
1732
+ try {
1733
+ cb(u2, JSON.stringify(v, r, s), json.sucks(+/* @__PURE__ */ new Date() - d));
1734
+ } catch (e) {
1735
+ cb(e);
1736
+ }
1737
+ };
1738
+ json.sucks = function(d) {
1739
+ if (d > 99) {
1740
+ console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix.");
1741
+ json.sucks = noop;
1742
+ }
1743
+ };
1744
+ function Mesh(root) {
1745
+ var mesh = function() {
1746
+ };
1747
+ var opt = root.opt || {};
1748
+ opt.log = opt.log || console.log;
1749
+ opt.gap = opt.gap || opt.wait || 0;
1750
+ opt.max = opt.max || (opt.memory ? opt.memory * 999 * 999 : 3e8) * 0.3;
1751
+ opt.pack = opt.pack || opt.max * 0.01 * 0.01;
1752
+ opt.puff = opt.puff || 9;
1753
+ var puff = setTimeout.turn || setTimeout;
1754
+ var dup = root.dup, dup_check = dup.check, dup_track = dup.track;
1755
+ var hear = mesh.hear = function(raw, peer) {
1756
+ if (!raw) {
1757
+ return;
1758
+ }
1759
+ if (opt.max <= raw.length) {
1760
+ return mesh.say({ dam: "!", err: "Message too big!" }, peer);
1761
+ }
1762
+ if (mesh === this) {
1763
+ hear.d += raw.length || 0;
1764
+ ++hear.c;
1765
+ }
1766
+ var S = peer.SH = +/* @__PURE__ */ new Date();
1767
+ var tmp = raw[0], msg;
1768
+ if ("[" === tmp) {
1769
+ parse(raw, function(err, msg2) {
1770
+ if (err || !msg2) {
1771
+ return mesh.say({ dam: "!", err: "DAM JSON parse error." }, peer);
1772
+ }
1773
+ console.STAT && console.STAT(+/* @__PURE__ */ new Date(), msg2.length, "# on hear batch");
1774
+ var P = opt.puff;
1775
+ (function go() {
1776
+ var S2 = +/* @__PURE__ */ new Date();
1777
+ var i = 0, m;
1778
+ while (i < P && (m = msg2[i++])) {
1779
+ mesh.hear(m, peer);
1780
+ }
1781
+ msg2 = msg2.slice(i);
1782
+ console.STAT && console.STAT(S2, +/* @__PURE__ */ new Date() - S2, "hear loop");
1783
+ flush(peer);
1784
+ if (!msg2.length) {
1785
+ return;
1786
+ }
1787
+ puff(go, 0);
1788
+ })();
1789
+ });
1790
+ raw = "";
1791
+ return;
1792
+ }
1793
+ if ("{" === tmp || (raw["#"] || Object.plain(raw)) && (msg = raw)) {
1794
+ if (msg) {
1795
+ return hear.one(msg, peer, S);
1796
+ }
1797
+ parse(raw, function(err, msg2) {
1798
+ if (err || !msg2) {
1799
+ return mesh.say({ dam: "!", err: "DAM JSON parse error." }, peer);
1800
+ }
1801
+ hear.one(msg2, peer, S);
1802
+ });
1803
+ return;
1804
+ }
1805
+ };
1806
+ hear.one = function(msg, peer, S) {
1807
+ var id, hash, tmp, ash, DBG;
1808
+ if (msg.DBG) {
1809
+ msg.DBG = DBG = { DBG: msg.DBG };
1810
+ }
1811
+ DBG && (DBG.h = S);
1812
+ DBG && (DBG.hp = +/* @__PURE__ */ new Date());
1813
+ if (!(id = msg["#"])) {
1814
+ id = msg["#"] = String.random(9);
1815
+ }
1816
+ if (tmp = dup_check(id)) {
1817
+ return;
1818
+ }
1819
+ if (!(hash = msg["##"]) && false) ;
1820
+ if (hash && (tmp = msg["@"] || msg.get && id) && dup.check(ash = tmp + hash)) {
1821
+ return;
1822
+ }
1823
+ (msg._ = function() {
1824
+ }).via = mesh.leap = peer;
1825
+ if ((tmp = msg["><"]) && "string" == typeof tmp) {
1826
+ tmp.slice(0, 99).split(",").forEach(function(k) {
1827
+ this[k] = 1;
1828
+ }, msg._.yo = {});
1829
+ }
1830
+ if (tmp = msg.dam) {
1831
+ if (tmp = mesh.hear[tmp]) {
1832
+ tmp(msg, peer, root);
1833
+ }
1834
+ dup_track(id);
1835
+ return;
1836
+ }
1837
+ if (tmp = msg.ok) {
1838
+ msg._.near = tmp["/"];
1839
+ }
1840
+ var S = +/* @__PURE__ */ new Date();
1841
+ DBG && (DBG.is = S);
1842
+ peer.SI = id;
1843
+ dup_track.ed = function(d) {
1844
+ if (id !== d) {
1845
+ return;
1846
+ }
1847
+ dup_track.ed = 0;
1848
+ if (!(d = dup.s[id])) {
1849
+ return;
1850
+ }
1851
+ d.via = peer;
1852
+ if (msg.get) {
1853
+ d.it = msg;
1854
+ }
1855
+ };
1856
+ root.on("in", mesh.last = msg);
1857
+ DBG && (DBG.hd = +/* @__PURE__ */ new Date());
1858
+ console.STAT && console.STAT(S, +/* @__PURE__ */ new Date() - S, msg.get ? "msg get" : msg.put ? "msg put" : "msg");
1859
+ dup_track(id);
1860
+ if (ash) {
1861
+ dup_track(ash);
1862
+ }
1863
+ mesh.leap = mesh.last = null;
1864
+ };
1865
+ hear.c = hear.d = 0;
1866
+ (function() {
1867
+ var SMIA = 0;
1868
+ var loop;
1869
+ mesh.hash = function(msg, peer) {
1870
+ var h, s, t;
1871
+ var S = +/* @__PURE__ */ new Date();
1872
+ json(msg.put, function hash(err, text) {
1873
+ var ss = (s || (s = t = text || "")).slice(0, 32768);
1874
+ h = String.hash(ss, h);
1875
+ s = s.slice(32768);
1876
+ if (s) {
1877
+ puff(hash, 0);
1878
+ return;
1879
+ }
1880
+ console.STAT && console.STAT(S, +/* @__PURE__ */ new Date() - S, "say json+hash");
1881
+ msg._.$put = t;
1882
+ msg["##"] = h;
1883
+ mesh.say(msg, peer);
1884
+ delete msg._.$put;
1885
+ }, sort);
1886
+ };
1887
+ function sort(k, v) {
1888
+ var tmp;
1889
+ if (!(v instanceof Object)) {
1890
+ return v;
1891
+ }
1892
+ Object.keys(v).sort().forEach(sorta, { to: tmp = {}, on: v });
1893
+ return tmp;
1894
+ }
1895
+ function sorta(k) {
1896
+ this.to[k] = this.on[k];
1897
+ }
1898
+ mesh.say = function(msg, peer) {
1899
+ var tmp;
1900
+ if ((tmp = this) && (tmp = tmp.to) && tmp.next) {
1901
+ tmp.next(msg);
1902
+ }
1903
+ if (!msg) {
1904
+ return false;
1905
+ }
1906
+ var id, hash, raw, ack = msg["@"];
1907
+ var meta = msg._ || (msg._ = function() {
1908
+ });
1909
+ var DBG = msg.DBG, S = +/* @__PURE__ */ new Date();
1910
+ meta.y = meta.y || S;
1911
+ if (!peer) {
1912
+ DBG && (DBG.y = S);
1913
+ }
1914
+ if (!(id = msg["#"])) {
1915
+ id = msg["#"] = String.random(9);
1916
+ }
1917
+ !loop && dup_track(id);
1918
+ if (!(hash = msg["##"]) && u !== msg.put && !meta.via && ack) {
1919
+ mesh.hash(msg, peer);
1920
+ return;
1921
+ }
1922
+ if (!peer && ack) {
1923
+ peer = (tmp = dup.s[ack]) && (tmp.via || (tmp = tmp.it) && (tmp = tmp._) && tmp.via) || (tmp = mesh.last) && ack === tmp["#"] && mesh.leap;
1924
+ }
1925
+ if (!peer && ack) {
1926
+ if (dup.s[ack]) {
1927
+ return;
1928
+ }
1929
+ console.STAT && console.STAT(+/* @__PURE__ */ new Date(), ++SMIA, "total no peer to ack to");
1930
+ return false;
1931
+ }
1932
+ if (ack && !msg.put && !hash && ((dup.s[ack] || "").it || "")["##"]) {
1933
+ return false;
1934
+ }
1935
+ if (!peer && mesh.way) {
1936
+ return mesh.way(msg);
1937
+ }
1938
+ DBG && (DBG.yh = +/* @__PURE__ */ new Date());
1939
+ if (!(raw = meta.raw)) {
1940
+ mesh.raw(msg, peer);
1941
+ return;
1942
+ }
1943
+ DBG && (DBG.yr = +/* @__PURE__ */ new Date());
1944
+ if (!peer || !peer.id) {
1945
+ if (!Object.plain(peer || opt.peers)) {
1946
+ return false;
1947
+ }
1948
+ var S = +/* @__PURE__ */ new Date();
1949
+ opt.puff;
1950
+ var ps = opt.peers, pl = Object.keys(peer || opt.peers || {});
1951
+ console.STAT && console.STAT(S, +/* @__PURE__ */ new Date() - S, "peer keys");
1952
+ (function go() {
1953
+ var S2 = +/* @__PURE__ */ new Date();
1954
+ loop = 1;
1955
+ var wr = meta.raw;
1956
+ meta.raw = raw;
1957
+ var i = 0, p;
1958
+ while (i < 9 && (p = (pl || "")[i++])) {
1959
+ if (!(p = ps[p] || (peer || "")[p])) {
1960
+ continue;
1961
+ }
1962
+ mesh.say(msg, p);
1963
+ }
1964
+ meta.raw = wr;
1965
+ loop = 0;
1966
+ pl = pl.slice(i);
1967
+ console.STAT && console.STAT(S2, +/* @__PURE__ */ new Date() - S2, "say loop");
1968
+ if (!pl.length) {
1969
+ return;
1970
+ }
1971
+ puff(go, 0);
1972
+ ack && dup_track(ack);
1973
+ })();
1974
+ return;
1975
+ }
1976
+ if (!peer.wire && mesh.wire) {
1977
+ mesh.wire(peer);
1978
+ }
1979
+ if (id === peer.last) {
1980
+ return;
1981
+ }
1982
+ peer.last = id;
1983
+ if (peer === meta.via) {
1984
+ return false;
1985
+ }
1986
+ if ((tmp = meta.yo) && (tmp[peer.url] || tmp[peer.pid] || tmp[peer.id])) {
1987
+ return false;
1988
+ }
1989
+ console.STAT && console.STAT(S, ((DBG || meta).yp = +/* @__PURE__ */ new Date()) - (meta.y || S), "say prep");
1990
+ !loop && ack && dup_track(ack);
1991
+ if (peer.batch) {
1992
+ peer.tail = (tmp = peer.tail || 0) + raw.length;
1993
+ if (peer.tail <= opt.pack) {
1994
+ peer.batch += (tmp ? "," : "") + raw;
1995
+ return;
1996
+ }
1997
+ flush(peer);
1998
+ }
1999
+ peer.batch = "[";
2000
+ var ST = +/* @__PURE__ */ new Date();
2001
+ setTimeout(function() {
2002
+ console.STAT && console.STAT(ST, +/* @__PURE__ */ new Date() - ST, "0ms TO");
2003
+ flush(peer);
2004
+ }, opt.gap);
2005
+ send(raw, peer);
2006
+ console.STAT && ack === peer.SI && console.STAT(S, +/* @__PURE__ */ new Date() - peer.SH, "say ack");
2007
+ };
2008
+ mesh.say.c = mesh.say.d = 0;
2009
+ mesh.raw = function(msg, peer) {
2010
+ if (!msg) {
2011
+ return "";
2012
+ }
2013
+ var meta = msg._ || {}, put, tmp;
2014
+ if (tmp = meta.raw) {
2015
+ return tmp;
2016
+ }
2017
+ if ("string" == typeof msg) {
2018
+ return msg;
2019
+ }
2020
+ var hash = msg["##"], ack = msg["@"];
2021
+ if (hash && ack) {
2022
+ if (!meta.via && dup_check(ack + hash)) {
2023
+ return false;
2024
+ }
2025
+ if (tmp = (dup.s[ack] || "").it) {
2026
+ if (hash === tmp["##"]) {
2027
+ return false;
2028
+ }
2029
+ if (!tmp["##"]) {
2030
+ tmp["##"] = hash;
2031
+ }
2032
+ }
2033
+ }
2034
+ if (!msg.dam && !msg["@"]) {
2035
+ var i = 0, to = [];
2036
+ tmp = opt.peers;
2037
+ for (var k in tmp) {
2038
+ var p = tmp[k];
2039
+ to.push(p.url || p.pid || p.id);
2040
+ if (++i > 6) {
2041
+ break;
2042
+ }
2043
+ }
2044
+ if (i > 1) {
2045
+ msg["><"] = to.join();
2046
+ }
2047
+ }
2048
+ if (msg.put && (tmp = msg.ok)) {
2049
+ msg.ok = { "@": (tmp["@"] || 1) - 1, "/": tmp["/"] == msg._.near ? mesh.near : tmp["/"] };
2050
+ }
2051
+ if (put = meta.$put) {
2052
+ tmp = {};
2053
+ Object.keys(msg).forEach(function(k2) {
2054
+ tmp[k2] = msg[k2];
2055
+ });
2056
+ tmp.put = ":])([:";
2057
+ json(tmp, function(err, raw) {
2058
+ if (err) {
2059
+ return;
2060
+ }
2061
+ var S = +/* @__PURE__ */ new Date();
2062
+ tmp = raw.indexOf('"put":":])([:"');
2063
+ res(u, raw = raw.slice(0, tmp + 6) + put + raw.slice(tmp + 14));
2064
+ console.STAT && console.STAT(S, +/* @__PURE__ */ new Date() - S, "say slice");
2065
+ });
2066
+ return;
2067
+ }
2068
+ json(msg, res);
2069
+ function res(err, raw) {
2070
+ if (err) {
2071
+ return;
2072
+ }
2073
+ meta.raw = raw;
2074
+ mesh.say(msg, peer);
2075
+ }
2076
+ };
2077
+ })();
2078
+ function flush(peer) {
2079
+ var tmp = peer.batch, t = "string" == typeof tmp;
2080
+ if (t) {
2081
+ tmp += "]";
2082
+ }
2083
+ peer.batch = peer.tail = null;
2084
+ if (!tmp) {
2085
+ return;
2086
+ }
2087
+ if (t ? 3 > tmp.length : !tmp.length) {
2088
+ return;
2089
+ }
2090
+ if (!t) {
2091
+ try {
2092
+ tmp = 1 === tmp.length ? tmp[0] : JSON.stringify(tmp);
2093
+ } catch (e) {
2094
+ return opt.log("DAM JSON stringify error", e);
2095
+ }
2096
+ }
2097
+ if (!tmp) {
2098
+ return;
2099
+ }
2100
+ send(tmp, peer);
2101
+ }
2102
+ function send(raw, peer) {
2103
+ try {
2104
+ var wire = peer.wire;
2105
+ if (peer.say) {
2106
+ peer.say(raw);
2107
+ } else if (wire.send) {
2108
+ wire.send(raw);
2109
+ }
2110
+ mesh.say.d += raw.length || 0;
2111
+ ++mesh.say.c;
2112
+ } catch (e) {
2113
+ (peer.queue = peer.queue || []).push(raw);
2114
+ }
2115
+ }
2116
+ mesh.near = 0;
2117
+ mesh.hi = function(peer) {
2118
+ var wire = peer.wire, tmp;
2119
+ if (!wire) {
2120
+ mesh.wire(peer.length && { url: peer, id: peer } || peer);
2121
+ return;
2122
+ }
2123
+ if (peer.id) {
2124
+ opt.peers[peer.url || peer.id] = peer;
2125
+ } else {
2126
+ tmp = peer.id = peer.id || peer.url || String.random(9);
2127
+ mesh.say({ dam: "?", pid: root.opt.pid }, opt.peers[tmp] = peer);
2128
+ delete dup.s[peer.last];
2129
+ }
2130
+ if (!peer.met) {
2131
+ mesh.near++;
2132
+ peer.met = +/* @__PURE__ */ new Date();
2133
+ root.on("hi", peer);
2134
+ }
2135
+ tmp = peer.queue;
2136
+ peer.queue = [];
2137
+ setTimeout.each(tmp || [], function(msg) {
2138
+ send(msg, peer);
2139
+ }, 0, 9);
2140
+ };
2141
+ mesh.bye = function(peer) {
2142
+ peer.met && --mesh.near;
2143
+ delete peer.met;
2144
+ root.on("bye", peer);
2145
+ var tmp = +/* @__PURE__ */ new Date();
2146
+ tmp = tmp - (peer.met || tmp);
2147
+ mesh.bye.time = ((mesh.bye.time || tmp) + tmp) / 2;
2148
+ };
2149
+ mesh.hear["!"] = function(msg, peer) {
2150
+ opt.log("Error:", msg.err);
2151
+ };
2152
+ mesh.hear["?"] = function(msg, peer) {
2153
+ if (msg.pid) {
2154
+ if (!peer.pid) {
2155
+ peer.pid = msg.pid;
2156
+ }
2157
+ if (msg["@"]) {
2158
+ return;
2159
+ }
2160
+ }
2161
+ mesh.say({ dam: "?", pid: opt.pid, "@": msg["#"] }, peer);
2162
+ delete dup.s[peer.last];
2163
+ };
2164
+ mesh.hear["mob"] = function(msg, peer) {
2165
+ if (!msg.peers) {
2166
+ return;
2167
+ }
2168
+ var peers = Object.keys(msg.peers), one = peers[Math.random() * peers.length >> 0];
2169
+ if (!one) {
2170
+ return;
2171
+ }
2172
+ mesh.bye(peer);
2173
+ mesh.hi(one);
2174
+ };
2175
+ root.on("create", function(root2) {
2176
+ root2.opt.pid = root2.opt.pid || String.random(9);
2177
+ this.to.next(root2);
2178
+ root2.on("out", mesh.say);
2179
+ });
2180
+ root.on("bye", function(peer, tmp) {
2181
+ peer = opt.peers[peer.id || peer] || peer;
2182
+ this.to.next(peer);
2183
+ peer.bye ? peer.bye() : (tmp = peer.wire) && tmp.close && tmp.close();
2184
+ delete opt.peers[peer.id];
2185
+ peer.wire = null;
2186
+ });
2187
+ root.on("bye", function(peer, tmp) {
2188
+ this.to.next(peer);
2189
+ if (tmp = console.STAT) {
2190
+ tmp.peers = mesh.near;
2191
+ }
2192
+ if (!(tmp = peer.url)) {
2193
+ return;
2194
+ }
2195
+ setTimeout(function() {
2196
+ }, opt.lack || 9e3);
2197
+ });
2198
+ root.on("hi", function(peer, tmp) {
2199
+ this.to.next(peer);
2200
+ if (tmp = console.STAT) {
2201
+ tmp.peers = mesh.near;
2202
+ }
2203
+ if (opt.super) {
2204
+ return;
2205
+ }
2206
+ var souls = Object.keys(root.next || "");
2207
+ if (souls.length > 9999 && !console.SUBS) {
2208
+ console.log(console.SUBS = "Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`.");
2209
+ }
2210
+ setTimeout.each(souls, function(soul) {
2211
+ var node = root.next[soul];
2212
+ if (opt.super || (node.ask || "")[""]) {
2213
+ mesh.say({ get: { "#": soul } }, peer);
2214
+ return;
2215
+ }
2216
+ setTimeout.each(Object.keys(node.ask || ""), function(key) {
2217
+ if (!key) {
2218
+ return;
2219
+ }
2220
+ mesh.say({ "##": String.hash((root.graph[soul] || "")[key]), get: { "#": soul, ".": key } }, peer);
2221
+ });
2222
+ });
2223
+ });
2224
+ return mesh;
2225
+ }
2226
+ var u;
2227
+ try {
2228
+ module2.exports = Mesh;
2229
+ } catch (e) {
2230
+ }
2231
+ })(USE, "./mesh");
2232
+ USE(function(module2) {
2233
+ var Gun2 = USE("./index");
2234
+ Gun2.Mesh = USE("./mesh");
2235
+ Gun2.on("opt", function(root) {
2236
+ this.to.next(root);
2237
+ if (root.once) {
2238
+ return;
2239
+ }
2240
+ var opt = root.opt;
2241
+ if (false === opt.WebSocket) {
2242
+ return;
2243
+ }
2244
+ var env = Gun2.window || {};
2245
+ var websocket = opt.WebSocket || env.WebSocket || env.webkitWebSocket || env.mozWebSocket;
2246
+ if (!websocket) {
2247
+ return;
2248
+ }
2249
+ opt.WebSocket = websocket;
2250
+ var mesh = opt.mesh = opt.mesh || Gun2.Mesh(root);
2251
+ mesh.wire || opt.wire;
2252
+ mesh.wire = opt.wire = open;
2253
+ function open(peer) {
2254
+ try {
2255
+ if (!peer || !peer.url) {
2256
+ return wire && wire(peer);
2257
+ }
2258
+ var url = peer.url.replace(/^http/, "ws");
2259
+ var wire = peer.wire = new opt.WebSocket(url);
2260
+ wire.onclose = function() {
2261
+ reconnect(peer);
2262
+ opt.mesh.bye(peer);
2263
+ };
2264
+ wire.onerror = function(err) {
2265
+ reconnect(peer);
2266
+ };
2267
+ wire.onopen = function() {
2268
+ opt.mesh.hi(peer);
2269
+ };
2270
+ wire.onmessage = function(msg) {
2271
+ if (!msg) {
2272
+ return;
2273
+ }
2274
+ opt.mesh.hear(msg.data || msg, peer);
2275
+ };
2276
+ return wire;
2277
+ } catch (e) {
2278
+ opt.mesh.bye(peer);
2279
+ }
2280
+ }
2281
+ setTimeout(function() {
2282
+ !opt.super && root.on("out", { dam: "hi" });
2283
+ }, 1);
2284
+ var wait = 2 * 999;
2285
+ function reconnect(peer) {
2286
+ clearTimeout(peer.defer);
2287
+ if (!opt.peers[peer.url]) {
2288
+ return;
2289
+ }
2290
+ if (doc && peer.retry <= 0) {
2291
+ return;
2292
+ }
2293
+ peer.retry = (peer.retry || opt.retry + 1 || 60) - (-peer.tried + (peer.tried = +/* @__PURE__ */ new Date()) < wait * 4 ? 1 : 0);
2294
+ peer.defer = setTimeout(function to() {
2295
+ if (doc && doc.hidden) {
2296
+ return setTimeout(to, wait);
2297
+ }
2298
+ open(peer);
2299
+ }, wait);
2300
+ }
2301
+ var doc = "" + u !== typeof document && document;
2302
+ });
2303
+ var u;
2304
+ })(USE, "./websocket");
2305
+ USE(function(module2) {
2306
+ if (typeof Gun === "undefined") {
2307
+ return;
2308
+ }
2309
+ var noop = function() {
2310
+ }, store;
2311
+ try {
2312
+ store = (Gun.window || noop).localStorage;
2313
+ } catch (e) {
2314
+ }
2315
+ if (!store) {
2316
+ Gun.log("Warning: No localStorage exists to persist data to!");
2317
+ store = { setItem: function(k, v) {
2318
+ this[k] = v;
2319
+ }, removeItem: function(k) {
2320
+ delete this[k];
2321
+ }, getItem: function(k) {
2322
+ return this[k];
2323
+ } };
2324
+ }
2325
+ var json = JSON.stringifyAsync || function(v, cb, r, s) {
2326
+ var u;
2327
+ try {
2328
+ cb(u, JSON.stringify(v, r, s));
2329
+ } catch (e) {
2330
+ cb(e);
2331
+ }
2332
+ };
2333
+ Gun.on("create", function lg(root) {
2334
+ this.to.next(root);
2335
+ var opt = root.opt;
2336
+ root.graph;
2337
+ var acks = [], disk, to, size, stop;
2338
+ if (false === opt.localStorage) {
2339
+ return;
2340
+ }
2341
+ opt.prefix = opt.file || "gun/";
2342
+ try {
2343
+ disk = lg[opt.prefix] = lg[opt.prefix] || JSON.parse(size = store.getItem(opt.prefix)) || {};
2344
+ } catch (e) {
2345
+ disk = lg[opt.prefix] = {};
2346
+ }
2347
+ size = (size || "").length;
2348
+ root.on("get", function(msg) {
2349
+ this.to.next(msg);
2350
+ var lex = msg.get, soul, data, tmp, u;
2351
+ if (!lex || !(soul = lex["#"])) {
2352
+ return;
2353
+ }
2354
+ data = disk[soul] || u;
2355
+ if (data && (tmp = lex["."]) && !Object.plain(tmp)) {
2356
+ data = Gun.state.ify({}, tmp, Gun.state.is(data, tmp), data[tmp], soul);
2357
+ }
2358
+ Gun.on.get.ack(msg, data);
2359
+ });
2360
+ root.on("put", function(msg) {
2361
+ this.to.next(msg);
2362
+ var put = msg.put, soul = put["#"], key = put["."], id = msg["#"], ok = msg.ok || "";
2363
+ if (!(root.next || "")[soul]) {
2364
+ return;
2365
+ }
2366
+ disk[soul] = Gun.state.ify(disk[soul], key, put[">"], put[":"], soul);
2367
+ if (stop && size > 4999880) {
2368
+ root.on("in", { "@": id, err: "localStorage max!" });
2369
+ return;
2370
+ }
2371
+ if (!msg["@"] && (!msg._.via || Math.random() < ok["@"] / ok["/"])) {
2372
+ acks.push(id);
2373
+ }
2374
+ if (to) {
2375
+ return;
2376
+ }
2377
+ to = setTimeout(flush, 9 + size / 333);
2378
+ });
2379
+ function flush() {
2380
+ if (!acks.length && ((setTimeout.turn || "").s || "").length) {
2381
+ setTimeout(flush, 99);
2382
+ return;
2383
+ }
2384
+ var ack = acks;
2385
+ clearTimeout(to);
2386
+ to = false;
2387
+ acks = [];
2388
+ json(disk, function(err, tmp) {
2389
+ try {
2390
+ !err && store.setItem(opt.prefix, tmp);
2391
+ } catch (e) {
2392
+ err = stop = e || "localStorage failure";
2393
+ }
2394
+ if (err) {
2395
+ Gun.log(err + " Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install");
2396
+ root.on("localStorage:error", { err, get: opt.prefix, put: disk });
2397
+ }
2398
+ size = tmp.length;
2399
+ setTimeout.each(ack, function(id) {
2400
+ root.on("in", { "@": id, err, ok: 0 });
2401
+ }, 0, 99);
2402
+ });
2403
+ }
2404
+ });
2405
+ })(USE, "./localStorage");
2406
+ })();
2407
+ (function() {
2408
+ var u;
2409
+ if ("" + u == typeof Gun) {
2410
+ return;
2411
+ }
2412
+ var DEP = function(n) {
2413
+ console.warn("Warning! Deprecated internal utility will break in next version:", n);
2414
+ };
2415
+ var Type = Gun;
2416
+ Type.fn = Type.fn || { is: function(fn2) {
2417
+ DEP("fn");
2418
+ return !!fn2 && "function" == typeof fn2;
2419
+ } };
2420
+ Type.bi = Type.bi || { is: function(b) {
2421
+ DEP("bi");
2422
+ return b instanceof Boolean || typeof b == "boolean";
2423
+ } };
2424
+ Type.num = Type.num || { is: function(n) {
2425
+ DEP("num");
2426
+ return !list_is(n) && (n - parseFloat(n) + 1 >= 0 || Infinity === n || -Infinity === n);
2427
+ } };
2428
+ Type.text = Type.text || { is: function(t) {
2429
+ DEP("text");
2430
+ return typeof t == "string";
2431
+ } };
2432
+ Type.text.ify = Type.text.ify || function(t) {
2433
+ DEP("text.ify");
2434
+ if (Type.text.is(t)) {
2435
+ return t;
2436
+ }
2437
+ if (typeof JSON !== "undefined") {
2438
+ return JSON.stringify(t);
2439
+ }
2440
+ return t && t.toString ? t.toString() : t;
2441
+ };
2442
+ Type.text.random = Type.text.random || function(l, c) {
2443
+ DEP("text.random");
2444
+ var s = "";
2445
+ l = l || 24;
2446
+ c = c || "0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";
2447
+ while (l > 0) {
2448
+ s += c.charAt(Math.floor(Math.random() * c.length));
2449
+ l--;
2450
+ }
2451
+ return s;
2452
+ };
2453
+ Type.text.match = Type.text.match || function(t, o) {
2454
+ var tmp, u2;
2455
+ DEP("text.match");
2456
+ if ("string" !== typeof t) {
2457
+ return false;
2458
+ }
2459
+ if ("string" == typeof o) {
2460
+ o = { "=": o };
2461
+ }
2462
+ o = o || {};
2463
+ tmp = o["="] || o["*"] || o[">"] || o["<"];
2464
+ if (t === tmp) {
2465
+ return true;
2466
+ }
2467
+ if (u2 !== o["="]) {
2468
+ return false;
2469
+ }
2470
+ tmp = o["*"] || o[">"] || o["<"];
2471
+ if (t.slice(0, (tmp || "").length) === tmp) {
2472
+ return true;
2473
+ }
2474
+ if (u2 !== o["*"]) {
2475
+ return false;
2476
+ }
2477
+ if (u2 !== o[">"] && u2 !== o["<"]) {
2478
+ return t >= o[">"] && t <= o["<"] ? true : false;
2479
+ }
2480
+ if (u2 !== o[">"] && t >= o[">"]) {
2481
+ return true;
2482
+ }
2483
+ if (u2 !== o["<"] && t <= o["<"]) {
2484
+ return true;
2485
+ }
2486
+ return false;
2487
+ };
2488
+ Type.text.hash = Type.text.hash || function(s, c) {
2489
+ DEP("text.hash");
2490
+ if (typeof s !== "string") {
2491
+ return;
2492
+ }
2493
+ c = c || 0;
2494
+ if (!s.length) {
2495
+ return c;
2496
+ }
2497
+ for (var i = 0, l = s.length, n; i < l; ++i) {
2498
+ n = s.charCodeAt(i);
2499
+ c = (c << 5) - c + n;
2500
+ c |= 0;
2501
+ }
2502
+ return c;
2503
+ };
2504
+ Type.list = Type.list || { is: function(l) {
2505
+ DEP("list");
2506
+ return l instanceof Array;
2507
+ } };
2508
+ Type.list.slit = Type.list.slit || Array.prototype.slice;
2509
+ Type.list.sort = Type.list.sort || function(k) {
2510
+ DEP("list.sort");
2511
+ return function(A, B) {
2512
+ if (!A || !B) {
2513
+ return 0;
2514
+ }
2515
+ A = A[k];
2516
+ B = B[k];
2517
+ if (A < B) {
2518
+ return -1;
2519
+ } else if (A > B) {
2520
+ return 1;
2521
+ } else {
2522
+ return 0;
2523
+ }
2524
+ };
2525
+ };
2526
+ Type.list.map = Type.list.map || function(l, c, _) {
2527
+ DEP("list.map");
2528
+ return obj_map(l, c, _);
2529
+ };
2530
+ Type.list.index = 1;
2531
+ Type.obj = Type.boj || { is: function(o) {
2532
+ DEP("obj");
2533
+ return o ? o instanceof Object && o.constructor === Object || Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] === "Object" : false;
2534
+ } };
2535
+ Type.obj.put = Type.obj.put || function(o, k, v) {
2536
+ DEP("obj.put");
2537
+ return (o || {})[k] = v, o;
2538
+ };
2539
+ Type.obj.has = Type.obj.has || function(o, k) {
2540
+ DEP("obj.has");
2541
+ return o && Object.prototype.hasOwnProperty.call(o, k);
2542
+ };
2543
+ Type.obj.del = Type.obj.del || function(o, k) {
2544
+ DEP("obj.del");
2545
+ if (!o) {
2546
+ return;
2547
+ }
2548
+ o[k] = null;
2549
+ delete o[k];
2550
+ return o;
2551
+ };
2552
+ Type.obj.as = Type.obj.as || function(o, k, v, u2) {
2553
+ DEP("obj.as");
2554
+ return o[k] = o[k] || (u2 === v ? {} : v);
2555
+ };
2556
+ Type.obj.ify = Type.obj.ify || function(o) {
2557
+ DEP("obj.ify");
2558
+ if (obj_is(o)) {
2559
+ return o;
2560
+ }
2561
+ try {
2562
+ o = JSON.parse(o);
2563
+ } catch (e) {
2564
+ o = {};
2565
+ }
2566
+ return o;
2567
+ };
2568
+ (function() {
2569
+ var u2;
2570
+ function map(v, k) {
2571
+ if (obj_has(this, k) && u2 !== this[k]) {
2572
+ return;
2573
+ }
2574
+ this[k] = v;
2575
+ }
2576
+ Type.obj.to = Type.obj.to || function(from, to) {
2577
+ DEP("obj.to");
2578
+ to = to || {};
2579
+ obj_map(from, map, to);
2580
+ return to;
2581
+ };
2582
+ })();
2583
+ Type.obj.copy = Type.obj.copy || function(o) {
2584
+ DEP("obj.copy");
2585
+ return !o ? o : JSON.parse(JSON.stringify(o));
2586
+ };
2587
+ (function() {
2588
+ function empty(v, i) {
2589
+ var n = this.n, u2;
2590
+ if (n && (i === n || obj_is(n) && obj_has(n, i))) {
2591
+ return;
2592
+ }
2593
+ if (u2 !== i) {
2594
+ return true;
2595
+ }
2596
+ }
2597
+ Type.obj.empty = Type.obj.empty || function(o, n) {
2598
+ DEP("obj.empty");
2599
+ if (!o) {
2600
+ return true;
2601
+ }
2602
+ return obj_map(o, empty, { n }) ? false : true;
2603
+ };
2604
+ })();
2605
+ (function() {
2606
+ function t(k, v) {
2607
+ if (2 === arguments.length) {
2608
+ t.r = t.r || {};
2609
+ t.r[k] = v;
2610
+ return;
2611
+ }
2612
+ t.r = t.r || [];
2613
+ t.r.push(k);
2614
+ }
2615
+ var keys = Object.keys, map;
2616
+ Object.keys = Object.keys || function(o) {
2617
+ return map(o, function(v, k, t2) {
2618
+ t2(k);
2619
+ });
2620
+ };
2621
+ Type.obj.map = map = Type.obj.map || function(l, c, _) {
2622
+ DEP("obj.map");
2623
+ var u2, i = 0, x, r, ll, lle, f = "function" == typeof c;
2624
+ t.r = u2;
2625
+ if (keys && obj_is(l)) {
2626
+ ll = keys(l);
2627
+ lle = true;
2628
+ }
2629
+ _ = _ || {};
2630
+ if (list_is(l) || ll) {
2631
+ x = (ll || l).length;
2632
+ for (; i < x; i++) {
2633
+ var ii = i + Type.list.index;
2634
+ if (f) {
2635
+ r = lle ? c.call(_, l[ll[i]], ll[i], t) : c.call(_, l[i], ii, t);
2636
+ if (r !== u2) {
2637
+ return r;
2638
+ }
2639
+ } else {
2640
+ if (c === l[lle ? ll[i] : i]) {
2641
+ return ll ? ll[i] : ii;
2642
+ }
2643
+ }
2644
+ }
2645
+ } else {
2646
+ for (i in l) {
2647
+ if (f) {
2648
+ if (obj_has(l, i)) {
2649
+ r = _ ? c.call(_, l[i], i, t) : c(l[i], i, t);
2650
+ if (r !== u2) {
2651
+ return r;
2652
+ }
2653
+ }
2654
+ } else {
2655
+ if (c === l[i]) {
2656
+ return i;
2657
+ }
2658
+ }
2659
+ }
2660
+ }
2661
+ return f ? t.r : Type.list.index ? 0 : -1;
2662
+ };
2663
+ })();
2664
+ Type.time = Type.time || {};
2665
+ Type.time.is = Type.time.is || function(t) {
2666
+ DEP("time");
2667
+ return t ? t instanceof Date : +(/* @__PURE__ */ new Date()).getTime();
2668
+ };
2669
+ var fn_is = Type.fn.is;
2670
+ var list_is = Type.list.is;
2671
+ var obj = Type.obj, obj_is = obj.is, obj_has = obj.has, obj_map = obj.map;
2672
+ var Val = {};
2673
+ Val.is = function(v) {
2674
+ DEP("val.is");
2675
+ if (v === u) {
2676
+ return false;
2677
+ }
2678
+ if (v === null) {
2679
+ return true;
2680
+ }
2681
+ if (v === Infinity) {
2682
+ return false;
2683
+ }
2684
+ if (text_is(v) || bi_is(v) || num_is(v)) {
2685
+ return true;
2686
+ }
2687
+ return Val.link.is(v) || false;
2688
+ };
2689
+ Val.link = Val.rel = { _: "#" };
2690
+ (function() {
2691
+ Val.link.is = function(v) {
2692
+ DEP("val.link.is");
2693
+ if (v && v[rel_] && !v._ && obj_is(v)) {
2694
+ var o = {};
2695
+ obj_map(v, map, o);
2696
+ if (o.id) {
2697
+ return o.id;
2698
+ }
2699
+ }
2700
+ return false;
2701
+ };
2702
+ function map(s, k) {
2703
+ var o = this;
2704
+ if (o.id) {
2705
+ return o.id = false;
2706
+ }
2707
+ if (k == rel_ && text_is(s)) {
2708
+ o.id = s;
2709
+ } else {
2710
+ return o.id = false;
2711
+ }
2712
+ }
2713
+ })();
2714
+ Val.link.ify = function(t) {
2715
+ DEP("val.link.ify");
2716
+ return obj_put({}, rel_, t);
2717
+ };
2718
+ Type.obj.has._ = ".";
2719
+ var rel_ = Val.link._, u;
2720
+ var bi_is = Type.bi.is;
2721
+ var num_is = Type.num.is;
2722
+ var text_is = Type.text.is;
2723
+ var obj = Type.obj, obj_is = obj.is, obj_put = obj.put, obj_map = obj.map;
2724
+ Type.val = Type.val || Val;
2725
+ var Node = { _: "_" };
2726
+ Node.soul = function(n, o) {
2727
+ DEP("node.soul");
2728
+ return n && n._ && n._[o || soul_];
2729
+ };
2730
+ Node.soul.ify = function(n, o) {
2731
+ DEP("node.soul.ify");
2732
+ o = typeof o === "string" ? { soul: o } : o || {};
2733
+ n = n || {};
2734
+ n._ = n._ || {};
2735
+ n._[soul_] = o.soul || n._[soul_] || text_random();
2736
+ return n;
2737
+ };
2738
+ Node.soul._ = Val.link._;
2739
+ (function() {
2740
+ Node.is = function(n, cb, as) {
2741
+ DEP("node.is");
2742
+ var s;
2743
+ if (!obj_is(n)) {
2744
+ return false;
2745
+ }
2746
+ if (s = Node.soul(n)) {
2747
+ return !obj_map(n, map, { as, cb, s, n });
2748
+ }
2749
+ return false;
2750
+ };
2751
+ function map(v, k) {
2752
+ if (k === Node._) {
2753
+ return;
2754
+ }
2755
+ if (!Val.is(v)) {
2756
+ return true;
2757
+ }
2758
+ if (this.cb) {
2759
+ this.cb.call(this.as, v, k, this.n, this.s);
2760
+ }
2761
+ }
2762
+ })();
2763
+ (function() {
2764
+ Node.ify = function(obj2, o, as) {
2765
+ DEP("node.ify");
2766
+ if (!o) {
2767
+ o = {};
2768
+ } else if (typeof o === "string") {
2769
+ o = { soul: o };
2770
+ } else if ("function" == typeof o) {
2771
+ o = { map: o };
2772
+ }
2773
+ if (o.map) {
2774
+ o.node = o.map.call(as, obj2, u, o.node || {});
2775
+ }
2776
+ if (o.node = Node.soul.ify(o.node || {}, o)) {
2777
+ obj_map(obj2, map, { o, as });
2778
+ }
2779
+ return o.node;
2780
+ };
2781
+ function map(v, k) {
2782
+ var o = this.o, tmp, u2;
2783
+ if (o.map) {
2784
+ tmp = o.map.call(this.as, v, "" + k, o.node);
2785
+ if (u2 === tmp) {
2786
+ obj_del(o.node, k);
2787
+ } else if (o.node) {
2788
+ o.node[k] = tmp;
2789
+ }
2790
+ return;
2791
+ }
2792
+ if (Val.is(v)) {
2793
+ o.node[k] = v;
2794
+ }
2795
+ }
2796
+ })();
2797
+ var obj = Type.obj, obj_is = obj.is, obj_del = obj.del, obj_map = obj.map;
2798
+ var text = Type.text, text_random = text.random;
2799
+ var soul_ = Node.soul._;
2800
+ var u;
2801
+ Type.node = Type.node || Node;
2802
+ var State = Type.state;
2803
+ State.lex = function() {
2804
+ DEP("state.lex");
2805
+ return State().toString(36).replace(".", "");
2806
+ };
2807
+ State.to = function(from, k, to) {
2808
+ DEP("state.to");
2809
+ var val = (from || {})[k];
2810
+ if (obj_is(val)) {
2811
+ val = obj_copy(val);
2812
+ }
2813
+ return State.ify(to, k, State.is(from, k), val, Node.soul(from));
2814
+ };
2815
+ (function() {
2816
+ State.map = function(cb, s, as) {
2817
+ DEP("state.map");
2818
+ var u2;
2819
+ var o = obj_is(o = cb || s) ? o : null;
2820
+ cb = fn_is(cb = cb || s) ? cb : null;
2821
+ if (o && !cb) {
2822
+ s = num_is(s) ? s : State();
2823
+ o[N_] = o[N_] || {};
2824
+ obj_map(o, map, { o, s });
2825
+ return o;
2826
+ }
2827
+ as = as || obj_is(s) ? s : u2;
2828
+ s = num_is(s) ? s : State();
2829
+ return function(v, k, o2, opt) {
2830
+ if (!cb) {
2831
+ map.call({ o: o2, s }, v, k);
2832
+ return v;
2833
+ }
2834
+ cb.call(as || this || {}, v, k, o2, opt);
2835
+ if (obj_has(o2, k) && u2 === o2[k]) {
2836
+ return;
2837
+ }
2838
+ map.call({ o: o2, s }, v, k);
2839
+ };
2840
+ };
2841
+ function map(v, k) {
2842
+ if (N_ === k) {
2843
+ return;
2844
+ }
2845
+ State.ify(this.o, k, this.s);
2846
+ }
2847
+ })();
2848
+ var obj = Type.obj;
2849
+ obj.as;
2850
+ var obj_has = obj.has, obj_is = obj.is, obj_map = obj.map, obj_copy = obj.copy;
2851
+ var num = Type.num, num_is = num.is;
2852
+ var fn = Type.fn, fn_is = fn.is;
2853
+ var N_ = Node._, u;
2854
+ var Graph = {};
2855
+ (function() {
2856
+ Graph.is = function(g, cb, fn2, as) {
2857
+ DEP("graph.is");
2858
+ if (!g || !obj_is(g) || obj_empty(g)) {
2859
+ return false;
2860
+ }
2861
+ return !obj_map(g, map, { cb, fn: fn2, as });
2862
+ };
2863
+ function map(n, s) {
2864
+ if (!n || s !== Node.soul(n) || !Node.is(n, this.fn, this.as)) {
2865
+ return true;
2866
+ }
2867
+ if (!this.cb) {
2868
+ return;
2869
+ }
2870
+ nf.n = n;
2871
+ nf.as = this.as;
2872
+ this.cb.call(nf.as, n, s, nf);
2873
+ }
2874
+ function nf(fn2) {
2875
+ if (fn2) {
2876
+ Node.is(nf.n, fn2, nf.as);
2877
+ }
2878
+ }
2879
+ })();
2880
+ (function() {
2881
+ Graph.ify = function(obj2, env, as) {
2882
+ DEP("graph.ify");
2883
+ var at = { path: [], obj: obj2 };
2884
+ if (!env) {
2885
+ env = {};
2886
+ } else if (typeof env === "string") {
2887
+ env = { soul: env };
2888
+ } else if ("function" == typeof env) {
2889
+ env.map = env;
2890
+ }
2891
+ if (typeof as === "string") {
2892
+ env.soul = env.soul || as;
2893
+ as = u;
2894
+ }
2895
+ if (env.soul) {
2896
+ at.link = Val.link.ify(env.soul);
2897
+ }
2898
+ env.shell = (as || {}).shell;
2899
+ env.graph = env.graph || {};
2900
+ env.seen = env.seen || [];
2901
+ env.as = env.as || as;
2902
+ node(env, at);
2903
+ env.root = at.node;
2904
+ return env.graph;
2905
+ };
2906
+ function node(env, at) {
2907
+ var tmp;
2908
+ if (tmp = seen(env, at)) {
2909
+ return tmp;
2910
+ }
2911
+ at.env = env;
2912
+ at.soul = soul;
2913
+ if (Node.ify(at.obj, map, at)) {
2914
+ at.link = at.link || Val.link.ify(Node.soul(at.node));
2915
+ if (at.obj !== env.shell) {
2916
+ env.graph[Val.link.is(at.link)] = at.node;
2917
+ }
2918
+ }
2919
+ return at;
2920
+ }
2921
+ function map(v, k, n) {
2922
+ var at = this, env = at.env, is, tmp;
2923
+ if (Node._ === k && obj_has(v, Val.link._)) {
2924
+ return n._;
2925
+ }
2926
+ if (!(is = valid(v, k, n, at, env))) {
2927
+ return;
2928
+ }
2929
+ if (!k) {
2930
+ at.node = at.node || n || {};
2931
+ if (obj_has(v, Node._) && Node.soul(v)) {
2932
+ at.node._ = obj_copy(v._);
2933
+ }
2934
+ at.node = Node.soul.ify(at.node, Val.link.is(at.link));
2935
+ at.link = at.link || Val.link.ify(Node.soul(at.node));
2936
+ }
2937
+ if (tmp = env.map) {
2938
+ tmp.call(env.as || {}, v, k, n, at);
2939
+ if (obj_has(n, k)) {
2940
+ v = n[k];
2941
+ if (u === v) {
2942
+ obj_del(n, k);
2943
+ return;
2944
+ }
2945
+ if (!(is = valid(v, k, n, at, env))) {
2946
+ return;
2947
+ }
2948
+ }
2949
+ }
2950
+ if (!k) {
2951
+ return at.node;
2952
+ }
2953
+ if (true === is) {
2954
+ return v;
2955
+ }
2956
+ tmp = node(env, { obj: v, path: at.path.concat(k) });
2957
+ if (!tmp.node) {
2958
+ return;
2959
+ }
2960
+ return tmp.link;
2961
+ }
2962
+ function soul(id) {
2963
+ var at = this;
2964
+ var prev = Val.link.is(at.link), graph = at.env.graph;
2965
+ at.link = at.link || Val.link.ify(id);
2966
+ at.link[Val.link._] = id;
2967
+ if (at.node && at.node[Node._]) {
2968
+ at.node[Node._][Val.link._] = id;
2969
+ }
2970
+ if (obj_has(graph, prev)) {
2971
+ graph[id] = graph[prev];
2972
+ obj_del(graph, prev);
2973
+ }
2974
+ }
2975
+ function valid(v, k, n, at, env) {
2976
+ var tmp;
2977
+ if (Val.is(v)) {
2978
+ return true;
2979
+ }
2980
+ if (obj_is(v)) {
2981
+ return 1;
2982
+ }
2983
+ if (tmp = env.invalid) {
2984
+ v = tmp.call(env.as || {}, v, k, n);
2985
+ return valid(v, k, n, at, env);
2986
+ }
2987
+ env.err = "Invalid value at '" + at.path.concat(k).join(".") + "'!";
2988
+ if (Type.list.is(v)) {
2989
+ env.err += " Use `.set(item)` instead of an Array.";
2990
+ }
2991
+ }
2992
+ function seen(env, at) {
2993
+ var arr = env.seen, i = arr.length, has;
2994
+ while (i--) {
2995
+ has = arr[i];
2996
+ if (at.obj === has.obj) {
2997
+ return has;
2998
+ }
2999
+ }
3000
+ arr.push(at);
3001
+ }
3002
+ })();
3003
+ Graph.node = function(node) {
3004
+ DEP("graph.node");
3005
+ var soul = Node.soul(node);
3006
+ if (!soul) {
3007
+ return;
3008
+ }
3009
+ return obj_put({}, soul, node);
3010
+ };
3011
+ (function() {
3012
+ Graph.to = function(graph, root, opt) {
3013
+ DEP("graph.to");
3014
+ if (!graph) {
3015
+ return;
3016
+ }
3017
+ var obj2 = {};
3018
+ opt = opt || { seen: {} };
3019
+ obj_map(graph[root], map, { obj: obj2, graph, opt });
3020
+ return obj2;
3021
+ };
3022
+ function map(v, k) {
3023
+ var tmp, obj2;
3024
+ if (Node._ === k) {
3025
+ if (obj_empty(v, Val.link._)) {
3026
+ return;
3027
+ }
3028
+ this.obj[k] = obj_copy(v);
3029
+ return;
3030
+ }
3031
+ if (!(tmp = Val.link.is(v))) {
3032
+ this.obj[k] = v;
3033
+ return;
3034
+ }
3035
+ if (obj2 = this.opt.seen[tmp]) {
3036
+ this.obj[k] = obj2;
3037
+ return;
3038
+ }
3039
+ this.obj[k] = this.opt.seen[tmp] = Graph.to(this.graph, tmp, this.opt);
3040
+ }
3041
+ })();
3042
+ var fn_is = Type.fn.is;
3043
+ var obj = Type.obj, obj_is = obj.is, obj_del = obj.del, obj_has = obj.has, obj_empty = obj.empty, obj_put = obj.put, obj_map = obj.map, obj_copy = obj.copy;
3044
+ var u;
3045
+ Type.graph = Type.graph || Graph;
3046
+ })();
3047
+ })(gun);
3048
+ var gunExports = gun.exports;
3049
+ var browser = gunExports;
3050
+ const browser$1 = /* @__PURE__ */ getDefaultExportFromCjs(browser);
3051
+ const browser$2 = /* @__PURE__ */ _mergeNamespaces({
3052
+ __proto__: null,
3053
+ default: browser$1
3054
+ }, [browser]);
3055
+ export {
3056
+ browser$2 as b
3057
+ };
3058
+ //# sourceMappingURL=browser-BSniCNqO.js.map