@@ -52,13 +52,42 @@ const validateSchema = (manifest: Manifest): void => {
52
52
throw new Error ( `The 'options' property should be an array` )
53
53
}
54
54
55
- //TODO: update this to use the new validation functions
56
- manifest . options ?. forEach ( ( option ) => {
57
- if ( ! ( 'name' in option && 'value' in option ) ) {
58
- throw new Error (
59
- `Some of the defined 'options' are invalid. ` +
60
- `Please, make sure they contain a 'name' and 'value' properties` ,
55
+ validateOptions ( manifest . options )
56
+ return
57
+ }
58
+
59
+ //NOTE: There is a duplicate of this function in the field-plugin/helpers/vite/src/manifest.ts file
60
+ const validateOptions = ( options : unknown [ ] ) : void => {
61
+ const incorrectValues : string [ ] = [ ]
62
+
63
+ for ( const option of options ) {
64
+ if ( ! isOptionObject ( option ) ) {
65
+ incorrectValues . push (
66
+ `${ JSON . stringify ( option ) } --> Incorrect object value. Must be of type {"name": string, "value": string}.` ,
61
67
)
68
+ continue
62
69
}
63
- } )
70
+
71
+ if ( ! isString ( option . value ) ) {
72
+ incorrectValues . push (
73
+ `${ JSON . stringify ( option ) } --> Incorrect value type. Must be of type string.` ,
74
+ )
75
+ continue
76
+ }
77
+ }
78
+
79
+ if ( incorrectValues . length > 0 ) {
80
+ throw new Error (
81
+ 'Each option must be an object with string properties "name" and "value". The following values need to be corrected: \n ' +
82
+ incorrectValues . join ( '\n ' ) ,
83
+ )
84
+ }
64
85
}
86
+
87
+ export const isString = ( value : unknown ) => typeof value === 'string'
88
+
89
+ export const isOptionObject = ( option : unknown ) : option is ManifestOption =>
90
+ typeof option === 'object' &&
91
+ option !== null &&
92
+ 'name' in option &&
93
+ 'value' in option
0 commit comments