(store: YamlStore)
| 9 | | { found: true, config: ConfigFile } |
| 10 | |
| 11 | export async function loadConfig(store: YamlStore): Promise<LoadResult> { |
| 12 | let raw: Record<string, unknown> | null |
| 13 | try { |
| 14 | raw = await store.getTyped<Record<string, unknown>>() |
| 15 | } |
| 16 | catch (err) { |
| 17 | throw newError( |
| 18 | ErrorCode.ConfigSchemaUnsupported, |
| 19 | `parse config.yml: ${(err as Error).message}`, |
| 20 | ).wrap(err).withHint('config.yml is not valid YAML') |
| 21 | } |
| 22 | |
| 23 | if (raw === null) |
| 24 | return { found: false } |
| 25 | |
| 26 | const result = ConfigFileSchema.safeParse(raw) |
| 27 | if (!result.success) { |
| 28 | throw newError( |
| 29 | ErrorCode.ConfigSchemaUnsupported, |
| 30 | `validate config.yml: ${result.error.issues.map(i => i.message).join('; ')}`, |
| 31 | ).withHint('config.yml does not match the v1 schema') |
| 32 | } |
| 33 | |
| 34 | if (result.data.schema_version > CURRENT_SCHEMA_VERSION) { |
| 35 | throw newError( |
| 36 | ErrorCode.ConfigSchemaUnsupported, |
| 37 | `config.yml schema_version=${result.data.schema_version} is newer than this binary supports (max=${CURRENT_SCHEMA_VERSION})`, |
| 38 | ).withHint('upgrade difyctl, or remove config.yml') |
| 39 | } |
| 40 | |
| 41 | return { found: true, config: result.data } |
| 42 | } |
no test coverage detected