From f6f2c2f38f226afabca59e4aaf960926406c0592 Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Tue, 28 Nov 2023 22:37:04 -0500 Subject: [PATCH] Added missing default generic parameters when parsers are not given. Also remove the validation from our default undefined parser and simply ignore the input, since that seems more useful on compositions than erroring in case something is passed. --- src/constructor.test.ts | 9 +++++---- src/constructor.ts | 12 +++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/constructor.test.ts b/src/constructor.test.ts index 0db58c9a..78a13b41 100644 --- a/src/constructor.test.ts +++ b/src/constructor.test.ts @@ -32,13 +32,14 @@ describe('makeDomainFunction', () => { }) it('fails gracefully if gets something other than undefined', async () => { - const handler = mdf()(() => 'no input!') - type _R = Expect>> + const handler = mdf()((args) => args) + type _R = Expect>> assertEquals(await handler('some input'), { - success: false, + success: true, + data: undefined, errors: [], - inputErrors: [{ path: [], message: 'Expected undefined' }], + inputErrors: [], environmentErrors: [], }) }) diff --git a/src/constructor.ts b/src/constructor.ts index 08b7a8a5..2bcacd7d 100644 --- a/src/constructor.ts +++ b/src/constructor.ts @@ -87,7 +87,7 @@ async function safeResult(fn: () => T): Promise> { * return { message: `${greeting} ${user.name}` } * }) */ -function makeDomainFunction( +function makeDomainFunction>( inputSchema?: ParserSchema, environmentSchema?: ParserSchema, ) { @@ -131,14 +131,8 @@ const objectSchema: ParserSchema> = { } const undefinedSchema: ParserSchema = { - safeParseAsync: (data: unknown) => { - if (data !== undefined) { - return Promise.resolve({ - success: false, - error: { issues: [{ path: [], message: 'Expected undefined' }] }, - }) - } - return Promise.resolve({ success: true, data }) + safeParseAsync: (_data: unknown) => { + return Promise.resolve({ success: true, data: undefined }) }, }