@peerbit/shared-log 9.2.13 → 10.0.0-05f4bef

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 (104) hide show
  1. package/dist/benchmark/get-samples.js +190 -64
  2. package/dist/benchmark/get-samples.js.map +1 -1
  3. package/dist/benchmark/index.js +16 -38
  4. package/dist/benchmark/index.js.map +1 -1
  5. package/dist/benchmark/memory/child.js.map +1 -1
  6. package/dist/benchmark/partial-sync.d.ts +3 -0
  7. package/dist/benchmark/partial-sync.d.ts.map +1 -0
  8. package/dist/benchmark/partial-sync.js +121 -0
  9. package/dist/benchmark/partial-sync.js.map +1 -0
  10. package/dist/benchmark/replication-prune.js.map +1 -1
  11. package/dist/benchmark/replication.js.map +1 -1
  12. package/dist/benchmark/to-rebalance.d.ts +2 -0
  13. package/dist/benchmark/to-rebalance.d.ts.map +1 -0
  14. package/dist/benchmark/to-rebalance.js +117 -0
  15. package/dist/benchmark/to-rebalance.js.map +1 -0
  16. package/dist/benchmark/utils.d.ts +24 -0
  17. package/dist/benchmark/utils.d.ts.map +1 -0
  18. package/dist/benchmark/utils.js +47 -0
  19. package/dist/benchmark/utils.js.map +1 -0
  20. package/dist/src/debounce.d.ts +2 -2
  21. package/dist/src/debounce.d.ts.map +1 -1
  22. package/dist/src/debounce.js +17 -47
  23. package/dist/src/debounce.js.map +1 -1
  24. package/dist/src/exchange-heads.d.ts +1 -13
  25. package/dist/src/exchange-heads.d.ts.map +1 -1
  26. package/dist/src/exchange-heads.js +0 -32
  27. package/dist/src/exchange-heads.js.map +1 -1
  28. package/dist/src/index.d.ts +119 -60
  29. package/dist/src/index.d.ts.map +1 -1
  30. package/dist/src/index.js +1116 -762
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/integers.d.ts +22 -0
  33. package/dist/src/integers.d.ts.map +1 -0
  34. package/dist/src/integers.js +76 -0
  35. package/dist/src/integers.js.map +1 -0
  36. package/dist/src/pid.d.ts.map +1 -1
  37. package/dist/src/pid.js +22 -22
  38. package/dist/src/pid.js.map +1 -1
  39. package/dist/src/ranges.d.ts +168 -38
  40. package/dist/src/ranges.d.ts.map +1 -1
  41. package/dist/src/ranges.js +869 -272
  42. package/dist/src/ranges.js.map +1 -1
  43. package/dist/src/replication-domain-hash.d.ts +2 -3
  44. package/dist/src/replication-domain-hash.d.ts.map +1 -1
  45. package/dist/src/replication-domain-hash.js +40 -15
  46. package/dist/src/replication-domain-hash.js.map +1 -1
  47. package/dist/src/replication-domain-time.d.ts +5 -5
  48. package/dist/src/replication-domain-time.d.ts.map +1 -1
  49. package/dist/src/replication-domain-time.js +2 -0
  50. package/dist/src/replication-domain-time.js.map +1 -1
  51. package/dist/src/replication-domain.d.ts +17 -19
  52. package/dist/src/replication-domain.d.ts.map +1 -1
  53. package/dist/src/replication-domain.js +2 -6
  54. package/dist/src/replication-domain.js.map +1 -1
  55. package/dist/src/replication.d.ts +6 -6
  56. package/dist/src/replication.d.ts.map +1 -1
  57. package/dist/src/replication.js +4 -4
  58. package/dist/src/replication.js.map +1 -1
  59. package/dist/src/role.d.ts +3 -6
  60. package/dist/src/role.d.ts.map +1 -1
  61. package/dist/src/role.js +4 -5
  62. package/dist/src/role.js.map +1 -1
  63. package/dist/src/sync/index.d.ts +40 -0
  64. package/dist/src/sync/index.d.ts.map +1 -0
  65. package/dist/src/sync/index.js +2 -0
  66. package/dist/src/sync/index.js.map +1 -0
  67. package/dist/src/sync/rateless-iblt.d.ts +124 -0
  68. package/dist/src/sync/rateless-iblt.d.ts.map +1 -0
  69. package/dist/src/sync/rateless-iblt.js +495 -0
  70. package/dist/src/sync/rateless-iblt.js.map +1 -0
  71. package/dist/src/sync/simple.d.ts +69 -0
  72. package/dist/src/sync/simple.d.ts.map +1 -0
  73. package/dist/src/sync/simple.js +338 -0
  74. package/dist/src/sync/simple.js.map +1 -0
  75. package/dist/src/sync/wasm-init.browser.d.ts +1 -0
  76. package/dist/src/sync/wasm-init.browser.d.ts.map +1 -0
  77. package/dist/src/sync/wasm-init.browser.js +3 -0
  78. package/dist/src/sync/wasm-init.browser.js.map +1 -0
  79. package/dist/src/sync/wasm-init.d.ts +2 -0
  80. package/dist/src/sync/wasm-init.d.ts.map +1 -0
  81. package/dist/src/sync/wasm-init.js +13 -0
  82. package/dist/src/sync/wasm-init.js.map +1 -0
  83. package/dist/src/utils.d.ts +3 -3
  84. package/dist/src/utils.d.ts.map +1 -1
  85. package/dist/src/utils.js +2 -2
  86. package/dist/src/utils.js.map +1 -1
  87. package/package.json +73 -69
  88. package/src/debounce.ts +16 -51
  89. package/src/exchange-heads.ts +1 -23
  90. package/src/index.ts +1532 -1038
  91. package/src/integers.ts +102 -0
  92. package/src/pid.ts +23 -22
  93. package/src/ranges.ts +1204 -413
  94. package/src/replication-domain-hash.ts +43 -18
  95. package/src/replication-domain-time.ts +9 -9
  96. package/src/replication-domain.ts +21 -31
  97. package/src/replication.ts +10 -9
  98. package/src/role.ts +4 -6
  99. package/src/sync/index.ts +51 -0
  100. package/src/sync/rateless-iblt.ts +617 -0
  101. package/src/sync/simple.ts +403 -0
  102. package/src/sync/wasm-init.browser.ts +1 -0
  103. package/src/sync/wasm-init.ts +14 -0
  104. package/src/utils.ts +10 -4
package/src/debounce.ts CHANGED
@@ -1,46 +1,3 @@
1
- /* export const debounceFixedInterval = <
2
- T extends (...args: any[]) => any | Promise<any>,
3
- >(
4
- fn: T,
5
- delay: number,
6
- options?: { debug?: boolean, onError?: (error: Error) => void },
7
- ) => {
8
- // a debounce function that will always wait for the delay to pass before invoking the function
9
- // though if delay time has passed it will call the function immediately instead of resetting the timer
10
-
11
- let onError = options?.onError || ((error: Error) => console.error(error));
12
- let timeout: NodeJS.Timeout | null = null;
13
- let lastArgs: any[] = [];
14
- let lastThis: any;
15
- let invokePromise = Promise.resolve();
16
- const invoke = async () => {
17
- const fnCall = fn.apply(lastThis, lastArgs);
18
- invokePromise = Promise.resolve(fnCall ?? {});
19
- await invokePromise.then((res) => {
20
-
21
- timeout = null;
22
- return res;
23
- }).catch(onError);
24
- };
25
-
26
- const debounced = (...args: Parameters<T>) => {
27
- lastArgs = args;
28
- lastThis = this;
29
- if (timeout) {
30
- return;
31
- }
32
- invokePromise.then(() => {
33
- timeout && clearTimeout(timeout);
34
- timeout = setTimeout(invoke, delay);
35
- if (options?.debug) {
36
- console.log("debounceFixedInterval: timeout set", timeout);
37
- }
38
- });
39
- };
40
-
41
- return debounced as T;
42
- };
43
- */
44
1
  export const debounceFixedInterval = <
45
2
  T extends (...args: any[]) => any | Promise<any>,
46
3
  >(
@@ -109,7 +66,7 @@ export const debounceFixedInterval = <
109
66
  return debounced as T;
110
67
  };
111
68
 
112
- export const debounceAcculmulator = <K, T, V>(
69
+ export const debounceAccumulator = <K, T, V>(
113
70
  fn: (args: V) => any,
114
71
  create: () => {
115
72
  delete: (string: K) => void;
@@ -145,18 +102,26 @@ export const debounceAcculmulator = <K, T, V>(
145
102
  export const debouncedAccumulatorMap = <T>(
146
103
  fn: (args: Map<string, T>) => any,
147
104
  delay: number,
105
+ merge?: (into: T, from: T) => void,
148
106
  ) => {
149
- return debounceAcculmulator<
150
- string,
151
- { key: string; value: T },
152
- Map<string, T>
153
- >(
107
+ return debounceAccumulator<string, { key: string; value: T }, Map<string, T>>(
154
108
  fn,
155
109
  () => {
156
110
  const map = new Map();
111
+ let add = merge
112
+ ? (props: { key: string; value: T }) => {
113
+ let prev = map.get(props.key);
114
+ if (prev != null) {
115
+ merge(prev, props.value);
116
+ } else {
117
+ map.set(props.key, props.value);
118
+ }
119
+ }
120
+ : (props: { key: string; value: T }) => {
121
+ map.set(props.key, props.value);
122
+ };
157
123
  return {
158
- add: (props: { key: string; value: T }) =>
159
- map.set(props.key, props.value),
124
+ add,
160
125
  delete: (key: string) => map.delete(key),
161
126
  size: () => map.size,
162
127
  value: map,
@@ -39,28 +39,6 @@ export class ExchangeHeadsMessage<T> extends TransportMessage {
39
39
  }
40
40
  }
41
41
 
42
- @variant([0, 1])
43
- export class RequestMaybeSync extends TransportMessage {
44
- @field({ type: vec("string") })
45
- hashes: string[];
46
-
47
- constructor(props: { hashes: string[] }) {
48
- super();
49
- this.hashes = props.hashes;
50
- }
51
- }
52
-
53
- @variant([0, 2])
54
- export class ResponseMaybeSync extends TransportMessage {
55
- @field({ type: vec("string") })
56
- hashes: string[];
57
-
58
- constructor(props: { hashes: string[] }) {
59
- super();
60
- this.hashes = props.hashes;
61
- }
62
- }
63
-
64
42
  @variant([0, 3])
65
43
  export class RequestIPrune extends TransportMessage {
66
44
  // Hashes which I want to prune
@@ -89,7 +67,7 @@ const MAX_EXCHANGE_MESSAGE_SIZE = 1e5; // 100kb. Too large size might not be fas
89
67
 
90
68
  export const createExchangeHeadsMessages = async function* (
91
69
  log: Log<any>,
92
- heads: Entry<any>[] | string[],
70
+ heads: Entry<any>[] | string[] | Set<string>,
93
71
  ): AsyncGenerator<ExchangeHeadsMessage<any>, void, void> {
94
72
  let size = 0;
95
73
  let current: EntryWithRefs<any>[] = [];