@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
@@ -0,0 +1,656 @@
1
+ const require_core = require('./core-BgYtAxCm.cjs');
2
+ require('./sqliteMetadata-D_2pKeCC.cjs');
3
+ let os = require("os");
4
+
5
+ //#region src/storage/sqlite/core/errors/errorMapper.ts
6
+ /**
7
+ * Extracts the SQLite error code string from a `sqlite3` driver error.
8
+ *
9
+ * The `sqlite3` (node-sqlite3) driver sets `error.code` to a string like
10
+ * `'SQLITE_CONSTRAINT'` and `error.errno` to the numeric result code.
11
+ * See: https://github.com/TryGhost/node-sqlite3
12
+ */
13
+ const getSqliteErrorCode = (error) => {
14
+ if (error instanceof Error && "code" in error && typeof error.code === "string") return error.code;
15
+ };
16
+ const getErrorMessage = (error) => error instanceof Error ? error.message : void 0;
17
+ const asError = (error) => error instanceof Error ? error : void 0;
18
+ /**
19
+ * Maps a constraint error to a specific DumboError subtype by inspecting the
20
+ * error message. The `sqlite3` driver only exposes the primary result code
21
+ * `SQLITE_CONSTRAINT` — the constraint subtype (UNIQUE, FOREIGN KEY, etc.)
22
+ * is embedded in the message string by SQLite, e.g.:
23
+ * "SQLITE_CONSTRAINT: UNIQUE constraint failed: users.email"
24
+ *
25
+ * Reference: https://www.sqlite.org/rescode.html (extended result codes 275–3091)
26
+ */
27
+ const mapConstraintError = (message, innerError) => {
28
+ const upperMessage = message?.toUpperCase() ?? "";
29
+ if (upperMessage.includes("UNIQUE") || upperMessage.includes("PRIMARY KEY")) return new require_core.UniqueConstraintError(message, innerError);
30
+ if (upperMessage.includes("FOREIGN KEY")) return new require_core.ForeignKeyViolationError(message, innerError);
31
+ if (upperMessage.includes("NOT NULL")) return new require_core.NotNullViolationError(message, innerError);
32
+ if (upperMessage.includes("CHECK")) return new require_core.CheckViolationError(message, innerError);
33
+ return new require_core.IntegrityConstraintViolationError(message, innerError);
34
+ };
35
+ /**
36
+ * Maps a SQLite error (from the `sqlite3` / node-sqlite3 driver) to a typed
37
+ * DumboError based on the SQLite result code.
38
+ *
39
+ * Result code reference: https://www.sqlite.org/rescode.html
40
+ *
41
+ * Falls back to a generic DumboError (500) if the error is not a recognized SQLite error.
42
+ */
43
+ const mapSqliteError = (error) => {
44
+ if (require_core.DumboError.isInstanceOf(error)) return error;
45
+ const code = getSqliteErrorCode(error);
46
+ if (!code) return new require_core.DumboError({
47
+ errorCode: 500,
48
+ message: getErrorMessage(error),
49
+ innerError: asError(error)
50
+ });
51
+ const message = getErrorMessage(error);
52
+ const innerError = asError(error);
53
+ switch (code) {
54
+ case "SQLITE_CONSTRAINT": return mapConstraintError(message, innerError);
55
+ case "SQLITE_BUSY": return new require_core.LockNotAvailableError(message, innerError);
56
+ case "SQLITE_LOCKED": return new require_core.DeadlockError(message, innerError);
57
+ case "SQLITE_PROTOCOL": return new require_core.LockNotAvailableError(message, innerError);
58
+ case "SQLITE_CANTOPEN": return new require_core.ConnectionError(message, innerError);
59
+ case "SQLITE_NOTADB": return new require_core.ConnectionError(message, innerError);
60
+ case "SQLITE_NOMEM": return new require_core.InsufficientResourcesError(message, innerError);
61
+ case "SQLITE_FULL": return new require_core.InsufficientResourcesError(message, innerError);
62
+ case "SQLITE_IOERR": return new require_core.SystemError(message, innerError);
63
+ case "SQLITE_CORRUPT": return new require_core.SystemError(message, innerError);
64
+ case "SQLITE_INTERNAL": return new require_core.SystemError(message, innerError);
65
+ case "SQLITE_NOLFS": return new require_core.SystemError(message, innerError);
66
+ case "SQLITE_TOOBIG": return new require_core.DataError(message, innerError);
67
+ case "SQLITE_MISMATCH": return new require_core.DataError(message, innerError);
68
+ case "SQLITE_RANGE": return new require_core.DataError(message, innerError);
69
+ case "SQLITE_ERROR": return new require_core.InvalidOperationError(message, innerError);
70
+ case "SQLITE_READONLY": return new require_core.InvalidOperationError(message, innerError);
71
+ case "SQLITE_MISUSE": return new require_core.InvalidOperationError(message, innerError);
72
+ case "SQLITE_AUTH": return new require_core.InvalidOperationError(message, innerError);
73
+ case "SQLITE_PERM": return new require_core.InvalidOperationError(message, innerError);
74
+ case "SQLITE_SCHEMA": return new require_core.InvalidOperationError(message, innerError);
75
+ case "SQLITE_ABORT": return new require_core.SerializationError(message, innerError);
76
+ case "SQLITE_INTERRUPT": return new require_core.SerializationError(message, innerError);
77
+ }
78
+ return new require_core.DumboError({
79
+ errorCode: 500,
80
+ message,
81
+ innerError
82
+ });
83
+ };
84
+
85
+ //#endregion
86
+ //#region src/storage/sqlite/core/sql/processors/columProcessors.ts
87
+ const mapColumnType = (token, { builder }) => {
88
+ let columnSQL;
89
+ const { sqlTokenType } = token;
90
+ switch (sqlTokenType) {
91
+ case "SQL_COLUMN_AUTO_INCREMENT":
92
+ columnSQL = `INTEGER ${token.primaryKey ? "PRIMARY KEY" : ""} AUTOINCREMENT`;
93
+ break;
94
+ case "SQL_COLUMN_BIGINT":
95
+ columnSQL = "INTEGER";
96
+ break;
97
+ case "SQL_COLUMN_SERIAL":
98
+ columnSQL = "INTEGER";
99
+ break;
100
+ case "SQL_COLUMN_INTEGER":
101
+ columnSQL = "INTEGER";
102
+ break;
103
+ case "SQL_COLUMN_JSONB":
104
+ columnSQL = "BLOB";
105
+ break;
106
+ case "SQL_COLUMN_BIGSERIAL":
107
+ columnSQL = "INTEGER";
108
+ break;
109
+ case "SQL_COLUMN_TIMESTAMP":
110
+ columnSQL = "DATETIME";
111
+ break;
112
+ case "SQL_COLUMN_TIMESTAMPTZ":
113
+ columnSQL = "DATETIME";
114
+ break;
115
+ case "SQL_COLUMN_VARCHAR":
116
+ columnSQL = `VARCHAR ${Number.isNaN(token.length) ? "" : `(${token.length})`}`;
117
+ break;
118
+ default: throw new Error(`Unknown column type: ${sqlTokenType}`);
119
+ }
120
+ builder.addSQL(columnSQL);
121
+ };
122
+ const sqliteColumnProcessors = require_core.mapDefaultSQLColumnProcessors(mapColumnType);
123
+
124
+ //#endregion
125
+ //#region src/storage/sqlite/core/sql/formatter/index.ts
126
+ const sqliteFormatter = require_core.SQLFormatter({ processorsRegistry: require_core.SQLProcessorsRegistry({ from: require_core.defaultProcessorsRegistry }).register(sqliteColumnProcessors) });
127
+ require_core.registerFormatter("SQLite", sqliteFormatter);
128
+
129
+ //#endregion
130
+ //#region src/storage/sqlite/core/execute/execute.ts
131
+ const sqliteExecute = async (database, handle) => {
132
+ try {
133
+ return await handle(database);
134
+ } finally {
135
+ await database.close();
136
+ }
137
+ };
138
+ const sqliteSQLExecutor = (driverType, serializer, formatter, errorMapper) => ({
139
+ driverType,
140
+ query: async (client, sql, options) => {
141
+ require_core.tracer.info("db:sql:query", {
142
+ query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,
143
+ params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,
144
+ debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer })
145
+ });
146
+ try {
147
+ let result = await client.query(sql, options);
148
+ if (options?.mapping) result = {
149
+ ...result,
150
+ rows: result.rows.map((row) => require_core.mapSQLQueryResult(row, options.mapping))
151
+ };
152
+ return result;
153
+ } catch (error) {
154
+ require_core.tracer.error("db:sql:query:execute:error", { error });
155
+ throw (errorMapper ?? mapSqliteError)(error);
156
+ }
157
+ },
158
+ batchQuery: async (client, sqls, options) => {
159
+ try {
160
+ const results = await client.batchQuery(sqls, options);
161
+ if (options?.mapping) return results.map((result) => ({
162
+ ...result,
163
+ rows: result.rows.map((row) => require_core.mapSQLQueryResult(row, options.mapping))
164
+ }));
165
+ return results;
166
+ } catch (error) {
167
+ require_core.tracer.error("db:sql:batch_query:execute:error", { error });
168
+ throw (errorMapper ?? mapSqliteError)(error);
169
+ }
170
+ },
171
+ command: async (client, sql, options) => {
172
+ require_core.tracer.info("db:sql:command", {
173
+ query: (formatter ?? sqliteFormatter).format(sql, { serializer }).query,
174
+ params: (formatter ?? sqliteFormatter).format(sql, { serializer }).params,
175
+ debugSQL: (formatter ?? sqliteFormatter).describe(sql, { serializer })
176
+ });
177
+ try {
178
+ return await client.command(sql, options);
179
+ } catch (error) {
180
+ require_core.tracer.error("db:sql:command:execute:error", { error });
181
+ throw (errorMapper ?? mapSqliteError)(error);
182
+ }
183
+ },
184
+ batchCommand: async (client, sqls, options) => {
185
+ try {
186
+ return await client.batchCommand(sqls, options);
187
+ } catch (error) {
188
+ require_core.tracer.error("db:sql:batch_command:execute:error", { error });
189
+ throw (errorMapper ?? mapSqliteError)(error);
190
+ }
191
+ },
192
+ formatter: formatter ?? sqliteFormatter
193
+ });
194
+
195
+ //#endregion
196
+ //#region src/storage/sqlite/core/transactions/index.ts
197
+ const sqliteTransaction = (driverType, connection, allowNestedTransactions, serializer, defaultTransactionMode) => (getClient, options) => {
198
+ const transactionCounter = transactionNestingCounter();
199
+ allowNestedTransactions = options?.allowNestedTransactions ?? allowNestedTransactions;
200
+ return {
201
+ connection: connection(),
202
+ driverType,
203
+ begin: async function() {
204
+ const client = await getClient;
205
+ if (allowNestedTransactions) {
206
+ if (transactionCounter.level >= 1) {
207
+ transactionCounter.increment();
208
+ if (options?.useSavepoints) await client.command(require_core.SQL`SAVEPOINT transaction${require_core.SQL.plain(transactionCounter.level.toString())}`);
209
+ return;
210
+ }
211
+ transactionCounter.increment();
212
+ }
213
+ const mode = options?.mode ?? defaultTransactionMode ?? "IMMEDIATE";
214
+ await client.command(require_core.SQL`BEGIN ${require_core.SQL.plain(mode)} TRANSACTION`);
215
+ },
216
+ commit: async function() {
217
+ const client = await getClient;
218
+ try {
219
+ if (allowNestedTransactions) {
220
+ if (transactionCounter.level > 1) {
221
+ if (options?.useSavepoints) await client.command(require_core.SQL`RELEASE transaction${require_core.SQL.plain(transactionCounter.level.toString())}`);
222
+ transactionCounter.decrement();
223
+ return;
224
+ }
225
+ transactionCounter.reset();
226
+ }
227
+ await client.command(require_core.SQL`COMMIT`);
228
+ } finally {
229
+ if (options?.close) await options?.close(client);
230
+ }
231
+ },
232
+ rollback: async function(error) {
233
+ const client = await getClient;
234
+ try {
235
+ if (allowNestedTransactions) {
236
+ if (transactionCounter.level > 1) {
237
+ transactionCounter.decrement();
238
+ return;
239
+ }
240
+ }
241
+ await client.command(require_core.SQL`ROLLBACK`);
242
+ } finally {
243
+ if (options?.close) await options?.close(client, error);
244
+ }
245
+ },
246
+ execute: require_core.sqlExecutor(sqliteSQLExecutor(driverType, serializer), { connect: () => getClient }),
247
+ _transactionOptions: options ?? {}
248
+ };
249
+ };
250
+
251
+ //#endregion
252
+ //#region src/storage/sqlite/core/connections/connectionString.ts
253
+ const SQLiteConnectionString = (connectionString) => {
254
+ if (!connectionString.startsWith("file:") && connectionString !== ":memory:" && !connectionString.startsWith("/") && !connectionString.startsWith("./")) throw new Error(`Invalid SQLite connection string: ${connectionString}. It should start with "file:", ":memory:", "/", or "./".`);
255
+ return connectionString;
256
+ };
257
+ const parsePragmasFromConnectionString = (connectionString) => {
258
+ const str = String(connectionString);
259
+ if (!str.startsWith("file:")) return {};
260
+ const params = new URL(str).searchParams;
261
+ const pragmas = {};
262
+ const journalMode = params.get("journal_mode");
263
+ if (journalMode !== null) pragmas.journal_mode = journalMode;
264
+ const synchronous = params.get("synchronous");
265
+ if (synchronous !== null) pragmas.synchronous = synchronous;
266
+ const cacheSize = params.get("cache_size");
267
+ if (cacheSize !== null) pragmas.cache_size = parseInt(cacheSize, 10);
268
+ const foreignKeys = params.get("foreign_keys");
269
+ if (foreignKeys !== null) {
270
+ const val = foreignKeys.toLowerCase();
271
+ pragmas.foreign_keys = val === "true" || val === "on" || val === "1";
272
+ }
273
+ const tempStore = params.get("temp_store");
274
+ if (tempStore !== null) pragmas.temp_store = tempStore.toUpperCase();
275
+ const busyTimeout = params.get("busy_timeout");
276
+ if (busyTimeout !== null) pragmas.busy_timeout = parseInt(busyTimeout, 10);
277
+ const mmapSize = params.get("mmap_size");
278
+ if (mmapSize !== null) pragmas.mmap_size = parseInt(mmapSize, 10);
279
+ return pragmas;
280
+ };
281
+
282
+ //#endregion
283
+ //#region src/storage/sqlite/core/connections/index.ts
284
+ const isSQLiteError = (error) => {
285
+ if (error instanceof Error && "code" in error) return true;
286
+ return false;
287
+ };
288
+ const transactionNestingCounter = () => {
289
+ let transactionLevel = 0;
290
+ return {
291
+ reset: () => {
292
+ transactionLevel = 0;
293
+ },
294
+ increment: () => {
295
+ transactionLevel++;
296
+ },
297
+ decrement: () => {
298
+ transactionLevel--;
299
+ if (transactionLevel < 0) throw new Error("Transaction level is out of bounds");
300
+ },
301
+ get level() {
302
+ return transactionLevel;
303
+ }
304
+ };
305
+ };
306
+ const sqliteAmbientClientConnection = (options) => {
307
+ const { client, driverType, initTransaction, allowNestedTransactions, defaultTransactionMode, serializer, errorMapper } = options;
308
+ return require_core.createAmbientConnection({
309
+ driverType,
310
+ client,
311
+ initTransaction: initTransaction ?? ((connection) => sqliteTransaction(driverType, connection, allowNestedTransactions ?? false, serializer, defaultTransactionMode)),
312
+ executor: ({ serializer }) => sqliteSQLExecutor(driverType, serializer, void 0, errorMapper),
313
+ serializer
314
+ });
315
+ };
316
+ const sqliteClientConnection = (options) => {
317
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
318
+ let client = null;
319
+ const connect = async () => {
320
+ if (client) return Promise.resolve(client);
321
+ client = sqliteClientFactory(connectionOptions);
322
+ if (client && "connect" in client && typeof client.connect === "function") try {
323
+ await client.connect();
324
+ } catch (error) {
325
+ throw mapSqliteError(error);
326
+ }
327
+ return client;
328
+ };
329
+ return require_core.createConnection({
330
+ driverType: options.driverType,
331
+ connect,
332
+ close: async () => {
333
+ if (client && "close" in client && typeof client.close === "function") await client.close();
334
+ else if (client && "release" in client && typeof client.release === "function") client.release();
335
+ },
336
+ initTransaction: (connection) => sqliteTransaction(options.driverType, connection, connectionOptions.transactionOptions?.allowNestedTransactions ?? false, serializer, connectionOptions.defaultTransactionMode),
337
+ executor: ({ serializer }) => sqliteSQLExecutor(options.driverType, serializer),
338
+ serializer
339
+ });
340
+ };
341
+ const sqlitePoolClientConnection = (options) => {
342
+ const { connectionOptions, sqliteClientFactory, serializer } = options;
343
+ let client = null;
344
+ const connect = async () => {
345
+ if (client) return Promise.resolve(client);
346
+ client = sqliteClientFactory(connectionOptions);
347
+ try {
348
+ await client.connect();
349
+ } catch (error) {
350
+ throw mapSqliteError(error);
351
+ }
352
+ return client;
353
+ };
354
+ return require_core.createConnection({
355
+ driverType: options.driverType,
356
+ connect,
357
+ close: () => client !== null ? Promise.resolve(client.release()) : Promise.resolve(),
358
+ initTransaction: (connection) => sqliteTransaction(options.driverType, connection, connectionOptions.transactionOptions?.allowNestedTransactions ?? false, serializer, connectionOptions.defaultTransactionMode),
359
+ executor: ({ serializer }) => sqliteSQLExecutor(options.driverType, serializer),
360
+ serializer
361
+ });
362
+ };
363
+ function sqliteConnection(options) {
364
+ return options.type === "Client" ? sqliteClientConnection(options) : sqlitePoolClientConnection(options);
365
+ }
366
+ const InMemorySQLiteDatabase = SQLiteConnectionString(":memory:");
367
+ const DEFAULT_SQLITE_PRAGMA_OPTIONS = {
368
+ journal_mode: "WAL",
369
+ synchronous: "NORMAL",
370
+ cache_size: -1e6,
371
+ foreign_keys: true,
372
+ temp_store: "MEMORY",
373
+ busy_timeout: 5e3,
374
+ mmap_size: 268435456
375
+ };
376
+
377
+ //#endregion
378
+ //#region src/storage/sqlite/core/pool/dualPool.ts
379
+ const sqliteDualConnectionPool = (options) => {
380
+ const { sqliteConnectionFactory, connectionOptions } = options;
381
+ const readerPoolSize = options.readerPoolSize ?? Math.max(4, (0, os.cpus)().length);
382
+ let databaseInitPromise = null;
383
+ const guardSingleConnection = require_core.guardInitializedOnce(async () => {
384
+ if (databaseInitPromise !== null) return databaseInitPromise;
385
+ const initConnection = sqliteConnectionFactory({
386
+ ...connectionOptions,
387
+ skipDatabasePragmas: false,
388
+ readonly: false
389
+ });
390
+ const initPromise = initConnection.open();
391
+ databaseInitPromise = initPromise;
392
+ try {
393
+ await initPromise;
394
+ await initConnection.close();
395
+ } catch (error) {
396
+ databaseInitPromise = null;
397
+ await initConnection.close();
398
+ throw mapSqliteError(error);
399
+ }
400
+ });
401
+ const ensureDatabaseInitialized = async () => {
402
+ if (databaseInitPromise !== null) return databaseInitPromise;
403
+ return guardSingleConnection.ensureInitialized();
404
+ };
405
+ const wrappedConnectionFactory = async (readonly, connectionOptions) => {
406
+ await ensureDatabaseInitialized();
407
+ const connection = sqliteConnectionFactory({
408
+ ...connectionOptions,
409
+ skipDatabasePragmas: true,
410
+ readonly
411
+ });
412
+ await connection.open();
413
+ return connection;
414
+ };
415
+ const writerPool = require_core.createSingletonConnectionPool({
416
+ driverType: options.driverType,
417
+ getConnection: () => wrappedConnectionFactory(false, connectionOptions)
418
+ });
419
+ const readerPool = require_core.createBoundedConnectionPool({
420
+ driverType: options.driverType,
421
+ getConnection: () => wrappedConnectionFactory(true, connectionOptions),
422
+ maxConnections: readerPoolSize
423
+ });
424
+ return {
425
+ driverType: options.driverType,
426
+ connection: (connectionOptions) => connectionOptions?.readonly ? readerPool.connection(connectionOptions) : writerPool.connection(connectionOptions),
427
+ execute: {
428
+ query: (...args) => readerPool.execute.query(...args),
429
+ batchQuery: (...args) => readerPool.execute.batchQuery(...args),
430
+ command: (...args) => writerPool.execute.command(...args),
431
+ batchCommand: (...args) => writerPool.execute.batchCommand(...args)
432
+ },
433
+ withConnection: (handle, connectionOptions) => connectionOptions?.readonly ? readerPool.withConnection(handle, connectionOptions) : writerPool.withConnection(handle, connectionOptions),
434
+ transaction: writerPool.transaction,
435
+ withTransaction: writerPool.withTransaction,
436
+ close: async () => {
437
+ await guardSingleConnection.stop();
438
+ await Promise.all([writerPool.close(), readerPool.close()]);
439
+ }
440
+ };
441
+ };
442
+
443
+ //#endregion
444
+ //#region src/storage/sqlite/core/pool/pool.ts
445
+ const isInMemoryDatabase = (options) => {
446
+ if ("fileName" in options) return options.fileName === InMemorySQLiteDatabase;
447
+ if ("connectionString" in options) return options.connectionString === InMemorySQLiteDatabase;
448
+ return false;
449
+ };
450
+ const sqliteAmbientConnectionPool = (options) => {
451
+ const { connection, driverType } = options;
452
+ return require_core.createAmbientConnectionPool({
453
+ driverType,
454
+ connection
455
+ });
456
+ };
457
+ const sqliteSingletonConnectionPool = (options) => {
458
+ const { driverType, sqliteConnectionFactory, connectionOptions } = options;
459
+ return require_core.createSingletonConnectionPool({
460
+ driverType,
461
+ getConnection: () => sqliteConnectionFactory(connectionOptions)
462
+ });
463
+ };
464
+ const sqliteAlwaysNewConnectionPool = (options) => {
465
+ const { driverType, sqliteConnectionFactory, connectionOptions } = options;
466
+ return require_core.createAlwaysNewConnectionPool({
467
+ driverType,
468
+ getConnection: () => sqliteConnectionFactory(connectionOptions)
469
+ });
470
+ };
471
+ const toSqlitePoolOptions = (options) => {
472
+ const { singleton, ...rest } = options;
473
+ const isInMemory = isInMemoryDatabase(options);
474
+ if ("client" in options && options.client) return {
475
+ ...rest,
476
+ singleton: true
477
+ };
478
+ if (isInMemory) return {
479
+ ...rest,
480
+ singleton: true
481
+ };
482
+ if (singleton === true) return {
483
+ ...rest,
484
+ singleton: true
485
+ };
486
+ return {
487
+ ...rest,
488
+ dual: true
489
+ };
490
+ };
491
+ function sqlitePool(options) {
492
+ const { driverType } = options;
493
+ if (options.connection) return require_core.createAmbientConnectionPool({
494
+ driverType,
495
+ connection: options.connection
496
+ });
497
+ if ("dual" in options && options.dual) return sqliteDualConnectionPool(options);
498
+ if (options.singleton === true && options.sqliteConnectionFactory) return require_core.createSingletonConnectionPool({
499
+ driverType,
500
+ getConnection: () => options.sqliteConnectionFactory(options.connectionOptions)
501
+ });
502
+ return require_core.createAlwaysNewConnectionPool({
503
+ driverType,
504
+ getConnection: () => options.sqliteConnectionFactory(options.connectionOptions)
505
+ });
506
+ }
507
+
508
+ //#endregion
509
+ //#region src/storage/sqlite/core/schema/migrations.ts
510
+ const DefaultSQLiteMigratorOptions = {};
511
+ require_core.registerDefaultMigratorOptions("SQLite", DefaultSQLiteMigratorOptions);
512
+
513
+ //#endregion
514
+ //#region src/storage/sqlite/core/index.ts
515
+ const SQLiteDatabaseName = "SQLite";
516
+
517
+ //#endregion
518
+ Object.defineProperty(exports, 'DEFAULT_SQLITE_PRAGMA_OPTIONS', {
519
+ enumerable: true,
520
+ get: function () {
521
+ return DEFAULT_SQLITE_PRAGMA_OPTIONS;
522
+ }
523
+ });
524
+ Object.defineProperty(exports, 'DefaultSQLiteMigratorOptions', {
525
+ enumerable: true,
526
+ get: function () {
527
+ return DefaultSQLiteMigratorOptions;
528
+ }
529
+ });
530
+ Object.defineProperty(exports, 'InMemorySQLiteDatabase', {
531
+ enumerable: true,
532
+ get: function () {
533
+ return InMemorySQLiteDatabase;
534
+ }
535
+ });
536
+ Object.defineProperty(exports, 'SQLiteConnectionString', {
537
+ enumerable: true,
538
+ get: function () {
539
+ return SQLiteConnectionString;
540
+ }
541
+ });
542
+ Object.defineProperty(exports, 'SQLiteDatabaseName', {
543
+ enumerable: true,
544
+ get: function () {
545
+ return SQLiteDatabaseName;
546
+ }
547
+ });
548
+ Object.defineProperty(exports, 'isInMemoryDatabase', {
549
+ enumerable: true,
550
+ get: function () {
551
+ return isInMemoryDatabase;
552
+ }
553
+ });
554
+ Object.defineProperty(exports, 'isSQLiteError', {
555
+ enumerable: true,
556
+ get: function () {
557
+ return isSQLiteError;
558
+ }
559
+ });
560
+ Object.defineProperty(exports, 'mapSqliteError', {
561
+ enumerable: true,
562
+ get: function () {
563
+ return mapSqliteError;
564
+ }
565
+ });
566
+ Object.defineProperty(exports, 'parsePragmasFromConnectionString', {
567
+ enumerable: true,
568
+ get: function () {
569
+ return parsePragmasFromConnectionString;
570
+ }
571
+ });
572
+ Object.defineProperty(exports, 'sqliteAlwaysNewConnectionPool', {
573
+ enumerable: true,
574
+ get: function () {
575
+ return sqliteAlwaysNewConnectionPool;
576
+ }
577
+ });
578
+ Object.defineProperty(exports, 'sqliteAmbientClientConnection', {
579
+ enumerable: true,
580
+ get: function () {
581
+ return sqliteAmbientClientConnection;
582
+ }
583
+ });
584
+ Object.defineProperty(exports, 'sqliteAmbientConnectionPool', {
585
+ enumerable: true,
586
+ get: function () {
587
+ return sqliteAmbientConnectionPool;
588
+ }
589
+ });
590
+ Object.defineProperty(exports, 'sqliteClientConnection', {
591
+ enumerable: true,
592
+ get: function () {
593
+ return sqliteClientConnection;
594
+ }
595
+ });
596
+ Object.defineProperty(exports, 'sqliteConnection', {
597
+ enumerable: true,
598
+ get: function () {
599
+ return sqliteConnection;
600
+ }
601
+ });
602
+ Object.defineProperty(exports, 'sqliteExecute', {
603
+ enumerable: true,
604
+ get: function () {
605
+ return sqliteExecute;
606
+ }
607
+ });
608
+ Object.defineProperty(exports, 'sqliteFormatter', {
609
+ enumerable: true,
610
+ get: function () {
611
+ return sqliteFormatter;
612
+ }
613
+ });
614
+ Object.defineProperty(exports, 'sqlitePool', {
615
+ enumerable: true,
616
+ get: function () {
617
+ return sqlitePool;
618
+ }
619
+ });
620
+ Object.defineProperty(exports, 'sqlitePoolClientConnection', {
621
+ enumerable: true,
622
+ get: function () {
623
+ return sqlitePoolClientConnection;
624
+ }
625
+ });
626
+ Object.defineProperty(exports, 'sqliteSQLExecutor', {
627
+ enumerable: true,
628
+ get: function () {
629
+ return sqliteSQLExecutor;
630
+ }
631
+ });
632
+ Object.defineProperty(exports, 'sqliteSingletonConnectionPool', {
633
+ enumerable: true,
634
+ get: function () {
635
+ return sqliteSingletonConnectionPool;
636
+ }
637
+ });
638
+ Object.defineProperty(exports, 'sqliteTransaction', {
639
+ enumerable: true,
640
+ get: function () {
641
+ return sqliteTransaction;
642
+ }
643
+ });
644
+ Object.defineProperty(exports, 'toSqlitePoolOptions', {
645
+ enumerable: true,
646
+ get: function () {
647
+ return toSqlitePoolOptions;
648
+ }
649
+ });
650
+ Object.defineProperty(exports, 'transactionNestingCounter', {
651
+ enumerable: true,
652
+ get: function () {
653
+ return transactionNestingCounter;
654
+ }
655
+ });
656
+ //# sourceMappingURL=core-DmbB4qMn.cjs.map