@archildata/sqlite 0.0.0 → 0.0.1
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 +259 -316
- package/dist/index.d.cts +25 -25
- package/dist/index.d.mts +44 -0
- package/dist/index.mjs +397 -0
- package/package.json +13 -12
- package/dist/index.d.ts +0 -44
- package/dist/index.js +0 -430
package/dist/index.cjs
CHANGED
|
@@ -1,39 +1,12 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
ArchilSQLiteError: () => ArchilSQLiteError,
|
|
24
|
-
createDatabase: () => createDatabase,
|
|
25
|
-
getDatabase: () => getDatabase
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
var import_disk = require("disk");
|
|
29
|
-
|
|
30
|
-
// src/adapter.ts
|
|
31
|
-
var import_node_buffer = require("buffer");
|
|
32
|
-
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
33
|
-
var WRITE_MOUNT_QUEUE_MS = 5e3;
|
|
34
|
-
var RESULT_PREFIX = "ARCHIL_SQLITE_RESULT:";
|
|
35
|
-
var DISK_EXEC_MOUNT_PATH = "/mnt/archil/disk";
|
|
36
|
-
var REMOTE_RUNNER = `
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let disk = require("disk");
|
|
3
|
+
let node_buffer = require("node:buffer");
|
|
4
|
+
//#region src/adapter.ts
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 5e3;
|
|
6
|
+
const WRITE_MOUNT_QUEUE_MS = 5e3;
|
|
7
|
+
const RESULT_PREFIX = "ARCHIL_SQLITE_RESULT:";
|
|
8
|
+
const DISK_EXEC_MOUNT_PATH = "/mnt/archil/disk";
|
|
9
|
+
const REMOTE_RUNNER = `
|
|
37
10
|
const { Buffer } = require("node:buffer");
|
|
38
11
|
const { DatabaseSync } = require("node:sqlite");
|
|
39
12
|
const fs = require("node:fs");
|
|
@@ -144,314 +117,284 @@ try {
|
|
|
144
117
|
}
|
|
145
118
|
`;
|
|
146
119
|
var ArchilSQLiteError = class extends Error {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
120
|
+
code;
|
|
121
|
+
remoteStack;
|
|
122
|
+
constructor(message, opts = {}) {
|
|
123
|
+
super(message);
|
|
124
|
+
this.name = "ArchilSQLiteError";
|
|
125
|
+
this.code = opts.code;
|
|
126
|
+
this.remoteStack = opts.remoteStack;
|
|
127
|
+
}
|
|
155
128
|
};
|
|
156
|
-
|
|
129
|
+
const operationStates = /* @__PURE__ */ new WeakMap();
|
|
157
130
|
function deferredPromise() {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
131
|
+
let resolve;
|
|
132
|
+
let reject;
|
|
133
|
+
const promise = new Promise((promiseResolve, promiseReject) => {
|
|
134
|
+
resolve = promiseResolve;
|
|
135
|
+
reject = promiseReject;
|
|
136
|
+
});
|
|
137
|
+
promise.catch(() => {});
|
|
138
|
+
return {
|
|
139
|
+
promise,
|
|
140
|
+
resolve,
|
|
141
|
+
reject
|
|
142
|
+
};
|
|
167
143
|
}
|
|
168
144
|
var SQLiteOperationImpl = class {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return this.execute().then(onfulfilled, onrejected);
|
|
187
|
-
}
|
|
145
|
+
executeRequest;
|
|
146
|
+
constructor(executeRequest, request) {
|
|
147
|
+
this.executeRequest = executeRequest;
|
|
148
|
+
operationStates.set(this, {
|
|
149
|
+
executeRequest,
|
|
150
|
+
request
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
execute() {
|
|
154
|
+
const state = operationStates.get(this);
|
|
155
|
+
if (!state) throw new TypeError("unknown SQLite operation");
|
|
156
|
+
state.promise ??= this.executeRequest(state.request);
|
|
157
|
+
return state.promise;
|
|
158
|
+
}
|
|
159
|
+
then(onfulfilled, onrejected) {
|
|
160
|
+
return this.execute().then(onfulfilled, onrejected);
|
|
161
|
+
}
|
|
188
162
|
};
|
|
189
163
|
var SQLiteQueryImpl = class {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
164
|
+
executeRequest;
|
|
165
|
+
request;
|
|
166
|
+
constructor(executeRequest, request) {
|
|
167
|
+
this.executeRequest = executeRequest;
|
|
168
|
+
this.request = request;
|
|
169
|
+
}
|
|
170
|
+
get() {
|
|
171
|
+
return new SQLiteOperationImpl(this.executeRequest, {
|
|
172
|
+
...this.request,
|
|
173
|
+
method: "get"
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
all() {
|
|
177
|
+
return new SQLiteOperationImpl(this.executeRequest, {
|
|
178
|
+
...this.request,
|
|
179
|
+
method: "all"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
run() {
|
|
183
|
+
return new SQLiteOperationImpl(this.executeRequest, {
|
|
184
|
+
...this.request,
|
|
185
|
+
method: "run"
|
|
186
|
+
});
|
|
187
|
+
}
|
|
214
188
|
};
|
|
215
189
|
var SQLiteAdapter = class {
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
});
|
|
311
|
-
const decoded = parseExecResult(result);
|
|
312
|
-
return opts.transaction ? decoded : [decoded];
|
|
313
|
-
}
|
|
190
|
+
exec;
|
|
191
|
+
disk;
|
|
192
|
+
database;
|
|
193
|
+
timeoutMs;
|
|
194
|
+
readBigInts;
|
|
195
|
+
returnArrays;
|
|
196
|
+
constructor(exec, disk, database, options = {}) {
|
|
197
|
+
this.exec = exec;
|
|
198
|
+
this.disk = disk;
|
|
199
|
+
this.database = database;
|
|
200
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
201
|
+
this.readBigInts = options.readBigInts ?? false;
|
|
202
|
+
this.returnArrays = options.returnArrays ?? false;
|
|
203
|
+
}
|
|
204
|
+
read(strings, ...values) {
|
|
205
|
+
return new SQLiteQueryImpl((request) => this.executeSingle(request), {
|
|
206
|
+
kind: "read",
|
|
207
|
+
sql: templateToSql(strings),
|
|
208
|
+
params: values.map(encodeParameter)
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
write(strings, ...values) {
|
|
212
|
+
return new SQLiteQueryImpl((request) => this.executeSingle(request), {
|
|
213
|
+
kind: "write",
|
|
214
|
+
sql: templateToSql(strings),
|
|
215
|
+
params: values.map(encodeParameter)
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
async transaction(operations) {
|
|
219
|
+
const states = operations.map((operation) => {
|
|
220
|
+
const state = operationStates.get(operation);
|
|
221
|
+
if (!state) throw new TypeError("unknown SQLite operation");
|
|
222
|
+
return state;
|
|
223
|
+
});
|
|
224
|
+
const seen = /* @__PURE__ */ new Set();
|
|
225
|
+
for (const state of states) {
|
|
226
|
+
if (state.promise) throw new TypeError("SQLite operation has already started");
|
|
227
|
+
if (seen.has(state)) throw new TypeError("SQLite operation cannot be used more than once in a transaction");
|
|
228
|
+
seen.add(state);
|
|
229
|
+
}
|
|
230
|
+
const requests = states.map((state) => state.request);
|
|
231
|
+
const readOnly = requests.every((request) => request.kind === "read");
|
|
232
|
+
const deferreds = states.map(() => deferredPromise());
|
|
233
|
+
states.forEach((state, index) => {
|
|
234
|
+
state.promise = deferreds[index].promise;
|
|
235
|
+
});
|
|
236
|
+
try {
|
|
237
|
+
const results = await this.executeRemote(requests, {
|
|
238
|
+
transaction: true,
|
|
239
|
+
readOnly
|
|
240
|
+
});
|
|
241
|
+
results.forEach((result, index) => {
|
|
242
|
+
deferreds[index].resolve(result);
|
|
243
|
+
});
|
|
244
|
+
return results;
|
|
245
|
+
} catch (err) {
|
|
246
|
+
deferreds.forEach((deferred) => {
|
|
247
|
+
deferred.reject(err);
|
|
248
|
+
});
|
|
249
|
+
throw err;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
executeSingle(request) {
|
|
253
|
+
return this.executeRemote([request], {
|
|
254
|
+
transaction: false,
|
|
255
|
+
readOnly: request.kind === "read"
|
|
256
|
+
}).then((results) => results[0]);
|
|
257
|
+
}
|
|
258
|
+
async executeRemote(operations, opts) {
|
|
259
|
+
const payload = {
|
|
260
|
+
databasePath: `${DISK_EXEC_MOUNT_PATH}/${this.database.path}`,
|
|
261
|
+
displayPath: this.database.path,
|
|
262
|
+
timeoutMs: this.timeoutMs,
|
|
263
|
+
readBigInts: this.readBigInts,
|
|
264
|
+
returnArrays: this.returnArrays,
|
|
265
|
+
readOnly: opts.readOnly,
|
|
266
|
+
transaction: opts.transaction,
|
|
267
|
+
operations
|
|
268
|
+
};
|
|
269
|
+
const checkoutPaths = opts.readOnly || !this.database.directory ? void 0 : [this.database.directory];
|
|
270
|
+
const queueMs = opts.readOnly ? void 0 : WRITE_MOUNT_QUEUE_MS;
|
|
271
|
+
const mount = {
|
|
272
|
+
disk: this.disk.id,
|
|
273
|
+
readOnly: opts.readOnly,
|
|
274
|
+
checkoutPaths,
|
|
275
|
+
queueMs
|
|
276
|
+
};
|
|
277
|
+
const command = buildCommand(payload);
|
|
278
|
+
const decoded = parseExecResult(await this.exec({
|
|
279
|
+
command,
|
|
280
|
+
disks: { disk: mount }
|
|
281
|
+
}));
|
|
282
|
+
return opts.transaction ? decoded : [decoded];
|
|
283
|
+
}
|
|
314
284
|
};
|
|
315
285
|
function createSQLiteAdapter(exec) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
return new SQLiteAdapter(exec, disk, database, options);
|
|
338
|
-
},
|
|
339
|
-
async getDatabase(disk, databasePath, options = {}) {
|
|
340
|
-
const database = normalizeDatabasePath(databasePath);
|
|
341
|
-
return new SQLiteAdapter(exec, disk, database, options);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
286
|
+
return {
|
|
287
|
+
async createDatabase(disk, databasePath, options = {}) {
|
|
288
|
+
const database = normalizeDatabasePath(databasePath);
|
|
289
|
+
const rootDirectory = database.directory ? `${DISK_EXEC_MOUNT_PATH}/${database.directory}` : DISK_EXEC_MOUNT_PATH;
|
|
290
|
+
const mountedDatabasePath = `${rootDirectory}/${database.filename}`;
|
|
291
|
+
const result = await exec({
|
|
292
|
+
command: `mkdir -p ${shellQuote(rootDirectory)} && node --no-warnings -e ${shellQuote(CREATE_DATABASE_RUNNER)} ${shellQuote(mountedDatabasePath)}`,
|
|
293
|
+
disks: { disk: {
|
|
294
|
+
disk: disk.id,
|
|
295
|
+
readOnly: false,
|
|
296
|
+
queueMs: WRITE_MOUNT_QUEUE_MS
|
|
297
|
+
} }
|
|
298
|
+
});
|
|
299
|
+
if (result.exitCode !== 0) throw new ArchilSQLiteError(`SQLite database creation failed with exit code ${result.exitCode}: ${result.stderr || result.stdout}`);
|
|
300
|
+
return new SQLiteAdapter(exec, disk, database, options);
|
|
301
|
+
},
|
|
302
|
+
async getDatabase(disk, databasePath, options = {}) {
|
|
303
|
+
return new SQLiteAdapter(exec, disk, normalizeDatabasePath(databasePath), options);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
344
306
|
}
|
|
345
307
|
function templateToSql(strings) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
return sql;
|
|
308
|
+
let sql = strings[0] ?? "";
|
|
309
|
+
for (let i = 1; i < strings.length; i++) sql += "?" + strings[i];
|
|
310
|
+
return sql;
|
|
351
311
|
}
|
|
352
312
|
function normalizeDatabasePath(path) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
path: segments.join("/"),
|
|
364
|
-
directory: directorySegments.length > 0 ? directorySegments.join("/") : void 0,
|
|
365
|
-
filename
|
|
366
|
-
};
|
|
313
|
+
if (path.endsWith("/")) throw new TypeError("database path must include a file name and not end with '/'");
|
|
314
|
+
const segments = path.split("/").filter((segment) => segment.length > 0 && segment !== ".");
|
|
315
|
+
if (segments.length === 0 || segments.some((segment) => segment === "..")) throw new TypeError("database path must be a non-empty relative file path without '..'");
|
|
316
|
+
const filename = segments[segments.length - 1];
|
|
317
|
+
const directorySegments = segments.slice(0, -1);
|
|
318
|
+
return {
|
|
319
|
+
path: segments.join("/"),
|
|
320
|
+
directory: directorySegments.length > 0 ? directorySegments.join("/") : void 0,
|
|
321
|
+
filename
|
|
322
|
+
};
|
|
367
323
|
}
|
|
368
|
-
|
|
324
|
+
const CREATE_DATABASE_RUNNER = `
|
|
369
325
|
const { DatabaseSync } = require("node:sqlite");
|
|
370
326
|
const db = new DatabaseSync(process.argv[1]);
|
|
371
327
|
db.close();
|
|
372
328
|
`;
|
|
373
329
|
function encodeParameter(value) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
330
|
+
if (value === null) return { type: "null" };
|
|
331
|
+
if (typeof value === "number") return {
|
|
332
|
+
type: "number",
|
|
333
|
+
value
|
|
334
|
+
};
|
|
335
|
+
if (typeof value === "string") return {
|
|
336
|
+
type: "string",
|
|
337
|
+
value
|
|
338
|
+
};
|
|
339
|
+
if (typeof value === "bigint") return {
|
|
340
|
+
type: "bigint",
|
|
341
|
+
value: value.toString()
|
|
342
|
+
};
|
|
343
|
+
if (value instanceof Uint8Array) return {
|
|
344
|
+
type: "bytes",
|
|
345
|
+
value: node_buffer.Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64")
|
|
346
|
+
};
|
|
347
|
+
if (value instanceof ArrayBuffer) return {
|
|
348
|
+
type: "bytes",
|
|
349
|
+
value: node_buffer.Buffer.from(value).toString("base64")
|
|
350
|
+
};
|
|
351
|
+
throw new TypeError(`unsupported SQLite parameter type: ${typeof value}`);
|
|
388
352
|
}
|
|
389
353
|
function decodeWireValue(value) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
case "bytes":
|
|
401
|
-
return Uint8Array.from(import_node_buffer.Buffer.from(value.value, "base64"));
|
|
402
|
-
case "array":
|
|
403
|
-
return value.value.map(decodeWireValue);
|
|
404
|
-
case "object":
|
|
405
|
-
return Object.fromEntries(
|
|
406
|
-
Object.entries(value.value).map(([key, entry]) => [key, decodeWireValue(entry)])
|
|
407
|
-
);
|
|
408
|
-
}
|
|
354
|
+
switch (value.type) {
|
|
355
|
+
case "undefined": return;
|
|
356
|
+
case "null": return null;
|
|
357
|
+
case "number":
|
|
358
|
+
case "string": return value.value;
|
|
359
|
+
case "bigint": return BigInt(value.value);
|
|
360
|
+
case "bytes": return Uint8Array.from(node_buffer.Buffer.from(value.value, "base64"));
|
|
361
|
+
case "array": return value.value.map(decodeWireValue);
|
|
362
|
+
case "object": return Object.fromEntries(Object.entries(value.value).map(([key, entry]) => [key, decodeWireValue(entry)]));
|
|
363
|
+
}
|
|
409
364
|
}
|
|
410
365
|
function buildCommand(payload) {
|
|
411
|
-
|
|
412
|
-
|
|
366
|
+
const encodedPayload = node_buffer.Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
|
|
367
|
+
return `node --no-warnings -e ${shellQuote(REMOTE_RUNNER)} ${shellQuote(encodedPayload)}`;
|
|
413
368
|
}
|
|
414
369
|
function shellQuote(value) {
|
|
415
|
-
|
|
370
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
416
371
|
}
|
|
417
372
|
function parseExecResult(result) {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
} catch (err) {
|
|
433
|
-
throw new ArchilSQLiteError(`SQLite serverless execution returned invalid JSON: ${err}`);
|
|
434
|
-
}
|
|
435
|
-
if (!parsed.ok) {
|
|
436
|
-
throw new ArchilSQLiteError(parsed.error.message ?? "SQLite serverless execution failed", {
|
|
437
|
-
code: parsed.error.code,
|
|
438
|
-
remoteStack: parsed.error.stack
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
return decodeWireValue(parsed.result);
|
|
373
|
+
if (result.exitCode !== 0) throw new ArchilSQLiteError(`SQLite serverless execution failed with exit code ${result.exitCode}: ${result.stderr || result.stdout}`);
|
|
374
|
+
const line = result.stdout.split(/\r?\n/).reverse().find((entry) => entry.startsWith(RESULT_PREFIX));
|
|
375
|
+
if (!line) throw new ArchilSQLiteError("SQLite serverless execution did not return a result payload");
|
|
376
|
+
let parsed;
|
|
377
|
+
try {
|
|
378
|
+
parsed = JSON.parse(node_buffer.Buffer.from(line.slice(21), "base64").toString("utf8"));
|
|
379
|
+
} catch (err) {
|
|
380
|
+
throw new ArchilSQLiteError(`SQLite serverless execution returned invalid JSON: ${err}`);
|
|
381
|
+
}
|
|
382
|
+
if (!parsed.ok) throw new ArchilSQLiteError(parsed.error.message ?? "SQLite serverless execution failed", {
|
|
383
|
+
code: parsed.error.code,
|
|
384
|
+
remoteStack: parsed.error.stack
|
|
385
|
+
});
|
|
386
|
+
return decodeWireValue(parsed.result);
|
|
442
387
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
function createDatabase(disk, databasePath, options) {
|
|
447
|
-
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/index.ts
|
|
390
|
+
const sqlite = createSQLiteAdapter((opts) => (0, disk.exec)(opts));
|
|
391
|
+
function createDatabase(disk$1, databasePath, options) {
|
|
392
|
+
return sqlite.createDatabase(disk$1, databasePath, options);
|
|
448
393
|
}
|
|
449
|
-
function getDatabase(disk, databasePath, options) {
|
|
450
|
-
|
|
394
|
+
function getDatabase(disk$2, databasePath, options) {
|
|
395
|
+
return sqlite.getDatabase(disk$2, databasePath, options);
|
|
451
396
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
getDatabase
|
|
457
|
-
});
|
|
397
|
+
//#endregion
|
|
398
|
+
exports.ArchilSQLiteError = ArchilSQLiteError;
|
|
399
|
+
exports.createDatabase = createDatabase;
|
|
400
|
+
exports.getDatabase = getDatabase;
|