*Update dist
This commit is contained in:
parent
663f565c8d
commit
14f3770bf7
|
@ -2,10 +2,13 @@ import { ErrTuple } from "libskynet";
|
|||
import type { RPCRequest } from "@lumeweb/dht-rpc-client";
|
||||
export declare class RpcNetwork {
|
||||
private _actionQueue;
|
||||
private _addQueue;
|
||||
private _removeQueue;
|
||||
get ready(): Promise<ErrTuple>;
|
||||
addRelay(pubkey: string): void;
|
||||
removeRelay(pubkey: string): void;
|
||||
clearRelays(): void;
|
||||
private static deleteItem;
|
||||
query(query: string, chain: string, data?: object | any[], force?: boolean): RpcQuery;
|
||||
processQueue(): Promise<void>;
|
||||
}
|
||||
|
|
|
@ -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"}
|
|
@ -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";
|
||||
let callModule, connectModule;
|
||||
if (typeof window !== "undefined" && window?.document) {
|
||||
callModule = callModuleKernel;
|
||||
connectModule = connectModuleKernel;
|
||||
}
|
||||
else {
|
||||
callModule = callModuleModule;
|
||||
connectModule = connectModuleModule;
|
||||
async function loadLibs() {
|
||||
if (callModule && connectModule) {
|
||||
return;
|
||||
}
|
||||
if (typeof window !== "undefined" && window?.document) {
|
||||
const pkg = await import("libkernel");
|
||||
callModule = pkg.callModule;
|
||||
connectModule = pkg.connectModule;
|
||||
}
|
||||
else {
|
||||
const pkg = await import("libkmodule");
|
||||
callModule = pkg.callModule;
|
||||
connectModule = pkg.connectModule;
|
||||
}
|
||||
}
|
||||
export class RpcNetwork {
|
||||
_actionQueue = [];
|
||||
_addQueue = [];
|
||||
_removeQueue = [];
|
||||
get ready() {
|
||||
return callModule(RPC_MODULE, "ready");
|
||||
return loadLibs().then(() => callModule(RPC_MODULE, "ready"));
|
||||
}
|
||||
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) {
|
||||
this._actionQueue.push(() => callModule(RPC_MODULE, "removeRelay", { pubkey }));
|
||||
this._removeQueue.push(pubkey);
|
||||
this._removeQueue = [...new Set(this._removeQueue)];
|
||||
RpcNetwork.deleteItem(this._addQueue, pubkey);
|
||||
}
|
||||
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) {
|
||||
return new RpcQuery(this, {
|
||||
|
@ -33,14 +51,18 @@ export class RpcNetwork {
|
|||
});
|
||||
}
|
||||
async processQueue() {
|
||||
for (const promise of this._actionQueue) {
|
||||
await loadLibs();
|
||||
for (const action of this._actionQueue) {
|
||||
try {
|
||||
const p = promise();
|
||||
await p;
|
||||
await callModule(RPC_MODULE, action[0], action[1]);
|
||||
}
|
||||
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._removeQueue = [];
|
||||
this._addQueue = [];
|
||||
}
|
||||
}
|
||||
export class RpcQuery {
|
||||
|
|
Loading…
Reference in New Issue