@gesslar/actioneer 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/ActionBuilder.js +106 -22
- package/src/lib/ActionHooks.js +46 -30
- package/src/lib/ActionRunner.js +123 -42
- package/src/lib/ActionWrapper.js +17 -7
- package/src/lib/Activity.js +74 -12
- package/src/lib/Piper.js +105 -55
- package/src/types/lib/ActionBuilder.d.ts +42 -2
- package/src/types/lib/ActionBuilder.d.ts.map +1 -1
- package/src/types/lib/ActionHooks.d.ts +23 -24
- package/src/types/lib/ActionHooks.d.ts.map +1 -1
- package/src/types/lib/ActionRunner.d.ts +4 -2
- package/src/types/lib/ActionRunner.d.ts.map +1 -1
- package/src/types/lib/ActionWrapper.d.ts +19 -5
- package/src/types/lib/ActionWrapper.d.ts.map +1 -1
- package/src/types/lib/Activity.d.ts +54 -19
- package/src/types/lib/Activity.d.ts.map +1 -1
- package/src/types/lib/Piper.d.ts +24 -7
- package/src/types/lib/Piper.d.ts.map +1 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {object} WrappedActivityConfig
|
|
3
3
|
* @property {string|symbol} name Activity identifier used by hooks/logs.
|
|
4
|
-
* @property {(context: unknown) => unknown|Promise<unknown>|
|
|
4
|
+
* @property {(context: unknown) => unknown|Promise<unknown>|import("./ActionBuilder.js").default} op Operation or nested ActionBuilder to execute.
|
|
5
5
|
* @property {number} [kind] Optional loop semantic flags.
|
|
6
6
|
* @property {(context: unknown) => boolean|Promise<boolean>} [pred] Predicate tied to WHILE/UNTIL semantics.
|
|
7
|
+
* @property {(context: unknown) => unknown} [splitter] Splitter function for SPLIT activities.
|
|
8
|
+
* @property {(originalContext: unknown, splitResults: unknown) => unknown} [rejoiner] Rejoiner function for SPLIT activities.
|
|
7
9
|
* @property {unknown} [action] Parent action instance supplied when invoking the op.
|
|
8
10
|
* @property {(message: string, level?: number, ...args: Array<unknown>) => void} [debug] Optional logger reference.
|
|
9
11
|
*/
|
|
@@ -17,11 +19,15 @@ export default class ActionWrapper {
|
|
|
17
19
|
/**
|
|
18
20
|
* Create a wrapper from the builder payload.
|
|
19
21
|
*
|
|
20
|
-
* @param {
|
|
22
|
+
* @param {object} config Builder payload containing activities + logger
|
|
23
|
+
* @param {Map<string|symbol, WrappedActivityConfig>} config.activities Activities map
|
|
24
|
+
* @param {(message: string, level?: number, ...args: Array<unknown>) => void} config.debug Debug function
|
|
25
|
+
* @param {object} config.hooks Hooks object
|
|
21
26
|
*/
|
|
22
|
-
constructor(
|
|
27
|
+
constructor(config: {
|
|
23
28
|
activities: Map<string | symbol, WrappedActivityConfig>;
|
|
24
29
|
debug: (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
30
|
+
hooks: object;
|
|
25
31
|
})
|
|
26
32
|
/**
|
|
27
33
|
* Iterator over the registered activities.
|
|
@@ -37,9 +43,9 @@ export type WrappedActivityConfig = {
|
|
|
37
43
|
*/
|
|
38
44
|
name: string | symbol;
|
|
39
45
|
/**
|
|
40
|
-
* Operation or nested
|
|
46
|
+
* Operation or nested ActionBuilder to execute.
|
|
41
47
|
*/
|
|
42
|
-
op: (context: unknown) => unknown | Promise<unknown> |
|
|
48
|
+
op: (context: unknown) => unknown | Promise<unknown> | import('./ActionBuilder.js').default;
|
|
43
49
|
/**
|
|
44
50
|
* Optional loop semantic flags.
|
|
45
51
|
*/
|
|
@@ -48,6 +54,14 @@ export type WrappedActivityConfig = {
|
|
|
48
54
|
* Predicate tied to WHILE/UNTIL semantics.
|
|
49
55
|
*/
|
|
50
56
|
pred?: ((context: unknown) => boolean | Promise<boolean>) | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Splitter function for SPLIT activities.
|
|
59
|
+
*/
|
|
60
|
+
splitter?: ((context: unknown) => unknown) | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Rejoiner function for SPLIT activities.
|
|
63
|
+
*/
|
|
64
|
+
rejoiner?: ((originalContext: unknown, splitResults: unknown) => unknown) | undefined;
|
|
51
65
|
/**
|
|
52
66
|
* Parent action instance supplied when invoking the op.
|
|
53
67
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionWrapper.d.ts","sourceRoot":"","sources":["../../lib/ActionWrapper.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"ActionWrapper.d.ts","sourceRoot":"","sources":["../../lib/ActionWrapper.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;GAEG;AACH;IAqBE;;;;;;;OAOG;IACH,oBAJG;QAA0D,UAAU,EAA5D,GAAG,CAAC,MAAM,GAAC,MAAM,EAAE,qBAAqB,CAAC;QACkC,KAAK,EAAhF,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;QACnD,KAAK,EAApB,MAAM;KAChB,EAUA;IAOD;;;;OAIG;IACH,kBAFa,gBAAgB,CAI5B;;CACF;;;;;UAtEa,MAAM,GAAC,MAAM;;;;QACb,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,OAAO,oBAAoB,EAAE,OAAO;;;;;;;;sBAEzE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC;;;;0BACpC,OAAO,KAAK,OAAO;;;;kCACX,OAAO,gBAAgB,OAAO,KAAK,OAAO;;;;aAC5D,OAAO;;;;uBACG,MAAM,UAAU,MAAM,WAAW,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;+BAInE,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC;qBAf1B,eAAe"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* loop semantics for an activity.
|
|
2
|
+
*
|
|
4
3
|
*/
|
|
5
4
|
export type ACTIVITY = number
|
|
6
5
|
/** @typedef {import("./ActionHooks.js").default} ActionHooks */
|
|
@@ -10,24 +9,38 @@ export type ACTIVITY = number
|
|
|
10
9
|
*
|
|
11
10
|
* @readonly
|
|
12
11
|
* @enum {number}
|
|
12
|
+
* @property {number} WHILE - Execute activity while predicate returns true (2)
|
|
13
|
+
* @property {number} UNTIL - Execute activity until predicate returns false (4)
|
|
14
|
+
* @property {number} SPLIT - Execute activity with split/rejoin pattern for parallel execution (8)
|
|
13
15
|
*/
|
|
14
16
|
export const ACTIVITY: Readonly<{
|
|
15
17
|
WHILE: number;
|
|
16
18
|
UNTIL: number;
|
|
19
|
+
SPLIT: number;
|
|
17
20
|
}>
|
|
18
21
|
export default class Activity {
|
|
19
22
|
/**
|
|
20
23
|
* Construct an Activity definition wrapper.
|
|
21
24
|
*
|
|
22
|
-
* @param {
|
|
25
|
+
* @param {object} init - Initial properties describing the activity operation, loop semantics, and predicate
|
|
26
|
+
* @param {unknown} init.action - Parent action instance
|
|
27
|
+
* @param {string|symbol} init.name - Activity identifier
|
|
28
|
+
* @param {(context: unknown) => unknown|Promise<unknown>|import("./ActionBuilder.js").default} init.op - Operation to execute
|
|
29
|
+
* @param {number} [init.kind] - Optional loop semantics flags
|
|
30
|
+
* @param {(context: unknown) => boolean|Promise<boolean>} [init.pred] - Optional predicate for WHILE/UNTIL
|
|
31
|
+
* @param {ActionHooks} [init.hooks] - Optional hooks instance
|
|
32
|
+
* @param {(context: unknown) => unknown} [init.splitter] - Optional splitter function for SPLIT activities
|
|
33
|
+
* @param {(originalContext: unknown, splitResults: unknown) => unknown} [init.rejoiner] - Optional rejoiner function for SPLIT activities
|
|
23
34
|
*/
|
|
24
|
-
constructor({ action, name, op, kind, pred, hooks }: {
|
|
35
|
+
constructor({ action, name, op, kind, pred, hooks, splitter, rejoiner }: {
|
|
25
36
|
action: unknown;
|
|
26
|
-
name: string;
|
|
27
|
-
op: (context: unknown) => unknown | Promise<unknown> |
|
|
28
|
-
kind?: number;
|
|
29
|
-
pred?: (context: unknown) => boolean | Promise<boolean
|
|
30
|
-
hooks?: ActionHooks;
|
|
37
|
+
name: string | symbol;
|
|
38
|
+
op: (context: unknown) => unknown | Promise<unknown> | import('./ActionBuilder.js').default;
|
|
39
|
+
kind?: number | undefined;
|
|
40
|
+
pred?: ((context: unknown) => boolean | Promise<boolean>) | undefined;
|
|
41
|
+
hooks?: import('./ActionHooks.js').default | undefined;
|
|
42
|
+
splitter?: ((context: unknown) => unknown) | undefined;
|
|
43
|
+
rejoiner?: ((originalContext: unknown, splitResults: unknown) => unknown) | undefined;
|
|
31
44
|
})
|
|
32
45
|
/**
|
|
33
46
|
* The activity name.
|
|
@@ -48,17 +61,35 @@ export default class Activity {
|
|
|
48
61
|
*/
|
|
49
62
|
get pred(): (context: unknown) => boolean | Promise<boolean> | undefined
|
|
50
63
|
/**
|
|
51
|
-
* The
|
|
64
|
+
* The current context (if set).
|
|
65
|
+
*
|
|
66
|
+
* @returns {unknown} Current context value
|
|
67
|
+
*/
|
|
68
|
+
get context(): unknown
|
|
69
|
+
/**
|
|
70
|
+
* The operator kind name (Function or ActionBuilder).
|
|
52
71
|
*
|
|
53
72
|
* @returns {string} - Kind name extracted via Data.typeOf
|
|
54
73
|
*/
|
|
55
74
|
get opKind(): string
|
|
56
75
|
/**
|
|
57
|
-
* The operator to execute (function or nested
|
|
76
|
+
* The operator to execute (function or nested ActionBuilder).
|
|
58
77
|
*
|
|
59
|
-
* @returns {unknown} - Activity operation
|
|
78
|
+
* @returns {(context: unknown) => unknown|Promise<unknown>|import("./ActionBuilder.js").default} - Activity operation
|
|
60
79
|
*/
|
|
61
|
-
get op(): unknown
|
|
80
|
+
get op(): (context: unknown) => unknown | Promise<unknown> | import('./ActionBuilder.js').default
|
|
81
|
+
/**
|
|
82
|
+
* The splitter function for SPLIT activities.
|
|
83
|
+
*
|
|
84
|
+
* @returns {((context: unknown) => unknown)|null} Splitter function or null
|
|
85
|
+
*/
|
|
86
|
+
get splitter(): ((context: unknown) => unknown) | null
|
|
87
|
+
/**
|
|
88
|
+
* The rejoiner function for SPLIT activities.
|
|
89
|
+
*
|
|
90
|
+
* @returns {((originalContext: unknown, splitResults: unknown) => unknown)|null} Rejoiner function or null
|
|
91
|
+
*/
|
|
92
|
+
get rejoiner(): ((originalContext: unknown, splitResults: unknown) => unknown) | null
|
|
62
93
|
/**
|
|
63
94
|
* The action instance this activity belongs to.
|
|
64
95
|
*
|
|
@@ -69,18 +100,22 @@ export default class Activity {
|
|
|
69
100
|
* Execute the activity with before/after hooks.
|
|
70
101
|
*
|
|
71
102
|
* @param {unknown} context - Mutable context flowing through the pipeline
|
|
72
|
-
* @returns {Promise<
|
|
103
|
+
* @returns {Promise<unknown>} - Activity result
|
|
73
104
|
*/
|
|
74
|
-
run(context: unknown): Promise<
|
|
75
|
-
activityResult: unknown;
|
|
76
|
-
}>
|
|
105
|
+
run(context: unknown): Promise<unknown>
|
|
77
106
|
/**
|
|
78
107
|
* Attach hooks to this activity instance.
|
|
79
108
|
*
|
|
80
|
-
* @param {
|
|
109
|
+
* @param {ActionHooks} hooks - Hooks instance with optional before$/after$ methods
|
|
81
110
|
* @returns {this} - This activity for chaining
|
|
82
111
|
*/
|
|
83
|
-
setActionHooks(hooks:
|
|
112
|
+
setActionHooks(hooks: ActionHooks): this
|
|
113
|
+
/**
|
|
114
|
+
* Get the hooks instance attached to this activity.
|
|
115
|
+
*
|
|
116
|
+
* @returns {ActionHooks|null} The hooks instance or null
|
|
117
|
+
*/
|
|
118
|
+
get hooks(): ActionHooks | null
|
|
84
119
|
#private
|
|
85
120
|
}
|
|
86
121
|
export type ActionHooks = import('./ActionHooks.js').default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../lib/Activity.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../lib/Activity.js"],"names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AKG;IACH,sBAHW,WAAW,GACT,IAAI,CAOhB;IAED;;;;OAIG;IACH,aAFa,WAAW,GAAC,IAAI,CAI5B;;CACF;0BAvLa,OAAO,kBAAkB,EAAE,OAAO"}
|
package/src/types/lib/Piper.d.ts
CHANGED
|
@@ -8,15 +8,17 @@ export default class Piper {
|
|
|
8
8
|
debug?: (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
9
9
|
})
|
|
10
10
|
/**
|
|
11
|
-
* Add a processing step to the pipeline
|
|
11
|
+
* Add a processing step to the pipeline.
|
|
12
|
+
* Each step is executed sequentially per item.
|
|
12
13
|
*
|
|
13
14
|
* @param {(context: unknown) => Promise<unknown>|unknown} fn Function that processes an item
|
|
14
|
-
* @param {{name
|
|
15
|
+
* @param {{name: string, required?: boolean}} options Step options (name is required)
|
|
15
16
|
* @param {unknown} [newThis] Optional this binding
|
|
16
17
|
* @returns {Piper} The pipeline instance (for chaining)
|
|
18
|
+
* @throws {Sass} If name is not provided in options
|
|
17
19
|
*/
|
|
18
20
|
addStep(fn: (context: unknown) => Promise<unknown> | unknown, options?: {
|
|
19
|
-
name
|
|
21
|
+
name: string;
|
|
20
22
|
required?: boolean;
|
|
21
23
|
}, newThis?: unknown): Piper
|
|
22
24
|
/**
|
|
@@ -36,13 +38,28 @@ export default class Piper {
|
|
|
36
38
|
*/
|
|
37
39
|
addCleanup(fn: () => Promise<void> | void, thisArg?: unknown): Piper
|
|
38
40
|
/**
|
|
39
|
-
* Process items through the pipeline with concurrency control
|
|
41
|
+
* Process items through the pipeline with concurrency control using a worker pool pattern.
|
|
42
|
+
* Workers are spawned up to maxConcurrent limit, and as workers complete, new workers
|
|
43
|
+
* are spawned to maintain concurrency until all items are processed.
|
|
44
|
+
*
|
|
45
|
+
* This implementation uses dynamic worker spawning to maintain concurrency:
|
|
46
|
+
* - Initial workers are spawned up to maxConcurrent limit
|
|
47
|
+
* - As each worker completes (success OR failure), a replacement worker is spawned if items remain
|
|
48
|
+
* - Worker spawning occurs in finally block to ensure resilience to individual worker failures
|
|
49
|
+
* - All results are collected with {ok, value} or {ok: false, error} structure
|
|
50
|
+
* - Processing continues even if individual workers fail, collecting all errors
|
|
40
51
|
*
|
|
41
52
|
* @param {Array<unknown>|unknown} items - Items to process
|
|
42
|
-
* @param {number} maxConcurrent - Maximum concurrent items to process
|
|
43
|
-
* @returns {Promise<Array<unknown>>} -
|
|
53
|
+
* @param {number} [maxConcurrent] - Maximum concurrent items to process (default: 10)
|
|
54
|
+
* @returns {Promise<Array<{ok: boolean, value?: unknown, error?: Sass}>>} - Results with success/failure status
|
|
55
|
+
* @throws {Sass} If setup or teardown fails
|
|
44
56
|
*/
|
|
45
|
-
pipe(items: Array<unknown> | unknown, maxConcurrent?: number): Promise<Array<
|
|
57
|
+
pipe(items: Array<unknown> | unknown, maxConcurrent?: number): Promise<Array<{
|
|
58
|
+
ok: boolean;
|
|
59
|
+
value?: unknown;
|
|
60
|
+
error?: Sass;
|
|
61
|
+
}>>
|
|
46
62
|
#private
|
|
47
63
|
}
|
|
64
|
+
import { Sass } from '@gesslar/toolkit'
|
|
48
65
|
//# sourceMappingURL=Piper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Piper.d.ts","sourceRoot":"","sources":["../../lib/Piper.js"],"names":[],"mappings":"AAaA;
|
|
1
|
+
{"version":3,"file":"Piper.d.ts","sourceRoot":"","sources":["../../lib/Piper.js"],"names":[],"mappings":"AAaA;IAWE;;;;OAIG;IACH,wBAFW;QAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,CAAA;KAAC,EAItF;IAED;;;;;;;;;OASG;IACH,YANW,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAC,OAAO,YAC9C;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,YAClC,OAAO,GACL,KAAK,CAejB;IAED;;;;;;OAMG;IACH,aAJW,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,YACxB,OAAO,GACL,KAAK,CAMjB;IAED;;;;;;OAMG;IACH,eAJW,MAAM,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI,YACxB,OAAO,GACL,KAAK,CAMjB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,YALW,KAAK,CAAC,OAAO,CAAC,GAAC,OAAO,kBACtB,MAAM,GACJ,OAAO,CAAC,KAAK,CAAC;QAAC,EAAE,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,IAAI,CAAA;KAAC,CAAC,CAAC,CAqFxE;;CAwCF;qBAnNiC,kBAAkB"}
|