*Update dist

This commit is contained in:
Derrick Hammer 2022-07-21 00:58:47 -04:00
parent 663f565c8d
commit 14f3770bf7
3 changed files with 42 additions and 17 deletions

3
dist/index.d.ts vendored
View File

@ -2,10 +2,13 @@ import { ErrTuple } from "libskynet";
import type { RPCRequest } from "@lumeweb/dht-rpc-client"; import type { RPCRequest } from "@lumeweb/dht-rpc-client";
export declare class RpcNetwork { export declare class RpcNetwork {
private _actionQueue; private _actionQueue;
private _addQueue;
private _removeQueue;
get ready(): Promise<ErrTuple>; get ready(): Promise<ErrTuple>;
addRelay(pubkey: string): void; addRelay(pubkey: string): void;
removeRelay(pubkey: string): void; removeRelay(pubkey: string): void;
clearRelays(): void; clearRelays(): void;
private static deleteItem;
query(query: string, chain: string, data?: object | any[], force?: boolean): RpcQuery; query(query: string, chain: string, data?: object | any[], force?: boolean): RpcQuery;
processQueue(): Promise<void>; processQueue(): Promise<void>;
} }

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

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAiB1D,qBAAa,UAAU;IACrB,OAAO,CAAC,YAAY,CAAmB;IAEvC,IAAI,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE7B;IAEM,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM9B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAMjC,WAAW,IAAI,IAAI;IAInB,KAAK,CACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,MAAM,GAAG,GAAG,EAAO,EACzB,KAAK,GAAE,OAAe,GACrB,QAAQ;IASE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAU3C;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;gBAEnB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAMlD,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAOzB;CACF"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAwB1D,qBAAa,UAAU;IACrB,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,YAAY,CAAgB;IAEpC,IAAI,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE7B;IAEM,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM9B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAMjC,WAAW,IAAI,IAAI;IAI1B,OAAO,CAAC,MAAM,CAAC,UAAU;IAQlB,KAAK,CACV,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,MAAM,GAAG,GAAG,EAAO,EACzB,KAAK,GAAE,OAAe,GACrB,QAAQ;IASE,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB3C;AAED,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAe;gBAEnB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU;IAMlD,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAOzB;CACF"}

54
dist/index.js vendored
View File

@ -1,28 +1,46 @@
import { callModule as callModuleKernel, connectModule as connectModuleKernel, } from "libkernel";
import { callModule as callModuleModule, connectModule as connectModuleModule, } from "libkmodule";
const RPC_MODULE = "AQDaEPIo_lpdvz7AKbeafERBHR331RiyvweJ6OrFTplzyg"; const RPC_MODULE = "AQDaEPIo_lpdvz7AKbeafERBHR331RiyvweJ6OrFTplzyg";
let callModule, connectModule; let callModule, connectModule;
if (typeof window !== "undefined" && window?.document) { async function loadLibs() {
callModule = callModuleKernel; if (callModule && connectModule) {
connectModule = connectModuleKernel; return;
} }
else { if (typeof window !== "undefined" && window?.document) {
callModule = callModuleModule; const pkg = await import("libkernel");
connectModule = connectModuleModule; callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
else {
const pkg = await import("libkmodule");
callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
} }
export class RpcNetwork { export class RpcNetwork {
_actionQueue = []; _actionQueue = [];
_addQueue = [];
_removeQueue = [];
get ready() { get ready() {
return callModule(RPC_MODULE, "ready"); return loadLibs().then(() => callModule(RPC_MODULE, "ready"));
} }
addRelay(pubkey) { addRelay(pubkey) {
this._actionQueue.push(() => callModule(RPC_MODULE, "addRelay", { pubkey })); this._addQueue.push(pubkey);
this._addQueue = [...new Set(this._addQueue)];
RpcNetwork.deleteItem(this._removeQueue, pubkey);
} }
removeRelay(pubkey) { removeRelay(pubkey) {
this._actionQueue.push(() => callModule(RPC_MODULE, "removeRelay", { pubkey })); this._removeQueue.push(pubkey);
this._removeQueue = [...new Set(this._removeQueue)];
RpcNetwork.deleteItem(this._addQueue, pubkey);
} }
clearRelays() { clearRelays() {
this._actionQueue.push(() => callModule(RPC_MODULE, "clearRelays")); this._actionQueue.push(["clearRelays", {}]);
}
static deleteItem(array, item) {
if (array.includes(item)) {
let queue = new Set(array);
queue.delete(item);
array = [...queue];
}
} }
query(query, chain, data = {}, force = false) { query(query, chain, data = {}, force = false) {
return new RpcQuery(this, { return new RpcQuery(this, {
@ -33,14 +51,18 @@ export class RpcNetwork {
}); });
} }
async processQueue() { async processQueue() {
for (const promise of this._actionQueue) { await loadLibs();
for (const action of this._actionQueue) {
try { try {
const p = promise(); await callModule(RPC_MODULE, action[0], action[1]);
await p;
} }
catch (e) { } catch (e) { }
} }
await Promise.allSettled(this._removeQueue.map((item) => callModule(RPC_MODULE, "removeRelay", { pubkey: item })));
await Promise.allSettled(this._addQueue.map((item) => callModule(RPC_MODULE, "addRelay", { pubkey: item })));
this._actionQueue = []; this._actionQueue = [];
this._removeQueue = [];
this._addQueue = [];
} }
} }
export class RpcQuery { export class RpcQuery {