*Update dist
This commit is contained in:
parent
9d04fa3933
commit
f2ed076a47
|
@ -11,11 +11,15 @@ export declare class RpcNetwork {
|
||||||
private _actionQueue;
|
private _actionQueue;
|
||||||
private _addQueue;
|
private _addQueue;
|
||||||
private _removeQueue;
|
private _removeQueue;
|
||||||
|
private _def;
|
||||||
|
constructor(def?: boolean);
|
||||||
|
private _networkId;
|
||||||
|
get networkId(): number;
|
||||||
get ready(): Promise<ErrTuple>;
|
get ready(): Promise<ErrTuple>;
|
||||||
|
private static deleteItem;
|
||||||
addRelay(pubkey: string): void;
|
addRelay(pubkey: string): void;
|
||||||
removeRelay(pubkey: string): void;
|
removeRelay(pubkey: string): void;
|
||||||
clearRelays(): void;
|
clearRelays(): void;
|
||||||
private static deleteItem;
|
|
||||||
wisdomQuery(
|
wisdomQuery(
|
||||||
method: string,
|
method: string,
|
||||||
module: string,
|
module: string,
|
||||||
|
@ -52,8 +56,8 @@ export declare abstract class RpcQueryBase {
|
||||||
options: RpcQueryOptions | undefined,
|
options: RpcQueryOptions | undefined,
|
||||||
queryType: string
|
queryType: string
|
||||||
);
|
);
|
||||||
run(): this;
|
|
||||||
get result(): Promise<RPCResponse>;
|
get result(): Promise<RPCResponse>;
|
||||||
|
run(): this;
|
||||||
}
|
}
|
||||||
export declare class SimpleRpcQuery extends RpcQueryBase {
|
export declare class SimpleRpcQuery extends RpcQueryBase {
|
||||||
constructor(
|
constructor(
|
||||||
|
|
|
@ -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,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAsBhC,qBAAa,U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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;CAgBnB;AAED,qBAAa,cAAe,SAAQ,YAAY;gBAE5C,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE,eAAoB;CAIhC"}
|
|
@ -19,8 +19,32 @@ export class RpcNetwork {
|
||||||
_actionQueue = [];
|
_actionQueue = [];
|
||||||
_addQueue = [];
|
_addQueue = [];
|
||||||
_removeQueue = [];
|
_removeQueue = [];
|
||||||
|
_def;
|
||||||
|
constructor(def = true) {
|
||||||
|
this._def = def;
|
||||||
|
}
|
||||||
|
_networkId = 0;
|
||||||
|
get networkId() {
|
||||||
|
return this._networkId;
|
||||||
|
}
|
||||||
get ready() {
|
get ready() {
|
||||||
return loadLibs().then(() => callModule(RPC_MODULE, "ready"));
|
let promise = loadLibs();
|
||||||
|
if (this._def) {
|
||||||
|
this._networkId = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
promise = promise
|
||||||
|
.then(() => callModule(RPC_MODULE, "createNetwork"))
|
||||||
|
.then((ret) => (this._networkId = ret[0]));
|
||||||
|
}
|
||||||
|
return promise.then(() => callModule(RPC_MODULE, "ready", { network: this._networkId }));
|
||||||
|
}
|
||||||
|
static deleteItem(array, item) {
|
||||||
|
if (array.includes(item)) {
|
||||||
|
let queue = new Set(array);
|
||||||
|
queue.delete(item);
|
||||||
|
[].splice.apply(array, [0, array.length].concat([...queue]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addRelay(pubkey) {
|
addRelay(pubkey) {
|
||||||
this._addQueue.push(pubkey);
|
this._addQueue.push(pubkey);
|
||||||
|
@ -35,13 +59,6 @@ export class RpcNetwork {
|
||||||
clearRelays() {
|
clearRelays() {
|
||||||
this._actionQueue.push(["clearRelays", {}]);
|
this._actionQueue.push(["clearRelays", {}]);
|
||||||
}
|
}
|
||||||
static deleteItem(array, item) {
|
|
||||||
if (array.includes(item)) {
|
|
||||||
let queue = new Set(array);
|
|
||||||
queue.delete(item);
|
|
||||||
[].splice.apply(array, [0, array.length].concat([...queue]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wisdomQuery(method, module, data = {}, bypassCache = false, options = {}) {
|
wisdomQuery(method, module, data = {}, bypassCache = false, options = {}) {
|
||||||
return new WisdomRpcQuery(this, {
|
return new WisdomRpcQuery(this, {
|
||||||
method,
|
method,
|
||||||
|
@ -64,12 +81,21 @@ export class RpcNetwork {
|
||||||
await loadLibs();
|
await loadLibs();
|
||||||
for (const action of this._actionQueue) {
|
for (const action of this._actionQueue) {
|
||||||
try {
|
try {
|
||||||
await callModule(RPC_MODULE, action[0], action[1]);
|
await callModule(RPC_MODULE, action[0], {
|
||||||
|
...action[1],
|
||||||
|
network: this._networkId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (e) { }
|
catch (e) { }
|
||||||
}
|
}
|
||||||
await Promise.allSettled(this._removeQueue.map((item) => callModule(RPC_MODULE, "removeRelay", { pubkey: item })));
|
await Promise.allSettled(this._removeQueue.map((item) => callModule(RPC_MODULE, "removeRelay", {
|
||||||
await Promise.allSettled(this._addQueue.map((item) => callModule(RPC_MODULE, "addRelay", { pubkey: item })));
|
pubkey: item,
|
||||||
|
network: this._networkId,
|
||||||
|
})));
|
||||||
|
await Promise.allSettled(this._addQueue.map((item) => callModule(RPC_MODULE, "addRelay", {
|
||||||
|
pubkey: item,
|
||||||
|
network: this._networkId,
|
||||||
|
})));
|
||||||
this._actionQueue = [];
|
this._actionQueue = [];
|
||||||
this._removeQueue = [];
|
this._removeQueue = [];
|
||||||
this._addQueue = [];
|
this._addQueue = [];
|
||||||
|
@ -87,13 +113,6 @@ export class RpcQueryBase {
|
||||||
this._options = options;
|
this._options = options;
|
||||||
this._queryType = queryType;
|
this._queryType = queryType;
|
||||||
}
|
}
|
||||||
run() {
|
|
||||||
this._promise = this._network.processQueue().then(() => callModule(RPC_MODULE, this._queryType, {
|
|
||||||
query: this._query,
|
|
||||||
options: this._options,
|
|
||||||
}));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
get result() {
|
get result() {
|
||||||
return this._promise.then((result) => {
|
return this._promise.then((result) => {
|
||||||
if (result[1]) {
|
if (result[1]) {
|
||||||
|
@ -102,6 +121,14 @@ export class RpcQueryBase {
|
||||||
return result[0];
|
return result[0];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
run() {
|
||||||
|
this._promise = this._network.processQueue().then(() => callModule(RPC_MODULE, this._queryType, {
|
||||||
|
query: this._query,
|
||||||
|
options: this._options,
|
||||||
|
network: this._network.networkId,
|
||||||
|
}));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export class SimpleRpcQuery extends RpcQueryBase {
|
export class SimpleRpcQuery extends RpcQueryBase {
|
||||||
constructor(network, relay, query, options) {
|
constructor(network, relay, query, options) {
|
||||||
|
@ -118,6 +145,7 @@ export class StreamingRpcQuery extends RpcQueryBase {
|
||||||
this._promise = this._network.processQueue().then(() => connectModule(RPC_MODULE, this._queryType, {
|
this._promise = this._network.processQueue().then(() => connectModule(RPC_MODULE, this._queryType, {
|
||||||
query: this._query,
|
query: this._query,
|
||||||
options: this._options,
|
options: this._options,
|
||||||
|
network: this._network.networkId,
|
||||||
}, this._options.streamHandler));
|
}, this._options.streamHandler));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue