pg-promise 11.15.0 → 12.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
@@ -52,7 +52,6 @@ Built on top of [node-postgres], this library adds the following:
52
52
  * Declarative approach to handling query results
53
53
  * Global events reporting for central handling
54
54
  * Extensive support for external SQL files
55
- * Support for all promise libraries
56
55
 
57
56
  At its inception in 2015, this library was only adding promises to the base driver, hence the name `pg-promise`.
58
57
  And while the original name was kept, the library's functionality was vastly extended, with promises now being
@@ -999,7 +998,7 @@ to force the pool to shut down all the connections it holds:
999
998
  db.$pool.end(); // shuts down the connection pool associated with the Database object
1000
999
  ```
1001
1000
 
1002
- For example, if you are using the [Bluebird] library, you can chain the last promise in the process like this:
1001
+ For example, you can chain the last promise in the process like this:
1003
1002
 
1004
1003
  ```js
1005
1004
  .finally(db.$pool.end);
@@ -1117,7 +1116,6 @@ See the relevant API: [pgp.end], [Database.$pool]
1117
1116
  <!-- External Links -->
1118
1117
 
1119
1118
  [node-postgres]:https://github.com/brianc/node-postgres
1120
- [Bluebird]:https://github.com/petkaantonov/bluebird
1121
1119
  [SQL injection]:https://en.wikipedia.org/wiki/SQL_injection
1122
1120
  [Symbol]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
1123
1121
  [idleTimeoutMillis]:https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js
package/lib/connect.js CHANGED
@@ -16,8 +16,8 @@ const npm = {
16
16
  formatting: require('./formatting')
17
17
  };
18
18
 
19
- function poolConnect(ctx, db, config) {
20
- return config.promise((resolve, reject) => {
19
+ function poolConnect(ctx, db) {
20
+ return new Promise((resolve, reject) => {
21
21
  const p = db.$pool;
22
22
  if (p.ending) {
23
23
  db.$destroy();
@@ -37,7 +37,7 @@ function poolConnect(ctx, db, config) {
37
37
  reject(err);
38
38
  } else {
39
39
  if ('$useCount' in client) {
40
- // Make sure useCount drops to 1, if it ever reaches maximum integer number;
40
+ // Make sure useCount drops to 1, if it ever reaches the maximum integer number;
41
41
  // We do not drop it to zero, to avoid rerun of initialization queries that
42
42
  // usually check for useCount === 0;
43
43
  // istanbul ignore if
@@ -75,7 +75,7 @@ function poolConnect(ctx, db, config) {
75
75
  }
76
76
 
77
77
  function directConnect(ctx, config) {
78
- return config.promise((resolve, reject) => {
78
+ return new Promise((resolve, reject) => {
79
79
  const client = new config.pgp.pg.Client(ctx.cn);
80
80
  client.connect(err => {
81
81
  if (err) {
@@ -94,7 +94,7 @@ function directConnect(ctx, config) {
94
94
  useCount: 0,
95
95
  release() {
96
96
  client.end = end;
97
- const p = config.promise((res, rej) => client.end().then(res).catch(rej));
97
+ const p = new Promise((res, rej) => client.end().then(res).catch(rej));
98
98
  Events.disconnect(ctx, client);
99
99
  client.removeListener('error', onError);
100
100
  return p;
@@ -173,6 +173,6 @@ function setSchema(client, ctx) {
173
173
  }
174
174
 
175
175
  module.exports = config => ({
176
- pool: (ctx, db) => poolConnect(ctx, db, config),
176
+ pool: (ctx, db) => poolConnect(ctx, db),
177
177
  direct: ctx => directConnect(ctx, config)
178
178
  });
package/lib/database.js CHANGED
@@ -122,7 +122,6 @@ const npm = {
122
122
  function Database(cn, dc, config) {
123
123
 
124
124
  const dbThis = this,
125
- $p = config.promise,
126
125
  poolConnection = typeof cn === 'string' ? {connectionString: cn} : cn,
127
126
  pool = new config.pgp.pg.Pool(poolConnection),
128
127
  endMethod = pool.end;
@@ -249,7 +248,7 @@ function Database(cn, dc, config) {
249
248
  const self = {
250
249
  query(query, values, qrm) {
251
250
  if (!ctx.db) {
252
- return $p.reject(new Error(npm.text.queryDisconnected));
251
+ return Promise.reject(new Error(npm.text.queryDisconnected));
253
252
  }
254
253
  return config.$npm.query.call(this, ctx, query, values, qrm);
255
254
  },
@@ -338,7 +337,7 @@ function Database(cn, dc, config) {
338
337
  })
339
338
  .catch(error => {
340
339
  ctx.disconnect();
341
- return $p.reject(error);
340
+ return Promise.reject(error);
342
341
  });
343
342
  };
344
343
 
@@ -351,27 +350,8 @@ function Database(cn, dc, config) {
351
350
  * Properties available in the object:
352
351
  * - `pgp` - instance of the entire library after initialization
353
352
  * - `options` - the library's {@link module:pg-promise Initialization Options} object
354
- * - `promiseLib` - instance of the promise library that's used
355
- * - `promise` - generic promise interface that uses `promiseLib` via 4 basic methods:
356
- * - `promise((resolve, reject) => {})` - to create a new promise
357
- * - `promise.resolve(value)` - to resolve with a value
358
- * - `promise.reject(reason)` - to reject with a reason
359
- * - `promise.all(iterable)` - to resolve an iterable list of promises
360
353
  * - `version` - this library's version
361
354
  * - `$npm` _(hidden property)_ - internal module cache
362
- *
363
- * @example
364
- *
365
- * // Using the promise protocol as configured by pg-promise:
366
- *
367
- * const $p = db.$config.promise;
368
- *
369
- * const resolvedPromise = $p.resolve('some data');
370
- * const rejectedPromise = $p.reject('some reason');
371
- *
372
- * const newPromise = $p((resolve, reject) => {
373
- * // call either resolve(data) or reject(reason) here
374
- * });
375
355
  */
376
356
  npm.utils.addReadProp(this, '$config', config, true);
377
357
 
@@ -1353,12 +1333,12 @@ function Database(cn, dc, config) {
1353
1333
  if ('cnd' in args.options) {
1354
1334
  cnd = typeof cnd === 'function' ? cnd.call(obj, obj) : !!cnd;
1355
1335
  } else {
1356
- cnd = !obj.ctx; // create task, if it is the top level
1336
+ cnd = !obj.ctx; // create a task if it is the top level
1357
1337
  }
1358
- // reusable only if condition fails, and not top-level:
1338
+ // reusable only if the condition fails, and not top-level:
1359
1339
  args.options.reusable = !cnd && !!obj.ctx;
1360
1340
  } catch (e) {
1361
- return $p.reject(e);
1341
+ return Promise.reject(e);
1362
1342
  }
1363
1343
  return taskProcessor.call(this, args, false);
1364
1344
  };
@@ -1541,17 +1521,17 @@ function Database(cn, dc, config) {
1541
1521
  const reusable = args.options.reusable;
1542
1522
  args.options.reusable = !cnd && obj.ctx && typeof reusable === 'function' ? reusable.call(obj, obj) : !!reusable;
1543
1523
  } catch (e) {
1544
- return $p.reject(e);
1524
+ return Promise.reject(e);
1545
1525
  }
1546
1526
  return taskProcessor.call(this, args, args.options.cnd);
1547
1527
  };
1548
1528
 
1549
1529
  // Task method;
1550
- // Resolves with result from the callback function;
1530
+ // Resolves with the result from the callback function;
1551
1531
  function taskProcessor(params, isTX) {
1552
1532
 
1553
1533
  if (typeof params.cb !== 'function') {
1554
- return $p.reject(new TypeError('Callback function is required.'));
1534
+ return Promise.reject(new TypeError('Callback function is required.'));
1555
1535
  }
1556
1536
 
1557
1537
  if (params.options.reusable) {
@@ -1595,12 +1575,12 @@ function Database(cn, dc, config) {
1595
1575
  })
1596
1576
  .catch(error => {
1597
1577
  taskCtx.disconnect();
1598
- return $p.reject(error);
1578
+ return Promise.reject(error);
1599
1579
  });
1600
1580
  }
1601
1581
 
1602
1582
  function addServerVersion(target, client) {
1603
- // Exclude else-case from coverage, because it can only occur with Native Bindings.
1583
+ // Exclude else-case from the coverage because it can only occur with Native Bindings.
1604
1584
  // istanbul ignore else
1605
1585
  if (client.serverVersion) {
1606
1586
  npm.utils.addReadProp(target, 'serverVersion', client.serverVersion);
@@ -1632,7 +1612,7 @@ function onError(err) {
1632
1612
  module.exports = config => {
1633
1613
  const npmLocal = config.$npm;
1634
1614
  npmLocal.connect = npmLocal.connect || npm.connect(config);
1635
- npmLocal.query = npmLocal.query || npm.query(config);
1615
+ npmLocal.query = npmLocal.query || npm.query();
1636
1616
  npmLocal.task = npmLocal.task || npm.task(config);
1637
1617
  return Database;
1638
1618
  };
package/lib/main.js CHANGED
@@ -7,12 +7,10 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {PromiseAdapter} = require('./promise-adapter');
11
10
  const {DatabasePool} = require('./database-pool');
12
11
  const {PreparedStatement, ParameterizedQuery} = require('./types');
13
12
  const {QueryFile} = require('./query-file');
14
13
  const {queryResult} = require('./query-result');
15
- const {parsePromise} = require('./promise-parser');
16
14
  const {assert} = require('./assert');
17
15
 
18
16
  const npm = {
@@ -36,7 +34,7 @@ let originalClientConnect;
36
34
  * @module pg-promise
37
35
  *
38
36
  * @description
39
- * ## pg-promise v11.15
37
+ * ## pg-promise v12.0
40
38
  * All documentation here is for the latest official release only.
41
39
  *
42
40
  * ### Initialization Options
@@ -69,25 +67,6 @@ let originalClientConnect;
69
67
  *
70
68
  * This is a static option (can only be set prior to initialization).
71
69
  *
72
- * @property {object|function} [options.promiseLib=Promise]
73
- * Overrides the default (ES6 Promise) promise library for its internal use.
74
- *
75
- * Example below sets to use $[Bluebird] - the best and recommended promise library. It is the fastest one,
76
- * and supports $[Long Stack Traces], essential for debugging promises.
77
- *
78
- * ```js
79
- * const Promise = require('bluebird');
80
- * const initOptions = {
81
- * promiseLib: Promise
82
- * };
83
- * const pgp = require('pg-promise')(initOptions);
84
- * ```
85
- *
86
- * All existing promise libraries are supported. The ones with recognizable signature are used automatically,
87
- * while the rest can be configured via the $[Promise Adapter].
88
- *
89
- * This is a static option (can only be set prior to initialization).
90
- *
91
70
  * @property {boolean} [options.capSQL=false]
92
71
  * Capitalizes any SQL generated by the library.
93
72
  *
@@ -178,22 +157,18 @@ let originalClientConnect;
178
157
  */
179
158
  function $main(options) {
180
159
 
181
- options = assert(options, ['pgFormatting', 'pgNative', 'promiseLib', 'capSQL', 'noWarnings',
160
+ options = assert(options, ['pgFormatting', 'pgNative', 'capSQL', 'noWarnings',
182
161
  'connect', 'disconnect', 'query', 'receive', 'task', 'transact', 'error', 'extend', 'schema']);
183
162
 
184
163
  let pg = npm.pg;
185
- const p = parsePromise(options.promiseLib);
186
164
 
187
165
  const config = {
188
- version: npm.package.version,
189
- promiseLib: p.promiseLib,
190
- promise: p.promise
166
+ version: npm.package.version
191
167
  };
192
168
 
193
169
  npm.utils.addReadProp(config, '$npm', {}, true);
194
170
 
195
171
  // Locking properties that cannot be changed later:
196
- npm.utils.addReadProp(options, 'promiseLib', options.promiseLib);
197
172
  npm.utils.addReadProp(options, 'pgNative', !!options.pgNative);
198
173
 
199
174
  config.options = options;
@@ -235,7 +210,7 @@ function $main(options) {
235
210
  /**
236
211
  * @member {external:PG} pg
237
212
  * @description
238
- * Instance of the $[pg] library that's being used, depending on initialization option `pgNative`:
213
+ * Instance of the $[pg] library being used, depending on initialization option `pgNative`:
239
214
  * - regular `pg` module instance, without option `pgNative`, or equal to `false` (default)
240
215
  * - `pg` module instance with $[Native Bindings], if option `pgNative` was set.
241
216
  *
@@ -328,16 +303,6 @@ const rootNameSpace = {
328
303
  */
329
304
  queryResult,
330
305
 
331
- /**
332
- * @member {PromiseAdapter} PromiseAdapter
333
- * @readonly
334
- * @description
335
- * {@link PromiseAdapter} class.
336
- *
337
- * Available as `pgp.PromiseAdapter`, before and after initializing the library.
338
- */
339
- PromiseAdapter,
340
-
341
306
  /**
342
307
  * @member {ParameterizedQuery} ParameterizedQuery
343
308
  * @readonly
package/lib/query.js CHANGED
@@ -30,13 +30,12 @@ const badMask = queryResult.one | queryResult.many; // unsupported combination b
30
30
 
31
31
  //////////////////////////////
32
32
  // Generic query method;
33
- function $query(ctx, query, values, qrm, config) {
33
+ function $query(ctx, query, values, qrm) {
34
34
 
35
35
  const special = qrm instanceof SpecialQuery && qrm;
36
- const $p = config.promise;
37
36
 
38
37
  if (special && special.isStream) {
39
- return npm.stream.call(this, ctx, query, values, config);
38
+ return npm.stream.call(this, ctx, query, values);
40
39
  }
41
40
 
42
41
  const opt = ctx.options,
@@ -122,7 +121,7 @@ function $query(ctx, query, values, qrm, config) {
122
121
 
123
122
  if (!error && (!pgFormatting || entityType)) {
124
123
  try {
125
- // use 'pg-promise' implementation of values formatting;
124
+ // use 'pg-promise' implementation of value formatting;
126
125
  if (entityType) {
127
126
  params = undefined;
128
127
  query = npm.formatting.formatEntity(query, values, {capSQL, type: entityType});
@@ -143,7 +142,7 @@ function $query(ctx, query, values, qrm, config) {
143
142
  }
144
143
  }
145
144
 
146
- return $p((resolve, reject) => {
145
+ return new Promise((resolve, reject) => {
147
146
 
148
147
  if (notifyReject()) {
149
148
  return;
@@ -194,7 +193,7 @@ function $query(ctx, query, values, qrm, config) {
194
193
  const len = data.length;
195
194
  if (len) {
196
195
  if (len > 1 && qrm & queryResult.one) {
197
- // one row was expected, but returned multiple;
196
+ // one row was expected but returned multiple;
198
197
  error = new QueryResultError(qrec.multiple, lastResult, query, params);
199
198
  } else {
200
199
  if (!(qrm & (queryResult.one | queryResult.many))) {
@@ -271,8 +270,4 @@ function makeIterable(r) {
271
270
  };
272
271
  }
273
272
 
274
- module.exports = config => {
275
- return function (ctx, query, values, qrm) {
276
- return $query.call(this, ctx, query, values, qrm, config);
277
- };
278
- };
273
+ module.exports = () => $query;
package/lib/stream.js CHANGED
@@ -17,28 +17,26 @@ const npm = {
17
17
  ////////////////////////////////////////////
18
18
  // Streams query data into any destination,
19
19
  // with the help of pg-query-stream library.
20
- function $stream(ctx, qs, initCB, config) {
21
-
22
- const $p = config.promise;
20
+ function $stream(ctx, qs, initCB) {
23
21
 
24
22
  // istanbul ignore next:
25
23
  // we do not provide code coverage for the Native Bindings specifics
26
24
  if (ctx.options.pgNative) {
27
- return $p.reject(new Error(npm.text.nativeStreaming));
25
+ return Promise.reject(new Error(npm.text.nativeStreaming));
28
26
  }
29
27
  // Stream class was renamed again, see the following issue:
30
28
  // https://github.com/brianc/node-postgres/issues/2412
31
29
  if (!qs || !qs.constructor || qs.constructor.name !== 'QueryStream') {
32
30
  // invalid or missing stream object;
33
- return $p.reject(new TypeError(npm.text.invalidStream));
31
+ return Promise.reject(new TypeError(npm.text.invalidStream));
34
32
  }
35
33
  if (qs._reading || qs._closed) {
36
34
  // stream object is in the wrong state;
37
- return $p.reject(new Error(npm.text.invalidStreamState));
35
+ return Promise.reject(new Error(npm.text.invalidStreamState));
38
36
  }
39
37
  if (typeof initCB !== 'function') {
40
38
  // parameter `initCB` must be passed as the initialization callback;
41
- return $p.reject(new TypeError(npm.text.invalidStreamCB));
39
+ return Promise.reject(new TypeError(npm.text.invalidStreamCB));
42
40
  }
43
41
 
44
42
  let error = Events.query(ctx.options, getContext());
@@ -46,7 +44,7 @@ function $stream(ctx, qs, initCB, config) {
46
44
  if (error) {
47
45
  error = getError(error);
48
46
  Events.error(ctx.options, error, getContext());
49
- return $p.reject(error);
47
+ return Promise.reject(error);
50
48
  }
51
49
 
52
50
  const stream = ctx.db.client.query(qs);
@@ -61,7 +59,7 @@ function $stream(ctx, qs, initCB, config) {
61
59
  release();
62
60
  error = getError(e);
63
61
  Events.error(ctx.options, error, getContext());
64
- return $p.reject(error);
62
+ return Promise.reject(error);
65
63
  }
66
64
 
67
65
  const start = Date.now();
@@ -117,7 +115,7 @@ function $stream(ctx, qs, initCB, config) {
117
115
  };
118
116
  }
119
117
 
120
- return $p((res, rej) => {
118
+ return new Promise((res, rej) => {
121
119
  resolve = res;
122
120
  reject = rej;
123
121
  });
package/lib/task.js CHANGED
@@ -61,8 +61,6 @@ const npm = {
61
61
  */
62
62
  function Task(ctx, tag, isTX, config) {
63
63
 
64
- const $p = config.promise;
65
-
66
64
  /**
67
65
  * @member {TaskContext} Task#ctx
68
66
  * @readonly
@@ -112,7 +110,7 @@ function Task(ctx, tag, isTX, config) {
112
110
  // generic query method;
113
111
  this.query = function (query, values, qrm) {
114
112
  if (!ctx.db) {
115
- return $p.reject(new Error(npm.text.looseQuery));
113
+ return Promise.reject(new Error(npm.text.looseQuery));
116
114
  }
117
115
  return config.$npm.query.call(this, ctx, query, values, qrm);
118
116
  };
@@ -191,9 +189,8 @@ function Task(ctx, tag, isTX, config) {
191
189
  * @param config
192
190
  * @returns {Promise.<TResult>}
193
191
  */
194
- const callback = (ctx, obj, cb, config) => {
192
+ const callback = (ctx, obj, cb) => {
195
193
 
196
- const $p = config.promise;
197
194
  let result;
198
195
 
199
196
  try {
@@ -209,12 +206,12 @@ const callback = (ctx, obj, cb, config) => {
209
206
  dc: ctx.dc,
210
207
  ctx: ctx.ctx
211
208
  });
212
- return $p.reject(err); // reject with the error;
209
+ return Promise.reject(err); // reject with the error;
213
210
  }
214
211
  if (result && typeof result.then === 'function') {
215
212
  return result; // result is a valid promise object;
216
213
  }
217
- return $p.resolve(result);
214
+ return Promise.resolve(result);
218
215
  };
219
216
 
220
217
  /**
@@ -230,8 +227,6 @@ const callback = (ctx, obj, cb, config) => {
230
227
  */
231
228
  const execute = (ctx, obj, isTX, config) => {
232
229
 
233
- const $p = config.promise;
234
-
235
230
  // updates the task context and notifies the client;
236
231
  function update(start, success, result) {
237
232
  const c = ctx.ctx;
@@ -276,7 +271,7 @@ const execute = (ctx, obj, isTX, config) => {
276
271
  return cbData;
277
272
  }
278
273
  update(false, false, cbReason);
279
- return $p.reject(cbReason);
274
+ return Promise.reject(cbReason);
280
275
  },
281
276
  err => {
282
277
  // either COMMIT or ROLLBACK has failed, which is impossible
@@ -284,7 +279,7 @@ const execute = (ctx, obj, isTX, config) => {
284
279
  // istanbul ignore next:
285
280
  update(false, false, err);
286
281
  // istanbul ignore next:
287
- return $p.reject(err);
282
+ return Promise.reject(err);
288
283
  }),
289
284
  err => {
290
285
  // BEGIN has failed, which is impossible to replicate in a test
@@ -292,7 +287,7 @@ const execute = (ctx, obj, isTX, config) => {
292
287
  // istanbul ignore next:
293
288
  update(false, false, err);
294
289
  // istanbul ignore next:
295
- return $p.reject(err);
290
+ return Promise.reject(err);
296
291
  });
297
292
  }
298
293
 
@@ -326,7 +321,7 @@ const execute = (ctx, obj, isTX, config) => {
326
321
  })
327
322
  .catch(error => {
328
323
  update(false, false, error);
329
- return $p.reject(error);
324
+ return Promise.reject(error);
330
325
  });
331
326
  };
332
327
 
@@ -336,8 +331,8 @@ module.exports = config => {
336
331
  // istanbul ignore next:
337
332
  // we keep 'npm.query' initialization here, even though it is always
338
333
  // pre-initialized by the 'database' module, for integrity purpose.
339
- npmLocal.query = npmLocal.query || npm.query(config);
340
- npmLocal.spex = npmLocal.spex || npm.spex(config.promiseLib);
334
+ npmLocal.query = npmLocal.query || npm.query();
335
+ npmLocal.spex = npmLocal.spex || npm.spex(Promise);
341
336
 
342
337
  return {
343
338
  Task, execute, callback
@@ -415,5 +410,4 @@ module.exports = config => {
415
410
  * Once the operation has finished, this property contains the result, depending on property `success`:
416
411
  * - data resolved by the operation, if `success = true`
417
412
  * - error / rejection reason, if `success = false`
418
- *
419
413
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "11.15.0",
3
+ "version": "12.0.0",
4
4
  "description": "PostgreSQL interface for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "typings": "typescript/pg-promise.d.ts",
@@ -50,18 +50,17 @@
50
50
  "pg-query-stream": "4.10.3"
51
51
  },
52
52
  "devDependencies": {
53
- "@eslint/js": "9.30.1",
54
- "@types/node": "24.0.10",
55
- "bluebird": "3.7.2",
53
+ "@eslint/js": "9.34.0",
54
+ "@types/node": "24.3.0",
56
55
  "coveralls": "3.1.1",
57
- "cspell": "9.1.3",
58
- "eslint": "9.30.1",
56
+ "cspell": "9.2.0",
57
+ "eslint": "9.34.0",
59
58
  "globals": "16.3.0",
60
59
  "istanbul": "0.4.5",
61
60
  "jasmine-node": "3.0.0",
62
61
  "jsdoc": "4.0.4",
63
62
  "JSONStream": "1.3.5",
64
63
  "tslint": "6.1.3",
65
- "typescript": "5.8.3"
64
+ "typescript": "5.9.2"
66
65
  }
67
66
  }
@@ -126,16 +126,6 @@ declare namespace pgPromise {
126
126
  table: string
127
127
  }
128
128
 
129
- interface IPromiseConfig {
130
- create(resolve: (value?: any) => void, reject?: (reason?: any) => void): Promise<any>
131
-
132
- resolve(value?: any): void
133
-
134
- reject(reason?: any): void
135
-
136
- all(iterable: any): Promise<any>
137
- }
138
-
139
129
  type FormattingFilter = '^' | '~' | '#' | ':raw' | ':alias' | ':name' | ':json' | ':csv' | ':list' | ':value';
140
130
 
141
131
  type QueryColumns<T> = Column<T> | ColumnSet<T> | Array<string | IColumnConfig<T> | Column<T>>;
@@ -281,12 +271,6 @@ declare namespace pgPromise {
281
271
  toString(level?: number): string
282
272
  }
283
273
 
284
- // PromiseAdapter class;
285
- // API: https://vitaly-t.github.io/pg-promise/PromiseAdapter.html
286
- class PromiseAdapter {
287
- constructor(api: IPromiseConfig)
288
- }
289
-
290
274
  const txMode: typeof _txMode;
291
275
  const utils: IUtils;
292
276
  const as: IFormatting;
@@ -320,7 +304,6 @@ declare namespace pgPromise {
320
304
  interface IMain<Ext = {}, C extends pg.IClient = pg.IClient> {
321
305
  <T = Ext, C extends pg.IClient = pg.IClient>(cn: string | pg.IConnectionParameters<C>, dc?: any): IDatabase<T, C> & T
322
306
 
323
- readonly PromiseAdapter: typeof PromiseAdapter
324
307
  readonly PreparedStatement: typeof PreparedStatement
325
308
  readonly ParameterizedQuery: typeof ParameterizedQuery
326
309
  readonly QueryFile: typeof QueryFile
@@ -464,7 +447,7 @@ declare namespace pgPromise {
464
447
  // See: https://vitaly-t.github.io/pg-promise/global.html#TaskContext
465
448
  interface ITaskContext {
466
449
 
467
- // these are set in the beginning of each task/transaction:
450
+ // these are set at the beginning of each task/transaction:
468
451
  readonly context: any
469
452
  readonly parent: ITaskContext | null
470
453
  readonly connected: boolean
@@ -588,7 +571,6 @@ declare namespace pgPromise {
588
571
  noWarnings?: boolean
589
572
  pgFormatting?: boolean
590
573
  pgNative?: boolean
591
- promiseLib?: any
592
574
  capSQL?: boolean
593
575
  schema?: ValidSchema | ((dc: any) => ValidSchema)
594
576
 
@@ -613,7 +595,6 @@ declare namespace pgPromise {
613
595
  // API: https://vitaly-t.github.io/pg-promise/Database.html#$config
614
596
  interface ILibConfig<Ext, C extends pg.IClient = pg.IClient> {
615
597
  version: string
616
- promiseLib: any
617
598
  promise: IGenericPromise
618
599
  options: IInitOptions<Ext, C>
619
600
  pgp: IMain<Ext, C>
@@ -1,86 +0,0 @@
1
- /*
2
- * Copyright (c) 2015-present, Vitaly Tomilov
3
- *
4
- * See the LICENSE file at the top-level directory of this distribution
5
- * for licensing information.
6
- *
7
- * Removal or modification of this copyright notice is prohibited.
8
- */
9
-
10
- const {assert} = require('./assert');
11
-
12
- /**
13
- * @class PromiseAdapter
14
- * @summary Adapter for the primary promise operations.
15
- * @description
16
- * Provides compatibility with promise libraries that cannot be recognized automatically,
17
- * via functions that implement the primary operations with promises:
18
- *
19
- * - construct a new promise with a callback function
20
- * - resolve a promise with some result data
21
- * - reject a promise with a reason
22
- * - resolve an array of promises
23
- *
24
- * The type is available from the library's root: `pgp.PromiseAdapter`.
25
- *
26
- * @param {object} api
27
- * Promise API configuration object.
28
- *
29
- * Passing in anything other than an object will throw {@link external:TypeError TypeError} = `Adapter requires an api configuration object.`
30
- *
31
- * @param {function} api.create
32
- * A function that takes a callback parameter and returns a new promise object.
33
- * The callback parameter is expected to be `function(resolve, reject)`.
34
- *
35
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'create' must be specified.`
36
- *
37
- * @param {function} api.resolve
38
- * A function that takes an optional data parameter and resolves a promise with it.
39
- *
40
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'resolve' must be specified.`
41
- *
42
- * @param {function} api.reject
43
- * A function that takes an optional error parameter and rejects a promise with it.
44
- *
45
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'reject' must be specified.`
46
- *
47
- * @param {function} api.all
48
- * A function that resolves an array of promises.
49
- *
50
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'all' must be specified.`
51
- *
52
- * @returns {PromiseAdapter}
53
- */
54
- class PromiseAdapter {
55
- constructor(api) {
56
-
57
- if (!api || typeof api !== 'object') {
58
- throw new TypeError('Adapter requires an api configuration object.');
59
- }
60
-
61
- api = assert(api, ['create', 'resolve', 'reject', 'all']);
62
-
63
- this.create = api.create;
64
- this.resolve = api.resolve;
65
- this.reject = api.reject;
66
- this.all = api.all;
67
-
68
- if (typeof this.create !== 'function') {
69
- throw new TypeError('Function \'create\' must be specified.');
70
- }
71
-
72
- if (typeof this.resolve !== 'function') {
73
- throw new TypeError('Function \'resolve\' must be specified.');
74
- }
75
-
76
- if (typeof this.reject !== 'function') {
77
- throw new TypeError('Function \'reject\' must be specified.');
78
- }
79
-
80
- if (typeof this.all !== 'function') {
81
- throw new TypeError('Function \'all\' must be specified.');
82
- }
83
- }
84
- }
85
-
86
- module.exports = {PromiseAdapter};
@@ -1,56 +0,0 @@
1
- /*
2
- * Copyright (c) 2015-present, Vitaly Tomilov
3
- *
4
- * See the LICENSE file at the top-level directory of this distribution
5
- * for licensing information.
6
- *
7
- * Removal or modification of this copyright notice is prohibited.
8
- */
9
-
10
- const {PromiseAdapter} = require('./promise-adapter');
11
-
12
- //////////////////////////////////////////
13
- // Parses and validates a promise library;
14
- function parse(pl) {
15
-
16
- let promise;
17
- if (pl instanceof PromiseAdapter) {
18
- promise = function (func) {
19
- return pl.create(func);
20
- };
21
- promise.resolve = pl.resolve;
22
- promise.reject = pl.reject;
23
- promise.all = pl.all;
24
- return promise;
25
- }
26
- const t = typeof pl;
27
- if (t === 'function' || t === 'object') {
28
- const Root = typeof pl.Promise === 'function' ? pl.Promise : pl;
29
- promise = function (func) {
30
- return new Root(func);
31
- };
32
- promise.resolve = Root.resolve;
33
- promise.reject = Root.reject;
34
- promise.all = Root.all;
35
- if (typeof promise.resolve === 'function' &&
36
- typeof promise.reject === 'function' &&
37
- typeof promise.all === 'function') {
38
- return promise;
39
- }
40
- }
41
-
42
- throw new TypeError('Invalid promise library specified.');
43
- }
44
-
45
- function parsePromise(promiseLib) {
46
- const result = {promiseLib};
47
- if (promiseLib) {
48
- result.promise = parse(promiseLib);
49
- } else {
50
- result.promise = parse(Promise);
51
- result.promiseLib = Promise;
52
- }
53
- return result;
54
- }
55
-
56
- module.exports = {parsePromise};