pgsql-test 2.16.3 → 2.17.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/esm/utils.js CHANGED
@@ -1,5 +1,12 @@
1
1
  const uuidRegexp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2
- const idReplacement = (v) => (!v ? v : '[ID]');
2
+ const idReplacement = (v, idHash) => {
3
+ if (!v)
4
+ return v;
5
+ if (!idHash)
6
+ return '[ID]';
7
+ const key = String(v);
8
+ return idHash[key] !== undefined ? `[ID-${idHash[key]}]` : '[ID]';
9
+ };
3
10
  function mapValues(obj, fn) {
4
11
  return Object.entries(obj).reduce((acc, [key, value]) => {
5
12
  acc[key] = fn(value, key);
@@ -20,9 +27,9 @@ export const pruneDates = (row) => mapValues(row, (v, k) => {
20
27
  }
21
28
  return v;
22
29
  });
23
- export const pruneIds = (row) => mapValues(row, (v, k) => (k === 'id' || (typeof k === 'string' && k.endsWith('_id'))) &&
30
+ export const pruneIds = (row, idHash) => mapValues(row, (v, k) => (k === 'id' || (typeof k === 'string' && k.endsWith('_id'))) &&
24
31
  (typeof v === 'string' || typeof v === 'number')
25
- ? idReplacement(v)
32
+ ? idReplacement(v, idHash)
26
33
  : v);
27
34
  export const pruneIdArrays = (row) => mapValues(row, (v, k) => typeof k === 'string' && k.endsWith('_ids') && Array.isArray(v)
28
35
  ? `[UUIDs-${v.length}]`
@@ -51,26 +58,31 @@ export const pruneTokens = (row) => mapValues(row, (v, k) => (k === 'token' || k
51
58
  ? '[token]'
52
59
  : v);
53
60
  export const composePruners = (...pruners) => (row) => pruners.reduce((acc, pruner) => pruner(acc), row);
54
- // Default pruners used by prune/snapshot
61
+ // Default pruners used by prune/snapshot (without IdHash)
55
62
  export const defaultPruners = [
56
63
  pruneTokens,
57
64
  prunePeoplestamps,
58
65
  pruneDates,
59
66
  pruneIdArrays,
60
- pruneIds,
61
67
  pruneUUIDs,
62
68
  pruneHashes
63
69
  ];
64
- export const prune = composePruners(...defaultPruners);
70
+ // Compose pruners and apply pruneIds with IdHash support
71
+ export const prune = (row, idHash) => {
72
+ const pruned = composePruners(...defaultPruners)(row);
73
+ return pruneIds(pruned, idHash);
74
+ };
65
75
  // Factory to create a snapshot function with custom pruners
66
76
  export const createSnapshot = (pruners) => {
67
77
  const pruneFn = composePruners(...pruners);
68
- const snap = (obj) => {
78
+ const snap = (obj, idHash) => {
69
79
  if (Array.isArray(obj)) {
70
- return obj.map(snap);
80
+ return obj.map((el) => snap(el, idHash));
71
81
  }
72
82
  else if (obj && typeof obj === 'object') {
73
- return mapValues(pruneFn(obj), snap);
83
+ const pruned = pruneFn(obj);
84
+ const prunedWithIds = pruneIds(pruned, idHash);
85
+ return mapValues(prunedWithIds, (v) => snap(v, idHash));
74
86
  }
75
87
  return obj;
76
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgsql-test",
3
- "version": "2.16.3",
3
+ "version": "2.17.0",
4
4
  "author": "Constructive <developers@constructive.io>",
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",
@@ -60,16 +60,16 @@
60
60
  "makage": "^0.1.8"
61
61
  },
62
62
  "dependencies": {
63
- "@pgpmjs/core": "^3.0.3",
64
- "@pgpmjs/env": "^2.8.1",
65
- "@pgpmjs/logger": "^1.3.2",
66
- "@pgpmjs/server-utils": "^2.8.3",
67
- "@pgpmjs/types": "^2.12.1",
63
+ "@pgpmjs/core": "^3.0.4",
64
+ "@pgpmjs/env": "^2.8.2",
65
+ "@pgpmjs/logger": "^1.3.3",
66
+ "@pgpmjs/server-utils": "^2.8.4",
67
+ "@pgpmjs/types": "^2.12.2",
68
68
  "csv-parse": "^6.1.0",
69
69
  "pg": "^8.16.3",
70
- "pg-cache": "^1.6.3",
70
+ "pg-cache": "^1.6.4",
71
71
  "pg-copy-streams": "^7.0.0",
72
- "pg-env": "^1.2.1"
72
+ "pg-env": "^1.2.2"
73
73
  },
74
- "gitHead": "52828c38b144fdc02b6a9a0c8b0ff795d1752d53"
74
+ "gitHead": "4326e2092d0c57901e898560974d502d626c42cb"
75
75
  }
package/utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ export type IdHash = Record<string, number | string>;
1
2
  type AnyObject = Record<string, any>;
2
3
  export declare const pruneDates: (row: AnyObject) => AnyObject;
3
- export declare const pruneIds: (row: AnyObject) => AnyObject;
4
+ export declare const pruneIds: (row: AnyObject, idHash?: IdHash) => AnyObject;
4
5
  export declare const pruneIdArrays: (row: AnyObject) => AnyObject;
5
6
  export declare const pruneUUIDs: (row: AnyObject) => AnyObject;
6
7
  export declare const pruneHashes: (row: AnyObject) => AnyObject;
@@ -10,7 +11,7 @@ export declare const pruneTokens: (row: AnyObject) => AnyObject;
10
11
  type Pruner = (row: AnyObject) => AnyObject;
11
12
  export declare const composePruners: (...pruners: Pruner[]) => Pruner;
12
13
  export declare const defaultPruners: Pruner[];
13
- export declare const prune: Pruner;
14
- export declare const createSnapshot: (pruners: Pruner[]) => (obj: unknown) => unknown;
15
- export declare const snapshot: (obj: unknown) => unknown;
14
+ export declare const prune: (row: AnyObject, idHash?: IdHash) => AnyObject;
15
+ export declare const createSnapshot: (pruners: Pruner[]) => (obj: unknown, idHash?: IdHash) => unknown;
16
+ export declare const snapshot: (obj: unknown, idHash?: IdHash) => unknown;
16
17
  export {};
package/utils.js CHANGED
@@ -2,7 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
- const idReplacement = (v) => (!v ? v : '[ID]');
5
+ const idReplacement = (v, idHash) => {
6
+ if (!v)
7
+ return v;
8
+ if (!idHash)
9
+ return '[ID]';
10
+ const key = String(v);
11
+ return idHash[key] !== undefined ? `[ID-${idHash[key]}]` : '[ID]';
12
+ };
6
13
  function mapValues(obj, fn) {
7
14
  return Object.entries(obj).reduce((acc, [key, value]) => {
8
15
  acc[key] = fn(value, key);
@@ -24,9 +31,9 @@ const pruneDates = (row) => mapValues(row, (v, k) => {
24
31
  return v;
25
32
  });
26
33
  exports.pruneDates = pruneDates;
27
- const pruneIds = (row) => mapValues(row, (v, k) => (k === 'id' || (typeof k === 'string' && k.endsWith('_id'))) &&
34
+ const pruneIds = (row, idHash) => mapValues(row, (v, k) => (k === 'id' || (typeof k === 'string' && k.endsWith('_id'))) &&
28
35
  (typeof v === 'string' || typeof v === 'number')
29
- ? idReplacement(v)
36
+ ? idReplacement(v, idHash)
30
37
  : v);
31
38
  exports.pruneIds = pruneIds;
32
39
  const pruneIdArrays = (row) => mapValues(row, (v, k) => typeof k === 'string' && k.endsWith('_ids') && Array.isArray(v)
@@ -63,26 +70,32 @@ const pruneTokens = (row) => mapValues(row, (v, k) => (k === 'token' || k.endsWi
63
70
  exports.pruneTokens = pruneTokens;
64
71
  const composePruners = (...pruners) => (row) => pruners.reduce((acc, pruner) => pruner(acc), row);
65
72
  exports.composePruners = composePruners;
66
- // Default pruners used by prune/snapshot
73
+ // Default pruners used by prune/snapshot (without IdHash)
67
74
  exports.defaultPruners = [
68
75
  exports.pruneTokens,
69
76
  exports.prunePeoplestamps,
70
77
  exports.pruneDates,
71
78
  exports.pruneIdArrays,
72
- exports.pruneIds,
73
79
  exports.pruneUUIDs,
74
80
  exports.pruneHashes
75
81
  ];
76
- exports.prune = (0, exports.composePruners)(...exports.defaultPruners);
82
+ // Compose pruners and apply pruneIds with IdHash support
83
+ const prune = (row, idHash) => {
84
+ const pruned = (0, exports.composePruners)(...exports.defaultPruners)(row);
85
+ return (0, exports.pruneIds)(pruned, idHash);
86
+ };
87
+ exports.prune = prune;
77
88
  // Factory to create a snapshot function with custom pruners
78
89
  const createSnapshot = (pruners) => {
79
90
  const pruneFn = (0, exports.composePruners)(...pruners);
80
- const snap = (obj) => {
91
+ const snap = (obj, idHash) => {
81
92
  if (Array.isArray(obj)) {
82
- return obj.map(snap);
93
+ return obj.map((el) => snap(el, idHash));
83
94
  }
84
95
  else if (obj && typeof obj === 'object') {
85
- return mapValues(pruneFn(obj), snap);
96
+ const pruned = pruneFn(obj);
97
+ const prunedWithIds = (0, exports.pruneIds)(pruned, idHash);
98
+ return mapValues(prunedWithIds, (v) => snap(v, idHash));
86
99
  }
87
100
  return obj;
88
101
  };