( workflowState: WorkflowState, options: GenerateWorkflowJsonOptions )
| 775 | * This is a pure function that takes the workflow state and metadata and returns the JSON string. |
| 776 | */ |
| 777 | export function generateWorkflowJson( |
| 778 | workflowState: WorkflowState, |
| 779 | options: GenerateWorkflowJsonOptions |
| 780 | ): string { |
| 781 | const variablesRecord: Record<string, Variable> | undefined = options.variables?.reduce( |
| 782 | (acc, v) => { |
| 783 | acc[v.id] = { |
| 784 | id: v.id, |
| 785 | name: v.name, |
| 786 | type: v.type, |
| 787 | value: v.value, |
| 788 | } |
| 789 | return acc |
| 790 | }, |
| 791 | {} as Record<string, Variable> |
| 792 | ) |
| 793 | |
| 794 | const stateWithMetadata: WorkflowState = { |
| 795 | ...workflowState, |
| 796 | metadata: { |
| 797 | name: options.name, |
| 798 | description: options.description, |
| 799 | exportedAt: new Date().toISOString(), |
| 800 | }, |
| 801 | variables: variablesRecord, |
| 802 | } |
| 803 | |
| 804 | const exportState: ExportWorkflowState = sanitizeForExport(stateWithMetadata) |
| 805 | const jsonString = JSON.stringify(exportState, null, 2) |
| 806 | |
| 807 | logger.info('Workflow JSON generated successfully', { |
| 808 | version: exportState.version, |
| 809 | exportedAt: exportState.exportedAt, |
| 810 | blocksCount: Object.keys(exportState.state.blocks).length, |
| 811 | edgesCount: exportState.state.edges.length, |
| 812 | jsonLength: jsonString.length, |
| 813 | }) |
| 814 | |
| 815 | return jsonString |
| 816 | } |
no test coverage detected