libsql-stateless-easy
Advanced tools
Comparing version 1.7.8 to 1.8.0
import { libsqlFetchLike, libsqlSQLValue, libsqlSQLStatement, libsqlBatchReqStepExecCond, libsqlBatchReqStep, libsqlStatementResOkData, libsqlBatchStreamResOkData } from 'libsql-stateless'; | ||
export { libsqlFetchLike } from 'libsql-stateless'; | ||
type rawValue = null | bigint | number | string | ArrayBuffer; | ||
type intMode = "bigint" | "number" | "string"; | ||
type rawSQL = string; | ||
type rawSQLArgs = Array<rawValue> | Record<string, rawValue>; | ||
type rawSQLStatement = { | ||
sql: rawSQL; | ||
args: rawSQLArgs; | ||
want_rows?: boolean; | ||
}; | ||
interface libsqlConfig { | ||
/** Configuration object for {@link createClient}. */ | ||
interface Config { | ||
/** The database URL. | ||
* | ||
* The client supports `http:`/`https:`. | ||
* The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more infomation, | ||
* please refer to the project README: | ||
* | ||
* https://github.com/libsql/libsql-client-ts#supported-urls | ||
*/ | ||
@@ -21,2 +16,13 @@ url: string; | ||
authToken?: string; | ||
/** Encryption key for the database. */ | ||
encryptionKey?: string; | ||
/** URL of a remote server to synchronize database with. */ | ||
syncUrl?: string; | ||
/** Sync interval in seconds. */ | ||
syncInterval?: number; | ||
/** Enables or disables TLS for `libsql:` URLs. | ||
* | ||
* By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS. | ||
*/ | ||
tls?: boolean; | ||
/** How to convert SQLite integers to JavaScript values: | ||
@@ -31,44 +37,318 @@ * | ||
*/ | ||
intMode?: intMode; | ||
/** Disables performing some critical checks to make sure the library works well. | ||
intMode?: IntMode; | ||
/** Custom `fetch` function to use for the HTTP client. | ||
* | ||
* By default, these checks are enabled. Set to true to disable. | ||
* By default, the HTTP client uses `fetch` from the `@libsql/isomorphic-fetch` package, but you can pass | ||
* your own function here. The argument to this function will be `Request` from | ||
* `@libsql/isomorphic-fetch`, and it must return a promise that resolves to an object that is compatible | ||
* with the Web `Response`. | ||
*/ | ||
fetch?: Function; | ||
/** Concurrency limit. | ||
* | ||
* These includes: | ||
* - Checking the Database URL is valid (appropriate protocol, etc) | ||
* - Checking if global fetch is available and functioning properly. | ||
* - Checking if the LibSQL server supports this client. | ||
* By default, the client performs up to 20 concurrent requests. You can set this option to a higher | ||
* number to increase the concurrency limit or set it to 0 to disable concurrency limits completely. | ||
*/ | ||
concurrency?: number | undefined; | ||
} | ||
/** Representation of integers from database as JavaScript values. See {@link Config.intMode}. */ | ||
type IntMode = "number" | "bigint" | "string"; | ||
/** Client object for a remote or local database. | ||
* | ||
* After you are done with the client, you **should** close it by calling {@link close}. | ||
*/ | ||
interface Client { | ||
/** Execute a single SQL statement. | ||
* | ||
* IF YOU ARE SURE ALL OF THESE ARE CORRECT, PLEASE DISABLE THESE CHECKS BY SETTING TO TRUE. | ||
* Every statement executed with this method is executed in its own logical database connection. If you | ||
* want to execute a group of statements in a transaction, use the {@link batch} or the {@link | ||
* transaction} methods. | ||
* | ||
* ```javascript | ||
* // execute a statement without arguments | ||
* const rs = await client.execute("SELECT * FROM books"); | ||
* | ||
* // execute a statement with positional arguments | ||
* const rs = await client.execute({ | ||
* sql: "SELECT * FROM books WHERE author = ?", | ||
* args: ["Jane Austen"], | ||
* }); | ||
* | ||
* // execute a statement with named arguments | ||
* const rs = await client.execute({ | ||
* sql: "SELECT * FROM books WHERE published_at > $year", | ||
* args: {year: 1719}, | ||
* }); | ||
* ``` | ||
*/ | ||
disableCriticalChecks?: boolean; | ||
/** Custom `fetch` function to use for the HTTP client.*/ | ||
fetch?: libsqlFetchLike; | ||
execute(stmt: InStatement): Promise<ResultSet$1>; | ||
/** Execute a batch of SQL statements in a transaction. | ||
* | ||
* The batch is executed in its own logical database connection and the statements are wrapped in a | ||
* transaction. This ensures that the batch is applied atomically: either all or no changes are applied. | ||
* | ||
* The `mode` parameter selects the transaction mode for the batch; please see {@link TransactionMode} for | ||
* details. The default transaction mode is `"deferred"`. | ||
* | ||
* If any of the statements in the batch fails with an error, the batch is aborted, the transaction is | ||
* rolled back and the returned promise is rejected. | ||
* | ||
* This method provides non-interactive transactions. If you need interactive transactions, please use the | ||
* {@link transaction} method. | ||
* | ||
* ```javascript | ||
* const rss = await client.batch([ | ||
* // batch statement without arguments | ||
* "DELETE FROM books WHERE name LIKE '%Crusoe'", | ||
* | ||
* // batch statement with positional arguments | ||
* { | ||
* sql: "INSERT INTO books (name, author, published_at) VALUES (?, ?, ?)", | ||
* args: ["First Impressions", "Jane Austen", 1813], | ||
* }, | ||
* | ||
* // batch statement with named arguments | ||
* { | ||
* sql: "UPDATE books SET name = $new WHERE name = $old", | ||
* args: {old: "First Impressions", new: "Pride and Prejudice"}, | ||
* }, | ||
* ], "write"); | ||
* ``` | ||
*/ | ||
batch(stmts: Array<InStatement>, mode?: TransactionMode): Promise<Array<ResultSet$1>>; | ||
/** Execute a batch of SQL statements in a transaction with PRAGMA foreign_keys=off; before and PRAGMA foreign_keys=on; after. | ||
* | ||
* The batch is executed in its own logical database connection and the statements are wrapped in a | ||
* transaction. This ensures that the batch is applied atomically: either all or no changes are applied. | ||
* | ||
* The transaction mode is `"deferred"`. | ||
* | ||
* If any of the statements in the batch fails with an error, the batch is aborted, the transaction is | ||
* rolled back and the returned promise is rejected. | ||
* | ||
* ```javascript | ||
* const rss = await client.migrate([ | ||
* // statement without arguments | ||
* "CREATE TABLE test (a INT)", | ||
* | ||
* // statement with positional arguments | ||
* { | ||
* sql: "INSERT INTO books (name, author, published_at) VALUES (?, ?, ?)", | ||
* args: ["First Impressions", "Jane Austen", 1813], | ||
* }, | ||
* | ||
* // statement with named arguments | ||
* { | ||
* sql: "UPDATE books SET name = $new WHERE name = $old", | ||
* args: {old: "First Impressions", new: "Pride and Prejudice"}, | ||
* }, | ||
* ]); | ||
* ``` | ||
*/ | ||
migrate(stmts: Array<InStatement>): Promise<Array<ResultSet$1>>; | ||
/** Start an interactive transaction. | ||
* | ||
* Interactive transactions allow you to interleave execution of SQL statements with your application | ||
* logic. They can be used if the {@link batch} method is too restrictive, but please note that | ||
* interactive transactions have higher latency. | ||
* | ||
* The `mode` parameter selects the transaction mode for the interactive transaction; please see {@link | ||
* TransactionMode} for details. The default transaction mode is `"deferred"`. | ||
* | ||
* You **must** make sure that the returned {@link Transaction} object is closed, by calling {@link | ||
* Transaction.close}, {@link Transaction.commit} or {@link Transaction.rollback}. The best practice is | ||
* to call {@link Transaction.close} in a `finally` block, as follows: | ||
* | ||
* ```javascript | ||
* const transaction = client.transaction("write"); | ||
* try { | ||
* // do some operations with the transaction here | ||
* await transaction.execute({ | ||
* sql: "INSERT INTO books (name, author) VALUES (?, ?)", | ||
* args: ["First Impressions", "Jane Austen"], | ||
* }); | ||
* await transaction.execute({ | ||
* sql: "UPDATE books SET name = ? WHERE name = ?", | ||
* args: ["Pride and Prejudice", "First Impressions"], | ||
* }); | ||
* | ||
* // if all went well, commit the transaction | ||
* await transaction.commit(); | ||
* } finally { | ||
* // make sure to close the transaction, even if an exception was thrown | ||
* transaction.close(); | ||
* } | ||
* ``` | ||
*/ | ||
transaction(mode?: TransactionMode): Promise<Transaction>; | ||
/** Start an interactive transaction in `"write"` mode. | ||
* | ||
* Please see {@link transaction} for details. | ||
* | ||
* @deprecated Please specify the `mode` explicitly. The default `"write"` will be removed in the next | ||
* major release. | ||
*/ | ||
transaction(): Promise<Transaction>; | ||
/** Execute a sequence of SQL statements separated by semicolons. | ||
* | ||
* The statements are executed sequentially on a new logical database connection. If a statement fails, | ||
* further statements are not executed and this method throws an error. All results from the statements | ||
* are ignored. | ||
* | ||
* We do not wrap the statements in a transaction, but the SQL can contain explicit transaction-control | ||
* statements such as `BEGIN` and `COMMIT`. | ||
* | ||
* This method is intended to be used with existing SQL scripts, such as migrations or small database | ||
* dumps. If you want to execute a sequence of statements programmatically, please use {@link batch} | ||
* instead. | ||
* | ||
* ```javascript | ||
* await client.executeMultiple(` | ||
* CREATE TABLE books (id INTEGER PRIMARY KEY, title TEXT NOT NULL, author_id INTEGER NOT NULL); | ||
* CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT NOT NULL); | ||
* `); | ||
* ``` | ||
*/ | ||
executeMultiple(sql: string): Promise<void>; | ||
sync(): Promise<Replicated>; | ||
/** Close the client and release resources. | ||
* | ||
* This method closes the client (aborting any operations that are currently in progress) and releases any | ||
* resources associated with the client (such as a WebSocket connection). | ||
*/ | ||
close(): void; | ||
/** Is the client closed? | ||
* | ||
* This is set to `true` after a call to {@link close} or if the client encounters an unrecoverable | ||
* error. | ||
*/ | ||
closed: boolean; | ||
/** Which protocol does the client use? | ||
* | ||
* - `"http"` if the client connects over HTTP | ||
* - `"ws"` if the client connects over WebSockets | ||
* - `"file"` if the client works with a local file | ||
*/ | ||
protocol: string; | ||
} | ||
/** Row returned from an SQL statement. | ||
/** Interactive transaction. | ||
* | ||
* The row object can be used as an `Array` or as an object: | ||
* A transaction groups multiple SQL statements together, so that they are applied atomically: either all | ||
* changes are applied, or none are. Other SQL statements on the database (including statements executed on | ||
* the same {@link Client} object outside of this transaction) will not see any changes from the transaction | ||
* until the transaction is committed by calling {@link commit}. You can also use {@link rollback} to abort | ||
* the transaction and roll back the changes. | ||
* | ||
* You **must** make sure that the {@link Transaction} object is closed, by calling {@link close}, {@link | ||
* commit} or {@link rollback}. The best practice is to call {@link close} in a `finally` block, as follows: | ||
* | ||
* ```javascript | ||
* const rs = await client.execute("SELECT name, title FROM books"); | ||
* for (const row in rs.rows) { | ||
* // Get the value from column `name` | ||
* console.log(row.name); | ||
* // Get the value from second column (`title`) | ||
* console.log(row[1]); | ||
* const transaction = client.transaction("write"); | ||
* try { | ||
* // do some operations with the transaction here | ||
* await transaction.execute({ | ||
* sql: "INSERT INTO books (name, author) VALUES (?, ?)", | ||
* args: ["First Impressions", "Jane Austen"], | ||
* }); | ||
* await transaction.execute({ | ||
* sql: "UPDATE books SET name = ? WHERE name = ?", | ||
* args: ["Pride and Prejudice", "First Impressions"], | ||
* }); | ||
* | ||
* // if all went well, commit the transaction | ||
* await transaction.commit(); | ||
* } finally { | ||
* // make sure to close the transaction, even if an exception was thrown | ||
* transaction.close(); | ||
* } | ||
* ``` | ||
*/ | ||
interface Row { | ||
/** Number of columns in this row. | ||
interface Transaction { | ||
/** Execute an SQL statement in this transaction. | ||
* | ||
* All rows in one {@link ResultSet} have the same number and names of columns. | ||
* If the statement makes any changes to the database, these changes won't be visible to statements | ||
* outside of this transaction until you call {@link rollback}. | ||
* | ||
* ```javascript | ||
* await transaction.execute({ | ||
* sql: "INSERT INTO books (name, author) VALUES (?, ?)", | ||
* args: ["First Impressions", "Jane Austen"], | ||
* }); | ||
* ``` | ||
*/ | ||
length: number; | ||
/** Columns can be accessed like an array by numeric indexes. */ | ||
[index: number]: rawValue; | ||
/** Columns can be accessed like an object by column names. */ | ||
[name: string]: rawValue; | ||
execute(stmt: InStatement): Promise<ResultSet$1>; | ||
/** Execute a batch of SQL statements in this transaction. | ||
* | ||
* If any of the statements in the batch fails with an error, further statements are not executed and the | ||
* returned promise is rejected with an error, but the transaction is not rolled back. | ||
*/ | ||
batch(stmts: Array<InStatement>): Promise<Array<ResultSet$1>>; | ||
/** Execute a sequence of SQL statements separated by semicolons. | ||
* | ||
* The statements are executed sequentially in the transaction. If a statement fails, further statements | ||
* are not executed and this method throws an error, but the transaction won't be rolled back. All results | ||
* from the statements are ignored. | ||
* | ||
* This method is intended to be used with existing SQL scripts, such as migrations or small database | ||
* dumps. If you want to execute statements programmatically, please use {@link batch} instead. | ||
*/ | ||
executeMultiple(sql: string): Promise<void>; | ||
/** Roll back any changes from this transaction. | ||
* | ||
* This method closes the transaction and undoes any changes done by the previous SQL statements on this | ||
* transaction. You cannot call this method after calling {@link commit}, though. | ||
*/ | ||
rollback(): Promise<void>; | ||
/** Commit changes from this transaction to the database. | ||
* | ||
* This method closes the transaction and applies all changes done by the previous SQL statement on this | ||
* transaction. Once the returned promise is resolved successfully, the database guarantees that the | ||
* changes were applied. | ||
*/ | ||
commit(): Promise<void>; | ||
/** Close the transaction. | ||
* | ||
* This method closes the transaction and releases any resources associated with the transaction. If the | ||
* transaction is already closed (perhaps by a previous call to {@link commit} or {@link rollback}), then | ||
* this method does nothing. | ||
* | ||
* If the transaction wasn't already committed by calling {@link commit}, the transaction is rolled | ||
* back. | ||
*/ | ||
close(): void; | ||
/** Is the transaction closed? | ||
* | ||
* This is set to `true` after a call to {@link close}, {@link commit} or {@link rollback}, or if we | ||
* encounter an unrecoverable error. | ||
*/ | ||
closed: boolean; | ||
} | ||
/** Transaction mode. | ||
* | ||
* The client supports multiple modes for transactions: | ||
* | ||
* - `"write"` is a read-write transaction, started with `BEGIN IMMEDIATE`. This transaction mode supports | ||
* both read statements (`SELECT`) and write statements (`INSERT`, `UPDATE`, `CREATE TABLE`, etc). The libSQL | ||
* server cannot process multiple write transactions concurrently, so if there is another write transaction | ||
* already started, our transaction will wait in a queue before it can begin. | ||
* | ||
* - `"read"` is a read-only transaction, started with `BEGIN TRANSACTION READONLY` (a libSQL extension). This | ||
* transaction mode supports only reads (`SELECT`) and will not accept write statements. The libSQL server can | ||
* handle multiple read transactions at the same time, so we don't need to wait for other transactions to | ||
* complete. A read-only transaction can also be executed on a local replica, so it provides lower latency. | ||
* | ||
* - `"deferred"` is a transaction started with `BEGIN DEFERRED`, which starts as a read transaction, but the | ||
* first write statement will try to upgrade it to a write transaction. However, this upgrade may fail if | ||
* there already is a write transaction executing on the server, so you should be ready to handle these | ||
* failures. | ||
* | ||
* If your transaction includes only read statements, `"read"` is always preferred over `"deferred"` or | ||
* `"write"`, because `"read"` transactions can be executed more efficiently and don't block other | ||
* transactions. | ||
* | ||
* If your transaction includes both read and write statements, you should be using the `"write"` mode most of | ||
* the time. Use the `"deferred"` mode only if you prefer to fail the write transaction instead of waiting for | ||
* the previous write transactions to complete. | ||
*/ | ||
type TransactionMode = "write" | "read" | "deferred"; | ||
/** Result of executing an SQL statement. | ||
@@ -87,3 +367,3 @@ * | ||
*/ | ||
interface ResultSet { | ||
interface ResultSet$1 { | ||
/** Names of columns. | ||
@@ -123,3 +403,57 @@ * | ||
toJSON(): any; | ||
} | ||
/** Row returned from an SQL statement. | ||
* | ||
* The row object can be used as an `Array` or as an object: | ||
* | ||
* ```javascript | ||
* const rs = await client.execute("SELECT name, title FROM books"); | ||
* for (const row in rs.rows) { | ||
* // Get the value from column `name` | ||
* console.log(row.name); | ||
* // Get the value from second column (`title`) | ||
* console.log(row[1]); | ||
* } | ||
* ``` | ||
*/ | ||
interface Row { | ||
/** Number of columns in this row. | ||
* | ||
* All rows in one {@link ResultSet} have the same number and names of columns. | ||
*/ | ||
length: number; | ||
/** Columns can be accessed like an array by numeric indexes. */ | ||
[index: number]: Value; | ||
/** Columns can be accessed like an object by column names. */ | ||
[name: string]: Value; | ||
} | ||
type Replicated = { | ||
frame_no: number; | ||
frames_synced: number; | ||
} | undefined; | ||
type Value = null | string | number | bigint | ArrayBuffer; | ||
type InValue = Value | boolean | Uint8Array | Date; | ||
type InStatement = { | ||
sql: string; | ||
args: InArgs; | ||
} | string; | ||
type InArgs = Array<InValue> | Record<string, InValue>; | ||
/** Error thrown by the client. */ | ||
declare class LibsqlError extends Error { | ||
/** Machine-readable error code. */ | ||
code: string; | ||
/** Raw numeric error code */ | ||
rawCode?: number; | ||
constructor(message: string, code: string, rawCode?: number, cause?: Error); | ||
} | ||
type rawSQL = string; | ||
type rawSQLStatement = { | ||
sql: rawSQL; | ||
args: InArgs; | ||
want_rows?: boolean; | ||
}; | ||
interface ResultSet extends ResultSet$1 { | ||
/** Rows read during processing query. | ||
* | ||
* Might not be available on older server versions. | ||
@@ -129,2 +463,3 @@ */ | ||
/** Rows written during processing query. | ||
* | ||
* Might not be available on older server versions. | ||
@@ -134,2 +469,3 @@ */ | ||
/** Wall time of work done by server. | ||
* | ||
* Might not be available on older server versions. | ||
@@ -139,34 +475,27 @@ */ | ||
} | ||
/** Transaction mode. | ||
* | ||
* The client supports multiple modes for transactions: | ||
* | ||
* - `"write"` is a read-write transaction, started with `BEGIN IMMEDIATE`. This transaction mode supports | ||
* both read statements (`SELECT`) and write statements (`INSERT`, `UPDATE`, `CREATE TABLE`, etc). The libSQL | ||
* server cannot process multiple write transactions concurrently, so if there is another write transaction | ||
* already started, our transaction will wait in a queue before it can begin. | ||
* | ||
* - `"read"` is a read-only transaction, started with `BEGIN TRANSACTION READONLY` (a libSQL extension). This | ||
* transaction mode supports only reads (`SELECT`) and will not accept write statements. The libSQL server can | ||
* handle multiple read transactions at the same time, so we don't need to wait for other transactions to | ||
* complete. A read-only transaction can also be executed on a local replica, so it provides lower latency. | ||
* | ||
* - `"deferred"` is a transaction started with `BEGIN DEFERRED`, which starts as a read transaction, but the | ||
* first write statement will try to upgrade it to a write transaction. However, this upgrade may fail if | ||
* there already is a write transaction executing on the server, so you should be ready to handle these | ||
* failures. | ||
* | ||
* If your transaction includes only read statements, `"read"` is always preferred over `"deferred"` or | ||
* `"write"`, because `"read"` transactions can be executed more efficiently and don't block other | ||
* transactions. | ||
* | ||
* If your transaction includes both read and write statements, you should be using the `"write"` mode most of | ||
* the time. Use the `"deferred"` mode only if you prefer to fail the write transaction instead of waiting for | ||
* the previous write transactions to complete. | ||
*/ | ||
type TransactionMode = "write" | "read" | "deferred"; | ||
interface libsqlConfig extends Config { | ||
/** Disables performing some critical checks to make sure the library works well. | ||
* | ||
* By default, these checks are enabled. Set to true to disable. | ||
* | ||
* These includes: | ||
* - Checking the Database URL is valid (appropriate protocol, etc) | ||
* - Checking if global fetch is available and functioning properly. | ||
* - Checking if the LibSQL server supports this client. | ||
* | ||
* IF YOU ARE SURE ALL OF THESE ARE CORRECT, PLEASE DISABLE THESE CHECKS BY SETTING TO TRUE. | ||
* | ||
*/ | ||
disableCriticalChecks?: boolean; | ||
/** Custom `fetch` function to use for the HTTP client. | ||
* | ||
* By default, the HTTP client uses `globalThis.fetch` but you can pass | ||
* your own function here. Check https://github.com/DaBigBlob/libsql-stateless-easy/#custom-fetch | ||
*/ | ||
fetch?: libsqlFetchLike; | ||
} | ||
declare function libsqlValueBuilder(value: rawValue): libsqlSQLValue; | ||
declare function libsqlArgumentsBuilder(a?: rawSQLArgs): Omit<libsqlSQLStatement, 'sql' | 'want_rows'>; | ||
declare function libsqlStatementBuilder(s: rawSQL | rawSQLStatement, or_a?: rawSQLArgs, or_want_rows?: boolean): libsqlSQLStatement; | ||
declare function libsqlValueBuilder(value: InValue): libsqlSQLValue; | ||
declare function libsqlArgumentsBuilder(a?: InArgs): Omit<libsqlSQLStatement, 'sql' | 'want_rows'>; | ||
declare function libsqlStatementBuilder(s: rawSQL | rawSQLStatement, or_a?: InArgs, or_want_rows?: boolean): libsqlSQLStatement; | ||
declare const libsqlBatchReqStepExecCondBuilder: { | ||
@@ -185,58 +514,21 @@ ok: (step: number) => libsqlBatchReqStepExecCond; | ||
declare function libsqlValueParser(value: libsqlSQLValue, intMode?: intMode): rawValue; | ||
declare function libsqlStatementResParser(res: libsqlStatementResOkData, intMode?: intMode): ResultSet; | ||
declare function libsqlBatchStreamResParser(res: libsqlBatchStreamResOkData, intMode?: intMode): Array<ResultSet | null>; | ||
declare function libsqlTransactionBatchStreamResParser(res: libsqlBatchStreamResOkData, intMode?: intMode): Array<ResultSet>; | ||
declare function libsqlValueParser(value: libsqlSQLValue, intMode?: IntMode): InValue; | ||
declare function libsqlStatementResParser(res: libsqlStatementResOkData, intMode?: IntMode): ResultSet; | ||
declare function libsqlBatchStreamResParser(res: libsqlBatchStreamResOkData, intMode?: IntMode): Array<ResultSet | null>; | ||
declare function libsqlTransactionBatchStreamResParser(res: libsqlBatchStreamResOkData, intMode?: IntMode): Array<ResultSet>; | ||
declare function libsqlExecute(conf: libsqlConfig, stmt_or_sql: rawSQL | rawSQLStatement, or_args?: rawSQLArgs, or_want_rows?: boolean): Promise<ResultSet>; | ||
declare function libsqlBatch(conf: libsqlConfig, steps: Array<rawSQL | rawSQLStatement>, step_conditions: Array<libsqlBatchReqStepExecCond | null | undefined>): Promise<Array<ResultSet | null>>; | ||
declare function libsqlExecute(conf: libsqlConfig, stmt_or_sql: rawSQL | rawSQLStatement, or_args?: InArgs, or_want_rows?: boolean): Promise<ResultSet>; | ||
declare function libsqlBatchWithoutTransaction(conf: libsqlConfig, steps: Array<rawSQL | rawSQLStatement>, step_conditions: Array<libsqlBatchReqStepExecCond | null | undefined>): Promise<Array<ResultSet | null>>; | ||
declare function libsqlServerCompatCheck(conf: libsqlConfig): Promise<boolean>; | ||
declare function libsqlBatchTransaction(conf: libsqlConfig, steps: Array<rawSQL | rawSQLStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>; | ||
declare function libsqlBatch(conf: libsqlConfig, steps: Array<rawSQL | rawSQLStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>; | ||
declare function libsqlMigrate(conf: libsqlConfig, stmts: Array<rawSQL | rawSQLStatement>): Promise<Array<ResultSet>>; | ||
declare function libsqlExecuteMultiple(conf: libsqlConfig, sql: string): Promise<undefined>; | ||
declare function createClient(conf: libsqlConfig): libsqlClient; | ||
declare class libsqlClient { | ||
declare class libsqlClient implements Client { | ||
private readonly conf; | ||
closed: boolean; | ||
/** Which protocol does the client use? | ||
* | ||
* - `"http"` if the client connects over HTTP | ||
* - `"ws"` if the client connects over WebSockets | ||
* - `"file"` if the client works with a local file | ||
*/ | ||
protocol: string; | ||
constructor(conf: libsqlConfig); | ||
/** Execute a single SQL statement. | ||
* | ||
* Every statement executed with this method is executed in its own logical database connection. If you | ||
* want to execute a group of statements in a transaction, use the {@link batch} method. | ||
* | ||
* ```javascript | ||
* // execute a statement without arguments | ||
* const rs = await client.execute("SELECT * FROM books"); | ||
* | ||
* // execute a statement with positional arguments | ||
* const rs = await client.execute( | ||
* "SELECT * FROM books WHERE author = ?", | ||
* ["Jane Austen"], | ||
* ); | ||
* // for backward compatibality | ||
* const rs = await client.execute({ | ||
* sql: "SELECT * FROM books WHERE author = ?", | ||
* args: ["Jane Austen"], | ||
* }); | ||
* | ||
* // execute a statement with named arguments | ||
* const rs = await client.execute( | ||
* "SELECT * FROM books WHERE published_at > $year", | ||
* {year: 1719}, | ||
* ); | ||
* // for backward compatibality | ||
* const rs = await client.execute({ | ||
* sql: "SELECT * FROM books WHERE published_at > $year", | ||
* args: {year: 1719}, | ||
* }); | ||
* ``` | ||
*/ | ||
execute(stmt: rawSQL, args?: rawSQLArgs, want_rows?: boolean): Promise<ResultSet>; | ||
execute(stmt: rawSQL, args?: InArgs, want_rows?: boolean): Promise<ResultSet>; | ||
execute(stmt: rawSQLStatement): Promise<ResultSet>; | ||
@@ -285,3 +577,4 @@ /** Execute a batch of SQL statements in a transaction. | ||
batchWithoutTransaction(steps: Array<rawSQL | rawSQLStatement>, step_conditions: Array<libsqlBatchReqStepExecCond | null | undefined>): Promise<(ResultSet | null)[]>; | ||
transaction(mode?: TransactionMode): Promise<any>; | ||
migrate(stmts: Array<rawSQL | rawSQLStatement>): Promise<ResultSet[]>; | ||
transaction(_mode?: TransactionMode): Promise<any>; | ||
/** Execute a sequence of SQL statements separated by semicolons. | ||
@@ -310,12 +603,6 @@ * | ||
executeMultiple(sql: string): Promise<undefined>; | ||
sync(): Promise<void>; | ||
sync(): Promise<any>; | ||
close(): void; | ||
} | ||
/** Error thrown by the client. */ | ||
declare class LibsqlError extends Error { | ||
/** Machine-readable error code. */ | ||
code: string; | ||
constructor(message: string, code: string, cause?: Error); | ||
} | ||
/** Error thrown when the server violates the protocol. */ | ||
@@ -340,2 +627,2 @@ declare class ProtoError extends LibsqlError { | ||
export { HttpServerError, LibsqlError, MisuseError, ProtoError, ResponseError, type ResultSet, type Row, type TransactionMode, createClient, type intMode, libsqlArgumentsBuilder, libsqlBatch, libsqlBatchReqStepExecCondBuilder, libsqlBatchReqStepsBuilder, libsqlBatchStreamResParser, libsqlBatchTransaction, libsqlClient, type libsqlConfig, libsqlExecute, libsqlExecuteMultiple, libsqlServerCompatCheck, libsqlStatementBuilder, libsqlStatementResParser, libsqlTransactionBatchReqStepsBuilder, libsqlTransactionBatchStreamResParser, libsqlTransactionBeginStatement, libsqlTransactionEndStatements, libsqlValueBuilder, libsqlValueParser, type rawSQL, type rawSQLArgs, type rawSQLStatement, type rawValue }; | ||
export { HttpServerError, LibsqlError, MisuseError, ProtoError, ResponseError, type ResultSet, type Row, type TransactionMode, type Client as clientInterface, createClient, type IntMode as intMode, libsqlArgumentsBuilder, libsqlBatch, libsqlBatchReqStepExecCondBuilder, libsqlBatchReqStepsBuilder, libsqlBatchStreamResParser, libsqlBatchWithoutTransaction, libsqlClient, type libsqlConfig, libsqlExecute, libsqlExecuteMultiple, libsqlMigrate, libsqlServerCompatCheck, libsqlStatementBuilder, libsqlStatementResParser, libsqlTransactionBatchReqStepsBuilder, libsqlTransactionBatchStreamResParser, libsqlTransactionBeginStatement, libsqlTransactionEndStatements, libsqlValueBuilder, libsqlValueParser, type rawSQL, type InArgs as rawSQLArgs, type rawSQLStatement, type InValue as rawValue }; |
import { libsqlExecute, libsqlBatch, libsqlServerCompatCheck } from 'libsql-stateless'; | ||
var et=Object.defineProperty;var rt=(t,e,r)=>e in t?et(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var u=(t,e,r)=>(rt(t,typeof e!="symbol"?e+"":e,r),r);var a=class extends Error{constructor(r,s,n){super(`${s}: ${r}`,{cause:n});u(this,"code");this.code=s,this.name="LibsqlError";}},b=class extends a{constructor(e){super(e,"HRANA_PROTO_ERROR"),this.name="ProtoError";}},p=class extends a{constructor(e,r){super(e,r??"UNKNOWN"),this.name="ResponseError",this.stack=void 0;}},d=class extends a{constructor(r,s){super(`HTTP code ${r}: ${s??"No error message from server."}`,"SERVER_ERROR");u(this,"http_status_code");this.http_status_code=r,this.name="HttpServerError";}},l=class extends a{constructor(e){super(e,"UNKNOWN"),this.name="MisuseError";}};var f=typeof Buffer=="function",E=typeof btoa=="function",L=typeof atob=="function",C=t=>atob(t),Q=t=>btoa(t),O=t=>Buffer.from(t).toString("base64"),T=t=>Buffer.from(t,"binary").toString("base64"),U=t=>Buffer.from(t,"base64"),M=t=>Buffer.from(t,"base64").toString("binary");var st="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=Array.prototype.slice.call(st),h=(t=>{let e={};return t.forEach((r,s)=>e[r]=s),e})(m),nt=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,ot=t=>{let e,r,s,n,o="",i=t.length%3;for(let c=0;c<t.length;){if((r=t.charCodeAt(c++))>255||(s=t.charCodeAt(c++))>255||(n=t.charCodeAt(c++))>255)throw new a("Invalid character found while polyfilling btoa","BTOA_POLYFILL_INVALID_CHAR");e=r<<16|s<<8|n,o+=m[e>>18&63]+m[e>>12&63]+m[e>>6&63]+m[e&63];}return i?o.slice(0,i-3)+"===".substring(i):o},at=E?t=>Q(t):f?t=>T(t):ot,S=String.fromCharCode.bind(String),I=f?t=>O(t):t=>{let r=[];for(let s=0,n=t.length;s<n;s+=4096){let o=[];t.subarray(s,s+4096).forEach(i=>o.push(i.valueOf())),r.push(S.apply(null,o));}return at(r.join(""))},P=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),it=t=>{if(t=t.replace(/\s+/g,""),!nt.test(t))throw new a("Malformed base64 while polyfilling atob","MALFORMED_BASE64_FOR_ATOB");t+="==".slice(2-(t.length&3));let e,r="",s,n;for(let o=0;o<t.length;)e=h[t.charAt(o++)]<<18|h[t.charAt(o++)]<<12|(s=h[t.charAt(o++)])<<6|(n=h[t.charAt(o++)]),r+=s===64?S(e>>16&255):n===64?S(e>>16&255,e>>8&255):S(e>>16&255,e>>8&255,e&255);return r},lt=L?t=>C(P(t)):f?t=>M(t):it,k=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),ct=f?t=>k(U(t)):t=>k(lt(t).split("").map(e=>e.charCodeAt(0))),ut=t=>P(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),v=t=>ct(ut(t));function N(t){if(t===null)return {type:"null"};if(typeof t=="bigint")return {type:"integer",value:""+t};if(typeof t=="number")return {type:"float",value:t};if(typeof t=="string")return {type:"text",value:t};if(t instanceof Uint8Array)return {type:"blob",base64:I(t)};throw new l("Invalid type of input. Cannot build request to server.")}function V(t){if(t===void 0)return {};if(Object.prototype.toString.call(t)==="[object Array]")return {args:t.map(e=>N(e))};{let e=[],r=t;for(let s in r)e.push({name:s,value:N(r[s])});return {named_args:e}}}function q(t,e,r){if(typeof t=="string"){let s=V(e);return {sql:t,args:s.args,named_args:s.named_args,want_rows:r}}else {let s=V(t.args);return {sql:t.sql,args:s.args,named_args:s.named_args,want_rows:t.want_rows}}}var g={ok:t=>({type:"ok",step:t}),error:t=>({type:"error",step:t}),not:t=>({type:"not",cond:t}),and:t=>({type:"and",conds:t}),or:t=>({type:"or",conds:t}),is_autocommit:()=>({type:"is_autocommit"})};function D(t,e){return t.map((r,s)=>({stmt:q(r),condition:e[s]??void 0}))}function pt(t){if(t==="write")return {stmt:{sql:"BEGIN IMMEDIATE"}};if(t==="read")return {stmt:{sql:"BEGIN TRANSACTION READONLY"}};if(t==="deferred")return {stmt:{sql:"BEGIN DEFERRED"}};throw RangeError('Unknown transaction mode, supported values are "write", "read" and "deferred"')}function ft(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function j(t,e){let r=t.map((s,n)=>({stmt:q(s),condition:g.ok(n)}));return [pt(e)].concat(r).concat(ft(r.length))}function mt(t,e="number"){switch(e){case"number":return +t;case"string":return t;case"bigint":return BigInt(t);default:throw new l('Invalid value for "intMode".')}}function bt(t,e){switch(t.type){case"null":return null;case"integer":return mt(t.value,e);case"float":return Number(t.value);case"text":return t.value;case"blob":return v(t.base64);default:throw new b("Invalid data type from server. Cannot parse.")}}function R(t,e){let r=[];for(let n=0;n<t.rows.length;n++){let o={};Object.defineProperty(o,"length",{value:t.rows[n].length});for(let i=0;i<t.rows[n].length;i++){let c=bt(t.rows[n][i],e);Object.defineProperty(o,i,{value:c});let w=t.cols[i].name;w!==void 0&&!Object.hasOwn(o,w)&&Object.defineProperty(o,w,{value:c,enumerable:!0,configurable:!0,writable:!0});}r.push(o);}let s={rows:r,columns:t.cols.map(n=>n.name??""),columnTypes:t.cols.map(n=>n.decltype??""),rowsAffected:t.affected_row_count,lastInsertRowid:t.last_insert_rowid?BigInt(t.last_insert_rowid):void 0,rowsRead:t.rows_read,rowsWritten:t.rows_written,queryDurationMS:t.query_duration_ms};return {...s,toJSON:()=>s}}function _(t,e){return t.step_results.map((r,s)=>{var n,o;if(r)return R(r,e);if(t.step_errors[s])throw new p((n=t.step_errors[s])==null?void 0:n.message,(o=t.step_errors[s])==null?void 0:o.code);return null})}function H(t,e){let r=_(t,e);return r.slice(1,r.length-2).filter(s=>s!==null)}function y(t){return t.kind==="LIBSQL_SERVER_ERROR"?new d(t.http_status_code,t.server_message):new p(t.data.message,t.data.code)}async function F(t,e,r,s){let n=await libsqlExecute(t,q(e,r,s));if(n.isOk)return R(n.val,t.intMode);throw y(n.err)}async function W(t,e,r){let s=await libsqlBatch(t,D(e,r));if(s.isOk)return _(s.val,t.intMode);throw y(s.err)}async function z(t){return (await libsqlServerCompatCheck(t)).isOk}async function K(t,e,r="deferred"){let s=await libsqlBatch(t,j(e,r));if(s.isOk)return H(s.val,t.intMode);throw y(s.err)}async function Z(t,e){let r=e.split(";").filter(n=>n.trim()!=="").map((n,o)=>({stmt:{sql:n},condition:g.ok(o-1)}));r[0].condition=void 0;let s=await libsqlBatch(t,r);if(!s.isOk)throw y(s.err)}var $=typeof console.error=="function",G=typeof URL=="function",J=t=>console.error(t),Y=t=>new URL(t);function X(t){try{if(!z(t))throw new a("Server incompatible. Please upgrade your libSQL server.","OUT_OF_DATE_SERVER")}catch{throw new a("The fetch function is non functional.","FETCH_FUCKED")}}function x(t){$&&J(t);}function tt(t){if((()=>{if(G)try{let r=Y(t);return !(r.protocol==="https:"||r.protocol==="http:")}catch(r){throw new a(r.message,"ERR_INVALID_URL",r)}else if(t.startsWith("https://")||t.startsWith("http://"))return !1;return !0})())throw new a('This is a HTTP client and only supports "https:" and "http:" URLs. For modern libsql DBs simply changing "libsql://" to "https://" should resolve this.',"URL_SCHEME_NOT_SUPPORTED")}function Ht(t){return new A(t)}var A=class{constructor(e){u(this,"conf");u(this,"closed");u(this,"protocol");e.disableCriticalChecks||(tt(e.url),X(e)),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e,r,s){return await F(this.conf,e,r,s)}async batch(e,r){return await K(this.conf,e,r)}async batchWithoutTransaction(e,r){return await W(this.conf,e,r)}async transaction(e){throw new l("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await Z(this.conf,e)}async sync(){x("'libsql-stateless' is remote only so nothing to sync.");}close(){x("'libsql-stateless' is stateless therefore no connection to close.");}}; | ||
var nt=Object.defineProperty;var st=(t,e,r)=>e in t?nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var l=(t,e,r)=>(st(t,typeof e!="symbol"?e+"":e,r),r);var a=class extends Error{constructor(r,n,s,o){n!==void 0&&(r=`${n}: ${r}`);super(r,{cause:o});l(this,"code");l(this,"rawCode");this.code=n,this.rawCode=s,this.name="LibsqlError";}};var y=class extends a{constructor(e){super(e,"HRANA_PROTO_ERROR"),this.name="ProtoError";}},f=class extends a{constructor(e,r){super(e,r??"UNKNOWN"),this.name="ResponseError",this.stack=void 0;}},h=class extends a{constructor(r,n){super(`HTTP code ${r}: ${n??"No error message from server."}`,"SERVER_ERROR");l(this,"http_status_code");this.http_status_code=r,this.name="HttpServerError";}},c=class extends a{constructor(e){super(e,"UNKNOWN"),this.name="MisuseError";}};var b=typeof Buffer=="function",C=typeof btoa=="function",I=typeof atob=="function",Q=t=>atob(t),M=t=>btoa(t),T=t=>Buffer.from(t).toString("base64"),O=t=>Buffer.from(t,"binary").toString("base64"),P=t=>Buffer.from(t,"base64"),U=t=>Buffer.from(t,"base64").toString("binary");var ot="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d=Array.prototype.slice.call(ot),S=(t=>{let e={};return t.forEach((r,n)=>e[r]=n),e})(d),at=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,it=t=>{let e,r,n,s,o="",i=t.length%3;for(let p=0;p<t.length;){if((r=t.charCodeAt(p++))>255||(n=t.charCodeAt(p++))>255||(s=t.charCodeAt(p++))>255)throw new a("Invalid character found while polyfilling btoa","BTOA_POLYFILL_INVALID_CHAR");e=r<<16|n<<8|s,o+=d[e>>18&63]+d[e>>12&63]+d[e>>6&63]+d[e&63];}return i?o.slice(0,i-3)+"===".substring(i):o},lt=C?t=>M(t):b?t=>O(t):it,g=String.fromCharCode.bind(String),A=b?t=>T(t):t=>{let r=[];for(let n=0,s=t.length;n<s;n+=4096){let o=[];t.subarray(n,n+4096).forEach(i=>o.push(i.valueOf())),r.push(g.apply(null,o));}return lt(r.join(""))},v=t=>t.replace(/[^A-Za-z0-9\+\/]/g,""),ct=t=>{if(t=t.replace(/\s+/g,""),!at.test(t))throw new a("Malformed base64 while polyfilling atob","MALFORMED_BASE64_FOR_ATOB");t+="==".slice(2-(t.length&3));let e,r="",n,s;for(let o=0;o<t.length;)e=S[t.charAt(o++)]<<18|S[t.charAt(o++)]<<12|(n=S[t.charAt(o++)])<<6|(s=S[t.charAt(o++)]),r+=n===64?g(e>>16&255):s===64?g(e>>16&255,e>>8&255):g(e>>16&255,e>>8&255,e&255);return r},ut=I?t=>Q(v(t)):b?t=>U(t):ct,k=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):t=>new Uint8Array(Array.prototype.slice.call(t,0)),pt=b?t=>k(P(t)):t=>k(ut(t).split("").map(e=>e.charCodeAt(0))),ft=t=>v(t.replace(/[-_]/g,e=>e=="-"?"+":"/")),V=t=>pt(ft(t));function N(t){if(t===null)return {type:"null"};if(typeof t=="string")return {type:"text",value:t};if(typeof t=="number"){if(!Number.isFinite(t))throw new RangeError("Only finite numbers (not Infinity or NaN) can be passed as arguments");return {type:"float",value:t}}if(typeof t=="bigint"){if(t<-9223372036854775808n||t>9223372036854775807n)throw new RangeError("This bigint value is too large to be represented as a 64-bit integer and passed as argument");return {type:"integer",value:""+t}}if(typeof t=="boolean")return {type:"integer",value:""+(t?1n:0n)};if(t instanceof ArrayBuffer)return {type:"blob",base64:A(new Uint8Array(t))};if(t instanceof Uint8Array)return {type:"blob",base64:A(t)};if(t instanceof Date)return {type:"float",value:+t.valueOf()};throw new c("Invalid type of input. Cannot build request to server.")}function D(t){if(t===void 0)return {};if(Object.prototype.toString.call(t)==="[object Array]")return {args:t.map(e=>N(e))};{let e=[],r=t;for(let n in r)e.push({name:n,value:N(r[n])});return {named_args:e}}}function w(t,e,r){if(typeof t=="string"){let n=D(e);return {sql:t,args:n.args,named_args:n.named_args,want_rows:r}}else {let n=D(t.args);return {sql:t.sql,args:n.args,named_args:n.named_args,want_rows:t.want_rows}}}var m={ok:t=>({type:"ok",step:t}),error:t=>({type:"error",step:t}),not:t=>({type:"not",cond:t}),and:t=>({type:"and",conds:t}),or:t=>({type:"or",conds:t}),is_autocommit:()=>({type:"is_autocommit"})};function j(t,e){return t.map((r,n)=>({stmt:w(r),condition:e[n]??void 0}))}function mt(t){if(t==="write")return {stmt:{sql:"BEGIN IMMEDIATE"}};if(t==="read")return {stmt:{sql:"BEGIN TRANSACTION READONLY"}};if(t==="deferred")return {stmt:{sql:"BEGIN DEFERRED"}};throw RangeError('Unknown transaction mode, supported values are "write", "read" and "deferred"')}function bt(t){return [{stmt:{sql:"COMMIT"},condition:{type:"ok",step:t}},{stmt:{sql:"ROLLBACK"},condition:{type:"not",cond:{type:"ok",step:t+1}}}]}function F(t,e){let r=t.map((n,s)=>({stmt:w(n),condition:m.and([m.ok(s),m.not(m.is_autocommit())])}));return [mt(e)].concat(r).concat(bt(r.length))}function dt(t,e="number"){switch(t.type){case"null":return null;case"integer":switch(e){case"number":{let r=Number(t.value);if(!Number.isSafeInteger(r))throw new RangeError("Received integer which is too large to be safely represented as a JavaScript number");return r}case"bigint":return BigInt(t.value);case"string":return t.value;default:throw new c('Invalid value for "intMode".')}case"float":return t.value;case"text":return t.value;case"blob":return V(t.base64).slice().buffer;default:throw new y("Invalid data type from server. Cannot parse.")}}function x(t,e){let r=[];for(let s=0;s<t.rows.length;s++){let o={};Object.defineProperty(o,"length",{value:t.rows[s].length});for(let i=0;i<t.rows[s].length;i++){let p=dt(t.rows[s][i],e);Object.defineProperty(o,i,{value:p});let R=t.cols[i].name;R!==void 0&&!Object.hasOwn(o,R)&&Object.defineProperty(o,R,{value:p,enumerable:!0,configurable:!0,writable:!0});}r.push(o);}let n={rows:r,columns:t.cols.map(s=>s.name??""),columnTypes:t.cols.map(s=>s.decltype??""),rowsAffected:t.affected_row_count,lastInsertRowid:t.last_insert_rowid?BigInt(t.last_insert_rowid):void 0,rowsRead:t.rows_read,rowsWritten:t.rows_written,queryDurationMS:t.query_duration_ms};return {...n,toJSON:()=>n}}function _(t,e){return t.step_results.map((r,n)=>{var s,o;if(r)return x(r,e);if(t.step_errors[n])throw new f((s=t.step_errors[n])==null?void 0:s.message,(o=t.step_errors[n])==null?void 0:o.code);return null})}function H(t,e){let r=_(t,e);return r.slice(1,r.length-2).filter(n=>n!==null)}function q(t){return t.kind==="LIBSQL_SERVER_ERROR"?new h(t.http_status_code,t.server_message):new f(t.data.message,t.data.code)}async function W(t,e,r,n){let s=await libsqlExecute(t,w(e,r,n));if(s.isOk)return x(s.val,t.intMode);throw q(s.err)}async function K(t,e,r){let n=await libsqlBatch(t,j(e,r));if(n.isOk)return _(n.val,t.intMode);throw q(n.err)}async function G(t){return (await libsqlServerCompatCheck(t)).isOk}async function L(t,e,r="deferred"){let n=await libsqlBatch(t,F(e,r));if(n.isOk)return H(n.val,t.intMode);throw q(n.err)}async function z(t,e){return L(t,["PRAGMA foreign_keys=off"].concat(e).concat("PRAGMA foreign_keys=on"),"deferred")}async function J(t,e){let r=e.split(";").filter(s=>s.trim()!=="").map((s,o)=>({stmt:{sql:s},condition:m.ok(o-1)}));r[0].condition=void 0;let n=await libsqlBatch(t,r);if(!n.isOk)throw q(n.err)}var Z=typeof console.error=="function",$=typeof URL=="function",Y=t=>console.error(t),X=t=>new URL(t);function tt(t){try{if(!G(t))throw new a("Server incompatible. Please upgrade your libSQL server.","OUT_OF_DATE_SERVER")}catch{throw new a("The fetch function is non functional.","FETCH_FUCKED")}}function u(t){Z&&Y(t);}function et(t){if((()=>{if($)try{let r=X(t);return !(r.protocol==="https:"||r.protocol==="http:")}catch(r){throw new a(r.message,"ERR_INVALID_URL",void 0,r)}else if(t.startsWith("https://")||t.startsWith("http://"))return !1;return !0})())throw new a('This is a HTTP client and only supports "https:" and "http:" URLs. For modern libsql DBs simply changing "libsql://" to "https://" should resolve this.',"URL_SCHEME_NOT_SUPPORTED")}function rt(t){t.encryptionKey&&u("'encryptionKey' config unsupported."),t.syncUrl&&u("'syncUrl' config unsupported because 'url' is the remote url. (embedded replicas unsupported)"),t.syncInterval&&u("'syncInterval' config unsupported because nothing to sync. (embedded replicas unsupported)"),t.tls&&u("'tls' config unsupported. Change url scheme to 'http' for no tls and 'https' for tls."),t.concurrency&&u("'concurrency' config unsupported. You may use a custom fetch to specify concurrency.");}function Jt(t){return new E(t)}var E=class{constructor(e){l(this,"conf");l(this,"closed");l(this,"protocol");e.disableCriticalChecks||(et(e.url),tt(e),rt(e)),this.conf=e,this.closed=!1,this.protocol="http";}async execute(e,r,n){return await W(this.conf,e,r,n)}async batch(e,r){return await L(this.conf,e,r)}async batchWithoutTransaction(e,r){return await K(this.conf,e,r)}async migrate(e){return await z(this.conf,e)}async transaction(e){throw new c("'libsql-stateless' is stateless and does not support interactive transactions. Use this.batch() instead.")}async executeMultiple(e){return await J(this.conf,e)}async sync(){u("'libsql-stateless' is remote only so nothing to sync.");}close(){u("'libsql-stateless' is stateless therefore no connection to close.");}}; | ||
export { d as HttpServerError, a as LibsqlError, l as MisuseError, b as ProtoError, p as ResponseError, Ht as createClient, V as libsqlArgumentsBuilder, W as libsqlBatch, g as libsqlBatchReqStepExecCondBuilder, D as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, K as libsqlBatchTransaction, A as libsqlClient, F as libsqlExecute, Z as libsqlExecuteMultiple, z as libsqlServerCompatCheck, q as libsqlStatementBuilder, R as libsqlStatementResParser, j as libsqlTransactionBatchReqStepsBuilder, H as libsqlTransactionBatchStreamResParser, pt as libsqlTransactionBeginStatement, ft as libsqlTransactionEndStatements, N as libsqlValueBuilder, bt as libsqlValueParser }; | ||
export { h as HttpServerError, a as LibsqlError, c as MisuseError, y as ProtoError, f as ResponseError, Jt as createClient, D as libsqlArgumentsBuilder, L as libsqlBatch, m as libsqlBatchReqStepExecCondBuilder, j as libsqlBatchReqStepsBuilder, _ as libsqlBatchStreamResParser, K as libsqlBatchWithoutTransaction, E as libsqlClient, W as libsqlExecute, J as libsqlExecuteMultiple, z as libsqlMigrate, G as libsqlServerCompatCheck, w as libsqlStatementBuilder, x as libsqlStatementResParser, F as libsqlTransactionBatchReqStepsBuilder, H as libsqlTransactionBatchStreamResParser, mt as libsqlTransactionBeginStatement, bt as libsqlTransactionEndStatements, N as libsqlValueBuilder, dt as libsqlValueParser }; |
{ | ||
"name": "libsql-stateless-easy", | ||
"version": "1.7.8", | ||
"version": "1.8.0", | ||
"description": "thin libSQL stateless http driver for TypeScript and JavaScript but easy", | ||
@@ -66,4 +66,4 @@ "homepage": "https://github.com/DaBigBlob/libsql-stateless-easy#readme", | ||
"dependencies": { | ||
"libsql-stateless": "^2.9.1" | ||
"libsql-stateless": "2.9.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58873
706
1
Updatedlibsql-stateless@2.9.1