Lightning.Collaboration.WorkflowSerializer (Lightning v2.14.11-pre1)
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 five top-level collections:
workflow
(Map): Core workflow metadata (id, name, lock_version, deleted_at)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})
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:
workflow
map: Core workflow metadata (id, name, lock_version, deleted_at)jobs
array: Array of job objectsedges
array: Array of edge objectstriggers
array: Array of trigger objectspositions
map: 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)