Skip to content

Commit cf87350

Browse files
committed
Simplify preprocess
1 parent 5603883 commit cf87350

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,8 @@ const FormElicitationCapabilitySchema = z.intersection(
284284
const ElicitationCapabilitySchema = z.preprocess(
285285
value => {
286286
if (value && typeof value === 'object' && !Array.isArray(value)) {
287-
const recordValue = value as Record<string, unknown>;
288-
const hasForm = Object.prototype.hasOwnProperty.call(recordValue, 'form');
289-
const hasUrl = Object.prototype.hasOwnProperty.call(recordValue, 'url');
290-
if (!hasForm && !hasUrl) {
291-
return { ...recordValue, form: {} };
287+
if (Object.keys(value as Record<string, unknown>).length === 0) {
288+
return { form: {} };
292289
}
293290
}
294291
return value;
@@ -298,7 +295,7 @@ const ElicitationCapabilitySchema = z.preprocess(
298295
form: FormElicitationCapabilitySchema.optional(),
299296
url: AssertObjectSchema.optional()
300297
}),
301-
z.record(z.string(), z.unknown())
298+
z.record(z.string(), z.unknown()).optional()
302299
)
303300
);
304301

0 commit comments

Comments
 (0)