diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..e260b6b --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,17 @@ +import { ErrTuple } from "libskynet"; +import type { RPCRequest } from "@lumeweb/dht-rpc-client"; +export declare class RpcNetwork { + private _actionQueue; + get ready(): Promise; + addRelay(pubkey: string): void; + removeRelay(pubkey: string): void; + clearRelays(): void; + query(query: string, chain: string, data?: object | any[], force?: boolean): RpcQuery; + processQueue(): Promise; +} +export declare class RpcQuery { + private _promise; + constructor(network: RpcNetwork, query: RPCRequest); + get result(): Promise; +} +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map new file mode 100644 index 0000000..512732f --- /dev/null +++ b/dist/index.d.ts.map @@ -0,0 +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;AAe1D,qBAAa,UAAU;IACrB,OAAO,CAAC,YAAY,CAA2B;IAE/C,IAAI,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC,CAE7B;IAEM,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI9B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIjC,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;CAI3C;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"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..28ba42d --- /dev/null +++ b/dist/index.js @@ -0,0 +1,55 @@ +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 (window.document) { + callModule = callModuleKernel; + connectModule = connectModuleKernel; +} +else { + callModule = callModuleModule; + connectModule = connectModuleModule; +} +export class RpcNetwork { + _actionQueue = []; + get ready() { + return callModule(RPC_MODULE, "ready"); + } + addRelay(pubkey) { + this._actionQueue.push(callModule(RPC_MODULE, "addRelay", { pubkey })); + } + removeRelay(pubkey) { + this._actionQueue.push(callModule(RPC_MODULE, "removeRelay", { pubkey })); + } + clearRelays() { + this._actionQueue.push(callModule(RPC_MODULE, "clearRelays")); + } + query(query, chain, data = {}, force = false) { + return new RpcQuery(this, { + query, + chain, + data, + force: force, + }); + } + async processQueue() { + await Promise.allSettled(this._actionQueue); + this._actionQueue = []; + } +} +export class RpcQuery { + _promise; + constructor(network, query) { + this._promise = network + .processQueue() + .then(() => callModule(RPC_MODULE, "query", query)); + } + get result() { + return this._promise.then((result) => { + if (result[1]) { + throw new Error(result[1]); + } + return result[0]; + }); + } +}