@ronaldroe/micro-flow 1.0.0 → 1.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 +63 -153
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/src/classes/base.js +4 -0
- package/dist/src/classes/base.js.map +7 -0
- package/dist/src/classes/events/broadcast.js +2 -0
- package/dist/src/classes/events/broadcast.js.map +7 -0
- package/dist/src/classes/events/event.js +2 -0
- package/dist/src/classes/events/event.js.map +7 -0
- package/dist/src/classes/events/index.js +2 -0
- package/dist/src/classes/events/index.js.map +7 -0
- package/dist/src/classes/events/state_event.js +2 -0
- package/dist/src/classes/events/state_event.js.map +7 -0
- package/dist/src/classes/events/step_event.js +2 -0
- package/dist/src/classes/events/step_event.js.map +7 -0
- package/dist/src/classes/events/workflow_event.js +2 -0
- package/dist/src/classes/events/workflow_event.js.map +7 -0
- package/dist/src/classes/index.js +2 -0
- package/dist/src/classes/index.js.map +7 -0
- package/dist/src/classes/state.js +2 -0
- package/dist/src/classes/state.js.map +7 -0
- package/dist/src/classes/steps/case.js +2 -0
- package/dist/src/classes/steps/case.js.map +7 -0
- package/dist/src/classes/steps/conditional_step.js +2 -0
- package/dist/src/classes/steps/conditional_step.js.map +7 -0
- package/dist/src/classes/steps/delay_step.js +2 -0
- package/dist/src/classes/steps/delay_step.js.map +7 -0
- package/dist/src/classes/steps/flow_control_step.js +2 -0
- package/dist/src/classes/steps/flow_control_step.js.map +7 -0
- package/dist/src/classes/steps/index.js +2 -0
- package/dist/src/classes/steps/index.js.map +7 -0
- package/dist/src/classes/steps/logic_step.js +2 -0
- package/dist/src/classes/steps/logic_step.js.map +7 -0
- package/dist/src/classes/steps/loop_step.js +2 -0
- package/dist/src/classes/steps/loop_step.js.map +7 -0
- package/dist/src/classes/steps/step.js +2 -0
- package/dist/src/classes/steps/step.js.map +7 -0
- package/dist/src/classes/steps/switch_step.js +2 -0
- package/dist/src/classes/steps/switch_step.js.map +7 -0
- package/dist/src/classes/workflow.js +2 -0
- package/dist/src/classes/workflow.js.map +7 -0
- package/dist/src/classes/workflow.test.js +2 -0
- package/dist/src/classes/workflow.test.js.map +7 -0
- package/dist/src/enums/base_types.js +2 -0
- package/dist/src/enums/base_types.js.map +7 -0
- package/dist/src/enums/conditional_step_comparators.js +2 -0
- package/dist/src/enums/conditional_step_comparators.js.map +7 -0
- package/dist/src/enums/delay_types.js +2 -0
- package/dist/src/enums/delay_types.js.map +7 -0
- package/dist/src/enums/errors.js +6 -0
- package/dist/src/enums/errors.js.map +7 -0
- package/dist/src/enums/flow_control_types.js +2 -0
- package/dist/src/enums/flow_control_types.js.map +7 -0
- package/dist/src/enums/index.js +2 -0
- package/dist/src/enums/index.js.map +7 -0
- package/dist/src/enums/logic_step_types.js +2 -0
- package/dist/src/enums/logic_step_types.js.map +7 -0
- package/dist/src/enums/loop_types.js +2 -0
- package/dist/src/enums/loop_types.js.map +7 -0
- package/dist/src/enums/state_event_names.js +2 -0
- package/dist/src/enums/state_event_names.js.map +7 -0
- package/dist/src/enums/step_event_names.js +2 -0
- package/dist/src/enums/step_event_names.js.map +7 -0
- package/dist/src/enums/step_statuses.js +2 -0
- package/dist/src/enums/step_statuses.js.map +7 -0
- package/dist/src/enums/step_types.js +2 -0
- package/dist/src/enums/step_types.js.map +7 -0
- package/dist/src/enums/sub_step_types.js +2 -0
- package/dist/src/enums/sub_step_types.js.map +7 -0
- package/dist/src/enums/workflow_event_names.js +2 -0
- package/dist/src/enums/workflow_event_names.js.map +7 -0
- package/dist/src/enums/workflow_statuses.js +2 -0
- package/dist/src/enums/workflow_statuses.js.map +7 -0
- package/package.json +10 -6
- package/src/classes/base.js +4 -5
- package/src/classes/events/event.js +16 -9
- package/src/classes/events/index.js +1 -1
- package/src/classes/events/state_event.js +28 -0
- package/src/classes/state.js +161 -54
- package/src/classes/steps/case.js +70 -0
- package/src/classes/steps/conditional_step.js +20 -7
- package/src/classes/steps/delay_step.js +103 -0
- package/src/classes/steps/flow_control_step.js +8 -7
- package/src/classes/steps/index.js +4 -0
- package/src/classes/steps/logic_step.js +89 -29
- package/src/classes/steps/loop_step.js +148 -0
- package/src/classes/steps/step.js +59 -18
- package/src/classes/steps/switch_step.js +77 -0
- package/src/classes/workflow.js +74 -26
- package/src/enums/conditional_step_comparators.js +38 -8
- package/src/enums/delay_types.js +0 -7
- package/src/enums/errors.js +2 -0
- package/src/enums/index.js +1 -0
- package/src/enums/loop_types.js +3 -1
- package/src/enums/state_event_names.js +17 -0
- package/src/enums/step_event_names.js +3 -0
- package/src/enums/step_types.js +2 -1
- package/src/enums/sub_step_types.js +15 -125
- package/src/enums/workflow_event_names.js +1 -0
- package/index.js +0 -1
- package/src/classes/events/broadcast.js +0 -57
package/README.md
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
# Micro-Flow
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Micro-Flow is a simple, lightweight, cross platform (browser and runtime) logic orchestration library. Micro-Flow makes async logic flows first-class objects — named, observable, pauseable, and composable — so a multi-step process is something you can reason about, monitor, and control, not just a wall of awaits.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- 🌿 **
|
|
10
|
-
- 🎯 **Flow Control** - Break
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
- ⚡ **Minimal Dependencies** - Lightweight and
|
|
16
|
-
- 🎨 **Framework Friendly** - Integrates seamlessly with React, Vue, your favorite framework and vanilla JS
|
|
7
|
+
- �️ **Observable** - Every step and logic flow emits lifecycle events (`STEP_FAILED`, `WORKFLOW_COMPLETE`, etc.) so you always know what's running, what finished, and what broke — no log-sprinkling required
|
|
8
|
+
- ⏸️ **Pauseable & Resumeable** - Suspend a running logic flow mid-pipeline (e.g. waiting on user input or an external signal) and resume it without losing state
|
|
9
|
+
- 🌿 **First-Class Branching** - `ConditionalStep` and `SwitchStep` keep branching logic out of your callables and in the logic flow structure where it belongs
|
|
10
|
+
- 🎯 **Fine-Grained Flow Control** - Break out of or skip steps in a logic flow dynamically at runtime
|
|
11
|
+
- 💾 **Shared State Singleton** - Steps communicate through a global `State` object with dot/bracket-notation path access — no threading data through function arguments
|
|
12
|
+
- 📢 **Cross-Tab/Worker Communication** - Events broadcast automatically via `BroadcastChannel`, reaching other tabs and workers with no extra wiring
|
|
13
|
+
- 🌐 **Universal** - Works in Node.js (≥18) and all modern browsers
|
|
14
|
+
- 🎨 **Framework Friendly** - Integrates seamlessly with React, Vue, your favorite framework, and vanilla JS
|
|
15
|
+
- ⚡ **Minimal Dependencies** - Lightweight and focused
|
|
17
16
|
|
|
18
17
|
## Installation
|
|
19
18
|
|
|
@@ -220,7 +219,7 @@ const workflow = new Workflow({
|
|
|
220
219
|
|
|
221
220
|
### Steps
|
|
222
221
|
|
|
223
|
-
Steps are individual units of work that execute functions, other steps, or even entire workflows
|
|
222
|
+
Steps are individual units of work that execute functions, other steps, or even entire workflows. Steps have retry and timeout mechanisms.
|
|
224
223
|
|
|
225
224
|
```javascript
|
|
226
225
|
import { Step } from 'micro-flow';
|
|
@@ -234,103 +233,11 @@ const step = new Step({
|
|
|
234
233
|
});
|
|
235
234
|
```
|
|
236
235
|
|
|
237
|
-
###
|
|
236
|
+
### Callables
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
Most step types accept a `callable` parameter. Callables are the individual actions a step can take.
|
|
240
239
|
|
|
241
|
-
|
|
242
|
-
import { ConditionalStep } from 'micro-flow';
|
|
243
|
-
|
|
244
|
-
const conditionalStep = new ConditionalStep({
|
|
245
|
-
name: 'environment-check',
|
|
246
|
-
conditional: {
|
|
247
|
-
subject: process.env.NODE_ENV,
|
|
248
|
-
operator: '===',
|
|
249
|
-
value: 'production'
|
|
250
|
-
},
|
|
251
|
-
true_callable: async () => {
|
|
252
|
-
return loadProductionConfig();
|
|
253
|
-
},
|
|
254
|
-
false_callable: async () => {
|
|
255
|
-
return loadDevelopmentConfig();
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
### Loop Steps
|
|
261
|
-
|
|
262
|
-
Iterate over collections or repeat while conditions are met:
|
|
263
|
-
|
|
264
|
-
```javascript
|
|
265
|
-
import { LoopStep, loop_types } from 'micro-flow';
|
|
266
|
-
|
|
267
|
-
// For-each loop
|
|
268
|
-
const forEachLoop = new LoopStep({
|
|
269
|
-
name: 'process-items',
|
|
270
|
-
loop_type: loop_types.FOR_EACH,
|
|
271
|
-
items: [1, 2, 3, 4, 5],
|
|
272
|
-
callable: async (item) => {
|
|
273
|
-
console.log('Processing:', item);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// While loop
|
|
278
|
-
const whileLoop = new LoopStep({
|
|
279
|
-
name: 'retry-until-success',
|
|
280
|
-
loop_type: loop_types.WHILE,
|
|
281
|
-
condition: () => retryCount < maxRetries,
|
|
282
|
-
callable: async () => {
|
|
283
|
-
await attemptOperation();
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
### Delay Steps
|
|
289
|
-
|
|
290
|
-
Delay workflow execution with various timing strategies:
|
|
291
|
-
|
|
292
|
-
```javascript
|
|
293
|
-
import { DelayStep, delay_types } from 'micro-flow';
|
|
294
|
-
|
|
295
|
-
// Relative delay (milliseconds)
|
|
296
|
-
const relativeDelay = new DelayStep({
|
|
297
|
-
name: 'wait-5-seconds',
|
|
298
|
-
delay_type: delay_types.RELATIVE,
|
|
299
|
-
delay_duration: 5000
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// Absolute delay (specific time)
|
|
303
|
-
const absoluteDelay = new DelayStep({
|
|
304
|
-
name: 'wait-until-midnight',
|
|
305
|
-
delay_type: delay_types.ABSOLUTE,
|
|
306
|
-
delay_timestamp: new Date('2025-12-31T23:59:59')
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Cron-based delay (scheduled)
|
|
310
|
-
const cronDelay = new DelayStep({
|
|
311
|
-
name: 'daily-task',
|
|
312
|
-
delay_type: delay_types.CRON,
|
|
313
|
-
cron_expression: '0 9 * * *' // Every day at 9 AM
|
|
314
|
-
});
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### Flow Control
|
|
318
|
-
|
|
319
|
-
Control workflow execution with break and skip logic:
|
|
320
|
-
|
|
321
|
-
```javascript
|
|
322
|
-
import { FlowControlStep, flow_control_types } from 'micro-flow';
|
|
323
|
-
|
|
324
|
-
const breakStep = new FlowControlStep({
|
|
325
|
-
name: 'error-check',
|
|
326
|
-
conditional: {
|
|
327
|
-
subject: errorCount,
|
|
328
|
-
operator: '>',
|
|
329
|
-
value: 0
|
|
330
|
-
},
|
|
331
|
-
flow_control_type: flow_control_types.BREAK
|
|
332
|
-
});
|
|
333
|
-
```
|
|
240
|
+
A callable can be any async function, another step, or even a whole workflow. That flexibility allows for everything from very simple logic flows to large, modularized flows broken down into logical units for execution.
|
|
334
241
|
|
|
335
242
|
### State Management
|
|
336
243
|
|
|
@@ -349,11 +256,26 @@ const timeout = State.get('config.timeout', 3000); // with default
|
|
|
349
256
|
|
|
350
257
|
// Delete values
|
|
351
258
|
State.delete('user.name');
|
|
259
|
+
|
|
260
|
+
// Merge objects into state
|
|
261
|
+
State.merge({ settings: { theme: 'dark', lang: 'en' } });
|
|
262
|
+
|
|
263
|
+
// Iterate over collections
|
|
264
|
+
State.set('users', [{ name: 'Alice' }, { name: 'Bob' }]);
|
|
265
|
+
State.each('users', (user, index) => {
|
|
266
|
+
console.log(`User ${index}: ${user.name}`);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Freeze state (make immutable)
|
|
270
|
+
State.freeze();
|
|
271
|
+
|
|
272
|
+
// Reset state to defaults
|
|
273
|
+
State.reset();
|
|
352
274
|
```
|
|
353
275
|
|
|
354
276
|
### Events
|
|
355
277
|
|
|
356
|
-
Listen to workflow and
|
|
278
|
+
Listen to workflow, step, and state lifecycle events. You can do this using Node's EventEmitter syntax or the browser's CustomEvent syntax. Both work in any environment:
|
|
357
279
|
|
|
358
280
|
```javascript
|
|
359
281
|
import { State } from 'micro-flow';
|
|
@@ -369,30 +291,38 @@ const stepEvents = State.get('events.step');
|
|
|
369
291
|
stepEvents.on('step_failed', (data) => {
|
|
370
292
|
console.error(`Step ${data.name} failed:`, data.errors);
|
|
371
293
|
});
|
|
294
|
+
|
|
295
|
+
const stateEvents = State.get('events.state');
|
|
296
|
+
|
|
297
|
+
stateEvents.on('set', (data) => {
|
|
298
|
+
console.log('State modified:', data.state);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
stateEvents.on('deleted', (data) => {
|
|
302
|
+
console.log('State property deleted');
|
|
303
|
+
});
|
|
372
304
|
```
|
|
373
305
|
|
|
374
306
|
### Cross-Tab/Worker Communication
|
|
375
307
|
|
|
376
|
-
|
|
308
|
+
Events broadcast automatically between browser tabs and windows or across workers when emitted, with no extra wiring needed:
|
|
377
309
|
|
|
378
310
|
```javascript
|
|
379
|
-
import {
|
|
311
|
+
import { State } from './micro-flow.js';
|
|
380
312
|
|
|
381
|
-
|
|
313
|
+
// All events broadcast automatically via BroadcastChannel
|
|
314
|
+
const event = State.get('events.workflow');
|
|
382
315
|
|
|
383
|
-
// Send
|
|
384
|
-
|
|
316
|
+
// Send event to other tabs
|
|
317
|
+
event.emit('my-event', { type: 'update', data: { userId: 123 } });
|
|
385
318
|
|
|
386
|
-
// Receive
|
|
387
|
-
|
|
319
|
+
// Receive events from other tabs
|
|
320
|
+
event.on('my-event', (data) => {
|
|
388
321
|
console.log('Message from another tab:', data);
|
|
389
322
|
if (data.type === 'update') {
|
|
390
323
|
updateUI(data.data);
|
|
391
324
|
}
|
|
392
325
|
});
|
|
393
|
-
|
|
394
|
-
// Clean up when done
|
|
395
|
-
broadcast.destroy();
|
|
396
326
|
```
|
|
397
327
|
|
|
398
328
|
## Use Cases
|
|
@@ -532,50 +462,30 @@ Full documentation is available in the [docs](docs/) directory:
|
|
|
532
462
|
- [LogicStep API](docs/classes/steps/logic_step.md)
|
|
533
463
|
- [ConditionalStep API](docs/classes/steps/conditional_step.md)
|
|
534
464
|
- [FlowControlStep API](docs/classes/steps/flow_control_step.md)
|
|
465
|
+
- [CaseStep API](docs/classes/steps/case.md)
|
|
466
|
+
- [SwitchStep API](docs/classes/steps/switch_step.md)
|
|
467
|
+
- [LoopStep API](docs/classes/steps/loop_step.md)
|
|
468
|
+
- [DelayStep API](docs/classes/steps/delay_step.md)
|
|
535
469
|
|
|
536
470
|
**Events:**
|
|
537
471
|
- [Event System](docs/classes/events/event.md)
|
|
538
472
|
- [WorkflowEvent API](docs/classes/events/workflow_event.md)
|
|
539
473
|
- [StepEvent API](docs/classes/events/step_event.md)
|
|
540
|
-
- [
|
|
474
|
+
- [StateEvent API](docs/classes/events/state_event.md)
|
|
475
|
+
|
|
541
476
|
|
|
542
477
|
**Enumerations:**
|
|
478
|
+
- [Base Types](docs/enums/base_types.md)
|
|
543
479
|
- [Step Types](docs/enums/step_types.md)
|
|
480
|
+
- [Sub Step Types](docs/enums/sub_step_types.md)
|
|
481
|
+
- [Logic Step Types](docs/enums/logic_step_types.md)
|
|
482
|
+
- [Conditional Step Comparators](docs/enums/conditional_step_comparators.md)
|
|
483
|
+
- [Flow Control Types](docs/enums/flow_control_types.md)
|
|
544
484
|
- [Step Statuses](docs/enums/step_statuses.md)
|
|
545
485
|
- [Workflow Statuses](docs/enums/workflow_statuses.md)
|
|
486
|
+
- [Step Event Names](docs/enums/step_event_names.md)
|
|
487
|
+
- [Workflow Event Names](docs/enums/workflow_event_names.md)
|
|
488
|
+
- [State Event Names](docs/enums/state_event_names.md)
|
|
546
489
|
- [Delay Types](docs/enums/delay_types.md)
|
|
547
490
|
- [Loop Types](docs/enums/loop_types.md)
|
|
548
|
-
|
|
549
|
-
## Browser Compatibility
|
|
550
|
-
|
|
551
|
-
Micro-flow works in all modern browsers that support:
|
|
552
|
-
- ES6 Modules
|
|
553
|
-
- Async/await
|
|
554
|
-
- CustomEvent API
|
|
555
|
-
- EventTarget API
|
|
556
|
-
|
|
557
|
-
Supported browsers:
|
|
558
|
-
- Chrome/Edge 63+
|
|
559
|
-
- Firefox 60+
|
|
560
|
-
- Safari 11.1+
|
|
561
|
-
- Opera 50+
|
|
562
|
-
|
|
563
|
-
## Node.js Compatibility
|
|
564
|
-
|
|
565
|
-
Requires Node.js 14+ for full ES6 module support.
|
|
566
|
-
|
|
567
|
-
## Contributing
|
|
568
|
-
|
|
569
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
570
|
-
|
|
571
|
-
## Why Micro-Flow?
|
|
572
|
-
|
|
573
|
-
Micro-flow is designed to be:
|
|
574
|
-
|
|
575
|
-
- **Lightweight** - Small footprint, zero dependencies
|
|
576
|
-
- **Simple** - Easy to learn and use
|
|
577
|
-
- **Flexible** - Works in Node.js and browsers
|
|
578
|
-
- **Powerful** - Handles complex workflows with ease
|
|
579
|
-
- **Type-Safe Ready** - Can be extended with TypeScript definitions
|
|
580
|
-
|
|
581
|
-
Perfect for projects that need workflow orchestration without the complexity of enterprise solutions.
|
|
491
|
+
- [Errors and Warnings](docs/enums/errors.md)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var h=Object.defineProperty;var a=(i,t)=>h(i,"name",{value:t,configurable:!0});import p from"crypto";import{base_types as o}from"../enums/index.js";import e from"./state.js";class r{static{a(this,"Base")}constructor({name:t,base_type:s=o.STEP}){this.id=p.randomUUID(),this.name=t??`${s}-${this.id}`,this.base_type=s,this.timing={cancel_time:null,complete_time:null,execution_time_ms:null,start_time:null}}async execute(){throw new Error("Execute method not implemented")}log(t,s=null){if(!t||!e.get(`events.${this.base_type}`))throw new Error("Invalid event name or event emitter not found");if(e.get(`events.${this.base_type}`).emit(t,this),e.get("log_suppress"))return;const n=s?`
|
|
2
|
+
[${this.base_type.toUpperCase()} - ${this.name}] ${s}`:`
|
|
3
|
+
[${this.base_type.toUpperCase()} - ${this.name}] Event: ${t}`,m=t.endsWith("_failed")?"error":"log";console[m](n)}markAsComplete(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].COMPLETE,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.steps_by_id&&delete this.steps_by_id,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" complete.`)}markAsFailed(){this.timing.complete_time=new Date,this.status=e.get("statuses")[this.base_type].FAILED,this.timing.execution_time_ms=this.timing.complete_time-this.timing.start_time,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" failed.`)}markAsWaiting(){}markAsPending(){}markAsRunning(){this.timing.start_time=this.timing.start_time??new Date,this.status=e.get("statuses")[this.base_type].RUNNING,this.log(e.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],`${this.base_type.charAt(0).toUpperCase()+this.base_type.slice(1)} "${this.name}" started.`)}getState(t){return e.get(t)}setState(t,s){e.set(t,s)}deleteState(t){e.delete(t)}}export{r as default};
|
|
4
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/classes/base.js"],
|
|
4
|
+
"sourcesContent": ["import crypto from 'crypto';\nimport { base_types } from '../enums/index.js';\nimport State from './state.js';\n\n/**\n * Base class for workflows and steps.\n * Provides common functionality for timing, status management, logging, and state access.\n * @class Base\n */\nexport default class Base {\n /**\n * Creates a new Base instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the instance.\n * @param {string} [options.base_type=base_types.STEP] - Type of the base instance.\n */\n constructor({ name, base_type = base_types.STEP }) {\n this.id = crypto.randomUUID();\n this.name = name ?? `${base_type}-${this.id}`;\n\n this.base_type = base_type;\n this.timing = {\n cancel_time: null,\n complete_time: null,\n execution_time_ms: null,\n start_time: null,\n }\n }\n\n /**\n * Executes the instance. Must be overridden by subclasses.\n * @async\n * @throws {Error} Throws if not implemented in subclass.\n */\n async execute() {\n throw new Error('Execute method not implemented');\n }\n\n /**\n * Logs an event and emits it to the appropriate event emitter.\n * @param {string} event_name - Name of the event to log.\n * @param {string} [message=null] - Optional message to log.\n * @throws {Error} Throws if event name is invalid or event emitter not found.\n */\n log(event_name, message = null) {\n if (!event_name || !State.get(`events.${this.base_type}`)) {\n throw new Error('Invalid event name or event emitter not found');\n }\n\n State.get(`events.${this.base_type}`).emit(event_name, this);\n if (State.get('log_suppress')) {\n return;\n }\n\n const logMessage = message ? `\\n[${this.base_type.toUpperCase()} - ${this.name}] ${message}` : `\\n[${this.base_type.toUpperCase()} - ${this.name}] Event: ${event_name}`;\n const logType = event_name.endsWith('_failed') ? 'error' : 'log';\n\n console[logType](logMessage);\n }\n\n /**\n * Marks the instance as complete and calculates execution time.\n */\n markAsComplete() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].COMPLETE;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n if (this.steps_by_id) {\n delete this.steps_by_id;\n }\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_COMPLETE`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" complete.`\n );\n }\n\n /**\n * Marks the instance as failed and calculates execution time.\n */\n markAsFailed() {\n this.timing.complete_time = new Date();\n this.status = State.get('statuses')[this.base_type].FAILED;\n this.timing.execution_time_ms = this.timing.complete_time - this.timing.start_time;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_FAILED`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" failed.`\n );\n }\n\n /**\n * Marks the instance as waiting. To be implemented by subclasses.\n */\n markAsWaiting() { }\n\n /**\n * Marks the instance as pending. To be implemented by subclasses.\n */\n markAsPending() { }\n\n /**\n * Marks the instance as running and sets the start time.\n */\n markAsRunning() {\n this.timing.start_time = this.timing.start_time ?? new Date();\n this.status = State.get('statuses')[this.base_type].RUNNING;\n\n this.log(\n State.get(`event_names.${this.base_type}`)[`${this.base_type.toUpperCase()}_RUNNING`],\n `${this.base_type.charAt(0).toUpperCase() + this.base_type.slice(1)} \"${this.name}\" started.`\n );\n }\n\n // State management methods\n /**\n * Gets a value from the global state.\n * @param {string} path - Path to the state property.\n * @returns {*} The state value at the specified path.\n */\n getState(path) {\n return State.get(path);\n }\n\n /**\n * Sets a value in the global state.\n * @param {string} path - Path to the state property.\n * @param {*} value - Value to set.\n */\n setState(path, value) {\n State.set(path, value);\n }\n\n /**\n * Deletes a property from the global state.\n * @param {string} path - Path to the state property to delete.\n */\n deleteState(path) {\n State.delete(path);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAY,SACnB,OAAS,cAAAC,MAAkB,oBAC3B,OAAOC,MAAW,aAOlB,MAAOC,CAAmB,CAT1B,MAS0B,CAAAC,EAAA,aAOxB,YAAY,CAAE,KAAAC,EAAM,UAAAC,EAAYL,EAAW,IAAK,EAAG,CACjD,KAAK,GAAKD,EAAO,WAAW,EAC5B,KAAK,KAAOK,GAAQ,GAAGC,CAAS,IAAI,KAAK,EAAE,GAE3C,KAAK,UAAYA,EACjB,KAAK,OAAS,CACZ,YAAa,KACb,cAAe,KACf,kBAAmB,KACnB,WAAY,IACd,CACF,CAOA,MAAM,SAAU,CACd,MAAM,IAAI,MAAM,gCAAgC,CAClD,CAQA,IAAIC,EAAYC,EAAU,KAAM,CAC9B,GAAI,CAACD,GAAc,CAACL,EAAM,IAAI,UAAU,KAAK,SAAS,EAAE,EACtD,MAAM,IAAI,MAAM,+CAA+C,EAIjE,GADAA,EAAM,IAAI,UAAU,KAAK,SAAS,EAAE,EAAE,KAAKK,EAAY,IAAI,EACvDL,EAAM,IAAI,cAAc,EAC1B,OAGF,MAAMO,EAAaD,EAAU;AAAA,GAAM,KAAK,UAAU,YAAY,CAAC,MAAM,KAAK,IAAI,KAAKA,CAAO,GAAK;AAAA,GAAM,KAAK,UAAU,YAAY,CAAC,MAAM,KAAK,IAAI,YAAYD,CAAU,GAChKG,EAAUH,EAAW,SAAS,SAAS,EAAI,QAAU,MAE3D,QAAQG,CAAO,EAAED,CAAU,CAC7B,CAKA,gBAAiB,CACf,KAAK,OAAO,cAAgB,IAAI,KAChC,KAAK,OAASP,EAAM,IAAI,UAAU,EAAE,KAAK,SAAS,EAAE,SACpD,KAAK,OAAO,kBAAoB,KAAK,OAAO,cAAgB,KAAK,OAAO,WAEpE,KAAK,aACP,OAAO,KAAK,YAGd,KAAK,IACHA,EAAM,IAAI,eAAe,KAAK,SAAS,EAAE,EAAE,GAAG,KAAK,UAAU,YAAY,CAAC,WAAW,EACrF,GAAG,KAAK,UAAU,OAAO,CAAC,EAAE,YAAY,EAAI,KAAK,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,IAAI,aACnF,CACF,CAKA,cAAe,CACb,KAAK,OAAO,cAAgB,IAAI,KAChC,KAAK,OAASA,EAAM,IAAI,UAAU,EAAE,KAAK,SAAS,EAAE,OACpD,KAAK,OAAO,kBAAoB,KAAK,OAAO,cAAgB,KAAK,OAAO,WAExE,KAAK,IACHA,EAAM,IAAI,eAAe,KAAK,SAAS,EAAE,EAAE,GAAG,KAAK,UAAU,YAAY,CAAC,SAAS,EACnF,GAAG,KAAK,UAAU,OAAO,CAAC,EAAE,YAAY,EAAI,KAAK,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,IAAI,WACnF,CACF,CAKA,eAAgB,CAAE,CAKlB,eAAgB,CAAE,CAKlB,eAAgB,CACd,KAAK,OAAO,WAAa,KAAK,OAAO,YAAc,IAAI,KACvD,KAAK,OAASA,EAAM,IAAI,UAAU,EAAE,KAAK,SAAS,EAAE,QAEpD,KAAK,IACHA,EAAM,IAAI,eAAe,KAAK,SAAS,EAAE,EAAE,GAAG,KAAK,UAAU,YAAY,CAAC,UAAU,EACpF,GAAG,KAAK,UAAU,OAAO,CAAC,EAAE,YAAY,EAAI,KAAK,UAAU,MAAM,CAAC,CAAC,KAAK,KAAK,IAAI,YACnF,CACF,CAQA,SAASS,EAAM,CACb,OAAOT,EAAM,IAAIS,CAAI,CACvB,CAOA,SAASA,EAAMC,EAAO,CACpBV,EAAM,IAAIS,EAAMC,CAAK,CACvB,CAMA,YAAYD,EAAM,CAChBT,EAAM,OAAOS,CAAI,CACnB,CACF",
|
|
6
|
+
"names": ["crypto", "base_types", "State", "Base", "__name", "name", "base_type", "event_name", "message", "logMessage", "logType", "path", "value"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.defineProperty;var t=(e,s)=>o(e,"name",{value:s,configurable:!0});class c extends BroadcastChannel{static{t(this,"Broadcast")}constructor(s){super(s)}send(s){this.postMessage(s)}onReceive(s){this.onmessage=a=>{s(a.data)}}destroy(){this.close()}}export{c as default};
|
|
2
|
+
//# sourceMappingURL=broadcast.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/broadcast.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Broadcast class provides a simplified wrapper around the BroadcastChannel API\n * for cross-context communication (e.g., between tabs, windows, workers).\n * \n * This class allows you to send and receive messages across different browsing contexts\n * that share the same origin. It encapsulates the creation and management of a BroadcastChannel,\n * providing a simplified API for sending and receiving messages.\n * \n * @class Broadcast\n * @extends BroadcastChannel\n */\nexport default class Broadcast extends BroadcastChannel {\n /**\n * Creates a new Broadcast instance for a named channel.\n * \n * @constructor\n * @param {string} channelName - The name of the broadcast channel to create or connect to.\n * Multiple Broadcast instances with the same channel name can communicate with each other.\n */\n constructor(channelName) {\n super(channelName);\n }\n\n /**\n * Sends data to all other contexts listening on this channel.\n * \n * @param {*} data - The data to broadcast. Can be any structured-cloneable value\n * (primitives, objects, arrays, etc.). Functions and DOM nodes cannot be sent.\n * @returns {void}\n */\n send(data) {\n this.postMessage(data);\n }\n\n /**\n * Registers a callback to handle incoming messages on this channel.\n * \n * @param {Function} callback - Function to call when a message is received.\n * Receives the message data as its only parameter.\n * @returns {void}\n */\n onReceive(callback) {\n this.onmessage = (event) => {\n callback(event.data);\n };\n }\n\n /**\n * Closes the broadcast channel and releases its resources.\n * After calling this method, the Broadcast instance can no longer send or receive messages.\n * \n * @returns {void}\n */\n destroy() {\n this.close();\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAWA,MAAOA,UAAgC,gBAAiB,CAXxD,MAWwD,CAAAC,EAAA,kBAQtD,YAAYC,EAAa,CACvB,MAAMA,CAAW,CACnB,CASA,KAAKC,EAAM,CACT,KAAK,YAAYA,CAAI,CACvB,CASA,UAAUC,EAAU,CAClB,KAAK,UAAaC,GAAU,CAC1BD,EAASC,EAAM,IAAI,CACrB,CACF,CAQA,SAAU,CACR,KAAK,MAAM,CACb,CACF",
|
|
6
|
+
"names": ["Broadcast", "__name", "channelName", "data", "callback", "event"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var a=(c,e)=>l(c,"name",{value:e,configurable:!0});import{warnings as p}from"../../enums/index.js";class o extends EventTarget{static{a(this,"Event")}constructor(){super(),this.events={},this._listener_map=new Map}registerEvents(e){for(const t of Object.values(e))this.events[t]=new o}emit(e,t,s=!1,n=!0){const i=JSON.parse(JSON.stringify(t)),h=new CustomEvent(e,{detail:i,bubbles:s,cancelable:n}),d=this.dispatchEvent(h);try{const r=new BroadcastChannel(e);r.postMessage(i),r.close()}catch(r){console.warn(p.BROADCAST_FAILED,r)}return d}onBroadcast(e,t){const s=new BroadcastChannel(e);return s.onmessage=n=>{t(n.data)},s.send=n=>{s.postMessage(n)},s.destroy=()=>{s.close()},s}onAny(e,t){this.on(e,t);const s=this.onBroadcast(e,t);return{event:this,broadcast:s}}on(e,t){const s=a(n=>{t(n.detail)},"wrapped_listener");return this._listener_map.set(t,s),this.addEventListener(e,s),this}once(e,t){const s=a(n=>{t(n.detail)},"wrapped_listener");return this.addEventListener(e,s,{once:!0}),this}off(e,t){if(this._listener_map&&this._listener_map.has(t)){const s=this._listener_map.get(t);this.removeEventListener(e,s),this._listener_map.delete(t)}return this}removeListener(e,t){return this.off(e,t)}}var v=o;export{v as default};
|
|
2
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/event.js"],
|
|
4
|
+
"sourcesContent": ["import { errors, warnings } from '../../enums/index.js';\n\n/**\n * Event class for micro-flow\n * Provides a simple event emitter implementation for workflow steps and state changes.\n *\n * This class is used for emitting and listening to events within workflows and steps.\n * For broadcasting events across multiple workflows or listeners, it uses BroadcastChannel.\n */\nclass Event extends EventTarget {\n /**\n * Creates a new Event instance.\n * @constructor\n */\n constructor() {\n super();\n this.events = {};\n this._listener_map = new Map();\n }\n\n /**\n * Registers multiple events by creating Event instances for each event name.\n * @param {Object} event_names - An object containing event name constants.\n * @returns {void}\n */\n registerEvents(event_names) {\n for (const event_name of Object.values(event_names)) {\n this.events[event_name] = new Event();\n }\n }\n\n /**\n * Emits a custom event with optional data payload.\n * This method maintains API compatibility with EventEmitter while using CustomEvent.\n * @param {string} event_name - The name of the event to emit.\n * @param {*} [data] - Optional data to pass with the event in the detail property.\n * @param {boolean} [bubbles=false] - Whether the event should bubble up through the DOM.\n * @param {boolean} [cancelable=true] - Whether the event is cancelable.\n * @returns {boolean} True if the event was not cancelled, false if it was cancelled.\n */\n emit(event_name, data, bubbles = false, cancelable = true) {\n const workingData = JSON.parse(JSON.stringify(data));\n\n const custom_event = new CustomEvent(event_name, {\n detail: workingData,\n bubbles,\n cancelable\n });\n const result = this.dispatchEvent(custom_event);\n\n try {\n const channel = new BroadcastChannel(event_name);\n channel.postMessage(workingData);\n channel.close();\n } catch (e) {\n console.warn(warnings.BROADCAST_FAILED, e);\n }\n return result;\n }\n\n /**\n * Listen for broadcasts on a given event name (channel).\n * @param {string} event_name - The event name/channel to listen for.\n * @param {Function} listener - Callback for broadcasted data.\n * @returns {BroadcastChannel} Returns the channel with send() and destroy() aliases.\n */\n onBroadcast(event_name, listener) {\n const channel = new BroadcastChannel(event_name);\n channel.onmessage = (event) => {\n listener(event.data);\n };\n channel.send = (data) => {\n channel.postMessage(data);\n };\n channel.destroy = () => {\n channel.close();\n };\n return channel;\n }\n\n /**\n * Listen for both local and broadcast events.\n * @param {string} event_name - The event name/channel to listen for.\n * @param {Function} listener - Callback for event data.\n * @returns {Object} Returns { event: this, broadcast: BroadcastChannel }\n */\n onAny(event_name, listener) {\n this.on(event_name, listener);\n const broadcast = this.onBroadcast(event_name, listener);\n return { event: this, broadcast };\n }\n\n /**\n * Adds an event listener with EventEmitter-style API.\n * Maintains compatibility with the original API while using addEventListener.\n * @param {string} event_name - The name of the event to listen for.\n * @param {Function} listener - The callback function to execute when the event fires.\n * @returns {Event} Returns this for chaining.\n */\n on(event_name, listener) {\n const wrapped_listener = (event) => {\n // Call the listener with the detail (data) from CustomEvent\n listener(event.detail);\n };\n // Store the original listener reference for removeListener\n this._listener_map.set(listener, wrapped_listener);\n this.addEventListener(event_name, wrapped_listener);\n return this;\n }\n\n /**\n * Adds a one-time event listener with EventEmitter-style API.\n * @param {string} event_name - The name of the event to listen for.\n * @param {Function} listener - The callback function to execute when the event fires.\n * @returns {Event} Returns this for chaining.\n */\n once(event_name, listener) {\n const wrapped_listener = (event) => {\n listener(event.detail);\n };\n this.addEventListener(event_name, wrapped_listener, { once: true });\n return this;\n }\n\n /**\n * Removes an event listener with EventEmitter-style API.\n * @param {string} event_name - The name of the event.\n * @param {Function} listener - The callback function to remove.\n * @returns {Event} Returns this for chaining.\n */\n off(event_name, listener) {\n if (this._listener_map && this._listener_map.has(listener)) {\n const wrapped_listener = this._listener_map.get(listener);\n this.removeEventListener(event_name, wrapped_listener);\n this._listener_map.delete(listener);\n }\n return this;\n }\n\n /**\n * Alias for off() to maintain EventEmitter API compatibility.\n * @param {string} event_name - The name of the event.\n * @param {Function} listener - The callback function to remove.\n * @returns {Event} Returns this for chaining.\n */\n removeListener(event_name, listener) {\n return this.off(event_name, listener);\n }\n}\n\nexport default Event;\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAiB,YAAAA,MAAgB,uBASjC,MAAMC,UAAc,WAAY,CAThC,MASgC,CAAAC,EAAA,cAK9B,aAAc,CACZ,MAAM,EACN,KAAK,OAAS,CAAC,EACf,KAAK,cAAgB,IAAI,GAC3B,CAOA,eAAeC,EAAa,CAC1B,UAAWC,KAAc,OAAO,OAAOD,CAAW,EAChD,KAAK,OAAOC,CAAU,EAAI,IAAIH,CAElC,CAWA,KAAKG,EAAYC,EAAMC,EAAU,GAAOC,EAAa,GAAM,CACzD,MAAMC,EAAc,KAAK,MAAM,KAAK,UAAUH,CAAI,CAAC,EAE7CI,EAAe,IAAI,YAAYL,EAAY,CAC/C,OAAQI,EACR,QAAAF,EACA,WAAAC,CACF,CAAC,EACKG,EAAS,KAAK,cAAcD,CAAY,EAE9C,GAAI,CACF,MAAME,EAAU,IAAI,iBAAiBP,CAAU,EAC/CO,EAAQ,YAAYH,CAAW,EAC/BG,EAAQ,MAAM,CAChB,OAASC,EAAG,CACV,QAAQ,KAAKZ,EAAS,iBAAkBY,CAAC,CAC3C,CACA,OAAOF,CACT,CAQA,YAAYN,EAAYS,EAAU,CAChC,MAAMF,EAAU,IAAI,iBAAiBP,CAAU,EAC/C,OAAAO,EAAQ,UAAaG,GAAU,CAC7BD,EAASC,EAAM,IAAI,CACrB,EACAH,EAAQ,KAAQN,GAAS,CACvBM,EAAQ,YAAYN,CAAI,CAC1B,EACAM,EAAQ,QAAU,IAAM,CACtBA,EAAQ,MAAM,CAChB,EACOA,CACT,CAQA,MAAMP,EAAYS,EAAU,CAC1B,KAAK,GAAGT,EAAYS,CAAQ,EAC5B,MAAME,EAAY,KAAK,YAAYX,EAAYS,CAAQ,EACvD,MAAO,CAAE,MAAO,KAAM,UAAAE,CAAU,CAClC,CASA,GAAGX,EAAYS,EAAU,CACvB,MAAMG,EAAmBd,EAACY,GAAU,CAElCD,EAASC,EAAM,MAAM,CACvB,EAHyB,oBAKzB,YAAK,cAAc,IAAID,EAAUG,CAAgB,EACjD,KAAK,iBAAiBZ,EAAYY,CAAgB,EAC3C,IACT,CAQA,KAAKZ,EAAYS,EAAU,CACzB,MAAMG,EAAmBd,EAACY,GAAU,CAClCD,EAASC,EAAM,MAAM,CACvB,EAFyB,oBAGzB,YAAK,iBAAiBV,EAAYY,EAAkB,CAAE,KAAM,EAAK,CAAC,EAC3D,IACT,CAQA,IAAIZ,EAAYS,EAAU,CACxB,GAAI,KAAK,eAAiB,KAAK,cAAc,IAAIA,CAAQ,EAAG,CAC1D,MAAMG,EAAmB,KAAK,cAAc,IAAIH,CAAQ,EACxD,KAAK,oBAAoBT,EAAYY,CAAgB,EACrD,KAAK,cAAc,OAAOH,CAAQ,CACpC,CACA,OAAO,IACT,CAQA,eAAeT,EAAYS,EAAU,CACnC,OAAO,KAAK,IAAIT,EAAYS,CAAQ,CACtC,CACF,CAEA,IAAOI,EAAQhB",
|
|
6
|
+
"names": ["warnings", "Event", "__name", "event_names", "event_name", "data", "bubbles", "cancelable", "workingData", "custom_event", "result", "channel", "e", "listener", "event", "broadcast", "wrapped_listener", "event_default"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as Event } from './event.js';\nexport { default as StateEvent } from './state_event.js';\nexport { default as StepEvent } from './step_event.js';\nexport { default as WorkflowEvent } from './workflow_event.js';\n"],
|
|
5
|
+
"mappings": "AAAA,OAAoB,WAAXA,MAAwB,aACjC,OAAoB,WAAXA,MAA6B,mBACtC,OAAoB,WAAXA,MAA4B,kBACrC,OAAoB,WAAXA,MAAgC",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var t=(e,s)=>r(e,"name",{value:s,configurable:!0});import{Event as n}from"./index.js";import{state_event_names as a}from"../../enums/index.js";class i extends n{static{t(this,"StateEvent")}event_names=a;constructor(){super(),this.registerStateEvents()}registerStateEvents(){this.registerEvents(this.event_names)}}export{i as default};
|
|
2
|
+
//# sourceMappingURL=state_event.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/state_event.js"],
|
|
4
|
+
"sourcesContent": ["import { Event } from './index.js';\nimport { state_event_names } from '../../enums/index.js';\n\n/**\n * Manages state-specific events by extending the base Event class.\n * @class StateEvent\n * @extends Event\n */\nexport default class StateEvent extends Event {\n event_names = state_event_names;\n\n /**\n * Creates a new StateEvent instance and registers all state events.\n * @constructor\n */\n constructor() {\n super();\n this.registerStateEvents();\n }\n\n /**\n * Registers all state event names defined in the state_event_names enum.\n * @returns {void}\n */\n registerStateEvents() {\n this.registerEvents(this.event_names);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,SAAAA,MAAa,aACtB,OAAS,qBAAAC,MAAyB,uBAOlC,MAAOC,UAAiCF,CAAM,CAR9C,MAQ8C,CAAAG,EAAA,mBAC5C,YAAcF,EAMd,aAAc,CACZ,MAAM,EACN,KAAK,oBAAoB,CAC3B,CAMA,qBAAsB,CACpB,KAAK,eAAe,KAAK,WAAW,CACtC,CACF",
|
|
6
|
+
"names": ["Event", "state_event_names", "StateEvent", "__name"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=Object.defineProperty;var t=(e,s)=>r(e,"name",{value:s,configurable:!0});import{Event as n}from"./index.js";import{step_event_names as i}from"../../enums/index.js";class p extends n{static{t(this,"StepEvent")}event_names=i;constructor(){super(),this.registerStepEvents()}registerStepEvents(){this.registerEvents(this.event_names)}}export{p as default};
|
|
2
|
+
//# sourceMappingURL=step_event.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/step_event.js"],
|
|
4
|
+
"sourcesContent": ["import { Event } from './index.js';\nimport { step_event_names } from '../../enums/index.js';\n\n/**\n * Manages step-specific events by extending the base Event class.\n * @class StepEvent\n * @extends Event\n */\nexport default class StepEvent extends Event {\n event_names = step_event_names;\n\n /**\n * Creates a new StepEvent instance and registers all step events.\n * @constructor\n */\n constructor() {\n super();\n this.registerStepEvents();\n }\n \n /**\n * Registers all step event names defined in the step_event_names enum.\n * @returns {void}\n */\n registerStepEvents() {\n this.registerEvents(this.event_names);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,SAAAA,MAAa,aACtB,OAAS,oBAAAC,MAAwB,uBAOjC,MAAOC,UAAgCF,CAAM,CAR7C,MAQ6C,CAAAG,EAAA,kBAC3C,YAAcF,EAMd,aAAc,CACZ,MAAM,EACN,KAAK,mBAAmB,CAC1B,CAMA,oBAAqB,CACnB,KAAK,eAAe,KAAK,WAAW,CACtC,CACF",
|
|
6
|
+
"names": ["Event", "step_event_names", "StepEvent", "__name"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var s=Object.defineProperty;var t=(e,r)=>s(e,"name",{value:r,configurable:!0});import{Event as o}from"./index.js";import{workflow_event_names as n}from"../../enums/index.js";class i extends o{static{t(this,"WorkflowEvent")}event_names=n;constructor(){super(),this.registerWorkflowEvents()}registerWorkflowEvents(){this.registerEvents(this.event_names)}}export{i as default};
|
|
2
|
+
//# sourceMappingURL=workflow_event.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/events/workflow_event.js"],
|
|
4
|
+
"sourcesContent": ["import { Event } from './index.js';\nimport { workflow_event_names } from '../../enums/index.js';\n\n/**\n * Manages workflow-specific events by extending the base Event class.\n * @class WorkflowEvent\n * @extends Event\n */\nexport default class WorkflowEvent extends Event {\n event_names = workflow_event_names;\n\n /**\n * Creates a new WorkflowEvent instance and registers all workflow events.\n * @constructor\n */\n constructor() {\n super();\n this.registerWorkflowEvents();\n }\n\n /**\n * Registers all workflow event names defined in the workflow_event_names enum.\n * @returns {void}\n */\n registerWorkflowEvents() {\n this.registerEvents(this.event_names);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAS,SAAAA,MAAa,aACtB,OAAS,wBAAAC,MAA4B,uBAOrC,MAAOC,UAAoCF,CAAM,CARjD,MAQiD,CAAAG,EAAA,sBAC/C,YAAcF,EAMd,aAAc,CACZ,MAAM,EACN,KAAK,uBAAuB,CAC9B,CAMA,wBAAyB,CACvB,KAAK,eAAe,KAAK,WAAW,CACtC,CACF",
|
|
6
|
+
"names": ["Event", "workflow_event_names", "WorkflowEvent", "__name"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/classes/index.js"],
|
|
4
|
+
"sourcesContent": ["export * from './events/index.js';\nexport { default as Base } from './base.js';\nexport { default as State } from './state.js';\nexport { default as Workflow } from './workflow.js';\nexport * from './steps/index.js';\n"],
|
|
5
|
+
"mappings": "AAAA,WAAc,oBACd,OAAoB,WAAXA,MAAuB,YAChC,OAAoB,WAAXA,MAAwB,aACjC,OAAoB,WAAXA,MAA2B,gBACpC,WAAc",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var T=Object.defineProperty;var m=(E,e)=>T(E,"name",{value:e,configurable:!0});import{errors as f,warnings as _}from"../enums/errors.js";import{StepEvent as y,WorkflowEvent as b,StateEvent as g}from"./events/index.js";import{base_types as h,conditional_step_comparators as O,state_event_names as A,step_event_names as v,step_statuses as k,step_types as j,sub_step_types as d,workflow_event_names as R,workflow_statuses as S}from"../enums/index.js";const w={messages:{errors:f,warnings:_},statuses:{workflow:S,step:k},event_names:{workflow:R,step:v,state:A},events:{workflow:new b,step:new y,state:new g},types:{base_types:h,step_types:j,sub_step_types:d},workflows:{},conditional_step_comparators:O};let s={...w};const n=s.events,c=s.event_names;class i{static{m(this,"State")}static delete(e){if(!e)throw new Error(f.INVALID_STATE_PATH);const a=i.parsePath(e);let r=s;for(let t=0;t<a.length-1;t++){const o=a[t];if(!Object.prototype.hasOwnProperty.call(r,o)||typeof r[o]!="object")return;r=r[o]}delete r[a[a.length-1]],n.state.emit(c.state.DELETED,{state:s})}static async each(e,a){const r=i.get(e);if(Array.isArray(r))for(const[t,o]of r.entries())n.state.emit(c.state.EACH,{state:s}),await a(o,t);else if(typeof r=="object"&&Object.prototype.toString.call(r)==="[object Object]")for(const t of Object.keys(r))n.state.emit(c.state.EACH,{state:s}),await a(r[t],t);else throw new Error(f.VALUE_NOT_ITERABLE)}static freeze(){const e=Object.freeze(s);return n.state.emit(c.state.FROZEN,{state:s}),e}static get(e,a=null,r=null){let t=s;if(!e||["*",""].includes(e))return n.state.emit(c.state.GET,{state:t??a}),t;if(t=i.getFromPropertyPath(e,!1)??a,r)try{switch(r){case"string":t=String(t);break;case"number":t=Number(t);break;case"boolean":t=!!t;break;default:break}}catch(o){console.error("Error converting state value: ",o)}return n.state.emit(c.state.GET,{state:t}),t??a}static getFromPropertyPath(e,a=!0){const r=i.parsePath(e);let t=s;for(const o of r)if(t&&Object.prototype.hasOwnProperty.call(t,o))t=t[o];else return;return a&&n.state.emit(c.state.GET_FROM_PROPERTY_PATH,{state:s}),t}static getState(){return n.state.emit(c.state.GET_STATE,{state:s}),s}static merge(e){return s={...s,...e},n.state.emit(c.state.MERGE,{state:s}),s}static parsePath(e){const a=e.match(/[^.[\]]+|(?<=\[)([^\]]+)(?=\])/g);return a?a.map(r=>r.replace(/^['"]|['"]$/g,"")):[]}static reset(){return s={...w,workflows:{}},n.state.emit(c.state.RESET,{state:s}),s}static set(e,a){if(!e)throw new Error(f.INVALID_STATE_PATH);n.state.emit(c.state.SET,{state:s}),i.setToPropertyPath(e,a,!1)}static setToPropertyPath(e,a,r=!0){const t=i.parsePath(e);let o=s;for(let l=0;l<t.length-1;l++){const p=t[l],u=t[l+1];if(!Object.prototype.hasOwnProperty.call(o,p)||typeof o[p]!="object"){const P=/^\d+$/.test(u);o[p]=P?[]:{}}o=o[p]}r&&n.state.emit(c.state.SET_TO_PROPERTY_PATH,{state:s}),o[t[t.length-1]]=a}}var L=i;export{L as default};
|
|
2
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/classes/state.js"],
|
|
4
|
+
"sourcesContent": ["import { errors, warnings } from '../enums/errors.js';\nimport { StepEvent, WorkflowEvent, StateEvent } from './events/index.js';\nimport {\n base_types,\n conditional_step_comparators,\n state_event_names,\n step_event_names,\n step_statuses,\n step_types,\n sub_step_types,\n workflow_event_names,\n workflow_statuses,\n} from '../enums/index.js';\n\nconst defaultState = {\n messages: {\n errors,\n warnings,\n },\n statuses: {\n workflow: workflow_statuses,\n step: step_statuses\n },\n event_names: {\n workflow: workflow_event_names,\n step: step_event_names,\n state: state_event_names,\n },\n events: {\n workflow: new WorkflowEvent(),\n step: new StepEvent(),\n state: new StateEvent(),\n },\n types: {\n base_types,\n step_types,\n sub_step_types,\n },\n workflows: {},\n conditional_step_comparators\n};\n\nlet state = { ...defaultState };\n\n// Module-level shortcuts for events and event_names\nconst events = state.events;\nconst event_names = state.event_names;\n\n/**\n * Singleton class representing the global state for workflows, steps, and processes.\n * Provides methods for managing state with getter/setter functionality, nested path access,\n * and immutability options. The state is shared across all workflow and step instances.\n * \n * @class State\n */\nclass State {\n /**\n * Deletes a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to delete (e.g., \"user.profile.email\" or \"users[0].email\").\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static delete(path) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n \n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n return;\n }\n \n current = current[part];\n }\n \n delete current[parts[parts.length - 1]];\n\n events.state.emit(event_names.state.DELETED, { state });\n }\n\n /**\n * Iterates over a collection (array or object) located at the specified state path,\n * executing a callback function for each item.\n * \n * @param {string} path - The path of the state property to iterate over.\n * @param {Function} callback - The function to execute for each item in the collection.\n * @throws {Error} Throws if the state property at the path is not an array or object.\n */\n static async each(path, callback) {\n const collection = State.get(path);\n \n if (Array.isArray(collection)) {\n for (const [index, item] of collection.entries()) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(item, index);\n }\n } else if (\n typeof collection === 'object' &&\n Object.prototype.toString.call(collection) === '[object Object]'\n ) {\n for (const key of Object.keys(collection)) {\n events.state.emit(event_names.state.EACH, { state });\n await callback(collection[key], key);\n }\n } else {\n throw new Error(errors.VALUE_NOT_ITERABLE);\n }\n }\n\n /**\n * Freezes the entire state object, making it immutable.\n * @returns {void}\n */\n static freeze() {\n const frozenState = Object.freeze(state);\n events.state.emit(event_names.state.FROZEN, { state });\n return frozenState;\n }\n\n /**\n * Gets the value of a state property using dot-notation or bracket-notation path access.\n * \n * @param {string} path - The path of the state property to get. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * Special values:\n * - Falsy values (null, undefined, false, \"\"): Returns entire state object\n * - \"*\": Returns entire state object\n * @param {*} [defaultValue=null] - Default value to return if the path doesn't exist.\n * @param {string} [type='string'] - The output type to convert the value to.\n * Supported types: \"string\", \"number\", \"boolean\".\n * @returns {*} The value of the state property, or defaultValue if not found. null if not found\n * and no defaultValue provided.\n * @throws {Error} Throws if the value cannot be converted to the specified type.\n */\n static get(path, defaultValue = null, type = null) {\n let gotten = state;\n if (!path || ['*', ''].includes(path)) {\n events.state.emit(event_names.state.GET, { state: gotten ?? defaultValue });\n return gotten;\n }\n\n gotten = State.getFromPropertyPath(path, false) ?? defaultValue;\n\n if (type) {\n try {\n switch (type) {\n case 'string':\n gotten = String(gotten);\n break;\n case 'number':\n gotten = Number(gotten);\n break;\n case 'boolean':\n gotten = Boolean(gotten);\n break;\n default:\n break;\n }\n } catch (error) {\n console.error(\"Error converting state value: \", error);\n }\n }\n\n events.state.emit(event_names.state.GET, { state: gotten });\n\n return gotten ?? defaultValue;\n }\n\n /**\n * Resolves a nested property path within the state object.\n * Supports both dot notation and bracket notation.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {boolean} [emit=true] - Whether to emit the GET_FROM_PROPERTY_PATH event.\n * @returns {*} The value at the specified path, or undefined if not found.\n */\n static getFromPropertyPath(path, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n\n for (const part of parts) {\n if (current && Object.prototype.hasOwnProperty.call(current, part)) {\n current = current[part];\n } else {\n return undefined;\n }\n }\n\n if (emit) {\n events.state.emit(event_names.state.GET_FROM_PROPERTY_PATH, { state });\n }\n\n return current;\n }\n\n /**\n * Gets the entire state object.\n * @returns {Object} The entire state object.\n */\n static getState() {\n events.state.emit(event_names.state.GET_STATE, { state });\n return state;\n }\n\n /**\n * Merges an object into the current State.\n * @param {Object} newState - The object to merge into the current State.\n * @returns {object} The updated state object.\n */\n static merge(newState) {\n state = { ...state, ...newState };\n events.state.emit(event_names.state.MERGE, { state });\n return state;\n }\n\n /**\n * Parses a property path string into an array of keys, supporting both dot notation\n * and bracket notation.\n * \n * @param {string} path - The path to parse (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @returns {string[]} Array of property keys.\n */\n static parsePath(path) {\n const matches = path.match(/[^.[\\]]+|(?<=\\[)([^\\]]+)(?=\\])/g);\n \n if (!matches) {\n return [];\n }\n\n return matches.map(part => part.replace(/^['\"]|['\"]$/g, ''));\n }\n\n /**\n * Resets the state to its default values.\n * @returns {object} The reset state object.\n */\n static reset() {\n state = { \n ...defaultState,\n workflows: {}, // Always create fresh to avoid shared reference mutation\n };\n events.state.emit(event_names.state.RESET, { state });\n return state;\n }\n\n /**\n * Sets the value of a state property using dot-notation or bracket-notation path access.\n * Creates intermediate objects if they don't exist.\n * \n * @param {string} path - The path of the state property to set. Supports both dot notation\n * (e.g., \"user.profile.name\") and bracket notation (e.g., \"users[0].name\" or \"data['key-name']\").\n * @param {*} value - The value to set for the state property.\n * @returns {void}\n * @throws {Error} Throws if path is empty or invalid.\n */\n static set(path, value) {\n if (!path) {\n throw new Error(errors.INVALID_STATE_PATH);\n }\n\n events.state.emit(event_names.state.SET, { state });\n\n State.setToPropertyPath(path, value, false);\n }\n\n /**\n * Sets a nested property value within the state object based on a path.\n * Supports both dot notation and bracket notation. Creates intermediate objects/arrays as needed.\n * \n * @param {string} path - The path to the property (e.g., \"user.profile.name\", \"users[0].name\", \"data['key-name']\").\n * @param {*} value - The value to set at the specified path.\n * @param {boolean} [emit=true] - Whether to emit the SET_TO_PROPERTY_PATH event.\n */\n static setToPropertyPath(path, value, emit = true) {\n const parts = State.parsePath(path);\n let current = state;\n \n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const nextPart = parts[i + 1];\n \n if (!Object.prototype.hasOwnProperty.call(current, part) || typeof current[part] !== 'object') {\n // Determine if next part is an array index (numeric)\n const isNextPartNumeric = /^\\d+$/.test(nextPart);\n current[part] = isNextPartNumeric ? [] : {};\n }\n current = current[part];\n }\n \n if (emit) {\n events.state.emit(event_names.state.SET_TO_PROPERTY_PATH, { state });\n }\n\n current[parts[parts.length - 1]] = value;\n }\n}\n\nexport default State;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["errors", "warnings", "StepEvent", "WorkflowEvent", "StateEvent", "base_types", "conditional_step_comparators", "state_event_names", "step_event_names", "step_statuses", "step_types", "sub_step_types", "workflow_event_names", "workflow_statuses", "defaultState", "state", "events", "event_names", "State", "__name", "path", "parts", "current", "i", "part", "callback", "collection", "index", "item", "key", "frozenState", "defaultValue", "type", "gotten", "error", "emit", "newState", "matches", "value", "nextPart", "isNextPartNumeric", "state_default"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(n,t)=>a(n,"name",{value:t,configurable:!0});import r from"./logic_step.js";import"../../enums/index.js";class s extends r{static{o(this,"Case")}static step_name="case";constructor({name:t,conditional:e={subject:null,operator:null,value:null},callable:i=o(async()=>{},"callable"),force_subject_override:c=!1}){super({name:t,step_type:s.step_name,callable:i}),this.conditional_config=e,this.force_subject_override=c,this.is_matched=!1}set switch_subject(t){const e=t!=null,i=this.conditional_config.subject!==null&&this.conditional_config.subject!==void 0;if(!e&&!i)throw new Error(`No subject set for case step: ${this.name}, using default equality check`);if(e&&(!i||this.force_subject_override)&&(this.conditional_config.subject=t),!this.conditionalIsValid())throw new Error(`Invalid conditional configuration for case step: ${this.name}`)}}export{s as default};
|
|
2
|
+
//# sourceMappingURL=case.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/steps/case.js"],
|
|
4
|
+
"sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * Case class representing a single case in a switch statement.\n * Used in conjunction with SwitchStep to create switch/case logic.\n * @class Case\n * @extends LogicStep\n */\nexport default class Case extends LogicStep {\n static step_name = 'case';\n\n /**\n * Creates a new Case instance.\n * Note: Plain LogicStep instances can be used in place of Case, but they MUST have conditional.subject set.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the case.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject=null] - Subject to evaluate (typically set by SwitchStep). Can be a function.\n * @param {conditional_step_comparators|string} [options.conditional.operator=null] - Comparison operator.\n * @param {*|Function} [options.conditional.value=null] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.callable=async () => {}] - Function, Step, or Workflow to execute when case matches.\n * @param {boolean} [options.force_subject_override=false] - Force override of subject even if already set.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n callable = async () => {},\n force_subject_override = false,\n }) {\n super({\n name,\n step_type: Case.step_name,\n callable,\n });\n\n this.conditional_config = conditional;\n this.force_subject_override = force_subject_override;\n\n this.is_matched = false;\n }\n\n /**\n * Sets the switch subject from the parent SwitchStep.\n * Automatically sets the conditional subject if not already set or if force_subject_override is true.\n * @param {*} subject - The subject value from the SwitchStep.\n * @throws {Error} If no subject is provided and conditional.subject is not set.\n * @throws {Error} If the resulting conditional configuration is invalid.\n */\n set switch_subject(subject) {\n const subjectProvided = subject !== null && subject !== undefined;\n const hasExistingSubject = this.conditional_config.subject !== null && this.conditional_config.subject !== undefined;\n\n if (!subjectProvided && !hasExistingSubject) {\n throw new Error(`No subject set for case step: ${this.name}, using default equality check`);\n }\n\n if (subjectProvided && (!hasExistingSubject || this.force_subject_override)) {\n this.conditional_config.subject = subject;\n }\n\n if (!this.conditionalIsValid()) {\n throw new Error(`Invalid conditional configuration for case step: ${this.name}`);\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAQ7C,MAAOC,UAA2BD,CAAU,CAT5C,MAS4C,CAAAE,EAAA,aAC1C,OAAO,UAAY,OAcnB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,SAAAC,EAAWH,EAAA,SAAY,CAAC,EAAb,YACX,uBAAAI,EAAyB,EAC3B,EAAG,CACD,MAAM,CACJ,KAAAH,EACA,UAAWF,EAAK,UAChB,SAAAI,CACF,CAAC,EAED,KAAK,mBAAqBD,EAC1B,KAAK,uBAAyBE,EAE9B,KAAK,WAAa,EACpB,CASA,IAAI,eAAeC,EAAS,CAC1B,MAAMC,EAAkBD,GAAY,KAC9BE,EAAqB,KAAK,mBAAmB,UAAY,MAAQ,KAAK,mBAAmB,UAAY,OAE3G,GAAI,CAACD,GAAmB,CAACC,EACvB,MAAM,IAAI,MAAM,iCAAiC,KAAK,IAAI,gCAAgC,EAO5F,GAJID,IAAoB,CAACC,GAAsB,KAAK,0BAClD,KAAK,mBAAmB,QAAUF,GAGhC,CAAC,KAAK,mBAAmB,EAC3B,MAAM,IAAI,MAAM,oDAAoD,KAAK,IAAI,EAAE,CAEnF,CACF",
|
|
6
|
+
"names": ["LogicStep", "Case", "__name", "name", "conditional", "callable", "force_subject_override", "subject", "subjectProvided", "hasExistingSubject"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var a=Object.defineProperty;var n=(o,e)=>a(o,"name",{value:e,configurable:!0});import l from"./logic_step.js";import"../../enums/index.js";class c extends l{static{n(this,"ConditionalStep")}static step_name="conditional";constructor({name:e,conditional:i={subject:null,operator:null,value:null},true_callable:t=n(async()=>{},"true_callable"),false_callable:s=n(async()=>{},"false_callable")}){super({name:e,conditional:i}),typeof t=="function"?this.true_callable=t.bind(this):this.true_callable=t,typeof s=="function"?this.false_callable=s.bind(this):this.false_callable=s,this.callable=this.conditional.bind(this)}async conditional(){const e=this.true_callable,i=this.false_callable;let t=null;return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Condition met for step: ${this.name}, executing true branch`),typeof e=="function"?t=await e():(e.parentWorkflowId=this.parentWorkflowId,t=await e.execute())):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Condition not met for step: ${this.name}, executing false branch`),typeof i=="function"?t=await i():(i.parentWorkflowId=this.parentWorkflowId,t=await i.execute())),{message:`Conditional step ${this.name} completed`,result:t}}}export{c as default};
|
|
2
|
+
//# sourceMappingURL=conditional_step.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/steps/conditional_step.js"],
|
|
4
|
+
"sourcesContent": ["import LogicStep from './logic_step.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * ConditionalStep class for branching logic based on conditions.\n * @class ConditionalStep\n * @extends LogicStep\n */\nexport default class ConditionalStep extends LogicStep {\n static step_name = 'conditional';\n\n /**\n * Creates a new ConditionalStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {Function|Step|Workflow} [options.true_callable=async () => {}] - Callable to execute if condition is true.\n * @param {Function|Step|Workflow} [options.false_callable=async () => {}] - Callable to execute if condition is false.\n */\n constructor({\n name,\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n true_callable = async () => {},\n false_callable = async () => {},\n }) {\n super({\n name,\n conditional\n });\n\n // Bind function callables to this step instance for state access\n if (typeof true_callable === 'function') {\n this.true_callable = true_callable.bind(this);\n } else {\n this.true_callable = true_callable;\n }\n\n if (typeof false_callable === 'function') {\n this.false_callable = false_callable.bind(this);\n } else {\n this.false_callable = false_callable;\n }\n\n this.callable = this.conditional.bind(this);\n }\n\n /**\n * Executes the appropriate branch based on the condition evaluation.\n * @async\n * @returns {Promise<*>} The result of the executed branch.\n */\n async conditional() {\n const true_callable = this.true_callable;\n const false_callable = this.false_callable;\n\n let result = null;\n\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Condition met for step: ${this.name}, executing true branch`\n );\n\n if (typeof true_callable === 'function') {\n result = await true_callable();\n } else {\n true_callable.parentWorkflowId = this.parentWorkflowId;\n result = await true_callable.execute();\n }\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Condition not met for step: ${this.name}, executing false branch`\n );\n\n if (typeof false_callable === 'function') {\n result = await false_callable();\n } else {\n false_callable.parentWorkflowId = this.parentWorkflowId;\n result = await false_callable.execute();\n }\n }\n\n return { message: `Conditional step ${this.name} completed`, result };\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAe,kBACtB,MAA6C,uBAO7C,MAAOC,UAAsCD,CAAU,CARvD,MAQuD,CAAAE,EAAA,wBACrD,OAAO,UAAY,cAanB,YAAY,CACV,KAAAC,EACA,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,cAAAC,EAAgBH,EAAA,SAAY,CAAC,EAAb,iBAChB,eAAAI,EAAiBJ,EAAA,SAAY,CAAC,EAAb,iBACnB,EAAG,CACD,MAAM,CACJ,KAAAC,EACA,YAAAC,CACF,CAAC,EAGG,OAAOC,GAAkB,WAC3B,KAAK,cAAgBA,EAAc,KAAK,IAAI,EAE5C,KAAK,cAAgBA,EAGnB,OAAOC,GAAmB,WAC5B,KAAK,eAAiBA,EAAe,KAAK,IAAI,EAE9C,KAAK,eAAiBA,EAGxB,KAAK,SAAW,KAAK,YAAY,KAAK,IAAI,CAC5C,CAOA,MAAM,aAAc,CAClB,MAAMD,EAAgB,KAAK,cACrBC,EAAiB,KAAK,eAE5B,IAAIC,EAAS,KAEb,OAAI,KAAK,eAAe,GACtB,KAAK,IACH,KAAK,SAAS,0DAA0D,EACxE,2BAA2B,KAAK,IAAI,yBACtC,EAEI,OAAOF,GAAkB,WAC3BE,EAAS,MAAMF,EAAc,GAE7BA,EAAc,iBAAmB,KAAK,iBACtCE,EAAS,MAAMF,EAAc,QAAQ,KAGvC,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,+BAA+B,KAAK,IAAI,0BAC1C,EAEI,OAAOC,GAAmB,WAC5BC,EAAS,MAAMD,EAAe,GAE9BA,EAAe,iBAAmB,KAAK,iBACvCC,EAAS,MAAMD,EAAe,QAAQ,IAInC,CAAE,QAAS,oBAAoB,KAAK,IAAI,aAAc,OAAAC,CAAO,CACtE,CACF",
|
|
6
|
+
"names": ["LogicStep", "ConditionalStep", "__name", "name", "conditional", "true_callable", "false_callable", "result"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var l=Object.defineProperty;var n=(a,e)=>l(a,"name",{value:e,configurable:!0});import o from"./step.js";import{delay_types as p,step_types as r}from"../../enums/index.js";import y from"node-schedule";import{addMilliseconds as _}from"date-fns";class d extends o{static{n(this,"DelayStep")}static step_name="delay";constructor({name:e,absolute_timestamp:t=new Date,relative_delay_ms:s=0,delay_type:i=p.RELATIVE}){super({name:e,step_type:r.DELAY}),this.delay_type=i,this.absolute_timestamp=new Date(t),this.relative_delay_ms=s,this.callable=this[i].bind(this)}async absolute(){const e=new Date;return this.absolute_timestamp.getTime()<=e.getTime()?(this.log(this.getState("events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:e.toISOString()}):this.delay(this.absolute_timestamp)}async delay(e){return new Promise(t=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`),`Delay scheduled for step: ${this.name} until ${e.toISOString()}`);const s=y.scheduleJob(e,()=>{this.log(this.getState(`events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`),`Delay complete for step: ${this.name}. Continuing.`),t({delayed:!0,delay_type:this.delay_type,timestamp:new Date().toISOString()})});this.scheduled_job=s})}async relative(){if(this.relative_delay_ms<=0)return this.log(this.getState("events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE"),`No delay for step: ${this.name}. Continuing.`),{delayed:!1,delay_type:this.delay_type,timestamp:new Date().toISOString()};const e=_(new Date,this.relative_delay_ms);return this.delay(e)}}export{d as default};
|
|
2
|
+
//# sourceMappingURL=delay_step.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/steps/delay_step.js"],
|
|
4
|
+
"sourcesContent": ["import Step from './step.js';\nimport { delay_types, step_types } from '../../enums/index.js';\nimport schedule from 'node-schedule';\nimport { addMilliseconds } from 'date-fns';\n\n/**\n * DelayStep class for introducing delays in workflow execution.\n * Supports both absolute and relative delays.\n * @class DelayStep\n * @extends Step\n */\nexport default class DelayStep extends Step {\n static step_name = 'delay';\n\n /**\n * Creates a new DelayStep instance.\n * @param {Object} options - Configuration options.\n * @param {string} [options.name] - Name of the step.\n * @param {Date|string} [options.absolute_timestamp=new Date()] - Absolute timestamp to delay until.\n * @param {number} [options.relative_delay_ms=0] - Relative delay in milliseconds.\n * @param {string} [options.delay_type=delay_types.RELATIVE] - Type of delay ('absolute' or 'relative').\n */\n constructor({\n name,\n absolute_timestamp = new Date(),\n relative_delay_ms = 0,\n delay_type = delay_types.RELATIVE\n }) {\n super({\n name,\n step_type: step_types.DELAY,\n });\n\n this.delay_type = delay_type;\n this.absolute_timestamp = new Date(absolute_timestamp);\n this.relative_delay_ms = relative_delay_ms;\n\n this.callable = this[delay_type].bind(this);\n }\n\n /**\n * Executes an absolute delay until the specified timestamp. If the timestamp is in the past, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async absolute() {\n const now = new Date();\n\n if (this.absolute_timestamp.getTime() <= now.getTime()) {\n this.log(\n this.getState('events.step.event_names.DELAY_STEP_ABSOLUTE_COMPLETE'),\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: now.toISOString() };\n }\n\n return this.delay(this.absolute_timestamp);\n }\n\n /** Schedules a delay until the specified date and time.\n * @param {Date} delay_until - The date and time to delay until.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async delay(delay_until) {\n return new Promise((resolve) => {\n this.log(\n this.getState(\n `events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_SCHEDULED`\n ),\n `Delay scheduled for step: ${this.name} until ${delay_until.toISOString()}`\n );\n\n const job = schedule.scheduleJob(delay_until, () => {\n this.log(\n this.getState(\n `events.step.event_names.DELAY_STEP_${this.delay_type.toUpperCase()}_COMPLETE`\n ),\n `Delay complete for step: ${this.name}. Continuing.`\n );\n resolve({ delayed: true, delay_type: this.delay_type, timestamp: new Date().toISOString() });\n });\n\n this.scheduled_job = job;\n });\n }\n\n /**\n * Executes a relative delay for the specified duration. If the delay duration is zero or negative, it continues immediately.\n * @returns {Promise<Object>} Resolves with delay completion info when delay completes.\n */\n async relative() {\n if (this.relative_delay_ms <= 0) {\n this.log(\n this.getState('events.step.event_names.DELAY_STEP_RELATIVE_COMPLETE'),\n `No delay for step: ${this.name}. Continuing.`\n );\n return { delayed: false, delay_type: this.delay_type, timestamp: new Date().toISOString() };\n }\n\n const delay_until = addMilliseconds(new Date(), this.relative_delay_ms);\n\n return this.delay(delay_until);\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAU,YACjB,OAAS,eAAAC,EAAa,cAAAC,MAAkB,uBACxC,OAAOC,MAAc,gBACrB,OAAS,mBAAAC,MAAuB,WAQhC,MAAOC,UAAgCL,CAAK,CAX5C,MAW4C,CAAAM,EAAA,kBAC1C,OAAO,UAAY,QAUnB,YAAY,CACV,KAAAC,EACA,mBAAAC,EAAqB,IAAI,KACzB,kBAAAC,EAAoB,EACpB,WAAAC,EAAaT,EAAY,QAC3B,EAAG,CACD,MAAM,CACJ,KAAAM,EACA,UAAWL,EAAW,KACxB,CAAC,EAED,KAAK,WAAaQ,EAClB,KAAK,mBAAqB,IAAI,KAAKF,CAAkB,EACrD,KAAK,kBAAoBC,EAEzB,KAAK,SAAW,KAAKC,CAAU,EAAE,KAAK,IAAI,CAC5C,CAMA,MAAM,UAAW,CACf,MAAMC,EAAM,IAAI,KAEhB,OAAI,KAAK,mBAAmB,QAAQ,GAAKA,EAAI,QAAQ,GACnD,KAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAWA,EAAI,YAAY,CAAE,GAG9E,KAAK,MAAM,KAAK,kBAAkB,CAC3C,CAMA,MAAM,MAAMC,EAAa,CACvB,OAAO,IAAI,QAASC,GAAY,CAC9B,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,YACrE,EACA,6BAA6B,KAAK,IAAI,UAAUD,EAAY,YAAY,CAAC,EAC3E,EAEA,MAAME,EAAMX,EAAS,YAAYS,EAAa,IAAM,CAClD,KAAK,IACH,KAAK,SACH,sCAAsC,KAAK,WAAW,YAAY,CAAC,WACrE,EACA,4BAA4B,KAAK,IAAI,eACvC,EACAC,EAAQ,CAAE,QAAS,GAAM,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,CAAC,CAC7F,CAAC,EAED,KAAK,cAAgBC,CACvB,CAAC,CACH,CAMA,MAAM,UAAW,CACf,GAAI,KAAK,mBAAqB,EAC5B,YAAK,IACH,KAAK,SAAS,sDAAsD,EACpE,sBAAsB,KAAK,IAAI,eACjC,EACO,CAAE,QAAS,GAAO,WAAY,KAAK,WAAY,UAAW,IAAI,KAAK,EAAE,YAAY,CAAE,EAG5F,MAAMF,EAAcR,EAAgB,IAAI,KAAQ,KAAK,iBAAiB,EAEtE,OAAO,KAAK,MAAMQ,CAAW,CAC/B,CACF",
|
|
6
|
+
"names": ["Step", "delay_types", "step_types", "schedule", "addMilliseconds", "DelayStep", "__name", "name", "absolute_timestamp", "relative_delay_ms", "delay_type", "now", "delay_until", "resolve", "job"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var n=Object.defineProperty;var s=(o,t)=>n(o,"name",{value:t,configurable:!0});import i from"./logic_step.js";import l from"../../enums/flow_control_types.js";import"../../enums/index.js";class a extends i{static{s(this,"FlowControlStep")}static step_name="flow_control";constructor({conditional:t={subject:null,operator:null,value:null},name:r,flow_control_type:e=l.BREAK}){if(super({name:r,conditional:t}),!Object.values(l).includes(e))throw new Error(`Invalid flow control type: ${e}`);this.flow_control_type=e,this.callable=this.shouldFlowControl.bind(this)}async shouldFlowControl(){return this.checkCondition()?(this.log(this.getState("events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED"),`Break condition met for step: ${this.name}`),this.setParentWorkflowValue(this.parentWorkflowId,`should_${this.flow_control_type}`,!0),!0):(this.log(this.getState("events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED"),`Break condition not met for step: ${this.name}`),this.setParentWorkflowValue(this.parentWorkflowId,`should_${this.flow_control_type}`,!1),!1)}}export{a as default};
|
|
2
|
+
//# sourceMappingURL=flow_control_step.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/classes/steps/flow_control_step.js"],
|
|
4
|
+
"sourcesContent": ["import LogicStep from './logic_step.js';\nimport flow_control_types from '../../enums/flow_control_types.js';\nimport { conditional_step_comparators } from '../../enums/index.js';\n\n/**\n * FlowControlStep class for controlling workflow execution flow (break or skip).\n * @class FlowControlStep\n * @extends LogicStep\n */\nexport default class FlowControlStep extends LogicStep {\n static step_name = 'flow_control';\n\n /**\n * Creates a new FlowControlStep instance.\n * @param {Object} options - Configuration options.\n * @param {Object} [options.conditional] - Conditional configuration.\n * @param {*|Function} [options.conditional.subject] - Subject to evaluate. Can be a function that returns the value.\n * @param {conditional_step_comparators|string} [options.conditional.operator] - Comparison operator.\n * @param {*|Function} [options.conditional.value] - Value to compare against. Can be a function that returns the value.\n * @param {string} [options.name] - Name of the step.\n * @param {string} [options.flow_control_type=flow_control_types.BREAK] - Type of flow control.\n * @throws {Error} Throws if flow_control_type is invalid.\n */\n constructor({\n conditional = {\n subject: null,\n operator: null,\n value: null,\n },\n name,\n flow_control_type = flow_control_types.BREAK,\n }) {\n super({\n name,\n conditional\n });\n\n if (!Object.values(flow_control_types).includes(flow_control_type)) {\n throw new Error(`Invalid flow control type: ${flow_control_type}`);\n }\n\n this.flow_control_type = flow_control_type;\n this.callable = this.shouldFlowControl.bind(this);\n }\n\n /**\n * Evaluates the condition and sets the appropriate flow control flag.\n * @async\n * @returns {Promise<boolean>} True if the flow control should be activated.\n */\n async shouldFlowControl() {\n if (this.checkCondition()) {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_TRUE_BRANCH_EXECUTED'),\n `Break condition met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parentWorkflowId, `should_${this.flow_control_type}`, true);\n\n return true;\n } else {\n this.log(\n this.getState('events.step.event_names.CONDITIONAL_FALSE_BRANCH_EXECUTED'),\n `Break condition not met for step: ${this.name}`\n );\n this.setParentWorkflowValue(this.parentWorkflowId, `should_${this.flow_control_type}`, false);\n\n return false;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "+EAAA,OAAOA,MAAe,kBACtB,OAAOC,MAAwB,oCAC/B,MAA6C,uBAO7C,MAAOC,UAAsCF,CAAU,CATvD,MASuD,CAAAG,EAAA,wBACrD,OAAO,UAAY,eAanB,YAAY,CACV,YAAAC,EAAc,CACZ,QAAS,KACT,SAAU,KACV,MAAO,IACT,EACA,KAAAC,EACA,kBAAAC,EAAoBL,EAAmB,KACzC,EAAG,CAMD,GALA,MAAM,CACJ,KAAAI,EACA,YAAAD,CACF,CAAC,EAEG,CAAC,OAAO,OAAOH,CAAkB,EAAE,SAASK,CAAiB,EAC/D,MAAM,IAAI,MAAM,8BAA8BA,CAAiB,EAAE,EAGnE,KAAK,kBAAoBA,EACzB,KAAK,SAAW,KAAK,kBAAkB,KAAK,IAAI,CAClD,CAOA,MAAM,mBAAoB,CACxB,OAAI,KAAK,eAAe,GACtB,KAAK,IACH,KAAK,SAAS,0DAA0D,EACxE,iCAAiC,KAAK,IAAI,EAC5C,EACA,KAAK,uBAAuB,KAAK,iBAAkB,UAAU,KAAK,iBAAiB,GAAI,EAAI,EAEpF,KAEP,KAAK,IACH,KAAK,SAAS,2DAA2D,EACzE,qCAAqC,KAAK,IAAI,EAChD,EACA,KAAK,uBAAuB,KAAK,iBAAkB,UAAU,KAAK,iBAAiB,GAAI,EAAK,EAErF,GAEX,CACF",
|
|
6
|
+
"names": ["LogicStep", "flow_control_types", "FlowControlStep", "__name", "conditional", "name", "flow_control_type"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{default as o}from"./step.js";import{default as r}from"./logic_step.js";import{default as p}from"./case.js";import{default as d}from"./conditional_step.js";import{default as m}from"./delay_step.js";import{default as x}from"./flow_control_step.js";import{default as i}from"./loop_step.js";import{default as C}from"./switch_step.js";export{p as Case,d as ConditionalStep,m as DelayStep,x as FlowControlStep,r as LogicStep,i as LoopStep,o as Step,C as SwitchStep};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|