( values: Record<string, unknown>, declarations: readonly CompositionVariable[], )
| 13 | * failure under `--strict-variables`). |
| 14 | */ |
| 15 | export function validateVariables( |
| 16 | values: Record<string, unknown>, |
| 17 | declarations: readonly CompositionVariable[], |
| 18 | ): VariableValidationIssue[] { |
| 19 | const decls = new Map<string, CompositionVariable>(); |
| 20 | for (const decl of declarations) decls.set(decl.id, decl); |
| 21 | |
| 22 | const issues: VariableValidationIssue[] = []; |
| 23 | for (const [id, value] of Object.entries(values)) { |
| 24 | const decl = decls.get(id); |
| 25 | if (!decl) { |
| 26 | issues.push({ kind: "undeclared", variableId: id }); |
| 27 | continue; |
| 28 | } |
| 29 | const mismatch = checkType(value, decl); |
| 30 | if (mismatch) issues.push(mismatch); |
| 31 | } |
| 32 | return issues; |
| 33 | } |
| 34 | |
| 35 | function isPlainObject(value: unknown): value is Record<string, unknown> { |
| 36 | return typeof value === "object" && value !== null && !Array.isArray(value); |
no test coverage detected