@prairielearn/postgres 2.1.15 → 3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @prairielearn/postgres
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - b911b61: Remove deprecated validated query/call functions.
8
+
9
+ Users should replace `queryValidated*` (except for `queryValidatedCursor`) and `callValidated*` with the equivalent `query*` and `call*`, respectively. For queries returning multiple columns, these calls would be equivalent. For queries returning a single column, the schema needs to be updated to the column schema.
10
+
3
11
  ## 2.1.15
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -161,20 +161,6 @@ These functions have some behaviors that can make them more convenient to work w
161
161
  console.log(userNames);
162
162
  ```
163
163
 
164
- There are also a number of legacy functions available, though these are discouraged in new code.
165
-
166
- - `queryValidatedRows`
167
- - `queryValidatedOneRow`
168
- - `queryValidatedZeroOrOneRow`
169
- - `queryValidatedSingleColumnRows`
170
- - `queryValidatedSingleColumnOneRow`
171
- - `queryValidatedSingleColumnZeroOrOneRow`
172
- - `callValidatedRows`
173
- - `callValidatedOneRow`
174
- - `callValidatedZeroOrOneRow`
175
-
176
- For details on the behavior of these functions, see the source code.
177
-
178
164
  ### Transactions
179
165
 
180
166
  To use transactions, wrap your queries with the `runInTransactionAsync` function:
@@ -37,15 +37,6 @@ export declare const callWithClientOneRow: (arg1: import("pg").PoolClient, arg2:
37
37
  export declare const callWithClientOneRowAsync: (client: import("pg").default.PoolClient, functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
38
38
  export declare const callWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
39
39
  export declare const callWithClientZeroOrOneRowAsync: (client: import("pg").default.PoolClient, functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
40
- export declare const queryValidatedRows: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
41
- export declare const queryValidatedOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>>;
42
- export declare const queryValidatedZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
43
- export declare const queryValidatedSingleColumnRows: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
44
- export declare const queryValidatedSingleColumnOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>>;
45
- export declare const queryValidatedSingleColumnZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: QueryParams, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
46
- export declare const callValidatedRows: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model>[]>;
47
- export declare const callValidatedOneRow: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model>>;
48
- export declare const callValidatedZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model> | null>;
49
40
  export declare const queryRows: {
50
41
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
51
42
  <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>[]>;
@@ -45,15 +45,6 @@ export const callWithClientOneRow = defaultPool.callWithClientOneRow.bind(defaul
45
45
  export const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);
46
46
  export const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);
47
47
  export const callWithClientZeroOrOneRowAsync = defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);
48
- export const queryValidatedRows = defaultPool.queryValidatedRows.bind(defaultPool);
49
- export const queryValidatedOneRow = defaultPool.queryValidatedOneRow.bind(defaultPool);
50
- export const queryValidatedZeroOrOneRow = defaultPool.queryValidatedZeroOrOneRow.bind(defaultPool);
51
- export const queryValidatedSingleColumnRows = defaultPool.queryValidatedSingleColumnRows.bind(defaultPool);
52
- export const queryValidatedSingleColumnOneRow = defaultPool.queryValidatedSingleColumnOneRow.bind(defaultPool);
53
- export const queryValidatedSingleColumnZeroOrOneRow = defaultPool.queryValidatedSingleColumnZeroOrOneRow.bind(defaultPool);
54
- export const callValidatedRows = defaultPool.callValidatedRows.bind(defaultPool);
55
- export const callValidatedOneRow = defaultPool.callValidatedOneRow.bind(defaultPool);
56
- export const callValidatedZeroOrOneRow = defaultPool.callValidatedZeroOrOneRow.bind(defaultPool);
57
48
  export const queryRows = defaultPool.queryRows.bind(defaultPool);
58
49
  export const queryRow = defaultPool.queryRow.bind(defaultPool);
59
50
  export const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);
@@ -1 +1 @@
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,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;A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AAC,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"]}
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;AA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CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7D,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,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACrE,MAAM,CAAC,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 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.d.ts CHANGED
@@ -200,54 +200,6 @@ export declare class PostgresPool {
200
200
  * Errors if the function returns more than one row.
201
201
  */
202
202
  callWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
203
- /**
204
- * Wrapper around {@link queryAsync} that parses the resulting rows with the
205
- * given Zod schema. Returns only the rows of the query.
206
- */
207
- queryValidatedRows<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>[]>;
208
- /**
209
- * Wrapper around {@link queryOneRowAsync} that parses the resulting row with
210
- * the given Zod schema. Returns only a single row of the query.
211
- */
212
- queryValidatedOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>>;
213
- /**
214
- * Wrapper around {@link queryZeroOrOneRowAsync} that parses the resulting row
215
- * (if any) with the given Zod schema. Returns either a single row or `null`.
216
- */
217
- queryValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model> | null>;
218
- /**
219
- * Wrapper around {@link queryAsync} that validates that only one column is
220
- * returned and parses the data in it with the given Zod schema. Returns only
221
- * the single column of the query as an array.
222
- */
223
- queryValidatedSingleColumnRows<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>[]>;
224
- /**
225
- * Wrapper around {@link queryOneRowAsync} that validates that only one column
226
- * is returned and parses the data in it with the given Zod schema. Returns
227
- * only the single entry.
228
- */
229
- queryValidatedSingleColumnOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>>;
230
- /**
231
- * Wrapper around {@link queryZeroOrOneRowAsync} that validates that only one
232
- * column is returned and parses the data in it (if any) with the given Zod
233
- * schema. Returns either the single row of the query or `null`.
234
- */
235
- queryValidatedSingleColumnZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model> | null>;
236
- /**
237
- * Wrapper around {@link callAsync} that parses the resulting rows with the
238
- * given Zod schema. Returns only the rows.
239
- */
240
- callValidatedRows<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model>[]>;
241
- /**
242
- * Wrapper around {@link callOneRowAsync} that parses the resulting rows with
243
- * the given Zod schema. Returns only a single row.
244
- */
245
- callValidatedOneRow<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model>>;
246
- /**
247
- * Wrapper around {@link callZeroOrOneRowAsync} that parses the resulting row
248
- * (if any) with the given Zod schema. Returns at most a single row.
249
- */
250
- callValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model> | null>;
251
203
  queryRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;
252
204
  queryRows<Model extends z.ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<z.infer<Model>[]>;
253
205
  queryRow<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>>;
package/dist/pool.js CHANGED
@@ -637,109 +637,6 @@ export class PostgresPool {
637
637
  * Errors if the function returns more than one row.
638
638
  */
639
639
  callWithClientZeroOrOneRow = callbackify(this.callWithClientZeroOrOneRowAsync);
640
- /**
641
- * Wrapper around {@link queryAsync} that parses the resulting rows with the
642
- * given Zod schema. Returns only the rows of the query.
643
- */
644
- async queryValidatedRows(query, params, model) {
645
- const results = await this.queryAsync(query, params);
646
- return z.array(model).parse(results.rows);
647
- }
648
- /**
649
- * Wrapper around {@link queryOneRowAsync} that parses the resulting row with
650
- * the given Zod schema. Returns only a single row of the query.
651
- */
652
- async queryValidatedOneRow(query, params, model) {
653
- const results = await this.queryOneRowAsync(query, params);
654
- return model.parse(results.rows[0]);
655
- }
656
- /**
657
- * Wrapper around {@link queryZeroOrOneRowAsync} that parses the resulting row
658
- * (if any) with the given Zod schema. Returns either a single row or `null`.
659
- */
660
- async queryValidatedZeroOrOneRow(query, params, model) {
661
- const results = await this.queryZeroOrOneRowAsync(query, params);
662
- if (results.rows.length === 0) {
663
- return null;
664
- }
665
- else {
666
- return model.parse(results.rows[0]);
667
- }
668
- }
669
- /**
670
- * Wrapper around {@link queryAsync} that validates that only one column is
671
- * returned and parses the data in it with the given Zod schema. Returns only
672
- * the single column of the query as an array.
673
- */
674
- async queryValidatedSingleColumnRows(query, params, model) {
675
- const results = await this.queryAsync(query, params);
676
- if (results.fields.length !== 1) {
677
- throw new Error(`Expected one column, got ${results.fields.length}`);
678
- }
679
- const columnName = results.fields[0].name;
680
- const rawData = results.rows.map((row) => row[columnName]);
681
- return z.array(model).parse(rawData);
682
- }
683
- /**
684
- * Wrapper around {@link queryOneRowAsync} that validates that only one column
685
- * is returned and parses the data in it with the given Zod schema. Returns
686
- * only the single entry.
687
- */
688
- async queryValidatedSingleColumnOneRow(query, params, model) {
689
- const results = await this.queryOneRowAsync(query, params);
690
- if (results.fields.length !== 1) {
691
- throw new Error(`Expected one column, got ${results.fields.length}`);
692
- }
693
- const columnName = results.fields[0].name;
694
- return model.parse(results.rows[0][columnName]);
695
- }
696
- /**
697
- * Wrapper around {@link queryZeroOrOneRowAsync} that validates that only one
698
- * column is returned and parses the data in it (if any) with the given Zod
699
- * schema. Returns either the single row of the query or `null`.
700
- */
701
- async queryValidatedSingleColumnZeroOrOneRow(query, params, model) {
702
- const results = await this.queryZeroOrOneRowAsync(query, params);
703
- if (results.fields.length !== 1) {
704
- throw new Error(`Expected one column, got ${results.fields.length}`);
705
- }
706
- if (results.rows.length === 0) {
707
- return null;
708
- }
709
- else {
710
- const columnName = results.fields[0].name;
711
- return model.parse(results.rows[0][columnName]);
712
- }
713
- }
714
- /**
715
- * Wrapper around {@link callAsync} that parses the resulting rows with the
716
- * given Zod schema. Returns only the rows.
717
- */
718
- async callValidatedRows(sprocName, params, model) {
719
- const results = await this.callAsync(sprocName, params);
720
- return z.array(model).parse(results.rows);
721
- }
722
- /**
723
- * Wrapper around {@link callOneRowAsync} that parses the resulting rows with
724
- * the given Zod schema. Returns only a single row.
725
- */
726
- async callValidatedOneRow(sprocName, params, model) {
727
- const results = await this.callOneRowAsync(sprocName, params);
728
- return model.parse(results.rows[0]);
729
- }
730
- /**
731
- * Wrapper around {@link callZeroOrOneRowAsync} that parses the resulting row
732
- * (if any) with the given Zod schema. Returns at most a single row.
733
- */
734
- async callValidatedZeroOrOneRow(sprocName, params, model) {
735
- const results = await this.callZeroOrOneRowAsync(sprocName, params);
736
- if (results.rows.length === 0) {
737
- return null;
738
- }
739
- else {
740
- return model.parse(results.rows[0]);
741
- }
742
- }
743
640
  async queryRows(sql, paramsOrSchema, maybeModel) {
744
641
  const params = maybeModel === undefined ? {} : paramsOrSchema;
745
642
  const model = maybeModel === undefined ? paramsOrSchema : maybeModel;
package/dist/pool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,OAAO,MAAM,OAAO,CAAC;AAC5B,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,EAAE,EAAoB,MAAM,IAAI,CAAC;AAC1C,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAChD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAyB,CAAC;AAC1D,MAAM,eAAe,GAAG,IAAI,OAAO,EAAyB,CAAC;AAE7D,SAAS,cAAc,CAAC,GAAU,EAAE,IAAyB;IAC1D,GAAW,CAAC,IAAI,GAAG;QAClB,GAAG,CAAE,GAAW,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5B,GAAG,IAAI;KACR,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC/B,IAAI,CAAsB;IAEjC,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C;aAC1D,IAAI,CAAC,EAAE,CAAC,CAAC;QAEZ,0EAA0E;QAC1E,oDAAoD;QACpD,wFAAwF;QACxF,MAAM,MAAM,GAAG,GAAG,WAAW,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACvD,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,qBAAqB,GAAG,WAAW,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAErE,6CAA6C;IAC7C,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,sCAAsC;IACtC,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,EAAE,SAAS,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,0EAA0E;IAC1E,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,IAAI,EAAE,YAAY,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { Readable, Transform } from 'node:stream';\nimport { callbackify } from 'node:util';\n\nimport debugfn from 'debug';\nimport _ from 'lodash';\nimport multipipe from 'multipipe';\nimport pg, { type QueryResult } from 'pg';\nimport Cursor from 'pg-cursor';\nimport { DatabaseError } from 'pg-protocol';\nimport { z } from 'zod';\n\nexport type QueryParams = Record<string, any> | any[];\n\nexport interface CursorIterator<T> {\n iterate: (batchSize: number) => AsyncGenerator<T[]>;\n stream: (batchSize: number) => NodeJS.ReadWriteStream;\n}\n\nexport interface PostgresPoolConfig extends pg.PoolConfig {\n errorOnUnusedParameters?: boolean;\n}\n\nconst debug = debugfn('@prairielearn/postgres');\nconst lastQueryMap = new WeakMap<pg.PoolClient, string>();\nconst searchSchemaMap = new WeakMap<pg.PoolClient, string>();\n\nfunction addDataToError(err: Error, data: Record<string, any>): Error {\n (err as any).data = {\n ...((err as any).data ?? {}),\n ...data,\n };\n return err;\n}\n\nexport class PostgresError extends Error {\n public data: Record<string, any>;\n\n constructor(message: string, data: Record<string, any>) {\n super(message);\n this.data = data;\n this.name = 'PostgresError';\n }\n}\n\n/**\n * Formats a string for debugging.\n */\nfunction debugString(s: string): string {\n if (typeof s !== 'string') return 'NOT A STRING';\n s = s.replace(/\\n/g, '\\\\n');\n if (s.length > 78) s = s.substring(0, 75) + '...';\n s = '\"' + s + '\"';\n return s;\n}\n\n/**\n * Formats a set of params for debugging.\n */\nfunction debugParams(params: QueryParams): string {\n let s;\n try {\n s = JSON.stringify(params);\n } catch {\n s = 'CANNOT JSON STRINGIFY';\n }\n return debugString(s);\n}\n\n/**\n * Given an SQL string and params, creates an array of params and an SQL string\n * with any named dollar-sign placeholders replaced with parameters.\n */\nfunction paramsToArray(\n sql: string,\n params: QueryParams,\n errorOnUnusedParameters: boolean,\n): { processedSql: string; paramsArray: any } {\n if (typeof sql !== 'string') throw new Error('SQL must be a string');\n if (Array.isArray(params)) {\n return {\n processedSql: sql,\n paramsArray: params,\n };\n }\n if (params == null || typeof params !== 'object') {\n throw new Error('params must be array or object');\n }\n\n const re = /\\$([-_a-zA-Z0-9]+)/;\n let result;\n let processedSql = '';\n let remainingSql = sql;\n let nParams = 0;\n const map: Record<string, string> = {};\n let paramsArray: any[] = [];\n while ((result = re.exec(remainingSql)) !== null) {\n const v = result[1];\n if (!(v in map)) {\n if (!(v in params)) throw new Error(`Missing parameter: ${v}`);\n if (Array.isArray(params[v])) {\n map[v] = 'ARRAY[' + params[v].map((_, n) => '$' + (n + nParams + 1)).join(',') + ']';\n nParams += params[v].length;\n paramsArray = paramsArray.concat(params[v]);\n } else {\n nParams++;\n map[v] = '$' + nParams;\n paramsArray.push(params[v]);\n }\n }\n processedSql += remainingSql.substring(0, result.index) + map[v];\n remainingSql = remainingSql.substring(result.index + result[0].length);\n }\n processedSql += remainingSql;\n remainingSql = '';\n if (errorOnUnusedParameters) {\n const difference = _.difference(Object.keys(params), Object.keys(map));\n if (difference.length) {\n throw new Error(`Unused parameters in SQL query: ${JSON.stringify(difference)}`);\n }\n }\n return { processedSql, paramsArray };\n}\n\n/**\n * Escapes the given identifier for use in an SQL query. Useful for preventing\n * SQL injection.\n */\nfunction escapeIdentifier(identifier: string): string {\n // Note that as of 2021-06-29 escapeIdentifier() is undocumented. See:\n // https://github.com/brianc/node-postgres/pull/396\n // https://github.com/brianc/node-postgres/issues/1978\n // https://www.postgresql.org/docs/current/sql-syntax-lexical.html\n return pg.Client.prototype.escapeIdentifier(identifier);\n}\n\nfunction enhanceError(err: Error, sql: string, params: QueryParams): Error {\n // Copy the error so we don't end up with a circular reference in the\n // final error.\n const sqlError = { ...err };\n\n // `message` is a non-enumerable property, so we need to copy it manually to\n // the error object.\n sqlError.message = err.message;\n\n const errorHasPosition = err instanceof DatabaseError && err.position != null;\n\n return addDataToError(err, {\n sqlError,\n // If the error has a `position` field, we need to use the processed source\n // (where e.g. `$foobar` has been replaced with `$1`) so that the position\n // is accurate.\n sql: errorHasPosition ? paramsToArray(sql, params, false).processedSql : sql,\n sqlParams: params,\n });\n}\n\nexport class PostgresPool {\n /** The pool from which clients will be acquired. */\n private pool: pg.Pool | null = null;\n /**\n * We use this to propagate the client associated with the current transaction\n * to any nested queries. In the past, we had some nasty bugs associated with\n * the fact that we tried to acquire new clients inside of transactions, which\n * ultimately lead to a deadlock.\n */\n private alsClient = new AsyncLocalStorage<pg.PoolClient>();\n private searchSchema: string | null = null;\n /** Tracks the total number of queries executed by this pool. */\n private _queryCount = 0;\n private errorOnUnusedParameters = false;\n\n /**\n * Creates a new connection pool and attempts to connect to the database.\n */\n async initAsync(\n pgConfig: PostgresPoolConfig,\n idleErrorHandler: (error: Error, client: pg.PoolClient) => void,\n ): Promise<void> {\n this.errorOnUnusedParameters = pgConfig.errorOnUnusedParameters ?? false;\n this.pool = new pg.Pool(pgConfig);\n this.pool.on('error', function (err, client) {\n const lastQuery = lastQueryMap.get(client);\n idleErrorHandler(addDataToError(err, { lastQuery }), client);\n });\n this.pool.on('connect', (client) => {\n client.on('error', (err) => {\n const lastQuery = lastQueryMap.get(client);\n idleErrorHandler(addDataToError(err, { lastQuery }), client);\n });\n });\n this.pool.on('remove', (client) => {\n // This shouldn't be necessary, as `pg` currently allows clients to be\n // garbage collected after they're removed. However, if `pg` someday\n // starts reusing client objects across difference connections, this\n // will ensure that we re-set the search path when the client reconnects.\n searchSchemaMap.delete(client);\n });\n\n // Attempt to connect to the database so that we can fail quickly if\n // something isn't configured correctly.\n let retryCount = 0;\n const retryTimeouts = [500, 1000, 2000, 5000, 10000];\n while (retryCount <= retryTimeouts.length) {\n try {\n const client = await this.pool.connect();\n client.release();\n return;\n } catch (err: any) {\n if (retryCount === retryTimeouts.length) {\n throw new Error(\n `Could not connect to Postgres after ${retryTimeouts.length} attempts: ${err.message}`,\n );\n }\n\n const timeout = retryTimeouts[retryCount];\n retryCount++;\n await new Promise((resolve) => setTimeout(resolve, timeout));\n }\n }\n }\n\n /**\n * Creates a new connection pool and attempts to connect to the database.\n */\n init = callbackify(this.initAsync);\n\n /**\n * Closes the connection pool.\n */\n async closeAsync(): Promise<void> {\n if (!this.pool) return;\n await this.pool.end();\n this.pool = null;\n }\n\n /**\n * Closes the connection pool.\n */\n close = callbackify(this.closeAsync);\n\n /**\n * Gets a new client from the connection pool. If `err` is not null\n * then `client` and `done` are undefined. If `err` is null then\n * `client` is valid and can be used. The caller MUST call `done()` to\n * release the client, whether or not errors occurred while using\n * `client`. The client can call `done(truthy_value)` to force\n * destruction of the client, but this should not be used except in\n * unusual circumstances.\n */\n async getClientAsync(): Promise<pg.PoolClient> {\n if (!this.pool) {\n throw new Error('Connection pool is not open');\n }\n\n // If we're inside a transaction, we'll reuse the same client to avoid a\n // potential deadlock.\n const client = this.alsClient.getStore() ?? (await this.pool.connect());\n\n // If we're configured to use a particular schema, we'll store whether or\n // not the search path has already been configured for this particular\n // client. If we acquire a client and it's already had its search path\n // set, we can avoid setting it again since the search path will persist\n // for the life of the client.\n //\n // We do this check for each call to `getClient` instead of on\n // `pool.connect` so that we don't have to be really careful about\n // destroying old clients that were created before `setSearchSchema` was\n // called. Instead, we'll just check if the search path matches the\n // currently-desired schema, and if it's a mismatch (or doesn't exist\n // at all), we re-set it for the current client.\n //\n // Note that this accidentally supports changing the search_path on the fly,\n // although that's not something we currently do (or would be likely to do).\n // It does NOT support clearing the existing search schema - e.g.,\n // `setSearchSchema(null)` would not work as you expect. This is fine, as\n // that's not something we ever do in practice.\n const clientSearchSchema = searchSchemaMap.get(client);\n if (this.searchSchema != null && clientSearchSchema !== this.searchSchema) {\n const setSearchPathSql = `SET search_path TO ${escapeIdentifier(this.searchSchema)},public`;\n try {\n await this.queryWithClientAsync(client, setSearchPathSql, {});\n } catch (err) {\n client.release();\n throw err;\n }\n searchSchemaMap.set(client, this.searchSchema);\n }\n\n return client;\n }\n\n /**\n * Gets a new client from the connection pool.\n */\n getClient(callback: (error: Error | null, client?: pg.PoolClient, done?: () => void) => void) {\n this.getClientAsync()\n .then((client) => callback(null, client, client.release))\n .catch((err) => callback(err));\n }\n\n /**\n * Performs a query with the given client.\n */\n async queryWithClientAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<pg.QueryResult> {\n this._queryCount += 1;\n debug('queryWithClient()', 'sql:', debugString(sql));\n debug('queryWithClient()', 'params:', debugParams(params));\n const { processedSql, paramsArray } = paramsToArray(sql, params, this.errorOnUnusedParameters);\n try {\n lastQueryMap.set(client, processedSql);\n const result = await client.query(processedSql, paramsArray);\n debug('queryWithClient() success', 'rowCount:', result.rowCount);\n return result;\n } catch (err: any) {\n throw enhanceError(err, sql, params);\n }\n }\n\n /**\n * Performs a query with the given client.\n */\n queryWithClient = callbackify(this.queryWithClientAsync);\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n async queryWithClientOneRowAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<pg.QueryResult> {\n debug('queryWithClientOneRow()', 'sql:', debugString(sql));\n debug('queryWithClientOneRow()', 'params:', debugParams(params));\n const result = await this.queryWithClientAsync(client, sql, params);\n if (result.rowCount !== 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n result,\n });\n }\n debug('queryWithClientOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n queryWithClientOneRow = callbackify(this.queryWithClientOneRowAsync);\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n async queryWithClientZeroOrOneRowAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<QueryResult> {\n debug('queryWithClientZeroOrOneRow()', 'sql:', debugString(sql));\n debug('queryWithClientZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.queryWithClientAsync(client, sql, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n result,\n });\n }\n debug('queryWithClientZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n queryWithClientZeroOrOneRow = callbackify(this.queryWithClientZeroOrOneRowAsync);\n\n /**\n * Rolls back the current transaction for the given client.\n */\n async rollbackWithClientAsync(client: pg.PoolClient) {\n debug('rollbackWithClient()');\n // From https://node-postgres.com/features/transactions\n try {\n await client.query('ROLLBACK');\n // Only release the client if we weren't already inside a transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n } catch (err: any) {\n // If there was a problem rolling back the query, something is\n // seriously messed up. Return the error to the release() function to\n // close & remove this client from the pool. If you leave a client in\n // the pool with an unaborted transaction, weird and hard to diagnose\n // problems might happen.\n client.release(err);\n }\n }\n\n /**\n * Rolls back the current transaction for the given client.\n */\n rollbackWithClient(\n client: pg.PoolClient,\n _done: (release?: any) => void,\n callback: (err: Error | null) => void,\n ) {\n // Note that we can't use `util.callbackify` here because this function\n // has an additional unused `done` parameter for backwards compatibility.\n this.rollbackWithClientAsync(client)\n .then(() => callback(null))\n .catch((err) => callback(err));\n }\n\n /**\n * Begins a new transaction.\n */\n async beginTransactionAsync(): Promise<pg.PoolClient> {\n debug('beginTransaction()');\n const client = await this.getClientAsync();\n try {\n await this.queryWithClientAsync(client, 'START TRANSACTION;', {});\n return client;\n } catch (err) {\n await this.rollbackWithClientAsync(client);\n throw err;\n }\n }\n\n /**\n * Commits the transaction if err is null, otherwise rollbacks the transaction.\n * Also releases the client.\n */\n async endTransactionAsync(client: pg.PoolClient, err: Error | null | undefined) {\n debug('endTransaction()');\n if (err) {\n try {\n await this.rollbackWithClientAsync(client);\n } catch (rollbackErr: any) {\n throw addDataToError(rollbackErr, { prevErr: err, rollback: 'fail' });\n }\n\n // Even though we successfully rolled back the transaction, there was\n // still an error in the first place that necessitated a rollback. Re-throw\n // that error here so that everything downstream of here will know about it.\n throw addDataToError(err, { rollback: 'success' });\n } else {\n try {\n await this.queryWithClientAsync(client, 'COMMIT', {});\n } finally {\n // Only release the client if we aren't nested inside another transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n }\n }\n }\n\n /**\n * Commits the transaction if err is null, otherwise rollbacks the transaction.\n * Also releases the client.\n */\n endTransaction(\n client: pg.PoolClient,\n _done: (rollback?: any) => void,\n err: Error | null | undefined,\n callback: (error: Error | null) => void,\n ): void {\n this.endTransactionAsync(client, err)\n .then(() => callback(null))\n .catch((error) => callback(error));\n }\n\n /**\n * Runs the specified function inside of a transaction. The function will\n * receive a database client as an argument, but it can also make queries\n * as usual, and the correct client will be used automatically.\n *\n * The transaction will be rolled back if the function throws an error, and\n * will be committed otherwise.\n */\n async runInTransactionAsync<T>(fn: (client: pg.PoolClient) => Promise<T>): Promise<T> {\n // Check if we're already inside a transaction. If so, we won't start another one,\n // as Postgres doesn't support nested transactions.\n const client = this.alsClient.getStore();\n const isNestedTransaction = client !== undefined;\n const transactionClient = client ?? (await this.beginTransactionAsync());\n\n let result: T;\n try {\n result = await this.alsClient.run(transactionClient, () => fn(transactionClient));\n } catch (err: any) {\n if (!isNestedTransaction) {\n // If we're inside another transaction, we assume that the root transaction\n // will catch this error and roll back the transaction.\n await this.endTransactionAsync(transactionClient, err);\n }\n throw err;\n }\n\n if (!isNestedTransaction) {\n // If we're inside another transaction; don't commit it prematurely. Allow\n // the root transaction to commit it instead.\n //\n // Note that we don't invoke `endTransactionAsync` inside the `try` block\n // because we don't want an error thrown by it to trigger *another* call\n // to `endTransactionAsync` in the `catch` block.\n await this.endTransactionAsync(transactionClient, null);\n }\n\n return result;\n }\n\n /**\n * Executes a query with the specified parameters.\n */\n async queryAsync(sql: string, params: QueryParams): Promise<QueryResult> {\n debug('query()', 'sql:', debugString(sql));\n debug('query()', 'params:', debugParams(params));\n const client = await this.getClientAsync();\n try {\n return await this.queryWithClientAsync(client, sql, params);\n } finally {\n // Only release if we aren't nested in a transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n }\n }\n\n /**\n * Executes a query with the specified parameters.\n */\n query = callbackify(this.queryAsync);\n\n /**\n * Executes a query with the specified parameters. Errors if the query does\n * not return exactly one row.\n */\n async queryOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult> {\n debug('queryOneRow()', 'sql:', debugString(sql));\n debug('queryOneRow()', 'params:', debugParams(params));\n const result = await this.queryAsync(sql, params);\n if (result.rowCount !== 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n });\n }\n debug('queryOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Executes a query with the specified parameters. Errors if the query does\n * not return exactly one row.\n */\n queryOneRow = callbackify(this.queryOneRowAsync);\n\n /**\n * Executes a query with the specified parameters. Errors if the query\n * returns more than one row.\n */\n async queryZeroOrOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult> {\n debug('queryZeroOrOneRow()', 'sql:', debugString(sql));\n debug('queryZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.queryAsync(sql, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n });\n }\n debug('queryZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Executes a query with the specified parameters. Errors if the query\n * returns more than one row.\n */\n queryZeroOrOneRow = callbackify(this.queryZeroOrOneRowAsync);\n\n /**\n * Calls the given function with the specified parameters.\n */\n async callAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('call()', 'function:', functionName);\n debug('call()', 'params:', debugParams(params));\n const placeholders = params.map((_, v) => '$' + (v + 1)).join();\n const sql = `SELECT * FROM ${escapeIdentifier(functionName)}(${placeholders});`;\n const result = await this.queryAsync(sql, params);\n debug('call() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters.\n */\n call = callbackify(this.callAsync);\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function does not return exactly one row.\n */\n async callOneRowAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('callOneRow()', 'function:', functionName);\n debug('callOneRow()', 'params:', debugParams(params));\n const result = await this.callAsync(functionName, params);\n if (result.rowCount !== 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function does not return exactly one row.\n */\n callOneRow = callbackify(this.callOneRowAsync);\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function returns more than one row.\n */\n async callZeroOrOneRowAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('callZeroOrOneRow()', 'function:', functionName);\n debug('callZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.callAsync(functionName, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function returns more than one row.\n */\n callZeroOrOneRow = callbackify(this.callZeroOrOneRowAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n */\n async callWithClientAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClient()', 'function:', functionName);\n debug('callWithClient()', 'params:', debugParams(params));\n const placeholders = params.map((_, v) => '$' + (v + 1)).join();\n const sql = `SELECT * FROM ${escapeIdentifier(functionName)}(${placeholders})`;\n const result = await this.queryWithClientAsync(client, sql, params);\n debug('callWithClient() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n */\n callWithClient = callbackify(this.callWithClientAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function does not return exactly one row.\n */\n async callWithClientOneRowAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClientOneRow()', 'function:', functionName);\n debug('callWithClientOneRow()', 'params:', debugParams(params));\n const result = await this.callWithClientAsync(client, functionName, params);\n if (result.rowCount !== 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callWithClientOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function does not return exactly one row.\n */\n callWithClientOneRow = callbackify(this.callWithClientOneRowAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function returns more than one row.\n */\n async callWithClientZeroOrOneRowAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClientZeroOrOneRow()', 'function:', functionName);\n debug('callWithClientZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.callWithClientAsync(client, functionName, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callWithClientZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function returns more than one row.\n */\n callWithClientZeroOrOneRow = callbackify(this.callWithClientZeroOrOneRowAsync);\n\n /**\n * Wrapper around {@link queryAsync} that parses the resulting rows with the\n * given Zod schema. Returns only the rows of the query.\n */\n async queryValidatedRows<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>[]> {\n const results = await this.queryAsync(query, params);\n return z.array(model).parse(results.rows);\n }\n\n /**\n * Wrapper around {@link queryOneRowAsync} that parses the resulting row with\n * the given Zod schema. Returns only a single row of the query.\n */\n async queryValidatedOneRow<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>> {\n const results = await this.queryOneRowAsync(query, params);\n return model.parse(results.rows[0]);\n }\n\n /**\n * Wrapper around {@link queryZeroOrOneRowAsync} that parses the resulting row\n * (if any) with the given Zod schema. Returns either a single row or `null`.\n */\n async queryValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model> | null> {\n const results = await this.queryZeroOrOneRowAsync(query, params);\n if (results.rows.length === 0) {\n return null;\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n /**\n * Wrapper around {@link queryAsync} that validates that only one column is\n * returned and parses the data in it with the given Zod schema. Returns only\n * the single column of the query as an array.\n */\n async queryValidatedSingleColumnRows<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>[]> {\n const results = await this.queryAsync(query, params);\n if (results.fields.length !== 1) {\n throw new Error(`Expected one column, got ${results.fields.length}`);\n }\n const columnName = results.fields[0].name;\n const rawData = results.rows.map((row) => row[columnName]);\n return z.array(model).parse(rawData);\n }\n\n /**\n * Wrapper around {@link queryOneRowAsync} that validates that only one column\n * is returned and parses the data in it with the given Zod schema. Returns\n * only the single entry.\n */\n async queryValidatedSingleColumnOneRow<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>> {\n const results = await this.queryOneRowAsync(query, params);\n if (results.fields.length !== 1) {\n throw new Error(`Expected one column, got ${results.fields.length}`);\n }\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n }\n\n /**\n * Wrapper around {@link queryZeroOrOneRowAsync} that validates that only one\n * column is returned and parses the data in it (if any) with the given Zod\n * schema. Returns either the single row of the query or `null`.\n */\n async queryValidatedSingleColumnZeroOrOneRow<Model extends z.ZodTypeAny>(\n query: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model> | null> {\n const results = await this.queryZeroOrOneRowAsync(query, params);\n if (results.fields.length !== 1) {\n throw new Error(`Expected one column, got ${results.fields.length}`);\n }\n if (results.rows.length === 0) {\n return null;\n } else {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n }\n }\n\n /**\n * Wrapper around {@link callAsync} that parses the resulting rows with the\n * given Zod schema. Returns only the rows.\n */\n async callValidatedRows<Model extends z.ZodTypeAny>(\n sprocName: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>[]> {\n const results = await this.callAsync(sprocName, params);\n return z.array(model).parse(results.rows);\n }\n\n /**\n * Wrapper around {@link callOneRowAsync} that parses the resulting rows with\n * the given Zod schema. Returns only a single row.\n */\n async callValidatedOneRow<Model extends z.ZodTypeAny>(\n sprocName: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>> {\n const results = await this.callOneRowAsync(sprocName, params);\n return model.parse(results.rows[0]);\n }\n\n /**\n * Wrapper around {@link callZeroOrOneRowAsync} that parses the resulting row\n * (if any) with the given Zod schema. Returns at most a single row.\n */\n async callValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(\n sprocName: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model> | null> {\n const results = await this.callZeroOrOneRowAsync(sprocName, params);\n if (results.rows.length === 0) {\n return null;\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async queryRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;\n async queryRows<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>[]>;\n async queryRows<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n const rawData = results.rows.map((row) => row[columnName]);\n return z.array(model).parse(rawData);\n } else {\n return z.array(model).parse(results.rows);\n }\n }\n\n async queryRow<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>>;\n async queryRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>>;\n async queryRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryOneRowAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryZeroOrOneRowAsync(sql, params);\n if (results.rows.length === 0) {\n return null;\n } else if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async callRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;\n async callRows<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>[]>;\n async callRows<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n const rawData = results.rows.map((row) => row[columnName]);\n return z.array(model).parse(rawData);\n } else {\n return z.array(model).parse(results.rows);\n }\n }\n\n async callRow<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>>;\n async callRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>>;\n async callRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callOneRowAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callZeroOrOneRowAsync(sql, params);\n if (results.rows.length === 0) {\n return null;\n } else if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n /**\n * Returns a {@link Cursor} for the given query. The cursor can be used to\n * read results in batches, which is useful for large result sets.\n */\n async queryCursorWithClient(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<Cursor> {\n this._queryCount += 1;\n debug('queryCursorWithClient()', 'sql:', debugString(sql));\n debug('queryCursorWithClient()', 'params:', debugParams(params));\n const { processedSql, paramsArray } = paramsToArray(sql, params, this.errorOnUnusedParameters);\n lastQueryMap.set(client, processedSql);\n return client.query(new Cursor(processedSql, paramsArray));\n }\n\n /**\n * Returns an {@link CursorIterator} that can be used to iterate over the\n * results of the query in batches, which is useful for large result sets.\n */\n async queryCursor<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n ): Promise<CursorIterator<z.infer<Model>>> {\n return this.queryValidatedCursorInternal(sql, params);\n }\n\n /**\n * Returns an {@link CursorIterator} that can be used to iterate over the\n * results of the query in batches, which is useful for large result sets.\n * Each row will be parsed by the given Zod schema.\n */\n async queryValidatedCursor<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<CursorIterator<z.infer<Model>>> {\n return this.queryValidatedCursorInternal(sql, params, model);\n }\n\n private async queryValidatedCursorInternal<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model?: Model,\n ): Promise<CursorIterator<z.infer<Model>>> {\n const client = await this.getClientAsync();\n const cursor = await this.queryCursorWithClient(client, sql, params);\n\n let iterateCalled = false;\n const iterator: CursorIterator<z.infer<Model>> = {\n async *iterate(batchSize: number) {\n // Safety check: if someone calls iterate multiple times, they're\n // definitely doing something wrong.\n if (iterateCalled) {\n throw new Error('iterate() called multiple times');\n }\n iterateCalled = true;\n\n try {\n while (true) {\n const rows = await cursor.read(batchSize);\n if (rows.length === 0) {\n break;\n }\n\n if (model) {\n yield z.array(model).parse(rows);\n } else {\n yield rows;\n }\n }\n } catch (err: any) {\n throw enhanceError(err, sql, params);\n } finally {\n try {\n await cursor.close();\n } finally {\n client.release();\n }\n }\n },\n stream(batchSize: number) {\n const transform = new Transform({\n readableObjectMode: true,\n writableObjectMode: true,\n transform(chunk, _encoding, callback) {\n for (const row of chunk) {\n this.push(row);\n }\n callback();\n },\n });\n\n // TODO: use native `node:stream#compose` once it's stable.\n const generator = iterator.iterate(batchSize);\n const pipe = multipipe(Readable.from(generator), transform);\n\n // When the underlying stream is closed, we need to make sure that the\n // cursor is also closed. We do this by calling `return()` on the generator,\n // which will trigger its `finally` block, which will in turn release\n // the client and close the cursor. The fact that the stream is already\n // closed by this point means that someone reading from the stream will\n // never actually see the `null` value that's returned.\n pipe.once('close', () => {\n generator.return(null);\n });\n\n return pipe;\n },\n };\n return iterator;\n }\n\n /**\n * Set the schema to use for the search path.\n *\n * @param schema The schema name to use (can be \"null\" to unset the search path)\n */\n async setSearchSchema(schema: string) {\n if (schema == null) {\n this.searchSchema = schema;\n return;\n }\n\n await this.queryAsync(`CREATE SCHEMA IF NOT EXISTS ${escapeIdentifier(schema)}`, {});\n // We only set searchSchema after CREATE to avoid the above query() call using searchSchema.\n this.searchSchema = schema;\n }\n\n /**\n * Get the schema that is currently used for the search path.\n *\n * @return schema in use (may be `null` to indicate no schema)\n */\n getSearchSchema(): string | null {\n return this.searchSchema;\n }\n\n /**\n * Generate, set, and return a random schema name.\n *\n * @param prefix The prefix of the new schema, only the first 28 characters will be used (after lowercasing).\n * @returns The randomly-generated search schema.\n */\n async setRandomSearchSchemaAsync(prefix: string): Promise<string> {\n // truncated prefix (max 28 characters)\n const truncPrefix = prefix.substring(0, 28);\n // timestamp in format YYYY-MM-DDTHH:MM:SS.SSSZ (guaranteed to not exceed 27 characters in the spec)\n const timestamp = new Date().toISOString();\n // random 6-character suffix to avoid clashes (approx 2 billion possible values)\n const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n const suffix = Array.from({ length: 6 })\n .map(() => chars[Math.floor(Math.random() * chars.length)])\n .join('');\n\n // Schema is guaranteed to have length at most 63 (= 28 + 1 + 27 + 1 + 6),\n // which is the default PostgreSQL identifier limit.\n // Note that this schema name will need quoting because of characters like ':', '-', etc\n const schema = `${truncPrefix}_${timestamp}_${suffix}`;\n await this.setSearchSchema(schema);\n return schema;\n }\n\n /**\n * Generate, set, and return a random schema name.\n */\n setRandomSearchSchema = callbackify(this.setRandomSearchSchemaAsync);\n\n /** The number of established connections. */\n get totalCount() {\n return this.pool?.totalCount ?? 0;\n }\n\n /** The number of idle connections. */\n get idleCount() {\n return this.pool?.idleCount ?? 0;\n }\n\n /** The number of queries waiting for a connection to become available. */\n get waitingCount() {\n return this.pool?.waitingCount ?? 0;\n }\n\n /** The total number of queries that have been executed by this pool. */\n get queryCount() {\n return this._queryCount;\n }\n}\n"]}
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,OAAO,MAAM,OAAO,CAAC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AC,IAAI,EAAE,SAAS,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,0EAA0E;IAC1E,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,IAAI,EAAE,YAAY,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,wEAAwE;IACxE,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport { Readable, Transform } from 'node:stream';\nimport { callbackify } from 'node:util';\n\nimport debugfn from 'debug';\nimport _ from 'lodash';\nimport multipipe from 'multipipe';\nimport pg, { type QueryResult } from 'pg';\nimport Cursor from 'pg-cursor';\nimport { DatabaseError } from 'pg-protocol';\nimport { z } from 'zod';\n\nexport type QueryParams = Record<string, any> | any[];\n\nexport interface CursorIterator<T> {\n iterate: (batchSize: number) => AsyncGenerator<T[]>;\n stream: (batchSize: number) => NodeJS.ReadWriteStream;\n}\n\nexport interface PostgresPoolConfig extends pg.PoolConfig {\n errorOnUnusedParameters?: boolean;\n}\n\nconst debug = debugfn('@prairielearn/postgres');\nconst lastQueryMap = new WeakMap<pg.PoolClient, string>();\nconst searchSchemaMap = new WeakMap<pg.PoolClient, string>();\n\nfunction addDataToError(err: Error, data: Record<string, any>): Error {\n (err as any).data = {\n ...((err as any).data ?? {}),\n ...data,\n };\n return err;\n}\n\nexport class PostgresError extends Error {\n public data: Record<string, any>;\n\n constructor(message: string, data: Record<string, any>) {\n super(message);\n this.data = data;\n this.name = 'PostgresError';\n }\n}\n\n/**\n * Formats a string for debugging.\n */\nfunction debugString(s: string): string {\n if (typeof s !== 'string') return 'NOT A STRING';\n s = s.replace(/\\n/g, '\\\\n');\n if (s.length > 78) s = s.substring(0, 75) + '...';\n s = '\"' + s + '\"';\n return s;\n}\n\n/**\n * Formats a set of params for debugging.\n */\nfunction debugParams(params: QueryParams): string {\n let s;\n try {\n s = JSON.stringify(params);\n } catch {\n s = 'CANNOT JSON STRINGIFY';\n }\n return debugString(s);\n}\n\n/**\n * Given an SQL string and params, creates an array of params and an SQL string\n * with any named dollar-sign placeholders replaced with parameters.\n */\nfunction paramsToArray(\n sql: string,\n params: QueryParams,\n errorOnUnusedParameters: boolean,\n): { processedSql: string; paramsArray: any } {\n if (typeof sql !== 'string') throw new Error('SQL must be a string');\n if (Array.isArray(params)) {\n return {\n processedSql: sql,\n paramsArray: params,\n };\n }\n if (params == null || typeof params !== 'object') {\n throw new Error('params must be array or object');\n }\n\n const re = /\\$([-_a-zA-Z0-9]+)/;\n let result;\n let processedSql = '';\n let remainingSql = sql;\n let nParams = 0;\n const map: Record<string, string> = {};\n let paramsArray: any[] = [];\n while ((result = re.exec(remainingSql)) !== null) {\n const v = result[1];\n if (!(v in map)) {\n if (!(v in params)) throw new Error(`Missing parameter: ${v}`);\n if (Array.isArray(params[v])) {\n map[v] = 'ARRAY[' + params[v].map((_, n) => '$' + (n + nParams + 1)).join(',') + ']';\n nParams += params[v].length;\n paramsArray = paramsArray.concat(params[v]);\n } else {\n nParams++;\n map[v] = '$' + nParams;\n paramsArray.push(params[v]);\n }\n }\n processedSql += remainingSql.substring(0, result.index) + map[v];\n remainingSql = remainingSql.substring(result.index + result[0].length);\n }\n processedSql += remainingSql;\n remainingSql = '';\n if (errorOnUnusedParameters) {\n const difference = _.difference(Object.keys(params), Object.keys(map));\n if (difference.length) {\n throw new Error(`Unused parameters in SQL query: ${JSON.stringify(difference)}`);\n }\n }\n return { processedSql, paramsArray };\n}\n\n/**\n * Escapes the given identifier for use in an SQL query. Useful for preventing\n * SQL injection.\n */\nfunction escapeIdentifier(identifier: string): string {\n // Note that as of 2021-06-29 escapeIdentifier() is undocumented. See:\n // https://github.com/brianc/node-postgres/pull/396\n // https://github.com/brianc/node-postgres/issues/1978\n // https://www.postgresql.org/docs/current/sql-syntax-lexical.html\n return pg.Client.prototype.escapeIdentifier(identifier);\n}\n\nfunction enhanceError(err: Error, sql: string, params: QueryParams): Error {\n // Copy the error so we don't end up with a circular reference in the\n // final error.\n const sqlError = { ...err };\n\n // `message` is a non-enumerable property, so we need to copy it manually to\n // the error object.\n sqlError.message = err.message;\n\n const errorHasPosition = err instanceof DatabaseError && err.position != null;\n\n return addDataToError(err, {\n sqlError,\n // If the error has a `position` field, we need to use the processed source\n // (where e.g. `$foobar` has been replaced with `$1`) so that the position\n // is accurate.\n sql: errorHasPosition ? paramsToArray(sql, params, false).processedSql : sql,\n sqlParams: params,\n });\n}\n\nexport class PostgresPool {\n /** The pool from which clients will be acquired. */\n private pool: pg.Pool | null = null;\n /**\n * We use this to propagate the client associated with the current transaction\n * to any nested queries. In the past, we had some nasty bugs associated with\n * the fact that we tried to acquire new clients inside of transactions, which\n * ultimately lead to a deadlock.\n */\n private alsClient = new AsyncLocalStorage<pg.PoolClient>();\n private searchSchema: string | null = null;\n /** Tracks the total number of queries executed by this pool. */\n private _queryCount = 0;\n private errorOnUnusedParameters = false;\n\n /**\n * Creates a new connection pool and attempts to connect to the database.\n */\n async initAsync(\n pgConfig: PostgresPoolConfig,\n idleErrorHandler: (error: Error, client: pg.PoolClient) => void,\n ): Promise<void> {\n this.errorOnUnusedParameters = pgConfig.errorOnUnusedParameters ?? false;\n this.pool = new pg.Pool(pgConfig);\n this.pool.on('error', function (err, client) {\n const lastQuery = lastQueryMap.get(client);\n idleErrorHandler(addDataToError(err, { lastQuery }), client);\n });\n this.pool.on('connect', (client) => {\n client.on('error', (err) => {\n const lastQuery = lastQueryMap.get(client);\n idleErrorHandler(addDataToError(err, { lastQuery }), client);\n });\n });\n this.pool.on('remove', (client) => {\n // This shouldn't be necessary, as `pg` currently allows clients to be\n // garbage collected after they're removed. However, if `pg` someday\n // starts reusing client objects across difference connections, this\n // will ensure that we re-set the search path when the client reconnects.\n searchSchemaMap.delete(client);\n });\n\n // Attempt to connect to the database so that we can fail quickly if\n // something isn't configured correctly.\n let retryCount = 0;\n const retryTimeouts = [500, 1000, 2000, 5000, 10000];\n while (retryCount <= retryTimeouts.length) {\n try {\n const client = await this.pool.connect();\n client.release();\n return;\n } catch (err: any) {\n if (retryCount === retryTimeouts.length) {\n throw new Error(\n `Could not connect to Postgres after ${retryTimeouts.length} attempts: ${err.message}`,\n );\n }\n\n const timeout = retryTimeouts[retryCount];\n retryCount++;\n await new Promise((resolve) => setTimeout(resolve, timeout));\n }\n }\n }\n\n /**\n * Creates a new connection pool and attempts to connect to the database.\n */\n init = callbackify(this.initAsync);\n\n /**\n * Closes the connection pool.\n */\n async closeAsync(): Promise<void> {\n if (!this.pool) return;\n await this.pool.end();\n this.pool = null;\n }\n\n /**\n * Closes the connection pool.\n */\n close = callbackify(this.closeAsync);\n\n /**\n * Gets a new client from the connection pool. If `err` is not null\n * then `client` and `done` are undefined. If `err` is null then\n * `client` is valid and can be used. The caller MUST call `done()` to\n * release the client, whether or not errors occurred while using\n * `client`. The client can call `done(truthy_value)` to force\n * destruction of the client, but this should not be used except in\n * unusual circumstances.\n */\n async getClientAsync(): Promise<pg.PoolClient> {\n if (!this.pool) {\n throw new Error('Connection pool is not open');\n }\n\n // If we're inside a transaction, we'll reuse the same client to avoid a\n // potential deadlock.\n const client = this.alsClient.getStore() ?? (await this.pool.connect());\n\n // If we're configured to use a particular schema, we'll store whether or\n // not the search path has already been configured for this particular\n // client. If we acquire a client and it's already had its search path\n // set, we can avoid setting it again since the search path will persist\n // for the life of the client.\n //\n // We do this check for each call to `getClient` instead of on\n // `pool.connect` so that we don't have to be really careful about\n // destroying old clients that were created before `setSearchSchema` was\n // called. Instead, we'll just check if the search path matches the\n // currently-desired schema, and if it's a mismatch (or doesn't exist\n // at all), we re-set it for the current client.\n //\n // Note that this accidentally supports changing the search_path on the fly,\n // although that's not something we currently do (or would be likely to do).\n // It does NOT support clearing the existing search schema - e.g.,\n // `setSearchSchema(null)` would not work as you expect. This is fine, as\n // that's not something we ever do in practice.\n const clientSearchSchema = searchSchemaMap.get(client);\n if (this.searchSchema != null && clientSearchSchema !== this.searchSchema) {\n const setSearchPathSql = `SET search_path TO ${escapeIdentifier(this.searchSchema)},public`;\n try {\n await this.queryWithClientAsync(client, setSearchPathSql, {});\n } catch (err) {\n client.release();\n throw err;\n }\n searchSchemaMap.set(client, this.searchSchema);\n }\n\n return client;\n }\n\n /**\n * Gets a new client from the connection pool.\n */\n getClient(callback: (error: Error | null, client?: pg.PoolClient, done?: () => void) => void) {\n this.getClientAsync()\n .then((client) => callback(null, client, client.release))\n .catch((err) => callback(err));\n }\n\n /**\n * Performs a query with the given client.\n */\n async queryWithClientAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<pg.QueryResult> {\n this._queryCount += 1;\n debug('queryWithClient()', 'sql:', debugString(sql));\n debug('queryWithClient()', 'params:', debugParams(params));\n const { processedSql, paramsArray } = paramsToArray(sql, params, this.errorOnUnusedParameters);\n try {\n lastQueryMap.set(client, processedSql);\n const result = await client.query(processedSql, paramsArray);\n debug('queryWithClient() success', 'rowCount:', result.rowCount);\n return result;\n } catch (err: any) {\n throw enhanceError(err, sql, params);\n }\n }\n\n /**\n * Performs a query with the given client.\n */\n queryWithClient = callbackify(this.queryWithClientAsync);\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n async queryWithClientOneRowAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<pg.QueryResult> {\n debug('queryWithClientOneRow()', 'sql:', debugString(sql));\n debug('queryWithClientOneRow()', 'params:', debugParams(params));\n const result = await this.queryWithClientAsync(client, sql, params);\n if (result.rowCount !== 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n result,\n });\n }\n debug('queryWithClientOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n queryWithClientOneRow = callbackify(this.queryWithClientOneRowAsync);\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n async queryWithClientZeroOrOneRowAsync(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<QueryResult> {\n debug('queryWithClientZeroOrOneRow()', 'sql:', debugString(sql));\n debug('queryWithClientZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.queryWithClientAsync(client, sql, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n result,\n });\n }\n debug('queryWithClientZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\n queryWithClientZeroOrOneRow = callbackify(this.queryWithClientZeroOrOneRowAsync);\n\n /**\n * Rolls back the current transaction for the given client.\n */\n async rollbackWithClientAsync(client: pg.PoolClient) {\n debug('rollbackWithClient()');\n // From https://node-postgres.com/features/transactions\n try {\n await client.query('ROLLBACK');\n // Only release the client if we weren't already inside a transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n } catch (err: any) {\n // If there was a problem rolling back the query, something is\n // seriously messed up. Return the error to the release() function to\n // close & remove this client from the pool. If you leave a client in\n // the pool with an unaborted transaction, weird and hard to diagnose\n // problems might happen.\n client.release(err);\n }\n }\n\n /**\n * Rolls back the current transaction for the given client.\n */\n rollbackWithClient(\n client: pg.PoolClient,\n _done: (release?: any) => void,\n callback: (err: Error | null) => void,\n ) {\n // Note that we can't use `util.callbackify` here because this function\n // has an additional unused `done` parameter for backwards compatibility.\n this.rollbackWithClientAsync(client)\n .then(() => callback(null))\n .catch((err) => callback(err));\n }\n\n /**\n * Begins a new transaction.\n */\n async beginTransactionAsync(): Promise<pg.PoolClient> {\n debug('beginTransaction()');\n const client = await this.getClientAsync();\n try {\n await this.queryWithClientAsync(client, 'START TRANSACTION;', {});\n return client;\n } catch (err) {\n await this.rollbackWithClientAsync(client);\n throw err;\n }\n }\n\n /**\n * Commits the transaction if err is null, otherwise rollbacks the transaction.\n * Also releases the client.\n */\n async endTransactionAsync(client: pg.PoolClient, err: Error | null | undefined) {\n debug('endTransaction()');\n if (err) {\n try {\n await this.rollbackWithClientAsync(client);\n } catch (rollbackErr: any) {\n throw addDataToError(rollbackErr, { prevErr: err, rollback: 'fail' });\n }\n\n // Even though we successfully rolled back the transaction, there was\n // still an error in the first place that necessitated a rollback. Re-throw\n // that error here so that everything downstream of here will know about it.\n throw addDataToError(err, { rollback: 'success' });\n } else {\n try {\n await this.queryWithClientAsync(client, 'COMMIT', {});\n } finally {\n // Only release the client if we aren't nested inside another transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n }\n }\n }\n\n /**\n * Commits the transaction if err is null, otherwise rollbacks the transaction.\n * Also releases the client.\n */\n endTransaction(\n client: pg.PoolClient,\n _done: (rollback?: any) => void,\n err: Error | null | undefined,\n callback: (error: Error | null) => void,\n ): void {\n this.endTransactionAsync(client, err)\n .then(() => callback(null))\n .catch((error) => callback(error));\n }\n\n /**\n * Runs the specified function inside of a transaction. The function will\n * receive a database client as an argument, but it can also make queries\n * as usual, and the correct client will be used automatically.\n *\n * The transaction will be rolled back if the function throws an error, and\n * will be committed otherwise.\n */\n async runInTransactionAsync<T>(fn: (client: pg.PoolClient) => Promise<T>): Promise<T> {\n // Check if we're already inside a transaction. If so, we won't start another one,\n // as Postgres doesn't support nested transactions.\n const client = this.alsClient.getStore();\n const isNestedTransaction = client !== undefined;\n const transactionClient = client ?? (await this.beginTransactionAsync());\n\n let result: T;\n try {\n result = await this.alsClient.run(transactionClient, () => fn(transactionClient));\n } catch (err: any) {\n if (!isNestedTransaction) {\n // If we're inside another transaction, we assume that the root transaction\n // will catch this error and roll back the transaction.\n await this.endTransactionAsync(transactionClient, err);\n }\n throw err;\n }\n\n if (!isNestedTransaction) {\n // If we're inside another transaction; don't commit it prematurely. Allow\n // the root transaction to commit it instead.\n //\n // Note that we don't invoke `endTransactionAsync` inside the `try` block\n // because we don't want an error thrown by it to trigger *another* call\n // to `endTransactionAsync` in the `catch` block.\n await this.endTransactionAsync(transactionClient, null);\n }\n\n return result;\n }\n\n /**\n * Executes a query with the specified parameters.\n */\n async queryAsync(sql: string, params: QueryParams): Promise<QueryResult> {\n debug('query()', 'sql:', debugString(sql));\n debug('query()', 'params:', debugParams(params));\n const client = await this.getClientAsync();\n try {\n return await this.queryWithClientAsync(client, sql, params);\n } finally {\n // Only release if we aren't nested in a transaction.\n if (this.alsClient.getStore() === undefined) {\n client.release();\n }\n }\n }\n\n /**\n * Executes a query with the specified parameters.\n */\n query = callbackify(this.queryAsync);\n\n /**\n * Executes a query with the specified parameters. Errors if the query does\n * not return exactly one row.\n */\n async queryOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult> {\n debug('queryOneRow()', 'sql:', debugString(sql));\n debug('queryOneRow()', 'params:', debugParams(params));\n const result = await this.queryAsync(sql, params);\n if (result.rowCount !== 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n });\n }\n debug('queryOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Executes a query with the specified parameters. Errors if the query does\n * not return exactly one row.\n */\n queryOneRow = callbackify(this.queryOneRowAsync);\n\n /**\n * Executes a query with the specified parameters. Errors if the query\n * returns more than one row.\n */\n async queryZeroOrOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult> {\n debug('queryZeroOrOneRow()', 'sql:', debugString(sql));\n debug('queryZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.queryAsync(sql, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError(`Incorrect rowCount: ${result.rowCount}`, {\n sql,\n sqlParams: params,\n });\n }\n debug('queryZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Executes a query with the specified parameters. Errors if the query\n * returns more than one row.\n */\n queryZeroOrOneRow = callbackify(this.queryZeroOrOneRowAsync);\n\n /**\n * Calls the given function with the specified parameters.\n */\n async callAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('call()', 'function:', functionName);\n debug('call()', 'params:', debugParams(params));\n const placeholders = params.map((_, v) => '$' + (v + 1)).join();\n const sql = `SELECT * FROM ${escapeIdentifier(functionName)}(${placeholders});`;\n const result = await this.queryAsync(sql, params);\n debug('call() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters.\n */\n call = callbackify(this.callAsync);\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function does not return exactly one row.\n */\n async callOneRowAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('callOneRow()', 'function:', functionName);\n debug('callOneRow()', 'params:', debugParams(params));\n const result = await this.callAsync(functionName, params);\n if (result.rowCount !== 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function does not return exactly one row.\n */\n callOneRow = callbackify(this.callOneRowAsync);\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function returns more than one row.\n */\n async callZeroOrOneRowAsync(functionName: string, params: any[]): Promise<pg.QueryResult> {\n debug('callZeroOrOneRow()', 'function:', functionName);\n debug('callZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.callAsync(functionName, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls the given function with the specified parameters. Errors if the\n * function returns more than one row.\n */\n callZeroOrOneRow = callbackify(this.callZeroOrOneRowAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n */\n async callWithClientAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClient()', 'function:', functionName);\n debug('callWithClient()', 'params:', debugParams(params));\n const placeholders = params.map((_, v) => '$' + (v + 1)).join();\n const sql = `SELECT * FROM ${escapeIdentifier(functionName)}(${placeholders})`;\n const result = await this.queryWithClientAsync(client, sql, params);\n debug('callWithClient() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n */\n callWithClient = callbackify(this.callWithClientAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function does not return exactly one row.\n */\n async callWithClientOneRowAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClientOneRow()', 'function:', functionName);\n debug('callWithClientOneRow()', 'params:', debugParams(params));\n const result = await this.callWithClientAsync(client, functionName, params);\n if (result.rowCount !== 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callWithClientOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function does not return exactly one row.\n */\n callWithClientOneRow = callbackify(this.callWithClientOneRowAsync);\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function returns more than one row.\n */\n async callWithClientZeroOrOneRowAsync(\n client: pg.PoolClient,\n functionName: string,\n params: any[],\n ): Promise<pg.QueryResult> {\n debug('callWithClientZeroOrOneRow()', 'function:', functionName);\n debug('callWithClientZeroOrOneRow()', 'params:', debugParams(params));\n const result = await this.callWithClientAsync(client, functionName, params);\n if (result.rowCount == null || result.rowCount > 1) {\n throw new PostgresError('Incorrect rowCount: ' + result.rowCount, {\n functionName,\n sqlParams: params,\n });\n }\n debug('callWithClientZeroOrOneRow() success', 'rowCount:', result.rowCount);\n return result;\n }\n\n /**\n * Calls a function with the specified parameters using a specific client.\n * Errors if the function returns more than one row.\n */\n callWithClientZeroOrOneRow = callbackify(this.callWithClientZeroOrOneRowAsync);\n\n async queryRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;\n async queryRows<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>[]>;\n async queryRows<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n const rawData = results.rows.map((row) => row[columnName]);\n return z.array(model).parse(rawData);\n } else {\n return z.array(model).parse(results.rows);\n }\n }\n\n async queryRow<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>>;\n async queryRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model>>;\n async queryRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryOneRowAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async queryOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: QueryParams | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? {} : (paramsOrSchema as QueryParams);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.queryZeroOrOneRowAsync(sql, params);\n if (results.rows.length === 0) {\n return null;\n } else if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async callRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;\n async callRows<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>[]>;\n async callRows<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n const rawData = results.rows.map((row) => row[columnName]);\n return z.array(model).parse(rawData);\n } else {\n return z.array(model).parse(results.rows);\n }\n }\n\n async callRow<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>>;\n async callRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model>>;\n async callRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callOneRowAsync(sql, params);\n if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n params: any[],\n model: Model,\n ): Promise<z.infer<Model> | null>;\n async callOptionalRow<Model extends z.ZodTypeAny>(\n sql: string,\n paramsOrSchema: any[] | Model,\n maybeModel?: Model,\n ) {\n const params = maybeModel === undefined ? [] : (paramsOrSchema as any[]);\n const model = maybeModel === undefined ? (paramsOrSchema as Model) : maybeModel;\n const results = await this.callZeroOrOneRowAsync(sql, params);\n if (results.rows.length === 0) {\n return null;\n } else if (results.fields.length === 1) {\n const columnName = results.fields[0].name;\n return model.parse(results.rows[0][columnName]);\n } else {\n return model.parse(results.rows[0]);\n }\n }\n\n /**\n * Returns a {@link Cursor} for the given query. The cursor can be used to\n * read results in batches, which is useful for large result sets.\n */\n async queryCursorWithClient(\n client: pg.PoolClient,\n sql: string,\n params: QueryParams,\n ): Promise<Cursor> {\n this._queryCount += 1;\n debug('queryCursorWithClient()', 'sql:', debugString(sql));\n debug('queryCursorWithClient()', 'params:', debugParams(params));\n const { processedSql, paramsArray } = paramsToArray(sql, params, this.errorOnUnusedParameters);\n lastQueryMap.set(client, processedSql);\n return client.query(new Cursor(processedSql, paramsArray));\n }\n\n /**\n * Returns an {@link CursorIterator} that can be used to iterate over the\n * results of the query in batches, which is useful for large result sets.\n */\n async queryCursor<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n ): Promise<CursorIterator<z.infer<Model>>> {\n return this.queryValidatedCursorInternal(sql, params);\n }\n\n /**\n * Returns an {@link CursorIterator} that can be used to iterate over the\n * results of the query in batches, which is useful for large result sets.\n * Each row will be parsed by the given Zod schema.\n */\n async queryValidatedCursor<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model: Model,\n ): Promise<CursorIterator<z.infer<Model>>> {\n return this.queryValidatedCursorInternal(sql, params, model);\n }\n\n private async queryValidatedCursorInternal<Model extends z.ZodTypeAny>(\n sql: string,\n params: QueryParams,\n model?: Model,\n ): Promise<CursorIterator<z.infer<Model>>> {\n const client = await this.getClientAsync();\n const cursor = await this.queryCursorWithClient(client, sql, params);\n\n let iterateCalled = false;\n const iterator: CursorIterator<z.infer<Model>> = {\n async *iterate(batchSize: number) {\n // Safety check: if someone calls iterate multiple times, they're\n // definitely doing something wrong.\n if (iterateCalled) {\n throw new Error('iterate() called multiple times');\n }\n iterateCalled = true;\n\n try {\n while (true) {\n const rows = await cursor.read(batchSize);\n if (rows.length === 0) {\n break;\n }\n\n if (model) {\n yield z.array(model).parse(rows);\n } else {\n yield rows;\n }\n }\n } catch (err: any) {\n throw enhanceError(err, sql, params);\n } finally {\n try {\n await cursor.close();\n } finally {\n client.release();\n }\n }\n },\n stream(batchSize: number) {\n const transform = new Transform({\n readableObjectMode: true,\n writableObjectMode: true,\n transform(chunk, _encoding, callback) {\n for (const row of chunk) {\n this.push(row);\n }\n callback();\n },\n });\n\n // TODO: use native `node:stream#compose` once it's stable.\n const generator = iterator.iterate(batchSize);\n const pipe = multipipe(Readable.from(generator), transform);\n\n // When the underlying stream is closed, we need to make sure that the\n // cursor is also closed. We do this by calling `return()` on the generator,\n // which will trigger its `finally` block, which will in turn release\n // the client and close the cursor. The fact that the stream is already\n // closed by this point means that someone reading from the stream will\n // never actually see the `null` value that's returned.\n pipe.once('close', () => {\n generator.return(null);\n });\n\n return pipe;\n },\n };\n return iterator;\n }\n\n /**\n * Set the schema to use for the search path.\n *\n * @param schema The schema name to use (can be \"null\" to unset the search path)\n */\n async setSearchSchema(schema: string) {\n if (schema == null) {\n this.searchSchema = schema;\n return;\n }\n\n await this.queryAsync(`CREATE SCHEMA IF NOT EXISTS ${escapeIdentifier(schema)}`, {});\n // We only set searchSchema after CREATE to avoid the above query() call using searchSchema.\n this.searchSchema = schema;\n }\n\n /**\n * Get the schema that is currently used for the search path.\n *\n * @return schema in use (may be `null` to indicate no schema)\n */\n getSearchSchema(): string | null {\n return this.searchSchema;\n }\n\n /**\n * Generate, set, and return a random schema name.\n *\n * @param prefix The prefix of the new schema, only the first 28 characters will be used (after lowercasing).\n * @returns The randomly-generated search schema.\n */\n async setRandomSearchSchemaAsync(prefix: string): Promise<string> {\n // truncated prefix (max 28 characters)\n const truncPrefix = prefix.substring(0, 28);\n // timestamp in format YYYY-MM-DDTHH:MM:SS.SSSZ (guaranteed to not exceed 27 characters in the spec)\n const timestamp = new Date().toISOString();\n // random 6-character suffix to avoid clashes (approx 2 billion possible values)\n const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');\n const suffix = Array.from({ length: 6 })\n .map(() => chars[Math.floor(Math.random() * chars.length)])\n .join('');\n\n // Schema is guaranteed to have length at most 63 (= 28 + 1 + 27 + 1 + 6),\n // which is the default PostgreSQL identifier limit.\n // Note that this schema name will need quoting because of characters like ':', '-', etc\n const schema = `${truncPrefix}_${timestamp}_${suffix}`;\n await this.setSearchSchema(schema);\n return schema;\n }\n\n /**\n * Generate, set, and return a random schema name.\n */\n setRandomSearchSchema = callbackify(this.setRandomSearchSchemaAsync);\n\n /** The number of established connections. */\n get totalCount() {\n return this.pool?.totalCount ?? 0;\n }\n\n /** The number of idle connections. */\n get idleCount() {\n return this.pool?.idleCount ?? 0;\n }\n\n /** The number of queries waiting for a connection to become available. */\n get waitingCount() {\n return this.pool?.waitingCount ?? 0;\n }\n\n /** The total number of queries that have been executed by this pool. */\n get queryCount() {\n return this._queryCount;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prairielearn/postgres",
3
- "version": "2.1.15",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,14 +15,14 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@types/debug": "^4.1.12",
18
- "@types/lodash": "^4.17.19",
18
+ "@types/lodash": "^4.17.20",
19
19
  "@types/pg-cursor": "^2.7.2",
20
20
  "multipipe": "^4.0.0",
21
21
  "pg": "^8.16.3",
22
22
  "pg-cursor": "^2.15.3",
23
23
  "pg-pool": "^3.10.1",
24
24
  "pg-protocol": "^1.10.3",
25
- "zod": "^3.25.67"
25
+ "zod": "^3.25.69"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@prairielearn/tsconfig": "^0.0.0",
@@ -50,18 +50,6 @@ export const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.b
50
50
  export const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);
51
51
  export const callWithClientZeroOrOneRowAsync =
52
52
  defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);
53
- export const queryValidatedRows = defaultPool.queryValidatedRows.bind(defaultPool);
54
- export const queryValidatedOneRow = defaultPool.queryValidatedOneRow.bind(defaultPool);
55
- export const queryValidatedZeroOrOneRow = defaultPool.queryValidatedZeroOrOneRow.bind(defaultPool);
56
- export const queryValidatedSingleColumnRows =
57
- defaultPool.queryValidatedSingleColumnRows.bind(defaultPool);
58
- export const queryValidatedSingleColumnOneRow =
59
- defaultPool.queryValidatedSingleColumnOneRow.bind(defaultPool);
60
- export const queryValidatedSingleColumnZeroOrOneRow =
61
- defaultPool.queryValidatedSingleColumnZeroOrOneRow.bind(defaultPool);
62
- export const callValidatedRows = defaultPool.callValidatedRows.bind(defaultPool);
63
- export const callValidatedOneRow = defaultPool.callValidatedOneRow.bind(defaultPool);
64
- export const callValidatedZeroOrOneRow = defaultPool.callValidatedZeroOrOneRow.bind(defaultPool);
65
53
  export const queryRows = defaultPool.queryRows.bind(defaultPool);
66
54
  export const queryRow = defaultPool.queryRow.bind(defaultPool);
67
55
  export const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);
package/src/pool.ts CHANGED
@@ -734,151 +734,6 @@ export class PostgresPool {
734
734
  */
735
735
  callWithClientZeroOrOneRow = callbackify(this.callWithClientZeroOrOneRowAsync);
736
736
 
737
- /**
738
- * Wrapper around {@link queryAsync} that parses the resulting rows with the
739
- * given Zod schema. Returns only the rows of the query.
740
- */
741
- async queryValidatedRows<Model extends z.ZodTypeAny>(
742
- query: string,
743
- params: QueryParams,
744
- model: Model,
745
- ): Promise<z.infer<Model>[]> {
746
- const results = await this.queryAsync(query, params);
747
- return z.array(model).parse(results.rows);
748
- }
749
-
750
- /**
751
- * Wrapper around {@link queryOneRowAsync} that parses the resulting row with
752
- * the given Zod schema. Returns only a single row of the query.
753
- */
754
- async queryValidatedOneRow<Model extends z.ZodTypeAny>(
755
- query: string,
756
- params: QueryParams,
757
- model: Model,
758
- ): Promise<z.infer<Model>> {
759
- const results = await this.queryOneRowAsync(query, params);
760
- return model.parse(results.rows[0]);
761
- }
762
-
763
- /**
764
- * Wrapper around {@link queryZeroOrOneRowAsync} that parses the resulting row
765
- * (if any) with the given Zod schema. Returns either a single row or `null`.
766
- */
767
- async queryValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(
768
- query: string,
769
- params: QueryParams,
770
- model: Model,
771
- ): Promise<z.infer<Model> | null> {
772
- const results = await this.queryZeroOrOneRowAsync(query, params);
773
- if (results.rows.length === 0) {
774
- return null;
775
- } else {
776
- return model.parse(results.rows[0]);
777
- }
778
- }
779
-
780
- /**
781
- * Wrapper around {@link queryAsync} that validates that only one column is
782
- * returned and parses the data in it with the given Zod schema. Returns only
783
- * the single column of the query as an array.
784
- */
785
- async queryValidatedSingleColumnRows<Model extends z.ZodTypeAny>(
786
- query: string,
787
- params: QueryParams,
788
- model: Model,
789
- ): Promise<z.infer<Model>[]> {
790
- const results = await this.queryAsync(query, params);
791
- if (results.fields.length !== 1) {
792
- throw new Error(`Expected one column, got ${results.fields.length}`);
793
- }
794
- const columnName = results.fields[0].name;
795
- const rawData = results.rows.map((row) => row[columnName]);
796
- return z.array(model).parse(rawData);
797
- }
798
-
799
- /**
800
- * Wrapper around {@link queryOneRowAsync} that validates that only one column
801
- * is returned and parses the data in it with the given Zod schema. Returns
802
- * only the single entry.
803
- */
804
- async queryValidatedSingleColumnOneRow<Model extends z.ZodTypeAny>(
805
- query: string,
806
- params: QueryParams,
807
- model: Model,
808
- ): Promise<z.infer<Model>> {
809
- const results = await this.queryOneRowAsync(query, params);
810
- if (results.fields.length !== 1) {
811
- throw new Error(`Expected one column, got ${results.fields.length}`);
812
- }
813
- const columnName = results.fields[0].name;
814
- return model.parse(results.rows[0][columnName]);
815
- }
816
-
817
- /**
818
- * Wrapper around {@link queryZeroOrOneRowAsync} that validates that only one
819
- * column is returned and parses the data in it (if any) with the given Zod
820
- * schema. Returns either the single row of the query or `null`.
821
- */
822
- async queryValidatedSingleColumnZeroOrOneRow<Model extends z.ZodTypeAny>(
823
- query: string,
824
- params: QueryParams,
825
- model: Model,
826
- ): Promise<z.infer<Model> | null> {
827
- const results = await this.queryZeroOrOneRowAsync(query, params);
828
- if (results.fields.length !== 1) {
829
- throw new Error(`Expected one column, got ${results.fields.length}`);
830
- }
831
- if (results.rows.length === 0) {
832
- return null;
833
- } else {
834
- const columnName = results.fields[0].name;
835
- return model.parse(results.rows[0][columnName]);
836
- }
837
- }
838
-
839
- /**
840
- * Wrapper around {@link callAsync} that parses the resulting rows with the
841
- * given Zod schema. Returns only the rows.
842
- */
843
- async callValidatedRows<Model extends z.ZodTypeAny>(
844
- sprocName: string,
845
- params: any[],
846
- model: Model,
847
- ): Promise<z.infer<Model>[]> {
848
- const results = await this.callAsync(sprocName, params);
849
- return z.array(model).parse(results.rows);
850
- }
851
-
852
- /**
853
- * Wrapper around {@link callOneRowAsync} that parses the resulting rows with
854
- * the given Zod schema. Returns only a single row.
855
- */
856
- async callValidatedOneRow<Model extends z.ZodTypeAny>(
857
- sprocName: string,
858
- params: any[],
859
- model: Model,
860
- ): Promise<z.infer<Model>> {
861
- const results = await this.callOneRowAsync(sprocName, params);
862
- return model.parse(results.rows[0]);
863
- }
864
-
865
- /**
866
- * Wrapper around {@link callZeroOrOneRowAsync} that parses the resulting row
867
- * (if any) with the given Zod schema. Returns at most a single row.
868
- */
869
- async callValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(
870
- sprocName: string,
871
- params: any[],
872
- model: Model,
873
- ): Promise<z.infer<Model> | null> {
874
- const results = await this.callZeroOrOneRowAsync(sprocName, params);
875
- if (results.rows.length === 0) {
876
- return null;
877
- } else {
878
- return model.parse(results.rows[0]);
879
- }
880
- }
881
-
882
737
  async queryRows<Model extends z.ZodTypeAny>(sql: string, model: Model): Promise<z.infer<Model>[]>;
883
738
  async queryRows<Model extends z.ZodTypeAny>(
884
739
  sql: string,