@allternit/workflow-engine 0.1.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.
Files changed (49) hide show
  1. package/README.md +227 -0
  2. package/dist/engine/workflow-engine.d.ts +39 -0
  3. package/dist/engine/workflow-engine.d.ts.bak +39 -0
  4. package/dist/engine/workflow-engine.d.ts.map +1 -0
  5. package/dist/engine/workflow-engine.js +532 -0
  6. package/dist/engine/workflow-engine.js.bak +532 -0
  7. package/dist/engine/workflow-engine.js.map +1 -0
  8. package/dist/index.d.ts +38 -0
  9. package/dist/index.d.ts.bak +38 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +41 -0
  12. package/dist/index.js.bak +41 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/scheduler/index.d.ts +53 -0
  15. package/dist/scheduler/index.d.ts.bak +53 -0
  16. package/dist/scheduler/index.d.ts.map +1 -0
  17. package/dist/scheduler/index.js +135 -0
  18. package/dist/scheduler/index.js.bak +135 -0
  19. package/dist/scheduler/index.js.map +1 -0
  20. package/dist/types.d.ts +402 -0
  21. package/dist/types.d.ts.bak +402 -0
  22. package/dist/types.d.ts.map +1 -0
  23. package/dist/types.js +7 -0
  24. package/dist/types.js.bak +7 -0
  25. package/dist/types.js.map +1 -0
  26. package/dist/visualizer/index.d.ts +81 -0
  27. package/dist/visualizer/index.d.ts.bak +81 -0
  28. package/dist/visualizer/index.d.ts.map +1 -0
  29. package/dist/visualizer/index.js +277 -0
  30. package/dist/visualizer/index.js.bak +277 -0
  31. package/dist/visualizer/index.js.map +1 -0
  32. package/package.json +57 -0
  33. package/src/__tests__/visualizer.test.ts.bak +110 -0
  34. package/src/__tests__/workflow-engine.test.ts.bak +239 -0
  35. package/src/engine/workflow-engine.test.ts.bak +852 -0
  36. package/src/engine/workflow-engine.ts +651 -0
  37. package/src/engine/workflow-engine.ts.bak +651 -0
  38. package/src/index.ts +89 -0
  39. package/src/index.ts.bak +89 -0
  40. package/src/scheduler/index.ts +204 -0
  41. package/src/scheduler/index.ts.bak +204 -0
  42. package/src/scheduler/scheduler.test.ts.bak +521 -0
  43. package/src/types.ts +449 -0
  44. package/src/types.ts.bak +449 -0
  45. package/src/visualizer/index.ts +409 -0
  46. package/src/visualizer/index.ts.bak +409 -0
  47. package/src/visualizer/visualizer.test.ts.bak +844 -0
  48. package/tsconfig.json +22 -0
  49. package/vitest.config.ts.bak +9 -0
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+ # @allternit/workflow-engine
2
+
3
+ A2R Workflow Engine - Visual workflow orchestration with DAG support.
4
+
5
+ ## Overview
6
+
7
+ The Workflow Engine enables visual definition and execution of complex multi-step processes using a directed acyclic graph (DAG) structure. It supports conditional branching, parallel execution, loops, and custom node types.
8
+
9
+ ## Features
10
+
11
+ - **Visual Workflow Definition**: DAG-based workflow structure
12
+ - **Built-in Node Types**: Triggers, transforms, conditions, loops, HTTP requests
13
+ - **Parallel Execution**: Scheduler for concurrent task execution
14
+ - **Conditional Branching**: Route execution based on conditions
15
+ - **Error Handling**: Retry logic and error handlers
16
+ - **Visualization**: Export to SVG, Mermaid, or Graphviz
17
+ - **Extensible**: Custom node types and executors
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pnpm add @allternit/workflow-engine
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { createWorkflowEngine } from '@allternit/workflow-engine';
29
+
30
+ const engine = createWorkflowEngine();
31
+
32
+ // Define workflow
33
+ engine.registerWorkflow({
34
+ id: 'data-pipeline',
35
+ name: 'Data Pipeline',
36
+ version: '1.0.0',
37
+ nodes: [
38
+ {
39
+ id: 'trigger',
40
+ type: 'trigger:webhook',
41
+ name: 'Webhook Trigger',
42
+ },
43
+ {
44
+ id: 'fetch',
45
+ type: 'http:request',
46
+ name: 'Fetch Data',
47
+ config: {
48
+ method: 'GET',
49
+ url: 'https://api.example.com/data',
50
+ },
51
+ },
52
+ {
53
+ id: 'filter',
54
+ type: 'transform:filter',
55
+ name: 'Filter Items',
56
+ config: {
57
+ condition: 'item.active === true',
58
+ },
59
+ },
60
+ {
61
+ id: 'output',
62
+ type: 'output:result',
63
+ name: 'Return Results',
64
+ },
65
+ ],
66
+ connections: [
67
+ { id: 'c1', source: 'trigger', target: 'fetch' },
68
+ { id: 'c2', source: 'fetch', target: 'filter' },
69
+ { id: 'c3', source: 'filter', target: 'output' },
70
+ ],
71
+ });
72
+
73
+ // Execute workflow
74
+ const execution = await engine.execute('data-pipeline', {
75
+ webhookData: { id: 123 },
76
+ });
77
+
78
+ console.log(execution.status); // 'completed'
79
+ console.log(execution.outputs); // { response: [...] }
80
+ ```
81
+
82
+ ## Built-in Node Types
83
+
84
+ ### Triggers
85
+ | Type | Description |
86
+ |------|-------------|
87
+ | `trigger:manual` | Manual or API trigger |
88
+ | `trigger:schedule` | Scheduled execution |
89
+ | `trigger:webhook` | HTTP webhook trigger |
90
+
91
+ ### Transforms
92
+ | Type | Description |
93
+ |------|-------------|
94
+ | `transform:map` | Transform data using expression |
95
+ | `transform:filter` | Filter array items |
96
+
97
+ ### Logic
98
+ | Type | Description |
99
+ |------|-------------|
100
+ | `condition:if` | Conditional branching |
101
+ | `loop:for-each` | Iterate over array |
102
+
103
+ ### Actions
104
+ | Type | Description |
105
+ |------|-------------|
106
+ | `http:request` | HTTP request |
107
+ | `delay:wait` | Pause execution |
108
+ | `output:result` | Set workflow output |
109
+ | `output:log` | Log message |
110
+
111
+ ## Visualization
112
+
113
+ ```typescript
114
+ import { createVisualizer } from '@allternit/workflow-engine';
115
+
116
+ const visualizer = createVisualizer();
117
+
118
+ // Export to SVG
119
+ const svg = visualizer.toSVG(workflow);
120
+
121
+ // Export to Mermaid
122
+ const mermaid = visualizer.toMermaid(workflow);
123
+ // graph TD
124
+ // trigger["Start"]
125
+ // trigger --> http
126
+
127
+ // Export to Graphviz
128
+ const dot = visualizer.toDOT(workflow);
129
+ ```
130
+
131
+ ## Custom Node Types
132
+
133
+ ```typescript
134
+ engine.registerNodeType({
135
+ type: 'custom:processor',
136
+ category: 'custom',
137
+ displayName: 'Data Processor',
138
+ description: 'Process data with custom logic',
139
+ inputs: [
140
+ { name: 'data', type: 'object', required: true },
141
+ ],
142
+ outputs: [
143
+ { name: 'result', type: 'object' },
144
+ ],
145
+ configSchema: [
146
+ { name: 'multiplier', type: 'number', default: 1 },
147
+ ],
148
+ executor: async (node, context, inputs) => {
149
+ const multiplier = node.config?.multiplier || 1;
150
+ const result = inputs.data.value * multiplier;
151
+ return { result: { value: result } };
152
+ },
153
+ });
154
+ ```
155
+
156
+ ## Scheduler
157
+
158
+ ```typescript
159
+ import { createScheduler } from '@allternit/workflow-engine';
160
+
161
+ const scheduler = createScheduler({
162
+ maxConcurrency: 5,
163
+ defaultTimeout: 30000,
164
+ });
165
+
166
+ // Submit task
167
+ await scheduler.submit({
168
+ id: 'task-1',
169
+ node: workflowNode,
170
+ execution: workflowExecution,
171
+ });
172
+
173
+ // Check status
174
+ const status = scheduler.getStatus();
175
+ console.log(status.running); // 1
176
+ console.log(status.queued); // 0
177
+ ```
178
+
179
+ ## API Reference
180
+
181
+ ### WorkflowEngine
182
+
183
+ ```typescript
184
+ interface WorkflowEngine {
185
+ registerWorkflow(workflow: Workflow): void;
186
+ getWorkflow(id: string): Workflow | undefined;
187
+ execute(workflowId: string, inputs?: Record<string, unknown>): Promise<WorkflowExecution>;
188
+ getExecution(executionId: string): WorkflowExecution | undefined;
189
+ cancelExecution(executionId: string): boolean;
190
+ registerNodeType(nodeType: NodeType): void;
191
+ }
192
+ ```
193
+
194
+ ### Workflow Types
195
+
196
+ ```typescript
197
+ interface Workflow {
198
+ id: string;
199
+ name: string;
200
+ version: string;
201
+ nodes: WorkflowNode[];
202
+ connections: Connection[];
203
+ inputs?: ParameterSchema[];
204
+ outputs?: ParameterSchema[];
205
+ errorHandling?: ErrorHandlingConfig;
206
+ }
207
+
208
+ interface WorkflowNode {
209
+ id: string;
210
+ type: string;
211
+ name: string;
212
+ config?: Record<string, unknown>;
213
+ inputs?: InputMapping[];
214
+ outputs?: OutputMapping[];
215
+ }
216
+
217
+ interface Connection {
218
+ id: string;
219
+ source: string;
220
+ target: string;
221
+ condition?: string;
222
+ }
223
+ ```
224
+
225
+ ## License
226
+
227
+ MIT
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Workflow Engine
3
+ *
4
+ * Core engine for executing workflows with DAG support.
5
+ */
6
+ import type { Workflow, WorkflowExecution, WorkflowEngineConfig, NodeType } from '../types';
7
+ export interface WorkflowEngine {
8
+ /** Register a workflow */
9
+ registerWorkflow(workflow: Workflow): void;
10
+ /** Get workflow by ID */
11
+ getWorkflow(id: string): Workflow | undefined;
12
+ /** List all workflows */
13
+ listWorkflows(): Workflow[];
14
+ /** Delete workflow */
15
+ deleteWorkflow(id: string): boolean;
16
+ /** Execute workflow */
17
+ execute(workflowId: string, inputs?: Record<string, unknown>): Promise<WorkflowExecution>;
18
+ /** Get execution status */
19
+ getExecution(executionId: string): WorkflowExecution | undefined;
20
+ /** Cancel execution */
21
+ cancelExecution(executionId: string): boolean;
22
+ /** Pause execution */
23
+ pauseExecution(executionId: string): boolean;
24
+ /** Resume execution */
25
+ resumeExecution(executionId: string): boolean;
26
+ /** Register node type */
27
+ registerNodeType(nodeType: NodeType): void;
28
+ /** Get node type */
29
+ getNodeType(type: string): NodeType | undefined;
30
+ }
31
+ /**
32
+ * Create workflow engine
33
+ */
34
+ export declare function createWorkflowEngine(config?: WorkflowEngineConfig): WorkflowEngine;
35
+ /**
36
+ * Global workflow engine instance
37
+ */
38
+ export declare const globalWorkflowEngine: WorkflowEngine;
39
+ //# sourceMappingURL=workflow-engine.d.ts.map
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Workflow Engine
3
+ *
4
+ * Core engine for executing workflows with DAG support.
5
+ */
6
+ import type { Workflow, WorkflowExecution, WorkflowEngineConfig, NodeType } from '../types';
7
+ export interface WorkflowEngine {
8
+ /** Register a workflow */
9
+ registerWorkflow(workflow: Workflow): void;
10
+ /** Get workflow by ID */
11
+ getWorkflow(id: string): Workflow | undefined;
12
+ /** List all workflows */
13
+ listWorkflows(): Workflow[];
14
+ /** Delete workflow */
15
+ deleteWorkflow(id: string): boolean;
16
+ /** Execute workflow */
17
+ execute(workflowId: string, inputs?: Record<string, unknown>): Promise<WorkflowExecution>;
18
+ /** Get execution status */
19
+ getExecution(executionId: string): WorkflowExecution | undefined;
20
+ /** Cancel execution */
21
+ cancelExecution(executionId: string): boolean;
22
+ /** Pause execution */
23
+ pauseExecution(executionId: string): boolean;
24
+ /** Resume execution */
25
+ resumeExecution(executionId: string): boolean;
26
+ /** Register node type */
27
+ registerNodeType(nodeType: NodeType): void;
28
+ /** Get node type */
29
+ getNodeType(type: string): NodeType | undefined;
30
+ }
31
+ /**
32
+ * Create workflow engine
33
+ */
34
+ export declare function createWorkflowEngine(config?: WorkflowEngineConfig): WorkflowEngine;
35
+ /**
36
+ * Global workflow engine instance
37
+ */
38
+ export declare const globalWorkflowEngine: WorkflowEngine;
39
+ //# sourceMappingURL=workflow-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-engine.d.ts","sourceRoot":"","sources":["../../src/engine/workflow-engine.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,QAAQ,EACR,iBAAiB,EAQjB,oBAAoB,EACpB,QAAQ,EACT,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,cAAc;IAC7B,0BAA0B;IAC1B,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,yBAAyB;IACzB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC9C,yBAAyB;IACzB,aAAa,IAAI,QAAQ,EAAE,CAAC;IAC5B,sBAAsB;IACtB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IACpC,uBAAuB;IACvB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1F,2BAA2B;IAC3B,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACjE,uBAAuB;IACvB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9C,sBAAsB;IACtB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7C,uBAAuB;IACvB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9C,yBAAyB;IACzB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3C,oBAAoB;IACpB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;CACjD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAolBtF;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,gBAAyB,CAAC"}