| 506 | |
| 507 | // meta. prefixed keys are moved to meta, overwriting a nested key of the same name |
| 508 | const withPrefixedMeta = (input: dict): dict => { |
| 509 | let meta: dict | undefined |
| 510 | let rest: dict | undefined |
| 511 | for (const k in input) { |
| 512 | if (!k.startsWith("meta.")) continue |
| 513 | rest ??= { ...input } |
| 514 | meta ??= |
| 515 | typeof input.meta === "string" ? { description: input.meta } |
| 516 | : input.meta ? { ...(input.meta as dict) } |
| 517 | : {} |
| 518 | meta[k.slice(5)] = input[k] |
| 519 | delete rest[k] |
| 520 | } |
| 521 | return rest ? { ...rest, meta } : input |
| 522 | } |