(input: unknown)
| 16 | } |
| 17 | |
| 18 | export function canonicalizeWorkflowInput(input: unknown): unknown { |
| 19 | if (input == null || typeof input === "string" || typeof input === "boolean") { |
| 20 | return input; |
| 21 | } |
| 22 | |
| 23 | if (typeof input === "number") { |
| 24 | assert(Number.isFinite(input), "Workflow replay input numbers must be finite"); |
| 25 | return input; |
| 26 | } |
| 27 | |
| 28 | if (Array.isArray(input)) { |
| 29 | return input.map((value) => canonicalizeWorkflowInput(value)); |
| 30 | } |
| 31 | |
| 32 | if (typeof input === "object") { |
| 33 | assert( |
| 34 | Object.getPrototypeOf(input) === Object.prototype, |
| 35 | "Workflow replay inputs must be plain JSON objects/arrays" |
| 36 | ); |
| 37 | |
| 38 | const record = input as Record<string, unknown>; |
| 39 | const result: Record<string, unknown> = {}; |
| 40 | for (const key of Object.keys(record).sort()) { |
| 41 | const value = record[key]; |
| 42 | assert( |
| 43 | value !== undefined, |
| 44 | "Workflow replay inputs must not contain non-JSON value undefined" |
| 45 | ); |
| 46 | result[key] = canonicalizeWorkflowInput(value); |
| 47 | } |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | throw new Error(`Workflow replay inputs must be JSON values, got ${typeof input}`); |
| 52 | } |
no test coverage detected