| 17 | // schema into a map for easier lookups. |
| 18 | |
| 19 | function flattenSchema( |
| 20 | schema: SettingsSchema, |
| 21 | prefix = '', |
| 22 | ): Record<string, SettingDefinition & { key: string }> { |
| 23 | let result: Record<string, SettingDefinition & { key: string }> = {}; |
| 24 | for (const key in schema) { |
| 25 | const newKey = prefix ? `${prefix}.${key}` : key; |
| 26 | const definition = schema[key]; |
| 27 | result[newKey] = { ...definition, key: newKey }; |
| 28 | if (definition.properties) { |
| 29 | result = { ...result, ...flattenSchema(definition.properties, newKey) }; |
| 30 | } |
| 31 | } |
| 32 | return result; |
| 33 | } |
| 34 | |
| 35 | const FLATTENED_SCHEMA = flattenSchema(SETTINGS_SCHEMA); |
| 36 | |