Skip to content

Commit bd5032c

Browse files
committed
feat(helper): add logic also to manifest-helper
1 parent 33f30e1 commit bd5032c

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

packages/field-plugin/helpers/vite/src/manifest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const validateSchema = (manifest: Manifest): void => {
5353
return
5454
}
5555

56+
//NOTE: There is a duplicate of this function in the manifest-helper/src/manifest.ts file
5657
const validateOptions = (options: unknown[]): void => {
5758
const incorrectValues: string[] = []
5859

packages/manifest-helper/src/manifest.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,42 @@ const validateSchema = (manifest: Manifest): void => {
5252
throw new Error(`The 'options' property should be an array`)
5353
}
5454

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}.`,
6167
)
68+
continue
6269
}
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+
}
6485
}
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

Comments
 (0)