@slonik/pg-driver 48.12.2 → 48.13.0
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.
- package/README.md +6 -9
- package/dist/factories/createPgDriverFactory.d.ts +1 -1
- package/dist/factories/createPgDriverFactory.d.ts.map +1 -1
- package/dist/factories/createPgDriverFactory.js +48 -50
- package/dist/factories/createPgDriverFactory.js.map +1 -1
- package/dist/factories/createPgDriverFactory.test.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +40 -44
- package/src/factories/createPgDriverFactory.test.ts +2 -2
- package/src/factories/createPgDriverFactory.ts +54 -73
- package/src/index.ts +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
# Slonik Driver for `pg`
|
|
2
2
|
|
|
3
3
|
```ts
|
|
4
|
-
import {
|
|
5
|
-
createPgDriverFactory,
|
|
6
|
-
DatabaseError,
|
|
7
|
-
} from '@slonik/pg-driver';
|
|
4
|
+
import { createPgDriverFactory, DatabaseError } from "@slonik/pg-driver";
|
|
8
5
|
```
|
|
9
6
|
|
|
10
7
|
## Error handling
|
|
@@ -12,7 +9,7 @@ import {
|
|
|
12
9
|
All Slonik errors extend from `SlonikError`. `SlonikError` uses `cause` property to store the original error, which might be a `DatabaseError` from `pg`. Example:
|
|
13
10
|
|
|
14
11
|
```ts
|
|
15
|
-
pool.on(
|
|
12
|
+
pool.on("error", (error) => {
|
|
16
13
|
const cause = error.cause;
|
|
17
14
|
|
|
18
15
|
if (cause instanceof DatabaseError) {
|
|
@@ -28,12 +25,12 @@ Example of handling all errors that could warrant a fatal error:
|
|
|
28
25
|
```ts
|
|
29
26
|
const fatalErrorClasses = [
|
|
30
27
|
// Connection Exception
|
|
31
|
-
|
|
28
|
+
"08",
|
|
32
29
|
// Invalid Authorization Specification
|
|
33
|
-
|
|
30
|
+
"28",
|
|
34
31
|
];
|
|
35
32
|
|
|
36
|
-
pool.on(
|
|
33
|
+
pool.on("error", (error) => {
|
|
37
34
|
if (error.cause instanceof DatabaseError) {
|
|
38
35
|
const classCode = error.cause.code.slice(0, 2);
|
|
39
36
|
|
|
@@ -42,4 +39,4 @@ pool.on('error', (error) => {
|
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
41
|
});
|
|
45
|
-
```
|
|
42
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPgDriverFactory.d.ts","sourceRoot":"","sources":["../../src/factories/createPgDriverFactory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"createPgDriverFactory.d.ts","sourceRoot":"","sources":["../../src/factories/createPgDriverFactory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,gBAAgB,CAAC;AA8OxB,eAAO,MAAM,qBAAqB,QAAO,aA8IxC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* eslint-disable canonical/id-match */
|
|
2
|
-
import { createDriverFactory } from
|
|
3
|
-
import { BackendTerminatedError, BackendTerminatedUnexpectedlyError, CheckExclusionConstraintViolationError, CheckIntegrityConstraintViolationError, ForeignKeyIntegrityConstraintViolationError, IdleTransactionTimeoutError, InputSyntaxError, InvalidInputError, NotNullIntegrityConstraintViolationError, StatementCancelledError, StatementTimeoutError, UnexpectedStateError, UniqueIntegrityConstraintViolationError, } from
|
|
4
|
-
import { parseDsn } from
|
|
5
|
-
import { Transform } from
|
|
6
|
-
import { Client } from
|
|
7
|
-
import QueryStream from
|
|
8
|
-
import { getTypeParser as getNativeTypeParser } from
|
|
9
|
-
import { parse as parseArray } from
|
|
2
|
+
import { createDriverFactory } from "@slonik/driver";
|
|
3
|
+
import { BackendTerminatedError, BackendTerminatedUnexpectedlyError, CheckExclusionConstraintViolationError, CheckIntegrityConstraintViolationError, ForeignKeyIntegrityConstraintViolationError, IdleTransactionTimeoutError, InputSyntaxError, InvalidInputError, NotNullIntegrityConstraintViolationError, StatementCancelledError, StatementTimeoutError, UnexpectedStateError, UniqueIntegrityConstraintViolationError, } from "@slonik/errors";
|
|
4
|
+
import { parseDsn } from "@slonik/utilities";
|
|
5
|
+
import { Transform } from "node:stream";
|
|
6
|
+
import { Client } from "pg";
|
|
7
|
+
import QueryStream from "pg-query-stream";
|
|
8
|
+
import { getTypeParser as getNativeTypeParser } from "pg-types";
|
|
9
|
+
import { parse as parseArray } from "postgres-array";
|
|
10
10
|
const createTypeOverrides = async (connection, typeParsers) => {
|
|
11
11
|
const typeNames = typeParsers.map((typeParser) => {
|
|
12
12
|
return typeParser.name;
|
|
@@ -55,43 +55,41 @@ const createClientConfiguration = (clientConfiguration) => {
|
|
|
55
55
|
password: connectionOptions.password,
|
|
56
56
|
port: connectionOptions.port,
|
|
57
57
|
// @ts-expect-error - https://github.com/brianc/node-postgres/pull/3214
|
|
58
|
-
queryMode:
|
|
58
|
+
queryMode: "extended",
|
|
59
59
|
ssl: false,
|
|
60
60
|
user: connectionOptions.username,
|
|
61
61
|
};
|
|
62
62
|
if (clientConfiguration.ssl) {
|
|
63
63
|
poolConfiguration.ssl = clientConfiguration.ssl;
|
|
64
64
|
}
|
|
65
|
-
else if (connectionOptions.sslMode ===
|
|
65
|
+
else if (connectionOptions.sslMode === "disable") {
|
|
66
66
|
poolConfiguration.ssl = false;
|
|
67
67
|
}
|
|
68
|
-
else if (connectionOptions.sslMode ===
|
|
68
|
+
else if (connectionOptions.sslMode === "require") {
|
|
69
69
|
poolConfiguration.ssl = true;
|
|
70
70
|
}
|
|
71
|
-
else if (connectionOptions.sslMode ===
|
|
71
|
+
else if (connectionOptions.sslMode === "no-verify") {
|
|
72
72
|
poolConfiguration.ssl = {
|
|
73
73
|
rejectUnauthorized: false,
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
if (clientConfiguration.connectionTimeout !==
|
|
76
|
+
if (clientConfiguration.connectionTimeout !== "DISABLE_TIMEOUT") {
|
|
77
77
|
if (clientConfiguration.connectionTimeout === 0) {
|
|
78
78
|
poolConfiguration.connectionTimeoutMillis = 1;
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
poolConfiguration.connectionTimeoutMillis =
|
|
82
|
-
clientConfiguration.connectionTimeout;
|
|
81
|
+
poolConfiguration.connectionTimeoutMillis = clientConfiguration.connectionTimeout;
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
|
-
if (clientConfiguration.statementTimeout !==
|
|
84
|
+
if (clientConfiguration.statementTimeout !== "DISABLE_TIMEOUT") {
|
|
86
85
|
if (clientConfiguration.statementTimeout === 0) {
|
|
87
86
|
poolConfiguration.statement_timeout = 1;
|
|
88
87
|
}
|
|
89
88
|
else {
|
|
90
|
-
poolConfiguration.statement_timeout =
|
|
91
|
-
clientConfiguration.statementTimeout;
|
|
89
|
+
poolConfiguration.statement_timeout = clientConfiguration.statementTimeout;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
|
-
if (clientConfiguration.idleInTransactionSessionTimeout !==
|
|
92
|
+
if (clientConfiguration.idleInTransactionSessionTimeout !== "DISABLE_TIMEOUT") {
|
|
95
93
|
if (clientConfiguration.idleInTransactionSessionTimeout === 0) {
|
|
96
94
|
poolConfiguration.idle_in_transaction_session_timeout = 1;
|
|
97
95
|
}
|
|
@@ -113,57 +111,57 @@ const queryTypeOverrides = async (pgClientConfiguration, driverConfiguration) =>
|
|
|
113
111
|
}
|
|
114
112
|
};
|
|
115
113
|
const isErrorWithCode = (error) => {
|
|
116
|
-
return
|
|
114
|
+
return "code" in error;
|
|
117
115
|
};
|
|
118
116
|
// query is not available for connection-level errors.
|
|
119
117
|
// TODO evaluate if we can remove query from the error object.
|
|
120
118
|
// I suspect we should not be even using InputSyntaxError as one of the error types.
|
|
121
119
|
// @see https://github.com/gajus/slonik/issues/557
|
|
122
120
|
const wrapError = (error, query) => {
|
|
123
|
-
if (error.message.toLowerCase().includes(
|
|
121
|
+
if (error.message.toLowerCase().includes("connection terminated unexpectedly")) {
|
|
124
122
|
return new BackendTerminatedUnexpectedlyError(error);
|
|
125
123
|
}
|
|
126
|
-
if (error.message.toLowerCase().includes(
|
|
124
|
+
if (error.message.toLowerCase().includes("connection terminated")) {
|
|
127
125
|
return new BackendTerminatedError(error);
|
|
128
126
|
}
|
|
129
127
|
if (!isErrorWithCode(error)) {
|
|
130
128
|
return error;
|
|
131
129
|
}
|
|
132
|
-
if (error.code ===
|
|
130
|
+
if (error.code === "22P02") {
|
|
133
131
|
return new InvalidInputError(error.message);
|
|
134
132
|
}
|
|
135
|
-
if (error.code ===
|
|
133
|
+
if (error.code === "25P03") {
|
|
136
134
|
return new IdleTransactionTimeoutError(error);
|
|
137
135
|
}
|
|
138
|
-
if (error.code ===
|
|
136
|
+
if (error.code === "57P01") {
|
|
139
137
|
return new BackendTerminatedError(error);
|
|
140
138
|
}
|
|
141
|
-
if (error.code ===
|
|
139
|
+
if (error.code === "57014" &&
|
|
142
140
|
// The code alone is not enough to distinguish between a statement timeout and a statement cancellation.
|
|
143
|
-
error.message.includes(
|
|
141
|
+
error.message.includes("canceling statement due to user request")) {
|
|
144
142
|
return new StatementCancelledError(error);
|
|
145
143
|
}
|
|
146
|
-
if (error.code ===
|
|
144
|
+
if (error.code === "57014") {
|
|
147
145
|
return new StatementTimeoutError(error);
|
|
148
146
|
}
|
|
149
|
-
if (error.code ===
|
|
147
|
+
if (error.code === "23502") {
|
|
150
148
|
return new NotNullIntegrityConstraintViolationError(error);
|
|
151
149
|
}
|
|
152
|
-
if (error.code ===
|
|
150
|
+
if (error.code === "23503") {
|
|
153
151
|
return new ForeignKeyIntegrityConstraintViolationError(error);
|
|
154
152
|
}
|
|
155
|
-
if (error.code ===
|
|
153
|
+
if (error.code === "23505") {
|
|
156
154
|
return new UniqueIntegrityConstraintViolationError(error);
|
|
157
155
|
}
|
|
158
|
-
if (error.code ===
|
|
156
|
+
if (error.code === "23P01") {
|
|
159
157
|
return new CheckExclusionConstraintViolationError(error);
|
|
160
158
|
}
|
|
161
|
-
if (error.code ===
|
|
159
|
+
if (error.code === "23514") {
|
|
162
160
|
return new CheckIntegrityConstraintViolationError(error);
|
|
163
161
|
}
|
|
164
|
-
if (error.code ===
|
|
162
|
+
if (error.code === "42601") {
|
|
165
163
|
if (!query) {
|
|
166
|
-
return new UnexpectedStateError(
|
|
164
|
+
return new UnexpectedStateError("Expected query to be provided");
|
|
167
165
|
}
|
|
168
166
|
return new InputSyntaxError(error, query);
|
|
169
167
|
}
|
|
@@ -182,32 +180,32 @@ export const createPgDriverFactory = () => {
|
|
|
182
180
|
// We will see this triggered when the connection is terminated, e.g.
|
|
183
181
|
// "terminates transactions that are idle beyond idleInTransactionSessionTimeout" test.
|
|
184
182
|
const onError = (error) => {
|
|
185
|
-
clientEventEmitter.emit(
|
|
183
|
+
clientEventEmitter.emit("error", wrapError(error, null));
|
|
186
184
|
};
|
|
187
185
|
const onNotice = (notice) => {
|
|
188
186
|
if (notice.message) {
|
|
189
|
-
clientEventEmitter.emit(
|
|
187
|
+
clientEventEmitter.emit("notice", {
|
|
190
188
|
message: notice.message,
|
|
191
189
|
});
|
|
192
190
|
}
|
|
193
191
|
};
|
|
194
|
-
client.on(
|
|
195
|
-
client.on(
|
|
192
|
+
client.on("error", onError);
|
|
193
|
+
client.on("notice", onNotice);
|
|
196
194
|
return {
|
|
197
195
|
connect: async () => {
|
|
198
196
|
try {
|
|
199
197
|
await client.connect();
|
|
200
198
|
}
|
|
201
199
|
catch (error) {
|
|
202
|
-
client.removeListener(
|
|
203
|
-
client.removeListener(
|
|
200
|
+
client.removeListener("error", onError);
|
|
201
|
+
client.removeListener("notice", onNotice);
|
|
204
202
|
throw error;
|
|
205
203
|
}
|
|
206
204
|
},
|
|
207
205
|
end: async () => {
|
|
208
206
|
await client.end();
|
|
209
|
-
client.removeListener(
|
|
210
|
-
client.removeListener(
|
|
207
|
+
client.removeListener("error", onError);
|
|
208
|
+
client.removeListener("notice", onNotice);
|
|
211
209
|
},
|
|
212
210
|
query: async (sql, values, queryOptions) => {
|
|
213
211
|
let result;
|
|
@@ -232,7 +230,7 @@ export const createPgDriverFactory = () => {
|
|
|
232
230
|
});
|
|
233
231
|
}
|
|
234
232
|
if (Array.isArray(result)) {
|
|
235
|
-
throw new InvalidInputError(
|
|
233
|
+
throw new InvalidInputError("Must not use multiple statements in a single query.");
|
|
236
234
|
}
|
|
237
235
|
return {
|
|
238
236
|
command: result.command,
|
|
@@ -260,15 +258,15 @@ export const createPgDriverFactory = () => {
|
|
|
260
258
|
};
|
|
261
259
|
});
|
|
262
260
|
};
|
|
263
|
-
client.connection.once(
|
|
264
|
-
stream.once(
|
|
265
|
-
client.connection.removeListener(
|
|
261
|
+
client.connection.once("rowDescription", onRowDescription);
|
|
262
|
+
stream.once("close", () => {
|
|
263
|
+
client.connection.removeListener("rowDescription", onRowDescription);
|
|
266
264
|
});
|
|
267
265
|
const transform = new Transform({
|
|
268
266
|
objectMode: true,
|
|
269
267
|
async transform(datum, enc, callback) {
|
|
270
268
|
if (!fields) {
|
|
271
|
-
callback(new Error(
|
|
269
|
+
callback(new Error("Fields not available"));
|
|
272
270
|
return;
|
|
273
271
|
}
|
|
274
272
|
this.push({
|
|
@@ -278,8 +276,8 @@ export const createPgDriverFactory = () => {
|
|
|
278
276
|
callback();
|
|
279
277
|
},
|
|
280
278
|
});
|
|
281
|
-
stream.on(
|
|
282
|
-
transform.emit(
|
|
279
|
+
stream.on("error", (error) => {
|
|
280
|
+
transform.emit("error", wrapError(error, {
|
|
283
281
|
sql,
|
|
284
282
|
values: values,
|
|
285
283
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPgDriverFactory.js","sourceRoot":"","sources":["../../src/factories/createPgDriverFactory.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAOrD,OAAO,EACL,sBAAsB,EACtB,kCAAkC,EAClC,sCAAsC,EACtC,sCAAsC,EACtC,2CAA2C,EAC3C,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,wCAAwC,EACxC,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,uCAAuC,GACxC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"createPgDriverFactory.js","sourceRoot":"","sources":["../../src/factories/createPgDriverFactory.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAOrD,OAAO,EACL,sBAAsB,EACtB,kCAAkC,EAClC,sCAAsC,EACtC,sCAAsC,EACtC,2CAA2C,EAC3C,2BAA2B,EAC3B,gBAAgB,EAChB,iBAAiB,EACjB,wCAAwC,EACxC,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,uCAAuC,GACxC,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,OAAO,WAAW,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,aAAa,IAAI,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAWrD,MAAM,mBAAmB,GAAG,KAAK,EAC/B,UAAkB,EAClB,WAAwC,EAChB,EAAE;IAC1B,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAC/C,OAAO,UAAU,CAAC,IAAI,CAAC;IACzB,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DriverFactory } from
|
|
2
|
-
export { DatabaseError } from
|
|
1
|
+
export { createPgDriverFactory } from "./factories/createPgDriverFactory.js";
|
|
2
|
+
export { DatabaseError } from "pg";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createPgDriverFactory } from
|
|
2
|
-
export { DatabaseError } from
|
|
1
|
+
export { createPgDriverFactory } from "./factories/createPgDriverFactory.js";
|
|
2
|
+
export { DatabaseError } from "pg";
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,73 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
+
"name": "@slonik/pg-driver",
|
|
3
|
+
"version": "48.13.0",
|
|
4
|
+
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"postgresql",
|
|
7
|
+
"promise",
|
|
8
|
+
"types"
|
|
9
|
+
],
|
|
10
|
+
"license": "BSD-3-Clause",
|
|
2
11
|
"author": {
|
|
3
|
-
"email": "gajus@gajus.com",
|
|
4
12
|
"name": "Gajus Kuizinas",
|
|
13
|
+
"email": "gajus@gajus.com",
|
|
5
14
|
"url": "http://gajus.com"
|
|
6
15
|
},
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
],
|
|
11
|
-
"files": [
|
|
12
|
-
"src/**/*.test.ts"
|
|
13
|
-
],
|
|
14
|
-
"nodeArguments": [
|
|
15
|
-
"--import=tsimp"
|
|
16
|
-
]
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/gajus/slonik"
|
|
17
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"./src",
|
|
22
|
+
"./dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
18
27
|
"dependencies": {
|
|
19
|
-
"@slonik/driver": "^48.
|
|
20
|
-
"@slonik/errors": "^48.
|
|
21
|
-
"@slonik/sql-tag": "^48.
|
|
22
|
-
"@slonik/types": "^48.
|
|
23
|
-
"@slonik/utilities": "^48.
|
|
28
|
+
"@slonik/driver": "^48.13.0",
|
|
29
|
+
"@slonik/errors": "^48.13.0",
|
|
30
|
+
"@slonik/sql-tag": "^48.13.0",
|
|
31
|
+
"@slonik/types": "^48.13.0",
|
|
32
|
+
"@slonik/utilities": "^48.13.0",
|
|
24
33
|
"pg": "^8.18.0",
|
|
25
34
|
"pg-query-stream": "^4.12.0",
|
|
26
35
|
"pg-types": "^4.1.0",
|
|
27
36
|
"postgres-array": "^3.0.4"
|
|
28
37
|
},
|
|
29
|
-
"description": "A Node.js PostgreSQL client with strict types, detailed logging and assertions.",
|
|
30
38
|
"devDependencies": {
|
|
31
39
|
"@types/node": "^24.10.13",
|
|
32
40
|
"@types/pg": "^8.16.0",
|
|
33
41
|
"ava": "^6.4.1",
|
|
34
42
|
"cspell": "^9.6.4",
|
|
35
|
-
"eslint": "9.39.2",
|
|
36
43
|
"tsimp": "^2.0.12",
|
|
37
|
-
"typescript": "^5.9.3"
|
|
38
|
-
"typescript-eslint": "^8.55.0",
|
|
39
|
-
"@slonik/eslint-config": "^48.12.2"
|
|
40
|
-
},
|
|
41
|
-
"engines": {
|
|
42
|
-
"node": ">=24"
|
|
44
|
+
"typescript": "^5.9.3"
|
|
43
45
|
},
|
|
44
|
-
"files": [
|
|
45
|
-
"./src",
|
|
46
|
-
"./dist"
|
|
47
|
-
],
|
|
48
|
-
"keywords": [
|
|
49
|
-
"postgresql",
|
|
50
|
-
"promise",
|
|
51
|
-
"types"
|
|
52
|
-
],
|
|
53
|
-
"license": "BSD-3-Clause",
|
|
54
|
-
"main": "./dist/index.js",
|
|
55
|
-
"name": "@slonik/pg-driver",
|
|
56
46
|
"peerDependencies": {
|
|
57
47
|
"zod": "^3.25 || ^4"
|
|
58
48
|
},
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
49
|
+
"ava": {
|
|
50
|
+
"extensions": [
|
|
51
|
+
"ts"
|
|
52
|
+
],
|
|
53
|
+
"files": [
|
|
54
|
+
"src/**/*.test.ts"
|
|
55
|
+
],
|
|
56
|
+
"nodeArguments": [
|
|
57
|
+
"--import=tsimp"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=24"
|
|
62
62
|
},
|
|
63
|
-
"type": "module",
|
|
64
|
-
"types": "./dist/index.d.ts",
|
|
65
|
-
"version": "48.12.2",
|
|
66
63
|
"scripts": {
|
|
67
64
|
"build": "rm -fr ./dist && tsc --project ./tsconfig.json",
|
|
68
|
-
"lint": "npm run lint:cspell && npm run lint:
|
|
65
|
+
"lint": "npm run lint:cspell && npm run lint:tsc",
|
|
69
66
|
"lint:cspell": "cspell . --no-progress --gitignore",
|
|
70
|
-
"lint:eslint": "eslint --cache ./src",
|
|
71
67
|
"lint:tsc": "tsc --noEmit",
|
|
72
68
|
"test": "ava --verbose --serial"
|
|
73
69
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* eslint-disable canonical/id-match */
|
|
2
2
|
|
|
3
|
-
import { createDriverFactory } from
|
|
3
|
+
import { createDriverFactory } from "@slonik/driver";
|
|
4
4
|
import type {
|
|
5
5
|
DriverCommand,
|
|
6
6
|
DriverConfiguration,
|
|
7
7
|
DriverFactory,
|
|
8
8
|
DriverTypeParser,
|
|
9
|
-
} from
|
|
9
|
+
} from "@slonik/driver";
|
|
10
10
|
import {
|
|
11
11
|
BackendTerminatedError,
|
|
12
12
|
BackendTerminatedUnexpectedlyError,
|
|
@@ -21,19 +21,16 @@ import {
|
|
|
21
21
|
StatementTimeoutError,
|
|
22
22
|
UnexpectedStateError,
|
|
23
23
|
UniqueIntegrityConstraintViolationError,
|
|
24
|
-
} from
|
|
25
|
-
import type { PrimitiveValueExpression } from
|
|
26
|
-
import type { Field, Query } from
|
|
27
|
-
import { parseDsn } from
|
|
28
|
-
import { Transform } from
|
|
29
|
-
import { Client } from
|
|
30
|
-
import type {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} from
|
|
34
|
-
import QueryStream from 'pg-query-stream';
|
|
35
|
-
import { getTypeParser as getNativeTypeParser } from 'pg-types';
|
|
36
|
-
import { parse as parseArray } from 'postgres-array';
|
|
24
|
+
} from "@slonik/errors";
|
|
25
|
+
import type { PrimitiveValueExpression } from "@slonik/sql-tag";
|
|
26
|
+
import type { Field, Query } from "@slonik/types";
|
|
27
|
+
import { parseDsn } from "@slonik/utilities";
|
|
28
|
+
import { Transform } from "node:stream";
|
|
29
|
+
import { Client } from "pg";
|
|
30
|
+
import type { DatabaseError, ClientConfig as NativePostgresClientConfiguration } from "pg";
|
|
31
|
+
import QueryStream from "pg-query-stream";
|
|
32
|
+
import { getTypeParser as getNativeTypeParser } from "pg-types";
|
|
33
|
+
import { parse as parseArray } from "postgres-array";
|
|
37
34
|
|
|
38
35
|
type PostgresType = {
|
|
39
36
|
oid: string;
|
|
@@ -112,44 +109,40 @@ const createClientConfiguration = (
|
|
|
112
109
|
password: connectionOptions.password,
|
|
113
110
|
port: connectionOptions.port,
|
|
114
111
|
// @ts-expect-error - https://github.com/brianc/node-postgres/pull/3214
|
|
115
|
-
queryMode:
|
|
112
|
+
queryMode: "extended",
|
|
116
113
|
ssl: false,
|
|
117
114
|
user: connectionOptions.username,
|
|
118
115
|
};
|
|
119
116
|
|
|
120
117
|
if (clientConfiguration.ssl) {
|
|
121
118
|
poolConfiguration.ssl = clientConfiguration.ssl;
|
|
122
|
-
} else if (connectionOptions.sslMode ===
|
|
119
|
+
} else if (connectionOptions.sslMode === "disable") {
|
|
123
120
|
poolConfiguration.ssl = false;
|
|
124
|
-
} else if (connectionOptions.sslMode ===
|
|
121
|
+
} else if (connectionOptions.sslMode === "require") {
|
|
125
122
|
poolConfiguration.ssl = true;
|
|
126
|
-
} else if (connectionOptions.sslMode ===
|
|
123
|
+
} else if (connectionOptions.sslMode === "no-verify") {
|
|
127
124
|
poolConfiguration.ssl = {
|
|
128
125
|
rejectUnauthorized: false,
|
|
129
126
|
};
|
|
130
127
|
}
|
|
131
128
|
|
|
132
|
-
if (clientConfiguration.connectionTimeout !==
|
|
129
|
+
if (clientConfiguration.connectionTimeout !== "DISABLE_TIMEOUT") {
|
|
133
130
|
if (clientConfiguration.connectionTimeout === 0) {
|
|
134
131
|
poolConfiguration.connectionTimeoutMillis = 1;
|
|
135
132
|
} else {
|
|
136
|
-
poolConfiguration.connectionTimeoutMillis =
|
|
137
|
-
clientConfiguration.connectionTimeout;
|
|
133
|
+
poolConfiguration.connectionTimeoutMillis = clientConfiguration.connectionTimeout;
|
|
138
134
|
}
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
if (clientConfiguration.statementTimeout !==
|
|
137
|
+
if (clientConfiguration.statementTimeout !== "DISABLE_TIMEOUT") {
|
|
142
138
|
if (clientConfiguration.statementTimeout === 0) {
|
|
143
139
|
poolConfiguration.statement_timeout = 1;
|
|
144
140
|
} else {
|
|
145
|
-
poolConfiguration.statement_timeout =
|
|
146
|
-
clientConfiguration.statementTimeout;
|
|
141
|
+
poolConfiguration.statement_timeout = clientConfiguration.statementTimeout;
|
|
147
142
|
}
|
|
148
143
|
}
|
|
149
144
|
|
|
150
|
-
if (
|
|
151
|
-
clientConfiguration.idleInTransactionSessionTimeout !== 'DISABLE_TIMEOUT'
|
|
152
|
-
) {
|
|
145
|
+
if (clientConfiguration.idleInTransactionSessionTimeout !== "DISABLE_TIMEOUT") {
|
|
153
146
|
if (clientConfiguration.idleInTransactionSessionTimeout === 0) {
|
|
154
147
|
poolConfiguration.idle_in_transaction_session_timeout = 1;
|
|
155
148
|
} else {
|
|
@@ -176,7 +169,7 @@ const queryTypeOverrides = async (
|
|
|
176
169
|
};
|
|
177
170
|
|
|
178
171
|
const isErrorWithCode = (error: Error): error is DatabaseError => {
|
|
179
|
-
return
|
|
172
|
+
return "code" in error;
|
|
180
173
|
};
|
|
181
174
|
|
|
182
175
|
// query is not available for connection-level errors.
|
|
@@ -184,13 +177,11 @@ const isErrorWithCode = (error: Error): error is DatabaseError => {
|
|
|
184
177
|
// I suspect we should not be even using InputSyntaxError as one of the error types.
|
|
185
178
|
// @see https://github.com/gajus/slonik/issues/557
|
|
186
179
|
const wrapError = (error: Error, query: null | Query) => {
|
|
187
|
-
if (
|
|
188
|
-
error.message.toLowerCase().includes('connection terminated unexpectedly')
|
|
189
|
-
) {
|
|
180
|
+
if (error.message.toLowerCase().includes("connection terminated unexpectedly")) {
|
|
190
181
|
return new BackendTerminatedUnexpectedlyError(error);
|
|
191
182
|
}
|
|
192
183
|
|
|
193
|
-
if (error.message.toLowerCase().includes(
|
|
184
|
+
if (error.message.toLowerCase().includes("connection terminated")) {
|
|
194
185
|
return new BackendTerminatedError(error);
|
|
195
186
|
}
|
|
196
187
|
|
|
@@ -198,53 +189,53 @@ const wrapError = (error: Error, query: null | Query) => {
|
|
|
198
189
|
return error;
|
|
199
190
|
}
|
|
200
191
|
|
|
201
|
-
if (error.code ===
|
|
192
|
+
if (error.code === "22P02") {
|
|
202
193
|
return new InvalidInputError(error.message);
|
|
203
194
|
}
|
|
204
195
|
|
|
205
|
-
if (error.code ===
|
|
196
|
+
if (error.code === "25P03") {
|
|
206
197
|
return new IdleTransactionTimeoutError(error);
|
|
207
198
|
}
|
|
208
199
|
|
|
209
|
-
if (error.code ===
|
|
200
|
+
if (error.code === "57P01") {
|
|
210
201
|
return new BackendTerminatedError(error);
|
|
211
202
|
}
|
|
212
203
|
|
|
213
204
|
if (
|
|
214
|
-
error.code ===
|
|
205
|
+
error.code === "57014" &&
|
|
215
206
|
// The code alone is not enough to distinguish between a statement timeout and a statement cancellation.
|
|
216
|
-
error.message.includes(
|
|
207
|
+
error.message.includes("canceling statement due to user request")
|
|
217
208
|
) {
|
|
218
209
|
return new StatementCancelledError(error);
|
|
219
210
|
}
|
|
220
211
|
|
|
221
|
-
if (error.code ===
|
|
212
|
+
if (error.code === "57014") {
|
|
222
213
|
return new StatementTimeoutError(error);
|
|
223
214
|
}
|
|
224
215
|
|
|
225
|
-
if (error.code ===
|
|
216
|
+
if (error.code === "23502") {
|
|
226
217
|
return new NotNullIntegrityConstraintViolationError(error);
|
|
227
218
|
}
|
|
228
219
|
|
|
229
|
-
if (error.code ===
|
|
220
|
+
if (error.code === "23503") {
|
|
230
221
|
return new ForeignKeyIntegrityConstraintViolationError(error);
|
|
231
222
|
}
|
|
232
223
|
|
|
233
|
-
if (error.code ===
|
|
224
|
+
if (error.code === "23505") {
|
|
234
225
|
return new UniqueIntegrityConstraintViolationError(error);
|
|
235
226
|
}
|
|
236
227
|
|
|
237
|
-
if (error.code ===
|
|
228
|
+
if (error.code === "23P01") {
|
|
238
229
|
return new CheckExclusionConstraintViolationError(error);
|
|
239
230
|
}
|
|
240
231
|
|
|
241
|
-
if (error.code ===
|
|
232
|
+
if (error.code === "23514") {
|
|
242
233
|
return new CheckIntegrityConstraintViolationError(error);
|
|
243
234
|
}
|
|
244
235
|
|
|
245
|
-
if (error.code ===
|
|
236
|
+
if (error.code === "42601") {
|
|
246
237
|
if (!query) {
|
|
247
|
-
return new UnexpectedStateError(
|
|
238
|
+
return new UnexpectedStateError("Expected query to be provided");
|
|
248
239
|
}
|
|
249
240
|
|
|
250
241
|
return new InputSyntaxError(error, query);
|
|
@@ -259,10 +250,7 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
259
250
|
|
|
260
251
|
// eslint-disable-next-line require-atomic-updates
|
|
261
252
|
clientConfiguration.types = {
|
|
262
|
-
getTypeParser: await queryTypeOverrides(
|
|
263
|
-
clientConfiguration,
|
|
264
|
-
driverConfiguration,
|
|
265
|
-
),
|
|
253
|
+
getTypeParser: await queryTypeOverrides(clientConfiguration, driverConfiguration),
|
|
266
254
|
};
|
|
267
255
|
|
|
268
256
|
return {
|
|
@@ -272,27 +260,27 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
272
260
|
// We will see this triggered when the connection is terminated, e.g.
|
|
273
261
|
// "terminates transactions that are idle beyond idleInTransactionSessionTimeout" test.
|
|
274
262
|
const onError = (error) => {
|
|
275
|
-
clientEventEmitter.emit(
|
|
263
|
+
clientEventEmitter.emit("error", wrapError(error, null));
|
|
276
264
|
};
|
|
277
265
|
|
|
278
266
|
const onNotice = (notice) => {
|
|
279
267
|
if (notice.message) {
|
|
280
|
-
clientEventEmitter.emit(
|
|
268
|
+
clientEventEmitter.emit("notice", {
|
|
281
269
|
message: notice.message,
|
|
282
270
|
});
|
|
283
271
|
}
|
|
284
272
|
};
|
|
285
273
|
|
|
286
|
-
client.on(
|
|
287
|
-
client.on(
|
|
274
|
+
client.on("error", onError);
|
|
275
|
+
client.on("notice", onNotice);
|
|
288
276
|
|
|
289
277
|
return {
|
|
290
278
|
connect: async () => {
|
|
291
279
|
try {
|
|
292
280
|
await client.connect();
|
|
293
281
|
} catch (error) {
|
|
294
|
-
client.removeListener(
|
|
295
|
-
client.removeListener(
|
|
282
|
+
client.removeListener("error", onError);
|
|
283
|
+
client.removeListener("notice", onNotice);
|
|
296
284
|
|
|
297
285
|
throw error;
|
|
298
286
|
}
|
|
@@ -300,8 +288,8 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
300
288
|
end: async () => {
|
|
301
289
|
await client.end();
|
|
302
290
|
|
|
303
|
-
client.removeListener(
|
|
304
|
-
client.removeListener(
|
|
291
|
+
client.removeListener("error", onError);
|
|
292
|
+
client.removeListener("notice", onNotice);
|
|
305
293
|
},
|
|
306
294
|
query: async (sql, values, queryOptions) => {
|
|
307
295
|
let result;
|
|
@@ -326,9 +314,7 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
326
314
|
}
|
|
327
315
|
|
|
328
316
|
if (Array.isArray(result)) {
|
|
329
|
-
throw new InvalidInputError(
|
|
330
|
-
'Must not use multiple statements in a single query.',
|
|
331
|
-
);
|
|
317
|
+
throw new InvalidInputError("Must not use multiple statements in a single query.");
|
|
332
318
|
}
|
|
333
319
|
|
|
334
320
|
return {
|
|
@@ -344,9 +330,7 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
344
330
|
};
|
|
345
331
|
},
|
|
346
332
|
stream: (sql, values) => {
|
|
347
|
-
const stream = client.query(
|
|
348
|
-
new QueryStream(sql, values as unknown[]),
|
|
349
|
-
);
|
|
333
|
+
const stream = client.query(new QueryStream(sql, values as unknown[]));
|
|
350
334
|
|
|
351
335
|
let fields: readonly Field[] = [];
|
|
352
336
|
|
|
@@ -362,20 +346,17 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
362
346
|
});
|
|
363
347
|
};
|
|
364
348
|
|
|
365
|
-
client.connection.once(
|
|
349
|
+
client.connection.once("rowDescription", onRowDescription);
|
|
366
350
|
|
|
367
|
-
stream.once(
|
|
368
|
-
client.connection.removeListener(
|
|
369
|
-
'rowDescription',
|
|
370
|
-
onRowDescription,
|
|
371
|
-
);
|
|
351
|
+
stream.once("close", () => {
|
|
352
|
+
client.connection.removeListener("rowDescription", onRowDescription);
|
|
372
353
|
});
|
|
373
354
|
|
|
374
355
|
const transform = new Transform({
|
|
375
356
|
objectMode: true,
|
|
376
357
|
async transform(datum, enc, callback) {
|
|
377
358
|
if (!fields) {
|
|
378
|
-
callback(new Error(
|
|
359
|
+
callback(new Error("Fields not available"));
|
|
379
360
|
|
|
380
361
|
return;
|
|
381
362
|
}
|
|
@@ -389,9 +370,9 @@ export const createPgDriverFactory = (): DriverFactory => {
|
|
|
389
370
|
},
|
|
390
371
|
});
|
|
391
372
|
|
|
392
|
-
stream.on(
|
|
373
|
+
stream.on("error", (error) => {
|
|
393
374
|
transform.emit(
|
|
394
|
-
|
|
375
|
+
"error",
|
|
395
376
|
wrapError(error, {
|
|
396
377
|
sql,
|
|
397
378
|
values: values as PrimitiveValueExpression[],
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createPgDriverFactory } from
|
|
2
|
-
export { DatabaseError } from
|
|
1
|
+
export { createPgDriverFactory } from "./factories/createPgDriverFactory.js";
|
|
2
|
+
export { DatabaseError } from "pg";
|