bupkis 0.7.2 → 0.9.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/CHANGELOG.md +15 -0
- package/README.md +19 -2
- package/dist/commonjs/assertion/assertion-async.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-async.js +37 -7
- package/dist/commonjs/assertion/assertion-async.js.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-sync.js +32 -8
- package/dist/commonjs/assertion/assertion-sync.js.map +1 -1
- package/dist/commonjs/assertion/assertion-types.d.ts +37 -31
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion-types.js +0 -32
- package/dist/commonjs/assertion/assertion-types.js.map +1 -1
- package/dist/commonjs/assertion/assertion.d.ts +3 -21
- package/dist/commonjs/assertion/assertion.d.ts.map +1 -1
- package/dist/commonjs/assertion/assertion.js +42 -27
- package/dist/commonjs/assertion/assertion.js.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +2 -0
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +38 -42
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.d.ts +16 -4
- package/dist/commonjs/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.js +20 -15
- package/dist/commonjs/assertion/impl/assertion-util.js.map +1 -1
- package/dist/commonjs/assertion/impl/async-parametric.d.ts +63 -11
- package/dist/commonjs/assertion/impl/async-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async-parametric.js +89 -52
- package/dist/commonjs/assertion/impl/async-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +116 -12
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.js +6 -4
- package/dist/commonjs/assertion/impl/sync-basic.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-collection.js +24 -14
- package/dist/commonjs/assertion/impl/sync-collection.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts +1 -5
- package/dist/commonjs/assertion/impl/sync-esoteric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-esoteric.js +11 -13
- package/dist/commonjs/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +27 -7
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +75 -51
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +54 -22
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync.js +1 -1
- package/dist/commonjs/assertion/impl/sync.js.map +1 -1
- package/dist/commonjs/assertion/index.d.ts +1 -1
- package/dist/commonjs/assertion/index.d.ts.map +1 -1
- package/dist/commonjs/assertion/index.js +0 -1
- package/dist/commonjs/assertion/index.js.map +1 -1
- package/dist/commonjs/assertion/slotify.d.ts +1 -13
- package/dist/commonjs/assertion/slotify.d.ts.map +1 -1
- package/dist/commonjs/assertion/slotify.js +49 -16
- package/dist/commonjs/assertion/slotify.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +85 -17
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +1 -0
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/diff.d.ts +51 -0
- package/dist/commonjs/diff.d.ts.map +1 -0
- package/dist/commonjs/diff.js +279 -0
- package/dist/commonjs/diff.js.map +1 -0
- package/dist/commonjs/error.d.ts +37 -18
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +44 -30
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +131 -78
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +24 -10
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +56 -39
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +85 -17
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/internal-schema.d.ts +25 -0
- package/dist/commonjs/internal-schema.d.ts.map +1 -0
- package/dist/commonjs/internal-schema.js +209 -0
- package/dist/commonjs/internal-schema.js.map +1 -0
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +3 -2
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/use.js +22 -8
- package/dist/commonjs/use.js.map +1 -1
- package/dist/commonjs/util.d.ts +1 -0
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +14 -10
- package/dist/commonjs/util.js.map +1 -1
- package/dist/commonjs/value-to-schema.d.ts +1 -0
- package/dist/commonjs/value-to-schema.d.ts.map +1 -1
- package/dist/commonjs/value-to-schema.js +19 -12
- package/dist/commonjs/value-to-schema.js.map +1 -1
- package/dist/esm/assertion/assertion-async.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-async.js +37 -7
- package/dist/esm/assertion/assertion-async.js.map +1 -1
- package/dist/esm/assertion/assertion-sync.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-sync.js +32 -8
- package/dist/esm/assertion/assertion-sync.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +37 -31
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/assertion-types.js +1 -31
- package/dist/esm/assertion/assertion-types.js.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +3 -21
- package/dist/esm/assertion/assertion.d.ts.map +1 -1
- package/dist/esm/assertion/assertion.js +42 -27
- package/dist/esm/assertion/assertion.js.map +1 -1
- package/dist/esm/assertion/create.d.ts +2 -0
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +37 -41
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.d.ts +16 -4
- package/dist/esm/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.js +20 -15
- package/dist/esm/assertion/impl/assertion-util.js.map +1 -1
- package/dist/esm/assertion/impl/async-parametric.d.ts +63 -11
- package/dist/esm/assertion/impl/async-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async-parametric.js +89 -52
- package/dist/esm/assertion/impl/async-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +116 -12
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +2 -2
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.js +6 -4
- package/dist/esm/assertion/impl/sync-basic.js.map +1 -1
- package/dist/esm/assertion/impl/sync-collection.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-collection.js +24 -14
- package/dist/esm/assertion/impl/sync-collection.js.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.d.ts +1 -5
- package/dist/esm/assertion/impl/sync-esoteric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-esoteric.js +11 -13
- package/dist/esm/assertion/impl/sync-esoteric.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +27 -7
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +75 -51
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +54 -22
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync.js +2 -2
- package/dist/esm/assertion/impl/sync.js.map +1 -1
- package/dist/esm/assertion/index.d.ts +1 -1
- package/dist/esm/assertion/index.d.ts.map +1 -1
- package/dist/esm/assertion/index.js +0 -1
- package/dist/esm/assertion/index.js.map +1 -1
- package/dist/esm/assertion/slotify.d.ts +1 -13
- package/dist/esm/assertion/slotify.d.ts.map +1 -1
- package/dist/esm/assertion/slotify.js +50 -17
- package/dist/esm/assertion/slotify.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +85 -17
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +1 -0
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/diff.d.ts +51 -0
- package/dist/esm/diff.d.ts.map +1 -0
- package/dist/esm/diff.js +273 -0
- package/dist/esm/diff.js.map +1 -0
- package/dist/esm/error.d.ts +37 -18
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +41 -27
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +133 -80
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +24 -10
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +52 -36
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +85 -17
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/internal-schema.d.ts +25 -0
- package/dist/esm/internal-schema.d.ts.map +1 -0
- package/dist/esm/internal-schema.js +203 -0
- package/dist/esm/internal-schema.js.map +1 -0
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +3 -2
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/use.js +19 -6
- package/dist/esm/use.js.map +1 -1
- package/dist/esm/util.d.ts +1 -0
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +14 -10
- package/dist/esm/util.js.map +1 -1
- package/dist/esm/value-to-schema.d.ts +1 -0
- package/dist/esm/value-to-schema.d.ts.map +1 -1
- package/dist/esm/value-to-schema.js +20 -13
- package/dist/esm/value-to-schema.js.map +1 -1
- package/package.json +29 -11
- package/src/assertion/assertion-async.ts +42 -14
- package/src/assertion/assertion-sync.ts +40 -17
- package/src/assertion/assertion-types.ts +55 -45
- package/src/assertion/assertion.ts +49 -32
- package/src/assertion/create.ts +46 -65
- package/src/assertion/impl/assertion-util.ts +31 -18
- package/src/assertion/impl/async-parametric.ts +93 -52
- package/src/assertion/impl/async.ts +2 -2
- package/src/assertion/impl/sync-basic.ts +7 -4
- package/src/assertion/impl/sync-collection.ts +34 -14
- package/src/assertion/impl/sync-esoteric.ts +17 -13
- package/src/assertion/impl/sync-parametric.ts +79 -52
- package/src/assertion/impl/sync.ts +2 -2
- package/src/assertion/index.ts +1 -1
- package/src/assertion/slotify.ts +67 -21
- package/src/bootstrap.ts +1 -0
- package/src/diff.ts +343 -0
- package/src/error.ts +66 -31
- package/src/expect.ts +195 -129
- package/src/guards.ts +74 -48
- package/src/internal-schema.ts +246 -0
- package/src/schema.ts +4 -2
- package/src/use.ts +21 -7
- package/src/util.ts +15 -12
- package/src/value-to-schema.ts +21 -13
package/dist/esm/diff.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff utilities for generating rich assertion failure output.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for extracting meaningful actual/expected
|
|
5
|
+
* values from Zod validation errors and generating high-quality diff output
|
|
6
|
+
* using `jest-diff` for assertion failures.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
* @see {@link https://npm.im/jest-diff | jest-diff}
|
|
10
|
+
*/
|
|
11
|
+
import { diff } from 'jest-diff';
|
|
12
|
+
const { isArray } = Array;
|
|
13
|
+
const { max } = Math;
|
|
14
|
+
const { stringify } = JSON;
|
|
15
|
+
const { entries } = Object;
|
|
16
|
+
/**
|
|
17
|
+
* Extracts actual and expected values from a `ZodError` for meaningful diffs.
|
|
18
|
+
*
|
|
19
|
+
* @function
|
|
20
|
+
* @param zodError The `ZodError` to extract values from
|
|
21
|
+
* @param subject The original subject that failed validation
|
|
22
|
+
* @returns Object with actual and expected values for diff
|
|
23
|
+
*/
|
|
24
|
+
export const extractDiffValues = (zodError, subject) => {
|
|
25
|
+
try {
|
|
26
|
+
// Start with the original subject as the actual value
|
|
27
|
+
const actual = subject;
|
|
28
|
+
// Create a copy to modify as the expected value
|
|
29
|
+
let expected = subject != null ? deepClone(subject) : subject;
|
|
30
|
+
// Process each issue to build the expected value
|
|
31
|
+
for (const issue of zodError.issues) {
|
|
32
|
+
try {
|
|
33
|
+
// Filter path to only string/number keys (symbols are rare in practice)
|
|
34
|
+
const filteredPath = issue.path.filter((key) => typeof key === 'string' || typeof key === 'number');
|
|
35
|
+
switch (issue.code) {
|
|
36
|
+
case 'invalid_type': {
|
|
37
|
+
const correctedValue = createCorrectValueForType(issue.expected, getValueAtPath(actual, filteredPath));
|
|
38
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'invalid_value': {
|
|
42
|
+
// For literal/enum errors, use the first valid value
|
|
43
|
+
const correctedValue = issue.values && issue.values.length > 0
|
|
44
|
+
? issue.values[0]
|
|
45
|
+
: '<valid value>';
|
|
46
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'too_big': {
|
|
50
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
51
|
+
let correctedValue;
|
|
52
|
+
if (issue.origin === 'string' && typeof actualValue === 'string') {
|
|
53
|
+
correctedValue = actualValue.slice(0, Number(issue.maximum));
|
|
54
|
+
}
|
|
55
|
+
else if (issue.origin === 'array' && isArray(actualValue)) {
|
|
56
|
+
correctedValue = actualValue.slice(0, Number(issue.maximum));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
correctedValue = issue.maximum;
|
|
60
|
+
}
|
|
61
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case 'too_small': {
|
|
65
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
66
|
+
let correctedValue;
|
|
67
|
+
if (issue.origin === 'string' && typeof actualValue === 'string') {
|
|
68
|
+
const needed = Number(issue.minimum) - actualValue.length;
|
|
69
|
+
correctedValue = actualValue + 'x'.repeat(max(0, needed));
|
|
70
|
+
}
|
|
71
|
+
else if (issue.origin === 'array' && isArray(actualValue)) {
|
|
72
|
+
const needed = Number(issue.minimum) - actualValue.length;
|
|
73
|
+
correctedValue = actualValue.concat(new Array(max(0, needed)).fill(null));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
correctedValue = issue.minimum;
|
|
77
|
+
}
|
|
78
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case 'unrecognized_keys': {
|
|
82
|
+
// Remove unrecognized keys from expected
|
|
83
|
+
if (filteredPath.length === 0 &&
|
|
84
|
+
typeof expected === 'object' &&
|
|
85
|
+
expected !== null) {
|
|
86
|
+
const expectedCopy = {
|
|
87
|
+
...expected,
|
|
88
|
+
};
|
|
89
|
+
for (const key of issue.keys) {
|
|
90
|
+
delete expectedCopy[key];
|
|
91
|
+
}
|
|
92
|
+
expected = expectedCopy;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
default: {
|
|
97
|
+
// For other error types, just mark that something should be different
|
|
98
|
+
// but don't try to guess what the correct value should be
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// If we can't process an individual issue, continue with others
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { actual, expected };
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// If anything goes wrong, return undefined to fall back to pretty error
|
|
112
|
+
return { actual: undefined, expected: undefined };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Generates a rich diff string using jest-diff for assertion failures.
|
|
117
|
+
*
|
|
118
|
+
* @function
|
|
119
|
+
* @param expected The expected value
|
|
120
|
+
* @param actual The actual value
|
|
121
|
+
* @param options Configuration options for diff generation
|
|
122
|
+
* @returns A formatted diff string, or null if values are identical
|
|
123
|
+
*/
|
|
124
|
+
export const generateDiff = (expected, actual, options = {}) => {
|
|
125
|
+
if (!shouldGenerateDiff(actual, expected)) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return diff(expected, actual, {
|
|
129
|
+
aAnnotation: 'expected',
|
|
130
|
+
bAnnotation: 'actual',
|
|
131
|
+
expand: false,
|
|
132
|
+
includeChangeCounts: true,
|
|
133
|
+
...options,
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Checks if two values should generate a meaningful diff.
|
|
138
|
+
*
|
|
139
|
+
* @function
|
|
140
|
+
* @param actual The actual value
|
|
141
|
+
* @param expected The expected value
|
|
142
|
+
* @returns True if a diff should be generated, false otherwise
|
|
143
|
+
*/
|
|
144
|
+
export const shouldGenerateDiff = (actual, expected) => actual !== undefined && expected !== undefined && actual !== expected;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a corrected value for a given type
|
|
147
|
+
*
|
|
148
|
+
* @function
|
|
149
|
+
*/
|
|
150
|
+
const createCorrectValueForType = (expectedType, actualValue) => {
|
|
151
|
+
switch (expectedType) {
|
|
152
|
+
case 'array':
|
|
153
|
+
return isArray(actualValue) ? actualValue : [];
|
|
154
|
+
case 'boolean':
|
|
155
|
+
return typeof actualValue === 'boolean'
|
|
156
|
+
? actualValue
|
|
157
|
+
: Boolean(actualValue);
|
|
158
|
+
case 'null':
|
|
159
|
+
return null;
|
|
160
|
+
case 'number':
|
|
161
|
+
return typeof actualValue === 'number'
|
|
162
|
+
? actualValue
|
|
163
|
+
: Number(actualValue) || 0;
|
|
164
|
+
case 'object':
|
|
165
|
+
return typeof actualValue === 'object' && actualValue !== null
|
|
166
|
+
? actualValue
|
|
167
|
+
: {};
|
|
168
|
+
case 'string':
|
|
169
|
+
if (typeof actualValue === 'string') {
|
|
170
|
+
return actualValue;
|
|
171
|
+
}
|
|
172
|
+
if (actualValue == null) {
|
|
173
|
+
return '';
|
|
174
|
+
}
|
|
175
|
+
if (typeof actualValue === 'object') {
|
|
176
|
+
return stringify(actualValue);
|
|
177
|
+
}
|
|
178
|
+
// For primitive types (number, boolean, etc.) - we know it's not an object here
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
180
|
+
return `${actualValue}`;
|
|
181
|
+
case 'undefined':
|
|
182
|
+
return undefined;
|
|
183
|
+
default:
|
|
184
|
+
return `<${expectedType}>`;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Custom deep clone implementation for values that structuredClone can't
|
|
189
|
+
* handle. Used as fallback when structuredClone fails.
|
|
190
|
+
*
|
|
191
|
+
* @function
|
|
192
|
+
*/
|
|
193
|
+
const customDeepClone = (value) => {
|
|
194
|
+
if (value === null || typeof value !== 'object') {
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
if (isArray(value)) {
|
|
198
|
+
return value.map(customDeepClone);
|
|
199
|
+
}
|
|
200
|
+
// For objects, create a new object and copy properties
|
|
201
|
+
const cloned = {};
|
|
202
|
+
for (const [key, val] of entries(value)) {
|
|
203
|
+
cloned[key] = customDeepClone(val);
|
|
204
|
+
}
|
|
205
|
+
return cloned;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Deep clone a value to avoid mutating the original. Uses the native
|
|
209
|
+
* structuredClone API which handles more types and circular references better
|
|
210
|
+
* than a custom implementation. Falls back to custom implementation for values
|
|
211
|
+
* containing functions.
|
|
212
|
+
*
|
|
213
|
+
* @function
|
|
214
|
+
*/
|
|
215
|
+
const deepClone = (value) => {
|
|
216
|
+
try {
|
|
217
|
+
return structuredClone(value);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
// Handle DataCloneError for values that can't be cloned (functions, symbols, etc.)
|
|
221
|
+
if (error instanceof Error && error.name === 'DataCloneError') {
|
|
222
|
+
return customDeepClone(value);
|
|
223
|
+
}
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Gets a value at a specific path in an object
|
|
229
|
+
*
|
|
230
|
+
* @function
|
|
231
|
+
*/
|
|
232
|
+
const getValueAtPath = (obj, path) => {
|
|
233
|
+
if (path.length === 0) {
|
|
234
|
+
return obj;
|
|
235
|
+
}
|
|
236
|
+
let current = obj;
|
|
237
|
+
for (const key of path) {
|
|
238
|
+
if (current == null) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
current = current[key];
|
|
242
|
+
}
|
|
243
|
+
return current;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Returns a new object with the value at the specified path set to the given
|
|
247
|
+
* value.
|
|
248
|
+
*
|
|
249
|
+
* @function
|
|
250
|
+
*/
|
|
251
|
+
const setValueAtPath = (obj, path, value) => {
|
|
252
|
+
if (path.length === 0) {
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
if (obj == null) {
|
|
256
|
+
// Need to create the structure
|
|
257
|
+
obj = typeof path[0] === 'number' ? [] : {};
|
|
258
|
+
}
|
|
259
|
+
const result = isArray(obj)
|
|
260
|
+
? [...obj]
|
|
261
|
+
: { ...obj };
|
|
262
|
+
const [head, ...tail] = path;
|
|
263
|
+
if (head !== undefined) {
|
|
264
|
+
if (tail.length === 0) {
|
|
265
|
+
result[head] = value;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
269
|
+
}
|
|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KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;QACzB,CAAC,CAAC,CAAC,GAAI,GAAiB,CAAC;QACzB,CAAC,CAAC,EAAE,GAAI,GAA+B,EAAE,CAAC;IAC5C,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAE7B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,MAA2C,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAC7D,CAAC;aAAM,CAAC;YACL,MAA2C,CAAC,IAAI,CAAC,GAAG,cAAc,CAChE,MAA2C,CAAC,IAAI,CAAC,EAClD,IAAI,EACJ,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/dist/esm/error.d.ts
CHANGED
|
@@ -7,6 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { AssertionError as NodeAssertionError } from 'node:assert';
|
|
9
9
|
import { kBupkisError } from './constant.js';
|
|
10
|
+
/**
|
|
11
|
+
* Options for {@link AssertionError}'s constructor
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Based on Node.js' {@link NodeAssertionError}'s constructor options, sans
|
|
15
|
+
* `operator`.
|
|
16
|
+
* @group Error Options
|
|
17
|
+
*/
|
|
18
|
+
export type AssertionErrorOptions = Partial<Omit<NonNullable<ConstructorParameters<typeof NodeAssertionError>[0]>, 'operator'>>;
|
|
10
19
|
/**
|
|
11
20
|
* Options for {@link AssertionImplementationError}
|
|
12
21
|
*
|
|
@@ -30,7 +39,7 @@ export interface InvalidMetadataErrorOptions extends ErrorOptions {
|
|
|
30
39
|
metadata?: unknown;
|
|
31
40
|
}
|
|
32
41
|
/**
|
|
33
|
-
* Options for {@link
|
|
42
|
+
* Options for {@link InvalidObjectSchemaError}
|
|
34
43
|
*
|
|
35
44
|
* @group Error Options
|
|
36
45
|
*/
|
|
@@ -61,6 +70,7 @@ export interface UnknownAssertionErrorOptions<T extends readonly unknown[]> exte
|
|
|
61
70
|
*/
|
|
62
71
|
export declare class AssertionError extends NodeAssertionError {
|
|
63
72
|
name: string;
|
|
73
|
+
constructor(options?: AssertionErrorOptions);
|
|
64
74
|
/**
|
|
65
75
|
* Type guard for an instance of this error.
|
|
66
76
|
*
|
|
@@ -68,6 +78,13 @@ export declare class AssertionError extends NodeAssertionError {
|
|
|
68
78
|
* @returns `true` if `value` is an instance of `AssertionError`
|
|
69
79
|
*/
|
|
70
80
|
static isAssertionError(value: unknown): value is AssertionError;
|
|
81
|
+
toJSON(): {
|
|
82
|
+
actual: unknown;
|
|
83
|
+
expected: unknown;
|
|
84
|
+
message: string;
|
|
85
|
+
name: string;
|
|
86
|
+
stack: string | undefined;
|
|
87
|
+
};
|
|
71
88
|
}
|
|
72
89
|
/**
|
|
73
90
|
* Base class for all custom errors thrown by <span
|
|
@@ -93,6 +110,7 @@ export declare class AssertionImplementationError extends BupkisError {
|
|
|
93
110
|
name: string;
|
|
94
111
|
readonly result: unknown;
|
|
95
112
|
constructor(message: string, options?: AssertionImplementationErrorOptions);
|
|
113
|
+
static isAssertionImplementationError(err: unknown): err is AssertionImplementationError;
|
|
96
114
|
}
|
|
97
115
|
/**
|
|
98
116
|
* Variant of an {@link AssertionError} that is thrown when
|
|
@@ -119,16 +137,31 @@ export declare class InvalidMetadataError extends BupkisError {
|
|
|
119
137
|
constructor(message: string, options?: InvalidMetadataErrorOptions);
|
|
120
138
|
}
|
|
121
139
|
/**
|
|
122
|
-
* Thrown from certain assertions when
|
|
140
|
+
* Thrown from certain assertions when a parameter cannot be used as an "object
|
|
141
|
+
* schema"
|
|
123
142
|
*
|
|
124
143
|
* @group Errors
|
|
125
144
|
*/
|
|
126
|
-
export declare class
|
|
127
|
-
readonly code = "
|
|
145
|
+
export declare class InvalidObjectSchemaError extends BupkisError {
|
|
146
|
+
readonly code = "ERR_BUPKIS_INVALID_OBJECT_SCHEMA";
|
|
128
147
|
name: string;
|
|
129
148
|
readonly schema?: unknown;
|
|
130
149
|
constructor(message: string, options?: InvalidSchemaErrorOptions);
|
|
131
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Thrown when a value cannot be converted to a schema using `valueToSchema()`.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Currently, this includes the presence of an own property `__proto__` or an
|
|
156
|
+
* empty object (because this will match anything; though maybe we should change
|
|
157
|
+
* that).
|
|
158
|
+
* @group Errors
|
|
159
|
+
*/
|
|
160
|
+
export declare class SatisfactionError extends BupkisError {
|
|
161
|
+
readonly code = "ERR_BUPKIS_SATISFACTION";
|
|
162
|
+
name: string;
|
|
163
|
+
constructor(message: string, options?: ErrorOptions);
|
|
164
|
+
}
|
|
132
165
|
/**
|
|
133
166
|
* Thrown when `expect()` is called with something async.
|
|
134
167
|
*
|
|
@@ -150,18 +183,4 @@ export declare class UnknownAssertionError<T extends readonly unknown[]> extends
|
|
|
150
183
|
name: string;
|
|
151
184
|
constructor(message: string, options: UnknownAssertionErrorOptions<T>);
|
|
152
185
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Thrown when a value cannot be converted to a schema using `valueToSchema()`.
|
|
155
|
-
*
|
|
156
|
-
* @remarks
|
|
157
|
-
* Currently, this includes the presence of an own property `__proto__` or an
|
|
158
|
-
* empty object (because this will match anything; though maybe we should change
|
|
159
|
-
* that).
|
|
160
|
-
* @group Errors
|
|
161
|
-
*/
|
|
162
|
-
export declare class ValueToSchemaError extends BupkisError {
|
|
163
|
-
readonly code = "ERR_BUPKIS_SATISFACTION";
|
|
164
|
-
name: string;
|
|
165
|
-
constructor(message: string, options?: ErrorOptions);
|
|
166
|
-
}
|
|
167
186
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/esm/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAEL,YAAY,EAGb,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAEL,YAAY,EAGb,MAAM,eAAe,CAAC;AAKvB;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,CACzC,IAAI,CACF,WAAW,CAAC,qBAAqB,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,EAChE,UAAU,CACX,CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,mCAAoC,SAAQ,YAAY;IACvE;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AACD;;;;GAIG;AACH,MAAM,WAAW,2BAA4B,SAAQ,YAAY;IAC/D;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAA0B,SAAQ,YAAY;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,4BAA4B,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,CACxE,SAAQ,YAAY;IACpB;;;OAGG;IACH,IAAI,EAAE,CAAC,CAAC;CACT;AAED;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;IAM3C,IAAI,SAAoB;gBAErB,OAAO,CAAC,EAAE,qBAAqB;IAI3C;;;;;OAKG;IACH,MAAM,CAAC,gBAAg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uB;gBAExB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;CAGxD;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,WAAW;IACnD,QAAQ,CAAC,IAAI,iCAAiC;IAErC,IAAI,SAA0B;CACxC;AAED;;;;;GAKG;AACH,qBAAa,qBAAqB,CAChC,CAAC,SAAS,SAAS,OAAO,EAAE,CAC5B,SAAQ,WAAW;IACnB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjB,QAAQ,CAAC,IAAI,kCAAkC;IAEtC,IAAI,SAA2B;gBAE5B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,4BAA4B,CAAC,CAAC,CAAC;CAKtE"}
|
package/dist/esm/error.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { AssertionError as NodeAssertionError } from 'node:assert';
|
|
9
9
|
import { kBupkisAssertionError, kBupkisError, kBupkisFailAssertionError, kBupkisNegatedAssertionError, } from './constant.js';
|
|
10
10
|
import { isA } from './guards.js';
|
|
11
|
+
const { hasOwn } = Object;
|
|
11
12
|
/**
|
|
12
13
|
* _BUPKIS_' s custom `AssertionError` class, which is just a thin wrapper
|
|
13
14
|
* around Node.js' {@link NodeAssertionError AssertionError}.
|
|
@@ -21,6 +22,9 @@ export class AssertionError extends NodeAssertionError {
|
|
|
21
22
|
*/
|
|
22
23
|
[kBupkisAssertionError] = true;
|
|
23
24
|
name = 'AssertionError';
|
|
25
|
+
constructor(options) {
|
|
26
|
+
super(options);
|
|
27
|
+
}
|
|
24
28
|
/**
|
|
25
29
|
* Type guard for an instance of this error.
|
|
26
30
|
*
|
|
@@ -28,8 +32,16 @@ export class AssertionError extends NodeAssertionError {
|
|
|
28
32
|
* @returns `true` if `value` is an instance of `AssertionError`
|
|
29
33
|
*/
|
|
30
34
|
static isAssertionError(value) {
|
|
31
|
-
return (isA(value, NodeAssertionError) &&
|
|
32
|
-
|
|
35
|
+
return (isA(value, NodeAssertionError) && hasOwn(value, kBupkisAssertionError));
|
|
36
|
+
}
|
|
37
|
+
toJSON() {
|
|
38
|
+
return {
|
|
39
|
+
actual: this.actual,
|
|
40
|
+
expected: this.expected,
|
|
41
|
+
message: this.message,
|
|
42
|
+
name: this.name,
|
|
43
|
+
stack: this.stack,
|
|
44
|
+
};
|
|
33
45
|
}
|
|
34
46
|
}
|
|
35
47
|
/**
|
|
@@ -44,7 +56,7 @@ export class BupkisError extends Error {
|
|
|
44
56
|
[kBupkisError] = true;
|
|
45
57
|
name = 'BupkisError';
|
|
46
58
|
static isBupkisError(err) {
|
|
47
|
-
return isA(err, Error) &&
|
|
59
|
+
return isA(err, Error) && hasOwn(err, kBupkisError);
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
62
|
/**
|
|
@@ -62,6 +74,9 @@ export class AssertionImplementationError extends BupkisError {
|
|
|
62
74
|
super(message, rest);
|
|
63
75
|
this.result = result;
|
|
64
76
|
}
|
|
77
|
+
static isAssertionImplementationError(err) {
|
|
78
|
+
return isA(err, AssertionImplementationError);
|
|
79
|
+
}
|
|
65
80
|
}
|
|
66
81
|
/**
|
|
67
82
|
* Variant of an {@link AssertionError} that is thrown when
|
|
@@ -76,8 +91,7 @@ export class FailAssertionError extends AssertionError {
|
|
|
76
91
|
[kBupkisFailAssertionError] = true;
|
|
77
92
|
name = 'FailAssertionError';
|
|
78
93
|
static isFailAssertionError(err) {
|
|
79
|
-
return (isA(err, FailAssertionError) &&
|
|
80
|
-
Object.hasOwn(err, kBupkisFailAssertionError));
|
|
94
|
+
return (isA(err, FailAssertionError) && hasOwn(err, kBupkisFailAssertionError));
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
97
|
/**
|
|
@@ -99,13 +113,14 @@ export class InvalidMetadataError extends BupkisError {
|
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
115
|
/**
|
|
102
|
-
* Thrown from certain assertions when
|
|
116
|
+
* Thrown from certain assertions when a parameter cannot be used as an "object
|
|
117
|
+
* schema"
|
|
103
118
|
*
|
|
104
119
|
* @group Errors
|
|
105
120
|
*/
|
|
106
|
-
export class
|
|
107
|
-
code = '
|
|
108
|
-
name = '
|
|
121
|
+
export class InvalidObjectSchemaError extends BupkisError {
|
|
122
|
+
code = 'ERR_BUPKIS_INVALID_OBJECT_SCHEMA';
|
|
123
|
+
name = 'InvalidObjectSchemaError';
|
|
109
124
|
schema;
|
|
110
125
|
constructor(message, options = {}) {
|
|
111
126
|
const { schema, ...rest } = options;
|
|
@@ -123,8 +138,23 @@ export class NegatedAssertionError extends AssertionError {
|
|
|
123
138
|
[kBupkisNegatedAssertionError] = true;
|
|
124
139
|
name = 'NegatedAssertionError';
|
|
125
140
|
static isNegatedAssertionError(err) {
|
|
126
|
-
return (isA(err, AssertionError) &&
|
|
127
|
-
|
|
141
|
+
return (isA(err, AssertionError) && hasOwn(err, kBupkisNegatedAssertionError));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Thrown when a value cannot be converted to a schema using `valueToSchema()`.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* Currently, this includes the presence of an own property `__proto__` or an
|
|
149
|
+
* empty object (because this will match anything; though maybe we should change
|
|
150
|
+
* that).
|
|
151
|
+
* @group Errors
|
|
152
|
+
*/
|
|
153
|
+
export class SatisfactionError extends BupkisError {
|
|
154
|
+
code = 'ERR_BUPKIS_SATISFACTION';
|
|
155
|
+
name = 'SatisfactionError';
|
|
156
|
+
constructor(message, options = {}) {
|
|
157
|
+
super(message, options);
|
|
128
158
|
}
|
|
129
159
|
}
|
|
130
160
|
/**
|
|
@@ -152,20 +182,4 @@ export class UnknownAssertionError extends BupkisError {
|
|
|
152
182
|
this.args = args;
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Thrown when a value cannot be converted to a schema using `valueToSchema()`.
|
|
157
|
-
*
|
|
158
|
-
* @remarks
|
|
159
|
-
* Currently, this includes the presence of an own property `__proto__` or an
|
|
160
|
-
* empty object (because this will match anything; though maybe we should change
|
|
161
|
-
* that).
|
|
162
|
-
* @group Errors
|
|
163
|
-
*/
|
|
164
|
-
export class ValueToSchemaError extends BupkisError {
|
|
165
|
-
code = 'ERR_BUPKIS_SATISFACTION';
|
|
166
|
-
name = 'SatisfactionError';
|
|
167
|
-
constructor(message, options = {}) {
|
|
168
|
-
super(message, options);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
185
|
//# sourceMappingURL=error.js.map
|
package/dist/esm/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;AAkE1B;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,kBAAkB;IACpD;;OAEG;IACH,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC;IAEtB,IAAI,GAAG,gBAAgB,CAAC;IAEjC,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,gB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,iBAAkB,SAAQ,WAAW;IACvC,IAAI,GAAG,yBAAyB,CAAC;IAEjC,IAAI,GAAG,mBAAmB,CAAC;IAEpC,YAAY,OAAe,EAAE,UAAwB,EAAE;QACrD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,WAAW;IAC1C,IAAI,GAAG,6BAA6B,CAAC;IAErC,IAAI,GAAG,sBAAsB,CAAC;CACxC;AAED;;;;;GAKG;AACH,MAAM,OAAO,qBAEX,SAAQ,WAAW;IACV,IAAI,CAAI;IAER,IAAI,GAAG,8BAA8B,CAAC;IAEtC,IAAI,GAAG,uBAAuB,CAAC;IAExC,YAAY,OAAe,EAAE,OAAwC;QACnE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;QAClC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/esm/expect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EASvB,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EASvB,MAAM,gCAAgC,CAAC;AAUxC,OAAO,EACL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAKpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH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