@allternit/workflow-engine 0.1.0 → 0.1.1

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/src/index.ts.bak DELETED
@@ -1,89 +0,0 @@
1
- /**
2
- * A2R Workflow Engine
3
- *
4
- * Visual workflow orchestration with DAG support.
5
- *
6
- * @example
7
- * ```typescript
8
- * import { createWorkflowEngine, createVisualizer } from '@allternit/workflow-engine';
9
- *
10
- * const engine = createWorkflowEngine();
11
- *
12
- * // Register workflow
13
- * engine.registerWorkflow({
14
- * id: 'my-workflow',
15
- * name: 'My Workflow',
16
- * version: '1.0.0',
17
- * nodes: [
18
- * { id: 'trigger', type: 'trigger:manual', name: 'Start' },
19
- * { id: 'http', type: 'http:request', name: 'Fetch Data', config: { method: 'GET' } },
20
- * { id: 'output', type: 'output:result', name: 'Return Result' },
21
- * ],
22
- * connections: [
23
- * { id: 'c1', source: 'trigger', target: 'http' },
24
- * { id: 'c2', source: 'http', target: 'output' },
25
- * ],
26
- * });
27
- *
28
- * // Execute workflow
29
- * const execution = await engine.execute('my-workflow', { url: 'https://api.example.com' });
30
- * console.log(execution.status); // 'completed'
31
- * ```
32
- */
33
-
34
- // Core Types
35
- export type {
36
- Workflow,
37
- WorkflowNode,
38
- Connection,
39
- WorkflowExecution,
40
- ExecutionContext,
41
- ExecutionState,
42
- NodeExecution,
43
- ExecutionStatus,
44
- ExecutionError,
45
- ParameterSchema,
46
- Variable,
47
- InputMapping,
48
- OutputMapping,
49
- Trigger,
50
- ErrorHandlingConfig,
51
- NodeType,
52
- NodeCategory,
53
- PortDefinition,
54
- WorkflowEngineConfig,
55
- WorkflowHooks,
56
- Position,
57
- } from './types';
58
-
59
- // Engine
60
- export {
61
- createWorkflowEngine,
62
- globalWorkflowEngine,
63
- type WorkflowEngine,
64
- } from './engine/workflow-engine';
65
-
66
- // Scheduler
67
- export {
68
- createScheduler,
69
- globalScheduler,
70
- type Scheduler,
71
- type SchedulerConfig,
72
- type Task,
73
- type SchedulerStatus,
74
- } from './scheduler';
75
-
76
- // Visualizer
77
- export {
78
- createVisualizer,
79
- globalVisualizer,
80
- type WorkflowVisualizer,
81
- type VisualizerConfig,
82
- type VisualLayout,
83
- type VisualNode,
84
- type VisualConnection,
85
- type Bounds,
86
- } from './visualizer';
87
-
88
- // Version
89
- export const VERSION = '0.1.0';
@@ -1,204 +0,0 @@
1
- /**
2
- * Workflow Scheduler
3
- *
4
- * Handles parallel execution, queuing, and resource management.
5
- */
6
-
7
- import type { WorkflowExecution, WorkflowNode, ExecutionContext } from '../types';
8
-
9
- export interface SchedulerConfig {
10
- /** Max concurrent tasks */
11
- maxConcurrency?: number;
12
- /** Queue size limit */
13
- queueLimit?: number;
14
- /** Default task timeout (ms) */
15
- defaultTimeout?: number;
16
- /** Enable task prioritization */
17
- enablePriority?: boolean;
18
- }
19
-
20
- export interface Task {
21
- id: string;
22
- node: WorkflowNode;
23
- execution: WorkflowExecution;
24
- priority?: number;
25
- timeout?: number;
26
- }
27
-
28
- export interface Scheduler {
29
- /** Submit task for execution */
30
- submit(task: Task): Promise<unknown>;
31
- /** Submit multiple tasks (parallel) */
32
- submitAll(tasks: Task[]): Promise<unknown[]>;
33
- /** Cancel task */
34
- cancel(taskId: string): boolean;
35
- /** Get queue status */
36
- getStatus(): SchedulerStatus;
37
- /** Pause scheduler */
38
- pause(): void;
39
- /** Resume scheduler */
40
- resume(): void;
41
- }
42
-
43
- export interface SchedulerStatus {
44
- running: number;
45
- queued: number;
46
- completed: number;
47
- failed: number;
48
- isPaused: boolean;
49
- }
50
-
51
- /**
52
- * Create workflow scheduler
53
- */
54
- export function createScheduler(config: SchedulerConfig = {}): Scheduler {
55
- const {
56
- maxConcurrency = 5,
57
- queueLimit = 100,
58
- defaultTimeout = 60000,
59
- enablePriority = false,
60
- } = config;
61
-
62
- const queue: Task[] = [];
63
- const running = new Map<string, AbortController>();
64
- let isPaused = false;
65
- let completed = 0;
66
- let failed = 0;
67
-
68
- /**
69
- * Process queue
70
- */
71
- async function processQueue(): Promise<void> {
72
- if (isPaused || running.size >= maxConcurrency || queue.length === 0) {
73
- return;
74
- }
75
-
76
- // Sort by priority if enabled
77
- if (enablePriority) {
78
- queue.sort((a, b) => (b.priority || 0) - (a.priority || 0));
79
- }
80
-
81
- const task = queue.shift();
82
- if (!task) return;
83
-
84
- const controller = new AbortController();
85
- running.set(task.id, controller);
86
-
87
- try {
88
- const timeout = task.timeout || defaultTimeout;
89
- const timeoutId = setTimeout(() => controller.abort(), timeout);
90
-
91
- // Execute task
92
- const result = await executeTask(task, controller.signal);
93
-
94
- clearTimeout(timeoutId);
95
- completed++;
96
-
97
- return;
98
- } catch (error) {
99
- failed++;
100
- throw error;
101
- } finally {
102
- running.delete(task.id);
103
- // Process next
104
- processQueue();
105
- }
106
- }
107
-
108
- /**
109
- * Execute task
110
- */
111
- async function executeTask(task: Task, signal: AbortSignal): Promise<unknown> {
112
- if (signal.aborted) {
113
- throw new Error('Task cancelled');
114
- }
115
-
116
- // Task execution logic here
117
- // This would integrate with the workflow engine
118
- return { taskId: task.id, status: 'completed' };
119
- }
120
-
121
- /**
122
- * Submit task
123
- */
124
- async function submit(task: Task): Promise<unknown> {
125
- if (queue.length >= queueLimit) {
126
- throw new Error('Queue limit reached');
127
- }
128
-
129
- queue.push(task);
130
-
131
- // Start processing
132
- return processQueue();
133
- }
134
-
135
- /**
136
- * Submit multiple tasks
137
- */
138
- async function submitAll(tasks: Task[]): Promise<unknown[]> {
139
- return Promise.all(tasks.map(task => submit(task)));
140
- }
141
-
142
- /**
143
- * Cancel task
144
- */
145
- function cancel(taskId: string): boolean {
146
- // Cancel if running
147
- const controller = running.get(taskId);
148
- if (controller) {
149
- controller.abort();
150
- return true;
151
- }
152
-
153
- // Remove from queue
154
- const index = queue.findIndex(t => t.id === taskId);
155
- if (index >= 0) {
156
- queue.splice(index, 1);
157
- return true;
158
- }
159
-
160
- return false;
161
- }
162
-
163
- /**
164
- * Get status
165
- */
166
- function getStatus(): SchedulerStatus {
167
- return {
168
- running: running.size,
169
- queued: queue.length,
170
- completed,
171
- failed,
172
- isPaused,
173
- };
174
- }
175
-
176
- /**
177
- * Pause scheduler
178
- */
179
- function pause(): void {
180
- isPaused = true;
181
- }
182
-
183
- /**
184
- * Resume scheduler
185
- */
186
- function resume(): void {
187
- isPaused = false;
188
- processQueue();
189
- }
190
-
191
- return {
192
- submit,
193
- submitAll,
194
- cancel,
195
- getStatus,
196
- pause,
197
- resume,
198
- };
199
- }
200
-
201
- /**
202
- * Global scheduler instance
203
- */
204
- export const globalScheduler = createScheduler();