@gesslar/actioneer 0.1.3 → 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/README.md +128 -2
- package/package.json +1 -1
- package/src/lib/ActionBuilder.js +158 -16
- package/src/lib/ActionHooks.js +90 -50
- package/src/lib/ActionRunner.js +131 -138
- package/src/lib/ActionWrapper.js +20 -7
- package/src/lib/Activity.js +79 -19
- package/src/lib/Piper.js +106 -57
- package/src/types/lib/ActionBuilder.d.ts +63 -6
- 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 +7 -20
- 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 +56 -18
- 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,31 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* loop semantics for an activity.
|
|
2
|
+
*
|
|
4
3
|
*/
|
|
5
4
|
export type ACTIVITY = number
|
|
5
|
+
/** @typedef {import("./ActionHooks.js").default} ActionHooks */
|
|
6
6
|
/**
|
|
7
7
|
* Activity bit flags recognised by the builder. The flag decides
|
|
8
8
|
* loop semantics for an activity.
|
|
9
9
|
*
|
|
10
10
|
* @readonly
|
|
11
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)
|
|
12
15
|
*/
|
|
13
16
|
export const ACTIVITY: Readonly<{
|
|
14
17
|
WHILE: number;
|
|
15
18
|
UNTIL: number;
|
|
19
|
+
SPLIT: number;
|
|
16
20
|
}>
|
|
17
21
|
export default class Activity {
|
|
18
22
|
/**
|
|
19
23
|
* Construct an Activity definition wrapper.
|
|
20
24
|
*
|
|
21
|
-
* @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
|
|
22
34
|
*/
|
|
23
|
-
constructor({ action, name, op, kind, pred }: {
|
|
35
|
+
constructor({ action, name, op, kind, pred, hooks, splitter, rejoiner }: {
|
|
24
36
|
action: unknown;
|
|
25
|
-
name: string;
|
|
26
|
-
op: (context: unknown) => unknown | Promise<unknown> |
|
|
27
|
-
kind?: number;
|
|
28
|
-
pred?: (context: unknown) => boolean | Promise<boolean
|
|
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;
|
|
29
44
|
})
|
|
30
45
|
/**
|
|
31
46
|
* The activity name.
|
|
@@ -46,17 +61,35 @@ export default class Activity {
|
|
|
46
61
|
*/
|
|
47
62
|
get pred(): (context: unknown) => boolean | Promise<boolean> | undefined
|
|
48
63
|
/**
|
|
49
|
-
* 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).
|
|
50
71
|
*
|
|
51
72
|
* @returns {string} - Kind name extracted via Data.typeOf
|
|
52
73
|
*/
|
|
53
74
|
get opKind(): string
|
|
54
75
|
/**
|
|
55
|
-
* The operator to execute (function or nested
|
|
76
|
+
* The operator to execute (function or nested ActionBuilder).
|
|
56
77
|
*
|
|
57
|
-
* @returns {unknown} - Activity operation
|
|
78
|
+
* @returns {(context: unknown) => unknown|Promise<unknown>|import("./ActionBuilder.js").default} - Activity operation
|
|
58
79
|
*/
|
|
59
|
-
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
|
|
60
93
|
/**
|
|
61
94
|
* The action instance this activity belongs to.
|
|
62
95
|
*
|
|
@@ -67,18 +100,23 @@ export default class Activity {
|
|
|
67
100
|
* Execute the activity with before/after hooks.
|
|
68
101
|
*
|
|
69
102
|
* @param {unknown} context - Mutable context flowing through the pipeline
|
|
70
|
-
* @returns {Promise<
|
|
103
|
+
* @returns {Promise<unknown>} - Activity result
|
|
71
104
|
*/
|
|
72
|
-
run(context: unknown): Promise<
|
|
73
|
-
activityResult: unknown;
|
|
74
|
-
}>
|
|
105
|
+
run(context: unknown): Promise<unknown>
|
|
75
106
|
/**
|
|
76
107
|
* Attach hooks to this activity instance.
|
|
77
108
|
*
|
|
78
|
-
* @param {
|
|
109
|
+
* @param {ActionHooks} hooks - Hooks instance with optional before$/after$ methods
|
|
79
110
|
* @returns {this} - This activity for chaining
|
|
80
111
|
*/
|
|
81
|
-
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
|
|
82
119
|
#private
|
|
83
120
|
}
|
|
121
|
+
export type ActionHooks = import('./ActionHooks.js').default
|
|
84
122
|
//# sourceMappingURL=Activity.d.ts.map
|
|
@@ -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":[],"mappings":";;;uBASU,MAAM;AAPhB,gEAAgE;AAEhE;;;;;;;;;GASG;AACH;;;;GAIE;AAEF;IAoBE;;;;;;;;;;;;OAYG;IACH,yEATG;QAAsB,MAAM,EAApB,OAAO;QACa,IAAI,EAAxB,MAAM,GAAC,MAAM;QAC6E,EAAE,EAA5F,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,OAAO,oBAAoB,EAAE,OAAO;QACrE,IAAI;QACoC,IAAI,cAAhD,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC;QAC3B,KAAK;QACa,QAAQ,cAAnC,OAAO,KAAK,OAAO;QACuC,QAAQ,sBAA1D,OAAO,gBAAgB,OAAO,KAAK,OAAO;KACtE,EAUA;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,GAAC,IAAI,CAIvB;IAED;;;;OAIG;IACH,YAFa,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,SAAS,CAIpE;IAED;;;;OAIG;IACH,eAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,cAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,UAFa,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,OAAO,oBAAoB,EAAE,OAAO,CAI/F;IAED;;;;OAIG;IACH,gBAFa,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,GAAC,IAAI,CAIhD;IAED;;;;OAIG;IACH,gBAFa,CAAC,CAAC,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,GAAC,IAAI,CAI/E;IAED;;;;OAIG;IACH,cAFa,OAAO,CAInB;IAED;;;;;OAKG;IACH,aAHW,OAAO,GACL,OAAO,CAAC,OAAO,CAAC,CAa5B;IAED;;;;;OAKG;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"}
|