@voxpelli/pg-utils 4.0.0 → 4.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/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/lib/csv-folder-to-db.d.ts.map +1 -1
- package/lib/csv-folder-to-db.js +2 -1
- package/lib/db-to-csv-folder.d.ts.map +1 -1
- package/lib/db-to-csv-folder.js +2 -1
- package/lib/test-helpers.d.ts +3 -1
- package/lib/test-helpers.d.ts.map +1 -1
- package/lib/test-helpers.js +5 -3
- package/lib/utils.d.ts +0 -1
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -19
- package/package.json +2 -1
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { csvFromFolderToDb } from "./lib/csv-folder-to-db.js";
|
|
2
2
|
export { dbToCsvFolder } from "./lib/db-to-csv-folder.js";
|
|
3
|
+
export type PgTestHelpersOptions = import("./lib/test-helpers.js").PgTestHelpersOptions;
|
|
3
4
|
export { PgTestHelpers, pgTestSetup, pgTestSetupFor } from "./lib/test-helpers.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;mCAIc,OAAO,uBAAuB,EAAE,oBAAoB"}
|
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { csvFromFolderToDb } from './lib/csv-folder-to-db.js';
|
|
2
2
|
export { dbToCsvFolder } from './lib/db-to-csv-folder.js';
|
|
3
3
|
export { PgTestHelpers, pgTestSetup, pgTestSetupFor } from './lib/test-helpers.js';
|
|
4
|
+
|
|
5
|
+
/** @typedef {import('./lib/test-helpers.js').PgTestHelpersOptions} PgTestHelpersOptions */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csv-folder-to-db.d.ts","sourceRoot":"","sources":["csv-folder-to-db.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"csv-folder-to-db.d.ts","sourceRoot":"","sources":["csv-folder-to-db.js"],"names":[],"mappings":"AAmHA,8CALW,MAAM,GAAG,IAAI,QACb,MAAM,GAAG,GAAG,YACZ,MAAM,EAAE,GAAG,wBAAwB,GACjC,OAAO,CAAC,IAAI,CAAC,CAgCzB;;qBA/Ea,MAAM,EAAE;6BACR,MAAM,EAAE;;0BAvDI,IAAI"}
|
package/lib/csv-folder-to-db.js
CHANGED
|
@@ -4,6 +4,7 @@ import pathModule from 'node:path';
|
|
|
4
4
|
import { pipeline as promisedPipeline } from 'node:stream/promises';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
7
|
+
import { isObjectWithKey } from '@voxpelli/typed-utils';
|
|
7
8
|
import { from as copyFrom } from 'pg-copy-streams';
|
|
8
9
|
import pg from 'pg';
|
|
9
10
|
|
|
@@ -116,7 +117,7 @@ export async function csvFromFolderToDb (connection, path, options) {
|
|
|
116
117
|
const tablesWithDependencies = resolveTableOrder(options);
|
|
117
118
|
const files = await getFilesOrderedByDependencies(path, tablesWithDependencies);
|
|
118
119
|
|
|
119
|
-
const ownPool =
|
|
120
|
+
const ownPool = !isObjectWithKey(connection, 'connect');
|
|
120
121
|
const pool = ownPool ? createPgPool(connection) : connection;
|
|
121
122
|
|
|
122
123
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"db-to-csv-folder.d.ts","sourceRoot":"","sources":["db-to-csv-folder.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"db-to-csv-folder.d.ts","sourceRoot":"","sources":["db-to-csv-folder.js"],"names":[],"mappings":"AA+BA,0CANW,MAAM,GAAG,IAAI,cACb,MAAM,GAAG,GAAG,UACZ,MAAM,EAAE,YACR,oBAAoB,GAClB,OAAO,CAAC,IAAI,CAAC,CAgDzB;;cA7Da,MAAM;;0BAJM,IAAI"}
|
package/lib/db-to-csv-folder.js
CHANGED
|
@@ -4,6 +4,7 @@ import pathModule from 'node:path';
|
|
|
4
4
|
import { pipeline } from 'node:stream/promises';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
7
|
+
import { isObjectWithKey } from '@voxpelli/typed-utils';
|
|
7
8
|
import pg from 'pg';
|
|
8
9
|
import { to as copyTo } from 'pg-copy-streams';
|
|
9
10
|
|
|
@@ -49,7 +50,7 @@ export async function dbToCsvFolder (connection, outputPath, tables, options = {
|
|
|
49
50
|
|
|
50
51
|
const escapedOrderBy = isColumnIndex ? orderBy : pg.escapeIdentifier(orderBy);
|
|
51
52
|
|
|
52
|
-
const ownPool =
|
|
53
|
+
const ownPool = !isObjectWithKey(connection, 'connect');
|
|
53
54
|
const pool = ownPool ? createPgPool(connection) : connection;
|
|
54
55
|
|
|
55
56
|
try {
|
package/lib/test-helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function pgTestSetup(options: PgTestHelpersOptions): Promise<PgTestHelpers>;
|
|
2
|
-
export function pgTestSetupFor(options: PgTestHelpersOptions, t: {
|
|
2
|
+
export function pgTestSetupFor(options: PgTestHelpersOptions, t: TestContext | SuiteContext | {
|
|
3
3
|
after?: (fn: () => Promise<void>) => void;
|
|
4
4
|
}): Promise<PgTestHelpers>;
|
|
5
5
|
export class PgTestHelpers {
|
|
@@ -25,5 +25,7 @@ export type PgTestHelpersOptions = {
|
|
|
25
25
|
tableLoadOrder?: Array<string[] | string>;
|
|
26
26
|
tablesWithDependencies?: Array<string[] | string>;
|
|
27
27
|
};
|
|
28
|
+
import type { TestContext } from 'node:test';
|
|
29
|
+
import type { SuiteContext } from 'node:test';
|
|
28
30
|
import type { Pool } from 'pg';
|
|
29
31
|
//# sourceMappingURL=test-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"test-helpers.d.ts","sourceRoot":"","sources":["test-helpers.js"],"names":[],"mappings":"AAgVA,qCAHW,oBAAoB,GAClB,OAAO,CAAC,aAAa,CAAC,CAIlC;AAgBD,wCAJW,oBAAoB,KACpB,WAAW,GAAG,YAAY,GAAG;IAAE,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAA;CAAE,GACxE,OAAO,CAAC,aAAa,CAAC,CAUlC;AA7UD;IA2BE,qBADY,oBAAoB,EAsF/B;IAxFD,cADW,IAAI,CAAC,OAAO,CAAC,CACX;IAqKb,cADc,OAAO,CAAC,IAAI,CAAC,CAoB1B;IAGD,kBADc,OAAO,CAAC,IAAI,CAAC,CAuB1B;IASD,SAFa,OAAO,CAAC,IAAI,CAAC,CAgBzB;IAGD,gBADc,OAAO,CAAC,IAAI,CAAC,CAqB1B;IAGD,OADc,OAAO,CAAC,IAAI,CAAC,CAW1B;IAGD,yBADc,OAAO,CAAC,IAAI,CAAC,CAG1B;;CACF;;sBAtTa,MAAM;oBACN,MAAM,GAAG,GAAG;mBACZ,MAAM,EAAE;aACR,MAAM;oBACN,MAAM;yBACN,MAAM;iCACN,MAAM;YACN,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;qBAC9I,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;6BACxB,KAAK,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;;iCAbS,WAAW;kCAAX,WAAW;0BADxB,IAAI"}
|
package/lib/test-helpers.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
|
|
3
|
+
import { isKeyWithType, isStringArray } from '@voxpelli/typed-utils';
|
|
3
4
|
import pg from 'pg';
|
|
4
5
|
import {
|
|
5
6
|
createUmzeptionPgContext,
|
|
@@ -7,9 +8,10 @@ import {
|
|
|
7
8
|
} from 'umzeption';
|
|
8
9
|
|
|
9
10
|
import { csvFromFolderToDb } from './csv-folder-to-db.js';
|
|
10
|
-
import { createPgPool, createAndLockConnection, releaseLock,
|
|
11
|
+
import { createPgPool, createAndLockConnection, releaseLock, TypeNeverError } from './utils.js';
|
|
11
12
|
|
|
12
13
|
/** @import { Pool, Client } from 'pg' */
|
|
14
|
+
/** @import { TestContext, SuiteContext } from 'node:test' */
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* @typedef PgTestHelpersOptions
|
|
@@ -347,11 +349,11 @@ export async function pgTestSetup (options) {
|
|
|
347
349
|
* (which has `after`). A clear error is thrown if `after` is missing.
|
|
348
350
|
*
|
|
349
351
|
* @param {PgTestHelpersOptions} options
|
|
350
|
-
* @param {{ after?: (fn: () => Promise<void>) => void }} t Test context.
|
|
352
|
+
* @param {TestContext | SuiteContext | { after?: (fn: () => Promise<void>) => void }} t Test context.
|
|
351
353
|
* @returns {Promise<PgTestHelpers>}
|
|
352
354
|
*/
|
|
353
355
|
export async function pgTestSetupFor (options, t) {
|
|
354
|
-
if (
|
|
356
|
+
if (!isKeyWithType(t, 'after', 'function')) {
|
|
355
357
|
throw new TypeError('pgTestSetupFor requires a test context with an after() method');
|
|
356
358
|
}
|
|
357
359
|
|
package/lib/utils.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export function createAndLockConnection(connectionString: string, options?: {
|
|
|
4
4
|
lockTimeoutMs?: number;
|
|
5
5
|
}): Promise<Client>;
|
|
6
6
|
export function releaseLock(lockClient: Client | Promise<Client>, lockId?: number): Promise<void>;
|
|
7
|
-
export function isStringArray(value: unknown): value is string[];
|
|
8
7
|
export class TypeNeverError extends TypeError {
|
|
9
8
|
constructor(value: never, message: string, options?: ErrorOptions);
|
|
10
9
|
}
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAuBA,+CAHW,MAAM,GACJ,IAAI,CAOhB;AAOD,0DAJW,MAAM,YACN;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC,OAAO,CAAC,MAAM,CAAC,CAwC3B;AAOD,wCAJW,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WACxB,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAUzB;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["utils.js"],"names":[],"mappings":"AAuBA,+CAHW,MAAM,GACJ,IAAI,CAOhB;AAOD,0DAJW,MAAM,YACN;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC,OAAO,CAAC,MAAM,CAAC,CAwC3B;AAOD,wCAJW,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WACxB,MAAM,GACJ,OAAO,CAAC,IAAI,CAAC,CAUzB;AAGD;IAME,mBAJW,KAAK,WACL,MAAM,YACN,YAAY,EAItB;CACF;0BAlGiC,IAAI;4BAAJ,IAAI"}
|
package/lib/utils.js
CHANGED
|
@@ -99,22 +99,3 @@ export class TypeNeverError extends TypeError {
|
|
|
99
99
|
super(`${message}. Got: ${typeof value}`, options);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Array.isArray() on its own give type any[]
|
|
105
|
-
*
|
|
106
|
-
* @param {unknown} value
|
|
107
|
-
* @returns {value is unknown[]}
|
|
108
|
-
*/
|
|
109
|
-
function typesafeIsArray (value) {
|
|
110
|
-
return Array.isArray(value);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param {unknown} value
|
|
115
|
-
* @returns {value is string[]}
|
|
116
|
-
*/
|
|
117
|
-
export function isStringArray (value) {
|
|
118
|
-
if (!typesafeIsArray(value)) return false;
|
|
119
|
-
return value.every(item => typeof item === 'string');
|
|
120
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxpelli/pg-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": " My personal database utils / helpers for Postgres",
|
|
5
5
|
"homepage": "http://github.com/voxpelli/pg-utils",
|
|
6
6
|
"repository": {
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@types/pg": "^8.16.0",
|
|
74
|
+
"@voxpelli/typed-utils": "^4.1.0",
|
|
74
75
|
"pg": "^8.18.0",
|
|
75
76
|
"pg-copy-streams": "^7.0.0",
|
|
76
77
|
"umzeption": "^0.4.1",
|