feat: initial release
This commit is contained in:
parent
d2bd926275
commit
79f8d105c5
|
@ -0,0 +1,13 @@
|
||||||
|
name: Build/Publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- develop
|
||||||
|
- develop-*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
main:
|
||||||
|
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
|
||||||
|
secrets: inherit
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"preset": [
|
||||||
|
"@lumeweb/node-library-preset"
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
/// <reference types="node" />
|
|
||||||
export interface Peer {
|
|
||||||
host: string;
|
|
||||||
port: number;
|
|
||||||
}
|
|
||||||
export type PeerSource = (pubkey: Buffer, options?: any) => Promise<boolean | Peer>;
|
|
||||||
export declare class PeerDiscovery {
|
|
||||||
private _sources;
|
|
||||||
registerSource(name: string, source: PeerSource): boolean;
|
|
||||||
removeSource(name: string): boolean;
|
|
||||||
removeAllSources(): void;
|
|
||||||
sourceExists(name: string): boolean;
|
|
||||||
discover(pubkey: string | Buffer, options?: {}): Promise<Peer | boolean>;
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
"use strict";
|
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
exports.PeerDiscovery = void 0;
|
|
||||||
const b4a_1 = __importDefault(require("b4a"));
|
|
||||||
class PeerDiscovery {
|
|
||||||
_sources = new Map();
|
|
||||||
registerSource(name, source) {
|
|
||||||
if (this._sources.has(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this._sources.set(name, source);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
removeSource(name) {
|
|
||||||
if (!this._sources.has(name)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this._sources.delete(name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
removeAllSources() {
|
|
||||||
this._sources.clear();
|
|
||||||
}
|
|
||||||
sourceExists(name) {
|
|
||||||
return this._sources.has(name);
|
|
||||||
}
|
|
||||||
async discover(pubkey, options = {}) {
|
|
||||||
if (!b4a_1.default.isBuffer(pubkey)) {
|
|
||||||
pubkey = b4a_1.default.from(pubkey, "hex");
|
|
||||||
}
|
|
||||||
for (const source of this._sources.values()) {
|
|
||||||
const result = await source(pubkey, options);
|
|
||||||
if (result) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.PeerDiscovery = PeerDiscovery;
|
|
||||||
//# sourceMappingURL=index.js.map
|
|
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
|
@ -1,14 +1,24 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/peer-discovery",
|
"name": "@lumeweb/libpeerdiscovery",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"main": "dist/index.js",
|
"type": "module",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"types": "lib/index.d.ts",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/b4a": "^1.6.0",
|
"@lumeweb/node-library-preset": "^0.2.5",
|
||||||
"@types/node": "^18.11.17",
|
"presetter": "*"
|
||||||
"prettier": "^2.8.1",
|
},
|
||||||
"typescript": "^4.9.4"
|
"readme": "ERROR: No README data found!",
|
||||||
|
"_id": "@lumeweb/libpeerdiscovery@0.1.0",
|
||||||
|
"scripts": {
|
||||||
|
"prepare": "presetter bootstrap",
|
||||||
|
"build": "run build",
|
||||||
|
"semantic-release": "semantic-release"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"b4a": "^1.6.1"
|
"b4a": "^1.6.4"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
lockfileVersion: 5.4
|
|
||||||
|
|
||||||
specifiers:
|
|
||||||
'@types/b4a': ^1.6.0
|
|
||||||
'@types/node': ^18.11.17
|
|
||||||
b4a: ^1.6.1
|
|
||||||
prettier: ^2.8.1
|
|
||||||
typescript: ^4.9.4
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
b4a: 1.6.1
|
|
||||||
|
|
||||||
devDependencies:
|
|
||||||
'@types/b4a': 1.6.0
|
|
||||||
'@types/node': 18.11.18
|
|
||||||
prettier: 2.8.3
|
|
||||||
typescript: 4.9.4
|
|
||||||
|
|
||||||
packages:
|
|
||||||
|
|
||||||
/@types/b4a/1.6.0:
|
|
||||||
resolution: {integrity: sha512-rYU2r5nSUPyKyufWijxgTjsFp2kLCwydj2TmKU4StJeGPHS/Fs5KHgP89DNF0jddyeAbN5mdjNDqIrjIHca60g==}
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 18.11.18
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/@types/node/18.11.18:
|
|
||||||
resolution: {integrity: sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==}
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/b4a/1.6.1:
|
|
||||||
resolution: {integrity: sha512-AsKjNhz72yxteo/0EtQEiwkMUgk/tGmycXlbG4g3Ard2/ULtNLUykGOkeK0egmN27h0xMAhb76jYccW+XTBExA==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/prettier/2.8.3:
|
|
||||||
resolution: {integrity: sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw==}
|
|
||||||
engines: {node: '>=10.13.0'}
|
|
||||||
hasBin: true
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/typescript/4.9.4:
|
|
||||||
resolution: {integrity: sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==}
|
|
||||||
engines: {node: '>=4.2.0'}
|
|
||||||
hasBin: true
|
|
||||||
dev: true
|
|
|
@ -7,7 +7,7 @@ export interface Peer {
|
||||||
|
|
||||||
export type PeerSource = (
|
export type PeerSource = (
|
||||||
pubkey: Buffer,
|
pubkey: Buffer,
|
||||||
options?: any
|
options?: any,
|
||||||
) => Promise<boolean | Peer>;
|
) => Promise<boolean | Peer>;
|
||||||
|
|
||||||
export class PeerDiscovery {
|
export class PeerDiscovery {
|
||||||
|
@ -42,14 +42,14 @@ export class PeerDiscovery {
|
||||||
|
|
||||||
public async discover(
|
public async discover(
|
||||||
pubkey: string | Buffer,
|
pubkey: string | Buffer,
|
||||||
options = {}
|
options = {},
|
||||||
): Promise<Peer | boolean> {
|
): Promise<Peer | boolean> {
|
||||||
if (!b4a.isBuffer(pubkey)) {
|
if (!b4a.isBuffer(pubkey)) {
|
||||||
pubkey = b4a.from(pubkey, "hex") as Buffer;
|
pubkey = b4a.from(pubkey, "hex") as Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const source of this._sources.values()) {
|
for (const source of this._sources.values()) {
|
||||||
const result = await source(pubkey, options);
|
const result = await source(pubkey as Buffer, options);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "esnext",
|
|
||||||
"sourceMap": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"outDir": "dist",
|
|
||||||
"declaration": true
|
|
||||||
},
|
|
||||||
"include": ["src"],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules"
|
|
||||||
]
|
|
||||||
}
|
|
Loading…
Reference in New Issue