Compare commits

..

3 Commits

6 changed files with 19 additions and 12 deletions

View File

@ -42,7 +42,7 @@ export default class SimpleRpcQuery extends RpcQueryBase {
}
this._relay = socket;
await socket.opened;
const rpc = setupStream(socket);
const rpc = await setupStream(socket);
if (this._query.bypassCache) {
delete this._query.bypassCache;
await this.queryRpc(rpc, {

2
dist/util.d.ts vendored
View File

@ -14,6 +14,6 @@ export declare function validateTimestampedResponse(
): boolean;
export declare function hashQuery(query: RPCRequest): string;
export declare function createHash(data: string): Buffer;
export declare function setupStream(stream: any): any;
export declare function setupStream(stream: any): Promise<any>;
export declare function maybeGetAsyncProperty(object: any): Promise<any>;
//# sourceMappingURL=util.d.ts.map

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

@ -1 +1 @@
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOxE,eAAO,MAAM,mBAAmB,eAAwB,CAAC;AAEzD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,WAM1C;AAKD,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,GAAQ,GAAG,GAAG,EAAE,CA0C1D;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,WAAW,EACrB,WAAW,UAAQ,GAClB,OAAO,CAkBT;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,WAAW,GACpB,OAAO,CAET;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAUnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,GAAG,OAStC;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,GAAG,gBAUtD"}
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOxE,eAAO,MAAM,mBAAmB,eAAwB,CAAC;AAEzD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,WAM1C;AAKD,wBAAgB,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,GAAQ,GAAG,GAAG,EAAE,CA0C1D;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,WAAW,EACrB,WAAW,UAAQ,GAClB,OAAO,CAkBT;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,WAAW,GACpB,OAAO,CAET;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAUnD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,GAAG,gBAa5C;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,GAAG,gBAUtD"}

11
dist/util.js vendored
View File

@ -80,13 +80,16 @@ export function createHash(data) {
sodium.crypto_generichash(hash, buffer);
return hash;
}
export function setupStream(stream) {
export async function setupStream(stream) {
const existing = stream[RPC_PROTOCOL_SYMBOL];
if (existing) {
if (!existing) {
await existing._channel.ready;
return existing;
}
stream[RPC_PROTOCOL_SYMBOL] = new RPC(stream);
return stream[RPC_PROTOCOL_SYMBOL];
const rpc = new RPC(stream);
stream[RPC_PROTOCOL_SYMBOL] = rpc;
await existing.ready;
return rpc;
}
export async function maybeGetAsyncProperty(object) {
if (typeof object === "function") {

View File

@ -75,7 +75,7 @@ export default class SimpleRpcQuery extends RpcQueryBase {
await socket.opened;
const rpc = setupStream(socket);
const rpc = await setupStream(socket);
if (this._query.bypassCache) {
delete this._query.bypassCache;

View File

@ -115,15 +115,19 @@ export function createHash(data: string): Buffer {
return hash;
}
export function setupStream(stream: any) {
export async function setupStream(stream: any) {
const existing = stream[RPC_PROTOCOL_SYMBOL];
if (existing) {
if (!existing) {
await existing._channel.ready;
return existing;
}
stream[RPC_PROTOCOL_SYMBOL] = new RPC(stream);
const rpc = new RPC(stream);
stream[RPC_PROTOCOL_SYMBOL] = rpc;
return stream[RPC_PROTOCOL_SYMBOL];
await existing.ready;
return rpc;
}
export async function maybeGetAsyncProperty(object: any) {