shogun-core 1.8.0 → 1.8.1

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 (83) hide show
  1. package/dist/browser/shogun-core.js +1015 -3
  2. package/dist/browser/shogun-core.js.map +1 -1
  3. package/dist/example/relay-example.js +165 -0
  4. package/dist/{gundb → src/gundb}/index.js +2 -0
  5. package/dist/src/gundb/relay.js +311 -0
  6. package/dist/{index.js → src/index.js} +6 -3
  7. package/dist/types/example/relay-example.d.ts +24 -0
  8. package/dist/types/{gundb → src/gundb}/index.d.ts +1 -0
  9. package/dist/types/src/gundb/relay.d.ts +150 -0
  10. package/dist/types/{index.d.ts → src/index.d.ts} +2 -2
  11. package/package.json +1 -1
  12. /package/dist/{gundb → src/gundb}/crypto.js +0 -0
  13. /package/dist/{gundb → src/gundb}/derive.js +0 -0
  14. /package/dist/{gundb → src/gundb}/errors.js +0 -0
  15. /package/dist/{gundb → src/gundb}/gun-Instance.js +0 -0
  16. /package/dist/{gundb → src/gundb}/gun-rxjs.js +0 -0
  17. /package/dist/{gundb → src/gundb}/restricted-put.js +0 -0
  18. /package/dist/{gundb → src/gundb}/types.js +0 -0
  19. /package/dist/{plugins → src/plugins}/base.js +0 -0
  20. /package/dist/{plugins → src/plugins}/index.js +0 -0
  21. /package/dist/{plugins → src/plugins}/nostr/index.js +0 -0
  22. /package/dist/{plugins → src/plugins}/nostr/nostrConnector.js +0 -0
  23. /package/dist/{plugins → src/plugins}/nostr/nostrConnectorPlugin.js +0 -0
  24. /package/dist/{plugins → src/plugins}/nostr/nostrSigner.js +0 -0
  25. /package/dist/{plugins → src/plugins}/nostr/types.js +0 -0
  26. /package/dist/{plugins → src/plugins}/oauth/index.js +0 -0
  27. /package/dist/{plugins → src/plugins}/oauth/oauthConnector.js +0 -0
  28. /package/dist/{plugins → src/plugins}/oauth/oauthPlugin.js +0 -0
  29. /package/dist/{plugins → src/plugins}/oauth/types.js +0 -0
  30. /package/dist/{plugins → src/plugins}/web3/index.js +0 -0
  31. /package/dist/{plugins → src/plugins}/web3/types.js +0 -0
  32. /package/dist/{plugins → src/plugins}/web3/web3Connector.js +0 -0
  33. /package/dist/{plugins → src/plugins}/web3/web3ConnectorPlugin.js +0 -0
  34. /package/dist/{plugins → src/plugins}/web3/web3Signer.js +0 -0
  35. /package/dist/{plugins → src/plugins}/webauthn/index.js +0 -0
  36. /package/dist/{plugins → src/plugins}/webauthn/types.js +0 -0
  37. /package/dist/{plugins → src/plugins}/webauthn/webauthn.js +0 -0
  38. /package/dist/{plugins → src/plugins}/webauthn/webauthnPlugin.js +0 -0
  39. /package/dist/{plugins → src/plugins}/webauthn/webauthnSigner.js +0 -0
  40. /package/dist/{storage → src/storage}/storage.js +0 -0
  41. /package/dist/{types → src/types}/common.js +0 -0
  42. /package/dist/{types → src/types}/events.js +0 -0
  43. /package/dist/{types → src/types}/plugin.js +0 -0
  44. /package/dist/{types → src/types}/shogun.js +0 -0
  45. /package/dist/{utils → src/utils}/errorHandler.js +0 -0
  46. /package/dist/{utils → src/utils}/eventEmitter.js +0 -0
  47. /package/dist/{utils → src/utils}/validation.js +0 -0
  48. /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
  49. /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
  50. /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
  51. /package/dist/types/{gundb → src/gundb}/gun-Instance.d.ts +0 -0
  52. /package/dist/types/{gundb → src/gundb}/gun-rxjs.d.ts +0 -0
  53. /package/dist/types/{gundb → src/gundb}/restricted-put.d.ts +0 -0
  54. /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
  55. /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
  56. /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
  57. /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
  58. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
  59. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  60. /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
  61. /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
  62. /package/dist/types/{plugins → src/plugins}/oauth/index.d.ts +0 -0
  63. /package/dist/types/{plugins → src/plugins}/oauth/oauthConnector.d.ts +0 -0
  64. /package/dist/types/{plugins → src/plugins}/oauth/oauthPlugin.d.ts +0 -0
  65. /package/dist/types/{plugins → src/plugins}/oauth/types.d.ts +0 -0
  66. /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
  67. /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
  68. /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
  69. /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  70. /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
  71. /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
  72. /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
  73. /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
  74. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  75. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
  76. /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
  77. /package/dist/types/{types → src/types}/common.d.ts +0 -0
  78. /package/dist/types/{types → src/types}/events.d.ts +0 -0
  79. /package/dist/types/{types → src/types}/plugin.d.ts +0 -0
  80. /package/dist/types/{types → src/types}/shogun.d.ts +0 -0
  81. /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
  82. /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
  83. /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
@@ -64245,6 +64245,108 @@ function EVP_BytesToKey (password, salt, keyBits, ivLen) {
64245
64245
  module.exports = EVP_BytesToKey
64246
64246
 
64247
64247
 
64248
+ /***/ }),
64249
+
64250
+ /***/ "./node_modules/gun/axe.js":
64251
+ /*!*********************************!*\
64252
+ !*** ./node_modules/gun/axe.js ***!
64253
+ \*********************************/
64254
+ /***/ (() => {
64255
+
64256
+ ;(function(){
64257
+
64258
+ var sT = setTimeout || {}, u;
64259
+ if(typeof window !== ''+u){ sT.window = window }
64260
+ var AXE = (sT.window||'').AXE || function(){};
64261
+ if(AXE.window = sT.window){ AXE.window.AXE = AXE }
64262
+
64263
+ var Gun = (AXE.window||'').GUN || require('./gun');
64264
+ (Gun.AXE = AXE).GUN = AXE.Gun = Gun;
64265
+
64266
+ //if(!Gun.window){ try{ require('./lib/axe') }catch(e){} }
64267
+ if(!Gun.window){ require('./lib/axe') }
64268
+
64269
+ Gun.on('opt', function(at){ start(at) ; this.to.next(at) }); // make sure to call the "next" middleware adapter.
64270
+
64271
+ function start(root){
64272
+ if(root.axe){ return }
64273
+ var opt = root.opt, peers = opt.peers;
64274
+ if(false === opt.axe){ return }
64275
+ if(!Gun.window){ return } // handled by ^ lib/axe.js
64276
+ var w = Gun.window, lS = w.localStorage || opt.localStorage || {}, loc = w.location || opt.location || {}, nav = w.navigator || opt.navigator || {};
64277
+ var axe = root.axe = {}, tmp, id;
64278
+ var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
64279
+
64280
+ tmp = peers[id = loc.origin + '/gun'] = peers[id] || {};
64281
+ tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0;
64282
+ tmp = peers[id = 'http://localhost:8765/gun'] = peers[id] || {};
64283
+ tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0;
64284
+ Gun.log.once("AXE", "AXE enabled: Trying to find network via (1) local peer (2) last used peers (3) a URL parameter, and last (4) hard coded peers.");
64285
+ Gun.log.once("AXEWarn", "Warning: AXE is in alpha, use only for testing!");
64286
+ var last = lS.peers || ''; if(last){ last += ' ' }
64287
+ last += ((loc.search||'').split('peers=')[1]||'').split('&')[0];
64288
+
64289
+ root.on('bye', function(peer){
64290
+ this.to.next(peer);
64291
+ if(!peer.url){ return } // ignore WebRTC disconnects for now.
64292
+ if(!nav.onLine){ peer.retry = 1 }
64293
+ if(peer.retry){ return }
64294
+ if(axe.fall){ delete axe.fall[peer.url || peer.id] }
64295
+ (function next(){
64296
+ if(!axe.fall){ setTimeout(next, 9); return } // not found yet
64297
+ var fall = Object.keys(axe.fall||''), one = fall[(Math.random()*fall.length) >> 0];
64298
+ if(!fall.length){ lS.peers = ''; one = 'https://gunjs.herokuapp.com/gun' } // out of peers
64299
+ if(peers[one]){ next(); return } // already choose
64300
+ mesh.hi(one);
64301
+ }());
64302
+ });
64303
+
64304
+ root.on('hi', function(peer){ // TEMPORARY! Try to connect all peers.
64305
+ this.to.next(peer);
64306
+ if(!peer.url){ return } // ignore WebRTC disconnects for now.
64307
+ return; // DO NOT COMMIT THIS FEATURE YET! KEEP TESTING NETWORK PERFORMANCE FIRST!
64308
+ // removed by dead control flow
64309
+ {}
64310
+ });
64311
+
64312
+ function found(text){
64313
+
64314
+ axe.fall = {};
64315
+ ((text||'').match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/ig)||[]).forEach(function(url){
64316
+ axe.fall[url] = {url: url, id: url, retry: 0}; // RETRY
64317
+ });
64318
+
64319
+ return;
64320
+
64321
+ // TODO: Finish porting below? Maybe not.
64322
+
64323
+ // removed by dead control flow
64324
+ {}
64325
+ // removed by dead control flow
64326
+ {}
64327
+ // removed by dead control flow
64328
+ {}
64329
+
64330
+ // removed by dead control flow
64331
+ { var mesh; } // DAM!
64332
+ // removed by dead control flow
64333
+ {}
64334
+ }
64335
+
64336
+ if(last){ found(last); return }
64337
+ try{ fetch(((loc.search||'').split('axe=')[1]||'').split('&')[0] || loc.axe || 'https://raw.githubusercontent.com/wiki/amark/gun/volunteer.dht.md').then(function(res){
64338
+ return res.text()
64339
+ }).then(function(text){
64340
+ found(lS.peers = text);
64341
+ }).catch(function(){
64342
+ found(); // nothing
64343
+ })}catch(e){found()}
64344
+ }
64345
+
64346
+ var empty = {}, yes = true;
64347
+ try{ if(typeof module != ''+u){ module.exports = AXE } }catch(e){}
64348
+ }());
64349
+
64248
64350
  /***/ }),
64249
64351
 
64250
64352
  /***/ "./node_modules/gun/gun.js":
@@ -68157,6 +68259,114 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
68157
68259
  Type.graph = Type.graph || Graph;
68158
68260
  })();
68159
68261
 
68262
+ /***/ }),
68263
+
68264
+ /***/ "./node_modules/gun/lib/multicast.js":
68265
+ /*!*******************************************!*\
68266
+ !*** ./node_modules/gun/lib/multicast.js ***!
68267
+ \*******************************************/
68268
+ /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
68269
+
68270
+ /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
68271
+ /* provided dependency */ var Buffer = __webpack_require__(/*! buffer */ "./node_modules/buffer/index.js")["Buffer"];
68272
+ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
68273
+
68274
+ Gun.on('create', function(root){
68275
+ this.to.next(root);
68276
+ var opt = root.opt;
68277
+ if(false === opt.multicast){ return }
68278
+ if((typeof process !== "undefined") && 'false' === ''+(process.env||{}).MULTICAST){ return }
68279
+ //if(true !== opt.multicast){ return } // disable multicast by default for now.
68280
+
68281
+ var udp = opt.multicast = opt.multicast || {};
68282
+ udp.address = udp.address || '233.255.255.255';
68283
+ udp.pack = udp.pack || 50000; // UDP messages limited to 65KB.
68284
+ udp.port = udp.port || 8765;
68285
+
68286
+ var noop = function(){}, u;
68287
+ var pid = '2'+Math.random().toString().slice(-8);
68288
+ var mesh = opt.mesh = opt.mesh || Gun.Mesh(root);
68289
+ var dgram;
68290
+
68291
+ try{ dgram = require("dgram") }catch(e){ return }
68292
+ var socket = dgram.createSocket({type: "udp4", reuseAddr: true});
68293
+ socket.bind({port: udp.port, exclusive: true}, function(){
68294
+ socket.setBroadcast(true);
68295
+ socket.setMulticastTTL(128);
68296
+ });
68297
+
68298
+ socket.on("listening", function(){
68299
+ try { socket.addMembership(udp.address) }catch(e){ console.error(e); return; }
68300
+ udp.peer = {id: udp.address + ':' + udp.port, wire: socket};
68301
+
68302
+ udp.peer.say = function(raw){
68303
+ var buf = Buffer.from(raw, 'utf8');
68304
+ if(udp.pack <= buf.length){ // message too big!!!
68305
+ return;
68306
+ }
68307
+ socket.send(buf, 0, buf.length, udp.port, udp.address, noop);
68308
+ }
68309
+ //opt.mesh.hi(udp.peer);
68310
+
68311
+ Gun.log.once('multi', 'Multicast on '+udp.peer.id);
68312
+ return; // below code only needed for when WebSocket connections desired!
68313
+ // removed by dead control flow
68314
+ {}
68315
+ });
68316
+
68317
+ socket.on("message", function(raw, info) { try {
68318
+ if(!raw){ return }
68319
+ raw = raw.toString('utf8');
68320
+ if('2'===raw[0]){ return check(raw, info) }
68321
+ opt.mesh.hear(raw, udp.peer);
68322
+
68323
+ return; // below code only needed for when WebSocket connections desired!
68324
+ // removed by dead control flow
68325
+ { var message; }
68326
+ // removed by dead control flow
68327
+ {}
68328
+
68329
+ // removed by dead control flow
68330
+ {} // ignore self
68331
+
68332
+ // removed by dead control flow
68333
+ { var url; }
68334
+ // removed by dead control flow
68335
+ {}
68336
+
68337
+ //console.log('discovered', url, message, info);
68338
+ // removed by dead control flow
68339
+ {}
68340
+
68341
+ } catch(e){
68342
+ //console.log('multicast error', e, raw);
68343
+ return;
68344
+ } });
68345
+
68346
+ function say(msg){
68347
+ this.to.next(msg);
68348
+ if(!udp.peer){ return }
68349
+ mesh.say(msg, udp.peer);
68350
+ }
68351
+
68352
+ function check(id, info){ var tmp;
68353
+ if(!udp.peer){ return }
68354
+ if(!id){
68355
+ id = check.id = check.id || Buffer.from(pid, 'utf8');
68356
+ socket.send(id, 0, id.length, udp.port, udp.address, noop);
68357
+ return;
68358
+ }
68359
+ if((tmp = root.stats) && (tmp = tmp.gap) && info){ (tmp.near || (tmp.near = {}))[info.address] = info.port || 1 } // STATS!
68360
+ if(check.on || id === pid){ return }
68361
+ root.on('out', check.on = say); // TODO: MULTICAST NEEDS TO BE CHECKED FOR NEW CODE SYSTEM!!!!!!!!!! // TODO: This approach seems interferes with other relays, below does not but...
68362
+ //opt.mesh.hi(udp.peer); // IS THIS CORRECT?
68363
+ }
68364
+
68365
+ setInterval(check, 1000 * 1);
68366
+
68367
+ });
68368
+
68369
+
68160
68370
  /***/ }),
68161
68371
 
68162
68372
  /***/ "./node_modules/gun/lib/radisk.js":
@@ -68774,6 +68984,104 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
68774
68984
 
68775
68985
  /***/ }),
68776
68986
 
68987
+ /***/ "./node_modules/gun/lib/rfs.js":
68988
+ /*!*************************************!*\
68989
+ !*** ./node_modules/gun/lib/rfs.js ***!
68990
+ \*************************************/
68991
+ /***/ (() => {
68992
+
68993
+ function Store(opt){
68994
+ opt = opt || {};
68995
+ opt.log = opt.log || console.log;
68996
+ opt.file = String(opt.file || 'radata');
68997
+ var fs = require('fs'), u;
68998
+
68999
+ var store = function Store(){};
69000
+ if(Store[opt.file]){
69001
+ console.log("Warning: reusing same fs store and options as 1st.");
69002
+ return Store[opt.file];
69003
+ }
69004
+ Store[opt.file] = store;
69005
+ var puts = {};
69006
+
69007
+ // TODO!!! ADD ZLIB INFLATE / DEFLATE COMPRESSION!
69008
+ store.put = function(file, data, cb){
69009
+ var random = Math.random().toString(36).slice(-3);
69010
+ puts[file] = {id: random, data: data};
69011
+ var tmp = opt.file+'-'+file+'-'+random+'.tmp';
69012
+ fs.writeFile(tmp, data, function(err, ok){
69013
+ if(err){
69014
+ if(random === (puts[file]||'').id){ delete puts[file] }
69015
+ return cb(err);
69016
+ }
69017
+ move(tmp, opt.file+'/'+file, function(err, ok){
69018
+ if(random === (puts[file]||'').id){ delete puts[file] }
69019
+ cb(err, ok || !err);
69020
+ });
69021
+ });
69022
+ };
69023
+ store.get = function(file, cb){ var tmp; // this took 3s+?
69024
+ if(tmp = puts[file]){ cb(u, tmp.data); return }
69025
+ fs.readFile(opt.file+'/'+file, function(err, data){
69026
+ if(err){
69027
+ if('ENOENT' === (err.code||'').toUpperCase()){
69028
+ return cb();
69029
+ }
69030
+ opt.log("ERROR:", err);
69031
+ }
69032
+ cb(err, data);
69033
+ });
69034
+ };
69035
+
69036
+ if(!fs.existsSync(opt.file)){ fs.mkdirSync(opt.file) }
69037
+
69038
+ function move(oldPath, newPath, cb) {
69039
+ fs.rename(oldPath, newPath, function (err) {
69040
+ if (err) {
69041
+ if (err.code === 'EXDEV') {
69042
+ var readStream = fs.createReadStream(oldPath);
69043
+ var writeStream = fs.createWriteStream(newPath);
69044
+
69045
+ readStream.on('error', cb);
69046
+ writeStream.on('error', cb);
69047
+
69048
+ readStream.on('close', function () {
69049
+ fs.unlink(oldPath, cb);
69050
+ });
69051
+
69052
+ readStream.pipe(writeStream);
69053
+ } else {
69054
+ cb(err);
69055
+ }
69056
+ } else {
69057
+ cb();
69058
+ }
69059
+ });
69060
+ };
69061
+
69062
+ store.list = function(cb, match, params, cbs){
69063
+ var dir = fs.readdirSync(opt.file);
69064
+ dir.forEach(function(file){
69065
+ cb(file);
69066
+ })
69067
+ cb();
69068
+ };
69069
+
69070
+ return store;
69071
+ }
69072
+
69073
+ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
69074
+ Gun.on('create', function(root){
69075
+ this.to.next(root);
69076
+ var opt = root.opt;
69077
+ if(opt.rfs === false){ return }
69078
+ opt.store = opt.store || (!Gun.window && Store(opt));
69079
+ });
69080
+
69081
+ module.exports = Store;
69082
+
69083
+ /***/ }),
69084
+
68777
69085
  /***/ "./node_modules/gun/lib/rindexed.js":
68778
69086
  /*!******************************************!*\
68779
69087
  !*** ./node_modules/gun/lib/rindexed.js ***!
@@ -68862,6 +69170,288 @@ if (navigator.storage && navigator.storage.estimate) {
68862
69170
 
68863
69171
  /***/ }),
68864
69172
 
69173
+ /***/ "./node_modules/gun/lib/rs3.js":
69174
+ /*!*************************************!*\
69175
+ !*** ./node_modules/gun/lib/rs3.js ***!
69176
+ \*************************************/
69177
+ /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
69178
+
69179
+ /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
69180
+ var Gun = require('../gun');
69181
+ var Radisk = require('./radisk');
69182
+ var fs = require('fs');
69183
+ var Radix = Radisk.Radix;
69184
+ var u, AWS;
69185
+
69186
+ Gun.on('create', function(root){
69187
+ this.to.next(root);
69188
+ var opt = root.opt;
69189
+ if(!opt.s3 && !process.env.AWS_S3_BUCKET){ return }
69190
+ //opt.batch = opt.batch || (1000 * 10);
69191
+ //opt.until = opt.until || (1000 * 3); // ignoring these now, cause perf > cost
69192
+ //opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB // when cost only cents
69193
+
69194
+ try{AWS = require('aws-sdk');
69195
+ }catch(e){
69196
+ console.log("Please `npm install aws-sdk` or add it to your package.json !");
69197
+ AWS_SDK_NOT_INSTALLED;
69198
+ }
69199
+
69200
+ var opts = opt.s3 || (opt.s3 = {});
69201
+ opts.bucket = opts.bucket || process.env.AWS_S3_BUCKET;
69202
+ opts.region = opts.region || process.env.AWS_REGION || "us-east-1";
69203
+ opts.accessKeyId = opts.key = opts.key || opts.accessKeyId || process.env.AWS_ACCESS_KEY_ID;
69204
+ opts.secretAccessKey = opts.secret = opts.secret || opts.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY;
69205
+
69206
+ if(opt.fakes3 = opt.fakes3 || process.env.fakes3){
69207
+ opts.endpoint = opt.fakes3;
69208
+ opts.sslEnabled = false;
69209
+ opts.bucket = opts.bucket.replace('.','p');
69210
+ }
69211
+
69212
+ opts.config = new AWS.Config(opts);
69213
+ opts.s3 = opts.s3 || new AWS.S3(opts.config);
69214
+
69215
+ opt.store = Object.keys(opts.s3).length === 0 ? opt.store : Store(opt);
69216
+ });
69217
+
69218
+ function Store(opt){
69219
+ opt = opt || {};
69220
+ opt.file = String(opt.file || 'radata');
69221
+ var opts = opt.s3, s3 = opts.s3;
69222
+ var c = {p: {}, g: {}, l: {}};
69223
+
69224
+ var store = function Store(){};
69225
+ if(Store[opt.file]){
69226
+ console.log("Warning: reusing same S3 store and options as 1st.");
69227
+ return Store[opt.file];
69228
+ }
69229
+ Store[opt.file] = store;
69230
+
69231
+ store.put = function(file, data, cb){
69232
+ var params = {Bucket: opts.bucket, Key: file, Body: data};
69233
+ //console.log("RS3 PUT ---->", (data||"").slice(0,20));
69234
+ c.p[file] = data;
69235
+ delete c.g[file];//Gun.obj.del(c.g, file);
69236
+ delete c.l[1];//Gun.obj.del(c.l, 1);
69237
+ s3.putObject(params, function(err, ok){
69238
+ delete c.p[file];
69239
+ cb(err, 's3');
69240
+ });
69241
+ };
69242
+ store.get = function(file, cb){ var tmp;
69243
+ if(tmp = c.p[file]){ cb(u, tmp); return }
69244
+ if(tmp = c.g[file]){ tmp.push(cb); return }
69245
+ var cbs = c.g[file] = [cb];
69246
+ var params = {Bucket: opts.bucket, Key: file||''};
69247
+ //console.log("RS3 GET ---->", file);
69248
+ s3.getObject(params, function got(err, ack){
69249
+ if(err && 'NoSuchKey' === err.code){ err = u }
69250
+ //console.log("RS3 GOT <----", err, file, cbs.length, ((ack||{}).Body||'').length);//.toString().slice(0,20));
69251
+ delete c.g[file];//Gun.obj.del(c.g, file);
69252
+ var data, data = (ack||'').Body;
69253
+ //console.log(1, process.memoryUsage().heapUsed);
69254
+ var i = 0, cba; while(cba = cbs[i++]){ cba && cba(err, data) }//Gun.obj.map(cbs, cbe);
69255
+ });
69256
+ };
69257
+ store.list = function(cb, match, params, cbs){
69258
+ if(!cbs){
69259
+ if(c.l[1]){ return c.l[1].push(cb) }
69260
+ cbs = c.l[1] = [cb];
69261
+ }
69262
+ params = params || {Bucket: opts.bucket};
69263
+ //console.log("RS3 LIST --->");
69264
+ s3.listObjectsV2(params, function(err, data){
69265
+ //console.log("RS3 LIST <---", err, data, cbs.length);
69266
+ if(err){ return Gun.log(err, err.stack) }
69267
+ var IT = data.IsTruncated, cbe = function(cb){
69268
+ if(cb.end){ return }
69269
+ if(Gun.obj.map(data.Contents, function(content){
69270
+ return cb(content.Key);
69271
+ })){ cb.end = true; return }
69272
+ if(IT){ return }
69273
+ // Stream interface requires a final call to know when to be done.
69274
+ cb.end = true; cb();
69275
+ }
69276
+ // Gun.obj.map(cbs, cbe); // lets see if fixes heroku
69277
+ if(!IT){ delete c.l[1]; return }
69278
+ params.ContinuationToken = data.NextContinuationToken;
69279
+ store.list(cb, match, params, cbs);
69280
+ });
69281
+ };
69282
+ //store.list(function(){ return true });
69283
+ if(false !== opt.rfs){ require('./rfsmix')(opt, store) } // ugly, but gotta move fast for now.
69284
+ return store;
69285
+ }
69286
+
69287
+ module.exports = Store;
69288
+
69289
+
69290
+ /***/ }),
69291
+
69292
+ /***/ "./node_modules/gun/lib/serve.js":
69293
+ /*!***************************************!*\
69294
+ !*** ./node_modules/gun/lib/serve.js ***!
69295
+ \***************************************/
69296
+ /***/ (() => {
69297
+
69298
+ var __dirname = "/";
69299
+ var fs = require('fs');
69300
+ var path = require('path');
69301
+ var dot = /\.\.+/g;
69302
+ var slash = /\/\/+/g;
69303
+
69304
+ function CDN(dir){
69305
+ return function(req, res){
69306
+ req.url = (req.url||'').replace(dot,'').replace(slash,'/');
69307
+ if(serve(req, res)){ return } // filters GUN requests!
69308
+ if (req.url.slice(-3) === '.js') {
69309
+ res.writeHead(200, {'Content-Type': 'text/javascript'});
69310
+ }
69311
+ fs.createReadStream(path.join(dir, req.url)).on('error',function(tmp){ // static files!
69312
+ fs.readFile(path.join(dir, 'index.html'), function(err, tmp){
69313
+ try{ res.writeHead(200, {'Content-Type': 'text/html'});
69314
+ res.end(tmp+''); }catch(e){} // or default to index
69315
+ })}).pipe(res); // stream
69316
+ }
69317
+ }
69318
+
69319
+ function serve(req, res, next){ var tmp;
69320
+ if(typeof req === 'string'){
69321
+ return CDN(req);
69322
+ }
69323
+ if(!req || !res){ return false }
69324
+ next = next || serve;
69325
+ if(!req.url){ return next() }
69326
+ if(res.setHeader){ res.setHeader('Access-Control-Allow-Origin', '*') }
69327
+ if(0 <= req.url.indexOf('gun.js')){
69328
+ res.writeHead(200, {'Content-Type': 'text/javascript'});
69329
+ res.end(serve.js = serve.js || require('fs').readFileSync(__dirname + '/../gun.js'));
69330
+ return true;
69331
+ }
69332
+ if(0 <= req.url.indexOf('gun/')){
69333
+ var path = __dirname + '/../' + req.url.split('/').slice(2).join('/');
69334
+ if('/' === path.slice(-1)){
69335
+ fs.readdir(path, function(err, dir){ res.end((dir || (err && 404))+'') });
69336
+ return true;
69337
+ }
69338
+ var S = +new Date;
69339
+ var rs = fs.createReadStream(path);
69340
+ rs.on('open', function(){ console.STAT && console.STAT(S, +new Date - S, 'serve file open'); rs.pipe(res) });
69341
+ rs.on('error', function(err){ res.end(404+'') });
69342
+ rs.on('end', function(){ console.STAT && console.STAT(S, +new Date - S, 'serve file end') });
69343
+ return true;
69344
+ }
69345
+ if((tmp = req.socket) && (tmp = tmp.server) && (tmp = tmp.route)){ var url;
69346
+ if(tmp = tmp[(((req.url||'').slice(1)).split('/')[0]||'').split('.')[0]]){
69347
+ try{ return tmp(req, res, next) }catch(e){ console.log(req.url+' crashed with '+e) }
69348
+ }
69349
+ }
69350
+ return next();
69351
+ }
69352
+
69353
+ module.exports = serve;
69354
+
69355
+
69356
+ /***/ }),
69357
+
69358
+ /***/ "./node_modules/gun/lib/stats.js":
69359
+ /*!***************************************!*\
69360
+ !*** ./node_modules/gun/lib/stats.js ***!
69361
+ \***************************************/
69362
+ /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
69363
+
69364
+ var __dirname = "/";
69365
+ /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
69366
+ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
69367
+
69368
+ Gun.on('opt', function(root){
69369
+ this.to.next(root);
69370
+ if(root.once){ return }
69371
+ if(typeof process === 'undefined'){ return }
69372
+ if(typeof require === 'undefined'){ return }
69373
+ if(false === root.opt.stats){ return }
69374
+ var path = require('path') || {};
69375
+ var file = root.opt.file ? path.resolve(root.opt.file).split(path.sep).slice(-1)[0] : 'radata';
69376
+ var noop = function(){};
69377
+ var os = require('os') || {};
69378
+ var fs = require('fs') || {};
69379
+ fs.existsSync = fs.existsSync || path.existsSync;
69380
+ if(!fs.existsSync){ return }
69381
+ if(!process){ return }
69382
+ process.uptime = process.uptime || noop;
69383
+ process.cpuUsage = process.cpuUsage || noop;
69384
+ process.memoryUsage = process.memoryUsage || noop;
69385
+ os.totalmem = os.totalmem || noop;
69386
+ os.freemem = os.freemem || noop;
69387
+ os.loadavg = os.loadavg || noop;
69388
+ os.cpus = os.cpus || noop;
69389
+ var S = +new Date, W;
69390
+ var obj_ify = function(o){try{o = JSON.parse(o)}catch(e){o={}};return o;}
69391
+ setTimeout(function(){
69392
+ root.stats = obj_ify((fs.existsSync(__dirname+'/../stats.'+file) && fs.readFileSync(__dirname+'/../stats.'+file).toString())) || {};
69393
+ root.stats.up = root.stats.up || {};
69394
+ root.stats.up.start = root.stats.up.start || +(new Date);
69395
+ root.stats.up.count = (root.stats.up.count || 0) + 1;
69396
+ root.stats.stay = root.stats.stay || {};
69397
+ root.stats.over = +new Date;
69398
+ },1);
69399
+ setInterval(function(){
69400
+ if(!root.stats){ root.stats = {} }
69401
+ if(W){ return }
69402
+ var stats = root.stats, tmp;
69403
+ stats.over = -(S - (S = +new Date));
69404
+ (stats.up||{}).time = process.uptime();
69405
+ stats.memory = process.memoryUsage() || {};
69406
+ stats.memory.totalmem = os.totalmem();
69407
+ stats.memory.freemem = os.freemem();
69408
+ stats.cpu = process.cpuUsage() || {};
69409
+ stats.cpu.loadavg = os.loadavg();
69410
+ stats.cpu.stack = (((setTimeout||'').turn||'').s||'').length;
69411
+ stats.peers = {};
69412
+
69413
+ stats.peers.count = console.STAT.peers || Object.keys(root.opt.peers||{}).length; // TODO: .keys( is slow
69414
+ stats.node = {};
69415
+ stats.node.count = Object.keys(root.graph||{}).length; // TODO: .keys( is slow
69416
+ stats.all = all;
69417
+ stats.sites = console.STAT.sites;
69418
+ all = {}; // will this cause missing stats?
69419
+ var dam = root.opt.mesh;
69420
+ if(dam){
69421
+ stats.dam = {'in': {count: dam.hear.c, done: dam.hear.d}, 'out': {count: dam.say.c, done: dam.say.d}};
69422
+ dam.hear.c = dam.hear.d = dam.say.c = dam.say.d = 0; // reset
69423
+ stats.peers.time = dam.bye.time || 0;
69424
+ }
69425
+ var rad = root.opt.store; rad = rad && rad.stats;
69426
+ if(rad){
69427
+ stats.rad = rad;
69428
+ root.opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // reset
69429
+ }
69430
+ JSON.stringifyAsync(stats, function(err, raw){ if(err){ return } W = true;
69431
+ fs.writeFile(__dirname+'/../stats.'+file, raw, function(err){ W = false; err && console.log(console.STAT.err = err); console.STAT && console.STAT(S, +new Date - S, 'stats stash') });
69432
+ });
69433
+
69434
+ //exec("top -b -n 1", function(err, out){ out && fs.writeFile(__dirname+'/../stats.top.'+file, out, noop) }); // was it really seriously actually this?
69435
+ //}, 1000 * 15);
69436
+ }, 1000 * 5);
69437
+ });
69438
+
69439
+ var exec = require("child_process").exec, noop = function(){};
69440
+ require('./yson');
69441
+
69442
+ var log = Gun.log, all = {}, max = 1000;
69443
+ console.STAT = function(a,b,c,d){
69444
+ if('number' == typeof a && 'number' == typeof b && 'string' == typeof c){
69445
+ var tmp = (all[c] || (all[c] = []));
69446
+ if(max < tmp.push([a,b])){ all[c] = [] } // reset
69447
+ //return;
69448
+ }
69449
+ if(!console.LOG || log.off){ return a }
69450
+ return log.apply(Gun, arguments);
69451
+ }
69452
+
69453
+ /***/ }),
69454
+
68865
69455
  /***/ "./node_modules/gun/lib/store.js":
68866
69456
  /*!***************************************!*\
68867
69457
  !*** ./node_modules/gun/lib/store.js ***!
@@ -69175,6 +69765,99 @@ Gun.chain.then = function(cb) {
69175
69765
 
69176
69766
  /***/ }),
69177
69767
 
69768
+ /***/ "./node_modules/gun/lib/wire.js":
69769
+ /*!**************************************!*\
69770
+ !*** ./node_modules/gun/lib/wire.js ***!
69771
+ \**************************************/
69772
+ /***/ (() => {
69773
+
69774
+ var Gun = require('../gun');
69775
+
69776
+ /*
69777
+ An Ad-Hoc Mesh-Network Daisy-Chain
69778
+ should work even if humans are
69779
+ communicating with each other blind.
69780
+
69781
+ To prevent infinite broadcast loops,
69782
+ we use a deduplication process
69783
+ based on the message's identifier.
69784
+ This is currently implemented in core.
69785
+
69786
+ However, because this still creates a
69787
+ N*2 (where N is the number of connections)
69788
+ flood, it is not scalable for traditional
69789
+ services that have a hub network topology.
69790
+
69791
+ Does this mean we have to abandon mesh
69792
+ algorithms? No, we can simply layer more
69793
+ efficient optimizations in based on constraints.
69794
+ If these constraints exist, it automatically
69795
+ upgrades, but if not, it falls back to the
69796
+ brute-force mesh based robust algorithm.
69797
+ A simple example is to limit peer connections
69798
+ and rely upon daisy chaining to relay messages.
69799
+
69800
+ Another example, is if peers are willing to
69801
+ identify themselves, then we can improve the
69802
+ efficiency of the network by having each peer
69803
+ include the names of peers it is connected in
69804
+ each message. Then each subsequent peer will
69805
+ not relay it to them, since it is unnecessary.
69806
+ This should create N (where N is the number of
69807
+ peers) messages (or possibly N+ if there is a
69808
+ common peer of uncommon peers that receives it
69809
+ and relays at exact latency timings), which is
69810
+ optimal.
69811
+
69812
+ Since computer networks aren't actually blind,
69813
+ we will implement the above method to improve
69814
+ the performance of the ad-hoc mesh network.
69815
+
69816
+ But why not have every message contain the
69817
+ whole history of peers that it relayed through?
69818
+ Because in sufficiently large enough networks,
69819
+ with extensive daisy chaining, this will cause
69820
+ the message to become prohibitively slow and
69821
+ increase indefinitely in size.
69822
+
69823
+ */
69824
+
69825
+ Gun.on('opt', function(root){
69826
+ var opt = root.opt;
69827
+ if(false === opt.ws || opt.once){
69828
+ this.to.next(root);
69829
+ return;
69830
+ }
69831
+
69832
+ var url = require('url');
69833
+ opt.mesh = opt.mesh || Gun.Mesh(root);
69834
+ opt.WebSocket = opt.WebSocket || require('ws');
69835
+ var ws = opt.ws = opt.ws || {};
69836
+ ws.path = ws.path || '/gun';
69837
+ // if we DO need an HTTP server, then choose ws specific one or GUN default one.
69838
+ if(!ws.noServer){
69839
+ ws.server = ws.server || opt.web;
69840
+ if(!ws.server){ this.to.next(root); return } // ugh, bug fix for @jamierez & unstoppable ryan.
69841
+ }
69842
+ ws.web = ws.web || new opt.WebSocket.Server(ws); // we still need a WS server.
69843
+ ws.web.on('connection', function(wire, req){ var peer;
69844
+ wire.headers = wire.headers || (req||'').headers || '';
69845
+ console.STAT && ((console.STAT.sites || (console.STAT.sites = {}))[wire.headers.origin] = 1);
69846
+ opt.mesh.hi(peer = {wire: wire});
69847
+ wire.on('message', function(msg){
69848
+ opt.mesh.hear(msg.data || msg, peer);
69849
+ });
69850
+ wire.on('close', function(){
69851
+ opt.mesh.bye(peer);
69852
+ });
69853
+ wire.on('error', function(e){});
69854
+ setTimeout(function heart(){ if(!opt.peers[peer.id]){ return } try{ wire.send("[]") }catch(e){} ;setTimeout(heart, 1000 * 20) }, 1000 * 20); // Some systems, like Heroku, require heartbeats to not time out. // TODO: Make this configurable? // TODO: PERF: Find better approach than try/timeouts?
69855
+ });
69856
+ this.to.next(root);
69857
+ });
69858
+
69859
+ /***/ }),
69860
+
69178
69861
  /***/ "./node_modules/gun/lib/yson.js":
69179
69862
  /*!**************************************!*\
69180
69863
  !*** ./node_modules/gun/lib/yson.js ***!
@@ -97951,6 +98634,25 @@ exports.createContext = Script.createContext = function (context) {
97951
98634
  };
97952
98635
 
97953
98636
 
98637
+ /***/ }),
98638
+
98639
+ /***/ "./node_modules/ws/browser.js":
98640
+ /*!************************************!*\
98641
+ !*** ./node_modules/ws/browser.js ***!
98642
+ \************************************/
98643
+ /***/ ((module) => {
98644
+
98645
+ "use strict";
98646
+
98647
+
98648
+ module.exports = function () {
98649
+ throw new Error(
98650
+ 'ws does not work in the browser. Browser clients must use the native ' +
98651
+ 'WebSocket object'
98652
+ );
98653
+ };
98654
+
98655
+
97954
98656
  /***/ }),
97955
98657
 
97956
98658
  /***/ "./src/gundb/crypto.ts":
@@ -101597,6 +102299,313 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
101597
102299
  Object.defineProperty(exports, "__esModule", ({ value: true }));
101598
102300
  // Export the main class
101599
102301
  __exportStar(__webpack_require__(/*! ./gun-Instance */ "./src/gundb/gun-Instance.ts"), exports);
102302
+ // Export the relay class
102303
+ __exportStar(__webpack_require__(/*! ./relay */ "./src/gundb/relay.ts"), exports);
102304
+
102305
+
102306
+ /***/ }),
102307
+
102308
+ /***/ "./src/gundb/relay.ts":
102309
+ /*!****************************!*\
102310
+ !*** ./src/gundb/relay.ts ***!
102311
+ \****************************/
102312
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
102313
+
102314
+ "use strict";
102315
+
102316
+ /**
102317
+ * GunDB Relay Server Class
102318
+ * Instantiates and manages a GunDB relay server with configurable options
102319
+ */
102320
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
102321
+ exports.RelayPresets = exports.Relay = void 0;
102322
+ exports.createRelay = createRelay;
102323
+ // Gun modules will be loaded dynamically when needed
102324
+ let Gun;
102325
+ let gunModulesLoaded = false;
102326
+ /**
102327
+ * Loads Gun modules dynamically to avoid issues during testing
102328
+ */
102329
+ function loadGunModules() {
102330
+ if (gunModulesLoaded)
102331
+ return;
102332
+ try {
102333
+ Gun = __webpack_require__(/*! gun/gun */ "./node_modules/gun/gun.js");
102334
+ __webpack_require__(/*! gun/lib/yson */ "./node_modules/gun/lib/yson.js");
102335
+ __webpack_require__(/*! gun/lib/serve */ "./node_modules/gun/lib/serve.js");
102336
+ __webpack_require__(/*! gun/lib/store */ "./node_modules/gun/lib/store.js");
102337
+ __webpack_require__(/*! gun/lib/rfs */ "./node_modules/gun/lib/rfs.js");
102338
+ __webpack_require__(/*! gun/lib/rs3 */ "./node_modules/gun/lib/rs3.js");
102339
+ __webpack_require__(/*! gun/lib/wire */ "./node_modules/gun/lib/wire.js");
102340
+ __webpack_require__(/*! gun/lib/multicast */ "./node_modules/gun/lib/multicast.js");
102341
+ __webpack_require__(/*! gun/lib/stats */ "./node_modules/gun/lib/stats.js");
102342
+ // Optional modules - wrapped in try-catch for compatibility
102343
+ try {
102344
+ __webpack_require__(/*! gun/sea */ "./node_modules/gun/sea.js");
102345
+ }
102346
+ catch (e) {
102347
+ // SEA not available
102348
+ }
102349
+ try {
102350
+ __webpack_require__(/*! gun/axe */ "./node_modules/gun/axe.js");
102351
+ }
102352
+ catch (e) {
102353
+ // Axe not available
102354
+ }
102355
+ gunModulesLoaded = true;
102356
+ }
102357
+ catch (error) {
102358
+ // In test environment, don't throw error, just log it
102359
+ if (false) // removed by dead control flow
102360
+ {}
102361
+ else {
102362
+ throw new Error(`Failed to load Gun modules: ${error}`);
102363
+ }
102364
+ }
102365
+ }
102366
+ /**
102367
+ * GunDB Relay Server Class
102368
+ *
102369
+ * This class creates and manages a GunDB relay server that can:
102370
+ * - Serve as a peer for other GunDB instances
102371
+ * - Store and relay data between connected peers
102372
+ * - Provide persistence and caching
102373
+ * - Handle authentication and encryption
102374
+ */
102375
+ class Relay {
102376
+ gun;
102377
+ server;
102378
+ config;
102379
+ status;
102380
+ log;
102381
+ /**
102382
+ * Creates a new GunDB relay server instance
102383
+ * @param config Configuration options for the relay server
102384
+ */
102385
+ constructor(config = {}) {
102386
+ // Load Gun modules when the class is instantiated
102387
+ loadGunModules();
102388
+ this.config = {
102389
+ port: 8765,
102390
+ host: "0.0.0.0",
102391
+ super: false,
102392
+ faith: false,
102393
+ enableFileStorage: false,
102394
+ enableEviction: false,
102395
+ ...config,
102396
+ };
102397
+ this.status = {
102398
+ running: false,
102399
+ peers: 0,
102400
+ };
102401
+ this.log = this.config.log || console.log;
102402
+ // Initialize Gun instance with relay configuration
102403
+ try {
102404
+ this.gun = Gun({
102405
+ file: this.config.enableFileStorage ? "data" : false,
102406
+ web: this.createServer(),
102407
+ multicast: false, // Disable multicast for relay servers
102408
+ ...this.config.gunOptions,
102409
+ });
102410
+ }
102411
+ catch (error) {
102412
+ // In test environment, create a minimal mock
102413
+ if (false) // removed by dead control flow
102414
+ {}
102415
+ else {
102416
+ throw error;
102417
+ }
102418
+ }
102419
+ // Configure Gun options
102420
+ this.gun.on("opt", (root) => {
102421
+ if (this.config.super !== undefined) {
102422
+ root.opt.super = this.config.super;
102423
+ }
102424
+ if (this.config.faith !== undefined) {
102425
+ root.opt.faith = this.config.faith;
102426
+ }
102427
+ root.opt.log = root.opt.log || this.log;
102428
+ // Continue the chain
102429
+ if (root.to && root.to.next) {
102430
+ root.to.next(root);
102431
+ }
102432
+ });
102433
+ // Track peer connections
102434
+ this.gun.on("hi", () => {
102435
+ this.status.peers++;
102436
+ this.log(`Peer connected. Total peers: ${this.status.peers}`);
102437
+ });
102438
+ this.gun.on("bye", () => {
102439
+ this.status.peers = Math.max(0, this.status.peers - 1);
102440
+ this.log(`Peer disconnected. Total peers: ${this.status.peers}`);
102441
+ });
102442
+ }
102443
+ /**
102444
+ * Creates the HTTP/WebSocket server for the relay
102445
+ * @returns Server instance
102446
+ */
102447
+ createServer() {
102448
+ try {
102449
+ const server = Object(function webpackMissingModule() { var e = new Error("Cannot find module 'http'"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();
102450
+ // Configure WebSocket server
102451
+ if (this.config.ws) {
102452
+ const WebSocketServer = (__webpack_require__(/*! ws */ "./node_modules/ws/browser.js").Server);
102453
+ const wss = new WebSocketServer({ server });
102454
+ wss.on("connection", (ws) => {
102455
+ this.log("WebSocket connection established");
102456
+ });
102457
+ }
102458
+ // Configure HTTP server
102459
+ if (this.config.http) {
102460
+ Object.assign(server, this.config.http);
102461
+ }
102462
+ this.server = server;
102463
+ return server;
102464
+ }
102465
+ catch (error) {
102466
+ // In test environment, create a minimal mock server
102467
+ if (false) // removed by dead control flow
102468
+ {}
102469
+ else {
102470
+ throw error;
102471
+ }
102472
+ }
102473
+ }
102474
+ /**
102475
+ * Starts the relay server
102476
+ * @returns Promise that resolves when the server is started
102477
+ */
102478
+ async start() {
102479
+ return new Promise((resolve, reject) => {
102480
+ try {
102481
+ this.server.listen(this.config.port, this.config.host, () => {
102482
+ this.status.running = true;
102483
+ this.status.port = this.config.port;
102484
+ this.status.host = this.config.host;
102485
+ this.status.startTime = new Date();
102486
+ this.log(`GunDB Relay Server started on ${this.config.host}:${this.config.port}`);
102487
+ this.log(`Super peer mode: ${this.config.super ? "enabled" : "disabled"}`);
102488
+ this.log(`Faith mode: ${this.config.faith ? "enabled" : "disabled"}`);
102489
+ resolve();
102490
+ });
102491
+ this.server.on("error", (error) => {
102492
+ this.log("Server error:", error);
102493
+ reject(error);
102494
+ });
102495
+ }
102496
+ catch (error) {
102497
+ reject(error);
102498
+ }
102499
+ });
102500
+ }
102501
+ /**
102502
+ * Stops the relay server
102503
+ * @returns Promise that resolves when the server is stopped
102504
+ */
102505
+ async stop() {
102506
+ return new Promise((resolve) => {
102507
+ if (this.server && this.status.running) {
102508
+ this.server.close(() => {
102509
+ this.status.running = false;
102510
+ this.log("GunDB Relay Server stopped");
102511
+ resolve();
102512
+ });
102513
+ }
102514
+ else {
102515
+ resolve();
102516
+ }
102517
+ });
102518
+ }
102519
+ /**
102520
+ * Gets the current status of the relay server
102521
+ * @returns Current relay status
102522
+ */
102523
+ getStatus() {
102524
+ return { ...this.status };
102525
+ }
102526
+ /**
102527
+ * Gets the Gun instance
102528
+ * @returns Gun instance
102529
+ */
102530
+ getGun() {
102531
+ return this.gun;
102532
+ }
102533
+ /**
102534
+ * Gets the server instance
102535
+ * @returns Server instance
102536
+ */
102537
+ getServer() {
102538
+ return this.server;
102539
+ }
102540
+ /**
102541
+ * Updates the relay configuration
102542
+ * @param newConfig New configuration options
102543
+ */
102544
+ updateConfig(newConfig) {
102545
+ this.config = { ...this.config, ...newConfig };
102546
+ this.log("Relay configuration updated");
102547
+ }
102548
+ /**
102549
+ * Gets the relay URL
102550
+ * @returns Relay URL string
102551
+ */
102552
+ getRelayUrl() {
102553
+ const protocol = this.config.ws ? "wss" : "http";
102554
+ return `${protocol}://${this.config.host}:${this.config.port}/gun`;
102555
+ }
102556
+ /**
102557
+ * Checks if the relay is healthy
102558
+ * @returns Promise that resolves to true if healthy
102559
+ */
102560
+ async healthCheck() {
102561
+ try {
102562
+ return this.status.running && this.server.listening;
102563
+ }
102564
+ catch (error) {
102565
+ return false;
102566
+ }
102567
+ }
102568
+ }
102569
+ exports.Relay = Relay;
102570
+ /**
102571
+ * Factory function to create a relay server with default configuration
102572
+ * @param config Optional configuration overrides
102573
+ * @returns Relay instance
102574
+ */
102575
+ function createRelay(config = {}) {
102576
+ return new Relay(config);
102577
+ }
102578
+ /**
102579
+ * Default relay configurations for common use cases
102580
+ */
102581
+ exports.RelayPresets = {
102582
+ /** Development relay with basic configuration */
102583
+ development: {
102584
+ port: 8765,
102585
+ host: "localhost",
102586
+ super: false,
102587
+ faith: false,
102588
+ enableFileStorage: true,
102589
+ },
102590
+ /** Production relay with enhanced configuration */
102591
+ production: {
102592
+ port: 8765,
102593
+ host: "0.0.0.0",
102594
+ super: true,
102595
+ faith: true,
102596
+ enableFileStorage: true,
102597
+ enableEviction: true,
102598
+ },
102599
+ /** Test relay with minimal configuration */
102600
+ test: {
102601
+ port: 8766,
102602
+ host: "localhost",
102603
+ super: false,
102604
+ faith: false,
102605
+ enableFileStorage: false,
102606
+ },
102607
+ };
102608
+ exports["default"] = Relay;
101600
102609
 
101601
102610
 
101602
102611
  /***/ }),
@@ -101722,7 +102731,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
101722
102731
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
101723
102732
  };
101724
102733
  Object.defineProperty(exports, "__esModule", ({ value: true }));
101725
- exports.ShogunCore = exports.GunInstance = exports.GunErrors = exports.derive = exports.crypto = exports.GunRxJS = exports.Gun = exports.SEA = void 0;
102734
+ exports.ShogunCore = exports.RelayPresets = exports.createRelay = exports.Relay = exports.GunInstance = exports.GunErrors = exports.derive = exports.crypto = exports.GunRxJS = exports.Gun = exports.SEA = void 0;
101726
102735
  const events_1 = __webpack_require__(/*! ./types/events */ "./src/types/events.ts");
101727
102736
  const errorHandler_1 = __webpack_require__(/*! ./utils/errorHandler */ "./src/utils/errorHandler.ts");
101728
102737
  const storage_1 = __webpack_require__(/*! ./storage/storage */ "./src/storage/storage.ts");
@@ -101739,6 +102748,9 @@ Object.defineProperty(exports, "GunRxJS", ({ enumerable: true, get: function ()
101739
102748
  Object.defineProperty(exports, "crypto", ({ enumerable: true, get: function () { return gundb_1.crypto; } }));
101740
102749
  Object.defineProperty(exports, "derive", ({ enumerable: true, get: function () { return gundb_1.derive; } }));
101741
102750
  Object.defineProperty(exports, "GunErrors", ({ enumerable: true, get: function () { return gundb_1.GunErrors; } }));
102751
+ Object.defineProperty(exports, "Relay", ({ enumerable: true, get: function () { return gundb_1.Relay; } }));
102752
+ Object.defineProperty(exports, "createRelay", ({ enumerable: true, get: function () { return gundb_1.createRelay; } }));
102753
+ Object.defineProperty(exports, "RelayPresets", ({ enumerable: true, get: function () { return gundb_1.RelayPresets; } }));
101742
102754
  __exportStar(__webpack_require__(/*! ./utils/errorHandler */ "./src/utils/errorHandler.ts"), exports);
101743
102755
  __exportStar(__webpack_require__(/*! ./plugins */ "./src/plugins/index.ts"), exports);
101744
102756
  __exportStar(__webpack_require__(/*! ./types/shogun */ "./src/types/shogun.ts"), exports);
@@ -101804,8 +102816,8 @@ class ShogunCore {
101804
102816
  else {
101805
102817
  this._gun = (0, gundb_1.Gun)({
101806
102818
  peers: config.peers || [],
101807
- radisk: false,
101808
- localStorage: false,
102819
+ radisk: config.radisk || false,
102820
+ localStorage: config.localStorage || false,
101809
102821
  });
101810
102822
  }
101811
102823
  }