(obj: Record<string, unknown>)
| 158 | } |
| 159 | |
| 160 | async function evaluateObject(obj: Record<string, unknown>) { |
| 161 | if (obj.hasOwnProperty("@ref")) { |
| 162 | const index = obj["@ref"]; |
| 163 | if (typeof index === "number" && index < results.length) { |
| 164 | return results[index]; |
| 165 | } |
| 166 | } |
| 167 | else if (obj.hasOwnProperty("@func")) { |
| 168 | const func = obj["@func"]; |
| 169 | const args = obj.hasOwnProperty("@args") ? obj["@args"] : []; |
| 170 | if (typeof func === "string" && Array.isArray(args)) { |
| 171 | return await onCall(func, await evaluateArray(args)); |
| 172 | } |
| 173 | } |
| 174 | else if (Array.isArray(obj)) { |
| 175 | return evaluateArray(obj); |
| 176 | } |
| 177 | else { |
| 178 | const values = await Promise.all(Object.values(obj).map(evaluate)); |
| 179 | return Object.fromEntries(Object.keys(obj).map((k, i) => [k, values[i]])); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | function evaluateArray(array: unknown[]) { |
| 184 | return Promise.all(array.map(evaluate)); |
no test coverage detected
searching dependent graphs…