* Normalizes a JSON field value: strings are parsed as JSON, already-resolved objects * and arrays are used as-is, and empty input returns undefined so the field is omitted.
(value: unknown, fieldName: string)
| 118 | * and arrays are used as-is, and empty input returns undefined so the field is omitted. |
| 119 | */ |
| 120 | function parseJsonValue(value: unknown, fieldName: string): unknown { |
| 121 | if (value == null) return undefined |
| 122 | if (typeof value === 'string') { |
| 123 | if (!value.trim()) return undefined |
| 124 | try { |
| 125 | return JSON.parse(value) |
| 126 | } catch { |
| 127 | throw new Error(`Invalid JSON in ${fieldName}`) |
| 128 | } |
| 129 | } |
| 130 | return value |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Parses a JSON value into Temporal `Payloads`. A top-level array is treated as the |
no test coverage detected