@gesslar/actioneer 1.6.0 → 2.0.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 +128 -12
- package/package.json +15 -5
- package/src/browser/index.js +9 -0
- package/src/browser/lib/ActionHooks.js +198 -0
- package/src/index.js +8 -5
- package/src/lib/ActionHooks.js +37 -174
- package/src/types/browser/index.d.ts +7 -0
- package/src/types/browser/index.d.ts.map +1 -0
- package/src/types/browser/lib/ActionBuilder.d.ts +174 -0
- package/src/types/browser/lib/ActionBuilder.d.ts.map +1 -0
- package/src/types/browser/lib/ActionHooks.d.ts +98 -0
- package/src/types/browser/lib/ActionHooks.d.ts.map +1 -0
- package/src/types/browser/lib/ActionRunner.d.ts +43 -0
- package/src/types/browser/lib/ActionRunner.d.ts.map +1 -0
- package/src/types/browser/lib/ActionWrapper.d.ts +62 -0
- package/src/types/browser/lib/ActionWrapper.d.ts.map +1 -0
- package/src/types/browser/lib/Activity.d.ts +122 -0
- package/src/types/browser/lib/Activity.d.ts.map +1 -0
- package/src/types/browser/lib/Piper.d.ts +52 -0
- package/src/types/browser/lib/Piper.d.ts.map +1 -0
- package/src/types/index.d.ts +7 -7
- package/src/types/lib/ActionHooks.d.ts +54 -97
- package/src/types/lib/ActionHooks.d.ts.map +1 -1
- /package/src/{lib → browser/lib}/ActionBuilder.js +0 -0
- /package/src/{lib → browser/lib}/ActionRunner.js +0 -0
- /package/src/{lib → browser/lib}/ActionWrapper.js +0 -0
- /package/src/{lib → browser/lib}/Activity.js +0 -0
- /package/src/{lib → browser/lib}/Piper.js +0 -0
package/src/lib/ActionHooks.js
CHANGED
|
@@ -1,60 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {FileObject, Sass} from "@gesslar/toolkit"
|
|
2
|
+
import {ActionHooks as BrowserActionHooks} from "../browser/index.js"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {(message: string, level?: number, ...args: Array<unknown>) => void} DebugFn
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @typedef {object}
|
|
9
|
+
* @typedef {object} NodeActionHooksConfig
|
|
10
10
|
* @property {string} actionKind Action identifier shared between runner and hooks.
|
|
11
|
-
* @property {FileObject} hooksFile File handle used to import the hooks module.
|
|
11
|
+
* @property {FileObject} [hooksFile] File handle used to import the hooks module.
|
|
12
12
|
* @property {unknown} [hooks] Already-instantiated hooks implementation (skips loading).
|
|
13
13
|
* @property {number} [hookTimeout] Timeout applied to hook execution in milliseconds.
|
|
14
14
|
* @property {DebugFn} debug Logger to emit diagnostics.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Node.js-enhanced ActionHooks that extends browser version with file-based hook loading.
|
|
19
|
+
* Inherits all browser functionality and adds FileObject-based hook import capability.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Generic base class for managing hooks with configurable event types.
|
|
23
|
-
* Provides common functionality for hook registration, execution, and lifecycle management.
|
|
24
|
-
* Designed to be extended by specific implementations.
|
|
25
|
-
*/
|
|
26
|
-
export default class ActionHooks {
|
|
21
|
+
export default class ActionHooks extends BrowserActionHooks {
|
|
27
22
|
/** @type {FileObject|null} */
|
|
28
23
|
#hooksFile = null
|
|
29
|
-
/** @type {HookModule|null} */
|
|
30
|
-
#hooks = null
|
|
31
|
-
/** @type {string|null} */
|
|
32
|
-
#actionKind = null
|
|
33
|
-
/** @type {number} */
|
|
34
|
-
#timeout = 1_000 // Default 1 second timeout
|
|
35
|
-
/** @type {DebugFn|null} */
|
|
36
|
-
#debug = null
|
|
37
24
|
|
|
38
25
|
/**
|
|
39
26
|
* Creates a new ActionHook instance.
|
|
40
27
|
*
|
|
41
|
-
* @param {
|
|
28
|
+
* @param {NodeActionHooksConfig} config Configuration values describing how to load the hooks.
|
|
42
29
|
*/
|
|
43
30
|
constructor({actionKind, hooksFile, hooks, hookTimeout = 1_000, debug}) {
|
|
44
|
-
|
|
31
|
+
super({actionKind, hooks, hookTimeout, debug})
|
|
45
32
|
this.#hooksFile = hooksFile
|
|
46
|
-
this.#hooks = hooks
|
|
47
|
-
this.#timeout = hookTimeout
|
|
48
|
-
this.#debug = debug
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Gets the action identifier.
|
|
53
|
-
*
|
|
54
|
-
* @returns {string} Action identifier or instance
|
|
55
|
-
*/
|
|
56
|
-
get actionKind() {
|
|
57
|
-
return this.#actionKind
|
|
58
33
|
}
|
|
59
34
|
|
|
60
35
|
/**
|
|
@@ -66,42 +41,6 @@ export default class ActionHooks {
|
|
|
66
41
|
return this.#hooksFile
|
|
67
42
|
}
|
|
68
43
|
|
|
69
|
-
/**
|
|
70
|
-
* Gets the loaded hooks object.
|
|
71
|
-
*
|
|
72
|
-
* @returns {object|null} Hooks object or null if not loaded
|
|
73
|
-
*/
|
|
74
|
-
get hooks() {
|
|
75
|
-
return this.#hooks
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Gets the hook execution timeout in milliseconds.
|
|
80
|
-
*
|
|
81
|
-
* @returns {number} Timeout in milliseconds
|
|
82
|
-
*/
|
|
83
|
-
get timeout() {
|
|
84
|
-
return this.#timeout
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Gets the setup hook function if available.
|
|
89
|
-
*
|
|
90
|
-
* @returns {(args: object) => unknown|null} Setup hook function or null
|
|
91
|
-
*/
|
|
92
|
-
get setup() {
|
|
93
|
-
return this.hooks?.setup || null
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Gets the cleanup hook function if available.
|
|
98
|
-
*
|
|
99
|
-
* @returns {(args: object) => unknown|null} Cleanup hook function or null
|
|
100
|
-
*/
|
|
101
|
-
get cleanup() {
|
|
102
|
-
return this.hooks?.cleanup || null
|
|
103
|
-
}
|
|
104
|
-
|
|
105
44
|
/**
|
|
106
45
|
* Static factory method to create and initialize a hook manager.
|
|
107
46
|
* Loads hooks from the specified file and returns an initialized instance.
|
|
@@ -114,125 +53,49 @@ export default class ActionHooks {
|
|
|
114
53
|
static async new(config, debug) {
|
|
115
54
|
debug("Creating new HookManager instance with args: %o", 2, config)
|
|
116
55
|
|
|
117
|
-
|
|
118
|
-
if(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
debug("Loading hooks from %o", 2, hooksFile.uri)
|
|
122
|
-
|
|
123
|
-
debug("Checking hooks file exists: %o", 2, hooksFile.uri)
|
|
124
|
-
if(!await hooksFile.exists)
|
|
125
|
-
throw Sass.new(`No such hooks file, ${hooksFile.uri}`)
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
const hooksImport = await hooksFile.import()
|
|
129
|
-
|
|
130
|
-
if(!hooksImport)
|
|
131
|
-
return null
|
|
132
|
-
|
|
133
|
-
debug("Hooks file imported successfully as a module", 2)
|
|
134
|
-
|
|
135
|
-
const actionKind = instance.actionKind
|
|
136
|
-
if(!hooksImport[actionKind])
|
|
137
|
-
return null
|
|
138
|
-
|
|
139
|
-
const hooks = new hooksImport[actionKind]({debug})
|
|
140
|
-
|
|
141
|
-
debug(hooks.constructor.name, 4)
|
|
142
|
-
|
|
143
|
-
instance.#hooks = hooks
|
|
144
|
-
debug("Hooks %o loaded successfully for %o", 2, hooksFile.uri, instance.actionKind)
|
|
145
|
-
|
|
146
|
-
return instance
|
|
147
|
-
} catch(error) {
|
|
148
|
-
debug("Failed to load hooks %o: %o", 1, hooksFile.uri, error.message)
|
|
149
|
-
|
|
150
|
-
return null
|
|
151
|
-
}
|
|
56
|
+
// If hooks already provided, use parent class factory
|
|
57
|
+
if(config.hooks) {
|
|
58
|
+
return super.new(config, debug)
|
|
152
59
|
}
|
|
153
60
|
|
|
154
|
-
|
|
155
|
-
|
|
61
|
+
// Load hooks from file
|
|
62
|
+
if(!config.hooksFile) {
|
|
63
|
+
debug("No hooks file provided", 2)
|
|
156
64
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*
|
|
160
|
-
* @param {'before'|'after'|'setup'|'cleanup'|string} kind Hook namespace.
|
|
161
|
-
* @param {string|symbol} activityName Activity identifier.
|
|
162
|
-
* @param {unknown} context Pipeline context supplied to the hook.
|
|
163
|
-
* @returns {Promise<void>}
|
|
164
|
-
*/
|
|
165
|
-
async callHook(kind, activityName, context) {
|
|
166
|
-
try {
|
|
167
|
-
const debug = this.#debug
|
|
168
|
-
const hooks = this.#hooks
|
|
169
|
-
|
|
170
|
-
if(!hooks)
|
|
171
|
-
return
|
|
172
|
-
|
|
173
|
-
const stringActivityName = Data.isType(activityName, "Symbol")
|
|
174
|
-
? activityName.description
|
|
175
|
-
: activityName
|
|
176
|
-
|
|
177
|
-
const hookName = this.#getActivityHookName(kind, stringActivityName)
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
178
67
|
|
|
179
|
-
|
|
68
|
+
const hooksFile = new FileObject(config.hooksFile)
|
|
180
69
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
70
|
+
debug("Loading hooks from %o", 2, hooksFile.uri)
|
|
71
|
+
debug("Checking hooks file exists: %o", 2, hooksFile.uri)
|
|
184
72
|
|
|
185
|
-
|
|
186
|
-
|
|
73
|
+
if(!await hooksFile.exists)
|
|
74
|
+
throw Sass.new(`No such hooks file, ${hooksFile.uri}`)
|
|
187
75
|
|
|
188
|
-
|
|
189
|
-
|
|
76
|
+
try {
|
|
77
|
+
const hooksImport = await hooksFile.import()
|
|
190
78
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
).cost
|
|
79
|
+
if(!hooksImport)
|
|
80
|
+
return null
|
|
194
81
|
|
|
195
|
-
|
|
196
|
-
}
|
|
82
|
+
debug("Hooks file imported successfully as a module", 2)
|
|
197
83
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
await timeout(hookTimeout)
|
|
201
|
-
throw Sass.new(`Hook ${hookName} execution exceeded timeout of ${hookTimeout}ms`)
|
|
202
|
-
})()
|
|
84
|
+
if(!hooksImport[config.actionKind])
|
|
85
|
+
return null
|
|
203
86
|
|
|
204
|
-
|
|
205
|
-
debug("Starting Promise race for hook: %o", 4, hookName)
|
|
206
|
-
await Promised.race([
|
|
207
|
-
hookFunction(),
|
|
208
|
-
expireAsync
|
|
209
|
-
])
|
|
210
|
-
} catch(error) {
|
|
211
|
-
throw Sass.new(`Processing hook ${kind}$${activityName}`, error)
|
|
212
|
-
}
|
|
87
|
+
const hooks = new hooksImport[config.actionKind]({debug})
|
|
213
88
|
|
|
214
|
-
debug(
|
|
89
|
+
debug(hooks.constructor.name, 4)
|
|
90
|
+
debug("Hooks loaded successfully for %o", 2, config.actionKind)
|
|
215
91
|
|
|
92
|
+
// Create instance with loaded hooks
|
|
93
|
+
return new ActionHooks({...config, hooks, debug})
|
|
216
94
|
} catch(error) {
|
|
217
|
-
|
|
95
|
+
debug("Failed to load hooks %o: %o", 1, hooksFile.uri, error.message)
|
|
96
|
+
|
|
97
|
+
return null
|
|
218
98
|
}
|
|
219
99
|
}
|
|
220
100
|
|
|
221
|
-
#getActivityHookName(event, activityName) {
|
|
222
|
-
const name = activityName
|
|
223
|
-
.split(" ")
|
|
224
|
-
.map(a => a.trim())
|
|
225
|
-
.filter(Boolean)
|
|
226
|
-
.map(a => a
|
|
227
|
-
.split("")
|
|
228
|
-
.filter(b => /[\w]/.test(b))
|
|
229
|
-
.filter(Boolean)
|
|
230
|
-
.join("")
|
|
231
|
-
)
|
|
232
|
-
.map(a => a.toLowerCase())
|
|
233
|
-
.map((a, i) => i === 0 ? a : Util.capitalize(a))
|
|
234
|
-
.join("")
|
|
235
|
-
|
|
236
|
-
return `${event}$${name}`
|
|
237
|
-
}
|
|
238
101
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as ActionBuilder } from "./lib/ActionBuilder.js";
|
|
2
|
+
export { default as ActionHooks } from "./lib/ActionHooks.js";
|
|
3
|
+
export { default as ActionRunner } from "./lib/ActionRunner.js";
|
|
4
|
+
export { default as ActionWrapper } from "./lib/ActionWrapper.js";
|
|
5
|
+
export { default as Piper } from "./lib/Piper.js";
|
|
6
|
+
export { default as Activity, ACTIVITY } from "./lib/Activity.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../browser/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/** @typedef {import("./ActionRunner.js").default} ActionRunner */
|
|
2
|
+
/** @typedef {typeof import("./Activity.js").ACTIVITY} ActivityFlags */
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {(message: string, level?: number, ...args: Array<unknown>) => void} DebugFn
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {object} ActionBuilderAction
|
|
8
|
+
* @property {(builder: ActionBuilder) => void} setup Function invoked during {@link ActionBuilder#build} to register activities.
|
|
9
|
+
* @property {symbol} [tag] Optional tag to reuse when reconstructing builders.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {object} ActionBuilderConfig
|
|
13
|
+
* @property {symbol} [tag] Optional tag for the builder instance.
|
|
14
|
+
* @property {DebugFn} [debug] Logger used by the pipeline internals.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {object} ActivityDefinition
|
|
18
|
+
* @property {ActionBuilderAction|null} action Parent action instance when available.
|
|
19
|
+
* @property {DebugFn|null} debug Logger function.
|
|
20
|
+
* @property {string|symbol} name Activity identifier.
|
|
21
|
+
* @property {ActionFunction|import("./ActionWrapper.js").default} op Operation to execute.
|
|
22
|
+
* @property {number} [kind] Optional kind flags from {@link ActivityFlags}.
|
|
23
|
+
* @property {(context: unknown) => boolean|Promise<boolean>} [pred] Loop predicate.
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {(context: unknown) => unknown|Promise<unknown>} ActionFunction
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Fluent builder for describing how an action should process the context that
|
|
30
|
+
* flows through the {@link ActionRunner}. Consumers register named activities,
|
|
31
|
+
* and nested parallel pipelines before handing the builder back to the runner
|
|
32
|
+
* for execution.
|
|
33
|
+
*
|
|
34
|
+
* Typical usage:
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* const pipeline = new ActionBuilder(myAction)
|
|
38
|
+
* .act("prepare", ACTIVITY.ONCE, ctx => ctx.initialise())
|
|
39
|
+
* .parallel(parallel => parallel
|
|
40
|
+
* .act("step", ACTIVITY.MANY, ctx => ctx.consume())
|
|
41
|
+
* )
|
|
42
|
+
* .act("finalise", ACTIVITY.ONCE, ctx => ctx.complete())
|
|
43
|
+
* .build()
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @class ActionBuilder
|
|
47
|
+
*/
|
|
48
|
+
export default class ActionBuilder {
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new ActionBuilder instance with the provided action callback.
|
|
51
|
+
*
|
|
52
|
+
* @param {ActionBuilderAction} [action] Base action invoked by the runner when a block satisfies the configured structure.
|
|
53
|
+
* @param {ActionBuilderConfig} [config] Options
|
|
54
|
+
*/
|
|
55
|
+
constructor(action?: ActionBuilderAction, { tag, debug }?: ActionBuilderConfig);
|
|
56
|
+
get tag(): symbol | null;
|
|
57
|
+
/**
|
|
58
|
+
* Register an activity that the runner can execute.
|
|
59
|
+
*
|
|
60
|
+
* Overloads:
|
|
61
|
+
* - do(name, op)
|
|
62
|
+
* - do(name, kind, pred, opOrWrapper)
|
|
63
|
+
* - do(name, kind, splitter, rejoiner, opOrWrapper)
|
|
64
|
+
*
|
|
65
|
+
* @overload
|
|
66
|
+
* @param {string|symbol} name Activity name
|
|
67
|
+
* @param {ActionFunction} op Operation to execute once.
|
|
68
|
+
* @returns {ActionBuilder}
|
|
69
|
+
*/
|
|
70
|
+
do(name: string | symbol, op: ActionFunction): ActionBuilder;
|
|
71
|
+
/**
|
|
72
|
+
* @overload
|
|
73
|
+
* @param {string|symbol} name Activity name
|
|
74
|
+
* @param {number} kind Kind bitfield from {@link ActivityFlags}.
|
|
75
|
+
* @param {(context: unknown) => boolean|Promise<boolean>} pred Predicate executed before/after the op.
|
|
76
|
+
* @param {ActionFunction|import("./ActionWrapper.js").default} op Operation or nested wrapper to execute.
|
|
77
|
+
* @returns {ActionBuilder}
|
|
78
|
+
*/
|
|
79
|
+
do(name: string | symbol, kind: number, pred: (context: unknown) => boolean | Promise<boolean>, op: ActionFunction | import("./ActionWrapper.js").default): ActionBuilder;
|
|
80
|
+
/**
|
|
81
|
+
* @overload
|
|
82
|
+
* @param {string|symbol} name Activity name
|
|
83
|
+
* @param {number} kind ACTIVITY.SPLIT flag.
|
|
84
|
+
* @param {(context: unknown) => unknown} splitter Splitter function for SPLIT mode.
|
|
85
|
+
* @param {(originalContext: unknown, splitResults: unknown) => unknown} rejoiner Rejoiner function for SPLIT mode.
|
|
86
|
+
* @param {ActionFunction|import("./ActionWrapper.js").default} op Operation or nested wrapper to execute.
|
|
87
|
+
* @returns {ActionBuilder}
|
|
88
|
+
*/
|
|
89
|
+
do(name: string | symbol, kind: number, splitter: (context: unknown) => unknown, rejoiner: (originalContext: unknown, splitResults: unknown) => unknown, op: ActionFunction | import("./ActionWrapper.js").default): ActionBuilder;
|
|
90
|
+
/**
|
|
91
|
+
* Configure hooks to be loaded from a file when the action is built.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} hooksFile Path to the hooks module file.
|
|
94
|
+
* @param {string} hooksKind Name of the exported hooks class to instantiate.
|
|
95
|
+
* @returns {ActionBuilder} The builder instance for chaining.
|
|
96
|
+
* @throws {Sass} If hooks have already been configured.
|
|
97
|
+
*/
|
|
98
|
+
withHooksFile(hooksFile: string, hooksKind: string): ActionBuilder;
|
|
99
|
+
/**
|
|
100
|
+
* Configure hooks using a pre-instantiated hooks object.
|
|
101
|
+
*
|
|
102
|
+
* @param {import("./ActionHooks.js").default} hooks An already-instantiated hooks instance.
|
|
103
|
+
* @returns {ActionBuilder} The builder instance for chaining.
|
|
104
|
+
* @throws {Sass} If hooks have already been configured with a different instance.
|
|
105
|
+
*/
|
|
106
|
+
withHooks(hooks: import("./ActionHooks.js").default): ActionBuilder;
|
|
107
|
+
/**
|
|
108
|
+
* Configure the action instance if not already set.
|
|
109
|
+
* Used to propagate parent action context to nested builders.
|
|
110
|
+
*
|
|
111
|
+
* @param {ActionBuilderAction} action The action instance to inherit.
|
|
112
|
+
* @returns {ActionBuilder} The builder instance for chaining.
|
|
113
|
+
*/
|
|
114
|
+
withAction(action: ActionBuilderAction): ActionBuilder;
|
|
115
|
+
/**
|
|
116
|
+
* Finalises the builder and returns a payload that can be consumed by the
|
|
117
|
+
* runner.
|
|
118
|
+
*
|
|
119
|
+
* @returns {Promise<import("./ActionWrapper.js").default>} Payload consumed by the {@link ActionRunner} constructor.
|
|
120
|
+
*/
|
|
121
|
+
build(): Promise<import("./ActionWrapper.js").default>;
|
|
122
|
+
#private;
|
|
123
|
+
}
|
|
124
|
+
export type ActionRunner = import("./ActionRunner.js").default;
|
|
125
|
+
export type ActivityFlags = typeof import("./Activity.js").ACTIVITY;
|
|
126
|
+
export type DebugFn = (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
127
|
+
export type ActionBuilderAction = {
|
|
128
|
+
/**
|
|
129
|
+
* Function invoked during {@link ActionBuilder#build} to register activities.
|
|
130
|
+
*/
|
|
131
|
+
setup: (builder: ActionBuilder) => void;
|
|
132
|
+
/**
|
|
133
|
+
* Optional tag to reuse when reconstructing builders.
|
|
134
|
+
*/
|
|
135
|
+
tag?: symbol | undefined;
|
|
136
|
+
};
|
|
137
|
+
export type ActionBuilderConfig = {
|
|
138
|
+
/**
|
|
139
|
+
* Optional tag for the builder instance.
|
|
140
|
+
*/
|
|
141
|
+
tag?: symbol | undefined;
|
|
142
|
+
/**
|
|
143
|
+
* Logger used by the pipeline internals.
|
|
144
|
+
*/
|
|
145
|
+
debug?: DebugFn | undefined;
|
|
146
|
+
};
|
|
147
|
+
export type ActivityDefinition = {
|
|
148
|
+
/**
|
|
149
|
+
* Parent action instance when available.
|
|
150
|
+
*/
|
|
151
|
+
action: ActionBuilderAction | null;
|
|
152
|
+
/**
|
|
153
|
+
* Logger function.
|
|
154
|
+
*/
|
|
155
|
+
debug: DebugFn | null;
|
|
156
|
+
/**
|
|
157
|
+
* Activity identifier.
|
|
158
|
+
*/
|
|
159
|
+
name: string | symbol;
|
|
160
|
+
/**
|
|
161
|
+
* Operation to execute.
|
|
162
|
+
*/
|
|
163
|
+
op: ActionFunction | import("./ActionWrapper.js").default;
|
|
164
|
+
/**
|
|
165
|
+
* Optional kind flags from {@link ActivityFlags}.
|
|
166
|
+
*/
|
|
167
|
+
kind?: number | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Loop predicate.
|
|
170
|
+
*/
|
|
171
|
+
pred?: ((context: unknown) => boolean | Promise<boolean>) | undefined;
|
|
172
|
+
};
|
|
173
|
+
export type ActionFunction = (context: unknown) => unknown | Promise<unknown>;
|
|
174
|
+
//# sourceMappingURL=ActionBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionBuilder.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionBuilder.js"],"names":[],"mappings":"AAMA,kEAAkE;AAClE,uEAAuE;AAEvE;;GAEG;AAEH;;;;GAIG;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IAaE;;;;;OAKG;IACH,qBAHW,mBAAmB,mBACnB,mBAAmB,EAe7B;IAED,yBAEC;;;;;;;;;;;;;;IAUE,SACQ,MAAM,GAAC,MAAM,MACb,cAAc,GACZ,aAAa,CACzB;;;;;;;;;IAGE,SACQ,MAAM,GAAC,MAAM,QACb,MAAM,QACN,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,MAC9C,cAAc,GAAC,OAAO,oBAAoB,EAAE,OAAO,GACjD,aAAa,CACzB;;;;;;;;;;IAGE,SACQ,MAAM,GAAC,MAAM,QACb,MAAM,YACN,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,YAC7B,CAAC,eAAe,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,KAAK,OAAO,MAC5D,cAAc,GAAC,OAAO,oBAAoB,EAAE,OAAO,GACjD,aAAa,CACzB;IA0DD;;;;;;;OAOG;IACH,yBALW,MAAM,aACN,MAAM,GACJ,aAAa,CAYzB;IAED;;;;;;OAMG;IACH,iBAJW,OAAO,kBAAkB,EAAE,OAAO,GAChC,aAAa,CAgBzB;IAED;;;;;;OAMG;IACH,mBAHW,mBAAmB,GACjB,aAAa,CAczB;IAeD;;;;;OAKG;IACH,SAFa,OAAO,CAAC,OAAO,oBAAoB,EAAE,OAAO,CAAC,CAmBzD;;CAqBF;2BA3Sa,OAAO,mBAAmB,EAAE,OAAO;4BACnC,cAAc,eAAe,EAAE,QAAQ;sBAGxC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;;;;WAKjE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;YAYhC,mBAAmB,GAAC,IAAI;;;;WACxB,OAAO,GAAC,IAAI;;;;UACZ,MAAM,GAAC,MAAM;;;;QACb,cAAc,GAAC,OAAO,oBAAoB,EAAE,OAAO;;;;;;;;sBAEzC,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC;;6BAI/C,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {(message: string, level?: number, ...args: Array<unknown>) => void} DebugFn
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} ActionHooksConfig
|
|
6
|
+
* @property {string} actionKind Action identifier shared between runner and hooks.
|
|
7
|
+
* @property {unknown} hooks Already-instantiated hooks implementation.
|
|
8
|
+
* @property {number} [hookTimeout] Timeout applied to hook execution in milliseconds.
|
|
9
|
+
* @property {DebugFn} debug Logger to emit diagnostics.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Record<string, (context: unknown) => Promise<unknown>|unknown>} HookModule
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Generic base class for managing hooks with configurable event types.
|
|
16
|
+
* Provides common functionality for hook registration, execution, and lifecycle management.
|
|
17
|
+
* Designed to be extended by specific implementations.
|
|
18
|
+
*
|
|
19
|
+
* Browser version: Requires pre-instantiated hooks. File-based loading is not supported.
|
|
20
|
+
*/
|
|
21
|
+
export default class ActionHooks {
|
|
22
|
+
/**
|
|
23
|
+
* Static factory method to create and initialize a hook manager.
|
|
24
|
+
* Browser version: Only works with pre-instantiated hooks passed via config.hooks.
|
|
25
|
+
*
|
|
26
|
+
* @param {ActionHooksConfig} config Configuration object with hooks property
|
|
27
|
+
* @param {DebugFn} debug The debug function.
|
|
28
|
+
* @returns {Promise<ActionHooks|null>} Initialized hook manager or null if no hooks provided
|
|
29
|
+
*/
|
|
30
|
+
static "new"(config: ActionHooksConfig, debug: DebugFn): Promise<ActionHooks | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new ActionHook instance.
|
|
33
|
+
*
|
|
34
|
+
* @param {ActionHooksConfig} config Configuration values describing how to load the hooks.
|
|
35
|
+
*/
|
|
36
|
+
constructor({ actionKind, hooks, hookTimeout, debug }: ActionHooksConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Gets the action identifier.
|
|
39
|
+
*
|
|
40
|
+
* @returns {string} Action identifier or instance
|
|
41
|
+
*/
|
|
42
|
+
get actionKind(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the loaded hooks object.
|
|
45
|
+
*
|
|
46
|
+
* @returns {object|null} Hooks object or null if not loaded
|
|
47
|
+
*/
|
|
48
|
+
get hooks(): object | null;
|
|
49
|
+
/**
|
|
50
|
+
* Gets the hook execution timeout in milliseconds.
|
|
51
|
+
*
|
|
52
|
+
* @returns {number} Timeout in milliseconds
|
|
53
|
+
*/
|
|
54
|
+
get timeout(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the setup hook function if available.
|
|
57
|
+
*
|
|
58
|
+
* @returns {(args: object) => unknown|null} Setup hook function or null
|
|
59
|
+
*/
|
|
60
|
+
get setup(): (args: object) => unknown | null;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the cleanup hook function if available.
|
|
63
|
+
*
|
|
64
|
+
* @returns {(args: object) => unknown|null} Cleanup hook function or null
|
|
65
|
+
*/
|
|
66
|
+
get cleanup(): (args: object) => unknown | null;
|
|
67
|
+
/**
|
|
68
|
+
* Invoke a dynamically-named hook such as `before$foo`.
|
|
69
|
+
*
|
|
70
|
+
* @param {'before'|'after'|'setup'|'cleanup'|string} kind Hook namespace.
|
|
71
|
+
* @param {string|symbol} activityName Activity identifier.
|
|
72
|
+
* @param {unknown} context Pipeline context supplied to the hook.
|
|
73
|
+
* @returns {Promise<void>}
|
|
74
|
+
*/
|
|
75
|
+
callHook(kind: "before" | "after" | "setup" | "cleanup" | string, activityName: string | symbol, context: unknown): Promise<void>;
|
|
76
|
+
#private;
|
|
77
|
+
}
|
|
78
|
+
export type DebugFn = (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
79
|
+
export type ActionHooksConfig = {
|
|
80
|
+
/**
|
|
81
|
+
* Action identifier shared between runner and hooks.
|
|
82
|
+
*/
|
|
83
|
+
actionKind: string;
|
|
84
|
+
/**
|
|
85
|
+
* Already-instantiated hooks implementation.
|
|
86
|
+
*/
|
|
87
|
+
hooks: unknown;
|
|
88
|
+
/**
|
|
89
|
+
* Timeout applied to hook execution in milliseconds.
|
|
90
|
+
*/
|
|
91
|
+
hookTimeout?: number | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Logger to emit diagnostics.
|
|
94
|
+
*/
|
|
95
|
+
debug: DebugFn;
|
|
96
|
+
};
|
|
97
|
+
export type HookModule = Record<string, (context: unknown) => Promise<unknown> | unknown>;
|
|
98
|
+
//# sourceMappingURL=ActionHooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionHooks.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionHooks.js"],"names":[],"mappings":"AAEA;;GAEG;AAEH;;;;;;GAMG;AAEH;;GAEG;AAEH;;;;;;GAMG;AACH;IAmEE;;;;;;;OAOG;IACH,qBAJW,iBAAiB,SACjB,OAAO,GACL,OAAO,CAAC,WAAW,GAAC,IAAI,CAAC,CAgBrC;IA/ED;;;;OAIG;IACH,uDAFW,iBAAiB,EAO3B;IAED;;;;OAIG;IACH,kBAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,aAFa,MAAM,GAAC,IAAI,CAIvB;IAED;;;;OAIG;IACH,eAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,aAFa,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAC,IAAI,CAI1C;IAED;;;;OAIG;IACH,eAFa,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAC,IAAI,CAI1C;IA0BD;;;;;;;OAOG;IACH,eALW,QAAQ,GAAC,OAAO,GAAC,OAAO,GAAC,SAAS,GAAC,MAAM,gBACzC,MAAM,GAAC,MAAM,WACb,OAAO,GACL,OAAO,CAAC,IAAI,CAAC,CAwDzB;;CAmBF;sBAlMY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;;;;gBAKjE,MAAM;;;;WACN,OAAO;;;;;;;;WAEP,OAAO;;yBAIR,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,GAAC,OAAO,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {(message: string, level?: number, ...args: Array<unknown>) => void} DebugFn
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} ActionRunnerOptions
|
|
6
|
+
* @property {DebugFn} [debug] Logger function.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Orchestrates execution of {@link ActionBuilder}-produced pipelines.
|
|
10
|
+
*
|
|
11
|
+
* Activities run in insertion order, with support for once-off work, repeated
|
|
12
|
+
* loops, and nested parallel pipelines. Each activity receives a mutable
|
|
13
|
+
* context object under `result.value` that can be replaced or enriched.
|
|
14
|
+
*/
|
|
15
|
+
export default class ActionRunner extends Piper {
|
|
16
|
+
/**
|
|
17
|
+
* Instantiate a runner over an optional action wrapper.
|
|
18
|
+
*
|
|
19
|
+
* @param {import("./ActionBuilder.js").default|null} actionBuilder ActionBuilder to build.
|
|
20
|
+
* @param {ActionRunnerOptions} [options] Optional debug overrides.
|
|
21
|
+
*/
|
|
22
|
+
constructor(actionBuilder: import("./ActionBuilder.js").default | null, { debug }?: ActionRunnerOptions);
|
|
23
|
+
/**
|
|
24
|
+
* Executes the configured action pipeline.
|
|
25
|
+
* Builds the ActionWrapper on first run and caches it for subsequent calls.
|
|
26
|
+
* Supports WHILE, UNTIL, and SPLIT activity kinds.
|
|
27
|
+
*
|
|
28
|
+
* @param {unknown} context - Seed value passed to the first activity.
|
|
29
|
+
* @returns {Promise<unknown>} Final value produced by the pipeline.
|
|
30
|
+
* @throws {Sass} When no activities are registered, conflicting activity kinds are used, or execution fails.
|
|
31
|
+
*/
|
|
32
|
+
run(context: unknown): Promise<unknown>;
|
|
33
|
+
#private;
|
|
34
|
+
}
|
|
35
|
+
export type DebugFn = (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
36
|
+
export type ActionRunnerOptions = {
|
|
37
|
+
/**
|
|
38
|
+
* Logger function.
|
|
39
|
+
*/
|
|
40
|
+
debug?: DebugFn | undefined;
|
|
41
|
+
};
|
|
42
|
+
import Piper from "./Piper.js";
|
|
43
|
+
//# sourceMappingURL=ActionRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionRunner.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionRunner.js"],"names":[],"mappings":"AAKA;;GAEG;AAEH;;;GAGG;AACH;;;;;;GAMG;AACH;IAaE;;;;;OAKG;IACH,2BAHW,OAAO,oBAAoB,EAAE,OAAO,GAAC,IAAI,cACzC,mBAAmB,EAkB7B;IAED;;;;;;;;OAQG;IACH,aAJW,OAAO,GACL,OAAO,CAAC,OAAO,CAAC,CAuG5B;;CA0FF;sBA1PY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;;;;;;kBAH7D,YAAY"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} WrappedActivityConfig
|
|
3
|
+
* @property {string|symbol} name Activity identifier used by hooks/logs.
|
|
4
|
+
* @property {(context: unknown) => unknown|Promise<unknown>|ActionWrapper} op Operation or nested wrapper to execute.
|
|
5
|
+
* @property {number} [kind] Optional loop semantic flags.
|
|
6
|
+
* @property {(context: unknown) => boolean|Promise<boolean>} [pred] Predicate tied to WHILE/UNTIL semantics.
|
|
7
|
+
* @property {unknown} [action] Parent action instance supplied when invoking the op.
|
|
8
|
+
* @property {(message: string, level?: number, ...args: Array<unknown>) => void} [debug] Optional logger reference.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Generator<Activity, void, unknown>} ActivityIterator
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Thin wrapper that materialises {@link Activity} instances on demand.
|
|
15
|
+
*/
|
|
16
|
+
export default class ActionWrapper {
|
|
17
|
+
/**
|
|
18
|
+
* Create a wrapper from the builder payload.
|
|
19
|
+
*
|
|
20
|
+
* @param {{activities: Map<string|symbol, WrappedActivityConfig>, debug: (message: string, level?: number, ...args: Array<unknown>) => void}} init Builder payload containing activities + logger.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ activities, hooks, debug }: {
|
|
23
|
+
activities: Map<string | symbol, WrappedActivityConfig>;
|
|
24
|
+
debug: (message: string, level?: number, ...args: Array<unknown>) => void;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Iterator over the registered activities.
|
|
28
|
+
*
|
|
29
|
+
* @returns {ActivityIterator} Lazy iterator yielding Activity instances.
|
|
30
|
+
*/
|
|
31
|
+
get activities(): ActivityIterator;
|
|
32
|
+
#private;
|
|
33
|
+
}
|
|
34
|
+
export type WrappedActivityConfig = {
|
|
35
|
+
/**
|
|
36
|
+
* Activity identifier used by hooks/logs.
|
|
37
|
+
*/
|
|
38
|
+
name: string | symbol;
|
|
39
|
+
/**
|
|
40
|
+
* Operation or nested wrapper to execute.
|
|
41
|
+
*/
|
|
42
|
+
op: (context: unknown) => unknown | Promise<unknown> | ActionWrapper;
|
|
43
|
+
/**
|
|
44
|
+
* Optional loop semantic flags.
|
|
45
|
+
*/
|
|
46
|
+
kind?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Predicate tied to WHILE/UNTIL semantics.
|
|
49
|
+
*/
|
|
50
|
+
pred?: ((context: unknown) => boolean | Promise<boolean>) | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Parent action instance supplied when invoking the op.
|
|
53
|
+
*/
|
|
54
|
+
action?: unknown;
|
|
55
|
+
/**
|
|
56
|
+
* Optional logger reference.
|
|
57
|
+
*/
|
|
58
|
+
debug?: ((message: string, level?: number, ...args: Array<unknown>) => void) | undefined;
|
|
59
|
+
};
|
|
60
|
+
export type ActivityIterator = Generator<Activity, void, unknown>;
|
|
61
|
+
import Activity from "./Activity.js";
|
|
62
|
+
//# sourceMappingURL=ActionWrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ActionWrapper.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionWrapper.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH;;GAEG;AAEH;;GAEG;AACH;IAgBE;;;;OAIG;IACH,0CAFW;QAAC,UAAU,EAAE,GAAG,CAAC,MAAM,GAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;QAAC,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,CAAA;KAAC,EAW5I;IAOD;;;;OAIG;IACH,kBAFa,gBAAgB,CAI5B;;CACF;;;;;UA5Da,MAAM,GAAC,MAAM;;;;QACb,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,GAAC,aAAa;;;;;;;;sBAElD,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC;;;;aAC9C,OAAO;;;;uBACG,MAAM,UAAU,MAAM,WAAW,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;+BAInE,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC;qBAb1B,eAAe"}
|