@archildata/sqlite 0.0.0 → 0.0.2

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.d.cts CHANGED
@@ -1,44 +1,44 @@
1
+ //#region src/adapter.d.ts
1
2
  interface SQLiteDisk {
2
- id: string;
3
+ id: string;
3
4
  }
4
5
  interface SQLiteDatabaseOptions {
5
- timeoutMs?: number;
6
- readBigInts?: boolean;
7
- returnArrays?: boolean;
6
+ timeoutMs?: number;
7
+ readBigInts?: boolean;
8
+ returnArrays?: boolean;
8
9
  }
9
10
  type SQLiteValue = null | number | bigint | string | Uint8Array | ArrayBuffer;
10
11
  type SQLiteRow = Record<string, SQLiteValue>;
11
12
  interface SQLiteWriteResult {
12
- changes: number | bigint;
13
- lastInsertRowid: number | bigint;
13
+ changes: number | bigint;
14
+ lastInsertRowid: number | bigint;
14
15
  }
15
16
  declare class ArchilSQLiteError extends Error {
16
- readonly code?: string | number;
17
- readonly remoteStack?: string;
18
- constructor(message: string, opts?: {
19
- code?: string | number;
20
- remoteStack?: string;
21
- });
17
+ readonly code?: string | number;
18
+ readonly remoteStack?: string;
19
+ constructor(message: string, opts?: {
20
+ code?: string | number;
21
+ remoteStack?: string;
22
+ });
22
23
  }
23
24
  interface SQLiteOperation<Result> extends PromiseLike<Result> {
24
- execute(): Promise<Result>;
25
+ execute(): Promise<Result>;
25
26
  }
26
27
  interface SQLiteQuery<Row = SQLiteRow> {
27
- get(): SQLiteOperation<Row | undefined>;
28
- all(): SQLiteOperation<Row[]>;
29
- run(): SQLiteOperation<SQLiteWriteResult>;
28
+ get(): SQLiteOperation<Row | undefined>;
29
+ all(): SQLiteOperation<Row[]>;
30
+ run(): SQLiteOperation<SQLiteWriteResult>;
30
31
  }
31
32
  type SQLiteOperationResult<Operation> = Operation extends SQLiteOperation<infer Result> ? Result : never;
32
- type SQLiteTransactionResult<Operations extends readonly SQLiteOperation<unknown>[]> = {
33
- -readonly [Index in keyof Operations]: SQLiteOperationResult<Operations[Index]>;
34
- };
33
+ type SQLiteTransactionResult<Operations extends readonly SQLiteOperation<unknown>[]> = { -readonly [Index in keyof Operations]: SQLiteOperationResult<Operations[Index]> };
35
34
  interface SQLiteDatabase {
36
- read<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
37
- write<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
38
- transaction<const Operations extends readonly SQLiteOperation<unknown>[]>(operations: Operations): Promise<SQLiteTransactionResult<Operations>>;
35
+ read<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
36
+ write<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
37
+ transaction<const Operations extends readonly SQLiteOperation<unknown>[]>(operations: Operations): Promise<SQLiteTransactionResult<Operations>>;
39
38
  }
40
-
39
+ //#endregion
40
+ //#region src/index.d.ts
41
41
  declare function createDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
42
42
  declare function getDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
43
-
44
- export { ArchilSQLiteError, type SQLiteDatabase, type SQLiteDatabaseOptions, type SQLiteDisk, type SQLiteOperation, type SQLiteQuery, type SQLiteRow, type SQLiteTransactionResult, type SQLiteValue, type SQLiteWriteResult, createDatabase, getDatabase };
43
+ //#endregion
44
+ export { ArchilSQLiteError, type SQLiteDatabase, type SQLiteDatabaseOptions, type SQLiteDisk, type SQLiteOperation, type SQLiteQuery, type SQLiteRow, type SQLiteTransactionResult, type SQLiteValue, type SQLiteWriteResult, createDatabase, getDatabase };
@@ -0,0 +1,44 @@
1
+ //#region src/adapter.d.ts
2
+ interface SQLiteDisk {
3
+ id: string;
4
+ }
5
+ interface SQLiteDatabaseOptions {
6
+ timeoutMs?: number;
7
+ readBigInts?: boolean;
8
+ returnArrays?: boolean;
9
+ }
10
+ type SQLiteValue = null | number | bigint | string | Uint8Array | ArrayBuffer;
11
+ type SQLiteRow = Record<string, SQLiteValue>;
12
+ interface SQLiteWriteResult {
13
+ changes: number | bigint;
14
+ lastInsertRowid: number | bigint;
15
+ }
16
+ declare class ArchilSQLiteError extends Error {
17
+ readonly code?: string | number;
18
+ readonly remoteStack?: string;
19
+ constructor(message: string, opts?: {
20
+ code?: string | number;
21
+ remoteStack?: string;
22
+ });
23
+ }
24
+ interface SQLiteOperation<Result> extends PromiseLike<Result> {
25
+ execute(): Promise<Result>;
26
+ }
27
+ interface SQLiteQuery<Row = SQLiteRow> {
28
+ get(): SQLiteOperation<Row | undefined>;
29
+ all(): SQLiteOperation<Row[]>;
30
+ run(): SQLiteOperation<SQLiteWriteResult>;
31
+ }
32
+ type SQLiteOperationResult<Operation> = Operation extends SQLiteOperation<infer Result> ? Result : never;
33
+ type SQLiteTransactionResult<Operations extends readonly SQLiteOperation<unknown>[]> = { -readonly [Index in keyof Operations]: SQLiteOperationResult<Operations[Index]> };
34
+ interface SQLiteDatabase {
35
+ read<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
36
+ write<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
37
+ transaction<const Operations extends readonly SQLiteOperation<unknown>[]>(operations: Operations): Promise<SQLiteTransactionResult<Operations>>;
38
+ }
39
+ //#endregion
40
+ //#region src/index.d.ts
41
+ declare function createDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
42
+ declare function getDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
43
+ //#endregion
44
+ export { ArchilSQLiteError, type SQLiteDatabase, type SQLiteDatabaseOptions, type SQLiteDisk, type SQLiteOperation, type SQLiteQuery, type SQLiteRow, type SQLiteTransactionResult, type SQLiteValue, type SQLiteWriteResult, createDatabase, getDatabase };
package/dist/index.mjs ADDED
@@ -0,0 +1,397 @@
1
+ import { exec } from "disk";
2
+ import { Buffer } from "node:buffer";
3
+ //#region src/adapter.ts
4
+ const DEFAULT_TIMEOUT_MS = 5e3;
5
+ const WRITE_MOUNT_QUEUE_MS = 5e3;
6
+ const RESULT_PREFIX = "ARCHIL_SQLITE_RESULT:";
7
+ const DISK_EXEC_MOUNT_PATH = "/mnt/archil/disk";
8
+ const REMOTE_RUNNER = `
9
+ const { Buffer } = require("node:buffer");
10
+ const { DatabaseSync } = require("node:sqlite");
11
+ const fs = require("node:fs");
12
+
13
+ const RESULT_PREFIX = ${JSON.stringify(RESULT_PREFIX)};
14
+
15
+ function emit(payload) {
16
+ const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
17
+ console.log(RESULT_PREFIX + encoded);
18
+ }
19
+
20
+ function decodeValue(value) {
21
+ switch (value.type) {
22
+ case "null":
23
+ return null;
24
+ case "number":
25
+ case "string":
26
+ return value.value;
27
+ case "bigint":
28
+ return BigInt(value.value);
29
+ case "bytes":
30
+ return Buffer.from(value.value, "base64");
31
+ default:
32
+ throw new TypeError("unsupported SQLite parameter type: " + value.type);
33
+ }
34
+ }
35
+
36
+ function encodeValue(value) {
37
+ if (value === undefined) return { type: "undefined" };
38
+ if (value === null) return { type: "null" };
39
+ if (typeof value === "number") return { type: "number", value };
40
+ if (typeof value === "string") return { type: "string", value };
41
+ if (typeof value === "bigint") return { type: "bigint", value: value.toString() };
42
+ if (value instanceof Uint8Array) {
43
+ return { type: "bytes", value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64") };
44
+ }
45
+ if (Array.isArray(value)) return { type: "array", value: value.map(encodeValue) };
46
+ if (typeof value === "object") {
47
+ return {
48
+ type: "object",
49
+ value: Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, encodeValue(entry)])),
50
+ };
51
+ }
52
+ throw new TypeError("unsupported SQLite result type: " + typeof value);
53
+ }
54
+
55
+ function executeOperation(db, operation) {
56
+ const statement = db.prepare(operation.sql);
57
+ const params = operation.params.map(decodeValue);
58
+ switch (operation.method) {
59
+ case "get":
60
+ return statement.get(...params);
61
+ case "all":
62
+ return statement.all(...params);
63
+ case "run":
64
+ return statement.run(...params);
65
+ }
66
+ }
67
+
68
+ function run(payload) {
69
+ if (!fs.existsSync(payload.databasePath)) {
70
+ const err = new Error("SQLite database does not exist at " + payload.displayPath);
71
+ err.code = "SQLITE_DATABASE_NOT_FOUND";
72
+ throw err;
73
+ }
74
+
75
+ const db = new DatabaseSync(payload.databasePath, {
76
+ readOnly: payload.readOnly,
77
+ timeout: payload.timeoutMs,
78
+ readBigInts: payload.readBigInts,
79
+ returnArrays: payload.returnArrays,
80
+ });
81
+
82
+ try {
83
+ if (!payload.transaction) {
84
+ return executeOperation(db, payload.operations[0]);
85
+ }
86
+
87
+ db.exec(payload.readOnly ? "BEGIN" : "BEGIN IMMEDIATE");
88
+ try {
89
+ const results = payload.operations.map((operation) => executeOperation(db, operation));
90
+ db.exec("COMMIT");
91
+ return results;
92
+ } catch (err) {
93
+ try {
94
+ db.exec("ROLLBACK");
95
+ } catch {}
96
+ throw err;
97
+ }
98
+ } finally {
99
+ db.close();
100
+ }
101
+ }
102
+
103
+ try {
104
+ const payload = JSON.parse(Buffer.from(process.argv[1], "base64").toString("utf8"));
105
+ emit({ ok: true, result: encodeValue(run(payload)) });
106
+ } catch (err) {
107
+ emit({
108
+ ok: false,
109
+ error: {
110
+ name: err && err.name,
111
+ message: err && err.message,
112
+ stack: err && err.stack,
113
+ code: err && err.code,
114
+ },
115
+ });
116
+ }
117
+ `;
118
+ var ArchilSQLiteError = class extends Error {
119
+ code;
120
+ remoteStack;
121
+ constructor(message, opts = {}) {
122
+ super(message);
123
+ this.name = "ArchilSQLiteError";
124
+ this.code = opts.code;
125
+ this.remoteStack = opts.remoteStack;
126
+ }
127
+ };
128
+ const operationStates = /* @__PURE__ */ new WeakMap();
129
+ function deferredPromise() {
130
+ let resolve;
131
+ let reject;
132
+ const promise = new Promise((promiseResolve, promiseReject) => {
133
+ resolve = promiseResolve;
134
+ reject = promiseReject;
135
+ });
136
+ promise.catch(() => {});
137
+ return {
138
+ promise,
139
+ resolve,
140
+ reject
141
+ };
142
+ }
143
+ var SQLiteOperationImpl = class {
144
+ executeRequest;
145
+ constructor(executeRequest, request) {
146
+ this.executeRequest = executeRequest;
147
+ operationStates.set(this, {
148
+ executeRequest,
149
+ request
150
+ });
151
+ }
152
+ execute() {
153
+ const state = operationStates.get(this);
154
+ if (!state) throw new TypeError("unknown SQLite operation");
155
+ state.promise ??= this.executeRequest(state.request);
156
+ return state.promise;
157
+ }
158
+ then(onfulfilled, onrejected) {
159
+ return this.execute().then(onfulfilled, onrejected);
160
+ }
161
+ };
162
+ var SQLiteQueryImpl = class {
163
+ executeRequest;
164
+ request;
165
+ constructor(executeRequest, request) {
166
+ this.executeRequest = executeRequest;
167
+ this.request = request;
168
+ }
169
+ get() {
170
+ return new SQLiteOperationImpl(this.executeRequest, {
171
+ ...this.request,
172
+ method: "get"
173
+ });
174
+ }
175
+ all() {
176
+ return new SQLiteOperationImpl(this.executeRequest, {
177
+ ...this.request,
178
+ method: "all"
179
+ });
180
+ }
181
+ run() {
182
+ return new SQLiteOperationImpl(this.executeRequest, {
183
+ ...this.request,
184
+ method: "run"
185
+ });
186
+ }
187
+ };
188
+ var SQLiteAdapter = class {
189
+ exec;
190
+ disk;
191
+ database;
192
+ timeoutMs;
193
+ readBigInts;
194
+ returnArrays;
195
+ constructor(exec, disk, database, options = {}) {
196
+ this.exec = exec;
197
+ this.disk = disk;
198
+ this.database = database;
199
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
200
+ this.readBigInts = options.readBigInts ?? false;
201
+ this.returnArrays = options.returnArrays ?? false;
202
+ }
203
+ read(strings, ...values) {
204
+ return new SQLiteQueryImpl((request) => this.executeSingle(request), {
205
+ kind: "read",
206
+ sql: templateToSql(strings),
207
+ params: values.map(encodeParameter)
208
+ });
209
+ }
210
+ write(strings, ...values) {
211
+ return new SQLiteQueryImpl((request) => this.executeSingle(request), {
212
+ kind: "write",
213
+ sql: templateToSql(strings),
214
+ params: values.map(encodeParameter)
215
+ });
216
+ }
217
+ async transaction(operations) {
218
+ const states = operations.map((operation) => {
219
+ const state = operationStates.get(operation);
220
+ if (!state) throw new TypeError("unknown SQLite operation");
221
+ return state;
222
+ });
223
+ const seen = /* @__PURE__ */ new Set();
224
+ for (const state of states) {
225
+ if (state.promise) throw new TypeError("SQLite operation has already started");
226
+ if (seen.has(state)) throw new TypeError("SQLite operation cannot be used more than once in a transaction");
227
+ seen.add(state);
228
+ }
229
+ const requests = states.map((state) => state.request);
230
+ const readOnly = requests.every((request) => request.kind === "read");
231
+ const deferreds = states.map(() => deferredPromise());
232
+ states.forEach((state, index) => {
233
+ state.promise = deferreds[index].promise;
234
+ });
235
+ try {
236
+ const results = await this.executeRemote(requests, {
237
+ transaction: true,
238
+ readOnly
239
+ });
240
+ results.forEach((result, index) => {
241
+ deferreds[index].resolve(result);
242
+ });
243
+ return results;
244
+ } catch (err) {
245
+ deferreds.forEach((deferred) => {
246
+ deferred.reject(err);
247
+ });
248
+ throw err;
249
+ }
250
+ }
251
+ executeSingle(request) {
252
+ return this.executeRemote([request], {
253
+ transaction: false,
254
+ readOnly: request.kind === "read"
255
+ }).then((results) => results[0]);
256
+ }
257
+ async executeRemote(operations, opts) {
258
+ const payload = {
259
+ databasePath: `${DISK_EXEC_MOUNT_PATH}/${this.database.path}`,
260
+ displayPath: this.database.path,
261
+ timeoutMs: this.timeoutMs,
262
+ readBigInts: this.readBigInts,
263
+ returnArrays: this.returnArrays,
264
+ readOnly: opts.readOnly,
265
+ transaction: opts.transaction,
266
+ operations
267
+ };
268
+ const checkoutPaths = opts.readOnly || !this.database.directory ? void 0 : [this.database.directory];
269
+ const queueMs = opts.readOnly ? void 0 : WRITE_MOUNT_QUEUE_MS;
270
+ const mount = {
271
+ disk: this.disk.id,
272
+ readOnly: opts.readOnly,
273
+ checkoutPaths,
274
+ queueMs
275
+ };
276
+ const command = buildCommand(payload);
277
+ const decoded = parseExecResult(await this.exec({
278
+ command,
279
+ disks: { disk: mount }
280
+ }));
281
+ return opts.transaction ? decoded : [decoded];
282
+ }
283
+ };
284
+ function createSQLiteAdapter(exec) {
285
+ return {
286
+ async createDatabase(disk, databasePath, options = {}) {
287
+ const database = normalizeDatabasePath(databasePath);
288
+ const rootDirectory = database.directory ? `${DISK_EXEC_MOUNT_PATH}/${database.directory}` : DISK_EXEC_MOUNT_PATH;
289
+ const mountedDatabasePath = `${rootDirectory}/${database.filename}`;
290
+ const result = await exec({
291
+ command: `mkdir -p ${shellQuote(rootDirectory)} && node --no-warnings -e ${shellQuote(CREATE_DATABASE_RUNNER)} ${shellQuote(mountedDatabasePath)}`,
292
+ disks: { disk: {
293
+ disk: disk.id,
294
+ readOnly: false,
295
+ queueMs: WRITE_MOUNT_QUEUE_MS
296
+ } }
297
+ });
298
+ if (result.exitCode !== 0) throw new ArchilSQLiteError(`SQLite database creation failed with exit code ${result.exitCode}: ${result.stderr || result.stdout}`);
299
+ return new SQLiteAdapter(exec, disk, database, options);
300
+ },
301
+ async getDatabase(disk, databasePath, options = {}) {
302
+ return new SQLiteAdapter(exec, disk, normalizeDatabasePath(databasePath), options);
303
+ }
304
+ };
305
+ }
306
+ function templateToSql(strings) {
307
+ let sql = strings[0] ?? "";
308
+ for (let i = 1; i < strings.length; i++) sql += "?" + strings[i];
309
+ return sql;
310
+ }
311
+ function normalizeDatabasePath(path) {
312
+ if (path.endsWith("/")) throw new TypeError("database path must include a file name and not end with '/'");
313
+ const segments = path.split("/").filter((segment) => segment.length > 0 && segment !== ".");
314
+ if (segments.length === 0 || segments.some((segment) => segment === "..")) throw new TypeError("database path must be a non-empty relative file path without '..'");
315
+ const filename = segments[segments.length - 1];
316
+ const directorySegments = segments.slice(0, -1);
317
+ return {
318
+ path: segments.join("/"),
319
+ directory: directorySegments.length > 0 ? directorySegments.join("/") : void 0,
320
+ filename
321
+ };
322
+ }
323
+ const CREATE_DATABASE_RUNNER = `
324
+ const { DatabaseSync } = require("node:sqlite");
325
+ const db = new DatabaseSync(process.argv[1]);
326
+ db.close();
327
+ `;
328
+ function encodeParameter(value) {
329
+ if (value === null) return { type: "null" };
330
+ if (typeof value === "number") return {
331
+ type: "number",
332
+ value
333
+ };
334
+ if (typeof value === "string") return {
335
+ type: "string",
336
+ value
337
+ };
338
+ if (typeof value === "bigint") return {
339
+ type: "bigint",
340
+ value: value.toString()
341
+ };
342
+ if (value instanceof Uint8Array) return {
343
+ type: "bytes",
344
+ value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64")
345
+ };
346
+ if (value instanceof ArrayBuffer) return {
347
+ type: "bytes",
348
+ value: Buffer.from(value).toString("base64")
349
+ };
350
+ throw new TypeError(`unsupported SQLite parameter type: ${typeof value}`);
351
+ }
352
+ function decodeWireValue(value) {
353
+ switch (value.type) {
354
+ case "undefined": return;
355
+ case "null": return null;
356
+ case "number":
357
+ case "string": return value.value;
358
+ case "bigint": return BigInt(value.value);
359
+ case "bytes": return Uint8Array.from(Buffer.from(value.value, "base64"));
360
+ case "array": return value.value.map(decodeWireValue);
361
+ case "object": return Object.fromEntries(Object.entries(value.value).map(([key, entry]) => [key, decodeWireValue(entry)]));
362
+ }
363
+ }
364
+ function buildCommand(payload) {
365
+ const encodedPayload = Buffer.from(JSON.stringify(payload), "utf8").toString("base64");
366
+ return `node --no-warnings -e ${shellQuote(REMOTE_RUNNER)} ${shellQuote(encodedPayload)}`;
367
+ }
368
+ function shellQuote(value) {
369
+ return `'${value.replace(/'/g, "'\\''")}'`;
370
+ }
371
+ function parseExecResult(result) {
372
+ if (result.exitCode !== 0) throw new ArchilSQLiteError(`SQLite serverless execution failed with exit code ${result.exitCode}: ${result.stderr || result.stdout}`);
373
+ const line = result.stdout.split(/\r?\n/).reverse().find((entry) => entry.startsWith(RESULT_PREFIX));
374
+ if (!line) throw new ArchilSQLiteError("SQLite serverless execution did not return a result payload");
375
+ let parsed;
376
+ try {
377
+ parsed = JSON.parse(Buffer.from(line.slice(21), "base64").toString("utf8"));
378
+ } catch (err) {
379
+ throw new ArchilSQLiteError(`SQLite serverless execution returned invalid JSON: ${err}`);
380
+ }
381
+ if (!parsed.ok) throw new ArchilSQLiteError(parsed.error.message ?? "SQLite serverless execution failed", {
382
+ code: parsed.error.code,
383
+ remoteStack: parsed.error.stack
384
+ });
385
+ return decodeWireValue(parsed.result);
386
+ }
387
+ //#endregion
388
+ //#region src/index.ts
389
+ const sqlite = createSQLiteAdapter((opts) => exec(opts));
390
+ function createDatabase(disk, databasePath, options) {
391
+ return sqlite.createDatabase(disk, databasePath, options);
392
+ }
393
+ function getDatabase(disk, databasePath, options) {
394
+ return sqlite.getDatabase(disk, databasePath, options);
395
+ }
396
+ //#endregion
397
+ export { ArchilSQLiteError, createDatabase, getDatabase };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@archildata/sqlite",
3
- "version": "0.0.0",
3
+ "version": "0.0.2",
4
4
  "description": "serverless SQLite databases on Archil disks",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
- "module": "dist/index.js",
8
- "types": "dist/index.d.ts",
7
+ "module": "dist/index.mjs",
8
+ "types": "dist/index.d.mts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
11
+ "types": "./dist/index.d.mts",
12
+ "import": "./dist/index.mjs",
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
@@ -19,13 +19,14 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "peerDependencies": {
22
- "disk": "^0.8.18"
22
+ "disk": "0.8.20"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.19.33",
26
- "tsup": "^8.4.0",
27
- "tsx": "^4.22.4",
28
- "typescript": "^5.9.3"
26
+ "tsdown": "^0.22.3",
27
+ "typescript": "^6.0.3",
28
+ "vitest": "^4.1.9",
29
+ "disk": "0.8.20"
29
30
  },
30
31
  "engines": {
31
32
  "node": ">= 22"
@@ -37,9 +38,9 @@
37
38
  ],
38
39
  "license": "MIT",
39
40
  "scripts": {
40
- "build": "tsup src/index.ts --format cjs,esm --dts",
41
- "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
41
+ "build": "tsdown",
42
+ "dev": "tsdown --watch",
42
43
  "typecheck": "tsc --noEmit",
43
- "test": "node --import tsx --test test/adapter.test.ts"
44
+ "test": "vitest run"
44
45
  }
45
46
  }
package/dist/index.d.ts DELETED
@@ -1,44 +0,0 @@
1
- interface SQLiteDisk {
2
- id: string;
3
- }
4
- interface SQLiteDatabaseOptions {
5
- timeoutMs?: number;
6
- readBigInts?: boolean;
7
- returnArrays?: boolean;
8
- }
9
- type SQLiteValue = null | number | bigint | string | Uint8Array | ArrayBuffer;
10
- type SQLiteRow = Record<string, SQLiteValue>;
11
- interface SQLiteWriteResult {
12
- changes: number | bigint;
13
- lastInsertRowid: number | bigint;
14
- }
15
- declare class ArchilSQLiteError extends Error {
16
- readonly code?: string | number;
17
- readonly remoteStack?: string;
18
- constructor(message: string, opts?: {
19
- code?: string | number;
20
- remoteStack?: string;
21
- });
22
- }
23
- interface SQLiteOperation<Result> extends PromiseLike<Result> {
24
- execute(): Promise<Result>;
25
- }
26
- interface SQLiteQuery<Row = SQLiteRow> {
27
- get(): SQLiteOperation<Row | undefined>;
28
- all(): SQLiteOperation<Row[]>;
29
- run(): SQLiteOperation<SQLiteWriteResult>;
30
- }
31
- type SQLiteOperationResult<Operation> = Operation extends SQLiteOperation<infer Result> ? Result : never;
32
- type SQLiteTransactionResult<Operations extends readonly SQLiteOperation<unknown>[]> = {
33
- -readonly [Index in keyof Operations]: SQLiteOperationResult<Operations[Index]>;
34
- };
35
- interface SQLiteDatabase {
36
- read<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
37
- write<Row = SQLiteRow>(strings: TemplateStringsArray, ...values: SQLiteValue[]): SQLiteQuery<Row>;
38
- transaction<const Operations extends readonly SQLiteOperation<unknown>[]>(operations: Operations): Promise<SQLiteTransactionResult<Operations>>;
39
- }
40
-
41
- declare function createDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
42
- declare function getDatabase(disk: SQLiteDisk, databasePath: string, options?: SQLiteDatabaseOptions): Promise<SQLiteDatabase>;
43
-
44
- export { ArchilSQLiteError, type SQLiteDatabase, type SQLiteDatabaseOptions, type SQLiteDisk, type SQLiteOperation, type SQLiteQuery, type SQLiteRow, type SQLiteTransactionResult, type SQLiteValue, type SQLiteWriteResult, createDatabase, getDatabase };