@event-driven-io/dumbo 0.13.0-beta.2 → 0.13.0-beta.21

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.
Files changed (90) hide show
  1. package/dist/chunk-65DKXURG.js +481 -0
  2. package/dist/chunk-65DKXURG.js.map +1 -0
  3. package/dist/chunk-7WEBHXZD.cjs +481 -0
  4. package/dist/chunk-7WEBHXZD.cjs.map +1 -0
  5. package/dist/chunk-AMACBMAZ.cjs +556 -0
  6. package/dist/chunk-AMACBMAZ.cjs.map +1 -0
  7. package/dist/chunk-FC4JR2R3.js +83 -0
  8. package/dist/chunk-FC4JR2R3.js.map +1 -0
  9. package/dist/chunk-H7ZKIJHB.cjs +83 -0
  10. package/dist/chunk-H7ZKIJHB.cjs.map +1 -0
  11. package/dist/chunk-IVJ3SNPJ.js +34 -0
  12. package/dist/chunk-IVJ3SNPJ.js.map +1 -0
  13. package/dist/chunk-R7P7CNMK.cjs +34 -0
  14. package/dist/chunk-R7P7CNMK.cjs.map +1 -0
  15. package/dist/{chunk-XVV3OOQX.js → chunk-T4A6BQRA.js} +209 -58
  16. package/dist/chunk-T4A6BQRA.js.map +1 -0
  17. package/dist/{chunk-N7RWT46K.js → chunk-XO5T5N5S.js} +2135 -1613
  18. package/dist/chunk-XO5T5N5S.js.map +1 -0
  19. package/dist/{chunk-OJ34O3Q2.cjs → chunk-XOQHZABK.cjs} +2161 -1639
  20. package/dist/chunk-XOQHZABK.cjs.map +1 -0
  21. package/dist/cloudflare.cjs +451 -0
  22. package/dist/cloudflare.cjs.map +1 -0
  23. package/dist/cloudflare.d.cts +92 -0
  24. package/dist/cloudflare.d.ts +92 -0
  25. package/dist/cloudflare.js +451 -0
  26. package/dist/cloudflare.js.map +1 -0
  27. package/dist/{columnProcessors-DMPpTPqM.d.ts → columnProcessors-C7fRa54L.d.ts} +1 -1
  28. package/dist/{columnProcessors-BX-sH7ah.d.cts → columnProcessors-Difrrk4c.d.cts} +1 -1
  29. package/dist/{connectionString-B1wm0TFc.d.cts → connectionString-oeg1LD5V.d.cts} +352 -137
  30. package/dist/{connectionString-B1wm0TFc.d.ts → connectionString-oeg1LD5V.d.ts} +352 -137
  31. package/dist/index.cjs +96 -4
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +23 -18
  34. package/dist/index.d.ts +23 -18
  35. package/dist/index.js +101 -9
  36. package/dist/index.js.map +1 -1
  37. package/dist/pg.cjs +382 -9
  38. package/dist/pg.cjs.map +1 -1
  39. package/dist/pg.d.cts +81 -105
  40. package/dist/pg.d.ts +81 -105
  41. package/dist/pg.js +434 -61
  42. package/dist/pg.js.map +1 -1
  43. package/dist/postgresql.cjs +50 -0
  44. package/dist/postgresql.cjs.map +1 -0
  45. package/dist/postgresql.d.cts +61 -0
  46. package/dist/postgresql.d.ts +61 -0
  47. package/dist/postgresql.js +50 -0
  48. package/dist/sqlite.cjs +56 -0
  49. package/dist/sqlite.cjs.map +1 -0
  50. package/dist/{index-C0h0c380.d.cts → sqlite.d.cts} +31 -10
  51. package/dist/{index-C2z_XBn6.d.ts → sqlite.d.ts} +31 -10
  52. package/dist/sqlite.js +56 -0
  53. package/dist/sqlite3.cjs +240 -11
  54. package/dist/sqlite3.cjs.map +1 -1
  55. package/dist/sqlite3.d.cts +39 -19
  56. package/dist/sqlite3.d.ts +39 -19
  57. package/dist/sqlite3.js +251 -22
  58. package/dist/sqlite3.js.map +1 -1
  59. package/package.json +69 -29
  60. package/dist/chunk-A7TC7IOP.cjs +0 -55
  61. package/dist/chunk-A7TC7IOP.cjs.map +0 -1
  62. package/dist/chunk-F7JQ7BX7.js +0 -240
  63. package/dist/chunk-F7JQ7BX7.js.map +0 -1
  64. package/dist/chunk-I34X53VL.js +0 -688
  65. package/dist/chunk-I34X53VL.js.map +0 -1
  66. package/dist/chunk-ISNF6USX.cjs +0 -688
  67. package/dist/chunk-ISNF6USX.cjs.map +0 -1
  68. package/dist/chunk-IYEHOE4S.cjs +0 -405
  69. package/dist/chunk-IYEHOE4S.cjs.map +0 -1
  70. package/dist/chunk-L2YZQAG3.cjs +0 -240
  71. package/dist/chunk-L2YZQAG3.cjs.map +0 -1
  72. package/dist/chunk-N7RWT46K.js.map +0 -1
  73. package/dist/chunk-OJ34O3Q2.cjs.map +0 -1
  74. package/dist/chunk-TXSETOGH.js +0 -55
  75. package/dist/chunk-TXSETOGH.js.map +0 -1
  76. package/dist/chunk-XVV3OOQX.js.map +0 -1
  77. package/dist/d1.cjs +0 -277
  78. package/dist/d1.cjs.map +0 -1
  79. package/dist/d1.d.cts +0 -72
  80. package/dist/d1.d.ts +0 -72
  81. package/dist/d1.js +0 -277
  82. package/dist/d1.js.map +0 -1
  83. package/dist/pg-3ACXFMU4.cjs +0 -59
  84. package/dist/pg-3ACXFMU4.cjs.map +0 -1
  85. package/dist/pg-GHOW3XSG.js +0 -59
  86. package/dist/sqlite3-EEIKQCJR.js +0 -25
  87. package/dist/sqlite3-SE4DDYZE.cjs +0 -25
  88. package/dist/sqlite3-SE4DDYZE.cjs.map +0 -1
  89. /package/dist/{pg-GHOW3XSG.js.map → postgresql.js.map} +0 -0
  90. /package/dist/{sqlite3-EEIKQCJR.js.map → sqlite.js.map} +0 -0
@@ -1,21 +1,152 @@
1
1
  import {
2
+ CheckViolationError,
3
+ ConnectionError,
4
+ DataError,
5
+ DeadlockError,
6
+ DumboError,
7
+ ForeignKeyViolationError,
8
+ InsufficientResourcesError,
9
+ IntegrityConstraintViolationError,
10
+ InvalidOperationError,
11
+ LockNotAvailableError,
12
+ NotNullViolationError,
2
13
  SQL,
3
14
  SQLFormatter,
4
15
  SQLProcessorsRegistry,
16
+ SerializationError,
17
+ SystemError,
18
+ UniqueConstraintError,
5
19
  createAlwaysNewConnectionPool,
6
20
  createAmbientConnection,
7
21
  createAmbientConnectionPool,
8
22
  createConnection,
9
23
  createSingletonConnectionPool,
10
24
  defaultProcessorsRegistry,
11
- exists,
12
25
  mapDefaultSQLColumnProcessors,
13
26
  mapSQLQueryResult,
14
27
  registerDefaultMigratorOptions,
15
28
  registerFormatter,
16
29
  sqlExecutor,
17
30
  tracer
18
- } from "./chunk-N7RWT46K.js";
31
+ } from "./chunk-XO5T5N5S.js";
32
+
33
+ // src/storage/sqlite/core/errors/errorMapper.ts
34
+ var getSqliteErrorCode = (error) => {
35
+ if (error instanceof Error && "code" in error && typeof error.code === "string") {
36
+ return error.code;
37
+ }
38
+ return void 0;
39
+ };
40
+ var getErrorMessage = (error) => error instanceof Error ? error.message : void 0;
41
+ var asError = (error) => error instanceof Error ? error : void 0;
42
+ var mapConstraintError = (message, innerError) => {
43
+ const upperMessage = message?.toUpperCase() ?? "";
44
+ if (upperMessage.includes("UNIQUE") || upperMessage.includes("PRIMARY KEY"))
45
+ return new UniqueConstraintError(message, innerError);
46
+ if (upperMessage.includes("FOREIGN KEY"))
47
+ return new ForeignKeyViolationError(message, innerError);
48
+ if (upperMessage.includes("NOT NULL"))
49
+ return new NotNullViolationError(message, innerError);
50
+ if (upperMessage.includes("CHECK"))
51
+ return new CheckViolationError(message, innerError);
52
+ return new IntegrityConstraintViolationError(message, innerError);
53
+ };
54
+ var mapSqliteError = (error) => {
55
+ if (DumboError.isInstanceOf(error)) return error;
56
+ const code = getSqliteErrorCode(error);
57
+ if (!code)
58
+ return new DumboError({
59
+ errorCode: 500,
60
+ message: getErrorMessage(error),
61
+ innerError: asError(error)
62
+ });
63
+ const message = getErrorMessage(error);
64
+ const innerError = asError(error);
65
+ switch (code) {
66
+ // ── Constraint violations (19) ──
67
+ // node-sqlite3 only exposes the primary code; subtype is in the message.
68
+ case "SQLITE_CONSTRAINT":
69
+ return mapConstraintError(message, innerError);
70
+ // ── Busy / lock contention ──
71
+ // SQLITE_BUSY (5): conflict with a separate database connection
72
+ case "SQLITE_BUSY":
73
+ return new LockNotAvailableError(message, innerError);
74
+ // SQLITE_LOCKED (6): conflict within the same connection or shared cache
75
+ case "SQLITE_LOCKED":
76
+ return new DeadlockError(message, innerError);
77
+ // SQLITE_PROTOCOL (15): WAL locking race condition
78
+ case "SQLITE_PROTOCOL":
79
+ return new LockNotAvailableError(message, innerError);
80
+ // ── Connection / open errors ──
81
+ // SQLITE_CANTOPEN (14): unable to open database file
82
+ case "SQLITE_CANTOPEN":
83
+ return new ConnectionError(message, innerError);
84
+ // SQLITE_NOTADB (26): file is not a database
85
+ case "SQLITE_NOTADB":
86
+ return new ConnectionError(message, innerError);
87
+ // ── Resource exhaustion ──
88
+ // SQLITE_NOMEM (7): out of memory
89
+ case "SQLITE_NOMEM":
90
+ return new InsufficientResourcesError(message, innerError);
91
+ // SQLITE_FULL (13): disk full
92
+ case "SQLITE_FULL":
93
+ return new InsufficientResourcesError(message, innerError);
94
+ // ── System / I/O errors ──
95
+ // SQLITE_IOERR (10): operating system I/O error
96
+ case "SQLITE_IOERR":
97
+ return new SystemError(message, innerError);
98
+ // SQLITE_CORRUPT (11): database file is corrupted
99
+ case "SQLITE_CORRUPT":
100
+ return new SystemError(message, innerError);
101
+ // SQLITE_INTERNAL (2): internal SQLite malfunction
102
+ case "SQLITE_INTERNAL":
103
+ return new SystemError(message, innerError);
104
+ // SQLITE_NOLFS (22): large file support unavailable
105
+ case "SQLITE_NOLFS":
106
+ return new SystemError(message, innerError);
107
+ // ── Data errors ──
108
+ // SQLITE_TOOBIG (18): string or BLOB too large
109
+ case "SQLITE_TOOBIG":
110
+ return new DataError(message, innerError);
111
+ // SQLITE_MISMATCH (20): datatype mismatch
112
+ case "SQLITE_MISMATCH":
113
+ return new DataError(message, innerError);
114
+ // SQLITE_RANGE (25): bind parameter index out of range
115
+ case "SQLITE_RANGE":
116
+ return new DataError(message, innerError);
117
+ // ── Invalid operations ──
118
+ // SQLITE_ERROR (1): generic SQL error (syntax errors, missing tables, etc.)
119
+ case "SQLITE_ERROR":
120
+ return new InvalidOperationError(message, innerError);
121
+ // SQLITE_READONLY (8): attempt to write to a read-only database
122
+ case "SQLITE_READONLY":
123
+ return new InvalidOperationError(message, innerError);
124
+ // SQLITE_MISUSE (21): API misuse
125
+ case "SQLITE_MISUSE":
126
+ return new InvalidOperationError(message, innerError);
127
+ // SQLITE_AUTH (23): authorization denied
128
+ case "SQLITE_AUTH":
129
+ return new InvalidOperationError(message, innerError);
130
+ // SQLITE_PERM (3): access permission denied
131
+ case "SQLITE_PERM":
132
+ return new InvalidOperationError(message, innerError);
133
+ // SQLITE_SCHEMA (17): schema changed, statement needs re-preparation
134
+ case "SQLITE_SCHEMA":
135
+ return new InvalidOperationError(message, innerError);
136
+ // ── Transaction / abort ──
137
+ // SQLITE_ABORT (4): operation aborted (e.g. by rollback)
138
+ case "SQLITE_ABORT":
139
+ return new SerializationError(message, innerError);
140
+ // SQLITE_INTERRUPT (9): operation interrupted
141
+ case "SQLITE_INTERRUPT":
142
+ return new SerializationError(message, innerError);
143
+ }
144
+ return new DumboError({
145
+ errorCode: 500,
146
+ message,
147
+ innerError
148
+ });
149
+ };
19
150
 
20
151
  // src/storage/sqlite/core/sql/processors/columProcessors.ts
21
152
  var mapColumnType = (token, { builder }) => {
@@ -75,59 +206,79 @@ var sqliteExecute = async (database, handle) => {
75
206
  await database.close();
76
207
  }
77
208
  };
78
- var sqliteSQLExecutor = (driverType, formatter) => ({
209
+ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
79
210
  driverType,
80
211
  query: async (client, sql, options) => {
81
212
  if (options?.timeoutMs) {
82
213
  await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);
83
214
  }
84
215
  tracer.info("db:sql:query", {
85
- query: (formatter ?? sqliteFormatter).format(sql).query,
86
- params: (formatter ?? sqliteFormatter).format(sql).params,
87
- debugSQL: (formatter ?? sqliteFormatter).describe(sql)
216
+ query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,
217
+ params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,
218
+ debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer })
88
219
  });
89
- let result = await client.query(sql, options);
90
- if (options?.mapping) {
91
- result = {
92
- ...result,
93
- rows: result.rows.map(
94
- (row) => mapSQLQueryResult(row, options.mapping)
95
- )
96
- };
220
+ try {
221
+ let result = await client.query(sql, options);
222
+ if (options?.mapping) {
223
+ result = {
224
+ ...result,
225
+ rows: result.rows.map(
226
+ (row) => mapSQLQueryResult(row, options.mapping)
227
+ )
228
+ };
229
+ }
230
+ return result;
231
+ } catch (error) {
232
+ tracer.error("db:sql:query:execute:error", { error });
233
+ throw (errorMapper ?? mapSqliteError)(error);
97
234
  }
98
- return result;
99
235
  },
100
236
  batchQuery: async (client, sqls, options) => {
101
237
  if (options?.timeoutMs) {
102
238
  await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);
103
239
  }
104
- const results = await client.batchQuery(sqls, options);
105
- if (options?.mapping) {
106
- return results.map((result) => ({
107
- ...result,
108
- rows: result.rows.map(
109
- (row) => mapSQLQueryResult(row, options.mapping)
110
- )
111
- }));
240
+ try {
241
+ const results = await client.batchQuery(sqls, options);
242
+ if (options?.mapping) {
243
+ return results.map((result) => ({
244
+ ...result,
245
+ rows: result.rows.map(
246
+ (row) => mapSQLQueryResult(row, options.mapping)
247
+ )
248
+ }));
249
+ }
250
+ return results;
251
+ } catch (error) {
252
+ tracer.error("db:sql:batch_query:execute:error", { error });
253
+ throw (errorMapper ?? mapSqliteError)(error);
112
254
  }
113
- return results;
114
255
  },
115
256
  command: async (client, sql, options) => {
116
257
  if (options?.timeoutMs) {
117
258
  await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);
118
259
  }
119
260
  tracer.info("db:sql:command", {
120
- query: (formatter ?? sqliteFormatter).format(sql).query,
121
- params: (formatter ?? sqliteFormatter).format(sql).params,
122
- debugSQL: (formatter ?? sqliteFormatter).describe(sql)
261
+ query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,
262
+ params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,
263
+ debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer })
123
264
  });
124
- return await client.command(sql, options);
265
+ try {
266
+ return await client.command(sql, options);
267
+ } catch (error) {
268
+ tracer.error("db:sql:command:execute:error", { error });
269
+ throw (errorMapper ?? mapSqliteError)(error);
270
+ }
125
271
  },
126
272
  batchCommand: async (client, sqls, options) => {
127
273
  if (options?.timeoutMs) {
128
274
  await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);
129
275
  }
130
- return await client.batchCommand(sqls, options);
276
+ try {
277
+ return await client.batchCommand(sqls, options);
278
+ } catch (error) {
279
+ tracer.error("db:sql:batch_command:execute:error", { error });
280
+ throw (errorMapper ?? mapSqliteError)(error);
281
+ }
131
282
  },
132
283
  formatter: formatter ?? sqliteFormatter
133
284
  });
@@ -194,22 +345,11 @@ function sqlitePool(options) {
194
345
  var DefaultSQLiteMigratorOptions = {};
195
346
  registerDefaultMigratorOptions("SQLite", DefaultSQLiteMigratorOptions);
196
347
 
197
- // src/storage/sqlite/core/schema/schema.ts
198
- var defaultPostgreSqlDatabase = "postgres";
199
- var tableExistsSQL = (tableName) => SQL`
200
- SELECT EXISTS (
201
- SELECT 1
202
- FROM sqlite_master
203
- WHERE type = 'table' AND name = ${tableName}
204
- ) AS "exists"
205
- `;
206
- var tableExists = async (pool, tableName) => exists(pool.execute.query(tableExistsSQL(tableName)));
207
-
208
348
  // src/storage/sqlite/core/index.ts
209
349
  var SQLiteDatabaseName = "SQLite";
210
350
 
211
351
  // src/storage/sqlite/core/connections/connectionString.ts
212
- var SQLiteConnectionString2 = (connectionString) => {
352
+ var SQLiteConnectionString = (connectionString) => {
213
353
  if (!connectionString.startsWith("file:") && connectionString !== ":memory:" && !connectionString.startsWith("/") && !connectionString.startsWith("./")) {
214
354
  throw new Error(
215
355
  `Invalid SQLite connection string: ${connectionString}. It should start with "file:", ":memory:", "/", or "./".`
@@ -246,20 +386,29 @@ var transactionNestingCounter = () => {
246
386
  };
247
387
  };
248
388
  var sqliteAmbientClientConnection = (options) => {
249
- const { client, driverType, initTransaction, allowNestedTransactions } = options;
389
+ const {
390
+ client,
391
+ driverType,
392
+ initTransaction,
393
+ allowNestedTransactions,
394
+ serializer,
395
+ errorMapper
396
+ } = options;
250
397
  return createAmbientConnection({
251
398
  driverType,
252
399
  client,
253
400
  initTransaction: initTransaction ?? ((connection) => sqliteTransaction(
254
401
  driverType,
255
402
  connection,
256
- allowNestedTransactions ?? false
403
+ allowNestedTransactions ?? false,
404
+ serializer
257
405
  )),
258
- executor: () => sqliteSQLExecutor(driverType)
406
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(driverType, serializer2, void 0, errorMapper),
407
+ serializer
259
408
  });
260
409
  };
261
410
  var sqliteClientConnection = (options) => {
262
- const { connectionOptions, sqliteClientFactory } = options;
411
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
263
412
  let client = null;
264
413
  const connect = async () => {
265
414
  if (client) return Promise.resolve(client);
@@ -280,13 +429,15 @@ var sqliteClientConnection = (options) => {
280
429
  initTransaction: (connection) => sqliteTransaction(
281
430
  options.driverType,
282
431
  connection,
283
- connectionOptions.transactionOptions?.allowNestedTransactions ?? false
432
+ connectionOptions.transactionOptions?.allowNestedTransactions ?? false,
433
+ serializer
284
434
  ),
285
- executor: () => sqliteSQLExecutor(options.driverType)
435
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
436
+ serializer
286
437
  });
287
438
  };
288
439
  var sqlitePoolClientConnection = (options) => {
289
- const { connectionOptions, sqliteClientFactory } = options;
440
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
290
441
  let client = null;
291
442
  const connect = async () => {
292
443
  if (client) return Promise.resolve(client);
@@ -301,18 +452,20 @@ var sqlitePoolClientConnection = (options) => {
301
452
  initTransaction: (connection) => sqliteTransaction(
302
453
  options.driverType,
303
454
  connection,
304
- connectionOptions.transactionOptions?.allowNestedTransactions ?? false
455
+ connectionOptions.transactionOptions?.allowNestedTransactions ?? false,
456
+ serializer
305
457
  ),
306
- executor: () => sqliteSQLExecutor(options.driverType)
458
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
459
+ serializer
307
460
  });
308
461
  };
309
462
  function sqliteConnection(options) {
310
463
  return options.type === "Client" ? sqliteClientConnection(options) : sqlitePoolClientConnection(options);
311
464
  }
312
- var InMemorySQLiteDatabase = SQLiteConnectionString2(":memory:");
465
+ var InMemorySQLiteDatabase = SQLiteConnectionString(":memory:");
313
466
 
314
467
  // src/storage/sqlite/core/transactions/index.ts
315
- var sqliteTransaction = (driverType, connection, allowNestedTransactions) => (getClient, options) => {
468
+ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serializer) => (getClient, options) => {
316
469
  const transactionCounter = transactionNestingCounter();
317
470
  allowNestedTransactions = options?.allowNestedTransactions ?? allowNestedTransactions;
318
471
  return {
@@ -371,18 +524,19 @@ var sqliteTransaction = (driverType, connection, allowNestedTransactions) => (ge
371
524
  );
372
525
  }
373
526
  },
374
- execute: sqlExecutor(sqliteSQLExecutor(driverType), {
527
+ execute: sqlExecutor(sqliteSQLExecutor(driverType, serializer), {
375
528
  connect: () => getClient
376
529
  })
377
530
  };
378
531
  };
379
532
 
380
533
  export {
534
+ mapSqliteError,
381
535
  sqliteFormatter,
382
536
  sqliteExecute,
383
537
  sqliteSQLExecutor,
384
538
  sqliteTransaction,
385
- SQLiteConnectionString2 as SQLiteConnectionString,
539
+ SQLiteConnectionString,
386
540
  isSQLiteError,
387
541
  transactionNestingCounter,
388
542
  sqliteAmbientClientConnection,
@@ -397,9 +551,6 @@ export {
397
551
  toSqlitePoolOptions,
398
552
  sqlitePool,
399
553
  DefaultSQLiteMigratorOptions,
400
- defaultPostgreSqlDatabase,
401
- tableExistsSQL,
402
- tableExists,
403
554
  SQLiteDatabaseName
404
555
  };
405
- //# sourceMappingURL=chunk-XVV3OOQX.js.map
556
+ //# sourceMappingURL=chunk-T4A6BQRA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/storage/sqlite/core/errors/errorMapper.ts","../src/storage/sqlite/core/sql/processors/columProcessors.ts","../src/storage/sqlite/core/sql/formatter/index.ts","../src/storage/sqlite/core/execute/execute.ts","../src/storage/sqlite/core/pool/pool.ts","../src/storage/sqlite/core/schema/migrations.ts","../src/storage/sqlite/core/index.ts","../src/storage/sqlite/core/connections/connectionString.ts","../src/storage/sqlite/core/connections/index.ts","../src/storage/sqlite/core/transactions/index.ts"],"sourcesContent":["import {\n CheckViolationError,\n ConnectionError,\n DataError,\n DeadlockError,\n DumboError,\n ForeignKeyViolationError,\n InsufficientResourcesError,\n IntegrityConstraintViolationError,\n InvalidOperationError,\n LockNotAvailableError,\n NotNullViolationError,\n SerializationError,\n SystemError,\n UniqueConstraintError,\n} from '../../../../core/errors';\n\n/**\n * Extracts the SQLite error code string from a `sqlite3` driver error.\n *\n * The `sqlite3` (node-sqlite3) driver sets `error.code` to a string like\n * `'SQLITE_CONSTRAINT'` and `error.errno` to the numeric result code.\n * See: https://github.com/TryGhost/node-sqlite3\n */\nconst getSqliteErrorCode = (error: unknown): string | undefined => {\n if (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as Record<string, unknown>).code === 'string'\n ) {\n return (error as Record<string, unknown>).code as string;\n }\n return undefined;\n};\n\nconst getErrorMessage = (error: unknown): string | undefined =>\n error instanceof Error ? error.message : undefined;\n\nconst asError = (error: unknown): Error | undefined =>\n error instanceof Error ? error : undefined;\n\n/**\n * Maps a constraint error to a specific DumboError subtype by inspecting the\n * error message. The `sqlite3` driver only exposes the primary result code\n * `SQLITE_CONSTRAINT` — the constraint subtype (UNIQUE, FOREIGN KEY, etc.)\n * is embedded in the message string by SQLite, e.g.:\n * \"SQLITE_CONSTRAINT: UNIQUE constraint failed: users.email\"\n *\n * Reference: https://www.sqlite.org/rescode.html (extended result codes 275–3091)\n */\nconst mapConstraintError = (\n message: string | undefined,\n innerError: Error | undefined,\n): DumboError => {\n const upperMessage = message?.toUpperCase() ?? '';\n\n // SQLITE_CONSTRAINT_UNIQUE (2067) / SQLITE_CONSTRAINT_PRIMARYKEY (1555)\n if (upperMessage.includes('UNIQUE') || upperMessage.includes('PRIMARY KEY'))\n return new UniqueConstraintError(message, innerError);\n\n // SQLITE_CONSTRAINT_FOREIGNKEY (787)\n if (upperMessage.includes('FOREIGN KEY'))\n return new ForeignKeyViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_NOTNULL (1299)\n if (upperMessage.includes('NOT NULL'))\n return new NotNullViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_CHECK (275)\n if (upperMessage.includes('CHECK'))\n return new CheckViolationError(message, innerError);\n\n // SQLITE_CONSTRAINT_ROWID (2579), SQLITE_CONSTRAINT_TRIGGER (1811),\n // SQLITE_CONSTRAINT_COMMITHOOK (531), SQLITE_CONSTRAINT_PINNED (2835),\n // SQLITE_CONSTRAINT_DATATYPE (3091), etc.\n return new IntegrityConstraintViolationError(message, innerError);\n};\n\n/**\n * Maps a SQLite error (from the `sqlite3` / node-sqlite3 driver) to a typed\n * DumboError based on the SQLite result code.\n *\n * Result code reference: https://www.sqlite.org/rescode.html\n *\n * Falls back to a generic DumboError (500) if the error is not a recognized SQLite error.\n */\nexport const mapSqliteError = (error: unknown): DumboError => {\n if (DumboError.isInstanceOf<DumboError>(error)) return error;\n\n const code = getSqliteErrorCode(error);\n if (!code)\n return new DumboError({\n errorCode: 500,\n message: getErrorMessage(error),\n innerError: asError(error),\n });\n\n const message = getErrorMessage(error);\n const innerError = asError(error);\n\n switch (code) {\n // ── Constraint violations (19) ──\n // node-sqlite3 only exposes the primary code; subtype is in the message.\n case 'SQLITE_CONSTRAINT':\n return mapConstraintError(message, innerError);\n\n // ── Busy / lock contention ──\n // SQLITE_BUSY (5): conflict with a separate database connection\n case 'SQLITE_BUSY':\n return new LockNotAvailableError(message, innerError);\n\n // SQLITE_LOCKED (6): conflict within the same connection or shared cache\n case 'SQLITE_LOCKED':\n return new DeadlockError(message, innerError);\n\n // SQLITE_PROTOCOL (15): WAL locking race condition\n case 'SQLITE_PROTOCOL':\n return new LockNotAvailableError(message, innerError);\n\n // ── Connection / open errors ──\n // SQLITE_CANTOPEN (14): unable to open database file\n case 'SQLITE_CANTOPEN':\n return new ConnectionError(message, innerError);\n\n // SQLITE_NOTADB (26): file is not a database\n case 'SQLITE_NOTADB':\n return new ConnectionError(message, innerError);\n\n // ── Resource exhaustion ──\n // SQLITE_NOMEM (7): out of memory\n case 'SQLITE_NOMEM':\n return new InsufficientResourcesError(message, innerError);\n\n // SQLITE_FULL (13): disk full\n case 'SQLITE_FULL':\n return new InsufficientResourcesError(message, innerError);\n\n // ── System / I/O errors ──\n // SQLITE_IOERR (10): operating system I/O error\n case 'SQLITE_IOERR':\n return new SystemError(message, innerError);\n\n // SQLITE_CORRUPT (11): database file is corrupted\n case 'SQLITE_CORRUPT':\n return new SystemError(message, innerError);\n\n // SQLITE_INTERNAL (2): internal SQLite malfunction\n case 'SQLITE_INTERNAL':\n return new SystemError(message, innerError);\n\n // SQLITE_NOLFS (22): large file support unavailable\n case 'SQLITE_NOLFS':\n return new SystemError(message, innerError);\n\n // ── Data errors ──\n // SQLITE_TOOBIG (18): string or BLOB too large\n case 'SQLITE_TOOBIG':\n return new DataError(message, innerError);\n\n // SQLITE_MISMATCH (20): datatype mismatch\n case 'SQLITE_MISMATCH':\n return new DataError(message, innerError);\n\n // SQLITE_RANGE (25): bind parameter index out of range\n case 'SQLITE_RANGE':\n return new DataError(message, innerError);\n\n // ── Invalid operations ──\n // SQLITE_ERROR (1): generic SQL error (syntax errors, missing tables, etc.)\n case 'SQLITE_ERROR':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_READONLY (8): attempt to write to a read-only database\n case 'SQLITE_READONLY':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_MISUSE (21): API misuse\n case 'SQLITE_MISUSE':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_AUTH (23): authorization denied\n case 'SQLITE_AUTH':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_PERM (3): access permission denied\n case 'SQLITE_PERM':\n return new InvalidOperationError(message, innerError);\n\n // SQLITE_SCHEMA (17): schema changed, statement needs re-preparation\n case 'SQLITE_SCHEMA':\n return new InvalidOperationError(message, innerError);\n\n // ── Transaction / abort ──\n // SQLITE_ABORT (4): operation aborted (e.g. by rollback)\n case 'SQLITE_ABORT':\n return new SerializationError(message, innerError);\n\n // SQLITE_INTERRUPT (9): operation interrupted\n case 'SQLITE_INTERRUPT':\n return new SerializationError(message, innerError);\n }\n\n return new DumboError({\n errorCode: 500,\n message,\n innerError,\n });\n};\n","import {\n mapDefaultSQLColumnProcessors,\n type DefaultSQLColumnProcessors,\n type DefaultSQLColumnToken,\n type SQLProcessorContext,\n} from '../../../../../core';\n\nconst mapColumnType = (\n token: DefaultSQLColumnToken,\n { builder }: SQLProcessorContext,\n): void => {\n let columnSQL: string;\n const { sqlTokenType } = token;\n switch (sqlTokenType) {\n case 'SQL_COLUMN_AUTO_INCREMENT':\n columnSQL = `INTEGER ${token.primaryKey ? 'PRIMARY KEY' : ''} AUTOINCREMENT`;\n break;\n case 'SQL_COLUMN_BIGINT':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_SERIAL':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_INTEGER':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_JSONB':\n columnSQL = 'BLOB';\n break;\n case 'SQL_COLUMN_BIGSERIAL':\n columnSQL = 'INTEGER';\n break;\n case 'SQL_COLUMN_TIMESTAMP':\n columnSQL = 'DATETIME';\n break;\n case 'SQL_COLUMN_TIMESTAMPTZ':\n columnSQL = 'DATETIME';\n break;\n case 'SQL_COLUMN_VARCHAR':\n columnSQL = `VARCHAR ${Number.isNaN(token.length) ? '' : `(${token.length})`}`;\n break;\n default: {\n const exhaustiveCheck: never = sqlTokenType;\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n throw new Error(`Unknown column type: ${exhaustiveCheck}`);\n }\n }\n builder.addSQL(columnSQL);\n};\n\nexport const sqliteColumnProcessors: DefaultSQLColumnProcessors =\n mapDefaultSQLColumnProcessors(mapColumnType);\n","import {\n defaultProcessorsRegistry,\n registerFormatter,\n SQLFormatter,\n SQLProcessorsRegistry,\n} from '../../../../../core/sql';\nimport { sqliteColumnProcessors } from '../processors';\n\nconst sqliteSQLProcessorsRegistry = SQLProcessorsRegistry({\n from: defaultProcessorsRegistry,\n}).register(sqliteColumnProcessors);\n\nconst sqliteFormatter: SQLFormatter = SQLFormatter({\n processorsRegistry: sqliteSQLProcessorsRegistry,\n});\n\nregisterFormatter('SQLite', sqliteFormatter);\n\nexport { sqliteFormatter };\n","import type { SQLiteDriverType } from '..';\nimport type { JSONSerializer, SQLFormatter } from '../../../../core';\nimport {\n mapSQLQueryResult,\n SQL,\n tracer,\n type BatchSQLCommandOptions,\n type DbSQLExecutor,\n type QueryResult,\n type QueryResultRow,\n type SQLCommandOptions,\n type SQLQueryOptions,\n} from '../../../../core';\nimport type { DumboError } from '../../../../core/errors';\nimport type { SQLiteClient } from '../connections';\nimport { mapSqliteError } from '../errors/errorMapper';\nimport { sqliteFormatter } from '../sql/formatter';\n\nexport type SQLiteErrorMapper = (error: unknown) => DumboError;\n\nexport const sqliteExecute = async <Result = void>(\n database: SQLiteClient,\n handle: (client: SQLiteClient) => Promise<Result>,\n) => {\n try {\n return await handle(database);\n } finally {\n await database.close();\n }\n};\n\nexport type SQLiteSQLExecutor<\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n> = DbSQLExecutor<DriverType, SQLiteClient>;\n\nexport const sqliteSQLExecutor = <\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n>(\n driverType: DriverType,\n serializer: JSONSerializer,\n formatter?: SQLFormatter,\n errorMapper?: SQLiteErrorMapper,\n): SQLiteSQLExecutor<DriverType> => ({\n driverType,\n query: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sql: SQL,\n options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>> => {\n if (options?.timeoutMs) {\n await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);\n }\n\n tracer.info('db:sql:query', {\n query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,\n params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,\n debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer }),\n });\n\n try {\n let result = await client.query<Result>(sql, options);\n\n if (options?.mapping) {\n result = {\n ...result,\n rows: result.rows.map((row) =>\n mapSQLQueryResult(row, options.mapping!),\n ),\n };\n }\n\n return result;\n } catch (error) {\n tracer.error('db:sql:query:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n batchQuery: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sqls: SQL[],\n options?: SQLQueryOptions,\n ): Promise<QueryResult<Result>[]> => {\n if (options?.timeoutMs) {\n await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);\n }\n\n try {\n const results = await client.batchQuery<Result>(sqls, options);\n\n if (options?.mapping) {\n return results.map((result) => ({\n ...result,\n rows: result.rows.map((row) =>\n mapSQLQueryResult(row, options.mapping!),\n ),\n }));\n }\n\n return results;\n } catch (error) {\n tracer.error('db:sql:batch_query:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n command: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sql: SQL,\n options?: SQLCommandOptions,\n ): Promise<QueryResult<Result>> => {\n if (options?.timeoutMs) {\n await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);\n }\n\n tracer.info('db:sql:command', {\n query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,\n params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,\n debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer }),\n });\n\n try {\n return await client.command<Result>(sql, options);\n } catch (error) {\n tracer.error('db:sql:command:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n batchCommand: async <Result extends QueryResultRow = QueryResultRow>(\n client: SQLiteClient,\n sqls: SQL[],\n options?: BatchSQLCommandOptions,\n ): Promise<QueryResult<Result>[]> => {\n if (options?.timeoutMs) {\n await client.query(SQL`PRAGMA busy_timeout = ${options.timeoutMs}`);\n }\n\n try {\n return await client.batchCommand<Result>(sqls, options);\n } catch (error) {\n tracer.error('db:sql:batch_command:execute:error', { error });\n throw (errorMapper ?? mapSqliteError)(error);\n }\n },\n formatter: formatter ?? sqliteFormatter,\n});\n","import type { SQLiteConnectionString } from '..';\nimport {\n InMemorySQLiteDatabase,\n type AnySQLiteConnection,\n type SQLiteConnectionFactory,\n type SQLiteConnectionOptions,\n} from '..';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n createAlwaysNewConnectionPool,\n createAmbientConnectionPool,\n createSingletonConnectionPool,\n type ConnectionPool,\n type InferTransactionFromConnection,\n type InferTransactionOptionsFromConnection,\n} from '../../../../core';\n\nexport type SQLiteFileNameOrConnectionString =\n | {\n fileName: string | SQLiteConnectionString;\n connectionString?: never;\n }\n | {\n connectionString: string | SQLiteConnectionString;\n fileName?: never;\n };\n\nexport const isInMemoryDatabase = (\n options: Record<string, unknown>,\n): boolean => {\n if ('fileName' in options) {\n return options.fileName === InMemorySQLiteDatabase;\n }\n if ('connectionString' in options) {\n return options.connectionString === InMemorySQLiteDatabase;\n }\n return false;\n};\n\nexport type SQLiteAmbientConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<\n SQLiteConnectionType,\n InferTransactionFromConnection<SQLiteConnectionType>,\n InferTransactionOptionsFromConnection<SQLiteConnectionType>\n>;\n\ntype SQLiteAmbientConnectionPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = {\n singleton?: true;\n pooled?: false;\n sqliteConnectionFactory?: never;\n connection: SQLiteConnectionType;\n connectionOptions?: never;\n};\n\nexport const sqliteAmbientConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType['driverType']>,\n): SQLiteAmbientConnectionPool<SQLiteConnectionType['driverType']> => {\n const { connection, driverType } = options;\n\n return createAmbientConnectionPool<SQLiteConnectionType>({\n driverType,\n connection: connection,\n }) as unknown as SQLiteAmbientConnectionPool<\n SQLiteConnectionType['driverType']\n >;\n};\n\ntype SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = {\n singleton: true;\n pooled?: true;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connection?: never;\n connectionOptions: ConnectionOptions;\n};\n\nexport type SQLiteSingletonConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<\n SQLiteConnectionType,\n InferTransactionFromConnection<SQLiteConnectionType>,\n InferTransactionOptionsFromConnection<SQLiteConnectionType>\n>;\n\nexport const sqliteSingletonConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions & Record<string, unknown> =\n SQLiteConnectionOptions & Record<string, unknown>,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >,\n): SQLiteSingletonConnectionPool<SQLiteConnectionType> => {\n const { driverType, sqliteConnectionFactory, connectionOptions } = options;\n\n return createSingletonConnectionPool<SQLiteConnectionType>({\n driverType,\n getConnection: () => sqliteConnectionFactory(connectionOptions),\n }) as unknown as SQLiteSingletonConnectionPool<SQLiteConnectionType>;\n};\n\ntype SQLiteAlwaysNewPoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = {\n singleton?: false;\n pooled?: true;\n sqliteConnectionFactory: SQLiteConnectionFactory<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n connection?: never;\n connectionOptions: ConnectionOptions;\n};\n\nexport type SQLiteAlwaysNewConnectionPool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionPool<\n SQLiteConnectionType,\n InferTransactionFromConnection<SQLiteConnectionType>,\n InferTransactionOptionsFromConnection<SQLiteConnectionType>\n>;\n\nexport const sqliteAlwaysNewConnectionPool = <\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions & Record<string, unknown> =\n SQLiteConnectionOptions & Record<string, unknown>,\n>(\n options: {\n driverType: SQLiteConnectionType['driverType'];\n } & SQLiteAlwaysNewPoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLiteAlwaysNewConnectionPool<SQLiteConnectionType> => {\n const { driverType, sqliteConnectionFactory, connectionOptions } = options;\n\n return createAlwaysNewConnectionPool<SQLiteConnectionType>({\n driverType,\n getConnection: () => sqliteConnectionFactory(connectionOptions),\n }) as unknown as SQLiteAlwaysNewConnectionPool<SQLiteConnectionType>;\n};\n\nexport type SQLitePoolOptions<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = (\n | SQLiteAlwaysNewPoolOptions<SQLiteConnectionType, ConnectionOptions>\n | SQLiteSingletonConnectionPoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >\n | SQLiteAmbientConnectionPoolOptions<SQLiteConnectionType>\n) & {\n driverType: SQLiteConnectionType['driverType'];\n serializer?: JSONSerializer;\n};\n\nexport type SQLitePool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> =\n | SQLiteAmbientConnectionPool<SQLiteConnectionType>\n | SQLiteSingletonConnectionPool<SQLiteConnectionType>\n | SQLiteAlwaysNewConnectionPool<SQLiteConnectionType>;\n\nexport type SQLitePoolFactoryOptions<\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n> = Omit<\n SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions>,\n 'singleton'\n> & {\n singleton?: boolean;\n};\n\nexport const toSqlitePoolOptions = <\n SQLiteConnectionType extends AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions,\n>(\n options: SQLitePoolFactoryOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions> => {\n const { singleton, ...rest } = options;\n const useSingleton = singleton ?? isInMemoryDatabase(options);\n\n if (useSingleton) {\n return { ...rest, singleton: true } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n }\n return { ...rest, singleton: false } as SQLitePoolOptions<\n SQLiteConnectionType,\n ConnectionOptions\n >;\n};\n\nexport function sqlitePool<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n>(\n options: SQLitePoolOptions<SQLiteConnectionType, ConnectionOptions>,\n): SQLitePool<SQLiteConnectionType> {\n const { driverType } = options;\n\n // TODO: Handle dates and bigints\n // setSQLiteTypeParser(serializer ?? JSONSerializer);\n\n if (options.connection)\n return createAmbientConnectionPool<SQLiteConnectionType>({\n driverType,\n connection: options.connection,\n }) as unknown as SQLitePool<SQLiteConnectionType>;\n\n if (options.singleton === true && options.sqliteConnectionFactory) {\n return createSingletonConnectionPool({\n driverType,\n getConnection: () =>\n options.sqliteConnectionFactory(options.connectionOptions),\n }) as unknown as SQLitePool<SQLiteConnectionType>;\n }\n\n return createAlwaysNewConnectionPool({\n driverType,\n getConnection: () =>\n options.sqliteConnectionFactory!(options.connectionOptions!),\n }) as unknown as SQLitePool<SQLiteConnectionType>;\n}\n","import {\n registerDefaultMigratorOptions,\n type MigratorOptions,\n} from '../../../../core';\n\nexport const DefaultSQLiteMigratorOptions: MigratorOptions = {};\n\nregisterDefaultMigratorOptions('SQLite', DefaultSQLiteMigratorOptions);\n","import type { DatabaseDriverType } from '../../..';\n\nexport * from './connections';\nexport * from './errors';\nexport * from './execute';\nexport * from './pool';\nexport * from './schema';\nexport * from './sql';\nexport * from './transactions';\n\nexport type SQLiteDatabaseName = 'SQLite';\nexport const SQLiteDatabaseName = 'SQLite';\n\nexport type SQLiteDriverType<DriverName extends string = string> =\n DatabaseDriverType<SQLiteDatabaseName, DriverName>;\n\nexport type SQLiteDatabaseType = 'SQLite';\n","import type { DatabaseConnectionString } from '../../../all';\n\nexport type SQLiteConnectionString = DatabaseConnectionString<\n 'SQLite',\n `file:${string}` | `:memory:` | `/${string}` | `./${string}`\n>;\n\nexport const SQLiteConnectionString = (\n connectionString: string,\n): SQLiteConnectionString => {\n if (\n !connectionString.startsWith('file:') &&\n connectionString !== ':memory:' &&\n !connectionString.startsWith('/') &&\n !connectionString.startsWith('./')\n ) {\n throw new Error(\n `Invalid SQLite connection string: ${connectionString}. It should start with \"file:\", \":memory:\", \"/\", or \"./\".`,\n );\n }\n return connectionString as SQLiteConnectionString;\n};\n","import {\n SQLiteConnectionString,\n sqliteSQLExecutor,\n type SQLiteDriverType,\n type SQLiteErrorMapper,\n} from '..';\nimport type { JSONSerializer } from '../../../../core';\nimport {\n createAmbientConnection,\n createConnection,\n type AnyConnection,\n type BatchSQLCommandOptions,\n type Connection,\n type ConnectionOptions,\n type DatabaseTransaction,\n type DatabaseTransactionOptions,\n type InferDbClientFromConnection,\n type InferDriverTypeFromConnection,\n type InitTransaction,\n type SQLCommandOptions,\n type SQLExecutor,\n} from '../../../../core';\nimport { sqliteTransaction } from '../transactions';\n\nexport type SQLiteCommandOptions = SQLCommandOptions & {\n ignoreChangesCount?: boolean;\n};\n\nexport type BatchSQLiteCommandOptions = SQLiteCommandOptions &\n BatchSQLCommandOptions;\n\nexport type SQLiteParameters =\n | object\n | string\n | bigint\n | number\n | boolean\n | null;\n\nexport type SQLiteClient = {\n connect: () => Promise<void>;\n close: () => Promise<void>;\n} & SQLExecutor;\n\nexport type SQLitePoolClient = {\n release: () => void;\n} & SQLExecutor;\n\nexport type SQLiteClientFactory<\n SQLiteClientType extends SQLiteClient = SQLiteClient,\n ClientOptions = SQLiteClientOptions,\n> = (options: ClientOptions) => SQLiteClientType;\n\nexport type SQLiteClientOrPoolClient = SQLitePoolClient | SQLiteClient;\n\nexport interface SQLiteError extends Error {\n errno: number;\n}\n\nexport const isSQLiteError = (error: unknown): error is SQLiteError => {\n if (error instanceof Error && 'code' in error) {\n return true;\n }\n\n return false;\n};\n\nexport type SQLiteClientConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLiteClientType extends SQLiteClient = SQLiteClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n TransactionOptionsType extends DatabaseTransactionOptions =\n DatabaseTransactionOptions,\n> = Connection<\n Self,\n DriverType,\n SQLiteClientType,\n TransactionType,\n TransactionOptionsType\n>;\n\nexport type SQLitePoolClientConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLitePoolClientType extends SQLitePoolClient = SQLitePoolClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n TransactionOptionsType extends DatabaseTransactionOptions =\n DatabaseTransactionOptions,\n> = Connection<\n Self,\n DriverType,\n SQLitePoolClientType,\n TransactionType,\n TransactionOptionsType\n>;\n\nexport type SQLiteConnection<\n Self extends AnyConnection = AnyConnection,\n DriverType extends SQLiteDriverType = SQLiteDriverType,\n SQLiteClientType extends SQLiteClientOrPoolClient =\n | SQLiteClient\n | SQLitePoolClient,\n TransactionType extends DatabaseTransaction<Self> = DatabaseTransaction<Self>,\n TransactionOptionsType extends DatabaseTransactionOptions =\n DatabaseTransactionOptions,\n> =\n | (SQLiteClientType extends SQLiteClient\n ? SQLiteClientConnection<\n Self,\n DriverType,\n SQLiteClientType,\n TransactionType,\n TransactionOptionsType\n >\n : never)\n | (SQLiteClientType extends SQLitePoolClient\n ? SQLitePoolClientConnection<\n Self,\n DriverType,\n SQLiteClientType,\n TransactionType,\n TransactionOptionsType\n >\n : never);\n\nexport type AnySQLiteClientConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLiteClientConnection<any, any>;\n\nexport type AnySQLitePoolClientConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLitePoolClientConnection<any, any, any, any, any>;\n\nexport type AnySQLiteConnection =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n SQLiteConnection<any, any, any, any, any>;\n\nexport type SQLiteConnectionOptions<\n ConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = ConnectionOptions<ConnectionType> & SQLiteClientOptions;\n\nexport type SQLiteClientConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ConnectionOptions = SQLiteConnectionOptions,\n> = {\n driverType: InferDriverTypeFromConnection<SQLiteConnectionType>;\n type: 'Client';\n sqliteClientFactory: SQLiteClientFactory<\n InferDbClientFromConnection<SQLiteConnectionType>,\n ConnectionOptions\n >;\n connectionOptions: SQLiteConnectionOptions<SQLiteConnectionType>;\n serializer: JSONSerializer;\n};\n\nexport type SQLitePoolConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLitePoolClientConnection =\n AnySQLitePoolClientConnection,\n ConnectionOptions = SQLiteConnectionOptions,\n> = {\n driverType: InferDriverTypeFromConnection<SQLiteConnectionType>;\n type: 'PoolClient';\n sqliteClientFactory: SQLiteClientFactory<\n InferDbClientFromConnection<SQLiteConnectionType>,\n ConnectionOptions\n >;\n connectionOptions: SQLiteConnectionOptions<SQLiteConnectionType>;\n serializer: JSONSerializer;\n};\n\nexport type SQLiteConnectionDefinitionOptions<\n SQLiteConnectionType extends AnySQLitePoolClientConnection =\n AnySQLitePoolClientConnection,\n ClientOptions = SQLiteClientOptions,\n> =\n | SQLiteClientConnectionDefinitionOptions<SQLiteConnectionType, ClientOptions>\n | SQLitePoolConnectionDefinitionOptions<SQLiteConnectionType, ClientOptions>;\n\nexport type SQLiteConnectionFactory<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ConnectionOptions extends SQLiteConnectionOptions = SQLiteConnectionOptions,\n> = (options: ConnectionOptions) => SQLiteConnectionType;\n\nexport type TransactionNestingCounter = {\n increment: () => void;\n decrement: () => void;\n reset: () => void;\n level: number;\n};\n\nexport const transactionNestingCounter = (): TransactionNestingCounter => {\n let transactionLevel = 0;\n\n return {\n reset: () => {\n transactionLevel = 0;\n },\n increment: () => {\n transactionLevel++;\n },\n decrement: () => {\n transactionLevel--;\n\n if (transactionLevel < 0) {\n throw new Error('Transaction level is out of bounds');\n }\n },\n get level() {\n return transactionLevel;\n },\n };\n};\n\nexport type SqliteAmbientClientConnectionOptions<\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n TransactionType extends DatabaseTransaction<SQLiteConnectionType> =\n DatabaseTransaction<SQLiteConnectionType>,\n TransactionOptionsType extends DatabaseTransactionOptions =\n DatabaseTransactionOptions,\n> = {\n driverType: SQLiteConnectionType['driverType'];\n client: InferDbClientFromConnection<SQLiteConnectionType>;\n initTransaction?: InitTransaction<\n SQLiteConnectionType,\n TransactionType,\n TransactionOptionsType\n >;\n allowNestedTransactions?: boolean;\n serializer: JSONSerializer;\n errorMapper?: SQLiteErrorMapper;\n};\n\nexport const sqliteAmbientClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n>(\n options: SqliteAmbientClientConnectionOptions<SQLiteConnectionType>,\n) => {\n const {\n client,\n driverType,\n initTransaction,\n allowNestedTransactions,\n serializer,\n errorMapper,\n } = options;\n\n return createAmbientConnection<SQLiteConnectionType>({\n driverType,\n client,\n initTransaction:\n initTransaction ??\n ((connection) =>\n sqliteTransaction(\n driverType,\n connection,\n allowNestedTransactions ?? false,\n serializer,\n )),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(driverType, serializer, undefined, errorMapper),\n serializer,\n });\n};\n\nexport const sqliteClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLiteClientConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType => {\n const { connectionOptions, sqliteClientFactory, serializer } = options;\n\n let client: InferDbClientFromConnection<SQLiteConnectionType> | null = null;\n\n const connect = async (): Promise<\n InferDbClientFromConnection<SQLiteConnectionType>\n > => {\n if (client) return Promise.resolve(client);\n\n client = sqliteClientFactory(connectionOptions as ClientOptions);\n\n if (client && 'connect' in client && typeof client.connect === 'function')\n await client.connect();\n\n return client;\n };\n\n return createConnection({\n driverType: options.driverType,\n connect,\n close: async () => {\n if (client && 'close' in client && typeof client.close === 'function')\n await client.close();\n else if (\n client &&\n 'release' in client &&\n typeof client.release === 'function'\n )\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n client.release();\n },\n initTransaction: (connection) =>\n sqliteTransaction(\n options.driverType,\n connection,\n connectionOptions.transactionOptions?.allowNestedTransactions ?? false,\n serializer,\n ),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(options.driverType, serializer),\n serializer,\n });\n};\n\nexport const sqlitePoolClientConnection = <\n SQLiteConnectionType extends AnySQLiteClientConnection =\n AnySQLiteClientConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLitePoolConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType => {\n const { connectionOptions, sqliteClientFactory, serializer } = options;\n\n let client: InferDbClientFromConnection<SQLiteConnectionType> | null = null;\n\n const connect = async (): Promise<\n InferDbClientFromConnection<SQLiteConnectionType>\n > => {\n if (client) return Promise.resolve(client);\n\n client = sqliteClientFactory(connectionOptions as ClientOptions);\n\n await client.connect();\n\n return client;\n };\n\n return createConnection({\n driverType: options.driverType,\n connect,\n close: () =>\n client !== null\n ? Promise.resolve((client as unknown as SQLitePoolClient).release())\n : Promise.resolve(),\n initTransaction: (connection) =>\n sqliteTransaction(\n options.driverType,\n connection,\n connectionOptions.transactionOptions?.allowNestedTransactions ?? false,\n serializer,\n ),\n executor: ({ serializer }) =>\n sqliteSQLExecutor(options.driverType, serializer),\n serializer,\n });\n};\n\nexport function sqliteConnection<\n SQLiteConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n ClientOptions = SQLiteClientOptions,\n>(\n options: SQLiteConnectionDefinitionOptions<\n SQLiteConnectionType,\n ClientOptions\n >,\n): SQLiteConnectionType {\n return options.type === 'Client'\n ? sqliteClientConnection(options)\n : sqlitePoolClientConnection(options);\n}\n\nexport type InMemorySQLiteDatabase = ':memory:';\nexport const InMemorySQLiteDatabase = SQLiteConnectionString(':memory:');\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport type SQLiteClientOptions = {};\n\nexport * from './connectionString';\n","import type { JSONSerializer } from '../../../../core';\nimport {\n SQL,\n sqlExecutor,\n type DatabaseTransaction,\n type DatabaseTransactionOptions,\n type InferDbClientFromConnection,\n} from '../../../../core';\nimport { sqliteSQLExecutor } from '../../core/execute';\nimport {\n transactionNestingCounter,\n type AnySQLiteConnection,\n type SQLiteClientOrPoolClient,\n} from '../connections';\n\nexport type SQLiteTransaction<\n ConnectionType extends AnySQLiteConnection = AnySQLiteConnection,\n> = DatabaseTransaction<ConnectionType>;\n\nexport type SQLiteTransactionMode = 'DEFERRED' | 'IMMEDIATE' | 'EXCLUSIVE';\n\nexport type SQLiteTransactionOptions = DatabaseTransactionOptions & {\n mode?: SQLiteTransactionMode;\n};\n\nexport const sqliteTransaction =\n <ConnectionType extends AnySQLiteConnection = AnySQLiteConnection>(\n driverType: ConnectionType['driverType'],\n connection: () => ConnectionType,\n allowNestedTransactions: boolean,\n serializer: JSONSerializer,\n ) =>\n (\n getClient: Promise<InferDbClientFromConnection<ConnectionType>>,\n options?: {\n close: (\n client: InferDbClientFromConnection<ConnectionType>,\n error?: unknown,\n ) => Promise<void>;\n } & DatabaseTransactionOptions,\n ): DatabaseTransaction<ConnectionType> => {\n const transactionCounter = transactionNestingCounter();\n allowNestedTransactions =\n options?.allowNestedTransactions ?? allowNestedTransactions;\n\n return {\n connection: connection(),\n driverType,\n begin: async function () {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n\n if (allowNestedTransactions) {\n if (transactionCounter.level >= 1) {\n transactionCounter.increment();\n await client.query(\n SQL`SAVEPOINT transaction${SQL.plain(transactionCounter.level.toString())}`,\n );\n return;\n }\n\n transactionCounter.increment();\n }\n\n await client.query(SQL`BEGIN TRANSACTION`);\n },\n commit: async function () {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n\n try {\n if (allowNestedTransactions) {\n if (transactionCounter.level > 1) {\n await client.query(\n SQL`RELEASE transaction${SQL.plain(transactionCounter.level.toString())}`,\n );\n transactionCounter.decrement();\n\n return;\n }\n\n transactionCounter.reset();\n }\n await client.query(SQL`COMMIT`);\n } finally {\n if (options?.close)\n await options?.close(\n client as InferDbClientFromConnection<ConnectionType>,\n );\n }\n },\n rollback: async function (error?: unknown) {\n const client = (await getClient) as SQLiteClientOrPoolClient;\n try {\n if (allowNestedTransactions) {\n if (transactionCounter.level > 1) {\n transactionCounter.decrement();\n return;\n }\n }\n\n await client.query(SQL`ROLLBACK`);\n } finally {\n if (options?.close)\n await options?.close(\n client as InferDbClientFromConnection<ConnectionType>,\n error,\n );\n }\n },\n execute: sqlExecutor(sqliteSQLExecutor(driverType, serializer), {\n connect: () => getClient,\n }),\n };\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,IAAM,qBAAqB,CAAC,UAAuC;AACjE,MACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAAkC,SAAS,UACnD;AACA,WAAQ,MAAkC;AAAA,EAC5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