@event-driven-io/dumbo 0.13.0-beta.35 → 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
package/dist/pg.js CHANGED
@@ -1,467 +1,356 @@
1
- import {
2
- AdvisoryLock,
3
- DefaultPostgreSQLMigratorOptions,
4
- PostgreSQLArrayProcessor,
5
- PostgreSQLDatabaseName,
6
- PostgreSQLExpandSQLInProcessor,
7
- acquireAdvisoryLock,
8
- advisoryLock,
9
- mapPostgresError,
10
- pgFormatter,
11
- postgreSQLColumnProcessors,
12
- releaseAdvisoryLock,
13
- tryAcquireAdvisoryLock
14
- } from "./chunk-Y5TD53QE.js";
15
- import {
16
- PostgreSQLConnectionString,
17
- defaultPostgreSQLConnectionString,
18
- defaultPostgreSqlDatabase,
19
- functionExists,
20
- functionExistsSQL,
21
- parseDatabaseName,
22
- postgreSQLMetadata,
23
- tableExists,
24
- tableExistsSQL
25
- } from "./chunk-33P5766L.js";
26
- import {
27
- BatchCommandNoChangesError,
28
- JSONSerializer,
29
- canHandleDriverWithConnectionString,
30
- createAmbientConnectionPool,
31
- createConnection,
32
- createConnectionPool,
33
- dumboDatabaseDriverRegistry,
34
- mapSQLQueryResult,
35
- sqlExecutor,
36
- tracer
37
- } from "./chunk-H2JBS7HM.js";
38
-
39
- // src/storage/postgresql/pg/connections/connection.ts
40
- import pg2 from "pg";
41
-
42
- // src/storage/postgresql/pg/execute/execute.ts
1
+ import { Dn as canHandleDriverWithConnectionString, On as dumboDatabaseDriverRegistry, T as sqlExecutor, _ as BatchCommandNoChangesError, i as createConnectionPool, l as createConnection, n as createAmbientConnectionPool, rn as JSONSerializer, rt as tracer, w as mapSQLQueryResult } from "./core-DDo4m0Z_.js";
2
+ import { a as tableExists, c as defaultPostgreSQLConnectionString, i as functionExistsSQL, l as parseDatabaseName, n as defaultPostgreSqlDatabase, o as tableExistsSQL, r as functionExists, s as PostgreSQLConnectionString, t as postgreSQLMetadata } from "./postgreSQLMetadata-zMq8yJo_.js";
3
+ import { a as PostgreSQLExpandSQLInProcessor, c as acquireAdvisoryLock, d as tryAcquireAdvisoryLock, f as mapPostgresError, i as PostgreSQLArrayProcessor, l as advisoryLock, n as pgFormatter, o as DefaultPostgreSQLMigratorOptions, r as postgreSQLColumnProcessors, s as AdvisoryLock, t as PostgreSQLDatabaseName, u as releaseAdvisoryLock } from "./core-Bf2ujUFy.js";
43
4
  import pg from "pg";
44
- var isPgNativePool = (poolOrClient) => {
45
- return poolOrClient instanceof pg.Pool;
5
+
6
+ //#region src/storage/postgresql/pg/execute/execute.ts
7
+ const isPgNativePool = (poolOrClient) => {
8
+ return poolOrClient instanceof pg.Pool;
46
9
  };
47
- var isPgClient = (poolOrClient) => poolOrClient instanceof pg.Client;
48
- var isPgPoolClient = (poolOrClient) => "release" in poolOrClient && typeof poolOrClient.release === "function";
49
- var pgExecute = async (poolOrClient, handle) => {
50
- const client = isPgNativePool(poolOrClient) ? await poolOrClient.connect() : poolOrClient;
51
- try {
52
- return await handle(client);
53
- } finally {
54
- if (isPgNativePool(poolOrClient) && isPgPoolClient(client))
55
- client.release();
56
- }
10
+ const isPgClient = (poolOrClient) => poolOrClient instanceof pg.Client;
11
+ const isPgPoolClient = (poolOrClient) => "release" in poolOrClient && typeof poolOrClient.release === "function";
12
+ const pgExecute = async (poolOrClient, handle) => {
13
+ const client = isPgNativePool(poolOrClient) ? await poolOrClient.connect() : poolOrClient;
14
+ try {
15
+ return await handle(client);
16
+ } finally {
17
+ if (isPgNativePool(poolOrClient) && isPgPoolClient(client)) client.release();
18
+ }
57
19
  };
58
- var pgSQLExecutor = ({
59
- serializer
60
- }) => ({
61
- driverType: PgDriverType,
62
- query: async (client, sql, options) => {
63
- const results = await batchQuery(
64
- client,
65
- [sql],
66
- serializer,
67
- options
68
- );
69
- return results[0];
70
- },
71
- batchQuery: (client, sqls, options) => batchQuery(client, sqls, serializer, options),
72
- command: async (client, sql, options) => {
73
- const results = await batchCommand(
74
- client,
75
- [sql],
76
- serializer,
77
- options
78
- );
79
- return results[0];
80
- },
81
- batchCommand: (client, sqls, options) => batchCommand(client, sqls, serializer, options),
82
- formatter: pgFormatter
20
+ const pgSQLExecutor = ({ serializer }) => ({
21
+ driverType: PgDriverType,
22
+ query: async (client, sql, options) => {
23
+ return (await batchQuery(client, [sql], serializer, options))[0];
24
+ },
25
+ batchQuery: (client, sqls, options) => batchQuery(client, sqls, serializer, options),
26
+ command: async (client, sql, options) => {
27
+ return (await batchCommand(client, [sql], serializer, options))[0];
28
+ },
29
+ batchCommand: (client, sqls, options) => batchCommand(client, sqls, serializer, options),
30
+ formatter: pgFormatter
83
31
  });
84
32
  async function batchQuery(client, sqls, serializer, options) {
85
- const results = Array(
86
- sqls.length
87
- );
88
- if (options?.timeoutMs) {
89
- await client.query(`SET statement_timeout = ${options.timeoutMs}`);
90
- }
91
- for (let i = 0; i < sqls.length; i++) {
92
- const { query, params } = pgFormatter.format(sqls[i], { serializer });
93
- tracer.info("db:sql:query", {
94
- query,
95
- params,
96
- debugSQL: pgFormatter.describe(sqls[i], { serializer })
97
- });
98
- try {
99
- let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
100
- if (options?.mapping) {
101
- result = {
102
- ...result,
103
- rows: result.rows.map(
104
- (row) => mapSQLQueryResult(row, options.mapping)
105
- )
106
- };
107
- }
108
- results[i] = { rowCount: result.rowCount, rows: result.rows };
109
- } catch (error) {
110
- tracer.error("db:sql:batch_query:execute:error", { error });
111
- throw mapPostgresError(error);
112
- }
113
- }
114
- return results;
33
+ const results = Array(sqls.length);
34
+ if (options?.timeoutMs) await client.query(`SET statement_timeout = ${options.timeoutMs}`);
35
+ for (let i = 0; i < sqls.length; i++) {
36
+ const { query, params } = pgFormatter.format(sqls[i], { serializer });
37
+ tracer.info("db:sql:query", {
38
+ query,
39
+ params,
40
+ debugSQL: pgFormatter.describe(sqls[i], { serializer })
41
+ });
42
+ try {
43
+ let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
44
+ if (options?.mapping) result = {
45
+ ...result,
46
+ rows: result.rows.map((row) => mapSQLQueryResult(row, options.mapping))
47
+ };
48
+ results[i] = {
49
+ rowCount: result.rowCount,
50
+ rows: result.rows
51
+ };
52
+ } catch (error) {
53
+ tracer.error("db:sql:batch_query:execute:error", { error });
54
+ throw mapPostgresError(error);
55
+ }
56
+ }
57
+ return results;
115
58
  }
116
59
  async function batchCommand(client, sqls, serializer, options) {
117
- const results = Array(
118
- sqls.length
119
- );
120
- if (options?.timeoutMs) {
121
- await client.query(`SET statement_timeout = ${options.timeoutMs}`);
122
- }
123
- for (let i = 0; i < sqls.length; i++) {
124
- const { query, params } = pgFormatter.format(sqls[i], { serializer });
125
- tracer.info("db:sql:command", {
126
- query,
127
- params,
128
- debugSQL: pgFormatter.describe(sqls[i], { serializer })
129
- });
130
- try {
131
- let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
132
- if (options?.mapping) {
133
- result = {
134
- ...result,
135
- rows: result.rows.map(
136
- (row) => mapSQLQueryResult(row, options.mapping)
137
- )
138
- };
139
- }
140
- results[i] = { rowCount: result.rowCount, rows: result.rows };
141
- if (options?.assertChanges && (results[i].rowCount ?? 0) === 0) {
142
- throw new BatchCommandNoChangesError(i);
143
- }
144
- } catch (error) {
145
- tracer.error("db:sql:batch_command:execute:error", { error });
146
- throw mapPostgresError(error);
147
- }
148
- }
149
- return results;
60
+ const results = Array(sqls.length);
61
+ if (options?.timeoutMs) await client.query(`SET statement_timeout = ${options.timeoutMs}`);
62
+ for (let i = 0; i < sqls.length; i++) {
63
+ const { query, params } = pgFormatter.format(sqls[i], { serializer });
64
+ tracer.info("db:sql:command", {
65
+ query,
66
+ params,
67
+ debugSQL: pgFormatter.describe(sqls[i], { serializer })
68
+ });
69
+ try {
70
+ let result = params.length > 0 ? await client.query(query, params) : await client.query(query);
71
+ if (options?.mapping) result = {
72
+ ...result,
73
+ rows: result.rows.map((row) => mapSQLQueryResult(row, options.mapping))
74
+ };
75
+ results[i] = {
76
+ rowCount: result.rowCount,
77
+ rows: result.rows
78
+ };
79
+ if (options?.assertChanges && (results[i].rowCount ?? 0) === 0) throw new BatchCommandNoChangesError(i);
80
+ } catch (error) {
81
+ tracer.error("db:sql:batch_command:execute:error", { error });
82
+ throw mapPostgresError(error);
83
+ }
84
+ }
85
+ return results;
150
86
  }
151
87
 
152
- // src/storage/postgresql/pg/connections/transaction.ts
153
- var pgTransaction = (connection, serializer) => (getClient, options) => ({
154
- connection: connection(),
155
- driverType: PgDriverType,
156
- begin: async () => {
157
- const client = await getClient;
158
- const parts = ["BEGIN"];
159
- if (options?.isolationLevel) {
160
- parts.push(`ISOLATION LEVEL ${options.isolationLevel}`);
161
- }
162
- if (options?.readonly) {
163
- parts.push("READ ONLY");
164
- }
165
- await client.query(parts.join(" "));
166
- },
167
- commit: async () => {
168
- const client = await getClient;
169
- try {
170
- await client.query("COMMIT");
171
- } finally {
172
- if (options?.close) await options?.close(client);
173
- }
174
- },
175
- rollback: async (error) => {
176
- const client = await getClient;
177
- try {
178
- await client.query("ROLLBACK");
179
- } finally {
180
- if (options?.close) await options?.close(client, error);
181
- }
182
- },
183
- execute: sqlExecutor(pgSQLExecutor({ serializer }), {
184
- connect: () => getClient
185
- }),
186
- _transactionOptions: options ?? {}
88
+ //#endregion
89
+ //#region src/storage/postgresql/pg/connections/transaction.ts
90
+ const pgTransaction = (connection, serializer) => (getClient, options) => ({
91
+ connection: connection(),
92
+ driverType: PgDriverType,
93
+ begin: async () => {
94
+ const client = await getClient;
95
+ const parts = ["BEGIN"];
96
+ if (options?.isolationLevel) parts.push(`ISOLATION LEVEL ${options.isolationLevel}`);
97
+ if (options?.readonly) parts.push("READ ONLY");
98
+ await client.query(parts.join(" "));
99
+ },
100
+ commit: async () => {
101
+ const client = await getClient;
102
+ try {
103
+ await client.query("COMMIT");
104
+ } finally {
105
+ if (options?.close) await options?.close(client);
106
+ }
107
+ },
108
+ rollback: async (error) => {
109
+ const client = await getClient;
110
+ try {
111
+ await client.query("ROLLBACK");
112
+ } finally {
113
+ if (options?.close) await options?.close(client, error);
114
+ }
115
+ },
116
+ execute: sqlExecutor(pgSQLExecutor({ serializer }), { connect: () => getClient }),
117
+ _transactionOptions: options ?? {}
187
118
  });
188
119
 
189
- // src/storage/postgresql/pg/connections/connection.ts
190
- var PgDriverType = "PostgreSQL:pg";
191
- var pgClientConnection = (options) => {
192
- const { connect, close } = options;
193
- return createConnection({
194
- driverType: PgDriverType,
195
- connect,
196
- close,
197
- initTransaction: (connection) => pgTransaction(connection, options.serializer),
198
- executor: pgSQLExecutor,
199
- serializer: options.serializer
200
- });
120
+ //#endregion
121
+ //#region src/storage/postgresql/pg/connections/connection.ts
122
+ const PgDriverType = "PostgreSQL:pg";
123
+ const pgClientConnection = (options) => {
124
+ const { connect, close } = options;
125
+ return createConnection({
126
+ driverType: PgDriverType,
127
+ connect,
128
+ close,
129
+ initTransaction: (connection) => pgTransaction(connection, options.serializer),
130
+ executor: pgSQLExecutor,
131
+ serializer: options.serializer
132
+ });
201
133
  };
202
- var pgPoolClientConnection = (options) => {
203
- const { connect, close } = options;
204
- return createConnection({
205
- driverType: PgDriverType,
206
- connect,
207
- close,
208
- initTransaction: (connection) => pgTransaction(connection, options.serializer),
209
- executor: pgSQLExecutor,
210
- serializer: options.serializer
211
- });
134
+ const pgPoolClientConnection = (options) => {
135
+ const { connect, close } = options;
136
+ return createConnection({
137
+ driverType: PgDriverType,
138
+ connect,
139
+ close,
140
+ initTransaction: (connection) => pgTransaction(connection, options.serializer),
141
+ executor: pgSQLExecutor,
142
+ serializer: options.serializer
143
+ });
212
144
  };
213
145
  function pgConnection(options) {
214
- return options.type === "Client" ? pgClientConnection(options) : pgPoolClientConnection(options);
146
+ return options.type === "Client" ? pgClientConnection(options) : pgPoolClientConnection(options);
215
147
  }
216
- var checkConnection = async (connectionString) => {
217
- const client = new pg2.Client({
218
- connectionString
219
- });
220
- try {
221
- await client.connect();
222
- return { successful: true };
223
- } catch (error) {
224
- const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
225
- return {
226
- successful: false,
227
- errorType: code === "ECONNREFUSED" ? "ConnectionRefused" : code === "28P01" ? "Authentication" : "Unknown",
228
- code,
229
- error
230
- };
231
- } finally {
232
- await client.end();
233
- }
148
+ const checkConnection = async (connectionString) => {
149
+ const client = new pg.Client({ connectionString });
150
+ try {
151
+ await client.connect();
152
+ return { successful: true };
153
+ } catch (error) {
154
+ const code = error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
155
+ return {
156
+ successful: false,
157
+ errorType: code === "ECONNREFUSED" ? "ConnectionRefused" : code === "28P01" ? "Authentication" : "Unknown",
158
+ code,
159
+ error
160
+ };
161
+ } finally {
162
+ await client.end();
163
+ }
234
164
  };
235
165
 
236
- // src/storage/postgresql/pg/connections/pool.ts
237
- import pg3 from "pg";
238
-
239
- // src/storage/postgresql/pg/serialization/index.ts
240
- var setPgTypeParser = (client, options) => {
241
- if (options?.parseBigInts === true)
242
- client.setTypeParser(20, (val) => BigInt(val));
243
- if (options?.serializer) {
244
- client.setTypeParser(3802, (val) => options.serializer.deserialize(val));
245
- client.setTypeParser(114, (val) => options.serializer.deserialize(val));
246
- }
166
+ //#endregion
167
+ //#region src/storage/postgresql/pg/serialization/index.ts
168
+ const setPgTypeParser = (client, options) => {
169
+ if (options?.parseBigInts === true) client.setTypeParser(20, (val) => BigInt(val));
170
+ if (options?.serializer) {
171
+ client.setTypeParser(3802, (val) => options.serializer.deserialize(val));
172
+ client.setTypeParser(114, (val) => options.serializer.deserialize(val));
173
+ }
247
174
  };
248
175
 
249
- // src/storage/postgresql/pg/connections/pool.ts
250
- var pgNativePool = (options) => {
251
- const { connectionString, database } = options;
252
- const pool = getPgPool({ connectionString, database });
253
- const getConnection = () => pgConnection({
254
- type: "PoolClient",
255
- connect: async () => {
256
- const client = await pool.connect();
257
- setPgTypeParser(client, {
258
- parseBigInts: true,
259
- serializer: options.serializer
260
- });
261
- return client;
262
- },
263
- close: (client) => Promise.resolve(client.release()),
264
- serializer: options.serializer
265
- });
266
- const open = () => Promise.resolve(getConnection());
267
- const close = () => endPgPool({ connectionString, database });
268
- return createConnectionPool({
269
- driverType: PgDriverType,
270
- connection: open,
271
- close,
272
- getConnection
273
- });
176
+ //#endregion
177
+ //#region src/storage/postgresql/pg/connections/pool.ts
178
+ const pgNativePool = (options) => {
179
+ const { connectionString, database } = options;
180
+ const pool = getPgPool({
181
+ connectionString,
182
+ database
183
+ });
184
+ const getConnection = () => pgConnection({
185
+ type: "PoolClient",
186
+ connect: async () => {
187
+ const client = await pool.connect();
188
+ setPgTypeParser(client, {
189
+ parseBigInts: true,
190
+ serializer: options.serializer
191
+ });
192
+ return client;
193
+ },
194
+ close: (client) => Promise.resolve(client.release()),
195
+ serializer: options.serializer
196
+ });
197
+ const open = () => Promise.resolve(getConnection());
198
+ const close = () => endPgPool({
199
+ connectionString,
200
+ database
201
+ });
202
+ return createConnectionPool({
203
+ driverType: PgDriverType,
204
+ connection: open,
205
+ close,
206
+ getConnection
207
+ });
274
208
  };
275
- var pgAmbientNativePool = (options) => {
276
- const { pool } = options;
277
- return createConnectionPool({
278
- driverType: PgDriverType,
279
- getConnection: () => pgConnection({
280
- type: "PoolClient",
281
- connect: () => pool.connect(),
282
- close: (client) => Promise.resolve(client.release()),
283
- serializer: options.serializer
284
- })
285
- });
209
+ const pgAmbientNativePool = (options) => {
210
+ const { pool } = options;
211
+ return createConnectionPool({
212
+ driverType: PgDriverType,
213
+ getConnection: () => pgConnection({
214
+ type: "PoolClient",
215
+ connect: () => pool.connect(),
216
+ close: (client) => Promise.resolve(client.release()),
217
+ serializer: options.serializer
218
+ })
219
+ });
286
220
  };
287
- var pgAmbientConnectionPool = (options) => {
288
- const { connection } = options;
289
- return createAmbientConnectionPool({
290
- driverType: PgDriverType,
291
- connection
292
- });
221
+ const pgAmbientConnectionPool = (options) => {
222
+ const { connection } = options;
223
+ return createAmbientConnectionPool({
224
+ driverType: PgDriverType,
225
+ connection
226
+ });
293
227
  };
294
- var pgClientPool = (options) => {
295
- const { connectionString, database } = options;
296
- return createConnectionPool({
297
- driverType: PgDriverType,
298
- getConnection: () => {
299
- const connect = async () => {
300
- const client = new pg3.Client({ connectionString, database });
301
- setPgTypeParser(client, {
302
- parseBigInts: true,
303
- serializer: options.serializer
304
- });
305
- await client.connect();
306
- return client;
307
- };
308
- return pgConnection({
309
- type: "Client",
310
- connect,
311
- close: (client) => client.end(),
312
- serializer: options.serializer
313
- });
314
- }
315
- });
228
+ const pgClientPool = (options) => {
229
+ const { connectionString, database } = options;
230
+ return createConnectionPool({
231
+ driverType: PgDriverType,
232
+ getConnection: () => {
233
+ const connect = async () => {
234
+ const client = new pg.Client({
235
+ connectionString,
236
+ database
237
+ });
238
+ setPgTypeParser(client, {
239
+ parseBigInts: true,
240
+ serializer: options.serializer
241
+ });
242
+ await client.connect();
243
+ return client;
244
+ };
245
+ return pgConnection({
246
+ type: "Client",
247
+ connect,
248
+ close: (client) => client.end(),
249
+ serializer: options.serializer
250
+ });
251
+ }
252
+ });
316
253
  };
317
- var pgAmbientClientPool = (options) => {
318
- const { client } = options;
319
- const getConnection = () => {
320
- const connect = () => Promise.resolve(client);
321
- return pgConnection({
322
- type: "Client",
323
- connect,
324
- close: () => Promise.resolve(),
325
- serializer: options.serializer
326
- });
327
- };
328
- const open = () => Promise.resolve(getConnection());
329
- const close = () => Promise.resolve();
330
- return createConnectionPool({
331
- driverType: PgDriverType,
332
- connection: open,
333
- close,
334
- getConnection
335
- });
254
+ const pgAmbientClientPool = (options) => {
255
+ const { client } = options;
256
+ const getConnection = () => {
257
+ const connect = () => Promise.resolve(client);
258
+ return pgConnection({
259
+ type: "Client",
260
+ connect,
261
+ close: () => Promise.resolve(),
262
+ serializer: options.serializer
263
+ });
264
+ };
265
+ const open = () => Promise.resolve(getConnection());
266
+ const close = () => Promise.resolve();
267
+ return createConnectionPool({
268
+ driverType: PgDriverType,
269
+ connection: open,
270
+ close,
271
+ getConnection
272
+ });
336
273
  };
337
274
  function pgPool(options) {
338
- const { connectionString, database } = options;
339
- const serializer = options.serialization?.serializer ?? JSONSerializer;
340
- if ("client" in options && options.client)
341
- return pgAmbientClientPool({ client: options.client, serializer });
342
- if ("connection" in options && options.connection)
343
- return pgAmbientConnectionPool({
344
- connection: options.connection
345
- });
346
- if ("pooled" in options && options.pooled === false)
347
- return pgClientPool({ connectionString, database, serializer });
348
- if ("pool" in options && options.pool)
349
- return pgAmbientNativePool({ pool: options.pool, serializer });
350
- return pgNativePool({
351
- connectionString,
352
- database,
353
- serializer
354
- });
275
+ const { connectionString, database } = options;
276
+ const serializer = options.serialization?.serializer ?? JSONSerializer;
277
+ if ("client" in options && options.client) return pgAmbientClientPool({
278
+ client: options.client,
279
+ serializer
280
+ });
281
+ if ("connection" in options && options.connection) return pgAmbientConnectionPool({ connection: options.connection });
282
+ if ("pooled" in options && options.pooled === false) return pgClientPool({
283
+ connectionString,
284
+ database,
285
+ serializer
286
+ });
287
+ if ("pool" in options && options.pool) return pgAmbientNativePool({
288
+ pool: options.pool,
289
+ serializer
290
+ });
291
+ return pgNativePool({
292
+ connectionString,
293
+ database,
294
+ serializer
295
+ });
355
296
  }
356
- var pools = /* @__PURE__ */ new Map();
357
- var usageCounter = /* @__PURE__ */ new Map();
358
- var getPgPool = (connectionStringOrOptions) => {
359
- const connectionString = typeof connectionStringOrOptions === "string" ? connectionStringOrOptions : connectionStringOrOptions.connectionString;
360
- const poolOptions = typeof connectionStringOrOptions === "string" ? { connectionString } : connectionStringOrOptions;
361
- const database = poolOptions.database ?? (poolOptions.connectionString ? parseDatabaseName(poolOptions.connectionString) ?? defaultPostgreSqlDatabase : void 0);
362
- const lookupKey = key(connectionString, database);
363
- updatePoolUsageCounter(lookupKey, 1);
364
- return pools.get(lookupKey) ?? pools.set(lookupKey, new pg3.Pool(poolOptions)).get(lookupKey);
297
+ const pools = /* @__PURE__ */ new Map();
298
+ const usageCounter = /* @__PURE__ */ new Map();
299
+ const getPgPool = (connectionStringOrOptions) => {
300
+ const connectionString = typeof connectionStringOrOptions === "string" ? connectionStringOrOptions : connectionStringOrOptions.connectionString;
301
+ const poolOptions = typeof connectionStringOrOptions === "string" ? { connectionString } : connectionStringOrOptions;
302
+ const lookupKey = key(connectionString, poolOptions.database ?? (poolOptions.connectionString ? parseDatabaseName(poolOptions.connectionString) ?? "postgres" : void 0));
303
+ updatePoolUsageCounter(lookupKey, 1);
304
+ return pools.get(lookupKey) ?? pools.set(lookupKey, new pg.Pool(poolOptions)).get(lookupKey);
365
305
  };
366
- var endPgPool = async ({
367
- connectionString,
368
- database,
369
- force
370
- }) => {
371
- database = database ?? parseDatabaseName(connectionString) ?? void 0;
372
- const lookupKey = key(connectionString, database);
373
- const pool = pools.get(lookupKey);
374
- if (pool && (updatePoolUsageCounter(lookupKey, -1) <= 0 || force === true)) {
375
- await onEndPool(lookupKey, pool);
376
- }
306
+ const endPgPool = async ({ connectionString, database, force }) => {
307
+ database = database ?? parseDatabaseName(connectionString) ?? void 0;
308
+ const lookupKey = key(connectionString, database);
309
+ const pool = pools.get(lookupKey);
310
+ if (pool && (updatePoolUsageCounter(lookupKey, -1) <= 0 || force === true)) await onEndPool(lookupKey, pool);
377
311
  };
378
- var onEndPool = async (lookupKey, pool) => {
379
- try {
380
- await pool.end();
381
- } catch (error) {
382
- tracer.error("connection-closing-error", { lookupKey, error });
383
- }
384
- pools.delete(lookupKey);
312
+ const onEndPool = async (lookupKey, pool) => {
313
+ try {
314
+ await pool.end();
315
+ } catch (error) {
316
+ tracer.error("connection-closing-error", {
317
+ lookupKey,
318
+ error
319
+ });
320
+ }
321
+ pools.delete(lookupKey);
385
322
  };
386
- var endAllPgPools = () => Promise.all(
387
- [...pools.entries()].map(([lookupKey, pool]) => onEndPool(lookupKey, pool))
388
- );
389
- var key = (connectionString, database) => `${connectionString}|${database ?? defaultPostgreSqlDatabase}`;
390
- var updatePoolUsageCounter = (lookupKey, by) => {
391
- const currentCounter = usageCounter.get(lookupKey) ?? 0;
392
- const newCounter = currentCounter + by;
393
- usageCounter.set(lookupKey, currentCounter + by);
394
- return newCounter;
323
+ const endAllPgPools = () => Promise.all([...pools.entries()].map(([lookupKey, pool]) => onEndPool(lookupKey, pool)));
324
+ const key = (connectionString, database) => `${connectionString}|${database ?? "postgres"}`;
325
+ const updatePoolUsageCounter = (lookupKey, by) => {
326
+ const currentCounter = usageCounter.get(lookupKey) ?? 0;
327
+ const newCounter = currentCounter + by;
328
+ usageCounter.set(lookupKey, currentCounter + by);
329
+ return newCounter;
395
330
  };
396
331
 
397
- // src/storage/postgresql/pg/index.ts
398
- var tryParseConnectionString = (connectionString) => {
399
- try {
400
- return PostgreSQLConnectionString(connectionString);
401
- } catch {
402
- return null;
403
- }
332
+ //#endregion
333
+ //#region src/storage/postgresql/pg/index.ts
334
+ const tryParseConnectionString = (connectionString) => {
335
+ try {
336
+ return PostgreSQLConnectionString(connectionString);
337
+ } catch {
338
+ return null;
339
+ }
404
340
  };
405
- var pgDumboDriver = {
406
- driverType: PgDriverType,
407
- createPool: (options) => pgPool(options),
408
- sqlFormatter: pgFormatter,
409
- defaultMigratorOptions: DefaultPostgreSQLMigratorOptions,
410
- canHandle: canHandleDriverWithConnectionString(
411
- PgDriverType,
412
- tryParseConnectionString
413
- ),
414
- databaseMetadata: postgreSQLMetadata
341
+ const pgDumboDriver = {
342
+ driverType: PgDriverType,
343
+ createPool: (options) => pgPool(options),
344
+ sqlFormatter: pgFormatter,
345
+ defaultMigratorOptions: DefaultPostgreSQLMigratorOptions,
346
+ canHandle: canHandleDriverWithConnectionString(PgDriverType, tryParseConnectionString),
347
+ databaseMetadata: postgreSQLMetadata
415
348
  };
416
- var usePgDumboDriver = () => {
417
- dumboDatabaseDriverRegistry.register(PgDriverType, pgDumboDriver);
349
+ const usePgDumboDriver = () => {
350
+ dumboDatabaseDriverRegistry.register(PgDriverType, pgDumboDriver);
418
351
  };
419
352
  usePgDumboDriver();
420
- export {
421
- AdvisoryLock,
422
- DefaultPostgreSQLMigratorOptions,
423
- PgDriverType,
424
- PostgreSQLArrayProcessor,
425
- PostgreSQLConnectionString,
426
- PostgreSQLDatabaseName,
427
- PostgreSQLExpandSQLInProcessor,
428
- acquireAdvisoryLock,
429
- advisoryLock,
430
- checkConnection,
431
- defaultPostgreSQLConnectionString,
432
- defaultPostgreSqlDatabase,
433
- endAllPgPools,
434
- endPgPool,
435
- functionExists,
436
- functionExistsSQL,
437
- getPgPool,
438
- isPgClient,
439
- isPgNativePool,
440
- isPgPoolClient,
441
- mapPostgresError,
442
- onEndPool,
443
- parseDatabaseName,
444
- pgAmbientClientPool,
445
- pgAmbientConnectionPool,
446
- pgAmbientNativePool,
447
- pgClientConnection,
448
- pgClientPool,
449
- pgConnection,
450
- pgDumboDriver,
451
- pgExecute,
452
- pgFormatter,
453
- pgNativePool,
454
- pgPool,
455
- pgPoolClientConnection,
456
- pgSQLExecutor,
457
- pgTransaction,
458
- postgreSQLColumnProcessors,
459
- postgreSQLMetadata,
460
- releaseAdvisoryLock,
461
- setPgTypeParser,
462
- tableExists,
463
- tableExistsSQL,
464
- tryAcquireAdvisoryLock,
465
- usePgDumboDriver
466
- };
353
+
354
+ //#endregion
355
+ export { AdvisoryLock, DefaultPostgreSQLMigratorOptions, PgDriverType, PostgreSQLArrayProcessor, PostgreSQLConnectionString, PostgreSQLDatabaseName, PostgreSQLExpandSQLInProcessor, acquireAdvisoryLock, advisoryLock, checkConnection, defaultPostgreSQLConnectionString, defaultPostgreSqlDatabase, endAllPgPools, endPgPool, functionExists, functionExistsSQL, getPgPool, isPgClient, isPgNativePool, isPgPoolClient, mapPostgresError, onEndPool, parseDatabaseName, pgAmbientClientPool, pgAmbientConnectionPool, pgAmbientNativePool, pgClientConnection, pgClientPool, pgConnection, pgDumboDriver, pgExecute, pgFormatter, pgNativePool, pgPool, pgPoolClientConnection, pgSQLExecutor, pgTransaction, postgreSQLColumnProcessors, postgreSQLMetadata, releaseAdvisoryLock, setPgTypeParser, tableExists, tableExistsSQL, tryAcquireAdvisoryLock, usePgDumboDriver };
467
356
  //# sourceMappingURL=pg.js.map