Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libsql/client

Package Overview
Dependencies
Maintainers
3
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libsql/client - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

lib-cjs/migrations.js

40

lib-cjs/hrana.js

@@ -64,3 +64,4 @@ "use strict";

rowsPromises = hranaStmts.map((hranaStmt) => {
const stmtStep = batch.step()
const stmtStep = batch
.step()
.condition(hrana.BatchCond.ok(lastStep));

@@ -78,3 +79,4 @@ if (this.#version >= 3) {

// of the batch are both successful.
this.#started = batch.execute()
this.#started = batch
.execute()
.then(() => beginPromise)

@@ -144,3 +146,4 @@ .then(() => undefined);

// If the transaction hasn't started yet, start it now
this.#started = stream.run((0, util_1.transactionModeToBegin)(this.#mode))
this.#started = stream
.run((0, util_1.transactionModeToBegin)(this.#mode))
.then(() => undefined);

@@ -180,4 +183,5 @@ try {

// Pipeline the ROLLBACK statement and the stream close.
const promise = stream.run("ROLLBACK")
.catch(e => { throw mapHranaError(e); });
const promise = stream.run("ROLLBACK").catch((e) => {
throw mapHranaError(e);
});
stream.closeGracefully();

@@ -211,4 +215,5 @@ await promise;

}
const promise = stream.run("COMMIT")
.catch(e => { throw mapHranaError(e); });
const promise = stream.run("COMMIT").catch((e) => {
throw mapHranaError(e);
});
stream.closeGracefully();

@@ -231,4 +236,3 @@ await promise;

const stmtPromises = hranaStmts.map((hranaStmt) => {
const stmtStep = batch.step()
.condition(hrana.BatchCond.ok(lastStep));
const stmtStep = batch.step().condition(hrana.BatchCond.ok(lastStep));
if (version >= 3) {

@@ -241,4 +245,3 @@ stmtStep.condition(hrana.BatchCond.not(hrana.BatchCond.isAutocommit(batch)));

});
const commitStep = batch.step()
.condition(hrana.BatchCond.ok(lastStep));
const commitStep = batch.step().condition(hrana.BatchCond.ok(lastStep));
if (version >= 3) {

@@ -248,5 +251,6 @@ commitStep.condition(hrana.BatchCond.not(hrana.BatchCond.isAutocommit(batch)));

const commitPromise = commitStep.run("COMMIT");
const rollbackStep = batch.step()
const rollbackStep = batch
.step()
.condition(hrana.BatchCond.not(hrana.BatchCond.ok(commitStep)));
rollbackStep.run("ROLLBACK").catch(_ => undefined);
rollbackStep.run("ROLLBACK").catch((_) => undefined);
await batch.execute();

@@ -283,8 +287,9 @@ const resultSets = [];

function resultSetFromHrana(hranaRows) {
const columns = hranaRows.columnNames.map(c => c ?? "");
const columnTypes = hranaRows.columnDecltypes.map(c => c ?? "");
const columns = hranaRows.columnNames.map((c) => c ?? "");
const columnTypes = hranaRows.columnDecltypes.map((c) => c ?? "");
const rows = hranaRows.rows;
const rowsAffected = hranaRows.affectedRowCount;
const lastInsertRowid = hranaRows.lastInsertRowid !== undefined
? hranaRows.lastInsertRowid : undefined;
? hranaRows.lastInsertRowid
: undefined;
return new util_1.ResultSetImpl(columns, columnTypes, rows, rowsAffected, lastInsertRowid);

@@ -310,3 +315,4 @@ }

return e.cause instanceof hrana.ClientError
? mapHranaErrorCode(e.cause) : "HRANA_CLOSED_ERROR";
? mapHranaErrorCode(e.cause)
: "HRANA_CLOSED_ERROR";
}

@@ -313,0 +319,0 @@ else if (e instanceof hrana.WebSocketError) {

@@ -37,2 +37,3 @@ "use strict";

const util_1 = require("@libsql/core/util");
const migrations_js_1 = require("./migrations.js");
__exportStar(require("@libsql/core/api"), exports);

@@ -66,2 +67,5 @@ function createClient(config) {

protocol;
#url;
#authToken;
#isSchemaDatabase;
/** @private */

@@ -72,5 +76,17 @@ constructor(url, authToken, intMode, customFetch) {

this.protocol = "http";
this.#url = url;
this.#authToken = authToken;
}
async getIsSchemaDatabase() {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = await (0, migrations_js_1.getIsSchemaDatabase)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return this.#isSchemaDatabase;
}
async execute(stmt) {
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = (0, hrana_js_1.stmtToHrana)(stmt);

@@ -87,3 +103,11 @@ // Pipeline all operations, so `hrana.HttpClient` can open the stream, execute the statement and

}
return (0, hrana_js_1.resultSetFromHrana)(await rowsPromise);
const rowsResult = await rowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await (0, migrations_js_1.waitForLastMigrationJobToFinish)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return (0, hrana_js_1.resultSetFromHrana)(rowsResult);
}

@@ -96,2 +120,3 @@ catch (e) {

try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(hrana_js_1.stmtToHrana);

@@ -118,3 +143,11 @@ const version = await this.#client.getVersion();

}
return await resultsPromise;
const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await (0, migrations_js_1.waitForLastMigrationJobToFinish)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return results;
}

@@ -121,0 +154,0 @@ catch (e) {

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

syncUrl: config.syncUrl,
syncInterval: config.syncInterval,
syncPeriod: config.syncInterval,
};

@@ -211,4 +211,5 @@ const db = new libsql_1.default(path, options);

for (const name in stmt.args) {
const argName = (name[0] === "@" || name[0] === "$" || name[0] === ":")
? name.substring(1) : name;
const argName = name[0] === "@" || name[0] === "$" || name[0] === ":"
? name.substring(1)
: name;
args[argName] = valueToSql(stmt.args[name], intMode);

@@ -230,4 +231,4 @@ }

if (returnsData) {
const columns = Array.from(sqlStmt.columns().map(col => col.name));
const columnTypes = Array.from(sqlStmt.columns().map(col => col.type ?? ""));
const columns = Array.from(sqlStmt.columns().map((col) => col.name));
const columnTypes = Array.from(sqlStmt.columns().map((col) => col.type ?? ""));
const rows = sqlStmt.all(args).map((sqlRow) => {

@@ -261,3 +262,8 @@ return rowFromSql(sqlRow, columns, intMode);

if (!Object.hasOwn(row, column)) {
Object.defineProperty(row, column, { value, enumerable: true, configurable: true, writable: true });
Object.defineProperty(row, column, {
value,
enumerable: true,
configurable: true,
writable: true,
});
}

@@ -264,0 +270,0 @@ }

@@ -37,2 +37,3 @@ "use strict";

const util_1 = require("@libsql/core/util");
const migrations_js_1 = require("./migrations.js");
__exportStar(require("@libsql/core/api"), exports);

@@ -89,2 +90,3 @@ function createClient(config) {

protocol;
#isSchemaDatabase;
/** @private */

@@ -100,5 +102,15 @@ constructor(client, url, authToken, intMode) {

}
async getIsSchemaDatabase() {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = await (0, migrations_js_1.getIsSchemaDatabase)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return this.#isSchemaDatabase;
}
async execute(stmt) {
const streamState = await this.#openStream();
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = (0, hrana_js_1.stmtToHrana)(stmt);

@@ -110,3 +122,11 @@ // Schedule all operations synchronously, so they will be pipelined and executed in a single

streamState.stream.closeGracefully();
return (0, hrana_js_1.resultSetFromHrana)(await hranaRowsPromise);
const hranaRowsResult = await hranaRowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await (0, migrations_js_1.waitForLastMigrationJobToFinish)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return (0, hrana_js_1.resultSetFromHrana)(hranaRowsResult);
}

@@ -123,2 +143,3 @@ catch (e) {

try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(hrana_js_1.stmtToHrana);

@@ -131,3 +152,11 @@ const version = await streamState.conn.client.getVersion();

const resultsPromise = (0, hrana_js_1.executeHranaBatch)(mode, version, batch, hranaStmts);
return await resultsPromise;
const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await (0, migrations_js_1.waitForLastMigrationJobToFinish)({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return results;
}

@@ -179,3 +208,4 @@ catch (e) {

const ageMillis = now.valueOf() - this.#connState.openTime.valueOf();
if (ageMillis > maxConnAgeMillis && this.#futureConnState === undefined) {
if (ageMillis > maxConnAgeMillis &&
this.#futureConnState === undefined) {
// The existing connection is too old, let's open a new one.

@@ -234,3 +264,4 @@ const futureConnState = this.#openConn();

if (connState.useSqlCache === undefined) {
connState.useSqlCache = await connState.client.getVersion() >= 2;
connState.useSqlCache =
(await connState.client.getVersion()) >= 2;
if (connState.useSqlCache) {

@@ -269,3 +300,4 @@ connState.sqlCache.capacity = sqlCacheCapacity;

connState.streamStates.delete(streamState);
if (connState.streamStates.size === 0 && connState !== this.#connState) {
if (connState.streamStates.size === 0 &&
connState !== this.#connState) {
// We are not using this connection anymore and this is the last stream that was using it, so we

@@ -272,0 +304,0 @@ // must close it now.

@@ -38,3 +38,4 @@ import * as hrana from "@libsql/hrana-client";

rowsPromises = hranaStmts.map((hranaStmt) => {
const stmtStep = batch.step()
const stmtStep = batch
.step()
.condition(hrana.BatchCond.ok(lastStep));

@@ -52,3 +53,4 @@ if (this.#version >= 3) {

// of the batch are both successful.
this.#started = batch.execute()
this.#started = batch
.execute()
.then(() => beginPromise)

@@ -118,3 +120,4 @@ .then(() => undefined);

// If the transaction hasn't started yet, start it now
this.#started = stream.run(transactionModeToBegin(this.#mode))
this.#started = stream
.run(transactionModeToBegin(this.#mode))
.then(() => undefined);

@@ -154,4 +157,5 @@ try {

// Pipeline the ROLLBACK statement and the stream close.
const promise = stream.run("ROLLBACK")
.catch(e => { throw mapHranaError(e); });
const promise = stream.run("ROLLBACK").catch((e) => {
throw mapHranaError(e);
});
stream.closeGracefully();

@@ -185,4 +189,5 @@ await promise;

}
const promise = stream.run("COMMIT")
.catch(e => { throw mapHranaError(e); });
const promise = stream.run("COMMIT").catch((e) => {
throw mapHranaError(e);
});
stream.closeGracefully();

@@ -204,4 +209,3 @@ await promise;

const stmtPromises = hranaStmts.map((hranaStmt) => {
const stmtStep = batch.step()
.condition(hrana.BatchCond.ok(lastStep));
const stmtStep = batch.step().condition(hrana.BatchCond.ok(lastStep));
if (version >= 3) {

@@ -214,4 +218,3 @@ stmtStep.condition(hrana.BatchCond.not(hrana.BatchCond.isAutocommit(batch)));

});
const commitStep = batch.step()
.condition(hrana.BatchCond.ok(lastStep));
const commitStep = batch.step().condition(hrana.BatchCond.ok(lastStep));
if (version >= 3) {

@@ -221,5 +224,6 @@ commitStep.condition(hrana.BatchCond.not(hrana.BatchCond.isAutocommit(batch)));

const commitPromise = commitStep.run("COMMIT");
const rollbackStep = batch.step()
const rollbackStep = batch
.step()
.condition(hrana.BatchCond.not(hrana.BatchCond.ok(commitStep)));
rollbackStep.run("ROLLBACK").catch(_ => undefined);
rollbackStep.run("ROLLBACK").catch((_) => undefined);
await batch.execute();

@@ -254,8 +258,9 @@ const resultSets = [];

export function resultSetFromHrana(hranaRows) {
const columns = hranaRows.columnNames.map(c => c ?? "");
const columnTypes = hranaRows.columnDecltypes.map(c => c ?? "");
const columns = hranaRows.columnNames.map((c) => c ?? "");
const columnTypes = hranaRows.columnDecltypes.map((c) => c ?? "");
const rows = hranaRows.rows;
const rowsAffected = hranaRows.affectedRowCount;
const lastInsertRowid = hranaRows.lastInsertRowid !== undefined
? hranaRows.lastInsertRowid : undefined;
? hranaRows.lastInsertRowid
: undefined;
return new ResultSetImpl(columns, columnTypes, rows, rowsAffected, lastInsertRowid);

@@ -279,3 +284,4 @@ }

return e.cause instanceof hrana.ClientError
? mapHranaErrorCode(e.cause) : "HRANA_CLOSED_ERROR";
? mapHranaErrorCode(e.cause)
: "HRANA_CLOSED_ERROR";
}

@@ -282,0 +288,0 @@ else if (e instanceof hrana.WebSocketError) {

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

constructor(url: URL, authToken: string | undefined, intMode: IntMode, customFetch: Function | undefined);
getIsSchemaDatabase(): Promise<boolean>;
execute(stmt: InStatement): Promise<ResultSet>;

@@ -20,0 +21,0 @@ batch(stmts: Array<InStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>;

@@ -8,2 +8,3 @@ import * as hrana from "@libsql/hrana-client";

import { supportedUrlLink } from "@libsql/core/util";
import { getIsSchemaDatabase, waitForLastMigrationJobToFinish, } from "./migrations.js";
export * from "@libsql/core/api";

@@ -35,2 +36,5 @@ export function createClient(config) {

protocol;
#url;
#authToken;
#isSchemaDatabase;
/** @private */

@@ -41,5 +45,17 @@ constructor(url, authToken, intMode, customFetch) {

this.protocol = "http";
this.#url = url;
this.#authToken = authToken;
}
async getIsSchemaDatabase() {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = await getIsSchemaDatabase({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return this.#isSchemaDatabase;
}
async execute(stmt) {
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = stmtToHrana(stmt);

@@ -56,3 +72,11 @@ // Pipeline all operations, so `hrana.HttpClient` can open the stream, execute the statement and

}
return resultSetFromHrana(await rowsPromise);
const rowsResult = await rowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return resultSetFromHrana(rowsResult);
}

@@ -65,2 +89,3 @@ catch (e) {

try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(stmtToHrana);

@@ -87,3 +112,11 @@ const version = await this.#client.getVersion();

}
return await resultsPromise;
const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return results;
}

@@ -90,0 +123,0 @@ catch (e) {

@@ -5,3 +5,3 @@ import Database from "libsql";

import { expandConfig } from "@libsql/core/config";
import { supportedUrlLink, transactionModeToBegin, ResultSetImpl } from "@libsql/core/util";
import { supportedUrlLink, transactionModeToBegin, ResultSetImpl, } from "@libsql/core/util";
export * from "@libsql/core/api";

@@ -38,3 +38,3 @@ export function createClient(config) {

syncUrl: config.syncUrl,
syncInterval: config.syncInterval,
syncPeriod: config.syncInterval,
};

@@ -188,4 +188,5 @@ const db = new Database(path, options);

for (const name in stmt.args) {
const argName = (name[0] === "@" || name[0] === "$" || name[0] === ":")
? name.substring(1) : name;
const argName = name[0] === "@" || name[0] === "$" || name[0] === ":"
? name.substring(1)
: name;
args[argName] = valueToSql(stmt.args[name], intMode);

@@ -207,4 +208,4 @@ }

if (returnsData) {
const columns = Array.from(sqlStmt.columns().map(col => col.name));
const columnTypes = Array.from(sqlStmt.columns().map(col => col.type ?? ""));
const columns = Array.from(sqlStmt.columns().map((col) => col.name));
const columnTypes = Array.from(sqlStmt.columns().map((col) => col.type ?? ""));
const rows = sqlStmt.all(args).map((sqlRow) => {

@@ -238,3 +239,8 @@ return rowFromSql(sqlRow, columns, intMode);

if (!Object.hasOwn(row, column)) {
Object.defineProperty(row, column, { value, enumerable: true, configurable: true, writable: true });
Object.defineProperty(row, column, {
value,
enumerable: true,
configurable: true,
writable: true,
});
}

@@ -241,0 +247,0 @@ }

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

constructor(client: hrana.WsClient, url: URL, authToken: string | undefined, intMode: IntMode);
getIsSchemaDatabase(): Promise<boolean>;
execute(stmt: InStatement): Promise<ResultSet>;

@@ -31,0 +32,0 @@ batch(stmts: Array<InStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>;

@@ -8,2 +8,3 @@ import * as hrana from "@libsql/hrana-client";

import { supportedUrlLink } from "@libsql/core/util";
import { getIsSchemaDatabase, waitForLastMigrationJobToFinish, } from "./migrations.js";
export * from "@libsql/core/api";

@@ -58,2 +59,3 @@ export function createClient(config) {

protocol;
#isSchemaDatabase;
/** @private */

@@ -69,5 +71,15 @@ constructor(client, url, authToken, intMode) {

}
async getIsSchemaDatabase() {
if (this.#isSchemaDatabase === undefined) {
this.#isSchemaDatabase = await getIsSchemaDatabase({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return this.#isSchemaDatabase;
}
async execute(stmt) {
const streamState = await this.#openStream();
try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmt = stmtToHrana(stmt);

@@ -79,3 +91,11 @@ // Schedule all operations synchronously, so they will be pipelined and executed in a single

streamState.stream.closeGracefully();
return resultSetFromHrana(await hranaRowsPromise);
const hranaRowsResult = await hranaRowsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return resultSetFromHrana(hranaRowsResult);
}

@@ -92,2 +112,3 @@ catch (e) {

try {
const isSchemaDatabasePromise = this.getIsSchemaDatabase();
const hranaStmts = stmts.map(stmtToHrana);

@@ -100,3 +121,11 @@ const version = await streamState.conn.client.getVersion();

const resultsPromise = executeHranaBatch(mode, version, batch, hranaStmts);
return await resultsPromise;
const results = await resultsPromise;
const isSchemaDatabase = await isSchemaDatabasePromise;
if (isSchemaDatabase) {
await waitForLastMigrationJobToFinish({
authToken: this.#authToken,
baseUrl: this.#url.origin,
});
}
return results;
}

@@ -148,3 +177,4 @@ catch (e) {

const ageMillis = now.valueOf() - this.#connState.openTime.valueOf();
if (ageMillis > maxConnAgeMillis && this.#futureConnState === undefined) {
if (ageMillis > maxConnAgeMillis &&
this.#futureConnState === undefined) {
// The existing connection is too old, let's open a new one.

@@ -203,3 +233,4 @@ const futureConnState = this.#openConn();

if (connState.useSqlCache === undefined) {
connState.useSqlCache = await connState.client.getVersion() >= 2;
connState.useSqlCache =
(await connState.client.getVersion()) >= 2;
if (connState.useSqlCache) {

@@ -238,3 +269,4 @@ connState.sqlCache.capacity = sqlCacheCapacity;

connState.streamStates.delete(streamState);
if (connState.streamStates.size === 0 && connState !== this.#connState) {
if (connState.streamStates.size === 0 &&
connState !== this.#connState) {
// We are not using this connection anymore and this is the last stream that was using it, so we

@@ -241,0 +273,0 @@ // must close it now.

{
"name": "@libsql/client",
"version": "0.6.0",
"version": "0.6.1",
"keywords": [

@@ -100,6 +100,8 @@ "libsql",

"typecheck": "tsc --noEmit",
"typedoc": "rm -rf ./docs && typedoc"
"typedoc": "rm -rf ./docs && typedoc",
"prepare": "husky install",
"lint-staged": "lint-staged"
},
"dependencies": {
"@libsql/core": "^0.6.0",
"@libsql/core": "^0.6.1",
"@libsql/hrana-client": "^0.6.0",

@@ -112,3 +114,7 @@ "js-base64": "^3.7.5",

"@types/node": "^18.15.5",
"husky": "^9.0.11",
"jest": "^29.3.1",
"lint-staged": "^15.2.2",
"msw": "^2.3.0",
"prettier": "3.2.5",
"ts-jest": "^29.0.5",

@@ -115,0 +121,0 @@ "typedoc": "^0.23.28",

@@ -46,7 +46,7 @@ <p align="center">

- [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas)
- [Platform API](https://docs.turso.tech/features/platform-api)
- [Data Edge](https://docs.turso.tech/features/data-edge)
- [Branching](https://docs.turso.tech/features/branching)
- [Point-in-Time Recovery](https://docs.turso.tech/features/point-in-time-recovery)
- [Scale to Zero](https://docs.turso.tech/features/scale-to-zero)
- [Embedded Replicas](https://docs.turso.tech/features/embedded-replicas)
- [Platform API](https://docs.turso.tech/features/platform-api)
- [Data Edge](https://docs.turso.tech/features/data-edge)
- [Branching](https://docs.turso.tech/features/branching)
- [Point-in-Time Recovery](https://docs.turso.tech/features/point-in-time-recovery)
- [Scale to Zero](https://docs.turso.tech/features/scale-to-zero)
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