@mastra/turso 0.1.2 → 0.1.3-alpha.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.
package/dist/index.cjs CHANGED
@@ -1,350 +1,334 @@
1
- 'use strict';
2
-
3
- var libsql = require('@mastra/libsql');
4
- var detectLibc = require('detect-libc');
5
-
6
- // src/index.ts
7
-
8
- // src/client.ts
9
- var ROLLBACK = /* @__PURE__ */ Symbol("turso-transaction-rollback");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _mastra_libsql = require("@mastra/libsql");
3
+ let detect_libc = require("detect-libc");
4
+ //#region src/client.ts
5
+ const ROLLBACK = Symbol("turso-transaction-rollback");
10
6
  var TursoSqliteError = class extends Error {
11
- code;
12
- rawCode;
13
- constructor(error, code) {
14
- super(error.message, { cause: error });
15
- this.name = "TursoSqliteError";
16
- this.code = code;
17
- const rawCode = error.rawCode;
18
- if (typeof rawCode === "number") this.rawCode = rawCode;
19
- }
7
+ code;
8
+ rawCode;
9
+ constructor(error, code) {
10
+ super(error.message, { cause: error });
11
+ this.name = "TursoSqliteError";
12
+ this.code = code;
13
+ const rawCode = error.rawCode;
14
+ if (typeof rawCode === "number") this.rawCode = rawCode;
15
+ }
20
16
  };
21
17
  function normalizeError(error) {
22
- if (!(error instanceof Error)) return error;
23
- const code = error.code;
24
- if (typeof code === "string" && code.startsWith("SQLITE_")) return error;
25
- const message = error.message.toLowerCase();
26
- if (message.includes("unique constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_UNIQUE");
27
- if (message.includes("primary key constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_PRIMARYKEY");
28
- if (message.includes("not null constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_NOTNULL");
29
- if (message.includes("foreign key constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_FOREIGNKEY");
30
- if (message.includes("check constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_CHECK");
31
- if (message.includes("database is locked") || message.includes("database is busy")) {
32
- return new TursoSqliteError(error, "SQLITE_BUSY");
33
- }
34
- return error;
18
+ if (!(error instanceof Error)) return error;
19
+ const code = error.code;
20
+ if (typeof code === "string" && code.startsWith("SQLITE_")) return error;
21
+ const message = error.message.toLowerCase();
22
+ if (message.includes("unique constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_UNIQUE");
23
+ if (message.includes("primary key constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_PRIMARYKEY");
24
+ if (message.includes("not null constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_NOTNULL");
25
+ if (message.includes("foreign key constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_FOREIGNKEY");
26
+ if (message.includes("check constraint")) return new TursoSqliteError(error, "SQLITE_CONSTRAINT_CHECK");
27
+ if (message.includes("database is locked") || message.includes("database is busy")) return new TursoSqliteError(error, "SQLITE_BUSY");
28
+ return error;
35
29
  }
36
30
  function deferred() {
37
- let resolve;
38
- let reject;
39
- const promise = new Promise((resolvePromise, rejectPromise) => {
40
- resolve = resolvePromise;
41
- reject = rejectPromise;
42
- });
43
- return { promise, resolve, reject };
31
+ let resolve;
32
+ let reject;
33
+ return {
34
+ promise: new Promise((resolvePromise, rejectPromise) => {
35
+ resolve = resolvePromise;
36
+ reject = rejectPromise;
37
+ }),
38
+ resolve,
39
+ reject
40
+ };
44
41
  }
45
42
  var AsyncMutex = class {
46
- #tail = Promise.resolve();
47
- async acquire() {
48
- const previous = this.#tail;
49
- const next = deferred();
50
- this.#tail = previous.then(
51
- () => next.promise,
52
- () => next.promise
53
- );
54
- await previous;
55
- let released = false;
56
- return () => {
57
- if (released) return;
58
- released = true;
59
- next.resolve();
60
- };
61
- }
43
+ #tail = Promise.resolve();
44
+ async acquire() {
45
+ const previous = this.#tail;
46
+ const next = deferred();
47
+ this.#tail = previous.then(() => next.promise, () => next.promise);
48
+ await previous;
49
+ let released = false;
50
+ return () => {
51
+ if (released) return;
52
+ released = true;
53
+ next.resolve();
54
+ };
55
+ }
62
56
  };
63
57
  function normalizeInput(value) {
64
- if (typeof value === "boolean") return value ? 1 : 0;
65
- if (value instanceof Date) return value.toISOString();
66
- if (value instanceof ArrayBuffer) return new Uint8Array(value);
67
- return value;
58
+ if (typeof value === "boolean") return value ? 1 : 0;
59
+ if (value instanceof Date) return value.toISOString();
60
+ if (value instanceof ArrayBuffer) return new Uint8Array(value);
61
+ return value;
68
62
  }
69
63
  function normalizeArgs(args) {
70
- if (!args) return void 0;
71
- if (Array.isArray(args)) return args.map(normalizeInput);
72
- return Object.fromEntries(Object.entries(args).map(([key, value]) => [key, normalizeInput(value)]));
64
+ if (!args) return void 0;
65
+ if (Array.isArray(args)) return args.map(normalizeInput);
66
+ return Object.fromEntries(Object.entries(args).map(([key, value]) => [key, normalizeInput(value)]));
73
67
  }
74
68
  function normalizeStatement(statement) {
75
- const args = normalizeArgs(statement.args);
76
- if (!Array.isArray(args) || !statement.sql.toLowerCase().includes("jsonb(?)")) {
77
- return { sql: statement.sql, ...args ? { args } : {} };
78
- }
79
- let argumentIndex = 0;
80
- const normalizedArgs = [];
81
- const sql = statement.sql.replace(/jsonb\(\?\)|\?/gi, (token) => {
82
- const value = args[argumentIndex++];
83
- if (token.toLowerCase() === "jsonb(?)" && value === null) return "NULL";
84
- normalizedArgs.push(value);
85
- return token;
86
- });
87
- return { sql, args: normalizedArgs };
69
+ const args = normalizeArgs(statement.args);
70
+ if (!Array.isArray(args) || !statement.sql.toLowerCase().includes("jsonb(?)")) return {
71
+ sql: statement.sql,
72
+ ...args ? { args } : {}
73
+ };
74
+ let argumentIndex = 0;
75
+ const normalizedArgs = [];
76
+ return {
77
+ sql: statement.sql.replace(/jsonb\(\?\)|\?/gi, (token) => {
78
+ const value = args[argumentIndex++];
79
+ if (token.toLowerCase() === "jsonb(?)" && value === null) return "NULL";
80
+ normalizedArgs.push(value);
81
+ return token;
82
+ }),
83
+ args: normalizedArgs
84
+ };
88
85
  }
89
86
  function toNativeStatement(statement) {
90
- return typeof statement === "string" ? statement : normalizeStatement(statement);
87
+ return typeof statement === "string" ? statement : normalizeStatement(statement);
91
88
  }
92
89
  function normalizeValue(value) {
93
- if (typeof value === "bigint") {
94
- return value <= BigInt(Number.MAX_SAFE_INTEGER) && value >= BigInt(Number.MIN_SAFE_INTEGER) ? Number(value) : value;
95
- }
96
- if (value instanceof Uint8Array) return Uint8Array.from(value).buffer;
97
- if (value === null || typeof value === "string" || typeof value === "number" || value instanceof ArrayBuffer) {
98
- return value;
99
- }
100
- throw new TypeError(`Unsupported Turso result value: ${typeof value}`);
90
+ if (typeof value === "bigint") return value <= BigInt(Number.MAX_SAFE_INTEGER) && value >= BigInt(Number.MIN_SAFE_INTEGER) ? Number(value) : value;
91
+ if (value instanceof Uint8Array) return Uint8Array.from(value).buffer;
92
+ if (value === null || typeof value === "string" || typeof value === "number" || value instanceof ArrayBuffer) return value;
93
+ throw new TypeError(`Unsupported Turso result value: ${typeof value}`);
101
94
  }
102
95
  function normalizeResult(result) {
103
- const rows = result.rows.map((row) => {
104
- if (Array.isArray(row)) {
105
- return Object.fromEntries(result.columns.map((column, index) => [column, normalizeValue(row[index])]));
106
- }
107
- return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, normalizeValue(value)]));
108
- });
109
- return {
110
- columns: result.columns,
111
- columnTypes: result.columnTypes,
112
- rows,
113
- rowsAffected: result.rowsAffected
114
- };
96
+ const rows = result.rows.map((row) => {
97
+ if (Array.isArray(row)) return Object.fromEntries(result.columns.map((column, index) => [column, normalizeValue(row[index])]));
98
+ return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, normalizeValue(value)]));
99
+ });
100
+ return {
101
+ columns: result.columns,
102
+ columnTypes: result.columnTypes,
103
+ rows,
104
+ rowsAffected: result.rowsAffected
105
+ };
115
106
  }
116
107
  var TursoSqliteClient = class {
117
- protocol = "turso";
118
- #mutex = new AsyncMutex();
119
- #readiness;
120
- #state = "open";
121
- #closePromise;
122
- #activeRollback;
123
- constructor(config) {
124
- this.#readiness = this.#connect(config);
125
- void this.#readiness.catch(() => void 0);
126
- }
127
- get closed() {
128
- return this.#state !== "open";
129
- }
130
- async execute(statement) {
131
- return this.#runExclusive(async (db) => normalizeResult((await db.batch([toNativeStatement(statement)]))[0]));
132
- }
133
- async batch(statements, mode) {
134
- return this.#runExclusive(async (db) => {
135
- const results = await db.batch(statements.map(toNativeStatement), mode);
136
- return results.map(normalizeResult);
137
- });
138
- }
139
- async transaction(mode = "write") {
140
- this.#assertOpen();
141
- const release = await this.#mutex.acquire();
142
- try {
143
- this.#assertOpen();
144
- const db = await this.#readiness;
145
- this.#assertOpen();
146
- const entered = deferred();
147
- const decision = deferred();
148
- let transactionClosed = false;
149
- let operationTail = Promise.resolve();
150
- let completion;
151
- let runner;
152
- const execute = (statement) => {
153
- if (transactionClosed) return Promise.reject(new Error("Turso transaction is closed."));
154
- const operation = operationTail.then(async () => {
155
- try {
156
- return normalizeResult((await db.batch([toNativeStatement(statement)]))[0]);
157
- } catch (error) {
158
- throw normalizeError(error);
159
- }
160
- });
161
- operationTail = operation.then(
162
- () => void 0,
163
- () => void 0
164
- );
165
- return operation;
166
- };
167
- const finish = (outcome) => {
168
- if (completion) return completion;
169
- transactionClosed = true;
170
- completion = (async () => {
171
- await operationTail;
172
- decision.resolve(outcome);
173
- try {
174
- await runner;
175
- } catch (error) {
176
- if (outcome !== "rollback" || error !== ROLLBACK) throw error;
177
- }
178
- })();
179
- return completion;
180
- };
181
- const transaction = {
182
- execute,
183
- commit: () => finish("commit"),
184
- rollback: () => finish("rollback"),
185
- close: () => finish("rollback"),
186
- get closed() {
187
- return transactionClosed;
188
- }
189
- };
190
- const rollback = () => finish("rollback");
191
- this.#activeRollback = rollback;
192
- const nativeTransaction = db.transaction(async () => {
193
- entered.resolve();
194
- if (await decision.promise === "rollback") throw ROLLBACK;
195
- });
196
- const nativeRunner = mode === "write" ? nativeTransaction.immediate() : nativeTransaction.deferred();
197
- runner = nativeRunner.catch((error) => {
198
- throw normalizeError(error);
199
- });
200
- runner.then(
201
- () => {
202
- if (this.#activeRollback === rollback) this.#activeRollback = void 0;
203
- release();
204
- },
205
- (error) => {
206
- entered.reject(error);
207
- if (this.#activeRollback === rollback) this.#activeRollback = void 0;
208
- release();
209
- }
210
- );
211
- await entered.promise;
212
- if (this.#state !== "open") {
213
- await rollback();
214
- throw new Error("Turso client is closed.");
215
- }
216
- return transaction;
217
- } catch (error) {
218
- release();
219
- throw error;
220
- }
221
- }
222
- close() {
223
- this.#closePromise ??= this.#close();
224
- return this.#closePromise;
225
- }
226
- async #connect(config) {
227
- const { connect } = await import('@tursodatabase/database');
228
- const db = await connect(config.path, {
229
- ...config.readonly === void 0 ? {} : { readonly: config.readonly },
230
- ...config.fileMustExist === void 0 ? {} : { fileMustExist: config.fileMustExist },
231
- ...config.timeout === void 0 ? {} : { timeout: config.timeout },
232
- ...config.defaultQueryTimeout === void 0 ? {} : { defaultQueryTimeout: config.defaultQueryTimeout },
233
- ...config.tracing === void 0 ? {} : { tracing: config.tracing },
234
- ...config.experimental === void 0 ? {} : { experimental: config.experimental }
235
- });
236
- db.defaultSafeIntegers(true);
237
- return db;
238
- }
239
- async #runExclusive(operation) {
240
- this.#assertOpen();
241
- const release = await this.#mutex.acquire();
242
- try {
243
- this.#assertOpen();
244
- const db = await this.#readiness;
245
- this.#assertOpen();
246
- try {
247
- return await operation(db);
248
- } catch (error) {
249
- throw normalizeError(error);
250
- }
251
- } finally {
252
- release();
253
- }
254
- }
255
- async #close() {
256
- if (this.#state === "closed") return;
257
- this.#state = "closing";
258
- await this.#activeRollback?.();
259
- const release = await this.#mutex.acquire();
260
- try {
261
- const db = await this.#readiness.catch(() => void 0);
262
- await db?.close();
263
- } finally {
264
- this.#state = "closed";
265
- release();
266
- }
267
- }
268
- #assertOpen() {
269
- if (this.#state !== "open") throw new Error("Turso client is closed.");
270
- }
108
+ protocol = "turso";
109
+ #mutex = new AsyncMutex();
110
+ #readiness;
111
+ #state = "open";
112
+ #closePromise;
113
+ #activeRollback;
114
+ constructor(config) {
115
+ this.#readiness = this.#connect(config);
116
+ this.#readiness.catch(() => void 0);
117
+ }
118
+ get closed() {
119
+ return this.#state !== "open";
120
+ }
121
+ async execute(statement) {
122
+ return this.#runExclusive(async (db) => normalizeResult((await db.batch([toNativeStatement(statement)]))[0]));
123
+ }
124
+ async batch(statements, mode) {
125
+ return this.#runExclusive(async (db) => {
126
+ return (await db.batch(statements.map(toNativeStatement), mode)).map(normalizeResult);
127
+ });
128
+ }
129
+ async transaction(mode = "write") {
130
+ this.#assertOpen();
131
+ const release = await this.#mutex.acquire();
132
+ try {
133
+ this.#assertOpen();
134
+ const db = await this.#readiness;
135
+ this.#assertOpen();
136
+ const entered = deferred();
137
+ const decision = deferred();
138
+ let transactionClosed = false;
139
+ let operationTail = Promise.resolve();
140
+ let completion;
141
+ let runner;
142
+ const execute = (statement) => {
143
+ if (transactionClosed) return Promise.reject(/* @__PURE__ */ new Error("Turso transaction is closed."));
144
+ const operation = operationTail.then(async () => {
145
+ try {
146
+ return normalizeResult((await db.batch([toNativeStatement(statement)]))[0]);
147
+ } catch (error) {
148
+ throw normalizeError(error);
149
+ }
150
+ });
151
+ operationTail = operation.then(() => void 0, () => void 0);
152
+ return operation;
153
+ };
154
+ const finish = (outcome) => {
155
+ if (completion) return completion;
156
+ transactionClosed = true;
157
+ completion = (async () => {
158
+ await operationTail;
159
+ decision.resolve(outcome);
160
+ try {
161
+ await runner;
162
+ } catch (error) {
163
+ if (outcome !== "rollback" || error !== ROLLBACK) throw error;
164
+ }
165
+ })();
166
+ return completion;
167
+ };
168
+ const transaction = {
169
+ execute,
170
+ commit: () => finish("commit"),
171
+ rollback: () => finish("rollback"),
172
+ close: () => finish("rollback"),
173
+ get closed() {
174
+ return transactionClosed;
175
+ }
176
+ };
177
+ const rollback = () => finish("rollback");
178
+ this.#activeRollback = rollback;
179
+ const nativeTransaction = db.transaction(async () => {
180
+ entered.resolve();
181
+ if (await decision.promise === "rollback") throw ROLLBACK;
182
+ });
183
+ runner = (mode === "write" ? nativeTransaction.immediate() : nativeTransaction.deferred()).catch((error) => {
184
+ throw normalizeError(error);
185
+ });
186
+ runner.then(() => {
187
+ if (this.#activeRollback === rollback) this.#activeRollback = void 0;
188
+ release();
189
+ }, (error) => {
190
+ entered.reject(error);
191
+ if (this.#activeRollback === rollback) this.#activeRollback = void 0;
192
+ release();
193
+ });
194
+ await entered.promise;
195
+ if (this.#state !== "open") {
196
+ await rollback();
197
+ throw new Error("Turso client is closed.");
198
+ }
199
+ return transaction;
200
+ } catch (error) {
201
+ release();
202
+ throw error;
203
+ }
204
+ }
205
+ close() {
206
+ this.#closePromise ??= this.#close();
207
+ return this.#closePromise;
208
+ }
209
+ async #connect(config) {
210
+ const { connect } = await import("@tursodatabase/database");
211
+ const db = await connect(config.path, {
212
+ ...config.readonly === void 0 ? {} : { readonly: config.readonly },
213
+ ...config.fileMustExist === void 0 ? {} : { fileMustExist: config.fileMustExist },
214
+ ...config.timeout === void 0 ? {} : { timeout: config.timeout },
215
+ ...config.defaultQueryTimeout === void 0 ? {} : { defaultQueryTimeout: config.defaultQueryTimeout },
216
+ ...config.tracing === void 0 ? {} : { tracing: config.tracing },
217
+ ...config.experimental === void 0 ? {} : { experimental: config.experimental }
218
+ });
219
+ db.defaultSafeIntegers(true);
220
+ return db;
221
+ }
222
+ async #runExclusive(operation) {
223
+ this.#assertOpen();
224
+ const release = await this.#mutex.acquire();
225
+ try {
226
+ this.#assertOpen();
227
+ const db = await this.#readiness;
228
+ this.#assertOpen();
229
+ try {
230
+ return await operation(db);
231
+ } catch (error) {
232
+ throw normalizeError(error);
233
+ }
234
+ } finally {
235
+ release();
236
+ }
237
+ }
238
+ async #close() {
239
+ if (this.#state === "closed") return;
240
+ this.#state = "closing";
241
+ await this.#activeRollback?.();
242
+ const release = await this.#mutex.acquire();
243
+ try {
244
+ await (await this.#readiness.catch(() => void 0))?.close();
245
+ } finally {
246
+ this.#state = "closed";
247
+ release();
248
+ }
249
+ }
250
+ #assertOpen() {
251
+ if (this.#state !== "open") throw new Error("Turso client is closed.");
252
+ }
271
253
  };
254
+ //#endregion
255
+ //#region src/support.ts
272
256
  function detectLinuxLibc() {
273
- const family = detectLibc.familySync();
274
- if (family === detectLibc.GLIBC) return "glibc";
275
- if (family === detectLibc.MUSL) return "musl";
276
- return "unknown";
257
+ const family = (0, detect_libc.familySync)();
258
+ if (family === detect_libc.GLIBC) return "glibc";
259
+ if (family === detect_libc.MUSL) return "musl";
260
+ return "unknown";
277
261
  }
278
262
  function getTursoDatabaseSupport(options = {}) {
279
- const platform = options.platform ?? process.platform;
280
- const arch = options.arch ?? process.arch;
281
- if (platform === "darwin" && arch === "arm64") return { supported: true, platform, arch };
282
- if (platform === "win32" && arch === "x64") return { supported: true, platform, arch };
283
- if (platform === "linux") {
284
- const linuxLibc = options.linuxLibc ?? detectLinuxLibc();
285
- const supported = (arch === "x64" || arch === "arm64") && linuxLibc === "glibc";
286
- return {
287
- supported,
288
- platform,
289
- arch,
290
- linuxLibc,
291
- ...supported ? {} : { reason: `Turso Database requires Linux x64 or arm64 with glibc; detected ${arch}/${linuxLibc}.` }
292
- };
293
- }
294
- return {
295
- supported: false,
296
- platform,
297
- arch,
298
- reason: `Turso Database does not provide a native binding for ${platform}/${arch}.`
299
- };
263
+ const platform = options.platform ?? process.platform;
264
+ const arch = options.arch ?? process.arch;
265
+ if (platform === "darwin" && arch === "arm64") return {
266
+ supported: true,
267
+ platform,
268
+ arch
269
+ };
270
+ if (platform === "win32" && arch === "x64") return {
271
+ supported: true,
272
+ platform,
273
+ arch
274
+ };
275
+ if (platform === "linux") {
276
+ const linuxLibc = options.linuxLibc ?? detectLinuxLibc();
277
+ const supported = (arch === "x64" || arch === "arm64") && linuxLibc === "glibc";
278
+ return {
279
+ supported,
280
+ platform,
281
+ arch,
282
+ linuxLibc,
283
+ ...supported ? {} : { reason: `Turso Database requires Linux x64 or arm64 with glibc; detected ${arch}/${linuxLibc}.` }
284
+ };
285
+ }
286
+ return {
287
+ supported: false,
288
+ platform,
289
+ arch,
290
+ reason: `Turso Database does not provide a native binding for ${platform}/${arch}.`
291
+ };
300
292
  }
301
-
302
- // src/index.ts
303
- var TursoStore = class extends libsql.LibSQLStore {
304
- #closePromise;
305
- constructor(config) {
306
- if (!config.id || typeof config.id !== "string" || config.id.trim() === "") {
307
- throw new Error("TursoStore: id must be provided and cannot be empty.");
308
- }
309
- let client;
310
- if ("client" in config && config.client) {
311
- client = config.client;
312
- } else {
313
- if (!config.path || typeof config.path !== "string" || config.path.trim() === "") {
314
- throw new Error("TursoStore: path must be provided and cannot be empty.");
315
- }
316
- const support = getTursoDatabaseSupport();
317
- if (!support.supported) {
318
- throw new Error(support.reason ?? `Turso Database is not supported on ${support.platform}/${support.arch}.`);
319
- }
320
- const clientConfig = {
321
- path: config.path,
322
- ...config.readonly === void 0 ? {} : { readonly: config.readonly },
323
- ...config.fileMustExist === void 0 ? {} : { fileMustExist: config.fileMustExist },
324
- ...config.timeout === void 0 ? {} : { timeout: config.timeout },
325
- ...config.defaultQueryTimeout === void 0 ? {} : { defaultQueryTimeout: config.defaultQueryTimeout },
326
- ...config.tracing === void 0 ? {} : { tracing: config.tracing },
327
- ...config.experimental === void 0 ? {} : { experimental: config.experimental }
328
- };
329
- client = new TursoSqliteClient(clientConfig);
330
- }
331
- super({
332
- id: config.id,
333
- client,
334
- ...config.maxRetries === void 0 ? {} : { maxRetries: config.maxRetries },
335
- ...config.initialBackoffMs === void 0 ? {} : { initialBackoffMs: config.initialBackoffMs },
336
- ...config.disableInit === void 0 ? {} : { disableInit: config.disableInit },
337
- ...config.retention === void 0 ? {} : { retention: config.retention }
338
- });
339
- this.name = "TursoStore";
340
- }
341
- close() {
342
- this.#closePromise ??= super.close();
343
- return this.#closePromise;
344
- }
293
+ //#endregion
294
+ //#region src/index.ts
295
+ var TursoStore = class extends _mastra_libsql.LibSQLStore {
296
+ #closePromise;
297
+ constructor(config) {
298
+ if (!config.id || typeof config.id !== "string" || config.id.trim() === "") throw new Error("TursoStore: id must be provided and cannot be empty.");
299
+ let client;
300
+ if ("client" in config && config.client) client = config.client;
301
+ else {
302
+ if (!config.path || typeof config.path !== "string" || config.path.trim() === "") throw new Error("TursoStore: path must be provided and cannot be empty.");
303
+ const support = getTursoDatabaseSupport();
304
+ if (!support.supported) throw new Error(support.reason ?? `Turso Database is not supported on ${support.platform}/${support.arch}.`);
305
+ client = new TursoSqliteClient({
306
+ path: config.path,
307
+ ...config.readonly === void 0 ? {} : { readonly: config.readonly },
308
+ ...config.fileMustExist === void 0 ? {} : { fileMustExist: config.fileMustExist },
309
+ ...config.timeout === void 0 ? {} : { timeout: config.timeout },
310
+ ...config.defaultQueryTimeout === void 0 ? {} : { defaultQueryTimeout: config.defaultQueryTimeout },
311
+ ...config.tracing === void 0 ? {} : { tracing: config.tracing },
312
+ ...config.experimental === void 0 ? {} : { experimental: config.experimental }
313
+ });
314
+ }
315
+ super({
316
+ id: config.id,
317
+ client,
318
+ ...config.maxRetries === void 0 ? {} : { maxRetries: config.maxRetries },
319
+ ...config.initialBackoffMs === void 0 ? {} : { initialBackoffMs: config.initialBackoffMs },
320
+ ...config.disableInit === void 0 ? {} : { disableInit: config.disableInit },
321
+ ...config.retention === void 0 ? {} : { retention: config.retention }
322
+ });
323
+ this.name = "TursoStore";
324
+ }
325
+ close() {
326
+ this.#closePromise ??= super.close();
327
+ return this.#closePromise;
328
+ }
345
329
  };
346
-
330
+ //#endregion
347
331
  exports.TursoStore = TursoStore;
348
332
  exports.getTursoDatabaseSupport = getTursoDatabaseSupport;
349
- //# sourceMappingURL=index.cjs.map
333
+
350
334
  //# sourceMappingURL=index.cjs.map