*Update dist
This commit is contained in:
parent
5345135b02
commit
1847eaaeac
|
@ -1,5 +1,8 @@
|
|||
/// <reference types="node" />
|
||||
import { ErrTuple } from "libskynet";
|
||||
import type { RPCRequest } from "@lumeweb/dht-rpc-client";
|
||||
import type { RPCRequest } from "@lumeweb/relay-types";
|
||||
import { RpcQueryOptions, StreamHandlerFunction, StreamingRpcQueryOptions } from "@lumeweb/dht-rpc-client";
|
||||
import { Buffer } from "buffer";
|
||||
export declare class RpcNetwork {
|
||||
private _actionQueue;
|
||||
private _addQueue;
|
||||
|
@ -9,12 +12,30 @@ export declare class RpcNetwork {
|
|||
removeRelay(pubkey: string): void;
|
||||
clearRelays(): void;
|
||||
private static deleteItem;
|
||||
query(query: string, chain: string, data?: object | any[], force?: boolean): RpcQuery;
|
||||
wisdomQuery(method: string, module: string, data?: object | any[], bypassCache?: boolean, options?: RpcQueryOptions): WisdomRpcQuery;
|
||||
streamingQuery(relay: Buffer | string, method: string, module: string, streamHandler: StreamHandlerFunction, data?: object | any[], options?: RpcQueryOptions): StreamingRpcQuery;
|
||||
simpleQuery(relay: Buffer | string, method: string, module: string, data?: object | any[], options?: RpcQueryOptions): SimpleRpcQuery;
|
||||
processQueue(): Promise<void>;
|
||||
}
|
||||
export declare class RpcQuery {
|
||||
private _promise;
|
||||
constructor(network: RpcNetwork, query: RPCRequest);
|
||||
export declare abstract class RpcQueryBase {
|
||||
protected _promise?: Promise<any>;
|
||||
protected _network: RpcNetwork;
|
||||
protected _query: RPCRequest;
|
||||
protected _options: RpcQueryOptions;
|
||||
protected _queryType: string;
|
||||
constructor(network: RpcNetwork, query: RPCRequest, options: RpcQueryOptions | undefined, queryType: string);
|
||||
run(): this;
|
||||
get result(): Promise<any>;
|
||||
}
|
||||
export declare class SimpleRpcQuery extends RpcQueryBase {
|
||||
constructor(network: RpcNetwork, relay: string | Buffer, query: RPCRequest, options: RpcQueryOptions);
|
||||
}
|
||||
export declare class StreamingRpcQuery extends RpcQueryBase {
|
||||
protected _options: StreamingRpcQueryOptions;
|
||||
constructor(network: RpcNetwork, relay: string | Buffer, query: RPCRequest, options: StreamingRpcQueryOptions);
|
||||
run(): this;
|
||||
}
|
||||
export declare class WisdomRpcQuery extends RpcQueryBase {
|
||||
constructor(network: RpcNetwork, query: RPCRequest, options?: RpcQueryOptions);
|
||||
}
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +1 @@
|
|||
{"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"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,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AC;IAC/B,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,eAAe,CAAC;IACpC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;gBAG3B,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,UAAU,EACjB,OAAO,6BAAsB,EAC7B,SAAS,EAAE,MAAM;IAQZ,GAAG,IAAI,IAAI;IAQlB,IAAI,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,CAOzB;CACF;AAED,qBAAa,cAAe,SAAQ,YAAY;gBAE5C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,eAAe;CAI3B;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,SAAS,CAAC,QAAQ,EAAE,wBAAwB,CAAC;gBAG3C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,wBAAwB;IAM5B,GAAG,IAAI,IAAI;CAcnB;AAED,qBAAa,cAAe,SAAQ,YAAY;gBAE5C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,eAAoB;CAIhC"}
|
|
@ -39,16 +39,26 @@ export class RpcNetwork {
|
|||
if (array.includes(item)) {
|
||||
let queue = new Set(array);
|
||||
queue.delete(item);
|
||||
array = [...queue];
|
||||
[].splice.apply(array, [0, array.length].concat([...queue]));
|
||||
}
|
||||
}
|
||||
query(query, chain, data = {}, force = false) {
|
||||
return new RpcQuery(this, {
|
||||
query,
|
||||
chain,
|
||||
wisdomQuery(method, module, data = {}, bypassCache = false, options = {}) {
|
||||
return new WisdomRpcQuery(this, {
|
||||
method,
|
||||
module,
|
||||
data,
|
||||
force: force,
|
||||
});
|
||||
bypassCache,
|
||||
}, options).run();
|
||||
}
|
||||
streamingQuery(relay, method, module, streamHandler, data = {}, options = {}) {
|
||||
return new StreamingRpcQuery(this, relay, { method, module, data }, { streamHandler, ...options }).run();
|
||||
}
|
||||
simpleQuery(relay, method, module, data = {}, options = {}) {
|
||||
return new SimpleRpcQuery(this, relay, {
|
||||
method,
|
||||
module,
|
||||
data,
|
||||
}, options).run();
|
||||
}
|
||||
async processQueue() {
|
||||
await loadLibs();
|
||||
|
@ -65,12 +75,23 @@ export class RpcNetwork {
|
|||
this._addQueue = [];
|
||||
}
|
||||
}
|
||||
export class RpcQuery {
|
||||
export class RpcQueryBase {
|
||||
_promise;
|
||||
constructor(network, query) {
|
||||
this._promise = network
|
||||
_network;
|
||||
_query;
|
||||
_options;
|
||||
_queryType;
|
||||
constructor(network, query, options = {}, queryType) {
|
||||
this._network = network;
|
||||
this._query = query;
|
||||
this._options = options;
|
||||
this._queryType = queryType;
|
||||
}
|
||||
run() {
|
||||
this._promise = this._network
|
||||
.processQueue()
|
||||
.then(() => callModule(RPC_MODULE, "query", query));
|
||||
.then(() => callModule(RPC_MODULE, this._queryType, this._query));
|
||||
return this;
|
||||
}
|
||||
get result() {
|
||||
return this._promise.then((result) => {
|
||||
|
@ -81,3 +102,26 @@ export class RpcQuery {
|
|||
});
|
||||
}
|
||||
}
|
||||
export class SimpleRpcQuery extends RpcQueryBase {
|
||||
constructor(network, relay, query, options) {
|
||||
super(network, query, options, "simpleQuery");
|
||||
}
|
||||
}
|
||||
export class StreamingRpcQuery extends RpcQueryBase {
|
||||
_options;
|
||||
constructor(network, relay, query, options) {
|
||||
super(network, query, options, "streamingQuery");
|
||||
this._options = options;
|
||||
}
|
||||
run() {
|
||||
this._promise = this._network
|
||||
.processQueue()
|
||||
.then(() => connectModule(RPC_MODULE, this._queryType, this._query, this._options.streamHandler));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
export class WisdomRpcQuery extends RpcQueryBase {
|
||||
constructor(network, query, options = {}) {
|
||||
super(network, query, options, "wisdomQuery");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue