@tursodatabase/serverless 1.2.0-pre.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ export declare class AsyncLock {
2
+ private locked;
3
+ private queue;
4
+ acquire(): Promise<void>;
5
+ release(): void;
6
+ }
@@ -0,0 +1,22 @@
1
+ export class AsyncLock {
2
+ constructor() {
3
+ this.locked = false;
4
+ this.queue = [];
5
+ }
6
+ async acquire() {
7
+ if (!this.locked) {
8
+ this.locked = true;
9
+ return;
10
+ }
11
+ return new Promise(resolve => { this.queue.push(resolve); });
12
+ }
13
+ release() {
14
+ const next = this.queue.shift();
15
+ if (next) {
16
+ next();
17
+ }
18
+ else {
19
+ this.locked = false;
20
+ }
21
+ }
22
+ }
@@ -1,147 +1 @@
1
- /**
2
- * Configuration options for creating a libSQL-compatible client.
3
- *
4
- * @remarks
5
- * This interface matches the libSQL client configuration. The `url`, `authToken`, and
6
- * `remoteEncryptionKey` options are supported in the serverless compatibility layer.
7
- * Other options will throw validation errors.
8
- */
9
- interface Config {
10
- /** Database URL (required) */
11
- url: string;
12
- /** Authentication token for the database */
13
- authToken?: string;
14
- /** @deprecated Local database encryption key - not supported in serverless mode */
15
- encryptionKey?: string;
16
- /**
17
- * Encryption key for the remote database (base64 encoded)
18
- * to enable access to encrypted Turso Cloud databases.
19
- */
20
- remoteEncryptionKey?: string;
21
- /** @deprecated Sync server URL - not supported in serverless mode */
22
- syncUrl?: string;
23
- /** @deprecated Sync frequency in seconds - not supported in serverless mode */
24
- syncInterval?: number;
25
- /** @deprecated Consistency mode - not supported in serverless mode */
26
- readYourWrites?: boolean;
27
- /** @deprecated Offline mode support - not supported in serverless mode */
28
- offline?: boolean;
29
- /** @deprecated TLS settings - not supported in serverless mode */
30
- tls?: boolean;
31
- /** @deprecated Integer handling mode - not supported in serverless mode */
32
- intMode?: "number" | "bigint" | "string";
33
- /** @deprecated Custom fetch implementation - not supported in serverless mode */
34
- fetch?: Function;
35
- /** @deprecated Concurrent request limit - not supported in serverless mode */
36
- concurrency?: number;
37
- }
38
- /** Input value types accepted by libSQL statements */
39
- type InValue = null | string | number | bigint | ArrayBuffer | boolean | Uint8Array | Date;
40
- /** Input arguments - either positional array or named object */
41
- type InArgs = Array<InValue> | Record<string, InValue>;
42
- /** Input statement - either SQL string or object with sql and args */
43
- type InStatement = {
44
- sql: string;
45
- args?: InArgs;
46
- } | string;
47
- /** Transaction execution modes */
48
- type TransactionMode = "write" | "read" | "deferred";
49
- /**
50
- * A result row that can be accessed both as an array and as an object.
51
- * Supports both numeric indexing (row[0]) and column name access (row.column_name).
52
- */
53
- interface Row {
54
- length: number;
55
- [index: number]: InValue;
56
- [name: string]: InValue;
57
- }
58
- /**
59
- * Result set returned from SQL statement execution.
60
- */
61
- interface ResultSet {
62
- /** Column names in the result set */
63
- columns: Array<string>;
64
- /** Column type information */
65
- columnTypes: Array<string>;
66
- /** Result rows */
67
- rows: Array<Row>;
68
- /** Number of rows affected by the statement */
69
- rowsAffected: number;
70
- /** ID of the last inserted row (for INSERT statements) */
71
- lastInsertRowid: bigint | undefined;
72
- /** Convert result set to JSON */
73
- toJSON(): any;
74
- }
75
- /**
76
- * libSQL-compatible error class with error codes.
77
- */
78
- declare class LibsqlError extends Error {
79
- /** Machine-readable error code (e.g., "SQLITE_CONSTRAINT") */
80
- code: string;
81
- /** Extended error code with more specific information (e.g., "SQLITE_CONSTRAINT_PRIMARYKEY") */
82
- extendedCode?: string;
83
- /** Raw numeric error code (if available) */
84
- rawCode?: number;
85
- /** Original error that caused this error */
86
- cause?: Error;
87
- constructor(message: string, code: string, extendedCode?: string, rawCode?: number, cause?: Error);
88
- }
89
- /**
90
- * Interactive transaction interface.
91
- *
92
- * @remarks
93
- * A transaction keeps a dedicated session open until commit/rollback/close.
94
- */
95
- interface Transaction {
96
- execute(stmt: InStatement): Promise<ResultSet>;
97
- batch(stmts: Array<InStatement>): Promise<Array<ResultSet>>;
98
- executeMultiple(sql: string): Promise<void>;
99
- commit(): Promise<void>;
100
- rollback(): Promise<void>;
101
- close(): void;
102
- closed: boolean;
103
- }
104
- /**
105
- * libSQL-compatible client interface.
106
- *
107
- * This interface matches the standard libSQL client API for drop-in compatibility.
108
- * Some methods are not implemented in the serverless compatibility layer.
109
- */
110
- interface Client {
111
- execute(stmt: InStatement): Promise<ResultSet>;
112
- execute(sql: string, args?: InArgs): Promise<ResultSet>;
113
- batch(stmts: Array<InStatement>, mode?: TransactionMode): Promise<Array<ResultSet>>;
114
- migrate(stmts: Array<InStatement>): Promise<Array<ResultSet>>;
115
- transaction(mode?: TransactionMode): Promise<Transaction>;
116
- executeMultiple(sql: string): Promise<void>;
117
- sync(): Promise<any>;
118
- close(): void;
119
- closed: boolean;
120
- protocol: string;
121
- }
122
- /**
123
- * Create a libSQL-compatible client for Turso database access.
124
- *
125
- * This function provides compatibility with the standard libSQL client API
126
- * while using the Turso serverless driver under the hood.
127
- *
128
- * @param config - Configuration object (only url and authToken are supported)
129
- * @returns A Client instance compatible with libSQL API
130
- * @throws LibsqlError if unsupported configuration options are provided
131
- *
132
- * @example
133
- * ```typescript
134
- * import { createClient } from "@tursodatabase/serverless/compat";
135
- *
136
- * const client = createClient({
137
- * url: process.env.TURSO_DATABASE_URL,
138
- * authToken: process.env.TURSO_AUTH_TOKEN
139
- * });
140
- *
141
- * const result = await client.execute("SELECT * FROM users");
142
- * console.log(result.rows);
143
- * ```
144
- */
145
- declare function createClient(config: Config): Client;
146
-
147
- export { type Client, type Config, type InArgs, type InStatement, type InValue, LibsqlError, type ResultSet, type Row, type Transaction, type TransactionMode, createClient };
1
+ export * from '../compat.js';