Lightning.Collaboration.WorkflowSerializer (Lightning v2.15.0-pre5)
View SourceSerializes Lightning Workflow structs to/from Y.Doc CRDT documents.
This module handles bidirectional conversion:
serialize_to_ydoc/2- Write workflow data into a Y.Doc (workflow → Y.Doc)deserialize_from_ydoc/2- Extract workflow data from a Y.Doc (Y.Doc → workflow)
These functions maintain consistent field mappings between the two formats.
Y.Doc Structure
The Y.Doc contains six top-level collections:
workflow(Map): Core workflow metadata (id, name, lock_version, deleted_at, concurrency, enable_job_logs)jobs(Array): Array of job objects with Y.Text body fieldedges(Array): Array of edge objects connecting jobs/triggerstriggers(Array): Array of trigger objects (webhook, cron, kafka)positions(Map): Canvas positions for visual editor (node_id → {x, y})errors(Map): Field-level validation errors (field_path → error_message)
Field Mappings
Special Type Conversions
- Job
body: Stored as Y.Text (for collaborative editing) - Atoms (condition_type, trigger type): Converted to/from strings
- Nil values: Coalesced to empty strings or defaults where appropriate
Summary
Functions
Extracts workflow data from a Y.Doc.
This reads the Y.Doc structure and converts it to a map suitable for passing to Lightning.Workflows.save_workflow/2.
Parameters
doc: The Y.Doc to read fromworkflow_id: The workflow ID (needed for the returned map)
Returns
- A map with workflow data in the format expected by Workflows.save_workflow/2
@spec serialize_to_ydoc(Yex.Doc.t(), Lightning.Workflows.Workflow.t()) :: Yex.Doc.t()
Writes a workflow's data into a Y.Doc.
This initializes the Y.Doc structure with:
workflowmap: Core workflow metadata (id, name, lock_version, deleted_at, concurrency, enable_job_logs)jobsarray: Array of job objectsedgesarray: Array of edge objectstriggersarray: Array of trigger objectspositionsmap: Canvas positions for visual editor
This function is a refactored version of Session.initialize_workflow_data/2 with no behavioral changes.
Parameters
doc: The Y.Doc to write intoworkflow: The workflow struct to serialize
Returns
- The doc (for chaining convenience)