@voxpelli/pg-utils 2.2.0 → 2.3.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/README.md CHANGED
@@ -20,7 +20,8 @@ import {
20
20
  const pgHelpers = new PgTestHelpers({
21
21
  connectionString: 'postgres://user:pass@localhost/example',
22
22
  fixtureFolder: new URL('./fixtures', import.meta.url),
23
- schema: new URL('./create-tables.sql', import.meta.url),,
23
+ ignoreTables: ['xyz'],
24
+ schema: new URL('./create-tables.sql', import.meta.url),
24
25
  tablesWithDependencies: [
25
26
  'abc',
26
27
  ['foo', 'bar'],
@@ -38,7 +39,10 @@ Class that creates a helpers instance
38
39
  new PgTestHelpers({
39
40
  connectionString: 'postgres://user:pass@localhost/example',
40
41
  fixtureFolder: new URL('./fixtures', import.meta.url),
41
- schema: new URL('./create-tables.sql', import.meta.url),,
42
+ ignoreTables: [
43
+ // ...
44
+ ],
45
+ schema: new URL('./create-tables.sql', import.meta.url),
42
46
  tablesWithDependencies: [
43
47
  // ...
44
48
  ]
@@ -53,6 +57,7 @@ new PgTestHelpers({
53
57
 
54
58
  * `connectionString` – _`string | _ – a connection string for the postgres database
55
59
  * `fixtureFolder` – _`[string | URL]`_ – _optional_ – the path to a folder of `.csv`-file fixtures named by their respective table
60
+ * `ignoreTables` – _`[string[]]`_ – _optional_ – names of tables to ignore when dropping
56
61
  * `schema` – _`string | URL | Umzug`_ – an umzug instance that can be used to initialize tables or the schema itself or a `URL` to a text file containing the schema
57
62
  * `tablesWithDependencies` – _`[Array<string[] | string>]`_ – _optional_ – names of tables that depend on other tables. If some of these tables depend on each other, then use nested arrays to ensure that within the same array no two tables depend on each other
58
63
 
@@ -10,6 +10,7 @@ export class PgTestHelpers {
10
10
  export type PgTestHelpersOptions = {
11
11
  connectionString: string;
12
12
  fixtureFolder?: string | URL;
13
+ ignoreTables?: string[];
13
14
  schema: string | URL | ((pool: Pool) => import("umzug").Umzug<import("umzeption").UmzeptionContext<"pg", import("umzeption").FastifyPostgresStyleDb>>);
14
15
  tablesWithDependencies?: Array<string[] | string>;
15
16
  };
@@ -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;IAGD,OADc,OAAO,CAAC,IAAI,CAAC,CAG1B;;CACF;;sBA1Ha,MAAM;oBACN,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC;6BAC9I,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
1
+ {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAqBA;IAeE,qBADY,oBAAoB,EAsC/B;IAxCD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAyEb,cADc,OAAO,CAAC,IAAI,CAAC,CAiB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAM1B;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAc1B;IAGD,OADc,OAAO,CAAC,IAAI,CAAC,CAG1B;;CACF;;sBA1Ia,MAAM;oBACN,MAAM,GAAG,GAAG;mBACZ,MAAM,EAAE;YACR,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,OAAO,EAAE,KAAK,CAAC,OAAO,WAAW,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,WAAW,EAAE,sBAAsB,CAAC,CAAC,CAAC;6BAC9I,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BARZ,IAAI"}
@@ -14,6 +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[]} [ignoreTables]
17
18
  * @property {string | URL | ((pool: Pool) => import('umzug').Umzug<import('umzeption').UmzeptionContext<'pg', import('umzeption').FastifyPostgresStyleDb>>)} schema
18
19
  * @property {Array<string[] | string>} [tablesWithDependencies]
19
20
  */
@@ -21,6 +22,8 @@ import { createPgPool, isStringArray, TypeNeverError } from './utils.js';
21
22
  export class PgTestHelpers {
22
23
  /** @type {string | URL | undefined} */
23
24
  #fixtureFolder;
25
+ /** @type {string[] | undefined} */
26
+ #ignoreTables;
24
27
  /** @type {Pool} */
25
28
  #pool;
26
29
  /** @type {PgTestHelpersOptions['schema']} */
@@ -39,6 +42,7 @@ export class PgTestHelpers {
39
42
  const {
40
43
  connectionString,
41
44
  fixtureFolder,
45
+ ignoreTables,
42
46
  schema,
43
47
  tablesWithDependencies,
44
48
  } = options;
@@ -49,6 +53,9 @@ export class PgTestHelpers {
49
53
  if (fixtureFolder && typeof fixtureFolder !== 'string' && !(fixtureFolder instanceof URL)) {
50
54
  throw new TypeNeverError(fixtureFolder, 'Invalid fixtureFolder, expected a string');
51
55
  }
56
+ if (ignoreTables && !Array.isArray(ignoreTables)) {
57
+ throw new TypeNeverError(ignoreTables, 'Invalid ignoreTables, expected an array');
58
+ }
52
59
  if (typeof schema !== 'string' && typeof schema !== 'object' && typeof schema !== 'function') {
53
60
  throw new TypeNeverError(schema, 'Invalid schema, expected a string, object or function');
54
61
  }
@@ -59,6 +66,7 @@ export class PgTestHelpers {
59
66
  const pool = createPgPool(connectionString);
60
67
 
61
68
  this.#fixtureFolder = fixtureFolder;
69
+ this.#ignoreTables = ignoreTables;
62
70
  this.#tablesWithDependencies = tablesWithDependencies;
63
71
  this.#pool = pool;
64
72
  this.#schema = schema;
@@ -127,7 +135,15 @@ export class PgTestHelpers {
127
135
  if (this.#tablesWithDependencies) {
128
136
  await this.#removeTablesByName(this.#tablesWithDependencies);
129
137
  }
130
- await this.#removeTablesByName(await this.#getTableNames());
138
+
139
+ let tableNames = await this.#getTableNames();
140
+ const ignoreTables = this.#ignoreTables;
141
+
142
+ if (ignoreTables) {
143
+ tableNames = tableNames.filter(name => !ignoreTables.includes(name));
144
+ }
145
+
146
+ await this.#removeTablesByName(tableNames);
131
147
  }
132
148
 
133
149
  /** @returns {Promise<void>} */
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAMA,+CAHW,MAAM,GACJ,OAAO,IAAI,EAAE,IAAI,CAO7B;AA2BD,qCAHW,OAAO,GACL,KAAK,IAAI,MAAM,EAAE,CAK7B;AA5BD;IAME,mBAJW,KAAK,WACL,MAAM,YACN,YAAY,EAItB;CACF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAMA,+CAHW,MAAM,GACJ,OAAO,IAAI,EAAE,IAAI,CAO7B;AA4BD,qCAHW,OAAO,GACL,KAAK,IAAI,MAAM,EAAE,CAK7B;AA5BD;IAME,mBAJW,KAAK,WACL,MAAM,YACN,YAAY,EAItB;CACF"}
package/lib/utils.js CHANGED
@@ -11,6 +11,7 @@ export function createPgPool (connectionString) {
11
11
  });
12
12
  }
13
13
 
14
+ // TODO: Export to typed-utils maybe?
14
15
  export class TypeNeverError extends TypeError {
15
16
  /**
16
17
  * @param {never} value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxpelli/pg-utils",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": " My personal database utils / helpers for Postgres",
5
5
  "homepage": "http://github.com/voxpelli/pg-utils",
6
6
  "repository": {