@prairielearn/postgres 1.9.4 → 2.0.1

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/src/pool.test.ts CHANGED
@@ -1,7 +1,8 @@
1
- import chai from 'chai';
2
- import chaiAsPromised from 'chai-as-promised';
3
1
  import { Writable } from 'node:stream';
4
2
  import { pipeline } from 'node:stream/promises';
3
+
4
+ import { use as chaiUse, assert } from 'chai';
5
+ import chaiAsPromised from 'chai-as-promised';
5
6
  import { z, ZodError } from 'zod';
6
7
 
7
8
  import {
@@ -14,11 +15,10 @@ import {
14
15
  callOptionalRow,
15
16
  queryCursor,
16
17
  queryValidatedCursor,
17
- } from './default-pool';
18
- import { makePostgresTestUtils } from './test-utils';
18
+ } from './default-pool.js';
19
+ import { makePostgresTestUtils } from './test-utils.js';
19
20
 
20
- chai.use(chaiAsPromised);
21
- const { assert } = chai;
21
+ chaiUse(chaiAsPromised);
22
22
 
23
23
  const postgresTestUtils = makePostgresTestUtils({
24
24
  database: 'prairielearn_postgres',
@@ -278,11 +278,11 @@ describe('@prairielearn/postgres', function () {
278
278
  const maybeError = await readAllRows().catch((err) => err);
279
279
  assert.instanceOf(maybeError, Error);
280
280
  assert.match(maybeError.message, /syntax error/);
281
- assert.isDefined(maybeError.data);
282
- assert.equal(maybeError.data.sql, 'NOT VALID SQL');
283
- assert.deepEqual(maybeError.data.sqlParams, { foo: 'bar' });
284
- assert.isDefined(maybeError.data.sqlError);
285
- assert.equal(maybeError.data.sqlError.severity, 'ERROR');
281
+ assert.isDefined((maybeError as any).data);
282
+ assert.equal((maybeError as any).data.sql, 'NOT VALID SQL');
283
+ assert.deepEqual((maybeError as any).data.sqlParams, { foo: 'bar' });
284
+ assert.isDefined((maybeError as any).data.sqlError);
285
+ assert.equal((maybeError as any).data.sqlError.severity, 'ERROR');
286
286
  });
287
287
  });
288
288
 
package/src/pool.ts CHANGED
@@ -1,12 +1,13 @@
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { Readable, Transform } from 'node:stream';
3
+ import { callbackify } from 'node:util';
4
+
5
+ import debugfn from 'debug';
1
6
  import _ from 'lodash';
7
+ import multipipe from 'multipipe';
2
8
  import pg, { QueryResult } from 'pg';
3
9
  import Cursor from 'pg-cursor';
4
- import debugFactory from 'debug';
5
- import { callbackify } from 'node:util';
6
- import { AsyncLocalStorage } from 'node:async_hooks';
7
10
  import { z } from 'zod';
8
- import { Readable, Transform } from 'node:stream';
9
- import multipipe from 'multipipe';
10
11
 
11
12
  export type QueryParams = Record<string, any> | any[];
12
13
 
@@ -15,7 +16,7 @@ export interface CursorIterator<T> {
15
16
  stream: (batchSize: number) => NodeJS.ReadWriteStream;
16
17
  }
17
18
 
18
- const debug = debugFactory('@prairielearn/postgres');
19
+ const debug = debugfn('@prairielearn/postgres');
19
20
  const lastQueryMap = new WeakMap<pg.PoolClient, string>();
20
21
  const searchSchemaMap = new WeakMap<pg.PoolClient, string>();
21
22
 
@@ -87,9 +88,9 @@ function paramsToArray(
87
88
  let paramsArray: any[] = [];
88
89
  while ((result = re.exec(remainingSql)) !== null) {
89
90
  const v = result[1];
90
- if (!_(map).has(v)) {
91
- if (!_(params).has(v)) throw new Error(`Missing parameter: ${v}`);
92
- if (_.isArray(params[v])) {
91
+ if (!(v in map)) {
92
+ if (!(v in params)) throw new Error(`Missing parameter: ${v}`);
93
+ if (Array.isArray(params[v])) {
93
94
  map[v] =
94
95
  'ARRAY[' +
95
96
  _.map(_.range(nParams + 1, nParams + params[v].length + 1), function (n) {
package/src/test-utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import pg from 'pg';
2
2
 
3
- import * as defaultPool from './default-pool';
3
+ import * as defaultPool from './default-pool.js';
4
4
 
5
5
  const POSTGRES_USER = 'postgres';
6
6
  const POSTGRES_HOST = 'localhost';