From d8fa1117b649a7bf1e07a2ca5f9df262ae878c44 Mon Sep 17 00:00:00 2001 From: Isaac Moldofsky Date: Sun, 14 Jul 2019 14:24:24 -0500 Subject: [PATCH 1/4] Update src/result.ts Co-Authored-By: Tom Crockett --- src/result.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/result.ts b/src/result.ts index 798b2656..06d4c232 100644 --- a/src/result.ts +++ b/src/result.ts @@ -30,7 +30,7 @@ export type Failure = { /** * A key indicating the location at which validation failed. */ - key: string; + key?: string; }; /** From baaef03338b49780cd283714c02d19118d3db0c9 Mon Sep 17 00:00:00 2001 From: Isaac Moldofsky Date: Mon, 30 Sep 2019 00:41:29 -0700 Subject: [PATCH 2/4] pass through value to failure --- src/result.ts | 6 ++++++ src/runtype.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/result.ts b/src/result.ts index 798b2656..9fff17bb 100644 --- a/src/result.ts +++ b/src/result.ts @@ -31,6 +31,12 @@ export type Failure = { * A key indicating the location at which validation failed. */ key: string; + + /** + * The original value passed through so data inspection can be done after failure. + * value is `any` here because its argument in `validate` is `any` type. + */ + value: any; }; /** diff --git a/src/runtype.ts b/src/runtype.ts index 17ead6c3..aa4acd11 100644 --- a/src/runtype.ts +++ b/src/runtype.ts @@ -117,7 +117,7 @@ export function create(check: (x: {}) => Static, A: any): check(value); return { success: true, value }; } catch ({ message, key }) { - return { success: false, message, key }; + return { success: false, message, key, value }; } } From 6439efd030f211a391fbab641dc829785aaa00ca Mon Sep 17 00:00:00 2001 From: Isaac Moldofsky Date: Mon, 30 Sep 2019 00:45:39 -0700 Subject: [PATCH 3/4] change name so success/failure does not match key on value --- src/result.ts | 2 +- src/runtype.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/result.ts b/src/result.ts index 9fff17bb..ca21b986 100644 --- a/src/result.ts +++ b/src/result.ts @@ -36,7 +36,7 @@ export type Failure = { * The original value passed through so data inspection can be done after failure. * value is `any` here because its argument in `validate` is `any` type. */ - value: any; + valueInvalidated: any; }; /** diff --git a/src/runtype.ts b/src/runtype.ts index aa4acd11..43e1479e 100644 --- a/src/runtype.ts +++ b/src/runtype.ts @@ -117,7 +117,7 @@ export function create(check: (x: {}) => Static, A: any): check(value); return { success: true, value }; } catch ({ message, key }) { - return { success: false, message, key, value }; + return { success: false, message, key, valueInvalidated: value }; } } From cf88d65836efe5978c253d93b6b81a935bbf9cde Mon Sep 17 00:00:00 2001 From: Isaac Moldofsky Date: Mon, 30 Sep 2019 00:56:25 -0700 Subject: [PATCH 4/4] fix merge conflict(?) --- src/result.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/result.ts b/src/result.ts index ca21b986..7819ec9d 100644 --- a/src/result.ts +++ b/src/result.ts @@ -30,7 +30,7 @@ export type Failure = { /** * A key indicating the location at which validation failed. */ - key: string; + key?: string; /** * The original value passed through so data inspection can be done after failure.