@feasibleone/blong-chain 1.7.0 → 1.8.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/dist/snapshot.js DELETED
@@ -1,70 +0,0 @@
1
- /**
2
- * Snapshot helper for TAP-based tests.
3
- *
4
- * Provides a thin wrapper around `t.matchSnapshot()` that applies flat
5
- * dot-path masking before comparison, eliminating the need for manual
6
- * normalisation (e.g. replacing dynamic ports or ULIDs) in every test file.
7
- *
8
- * Usage:
9
- *
10
- * ```typescript
11
- * import {snapshot} from '@feasibleone/blong-chain/snapshot';
12
- *
13
- * t.test('my test', async t => {
14
- * const result = await myApiCall();
15
- * snapshot(t, result, 'my-test', {mask: ['createdAt', 'user.userId']});
16
- * });
17
- * ```
18
- *
19
- * The `mask` option accepts an array of dot-delimited paths. Each matching
20
- * leaf value is replaced with the string `'<masked>'` before the snapshot is
21
- * taken. Glob-style wildcards (`*.field`) are not yet supported.
22
- */
23
- /**
24
- * Take a snapshot of `value` using the TAP test context `t`.
25
- *
26
- * Dynamic fields listed in `opts.mask` are replaced with `'<masked>'` so
27
- * that timestamps, IDs, and other non-deterministic values do not cause false
28
- * failures on subsequent runs.
29
- */
30
- export function snapshot(t, value, name, opts = {}) {
31
- const masked = opts.mask?.length ? maskPaths(value, opts.mask) : value;
32
- t.matchSnapshot(masked, name);
33
- }
34
- /**
35
- * Return a deep clone of `value` with the specified dot-path fields replaced
36
- * by `'<masked>'`.
37
- *
38
- * Only JSON-serialisable values are supported (the clone is performed via
39
- * `JSON.parse(JSON.stringify(value))`).
40
- */
41
- export function maskPaths(value, paths) {
42
- if (value === null || value === undefined || typeof value !== 'object') {
43
- return value;
44
- }
45
- // Deep clone via JSON round-trip (safe for plain data objects)
46
- const clone = JSON.parse(JSON.stringify(value));
47
- for (const path of paths) {
48
- setAtPath(clone, path.split('.'));
49
- }
50
- return clone;
51
- }
52
- /** Recursively navigate `obj` along `parts` and replace the leaf with `'<masked>'` */
53
- function setAtPath(obj, parts) {
54
- if (typeof obj !== 'object' || obj === null || parts.length === 0)
55
- return;
56
- const [head, ...tail] = parts;
57
- // Skip prototype-polluting keys to prevent prototype chain manipulation
58
- if (head === '__proto__' || head === 'constructor' || head === 'prototype')
59
- return;
60
- const record = obj;
61
- if (tail.length === 0) {
62
- if (Object.prototype.hasOwnProperty.call(record, head)) {
63
- record[head] = '<masked>';
64
- }
65
- }
66
- else {
67
- setAtPath(record[head], tail);
68
- }
69
- }
70
- //# sourceMappingURL=snapshot.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAqBH;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACpB,CAAmB,EACnB,KAAc,EACd,IAAY,EACZ,OAAyB,EAAE;IAE3B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvE,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc,EAAE,KAAe;IACrD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,+DAA+D;IAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAA4B,CAAC;IAE3E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,K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