@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/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +304 -320
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +302 -317
- package/dist/index.js.map +1 -1
- package/package.json +9 -10
- package/CHANGELOG.md +0 -87
package/dist/index.js
CHANGED
|
@@ -1,347 +1,332 @@
|
|
|
1
|
-
import { LibSQLStore } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
86
|
+
return typeof statement === "string" ? statement : normalizeStatement(statement);
|
|
89
87
|
}
|
|
90
88
|
function normalizeValue(value) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
292
|
+
//#endregion
|
|
293
|
+
//#region src/index.ts
|
|
301
294
|
var TursoStore = class extends LibSQLStore {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
331
|
+
|
|
347
332
|
//# sourceMappingURL=index.js.map
|