@voxpelli/pg-utils 1.0.0 → 1.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.
package/README.md CHANGED
@@ -17,15 +17,14 @@ import {
17
17
  PgTestHelpers,
18
18
  } from '@voxpelli/pg-utils';
19
19
 
20
- import pg from 'pg';
21
-
22
20
  const pgHelpers = new PgTestHelpers({
23
21
  connectionString: 'postgres://user:pass@localhost/example',
24
- fixtureFolder: new URL('./fixtures', ),
25
- pg,
26
- umzug: new Umzug({
27
- // ...
28
- }),
22
+ fixtureFolder: new URL('./fixtures', import.meta.url),
23
+ schema: new URL('./create-tables.sql', import.meta.url),,
24
+ tablesWithDependencies: [
25
+ 'abc',
26
+ ['foo', 'bar'],
27
+ ]
29
28
  });
30
29
  ```
31
30
 
@@ -38,10 +37,11 @@ Class that creates a helpers instance
38
37
  ```ts
39
38
  new PgTestHelpers({
40
39
  connectionString: 'postgres://user:pass@localhost/example',
41
- fixtureFolder: new URL('./fixtures', ),
42
- umzugInstall: new Umzug({
40
+ fixtureFolder: new URL('./fixtures', import.meta.url),
41
+ schema: new URL('./create-tables.sql', import.meta.url),,
42
+ tablesWithDependencies: [
43
43
  // ...
44
- }),
44
+ ]
45
45
  });
46
46
  ```
47
47
 
@@ -51,10 +51,10 @@ new PgTestHelpers({
51
51
 
52
52
  ### PgTestHelpersOptions
53
53
 
54
- * `connectionString` – _`string`_ – a connection string for the postgres database
55
- * `fixtureFolder` – _`[string]`_ – _optional_ – the path to a folder of `.csv`-file fixtures named by their respective table
56
- * `tablesWithDependencies` – _`[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
57
- * `umzugInstall` – _`Umzug`_ – an umzug instance that can be used to initialize tables
54
+ * `connectionString` – _`string | _ – a connection string for the postgres database
55
+ * `fixtureFolder` – _`[string | URL]`_ – _optional_ – the path to a folder of `.csv`-file fixtures named by their respective table
56
+ * `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
+ * `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
58
 
59
59
  ### Methods
60
60
 
@@ -1,4 +1,3 @@
1
- export function csvFromFolderToDb(connection: ConnectionConfig | Pool, path: string | URL, tablesWithDependencies?: string[] | undefined): Promise<void>;
2
- import type { ConnectionConfig } from './utils.js';
1
+ export function csvFromFolderToDb(connection: string | Pool, path: string | URL, tablesWithDependencies?: string[] | undefined): Promise<void>;
3
2
  import type { Pool } from 'pg';
4
3
  //# sourceMappingURL=csv-folder-to-db.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"csv-folder-to-db.d.ts","sourceRoot":"","sources":["csv-folder-to-db.js"],"names":[],"mappings":"AAmEA,8CALW,gBAAgB,GAAG,IAAI,QACvB,MAAM,GAAG,GAAG,2BACZ,MAAM,EAAE,GAAG,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC,CAwBzB;sCA7EqC,YAAY;0BAFxB,IAAI"}
1
+ {"version":3,"file":"csv-folder-to-db.d.ts","sourceRoot":"","sources":["csv-folder-to-db.js"],"names":[],"mappings":"AAiEA,8CALW,MAAM,GAAG,IAAI,QACb,MAAM,GAAG,GAAG,2BACZ,MAAM,EAAE,GAAG,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC,CAwBzB;0BA7EyB,IAAI"}
@@ -10,8 +10,6 @@ import { createPgPool } from './utils.js';
10
10
 
11
11
  /** @import { Pool } from 'pg' */
12
12
 
13
- /** @import { ConnectionConfig } from './utils.js' */
14
-
15
13
  /**
16
14
  * @param {string | URL} path
17
15
  * @param {string} [extension]
@@ -60,7 +58,7 @@ async function getFilesOrderedByDependencies (path, tablesWithDependencies) {
60
58
  }
61
59
 
62
60
  /**
63
- * @param {ConnectionConfig | Pool} connection
61
+ * @param {string | Pool} connection
64
62
  * @param {string | URL} path
65
63
  * @param {string[] | undefined} [tablesWithDependencies]
66
64
  * @returns {Promise<void>}
@@ -7,11 +7,10 @@ export class PgTestHelpers {
7
7
  #private;
8
8
  }
9
9
  export type PgTestHelpersOptions = {
10
- connectionConfig: ConnectionConfig;
10
+ connectionString: string;
11
11
  fixtureFolder?: string | URL;
12
12
  schema: string | URL | import("umzug").Umzug;
13
13
  tablesWithDependencies?: Array<string[] | string>;
14
14
  };
15
15
  import type { Pool } from 'pg';
16
- import type { ConnectionConfig } from './utils.js';
17
16
  //# sourceMappingURL=test-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAsBA;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,gBAAgB;oBAChB,MAAM,GAAG,GAAG;YACZ,MAAM,GAAG,GAAG,GAAG,OAAO,OAAO,EAAE,KAAK;6BACpC,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BATZ,IAAI;sCAEQ,YAAY"}
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;6BACpC,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;0BAPZ,IAAI"}
@@ -10,11 +10,9 @@ import { createPgPool, isStringArray, TypeNeverError } from './utils.js';
10
10
 
11
11
  /** @import { Pool } from 'pg' */
12
12
 
13
- /** @import { ConnectionConfig } from './utils.js' */
14
-
15
13
  /**
16
14
  * @typedef PgTestHelpersOptions
17
- * @property {ConnectionConfig} connectionConfig
15
+ * @property {string} connectionString
18
16
  * @property {string | URL} [fixtureFolder]
19
17
  * @property {string | URL | import('umzug').Umzug} schema
20
18
  * @property {Array<string[] | string>} [tablesWithDependencies]
@@ -39,14 +37,14 @@ export class PgTestHelpers {
39
37
  }
40
38
 
41
39
  const {
42
- connectionConfig,
40
+ connectionString,
43
41
  fixtureFolder,
44
42
  schema,
45
43
  tablesWithDependencies,
46
44
  } = options;
47
45
 
48
- if (typeof connectionConfig !== 'string' && typeof connectionConfig !== 'object') {
49
- throw new TypeNeverError(connectionConfig, 'Invalid connectionConfig, expected a string or an object');
46
+ if (typeof connectionString !== 'string') {
47
+ throw new TypeNeverError(connectionString, 'Invalid connectionString, expected a string');
50
48
  }
51
49
  if (fixtureFolder && typeof fixtureFolder !== 'string' && !(fixtureFolder instanceof URL)) {
52
50
  throw new TypeNeverError(fixtureFolder, 'Invalid fixtureFolder, expected a string');
@@ -58,7 +56,7 @@ export class PgTestHelpers {
58
56
  throw new TypeNeverError(tablesWithDependencies, 'Invalid tablesWithDependencies, expected an array');
59
57
  }
60
58
 
61
- const pool = createPgPool(connectionConfig);
59
+ const pool = createPgPool(connectionString);
62
60
 
63
61
  this.#fixtureFolder = fixtureFolder;
64
62
  this.#tablesWithDependencies = tablesWithDependencies;
package/lib/utils.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- export function createPgPool(connectionString: ConnectionConfig): import("pg").Pool;
1
+ export function createPgPool(connectionString: string): import("pg").Pool;
2
2
  export function isStringArray(value: unknown): value is string[];
3
3
  export class TypeNeverError extends TypeError {
4
4
  constructor(value: never, message: string, options?: ErrorOptions);
5
5
  }
6
- export type ConnectionConfigObject = Pick<import("pg").ClientConfig, "host" | "port" | "user" | "password" | "stream">;
7
- export type ConnectionConfig = string | ConnectionConfigObject;
8
6
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AASA,+CAHW,gBAAgB,GACd,OAAO,IAAI,EAAE,IAAI,CAO7B;AA2BD,qCAHW,OAAO,GACL,KAAK,IAAI,MAAM,EAAE,CAK7B;AA5BD;IAME,mBAJW,KAAK,WACL,MAAM,YACN,YAAY,EAItB;CACF;qCAvBa,IAAI,CAAC,OAAO,IAAI,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;+BACjF,MAAM,GAAG,sBAAsB"}
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"}
package/lib/utils.js CHANGED
@@ -1,16 +1,13 @@
1
1
  import pg from 'pg';
2
2
 
3
- /** @typedef {Pick<import('pg').ClientConfig, 'host' | 'port' | 'user' | 'password' | 'stream'>} ConnectionConfigObject */
4
- /** @typedef {string | ConnectionConfigObject} ConnectionConfig */
5
-
6
3
  /**
7
- * @param {ConnectionConfig} connectionString
4
+ * @param {string} connectionString
8
5
  * @returns {import('pg').Pool}
9
6
  */
10
7
  export function createPgPool (connectionString) {
11
8
  return new pg.Pool({
12
- ...(typeof connectionString === 'object' ? connectionString : { connectionString }),
13
9
  allowExitOnIdle: true,
10
+ connectionString,
14
11
  });
15
12
  }
16
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxpelli/pg-utils",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": " My personal database utils / helpers for Postgres",
5
5
  "homepage": "http://github.com/voxpelli/pg-utils",
6
6
  "repository": {
@@ -62,7 +62,8 @@
62
62
  "mocha": "^10.8.2",
63
63
  "npm-run-all2": "^7.0.1",
64
64
  "type-coverage": "^2.29.7",
65
- "typescript": "~5.7.2"
65
+ "typescript": "~5.7.2",
66
+ "validate-conventional-commit": "^1.0.4"
66
67
  },
67
68
  "dependencies": {
68
69
  "@types/pg": "^8.11.10",