(key: string, s: Schema<number> | Schema<string> | Schema<boolean>, defaultFamily = 'setting_basic')
| 85 | function schemaToSettings(schema: Schema<any>) { |
| 86 | const result: _Setting[] = []; |
| 87 | const processNode = (key: string, s: Schema<number> | Schema<string> | Schema<boolean>, defaultFamily = 'setting_basic') => { |
| 88 | if (s.dict) throw new Error('Dict is not supported here'); |
| 89 | let flag = (s.meta?.hidden ? FLAG_HIDDEN : 0) |
| 90 | | (s.meta?.disabled ? FLAG_DISABLED : 0); |
| 91 | const actualType = s.type === 'transform' ? s.inner.type : s.type; |
| 92 | const actualList = s.type === 'transform' ? s.inner.list : s.list; |
| 93 | const type = actualType === 'any' ? 'json' |
| 94 | : actualType === 'number' ? 'number' |
| 95 | : actualType === 'boolean' ? 'boolean' |
| 96 | : s.meta?.role === 'markdown' ? 'markdown' |
| 97 | : s.meta?.role === 'textarea' ? 'textarea' : 'text'; |
| 98 | if (s.meta?.role === 'password') flag |= FLAG_SECRET; |
| 99 | if (s.meta?.flag) flag |= s.meta?.flag; |
| 100 | const options = {}; |
| 101 | for (const item of actualList || []) { |
| 102 | if (item.type !== 'const') throw new Error(`List item must be a constant, got ${item.type}`); |
| 103 | options[item.value] = item.meta?.description || item.value; |
| 104 | } |
| 105 | return { |
| 106 | family: s.meta?.family || defaultFamily, |
| 107 | key, |
| 108 | value: s.meta?.default, |
| 109 | name: key, |
| 110 | desc: s.meta?.description, |
| 111 | flag, |
| 112 | subType: '', |
| 113 | type: actualList ? 'select' : type, |
| 114 | range: actualList ? options : null, |
| 115 | validation: (v) => { |
| 116 | try { |
| 117 | (s as any)(v); |
| 118 | return true; |
| 119 | } catch (e) { |
| 120 | return false; |
| 121 | } |
| 122 | }, |
| 123 | } as _Setting; |
| 124 | }; |
| 125 | if (!schema.dict) return []; |
| 126 | for (const key in schema.dict) { |
| 127 | const value = schema.dict[key]; |
no outgoing calls
no test coverage detected