Compare commits
No commits in common. "99f988addd9730fd8989cfbd8c9990e866b07c71" and "f875cd116fe18cfa29e8a9e376425dfcceca2e56" have entirely different histories.
99f988addd
...
f875cd116f
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/query/simple.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAU9C,OAAO,YAAY,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IACtD,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAChC,UAAkB,MAAM,EAAE,gBAAgB,CAAC;gBAE/B,EACV,OAAO,EACP,KAAK,EACL,KAAK,EACL,OAAO,GACR,EAAE;QACD,OAAO,EAAE,UAAU,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;QAC9B,KAAK,EAAE,gBAAgB,CAAC;QACxB,OAAO,EAAE,eAAe,CAAC;KAC1B;cASe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;cAKrB,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;cAwD1B,cAAc;CAmB/B"}
|
{"version":3,"file":"simple.d.ts","sourceRoot":"","sources":["../../src/query/simple.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9C,OAAO,YAAY,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,YAAY;IACtD,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAChC,UAAkB,MAAM,EAAE,gBAAgB,CAAC;gBAE/B,EACV,OAAO,EACP,KAAK,EACL,KAAK,EACL,OAAO,GACR,EAAE;QACD,OAAO,EAAE,UAAU,CAAC;QACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;QAC9B,KAAK,EAAE,gBAAgB,CAAC;QACxB,OAAO,EAAE,eAAe,CAAC;KAC1B;cASe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;cAKrB,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;cAwD1B,cAAc;CAmB/B"}
|
|
@ -1,5 +1,6 @@
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import { hashQuery, isPromise, setupStream, validateTimestampedResponse, } from "../util.js";
|
import { hashQuery, isPromise, validateTimestampedResponse } from "../util.js";
|
||||||
|
import RPC from "@lumeweb/rpc";
|
||||||
import { ERR_INVALID_SIGNATURE } from "../error.js";
|
import { ERR_INVALID_SIGNATURE } from "../error.js";
|
||||||
import RpcQueryBase from "./base.js";
|
import RpcQueryBase from "./base.js";
|
||||||
export default class SimpleRpcQuery extends RpcQueryBase {
|
export default class SimpleRpcQuery extends RpcQueryBase {
|
||||||
|
@ -42,7 +43,7 @@ export default class SimpleRpcQuery extends RpcQueryBase {
|
||||||
}
|
}
|
||||||
this._relay = socket;
|
this._relay = socket;
|
||||||
await socket.opened;
|
await socket.opened;
|
||||||
const rpc = setupStream(socket);
|
const rpc = new RPC(socket);
|
||||||
if (this._query.bypassCache) {
|
if (this._query.bypassCache) {
|
||||||
delete this._query.bypassCache;
|
delete this._query.bypassCache;
|
||||||
await this.queryRpc(rpc, {
|
await this.queryRpc(rpc, {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
import type { RPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
import type { RPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
||||||
export declare const RPC_PROTOCOL_SYMBOL: unique symbol;
|
|
||||||
export declare function isPromise(obj: Promise<any>): boolean;
|
export declare function isPromise(obj: Promise<any>): boolean;
|
||||||
export declare function flatten(target: any, opts?: any): any[];
|
export declare function flatten(target: any, opts?: any): any[];
|
||||||
export declare function validateResponse(
|
export declare function validateResponse(
|
||||||
|
@ -14,5 +13,4 @@ export declare function validateTimestampedResponse(
|
||||||
): boolean;
|
): boolean;
|
||||||
export declare function hashQuery(query: RPCRequest): string;
|
export declare function hashQuery(query: RPCRequest): string;
|
||||||
export declare function createHash(data: string): Buffer;
|
export declare function createHash(data: string): Buffer;
|
||||||
export declare function setupStream(stream: any): any;
|
|
||||||
//# sourceMappingURL=util.d.ts.map
|
//# sourceMappingURL=util.d.ts.map
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASpE,eAAO,MAAM,mBAAmB,eAAyC,CAAC;AAE1E,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"}
|
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAOpE,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"}
|
|
@ -5,9 +5,6 @@ import crypto from "hypercore-crypto";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import sodium from "sodium-universal";
|
import sodium from "sodium-universal";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import RPC from "@lumeweb/rpc";
|
|
||||||
const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
|
||||||
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
|
|
||||||
export function isPromise(obj) {
|
export function isPromise(obj) {
|
||||||
return (!!obj &&
|
return (!!obj &&
|
||||||
(typeof obj === "object" || typeof obj === "function") &&
|
(typeof obj === "object" || typeof obj === "function") &&
|
||||||
|
@ -81,11 +78,3 @@ export function createHash(data) {
|
||||||
sodium.crypto_generichash(hash, buffer);
|
sodium.crypto_generichash(hash, buffer);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
export function setupStream(stream) {
|
|
||||||
const existing = stream[RPC_PROTOCOL_SYMBOL];
|
|
||||||
if (existing) {
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
stream[RPC_PROTOCOL_SYMBOL] = new RPC(stream);
|
|
||||||
return stream[RPC_PROTOCOL_SYMBOL];
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,12 +2,7 @@ import RpcNetwork from "../network.js";
|
||||||
import { ClientRPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
import { ClientRPCRequest, RPCResponse } from "@lumeweb/relay-types";
|
||||||
import { RpcQueryOptions } from "../types.js";
|
import { RpcQueryOptions } from "../types.js";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import {
|
import { hashQuery, isPromise, validateTimestampedResponse } from "../util.js";
|
||||||
hashQuery,
|
|
||||||
isPromise,
|
|
||||||
setupStream,
|
|
||||||
validateTimestampedResponse,
|
|
||||||
} from "../util.js";
|
|
||||||
import RPC from "@lumeweb/rpc";
|
import RPC from "@lumeweb/rpc";
|
||||||
import { ERR_INVALID_SIGNATURE } from "../error.js";
|
import { ERR_INVALID_SIGNATURE } from "../error.js";
|
||||||
import RpcQueryBase from "./base.js";
|
import RpcQueryBase from "./base.js";
|
||||||
|
@ -74,7 +69,7 @@ export default class SimpleRpcQuery extends RpcQueryBase {
|
||||||
|
|
||||||
await socket.opened;
|
await socket.opened;
|
||||||
|
|
||||||
const rpc = setupStream(socket);
|
const rpc = new RPC(socket);
|
||||||
|
|
||||||
if (this._query.bypassCache) {
|
if (this._query.bypassCache) {
|
||||||
delete this._query.bypassCache;
|
delete this._query.bypassCache;
|
||||||
|
|
15
src/util.ts
15
src/util.ts
|
@ -6,10 +6,6 @@ import crypto from "hypercore-crypto";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import sodium from "sodium-universal";
|
import sodium from "sodium-universal";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import RPC from "@lumeweb/rpc";
|
|
||||||
|
|
||||||
const RPC_PROTOCOL_ID = b4a.from("lumeweb");
|
|
||||||
export const RPC_PROTOCOL_SYMBOL = Symbol.for(RPC_PROTOCOL_ID.toString());
|
|
||||||
|
|
||||||
export function isPromise(obj: Promise<any>) {
|
export function isPromise(obj: Promise<any>) {
|
||||||
return (
|
return (
|
||||||
|
@ -116,14 +112,3 @@ export function createHash(data: string): Buffer {
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setupStream(stream: any) {
|
|
||||||
const existing = stream[RPC_PROTOCOL_SYMBOL];
|
|
||||||
if (existing) {
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
|
|
||||||
stream[RPC_PROTOCOL_SYMBOL] = new RPC(stream);
|
|
||||||
|
|
||||||
return stream[RPC_PROTOCOL_SYMBOL];
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue