shogun-core 1.11.5 → 1.11.6

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.
@@ -68272,241 +68272,6 @@ module.exports = webpackEmptyContext;
68272
68272
  }());
68273
68273
 
68274
68274
 
68275
- /***/ }),
68276
-
68277
- /***/ "./node_modules/gun/lib/les.js":
68278
- /*!*************************************!*\
68279
- !*** ./node_modules/gun/lib/les.js ***!
68280
- \*************************************/
68281
- /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
68282
-
68283
- /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
68284
- ;
68285
- (function() {
68286
-
68287
- // _ _____ ____ _
68288
- // | | | ____/ ___| (_)___
68289
- // | | | _| \___ \ | / __|
68290
- // | |___| |___ ___) | | \__ \
68291
- // |_____|_____|____(_)/ |___/
68292
- // ----------------------------
68293
- // LES.js (Last rEcently uSed)
68294
- // ----------------------------
68295
- // A Small, lightweight, queue-based
68296
- // Garbage Collector for Gun
68297
- // Originally By: Collin Conrad (@masterex1000)
68298
-
68299
- /**
68300
- *
68301
- * Usage: require the file in your application
68302
- *
68303
- * Gun Params: these are passed to the new gun constructor
68304
- *
68305
- * - gc_enable : enables the gc, good if you are running multiple instances of gun, etc... def. true
68306
- * - gc_delay : sets the amount of time between attempted garbage collections in milliseconds
68307
- * - gc_info_enable : Enables or Disables the info printout
68308
- * - gc_info : sets the ~ amount of time between info messages
68309
- * this is checked every time the gc is ran
68310
- * - gc_info_mini : this will use a smaller, less user friendly info printout
68311
- * - gc_importance_func : This will be the function used for finding the importance of a potential collect
68312
- * takes the form of func(timestamp, ctime, memoryUsageRatio) {return val}
68313
- * Collects when returned value is 100
68314
- */
68315
-
68316
- //NOTE: set to false to use require for getting gun DEFAULT: false
68317
- var USELOCALGUN = false;
68318
-
68319
-
68320
- //NOTE: adds some debug messages DEFAULT: false
68321
- var DEBUG = false;
68322
-
68323
- if(false)
68324
- // removed by dead control flow
68325
- {}
68326
-
68327
- var Gun = ( true) ? window.Gun : (0);
68328
-
68329
- //Removes a node from the garbage collection until next write
68330
- Gun.chain.gcDequeue = function() {
68331
- //console.log(this._.root.dequeueNode);
68332
- if(this._.root.dequeueNode) { // check that we actually have the dequeue command on this node
68333
- let ctx = this;
68334
-
68335
- this.get(function (soul) {
68336
- ctx._.root.dequeueNode(soul);
68337
- }, true);
68338
- }
68339
- }
68340
-
68341
- //Puts node at the front for garbage collection, NOTE: only collects when it is hit it's time
68342
- Gun.chain.gcCollect = function() {
68343
- if(this._.root.collectNode) { // check that we actually have the dequeue command on this node
68344
- let ctx = this;
68345
-
68346
- this.get(function (soul) {
68347
- ctx._.root.collectNode(soul);
68348
- }, true);
68349
- }
68350
- }
68351
-
68352
- Gun.on('opt', function(root) {
68353
- //Setup various options
68354
-
68355
- const gc_enable = root.opt.gc_enable ? root.opt.gc_enable : true;
68356
- const gc_delay = root.opt.gc_delay ? root.opt.gc_delay : 1000;
68357
-
68358
- const gc_info_enable = ("gc_info_enable" in root.opt) ? root.opt.gc_info_enable : true;
68359
- const gc_info = root.opt.gc_info ? root.opt.gc_info : 5000;
68360
- const gc_info_mini = root.opt.gc_info_mini ? root.opt.gc_info_mini : false;
68361
-
68362
- //This is long, but it works well
68363
- const calcRemoveImportance = root.opt.gc_importance_func ? root.opt.gc_importance_func : function (timestamp, ctime, memoryUsageRatio) {
68364
- var time = (ctime - timestamp) * 0.001;
68365
- return time * 10 * (memoryUsageRatio * memoryUsageRatio);
68366
- }
68367
-
68368
- if(DEBUG) console.log(root.opt);
68369
-
68370
- this.to.next(root);
68371
-
68372
- if (root.once)
68373
- return;
68374
- if (typeof process == 'undefined')
68375
- return
68376
- var mem = process.memoryUsage;
68377
-
68378
- if(!gc_enable) // exit because the gc is disabled
68379
- return;
68380
-
68381
- if (!mem) //exit because we are in the browser
68382
- return;
68383
-
68384
- var ev = {}; //stores the environment
68385
- var empty = {}; //An empty list used to prevent crashes
68386
-
68387
- //Figure out the most amount of memory we can use. TODO: make configurable?
68388
- ev.max = parseFloat(root.opt.memory || process.env.WEB_MEMORY || 512) * 0.8;
68389
-
68390
- var nodes = {}; //checks if the node already exists
68391
- var nodesArray = []; //used to easily sort everything and store info about the nodes
68392
- var memoryUpdate = 0; // last time we printed the current memory stats
68393
-
68394
- root.dequeueNode = (soul) => { //forward the call to our gc
68395
- dequeueNode(soul);
68396
- }
68397
-
68398
- root.collectNode = (soul) => { //forward the call to our gc
68399
- collectNode(soul);
68400
- }
68401
-
68402
- var check = function() {
68403
- ev.used = mem().rss / 1024 / 1024; //Contains the amt. of used ram in MB
68404
- setTimeout(function() { // So we can handle requests etc. before we start collecting
68405
- GC(ev.used / ev.max); // Calculate the memory ratio, and execute the garbage collector
68406
- //GC(0.99);
68407
- }, 1);
68408
- }
68409
-
68410
- setInterval(check, gc_delay); // set the garbage collector to run every second
68411
-
68412
- //Executed every time a node gets modified
68413
- root.on("put", function(e) {
68414
- this.to.next(e);
68415
- var ctime = Date.now();
68416
- var souls = Object.keys(e.put || empty); // get all of the nodes in the update
68417
- for (var i = 0; i < souls.length; i++) { // iterate over them and add them
68418
- enqueueNode(souls[i], ctime);
68419
- }
68420
- });
68421
-
68422
- //Adds a soul the garbage collectors "freeing" queue
68423
- function enqueueNode(soul, ctime) {
68424
- if (nodes[soul] == true) { //The node already exists in the queue
68425
- var index = nodesArray.findIndex(function(e) {
68426
- return e[0] === soul;
68427
- });
68428
- if (index == -1) {
68429
- console.error("Something happened and the node '" + soul + "' won't get garbage collection unless the value is updated again");
68430
- return;
68431
- } else {
68432
- nodesArray.splice(index, 1); // remove the existing ref. faster than dequeue
68433
- nodesArray.push([soul, ctime]); // push the new instance
68434
- }
68435
- } else {
68436
- nodesArray.push([soul, ctime]);
68437
- nodes[soul] = true;
68438
- }
68439
- }
68440
-
68441
- //Removes a node from the queue
68442
- function dequeueNode(soul) {
68443
- if (nodes[soul] == true) { //The node already exists in the queue
68444
- var index = nodesArray.findIndex(function(e) {
68445
- return e[0] === soul;
68446
- });
68447
- if (index != -1) {
68448
- //nodesArray.splice(index, 1); // remove the existing ref.
68449
- nodesArray.shift();
68450
- nodes[soul] = false; // store that we no longer have that node in the queue
68451
- }
68452
- }
68453
- }
68454
-
68455
- //Moves a node to the start of the queue
68456
- function collectNode(soul) {
68457
- if (nodes[soul] == true) { //The node already exists in the queue
68458
- var index = nodesArray.findIndex(function(e) {
68459
- return e[0] === soul;
68460
- });
68461
- if (index != -1) {
68462
- //nodesArray.splice(index, 1); // remove the existing ref.
68463
- nodesArray.shift(); // WAY faster than splice
68464
- }
68465
- nodesArray.unshift([soul, nodesArray[0][1]]); // create a new node with the next nodes time stamp
68466
- nodes[soul] = true; // store that we no longer have that node in the queue
68467
- }
68468
- }
68469
-
68470
- //The main garbage collecting routine
68471
- function GC(memRatio) {
68472
- var curTime = Date.now(); // get the current time
68473
-
68474
- if (gc_info_enable && curTime - memoryUpdate >= gc_info) { // check if we need to print info
68475
- if(!gc_info_mini)
68476
- console.log("|GC| %s | Current Memory Ratio: %d | Current Ram Usage %sMB | Nodes in Memory %s", new Date().toLocaleString(), round(memRatio, 2), round(ev.used, 2), Object.keys(root.graph || empty).length);
68477
- else
68478
- console.log("|GC| %s, Mem Ratio %d, Ram %sMB, Nodes in mem %s, Tracked Nodes %s", new Date().toLocaleString(), round(memRatio, 2), round(ev.used, 2), Object.keys(root.graph || empty).length, nodesArray.length);
68479
- memoryUpdate = curTime; // reset the last update time
68480
- }
68481
-
68482
- var freed = 0; // Just a nice performance counter
68483
-
68484
- while (nodesArray.length > 0) { // iterate over all of our nodes
68485
- var soul = nodesArray[0][0];
68486
- var nts = nodesArray[0][1];
68487
- if (DEBUG)
68488
- console.log("Soul: " + soul + " | Remove Importance: " + calcRemoveImportance(nts, curTime, memRatio) +
68489
- " | Memory Ratio: " + memRatio + " | Time Existed: " + (curTime - nts) / 1000);
68490
- if (calcRemoveImportance(nodesArray[0][1], curTime, memRatio) >= 100) {
68491
- root.gun.get(nodesArray[0][0]).off(); //Remove the node
68492
- delete nodes[nodesArray[0][0]]; // remove the lookup value
68493
- //nodesArray.splice(0, 1);
68494
- nodesArray.shift();
68495
- freed++; // add one to our perf counter
68496
- } else
68497
- break; // Break out of the loop because we don't have any more nodes to free
68498
- }
68499
- if (freed > 0)
68500
- console.log("|GC| Removed %s nodes in %s seconds-----------------------------------------------------------------", freed, (Date.now() - curTime) * 0.001);
68501
- }
68502
-
68503
- function round(value, decimals) { //a basic rounding function
68504
- return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
68505
- }
68506
- });
68507
- }());
68508
-
68509
-
68510
68275
  /***/ }),
68511
68276
 
68512
68277
  /***/ "./node_modules/gun/lib/radisk.js":
@@ -100299,7 +100064,6 @@ exports.Gun = Gun;
100299
100064
  const sea_1 = __importDefault(__webpack_require__(/*! gun/sea */ "./node_modules/gun/sea.js"));
100300
100065
  exports.SEA = sea_1.default;
100301
100066
  // Garbage Collection
100302
- __webpack_require__(/*! gun/lib/les.js */ "./node_modules/gun/lib/les.js");
100303
100067
  __webpack_require__(/*! gun/lib/then */ "./node_modules/gun/lib/then.js");
100304
100068
  __webpack_require__(/*! gun/lib/radix */ "./node_modules/gun/lib/radix.js");
100305
100069
  __webpack_require__(/*! gun/lib/radisk */ "./node_modules/gun/lib/radisk.js");
@@ -102451,7 +102215,7 @@ let gunModulesLoaded = false;
102451
102215
  /**
102452
102216
  * Loads Gun modules dynamically to avoid issues during testing
102453
102217
  */
102454
- async function loadGunModules() {
102218
+ async function loadGunModules(config) {
102455
102219
  if (gunModulesLoaded)
102456
102220
  return;
102457
102221
  try {
@@ -102468,11 +102232,16 @@ async function loadGunModules() {
102468
102232
  Gun = req("gun/gun");
102469
102233
  // Best-effort load of server-side helpers; ignore if unavailable
102470
102234
  const nodeOnlyLibs = [
102235
+ "gun/lib/les",
102471
102236
  "gun/lib/yson",
102472
102237
  "gun/lib/serve",
102473
102238
  "gun/lib/stats",
102474
102239
  "gun/lib/webrtc",
102475
102240
  ];
102241
+ // Only load evict if explicitly enabled
102242
+ if (config?.enableEviction) {
102243
+ nodeOnlyLibs.push("gun/lib/evict");
102244
+ }
102476
102245
  for (const lib of nodeOnlyLibs) {
102477
102246
  try {
102478
102247
  req(lib);
@@ -102506,6 +102275,7 @@ async function createNodeServer(config) {
102506
102275
  try {
102507
102276
  const http = await Promise.resolve().then(() => __importStar(__webpack_require__(/*! http */ "?b12c")));
102508
102277
  const server = http.createServer();
102278
+ Gun.serve(server);
102509
102279
  // Configure WebSocket server
102510
102280
  if (config.ws) {
102511
102281
  const ws = await Promise.resolve().then(() => __importStar(__webpack_require__(/*! ws */ "./node_modules/ws/browser.js")));
@@ -102513,6 +102283,20 @@ async function createNodeServer(config) {
102513
102283
  const wss = new WebSocketServer({ server });
102514
102284
  wss.on("connection", (ws) => {
102515
102285
  console.log("WebSocket connection established");
102286
+ ws.on("message", (message) => {
102287
+ // Broadcast message to all connected clients
102288
+ wss.clients.forEach((client) => {
102289
+ if (client !== ws && client.readyState === ws.OPEN) {
102290
+ client.send(message);
102291
+ }
102292
+ });
102293
+ });
102294
+ ws.on("close", () => {
102295
+ console.log("WebSocket connection closed");
102296
+ });
102297
+ ws.on("error", (error) => {
102298
+ console.error("WebSocket error:", error);
102299
+ });
102516
102300
  });
102517
102301
  }
102518
102302
  // Configure HTTP server
@@ -102574,7 +102358,7 @@ class Relay {
102574
102358
  async initializeGun() {
102575
102359
  try {
102576
102360
  // Load Gun modules when the class is instantiated
102577
- await loadGunModules();
102361
+ await loadGunModules(this.config);
102578
102362
  // In browser environment, create a minimal Gun instance
102579
102363
  if (!this._isNodeEnvironment) {
102580
102364
  this.gun = Gun({
@@ -102590,6 +102374,8 @@ class Relay {
102590
102374
  file: this.config.enableFileStorage ? "data" : false,
102591
102375
  web: this.server,
102592
102376
  multicast: false, // Disable multicast for relay servers
102377
+ radisk: this.config.enableFileStorage, // Enable radisk for persistence
102378
+ localStorage: false, // Disable localStorage in server environment
102593
102379
  ...this.config.gunOptions,
102594
102380
  });
102595
102381
  // Configure Gun options
@@ -102601,6 +102387,11 @@ class Relay {
102601
102387
  root.opt.faith = this.config.faith;
102602
102388
  }
102603
102389
  root.opt.log = root.opt.log || this.log;
102390
+ // Add standard relay configurations
102391
+ root.opt.gc_enable = true;
102392
+ root.opt.gc_info_enable = true;
102393
+ root.opt.wire = true;
102394
+ root.opt.axe = true;
102604
102395
  // Continue the chain
102605
102396
  if (root.to && root.to.next) {
102606
102397
  root.to.next(root);