@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.cjs
CHANGED
|
@@ -1,350 +1,334 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
87
|
+
return typeof statement === "string" ? statement : normalizeStatement(statement);
|
|
91
88
|
}
|
|
92
89
|
function normalizeValue(value) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
303
|
-
var TursoStore = class extends
|
|
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
|
-
|
|
336
|
-
|
|
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
|
-
|
|
333
|
+
|
|
350
334
|
//# sourceMappingURL=index.cjs.map
|