@event-driven-io/dumbo 0.13.0-beta.35 → 0.13.0-beta.37

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 +375 -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 +339 -434
  6. package/dist/cloudflare.js.map +1 -1
  7. package/dist/core-BG__WVn6.js +2262 -0
  8. package/dist/core-BG__WVn6.js.map +1 -0
  9. package/dist/core-BchvTX3G.js +379 -0
  10. package/dist/core-BchvTX3G.js.map +1 -0
  11. package/dist/core-CWZb0zOY.cjs +588 -0
  12. package/dist/core-CWZb0zOY.cjs.map +1 -0
  13. package/dist/core-D-smW7cm.cjs +3243 -0
  14. package/dist/core-D-smW7cm.cjs.map +1 -0
  15. package/dist/core-DXCRR5A9.cjs +450 -0
  16. package/dist/core-DXCRR5A9.cjs.map +1 -0
  17. package/dist/core-DlV8ua1P.js +451 -0
  18. package/dist/core-DlV8ua1P.js.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-BgFHGsuP.d.ts +186 -0
  22. package/dist/index-DaP2fTEX.d.ts +67 -0
  23. package/dist/index-N2ly5shv.d.cts +186 -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-BTz6vdwE.js +65 -0
  40. package/dist/postgreSQLMetadata-BTz6vdwE.js.map +1 -0
  41. package/dist/postgreSQLMetadata-WGXySO7a.cjs +118 -0
  42. package/dist/postgreSQLMetadata-WGXySO7a.cjs.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 +432 -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 +396 -378
  56. package/dist/sqlite3.js.map +1 -1
  57. package/dist/sqliteMetadata-7qBjsMBN.js +29 -0
  58. package/dist/sqliteMetadata-7qBjsMBN.js.map +1 -0
  59. package/dist/sqliteMetadata-PJTRPIZ1.cjs +46 -0
  60. package/dist/sqliteMetadata-PJTRPIZ1.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
package/dist/sqlite3.cjs CHANGED
@@ -1,394 +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 _chunkJIZGCEPEcjs = require('./chunk-JIZGCEPE.cjs');
26
-
27
-
28
-
29
-
30
- var _chunkRQ3KKMTPcjs = require('./chunk-RQ3KKMTP.cjs');
31
-
32
-
33
-
34
-
35
-
36
-
37
- var _chunk4MMMEDQ7cjs = require('./chunk-4MMMEDQ7.cjs');
38
-
39
- // src/storage/sqlite/sqlite3/connections/connection.ts
40
- var _sqlite3 = require('sqlite3'); var _sqlite32 = _interopRequireDefault(_sqlite3);
41
-
42
- // src/storage/sqlite/core/connections/pragmas.ts
43
- var mergePragmaOptions = (connectionString, userOptions) => {
44
- const connectionStringPragmas = _chunkJIZGCEPEcjs.parsePragmasFromConnectionString.call(void 0, connectionString);
45
- return {
46
- ..._chunkJIZGCEPEcjs.DEFAULT_SQLITE_PRAGMA_OPTIONS,
47
- ...connectionStringPragmas,
48
- ...userOptions
49
- };
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_core = require('./core-D-smW7cm.cjs');
3
+ const require_sqliteMetadata = require('./sqliteMetadata-PJTRPIZ1.cjs');
4
+ const require_core$1 = require('./core-CWZb0zOY.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
+ };
50
18
  };
51
- var buildConnectionPragmaStatements = (pragmas) => [
52
- // busy_timeout FIRST - enables waiting on locks for subsequent operations
53
- { pragma: "busy_timeout", value: pragmas.busy_timeout },
54
- { pragma: "synchronous", value: pragmas.synchronous },
55
- { pragma: "cache_size", value: pragmas.cache_size },
56
- { pragma: "foreign_keys", value: pragmas.foreign_keys ? "ON" : "OFF" },
57
- { pragma: "temp_store", value: pragmas.temp_store },
58
- ...pragmas.mmap_size !== void 0 ? [{ pragma: "mmap_size", value: pragmas.mmap_size }] : []
59
- ];
60
- var buildDatabasePragmaStatements = (pragmas) => [
61
- { pragma: "journal_mode", value: pragmas.journal_mode }
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
+ }] : []
62
44
  ];
63
-
64
- // src/storage/sqlite/sqlite3/connections/connection.ts
65
- var SQLite3DriverType = "SQLite:sqlite3";
66
- var hasReturningClause = (sql) => /\bRETURNING\b/i.test(sql);
67
- var applyPragma = (database, pragma, value) => {
68
- return new Promise((resolve, reject) => {
69
- database.run(`PRAGMA ${pragma} = ${value};`, (err) => {
70
- if (err) reject(err);
71
- else resolve();
72
- });
73
- });
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
+ });
74
61
  };
75
- var queryPragma = (database, pragma) => new Promise((resolve, reject) => {
76
- database.get(
77
- `PRAGMA ${pragma};`,
78
- (err, row) => {
79
- if (err) reject(err);
80
- else resolve(_nullishCoalesce(_optionalChain([row, 'optionalAccess', _ => _[pragma]]), () => ( "")));
81
- }
82
- );
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
+ });
83
67
  });
84
- var applyPragmas = (database, pragmas) => pragmas.reduce(
85
- (promise, { pragma, value }) => promise.then(() => applyPragma(database, pragma, value)),
86
- Promise.resolve()
87
- );
88
- var sqlite3Client = (options) => {
89
- let db;
90
- let isClosed = false;
91
- const { serializer } = options;
92
- const connectionString = _nullishCoalesce(_nullishCoalesce(options.fileName, () => ( options.connectionString)), () => ( _chunkJIZGCEPEcjs.InMemorySQLiteDatabase));
93
- const finalPragmas = mergePragmaOptions(
94
- String(connectionString),
95
- options.pragmaOptions
96
- );
97
- const connectionPragmas = buildConnectionPragmaStatements(finalPragmas);
98
- const connect = () => db ? Promise.resolve() : new Promise((resolve, reject) => {
99
- try {
100
- db = new _sqlite32.default.Database(
101
- connectionString,
102
- _sqlite32.default.OPEN_URI | _sqlite32.default.OPEN_READWRITE | _sqlite32.default.OPEN_CREATE,
103
- (err) => {
104
- if (err) {
105
- reject(err);
106
- return;
107
- }
108
- const busyTimeout = _nullishCoalesce(finalPragmas.busy_timeout, () => ( _chunkJIZGCEPEcjs.DEFAULT_SQLITE_PRAGMA_OPTIONS.busy_timeout));
109
- db.configure("busyTimeout", busyTimeout);
110
- applyPragmas(
111
- db,
112
- connectionPragmas.filter((p) => p.pragma !== "busy_timeout")
113
- ).then(async () => {
114
- if (options.skipDatabasePragmas) return;
115
- const databasePragmas = buildDatabasePragmaStatements(finalPragmas);
116
- for (const { pragma, value } of databasePragmas) {
117
- const current = await queryPragma(db, pragma);
118
- if (current.toUpperCase() !== String(value).toUpperCase()) {
119
- await applyPragma(db, pragma, value);
120
- }
121
- }
122
- }).then(() => resolve()).catch(reject);
123
- }
124
- );
125
- } catch (error) {
126
- reject(error);
127
- }
128
- });
129
- const executeQuery = (sql, params) => new Promise((resolve, reject) => {
130
- try {
131
- db.all(sql, _nullishCoalesce(params, () => ( [])), (err, result) => {
132
- if (err) {
133
- reject(err);
134
- return;
135
- }
136
- resolve(result);
137
- });
138
- } catch (error) {
139
- reject(error);
140
- }
141
- });
142
- const executeCommand = (sql, params, options2) => new Promise((resolve, reject) => {
143
- try {
144
- if (_optionalChain([options2, 'optionalAccess', _2 => _2.ignoreChangesCount]) === true) {
145
- db.run(
146
- sql,
147
- _nullishCoalesce(params, () => ( [])),
148
- function(err, rows) {
149
- if (err) {
150
- reject(err);
151
- return;
152
- }
153
- resolve({
154
- rowCount: 0,
155
- rows: _nullishCoalesce(rows, () => ( []))
156
- });
157
- }
158
- );
159
- return;
160
- }
161
- if (hasReturningClause(sql)) {
162
- db.all(sql, _nullishCoalesce(params, () => ( [])), (err, rows) => {
163
- if (err) return reject(err);
164
- resolve({ rowCount: rows.length, rows });
165
- });
166
- return;
167
- }
168
- db.serialize(() => {
169
- let hasFailed = false;
170
- let resultRows = [];
171
- db.all(sql, _nullishCoalesce(params, () => ( [])), (err, rows) => {
172
- if (err) {
173
- hasFailed = true;
174
- return reject(err);
175
- }
176
- resultRows = rows;
177
- });
178
- db.get(
179
- "SELECT changes() as changes",
180
- (err, row) => {
181
- if (hasFailed) return;
182
- if (err) return reject(err);
183
- resolve({
184
- rowCount: _nullishCoalesce(_optionalChain([row, 'optionalAccess', _3 => _3.changes]), () => ( 0)),
185
- rows: resultRows
186
- });
187
- }
188
- );
189
- });
190
- } catch (error) {
191
- reject(error);
192
- }
193
- });
194
- return {
195
- connect,
196
- close: async () => {
197
- if (isClosed) {
198
- return;
199
- }
200
- isClosed = true;
201
- if (db) {
202
- try {
203
- await new Promise((resolve, reject) => {
204
- db.close((err) => {
205
- if (err) {
206
- reject(err);
207
- return;
208
- }
209
- resolve();
210
- });
211
- });
212
- } catch (error) {
213
- throw _chunkJIZGCEPEcjs.mapSqliteError.call(void 0, error);
214
- }
215
- }
216
- },
217
- query: async (sql, _options) => {
218
- try {
219
- const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, {
220
- serializer
221
- });
222
- const result = await executeQuery(
223
- query,
224
- params
225
- );
226
- return { rowCount: result.length, rows: result };
227
- } catch (error) {
228
- throw _chunkJIZGCEPEcjs.mapSqliteError.call(void 0, error);
229
- }
230
- },
231
- batchQuery: async (sqls, _options) => {
232
- try {
233
- const results = [];
234
- for (const sql of sqls) {
235
- const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, {
236
- serializer
237
- });
238
- const result = await executeQuery(
239
- query,
240
- params
241
- );
242
- results.push({ rowCount: result.length, rows: result });
243
- }
244
- return results;
245
- } catch (error) {
246
- throw _chunkJIZGCEPEcjs.mapSqliteError.call(void 0, error);
247
- }
248
- },
249
- command: async (sql, options2) => {
250
- try {
251
- const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sql, {
252
- serializer
253
- });
254
- return await executeCommand(
255
- query,
256
- params,
257
- options2
258
- );
259
- } catch (error) {
260
- throw _chunkJIZGCEPEcjs.mapSqliteError.call(void 0, error);
261
- }
262
- },
263
- batchCommand: async (sqls, options2) => {
264
- try {
265
- const results = [];
266
- for (let i = 0; i < sqls.length; i++) {
267
- const { query, params } = _chunkJIZGCEPEcjs.sqliteFormatter.format(sqls[i], {
268
- serializer
269
- });
270
- const result = await executeCommand(
271
- query,
272
- params,
273
- options2
274
- );
275
- results.push(result);
276
- if (_optionalChain([options2, 'optionalAccess', _4 => _4.assertChanges]) && (_nullishCoalesce(result.rowCount, () => ( 0))) === 0) {
277
- throw new (0, _chunk4MMMEDQ7cjs.BatchCommandNoChangesError)(i);
278
- }
279
- }
280
- return results;
281
- } catch (error) {
282
- throw _chunkJIZGCEPEcjs.mapSqliteError.call(void 0, error);
283
- }
284
- }
285
- };
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
+ };
286
226
  };
287
- var checkConnection = async (fileName, serializer) => {
288
- const client = sqlite3Client({
289
- fileName,
290
- serializer
291
- });
292
- try {
293
- await client.query(_chunk4MMMEDQ7cjs.SQL`SELECT 1`);
294
- return { successful: true };
295
- } catch (error) {
296
- const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
297
- return {
298
- successful: false,
299
- errorType: code === "SQLITE_CANTOPEN" ? "ConnectionRefused" : code === "SQLITE_AUTH" ? "Authentication" : "Unknown",
300
- code,
301
- error
302
- };
303
- } finally {
304
- await client.close();
305
- }
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
+ }
306
246
  };
307
- var sqlite3Connection = (options) => _chunkJIZGCEPEcjs.sqliteConnection.call(void 0, {
308
- type: "Client",
309
- driverType: SQLite3DriverType,
310
- sqliteClientFactory: (connectionOptions) => {
311
- if ("client" in connectionOptions && connectionOptions.client) {
312
- return connectionOptions.client;
313
- }
314
- return sqlite3Client({
315
- ...connectionOptions,
316
- serializer: options.serializer
317
- });
318
- },
319
- connectionOptions: options,
320
- serializer: options.serializer
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
321
259
  });
322
260
 
323
- // src/storage/sqlite/sqlite3/index.ts
324
- var sqlite3Pool = (options) => _chunkJIZGCEPEcjs.sqlitePool.call(void 0,
325
- _chunkJIZGCEPEcjs.toSqlitePoolOptions.call(void 0, {
326
- ...options,
327
- driverType: SQLite3DriverType,
328
- ..."connection" in options ? {} : {
329
- connectionOptions: options,
330
- sqliteConnectionFactory: (opts) => sqlite3Connection({
331
- ...opts,
332
- serializer: _nullishCoalesce(options.serializer, () => ( _chunk4MMMEDQ7cjs.JSONSerializer))
333
- })
334
- }
335
- })
336
- );
337
- var tryParseConnectionString = (connectionString) => {
338
- try {
339
- return _chunkJIZGCEPEcjs.SQLiteConnectionString.call(void 0, connectionString);
340
- } catch (e) {
341
- return null;
342
- }
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
+ };
343
301
  };
344
- var sqlite3DumboDriver = {
345
- driverType: SQLite3DriverType,
346
- createPool: (options) => sqlite3Pool(options),
347
- sqlFormatter: _chunkJIZGCEPEcjs.sqliteFormatter,
348
- defaultMigratorOptions: _chunkJIZGCEPEcjs.DefaultSQLiteMigratorOptions,
349
- canHandle: _chunk4MMMEDQ7cjs.canHandleDriverWithConnectionString.call(void 0,
350
- SQLite3DriverType,
351
- tryParseConnectionString
352
- ),
353
- databaseMetadata: _chunkRQ3KKMTPcjs.sqliteMetadata
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
+ };
354
367
  };
355
- var useSqlite3DumboDriver = () => {
356
- _chunk4MMMEDQ7cjs.dumboDatabaseDriverRegistry.register(SQLite3DriverType, sqlite3DumboDriver);
368
+
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);
357
409
  };
358
410
  useSqlite3DumboDriver();
359
411
 
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
- exports.DEFAULT_SQLITE_PRAGMA_OPTIONS = _chunkJIZGCEPEcjs.DEFAULT_SQLITE_PRAGMA_OPTIONS; exports.DefaultSQLiteMigratorOptions = _chunkJIZGCEPEcjs.DefaultSQLiteMigratorOptions; exports.InMemorySQLiteDatabase = _chunkJIZGCEPEcjs.InMemorySQLiteDatabase; exports.SQLite3DriverType = SQLite3DriverType; exports.SQLiteConnectionString = _chunkJIZGCEPEcjs.SQLiteConnectionString; exports.SQLiteDatabaseName = _chunkJIZGCEPEcjs.SQLiteDatabaseName; exports.checkConnection = checkConnection; exports.defaultSQLiteDatabase = _chunkRQ3KKMTPcjs.defaultSQLiteDatabase; exports.isInMemoryDatabase = _chunkJIZGCEPEcjs.isInMemoryDatabase; exports.isSQLiteError = _chunkJIZGCEPEcjs.isSQLiteError; exports.mapSqliteError = _chunkJIZGCEPEcjs.mapSqliteError; exports.parsePragmasFromConnectionString = _chunkJIZGCEPEcjs.parsePragmasFromConnectionString; exports.sqlite3Client = sqlite3Client; exports.sqlite3Connection = sqlite3Connection; exports.sqlite3DumboDriver = sqlite3DumboDriver; exports.sqlite3Pool = sqlite3Pool; exports.sqliteAlwaysNewConnectionPool = _chunkJIZGCEPEcjs.sqliteAlwaysNewConnectionPool; exports.sqliteAmbientClientConnection = _chunkJIZGCEPEcjs.sqliteAmbientClientConnection; exports.sqliteAmbientConnectionPool = _chunkJIZGCEPEcjs.sqliteAmbientConnectionPool; exports.sqliteClientConnection = _chunkJIZGCEPEcjs.sqliteClientConnection; exports.sqliteConnection = _chunkJIZGCEPEcjs.sqliteConnection; exports.sqliteExecute = _chunkJIZGCEPEcjs.sqliteExecute; exports.sqliteFormatter = _chunkJIZGCEPEcjs.sqliteFormatter; exports.sqliteMetadata = _chunkRQ3KKMTPcjs.sqliteMetadata; exports.sqlitePool = _chunkJIZGCEPEcjs.sqlitePool; exports.sqlitePoolClientConnection = _chunkJIZGCEPEcjs.sqlitePoolClientConnection; exports.sqliteSQLExecutor = _chunkJIZGCEPEcjs.sqliteSQLExecutor; exports.sqliteSingletonConnectionPool = _chunkJIZGCEPEcjs.sqliteSingletonConnectionPool; exports.sqliteTransaction = _chunkJIZGCEPEcjs.sqliteTransaction; exports.tableExists = _chunkRQ3KKMTPcjs.tableExists; exports.toSqlitePoolOptions = _chunkJIZGCEPEcjs.toSqlitePoolOptions; exports.transactionNestingCounter = _chunkJIZGCEPEcjs.transactionNestingCounter; exports.useSqlite3DumboDriver = useSqlite3DumboDriver;
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;
394
446
  //# sourceMappingURL=sqlite3.cjs.map