bupkis 0.7.2 → 0.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/CHANGELOG.md +7 -0
- package/dist/commonjs/assertion/assertion.d.ts +0 -13
- 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 +7 -4
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.d.ts +2 -0
- package/dist/commonjs/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/assertion-util.js +13 -2
- package/dist/commonjs/assertion/impl/assertion-util.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-basic.js +2 -3
- 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.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +4 -2
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +2 -10
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/assertion/slotify.d.ts +1 -0
- package/dist/commonjs/assertion/slotify.d.ts.map +1 -1
- package/dist/commonjs/assertion/slotify.js +1 -0
- package/dist/commonjs/assertion/slotify.js.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +1 -5
- 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 +17 -0
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +17 -7
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +13 -0
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +12 -8
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +24 -14
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -5
- package/dist/commonjs/index.d.ts.map +1 -1
- 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 +17 -10
- package/dist/commonjs/value-to-schema.js.map +1 -1
- package/dist/esm/assertion/assertion.d.ts +0 -13
- 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 +7 -4
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.d.ts +2 -0
- package/dist/esm/assertion/impl/assertion-util.d.ts.map +1 -1
- package/dist/esm/assertion/impl/assertion-util.js +13 -2
- package/dist/esm/assertion/impl/assertion-util.js.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-basic.js +2 -3
- 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.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +4 -2
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +2 -10
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/assertion/slotify.d.ts +1 -0
- package/dist/esm/assertion/slotify.d.ts.map +1 -1
- package/dist/esm/assertion/slotify.js +1 -0
- package/dist/esm/assertion/slotify.js.map +1 -1
- package/dist/esm/bootstrap.d.ts +1 -5
- 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 +17 -0
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +17 -7
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +13 -0
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +12 -8
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +23 -12
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +1 -5
- package/dist/esm/index.d.ts.map +1 -1
- 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 +17 -10
- package/dist/esm/value-to-schema.js.map +1 -1
- package/package.json +22 -6
- package/src/assertion/assertion.ts +47 -28
- package/src/assertion/create.ts +8 -8
- package/src/assertion/impl/assertion-util.ts +27 -16
- package/src/assertion/impl/sync-basic.ts +3 -3
- 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 +5 -2
- package/src/assertion/slotify.ts +1 -0
- package/src/bootstrap.ts +1 -0
- package/src/diff.ts +343 -0
- package/src/error.ts +35 -7
- package/src/expect.ts +13 -0
- package/src/guards.ts +27 -15
- package/src/schema.ts +4 -2
- package/src/use.ts +21 -7
- package/src/util.ts +15 -12
- package/src/value-to-schema.ts +18 -10
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Diff utilities for generating rich assertion failure output.
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities for extracting meaningful actual/expected
|
|
6
|
+
* values from Zod validation errors and generating high-quality diff output
|
|
7
|
+
* using `jest-diff` for assertion failures.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
* @see {@link https://npm.im/jest-diff | jest-diff}
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.shouldGenerateDiff = exports.generateDiff = exports.extractDiffValues = void 0;
|
|
14
|
+
const jest_diff_1 = require("jest-diff");
|
|
15
|
+
const { isArray } = Array;
|
|
16
|
+
const { max } = Math;
|
|
17
|
+
const { stringify } = JSON;
|
|
18
|
+
const { entries } = Object;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts actual and expected values from a `ZodError` for meaningful diffs.
|
|
21
|
+
*
|
|
22
|
+
* @function
|
|
23
|
+
* @param zodError The `ZodError` to extract values from
|
|
24
|
+
* @param subject The original subject that failed validation
|
|
25
|
+
* @returns Object with actual and expected values for diff
|
|
26
|
+
*/
|
|
27
|
+
const extractDiffValues = (zodError, subject) => {
|
|
28
|
+
try {
|
|
29
|
+
// Start with the original subject as the actual value
|
|
30
|
+
const actual = subject;
|
|
31
|
+
// Create a copy to modify as the expected value
|
|
32
|
+
let expected = subject != null ? deepClone(subject) : subject;
|
|
33
|
+
// Process each issue to build the expected value
|
|
34
|
+
for (const issue of zodError.issues) {
|
|
35
|
+
try {
|
|
36
|
+
// Filter path to only string/number keys (symbols are rare in practice)
|
|
37
|
+
const filteredPath = issue.path.filter((key) => typeof key === 'string' || typeof key === 'number');
|
|
38
|
+
switch (issue.code) {
|
|
39
|
+
case 'invalid_type': {
|
|
40
|
+
const correctedValue = createCorrectValueForType(issue.expected, getValueAtPath(actual, filteredPath));
|
|
41
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case 'invalid_value': {
|
|
45
|
+
// For literal/enum errors, use the first valid value
|
|
46
|
+
const correctedValue = issue.values && issue.values.length > 0
|
|
47
|
+
? issue.values[0]
|
|
48
|
+
: '<valid value>';
|
|
49
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'too_big': {
|
|
53
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
54
|
+
let correctedValue;
|
|
55
|
+
if (issue.origin === 'string' && typeof actualValue === 'string') {
|
|
56
|
+
correctedValue = actualValue.slice(0, Number(issue.maximum));
|
|
57
|
+
}
|
|
58
|
+
else if (issue.origin === 'array' && isArray(actualValue)) {
|
|
59
|
+
correctedValue = actualValue.slice(0, Number(issue.maximum));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
correctedValue = issue.maximum;
|
|
63
|
+
}
|
|
64
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'too_small': {
|
|
68
|
+
const actualValue = getValueAtPath(actual, filteredPath);
|
|
69
|
+
let correctedValue;
|
|
70
|
+
if (issue.origin === 'string' && typeof actualValue === 'string') {
|
|
71
|
+
const needed = Number(issue.minimum) - actualValue.length;
|
|
72
|
+
correctedValue = actualValue + 'x'.repeat(max(0, needed));
|
|
73
|
+
}
|
|
74
|
+
else if (issue.origin === 'array' && isArray(actualValue)) {
|
|
75
|
+
const needed = Number(issue.minimum) - actualValue.length;
|
|
76
|
+
correctedValue = actualValue.concat(new Array(max(0, needed)).fill(null));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
correctedValue = issue.minimum;
|
|
80
|
+
}
|
|
81
|
+
expected = setValueAtPath(expected, filteredPath, correctedValue);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'unrecognized_keys': {
|
|
85
|
+
// Remove unrecognized keys from expected
|
|
86
|
+
if (filteredPath.length === 0 &&
|
|
87
|
+
typeof expected === 'object' &&
|
|
88
|
+
expected !== null) {
|
|
89
|
+
const expectedCopy = {
|
|
90
|
+
...expected,
|
|
91
|
+
};
|
|
92
|
+
for (const key of issue.keys) {
|
|
93
|
+
delete expectedCopy[key];
|
|
94
|
+
}
|
|
95
|
+
expected = expectedCopy;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
default: {
|
|
100
|
+
// For other error types, just mark that something should be different
|
|
101
|
+
// but don't try to guess what the correct value should be
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// If we can't process an individual issue, continue with others
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { actual, expected };
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// If anything goes wrong, return undefined to fall back to pretty error
|
|
115
|
+
return { actual: undefined, expected: undefined };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.extractDiffValues = extractDiffValues;
|
|
119
|
+
/**
|
|
120
|
+
* Generates a rich diff string using jest-diff for assertion failures.
|
|
121
|
+
*
|
|
122
|
+
* @function
|
|
123
|
+
* @param expected The expected value
|
|
124
|
+
* @param actual The actual value
|
|
125
|
+
* @param options Configuration options for diff generation
|
|
126
|
+
* @returns A formatted diff string, or null if values are identical
|
|
127
|
+
*/
|
|
128
|
+
const generateDiff = (expected, actual, options = {}) => {
|
|
129
|
+
if (!(0, exports.shouldGenerateDiff)(actual, expected)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return (0, jest_diff_1.diff)(expected, actual, {
|
|
133
|
+
aAnnotation: 'expected',
|
|
134
|
+
bAnnotation: 'actual',
|
|
135
|
+
expand: false,
|
|
136
|
+
includeChangeCounts: true,
|
|
137
|
+
...options,
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
exports.generateDiff = generateDiff;
|
|
141
|
+
/**
|
|
142
|
+
* Checks if two values should generate a meaningful diff.
|
|
143
|
+
*
|
|
144
|
+
* @function
|
|
145
|
+
* @param actual The actual value
|
|
146
|
+
* @param expected The expected value
|
|
147
|
+
* @returns True if a diff should be generated, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
const shouldGenerateDiff = (actual, expected) => actual !== undefined && expected !== undefined && actual !== expected;
|
|
150
|
+
exports.shouldGenerateDiff = shouldGenerateDiff;
|
|
151
|
+
/**
|
|
152
|
+
* Creates a corrected value for a given type
|
|
153
|
+
*
|
|
154
|
+
* @function
|
|
155
|
+
*/
|
|
156
|
+
const createCorrectValueForType = (expectedType, actualValue) => {
|
|
157
|
+
switch (expectedType) {
|
|
158
|
+
case 'array':
|
|
159
|
+
return isArray(actualValue) ? actualValue : [];
|
|
160
|
+
case 'boolean':
|
|
161
|
+
return typeof actualValue === 'boolean'
|
|
162
|
+
? actualValue
|
|
163
|
+
: Boolean(actualValue);
|
|
164
|
+
case 'null':
|
|
165
|
+
return null;
|
|
166
|
+
case 'number':
|
|
167
|
+
return typeof actualValue === 'number'
|
|
168
|
+
? actualValue
|
|
169
|
+
: Number(actualValue) || 0;
|
|
170
|
+
case 'object':
|
|
171
|
+
return typeof actualValue === 'object' && actualValue !== null
|
|
172
|
+
? actualValue
|
|
173
|
+
: {};
|
|
174
|
+
case 'string':
|
|
175
|
+
if (typeof actualValue === 'string') {
|
|
176
|
+
return actualValue;
|
|
177
|
+
}
|
|
178
|
+
if (actualValue == null) {
|
|
179
|
+
return '';
|
|
180
|
+
}
|
|
181
|
+
if (typeof actualValue === 'object') {
|
|
182
|
+
return stringify(actualValue);
|
|
183
|
+
}
|
|
184
|
+
// For primitive types (number, boolean, etc.) - we know it's not an object here
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
186
|
+
return `${actualValue}`;
|
|
187
|
+
case 'undefined':
|
|
188
|
+
return undefined;
|
|
189
|
+
default:
|
|
190
|
+
return `<${expectedType}>`;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* Custom deep clone implementation for values that structuredClone can't
|
|
195
|
+
* handle. Used as fallback when structuredClone fails.
|
|
196
|
+
*
|
|
197
|
+
* @function
|
|
198
|
+
*/
|
|
199
|
+
const customDeepClone = (value) => {
|
|
200
|
+
if (value === null || typeof value !== 'object') {
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
if (isArray(value)) {
|
|
204
|
+
return value.map(customDeepClone);
|
|
205
|
+
}
|
|
206
|
+
// For objects, create a new object and copy properties
|
|
207
|
+
const cloned = {};
|
|
208
|
+
for (const [key, val] of entries(value)) {
|
|
209
|
+
cloned[key] = customDeepClone(val);
|
|
210
|
+
}
|
|
211
|
+
return cloned;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Deep clone a value to avoid mutating the original. Uses the native
|
|
215
|
+
* structuredClone API which handles more types and circular references better
|
|
216
|
+
* than a custom implementation. Falls back to custom implementation for values
|
|
217
|
+
* containing functions.
|
|
218
|
+
*
|
|
219
|
+
* @function
|
|
220
|
+
*/
|
|
221
|
+
const deepClone = (value) => {
|
|
222
|
+
try {
|
|
223
|
+
return structuredClone(value);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
// Handle DataCloneError for values that can't be cloned (functions, symbols, etc.)
|
|
227
|
+
if (error instanceof Error && error.name === 'DataCloneError') {
|
|
228
|
+
return customDeepClone(value);
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Gets a value at a specific path in an object
|
|
235
|
+
*
|
|
236
|
+
* @function
|
|
237
|
+
*/
|
|
238
|
+
const getValueAtPath = (obj, path) => {
|
|
239
|
+
if (path.length === 0) {
|
|
240
|
+
return obj;
|
|
241
|
+
}
|
|
242
|
+
let current = obj;
|
|
243
|
+
for (const key of path) {
|
|
244
|
+
if (current == null) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
current = current[key];
|
|
248
|
+
}
|
|
249
|
+
return current;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Returns a new object with the value at the specified path set to the given
|
|
253
|
+
* value.
|
|
254
|
+
*
|
|
255
|
+
* @function
|
|
256
|
+
*/
|
|
257
|
+
const setValueAtPath = (obj, path, value) => {
|
|
258
|
+
if (path.length === 0) {
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
if (obj == null) {
|
|
262
|
+
// Need to create the structure
|
|
263
|
+
obj = typeof path[0] === 'number' ? [] : {};
|
|
264
|
+
}
|
|
265
|
+
const result = isArray(obj)
|
|
266
|
+
? [...obj]
|
|
267
|
+
: { ...obj };
|
|
268
|
+
const [head, ...tail] = path;
|
|
269
|
+
if (head !== undefined) {
|
|
270
|
+
if (tail.length === 0) {
|
|
271
|
+
result[head] = value;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
result[head] = setValueAtPath(result[head], tail, value);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
};
|
|
279
|
+
//# sourceMappingURL=diff.js.map
|
|
@@ -0,0 +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;AAY3B;;;;;;;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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
|
|
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
|
*
|
|
@@ -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
|
|
@@ -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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IACjD,QAAQ,CAAC,IAAI,6BAA6B;IAEjC,IAAI,SAAuB;gBAExB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;CAGxD"}
|
package/dist/commonjs/error.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.ValueToSchemaError = exports.UnknownAssertionError = exports.UnexpectedA
|
|
|
11
11
|
const node_assert_1 = require("node:assert");
|
|
12
12
|
const constant_js_1 = require("./constant.js");
|
|
13
13
|
const guards_js_1 = require("./guards.js");
|
|
14
|
+
const { hasOwn } = Object;
|
|
14
15
|
/**
|
|
15
16
|
* _BUPKIS_' s custom `AssertionError` class, which is just a thin wrapper
|
|
16
17
|
* around Node.js' {@link NodeAssertionError AssertionError}.
|
|
@@ -24,6 +25,9 @@ class AssertionError extends node_assert_1.AssertionError {
|
|
|
24
25
|
*/
|
|
25
26
|
[constant_js_1.kBupkisAssertionError] = true;
|
|
26
27
|
name = 'AssertionError';
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(options);
|
|
30
|
+
}
|
|
27
31
|
/**
|
|
28
32
|
* Type guard for an instance of this error.
|
|
29
33
|
*
|
|
@@ -31,8 +35,16 @@ class AssertionError extends node_assert_1.AssertionError {
|
|
|
31
35
|
* @returns `true` if `value` is an instance of `AssertionError`
|
|
32
36
|
*/
|
|
33
37
|
static isAssertionError(value) {
|
|
34
|
-
return ((0, guards_js_1.isA)(value, node_assert_1.AssertionError) &&
|
|
35
|
-
|
|
38
|
+
return ((0, guards_js_1.isA)(value, node_assert_1.AssertionError) && hasOwn(value, constant_js_1.kBupkisAssertionError));
|
|
39
|
+
}
|
|
40
|
+
toJSON() {
|
|
41
|
+
return {
|
|
42
|
+
actual: this.actual,
|
|
43
|
+
expected: this.expected,
|
|
44
|
+
message: this.message,
|
|
45
|
+
name: this.name,
|
|
46
|
+
stack: this.stack,
|
|
47
|
+
};
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
exports.AssertionError = AssertionError;
|
|
@@ -48,7 +60,7 @@ class BupkisError extends Error {
|
|
|
48
60
|
[constant_js_1.kBupkisError] = true;
|
|
49
61
|
name = 'BupkisError';
|
|
50
62
|
static isBupkisError(err) {
|
|
51
|
-
return (0, guards_js_1.isA)(err, Error) &&
|
|
63
|
+
return (0, guards_js_1.isA)(err, Error) && hasOwn(err, constant_js_1.kBupkisError);
|
|
52
64
|
}
|
|
53
65
|
}
|
|
54
66
|
exports.BupkisError = BupkisError;
|
|
@@ -82,8 +94,7 @@ class FailAssertionError extends AssertionError {
|
|
|
82
94
|
[constant_js_1.kBupkisFailAssertionError] = true;
|
|
83
95
|
name = 'FailAssertionError';
|
|
84
96
|
static isFailAssertionError(err) {
|
|
85
|
-
return ((0, guards_js_1.isA)(err, FailAssertionError) &&
|
|
86
|
-
Object.hasOwn(err, constant_js_1.kBupkisFailAssertionError));
|
|
97
|
+
return ((0, guards_js_1.isA)(err, FailAssertionError) && hasOwn(err, constant_js_1.kBupkisFailAssertionError));
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
exports.FailAssertionError = FailAssertionError;
|
|
@@ -132,8 +143,7 @@ class NegatedAssertionError extends AssertionError {
|
|
|
132
143
|
[constant_js_1.kBupkisNegatedAssertionError] = true;
|
|
133
144
|
name = 'NegatedAssertionError';
|
|
134
145
|
static isNegatedAssertionError(err) {
|
|
135
|
-
return ((0, guards_js_1.isA)(err, AssertionError) &&
|
|
136
|
-
Object.hasOwn(err, constant_js_1.kBupkisNegatedAssertionError));
|
|
146
|
+
return ((0, guards_js_1.isA)(err, AssertionError) && hasOwn(err, constant_js_1.kBupkisNegatedAssertionError));
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
exports.NegatedAssertionError = NegatedAssertionError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAmE;AAEnE,+CAKuB;AACvB,2CAAkC;
|
|
1
|
+
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AAC,SAAS,kBAAkB,EACpE,UAAU,EAAE,CAAC,GACZ,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAuH1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,SAAS,iBAAiB,EACpC,YAAY,SAAS,MAAM,CAAC,iBAAiB,CAAC,EAE9C,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY,GACnB,cAAc,CAAC,UAAU,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,SAAS,iBAAiB,EAC3E,UAAU,EAAE,UAAU,GACrB,cAAc,CAAC,UAAU,CAAC,CAAC;AA4T9B;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,EAC5B,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9E;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,iBAAiB,EAC3B,CAAC,SAAS,kBAAkB,EAC5B,cAAc,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
package/dist/commonjs/expect.js
CHANGED
|
@@ -77,6 +77,9 @@ const debug = (0, debug_1.default)('bupkis:expect');
|
|
|
77
77
|
*/
|
|
78
78
|
function createExpectAsyncFunction(assertions, expect) {
|
|
79
79
|
debug('ℹ Creating expectAsync function with %d new assertions and %d existing assertions (%d total)', assertions.length, expect?.assertions.length ?? 0, assertions.length + (expect?.assertions.length ?? 0));
|
|
80
|
+
/**
|
|
81
|
+
* @function
|
|
82
|
+
*/
|
|
80
83
|
const expectAsyncFunction = async (...args) => {
|
|
81
84
|
await Promise.resolve();
|
|
82
85
|
const [isNegated, processedArgs] = maybeProcessNegation(args);
|
|
@@ -156,6 +159,9 @@ function createExpectAsyncFunction(assertions, expect) {
|
|
|
156
159
|
*/
|
|
157
160
|
function createExpectSyncFunction(assertions, expect) {
|
|
158
161
|
debug('ℹ Creating expect function with %d new assertions and %d existing assertions (%d total)', assertions.length, expect?.assertions.length ?? 0, assertions.length + (expect?.assertions.length ?? 0));
|
|
162
|
+
/**
|
|
163
|
+
* @function
|
|
164
|
+
*/
|
|
159
165
|
const expectFunction = (...args) => {
|
|
160
166
|
const [isNegated, processedArgs] = maybeProcessNegation(args);
|
|
161
167
|
const candidates = [];
|
|
@@ -185,6 +191,7 @@ function createExpectSyncFunction(assertions, expect) {
|
|
|
185
191
|
* @privateRemarks
|
|
186
192
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
187
193
|
* probably shouldn't.
|
|
194
|
+
* @function
|
|
188
195
|
* @param assertion - The assertion to execute
|
|
189
196
|
* @param parsedValues - Parsed values for the assertion
|
|
190
197
|
* @param args - Original arguments passed to expect
|
|
@@ -233,6 +240,7 @@ const execute = (assertion, parsedValues, args, stackStartFn, isNegated, parseRe
|
|
|
233
240
|
* @privateRemarks
|
|
234
241
|
* This is here because `Assertion` doesn't know anything about negation and
|
|
235
242
|
* probably shouldn't.
|
|
243
|
+
* @function
|
|
236
244
|
* @param assertion - The assertion to execute
|
|
237
245
|
* @param parsedValues - Parsed values for the assertion
|
|
238
246
|
* @param args - Original arguments passed to expectAsync
|
|
@@ -271,6 +279,7 @@ const executeAsync = async (assertion, parsedValues, args, stackStartFn, isNegat
|
|
|
271
279
|
* requested along with arguments stripped of the leading negation (to enable
|
|
272
280
|
* assertion matching).
|
|
273
281
|
*
|
|
282
|
+
* @function
|
|
274
283
|
* @internal
|
|
275
284
|
*/
|
|
276
285
|
const maybeProcessNegation = (args) => {
|
|
@@ -289,6 +298,7 @@ const maybeProcessNegation = (args) => {
|
|
|
289
298
|
* Throws an error indicating that no valid assertion could be found for the
|
|
290
299
|
* provided arguments.
|
|
291
300
|
*
|
|
301
|
+
* @function
|
|
292
302
|
* @param args The arguments that were passed to the expect function
|
|
293
303
|
* @internal
|
|
294
304
|
*/
|
|
@@ -301,6 +311,7 @@ const throwInvalidParametersError = (args) => {
|
|
|
301
311
|
* Detects if an assertion phrase starts with "not " and returns the cleaned
|
|
302
312
|
* phrase.
|
|
303
313
|
*
|
|
314
|
+
* @function
|
|
304
315
|
* @param phrase - The assertion phrase to check
|
|
305
316
|
* @returns Object with `isNegated` flag and `cleanedPhrase`
|
|
306
317
|
*/
|
|
@@ -318,6 +329,8 @@ const detectNegation = (phrase) => {
|
|
|
318
329
|
};
|
|
319
330
|
/**
|
|
320
331
|
* {@inheritdoc FailFn}
|
|
332
|
+
*
|
|
333
|
+
* @function
|
|
321
334
|
*/
|
|
322
335
|
const fail = (reason) => {
|
|
323
336
|
throw new error_js_1.FailAssertionError({ message: reason });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;AA6KA,
|
|
1
|
+
{"version":3,"file":"expect.js","sourceRoot":"","sources":["../../src/expect.ts"],"names":[],"mappings":";;;;;AA6KA,8DAqDC;AAgID,4DAoDC;AAmOD,4CAmBC;AA5oBD,kDAAgC;AAChC,+BAA+B;AAgB/B,qDAA8E;AAC9E,yCAKoB;AACpB,2CAA2D;AAY3D,qCAAqC;AAErC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,eAAe,CAAC,CAAC;AAyE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,SAAgB,yBAAyB,CAGvC,UAAa,EAAE,MAAU;IACzB,KAAK,CACH,8FAA8F,EAC9F,UAAU,CAAC,MAAM,EACjB,MAAM,EAAE,UAAU,CAAC,MAAM,IAA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E,MAAM,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC;AAgBF;;;GAGG;AACH,SAAgB,gBAAgB,CAG9B,cAAiB,EAAE,eAAkB,EAAE,IAAsB;IAC7D,OAAO,IAAI,KAAK,MAAM;QACpB,CAAC,CAAC;YACE,UAAU,EAAE,cAAc;YAC1B,eAAe,EAAf,2BAAe;YACf,oBAAoB,EAApB,gCAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD;QACH,CAAC,CAAC;YACE,UAAU,EAAE,eAAe;YAC3B,eAAe,EAAf,2BAAe;YACf,oBAAoB,EAApB,gCAAoB;YACpB,IAAI;YACJ,GAAG,EAAE,IAAA,kBAAS,EAAC,cAAc,EAAE,eAAe,CAAC;SAChD,CAAC;AACR,CAAC"}
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @packageDocumentation
|
|
17
17
|
*/
|
|
18
|
-
import { type Primitive } from 'type-fest';
|
|
19
18
|
import { z } from 'zod/v4';
|
|
20
19
|
import type { Constructor, ExpectItExecutor, ZodTypeMap } from './types.js';
|
|
21
20
|
/**
|
|
@@ -44,6 +43,7 @@ export declare function isZodType(value: unknown): value is z.ZodType;
|
|
|
44
43
|
/**
|
|
45
44
|
* Type guard for a plain object.
|
|
46
45
|
*
|
|
46
|
+
* @function
|
|
47
47
|
* @param value Value to test
|
|
48
48
|
* @returns `true` if the value is a plain object, `false` otherwise
|
|
49
49
|
*/
|
|
@@ -51,6 +51,7 @@ export declare const isObject: (value: unknown) => value is NonNullable<object>;
|
|
|
51
51
|
/**
|
|
52
52
|
* Returns `true` if the given value is a {@link z.ZodPromise} schema.
|
|
53
53
|
*
|
|
54
|
+
* @function
|
|
54
55
|
* @param value - Value to test
|
|
55
56
|
* @returns `true` if the value is a `ZodPromise` schema; `false` otherwise
|
|
56
57
|
*/
|
|
@@ -58,6 +59,7 @@ export declare const isZodPromise: (value: unknown) => value is z.ZodPromise;
|
|
|
58
59
|
/**
|
|
59
60
|
* Checks if a value is "promise-like", meaning it is a "thenable" object.
|
|
60
61
|
*
|
|
62
|
+
* @function
|
|
61
63
|
* @param value - Value to test
|
|
62
64
|
* @returns `true` if the value is promise-like, `false` otherwise
|
|
63
65
|
*/
|
|
@@ -74,6 +76,7 @@ export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unk
|
|
|
74
76
|
* This may be the only way we can determine, at runtime, if a function is a
|
|
75
77
|
* constructor without actually calling it. I am unsure if this only works for
|
|
76
78
|
* classes.
|
|
79
|
+
* @function
|
|
77
80
|
* @param fn - Function to test
|
|
78
81
|
* @returns Whether the function is constructable
|
|
79
82
|
*/
|
|
@@ -81,6 +84,7 @@ export declare const isConstructible: (fn: unknown) => fn is Constructor;
|
|
|
81
84
|
/**
|
|
82
85
|
* Type guard for a boolean value
|
|
83
86
|
*
|
|
87
|
+
* @function
|
|
84
88
|
* @param value Value to check
|
|
85
89
|
* @returns `true` if the value is a boolean, `false` otherwise
|
|
86
90
|
*/
|
|
@@ -88,6 +92,7 @@ export declare const isBoolean: (value: unknown) => value is boolean;
|
|
|
88
92
|
/**
|
|
89
93
|
* Type guard for a function value
|
|
90
94
|
*
|
|
95
|
+
* @function
|
|
91
96
|
* @param value Value to check
|
|
92
97
|
* @returns `true` if the value is a function, `false` otherwise
|
|
93
98
|
*/
|
|
@@ -95,6 +100,7 @@ export declare const isFunction: (value: unknown) => value is (...args: any[]) =
|
|
|
95
100
|
/**
|
|
96
101
|
* Type guard for a string value
|
|
97
102
|
*
|
|
103
|
+
* @function
|
|
98
104
|
* @param value Value to check
|
|
99
105
|
* @returns `true` if the value is a string, `false` otherwise
|
|
100
106
|
*/
|
|
@@ -102,23 +108,18 @@ export declare const isString: (value: unknown) => value is string;
|
|
|
102
108
|
/**
|
|
103
109
|
* Type guard for a non-null object value
|
|
104
110
|
*
|
|
111
|
+
* @function
|
|
105
112
|
* @param value Value to check
|
|
106
113
|
* @returns `true` if the value is an object and not null, `false` otherwise
|
|
107
114
|
*/
|
|
108
115
|
export declare const isNonNullObject: (value: unknown) => value is object;
|
|
109
|
-
/**
|
|
110
|
-
* Type guard for a null or non-object value
|
|
111
|
-
*
|
|
112
|
-
* @param value Value to check
|
|
113
|
-
* @returns `true` if the value is null or not an object, `false` otherwise
|
|
114
|
-
*/
|
|
115
|
-
export declare const isNullOrNonObject: (value: unknown) => value is null | Primitive;
|
|
116
116
|
/**
|
|
117
117
|
* Type guard for a valid WeakKey (object, function, or symbol).
|
|
118
118
|
*
|
|
119
119
|
* WeakMaps and WeakSets can only use objects (including functions) or symbols
|
|
120
120
|
* as keys, not primitives like strings, numbers, booleans, null, or undefined.
|
|
121
121
|
*
|
|
122
|
+
* @function
|
|
122
123
|
* @param value Value to check
|
|
123
124
|
* @returns `true` if the value is a valid WeakKey (object, function, or
|
|
124
125
|
* symbol), `false` otherwise
|
|
@@ -143,6 +144,7 @@ export declare const isWeakKey: (value: unknown) => value is WeakKey;
|
|
|
143
144
|
* ```
|
|
144
145
|
*
|
|
145
146
|
* @template T - The constructor type to check against
|
|
147
|
+
* @function
|
|
146
148
|
* @param value - Value to test
|
|
147
149
|
* @param ctor - Constructor function to check instanceof
|
|
148
150
|
* @returns `true` if the value is an instance of the constructor, `false`
|
|
@@ -169,6 +171,7 @@ export declare const isA: <T extends Constructor>(value: unknown, ctor: T) => va
|
|
|
169
171
|
* }
|
|
170
172
|
* ```
|
|
171
173
|
*
|
|
174
|
+
* @function
|
|
172
175
|
* @param value - Value to test
|
|
173
176
|
* @returns `true` if the value is an Error instance, `false` otherwise
|
|
174
177
|
*/
|
|
@@ -194,6 +197,7 @@ export declare const isError: (value: unknown) => value is Error;
|
|
|
194
197
|
* ```
|
|
195
198
|
*
|
|
196
199
|
* @template Subject - The subject type that the executor function operates on
|
|
200
|
+
* @function
|
|
197
201
|
* @param value - Value to test
|
|
198
202
|
* @returns `true` if the value is an ExpectItExecutor function, `false`
|
|
199
203
|
* otherwise
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAO3B,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM5E;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,UAAU,EAClD,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,CAAC,GACN,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAE1B;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC;AAsB9D;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAAW,CAAC,MAAM,CAEpE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,CAAC,CAAC,UAC5B,CAAC;AAE9B;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CAIpD,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAAI,IAAI,OAAO,KAAG,EAAE,IAAI,WAYnD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OACxB,CAAC;AAE7B;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,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