@glimt/record 0.0.29 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/record.cjs CHANGED
@@ -9306,6 +9306,34 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
9306
9306
  NodeType2[NodeType2["Comment"] = 5] = "Comment";
9307
9307
  return NodeType2;
9308
9308
  })(NodeType || {});
9309
+ class StormSnapshotManager {
9310
+ constructor() {
9311
+ __publicField(this, "fullSnapshotTaker", null);
9312
+ __publicField(this, "lastFullSnapshot", -1);
9313
+ __publicField(this, "intervalBetweenSnapshots", 150);
9314
+ }
9315
+ bindFullSnapshotTaker(takeFullSnapshot2) {
9316
+ this.fullSnapshotTaker = takeFullSnapshot2;
9317
+ }
9318
+ requestFullSnapshot(bufferId) {
9319
+ if (!this.fullSnapshotTaker) {
9320
+ console.log(
9321
+ "requestFullSnapshot: no full snapshot taker",
9322
+ "bufferId:",
9323
+ bufferId
9324
+ );
9325
+ return;
9326
+ }
9327
+ if (Date.now() - this.lastFullSnapshot < this.intervalBetweenSnapshots) {
9328
+ console.log("requestFullSnapshot: too soon", "bufferId:", bufferId);
9329
+ return;
9330
+ }
9331
+ console.log("taking full snapshot", "bufferId:", bufferId);
9332
+ this.fullSnapshotTaker();
9333
+ this.lastFullSnapshot = Date.now();
9334
+ }
9335
+ }
9336
+ const stormSnapshotManager = new StormSnapshotManager();
9309
9337
  function isNodeInLinkedList(n2) {
9310
9338
  return "__ln" in n2;
9311
9339
  }
@@ -9387,6 +9415,15 @@ class DoubleLinkedList {
9387
9415
  }
9388
9416
  }
9389
9417
  const moveKey = (id, parentId) => `${id}@${parentId}`;
9418
+ function makeid(length = 8) {
9419
+ var result2 = "";
9420
+ var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9421
+ var charactersLength = characters.length;
9422
+ for (var i2 = 0; i2 < length; i2++) {
9423
+ result2 += characters.charAt(Math.floor(Math.random() * charactersLength));
9424
+ }
9425
+ return result2;
9426
+ }
9390
9427
  class MutationBuffer {
9391
9428
  constructor() {
9392
9429
  __publicField(this, "frozen", false);
@@ -9423,6 +9460,7 @@ class MutationBuffer {
9423
9460
  __publicField(this, "canvasManager");
9424
9461
  __publicField(this, "processedNodeManager");
9425
9462
  __publicField(this, "unattachedDoc");
9463
+ __publicField(this, "bufId", makeid());
9426
9464
  __publicField(this, "stormBatches", []);
9427
9465
  __publicField(this, "stormInfo");
9428
9466
  __publicField(this, "stormSettings", {
@@ -9433,7 +9471,11 @@ class MutationBuffer {
9433
9471
  __publicField(this, "handleStormMutations", (muts) => {
9434
9472
  const time = Date.now();
9435
9473
  if (this.stormInfo == null) {
9436
- console.log("detected probable mutation storm start");
9474
+ console.log(
9475
+ "detected probable mutation storm start",
9476
+ "buffer id:",
9477
+ this.bufId
9478
+ );
9437
9479
  this.stormInfo = {
9438
9480
  startedAt: time,
9439
9481
  totalMutations: 0,
@@ -9442,7 +9484,12 @@ class MutationBuffer {
9442
9484
  };
9443
9485
  }
9444
9486
  this.stormInfo.totalMutations += muts.length;
9445
- console.log("current storm mutations", this.stormInfo.totalMutations);
9487
+ console.log(
9488
+ "current storm mutations",
9489
+ this.stormInfo.totalMutations,
9490
+ "buffer id:",
9491
+ this.bufId
9492
+ );
9446
9493
  if (this.stormInfo.totalMutations >= this.stormSettings.mutationLimit) {
9447
9494
  this.stormInfo.stormExceededLimit = true;
9448
9495
  this.stormBatches = [];
@@ -9468,7 +9515,9 @@ class MutationBuffer {
9468
9515
  stormExceededLimit,
9469
9516
  "storm duration:",
9470
9517
  Date.now() - this.stormInfo.startedAt,
9471
- "ms"
9518
+ "ms",
9519
+ "buffer id:",
9520
+ this.bufId
9472
9521
  );
9473
9522
  clearTimeout(this.stormInfo.timeout);
9474
9523
  this.stormInfo = null;
@@ -9481,7 +9530,7 @@ class MutationBuffer {
9481
9530
  this.processInternalMutations(muts, true);
9482
9531
  } else {
9483
9532
  this.stormBatches = [];
9484
- takeFullSnapshot();
9533
+ stormSnapshotManager.requestFullSnapshot(this.bufId);
9485
9534
  }
9486
9535
  });
9487
9536
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
@@ -9499,7 +9548,9 @@ class MutationBuffer {
9499
9548
  performance.now() - start,
9500
9549
  "ms",
9501
9550
  "overrideStorm",
9502
- overrideStorm
9551
+ overrideStorm,
9552
+ "buffer id:",
9553
+ this.bufId
9503
9554
  );
9504
9555
  this.emit();
9505
9556
  });
@@ -12624,6 +12675,7 @@ record.takeFullSnapshot = (isCheckout) => {
12624
12675
  }
12625
12676
  takeFullSnapshot$1(isCheckout);
12626
12677
  };
12678
+ stormSnapshotManager.bindFullSnapshotTaker(takeFullSnapshot$1);
12627
12679
  record.mirror = mirror;
12628
12680
  var n;
12629
12681
  !function(t2) {