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
package/src/use.ts
CHANGED
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
type UseFn,
|
|
28
28
|
} from './types.js';
|
|
29
29
|
|
|
30
|
+
const { assign } = Object;
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* Creates an `expect.it()` factory function for generating embeddable assertion
|
|
32
34
|
* executors.
|
|
@@ -60,6 +62,7 @@ import {
|
|
|
60
62
|
*
|
|
61
63
|
* @template SyncAssertions - Array of synchronous assertion objects that define
|
|
62
64
|
* the available assertion logic for the embeddable functions
|
|
65
|
+
* @function
|
|
63
66
|
* @param expect - The underlying expect function that will execute the
|
|
64
67
|
* assertions when the returned executors are called
|
|
65
68
|
* @returns A factory function that creates {@link ExpectItExecutor} instances
|
|
@@ -72,8 +75,11 @@ import {
|
|
|
72
75
|
const createExpectIt = <SyncAssertions extends AnySyncAssertions>(
|
|
73
76
|
expect: any,
|
|
74
77
|
): ExpectIt<SyncAssertions> => {
|
|
78
|
+
/**
|
|
79
|
+
* @function
|
|
80
|
+
*/
|
|
75
81
|
const expectIt = (...args: readonly unknown[]) => {
|
|
76
|
-
const func =
|
|
82
|
+
const func = assign(
|
|
77
83
|
(subject: unknown) => {
|
|
78
84
|
const allArgs = [subject, ...args];
|
|
79
85
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
@@ -121,6 +127,7 @@ const createExpectIt = <SyncAssertions extends AnySyncAssertions>(
|
|
|
121
127
|
*
|
|
122
128
|
* @template AsyncAssertions - Array of asynchronous assertion objects that
|
|
123
129
|
* define the available assertion logic for the embeddable async functions
|
|
130
|
+
* @function
|
|
124
131
|
* @param expectAsync - The underlying expectAsync function that will execute
|
|
125
132
|
* the assertions when the returned executors are called
|
|
126
133
|
* @returns A factory function that creates {@link ExpectItExecutorAsync}
|
|
@@ -134,8 +141,11 @@ const createExpectIt = <SyncAssertions extends AnySyncAssertions>(
|
|
|
134
141
|
const createExpectItAsync = <AsyncAssertions extends AnyAsyncAssertions>(
|
|
135
142
|
expectAsync: any,
|
|
136
143
|
): ExpectItAsync<AsyncAssertions> => {
|
|
144
|
+
/**
|
|
145
|
+
* @function
|
|
146
|
+
*/
|
|
137
147
|
const expectItAsync = (...args: readonly unknown[]) => {
|
|
138
|
-
const func =
|
|
148
|
+
const func = assign(
|
|
139
149
|
async (subject: unknown) => {
|
|
140
150
|
const allArgs = [subject, ...args];
|
|
141
151
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
@@ -210,6 +220,7 @@ const createExpectItAsync = <AsyncAssertions extends AnyAsyncAssertions>(
|
|
|
210
220
|
* available in the composed functions
|
|
211
221
|
* @template AsyncAssertions - Array of base asynchronous assertions that will
|
|
212
222
|
* be available in the composed functions
|
|
223
|
+
* @function
|
|
213
224
|
* @param syncAssertions - Base synchronous assertions to include in all
|
|
214
225
|
* composed expect functions
|
|
215
226
|
* @param asyncAssertions - Base asynchronous assertions to include in all
|
|
@@ -223,15 +234,18 @@ const createExpectItAsync = <AsyncAssertions extends AnyAsyncAssertions>(
|
|
|
223
234
|
* @see {@link FilterAsyncAssertions} for how async assertions are extracted
|
|
224
235
|
* @see {@link Concat} for how assertion arrays are combined
|
|
225
236
|
*/
|
|
226
|
-
export
|
|
237
|
+
export const createUse = <
|
|
227
238
|
const SyncAssertions extends AnySyncAssertions,
|
|
228
239
|
const AsyncAssertions extends AnyAsyncAssertions,
|
|
229
240
|
>(
|
|
230
241
|
syncAssertions: SyncAssertions,
|
|
231
242
|
asyncAssertions: AsyncAssertions,
|
|
232
|
-
): UseFn<SyncAssertions, AsyncAssertions> {
|
|
243
|
+
): UseFn<SyncAssertions, AsyncAssertions> => {
|
|
233
244
|
const syncAssertionsIn = syncAssertions ?? [];
|
|
234
245
|
const asyncAssertionsIn = asyncAssertions ?? [];
|
|
246
|
+
/**
|
|
247
|
+
* @function
|
|
248
|
+
*/
|
|
235
249
|
const use: UseFn<SyncAssertions, AsyncAssertions> = <
|
|
236
250
|
AllAssertions extends readonly AnyAssertion[],
|
|
237
251
|
FilteredSyncAssertions extends FilterSyncAssertions<AllAssertions>,
|
|
@@ -256,12 +270,12 @@ export function createUse<
|
|
|
256
270
|
const expectFunction = createExpectSyncFunction(allSyncAssertions);
|
|
257
271
|
const expectAsyncFunction = createExpectAsyncFunction(allAsyncAssertions);
|
|
258
272
|
|
|
259
|
-
const expect =
|
|
273
|
+
const expect = assign(
|
|
260
274
|
expectFunction,
|
|
261
275
|
createBaseExpect(allSyncAssertions, allAsyncAssertions, 'sync'),
|
|
262
276
|
{ it: createExpectIt(expectFunction) },
|
|
263
277
|
);
|
|
264
|
-
const expectAsync =
|
|
278
|
+
const expectAsync = assign(
|
|
265
279
|
expectAsyncFunction,
|
|
266
280
|
createBaseExpect(allSyncAssertions, allAsyncAssertions, 'async'),
|
|
267
281
|
{ it: createExpectItAsync(expectAsyncFunction) },
|
|
@@ -276,4 +290,4 @@ export function createUse<
|
|
|
276
290
|
};
|
|
277
291
|
};
|
|
278
292
|
return use;
|
|
279
|
-
}
|
|
293
|
+
};
|
package/src/util.ts
CHANGED
|
@@ -17,6 +17,10 @@ import { type Keypath } from './types.js';
|
|
|
17
17
|
|
|
18
18
|
export * from './value-to-schema.js';
|
|
19
19
|
|
|
20
|
+
const { hasOwn, keys, values } = Object;
|
|
21
|
+
const { isInteger, isNaN } = Number;
|
|
22
|
+
const { isArray } = Array;
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
25
|
* Retrieves the value at a given keypath from an object using dot or bracket
|
|
22
26
|
* notation.
|
|
@@ -191,18 +195,18 @@ export const hasKeyDeep = (
|
|
|
191
195
|
visited.add(obj);
|
|
192
196
|
|
|
193
197
|
try {
|
|
194
|
-
if (
|
|
198
|
+
if (hasOwn(obj, key)) {
|
|
195
199
|
return true;
|
|
196
200
|
}
|
|
197
201
|
|
|
198
|
-
if (
|
|
202
|
+
if (isArray(obj)) {
|
|
199
203
|
for (const item of obj) {
|
|
200
204
|
if (hasKeyDeep(item, key, visited)) {
|
|
201
205
|
return true;
|
|
202
206
|
}
|
|
203
207
|
}
|
|
204
208
|
} else {
|
|
205
|
-
for (const propValue of
|
|
209
|
+
for (const propValue of values(obj)) {
|
|
206
210
|
if (hasKeyDeep(propValue, key, visited)) {
|
|
207
211
|
return true;
|
|
208
212
|
}
|
|
@@ -255,13 +259,13 @@ export const hasValueDeep = (
|
|
|
255
259
|
if (
|
|
256
260
|
typeof obj === 'object' &&
|
|
257
261
|
obj !== null &&
|
|
258
|
-
!
|
|
262
|
+
!isArray(obj) &&
|
|
259
263
|
typeof value === 'object' &&
|
|
260
264
|
value !== null &&
|
|
261
|
-
!
|
|
265
|
+
!isArray(value)
|
|
262
266
|
) {
|
|
263
|
-
const objKeys =
|
|
264
|
-
const valueKeys =
|
|
267
|
+
const objKeys = keys(obj);
|
|
268
|
+
const valueKeys = keys(value);
|
|
265
269
|
|
|
266
270
|
if (objKeys.length === 0 && valueKeys.length === 0) {
|
|
267
271
|
return true;
|
|
@@ -278,14 +282,14 @@ export const hasValueDeep = (
|
|
|
278
282
|
visited.add(obj);
|
|
279
283
|
|
|
280
284
|
try {
|
|
281
|
-
if (
|
|
285
|
+
if (isArray(obj)) {
|
|
282
286
|
for (const item of obj) {
|
|
283
287
|
if (hasValueDeep(item, value, visited)) {
|
|
284
288
|
return true;
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
291
|
} else {
|
|
288
|
-
for (const propValue of
|
|
292
|
+
for (const propValue of values(obj)) {
|
|
289
293
|
if (hasValueDeep(propValue, value, visited)) {
|
|
290
294
|
return true;
|
|
291
295
|
}
|
|
@@ -364,6 +368,7 @@ export const keyBy = <
|
|
|
364
368
|
* parseKeypath("arr[10]['spam']"); // ['arr', 10, 'spam']
|
|
365
369
|
* ```
|
|
366
370
|
*
|
|
371
|
+
* @function
|
|
367
372
|
* @param keypath The keypath string to parse, using dot and/or bracket
|
|
368
373
|
* notation.
|
|
369
374
|
* @returns An array of keys, where each key is a string or number. Bracketed
|
|
@@ -401,9 +406,7 @@ export const parseKeypath = <S extends string = string>(
|
|
|
401
406
|
i++;
|
|
402
407
|
|
|
403
408
|
const numKey = Number(key);
|
|
404
|
-
keys.push(
|
|
405
|
-
Number.isInteger(numKey) && !Number.isNaN(numKey) ? numKey : key,
|
|
406
|
-
);
|
|
409
|
+
keys.push(isInteger(numKey) && !isNaN(numKey) ? numKey : key);
|
|
407
410
|
} else if (keypath[i] === '.') {
|
|
408
411
|
i++;
|
|
409
412
|
} else {
|
package/src/value-to-schema.ts
CHANGED
|
@@ -11,6 +11,10 @@ import {
|
|
|
11
11
|
} from './guards.js';
|
|
12
12
|
import { RegExpSchema, WrappedPromiseLikeSchema } from './schema.js';
|
|
13
13
|
|
|
14
|
+
const { isNaN } = Number;
|
|
15
|
+
const { entries, freeze, hasOwn, keys } = Object;
|
|
16
|
+
const { isArray } = Array;
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* Recursively converts an arbitrary value to a Zod v4 schema that would
|
|
16
20
|
* validate values with the same structure.
|
|
@@ -41,6 +45,7 @@ import { RegExpSchema, WrappedPromiseLikeSchema } from './schema.js';
|
|
|
41
45
|
* // z.object({ users: z.array(z.object({ name: z.string() })) })
|
|
42
46
|
* ```
|
|
43
47
|
*
|
|
48
|
+
* @function
|
|
44
49
|
* @param value - The value to convert to a schema
|
|
45
50
|
* @param options - Configuration options for schema generation
|
|
46
51
|
* @param visited - Internal WeakSet for circular reference detection
|
|
@@ -82,7 +87,7 @@ export const valueToSchema = (
|
|
|
82
87
|
})
|
|
83
88
|
: z.undefined();
|
|
84
89
|
}
|
|
85
|
-
if (
|
|
90
|
+
if (isNaN(value as number)) {
|
|
86
91
|
return z.nan();
|
|
87
92
|
}
|
|
88
93
|
if (value === Infinity || value === -Infinity) {
|
|
@@ -142,7 +147,7 @@ export const valueToSchema = (
|
|
|
142
147
|
|
|
143
148
|
try {
|
|
144
149
|
// Check for objects with own __proto__ property - these can cause unexpected behavior
|
|
145
|
-
if (
|
|
150
|
+
if (hasOwn(value, '__proto__')) {
|
|
146
151
|
throw new ValueToSchemaError(
|
|
147
152
|
'Objects with an own "__proto__" property are not supported by valueToSchema',
|
|
148
153
|
);
|
|
@@ -195,7 +200,7 @@ export const valueToSchema = (
|
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
// Handle arrays
|
|
198
|
-
if (
|
|
203
|
+
if (isArray(value)) {
|
|
199
204
|
// For arrays, we need to preserve undefined values while allowing
|
|
200
205
|
// other elements to use the original literalPrimitives setting
|
|
201
206
|
const filteredValue = value; // Always process all elements
|
|
@@ -232,6 +237,9 @@ export const valueToSchema = (
|
|
|
232
237
|
|
|
233
238
|
if (!noMixedArrays) {
|
|
234
239
|
// Helper function to generate structural keys for schemas
|
|
240
|
+
/**
|
|
241
|
+
* @function
|
|
242
|
+
*/
|
|
235
243
|
const getSchemaKey = <T extends z.core.SomeType | z.ZodType>(
|
|
236
244
|
zodType: T,
|
|
237
245
|
): string => {
|
|
@@ -253,7 +261,7 @@ export const valueToSchema = (
|
|
|
253
261
|
string,
|
|
254
262
|
z.ZodType
|
|
255
263
|
>;
|
|
256
|
-
const shapeKeys =
|
|
264
|
+
const shapeKeys = keys(shape)
|
|
257
265
|
.sort()
|
|
258
266
|
.map((key) => {
|
|
259
267
|
const propSchema = shape[key]!;
|
|
@@ -304,7 +312,7 @@ export const valueToSchema = (
|
|
|
304
312
|
const schemaShape: Record<string, z.ZodType<any>> = {};
|
|
305
313
|
const undefinedKeys: string[] = [];
|
|
306
314
|
|
|
307
|
-
for (const [key, val] of
|
|
315
|
+
for (const [key, val] of entries(value)) {
|
|
308
316
|
if (isString(key)) {
|
|
309
317
|
// Skip undefined values unless we're in literalPrimitives mode
|
|
310
318
|
// This prevents objects with only undefined values from matching any object
|
|
@@ -347,7 +355,7 @@ export const valueToSchema = (
|
|
|
347
355
|
|
|
348
356
|
const obj = data as Record<string, unknown>;
|
|
349
357
|
for (const key of undefinedKeys) {
|
|
350
|
-
if (!
|
|
358
|
+
if (!hasOwn(obj, key)) {
|
|
351
359
|
ctx.addIssue({
|
|
352
360
|
code: z.ZodIssueCode.custom,
|
|
353
361
|
message: `Expected property "${key}" to exist with value undefined`,
|
|
@@ -359,10 +367,10 @@ export const valueToSchema = (
|
|
|
359
367
|
}
|
|
360
368
|
|
|
361
369
|
// Check if this is an empty object and literalEmptyObjects is enabled
|
|
362
|
-
if (
|
|
370
|
+
if (keys(schemaShape).length === 0 && literalEmptyObjects) {
|
|
363
371
|
// Create a schema that only matches empty objects
|
|
364
372
|
return z.custom<Record<string, never>>(
|
|
365
|
-
(val) => isObject(val) &&
|
|
373
|
+
(val) => isObject(val) && keys(val).length === 0,
|
|
366
374
|
{
|
|
367
375
|
message: 'Expected an empty object with no own properties',
|
|
368
376
|
},
|
|
@@ -461,7 +469,7 @@ export interface ValueToSchemaOptions {
|
|
|
461
469
|
* Uses literal primitives and tuples for exact matching while allowing extra
|
|
462
470
|
* properties.
|
|
463
471
|
*/
|
|
464
|
-
export const valueToSchemaOptionsForSatisfies =
|
|
472
|
+
export const valueToSchemaOptionsForSatisfies = freeze({
|
|
465
473
|
literalEmptyObjects: true,
|
|
466
474
|
literalPrimitives: true,
|
|
467
475
|
literalRegExp: false,
|
|
@@ -476,7 +484,7 @@ export const valueToSchemaOptionsForSatisfies = Object.freeze({
|
|
|
476
484
|
* Uses literal primitives, regexp, and tuples with strict validation for exact
|
|
477
485
|
* matching.
|
|
478
486
|
*/
|
|
479
|
-
export const valueToSchemaOptionsForDeepEqual =
|
|
487
|
+
export const valueToSchemaOptionsForDeepEqual = freeze({
|
|
480
488
|
literalEmptyObjects: true,
|
|
481
489
|
literalPrimitives: true,
|
|
482
490
|
literalRegExp: true,
|