@event-driven-io/dumbo 0.13.0-beta.34 → 0.13.0-beta.36

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 (87) hide show
  1. package/dist/cloudflare.cjs +379 -434
  2. package/dist/cloudflare.cjs.map +1 -1
  3. package/dist/cloudflare.d.cts +36 -29
  4. package/dist/cloudflare.d.ts +36 -29
  5. package/dist/cloudflare.js +343 -434
  6. package/dist/cloudflare.js.map +1 -1
  7. package/dist/core-BeyC5tHn.js +519 -0
  8. package/dist/core-BeyC5tHn.js.map +1 -0
  9. package/dist/core-Bf2ujUFy.js +379 -0
  10. package/dist/core-Bf2ujUFy.js.map +1 -0
  11. package/dist/core-BgYtAxCm.cjs +3237 -0
  12. package/dist/core-BgYtAxCm.cjs.map +1 -0
  13. package/dist/core-DDo4m0Z_.js +2262 -0
  14. package/dist/core-DDo4m0Z_.js.map +1 -0
  15. package/dist/core-DmbB4qMn.cjs +656 -0
  16. package/dist/core-DmbB4qMn.cjs.map +1 -0
  17. package/dist/core-Go_IA78L.cjs +450 -0
  18. package/dist/core-Go_IA78L.cjs.map +1 -0
  19. package/dist/{connectionString-Dch_MIRU.d.cts → index-BDSQvDH2.d.cts} +1010 -922
  20. package/dist/index-BdWFmDhJ.d.cts +68 -0
  21. package/dist/index-D1jryNqo.d.ts +198 -0
  22. package/dist/index-DaP2fTEX.d.ts +67 -0
  23. package/dist/index-DqVvUav9.d.cts +198 -0
  24. package/dist/index-S_wp0Eaf.d.cts +67 -0
  25. package/dist/index-cxtbLiju.d.ts +68 -0
  26. package/dist/{connectionString-Dch_MIRU.d.ts → index-zkszkJqP.d.ts} +1010 -922
  27. package/dist/index.cjs +212 -359
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +3 -132
  30. package/dist/index.d.ts +3 -132
  31. package/dist/index.js +52 -361
  32. package/dist/index.js.map +1 -1
  33. package/dist/pg.cjs +366 -431
  34. package/dist/pg.cjs.map +1 -1
  35. package/dist/pg.d.cts +83 -72
  36. package/dist/pg.d.ts +83 -72
  37. package/dist/pg.js +320 -431
  38. package/dist/pg.js.map +1 -1
  39. package/dist/postgreSQLMetadata-LqX-Z_wo.cjs +118 -0
  40. package/dist/postgreSQLMetadata-LqX-Z_wo.cjs.map +1 -0
  41. package/dist/postgreSQLMetadata-zMq8yJo_.js +65 -0
  42. package/dist/postgreSQLMetadata-zMq8yJo_.js.map +1 -0
  43. package/dist/postgresql.cjs +25 -50
  44. package/dist/postgresql.d.cts +3 -61
  45. package/dist/postgresql.d.ts +3 -61
  46. package/dist/postgresql.js +4 -50
  47. package/dist/sqlite.cjs +30 -60
  48. package/dist/sqlite.d.cts +3 -190
  49. package/dist/sqlite.d.ts +3 -190
  50. package/dist/sqlite.js +4 -60
  51. package/dist/sqlite3.cjs +312 -380
  52. package/dist/sqlite3.cjs.map +1 -1
  53. package/dist/sqlite3.d.cts +79 -77
  54. package/dist/sqlite3.d.ts +79 -77
  55. package/dist/sqlite3.js +276 -378
  56. package/dist/sqlite3.js.map +1 -1
  57. package/dist/sqliteMetadata-BoQ7Sc9I.js +29 -0
  58. package/dist/sqliteMetadata-BoQ7Sc9I.js.map +1 -0
  59. package/dist/sqliteMetadata-D_2pKeCC.cjs +46 -0
  60. package/dist/sqliteMetadata-D_2pKeCC.cjs.map +1 -0
  61. package/package.json +12 -12
  62. package/dist/chunk-33P5766L.js +0 -83
  63. package/dist/chunk-33P5766L.js.map +0 -1
  64. package/dist/chunk-4MMMEDQ7.cjs +0 -2944
  65. package/dist/chunk-4MMMEDQ7.cjs.map +0 -1
  66. package/dist/chunk-6HAHSSPW.js +0 -701
  67. package/dist/chunk-6HAHSSPW.js.map +0 -1
  68. package/dist/chunk-GNH5XC6D.cjs +0 -481
  69. package/dist/chunk-GNH5XC6D.cjs.map +0 -1
  70. package/dist/chunk-H2JBS7HM.js +0 -2944
  71. package/dist/chunk-H2JBS7HM.js.map +0 -1
  72. package/dist/chunk-JIZGCEPE.cjs +0 -701
  73. package/dist/chunk-JIZGCEPE.cjs.map +0 -1
  74. package/dist/chunk-NJI6PJFZ.cjs +0 -83
  75. package/dist/chunk-NJI6PJFZ.cjs.map +0 -1
  76. package/dist/chunk-RQ3KKMTP.cjs +0 -34
  77. package/dist/chunk-RQ3KKMTP.cjs.map +0 -1
  78. package/dist/chunk-UK7MXVS2.js +0 -34
  79. package/dist/chunk-UK7MXVS2.js.map +0 -1
  80. package/dist/chunk-Y5TD53QE.js +0 -481
  81. package/dist/chunk-Y5TD53QE.js.map +0 -1
  82. package/dist/columnProcessors-Be2uMYjS.d.cts +0 -8
  83. package/dist/columnProcessors-D0ivj_SU.d.ts +0 -8
  84. package/dist/postgresql.cjs.map +0 -1
  85. package/dist/postgresql.js.map +0 -1
  86. package/dist/sqlite.cjs.map +0 -1
  87. package/dist/sqlite.js.map +0 -1
@@ -1,701 +0,0 @@
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 _chunk4MMMEDQ7cjs = require('./chunk-4MMMEDQ7.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, _chunk4MMMEDQ7cjs.UniqueConstraintError)(message, innerError);
48
- if (upperMessage.includes("FOREIGN KEY"))
49
- return new (0, _chunk4MMMEDQ7cjs.ForeignKeyViolationError)(message, innerError);
50
- if (upperMessage.includes("NOT NULL"))
51
- return new (0, _chunk4MMMEDQ7cjs.NotNullViolationError)(message, innerError);
52
- if (upperMessage.includes("CHECK"))
53
- return new (0, _chunk4MMMEDQ7cjs.CheckViolationError)(message, innerError);
54
- return new (0, _chunk4MMMEDQ7cjs.IntegrityConstraintViolationError)(message, innerError);
55
- };
56
- var mapSqliteError = (error) => {
57
- if (_chunk4MMMEDQ7cjs.DumboError.isInstanceOf(error)) return error;
58
- const code = getSqliteErrorCode(error);
59
- if (!code)
60
- return new (0, _chunk4MMMEDQ7cjs.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, _chunk4MMMEDQ7cjs.LockNotAvailableError)(message, innerError);
76
- // SQLITE_LOCKED (6): conflict within the same connection or shared cache
77
- case "SQLITE_LOCKED":
78
- return new (0, _chunk4MMMEDQ7cjs.DeadlockError)(message, innerError);
79
- // SQLITE_PROTOCOL (15): WAL locking race condition
80
- case "SQLITE_PROTOCOL":
81
- return new (0, _chunk4MMMEDQ7cjs.LockNotAvailableError)(message, innerError);
82
- // ── Connection / open errors ──
83
- // SQLITE_CANTOPEN (14): unable to open database file
84
- case "SQLITE_CANTOPEN":
85
- return new (0, _chunk4MMMEDQ7cjs.ConnectionError)(message, innerError);
86
- // SQLITE_NOTADB (26): file is not a database
87
- case "SQLITE_NOTADB":
88
- return new (0, _chunk4MMMEDQ7cjs.ConnectionError)(message, innerError);
89
- // ── Resource exhaustion ──
90
- // SQLITE_NOMEM (7): out of memory
91
- case "SQLITE_NOMEM":
92
- return new (0, _chunk4MMMEDQ7cjs.InsufficientResourcesError)(message, innerError);
93
- // SQLITE_FULL (13): disk full
94
- case "SQLITE_FULL":
95
- return new (0, _chunk4MMMEDQ7cjs.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, _chunk4MMMEDQ7cjs.SystemError)(message, innerError);
100
- // SQLITE_CORRUPT (11): database file is corrupted
101
- case "SQLITE_CORRUPT":
102
- return new (0, _chunk4MMMEDQ7cjs.SystemError)(message, innerError);
103
- // SQLITE_INTERNAL (2): internal SQLite malfunction
104
- case "SQLITE_INTERNAL":
105
- return new (0, _chunk4MMMEDQ7cjs.SystemError)(message, innerError);
106
- // SQLITE_NOLFS (22): large file support unavailable
107
- case "SQLITE_NOLFS":
108
- return new (0, _chunk4MMMEDQ7cjs.SystemError)(message, innerError);
109
- // ── Data errors ──
110
- // SQLITE_TOOBIG (18): string or BLOB too large
111
- case "SQLITE_TOOBIG":
112
- return new (0, _chunk4MMMEDQ7cjs.DataError)(message, innerError);
113
- // SQLITE_MISMATCH (20): datatype mismatch
114
- case "SQLITE_MISMATCH":
115
- return new (0, _chunk4MMMEDQ7cjs.DataError)(message, innerError);
116
- // SQLITE_RANGE (25): bind parameter index out of range
117
- case "SQLITE_RANGE":
118
- return new (0, _chunk4MMMEDQ7cjs.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, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
123
- // SQLITE_READONLY (8): attempt to write to a read-only database
124
- case "SQLITE_READONLY":
125
- return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
126
- // SQLITE_MISUSE (21): API misuse
127
- case "SQLITE_MISUSE":
128
- return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
129
- // SQLITE_AUTH (23): authorization denied
130
- case "SQLITE_AUTH":
131
- return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
132
- // SQLITE_PERM (3): access permission denied
133
- case "SQLITE_PERM":
134
- return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
135
- // SQLITE_SCHEMA (17): schema changed, statement needs re-preparation
136
- case "SQLITE_SCHEMA":
137
- return new (0, _chunk4MMMEDQ7cjs.InvalidOperationError)(message, innerError);
138
- // ── Transaction / abort ──
139
- // SQLITE_ABORT (4): operation aborted (e.g. by rollback)
140
- case "SQLITE_ABORT":
141
- return new (0, _chunk4MMMEDQ7cjs.SerializationError)(message, innerError);
142
- // SQLITE_INTERRUPT (9): operation interrupted
143
- case "SQLITE_INTERRUPT":
144
- return new (0, _chunk4MMMEDQ7cjs.SerializationError)(message, innerError);
145
- }
146
- return new (0, _chunk4MMMEDQ7cjs.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 = _chunk4MMMEDQ7cjs.mapDefaultSQLColumnProcessors.call(void 0, mapColumnType);
193
-
194
- // src/storage/sqlite/core/sql/formatter/index.ts
195
- var sqliteSQLProcessorsRegistry = _chunk4MMMEDQ7cjs.SQLProcessorsRegistry.call(void 0, {
196
- from: _chunk4MMMEDQ7cjs.defaultProcessorsRegistry
197
- }).register(sqliteColumnProcessors);
198
- var sqliteFormatter = _chunk4MMMEDQ7cjs.SQLFormatter.call(void 0, {
199
- processorsRegistry: sqliteSQLProcessorsRegistry
200
- });
201
- _chunk4MMMEDQ7cjs.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
- _chunk4MMMEDQ7cjs.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) => _chunk4MMMEDQ7cjs.mapSQLQueryResult.call(void 0, row, options.mapping)
226
- )
227
- };
228
- }
229
- return result;
230
- } catch (error) {
231
- _chunk4MMMEDQ7cjs.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) => _chunk4MMMEDQ7cjs.mapSQLQueryResult.call(void 0, row, options.mapping)
243
- )
244
- }));
245
- }
246
- return results;
247
- } catch (error) {
248
- _chunk4MMMEDQ7cjs.tracer.error("db:sql:batch_query:execute:error", { error });
249
- throw (_nullishCoalesce(errorMapper, () => ( mapSqliteError)))(error);
250
- }
251
- },
252
- command: async (client, sql, options) => {
253
- _chunk4MMMEDQ7cjs.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
- _chunk4MMMEDQ7cjs.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
- _chunk4MMMEDQ7cjs.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/connections/connectionString.ts
277
- var SQLiteConnectionString = (connectionString) => {
278
- if (!connectionString.startsWith("file:") && connectionString !== ":memory:" && !connectionString.startsWith("/") && !connectionString.startsWith("./")) {
279
- throw new Error(
280
- `Invalid SQLite connection string: ${connectionString}. It should start with "file:", ":memory:", "/", or "./".`
281
- );
282
- }
283
- return connectionString;
284
- };
285
- var parsePragmasFromConnectionString = (connectionString) => {
286
- const str = String(connectionString);
287
- if (!str.startsWith("file:")) {
288
- return {};
289
- }
290
- const url = new URL(str);
291
- const params = url.searchParams;
292
- const pragmas = {};
293
- const journalMode = params.get("journal_mode");
294
- if (journalMode !== null) {
295
- pragmas.journal_mode = journalMode;
296
- }
297
- const synchronous = params.get("synchronous");
298
- if (synchronous !== null) {
299
- pragmas.synchronous = synchronous;
300
- }
301
- const cacheSize = params.get("cache_size");
302
- if (cacheSize !== null) {
303
- pragmas.cache_size = parseInt(cacheSize, 10);
304
- }
305
- const foreignKeys = params.get("foreign_keys");
306
- if (foreignKeys !== null) {
307
- const val = foreignKeys.toLowerCase();
308
- pragmas.foreign_keys = val === "true" || val === "on" || val === "1";
309
- }
310
- const tempStore = params.get("temp_store");
311
- if (tempStore !== null) {
312
- pragmas.temp_store = tempStore.toUpperCase();
313
- }
314
- const busyTimeout = params.get("busy_timeout");
315
- if (busyTimeout !== null) {
316
- pragmas.busy_timeout = parseInt(busyTimeout, 10);
317
- }
318
- const mmapSize = params.get("mmap_size");
319
- if (mmapSize !== null) {
320
- pragmas.mmap_size = parseInt(mmapSize, 10);
321
- }
322
- return pragmas;
323
- };
324
-
325
- // src/storage/sqlite/core/connections/index.ts
326
- var isSQLiteError = (error) => {
327
- if (error instanceof Error && "code" in error) {
328
- return true;
329
- }
330
- return false;
331
- };
332
- var transactionNestingCounter = () => {
333
- let transactionLevel = 0;
334
- return {
335
- reset: () => {
336
- transactionLevel = 0;
337
- },
338
- increment: () => {
339
- transactionLevel++;
340
- },
341
- decrement: () => {
342
- transactionLevel--;
343
- if (transactionLevel < 0) {
344
- throw new Error("Transaction level is out of bounds");
345
- }
346
- },
347
- get level() {
348
- return transactionLevel;
349
- }
350
- };
351
- };
352
- var sqliteAmbientClientConnection = (options) => {
353
- const {
354
- client,
355
- driverType,
356
- initTransaction,
357
- allowNestedTransactions,
358
- defaultTransactionMode,
359
- serializer,
360
- errorMapper
361
- } = options;
362
- return _chunk4MMMEDQ7cjs.createAmbientConnection.call(void 0, {
363
- driverType,
364
- client,
365
- initTransaction: _nullishCoalesce(initTransaction, () => ( ((connection) => sqliteTransaction(
366
- driverType,
367
- connection,
368
- _nullishCoalesce(allowNestedTransactions, () => ( false)),
369
- serializer,
370
- defaultTransactionMode
371
- )))),
372
- executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(driverType, serializer2, void 0, errorMapper),
373
- serializer
374
- });
375
- };
376
- var sqliteClientConnection = (options) => {
377
- const { connectionOptions, sqliteClientFactory, serializer } = options;
378
- let client = null;
379
- const connect = async () => {
380
- if (client) return Promise.resolve(client);
381
- client = sqliteClientFactory(connectionOptions);
382
- if (client && "connect" in client && typeof client.connect === "function") {
383
- try {
384
- await client.connect();
385
- } catch (error) {
386
- throw mapSqliteError(error);
387
- }
388
- }
389
- return client;
390
- };
391
- return _chunk4MMMEDQ7cjs.createConnection.call(void 0, {
392
- driverType: options.driverType,
393
- connect,
394
- close: async () => {
395
- if (client && "close" in client && typeof client.close === "function")
396
- await client.close();
397
- else if (client && "release" in client && typeof client.release === "function")
398
- client.release();
399
- },
400
- initTransaction: (connection) => sqliteTransaction(
401
- options.driverType,
402
- connection,
403
- _nullishCoalesce(_optionalChain([connectionOptions, 'access', _5 => _5.transactionOptions, 'optionalAccess', _6 => _6.allowNestedTransactions]), () => ( false)),
404
- serializer,
405
- connectionOptions.defaultTransactionMode
406
- ),
407
- executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
408
- serializer
409
- });
410
- };
411
- var sqlitePoolClientConnection = (options) => {
412
- const { connectionOptions, sqliteClientFactory, serializer } = options;
413
- let client = null;
414
- const connect = async () => {
415
- if (client) return Promise.resolve(client);
416
- client = sqliteClientFactory(connectionOptions);
417
- try {
418
- await client.connect();
419
- } catch (error) {
420
- throw mapSqliteError(error);
421
- }
422
- return client;
423
- };
424
- return _chunk4MMMEDQ7cjs.createConnection.call(void 0, {
425
- driverType: options.driverType,
426
- connect,
427
- close: () => client !== null ? Promise.resolve(client.release()) : Promise.resolve(),
428
- initTransaction: (connection) => sqliteTransaction(
429
- options.driverType,
430
- connection,
431
- _nullishCoalesce(_optionalChain([connectionOptions, 'access', _7 => _7.transactionOptions, 'optionalAccess', _8 => _8.allowNestedTransactions]), () => ( false)),
432
- serializer,
433
- connectionOptions.defaultTransactionMode
434
- ),
435
- executor: ({ serializer: serializer2 }) => sqliteSQLExecutor(options.driverType, serializer2),
436
- serializer
437
- });
438
- };
439
- function sqliteConnection(options) {
440
- return options.type === "Client" ? sqliteClientConnection(options) : sqlitePoolClientConnection(options);
441
- }
442
- var InMemorySQLiteDatabase = SQLiteConnectionString(":memory:");
443
- var DEFAULT_SQLITE_PRAGMA_OPTIONS = {
444
- journal_mode: "WAL",
445
- synchronous: "NORMAL",
446
- cache_size: -1e6,
447
- foreign_keys: true,
448
- temp_store: "MEMORY",
449
- busy_timeout: 5e3,
450
- mmap_size: 268435456
451
- };
452
-
453
- // src/storage/sqlite/core/transactions/index.ts
454
- var sqliteTransaction = (driverType, connection, allowNestedTransactions, serializer, defaultTransactionMode) => (getClient, options) => {
455
- const transactionCounter = transactionNestingCounter();
456
- allowNestedTransactions = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.allowNestedTransactions]), () => ( allowNestedTransactions));
457
- const transaction = {
458
- connection: connection(),
459
- driverType,
460
- begin: async function() {
461
- const client = await getClient;
462
- if (allowNestedTransactions) {
463
- if (transactionCounter.level >= 1) {
464
- transactionCounter.increment();
465
- if (_optionalChain([options, 'optionalAccess', _10 => _10.useSavepoints])) {
466
- await client.command(
467
- _chunk4MMMEDQ7cjs.SQL`SAVEPOINT transaction${_chunk4MMMEDQ7cjs.SQL.plain(transactionCounter.level.toString())}`
468
- );
469
- }
470
- return;
471
- }
472
- transactionCounter.increment();
473
- }
474
- const mode = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.mode]), () => ( defaultTransactionMode)), () => ( "IMMEDIATE"));
475
- await client.command(_chunk4MMMEDQ7cjs.SQL`BEGIN ${_chunk4MMMEDQ7cjs.SQL.plain(mode)} TRANSACTION`);
476
- },
477
- commit: async function() {
478
- const client = await getClient;
479
- try {
480
- if (allowNestedTransactions) {
481
- if (transactionCounter.level > 1) {
482
- if (_optionalChain([options, 'optionalAccess', _12 => _12.useSavepoints])) {
483
- await client.command(
484
- _chunk4MMMEDQ7cjs.SQL`RELEASE transaction${_chunk4MMMEDQ7cjs.SQL.plain(transactionCounter.level.toString())}`
485
- );
486
- }
487
- transactionCounter.decrement();
488
- return;
489
- }
490
- transactionCounter.reset();
491
- }
492
- await client.command(_chunk4MMMEDQ7cjs.SQL`COMMIT`);
493
- } finally {
494
- if (_optionalChain([options, 'optionalAccess', _13 => _13.close]))
495
- await _optionalChain([options, 'optionalAccess', _14 => _14.close, 'call', _15 => _15(
496
- client
497
- )]);
498
- }
499
- },
500
- rollback: async function(error) {
501
- const client = await getClient;
502
- try {
503
- if (allowNestedTransactions) {
504
- if (transactionCounter.level > 1) {
505
- transactionCounter.decrement();
506
- return;
507
- }
508
- }
509
- await client.command(_chunk4MMMEDQ7cjs.SQL`ROLLBACK`);
510
- } finally {
511
- if (_optionalChain([options, 'optionalAccess', _16 => _16.close]))
512
- await _optionalChain([options, 'optionalAccess', _17 => _17.close, 'call', _18 => _18(
513
- client,
514
- error
515
- )]);
516
- }
517
- },
518
- execute: _chunk4MMMEDQ7cjs.sqlExecutor.call(void 0, sqliteSQLExecutor(driverType, serializer), {
519
- connect: () => getClient
520
- }),
521
- _transactionOptions: _nullishCoalesce(options, () => ( {}))
522
- };
523
- return transaction;
524
- };
525
-
526
- // src/storage/sqlite/core/pool/dualPool.ts
527
- var _os = require('os');
528
- var sqliteDualConnectionPool = (options) => {
529
- const { sqliteConnectionFactory, connectionOptions } = options;
530
- const readerPoolSize = _nullishCoalesce(options.readerPoolSize, () => ( Math.max(4, _os.cpus.call(void 0, ).length)));
531
- let databaseInitPromise = null;
532
- const guardSingleConnection = _chunk4MMMEDQ7cjs.guardInitializedOnce.call(void 0, async () => {
533
- if (databaseInitPromise !== null) {
534
- return databaseInitPromise;
535
- }
536
- const initConnection = sqliteConnectionFactory({
537
- ...connectionOptions,
538
- skipDatabasePragmas: false,
539
- readonly: false
540
- });
541
- const initPromise = initConnection.open();
542
- databaseInitPromise = initPromise;
543
- try {
544
- await initPromise;
545
- await initConnection.close();
546
- } catch (error) {
547
- databaseInitPromise = null;
548
- await initConnection.close();
549
- throw mapSqliteError(error);
550
- }
551
- });
552
- const ensureDatabaseInitialized = async () => {
553
- if (databaseInitPromise !== null) {
554
- return databaseInitPromise;
555
- }
556
- return guardSingleConnection.ensureInitialized();
557
- };
558
- const wrappedConnectionFactory = async (readonly, connectionOptions2) => {
559
- await ensureDatabaseInitialized();
560
- const connection = sqliteConnectionFactory({
561
- ...connectionOptions2,
562
- skipDatabasePragmas: true,
563
- readonly
564
- });
565
- await connection.open();
566
- return connection;
567
- };
568
- const writerPool = _chunk4MMMEDQ7cjs.createSingletonConnectionPool.call(void 0, {
569
- driverType: options.driverType,
570
- getConnection: () => wrappedConnectionFactory(false, connectionOptions)
571
- });
572
- const readerPool = _chunk4MMMEDQ7cjs.createBoundedConnectionPool.call(void 0, {
573
- driverType: options.driverType,
574
- getConnection: () => wrappedConnectionFactory(true, connectionOptions),
575
- maxConnections: readerPoolSize
576
- });
577
- return {
578
- driverType: options.driverType,
579
- connection: (connectionOptions2) => _optionalChain([connectionOptions2, 'optionalAccess', _19 => _19.readonly]) ? readerPool.connection(connectionOptions2) : writerPool.connection(connectionOptions2),
580
- execute: {
581
- query: (...args) => readerPool.execute.query(...args),
582
- batchQuery: (...args) => readerPool.execute.batchQuery(...args),
583
- command: (...args) => writerPool.execute.command(...args),
584
- batchCommand: (...args) => writerPool.execute.batchCommand(...args)
585
- },
586
- withConnection: (handle, connectionOptions2) => _optionalChain([connectionOptions2, 'optionalAccess', _20 => _20.readonly]) ? readerPool.withConnection(handle, connectionOptions2) : writerPool.withConnection(handle, connectionOptions2),
587
- transaction: writerPool.transaction,
588
- withTransaction: writerPool.withTransaction,
589
- close: async () => {
590
- await guardSingleConnection.stop();
591
- await Promise.all([writerPool.close(), readerPool.close()]);
592
- }
593
- };
594
- };
595
-
596
- // src/storage/sqlite/core/pool/pool.ts
597
- var isInMemoryDatabase = (options) => {
598
- if ("fileName" in options) {
599
- return options.fileName === InMemorySQLiteDatabase;
600
- }
601
- if ("connectionString" in options) {
602
- return options.connectionString === InMemorySQLiteDatabase;
603
- }
604
- return false;
605
- };
606
- var sqliteAmbientConnectionPool = (options) => {
607
- const { connection, driverType } = options;
608
- return _chunk4MMMEDQ7cjs.createAmbientConnectionPool.call(void 0, {
609
- driverType,
610
- connection
611
- });
612
- };
613
- var sqliteSingletonConnectionPool = (options) => {
614
- const { driverType, sqliteConnectionFactory, connectionOptions } = options;
615
- return _chunk4MMMEDQ7cjs.createSingletonConnectionPool.call(void 0, {
616
- driverType,
617
- getConnection: () => sqliteConnectionFactory(connectionOptions)
618
- });
619
- };
620
- var sqliteAlwaysNewConnectionPool = (options) => {
621
- const { driverType, sqliteConnectionFactory, connectionOptions } = options;
622
- return _chunk4MMMEDQ7cjs.createAlwaysNewConnectionPool.call(void 0, {
623
- driverType,
624
- getConnection: () => sqliteConnectionFactory(connectionOptions)
625
- });
626
- };
627
- var toSqlitePoolOptions = (options) => {
628
- const { singleton, ...rest } = options;
629
- const isInMemory = isInMemoryDatabase(options);
630
- if ("client" in options && options.client) {
631
- return { ...rest, singleton: true };
632
- }
633
- if (isInMemory) {
634
- return { ...rest, singleton: true };
635
- }
636
- if (singleton === true) {
637
- return { ...rest, singleton: true };
638
- }
639
- return { ...rest, dual: true };
640
- };
641
- function sqlitePool(options) {
642
- const { driverType } = options;
643
- if (options.connection)
644
- return _chunk4MMMEDQ7cjs.createAmbientConnectionPool.call(void 0, {
645
- driverType,
646
- connection: options.connection
647
- });
648
- if ("dual" in options && options.dual) {
649
- return sqliteDualConnectionPool(
650
- options
651
- );
652
- }
653
- if (options.singleton === true && options.sqliteConnectionFactory) {
654
- return _chunk4MMMEDQ7cjs.createSingletonConnectionPool.call(void 0, {
655
- driverType,
656
- getConnection: () => options.sqliteConnectionFactory(
657
- options.connectionOptions
658
- )
659
- });
660
- }
661
- return _chunk4MMMEDQ7cjs.createAlwaysNewConnectionPool.call(void 0, {
662
- driverType,
663
- getConnection: () => options.sqliteConnectionFactory(
664
- options.connectionOptions
665
- )
666
- });
667
- }
668
-
669
- // src/storage/sqlite/core/schema/migrations.ts
670
- var DefaultSQLiteMigratorOptions = {};
671
- _chunk4MMMEDQ7cjs.registerDefaultMigratorOptions.call(void 0, "SQLite", DefaultSQLiteMigratorOptions);
672
-
673
- // src/storage/sqlite/core/index.ts
674
- var SQLiteDatabaseName = "SQLite";
675
-
676
-
677
-
678
-
679
-
680
-
681
-
682
-
683
-
684
-
685
-
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-
698
-
699
-
700
- 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;
701
- //# sourceMappingURL=chunk-JIZGCEPE.cjs.map