pg-promise 10.14.0 → 10.14.2

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/lib/assert.js ADDED
@@ -0,0 +1,10 @@
1
+ const {assertOptions} = require(`assert-options`);
2
+
3
+ // this to allow override options-related errors globally (for pg-promise)
4
+ global.pgPromiseAssert = assertOptions;
5
+
6
+ module.exports = {
7
+ assert() {
8
+ return global.pgPromiseAssert.apply(null, [...arguments]);
9
+ }
10
+ };
package/lib/database.js CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const {Events} = require(`./events`);
11
- const {assertOptions} = require(`assert-options`);
11
+ const {assert} = require(`./assert`);
12
12
  const {resultQuery, multiResultQuery, streamQuery} = require(`./special-query`);
13
13
  const {ConnectionContext} = require(`./context`);
14
14
  const {DatabasePool} = require(`./database-pool`);
@@ -1289,7 +1289,7 @@ function Database(cn, dc, config) {
1289
1289
  */
1290
1290
  obj.task = function () {
1291
1291
  const args = npm.pubUtils.taskArgs(arguments);
1292
- assertOptions(args.options, [`tag`]);
1292
+ assert(args.options, [`tag`]);
1293
1293
  return taskProcessor.call(this, args, false);
1294
1294
  };
1295
1295
 
@@ -1347,7 +1347,7 @@ function Database(cn, dc, config) {
1347
1347
  */
1348
1348
  obj.taskIf = function () {
1349
1349
  const args = npm.pubUtils.taskArgs(arguments);
1350
- assertOptions(args.options, [`tag`, `cnd`]);
1350
+ assert(args.options, [`tag`, `cnd`]);
1351
1351
  try {
1352
1352
  let cnd = args.options.cnd;
1353
1353
  if (`cnd` in args.options) {
@@ -1456,7 +1456,7 @@ function Database(cn, dc, config) {
1456
1456
  */
1457
1457
  obj.tx = function () {
1458
1458
  const args = npm.pubUtils.taskArgs(arguments);
1459
- assertOptions(args.options, [`tag`, `mode`]);
1459
+ assert(args.options, [`tag`, `mode`]);
1460
1460
  return taskProcessor.call(this, args, true);
1461
1461
  };
1462
1462
 
@@ -1529,7 +1529,7 @@ function Database(cn, dc, config) {
1529
1529
  */
1530
1530
  obj.txIf = function () {
1531
1531
  const args = npm.pubUtils.taskArgs(arguments);
1532
- assertOptions(args.options, [`tag`, `mode`, `cnd`, `reusable`]);
1532
+ assert(args.options, [`tag`, `mode`, `cnd`, `reusable`]);
1533
1533
  try {
1534
1534
  let cnd;
1535
1535
  if (`cnd` in args.options) {
package/lib/formatting.js CHANGED
@@ -7,7 +7,7 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {assertOptions} = require(`assert-options`);
10
+ const {assert} = require(`./assert`);
11
11
 
12
12
  const npm = {
13
13
  pgUtils: require(`pg/lib/utils`),
@@ -101,7 +101,7 @@ function formatValue({value, fm, cc, options}) {
101
101
  if (Array.isArray(value)) {
102
102
  return $to.array(value, options);
103
103
  }
104
- if (value instanceof Buffer) {
104
+ if (Buffer.isBuffer(value)) {
105
105
  return $to.buffer(value, isRaw);
106
106
  }
107
107
  return $to.json(value, isRaw);
@@ -115,7 +115,7 @@ function formatValue({value, fm, cc, options}) {
115
115
  // Arrays of any depth/dimension are supported.
116
116
  //
117
117
  // Top-level empty arrays are formatted as literal '{}' to avoid the necessity of explicit type casting,
118
- // as the server cannot automatically infer the type of an empty non-literal array.
118
+ // as the server cannot automatically infer the type of empty non-literal array.
119
119
  function formatArray(array, options) {
120
120
  const loop = a => `[` + a.map(value => Array.isArray(value) ? loop(value) : formatValue({
121
121
  value,
@@ -683,7 +683,7 @@ const $as = {
683
683
  * @returns {string}
684
684
  */
685
685
  array(arr, options) {
686
- options = assertOptions(options, [`capSQL`]);
686
+ options = assert(options, [`capSQL`]);
687
687
  arr = resolveFunc(arr);
688
688
  if (isNull(arr)) {
689
689
  return `null`;
@@ -850,7 +850,7 @@ const $as = {
850
850
  * The function will throw an error, if any occurs during formatting.
851
851
  */
852
852
  format(query, values, options) {
853
- options = assertOptions(options, [`capSQL`, `partial`, `def`]);
853
+ options = assert(options, [`capSQL`, `partial`, `def`]);
854
854
  const ctf = getCTF(query);
855
855
  if (ctf) {
856
856
  query = ctf.toPostgres.call(query, query);
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const {InnerState} = require(`../inner-state`);
11
- const {assertOptions} = require(`assert-options`);
11
+ const {assert} = require(`../assert`);
12
12
  const {TableName} = require(`./table-name`);
13
13
  const {Column} = require(`./column`);
14
14
 
@@ -172,7 +172,7 @@ class ColumnSet extends InnerState {
172
172
  throw new TypeError(`Invalid parameter 'columns' specified.`);
173
173
  }
174
174
 
175
- opt = assertOptions(opt, [`table`, `inherit`]);
175
+ opt = assert(opt, [`table`, `inherit`]);
176
176
 
177
177
  if (!npm.utils.isNull(opt.table)) {
178
178
  this.table = (opt.table instanceof TableName) ? opt.table : new TableName(opt.table);
@@ -400,7 +400,7 @@ ColumnSet.prototype.assign = function (options) {
400
400
  *
401
401
  */
402
402
  ColumnSet.prototype.assignColumns = function (options) {
403
- options = assertOptions(options, [`from`, `to`, `skip`]);
403
+ options = assert(options, [`from`, `to`, `skip`]);
404
404
  const skip = (typeof options.skip === `string` && [options.skip]) || ((Array.isArray(options.skip) || typeof options.skip === `function`) && options.skip);
405
405
  const from = (typeof options.from === `string` && options.from && (npm.formatting.as.alias(options.from) + `.`)) || ``;
406
406
  const to = (typeof options.to === `string` && options.to && (npm.formatting.as.alias(options.to) + `.`)) || ``;
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  const {InnerState} = require(`../inner-state`);
11
- const {assertOptions} = require(`assert-options`);
11
+ const {assert} = require(`../assert`);
12
12
 
13
13
  const npm = {
14
14
  os: require(`os`),
@@ -142,7 +142,7 @@ class Column extends InnerState {
142
142
  this.cnd = info.cnd;
143
143
  }
144
144
  } else {
145
- col = assertOptions(col, [`name`, `prop`, `mod`, `cast`, `cnd`, `def`, `init`, `skip`]);
145
+ col = assert(col, [`name`, `prop`, `mod`, `cast`, `cnd`, `def`, `init`, `skip`]);
146
146
  if (`name` in col) {
147
147
  if (!npm.utils.isText(col.name)) {
148
148
  throw new TypeError(`Invalid 'name' value: ${npm.utils.toJson(col.name)}. A non-empty string was expected.`);
@@ -7,7 +7,7 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {assertOptions} = require(`assert-options`);
10
+ const {assert} = require(`../../assert`);
11
11
  const {TableName} = require(`../table-name`);
12
12
  const {ColumnSet} = require(`../column-set`);
13
13
 
@@ -65,7 +65,7 @@ const npm = {
65
65
  * @param {*} [options.emptyUpdate]
66
66
  * This is a convenience option, to avoid throwing an error when generating a conditional update results in no columns.
67
67
  *
68
- * When present, regardless of the value, this option overrides the method's behaviour when applying `skip` logic results in no columns,
68
+ * When present, regardless of the value, this option overrides the method's behavior when applying `skip` logic results in no columns,
69
69
  * i.e. when every column is being skipped.
70
70
  *
71
71
  * By default, in that situation the method throws {@link external:Error Error} = `Cannot generate an UPDATE without any columns.`
@@ -168,7 +168,7 @@ function update(data, columns, table, options, capSQL) {
168
168
  columns = new ColumnSet(columns || data);
169
169
  }
170
170
 
171
- options = assertOptions(options, [`tableAlias`, `valueAlias`, `emptyUpdate`]);
171
+ options = assert(options, [`tableAlias`, `valueAlias`, `emptyUpdate`]);
172
172
 
173
173
  const format = npm.formatting.as.format,
174
174
  useEmptyUpdate = `emptyUpdate` in options,
@@ -7,7 +7,7 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {assertOptions} = require(`assert-options`);
10
+ const {assert} = require(`../assert`);
11
11
 
12
12
  const npm = {
13
13
  utils: require(`../utils`),
@@ -65,7 +65,7 @@ class TableName {
65
65
  if (typeof table === `string`) {
66
66
  this.table = table;
67
67
  } else {
68
- const config = assertOptions(table, [`table`, `schema`]);
68
+ const config = assert(table, [`table`, `schema`]);
69
69
  this.table = config.table;
70
70
  if (npm.utils.isText(config.schema)) {
71
71
  this.schema = config.schema;
package/lib/main.js CHANGED
@@ -13,7 +13,7 @@ const {PreparedStatement, ParameterizedQuery} = require(`./types`);
13
13
  const {QueryFile} = require(`./query-file`);
14
14
  const {queryResult} = require(`./query-result`);
15
15
  const {parsePromise} = require(`./promise-parser`);
16
- const {assertOptions} = require(`assert-options`);
16
+ const {assert} = require(`./assert`);
17
17
 
18
18
  const npm = {
19
19
  path: require(`path`),
@@ -191,7 +191,7 @@ let originalClientConnect;
191
191
  */
192
192
  function $main(options) {
193
193
 
194
- options = assertOptions(options, [`pgFormatting`, `pgNative`, `promiseLib`, `noLocking`, `capSQL`, `noWarnings`,
194
+ options = assert(options, [`pgFormatting`, `pgNative`, `promiseLib`, `noLocking`, `capSQL`, `noWarnings`,
195
195
  `connect`, `disconnect`, `query`, `receive`, `task`, `transact`, `error`, `extend`, `schema`]);
196
196
 
197
197
  let pg = npm.pg;
@@ -7,7 +7,7 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {assertOptions} = require(`assert-options`);
10
+ const {assert} = require(`./assert`);
11
11
 
12
12
  /**
13
13
  * @class PromiseAdapter
@@ -58,7 +58,7 @@ class PromiseAdapter {
58
58
  throw new TypeError(`Adapter requires an api configuration object.`);
59
59
  }
60
60
 
61
- api = assertOptions(api, [`create`, `resolve`, `reject`, `all`]);
61
+ api = assert(api, [`create`, `resolve`, `reject`, `all`]);
62
62
 
63
63
  this.create = api.create;
64
64
  this.resolve = api.resolve;
package/lib/query-file.js CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  const {InnerState} = require(`./inner-state`);
11
11
  const {QueryFileError} = require(`./errors`);
12
- const {assertOptions} = require(`assert-options`);
12
+ const {assert} = require(`./assert`);
13
13
  const {ColorConsole} = require(`./utils/color`);
14
14
 
15
15
  const npm = {
@@ -106,7 +106,7 @@ class QueryFile extends InnerState {
106
106
 
107
107
  let filePath = file;
108
108
 
109
- options = assertOptions(options, {
109
+ options = assert(options, {
110
110
  debug: npm.utils.isDev(),
111
111
  minify: (options && options.compress && options.minify === undefined) ? true : undefined,
112
112
  compress: undefined,
package/lib/tx-mode.js CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  const {InnerState} = require(`./inner-state`);
11
11
  const {addInspection} = require(`./utils`);
12
- const {assertOptions} = require(`assert-options`);
12
+ const {assert} = require(`./assert`);
13
13
 
14
14
  /**
15
15
  * @enum {number}
@@ -103,7 +103,7 @@ const isolationLevel = {
103
103
  class TransactionMode extends InnerState {
104
104
 
105
105
  constructor(options) {
106
- options = assertOptions(options, [`tiLevel`, `deferrable`, `readOnly`]);
106
+ options = assert(options, [`tiLevel`, `deferrable`, `readOnly`]);
107
107
  const {readOnly, deferrable} = options;
108
108
  let {tiLevel} = options;
109
109
  let level, accessMode, deferrableMode, begin = `begin`;
@@ -10,7 +10,7 @@
10
10
  const {ServerFormatting} = require(`./server-formatting`);
11
11
  const {ParameterizedQueryError} = require(`../errors`);
12
12
  const {QueryFile} = require(`../query-file`);
13
- const {assertOptions} = require(`assert-options`);
13
+ const {assert} = require(`../assert`);
14
14
 
15
15
  const npm = {
16
16
  EOL: require(`os`).EOL,
@@ -91,7 +91,7 @@ class ParameterizedQuery extends ServerFormatting {
91
91
  text: options
92
92
  };
93
93
  } else {
94
- options = assertOptions(options, [`text`, `values`, `binary`, `rowMode`]);
94
+ options = assert(options, [`text`, `values`, `binary`, `rowMode`]);
95
95
  }
96
96
  super(options);
97
97
  }
@@ -10,7 +10,7 @@
10
10
  const {ServerFormatting} = require(`./server-formatting`);
11
11
  const {PreparedStatementError} = require(`../errors`);
12
12
  const {QueryFile} = require(`../query-file`);
13
- const {assertOptions} = require(`assert-options`);
13
+ const {assert} = require(`../assert`);
14
14
 
15
15
  const npm = {
16
16
  EOL: require(`os`).EOL,
@@ -89,7 +89,7 @@ const npm = {
89
89
  */
90
90
  class PreparedStatement extends ServerFormatting {
91
91
  constructor(options) {
92
- options = assertOptions(options, [`name`, `text`, `values`, `binary`, `rowMode`, `rows`]);
92
+ options = assert(options, [`name`, `text`, `values`, `binary`, `rowMode`, `rows`]);
93
93
  super(options);
94
94
  }
95
95
 
@@ -7,7 +7,7 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {assertOptions} = require(`assert-options`);
10
+ const {assert} = require(`../assert`);
11
11
 
12
12
  const npm = {
13
13
  fs: require(`fs`),
@@ -187,7 +187,7 @@ function enumSql(dir, options, cb) {
187
187
  if (!npm.utils.isText(dir)) {
188
188
  throw new TypeError(`Parameter 'dir' must be a non-empty text string.`);
189
189
  }
190
- options = assertOptions(options, [`recursive`, `ignoreErrors`]);
190
+ options = assert(options, [`recursive`, `ignoreErrors`]);
191
191
  cb = (typeof cb === `function`) ? cb : null;
192
192
  return _enumSql(dir, options, cb, ``);
193
193
  }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "10.14.0",
3
+ "version": "10.14.2",
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
- "test": "jasmine-node --captureExceptions test",
9
- "test:native": "jasmine-node test --config PG_NATIVE true",
10
- "doc": "jsdoc -c ./jsdoc/jsdoc.js ./jsdoc/README.md -t ./jsdoc/templates/custom",
8
+ "check-spelling": "cspell --config=.cspell.json \"**/*.{md,ts,js}\" --no-progress",
11
9
  "coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test",
10
+ "doc": "jsdoc -c ./jsdoc/jsdoc.js ./jsdoc/README.md -t ./jsdoc/templates/custom",
12
11
  "lint": "eslint ./lib ./test/*.js ./test/db --fix",
12
+ "test": "jasmine-node --captureExceptions test",
13
+ "test:native": "jasmine-node test --config PG_NATIVE true",
13
14
  "tslint": "tslint ./typescript/*.ts"
14
15
  },
15
16
  "files": [
@@ -39,7 +40,7 @@
39
40
  "node": ">=12.0"
40
41
  },
41
42
  "dependencies": {
42
- "assert-options": "0.7.0",
43
+ "assert-options": "0.8.0",
43
44
  "pg": "8.8.0",
44
45
  "pg-minify": "1.6.2",
45
46
  "spex": "3.2.0"
@@ -48,13 +49,14 @@
48
49
  "@types/node": "18.11.9",
49
50
  "bluebird": "3.7.2",
50
51
  "coveralls": "3.1.1",
52
+ "cspell": "6.14.2",
51
53
  "eslint": "8.27.0",
52
54
  "istanbul": "0.4.5",
53
55
  "jasmine-node": "3.0.0",
54
- "jsdoc": "4.0.0",
56
+ "jsdoc": "3.6.11",
55
57
  "JSONStream": "1.3.5",
56
58
  "pg-query-stream": "4.2.4",
57
59
  "tslint": "6.1.3",
58
- "typescript": "4.8.4"
60
+ "typescript": "4.9.3"
59
61
  }
60
62
  }
File without changes
@@ -21,6 +21,26 @@ import * as pg from './pg-subset';
21
21
  import * as pgMinify from 'pg-minify';
22
22
  import * as spexLib from 'spex';
23
23
 
24
+ // internal namespace for "txMode" property:
25
+ declare namespace _txMode {
26
+ // Transaction Isolation Level;
27
+ // API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel
28
+ enum isolationLevel {
29
+ none = 0,
30
+ serializable = 1,
31
+ repeatableRead = 2,
32
+ readCommitted = 3
33
+ }
34
+
35
+ // TransactionMode class;
36
+ // API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html
37
+ class TransactionMode {
38
+ constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean })
39
+
40
+ begin(cap?: boolean): string
41
+ }
42
+ }
43
+
24
44
  // Main protocol of the library;
25
45
  // API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html
26
46
  declare namespace pgPromise {
@@ -269,7 +289,7 @@ declare namespace pgPromise {
269
289
  constructor(api: IPromiseConfig)
270
290
  }
271
291
 
272
- const txMode: ITXMode;
292
+ const txMode: typeof _txMode;
273
293
  const utils: IUtils;
274
294
  const as: IFormatting;
275
295
 
@@ -311,7 +331,7 @@ declare namespace pgPromise {
311
331
  readonly spex: spexLib.ISpex
312
332
  readonly errors: typeof errors
313
333
  readonly utils: IUtils
314
- readonly txMode: ITXMode
334
+ readonly txMode: typeof txMode
315
335
  readonly helpers: IHelpers
316
336
  readonly as: IFormatting
317
337
  readonly pg: typeof pg
@@ -353,7 +373,7 @@ declare namespace pgPromise {
353
373
  any<T = any>(query: QueryParam, values?: any): XPromise<T[]>
354
374
 
355
375
  // API: http://vitaly-t.github.io/pg-promise/Database.html#result
356
- result<T = IResultExt>(query: QueryParam, values?: any, cb?: (value: IResultExt) => T, thisArg?: any): XPromise<T>
376
+ result<T, R = IResultExt<T>>(query: QueryParam, values?: any, cb?: (value: IResultExt<T>) => R, thisArg?: any): XPromise<R>
357
377
 
358
378
  // API: http://vitaly-t.github.io/pg-promise/Database.html#multiResult
359
379
  multiResult(query: QueryParam, values?: any): XPromise<pg.IResult[]>
@@ -398,7 +418,7 @@ declare namespace pgPromise {
398
418
 
399
419
  tx<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
400
420
 
401
- tx<T = any>(options: { tag?: any, mode?: TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
421
+ tx<T = any>(options: { tag?: any, mode?: _txMode.TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
402
422
 
403
423
  // Conditional Transactions;
404
424
  // API: http://vitaly-t.github.io/pg-promise/Database.html#txIf
@@ -406,7 +426,7 @@ declare namespace pgPromise {
406
426
 
407
427
  txIf<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
408
428
 
409
- txIf<T = any>(options: { tag?: any, mode?: TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
429
+ txIf<T = any>(options: { tag?: any, mode?: _txMode.TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
410
430
  }
411
431
 
412
432
  // Database object in connected state;
@@ -546,23 +566,6 @@ declare namespace pgPromise {
546
566
  }
547
567
  }
548
568
 
549
- // Transaction Isolation Level;
550
- // API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel
551
- enum isolationLevel {
552
- none = 0,
553
- serializable = 1,
554
- repeatableRead = 2,
555
- readCommitted = 3
556
- }
557
-
558
- // TransactionMode class;
559
- // API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html
560
- class TransactionMode {
561
- constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean })
562
-
563
- begin(cap?: boolean): string
564
- }
565
-
566
569
  // Library's Initialization Options
567
570
  // API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html
568
571
  interface IInitOptions<Ext = {}, C extends pg.IClient = pg.IClient> {
@@ -641,15 +644,8 @@ declare namespace pgPromise {
641
644
  value(value: any | (() => any)): string
642
645
  }
643
646
 
644
- // Transaction Mode namespace;
645
- // API: http://vitaly-t.github.io/pg-promise/txMode.html
646
- interface ITXMode {
647
- isolationLevel: typeof isolationLevel
648
- TransactionMode: typeof TransactionMode
649
- }
650
-
651
647
  interface ITaskArguments<T> extends IArguments {
652
- options: { tag?: any, cnd?: any, mode?: TransactionMode | null } & T
648
+ options: { tag?: any, cnd?: any, mode?: _txMode.TransactionMode | null } & T
653
649
 
654
650
  cb(): any
655
651
  }