File tree Expand file tree Collapse file tree 2 files changed +224
-198
lines changed
app-config-extension-utils/src
app-config-extensions/src Expand file tree Collapse file tree 2 files changed +224
-198
lines changed Original file line number Diff line number Diff line change @@ -52,22 +52,32 @@ export function validateOptions<T>(
52
52
schema . cacheValidationFunction ( ) ;
53
53
54
54
return ( value , ctxKey , ctx ) => {
55
- const valid = ( value as unknown ) as T ;
55
+ return async ( parse , ...args ) => {
56
+ const valid = ( ( await parse ( value ) ) . toJSON ( ) as unknown ) as T ;
56
57
57
- try {
58
- schema . validate ( valid ) ;
59
- } catch ( error ) {
60
- const message = error instanceof Error ? error . message : 'unknown' ;
58
+ try {
59
+ schema . validate ( valid ) ;
60
+ } catch ( error ) {
61
+ const message = error instanceof Error ? error . message : 'unknown' ;
61
62
62
- const parents =
63
- [ ...ctx , ctxKey ]
64
- . map ( ( [ , k ] ) => k )
65
- . filter ( ( v ) => ! ! v )
66
- . join ( '.' ) || 'root' ;
63
+ const parents =
64
+ [ ...ctx , ctxKey ]
65
+ . map ( ( [ , k ] ) => k )
66
+ . filter ( ( v ) => ! ! v )
67
+ . join ( '.' ) || 'root' ;
67
68
68
- throw new ParsingExtensionInvalidOptions ( `Validation failed in "${ parents } ": ${ message } ` ) ;
69
- }
69
+ throw new ParsingExtensionInvalidOptions ( `Validation failed in "${ parents } ": ${ message } ` ) ;
70
+ }
71
+
72
+ const call = extension ( valid , ctxKey , ctx ) ;
70
73
71
- return extension ( valid , ctxKey , ctx ) ;
74
+ if ( call ) {
75
+ return call ( parse , ...args ) ;
76
+ } else {
77
+ throw new AppConfigError (
78
+ `A parsing extension returned as non-applicable, when using validateOptions. This isn't supported.` ,
79
+ ) ;
80
+ }
81
+ } ;
72
82
} ;
73
83
}
You can’t perform that action at this time.
0 commit comments