| 291 | export const useExecutionContext = createContextHook(ExecutionContext); |
| 292 | |
| 293 | function tryParseJsonObject({ |
| 294 | json, |
| 295 | errorMessageParse, |
| 296 | errorMessageType, |
| 297 | }: { |
| 298 | json: string | undefined; |
| 299 | errorMessageParse: string; |
| 300 | errorMessageType: string; |
| 301 | }) { |
| 302 | let parsed: Record<string, any> | undefined; |
| 303 | try { |
| 304 | parsed = json && json.trim() !== '' ? JSON.parse(json) : undefined; |
| 305 | } catch (error) { |
| 306 | throw new Error( |
| 307 | `${errorMessageParse}: ${ |
| 308 | error instanceof Error ? error.message : error |
| 309 | }.`, |
| 310 | ); |
| 311 | } |
| 312 | const isObject = |
| 313 | typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed); |
| 314 | if (parsed !== undefined && !isObject) { |
| 315 | throw new Error(errorMessageType); |
| 316 | } |
| 317 | return parsed; |
| 318 | } |
| 319 | |
| 320 | type IncrementalResult = { |
| 321 | data?: Record<string, unknown> | null; |