bupkis 0.10.4 → 0.10.6
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/CHANGELOG.md +14 -0
- package/dist/commonjs/diff.d.ts.map +1 -1
- package/dist/commonjs/diff.js +102 -11
- package/dist/commonjs/diff.js.map +1 -1
- package/dist/esm/diff.d.ts.map +1 -1
- package/dist/esm/diff.js +102 -11
- package/dist/esm/diff.js.map +1 -1
- package/package.json +3 -3
- package/src/diff.ts +114 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.10.6](https://github.com/boneskull/bupkis/compare/bupkis-v0.10.5...bupkis-v0.10.6) (2025-10-06)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **deps:** move type-fest to dependencies ([7db2b81](https://github.com/boneskull/bupkis/commit/7db2b81fa14d2cefdcc57835706e694fa0794830))
|
|
9
|
+
|
|
10
|
+
## [0.10.5](https://github.com/boneskull/bupkis/compare/bupkis-v0.10.4...bupkis-v0.10.5) (2025-10-05)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **assertions:** better assertion error messages for regexes ([956c985](https://github.com/boneskull/bupkis/commit/956c9858b4a7c3c004fbe665cff2f1be1492b9c8))
|
|
16
|
+
|
|
3
17
|
## [0.10.4](https://github.com/boneskull/bupkis/compare/bupkis-v0.10.3...bupkis-v0.10.4) (2025-10-05)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,CAAC;AAO5B;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,CAAC,CAAC,QAAQ,EACpB,SAAS,OAAO,KACf,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,CAAC;AAO5B;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,CAAC,CAAC,QAAQ,EACpB,SAAS,OAAO,KACf,UA2JF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,OAAO,EACjB,QAAQ,OAAO,EACf,UAAS,WAAgB,KACxB,IAAI,GAAG,MAYT,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,OAAO,EACf,UAAU,OAAO,KAChB,OACoE,CAAC"}
|
package/dist/commonjs/diff.js
CHANGED
|
@@ -15,7 +15,7 @@ const jest_diff_1 = require("jest-diff");
|
|
|
15
15
|
const { isArray } = Array;
|
|
16
16
|
const { max } = Math;
|
|
17
17
|
const { stringify } = JSON;
|
|
18
|
-
const { entries } = Object;
|
|
18
|
+
const { entries, getOwnPropertyNames } = Object;
|
|
19
19
|
/**
|
|
20
20
|
* Extracts actual and expected values from a `ZodError` for meaningful diffs.
|
|
21
21
|
*
|
|
@@ -36,11 +36,53 @@ const extractDiffValues = (zodError, subject) => {
|
|
|
36
36
|
// Filter path to only string/number keys (symbols are rare in practice)
|
|
37
37
|
const filteredPath = issue.path.filter((key) => typeof key === 'string' || typeof key === 'number');
|
|
38
38
|
switch (issue.code) {
|
|
39
|
+
case 'invalid_format': {
|
|
40
|
+
// For format errors (e.g., regex patterns), show what the pattern expects
|
|
41
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
42
|
+
let correctedValue = actualValue;
|
|
43
|
+
// Try to extract pattern info from the message
|
|
44
|
+
const regexMatch = issue.message.match(/pattern (.+)/);
|
|
45
|
+
if (regexMatch) {
|
|
46
|
+
// For regex patterns, create a placeholder that indicates the expected pattern
|
|
47
|
+
correctedValue = `<string matching ${regexMatch[1]}>`;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// Fallback for other format errors
|
|
51
|
+
correctedValue = '<string in valid format>';
|
|
52
|
+
}
|
|
53
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
39
56
|
case 'invalid_type': {
|
|
40
57
|
const correctedValue = createCorrectValueForType(issue.expected, getValueAtPath(actual, filteredPath));
|
|
41
58
|
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
42
59
|
break;
|
|
43
60
|
}
|
|
61
|
+
case 'invalid_union': {
|
|
62
|
+
// For union errors, we can't easily determine the "correct" value
|
|
63
|
+
// but we can try to provide a hint based on the error context
|
|
64
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
65
|
+
// Check if this is a top-level union error (like regex OR object)
|
|
66
|
+
if (filteredPath.length === 0) {
|
|
67
|
+
// For top-level union errors, try to suggest an alternative format
|
|
68
|
+
if (typeof actualValue === 'object' && actualValue !== null) {
|
|
69
|
+
// If actual is an object, the union might expect a string pattern
|
|
70
|
+
expected = '<string matching pattern>';
|
|
71
|
+
}
|
|
72
|
+
else if (typeof actualValue === 'string') {
|
|
73
|
+
// If actual is a string, the union might expect an object structure
|
|
74
|
+
expected = '<object satisfying schema>';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
expected = '<value matching union schema>';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// For nested union errors, provide a generic placeholder
|
|
82
|
+
expected = setValueAtPath(expected, filteredPath, '<value matching union schema>');
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
44
86
|
case 'invalid_value': {
|
|
45
87
|
// For literal/enum errors, use the first valid value
|
|
46
88
|
const correctedValue = issue.values && issue.values.length > 0
|
|
@@ -203,7 +245,27 @@ const customDeepClone = (value) => {
|
|
|
203
245
|
if (isArray(value)) {
|
|
204
246
|
return value.map(customDeepClone);
|
|
205
247
|
}
|
|
206
|
-
//
|
|
248
|
+
// Special handling for Error objects to preserve non-enumerable properties
|
|
249
|
+
if (value instanceof Error) {
|
|
250
|
+
const cloned = {};
|
|
251
|
+
// Copy enumerable properties
|
|
252
|
+
for (const [key, val] of entries(value)) {
|
|
253
|
+
cloned[key] = customDeepClone(val);
|
|
254
|
+
}
|
|
255
|
+
// Copy non-enumerable properties that are important for Error objects
|
|
256
|
+
for (const prop of getOwnPropertyNames(value)) {
|
|
257
|
+
if (!(prop in cloned)) {
|
|
258
|
+
try {
|
|
259
|
+
cloned[prop] = value[prop];
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
// Skip properties that can't be accessed
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return cloned;
|
|
267
|
+
}
|
|
268
|
+
// For regular objects, create a new object and copy properties
|
|
207
269
|
const cloned = {};
|
|
208
270
|
for (const [key, val] of entries(value)) {
|
|
209
271
|
cloned[key] = customDeepClone(val);
|
|
@@ -262,18 +324,47 @@ const setValueAtPath = (obj, path, value) => {
|
|
|
262
324
|
// Need to create the structure
|
|
263
325
|
obj = typeof path[0] === 'number' ? [] : {};
|
|
264
326
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
327
|
+
if (isArray(obj)) {
|
|
328
|
+
const result = [...obj];
|
|
329
|
+
const [head, ...tail] = path;
|
|
330
|
+
if (head !== undefined) {
|
|
331
|
+
if (tail.length === 0) {
|
|
332
|
+
result[head] = value;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
let result;
|
|
342
|
+
// Handle Error objects and other objects with non-enumerable properties
|
|
343
|
+
if (obj instanceof Error) {
|
|
344
|
+
// For Error objects, copy all own properties (including non-enumerable ones)
|
|
345
|
+
result = {};
|
|
346
|
+
for (const prop of getOwnPropertyNames(obj)) {
|
|
347
|
+
if (prop !== 'stack') {
|
|
348
|
+
// Skip stack to reduce noise
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
350
|
+
result[prop] = obj[prop];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
272
353
|
}
|
|
273
354
|
else {
|
|
274
|
-
|
|
355
|
+
// For regular objects, use spread operator
|
|
356
|
+
result = { ...obj };
|
|
357
|
+
}
|
|
358
|
+
const [head, ...tail] = path;
|
|
359
|
+
if (head !== undefined) {
|
|
360
|
+
if (tail.length === 0) {
|
|
361
|
+
result[head] = value;
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
365
|
+
}
|
|
275
366
|
}
|
|
367
|
+
return result;
|
|
276
368
|
}
|
|
277
|
-
return result;
|
|
278
369
|
};
|
|
279
370
|
//# sourceMappingURL=diff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAKH,yCAAiC;AAGjC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;AAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAKH,yCAAiC;AAGjC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;AAC3B,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;AAYhD;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAC/B,QAAoB,EACpB,OAAgB,EACJ,EAAE;IACd,IAAI,CAAC;QACH,sDAAsD;QACtD,MAAM,MAAM,GAAG,OAAO,CAAC;QAEvB,gDAAgD;QAChD,IAAI,QAAQ,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAE9D,iDAAiD;QACjD,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC;gBACH,wEAAwE;gBACxE,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CACpC,CAAC,GAAG,EAA0B,EAAE,CAC9B,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,CACrD,CAAC;gBAEF,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;oBACnB,KAAK,gBAAgB,CAAC,CAA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sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,CAAC;AAO5B;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,CAAC,CAAC,QAAQ,EACpB,SAAS,OAAO,KACf,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAGhC,YAAY,EAAE,WAAW,EAAE,CAAC;AAO5B;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,0CAA0C;IAC1C,MAAM,EAAE,OAAO,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,CAAC,CAAC,QAAQ,EACpB,SAAS,OAAO,KACf,UA2JF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,UAAU,OAAO,EACjB,QAAQ,OAAO,EACf,UAAS,WAAgB,KACxB,IAAI,GAAG,MAYT,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,OAAO,EACf,UAAU,OAAO,KAChB,OACoE,CAAC"}
|
package/dist/esm/diff.js
CHANGED
|
@@ -12,7 +12,7 @@ import { diff } from 'jest-diff';
|
|
|
12
12
|
const { isArray } = Array;
|
|
13
13
|
const { max } = Math;
|
|
14
14
|
const { stringify } = JSON;
|
|
15
|
-
const { entries } = Object;
|
|
15
|
+
const { entries, getOwnPropertyNames } = Object;
|
|
16
16
|
/**
|
|
17
17
|
* Extracts actual and expected values from a `ZodError` for meaningful diffs.
|
|
18
18
|
*
|
|
@@ -33,11 +33,53 @@ export const extractDiffValues = (zodError, subject) => {
|
|
|
33
33
|
// Filter path to only string/number keys (symbols are rare in practice)
|
|
34
34
|
const filteredPath = issue.path.filter((key) => typeof key === 'string' || typeof key === 'number');
|
|
35
35
|
switch (issue.code) {
|
|
36
|
+
case 'invalid_format': {
|
|
37
|
+
// For format errors (e.g., regex patterns), show what the pattern expects
|
|
38
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
39
|
+
let correctedValue = actualValue;
|
|
40
|
+
// Try to extract pattern info from the message
|
|
41
|
+
const regexMatch = issue.message.match(/pattern (.+)/);
|
|
42
|
+
if (regexMatch) {
|
|
43
|
+
// For regex patterns, create a placeholder that indicates the expected pattern
|
|
44
|
+
correctedValue = `<string matching ${regexMatch[1]}>`;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Fallback for other format errors
|
|
48
|
+
correctedValue = '<string in valid format>';
|
|
49
|
+
}
|
|
50
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
36
53
|
case 'invalid_type': {
|
|
37
54
|
const correctedValue = createCorrectValueForType(issue.expected, getValueAtPath(actual, filteredPath));
|
|
38
55
|
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
39
56
|
break;
|
|
40
57
|
}
|
|
58
|
+
case 'invalid_union': {
|
|
59
|
+
// For union errors, we can't easily determine the "correct" value
|
|
60
|
+
// but we can try to provide a hint based on the error context
|
|
61
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
62
|
+
// Check if this is a top-level union error (like regex OR object)
|
|
63
|
+
if (filteredPath.length === 0) {
|
|
64
|
+
// For top-level union errors, try to suggest an alternative format
|
|
65
|
+
if (typeof actualValue === 'object' && actualValue !== null) {
|
|
66
|
+
// If actual is an object, the union might expect a string pattern
|
|
67
|
+
expected = '<string matching pattern>';
|
|
68
|
+
}
|
|
69
|
+
else if (typeof actualValue === 'string') {
|
|
70
|
+
// If actual is a string, the union might expect an object structure
|
|
71
|
+
expected = '<object satisfying schema>';
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
expected = '<value matching union schema>';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// For nested union errors, provide a generic placeholder
|
|
79
|
+
expected = setValueAtPath(expected, filteredPath, '<value matching union schema>');
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
41
83
|
case 'invalid_value': {
|
|
42
84
|
// For literal/enum errors, use the first valid value
|
|
43
85
|
const correctedValue = issue.values && issue.values.length > 0
|
|
@@ -197,7 +239,27 @@ const customDeepClone = (value) => {
|
|
|
197
239
|
if (isArray(value)) {
|
|
198
240
|
return value.map(customDeepClone);
|
|
199
241
|
}
|
|
200
|
-
//
|
|
242
|
+
// Special handling for Error objects to preserve non-enumerable properties
|
|
243
|
+
if (value instanceof Error) {
|
|
244
|
+
const cloned = {};
|
|
245
|
+
// Copy enumerable properties
|
|
246
|
+
for (const [key, val] of entries(value)) {
|
|
247
|
+
cloned[key] = customDeepClone(val);
|
|
248
|
+
}
|
|
249
|
+
// Copy non-enumerable properties that are important for Error objects
|
|
250
|
+
for (const prop of getOwnPropertyNames(value)) {
|
|
251
|
+
if (!(prop in cloned)) {
|
|
252
|
+
try {
|
|
253
|
+
cloned[prop] = value[prop];
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// Skip properties that can't be accessed
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return cloned;
|
|
261
|
+
}
|
|
262
|
+
// For regular objects, create a new object and copy properties
|
|
201
263
|
const cloned = {};
|
|
202
264
|
for (const [key, val] of entries(value)) {
|
|
203
265
|
cloned[key] = customDeepClone(val);
|
|
@@ -256,18 +318,47 @@ const setValueAtPath = (obj, path, value) => {
|
|
|
256
318
|
// Need to create the structure
|
|
257
319
|
obj = typeof path[0] === 'number' ? [] : {};
|
|
258
320
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
321
|
+
if (isArray(obj)) {
|
|
322
|
+
const result = [...obj];
|
|
323
|
+
const [head, ...tail] = path;
|
|
324
|
+
if (head !== undefined) {
|
|
325
|
+
if (tail.length === 0) {
|
|
326
|
+
result[head] = value;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
let result;
|
|
336
|
+
// Handle Error objects and other objects with non-enumerable properties
|
|
337
|
+
if (obj instanceof Error) {
|
|
338
|
+
// For Error objects, copy all own properties (including non-enumerable ones)
|
|
339
|
+
result = {};
|
|
340
|
+
for (const prop of getOwnPropertyNames(obj)) {
|
|
341
|
+
if (prop !== 'stack') {
|
|
342
|
+
// Skip stack to reduce noise
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
344
|
+
result[prop] = obj[prop];
|
|
345
|
+
}
|
|
346
|
+
}
|
|
266
347
|
}
|
|
267
348
|
else {
|
|
268
|
-
|
|
349
|
+
// For regular objects, use spread operator
|
|
350
|
+
result = { ...obj };
|
|
351
|
+
}
|
|
352
|
+
const [head, ...tail] = path;
|
|
353
|
+
if (head !== undefined) {
|
|
354
|
+
if (tail.length === 0) {
|
|
355
|
+
result[head] = value;
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
359
|
+
}
|
|
269
360
|
}
|
|
361
|
+
return result;
|
|
270
362
|
}
|
|
271
|
-
return result;
|
|
272
363
|
};
|
|
273
364
|
//# sourceMappingURL=diff.js.map
|
package/dist/esm/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;AAC3B,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../../src/diff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;AAC3B,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;AAYhD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAAoB,EACpB,OAAgB,EACJ,EAAE;IACd,IAAI,CAAC;QACH,sDAAsD;QACtD,MAAM,MAAM,GAAG,OAAO,CAAC;QAEvB,gDAAgD;QAChD,IAAI,QAAQ,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAE9D,iDAAiD;QACjD,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC;gBACH,w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AAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bupkis",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Uncommonly extensible assertions for the beautiful people",
|
|
6
6
|
"repository": {
|
|
@@ -156,7 +156,8 @@
|
|
|
156
156
|
"set.prototype.issupersetof": "^1.1.3",
|
|
157
157
|
"set.prototype.symmetricdifference": "^1.1.3",
|
|
158
158
|
"set.prototype.union": "^1.1.3",
|
|
159
|
-
"slug": "^11.0.0"
|
|
159
|
+
"slug": "^11.0.0",
|
|
160
|
+
"type-fest": "4.41.0"
|
|
160
161
|
},
|
|
161
162
|
"optionalDependencies": {
|
|
162
163
|
"zod": "^4.1.5"
|
|
@@ -193,7 +194,6 @@
|
|
|
193
194
|
"serve": "14.2.5",
|
|
194
195
|
"tshy": "3.0.3",
|
|
195
196
|
"tsx": "4.20.6",
|
|
196
|
-
"type-fest": "4.41.0",
|
|
197
197
|
"typedoc": "0.28.13",
|
|
198
198
|
"typedoc-plugin-dt-links": "2.0.21",
|
|
199
199
|
"typedoc-plugin-extras": "4.0.1",
|
package/src/diff.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type { DiffOptions };
|
|
|
18
18
|
const { isArray } = Array;
|
|
19
19
|
const { max } = Math;
|
|
20
20
|
const { stringify } = JSON;
|
|
21
|
-
const { entries } = Object;
|
|
21
|
+
const { entries, getOwnPropertyNames } = Object;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Result of extracting diff values from a `ZodError`
|
|
@@ -59,6 +59,25 @@ export const extractDiffValues = (
|
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
switch (issue.code) {
|
|
62
|
+
case 'invalid_format': {
|
|
63
|
+
// For format errors (e.g., regex patterns), show what the pattern expects
|
|
64
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
65
|
+
let correctedValue = actualValue;
|
|
66
|
+
|
|
67
|
+
// Try to extract pattern info from the message
|
|
68
|
+
const regexMatch = issue.message.match(/pattern (.+)/);
|
|
69
|
+
if (regexMatch) {
|
|
70
|
+
// For regex patterns, create a placeholder that indicates the expected pattern
|
|
71
|
+
correctedValue = `<string matching ${regexMatch[1]}>`;
|
|
72
|
+
} else {
|
|
73
|
+
// Fallback for other format errors
|
|
74
|
+
correctedValue = '<string in valid format>';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
62
81
|
case 'invalid_type': {
|
|
63
82
|
const correctedValue = createCorrectValueForType(
|
|
64
83
|
issue.expected,
|
|
@@ -68,6 +87,34 @@ export const extractDiffValues = (
|
|
|
68
87
|
break;
|
|
69
88
|
}
|
|
70
89
|
|
|
90
|
+
case 'invalid_union': {
|
|
91
|
+
// For union errors, we can't easily determine the "correct" value
|
|
92
|
+
// but we can try to provide a hint based on the error context
|
|
93
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
94
|
+
|
|
95
|
+
// Check if this is a top-level union error (like regex OR object)
|
|
96
|
+
if (filteredPath.length === 0) {
|
|
97
|
+
// For top-level union errors, try to suggest an alternative format
|
|
98
|
+
if (typeof actualValue === 'object' && actualValue !== null) {
|
|
99
|
+
// If actual is an object, the union might expect a string pattern
|
|
100
|
+
expected = '<string matching pattern>';
|
|
101
|
+
} else if (typeof actualValue === 'string') {
|
|
102
|
+
// If actual is a string, the union might expect an object structure
|
|
103
|
+
expected = '<object satisfying schema>';
|
|
104
|
+
} else {
|
|
105
|
+
expected = '<value matching union schema>';
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
// For nested union errors, provide a generic placeholder
|
|
109
|
+
expected = setValueAtPath(
|
|
110
|
+
expected,
|
|
111
|
+
filteredPath,
|
|
112
|
+
'<value matching union schema>',
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
|
|
71
118
|
case 'invalid_value': {
|
|
72
119
|
// For literal/enum errors, use the first valid value
|
|
73
120
|
const correctedValue =
|
|
@@ -251,7 +298,28 @@ const customDeepClone = (value: unknown): unknown => {
|
|
|
251
298
|
if (isArray(value)) {
|
|
252
299
|
return value.map(customDeepClone);
|
|
253
300
|
}
|
|
254
|
-
|
|
301
|
+
|
|
302
|
+
// Special handling for Error objects to preserve non-enumerable properties
|
|
303
|
+
if (value instanceof Error) {
|
|
304
|
+
const cloned: Record<string, unknown> = {};
|
|
305
|
+
// Copy enumerable properties
|
|
306
|
+
for (const [key, val] of entries(value)) {
|
|
307
|
+
cloned[key] = customDeepClone(val);
|
|
308
|
+
}
|
|
309
|
+
// Copy non-enumerable properties that are important for Error objects
|
|
310
|
+
for (const prop of getOwnPropertyNames(value)) {
|
|
311
|
+
if (!(prop in cloned)) {
|
|
312
|
+
try {
|
|
313
|
+
cloned[prop] = (value as unknown as Record<string, unknown>)[prop];
|
|
314
|
+
} catch {
|
|
315
|
+
// Skip properties that can't be accessed
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return cloned;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// For regular objects, create a new object and copy properties
|
|
255
323
|
const cloned: Record<string, unknown> = {};
|
|
256
324
|
for (const [key, val] of entries(value)) {
|
|
257
325
|
cloned[key] = customDeepClone(val);
|
|
@@ -322,22 +390,52 @@ const setValueAtPath = (
|
|
|
322
390
|
obj = typeof path[0] === 'number' ? [] : {};
|
|
323
391
|
}
|
|
324
392
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
393
|
+
if (isArray(obj)) {
|
|
394
|
+
const result = [...(obj as unknown[])];
|
|
395
|
+
const [head, ...tail] = path;
|
|
396
|
+
|
|
397
|
+
if (head !== undefined) {
|
|
398
|
+
if (tail.length === 0) {
|
|
399
|
+
result[head as number] = value;
|
|
400
|
+
} else {
|
|
401
|
+
result[head as number] = setValueAtPath(
|
|
402
|
+
result[head as number],
|
|
403
|
+
tail,
|
|
404
|
+
value,
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
329
408
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
409
|
+
return result;
|
|
410
|
+
} else {
|
|
411
|
+
let result: Record<number | string, unknown>;
|
|
412
|
+
|
|
413
|
+
// Handle Error objects and other objects with non-enumerable properties
|
|
414
|
+
if (obj instanceof Error) {
|
|
415
|
+
// For Error objects, copy all own properties (including non-enumerable ones)
|
|
416
|
+
result = {};
|
|
417
|
+
for (const prop of getOwnPropertyNames(obj)) {
|
|
418
|
+
if (prop !== 'stack') {
|
|
419
|
+
// Skip stack to reduce noise
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
421
|
+
result[prop] = (obj as any)[prop];
|
|
422
|
+
}
|
|
423
|
+
}
|
|
333
424
|
} else {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
tail,
|
|
337
|
-
value,
|
|
338
|
-
);
|
|
425
|
+
// For regular objects, use spread operator
|
|
426
|
+
result = { ...(obj as Record<string, unknown>) };
|
|
339
427
|
}
|
|
340
|
-
}
|
|
341
428
|
|
|
342
|
-
|
|
429
|
+
const [head, ...tail] = path;
|
|
430
|
+
|
|
431
|
+
if (head !== undefined) {
|
|
432
|
+
if (tail.length === 0) {
|
|
433
|
+
result[head] = value;
|
|
434
|
+
} else {
|
|
435
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
343
441
|
};
|