@peerbit/stream 4.0.5-efee9d3 → 4.0.6-2bc15a6
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/README.md +11 -1
- package/dist/benchmark/transfer.js +12 -12
- package/dist/benchmark/transfer.js.map +1 -1
- package/dist/src/index.d.ts +14 -31
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +59 -70
- package/dist/src/index.js.map +1 -1
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/logger.js.map +1 -1
- package/dist/src/pushable-lanes.d.ts +1 -0
- package/dist/src/pushable-lanes.d.ts.map +1 -1
- package/dist/src/pushable-lanes.js +4 -4
- package/dist/src/pushable-lanes.js.map +1 -1
- package/dist/src/routes.d.ts.map +1 -1
- package/dist/src/routes.js +5 -2
- package/dist/src/routes.js.map +1 -1
- package/package.json +12 -11
- package/src/index.ts +219 -217
- package/src/logger.ts +1 -1
- package/src/pushable-lanes.ts +9 -8
- package/src/routes.ts +6 -4
package/src/logger.ts
CHANGED
package/src/pushable-lanes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import defer from "p-defer";
|
|
2
1
|
import GenericFIFO from "fast-fifo";
|
|
2
|
+
import defer from "p-defer";
|
|
3
3
|
|
|
4
4
|
export class AbortError extends Error {
|
|
5
5
|
type: string;
|
|
@@ -53,6 +53,7 @@ export interface PushableLanes<T, R = void, N = unknown>
|
|
|
53
53
|
/**
|
|
54
54
|
* Get readable length for specific lane
|
|
55
55
|
* @param lane
|
|
56
|
+
* @returns readable length for the lane
|
|
56
57
|
*/
|
|
57
58
|
getReadableLength(lane?: number): number;
|
|
58
59
|
}
|
|
@@ -156,20 +157,20 @@ class Uint8arrayPriorityQueue<T extends { byteLength: number }> {
|
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
export function pushableLanes<T extends { byteLength: number } = Uint8Array>(
|
|
159
|
-
options: Options = {}
|
|
160
|
+
options: Options = {},
|
|
160
161
|
): PushableLanes<T> {
|
|
161
162
|
return _pushable<Uint8Array, T, PushableLanes<T>>(options);
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
// Modified from https://github.com/alanshaw/it-pushable
|
|
165
166
|
function _pushable<PushType extends Uint8Array, ValueType, ReturnType>(
|
|
166
|
-
options?: Options
|
|
167
|
+
options?: Options,
|
|
167
168
|
): ReturnType {
|
|
168
169
|
options = options ?? {};
|
|
169
170
|
let onEnd = options.onEnd;
|
|
170
171
|
let buffer: Uint8arrayPriorityQueue<PushType> | Uint8ArrayFifo<PushType> =
|
|
171
172
|
new Uint8arrayPriorityQueue<PushType>(
|
|
172
|
-
options.lanes ? { lanes: options.lanes } : undefined
|
|
173
|
+
options.lanes ? { lanes: options.lanes } : undefined,
|
|
173
174
|
);
|
|
174
175
|
let pushable: any;
|
|
175
176
|
let onNext: ((next: Next<PushType>, lane: number) => ReturnType) | null;
|
|
@@ -190,7 +191,7 @@ function _pushable<PushType extends Uint8Array, ValueType, ReturnType>(
|
|
|
190
191
|
return {
|
|
191
192
|
done: next.done === true,
|
|
192
193
|
// @ts-expect-error if done is false, value will be present
|
|
193
|
-
value: next.value
|
|
194
|
+
value: next.value,
|
|
194
195
|
};
|
|
195
196
|
};
|
|
196
197
|
|
|
@@ -211,7 +212,7 @@ function _pushable<PushType extends Uint8Array, ValueType, ReturnType>(
|
|
|
211
212
|
|
|
212
213
|
try {
|
|
213
214
|
resolve(getNext());
|
|
214
|
-
} catch (err) {
|
|
215
|
+
} catch (err: any) {
|
|
215
216
|
reject(err);
|
|
216
217
|
}
|
|
217
218
|
|
|
@@ -326,7 +327,7 @@ function _pushable<PushType extends Uint8Array, ValueType, ReturnType>(
|
|
|
326
327
|
signal?.removeEventListener("abort", listener);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
|
-
}
|
|
330
|
+
},
|
|
330
331
|
};
|
|
331
332
|
|
|
332
333
|
if (onEnd == null) {
|
|
@@ -378,7 +379,7 @@ function _pushable<PushType extends Uint8Array, ValueType, ReturnType>(
|
|
|
378
379
|
},
|
|
379
380
|
onEmpty: (opts?: AbortOptions) => {
|
|
380
381
|
return _pushable.onEmpty(opts);
|
|
381
|
-
}
|
|
382
|
+
},
|
|
382
383
|
};
|
|
383
384
|
|
|
384
385
|
return pushable;
|
package/src/routes.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class Routes {
|
|
|
28
28
|
|
|
29
29
|
constructor(
|
|
30
30
|
readonly me: string,
|
|
31
|
-
options?: { routeMaxRetentionPeriod?: number; signal?: AbortSignal }
|
|
31
|
+
options?: { routeMaxRetentionPeriod?: number; signal?: AbortSignal },
|
|
32
32
|
) {
|
|
33
33
|
this.routeMaxRetentionPeriod =
|
|
34
34
|
options?.routeMaxRetentionPeriod ?? 10 * 1000;
|
|
@@ -72,7 +72,7 @@ export class Routes {
|
|
|
72
72
|
target: string,
|
|
73
73
|
distance: number,
|
|
74
74
|
session: number,
|
|
75
|
-
remoteSession: number
|
|
75
|
+
remoteSession: number,
|
|
76
76
|
): "new" | "updated" | "restart" {
|
|
77
77
|
let fromMap = this.routes.get(from);
|
|
78
78
|
if (!fromMap) {
|
|
@@ -230,6 +230,8 @@ export class Routes {
|
|
|
230
230
|
return false;
|
|
231
231
|
}
|
|
232
232
|
if (
|
|
233
|
+
// TODO why do we need this check?
|
|
234
|
+
// eslint-disable-next-line eqeqeq
|
|
233
235
|
routeInfo.remoteSession == undefined ||
|
|
234
236
|
remoteInfo.session === undefined
|
|
235
237
|
) {
|
|
@@ -350,7 +352,7 @@ export class Routes {
|
|
|
350
352
|
getFanout(
|
|
351
353
|
from: string,
|
|
352
354
|
tos: string[],
|
|
353
|
-
redundancy: number
|
|
355
|
+
redundancy: number,
|
|
354
356
|
): Map<string, Map<string, { to: string; timestamp: number }>> | undefined {
|
|
355
357
|
if (tos.length === 0) {
|
|
356
358
|
return undefined;
|
|
@@ -402,7 +404,7 @@ export class Routes {
|
|
|
402
404
|
) {
|
|
403
405
|
foundClosest = true;
|
|
404
406
|
|
|
405
|
-
if (distance
|
|
407
|
+
if (distance === -1) {
|
|
406
408
|
// remove 1 from the expected redunancy since we got a route with negative 1 distance
|
|
407
409
|
// if we do not do this, we would get 2 routes if redundancy = 1, {-1, 0}, while it should just be
|
|
408
410
|
// {-1} in this case
|