@voxpelli/pg-utils 1.2.0 → 2.1.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.
@@ -4,12 +4,13 @@ export class PgTestHelpers {
4
4
  initTables(): Promise<void>;
5
5
  insertFixtures(): Promise<void>;
6
6
  removeTables(): Promise<void>;
7
+ end(): Promise<void>;
7
8
  #private;
8
9
  }
9
10
  export type PgTestHelpersOptions = {
10
11
  connectionString: string;
11
12
  fixtureFolder?: string | URL;
12
- schema: string | URL | import("umzug").Umzug<import("umzeption").UmzeptionContext<"pg", import("umzeption").FastifyPostgresStyleDb>>;
13
+ schema: string | URL | (() => import("umzug").Umzug<import("umzeption").UmzeptionContext<"pg", import("umzeption").FastifyPostgresStyleDb>>);
13
14
  tablesWithDependencies?: Array<string[] | string>;
14
15
  };
15
16
  import type { Pool } from 'pg';
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAoBA;IAaE,qBADY,oBAAoB,EAiC/B;IAnCD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAoEb,cADc,OAAO,CAAC,IAAI,CAAC,CAiB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;;CACF;;sBArHa,MAAM;oBACN,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC;6BAC5H,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAoBA;IAaE,qBADY,oBAAoB,EAiC/B;IAnCD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAoEb,cADc,OAAO,CAAC,IAAI,CAAC,CAiB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,OADc,OAAO,CAAC,IAAI,CAAC,CAG1B;;CACF;;sBA1Ha,MAAM;oBACN,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC;6BACpI,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
@@ -14,7 +14,7 @@ import { createPgPool, isStringArray, TypeNeverError } from './utils.js';
14
14
  * @typedef PgTestHelpersOptions
15
15
  * @property {string} connectionString
16
16
  * @property {string | URL} [fixtureFolder]
17
- * @property {string | URL | import('umzug').Umzug<import('umzeption').UmzeptionContext<'pg', import('umzeption').FastifyPostgresStyleDb>>} schema
17
+ * @property {string | URL | (() => import('umzug').Umzug<import('umzeption').UmzeptionContext<'pg', import('umzeption').FastifyPostgresStyleDb>>)} schema
18
18
  * @property {Array<string[] | string>} [tablesWithDependencies]
19
19
  */
20
20
 
@@ -49,8 +49,8 @@ export class PgTestHelpers {
49
49
  if (fixtureFolder && typeof fixtureFolder !== 'string' && !(fixtureFolder instanceof URL)) {
50
50
  throw new TypeNeverError(fixtureFolder, 'Invalid fixtureFolder, expected a string');
51
51
  }
52
- if (typeof schema !== 'string' && typeof schema !== 'object') {
53
- throw new TypeNeverError(schema, 'Invalid schema, expected a string or an object');
52
+ if (typeof schema !== 'string' && typeof schema !== 'object' && typeof schema !== 'function') {
53
+ throw new TypeNeverError(schema, 'Invalid schema, expected a string, object or function');
54
54
  }
55
55
  if (tablesWithDependencies && !Array.isArray(tablesWithDependencies)) {
56
56
  throw new TypeNeverError(tablesWithDependencies, 'Invalid tablesWithDependencies, expected an array');
@@ -88,8 +88,8 @@ export class PgTestHelpers {
88
88
  Array.isArray(name)
89
89
  ? this.#removeTablesByName(name)
90
90
  : this.queryPromise('DROP TABLE IF EXISTS ' + name + ' CASCADE').catch(cause => {
91
- throw new Error(`Failed to drop table: ${name}`, { cause });
92
- })
91
+ throw new Error(`Failed to drop table: ${name}`, { cause });
92
+ })
93
93
  );
94
94
  }
95
95
  }
@@ -98,8 +98,8 @@ export class PgTestHelpers {
98
98
  /** @returns {Promise<void>} */
99
99
  async initTables () {
100
100
  try {
101
- if (typeof this.#schema === 'object' && 'up' in this.#schema) {
102
- await this.#schema.up();
101
+ if (typeof this.#schema === 'function') {
102
+ await this.#schema().up();
103
103
  return;
104
104
  }
105
105
 
@@ -129,4 +129,9 @@ export class PgTestHelpers {
129
129
  }
130
130
  await this.#removeTablesByName(await this.#getTableNames());
131
131
  }
132
+
133
+ /** @returns {Promise<void>} */
134
+ async end () {
135
+ await this.#pool.end();
136
+ }
132
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxpelli/pg-utils",
3
- "version": "1.2.0",
3
+ "version": "2.1.0",
4
4
  "description": " My personal database utils / helpers for Postgres",
5
5
  "homepage": "http://github.com/voxpelli/pg-utils",
6
6
  "repository": {
@@ -47,22 +47,22 @@
47
47
  "@types/chai": "^4.3.20",
48
48
  "@types/chai-as-promised": "^7.1.8",
49
49
  "@types/mocha": "^10.0.10",
50
- "@types/node": "^20.17.9",
50
+ "@types/node": "^20.17.17",
51
51
  "@types/pg-copy-streams": "^1.2.5",
52
52
  "@voxpelli/eslint-config": "^22.2.0",
53
- "@voxpelli/tsconfig": "^15.1.0",
54
- "c8": "^10.1.2",
53
+ "@voxpelli/tsconfig": "^15.1.1",
54
+ "c8": "^10.1.3",
55
55
  "chai": "^4.5.0",
56
56
  "chai-as-promised": "^7.1.2",
57
- "dotenv": "^16.4.6",
58
- "eslint": "^9.16.0",
57
+ "dotenv": "^16.4.7",
58
+ "eslint": "^9.19.0",
59
59
  "husky": "^9.1.7",
60
60
  "installed-check": "^9.3.0",
61
- "knip": "^5.38.4",
62
- "mocha": "^10.8.2",
63
- "npm-run-all2": "^7.0.1",
61
+ "knip": "^5.43.6",
62
+ "mocha": "^11.1.0",
63
+ "npm-run-all2": "^7.0.2",
64
64
  "type-coverage": "^2.29.7",
65
- "typescript": "~5.7.2",
65
+ "typescript": "~5.7.3",
66
66
  "validate-conventional-commit": "^1.0.4"
67
67
  },
68
68
  "dependencies": {