@peerbit/shared-log 11.0.0 → 11.0.1-f151ed4

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/src/index.ts CHANGED
@@ -46,7 +46,12 @@ import {
46
46
  SilentDelivery,
47
47
  type WithMode,
48
48
  } from "@peerbit/stream-interface";
49
- import { AbortError, waitFor } from "@peerbit/time";
49
+ import {
50
+ AbortError,
51
+ debounceAccumulator,
52
+ debounceFixedInterval,
53
+ waitFor,
54
+ } from "@peerbit/time";
50
55
  import pDefer, { type DeferredPromise } from "p-defer";
51
56
  import PQueue from "p-queue";
52
57
  import { concat } from "uint8arrays";
@@ -54,8 +59,6 @@ import { BlocksMessage } from "./blocks.js";
54
59
  import { type CPUUsage, CPUUsageIntervalLag } from "./cpu.js";
55
60
  import {
56
61
  type DebouncedAccumulatorMap,
57
- debounceAccumulator,
58
- debounceFixedInterval,
59
62
  debouncedAccumulatorMap,
60
63
  } from "./debounce.js";
61
64
  import {
@@ -988,7 +991,7 @@ export class SharedLog<
988
991
  }
989
992
 
990
993
  if (!isMe) {
991
- this.rebalanceParticipationDebounced?.();
994
+ this.rebalanceParticipationDebounced?.call();
992
995
  }
993
996
  }
994
997
 
@@ -1072,7 +1075,7 @@ export class SharedLog<
1072
1075
  );
1073
1076
 
1074
1077
  if (!from.equals(this.node.identity.publicKey)) {
1075
- this.rebalanceParticipationDebounced?.();
1078
+ this.rebalanceParticipationDebounced?.call();
1076
1079
  }
1077
1080
  }
1078
1081
 
@@ -1319,7 +1322,7 @@ export class SharedLog<
1319
1322
  }
1320
1323
 
1321
1324
  if (!from.equals(this.node.identity.publicKey)) {
1322
- this.rebalanceParticipationDebounced?.();
1325
+ this.rebalanceParticipationDebounced?.call();
1323
1326
  }
1324
1327
  }
1325
1328
  return diffs;
@@ -1524,7 +1527,7 @@ export class SharedLog<
1524
1527
  value: { entry: result.entry, leaders },
1525
1528
  });
1526
1529
  }
1527
- this.rebalanceParticipationDebounced?.();
1530
+ this.rebalanceParticipationDebounced?.call();
1528
1531
 
1529
1532
  return result;
1530
1533
  }
@@ -1634,7 +1637,7 @@ export class SharedLog<
1634
1637
  >(
1635
1638
  (change) =>
1636
1639
  this.onReplicationChange(change).then(() =>
1637
- this.rebalanceParticipationDebounced?.(),
1640
+ this.rebalanceParticipationDebounced?.call(),
1638
1641
  ),
1639
1642
  this.distributionDebounceTime,
1640
1643
  );
@@ -1704,6 +1707,7 @@ export class SharedLog<
1704
1707
  size: () => accumulator.size,
1705
1708
  clear: () => accumulator.clear(),
1706
1709
  value: accumulator,
1710
+ has: (hash: string) => accumulator.has(hash),
1707
1711
  };
1708
1712
  },
1709
1713
  PRUNE_DEBOUNCE_INTERVAL, // TODO make this dynamic on the number of replicators
@@ -1812,7 +1816,7 @@ export class SharedLog<
1812
1816
  await this.syncronizer.open();
1813
1817
 
1814
1818
  this.interval = setInterval(() => {
1815
- this.rebalanceParticipationDebounced?.();
1819
+ this.rebalanceParticipationDebounced?.call();
1816
1820
  }, RECALCULATE_PARTICIPATION_DEBOUNCE_INTERVAL);
1817
1821
  }
1818
1822
 
@@ -2271,7 +2275,7 @@ export class SharedLog<
2271
2275
  value: { entry: x, leaders: leaders as Map<string, any> },
2272
2276
  }),
2273
2277
  );
2274
- this.rebalanceParticipationDebounced?.();
2278
+ this.rebalanceParticipationDebounced?.call();
2275
2279
  }
2276
2280
 
2277
2281
  if (maybeDelete) {
@@ -3667,14 +3671,14 @@ export class SharedLog<
3667
3671
  async _onUnsubscription(evt: CustomEvent<UnsubcriptionEvent>) {
3668
3672
  logger.trace(
3669
3673
  `Peer disconnected '${evt.detail.from.hashcode()}' from '${JSON.stringify(
3670
- evt.detail.unsubscriptions.map((x) => x),
3674
+ evt.detail.topics.map((x) => x),
3671
3675
  )} '`,
3672
3676
  );
3673
3677
  this.latestReplicationInfoMessage.delete(evt.detail.from.hashcode());
3674
3678
 
3675
3679
  return this.handleSubscriptionChange(
3676
3680
  evt.detail.from,
3677
- evt.detail.unsubscriptions,
3681
+ evt.detail.topics,
3678
3682
  false,
3679
3683
  );
3680
3684
  }
@@ -3682,14 +3686,14 @@ export class SharedLog<
3682
3686
  async _onSubscription(evt: CustomEvent<SubscriptionEvent>) {
3683
3687
  logger.trace(
3684
3688
  `New peer '${evt.detail.from.hashcode()}' connected to '${JSON.stringify(
3685
- evt.detail.subscriptions.map((x) => x),
3689
+ evt.detail.topics.map((x) => x),
3686
3690
  )}'`,
3687
3691
  );
3688
3692
  this.remoteBlocks.onReachable(evt.detail.from);
3689
3693
 
3690
3694
  return this.handleSubscriptionChange(
3691
3695
  evt.detail.from,
3692
- evt.detail.subscriptions,
3696
+ evt.detail.topics,
3693
3697
  true,
3694
3698
  );
3695
3699
  }
@@ -3756,11 +3760,11 @@ export class SharedLog<
3756
3760
  });
3757
3761
 
3758
3762
  /* await this._updateRole(newRole, onRoleChange); */
3759
- this.rebalanceParticipationDebounced?.();
3763
+ this.rebalanceParticipationDebounced?.call();
3760
3764
 
3761
3765
  return true;
3762
3766
  } else {
3763
- this.rebalanceParticipationDebounced?.();
3767
+ this.rebalanceParticipationDebounced?.call();
3764
3768
  }
3765
3769
  return false;
3766
3770
  }
package/src/ranges.ts CHANGED
@@ -30,7 +30,7 @@ import {
30
30
  } from "@peerbit/indexer-interface";
31
31
  import { id } from "@peerbit/indexer-interface";
32
32
  import { Meta, ShallowMeta } from "@peerbit/log";
33
- import { debounceAccumulator } from "./debounce.js";
33
+ import { debounceAccumulator } from "@peerbit/time";
34
34
  import {
35
35
  MAX_U32,
36
36
  MAX_U64,
@@ -2498,6 +2498,7 @@ export const debounceAggregationChanges = <
2498
2498
  },
2499
2499
  size: () => aggregated.size,
2500
2500
  value: aggregated,
2501
+ has: (key: string) => aggregated.has(key),
2501
2502
  };
2502
2503
  },
2503
2504
  delay,