New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@libsql/hrana-client

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libsql/hrana-client - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

12

lib-cjs/http/client.js

@@ -45,3 +45,3 @@ "use strict";

/** @private */
constructor(url, jwt, customFetch) {
constructor(url, jwt, customFetch, protocolVersion = 2) {
super();

@@ -53,4 +53,10 @@ this.#url = url;

this.#streams = new Set();
this._endpointPromise = findEndpoint(this.#fetch, this.#url);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
if (protocolVersion == 3) {
this._endpointPromise = findEndpoint(this.#fetch, this.#url);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
}
else {
this._endpointPromise = Promise.resolve(fallbackEndpoint);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
}
}

@@ -57,0 +63,0 @@ /** Get the protocol version supported by the server. */

@@ -53,7 +53,14 @@ "use strict";

/** Open a Hrana client over WebSocket connected to the given `url`. */
function openWs(url, jwt) {
function openWs(url, jwt, protocolVersion = 2) {
if (typeof isomorphic_ws_1.WebSocket === "undefined") {
throw new errors_js_1.WebSocketUnsupportedError("WebSockets are not supported in this environment");
}
const socket = new isomorphic_ws_1.WebSocket(url, Array.from(client_js_1.subprotocols.keys()));
var subprotocols = undefined;
if (protocolVersion == 3) {
subprotocols = Array.from(client_js_1.subprotocolsV3.keys());
}
else {
subprotocols = Array.from(client_js_1.subprotocolsV2.keys());
}
const socket = new isomorphic_ws_1.WebSocket(url, subprotocols);
return new client_js_3.WsClient(socket, jwt);

@@ -68,5 +75,5 @@ }

*/
function openHttp(url, jwt, customFetch) {
return new client_js_2.HttpClient(url instanceof URL ? url : new URL(url), jwt, customFetch);
function openHttp(url, jwt, customFetch, protocolVersion = 2) {
return new client_js_2.HttpClient(url instanceof URL ? url : new URL(url), jwt, customFetch, protocolVersion);
}
exports.openHttp = openHttp;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WsClient = exports.subprotocols = void 0;
exports.WsClient = exports.subprotocolsV3 = exports.subprotocolsV2 = void 0;
const client_js_1 = require("../client.js");

@@ -16,3 +16,7 @@ const index_js_1 = require("../encoding/index.js");

const protobuf_decode_js_1 = require("./protobuf_decode.js");
exports.subprotocols = new Map([
exports.subprotocolsV2 = new Map([
["hrana2", { version: 2, encoding: "json" }],
["hrana1", { version: 1, encoding: "json" }],
]);
exports.subprotocolsV3 = new Map([
["hrana3-protobuf", { version: 3, encoding: "protobuf" }],

@@ -102,3 +106,3 @@ ["hrana3", { version: 3, encoding: "json" }],

else {
this.#subprotocol = exports.subprotocols.get(protocol);
this.#subprotocol = exports.subprotocolsV3.get(protocol);
if (this.#subprotocol === undefined) {

@@ -105,0 +109,0 @@ this.#setClosed(new errors_js_1.ProtoError(`Unrecognized WebSocket subprotocol: ${JSON.stringify(protocol)}`));

@@ -21,3 +21,3 @@ /// <reference types="node" />

/** @private */
constructor(url: URL, jwt: string | undefined, customFetch: unknown | undefined);
constructor(url: URL, jwt: string | undefined, customFetch: unknown | undefined, protocolVersion?: ProtocolVersion);
/** Get the protocol version supported by the server. */

@@ -24,0 +24,0 @@ getVersion(): Promise<ProtocolVersion>;

@@ -42,3 +42,3 @@ import { fetch, Request } from "@libsql/isomorphic-fetch";

/** @private */
constructor(url, jwt, customFetch) {
constructor(url, jwt, customFetch, protocolVersion = 2) {
super();

@@ -50,4 +50,10 @@ this.#url = url;

this.#streams = new Set();
this._endpointPromise = findEndpoint(this.#fetch, this.#url);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
if (protocolVersion == 3) {
this._endpointPromise = findEndpoint(this.#fetch, this.#url);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
}
else {
this._endpointPromise = Promise.resolve(fallbackEndpoint);
this._endpointPromise.then((endpoint) => this._endpoint = endpoint, (error) => this.#setClosed(error));
}
}

@@ -54,0 +60,0 @@ /** Get the protocol version supported by the server. */

/// <reference types="node" />
import { HttpClient } from "./http/client.js";
import { WsClient } from "./ws/client.js";
import { ProtocolVersion } from "./client.js";
export { WebSocket } from "@libsql/isomorphic-ws";

@@ -26,3 +27,3 @@ export type { RequestInit, Response } from "@libsql/isomorphic-fetch";

/** Open a Hrana client over WebSocket connected to the given `url`. */
export declare function openWs(url: string | URL, jwt?: string): WsClient;
export declare function openWs(url: string | URL, jwt?: string, protocolVersion?: ProtocolVersion): WsClient;
/** Open a Hrana client over HTTP connected to the given `url`.

@@ -34,2 +35,2 @@ *

*/
export declare function openHttp(url: string | URL, jwt?: string, customFetch?: unknown | undefined): HttpClient;
export declare function openHttp(url: string | URL, jwt?: string, customFetch?: unknown | undefined, protocolVersion?: ProtocolVersion): HttpClient;
import { WebSocket } from "@libsql/isomorphic-ws";
import { subprotocols } from "./ws/client.js";
import { subprotocolsV2, subprotocolsV3 } from "./ws/client.js";
import { WebSocketUnsupportedError } from "./errors.js";

@@ -20,7 +20,14 @@ import { HttpClient } from "./http/client.js";

/** Open a Hrana client over WebSocket connected to the given `url`. */
export function openWs(url, jwt) {
export function openWs(url, jwt, protocolVersion = 2) {
if (typeof WebSocket === "undefined") {
throw new WebSocketUnsupportedError("WebSockets are not supported in this environment");
}
const socket = new WebSocket(url, Array.from(subprotocols.keys()));
var subprotocols = undefined;
if (protocolVersion == 3) {
subprotocols = Array.from(subprotocolsV3.keys());
}
else {
subprotocols = Array.from(subprotocolsV2.keys());
}
const socket = new WebSocket(url, subprotocols);
return new WsClient(socket, jwt);

@@ -34,4 +41,4 @@ }

*/
export function openHttp(url, jwt, customFetch) {
return new HttpClient(url instanceof URL ? url : new URL(url), jwt, customFetch);
export function openHttp(url, jwt, customFetch, protocolVersion = 2) {
return new HttpClient(url instanceof URL ? url : new URL(url), jwt, customFetch, protocolVersion);
}

@@ -13,3 +13,4 @@ /// <reference types="ws" />

};
export declare const subprotocols: Map<string, Subprotocol>;
export declare const subprotocolsV2: Map<string, Subprotocol>;
export declare const subprotocolsV3: Map<string, Subprotocol>;
/** A client for the Hrana protocol over a WebSocket. */

@@ -16,0 +17,0 @@ export declare class WsClient extends Client implements SqlOwner {

@@ -13,3 +13,7 @@ import { Client } from "../client.js";

import { ServerMsg as protobuf_ServerMsg } from "./protobuf_decode.js";
export const subprotocols = new Map([
export const subprotocolsV2 = new Map([
["hrana2", { version: 2, encoding: "json" }],
["hrana1", { version: 1, encoding: "json" }],
]);
export const subprotocolsV3 = new Map([
["hrana3-protobuf", { version: 3, encoding: "protobuf" }],

@@ -99,3 +103,3 @@ ["hrana3", { version: 3, encoding: "json" }],

else {
this.#subprotocol = subprotocols.get(protocol);
this.#subprotocol = subprotocolsV3.get(protocol);
if (this.#subprotocol === undefined) {

@@ -102,0 +106,0 @@ this.#setClosed(new ProtoError(`Unrecognized WebSocket subprotocol: ${JSON.stringify(protocol)}`));

{
"name": "@libsql/hrana-client",
"version": "0.5.1",
"version": "0.5.2",
"keywords": [

@@ -5,0 +5,0 @@ "hrana",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc