pgsql-test 2.14.13 → 2.14.14

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/esm/utils.js CHANGED
@@ -45,13 +45,35 @@ export const pruneHashes = (row) => mapValues(row, (v, k) => typeof k === 'strin
45
45
  v.startsWith('$')
46
46
  ? '[hash]'
47
47
  : v);
48
- export const prune = (obj) => pruneHashes(pruneUUIDs(pruneIds(pruneIdArrays(pruneDates(obj)))));
49
- export const snapshot = (obj) => {
50
- if (Array.isArray(obj)) {
51
- return obj.map(snapshot);
52
- }
53
- else if (obj && typeof obj === 'object') {
54
- return mapValues(prune(obj), snapshot);
55
- }
56
- return obj;
48
+ export const pruneSchemas = (row) => mapValues(row, (v, k) => typeof v === 'string' && /^zz-/.test(v) ? '[schemahash]' : v);
49
+ export const prunePeoplestamps = (row) => mapValues(row, (v, k) => k.endsWith('_by') && typeof v === 'string' ? '[peoplestamp]' : v);
50
+ export const pruneTokens = (row) => mapValues(row, (v, k) => (k === 'token' || k.endsWith('_token')) && typeof v === 'string'
51
+ ? '[token]'
52
+ : v);
53
+ export const composePruners = (...pruners) => (row) => pruners.reduce((acc, pruner) => pruner(acc), row);
54
+ // Default pruners used by prune/snapshot
55
+ export const defaultPruners = [
56
+ pruneTokens,
57
+ prunePeoplestamps,
58
+ pruneDates,
59
+ pruneIdArrays,
60
+ pruneIds,
61
+ pruneUUIDs,
62
+ pruneHashes
63
+ ];
64
+ export const prune = composePruners(...defaultPruners);
65
+ // Factory to create a snapshot function with custom pruners
66
+ export const createSnapshot = (pruners) => {
67
+ const pruneFn = composePruners(...pruners);
68
+ const snap = (obj) => {
69
+ if (Array.isArray(obj)) {
70
+ return obj.map(snap);
71
+ }
72
+ else if (obj && typeof obj === 'object') {
73
+ return mapValues(pruneFn(obj), snap);
74
+ }
75
+ return obj;
76
+ };
77
+ return snap;
57
78
  };
79
+ export const snapshot = createSnapshot(defaultPruners);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-test",
3
- "version": "2.14.13",
3
+ "version": "2.14.14",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "pgsql-test offers isolated, role-aware, and rollback-friendly PostgreSQL environments for integration tests — giving developers realistic test coverage without external state pollution",
6
6
  "main": "index.js",
@@ -71,5 +71,5 @@
71
71
  "pg-copy-streams": "^7.0.0",
72
72
  "pg-env": "^1.1.7"
73
73
  },
74
- "gitHead": "4e1ff9771c2b07808a9830281abc24d12c689187"
74
+ "gitHead": "00c90828cab8d3e306ebb2bc6053aab4aa9ae807"
75
75
  }
package/utils.d.ts CHANGED
@@ -4,6 +4,13 @@ export declare const pruneIds: (row: AnyObject) => AnyObject;
4
4
  export declare const pruneIdArrays: (row: AnyObject) => AnyObject;
5
5
  export declare const pruneUUIDs: (row: AnyObject) => AnyObject;
6
6
  export declare const pruneHashes: (row: AnyObject) => AnyObject;
7
- export declare const prune: (obj: AnyObject) => AnyObject;
7
+ export declare const pruneSchemas: (row: AnyObject) => AnyObject;
8
+ export declare const prunePeoplestamps: (row: AnyObject) => AnyObject;
9
+ export declare const pruneTokens: (row: AnyObject) => AnyObject;
10
+ type Pruner = (row: AnyObject) => AnyObject;
11
+ export declare const composePruners: (...pruners: Pruner[]) => Pruner;
12
+ export declare const defaultPruners: Pruner[];
13
+ export declare const prune: Pruner;
14
+ export declare const createSnapshot: (pruners: Pruner[]) => (obj: unknown) => unknown;
8
15
  export declare const snapshot: (obj: unknown) => unknown;
9
16
  export {};
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.snapshot = exports.prune = exports.pruneHashes = exports.pruneUUIDs = exports.pruneIdArrays = exports.pruneIds = exports.pruneDates = void 0;
3
+ exports.snapshot = exports.createSnapshot = exports.prune = exports.defaultPruners = exports.composePruners = exports.pruneTokens = exports.prunePeoplestamps = exports.pruneSchemas = exports.pruneHashes = exports.pruneUUIDs = exports.pruneIdArrays = exports.pruneIds = exports.pruneDates = void 0;
4
4
  const uuidRegexp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
5
5
  const idReplacement = (v) => (!v ? v : '[ID]');
6
6
  function mapValues(obj, fn) {
@@ -53,15 +53,40 @@ const pruneHashes = (row) => mapValues(row, (v, k) => typeof k === 'string' &&
53
53
  ? '[hash]'
54
54
  : v);
55
55
  exports.pruneHashes = pruneHashes;
56
- const prune = (obj) => (0, exports.pruneHashes)((0, exports.pruneUUIDs)((0, exports.pruneIds)((0, exports.pruneIdArrays)((0, exports.pruneDates)(obj)))));
57
- exports.prune = prune;
58
- const snapshot = (obj) => {
59
- if (Array.isArray(obj)) {
60
- return obj.map(exports.snapshot);
61
- }
62
- else if (obj && typeof obj === 'object') {
63
- return mapValues((0, exports.prune)(obj), exports.snapshot);
64
- }
65
- return obj;
56
+ const pruneSchemas = (row) => mapValues(row, (v, k) => typeof v === 'string' && /^zz-/.test(v) ? '[schemahash]' : v);
57
+ exports.pruneSchemas = pruneSchemas;
58
+ const prunePeoplestamps = (row) => mapValues(row, (v, k) => k.endsWith('_by') && typeof v === 'string' ? '[peoplestamp]' : v);
59
+ exports.prunePeoplestamps = prunePeoplestamps;
60
+ const pruneTokens = (row) => mapValues(row, (v, k) => (k === 'token' || k.endsWith('_token')) && typeof v === 'string'
61
+ ? '[token]'
62
+ : v);
63
+ exports.pruneTokens = pruneTokens;
64
+ const composePruners = (...pruners) => (row) => pruners.reduce((acc, pruner) => pruner(acc), row);
65
+ exports.composePruners = composePruners;
66
+ // Default pruners used by prune/snapshot
67
+ exports.defaultPruners = [
68
+ exports.pruneTokens,
69
+ exports.prunePeoplestamps,
70
+ exports.pruneDates,
71
+ exports.pruneIdArrays,
72
+ exports.pruneIds,
73
+ exports.pruneUUIDs,
74
+ exports.pruneHashes
75
+ ];
76
+ exports.prune = (0, exports.composePruners)(...exports.defaultPruners);
77
+ // Factory to create a snapshot function with custom pruners
78
+ const createSnapshot = (pruners) => {
79
+ const pruneFn = (0, exports.composePruners)(...pruners);
80
+ const snap = (obj) => {
81
+ if (Array.isArray(obj)) {
82
+ return obj.map(snap);
83
+ }
84
+ else if (obj && typeof obj === 'object') {
85
+ return mapValues(pruneFn(obj), snap);
86
+ }
87
+ return obj;
88
+ };
89
+ return snap;
66
90
  };
67
- exports.snapshot = snapshot;
91
+ exports.createSnapshot = createSnapshot;
92
+ exports.snapshot = (0, exports.createSnapshot)(exports.defaultPruners);