pg-promise 10.15.3 → 11.0.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 CHANGED
@@ -34,7 +34,6 @@ PostgreSQL interface for Node.js
34
34
  - [Configurable Transactions]
35
35
  - [Conditional Transactions]
36
36
  - [Library de-initialization]
37
- * [History](#history)
38
37
 
39
38
  ---
40
39
 
@@ -1030,15 +1029,6 @@ will be rejecting with [Error] = `Connection pool of the database object has bee
1030
1029
 
1031
1030
  See the relevant API: [pgp.end], [Database.$pool]
1032
1031
 
1033
- ### update
1034
-
1035
- Version 10.11.0 added support for connection option `allowExitOnIdle`, to let process exit when pool is idle.
1036
-
1037
- # History
1038
-
1039
- Although this project formally maintains a [CHANGELOG], for a short list of the top-level changes,
1040
- for detailed changes between versions you should see the corresponding release notes.
1041
-
1042
1032
  <!-- Internal Menu Links -->
1043
1033
 
1044
1034
  [Usage]:#usage
@@ -1131,6 +1121,6 @@ for detailed changes between versions you should see the corresponding release n
1131
1121
  [Bluebird]:https://github.com/petkaantonov/bluebird
1132
1122
  [SQL injection]:https://en.wikipedia.org/wiki/SQL_injection
1133
1123
  [Symbol]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
1134
- [idleTimeoutMillis]:https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js#L46
1135
- [connection pool]:https://github.com/brianc/node-pg-pool
1124
+ [idleTimeoutMillis]:https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js
1125
+ [connection pool]:https://github.com/brianc/node-postgres/tree/master/packages/pg-pool
1136
1126
  [Error]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
package/lib/database.js CHANGED
@@ -1608,15 +1608,8 @@ function Database(cn, dc, config) {
1608
1608
  }
1609
1609
  }
1610
1610
 
1611
- // lock all default properties to read-only,
1612
- // to prevent override by the client.
1613
- npm.utils.lock(obj, false, ctx.options);
1614
-
1615
- // extend the protocol;
1611
+ // extending the protocol;
1616
1612
  Events.extend(ctx.options, obj, ctx.dc);
1617
-
1618
- // freeze the protocol permanently;
1619
- npm.utils.lock(obj, true, ctx.options);
1620
1613
  }
1621
1614
 
1622
1615
  }
package/lib/events.js CHANGED
@@ -28,14 +28,16 @@ class Events {
28
28
  *
29
29
  * The library will suppress any error thrown by the handler and write it into the console.
30
30
  *
31
- * @param {external:Client} client
31
+ * @param {{}} e Event Properties
32
+ *
33
+ * @param {external:Client} e.client
32
34
  * $[pg.Client] object that represents the connection.
33
35
  *
34
- * @param {*} dc
36
+ * @param {*} e.dc
35
37
  * Database Context that was used when creating the database object (see {@link Database}).
36
38
  *
37
- * @param {number} useCount
38
- * Number of times the connection has been previously used, starting with 0 for a freshly
39
+ * @param {number} e.useCount
40
+ * Number of times the connection has been previously used, starting with 0, for a freshly
39
41
  * allocated physical connection.
40
42
  *
41
43
  * This parameter is always 0 for direct connections (created by calling {@link Database#connect Database.connect}
@@ -47,8 +49,8 @@ class Events {
47
49
  *
48
50
  * // pg-promise initialization options...
49
51
  *
50
- * connect(client, dc, useCount) {
51
- * const cp = client.connectionParameters;
52
+ * connect(e) {
53
+ * const cp = e.client.connectionParameters;
52
54
  * console.log('Connected to database:', cp.database);
53
55
  * }
54
56
  *
@@ -57,7 +59,7 @@ class Events {
57
59
  static connect(ctx, client, useCount) {
58
60
  if (typeof ctx.options.connect === `function`) {
59
61
  try {
60
- ctx.options.connect(client, ctx.dc, useCount);
62
+ ctx.options.connect({client, dc: ctx.dc, useCount});
61
63
  } catch (e) {
62
64
  // have to silence errors here;
63
65
  // cannot allow unhandled errors while connecting to the database,
@@ -77,9 +79,11 @@ class Events {
77
79
  *
78
80
  * The library will suppress any error thrown by the handler and write it into the console.
79
81
  *
80
- * @param {external:Client} client - $[pg.Client] object that represents connection with the database.
82
+ * @param {{}} e Event Properties
83
+ *
84
+ * @param {external:Client} e.client - $[pg.Client] object that represents connection with the database.
81
85
  *
82
- * @param {*} dc - Database Context that was used when creating the database object (see {@link Database}).
86
+ * @param {*} e.dc - Database Context that was used when creating the database object (see {@link Database}).
83
87
  *
84
88
  * @example
85
89
  *
@@ -87,8 +91,8 @@ class Events {
87
91
  *
88
92
  * // pg-promise initialization options...
89
93
  *
90
- * disconnect(client, dc) {
91
- * const cp = client.connectionParameters;
94
+ * disconnect(e) {
95
+ * const cp = e.client.connectionParameters;
92
96
  * console.log('Disconnecting from database:', cp.database);
93
97
  * }
94
98
  *
@@ -97,7 +101,7 @@ class Events {
97
101
  static disconnect(ctx, client) {
98
102
  if (typeof ctx.options.disconnect === `function`) {
99
103
  try {
100
- ctx.options.disconnect(client, ctx.dc);
104
+ ctx.options.disconnect({client, dc: ctx.dc});
101
105
  } catch (e) {
102
106
  // have to silence errors here;
103
107
  // cannot allow unhandled errors while disconnecting from the database,
@@ -161,18 +165,20 @@ class Events {
161
165
  * this event is called for every result that's returned. And for method {@link Database#stream Database.stream},
162
166
  * the event occurs for every record.
163
167
  *
164
- * @param {Array<Object>} data
168
+ * @param {{}} e Event Properties
169
+ *
170
+ * @param {Array<Object>} e.data
165
171
  * Array of received objects/rows.
166
172
  *
167
173
  * If any of those objects are modified during notification, the client will receive the modified data.
168
174
  *
169
- * @param {external:Result} result
175
+ * @param {external:Result} e.result
170
176
  * - Original $[Result] object, if the data is from a non-stream query, in which case `data = result.rows`.
171
177
  * For single-query requests, $[Result] object is extended with property `duration` - number of milliseconds
172
178
  * it took to send the query, execute it and get the result back.
173
179
  * - It is `undefined` when the data comes from a stream (method {@link Database#stream Database.stream}).
174
180
  *
175
- * @param {EventContext} e
181
+ * @param {EventContext} e.ctx
176
182
  * Event Context Object.
177
183
  *
178
184
  * @example
@@ -184,8 +190,8 @@ class Events {
184
190
  *
185
191
  * // pg-promise initialization options...
186
192
  *
187
- * receive(data, result, e) {
188
- * camelizeColumns(data);
193
+ * receive(e) {
194
+ * camelizeColumns(e.data);
189
195
  * }
190
196
  * };
191
197
  *
@@ -203,10 +209,10 @@ class Events {
203
209
  * }
204
210
  * }
205
211
  */
206
- static receive(options, data, result, context) {
212
+ static receive(options, data, result, ctx) {
207
213
  if (typeof options.receive === `function`) {
208
214
  try {
209
- options.receive(data, result, context);
215
+ options.receive({data, result, ctx});
210
216
  } catch (e) {
211
217
  // throwing an error during event 'receive'
212
218
  // will result in a reject for the request.
@@ -527,5 +533,4 @@ module.exports = {Events};
527
533
  * This property is always set for events {@link event:task task} and {@link event:transact transact}, while for events
528
534
  * {@link event:query query}, {@link event:receive receive} and {@link event:error error} it is only set when they occur
529
535
  * inside a task or transaction.
530
- *
531
536
  */
package/lib/formatting.js CHANGED
@@ -669,7 +669,7 @@ const $as = {
669
669
  * Converts an array of values into its PostgreSQL presentation as an Array-Type constructor string: `array[]`.
670
670
  *
671
671
  * Top-level empty arrays are formatted as literal `{}`, to avoid the necessity of explicit type casting,
672
- * as the server cannot automatically infer type of an empty non-literal array.
672
+ * as the server cannot automatically infer type of empty non-literal array.
673
673
  *
674
674
  * @param {Array|function} arr
675
675
  * Array to be converted, or a function that returns one.
@@ -11,7 +11,6 @@ const {Column} = require(`./column`);
11
11
  const {ColumnSet} = require(`./column-set`);
12
12
  const {TableName} = require(`./table-name`);
13
13
  const method = require(`./methods`);
14
- const utils = require(`../utils`);
15
14
 
16
15
  /**
17
16
  * @namespace helpers
@@ -68,6 +67,5 @@ module.exports = config => {
68
67
  ColumnSet,
69
68
  Column
70
69
  };
71
- utils.lock(res, true, config.options);
72
70
  return res;
73
71
  };
package/lib/index.js CHANGED
@@ -12,16 +12,17 @@ var v = process.versions.node.split(`.`),
12
12
  highVer = +v[0];
13
13
 
14
14
  // istanbul ignore next
15
- if (highVer < 12) {
15
+ if (highVer < 14) {
16
16
 
17
- // From pg-promise v10.15.0, the oldest supported Node.js is v12.0.0
17
+ // From pg-promise v11.0.0, the oldest supported Node.js is v14.0.0
18
18
 
19
+ // Node.js v12.0.0 was supported up to pg-promise v10.15.4
19
20
  // Node.js v8.0.0 was supported up to pg-promise v10.14.2
20
21
  // Node.js v7.6.0 was supported up to pg-promise v10.3.5
21
22
  // Node.js v4.5.0 was supported up to pg-promise v8.7.5
22
23
  // Node.js v0.10 was supported up to pg-promise v5.5.8
23
24
 
24
- throw new Error(`Minimum Node.js version supported by pg-promise is 12.0.0`);
25
+ throw new Error(`Minimum Node.js version supported by pg-promise is 14.0.0`);
25
26
  }
26
27
 
27
28
  module.exports = require(`./main`);
package/lib/main.js CHANGED
@@ -36,7 +36,7 @@ let originalClientConnect;
36
36
  * @module pg-promise
37
37
  *
38
38
  * @description
39
- * ## pg-promise v10.15
39
+ * ## pg-promise v11.0
40
40
  * All documentation here is for the latest official release only.
41
41
  *
42
42
  * ### Initialization Options
@@ -50,10 +50,10 @@ let originalClientConnect;
50
50
  * const pgp = require('pg-promise')(initOptions);
51
51
  * ```
52
52
  *
53
- * @param {{}} [options]
53
+ * @property {{}} [options]
54
54
  * Library Initialization Options.
55
55
  *
56
- * @param {boolean} [options.pgFormatting=false]
56
+ * @property {boolean} [options.pgFormatting=false]
57
57
  * Redirects all query formatting to the $[pg] driver.
58
58
  *
59
59
  * By default (`false`), the library uses its own advanced query-formatting engine.
@@ -63,13 +63,13 @@ let originalClientConnect;
63
63
  *
64
64
  * This option is dynamic (can be set before or after initialization).
65
65
  *
66
- * @param {boolean} [options.pgNative=false]
66
+ * @property {boolean} [options.pgNative=false]
67
67
  * Use $[Native Bindings]. Library $[pg-native] must be included and installed independently, or else there will
68
68
  * be an error thrown: {@link external:Error Error} = `Failed to initialize Native Bindings.`
69
69
  *
70
70
  * This is a static option (can only be set prior to initialization).
71
71
  *
72
- * @param {object|function} [options.promiseLib=Promise]
72
+ * @property {object|function} [options.promiseLib=Promise]
73
73
  * Overrides the default (ES6 Promise) promise library for its internal use.
74
74
  *
75
75
  * Example below sets to use $[Bluebird] - the best and recommended promise library. It is the fastest one,
@@ -88,20 +88,7 @@ let originalClientConnect;
88
88
  *
89
89
  * This is a static option (can only be set prior to initialization).
90
90
  *
91
- * @param {boolean} [options.noLocking=false]
92
- * Prevents protocol locking.
93
- *
94
- * By default, the library locks much of its protocol to read-only access, as a fool-proof mechanism.
95
- * Specifically for the {@link event:extend extend} event this serves as a protection against overriding existing
96
- * properties or trying to set them at the wrong time.
97
- *
98
- * If this provision gets in the way of using a mock-up framework for your tests, you can force
99
- * the library to deactivate most of the locks by setting `noLocking` = `true` within the options.
100
- *
101
- * This option is dynamic (can be set before or after initialization). However, changing it after the library's
102
- * initialization will not affect {@link Database} objects that have already been created.
103
- *
104
- * @param {boolean} [options.capSQL=false]
91
+ * @property {boolean} [options.capSQL=false]
105
92
  * Capitalizes any SQL generated by the library.
106
93
  *
107
94
  * By default, all internal SQL within the library is generated using the low case.
@@ -111,7 +98,7 @@ let originalClientConnect;
111
98
  *
112
99
  * This option is dynamic (can be set before or after initialization).
113
100
  *
114
- * @param {string|Array<string>|null|undefined|function} [options.schema]
101
+ * @property {string|Array<string>|null|undefined|function} [options.schema]
115
102
  * Forces change of the default database schema(s) for every fresh connection, i.e.
116
103
  * the library will execute `SET search_path TO schema_1, schema_2, ...` in the background
117
104
  * whenever a fresh physical connection is allocated.
@@ -128,47 +115,47 @@ let originalClientConnect;
128
115
  *
129
116
  * This option is dynamic (can be set before or after initialization).
130
117
  *
131
- * @param {boolean} [options.noWarnings=false]
118
+ * @property {boolean} [options.noWarnings=false]
132
119
  * Disables all diagnostic warnings in the library (it is ill-advised).
133
120
  *
134
121
  * This option is dynamic (can be set before or after initialization).
135
122
  *
136
- * @param {function} [options.connect]
123
+ * @property {function} [options.connect]
137
124
  * Global event {@link event:connect connect} handler.
138
125
  *
139
126
  * This option is dynamic (can be set before or after initialization).
140
127
  *
141
- * @param {function} [options.disconnect]
128
+ * @property {function} [options.disconnect]
142
129
  * Global event {@link event:disconnect disconnect} handler.
143
130
  *
144
131
  * This option is dynamic (can be set before or after initialization).
145
132
  *
146
- * @param {function} [options.query]
133
+ * @property {function} [options.query]
147
134
  * Global event {@link event:query query} handler.
148
135
  *
149
136
  * This option is dynamic (can be set before or after initialization).
150
137
  *
151
- * @param {function} [options.receive]
138
+ * @property {function} [options.receive]
152
139
  * Global event {@link event:receive receive} handler.
153
140
  *
154
141
  * This option is dynamic (can be set before or after initialization).
155
142
  *
156
- * @param {function} [options.task]
143
+ * @property {function} [options.task]
157
144
  * Global event {@link event:task task} handler.
158
145
  *
159
146
  * This option is dynamic (can be set before or after initialization).
160
147
  *
161
- * @param {function} [options.transact]
148
+ * @property {function} [options.transact]
162
149
  * Global event {@link event:transact transact} handler.
163
150
  *
164
151
  * This option is dynamic (can be set before or after initialization).
165
152
  *
166
- * @param {function} [options.error]
153
+ * @property {function} [options.error]
167
154
  * Global event {@link event:error error} handler.
168
155
  *
169
156
  * This option is dynamic (can be set before or after initialization).
170
157
  *
171
- * @param {function} [options.extend]
158
+ * @property {function} [options.extend]
172
159
  * Global event {@link event:extend extend} handler.
173
160
  *
174
161
  * This option is dynamic (can be set before or after initialization).
@@ -191,7 +178,7 @@ let originalClientConnect;
191
178
  */
192
179
  function $main(options) {
193
180
 
194
- options = assert(options, [`pgFormatting`, `pgNative`, `promiseLib`, `noLocking`, `capSQL`, `noWarnings`,
181
+ options = assert(options, [`pgFormatting`, `pgNative`, `promiseLib`, `capSQL`, `noWarnings`,
195
182
  `connect`, `disconnect`, `query`, `receive`, `task`, `transact`, `error`, `extend`, `schema`]);
196
183
 
197
184
  let pg = npm.pg;
@@ -303,7 +290,6 @@ function $main(options) {
303
290
  npm.utils.addReadProp(inst, `spex`, config.$npm.spex);
304
291
 
305
292
  config.pgp = inst;
306
- npm.utils.lock(config, true, options);
307
293
 
308
294
  return inst;
309
295
  }
package/lib/query.js CHANGED
@@ -160,8 +160,8 @@ function $query(ctx, query, values, qrm, config) {
160
160
  if (npm.utils.isConnectivityError(err)) {
161
161
  ctx.db.client.$connectionError = err;
162
162
  }
163
- err.query = err.query || query;
164
- err.params = err.params || params;
163
+ err.query ??= query;
164
+ err.params ??= params;
165
165
  error = err;
166
166
  } else {
167
167
  multiResult = Array.isArray(result);
package/lib/task.js CHANGED
@@ -238,7 +238,6 @@ const execute = (ctx, obj, isTX, config) => {
238
238
  c.success = success;
239
239
  c.result = result;
240
240
  c.duration = c.finish - c.start;
241
- npm.utils.lock(c, true);
242
241
  }
243
242
  (isTX ? Events.transact : Events.task)(ctx.options, {
244
243
  client: ctx.db && ctx.db.client, // loss of connectivity is possible at this point
@@ -10,8 +10,7 @@
10
10
  const npm = {
11
11
  path: require(`path`),
12
12
  util: require(`util`),
13
- patterns: require(`../patterns`),
14
- os: require(`os`)
13
+ patterns: require(`../patterns`)
15
14
  };
16
15
 
17
16
  ////////////////////////////////////////////
@@ -36,27 +35,6 @@ function isDev() {
36
35
  return env.toLowerCase().indexOf(`dev`) !== -1;
37
36
  }
38
37
 
39
- ///////////////////////////////////////////////////
40
- // Locks all properties in an object to read-only,
41
- // or freezes the entire object for any changes.
42
- function lock(obj, freeze, options) {
43
- if (options && options.noLocking) {
44
- return;
45
- }
46
- if (freeze) {
47
- Object.freeze(obj); // freeze the entire object, permanently;
48
- } else {
49
- const desc = {
50
- writable: false,
51
- configurable: false,
52
- enumerable: true
53
- };
54
- for (const p in obj) {
55
- Object.defineProperty(obj, p, desc);
56
- }
57
- }
58
- }
59
-
60
38
  /////////////////////////////////////////////
61
39
  // Adds properties from source to the target,
62
40
  // making them read-only and enumerable.
@@ -203,22 +181,15 @@ function toJson(data) {
203
181
  }
204
182
  }
205
183
 
206
- const platform = npm.os.platform();
207
-
208
184
  const exp = {
209
185
  toJson,
210
186
  getIfHas,
211
187
  addInspection,
212
188
  InternalError,
213
189
  getLocalStack,
214
- lock,
215
190
  isText,
216
191
  isNull,
217
192
  isDev,
218
- platform: {
219
- isWindows: platform === `win32`,
220
- isMac: platform === `darwin`
221
- },
222
193
  addReadProp,
223
194
  addReadProperties,
224
195
  getSafeConnection,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "10.15.3",
3
+ "version": "11.0.0",
4
4
  "description": "PostgreSQL interface for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "typings": "typescript/pg-promise.d.ts",
7
7
  "scripts": {
8
- "check-spelling": "cspell --config=.cspell.json \"**/*.{md,ts,js}\" --no-progress",
8
+ "spelling": "cspell --config=.cspell.json \"**/*.{md,ts,js}\" --no-progress",
9
9
  "coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
10
10
  "doc": "jsdoc -c ./jsdoc/jsdoc.js ./jsdoc/README.md -t ./jsdoc/templates/custom",
11
11
  "lint": "eslint ./lib ./test/*.js ./test/db --fix",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "license": "MIT",
39
39
  "engines": {
40
- "node": ">=12.0"
40
+ "node": ">=14.0"
41
41
  },
42
42
  "dependencies": {
43
43
  "assert-options": "0.8.0",
@@ -46,17 +46,18 @@
46
46
  "spex": "3.2.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/node": "18.11.9",
49
+ "@babel/eslint-parser": "7.19.1",
50
+ "@types/node": "18.11.18",
50
51
  "bluebird": "3.7.2",
51
52
  "coveralls": "3.1.1",
52
- "cspell": "6.14.3",
53
- "eslint": "8.28.0",
53
+ "cspell": "6.18.1",
54
+ "eslint": "8.30.0",
54
55
  "istanbul": "0.4.5",
55
56
  "jasmine-node": "3.0.0",
56
- "jsdoc": "3.6.11",
57
+ "jsdoc": "4.0.0",
57
58
  "JSONStream": "1.3.5",
58
59
  "pg-query-stream": "4.2.4",
59
60
  "tslint": "6.1.3",
60
- "typescript": "4.9.3"
61
+ "typescript": "4.9.4"
61
62
  }
62
63
  }
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  /////////////////////////////////////////
11
- // Requires pg-promise v10.14.0 or later.
11
+ // Requires pg-promise v11.0.0 or later.
12
12
  /////////////////////////////////////////
13
13
 
14
14
  // We use ES6 as static promise here, because generic promises are still not supported.
@@ -573,18 +573,17 @@ declare namespace pgPromise {
573
573
  pgFormatting?: boolean
574
574
  pgNative?: boolean
575
575
  promiseLib?: any
576
- noLocking?: boolean
577
576
  capSQL?: boolean
578
577
  schema?: ValidSchema | ((dc: any) => ValidSchema)
579
578
 
580
- connect?(client: C, dc: any, useCount: number): void
579
+ connect?(e: { client: C, dc: any, useCount: number }): void
581
580
 
582
- disconnect?(client: C, dc: any): void
581
+ disconnect?(e: { client: C, dc: any }): void
583
582
 
584
583
  query?(e: IEventContext<C>): void
585
584
 
586
585
  // NOTE: result is undefined when data comes from QueryStream, i.e. via method Database.stream
587
- receive?(data: any[], result: IResultExt | void, e: IEventContext<C>): void
586
+ receive?(e: { data: any[], result: IResultExt | void, ctx: IEventContext<C> }): void
588
587
 
589
588
  task?(e: IEventContext<C>): void
590
589
 
@@ -293,15 +293,15 @@ declare namespace pg {
293
293
 
294
294
  interface IClient extends EventEmitter {
295
295
 
296
- query<T>(config: any, values: any[], callback: (err: Error, result: IResult<T>) => void): undefined
296
+ query<T>(config: any, values: any[], callback: (err: Error, result: IResult<T>) => void): void
297
297
 
298
- query<T>(config: any, callback: (err: Error, result: IResult<T>) => void): undefined
298
+ query<T>(config: any, callback: (err: Error, result: IResult<T>) => void): void
299
299
 
300
300
  query<T>(config: any, values: any[]): Promise<IResult<T>>
301
301
 
302
302
  query<T>(config: any): Promise<IResult<T>>
303
303
 
304
- release();
304
+ release(): void
305
305
 
306
306
  connectionParameters: IConnectionParameters
307
307
  database: string