@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.
@@ -1,135 +0,0 @@
1
- /**
2
- * Workflow Scheduler
3
- *
4
- * Handles parallel execution, queuing, and resource management.
5
- */
6
- /**
7
- * Create workflow scheduler
8
- */
9
- export function createScheduler(config = {}) {
10
- const { maxConcurrency = 5, queueLimit = 100, defaultTimeout = 60000, enablePriority = false, } = config;
11
- const queue = [];
12
- const running = new Map();
13
- let isPaused = false;
14
- let completed = 0;
15
- let failed = 0;
16
- /**
17
- * Process queue
18
- */
19
- async function processQueue() {
20
- if (isPaused || running.size >= maxConcurrency || queue.length === 0) {
21
- return;
22
- }
23
- // Sort by priority if enabled
24
- if (enablePriority) {
25
- queue.sort((a, b) => (b.priority || 0) - (a.priority || 0));
26
- }
27
- const task = queue.shift();
28
- if (!task)
29
- return;
30
- const controller = new AbortController();
31
- running.set(task.id, controller);
32
- try {
33
- const timeout = task.timeout || defaultTimeout;
34
- const timeoutId = setTimeout(() => controller.abort(), timeout);
35
- // Execute task
36
- const result = await executeTask(task, controller.signal);
37
- clearTimeout(timeoutId);
38
- completed++;
39
- return;
40
- }
41
- catch (error) {
42
- failed++;
43
- throw error;
44
- }
45
- finally {
46
- running.delete(task.id);
47
- // Process next
48
- processQueue();
49
- }
50
- }
51
- /**
52
- * Execute task
53
- */
54
- async function executeTask(task, signal) {
55
- if (signal.aborted) {
56
- throw new Error('Task cancelled');
57
- }
58
- // Task execution logic here
59
- // This would integrate with the workflow engine
60
- return { taskId: task.id, status: 'completed' };
61
- }
62
- /**
63
- * Submit task
64
- */
65
- async function submit(task) {
66
- if (queue.length >= queueLimit) {
67
- throw new Error('Queue limit reached');
68
- }
69
- queue.push(task);
70
- // Start processing
71
- return processQueue();
72
- }
73
- /**
74
- * Submit multiple tasks
75
- */
76
- async function submitAll(tasks) {
77
- return Promise.all(tasks.map(task => submit(task)));
78
- }
79
- /**
80
- * Cancel task
81
- */
82
- function cancel(taskId) {
83
- // Cancel if running
84
- const controller = running.get(taskId);
85
- if (controller) {
86
- controller.abort();
87
- return true;
88
- }
89
- // Remove from queue
90
- const index = queue.findIndex(t => t.id === taskId);
91
- if (index >= 0) {
92
- queue.splice(index, 1);
93
- return true;
94
- }
95
- return false;
96
- }
97
- /**
98
- * Get status
99
- */
100
- function getStatus() {
101
- return {
102
- running: running.size,
103
- queued: queue.length,
104
- completed,
105
- failed,
106
- isPaused,
107
- };
108
- }
109
- /**
110
- * Pause scheduler
111
- */
112
- function pause() {
113
- isPaused = true;
114
- }
115
- /**
116
- * Resume scheduler
117
- */
118
- function resume() {
119
- isPaused = false;
120
- processQueue();
121
- }
122
- return {
123
- submit,
124
- submitAll,
125
- cancel,
126
- getStatus,
127
- pause,
128
- resume,
129
- };
130
- }
131
- /**
132
- * Global scheduler instance
133
- */
134
- export const globalScheduler = createScheduler();
135
- //# sourceMappingURL=index.js.map
@@ -1,402 +0,0 @@
1
- /**
2
- * A2R Workflow Engine Types
3
- *
4
- * Core type definitions for workflow orchestration.
5
- */
6
- /**
7
- * Workflow Definition
8
- */
9
- export interface Workflow {
10
- /** Workflow ID */
11
- id: string;
12
- /** Workflow name */
13
- name: string;
14
- /** Workflow version */
15
- version: string;
16
- /** Workflow description */
17
- description?: string;
18
- /** Input parameters schema */
19
- inputs?: ParameterSchema[];
20
- /** Output parameters schema */
21
- outputs?: ParameterSchema[];
22
- /** Workflow variables */
23
- variables?: Variable[];
24
- /** Workflow nodes */
25
- nodes: WorkflowNode[];
26
- /** Connections between nodes */
27
- connections: Connection[];
28
- /** Workflow triggers */
29
- triggers?: Trigger[];
30
- /** Error handling strategy */
31
- errorHandling?: ErrorHandlingConfig;
32
- /** Workflow metadata */
33
- metadata?: WorkflowMetadata;
34
- }
35
- /**
36
- * Workflow Node
37
- */
38
- export interface WorkflowNode {
39
- /** Unique node ID */
40
- id: string;
41
- /** Node type */
42
- type: string;
43
- /** Node name */
44
- name: string;
45
- /** Node configuration */
46
- config?: Record<string, unknown>;
47
- /** Input mappings */
48
- inputs?: InputMapping[];
49
- /** Output mappings */
50
- outputs?: OutputMapping[];
51
- /** Node position in visual editor */
52
- position?: Position;
53
- /** Node metadata */
54
- metadata?: NodeMetadata;
55
- }
56
- /**
57
- * Connection between nodes
58
- */
59
- export interface Connection {
60
- /** Connection ID */
61
- id: string;
62
- /** Source node ID */
63
- source: string;
64
- /** Source output port */
65
- sourcePort?: string;
66
- /** Target node ID */
67
- target: string;
68
- /** Target input port */
69
- targetPort?: string;
70
- /** Condition for this connection */
71
- condition?: string;
72
- }
73
- /**
74
- * Parameter Schema
75
- */
76
- export interface ParameterSchema {
77
- /** Parameter name */
78
- name: string;
79
- /** Parameter type */
80
- type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'any';
81
- /** Parameter description */
82
- description?: string;
83
- /** Is required */
84
- required?: boolean;
85
- /** Default value */
86
- default?: unknown;
87
- /** Validation rules */
88
- validation?: ValidationRule[];
89
- }
90
- /**
91
- * Validation Rule
92
- */
93
- export interface ValidationRule {
94
- /** Rule type */
95
- type: 'required' | 'min' | 'max' | 'pattern' | 'enum' | 'custom';
96
- /** Rule value */
97
- value?: unknown;
98
- /** Error message */
99
- message?: string;
100
- }
101
- /**
102
- * Workflow Variable
103
- */
104
- export interface Variable {
105
- /** Variable name */
106
- name: string;
107
- /** Variable type */
108
- type: string;
109
- /** Initial value */
110
- default?: unknown;
111
- /** Is secret */
112
- secret?: boolean;
113
- /** Scope */
114
- scope?: 'workflow' | 'node' | 'global';
115
- }
116
- /**
117
- * Input Mapping
118
- */
119
- export interface InputMapping {
120
- /** Target input name */
121
- target: string;
122
- /** Source expression */
123
- source: string;
124
- /** Transform expression */
125
- transform?: string;
126
- /** Default value if source is empty */
127
- default?: unknown;
128
- }
129
- /**
130
- * Output Mapping
131
- */
132
- export interface OutputMapping {
133
- /** Source output name */
134
- source: string;
135
- /** Target variable or expression */
136
- target: string;
137
- /** Transform expression */
138
- transform?: string;
139
- }
140
- /**
141
- * Workflow Trigger
142
- */
143
- export interface Trigger {
144
- /** Trigger ID */
145
- id: string;
146
- /** Trigger type */
147
- type: 'schedule' | 'webhook' | 'event' | 'manual' | 'api';
148
- /** Trigger configuration */
149
- config?: Record<string, unknown>;
150
- /** Is enabled */
151
- enabled?: boolean;
152
- }
153
- /**
154
- * Error Handling Configuration
155
- */
156
- export interface ErrorHandlingConfig {
157
- /** Default retry count */
158
- retryCount?: number;
159
- /** Default retry delay (ms) */
160
- retryDelay?: number;
161
- /** Error handler node ID */
162
- errorHandler?: string;
163
- /** Continue on error */
164
- continueOnError?: boolean;
165
- /** Max concurrent errors before failing workflow */
166
- maxErrors?: number;
167
- }
168
- /**
169
- * Workflow Metadata
170
- */
171
- export interface WorkflowMetadata {
172
- /** Created timestamp */
173
- createdAt?: string;
174
- /** Updated timestamp */
175
- updatedAt?: string;
176
- /** Author */
177
- author?: string;
178
- /** Tags */
179
- tags?: string[];
180
- /** Category */
181
- category?: string;
182
- }
183
- /**
184
- * Node Metadata
185
- */
186
- export interface NodeMetadata {
187
- /** Node color */
188
- color?: string;
189
- /** Node icon */
190
- icon?: string;
191
- /** Documentation URL */
192
- docs?: string;
193
- }
194
- /**
195
- * Position in visual editor
196
- */
197
- export interface Position {
198
- x: number;
199
- y: number;
200
- }
201
- /**
202
- * Workflow Execution
203
- */
204
- export interface WorkflowExecution {
205
- /** Execution ID */
206
- id: string;
207
- /** Workflow ID */
208
- workflowId: string;
209
- /** Execution status */
210
- status: ExecutionStatus;
211
- /** Input data */
212
- inputs?: Record<string, unknown>;
213
- /** Output data */
214
- outputs?: Record<string, unknown>;
215
- /** Execution context */
216
- context?: ExecutionContext;
217
- /** Node executions */
218
- nodeExecutions?: NodeExecution[];
219
- /** Started timestamp */
220
- startedAt?: string;
221
- /** Completed timestamp */
222
- completedAt?: string;
223
- /** Error information */
224
- error?: ExecutionError;
225
- }
226
- /**
227
- * Execution Status
228
- */
229
- export type ExecutionStatus = 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled' | 'timeout';
230
- /**
231
- * Execution Context
232
- */
233
- export interface ExecutionContext {
234
- /** Workflow variables */
235
- variables: Record<string, unknown>;
236
- /** Execution state */
237
- state: ExecutionState;
238
- /** Parent execution ID (for sub-workflows) */
239
- parentExecutionId?: string;
240
- /** Trigger information */
241
- trigger?: TriggerInfo;
242
- /** User/agent context */
243
- userContext?: UserContext;
244
- }
245
- /**
246
- * Execution State
247
- */
248
- export interface ExecutionState {
249
- /** Currently executing nodes */
250
- activeNodes: string[];
251
- /** Completed nodes */
252
- completedNodes: string[];
253
- /** Failed nodes */
254
- failedNodes: string[];
255
- /** Node results */
256
- nodeResults: Record<string, unknown>;
257
- /** Execution path taken */
258
- executionPath: string[];
259
- }
260
- /**
261
- * Node Execution
262
- */
263
- export interface NodeExecution {
264
- /** Node ID */
265
- nodeId: string;
266
- /** Execution status */
267
- status: ExecutionStatus;
268
- /** Input data */
269
- inputs?: Record<string, unknown>;
270
- /** Output data */
271
- outputs?: Record<string, unknown>;
272
- /** Started timestamp */
273
- startedAt?: string;
274
- /** Completed timestamp */
275
- completedAt?: string;
276
- /** Retry count */
277
- retryCount?: number;
278
- /** Error information */
279
- error?: ExecutionError;
280
- }
281
- /**
282
- * Execution Error
283
- */
284
- export interface ExecutionError {
285
- /** Error code */
286
- code: string;
287
- /** Error message */
288
- message: string;
289
- /** Error details */
290
- details?: unknown;
291
- /** Stack trace */
292
- stack?: string;
293
- /** Node ID where error occurred */
294
- nodeId?: string;
295
- }
296
- /**
297
- * Trigger Information
298
- */
299
- export interface TriggerInfo {
300
- /** Trigger type */
301
- type: string;
302
- /** Trigger ID */
303
- triggerId: string;
304
- /** Trigger data */
305
- data?: unknown;
306
- /** Timestamp */
307
- timestamp: string;
308
- }
309
- /**
310
- * User Context
311
- */
312
- export interface UserContext {
313
- /** User ID */
314
- userId?: string;
315
- /** Organization ID */
316
- orgId?: string;
317
- /** Roles */
318
- roles?: string[];
319
- /** Permissions */
320
- permissions?: string[];
321
- }
322
- /**
323
- * Node Type Definition
324
- */
325
- export interface NodeType {
326
- /** Node type ID */
327
- type: string;
328
- /** Node category */
329
- category: NodeCategory;
330
- /** Display name */
331
- displayName: string;
332
- /** Description */
333
- description?: string;
334
- /** Input ports */
335
- inputs?: PortDefinition[];
336
- /** Output ports */
337
- outputs?: PortDefinition[];
338
- /** Configuration schema */
339
- configSchema?: ParameterSchema[];
340
- /** Default configuration */
341
- defaultConfig?: Record<string, unknown>;
342
- /** Node executor */
343
- executor?: NodeExecutor;
344
- /** Icon */
345
- icon?: string;
346
- /** Color */
347
- color?: string;
348
- }
349
- /**
350
- * Node Category
351
- */
352
- export type NodeCategory = 'input' | 'output' | 'transform' | 'condition' | 'loop' | 'delay' | 'http' | 'database' | 'ai' | 'custom';
353
- /**
354
- * Port Definition
355
- */
356
- export interface PortDefinition {
357
- /** Port name */
358
- name: string;
359
- /** Port type */
360
- type: string;
361
- /** Is required */
362
- required?: boolean;
363
- /** Description */
364
- description?: string;
365
- }
366
- /**
367
- * Node Executor Function
368
- */
369
- export type NodeExecutor = (node: WorkflowNode, context: ExecutionContext, inputs: Record<string, unknown>) => Promise<Record<string, unknown>>;
370
- /**
371
- * Workflow Engine Configuration
372
- */
373
- export interface WorkflowEngineConfig {
374
- /** Max concurrent executions */
375
- maxConcurrentExecutions?: number;
376
- /** Default execution timeout (ms) */
377
- defaultTimeout?: number;
378
- /** Enable execution history */
379
- enableHistory?: boolean;
380
- /** History retention (days) */
381
- historyRetentionDays?: number;
382
- /** Custom node types */
383
- nodeTypes?: NodeType[];
384
- /** Hooks */
385
- hooks?: WorkflowHooks;
386
- }
387
- /**
388
- * Workflow Hooks
389
- */
390
- export interface WorkflowHooks {
391
- /** Before workflow execution */
392
- beforeExecute?: (execution: WorkflowExecution) => Promise<void>;
393
- /** After workflow execution */
394
- afterExecute?: (execution: WorkflowExecution) => Promise<void>;
395
- /** Before node execution */
396
- beforeNodeExecute?: (node: WorkflowNode, context: ExecutionContext) => Promise<void>;
397
- /** After node execution */
398
- afterNodeExecute?: (node: WorkflowNode, context: ExecutionContext, result: unknown) => Promise<void>;
399
- /** On error */
400
- onError?: (error: ExecutionError, context: ExecutionContext) => Promise<void>;
401
- }
402
- //# sourceMappingURL=types.d.ts.map
package/dist/types.js.bak DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * A2R Workflow Engine Types
3
- *
4
- * Core type definitions for workflow orchestration.
5
- */
6
- export {};
7
- //# sourceMappingURL=types.js.map
@@ -1,81 +0,0 @@
1
- /**
2
- * Workflow Visualizer
3
- *
4
- * Generates visual representations of workflows.
5
- */
6
- import type { Workflow, WorkflowNode, Connection, Position } from '../types';
7
- export interface VisualizerConfig {
8
- /** Canvas width */
9
- width?: number;
10
- /** Canvas height */
11
- height?: number;
12
- /** Node width */
13
- nodeWidth?: number;
14
- /** Node height */
15
- nodeHeight?: number;
16
- /** Horizontal spacing */
17
- hSpacing?: number;
18
- /** Vertical spacing */
19
- vSpacing?: number;
20
- /** Enable auto-layout */
21
- autoLayout?: boolean;
22
- }
23
- export interface VisualLayout {
24
- nodes: VisualNode[];
25
- connections: VisualConnection[];
26
- bounds: Bounds;
27
- }
28
- export interface VisualNode {
29
- id: string;
30
- x: number;
31
- y: number;
32
- width: number;
33
- height: number;
34
- color?: string;
35
- icon?: string;
36
- label: string;
37
- status?: 'pending' | 'running' | 'completed' | 'failed';
38
- }
39
- export interface VisualConnection {
40
- id: string;
41
- source: {
42
- x: number;
43
- y: number;
44
- };
45
- target: {
46
- x: number;
47
- y: number;
48
- };
49
- path: string;
50
- color?: string;
51
- animated?: boolean;
52
- }
53
- export interface Bounds {
54
- minX: number;
55
- minY: number;
56
- maxX: number;
57
- maxY: number;
58
- width: number;
59
- height: number;
60
- }
61
- export interface WorkflowVisualizer {
62
- /** Generate visual layout */
63
- layout(workflow: Workflow): VisualLayout;
64
- /** Auto-layout nodes */
65
- autoLayout(nodes: WorkflowNode[], connections: Connection[]): Record<string, Position>;
66
- /** Export to SVG */
67
- toSVG(workflow: Workflow): string;
68
- /** Export to Mermaid diagram */
69
- toMermaid(workflow: Workflow): string;
70
- /** Export to DOT (Graphviz) */
71
- toDOT(workflow: Workflow): string;
72
- }
73
- /**
74
- * Create workflow visualizer
75
- */
76
- export declare function createVisualizer(config?: VisualizerConfig): WorkflowVisualizer;
77
- /**
78
- * Global visualizer instance
79
- */
80
- export declare const globalVisualizer: WorkflowVisualizer;
81
- //# sourceMappingURL=index.d.ts.map