@event-driven-io/dumbo 0.13.0-beta.3 → 0.13.0-beta.30

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 (91) hide show
  1. package/dist/chunk-4SM4JJJZ.js +83 -0
  2. package/dist/chunk-4SM4JJJZ.js.map +1 -0
  3. package/dist/chunk-EEKBLOCH.cjs +706 -0
  4. package/dist/chunk-EEKBLOCH.cjs.map +1 -0
  5. package/dist/{chunk-OJ34O3Q2.cjs → chunk-GVR3PSDL.cjs} +2474 -1636
  6. package/dist/chunk-GVR3PSDL.cjs.map +1 -0
  7. package/dist/chunk-HZM7GDOT.cjs +34 -0
  8. package/dist/chunk-HZM7GDOT.cjs.map +1 -0
  9. package/dist/{chunk-N7RWT46K.js → chunk-JKE6SULM.js} +2522 -1684
  10. package/dist/chunk-JKE6SULM.js.map +1 -0
  11. package/dist/chunk-MOPKHYYU.cjs +83 -0
  12. package/dist/chunk-MOPKHYYU.cjs.map +1 -0
  13. package/dist/chunk-RA2L3FQW.js +481 -0
  14. package/dist/chunk-RA2L3FQW.js.map +1 -0
  15. package/dist/chunk-UA542GT3.cjs +481 -0
  16. package/dist/chunk-UA542GT3.cjs.map +1 -0
  17. package/dist/chunk-WLWELSA2.js +34 -0
  18. package/dist/chunk-WLWELSA2.js.map +1 -0
  19. package/dist/chunk-XFEGS3YT.js +706 -0
  20. package/dist/chunk-XFEGS3YT.js.map +1 -0
  21. package/dist/cloudflare.cjs +456 -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 +456 -0
  26. package/dist/cloudflare.js.map +1 -0
  27. package/dist/{columnProcessors-DMPpTPqM.d.ts → columnProcessors-Be2uMYjS.d.cts} +1 -1
  28. package/dist/{columnProcessors-BX-sH7ah.d.cts → columnProcessors-D0ivj_SU.d.ts} +1 -1
  29. package/dist/{connectionString-B1wm0TFc.d.cts → connectionString-Dch_MIRU.d.cts} +394 -168
  30. package/dist/{connectionString-B1wm0TFc.d.ts → connectionString-Dch_MIRU.d.ts} +394 -168
  31. package/dist/index.cjs +100 -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 +105 -9
  36. package/dist/index.js.map +1 -1
  37. package/dist/pg.cjs +383 -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 +435 -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 +60 -0
  49. package/dist/sqlite.cjs.map +1 -0
  50. package/dist/{index-C2z_XBn6.d.ts → sqlite.d.cts} +69 -20
  51. package/dist/{index-C0h0c380.d.cts → sqlite.d.ts} +69 -20
  52. package/dist/sqlite.js +60 -0
  53. package/dist/sqlite3.cjs +319 -6
  54. package/dist/sqlite3.cjs.map +1 -1
  55. package/dist/sqlite3.d.cts +45 -25
  56. package/dist/sqlite3.d.ts +45 -25
  57. package/dist/sqlite3.js +335 -22
  58. package/dist/sqlite3.js.map +1 -1
  59. package/package.json +55 -33
  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 +0 -405
  77. package/dist/chunk-XVV3OOQX.js.map +0 -1
  78. package/dist/d1.cjs +0 -277
  79. package/dist/d1.cjs.map +0 -1
  80. package/dist/d1.d.cts +0 -72
  81. package/dist/d1.d.ts +0 -72
  82. package/dist/d1.js +0 -277
  83. package/dist/d1.js.map +0 -1
  84. package/dist/pg-3ACXFMU4.cjs +0 -59
  85. package/dist/pg-3ACXFMU4.cjs.map +0 -1
  86. package/dist/pg-GHOW3XSG.js +0 -59
  87. package/dist/sqlite3-EEIKQCJR.js +0 -25
  88. package/dist/sqlite3-SE4DDYZE.cjs +0 -25
  89. package/dist/sqlite3-SE4DDYZE.cjs.map +0 -1
  90. /package/dist/{pg-GHOW3XSG.js.map → postgresql.js.map} +0 -0
  91. /package/dist/{sqlite3-EEIKQCJR.js.map → sqlite.js.map} +0 -0
@@ -0,0 +1,706 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ var _chunkGVR3PSDLcjs = require('./chunk-GVR3PSDL.cjs');
34
+
35
+ // src/storage/sqlite/core/errors/errorMapper.ts
36
+ var getSqliteErrorCode = (error) => {
37
+ if (error instanceof Error && "code" in error && typeof error.code === "string") {
38
+ return error.code;
39
+ }
40
+ return void 0;
41
+ };
42
+ var getErrorMessage = (error) => error instanceof Error ? error.message : void 0;
43
+ var asError = (error) => error instanceof Error ? error : void 0;
44
+ var mapConstraintError = (message, innerError) => {
45
+ const upperMessage = _nullishCoalesce(_optionalChain([message, 'optionalAccess', _ => _.toUpperCase, 'call', _2 => _2()]), () => ( ""));
46
+ if (upperMessage.includes("UNIQUE") || upperMessage.includes("PRIMARY KEY"))
47
+ return new (0, _chunkGVR3PSDLcjs.UniqueConstraintError)(message, innerError);
48
+ if (upperMessage.includes("FOREIGN KEY"))
49
+ return new (0, _chunkGVR3PSDLcjs.ForeignKeyViolationError)(message, innerError);
50
+ if (upperMessage.includes("NOT NULL"))
51
+ return new (0, _chunkGVR3PSDLcjs.NotNullViolationError)(message, innerError);
52
+ if (upperMessage.includes("CHECK"))
53
+ return new (0, _chunkGVR3PSDLcjs.CheckViolationError)(message, innerError);
54
+ return new (0, _chunkGVR3PSDLcjs.IntegrityConstraintViolationError)(message, innerError);
55
+ };
56
+ var mapSqliteError = (error) => {
57
+ if (_chunkGVR3PSDLcjs.DumboError.isInstanceOf(error)) return error;
58
+ const code = getSqliteErrorCode(error);
59
+ if (!code)
60
+ return new (0, _chunkGVR3PSDLcjs.DumboError)({
61
+ errorCode: 500,
62
+ message: getErrorMessage(error),
63
+ innerError: asError(error)
64
+ });
65
+ const message = getErrorMessage(error);
66
+ const innerError = asError(error);
67
+ switch (code) {
68
+ // ── Constraint violations (19) ──
69
+ // node-sqlite3 only exposes the primary code; subtype is in the message.
70
+ case "SQLITE_CONSTRAINT":
71
+ return mapConstraintError(message, innerError);
72
+ // ── Busy / lock contention ──
73
+ // SQLITE_BUSY (5): conflict with a separate database connection
74
+ case "SQLITE_BUSY":
75
+ return new (0, _chunkGVR3PSDLcjs.LockNotAvailableError)(message, innerError);
76
+ // SQLITE_LOCKED (6): conflict within the same connection or shared cache
77
+ case "SQLITE_LOCKED":
78
+ return new (0, _chunkGVR3PSDLcjs.DeadlockError)(message, innerError);
79
+ // SQLITE_PROTOCOL (15): WAL locking race condition
80
+ case "SQLITE_PROTOCOL":
81
+ return new (0, _chunkGVR3PSDLcjs.LockNotAvailableError)(message, innerError);
82
+ // ── Connection / open errors ──
83
+ // SQLITE_CANTOPEN (14): unable to open database file
84
+ case "SQLITE_CANTOPEN":
85
+ return new (0, _chunkGVR3PSDLcjs.ConnectionError)(message, innerError);
86
+ // SQLITE_NOTADB (26): file is not a database
87
+ case "SQLITE_NOTADB":
88
+ return new (0, _chunkGVR3PSDLcjs.ConnectionError)(message, innerError);
89
+ // ── Resource exhaustion ──
90
+ // SQLITE_NOMEM (7): out of memory
91
+ case "SQLITE_NOMEM":
92
+ return new (0, _chunkGVR3PSDLcjs.InsufficientResourcesError)(message, innerError);
93
+ // SQLITE_FULL (13): disk full
94
+ case "SQLITE_FULL":
95
+ return new (0, _chunkGVR3PSDLcjs.InsufficientResourcesError)(message, innerError);
96
+ // ── System / I/O errors ──
97
+ // SQLITE_IOERR (10): operating system I/O error
98
+ case "SQLITE_IOERR":
99
+ return new (0, _chunkGVR3PSDLcjs.SystemError)(message, innerError);
100
+ // SQLITE_CORRUPT (11): database file is corrupted
101
+ case "SQLITE_CORRUPT":
102
+ return new (0, _chunkGVR3PSDLcjs.SystemError)(message, innerError);
103
+ // SQLITE_INTERNAL (2): internal SQLite malfunction
104
+ case "SQLITE_INTERNAL":
105
+ return new (0, _chunkGVR3PSDLcjs.SystemError)(message, innerError);
106
+ // SQLITE_NOLFS (22): large file support unavailable
107
+ case "SQLITE_NOLFS":
108
+ return new (0, _chunkGVR3PSDLcjs.SystemError)(message, innerError);
109
+ // ── Data errors ──
110
+ // SQLITE_TOOBIG (18): string or BLOB too large
111
+ case "SQLITE_TOOBIG":
112
+ return new (0, _chunkGVR3PSDLcjs.DataError)(message, innerError);
113
+ // SQLITE_MISMATCH (20): datatype mismatch
114
+ case "SQLITE_MISMATCH":
115
+ return new (0, _chunkGVR3PSDLcjs.DataError)(message, innerError);
116
+ // SQLITE_RANGE (25): bind parameter index out of range
117
+ case "SQLITE_RANGE":
118
+ return new (0, _chunkGVR3PSDLcjs.DataError)(message, innerError);
119
+ // ── Invalid operations ──
120
+ // SQLITE_ERROR (1): generic SQL error (syntax errors, missing tables, etc.)
121
+ case "SQLITE_ERROR":
122
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
123
+ // SQLITE_READONLY (8): attempt to write to a read-only database
124
+ case "SQLITE_READONLY":
125
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
126
+ // SQLITE_MISUSE (21): API misuse
127
+ case "SQLITE_MISUSE":
128
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
129
+ // SQLITE_AUTH (23): authorization denied
130
+ case "SQLITE_AUTH":
131
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
132
+ // SQLITE_PERM (3): access permission denied
133
+ case "SQLITE_PERM":
134
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
135
+ // SQLITE_SCHEMA (17): schema changed, statement needs re-preparation
136
+ case "SQLITE_SCHEMA":
137
+ return new (0, _chunkGVR3PSDLcjs.InvalidOperationError)(message, innerError);
138
+ // ── Transaction / abort ──
139
+ // SQLITE_ABORT (4): operation aborted (e.g. by rollback)
140
+ case "SQLITE_ABORT":
141
+ return new (0, _chunkGVR3PSDLcjs.SerializationError)(message, innerError);
142
+ // SQLITE_INTERRUPT (9): operation interrupted
143
+ case "SQLITE_INTERRUPT":
144
+ return new (0, _chunkGVR3PSDLcjs.SerializationError)(message, innerError);
145
+ }
146
+ return new (0, _chunkGVR3PSDLcjs.DumboError)({
147
+ errorCode: 500,
148
+ message,
149
+ innerError
150
+ });
151
+ };
152
+
153
+ // src/storage/sqlite/core/sql/processors/columProcessors.ts
154
+ var mapColumnType = (token, { builder }) => {
155
+ let columnSQL;
156
+ const { sqlTokenType } = token;
157
+ switch (sqlTokenType) {
158
+ case "SQL_COLUMN_AUTO_INCREMENT":
159
+ columnSQL = `INTEGER ${token.primaryKey ? "PRIMARY KEY" : ""} AUTOINCREMENT`;
160
+ break;
161
+ case "SQL_COLUMN_BIGINT":
162
+ columnSQL = "INTEGER";
163
+ break;
164
+ case "SQL_COLUMN_SERIAL":
165
+ columnSQL = "INTEGER";
166
+ break;
167
+ case "SQL_COLUMN_INTEGER":
168
+ columnSQL = "INTEGER";
169
+ break;
170
+ case "SQL_COLUMN_JSONB":
171
+ columnSQL = "BLOB";
172
+ break;
173
+ case "SQL_COLUMN_BIGSERIAL":
174
+ columnSQL = "INTEGER";
175
+ break;
176
+ case "SQL_COLUMN_TIMESTAMP":
177
+ columnSQL = "DATETIME";
178
+ break;
179
+ case "SQL_COLUMN_TIMESTAMPTZ":
180
+ columnSQL = "DATETIME";
181
+ break;
182
+ case "SQL_COLUMN_VARCHAR":
183
+ columnSQL = `VARCHAR ${Number.isNaN(token.length) ? "" : `(${token.length})`}`;
184
+ break;
185
+ default: {
186
+ const exhaustiveCheck = sqlTokenType;
187
+ throw new Error(`Unknown column type: ${exhaustiveCheck}`);
188
+ }
189
+ }
190
+ builder.addSQL(columnSQL);
191
+ };
192
+ var sqliteColumnProcessors = _chunkGVR3PSDLcjs.mapDefaultSQLColumnProcessors.call(void 0, mapColumnType);
193
+
194
+ // src/storage/sqlite/core/sql/formatter/index.ts
195
+ var sqliteSQLProcessorsRegistry = _chunkGVR3PSDLcjs.SQLProcessorsRegistry.call(void 0, {
196
+ from: _chunkGVR3PSDLcjs.defaultProcessorsRegistry
197
+ }).register(sqliteColumnProcessors);
198
+ var sqliteFormatter = _chunkGVR3PSDLcjs.SQLFormatter.call(void 0, {
199
+ processorsRegistry: sqliteSQLProcessorsRegistry
200
+ });
201
+ _chunkGVR3PSDLcjs.registerFormatter.call(void 0, "SQLite", sqliteFormatter);
202
+
203
+ // src/storage/sqlite/core/execute/execute.ts
204
+ var sqliteExecute = async (database, handle) => {
205
+ try {
206
+ return await handle(database);
207
+ } finally {
208
+ await database.close();
209
+ }
210
+ };
211
+ var sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
212
+ driverType,
213
+ query: async (client, sql, options) => {
214
+ _chunkGVR3PSDLcjs.tracer.info("db:sql:query", {
215
+ query: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).query,
216
+ params: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).params,
217
+ debugSQL: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).describe(sql, { serializer })
218
+ });
219
+ try {
220
+ let result = await client.query(sql, options);
221
+ if (_optionalChain([options, 'optionalAccess', _3 => _3.mapping])) {
222
+ result = {
223
+ ...result,
224
+ rows: result.rows.map(
225
+ (row) => _chunkGVR3PSDLcjs.mapSQLQueryResult.call(void 0, row, options.mapping)
226
+ )
227
+ };
228
+ }
229
+ return result;
230
+ } catch (error) {
231
+ _chunkGVR3PSDLcjs.tracer.error("db:sql:query:execute:error", { error });
232
+ throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
233
+ }
234
+ },
235
+ batchQuery: async (client, sqls, options) => {
236
+ try {
237
+ const results = await client.batchQuery(sqls, options);
238
+ if (_optionalChain([options, 'optionalAccess', _4 => _4.mapping])) {
239
+ return results.map((result) => ({
240
+ ...result,
241
+ rows: result.rows.map(
242
+ (row) => _chunkGVR3PSDLcjs.mapSQLQueryResult.call(void 0, row, options.mapping)
243
+ )
244
+ }));
245
+ }
246
+ return results;
247
+ } catch (error) {
248
+ _chunkGVR3PSDLcjs.tracer.error("db:sql:batch_query:execute:error", { error });
249
+ throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
250
+ }
251
+ },
252
+ command: async (client, sql, options) => {
253
+ _chunkGVR3PSDLcjs.tracer.info("db:sql:command", {
254
+ query: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).query,
255
+ params: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).format(sql, { serializer }).params,
256
+ debugSQL: (_nullishCoalesce(formatter, () => ( sqliteFormatter))).describe(sql, { serializer })
257
+ });
258
+ try {
259
+ return await client.command(sql, options);
260
+ } catch (error) {
261
+ _chunkGVR3PSDLcjs.tracer.error("db:sql:command:execute:error", { error });
262
+ throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
263
+ }
264
+ },
265
+ batchCommand: async (client, sqls, options) => {
266
+ try {
267
+ return await client.batchCommand(sqls, options);
268
+ } catch (error) {
269
+ _chunkGVR3PSDLcjs.tracer.error("db:sql:batch_command:execute:error", { error });
270
+ throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
271
+ }
272
+ },
273
+ formatter: _nullishCoalesce(formatter, () => ( sqliteFormatter))
274
+ });
275
+
276
+ // src/storage/sqlite/core/pool/dualPool.ts
277
+ var _os = require('os');
278
+ var sqliteDualConnectionPool = (options) => {
279
+ const { sqliteConnectionFactory, connectionOptions } = options;
280
+ const readerPoolSize = _nullishCoalesce(options.readerPoolSize, () => ( Math.max(4, _os.cpus.call(void 0, ).length)));
281
+ let databaseInitPromise = null;
282
+ const initTaskProcessor = new (0, _chunkGVR3PSDLcjs.TaskProcessor)({
283
+ maxActiveTasks: 1,
284
+ maxQueueSize: 1e3
285
+ });
286
+ const ensureDatabaseInitialized = async (connectionOptions2, retryCount = 0) => {
287
+ if (databaseInitPromise !== null) {
288
+ return databaseInitPromise;
289
+ }
290
+ return initTaskProcessor.enqueue(
291
+ async ({ ack }) => {
292
+ if (databaseInitPromise !== null) {
293
+ ack();
294
+ return databaseInitPromise;
295
+ }
296
+ const initConnection = sqliteConnectionFactory({
297
+ ...connectionOptions2,
298
+ skipDatabasePragmas: false,
299
+ readonly: false
300
+ });
301
+ const initPromise = initConnection.open();
302
+ databaseInitPromise = initPromise;
303
+ try {
304
+ await initPromise;
305
+ await initConnection.close();
306
+ ack();
307
+ } catch (error) {
308
+ databaseInitPromise = null;
309
+ await initConnection.close();
310
+ ack();
311
+ if (retryCount < 3) {
312
+ return ensureDatabaseInitialized(connectionOptions2, retryCount + 1);
313
+ }
314
+ throw mapSqliteError(error);
315
+ }
316
+ },
317
+ { taskGroupId: "db-init" }
318
+ );
319
+ };
320
+ const wrappedConnectionFactory = async (readonly, connectionOptions2) => {
321
+ await ensureDatabaseInitialized(connectionOptions2);
322
+ const connection = sqliteConnectionFactory({
323
+ ...connectionOptions2,
324
+ skipDatabasePragmas: true,
325
+ readonly
326
+ });
327
+ await connection.open();
328
+ return connection;
329
+ };
330
+ const writerPool = _chunkGVR3PSDLcjs.createSingletonConnectionPool.call(void 0, {
331
+ driverType: options.driverType,
332
+ getConnection: () => wrappedConnectionFactory(false, connectionOptions)
333
+ });
334
+ const readerPool = _chunkGVR3PSDLcjs.createBoundedConnectionPool.call(void 0, {
335
+ driverType: options.driverType,
336
+ getConnection: () => wrappedConnectionFactory(true, connectionOptions),
337
+ maxConnections: readerPoolSize
338
+ });
339
+ return {
340
+ driverType: options.driverType,
341
+ connection: (connectionOptions2) => _optionalChain([connectionOptions2, 'optionalAccess', _5 => _5.readonly]) ? readerPool.connection(connectionOptions2) : writerPool.connection(connectionOptions2),
342
+ execute: {
343
+ query: (...args) => readerPool.execute.query(...args),
344
+ batchQuery: (...args) => readerPool.execute.batchQuery(...args),
345
+ command: (...args) => writerPool.execute.command(...args),
346
+ batchCommand: (...args) => writerPool.execute.batchCommand(...args)
347
+ },
348
+ withConnection: (handle, connectionOptions2) => _optionalChain([connectionOptions2, 'optionalAccess', _6 => _6.readonly]) ? readerPool.withConnection(handle, connectionOptions2) : writerPool.withConnection(handle, connectionOptions2),
349
+ transaction: writerPool.transaction,
350
+ withTransaction: writerPool.withTransaction,
351
+ close: () => Promise.all([writerPool.close(), readerPool.close()]).then(() => {
352
+ })
353
+ };
354
+ };
355
+
356
+ // src/storage/sqlite/core/pool/pool.ts
357
+ var isInMemoryDatabase = (options) => {
358
+ if ("fileName" in options) {
359
+ return options.fileName === InMemorySQLiteDatabase;
360
+ }
361
+ if ("connectionString" in options) {
362
+ return options.connectionString === InMemorySQLiteDatabase;
363
+ }
364
+ return false;
365
+ };
366
+ var sqliteAmbientConnectionPool = (options) => {
367
+ const { connection, driverType } = options;
368
+ return _chunkGVR3PSDLcjs.createAmbientConnectionPool.call(void 0, {
369
+ driverType,
370
+ connection
371
+ });
372
+ };
373
+ var sqliteSingletonConnectionPool = (options) => {
374
+ const { driverType, sqliteConnectionFactory, connectionOptions } = options;
375
+ return _chunkGVR3PSDLcjs.createSingletonConnectionPool.call(void 0, {
376
+ driverType,
377
+ getConnection: () => sqliteConnectionFactory(connectionOptions)
378
+ });
379
+ };
380
+ var sqliteAlwaysNewConnectionPool = (options) => {
381
+ const { driverType, sqliteConnectionFactory, connectionOptions } = options;
382
+ return _chunkGVR3PSDLcjs.createAlwaysNewConnectionPool.call(void 0, {
383
+ driverType,
384
+ getConnection: () => sqliteConnectionFactory(connectionOptions)
385
+ });
386
+ };
387
+ var toSqlitePoolOptions = (options) => {
388
+ const { singleton, ...rest } = options;
389
+ const isInMemory = isInMemoryDatabase(options);
390
+ if ("client" in options && options.client) {
391
+ return { ...rest, singleton: true };
392
+ }
393
+ if (isInMemory) {
394
+ return { ...rest, singleton: true };
395
+ }
396
+ if (singleton === true) {
397
+ return { ...rest, singleton: true };
398
+ }
399
+ return { ...rest, dual: true };
400
+ };
401
+ function sqlitePool(options) {
402
+ const { driverType } = options;
403
+ if (options.connection)
404
+ return _chunkGVR3PSDLcjs.createAmbientConnectionPool.call(void 0, {
405
+ driverType,
406
+ connection: options.connection
407
+ });
408
+ if ("dual" in options && options.dual) {
409
+ return sqliteDualConnectionPool(
410
+ options
411
+ );
412
+ }
413
+ if (options.singleton === true && options.sqliteConnectionFactory) {
414
+ return _chunkGVR3PSDLcjs.createSingletonConnectionPool.call(void 0, {
415
+ driverType,
416
+ getConnection: () => options.sqliteConnectionFactory(
417
+ options.connectionOptions
418
+ )
419
+ });
420
+ }
421
+ return _chunkGVR3PSDLcjs.createAlwaysNewConnectionPool.call(void 0, {
422
+ driverType,
423
+ getConnection: () => options.sqliteConnectionFactory(
424
+ options.connectionOptions
425
+ )
426
+ });
427
+ }
428
+
429
+ // src/storage/sqlite/core/schema/migrations.ts
430
+ var DefaultSQLiteMigratorOptions = {};
431
+ _chunkGVR3PSDLcjs.registerDefaultMigratorOptions.call(void 0, "SQLite", DefaultSQLiteMigratorOptions);
432
+
433
+ // src/storage/sqlite/core/index.ts
434
+ var SQLiteDatabaseName = "SQLite";
435
+
436
+ // src/storage/sqlite/core/connections/connectionString.ts
437
+ var SQLiteConnectionString = (connectionString) => {
438
+ if (!connectionString.startsWith("file:") && connectionString !== ":memory:" && !connectionString.startsWith("/") && !connectionString.startsWith("./")) {
439
+ throw new Error(
440
+ `Invalid SQLite connection string: ${connectionString}. It should start with "file:", ":memory:", "/", or "./".`
441
+ );
442
+ }
443
+ return connectionString;
444
+ };
445
+ var parsePragmasFromConnectionString = (connectionString) => {
446
+ const str = String(connectionString);
447
+ if (!str.startsWith("file:")) {
448
+ return {};
449
+ }
450
+ const url = new URL(str);
451
+ const params = url.searchParams;
452
+ const pragmas = {};
453
+ const journalMode = params.get("journal_mode");
454
+ if (journalMode !== null) {
455
+ pragmas.journal_mode = journalMode;
456
+ }
457
+ const synchronous = params.get("synchronous");
458
+ if (synchronous !== null) {
459
+ pragmas.synchronous = synchronous;
460
+ }
461
+ const cacheSize = params.get("cache_size");
462
+ if (cacheSize !== null) {
463
+ pragmas.cache_size = parseInt(cacheSize, 10);
464
+ }
465
+ const foreignKeys = params.get("foreign_keys");
466
+ if (foreignKeys !== null) {
467
+ const val = foreignKeys.toLowerCase();
468
+ pragmas.foreign_keys = val === "true" || val === "on" || val === "1";
469
+ }
470
+ const tempStore = params.get("temp_store");
471
+ if (tempStore !== null) {
472
+ pragmas.temp_store = tempStore.toUpperCase();
473
+ }
474
+ const busyTimeout = params.get("busy_timeout");
475
+ if (busyTimeout !== null) {
476
+ pragmas.busy_timeout = parseInt(busyTimeout, 10);
477
+ }
478
+ return pragmas;
479
+ };
480
+
481
+ // src/storage/sqlite/core/connections/index.ts
482
+ var isSQLiteError = (error) => {
483
+ if (error instanceof Error && "code" in error) {
484
+ return true;
485
+ }
486
+ return false;
487
+ };
488
+ var transactionNestingCounter = () => {
489
+ let transactionLevel = 0;
490
+ return {
491
+ reset: () => {
492
+ transactionLevel = 0;
493
+ },
494
+ increment: () => {
495
+ transactionLevel++;
496
+ },
497
+ decrement: () => {
498
+ transactionLevel--;
499
+ if (transactionLevel < 0) {
500
+ throw new Error("Transaction level is out of bounds");
501
+ }
502
+ },
503
+ get level() {
504
+ return transactionLevel;
505
+ }
506
+ };
507
+ };
508
+ var sqliteAmbientClientConnection = (options) => {
509
+ const {
510
+ client,
511
+ driverType,
512
+ initTransaction,
513
+ allowNestedTransactions,
514
+ defaultTransactionMode,
515
+ serializer,
516
+ errorMapper
517
+ } = options;
518
+ return _chunkGVR3PSDLcjs.createAmbientConnection.call(void 0, {
519
+ driverType,
520
+ client,
521
+ initTransaction: _nullishCoalesce(initTransaction, () => ( ((connection) => sqliteTransaction(
522
+ driverType,
523
+ connection,
524
+ _nullishCoalesce(allowNestedTransactions, () => ( false)),
525
+ serializer,
526
+ defaultTransactionMode
527
+ )))),
528
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(driverType, serializer2, void 0, errorMapper),
529
+ serializer
530
+ });
531
+ };
532
+ var sqliteClientConnection = (options) => {
533
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
534
+ let client = null;
535
+ const connect = async () => {
536
+ if (client) return Promise.resolve(client);
537
+ client = sqliteClientFactory(connectionOptions);
538
+ if (client && "connect" in client && typeof client.connect === "function") {
539
+ try {
540
+ await client.connect();
541
+ } catch (error) {
542
+ throw mapSqliteError(error);
543
+ }
544
+ }
545
+ return client;
546
+ };
547
+ return _chunkGVR3PSDLcjs.createConnection.call(void 0, {
548
+ driverType: options.driverType,
549
+ connect,
550
+ close: async () => {
551
+ if (client && "close" in client && typeof client.close === "function")
552
+ await client.close();
553
+ else if (client && "release" in client && typeof client.release === "function")
554
+ client.release();
555
+ },
556
+ initTransaction: (connection) => sqliteTransaction(
557
+ options.driverType,
558
+ connection,
559
+ _nullishCoalesce(_optionalChain([connectionOptions, 'access', _7 => _7.transactionOptions, 'optionalAccess', _8 => _8.allowNestedTransactions]), () => ( false)),
560
+ serializer,
561
+ connectionOptions.defaultTransactionMode
562
+ ),
563
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
564
+ serializer
565
+ });
566
+ };
567
+ var sqlitePoolClientConnection = (options) => {
568
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
569
+ let client = null;
570
+ const connect = async () => {
571
+ if (client) return Promise.resolve(client);
572
+ client = sqliteClientFactory(connectionOptions);
573
+ try {
574
+ await client.connect();
575
+ } catch (error) {
576
+ throw mapSqliteError(error);
577
+ }
578
+ return client;
579
+ };
580
+ return _chunkGVR3PSDLcjs.createConnection.call(void 0, {
581
+ driverType: options.driverType,
582
+ connect,
583
+ close: () => client !== null ? Promise.resolve(client.release()) : Promise.resolve(),
584
+ initTransaction: (connection) => sqliteTransaction(
585
+ options.driverType,
586
+ connection,
587
+ _nullishCoalesce(_optionalChain([connectionOptions, 'access', _9 => _9.transactionOptions, 'optionalAccess', _10 => _10.allowNestedTransactions]), () => ( false)),
588
+ serializer,
589
+ connectionOptions.defaultTransactionMode
590
+ ),
591
+ executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
592
+ serializer
593
+ });
594
+ };
595
+ function sqliteConnection(options) {
596
+ return options.type === "Client" ? sqliteClientConnection(options) : sqlitePoolClientConnection(options);
597
+ }
598
+ var InMemorySQLiteDatabase = SQLiteConnectionString(":memory:");
599
+ var DEFAULT_SQLITE_PRAGMA_OPTIONS = {
600
+ journal_mode: "WAL",
601
+ synchronous: "NORMAL",
602
+ cache_size: -1e6,
603
+ foreign_keys: true,
604
+ temp_store: "MEMORY",
605
+ busy_timeout: 5e3
606
+ };
607
+
608
+ // src/storage/sqlite/core/transactions/index.ts
609
+ var sqliteTransaction = (driverType, connection, allowNestedTransactions, serializer, defaultTransactionMode) => (getClient, options) => {
610
+ const transactionCounter = transactionNestingCounter();
611
+ allowNestedTransactions = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.allowNestedTransactions]), () => ( allowNestedTransactions));
612
+ const transaction = {
613
+ connection: connection(),
614
+ driverType,
615
+ begin: async function() {
616
+ const client = await getClient;
617
+ if (allowNestedTransactions) {
618
+ if (transactionCounter.level >= 1) {
619
+ transactionCounter.increment();
620
+ if (_optionalChain([options, 'optionalAccess', _12 => _12.useSavepoints])) {
621
+ await client.query(
622
+ _chunkGVR3PSDLcjs.SQL`SAVEPOINT transaction${_chunkGVR3PSDLcjs.SQL.plain(transactionCounter.level.toString())}`
623
+ );
624
+ }
625
+ return;
626
+ }
627
+ transactionCounter.increment();
628
+ }
629
+ const mode = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.mode]), () => ( defaultTransactionMode)), () => ( "IMMEDIATE"));
630
+ await client.query(_chunkGVR3PSDLcjs.SQL`BEGIN ${_chunkGVR3PSDLcjs.SQL.plain(mode)} TRANSACTION`);
631
+ },
632
+ commit: async function() {
633
+ const client = await getClient;
634
+ try {
635
+ if (allowNestedTransactions) {
636
+ if (transactionCounter.level > 1) {
637
+ if (_optionalChain([options, 'optionalAccess', _14 => _14.useSavepoints])) {
638
+ await client.query(
639
+ _chunkGVR3PSDLcjs.SQL`RELEASE transaction${_chunkGVR3PSDLcjs.SQL.plain(transactionCounter.level.toString())}`
640
+ );
641
+ }
642
+ transactionCounter.decrement();
643
+ return;
644
+ }
645
+ transactionCounter.reset();
646
+ }
647
+ await client.query(_chunkGVR3PSDLcjs.SQL`COMMIT`);
648
+ } finally {
649
+ if (_optionalChain([options, 'optionalAccess', _15 => _15.close]))
650
+ await _optionalChain([options, 'optionalAccess', _16 => _16.close, 'call', _17 => _17(
651
+ client
652
+ )]);
653
+ }
654
+ },
655
+ rollback: async function(error) {
656
+ const client = await getClient;
657
+ try {
658
+ if (allowNestedTransactions) {
659
+ if (transactionCounter.level > 1) {
660
+ transactionCounter.decrement();
661
+ return;
662
+ }
663
+ }
664
+ await client.query(_chunkGVR3PSDLcjs.SQL`ROLLBACK`);
665
+ } finally {
666
+ if (_optionalChain([options, 'optionalAccess', _18 => _18.close]))
667
+ await _optionalChain([options, 'optionalAccess', _19 => _19.close, 'call', _20 => _20(
668
+ client,
669
+ error
670
+ )]);
671
+ }
672
+ },
673
+ execute: _chunkGVR3PSDLcjs.sqlExecutor.call(void 0, sqliteSQLExecutor(driverType, serializer), {
674
+ connect: () => getClient
675
+ }),
676
+ _transactionOptions: _nullishCoalesce(options, () => ( {}))
677
+ };
678
+ return transaction;
679
+ };
680
+
681
+
682
+
683
+
684
+
685
+
686
+
687
+
688
+
689
+
690
+
691
+
692
+
693
+
694
+
695
+
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+ exports.mapSqliteError = mapSqliteError; exports.sqliteFormatter = sqliteFormatter; exports.sqliteExecute = sqliteExecute; exports.sqliteSQLExecutor = sqliteSQLExecutor; exports.sqliteTransaction = sqliteTransaction; exports.SQLiteConnectionString = SQLiteConnectionString; exports.parsePragmasFromConnectionString = parsePragmasFromConnectionString; exports.isSQLiteError = isSQLiteError; exports.transactionNestingCounter = transactionNestingCounter; exports.sqliteAmbientClientConnection = sqliteAmbientClientConnection; exports.sqliteClientConnection = sqliteClientConnection; exports.sqlitePoolClientConnection = sqlitePoolClientConnection; exports.sqliteConnection = sqliteConnection; exports.InMemorySQLiteDatabase = InMemorySQLiteDatabase; exports.DEFAULT_SQLITE_PRAGMA_OPTIONS = DEFAULT_SQLITE_PRAGMA_OPTIONS; exports.isInMemoryDatabase = isInMemoryDatabase; exports.sqliteAmbientConnectionPool = sqliteAmbientConnectionPool; exports.sqliteSingletonConnectionPool = sqliteSingletonConnectionPool; exports.sqliteAlwaysNewConnectionPool = sqliteAlwaysNewConnectionPool; exports.toSqlitePoolOptions = toSqlitePoolOptions; exports.sqlitePool = sqlitePool; exports.DefaultSQLiteMigratorOptions = DefaultSQLiteMigratorOptions; exports.SQLiteDatabaseName = SQLiteDatabaseName;
706
+ //# sourceMappingURL=chunk-EEKBLOCH.cjs.map