@event-driven-io/dumbo 0.13.0-beta.4 → 0.13.0-beta.41

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 (83) hide show
  1. package/dist/cloudflare.cjs +397 -0
  2. package/dist/cloudflare.cjs.map +1 -0
  3. package/dist/cloudflare.d.cts +99 -0
  4. package/dist/cloudflare.d.ts +99 -0
  5. package/dist/cloudflare.js +361 -0
  6. package/dist/cloudflare.js.map +1 -0
  7. package/dist/core-BMeDuqBQ.js +2265 -0
  8. package/dist/core-BMeDuqBQ.js.map +1 -0
  9. package/dist/core-BPNgo5b6.js +379 -0
  10. package/dist/core-BPNgo5b6.js.map +1 -0
  11. package/dist/core-CIVu4cNp.cjs +588 -0
  12. package/dist/core-CIVu4cNp.cjs.map +1 -0
  13. package/dist/core-D5W_5J8k.cjs +3246 -0
  14. package/dist/core-D5W_5J8k.cjs.map +1 -0
  15. package/dist/core-DqUjje4u.cjs +450 -0
  16. package/dist/core-DqUjje4u.cjs.map +1 -0
  17. package/dist/core-gu5fi784.js +451 -0
  18. package/dist/core-gu5fi784.js.map +1 -0
  19. package/dist/{index-C2z_XBn6.d.ts → index-B-q2er0S.d.cts} +122 -75
  20. package/dist/{index-C0h0c380.d.cts → index-B5qbt5nP.d.ts} +122 -75
  21. package/dist/index-BJJAkyuJ.d.ts +68 -0
  22. package/dist/index-CRbkvVjT.d.ts +1587 -0
  23. package/dist/index-Cmdlb0KP.d.cts +1587 -0
  24. package/dist/index-D7qxqMf9.d.cts +67 -0
  25. package/dist/index-DtRCGhFP.d.cts +68 -0
  26. package/dist/index-m5LDyNNF.d.ts +67 -0
  27. package/dist/index.cjs +219 -270
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +3 -127
  30. package/dist/index.d.ts +3 -127
  31. package/dist/index.js +56 -269
  32. package/dist/index.js.map +1 -1
  33. package/dist/pg.cjs +373 -659
  34. package/dist/pg.cjs.map +1 -1
  35. package/dist/pg.d.cts +140 -153
  36. package/dist/pg.d.ts +140 -153
  37. package/dist/pg.js +326 -658
  38. package/dist/pg.js.map +1 -1
  39. package/dist/postgreSQLMetadata-Khf1e9CT.js +65 -0
  40. package/dist/postgreSQLMetadata-Khf1e9CT.js.map +1 -0
  41. package/dist/postgreSQLMetadata-Ri_p5u6i.cjs +118 -0
  42. package/dist/postgreSQLMetadata-Ri_p5u6i.cjs.map +1 -0
  43. package/dist/postgresql.cjs +25 -0
  44. package/dist/postgresql.d.cts +3 -0
  45. package/dist/postgresql.d.ts +3 -0
  46. package/dist/postgresql.js +4 -0
  47. package/dist/sqlite.cjs +30 -0
  48. package/dist/sqlite.d.cts +3 -0
  49. package/dist/sqlite.d.ts +3 -0
  50. package/dist/sqlite.js +4 -0
  51. package/dist/sqlite3.cjs +437 -273
  52. package/dist/sqlite3.cjs.map +1 -1
  53. package/dist/sqlite3.d.cts +92 -70
  54. package/dist/sqlite3.d.ts +92 -70
  55. package/dist/sqlite3.js +402 -272
  56. package/dist/sqlite3.js.map +1 -1
  57. package/dist/sqliteMetadata-CpmoZxqb.cjs +46 -0
  58. package/dist/sqliteMetadata-CpmoZxqb.cjs.map +1 -0
  59. package/dist/sqliteMetadata-viYmVwA5.js +29 -0
  60. package/dist/sqliteMetadata-viYmVwA5.js.map +1 -0
  61. package/package.json +60 -37
  62. package/dist/chunk-32AL3EAS.cjs +0 -47
  63. package/dist/chunk-32AL3EAS.cjs.map +0 -1
  64. package/dist/chunk-6IHCIJ7S.js +0 -47
  65. package/dist/chunk-6IHCIJ7S.js.map +0 -1
  66. package/dist/chunk-IYEHOE4S.cjs +0 -405
  67. package/dist/chunk-IYEHOE4S.cjs.map +0 -1
  68. package/dist/chunk-N7RWT46K.js +0 -2011
  69. package/dist/chunk-N7RWT46K.js.map +0 -1
  70. package/dist/chunk-OJ34O3Q2.cjs +0 -2011
  71. package/dist/chunk-OJ34O3Q2.cjs.map +0 -1
  72. package/dist/chunk-XVV3OOQX.js +0 -405
  73. package/dist/chunk-XVV3OOQX.js.map +0 -1
  74. package/dist/columnProcessors-BX-sH7ah.d.cts +0 -8
  75. package/dist/columnProcessors-DMPpTPqM.d.ts +0 -8
  76. package/dist/connectionString-B1wm0TFc.d.cts +0 -1271
  77. package/dist/connectionString-B1wm0TFc.d.ts +0 -1271
  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
package/dist/sqlite3.cjs CHANGED
@@ -1,282 +1,446 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
- var _chunkIYEHOE4Scjs = require('./chunk-IYEHOE4S.cjs');
26
- require('./chunk-32AL3EAS.cjs');
27
-
28
-
29
-
30
-
31
- var _chunkOJ34O3Q2cjs = require('./chunk-OJ34O3Q2.cjs');
32
-
33
- // src/storage/sqlite/sqlite3/connections/connection.ts
34
- var _sqlite3 = require('sqlite3'); var _sqlite32 = _interopRequireDefault(_sqlite3);
35
- var SQLite3DriverType = "SQLite:sqlite3";
36
- var sqlite3Client = (options) => {
37
- let db;
38
- let isClosed = false;
39
- const connect = () => db ? Promise.resolve() : new Promise((resolve, reject) => {
40
- try {
41
- db = new _sqlite32.default.Database(
42
- _nullishCoalesce(_nullishCoalesce(options.fileName, () => ( options.connectionString)), () => ( _chunkIYEHOE4Scjs.InMemorySQLiteDatabase)),
43
- _sqlite32.default.OPEN_URI | _sqlite32.default.OPEN_READWRITE | _sqlite32.default.OPEN_CREATE,
44
- (err) => {
45
- if (err) {
46
- reject(err);
47
- return;
48
- }
49
- }
50
- );
51
- db.run("PRAGMA journal_mode = WAL;", (err) => {
52
- if (err) {
53
- reject(err);
54
- return;
55
- }
56
- resolve();
57
- });
58
- } catch (error) {
59
- reject(error);
60
- }
61
- });
62
- const executeQuery = (sql, params) => new Promise((resolve, reject) => {
63
- try {
64
- db.all(sql, _nullishCoalesce(params, () => ( [])), (err, result) => {
65
- if (err) {
66
- reject(err);
67
- return;
68
- }
69
- resolve(result);
70
- });
71
- } catch (error) {
72
- reject(error);
73
- }
74
- });
75
- const executeCommand = (sql, params, options2) => new Promise((resolve, reject) => {
76
- try {
77
- if (_optionalChain([options2, 'optionalAccess', _ => _.ignoreChangesCount]) === true) {
78
- db.run(
79
- sql,
80
- _nullishCoalesce(params, () => ( [])),
81
- function(err, rows) {
82
- if (err) {
83
- reject(err);
84
- return;
85
- }
86
- resolve({
87
- rowCount: 0,
88
- rows: _nullishCoalesce(rows, () => ( []))
89
- });
90
- }
91
- );
92
- }
93
- db.serialize(() => {
94
- db.all(sql, _nullishCoalesce(params, () => ( [])), (err, rows) => {
95
- if (err) {
96
- reject(err);
97
- return;
98
- }
99
- db.get(
100
- "SELECT changes() as changes",
101
- (changesErr, row) => {
102
- if (changesErr) {
103
- reject(changesErr);
104
- return;
105
- }
106
- resolve({
107
- rowCount: _nullishCoalesce(_optionalChain([row, 'optionalAccess', _2 => _2.changes]), () => ( 0)),
108
- rows: _nullishCoalesce(rows, () => ( []))
109
- });
110
- }
111
- );
112
- });
113
- });
114
- } catch (error) {
115
- reject(error);
116
- }
117
- });
118
- return {
119
- connect,
120
- close: () => {
121
- if (isClosed) {
122
- return Promise.resolve();
123
- }
124
- isClosed = true;
125
- if (db)
126
- return new Promise((resolve, reject) => {
127
- db.close((err) => {
128
- if (err) {
129
- reject(err);
130
- return;
131
- }
132
- resolve();
133
- });
134
- });
135
- return Promise.resolve();
136
- },
137
- query: async (sql, _options) => {
138
- const { query, params } = _chunkIYEHOE4Scjs.sqliteFormatter.format(sql);
139
- const result = await executeQuery(
140
- query,
141
- params
142
- );
143
- return { rowCount: result.length, rows: result };
144
- },
145
- batchQuery: async (sqls, _options) => {
146
- const results = [];
147
- for (const sql of sqls) {
148
- const { query, params } = _chunkIYEHOE4Scjs.sqliteFormatter.format(sql);
149
- const result = await executeQuery(
150
- query,
151
- params
152
- );
153
- results.push({ rowCount: result.length, rows: result });
154
- }
155
- return results;
156
- },
157
- command: async (sql, options2) => {
158
- const { query, params } = _chunkIYEHOE4Scjs.sqliteFormatter.format(sql);
159
- return executeCommand(
160
- query,
161
- params,
162
- options2
163
- );
164
- },
165
- batchCommand: async (sqls, options2) => {
166
- const results = [];
167
- for (const sql of sqls) {
168
- const { query, params } = _chunkIYEHOE4Scjs.sqliteFormatter.format(sql);
169
- const result = await executeCommand(
170
- query,
171
- params,
172
- options2
173
- );
174
- results.push(result);
175
- }
176
- return results;
177
- }
178
- };
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_core = require('./core-D5W_5J8k.cjs');
3
+ const require_sqliteMetadata = require('./sqliteMetadata-CpmoZxqb.cjs');
4
+ const require_core$1 = require('./core-CIVu4cNp.cjs');
5
+ let sqlite3 = require("sqlite3");
6
+ sqlite3 = require_core.__toESM(sqlite3, 1);
7
+ let os = require("os");
8
+ let node_async_hooks = require("node:async_hooks");
9
+
10
+ //#region src/storage/sqlite/core/connections/pragmas.ts
11
+ const mergePragmaOptions = (connectionString, userOptions) => {
12
+ const connectionStringPragmas = require_core$1.parsePragmasFromConnectionString(connectionString);
13
+ return {
14
+ ...require_core$1.DEFAULT_SQLITE_PRAGMA_OPTIONS,
15
+ ...connectionStringPragmas,
16
+ ...userOptions
17
+ };
179
18
  };
180
- var checkConnection = async (fileName) => {
181
- const client = sqlite3Client({
182
- fileName
183
- });
184
- try {
185
- await client.query(_chunkOJ34O3Q2cjs.SQL`SELECT 1`);
186
- return { successful: true };
187
- } catch (error) {
188
- const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
189
- return {
190
- successful: false,
191
- errorType: code === "SQLITE_CANTOPEN" ? "ConnectionRefused" : code === "SQLITE_AUTH" ? "Authentication" : "Unknown",
192
- code,
193
- error
194
- };
195
- } finally {
196
- await client.close();
197
- }
19
+ const buildConnectionPragmaStatements = (pragmas) => [
20
+ {
21
+ pragma: "busy_timeout",
22
+ value: pragmas.busy_timeout
23
+ },
24
+ {
25
+ pragma: "synchronous",
26
+ value: pragmas.synchronous
27
+ },
28
+ {
29
+ pragma: "cache_size",
30
+ value: pragmas.cache_size
31
+ },
32
+ {
33
+ pragma: "foreign_keys",
34
+ value: pragmas.foreign_keys ? "ON" : "OFF"
35
+ },
36
+ {
37
+ pragma: "temp_store",
38
+ value: pragmas.temp_store
39
+ },
40
+ ...pragmas.mmap_size !== void 0 ? [{
41
+ pragma: "mmap_size",
42
+ value: pragmas.mmap_size
43
+ }] : []
44
+ ];
45
+ const buildDatabasePragmaStatements = (pragmas) => [{
46
+ pragma: "journal_mode",
47
+ value: pragmas.journal_mode
48
+ }];
49
+
50
+ //#endregion
51
+ //#region src/storage/sqlite/sqlite3/connections/connection.ts
52
+ const SQLite3DriverType = "SQLite:sqlite3";
53
+ const hasReturningClause = (sql) => /\bRETURNING\b/i.test(sql);
54
+ const applyPragma = (database, pragma, value) => {
55
+ return new Promise((resolve, reject) => {
56
+ database.run(`PRAGMA ${pragma} = ${value};`, (err) => {
57
+ if (err) reject(err);
58
+ else resolve();
59
+ });
60
+ });
198
61
  };
199
- var sqlite3Connection = (options) => _chunkIYEHOE4Scjs.sqliteConnection.call(void 0, {
200
- type: "Client",
201
- driverType: SQLite3DriverType,
202
- sqliteClientFactory: (connectionOptions) => {
203
- if ("client" in connectionOptions && connectionOptions.client) {
204
- return connectionOptions.client;
205
- }
206
- return sqlite3Client(connectionOptions);
207
- },
208
- connectionOptions: options
62
+ const queryPragma = (database, pragma) => new Promise((resolve, reject) => {
63
+ database.get(`PRAGMA ${pragma};`, (err, row) => {
64
+ if (err) reject(err);
65
+ else resolve(row?.[pragma] ?? "");
66
+ });
209
67
  });
210
-
211
- // src/storage/sqlite/sqlite3/index.ts
212
- var sqlite3Pool = (options) => _chunkIYEHOE4Scjs.sqlitePool.call(void 0,
213
- _chunkIYEHOE4Scjs.toSqlitePoolOptions.call(void 0, {
214
- ...options,
215
- driverType: SQLite3DriverType,
216
- ..."connection" in options ? {} : {
217
- connectionOptions: options,
218
- sqliteConnectionFactory: (opts) => sqlite3Connection(opts)
219
- }
220
- })
221
- );
222
- var tryParseConnectionString = (connectionString) => {
223
- try {
224
- return _chunkIYEHOE4Scjs.SQLiteConnectionString.call(void 0, connectionString);
225
- } catch (e) {
226
- return null;
227
- }
228
- };
229
- var sqlite3DatabaseDriver = {
230
- driverType: SQLite3DriverType,
231
- createPool: (options) => sqlite3Pool(options),
232
- sqlFormatter: _chunkIYEHOE4Scjs.sqliteFormatter,
233
- defaultMigratorOptions: _chunkIYEHOE4Scjs.DefaultSQLiteMigratorOptions,
234
- getDatabaseNameOrDefault: () => _chunkIYEHOE4Scjs.InMemorySQLiteDatabase,
235
- canHandle: _chunkOJ34O3Q2cjs.canHandleDriverWithConnectionString.call(void 0,
236
- SQLite3DriverType,
237
- tryParseConnectionString
238
- )
68
+ const applyPragmas = (database, pragmas) => pragmas.reduce((promise, { pragma, value }) => promise.then(() => applyPragma(database, pragma, value)), Promise.resolve());
69
+ const sqlite3Client = (options) => {
70
+ let db;
71
+ let isClosed = false;
72
+ const { serializer } = options;
73
+ const connectionString = options.fileName ?? options.connectionString ?? require_core$1.InMemorySQLiteDatabase;
74
+ const finalPragmas = mergePragmaOptions(String(connectionString), options.pragmaOptions);
75
+ const connectionPragmas = buildConnectionPragmaStatements(finalPragmas);
76
+ const connect = () => db ? Promise.resolve() : new Promise((resolve, reject) => {
77
+ try {
78
+ db = new sqlite3.default.Database(connectionString, sqlite3.default.OPEN_URI | sqlite3.default.OPEN_READWRITE | sqlite3.default.OPEN_CREATE, (err) => {
79
+ if (err) {
80
+ reject(err);
81
+ return;
82
+ }
83
+ const busyTimeout = finalPragmas.busy_timeout ?? require_core$1.DEFAULT_SQLITE_PRAGMA_OPTIONS.busy_timeout;
84
+ db.configure("busyTimeout", busyTimeout);
85
+ applyPragmas(db, connectionPragmas.filter((p) => p.pragma !== "busy_timeout")).then(async () => {
86
+ if (options.skipDatabasePragmas) return;
87
+ const databasePragmas = buildDatabasePragmaStatements(finalPragmas);
88
+ for (const { pragma, value } of databasePragmas) if ((await queryPragma(db, pragma)).toUpperCase() !== String(value).toUpperCase()) await applyPragma(db, pragma, value);
89
+ }).then(() => resolve()).catch(reject);
90
+ });
91
+ } catch (error) {
92
+ reject(error instanceof Error ? error : new Error(String(error)));
93
+ }
94
+ });
95
+ const executeQuery = (sql, params) => new Promise((resolve, reject) => {
96
+ try {
97
+ db.all(sql, params ?? [], (err, result) => {
98
+ if (err) {
99
+ reject(err);
100
+ return;
101
+ }
102
+ resolve(result);
103
+ });
104
+ } catch (error) {
105
+ reject(error instanceof Error ? error : new Error(String(error)));
106
+ }
107
+ });
108
+ const executeCommand = (sql, params, options) => new Promise((resolve, reject) => {
109
+ try {
110
+ if (options?.ignoreChangesCount === true) {
111
+ db.run(sql, params ?? [], function(err, rows) {
112
+ if (err) {
113
+ reject(err);
114
+ return;
115
+ }
116
+ resolve({
117
+ rowCount: 0,
118
+ rows: rows ?? []
119
+ });
120
+ });
121
+ return;
122
+ }
123
+ if (hasReturningClause(sql)) {
124
+ db.all(sql, params ?? [], (err, rows) => {
125
+ if (err) return reject(err);
126
+ resolve({
127
+ rowCount: rows.length,
128
+ rows
129
+ });
130
+ });
131
+ return;
132
+ }
133
+ db.serialize(() => {
134
+ let hasFailed = false;
135
+ let resultRows = [];
136
+ db.all(sql, params ?? [], (err, rows) => {
137
+ if (err) {
138
+ hasFailed = true;
139
+ return reject(err);
140
+ }
141
+ resultRows = rows;
142
+ });
143
+ db.get("SELECT changes() as changes", (err, row) => {
144
+ if (hasFailed) return;
145
+ if (err) return reject(err);
146
+ resolve({
147
+ rowCount: row?.changes ?? 0,
148
+ rows: resultRows
149
+ });
150
+ });
151
+ });
152
+ } catch (error) {
153
+ reject(error instanceof Error ? error : new Error(String(error)));
154
+ }
155
+ });
156
+ return {
157
+ connect,
158
+ close: async () => {
159
+ if (isClosed) return;
160
+ isClosed = true;
161
+ if (db) try {
162
+ await new Promise((resolve, reject) => {
163
+ db.close((err) => {
164
+ if (err) {
165
+ reject(err);
166
+ return;
167
+ }
168
+ resolve();
169
+ });
170
+ });
171
+ } catch (error) {
172
+ throw require_core$1.mapSqliteError(error);
173
+ }
174
+ },
175
+ query: async (sql, _options) => {
176
+ try {
177
+ const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
178
+ const result = await executeQuery(query, params);
179
+ return {
180
+ rowCount: result.length,
181
+ rows: result
182
+ };
183
+ } catch (error) {
184
+ throw require_core$1.mapSqliteError(error);
185
+ }
186
+ },
187
+ batchQuery: async (sqls, _options) => {
188
+ try {
189
+ const results = [];
190
+ for (const sql of sqls) {
191
+ const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
192
+ const result = await executeQuery(query, params);
193
+ results.push({
194
+ rowCount: result.length,
195
+ rows: result
196
+ });
197
+ }
198
+ return results;
199
+ } catch (error) {
200
+ throw require_core$1.mapSqliteError(error);
201
+ }
202
+ },
203
+ command: async (sql, options) => {
204
+ try {
205
+ const { query, params } = require_core$1.sqliteFormatter.format(sql, { serializer });
206
+ return await executeCommand(query, params, options);
207
+ } catch (error) {
208
+ throw require_core$1.mapSqliteError(error);
209
+ }
210
+ },
211
+ batchCommand: async (sqls, options) => {
212
+ try {
213
+ const results = [];
214
+ for (let i = 0; i < sqls.length; i++) {
215
+ const { query, params } = require_core$1.sqliteFormatter.format(sqls[i], { serializer });
216
+ const result = await executeCommand(query, params, options);
217
+ results.push(result);
218
+ if (options?.assertChanges && (result.rowCount ?? 0) === 0) throw new require_core.BatchCommandNoChangesError(i);
219
+ }
220
+ return results;
221
+ } catch (error) {
222
+ throw require_core$1.mapSqliteError(error);
223
+ }
224
+ }
225
+ };
239
226
  };
240
- var useSqlite3DatabaseDriver = () => {
241
- _chunkOJ34O3Q2cjs.dumboDatabaseDriverRegistry.register(
242
- SQLite3DriverType,
243
- sqlite3DatabaseDriver
244
- );
227
+ const checkConnection = async (fileName, serializer) => {
228
+ const client = sqlite3Client({
229
+ fileName,
230
+ serializer
231
+ });
232
+ try {
233
+ await client.query(require_core.SQL`SELECT 1`);
234
+ return { successful: true };
235
+ } catch (error) {
236
+ const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
237
+ return {
238
+ successful: false,
239
+ errorType: code === "SQLITE_CANTOPEN" ? "ConnectionRefused" : code === "SQLITE_AUTH" ? "Authentication" : "Unknown",
240
+ code,
241
+ error
242
+ };
243
+ } finally {
244
+ await client.close();
245
+ }
245
246
  };
246
- useSqlite3DatabaseDriver();
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
247
+ const sqlite3Connection = (options) => require_core$1.sqliteConnection({
248
+ type: "Client",
249
+ driverType: SQLite3DriverType,
250
+ sqliteClientFactory: (connectionOptions) => {
251
+ if ("client" in connectionOptions && connectionOptions.client) return connectionOptions.client;
252
+ return sqlite3Client({
253
+ ...connectionOptions,
254
+ serializer: options.serializer
255
+ });
256
+ },
257
+ connectionOptions: options,
258
+ serializer: options.serializer
259
+ });
278
260
 
261
+ //#endregion
262
+ //#region src/storage/sqlite/sqlite3/pool/singletonPool.ts
263
+ const sqlite3SingletonPool = (options) => {
264
+ const inner = require_core.createSingletonConnectionPool({
265
+ driverType: options.driverType,
266
+ getConnection: options.getConnection,
267
+ ...options.closeConnection ? { closeConnection: options.closeConnection } : {}
268
+ });
269
+ const taskProcessor = new require_core.TaskProcessor({
270
+ maxActiveTasks: 1,
271
+ maxQueueSize: options.maxQueueSize ?? 1e3
272
+ });
273
+ const insideWriterTask = new node_async_hooks.AsyncLocalStorage();
274
+ const enqueue = (op) => {
275
+ if (insideWriterTask.getStore() === true) return op();
276
+ return taskProcessor.enqueue(({ ack }) => insideWriterTask.run(true, async () => {
277
+ try {
278
+ return await op();
279
+ } finally {
280
+ ack();
281
+ }
282
+ }));
283
+ };
284
+ return {
285
+ driverType: inner.driverType,
286
+ connection: inner.connection.bind(inner),
287
+ transaction: inner.transaction.bind(inner),
288
+ withConnection: (handle, connectionOptions) => enqueue(() => inner.withConnection(handle, connectionOptions)),
289
+ withTransaction: (handle, transactionOptions) => enqueue(() => inner.withTransaction(handle, transactionOptions)),
290
+ execute: {
291
+ query: (sql, queryOptions) => enqueue(() => inner.execute.query(sql, queryOptions)),
292
+ batchQuery: (sqls, queryOptions) => enqueue(() => inner.execute.batchQuery(sqls, queryOptions)),
293
+ command: (sql, commandOptions) => enqueue(() => inner.execute.command(sql, commandOptions)),
294
+ batchCommand: (sqls, commandOptions) => enqueue(() => inner.execute.batchCommand(sqls, commandOptions))
295
+ },
296
+ close: async () => {
297
+ await taskProcessor.stop();
298
+ await inner.close();
299
+ }
300
+ };
301
+ };
279
302
 
303
+ //#endregion
304
+ //#region src/storage/sqlite/sqlite3/pool/dualPool.ts
305
+ const sqliteDualConnectionPool = (options) => {
306
+ const { sqliteConnectionFactory, connectionOptions } = options;
307
+ const readerPoolSize = options.readerPoolSize ?? Math.max(4, (0, os.cpus)().length);
308
+ let databaseInitPromise = null;
309
+ const guardSingleConnection = require_core.guardInitializedOnce(async () => {
310
+ if (databaseInitPromise !== null) return databaseInitPromise;
311
+ const initConnection = sqliteConnectionFactory({
312
+ ...connectionOptions,
313
+ skipDatabasePragmas: false,
314
+ readonly: false
315
+ });
316
+ const initPromise = initConnection.open();
317
+ databaseInitPromise = initPromise;
318
+ try {
319
+ await initPromise;
320
+ await initConnection.close();
321
+ } catch (error) {
322
+ databaseInitPromise = null;
323
+ await initConnection.close();
324
+ throw require_core$1.mapSqliteError(error);
325
+ }
326
+ });
327
+ const ensureDatabaseInitialized = async () => {
328
+ if (databaseInitPromise !== null) return databaseInitPromise;
329
+ return guardSingleConnection.ensureInitialized();
330
+ };
331
+ const wrappedConnectionFactory = async (readonly, connectionOptions) => {
332
+ await ensureDatabaseInitialized();
333
+ const connection = sqliteConnectionFactory({
334
+ ...connectionOptions,
335
+ skipDatabasePragmas: true,
336
+ readonly
337
+ });
338
+ await connection.open();
339
+ return connection;
340
+ };
341
+ const writerPool = sqlite3SingletonPool({
342
+ driverType: options.driverType,
343
+ getConnection: () => wrappedConnectionFactory(false, connectionOptions)
344
+ });
345
+ const readerPool = require_core.createBoundedConnectionPool({
346
+ driverType: options.driverType,
347
+ getConnection: () => wrappedConnectionFactory(true, connectionOptions),
348
+ maxConnections: readerPoolSize
349
+ });
350
+ return {
351
+ driverType: options.driverType,
352
+ connection: (connectionOptions) => connectionOptions?.readonly ? readerPool.connection(connectionOptions) : writerPool.connection(connectionOptions),
353
+ execute: {
354
+ query: (...args) => readerPool.execute.query(...args),
355
+ batchQuery: (...args) => readerPool.execute.batchQuery(...args),
356
+ command: (...args) => writerPool.execute.command(...args),
357
+ batchCommand: (...args) => writerPool.execute.batchCommand(...args)
358
+ },
359
+ withConnection: (handle, connectionOptions) => connectionOptions?.readonly ? readerPool.withConnection(handle, connectionOptions) : writerPool.withConnection(handle, connectionOptions),
360
+ transaction: writerPool.transaction,
361
+ withTransaction: writerPool.withTransaction,
362
+ close: async () => {
363
+ await guardSingleConnection.stop();
364
+ await Promise.all([writerPool.close(), readerPool.close()]);
365
+ }
366
+ };
367
+ };
280
368
 
281
- exports.DefaultSQLiteMigratorOptions = _chunkIYEHOE4Scjs.DefaultSQLiteMigratorOptions; exports.InMemorySQLiteDatabase = _chunkIYEHOE4Scjs.InMemorySQLiteDatabase; exports.SQLite3DriverType = SQLite3DriverType; exports.SQLiteConnectionString = _chunkIYEHOE4Scjs.SQLiteConnectionString; exports.SQLiteDatabaseName = _chunkIYEHOE4Scjs.SQLiteDatabaseName; exports.checkConnection = checkConnection; exports.connectionPool = sqlite3Pool; exports.databaseDriver = sqlite3DatabaseDriver; exports.defaultPostgreSqlDatabase = _chunkIYEHOE4Scjs.defaultPostgreSqlDatabase; exports.isInMemoryDatabase = _chunkIYEHOE4Scjs.isInMemoryDatabase; exports.isSQLiteError = _chunkIYEHOE4Scjs.isSQLiteError; exports.sqlite3Client = sqlite3Client; exports.sqlite3Connection = sqlite3Connection; exports.sqlite3DatabaseDriver = sqlite3DatabaseDriver; exports.sqlite3Pool = sqlite3Pool; exports.sqliteAlwaysNewConnectionPool = _chunkIYEHOE4Scjs.sqliteAlwaysNewConnectionPool; exports.sqliteAmbientClientConnection = _chunkIYEHOE4Scjs.sqliteAmbientClientConnection; exports.sqliteAmbientConnectionPool = _chunkIYEHOE4Scjs.sqliteAmbientConnectionPool; exports.sqliteClient = sqlite3Client; exports.sqliteClientConnection = _chunkIYEHOE4Scjs.sqliteClientConnection; exports.sqliteConnection = _chunkIYEHOE4Scjs.sqliteConnection; exports.sqliteExecute = _chunkIYEHOE4Scjs.sqliteExecute; exports.sqliteFormatter = _chunkIYEHOE4Scjs.sqliteFormatter; exports.sqlitePool = _chunkIYEHOE4Scjs.sqlitePool; exports.sqlitePoolClientConnection = _chunkIYEHOE4Scjs.sqlitePoolClientConnection; exports.sqliteSQLExecutor = _chunkIYEHOE4Scjs.sqliteSQLExecutor; exports.sqliteSingletonConnectionPool = _chunkIYEHOE4Scjs.sqliteSingletonConnectionPool; exports.sqliteTransaction = _chunkIYEHOE4Scjs.sqliteTransaction; exports.tableExists = _chunkIYEHOE4Scjs.tableExists; exports.tableExistsSQL = _chunkIYEHOE4Scjs.tableExistsSQL; exports.toSqlitePoolOptions = _chunkIYEHOE4Scjs.toSqlitePoolOptions; exports.transactionNestingCounter = _chunkIYEHOE4Scjs.transactionNestingCounter; exports.useSqlite3DatabaseDriver = useSqlite3DatabaseDriver;
369
+ //#endregion
370
+ //#region src/storage/sqlite/sqlite3/index.ts
371
+ const sqlite3Pool = (options) => {
372
+ if ("connection" in options && options.connection) return require_core$1.sqlitePool(require_core$1.toSqlitePoolOptions({
373
+ ...options,
374
+ driverType: SQLite3DriverType
375
+ }));
376
+ const sqliteConnectionFactory = (opts) => sqlite3Connection({
377
+ ...opts,
378
+ serializer: options.serializer ?? require_core.JSONSerializer
379
+ });
380
+ if (require_core$1.isInMemoryDatabase(options) || "client" in options && Boolean(options.client) || options.singleton === true) return sqlite3SingletonPool({
381
+ driverType: SQLite3DriverType,
382
+ getConnection: () => sqliteConnectionFactory(options)
383
+ });
384
+ const readerPoolSize = options.readerPoolSize;
385
+ return sqliteDualConnectionPool({
386
+ driverType: SQLite3DriverType,
387
+ sqliteConnectionFactory,
388
+ connectionOptions: options,
389
+ ...readerPoolSize !== void 0 ? { readerPoolSize } : {}
390
+ });
391
+ };
392
+ const tryParseConnectionString = (connectionString) => {
393
+ try {
394
+ return require_core$1.SQLiteConnectionString(connectionString);
395
+ } catch {
396
+ return null;
397
+ }
398
+ };
399
+ const sqlite3DumboDriver = {
400
+ driverType: SQLite3DriverType,
401
+ createPool: (options) => sqlite3Pool(options),
402
+ sqlFormatter: require_core$1.sqliteFormatter,
403
+ defaultMigratorOptions: require_core$1.DefaultSQLiteMigratorOptions,
404
+ canHandle: require_core.canHandleDriverWithConnectionString(SQLite3DriverType, tryParseConnectionString),
405
+ databaseMetadata: require_sqliteMetadata.sqliteMetadata
406
+ };
407
+ const useSqlite3DumboDriver = () => {
408
+ require_core.dumboDatabaseDriverRegistry.register(SQLite3DriverType, sqlite3DumboDriver);
409
+ };
410
+ useSqlite3DumboDriver();
411
+
412
+ //#endregion
413
+ exports.DEFAULT_SQLITE_PRAGMA_OPTIONS = require_core$1.DEFAULT_SQLITE_PRAGMA_OPTIONS;
414
+ exports.DefaultSQLiteMigratorOptions = require_core$1.DefaultSQLiteMigratorOptions;
415
+ exports.InMemorySQLiteDatabase = require_core$1.InMemorySQLiteDatabase;
416
+ exports.SQLite3DriverType = SQLite3DriverType;
417
+ exports.SQLiteConnectionString = require_core$1.SQLiteConnectionString;
418
+ exports.SQLiteDatabaseName = require_core$1.SQLiteDatabaseName;
419
+ exports.checkConnection = checkConnection;
420
+ exports.defaultSQLiteDatabase = require_sqliteMetadata.defaultSQLiteDatabase;
421
+ exports.isInMemoryDatabase = require_core$1.isInMemoryDatabase;
422
+ exports.isSQLiteError = require_core$1.isSQLiteError;
423
+ exports.mapSqliteError = require_core$1.mapSqliteError;
424
+ exports.parsePragmasFromConnectionString = require_core$1.parsePragmasFromConnectionString;
425
+ exports.sqlite3Client = sqlite3Client;
426
+ exports.sqlite3Connection = sqlite3Connection;
427
+ exports.sqlite3DumboDriver = sqlite3DumboDriver;
428
+ exports.sqlite3Pool = sqlite3Pool;
429
+ exports.sqliteAlwaysNewConnectionPool = require_core$1.sqliteAlwaysNewConnectionPool;
430
+ exports.sqliteAmbientClientConnection = require_core$1.sqliteAmbientClientConnection;
431
+ exports.sqliteAmbientConnectionPool = require_core$1.sqliteAmbientConnectionPool;
432
+ exports.sqliteClientConnection = require_core$1.sqliteClientConnection;
433
+ exports.sqliteConnection = require_core$1.sqliteConnection;
434
+ exports.sqliteExecute = require_core$1.sqliteExecute;
435
+ exports.sqliteFormatter = require_core$1.sqliteFormatter;
436
+ exports.sqliteMetadata = require_sqliteMetadata.sqliteMetadata;
437
+ exports.sqlitePool = require_core$1.sqlitePool;
438
+ exports.sqlitePoolClientConnection = require_core$1.sqlitePoolClientConnection;
439
+ exports.sqliteSQLExecutor = require_core$1.sqliteSQLExecutor;
440
+ exports.sqliteSingletonConnectionPool = require_core$1.sqliteSingletonConnectionPool;
441
+ exports.sqliteTransaction = require_core$1.sqliteTransaction;
442
+ exports.tableExists = require_sqliteMetadata.tableExists;
443
+ exports.toSqlitePoolOptions = require_core$1.toSqlitePoolOptions;
444
+ exports.transactionNestingCounter = require_core$1.transactionNestingCounter;
445
+ exports.useSqlite3DumboDriver = useSqlite3DumboDriver;
282
446
  //# sourceMappingURL=sqlite3.cjs.map