@cyoda/workflow-core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,16 +11,102 @@ npm install @cyoda/workflow-core
11
11
 
12
12
  ## Highlights
13
13
 
14
- - Parse and validate workflow import/export payloads
15
- - Normalize workflow documents into canonical editor state
16
- - Apply and invert domain patches
17
- - Serialize workflow state back to deterministic JSON
14
+ - Parse and validate workflow import/export payloads (Zod schemas).
15
+ - Normalize documents into canonical `WorkflowEditorDocument` state.
16
+ - Apply and invert domain patches with exact inverses.
17
+ - `PatchTransaction` group multiple patches into one atomic undo step.
18
+ - Deterministic serialization — exported JSON excludes all editor metadata.
19
+ - Editor metadata types: `WorkflowUiMeta`, `CommentMeta` (layout/comments
20
+ never appear in exported Cyoda JSON).
21
+
22
+ ## Patch families
23
+
24
+ | Op | Description |
25
+ |---|---|
26
+ | `addState` / `renameState` / `removeState` | State lifecycle |
27
+ | `setInitialState` | Promote a state to initial |
28
+ | `addTransition` / `updateTransition` / `removeTransition` | Transition editing |
29
+ | `reorderTransition` | Reorder within source state |
30
+ | `moveTransitionSource` | Move transition to a different source state |
31
+ | `addProcessor` / `updateProcessor` / `removeProcessor` / `reorderProcessor` | Processor editing |
32
+ | `setCriterion` | Set or clear a criterion at an arbitrary path |
33
+ | `addWorkflow` / `removeWorkflow` / `updateWorkflowMeta` / `renameWorkflow` | Workflow lifecycle |
34
+ | `setImportMode` / `setEntity` | Session metadata |
35
+ | `replaceSession` | Replace full session (Monaco JSON edits) |
36
+ | `setEdgeAnchors` | UI-only: edge anchor overrides |
37
+ | `setNodePosition` / `removeNodePosition` / `resetLayout` | UI-only: manual layout |
38
+ | `addComment` / `updateComment` / `removeComment` | UI-only: canvas comments |
39
+
40
+ All UI-only patches write to `meta.workflowUi` and are excluded from
41
+ `serializeImportPayload` output.
42
+
43
+ ## Exact inverses
44
+
45
+ `invertPatch(doc, patch)` returns a patch that, when applied after the
46
+ original, restores the document to its prior state. Exact inverses are
47
+ implemented for all patch families including reorder, moveTransitionSource,
48
+ and all UI-only metadata ops.
49
+
50
+ `PatchTransaction` groups forward patches with pre-computed inverses for
51
+ multi-patch undo in one step:
52
+
53
+ ```ts
54
+ import { applyTransaction, invertTransaction } from "@cyoda/workflow-core";
55
+
56
+ const tx = {
57
+ summary: "Add state at position",
58
+ patches: [
59
+ { op: "addState", workflow: "wf", stateCode: "new" },
60
+ { op: "setNodePosition", workflow: "wf", stateCode: "new", x: 50, y: 100 },
61
+ ],
62
+ inverses: [
63
+ { op: "removeNodePosition", workflow: "wf", stateCode: "new" },
64
+ { op: "removeState", workflow: "wf", stateCode: "new" },
65
+ ],
66
+ };
67
+ const after = applyTransaction(doc, tx);
68
+ const undoTx = invertTransaction(doc, tx);
69
+ ```
70
+
71
+ ## Deterministic serialization
72
+
73
+ ```ts
74
+ import { serializeImportPayload } from "@cyoda/workflow-core";
75
+
76
+ // Always produces clean, canonical Cyoda workflow JSON.
77
+ // Layout positions, comments, edge anchors, and viewport state are excluded.
78
+ const json = serializeImportPayload(doc);
79
+ ```
80
+
81
+ Fixed key order, 2-space indent, LF, trailing newline. No `operatorType`
82
+ aliases in output.
83
+
84
+ ## Editor metadata types
85
+
86
+ ```ts
87
+ // WorkflowUiMeta lives in doc.meta.workflowUi[workflowName].
88
+ // It is never serialised into exported Cyoda JSON.
89
+ interface WorkflowUiMeta {
90
+ layout?: { nodes: Record<StateCode, { x: number; y: number; pinned?: boolean }> };
91
+ comments?: Record<string, CommentMeta>;
92
+ edgeAnchors?: Record<string, EdgeAnchorPair>;
93
+ viewports?: Partial<Record<"vertical" | "horizontal", EditorViewport>>;
94
+ }
95
+
96
+ interface CommentMeta {
97
+ id: string;
98
+ text: string;
99
+ x: number;
100
+ y: number;
101
+ attachedTo?: { kind: "state"; stateCode: string }
102
+ | { kind: "transition"; sourceState: string; transitionName: string }
103
+ | { kind: "free" };
104
+ }
105
+ ```
18
106
 
19
107
  ## Documentation
20
108
 
21
- See the
22
- [repository README](https://github.com/Cyoda-platform/cyoda-workflow-editor#readme)
23
- for package relationships, usage examples, and release notes.
109
+ See the [repository README](https://github.com/Cyoda-platform/cyoda-workflow-editor#readme).
24
110
 
25
111
  ## License
26
112