*Update dist

This commit is contained in:
Derrick Hammer 2022-12-19 08:44:54 -05:00
parent 67c098cb0d
commit fe99066220
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 25 additions and 9 deletions

5
dist/index.d.ts vendored
View File

@ -1,6 +1,8 @@
/// <reference types="node" />
/// <reference types="node" />
import EventEmitter from "events";
import DHTFlood from "@lumeweb/dht-flood";
import type { Logger } from "pino";
export default class DHTCache extends EventEmitter {
protected swarm: any;
private id;
@ -10,8 +12,9 @@ export default class DHTCache extends EventEmitter {
private heartBeatInterval;
protected flood: DHTFlood;
private log;
constructor(swarm: any, { id, heartBeatInterval, ...opts }?: {
constructor(swarm: any, { id, logger, heartBeatInterval, ...opts }?: {
id?: Buffer;
logger?: Logger;
[key: string]: any;
});
private _cache;

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAYlC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAc1C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAChD,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;IACrB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,iBAAiB,CAAS;IAElC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAa;gBAGtB,KAAK,EAAE,GAAG,EACV,EACE,EAA4B,EAC5B,iBAAsB,EACtB,GAAG,IAAI,EACR,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAO;IAuC7C,OAAO,CAAC,MAAM,CAAc;IAE5B,IAAW,KAAK,IAAI,MAAM,EAA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AC,MAAM,CAAC,CAE/B;IAEM,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM;IAIpC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG;IAInC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG;IAqClC,iBAAiB,CAAC,IAAI,EAAE,GAAG;IAa3B,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG;IAqBhC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAoGpD,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,uBAAuB;IAa/B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAmCtB,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,YAAY;IAgDpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IA4BtB,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,4BAA4B;IAKpC,OAAO,CAAC,qBAAqB;CAS9B"}

23
dist/index.js vendored
View File

@ -11,17 +11,28 @@ const hypercore_crypto_1 = __importDefault(require("hypercore-crypto"));
const b4a_1 = __importDefault(require("b4a"));
const messages_js_1 = require("./messages.js");
const dht_flood_1 = __importDefault(require("@lumeweb/dht-flood"));
const loglevel_1 = require("loglevel");
const EntityType = {
PUBKEY: Symbol.for("PUBKEY"),
ITEM: Symbol.for("ITEM"),
};
const DISCONNECT_SMOOTH = 500;
class DHTCache extends events_1.default {
constructor(swarm, { id = swarm.keyPair.publicKey, heartBeatInterval = 60, ...opts } = {}) {
swarm;
id;
bootstrapped;
graph;
connectedTo;
heartBeatInterval;
flood;
log;
constructor(swarm, { id = swarm.keyPair.publicKey, logger, heartBeatInterval = 60, ...opts } = {}) {
super();
if (!id)
if (!id) {
throw new TypeError("Must provide id for self");
}
if (!logger) {
throw new TypeError("Must logger for self");
}
this.id = b4a_1.default.from(id);
this.bootstrapped = false;
this.graph = new jsnetworkx_1.DiGraph();
@ -31,7 +42,7 @@ class DHTCache extends events_1.default {
this._online = new Set([this._maybeHexify(this.id)]);
this.swarm = swarm;
this.flood = new dht_flood_1.default({ id, swarm, ...opts });
this.log = loglevel_1.getLogger("dht-cache");
this.log = logger;
this.flood.on("peer-open", (peer) => this.addPeerHandler(peer));
this.flood.on("peer-remove", (peer) => this.removePeerHandler(peer));
this.flood.on("message", (message, id) => this.onGetBroadcast(message, id));
@ -48,6 +59,7 @@ class DHTCache extends events_1.default {
setInterval(() => this._heartbeatCheck(), (this.heartBeatInterval / 4) * 1000);
setInterval(() => this._emitHeartbeat(), this.heartBeatInterval * 1000);
}
_cache;
get cache() {
return [...this._cache].sort();
}
@ -110,6 +122,7 @@ class DHTCache extends events_1.default {
}
return true;
}
_online;
get online() {
return this._online;
}
@ -340,7 +353,7 @@ class DHTCache extends events_1.default {
if (item?.type !== EntityType.PUBKEY) {
continue;
}
if (jsnetworkx_1.hasPath(this.graph, {
if ((0, jsnetworkx_1.hasPath)(this.graph, {
source: this._maybeHexify(this.id),
target: id,
})) {

4
dist/messages.js vendored
View File

@ -59,7 +59,7 @@ class Message$Type extends runtime_5.MessageType {
const message = { type: 0, bootstrap: {} };
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
runtime_3.reflectionMergePartial(this, message, value);
(0, runtime_3.reflectionMergePartial)(this, message, value);
return message;
}
internalBinaryRead(reader, length, options, target) {
@ -150,7 +150,7 @@ class State$Type extends runtime_5.MessageType {
const message = { connectedTo: [] };
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this });
if (value !== undefined)
runtime_3.reflectionMergePartial(this, message, value);
(0, runtime_3.reflectionMergePartial)(this, message, value);
return message;
}
internalBinaryRead(reader, length, options, target) {