@prairielearn/postgres 2.1.7 → 2.1.9

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/postgres
2
2
 
3
+ ## 2.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 984dc62: Upgrade all JavaScript dependencies
8
+
9
+ ## 2.1.8
10
+
11
+ ### Patch Changes
12
+
13
+ - 49bb3fa: Upgrade all JavaScript dependencies
14
+
3
15
  ## 2.1.7
4
16
 
5
17
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { PostgresPool, type CursorIterator, type QueryParams } from './pool.js';
1
+ import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';
2
2
  declare const defaultPool: PostgresPool;
3
3
  export { defaultPool, type CursorIterator, type QueryParams };
4
4
  export declare const init: (arg1: import("./pool.js").PostgresPoolConfig, arg2: (error: Error, client: import("pg").PoolClient) => void, callback: (err: NodeJS.ErrnoException) => void) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"default-pool.js","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyC,MAAM,WAAW,CAAC;AAEhF,MAAM,WAAW,GAAG,IAAI,YAAY,EAAE,CAAC;AACvC,OAAO,EAAE,WAAW,EAAyC,CAAC;AAE9D,2EAA2E;AAC3E,6EAA6E;AAC7E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAA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Ae,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { PostgresPool, type CursorIterator, type QueryParams } from './pool.js';\n\nconst defaultPool = new PostgresPool();\nexport { defaultPool, type CursorIterator, type QueryParams };\n\n// We re-expose all functions from the default pool here to account for the\n// default case of a shared global pool of clients. If someone want to create\n// their own pool, we expose the `PostgresPool` class.\n//\n// Note that we explicitly bind all functions to `defaultPool`. This ensures\n// that they'll be invoked with the correct `this` context, specifically when\n// this module is imported as `import * as db from '...'` and that import is\n// subsequently transformed by Babel to `interopRequireWildcard(...)`.\nexport const init = defaultPool.init.bind(defaultPool);\nexport const initAsync = defaultPool.initAsync.bind(defaultPool);\nexport const close = defaultPool.close.bind(defaultPool);\nexport const closeAsync = defaultPool.closeAsync.bind(defaultPool);\nexport const getClientAsync = defaultPool.getClientAsync.bind(defaultPool);\nexport const getClient = defaultPool.getClient.bind(defaultPool);\nexport const queryWithClient = defaultPool.queryWithClient.bind(defaultPool);\nexport const queryWithClientAsync = defaultPool.queryWithClientAsync.bind(defaultPool);\nexport const queryWithClientOneRow = defaultPool.queryWithClientOneRow.bind(defaultPool);\nexport const queryWithClientOneRowAsync = defaultPool.queryWithClientOneRowAsync.bind(defaultPool);\nexport const queryWithClientZeroOrOneRow =\n defaultPool.queryWithClientZeroOrOneRow.bind(defaultPool);\nexport const queryWithClientZeroOrOneRowAsync =\n defaultPool.queryWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const rollbackWithClientAsync = defaultPool.rollbackWithClientAsync.bind(defaultPool);\nexport const rollbackWithClient = defaultPool.rollbackWithClient.bind(defaultPool);\nexport const beginTransactionAsync = defaultPool.beginTransactionAsync.bind(defaultPool);\nexport const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultPool);\nexport const endTransaction = defaultPool.endTransaction.bind(defaultPool);\nexport const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);\nexport const query = defaultPool.query.bind(defaultPool);\nexport const queryAsync = defaultPool.queryAsync.bind(defaultPool);\nexport const queryOneRow = defaultPool.queryOneRow.bind(defaultPool);\nexport const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);\nexport const queryZeroOrOneRow = defaultPool.queryZeroOrOneRow.bind(defaultPool);\nexport const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);\nexport const call = defaultPool.call.bind(defaultPool);\nexport const callAsync = defaultPool.callAsync.bind(defaultPool);\nexport const callOneRow = defaultPool.callOneRow.bind(defaultPool);\nexport const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);\nexport const callZeroOrOneRow = defaultPool.callZeroOrOneRow.bind(defaultPool);\nexport const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);\nexport const callWithClient = defaultPool.callWithClient.bind(defaultPool);\nexport const callWithClientAsync = defaultPool.callWithClientAsync.bind(defaultPool);\nexport const callWithClientOneRow = defaultPool.callWithClientOneRow.bind(defaultPool);\nexport const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);\nexport const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);\nexport const callWithClientZeroOrOneRowAsync =\n defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const queryValidatedRows = defaultPool.queryValidatedRows.bind(defaultPool);\nexport const queryValidatedOneRow = defaultPool.queryValidatedOneRow.bind(defaultPool);\nexport const queryValidatedZeroOrOneRow = defaultPool.queryValidatedZeroOrOneRow.bind(defaultPool);\nexport const queryValidatedSingleColumnRows =\n defaultPool.queryValidatedSingleColumnRows.bind(defaultPool);\nexport const queryValidatedSingleColumnOneRow =\n defaultPool.queryValidatedSingleColumnOneRow.bind(defaultPool);\nexport const queryValidatedSingleColumnZeroOrOneRow =\n defaultPool.queryValidatedSingleColumnZeroOrOneRow.bind(defaultPool);\nexport const callValidatedRows = defaultPool.callValidatedRows.bind(defaultPool);\nexport const callValidatedOneRow = defaultPool.callValidatedOneRow.bind(defaultPool);\nexport const callValidatedZeroOrOneRow = defaultPool.callValidatedZeroOrOneRow.bind(defaultPool);\nexport const queryRows = defaultPool.queryRows.bind(defaultPool);\nexport const queryRow = defaultPool.queryRow.bind(defaultPool);\nexport const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);\nexport const callRows = defaultPool.callRows.bind(defaultPool);\nexport const callRow = defaultPool.callRow.bind(defaultPool);\nexport const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);\nexport const queryCursorWithClient = defaultPool.queryCursorWithClient.bind(defaultPool);\nexport const queryCursor = defaultPool.queryCursor.bind(defaultPool);\nexport const queryValidatedCursor = defaultPool.queryValidatedCursor.bind(defaultPool);\nexport const setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);\nexport const getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchema = defaultPool.setRandomSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchemaAsync = defaultPool.setRandomSearchSchemaAsync.bind(defaultPool);\n"]}
1
+ {"version":3,"file":"default-pool.js","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAoB,MAAM,WAAW,CAAC;AAEhF,MAAM,WAAW,GAAG,IAAI,YAAY,EAAE,CAAC;AACvC,OAAO,EAAE,WAAW,EAAyC,CAAC;AAE9D,2EAA2E;AAC3E,6EAA6E;AAC7E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC,I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MAAM,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';\n\nconst defaultPool = new PostgresPool();\nexport { defaultPool, type CursorIterator, type QueryParams };\n\n// We re-expose all functions from the default pool here to account for the\n// default case of a shared global pool of clients. If someone want to create\n// their own pool, we expose the `PostgresPool` class.\n//\n// Note that we explicitly bind all functions to `defaultPool`. This ensures\n// that they'll be invoked with the correct `this` context, specifically when\n// this module is imported as `import * as db from '...'` and that import is\n// subsequently transformed by Babel to `interopRequireWildcard(...)`.\nexport const init = defaultPool.init.bind(defaultPool);\nexport const initAsync = defaultPool.initAsync.bind(defaultPool);\nexport const close = defaultPool.close.bind(defaultPool);\nexport const closeAsync = defaultPool.closeAsync.bind(defaultPool);\nexport const getClientAsync = defaultPool.getClientAsync.bind(defaultPool);\nexport const getClient = defaultPool.getClient.bind(defaultPool);\nexport const queryWithClient = defaultPool.queryWithClient.bind(defaultPool);\nexport const queryWithClientAsync = defaultPool.queryWithClientAsync.bind(defaultPool);\nexport const queryWithClientOneRow = defaultPool.queryWithClientOneRow.bind(defaultPool);\nexport const queryWithClientOneRowAsync = defaultPool.queryWithClientOneRowAsync.bind(defaultPool);\nexport const queryWithClientZeroOrOneRow =\n defaultPool.queryWithClientZeroOrOneRow.bind(defaultPool);\nexport const queryWithClientZeroOrOneRowAsync =\n defaultPool.queryWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const rollbackWithClientAsync = defaultPool.rollbackWithClientAsync.bind(defaultPool);\nexport const rollbackWithClient = defaultPool.rollbackWithClient.bind(defaultPool);\nexport const beginTransactionAsync = defaultPool.beginTransactionAsync.bind(defaultPool);\nexport const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultPool);\nexport const endTransaction = defaultPool.endTransaction.bind(defaultPool);\nexport const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);\nexport const query = defaultPool.query.bind(defaultPool);\nexport const queryAsync = defaultPool.queryAsync.bind(defaultPool);\nexport const queryOneRow = defaultPool.queryOneRow.bind(defaultPool);\nexport const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);\nexport const queryZeroOrOneRow = defaultPool.queryZeroOrOneRow.bind(defaultPool);\nexport const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);\nexport const call = defaultPool.call.bind(defaultPool);\nexport const callAsync = defaultPool.callAsync.bind(defaultPool);\nexport const callOneRow = defaultPool.callOneRow.bind(defaultPool);\nexport const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);\nexport const callZeroOrOneRow = defaultPool.callZeroOrOneRow.bind(defaultPool);\nexport const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);\nexport const callWithClient = defaultPool.callWithClient.bind(defaultPool);\nexport const callWithClientAsync = defaultPool.callWithClientAsync.bind(defaultPool);\nexport const callWithClientOneRow = defaultPool.callWithClientOneRow.bind(defaultPool);\nexport const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);\nexport const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);\nexport const callWithClientZeroOrOneRowAsync =\n defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const queryValidatedRows = defaultPool.queryValidatedRows.bind(defaultPool);\nexport const queryValidatedOneRow = defaultPool.queryValidatedOneRow.bind(defaultPool);\nexport const queryValidatedZeroOrOneRow = defaultPool.queryValidatedZeroOrOneRow.bind(defaultPool);\nexport const queryValidatedSingleColumnRows =\n defaultPool.queryValidatedSingleColumnRows.bind(defaultPool);\nexport const queryValidatedSingleColumnOneRow =\n defaultPool.queryValidatedSingleColumnOneRow.bind(defaultPool);\nexport const queryValidatedSingleColumnZeroOrOneRow =\n defaultPool.queryValidatedSingleColumnZeroOrOneRow.bind(defaultPool);\nexport const callValidatedRows = defaultPool.callValidatedRows.bind(defaultPool);\nexport const callValidatedOneRow = defaultPool.callValidatedOneRow.bind(defaultPool);\nexport const callValidatedZeroOrOneRow = defaultPool.callValidatedZeroOrOneRow.bind(defaultPool);\nexport const queryRows = defaultPool.queryRows.bind(defaultPool);\nexport const queryRow = defaultPool.queryRow.bind(defaultPool);\nexport const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);\nexport const callRows = defaultPool.callRows.bind(defaultPool);\nexport const callRow = defaultPool.callRow.bind(defaultPool);\nexport const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);\nexport const queryCursorWithClient = defaultPool.queryCursorWithClient.bind(defaultPool);\nexport const queryCursor = defaultPool.queryCursor.bind(defaultPool);\nexport const queryValidatedCursor = defaultPool.queryValidatedCursor.bind(defaultPool);\nexport const setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);\nexport const getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchema = defaultPool.setRandomSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchemaAsync = defaultPool.setRandomSearchSchemaAsync.bind(defaultPool);\n"]}
package/dist/pool.test.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Writable } from 'node:stream';
2
2
  import { pipeline } from 'node:stream/promises';
3
- import { use as chaiUse, assert } from 'chai';
3
+ import { assert, use as chaiUse } from 'chai';
4
4
  import chaiAsPromised from 'chai-as-promised';
5
- import { z, ZodError } from 'zod';
6
- import { queryAsync, queryRows, queryRow, queryOptionalRow, callRows, callRow, callOptionalRow, queryCursor, queryValidatedCursor, } from './default-pool.js';
5
+ import { ZodError, z } from 'zod';
6
+ import { callOptionalRow, callRow, callRows, queryAsync, queryCursor, queryOptionalRow, queryRow, queryRows, queryValidatedCursor, } from './default-pool.js';
7
7
  import { makePostgresTestUtils } from './test-utils.js';
8
8
  chaiUse(chaiAsPromised);
9
9
  const postgresTestUtils = makePostgresTestUtils({
@@ -1 +1 @@
1
- {"version":3,"file":"pool.test.js","sourceRoot":"","sources":["../src/pool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,EACL,UAAU,EACV,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,eAAe,EACf,WAAW,EACX,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,CAAC,cAAc,CAAC,CAAC;AAExB,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;IAC9C,QAAQ,EAAE,uBAAuB;CAClC,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE;CACrB,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,MAA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oB,CAAC,2BAA2B,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;gBAC5F,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEhC,MAAM,IAAI,GAAU,EAAE,CAAC;gBACvB,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;gBACjC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;oBAC5B,UAAU,EAAE,IAAI;oBAChB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ;wBAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAEjB,qEAAqE;wBACrE,oEAAoE;wBACpE,yCAAyC;wBACzC,EAAE,CAAC,KAAK,EAAE,CAAC;wBACX,QAAQ,EAAE,CAAC;oBACb,CAAC;iBACF,CAAC,CAAC;gBAEH,MAAM,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBAC3E,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Writable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport { use as chaiUse, assert } from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport { z, ZodError } from 'zod';\n\nimport {\n queryAsync,\n queryRows,\n queryRow,\n queryOptionalRow,\n callRows,\n callRow,\n callOptionalRow,\n queryCursor,\n queryValidatedCursor,\n} from './default-pool.js';\nimport { makePostgresTestUtils } from './test-utils.js';\n\nchaiUse(chaiAsPromised);\n\nconst postgresTestUtils = makePostgresTestUtils({\n database: 'prairielearn_postgres',\n});\n\nconst WorkspaceSchema = z.object({\n id: z.string(),\n created_at: z.date(),\n});\n\nconst SprocTwoColumnsSchema = z.object({\n id: z.string(),\n negative: z.number(),\n});\n\ndescribe('@prairielearn/postgres', function () {\n before(async () => {\n await postgresTestUtils.createDatabase();\n await queryAsync(\n 'CREATE TABLE workspaces (id BIGSERIAL PRIMARY KEY, created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP);',\n {},\n );\n await queryAsync('INSERT INTO workspaces (id) SELECT s FROM generate_series(1, 100) AS s', {});\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column(num_entries INT) RETURNS TABLE (id BIGINT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id FROM generate_series(1, num_entries) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_two_columns(num_entries INT) RETURNS TABLE (id BIGINT, negative INT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id, -s AS negative FROM generate_series(1, num_entries) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column_ten_rows() RETURNS TABLE (id BIGINT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id FROM generate_series(1, 10) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column_one_row(OUT id BIGINT) AS $$ BEGIN id = 1; END; $$ LANGUAGE plpgsql;',\n {},\n );\n });\n\n after(async () => {\n await postgresTestUtils.dropDatabase();\n });\n\n describe('paramsToArray', () => {\n it('enforces SQL must be a string', async () => {\n // @ts-expect-error SQL must be a string\n const rows = queryAsync({ invalid: true }, {});\n await assert.isRejected(rows, 'SQL must be a string');\n });\n\n it('enforces params must be array or object', async () => {\n // @ts-expect-error params must be an array or object\n const rows = queryAsync('SELECT 33;', 33);\n await assert.isRejected(rows, 'params must be array or object');\n });\n\n it('rejects missing parameters', async () => {\n const rows = queryAsync('SELECT $missing;', {});\n await assert.isRejected(rows, 'Missing parameter');\n });\n\n it('rejects unused parameters in testing', async () => {\n const rows = queryAsync('SELECT 33;', { unsed_parameter: true });\n await assert.isRejected(rows, 'Unused parameter');\n });\n });\n\n describe('queryRows', () => {\n it('handles single column', async () => {\n const rows = await queryRows('SELECT id FROM workspaces WHERE id <= 10;', z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles multiple columns', async () => {\n const rows = await queryRows('SELECT * FROM workspaces WHERE id <= 10;', WorkspaceSchema);\n assert.lengthOf(rows, 10);\n assert.equal(rows[0].id, '1');\n assert.isNotNull(rows[0].created_at);\n });\n\n it('handles parameters', async () => {\n const rows = await queryRows(\n 'SELECT * FROM workspaces WHERE id <= $1;',\n [10],\n WorkspaceSchema,\n );\n assert.lengthOf(rows, 10);\n });\n });\n\n describe('queryRow', () => {\n it('handles single column', async () => {\n const row = await queryRow('SELECT id FROM workspaces WHERE id = 1;', z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await queryRow('SELECT * FROM workspaces WHERE id = 1;', WorkspaceSchema);\n assert.equal(row.id, '1');\n assert.isNotNull(row.created_at);\n });\n\n it('handles parameters', async () => {\n const row = await queryRow('SELECT * FROM workspaces WHERE id = $1;', [1], WorkspaceSchema);\n assert.equal(row.id, '1');\n });\n\n it('rejects results with zero rows', async () => {\n const rows = queryRow('SELECT * FROM workspaces WHERE id = -1;', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 0');\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = queryRow('SELECT * FROM workspaces', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('queryOptionalRow', () => {\n it('handles single column', async () => {\n const row = await queryRow('SELECT id FROM workspaces WHERE id = 1;', z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await queryOptionalRow('SELECT * FROM workspaces WHERE id = 1;', WorkspaceSchema);\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n assert.isNotNull(row?.created_at);\n });\n\n it('handles parameters', async () => {\n const row = await queryOptionalRow(\n 'SELECT * FROM workspaces WHERE id = $1;',\n [1],\n WorkspaceSchema,\n );\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n });\n\n it('handles missing result', async () => {\n const row = await queryOptionalRow(\n 'SELECT * FROM workspaces WHERE id = -1;',\n WorkspaceSchema,\n );\n assert.isNull(row);\n });\n\n it('rejects with multiple rows', async () => {\n const rows = queryOptionalRow('SELECT * FROM workspaces', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('callRows', () => {\n it('handles single column', async () => {\n const rows = await callRows('test_sproc_one_column_ten_rows', z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles parameters', async () => {\n const rows = await callRows('test_sproc_one_column', [10], z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles multiple columns', async () => {\n const rows = await callRows('test_sproc_two_columns', [20], SprocTwoColumnsSchema);\n assert.lengthOf(rows, 20);\n assert.equal(rows[0].id, '1');\n assert.equal(rows[0].negative, -1);\n assert.equal(rows[19].id, '20');\n assert.equal(rows[19].negative, -20);\n });\n });\n\n describe('callRow', () => {\n it('handles single column', async () => {\n const row = await callRow('test_sproc_one_column_one_row', z.string());\n assert.equal(row, '1');\n });\n\n it('handles parameters', async () => {\n const row = await callRow('test_sproc_one_column', [1], z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await callRow('test_sproc_two_columns', [1], SprocTwoColumnsSchema);\n assert.equal(row.id, '1');\n assert.equal(row.negative, -1);\n });\n\n it('rejects results with zero rows', async () => {\n const row = callRow('test_sproc_two_columns', [0], SprocTwoColumnsSchema);\n await assert.isRejected(row, 'Incorrect rowCount: 0');\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = callRow('test_sproc_two_columns', [100], SprocTwoColumnsSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('callOptionalRow', () => {\n it('handles single column', async () => {\n const row = await callOptionalRow('test_sproc_one_column_one_row', z.string());\n assert.equal(row, '1');\n });\n\n it('handles parameters', async () => {\n const row = await callOptionalRow('test_sproc_one_column', [1], z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await callOptionalRow('test_sproc_two_columns', [1], SprocTwoColumnsSchema);\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n assert.equal(row?.negative, -1);\n });\n\n it('handles results with zero rows', async () => {\n const row = await callOptionalRow('test_sproc_two_columns', [0], SprocTwoColumnsSchema);\n assert.isNull(row);\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = callOptionalRow('test_sproc_two_columns', [100], SprocTwoColumnsSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('queryCursor', () => {\n it('returns zero rows', async () => {\n const cursor = await queryCursor('SELECT * FROM workspaces WHERE id = 10000;', {});\n const rowBatches = [];\n for await (const rows of cursor.iterate(10)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 0);\n });\n\n it('returns one row at a time', async () => {\n const cursor = await queryCursor('SELECT * FROM workspaces WHERE id <= 2;', {});\n const rowBatches = [];\n for await (const rows of cursor.iterate(1)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 2);\n assert.lengthOf(rowBatches[0], 1);\n assert.lengthOf(rowBatches[1], 1);\n });\n\n it('returns all rows at once', async () => {\n const cursor = queryCursor('SELECT * FROM workspaces WHERE id <= 10;', {});\n const rowBatches = [];\n for await (const rows of (await cursor).iterate(10)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 1);\n assert.lengthOf(rowBatches[0], 10);\n });\n\n it('handles errors', async () => {\n const cursor = await queryCursor('NOT VALID SQL', {});\n\n async function readAllRows() {\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, Error);\n assert.match(maybeError.message, /syntax error/);\n assert.isDefined((maybeError as any).data);\n assert.equal((maybeError as any).data.sql, 'NOT VALID SQL');\n assert.deepEqual((maybeError as any).data.sqlParams, {});\n assert.isDefined((maybeError as any).data.sqlError);\n assert.equal((maybeError as any).data.sqlError.severity, 'ERROR');\n });\n });\n\n describe('queryValidatedCursor', () => {\n const WorkspaceSchema = z.object({\n id: z.string(),\n });\n\n const BadWorkspaceSchema = z.object({\n badProperty: z.string(),\n });\n\n describe('iterator', () => {\n it('validates with provided schema', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n WorkspaceSchema,\n );\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n assert.lengthOf(allRows, 10);\n const workspace = allRows[0] as any;\n assert.equal(workspace.id, '1');\n assert.isUndefined(workspace.state);\n });\n\n it('throws error when validation fails', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n BadWorkspaceSchema,\n );\n\n async function readAllRows() {\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, ZodError);\n assert.lengthOf(maybeError.errors, 10);\n });\n });\n\n describe('stream', () => {\n it('validates with provided schema', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n WorkspaceSchema,\n );\n const stream = cursor.stream(1);\n const allRows = [];\n for await (const row of stream) {\n allRows.push(row);\n }\n\n assert.lengthOf(allRows, 10);\n });\n\n it('emits an error when validation fails', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces ORDER BY id ASC;',\n {},\n BadWorkspaceSchema,\n );\n const stream = cursor.stream(1);\n\n async function readAllRows() {\n const allRows = [];\n for await (const row of stream) {\n allRows.push(row);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, ZodError);\n assert.lengthOf(maybeError.errors, 1);\n });\n\n it('closes the cursor when the stream is closed', async () => {\n const cursor = await queryValidatedCursor('SELECT * FROM workspaces;', {}, WorkspaceSchema);\n const stream = cursor.stream(1);\n\n const rows: any[] = [];\n const ac = new AbortController();\n const writable = new Writable({\n objectMode: true,\n write(chunk, _encoding, callback) {\n rows.push(chunk);\n\n // After receiving the first row, abort the stream. This lets us test\n // that the underlying cursor is closed. If it is *not* closed, this\n // `after` hook will fail with a timeout.\n ac.abort();\n callback();\n },\n });\n\n await assert.isRejected(pipeline(stream, writable, { signal: ac.signal }));\n assert.lengthOf(rows, 1);\n });\n });\n });\n});\n"]}
1
+ {"version":3,"file":"pool.test.js","sourceRoot":"","sources":["../src/pool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAElC,OAAO,EACL,eAAe,EACf,OAAO,EACP,QAAQ,EACR,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,CAAC,cAAc,CAAC,CAAC;AAExB,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;IAC9C,QAAQ,EAAE,uBAAuB;CAClC,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,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MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;gBAC3D,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,2BAA2B,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;gBAC5F,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEhC,MAAM,IAAI,GAAU,EAAE,CAAC;gBACvB,MAAM,EAAE,GAAG,IAAI,eAAe,EAAE,CAAC;gBACjC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;oBAC5B,UAAU,EAAE,IAAI;oBAChB,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ;wBAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBAEjB,qEAAqE;wBACrE,oEAAoE;wBACpE,yCAAyC;wBACzC,EAAE,CAAC,KAAK,EAAE,CAAC;wBACX,QAAQ,EAAE,CAAC;oBACb,CAAC;iBACF,CAAC,CAAC;gBAEH,MAAM,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;gBAC3E,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { Writable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\n\nimport { assert, use as chaiUse } from 'chai';\nimport chaiAsPromised from 'chai-as-promised';\nimport { ZodError, z } from 'zod';\n\nimport {\n callOptionalRow,\n callRow,\n callRows,\n queryAsync,\n queryCursor,\n queryOptionalRow,\n queryRow,\n queryRows,\n queryValidatedCursor,\n} from './default-pool.js';\nimport { makePostgresTestUtils } from './test-utils.js';\n\nchaiUse(chaiAsPromised);\n\nconst postgresTestUtils = makePostgresTestUtils({\n database: 'prairielearn_postgres',\n});\n\nconst WorkspaceSchema = z.object({\n id: z.string(),\n created_at: z.date(),\n});\n\nconst SprocTwoColumnsSchema = z.object({\n id: z.string(),\n negative: z.number(),\n});\n\ndescribe('@prairielearn/postgres', function () {\n before(async () => {\n await postgresTestUtils.createDatabase();\n await queryAsync(\n 'CREATE TABLE workspaces (id BIGSERIAL PRIMARY KEY, created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP);',\n {},\n );\n await queryAsync('INSERT INTO workspaces (id) SELECT s FROM generate_series(1, 100) AS s', {});\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column(num_entries INT) RETURNS TABLE (id BIGINT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id FROM generate_series(1, num_entries) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_two_columns(num_entries INT) RETURNS TABLE (id BIGINT, negative INT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id, -s AS negative FROM generate_series(1, num_entries) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column_ten_rows() RETURNS TABLE (id BIGINT) AS $$ BEGIN RETURN QUERY SELECT s::BIGINT AS id FROM generate_series(1, 10) AS s; END; $$ LANGUAGE plpgsql;',\n {},\n );\n await queryAsync(\n 'CREATE FUNCTION test_sproc_one_column_one_row(OUT id BIGINT) AS $$ BEGIN id = 1; END; $$ LANGUAGE plpgsql;',\n {},\n );\n });\n\n after(async () => {\n await postgresTestUtils.dropDatabase();\n });\n\n describe('paramsToArray', () => {\n it('enforces SQL must be a string', async () => {\n // @ts-expect-error SQL must be a string\n const rows = queryAsync({ invalid: true }, {});\n await assert.isRejected(rows, 'SQL must be a string');\n });\n\n it('enforces params must be array or object', async () => {\n // @ts-expect-error params must be an array or object\n const rows = queryAsync('SELECT 33;', 33);\n await assert.isRejected(rows, 'params must be array or object');\n });\n\n it('rejects missing parameters', async () => {\n const rows = queryAsync('SELECT $missing;', {});\n await assert.isRejected(rows, 'Missing parameter');\n });\n\n it('rejects unused parameters in testing', async () => {\n const rows = queryAsync('SELECT 33;', { unsed_parameter: true });\n await assert.isRejected(rows, 'Unused parameter');\n });\n });\n\n describe('queryRows', () => {\n it('handles single column', async () => {\n const rows = await queryRows('SELECT id FROM workspaces WHERE id <= 10;', z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles multiple columns', async () => {\n const rows = await queryRows('SELECT * FROM workspaces WHERE id <= 10;', WorkspaceSchema);\n assert.lengthOf(rows, 10);\n assert.equal(rows[0].id, '1');\n assert.isNotNull(rows[0].created_at);\n });\n\n it('handles parameters', async () => {\n const rows = await queryRows(\n 'SELECT * FROM workspaces WHERE id <= $1;',\n [10],\n WorkspaceSchema,\n );\n assert.lengthOf(rows, 10);\n });\n });\n\n describe('queryRow', () => {\n it('handles single column', async () => {\n const row = await queryRow('SELECT id FROM workspaces WHERE id = 1;', z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await queryRow('SELECT * FROM workspaces WHERE id = 1;', WorkspaceSchema);\n assert.equal(row.id, '1');\n assert.isNotNull(row.created_at);\n });\n\n it('handles parameters', async () => {\n const row = await queryRow('SELECT * FROM workspaces WHERE id = $1;', [1], WorkspaceSchema);\n assert.equal(row.id, '1');\n });\n\n it('rejects results with zero rows', async () => {\n const rows = queryRow('SELECT * FROM workspaces WHERE id = -1;', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 0');\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = queryRow('SELECT * FROM workspaces', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('queryOptionalRow', () => {\n it('handles single column', async () => {\n const row = await queryRow('SELECT id FROM workspaces WHERE id = 1;', z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await queryOptionalRow('SELECT * FROM workspaces WHERE id = 1;', WorkspaceSchema);\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n assert.isNotNull(row?.created_at);\n });\n\n it('handles parameters', async () => {\n const row = await queryOptionalRow(\n 'SELECT * FROM workspaces WHERE id = $1;',\n [1],\n WorkspaceSchema,\n );\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n });\n\n it('handles missing result', async () => {\n const row = await queryOptionalRow(\n 'SELECT * FROM workspaces WHERE id = -1;',\n WorkspaceSchema,\n );\n assert.isNull(row);\n });\n\n it('rejects with multiple rows', async () => {\n const rows = queryOptionalRow('SELECT * FROM workspaces', WorkspaceSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('callRows', () => {\n it('handles single column', async () => {\n const rows = await callRows('test_sproc_one_column_ten_rows', z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles parameters', async () => {\n const rows = await callRows('test_sproc_one_column', [10], z.string());\n assert.lengthOf(rows, 10);\n assert.equal(rows[0], '1');\n });\n\n it('handles multiple columns', async () => {\n const rows = await callRows('test_sproc_two_columns', [20], SprocTwoColumnsSchema);\n assert.lengthOf(rows, 20);\n assert.equal(rows[0].id, '1');\n assert.equal(rows[0].negative, -1);\n assert.equal(rows[19].id, '20');\n assert.equal(rows[19].negative, -20);\n });\n });\n\n describe('callRow', () => {\n it('handles single column', async () => {\n const row = await callRow('test_sproc_one_column_one_row', z.string());\n assert.equal(row, '1');\n });\n\n it('handles parameters', async () => {\n const row = await callRow('test_sproc_one_column', [1], z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await callRow('test_sproc_two_columns', [1], SprocTwoColumnsSchema);\n assert.equal(row.id, '1');\n assert.equal(row.negative, -1);\n });\n\n it('rejects results with zero rows', async () => {\n const row = callRow('test_sproc_two_columns', [0], SprocTwoColumnsSchema);\n await assert.isRejected(row, 'Incorrect rowCount: 0');\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = callRow('test_sproc_two_columns', [100], SprocTwoColumnsSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('callOptionalRow', () => {\n it('handles single column', async () => {\n const row = await callOptionalRow('test_sproc_one_column_one_row', z.string());\n assert.equal(row, '1');\n });\n\n it('handles parameters', async () => {\n const row = await callOptionalRow('test_sproc_one_column', [1], z.string());\n assert.equal(row, '1');\n });\n\n it('handles multiple columns', async () => {\n const row = await callOptionalRow('test_sproc_two_columns', [1], SprocTwoColumnsSchema);\n assert.isNotNull(row);\n assert.equal(row?.id, '1');\n assert.equal(row?.negative, -1);\n });\n\n it('handles results with zero rows', async () => {\n const row = await callOptionalRow('test_sproc_two_columns', [0], SprocTwoColumnsSchema);\n assert.isNull(row);\n });\n\n it('rejects results with multiple rows', async () => {\n const rows = callOptionalRow('test_sproc_two_columns', [100], SprocTwoColumnsSchema);\n await assert.isRejected(rows, 'Incorrect rowCount: 100');\n });\n });\n\n describe('queryCursor', () => {\n it('returns zero rows', async () => {\n const cursor = await queryCursor('SELECT * FROM workspaces WHERE id = 10000;', {});\n const rowBatches = [];\n for await (const rows of cursor.iterate(10)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 0);\n });\n\n it('returns one row at a time', async () => {\n const cursor = await queryCursor('SELECT * FROM workspaces WHERE id <= 2;', {});\n const rowBatches = [];\n for await (const rows of cursor.iterate(1)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 2);\n assert.lengthOf(rowBatches[0], 1);\n assert.lengthOf(rowBatches[1], 1);\n });\n\n it('returns all rows at once', async () => {\n const cursor = queryCursor('SELECT * FROM workspaces WHERE id <= 10;', {});\n const rowBatches = [];\n for await (const rows of (await cursor).iterate(10)) {\n rowBatches.push(rows);\n }\n assert.lengthOf(rowBatches, 1);\n assert.lengthOf(rowBatches[0], 10);\n });\n\n it('handles errors', async () => {\n const cursor = await queryCursor('NOT VALID SQL', {});\n\n async function readAllRows() {\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, Error);\n assert.match(maybeError.message, /syntax error/);\n assert.isDefined((maybeError as any).data);\n assert.equal((maybeError as any).data.sql, 'NOT VALID SQL');\n assert.deepEqual((maybeError as any).data.sqlParams, {});\n assert.isDefined((maybeError as any).data.sqlError);\n assert.equal((maybeError as any).data.sqlError.severity, 'ERROR');\n });\n });\n\n describe('queryValidatedCursor', () => {\n const WorkspaceSchema = z.object({\n id: z.string(),\n });\n\n const BadWorkspaceSchema = z.object({\n badProperty: z.string(),\n });\n\n describe('iterator', () => {\n it('validates with provided schema', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n WorkspaceSchema,\n );\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n assert.lengthOf(allRows, 10);\n const workspace = allRows[0] as any;\n assert.equal(workspace.id, '1');\n assert.isUndefined(workspace.state);\n });\n\n it('throws error when validation fails', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n BadWorkspaceSchema,\n );\n\n async function readAllRows() {\n const allRows = [];\n for await (const rows of cursor.iterate(10)) {\n allRows.push(...rows);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, ZodError);\n assert.lengthOf(maybeError.errors, 10);\n });\n });\n\n describe('stream', () => {\n it('validates with provided schema', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces WHERE id <= 10 ORDER BY id ASC;',\n {},\n WorkspaceSchema,\n );\n const stream = cursor.stream(1);\n const allRows = [];\n for await (const row of stream) {\n allRows.push(row);\n }\n\n assert.lengthOf(allRows, 10);\n });\n\n it('emits an error when validation fails', async () => {\n const cursor = await queryValidatedCursor(\n 'SELECT * FROM workspaces ORDER BY id ASC;',\n {},\n BadWorkspaceSchema,\n );\n const stream = cursor.stream(1);\n\n async function readAllRows() {\n const allRows = [];\n for await (const row of stream) {\n allRows.push(row);\n }\n return allRows;\n }\n\n const maybeError = await readAllRows().catch((err) => err);\n assert.instanceOf(maybeError, ZodError);\n assert.lengthOf(maybeError.errors, 1);\n });\n\n it('closes the cursor when the stream is closed', async () => {\n const cursor = await queryValidatedCursor('SELECT * FROM workspaces;', {}, WorkspaceSchema);\n const stream = cursor.stream(1);\n\n const rows: any[] = [];\n const ac = new AbortController();\n const writable = new Writable({\n objectMode: true,\n write(chunk, _encoding, callback) {\n rows.push(chunk);\n\n // After receiving the first row, abort the stream. This lets us test\n // that the underlying cursor is closed. If it is *not* closed, this\n // `after` hook will fail with a timeout.\n ac.abort();\n callback();\n },\n });\n\n await assert.isRejected(pipeline(stream, writable, { signal: ac.signal }));\n assert.lengthOf(rows, 1);\n });\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@prairielearn/postgres",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "type": "module",
5
- "main": "./dist/index.js",
6
5
  "repository": {
7
6
  "type": "git",
8
7
  "url": "https://github.com/PrairieLearn/PrairieLearn.git",
9
8
  "directory": "packages/postgres"
10
9
  },
10
+ "main": "./dist/index.js",
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "dev": "tsc --watch --preserveWatchOutput",
@@ -15,26 +15,26 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@types/debug": "^4.1.12",
18
- "@types/lodash": "^4.17.15",
18
+ "@types/lodash": "^4.17.16",
19
19
  "@types/pg-cursor": "^2.7.2",
20
20
  "multipipe": "^4.0.0",
21
- "pg": "^8.13.1",
22
- "pg-cursor": "^2.12.1",
23
- "pg-pool": "^3.7.0",
24
- "pg-protocol": "^1.7.0",
25
- "zod": "^3.24.1"
21
+ "pg": "^8.14.1",
22
+ "pg-cursor": "^2.13.1",
23
+ "pg-pool": "^3.8.0",
24
+ "pg-protocol": "^1.8.0",
25
+ "zod": "^3.24.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@prairielearn/tsconfig": "^0.0.0",
29
29
  "@types/mocha": "^10.0.10",
30
30
  "@types/multipipe": "^3.0.5",
31
- "@types/node": "^20.17.16",
31
+ "@types/node": "^20.17.28",
32
32
  "c8": "^10.1.3",
33
- "chai": "^5.1.2",
33
+ "chai": "^5.2.0",
34
34
  "chai-as-promised": "^8.0.1",
35
- "mocha": "^10.8.2",
36
- "tsx": "^4.19.2",
37
- "typescript": "^5.7.3"
35
+ "mocha": "^11.1.0",
36
+ "tsx": "^4.19.3",
37
+ "typescript": "^5.8.2"
38
38
  },
39
39
  "c8": {
40
40
  "reporter": [
@@ -1,4 +1,4 @@
1
- import { PostgresPool, type CursorIterator, type QueryParams } from './pool.js';
1
+ import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';
2
2
 
3
3
  const defaultPool = new PostgresPool();
4
4
  export { defaultPool, type CursorIterator, type QueryParams };
package/src/pool.test.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  import { Writable } from 'node:stream';
2
2
  import { pipeline } from 'node:stream/promises';
3
3
 
4
- import { use as chaiUse, assert } from 'chai';
4
+ import { assert, use as chaiUse } from 'chai';
5
5
  import chaiAsPromised from 'chai-as-promised';
6
- import { z, ZodError } from 'zod';
6
+ import { ZodError, z } from 'zod';
7
7
 
8
8
  import {
9
- queryAsync,
10
- queryRows,
11
- queryRow,
12
- queryOptionalRow,
13
- callRows,
14
- callRow,
15
9
  callOptionalRow,
10
+ callRow,
11
+ callRows,
12
+ queryAsync,
16
13
  queryCursor,
14
+ queryOptionalRow,
15
+ queryRow,
16
+ queryRows,
17
17
  queryValidatedCursor,
18
18
  } from './default-pool.js';
19
19
  import { makePostgresTestUtils } from './test-utils.js';