mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-05-18 13:29:37 +00:00
* initialise the new package * feat: implement LocalStorageDiscovery * add: Startable to cspell * add compliance test * add: discovery tests * rm: browser tests script * address comments * add type safety to getting peers from local * only dispatch peer if it does not exist * move ws ma extraction to utils * chore: update package name to local-discovery * fix: add compliance test with no external deps on service node * use peer:identify instead of peer:update * add: unit tests & remove sdk dependency * move tests to self package * update cspell + remove unrequired deps * add types * maintain in-memory peers for localstorage * address comments * chore: rename * use name from options * fix: saving peers * rm: only
30 lines
857 B
TypeScript
30 lines
857 B
TypeScript
import type { Multiaddr } from "@multiformats/multiaddr";
|
|
export * from "./is_defined.js";
|
|
export * from "./random_subset.js";
|
|
export * from "./group_by.js";
|
|
export * from "./to_async_iterator.js";
|
|
export * from "./is_size_valid.js";
|
|
export * from "./sharding.js";
|
|
export * from "./push_or_init_map.js";
|
|
export * from "./relay_shard_codec.js";
|
|
|
|
export function removeItemFromArray(arr: unknown[], value: unknown): unknown[] {
|
|
const index = arr.indexOf(value);
|
|
if (index > -1) {
|
|
arr.splice(index, 1);
|
|
}
|
|
return arr;
|
|
}
|
|
|
|
export function getWsMultiaddrFromMultiaddrs(
|
|
addresses: Multiaddr[]
|
|
): Multiaddr {
|
|
const wsMultiaddr = addresses.find(
|
|
(addr) => addr.toString().includes("ws") || addr.toString().includes("wss")
|
|
);
|
|
if (!wsMultiaddr) {
|
|
throw new Error("No ws multiaddr found in the given addresses");
|
|
}
|
|
return wsMultiaddr;
|
|
}
|