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