@fkws/klonk 0.0.14 → 0.0.16
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 +18 -14
- 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,
|
|
@@ -79,11 +79,15 @@ interface Machine<
|
|
|
79
79
|
builder: InputBuilder<SourceType, AllOutputTypes, TaskInputType>;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* Important typing note:
|
|
83
|
+
*
|
|
84
|
+
* We intentionally do NOT wrap the builder return in `NoInfer<...>`.
|
|
85
|
+
* Doing so breaks contextual typing for object literals, causing string literal unions
|
|
86
|
+
* (e.g. `"low" | "critical"`) to widen to `string` inside input builder callbacks.
|
|
87
|
+
*
|
|
88
|
+
* By letting `TaskInputType` be inferred from the `task` argument (and then checking the
|
|
89
|
+
* builder against it), literal unions are preserved and DX stays sane.
|
|
85
90
|
*/
|
|
86
|
-
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
87
91
|
/**
|
|
88
92
|
* An ordered sequence of Tasks executed with strong type inference.
|
|
89
93
|
*
|
|
@@ -108,12 +112,12 @@ declare class Playlist<
|
|
|
108
112
|
/**
|
|
109
113
|
* Internal list of task + builder pairs in the order they will run.
|
|
110
114
|
*/
|
|
111
|
-
|
|
115
|
+
bundles: TaskBundle<any, any, any, any, string>[];
|
|
112
116
|
/**
|
|
113
117
|
* Optional finalizer invoked after all tasks complete (successfully or not).
|
|
114
118
|
*/
|
|
115
119
|
finalizer?: (source: SourceType, outputs: Record<string, any>) => void | Promise<void>;
|
|
116
|
-
constructor(
|
|
120
|
+
constructor(bundles?: TaskBundle<any, any, any, any, string>[], finalizer?: (source: SourceType, outputs: Record<string, any>) => void | Promise<void>);
|
|
117
121
|
/**
|
|
118
122
|
* Append a task to the end of the playlist.
|
|
119
123
|
*
|
|
@@ -134,7 +138,7 @@ declare class Playlist<
|
|
|
134
138
|
const IdentType extends string
|
|
135
139
|
>(task: Task<TaskInputType, TaskOutputType, IdentType> & {
|
|
136
140
|
ident: IdentType
|
|
137
|
-
}, builder: (source: SourceType, outputs: AllOutputTypes) =>
|
|
141
|
+
}, builder: (source: SourceType, outputs: AllOutputTypes) => TaskInputType): Playlist<AllOutputTypes & { [K in IdentType] : Railroad<TaskOutputType> }, SourceType>;
|
|
138
142
|
/**
|
|
139
143
|
* Register a callback to run after the playlist finishes. Use this hook to
|
|
140
144
|
* react to the last task or to adjust machine state before a transition.
|
|
@@ -418,7 +422,7 @@ declare class StateNode<TStateData> {
|
|
|
418
422
|
*
|
|
419
423
|
* @template TStateData - The shape of the external mutable state carried through the machine.
|
|
420
424
|
*/
|
|
421
|
-
declare class
|
|
425
|
+
declare class Machine<TStateData> {
|
|
422
426
|
initialState: StateNode<TStateData> | null;
|
|
423
427
|
statesToCreate: StateNode<TStateData>[];
|
|
424
428
|
private currentState;
|
|
@@ -447,7 +451,7 @@ declare class Machine2<TStateData> {
|
|
|
447
451
|
* @template TStateData
|
|
448
452
|
* @returns A new unfinalized machine instance.
|
|
449
453
|
*/
|
|
450
|
-
static create<TStateData>():
|
|
454
|
+
static create<TStateData>(): Machine<TStateData>;
|
|
451
455
|
/**
|
|
452
456
|
* Finalize the machine by resolving state transitions and locking configuration.
|
|
453
457
|
* Must be called before `start` or `run`.
|
|
@@ -460,7 +464,7 @@ declare class Machine2<TStateData> {
|
|
|
460
464
|
*/
|
|
461
465
|
finalize({ ident }?: {
|
|
462
466
|
ident?: string
|
|
463
|
-
}):
|
|
467
|
+
}): Machine<TStateData>;
|
|
464
468
|
/**
|
|
465
469
|
* Add a state to the machine.
|
|
466
470
|
*
|
|
@@ -471,12 +475,12 @@ declare class Machine2<TStateData> {
|
|
|
471
475
|
*/
|
|
472
476
|
addState(state: StateNode<TStateData>, options?: {
|
|
473
477
|
initial?: boolean
|
|
474
|
-
}):
|
|
478
|
+
}): Machine<TStateData>;
|
|
475
479
|
/**
|
|
476
480
|
* Attach a logger to this machine. If the machine has an initial state set,
|
|
477
481
|
* the logger will be propagated to all currently reachable states.
|
|
478
482
|
*/
|
|
479
|
-
addLogger(logger: Logger):
|
|
483
|
+
addLogger(logger: Logger): Machine<TStateData>;
|
|
480
484
|
/**
|
|
481
485
|
* Run the machine synchronously until it reaches a terminal condition:
|
|
482
486
|
* - A leaf state (no transitions)
|
|
@@ -503,4 +507,4 @@ type RunOptions = {
|
|
|
503
507
|
mode: "infinitely"
|
|
504
508
|
interval?: number
|
|
505
509
|
});
|
|
506
|
-
export { Workflow, TriggerEvent, Trigger, Task, StateNode, RunOptions, Railroad, Playlist,
|
|
510
|
+
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