New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@libsql/client

Package Overview
Dependencies
Maintainers
3
Versions
114
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.15.15
to
0.17.0
+43
-12
lib-cjs/hrana.js

@@ -122,9 +122,24 @@ "use strict";

const resultSets = [];
for (const rowsPromise of rowsPromises) {
const rows = await rowsPromise;
if (rows === undefined) {
throw new api_1.LibsqlError("Statement in a transaction was not executed, " +
"probably because the transaction has been rolled back", "TRANSACTION_CLOSED");
for (let i = 0; i < rowsPromises.length; i++) {
try {
const rows = await rowsPromises[i];
if (rows === undefined) {
throw new api_1.LibsqlBatchError("Statement in a transaction was not executed, " +
"probably because the transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(resultSetFromHrana(rows));
}
resultSets.push(resultSetFromHrana(rows));
catch (e) {
if (e instanceof api_1.LibsqlBatchError) {
throw e;
}
// Map hrana errors to LibsqlError first, then wrap in LibsqlBatchError
const mappedError = mapHranaError(e);
if (mappedError instanceof api_1.LibsqlError) {
throw new api_1.LibsqlBatchError(mappedError.message, i, mappedError.code, mappedError.extendedCode, mappedError.rawCode, mappedError.cause instanceof Error
? mappedError.cause
: undefined);
}
throw mappedError;
}
}

@@ -258,8 +273,23 @@ return resultSets;

await beginPromise;
for (const stmtPromise of stmtPromises) {
const hranaRows = await stmtPromise;
if (hranaRows === undefined) {
throw new api_1.LibsqlError("Statement in a batch was not executed, probably because the transaction has been rolled back", "TRANSACTION_CLOSED");
for (let i = 0; i < stmtPromises.length; i++) {
try {
const hranaRows = await stmtPromises[i];
if (hranaRows === undefined) {
throw new api_1.LibsqlBatchError("Statement in a batch was not executed, probably because the transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(resultSetFromHrana(hranaRows));
}
resultSets.push(resultSetFromHrana(hranaRows));
catch (e) {
if (e instanceof api_1.LibsqlBatchError) {
throw e;
}
// Map hrana errors to LibsqlError first, then wrap in LibsqlBatchError
const mappedError = mapHranaError(e);
if (mappedError instanceof api_1.LibsqlError) {
throw new api_1.LibsqlBatchError(mappedError.message, i, mappedError.code, mappedError.extendedCode, mappedError.rawCode, mappedError.cause instanceof Error
? mappedError.cause
: undefined);
}
throw mappedError;
}
}

@@ -311,3 +341,4 @@ await commitPromise;

const code = mapHranaErrorCode(e);
return new api_1.LibsqlError(e.message, code, undefined, e);
// TODO: Parse extendedCode once the SQL over HTTP protocol supports it
return new api_1.LibsqlError(e.message, code, undefined, undefined, e);
}

@@ -314,0 +345,0 @@ return e;

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

const url = (0, uri_1.encodeBaseUrl)(config.scheme, config.authority, config.path);
return new HttpClient(url, config.authToken, config.intMode, config.fetch, config.concurrency);
return new HttpClient(url, config.authToken, config.intMode, config.fetch, config.concurrency, config.remoteEncryptionKey);
}

@@ -75,5 +75,6 @@ exports._createClient = _createClient;

#authToken;
#remoteEncryptionKey;
#promiseLimitFunction;
/** @private */
constructor(url, authToken, intMode, customFetch, concurrency) {
constructor(url, authToken, intMode, customFetch, concurrency, remoteEncryptionKey) {
this.#url = url;

@@ -84,3 +85,4 @@ this.#authToken = authToken;

this.#concurrency = concurrency;
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch);
this.#remoteEncryptionKey = remoteEncryptionKey;
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch, remoteEncryptionKey);
this.#client.intMode = this.#intMode;

@@ -236,3 +238,3 @@ this.protocol = "http";

// Recreate the underlying hrana client
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch);
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch, this.#remoteEncryptionKey);
this.#client.intMode = this.#intMode;

@@ -239,0 +241,0 @@ }

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

encryptionKey: config.encryptionKey,
remoteEncryptionKey: config.remoteEncryptionKey,
syncUrl: config.syncUrl,

@@ -111,11 +112,24 @@ syncPeriod: config.syncInterval,

executeStmt(db, (0, util_1.transactionModeToBegin)(mode), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!db.inTransaction) {
throw new api_1.LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
if (!db.inTransaction) {
throw new api_1.LibsqlBatchError("The transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
const stmt = stmts[i];
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
resultSets.push(executeStmt(db, normalizedStmt, this.#intMode));
}
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
return executeStmt(db, normalizedStmt, this.#intMode);
});
catch (e) {
if (e instanceof api_1.LibsqlBatchError) {
throw e;
}
if (e instanceof api_1.LibsqlError) {
throw new api_1.LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
executeStmt(db, "COMMIT", this.#intMode);

@@ -136,8 +150,20 @@ return resultSets;

executeStmt(db, (0, util_1.transactionModeToBegin)("deferred"), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!db.inTransaction) {
throw new api_1.LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
if (!db.inTransaction) {
throw new api_1.LibsqlBatchError("The transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(executeStmt(db, stmts[i], this.#intMode));
}
return executeStmt(db, stmt, this.#intMode);
});
catch (e) {
if (e instanceof api_1.LibsqlBatchError) {
throw e;
}
if (e instanceof api_1.LibsqlError) {
throw new api_1.LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
executeStmt(db, "COMMIT", this.#intMode);

@@ -234,9 +260,23 @@ return resultSets;

async batch(stmts) {
return stmts.map((stmt) => {
this.#checkNotClosed();
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
return executeStmt(this.#database, normalizedStmt, this.#intMode);
});
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
this.#checkNotClosed();
const stmt = stmts[i];
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
resultSets.push(executeStmt(this.#database, normalizedStmt, this.#intMode));
}
catch (e) {
if (e instanceof api_1.LibsqlBatchError) {
throw e;
}
if (e instanceof api_1.LibsqlError) {
throw new api_1.LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
return resultSets;
}

@@ -420,5 +460,46 @@ async executeMultiple(sql) {

if (e instanceof libsql_1.default.SqliteError) {
return new api_1.LibsqlError(e.message, e.code, e.rawCode, e);
const extendedCode = e.code;
const code = mapToBaseCode(e.rawCode);
return new api_1.LibsqlError(e.message, code, extendedCode, e.rawCode, e);
}
return e;
}
// Map SQLite raw error code to base error code string.
// Extended error codes are (base | (extended << 8)), so base = rawCode & 0xFF
function mapToBaseCode(rawCode) {
if (rawCode === undefined) {
return "SQLITE_UNKNOWN";
}
const baseCode = rawCode & 0xff;
return (sqliteErrorCodes[baseCode] ?? `SQLITE_UNKNOWN_${baseCode.toString()}`);
}
const sqliteErrorCodes = {
1: "SQLITE_ERROR",
2: "SQLITE_INTERNAL",
3: "SQLITE_PERM",
4: "SQLITE_ABORT",
5: "SQLITE_BUSY",
6: "SQLITE_LOCKED",
7: "SQLITE_NOMEM",
8: "SQLITE_READONLY",
9: "SQLITE_INTERRUPT",
10: "SQLITE_IOERR",
11: "SQLITE_CORRUPT",
12: "SQLITE_NOTFOUND",
13: "SQLITE_FULL",
14: "SQLITE_CANTOPEN",
15: "SQLITE_PROTOCOL",
16: "SQLITE_EMPTY",
17: "SQLITE_SCHEMA",
18: "SQLITE_TOOBIG",
19: "SQLITE_CONSTRAINT",
20: "SQLITE_MISMATCH",
21: "SQLITE_MISUSE",
22: "SQLITE_NOLFS",
23: "SQLITE_AUTH",
24: "SQLITE_FORMAT",
25: "SQLITE_RANGE",
26: "SQLITE_NOTADB",
27: "SQLITE_NOTICE",
28: "SQLITE_WARNING",
};
import * as hrana from "@libsql/hrana-client";
import { LibsqlError } from "@libsql/core/api";
import { LibsqlError, LibsqlBatchError } from "@libsql/core/api";
import { transactionModeToBegin, ResultSetImpl } from "@libsql/core/util";

@@ -96,9 +96,24 @@ export class HranaTransaction {

const resultSets = [];
for (const rowsPromise of rowsPromises) {
const rows = await rowsPromise;
if (rows === undefined) {
throw new LibsqlError("Statement in a transaction was not executed, " +
"probably because the transaction has been rolled back", "TRANSACTION_CLOSED");
for (let i = 0; i < rowsPromises.length; i++) {
try {
const rows = await rowsPromises[i];
if (rows === undefined) {
throw new LibsqlBatchError("Statement in a transaction was not executed, " +
"probably because the transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(resultSetFromHrana(rows));
}
resultSets.push(resultSetFromHrana(rows));
catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
// Map hrana errors to LibsqlError first, then wrap in LibsqlBatchError
const mappedError = mapHranaError(e);
if (mappedError instanceof LibsqlError) {
throw new LibsqlBatchError(mappedError.message, i, mappedError.code, mappedError.extendedCode, mappedError.rawCode, mappedError.cause instanceof Error
? mappedError.cause
: undefined);
}
throw mappedError;
}
}

@@ -231,8 +246,23 @@ return resultSets;

await beginPromise;
for (const stmtPromise of stmtPromises) {
const hranaRows = await stmtPromise;
if (hranaRows === undefined) {
throw new LibsqlError("Statement in a batch was not executed, probably because the transaction has been rolled back", "TRANSACTION_CLOSED");
for (let i = 0; i < stmtPromises.length; i++) {
try {
const hranaRows = await stmtPromises[i];
if (hranaRows === undefined) {
throw new LibsqlBatchError("Statement in a batch was not executed, probably because the transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(resultSetFromHrana(hranaRows));
}
resultSets.push(resultSetFromHrana(hranaRows));
catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
// Map hrana errors to LibsqlError first, then wrap in LibsqlBatchError
const mappedError = mapHranaError(e);
if (mappedError instanceof LibsqlError) {
throw new LibsqlBatchError(mappedError.message, i, mappedError.code, mappedError.extendedCode, mappedError.rawCode, mappedError.cause instanceof Error
? mappedError.cause
: undefined);
}
throw mappedError;
}
}

@@ -281,3 +311,4 @@ await commitPromise;

const code = mapHranaErrorCode(e);
return new LibsqlError(e.message, code, undefined, e);
// TODO: Parse extendedCode once the SQL over HTTP protocol supports it
return new LibsqlError(e.message, code, undefined, undefined, e);
}

@@ -284,0 +315,0 @@ return e;

@@ -1,2 +0,1 @@

/// <reference types="node" />
import * as hrana from "@libsql/hrana-client";

@@ -17,3 +16,3 @@ import type { Config, Client } from "@libsql/core/api";

/** @private */
constructor(url: URL, authToken: string | undefined, intMode: IntMode, customFetch: Function | undefined, concurrency: number);
constructor(url: URL, authToken: string | undefined, intMode: IntMode, customFetch: Function | undefined, concurrency: number, remoteEncryptionKey: string | undefined);
private limit;

@@ -20,0 +19,0 @@ execute(stmtOrSql: InStatement | string, args?: InArgs): Promise<ResultSet>;

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

const url = encodeBaseUrl(config.scheme, config.authority, config.path);
return new HttpClient(url, config.authToken, config.intMode, config.fetch, config.concurrency);
return new HttpClient(url, config.authToken, config.intMode, config.fetch, config.concurrency, config.remoteEncryptionKey);
}

@@ -41,5 +41,6 @@ const sqlCacheCapacity = 30;

#authToken;
#remoteEncryptionKey;
#promiseLimitFunction;
/** @private */
constructor(url, authToken, intMode, customFetch, concurrency) {
constructor(url, authToken, intMode, customFetch, concurrency, remoteEncryptionKey) {
this.#url = url;

@@ -50,3 +51,4 @@ this.#authToken = authToken;

this.#concurrency = concurrency;
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch);
this.#remoteEncryptionKey = remoteEncryptionKey;
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch, remoteEncryptionKey);
this.#client.intMode = this.#intMode;

@@ -202,3 +204,3 @@ this.protocol = "http";

// Recreate the underlying hrana client
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch);
this.#client = hrana.openHttp(this.#url, this.#authToken, this.#customFetch, this.#remoteEncryptionKey);
this.#client.intMode = this.#intMode;

@@ -205,0 +207,0 @@ }

import Database from "libsql";
import { Buffer } from "node:buffer";
import { LibsqlError } from "@libsql/core/api";
import { LibsqlError, LibsqlBatchError } from "@libsql/core/api";
import { expandConfig, isInMemoryConfig } from "@libsql/core/config";

@@ -44,2 +44,3 @@ import { supportedUrlLink, transactionModeToBegin, ResultSetImpl, } from "@libsql/core/util";

encryptionKey: config.encryptionKey,
remoteEncryptionKey: config.remoteEncryptionKey,
syncUrl: config.syncUrl,

@@ -89,11 +90,24 @@ syncPeriod: config.syncInterval,

executeStmt(db, transactionModeToBegin(mode), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!db.inTransaction) {
throw new LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
if (!db.inTransaction) {
throw new LibsqlBatchError("The transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
const stmt = stmts[i];
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
resultSets.push(executeStmt(db, normalizedStmt, this.#intMode));
}
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
return executeStmt(db, normalizedStmt, this.#intMode);
});
catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
if (e instanceof LibsqlError) {
throw new LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
executeStmt(db, "COMMIT", this.#intMode);

@@ -114,8 +128,20 @@ return resultSets;

executeStmt(db, transactionModeToBegin("deferred"), this.#intMode);
const resultSets = stmts.map((stmt) => {
if (!db.inTransaction) {
throw new LibsqlError("The transaction has been rolled back", "TRANSACTION_CLOSED");
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
if (!db.inTransaction) {
throw new LibsqlBatchError("The transaction has been rolled back", i, "TRANSACTION_CLOSED");
}
resultSets.push(executeStmt(db, stmts[i], this.#intMode));
}
return executeStmt(db, stmt, this.#intMode);
});
catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
if (e instanceof LibsqlError) {
throw new LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
executeStmt(db, "COMMIT", this.#intMode);

@@ -211,9 +237,23 @@ return resultSets;

async batch(stmts) {
return stmts.map((stmt) => {
this.#checkNotClosed();
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
return executeStmt(this.#database, normalizedStmt, this.#intMode);
});
const resultSets = [];
for (let i = 0; i < stmts.length; i++) {
try {
this.#checkNotClosed();
const stmt = stmts[i];
const normalizedStmt = Array.isArray(stmt)
? { sql: stmt[0], args: stmt[1] || [] }
: stmt;
resultSets.push(executeStmt(this.#database, normalizedStmt, this.#intMode));
}
catch (e) {
if (e instanceof LibsqlBatchError) {
throw e;
}
if (e instanceof LibsqlError) {
throw new LibsqlBatchError(e.message, i, e.code, e.extendedCode, e.rawCode, e.cause instanceof Error ? e.cause : undefined);
}
throw e;
}
}
return resultSets;
}

@@ -396,5 +436,46 @@ async executeMultiple(sql) {

if (e instanceof Database.SqliteError) {
return new LibsqlError(e.message, e.code, e.rawCode, e);
const extendedCode = e.code;
const code = mapToBaseCode(e.rawCode);
return new LibsqlError(e.message, code, extendedCode, e.rawCode, e);
}
return e;
}
// Map SQLite raw error code to base error code string.
// Extended error codes are (base | (extended << 8)), so base = rawCode & 0xFF
function mapToBaseCode(rawCode) {
if (rawCode === undefined) {
return "SQLITE_UNKNOWN";
}
const baseCode = rawCode & 0xff;
return (sqliteErrorCodes[baseCode] ?? `SQLITE_UNKNOWN_${baseCode.toString()}`);
}
const sqliteErrorCodes = {
1: "SQLITE_ERROR",
2: "SQLITE_INTERNAL",
3: "SQLITE_PERM",
4: "SQLITE_ABORT",
5: "SQLITE_BUSY",
6: "SQLITE_LOCKED",
7: "SQLITE_NOMEM",
8: "SQLITE_READONLY",
9: "SQLITE_INTERRUPT",
10: "SQLITE_IOERR",
11: "SQLITE_CORRUPT",
12: "SQLITE_NOTFOUND",
13: "SQLITE_FULL",
14: "SQLITE_CANTOPEN",
15: "SQLITE_PROTOCOL",
16: "SQLITE_EMPTY",
17: "SQLITE_SCHEMA",
18: "SQLITE_TOOBIG",
19: "SQLITE_CONSTRAINT",
20: "SQLITE_MISMATCH",
21: "SQLITE_MISUSE",
22: "SQLITE_NOLFS",
23: "SQLITE_AUTH",
24: "SQLITE_FORMAT",
25: "SQLITE_RANGE",
26: "SQLITE_NOTADB",
27: "SQLITE_NOTICE",
28: "SQLITE_WARNING",
};

@@ -1,2 +0,1 @@

/// <reference types="node" />
import * as hrana from "@libsql/hrana-client";

@@ -3,0 +2,0 @@ import type { Config, IntMode, Client, Transaction, ResultSet, InStatement, InArgs, Replicated } from "@libsql/core/api";

{
"name": "@libsql/client",
"version": "0.15.15",
"version": "0.17.0",
"keywords": [

@@ -16,3 +16,3 @@ "libsql",

"type": "git",
"url": "git+https://github.com/libsql/libsql-client-ts",
"url": "git+https://github.com/tursodatabase/libsql-client-ts",
"directory": "packages/libsql-client"

@@ -107,4 +107,4 @@ },

"dependencies": {
"@libsql/core": "^0.15.14",
"@libsql/hrana-client": "^0.7.0",
"@libsql/core": "^0.17.0",
"@libsql/hrana-client": "^0.9.0",
"js-base64": "^3.7.5",

@@ -111,0 +111,0 @@ "libsql": "^0.5.22",