@fkws/klonk 0.0.14 → 0.0.17
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/dist/index.cjs +12 -12
- package/dist/index.d.ts +9 -9
- package/dist/index.js +12 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,16 +41,16 @@ module.exports = __toCommonJS(exports_src);
|
|
|
41
41
|
|
|
42
42
|
// src/prototypes/Playlist.ts
|
|
43
43
|
class Playlist {
|
|
44
|
-
|
|
44
|
+
bundles;
|
|
45
45
|
finalizer;
|
|
46
|
-
constructor(
|
|
47
|
-
this.
|
|
46
|
+
constructor(bundles = [], finalizer) {
|
|
47
|
+
this.bundles = bundles;
|
|
48
48
|
this.finalizer = finalizer;
|
|
49
49
|
}
|
|
50
50
|
addTask(task, builder) {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
return new Playlist(
|
|
51
|
+
const bundle = { task, builder };
|
|
52
|
+
const newBundles = [...this.bundles, bundle];
|
|
53
|
+
return new Playlist(newBundles, this.finalizer);
|
|
54
54
|
}
|
|
55
55
|
finally(finalizer) {
|
|
56
56
|
this.finalizer = finalizer;
|
|
@@ -58,14 +58,14 @@ class Playlist {
|
|
|
58
58
|
}
|
|
59
59
|
async run(source) {
|
|
60
60
|
const outputs = {};
|
|
61
|
-
for (const
|
|
62
|
-
const input =
|
|
63
|
-
const isValid = await
|
|
61
|
+
for (const bundle of this.bundles) {
|
|
62
|
+
const input = bundle.builder(source, outputs);
|
|
63
|
+
const isValid = await bundle.task.validateInput(input);
|
|
64
64
|
if (!isValid) {
|
|
65
|
-
throw new Error(`Input validation failed for task '${
|
|
65
|
+
throw new Error(`Input validation failed for task '${bundle.task.ident}'`);
|
|
66
66
|
}
|
|
67
|
-
const result = await
|
|
68
|
-
outputs[
|
|
67
|
+
const result = await bundle.task.run(input);
|
|
68
|
+
outputs[bundle.task.ident] = result;
|
|
69
69
|
}
|
|
70
70
|
if (this.finalizer) {
|
|
71
71
|
await this.finalizer(source, outputs);
|
package/dist/index.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ type InputBuilder<
|
|
|
68
68
|
/**
|
|
69
69
|
* @internal Internal assembly type that couples a task with its input builder.
|
|
70
70
|
*/
|
|
71
|
-
interface
|
|
71
|
+
interface TaskBundle<
|
|
72
72
|
SourceType,
|
|
73
73
|
AllOutputTypes,
|
|
74
74
|
TaskInputType,
|
|
@@ -108,12 +108,12 @@ declare class Playlist<
|
|
|
108
108
|
/**
|
|
109
109
|
* Internal list of task + builder pairs in the order they will run.
|
|
110
110
|
*/
|
|
111
|
-
|
|
111
|
+
bundles: TaskBundle<any, any, any, any, string>[];
|
|
112
112
|
/**
|
|
113
113
|
* Optional finalizer invoked after all tasks complete (successfully or not).
|
|
114
114
|
*/
|
|
115
115
|
finalizer?: (source: SourceType, outputs: Record<string, any>) => void | Promise<void>;
|
|
116
|
-
constructor(
|
|
116
|
+
constructor(bundles?: TaskBundle<any, any, any, any, string>[], finalizer?: (source: SourceType, outputs: Record<string, any>) => void | Promise<void>);
|
|
117
117
|
/**
|
|
118
118
|
* Append a task to the end of the playlist.
|
|
119
119
|
*
|
|
@@ -418,7 +418,7 @@ declare class StateNode<TStateData> {
|
|
|
418
418
|
*
|
|
419
419
|
* @template TStateData - The shape of the external mutable state carried through the machine.
|
|
420
420
|
*/
|
|
421
|
-
declare class
|
|
421
|
+
declare class Machine<TStateData> {
|
|
422
422
|
initialState: StateNode<TStateData> | null;
|
|
423
423
|
statesToCreate: StateNode<TStateData>[];
|
|
424
424
|
private currentState;
|
|
@@ -447,7 +447,7 @@ declare class Machine2<TStateData> {
|
|
|
447
447
|
* @template TStateData
|
|
448
448
|
* @returns A new unfinalized machine instance.
|
|
449
449
|
*/
|
|
450
|
-
static create<TStateData>():
|
|
450
|
+
static create<TStateData>(): Machine<TStateData>;
|
|
451
451
|
/**
|
|
452
452
|
* Finalize the machine by resolving state transitions and locking configuration.
|
|
453
453
|
* Must be called before `start` or `run`.
|
|
@@ -460,7 +460,7 @@ declare class Machine2<TStateData> {
|
|
|
460
460
|
*/
|
|
461
461
|
finalize({ ident }?: {
|
|
462
462
|
ident?: string
|
|
463
|
-
}):
|
|
463
|
+
}): Machine<TStateData>;
|
|
464
464
|
/**
|
|
465
465
|
* Add a state to the machine.
|
|
466
466
|
*
|
|
@@ -471,12 +471,12 @@ declare class Machine2<TStateData> {
|
|
|
471
471
|
*/
|
|
472
472
|
addState(state: StateNode<TStateData>, options?: {
|
|
473
473
|
initial?: boolean
|
|
474
|
-
}):
|
|
474
|
+
}): Machine<TStateData>;
|
|
475
475
|
/**
|
|
476
476
|
* Attach a logger to this machine. If the machine has an initial state set,
|
|
477
477
|
* the logger will be propagated to all currently reachable states.
|
|
478
478
|
*/
|
|
479
|
-
addLogger(logger: Logger):
|
|
479
|
+
addLogger(logger: Logger): Machine<TStateData>;
|
|
480
480
|
/**
|
|
481
481
|
* Run the machine synchronously until it reaches a terminal condition:
|
|
482
482
|
* - A leaf state (no transitions)
|
|
@@ -503,4 +503,4 @@ type RunOptions = {
|
|
|
503
503
|
mode: "infinitely"
|
|
504
504
|
interval?: number
|
|
505
505
|
});
|
|
506
|
-
export { Workflow, TriggerEvent, Trigger, Task, StateNode, RunOptions, Railroad, Playlist,
|
|
506
|
+
export { Workflow, TriggerEvent, Trigger, Task, StateNode, RunOptions, Railroad, Playlist, Machine };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// src/prototypes/Playlist.ts
|
|
2
2
|
class Playlist {
|
|
3
|
-
|
|
3
|
+
bundles;
|
|
4
4
|
finalizer;
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
5
|
+
constructor(bundles = [], finalizer) {
|
|
6
|
+
this.bundles = bundles;
|
|
7
7
|
this.finalizer = finalizer;
|
|
8
8
|
}
|
|
9
9
|
addTask(task, builder) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
return new Playlist(
|
|
10
|
+
const bundle = { task, builder };
|
|
11
|
+
const newBundles = [...this.bundles, bundle];
|
|
12
|
+
return new Playlist(newBundles, this.finalizer);
|
|
13
13
|
}
|
|
14
14
|
finally(finalizer) {
|
|
15
15
|
this.finalizer = finalizer;
|
|
@@ -17,14 +17,14 @@ class Playlist {
|
|
|
17
17
|
}
|
|
18
18
|
async run(source) {
|
|
19
19
|
const outputs = {};
|
|
20
|
-
for (const
|
|
21
|
-
const input =
|
|
22
|
-
const isValid = await
|
|
20
|
+
for (const bundle of this.bundles) {
|
|
21
|
+
const input = bundle.builder(source, outputs);
|
|
22
|
+
const isValid = await bundle.task.validateInput(input);
|
|
23
23
|
if (!isValid) {
|
|
24
|
-
throw new Error(`Input validation failed for task '${
|
|
24
|
+
throw new Error(`Input validation failed for task '${bundle.task.ident}'`);
|
|
25
25
|
}
|
|
26
|
-
const result = await
|
|
27
|
-
outputs[
|
|
26
|
+
const result = await bundle.task.run(input);
|
|
27
|
+
outputs[bundle.task.ident] = result;
|
|
28
28
|
}
|
|
29
29
|
if (this.finalizer) {
|
|
30
30
|
await this.finalizer(source, outputs);
|
package/package.json
CHANGED