@gesslar/actioneer 3.0.2 → 3.1.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/package.json +1 -1
- package/src/browser/lib/ActionBuilder.js +20 -4
- package/src/browser/lib/ActionRunner.js +29 -13
- package/src/browser/lib/ActionWrapper.js +9 -0
- package/src/browser/lib/Piper.js +2 -2
- package/src/index.js +9 -4
- package/src/lib/ActionHooks.js +4 -4
- package/src/types/browser/lib/ActionBuilder.d.ts +9 -0
- package/src/types/browser/lib/ActionBuilder.d.ts.map +1 -1
- package/src/types/browser/lib/ActionRunner.d.ts.map +1 -1
- package/src/types/browser/lib/ActionWrapper.d.ts +6 -0
- package/src/types/browser/lib/ActionWrapper.d.ts.map +1 -1
- package/src/types/index.d.ts +3 -2
- package/src/types/index.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -51,6 +51,16 @@ import {ACTIVITY} from "./Activity.js"
|
|
|
51
51
|
* @class ActionBuilder
|
|
52
52
|
*/
|
|
53
53
|
export default class ActionBuilder {
|
|
54
|
+
/**
|
|
55
|
+
* The ActionHooks class used to resolve hooks. Defaults to the
|
|
56
|
+
* browser-compatible implementation (pre-instantiated hooks only). The Node
|
|
57
|
+
* entry point overrides this with the file-loading subclass so that
|
|
58
|
+
* {@link ActionBuilder#withHooksFile} works.
|
|
59
|
+
*
|
|
60
|
+
* @type {typeof ActionHooks}
|
|
61
|
+
*/
|
|
62
|
+
static HooksClass = ActionHooks
|
|
63
|
+
|
|
54
64
|
/** @type {ActionBuilderAction?} */
|
|
55
65
|
#action = null
|
|
56
66
|
/** @type {Map<string|symbol, ActivityDefinition>} */
|
|
@@ -334,23 +344,29 @@ export default class ActionBuilder {
|
|
|
334
344
|
}
|
|
335
345
|
|
|
336
346
|
async #getHooks() {
|
|
337
|
-
const
|
|
347
|
+
const HooksClass = ActionBuilder.HooksClass
|
|
338
348
|
|
|
339
349
|
const hooks = this.#hooks
|
|
340
350
|
if(hooks) {
|
|
341
|
-
// If hooks is already an ActionHooks instance, use it directly
|
|
351
|
+
// If hooks is already an ActionHooks instance, use it directly.
|
|
352
|
+
// The base class catches subclass instances too.
|
|
342
353
|
if(hooks instanceof ActionHooks)
|
|
343
354
|
return hooks
|
|
344
355
|
|
|
345
356
|
// Otherwise, wrap it in a new ActionHooks instance
|
|
346
|
-
return await
|
|
357
|
+
return await HooksClass.new({hooks}, this.#debug)
|
|
347
358
|
}
|
|
348
359
|
|
|
349
360
|
const hooksFile = this.#hooksFile
|
|
350
361
|
const hooksKind = this.#hooksKind
|
|
351
362
|
|
|
363
|
+
// File loading is only available on the Node HooksClass; the loader keys the
|
|
364
|
+
// class to instantiate off `actionKind`.
|
|
352
365
|
if(hooksFile && hooksKind)
|
|
353
|
-
return await
|
|
366
|
+
return await HooksClass.new(
|
|
367
|
+
{hooksFile, actionKind: hooksKind},
|
|
368
|
+
this.#debug,
|
|
369
|
+
)
|
|
354
370
|
}
|
|
355
371
|
|
|
356
372
|
/**
|
|
@@ -63,7 +63,25 @@ export default class ActionRunner extends Piper {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
66
|
+
* Builds the ActionWrapper on first use and caches it for subsequent calls.
|
|
67
|
+
*
|
|
68
|
+
* Hooks are configured by the action's `setup()`, which only runs during
|
|
69
|
+
* `build()`. The setup/cleanup lifecycle hooks fire from {@link Piper#pipe}
|
|
70
|
+
* before any item is processed, so the wrapper must be built here too —
|
|
71
|
+
* otherwise the resolved hooks would not yet exist when setup runs.
|
|
72
|
+
*
|
|
73
|
+
* @returns {Promise<import("./ActionWrapper.js").default>} The built wrapper.
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
async #ensureBuilt() {
|
|
77
|
+
if(!this.#actionWrapper)
|
|
78
|
+
this.#actionWrapper = await this.#actionBuilder.build(this)
|
|
79
|
+
|
|
80
|
+
return this.#actionWrapper
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Invokes the `setup` lifecycle hook on the resolved hooks object, if defined.
|
|
67
85
|
* Registered as a Piper setup step so it fires before any items are processed.
|
|
68
86
|
*
|
|
69
87
|
* @param {unknown} ctx - Value passed by {@link Piper#pipe} (the items array).
|
|
@@ -71,29 +89,30 @@ export default class ActionRunner extends Piper {
|
|
|
71
89
|
* @private
|
|
72
90
|
*/
|
|
73
91
|
async #setupHooks(ctx) {
|
|
74
|
-
const
|
|
75
|
-
const ah =
|
|
92
|
+
const wrapper = await this.#ensureBuilt()
|
|
93
|
+
const ah = wrapper.hooks
|
|
76
94
|
const setup = ah?.setup
|
|
77
95
|
|
|
78
96
|
if(setup)
|
|
79
|
-
await setup.call(ah, ctx)
|
|
97
|
+
await setup.call(ah.hooks, ctx)
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
/**
|
|
83
|
-
* Invokes the `cleanup` lifecycle hook on the
|
|
84
|
-
* Registered as a Piper teardown step so it fires after all items
|
|
101
|
+
* Invokes the `cleanup` lifecycle hook on the resolved hooks object, if
|
|
102
|
+
* defined. Registered as a Piper teardown step so it fires after all items
|
|
103
|
+
* are processed.
|
|
85
104
|
*
|
|
86
105
|
* @param {unknown} ctx - Value passed by {@link Piper#pipe} (the items array).
|
|
87
106
|
* @returns {Promise<void>}
|
|
88
107
|
* @private
|
|
89
108
|
*/
|
|
90
109
|
async #cleanupHooks(ctx) {
|
|
91
|
-
const
|
|
92
|
-
const ah =
|
|
110
|
+
const wrapper = await this.#ensureBuilt()
|
|
111
|
+
const ah = wrapper.hooks
|
|
93
112
|
const cleanup = ah?.cleanup
|
|
94
113
|
|
|
95
114
|
if(cleanup)
|
|
96
|
-
await cleanup.call(ah, ctx)
|
|
115
|
+
await cleanup.call(ah.hooks, ctx)
|
|
97
116
|
}
|
|
98
117
|
|
|
99
118
|
/**
|
|
@@ -108,10 +127,7 @@ export default class ActionRunner extends Piper {
|
|
|
108
127
|
* @throws {Tantrum} When both an activity and the done callback fail.
|
|
109
128
|
*/
|
|
110
129
|
async run(context, parentWrapper=null) {
|
|
111
|
-
|
|
112
|
-
this.#actionWrapper = await this.#actionBuilder.build(this)
|
|
113
|
-
|
|
114
|
-
const actionWrapper = this.#actionWrapper
|
|
130
|
+
const actionWrapper = await this.#ensureBuilt()
|
|
115
131
|
const activities = Array.from(actionWrapper.activities)
|
|
116
132
|
|
|
117
133
|
let caughtError = null
|
|
@@ -113,4 +113,13 @@ export default class ActionWrapper {
|
|
|
113
113
|
get action() {
|
|
114
114
|
return this.#action
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get the resolved hooks manager.
|
|
119
|
+
*
|
|
120
|
+
* @returns {import("./ActionHooks.js").default?} Hooks manager or null.
|
|
121
|
+
*/
|
|
122
|
+
get hooks() {
|
|
123
|
+
return this.#hooks
|
|
124
|
+
}
|
|
116
125
|
}
|
package/src/browser/lib/Piper.js
CHANGED
|
@@ -170,9 +170,9 @@ export default class Piper extends NotifyClass {
|
|
|
170
170
|
* @param {Array<unknown>} settled - Results from settleAll
|
|
171
171
|
* @throws {Tantrum} - If any settled result was rejected
|
|
172
172
|
*/
|
|
173
|
-
#processResult(
|
|
173
|
+
#processResult(message, settled) {
|
|
174
174
|
if(Promised.hasRejected(settled))
|
|
175
|
-
Promised.throw(settled)
|
|
175
|
+
Promised.throw(message, settled)
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/**
|
package/src/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// Browser-compatible base classes
|
|
2
|
-
|
|
2
|
+
import ActionBuilder from "./browser/lib/ActionBuilder.js"
|
|
3
|
+
import ActionHooks from "./lib/ActionHooks.js"
|
|
4
|
+
|
|
5
|
+
// Node-enhanced ActionHooks (extends browser, adds FileObject support). Wiring
|
|
6
|
+
// it into the builder makes withHooksFile() load hooks from disk under the Node
|
|
7
|
+
// entry point, while the browser entry keeps the pre-instantiated-only default.
|
|
8
|
+
ActionBuilder.HooksClass = ActionHooks
|
|
9
|
+
|
|
10
|
+
export {ActionBuilder, ActionHooks}
|
|
3
11
|
export {default as ActionRunner} from "./browser/lib/ActionRunner.js"
|
|
4
12
|
export {default as ActionWrapper} from "./browser/lib/ActionWrapper.js"
|
|
5
13
|
export {default as Activity, ACTIVITY} from "./browser/lib/Activity.js"
|
|
6
14
|
export {default as Piper} from "./browser/lib/Piper.js"
|
|
7
|
-
|
|
8
|
-
// Node-enhanced version (extends browser, adds FileObject support)
|
|
9
|
-
export {default as ActionHooks} from "./lib/ActionHooks.js"
|
package/src/lib/ActionHooks.js
CHANGED
|
@@ -75,11 +75,11 @@ export default class ActionHooks extends BrowserActionHooks {
|
|
|
75
75
|
|
|
76
76
|
const hooksFile = new FileObject(config.hooksFile)
|
|
77
77
|
|
|
78
|
-
debug("Loading hooks from %o", 2, hooksFile.
|
|
79
|
-
debug("Checking hooks file exists: %o", 2, hooksFile.
|
|
78
|
+
debug("Loading hooks from %o", 2, hooksFile.path)
|
|
79
|
+
debug("Checking hooks file exists: %o", 2, hooksFile.path)
|
|
80
80
|
|
|
81
81
|
if(!await hooksFile.exists)
|
|
82
|
-
throw Sass.new(`No such hooks file, ${hooksFile.
|
|
82
|
+
throw Sass.new(`No such hooks file, ${hooksFile.path}`)
|
|
83
83
|
|
|
84
84
|
try {
|
|
85
85
|
const hooksImport = await hooksFile.import()
|
|
@@ -100,7 +100,7 @@ export default class ActionHooks extends BrowserActionHooks {
|
|
|
100
100
|
// Create instance with loaded hooks
|
|
101
101
|
return new ActionHooks({...config, hooks, debug})
|
|
102
102
|
} catch(error) {
|
|
103
|
-
debug("Failed to load hooks %o: %o", 1, hooksFile.
|
|
103
|
+
debug("Failed to load hooks %o: %o", 1, hooksFile.path, error.message)
|
|
104
104
|
|
|
105
105
|
return null
|
|
106
106
|
}
|
|
@@ -44,6 +44,15 @@
|
|
|
44
44
|
* @class ActionBuilder
|
|
45
45
|
*/
|
|
46
46
|
export default class ActionBuilder {
|
|
47
|
+
/**
|
|
48
|
+
* The ActionHooks class used to resolve hooks. Defaults to the
|
|
49
|
+
* browser-compatible implementation (pre-instantiated hooks only). The Node
|
|
50
|
+
* entry point overrides this with the file-loading subclass so that
|
|
51
|
+
* {@link ActionBuilder#withHooksFile} works.
|
|
52
|
+
*
|
|
53
|
+
* @type {typeof ActionHooks}
|
|
54
|
+
*/
|
|
55
|
+
static HooksClass: typeof ActionHooks;
|
|
47
56
|
/**
|
|
48
57
|
* Creates a new ActionBuilder instance with the provided action callback.
|
|
49
58
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionBuilder.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionBuilder.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH;
|
|
1
|
+
{"version":3,"file":"ActionBuilder.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionBuilder.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IACE;;;;;;;OAOG;IACH,mBAFU,OAAO,WAAW,CAEG;IAmB/B;;;;;OAKG;IACH,qBAHW,mBAAmB,mBACnB,mBAAmB,EAkB7B;IAED,yBAEC;;;;;;;;;;;;;;;IAWE,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,GAC5C,aAAa,CACzB;;;;;;;;;IAGE,SACQ,MAAM,GAAC,MAAM,QACb,MAAM,QACN,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,MAC9C,cAAc,GAAC,aAAa,GAC1B,aAAa,CACzB;;;;;;;;;;IAGE,SACQ,MAA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G;AACH;IAaE;;;;;OAKG;IACH,2BAHW,OAAO,oBAAoB,EAAE,OAAO,GAAC,IAAI,cACzC,mBAAmB,EAoB7B;
|
|
1
|
+
{"version":3,"file":"ActionRunner.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionRunner.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH;;;;;GAKG;AAEH;;;;;;GAMG;AACH;IAaE;;;;;OAKG;IACH,2BAHW,OAAO,oBAAoB,EAAE,OAAO,GAAC,IAAI,cACzC,mBAAmB,EAoB7B;IAuDD;;;;;;;;;;OAUG;IACH,aANW,OAAO,kBACP,OAAO,oBAAoB,EAAE,OAAO,GAAC,IAAI,GACvC,OAAO,CAAC,OAAO,CAAC,CAiJ5B;;CAiGF;sBAlWY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI;;;;;;;kBAT7D,YAAY"}
|
|
@@ -58,6 +58,12 @@ export default class ActionWrapper {
|
|
|
58
58
|
* @returns {unknown|null} Action instance or null.
|
|
59
59
|
*/
|
|
60
60
|
get action(): unknown | null;
|
|
61
|
+
/**
|
|
62
|
+
* Get the resolved hooks manager.
|
|
63
|
+
*
|
|
64
|
+
* @returns {import("./ActionHooks.js").default?} Hooks manager or null.
|
|
65
|
+
*/
|
|
66
|
+
get hooks(): import("./ActionHooks.js").default | null;
|
|
61
67
|
#private;
|
|
62
68
|
}
|
|
63
69
|
export type WrappedActivityConfig = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionWrapper.d.ts","sourceRoot":"","sources":["../../../browser/lib/ActionWrapper.js"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;;GAEG;AACH;IAwBE;;;;;;;;;OASG;IACH,sEANG;QAAwD,UAAU,EAA1D,GAAG,CAAC,MAAM,GAAC,MAAM,EAAE,qBAAqB,CAAC;QACgC,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AFa,CAAC,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAC,IAAI,CAIjE;IAED;;;;OAIG;IACH,cAFa,OAAO,GAAC,IAAI,CAIxB;IAED;;;;OAIG;IACH,aAFa,OAAO,kBAAkB,EAAE,OAAO,OAAC,CAI/C;;CACF;;;;;UAlHa,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;;qBAf3D,eAAe"}
|
package/src/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { default as ActionBuilder } from "./browser/lib/ActionBuilder.js";
|
|
2
1
|
export { default as ActionRunner } from "./browser/lib/ActionRunner.js";
|
|
3
2
|
export { default as ActionWrapper } from "./browser/lib/ActionWrapper.js";
|
|
4
3
|
export { default as Piper } from "./browser/lib/Piper.js";
|
|
5
|
-
|
|
4
|
+
import ActionBuilder from "./browser/lib/ActionBuilder.js";
|
|
5
|
+
import ActionHooks from "./lib/ActionHooks.js";
|
|
6
|
+
export { ActionBuilder, ActionHooks };
|
|
6
7
|
export { default as Activity, ACTIVITY } from "./browser/lib/Activity.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/src/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":";;;0BAC0B,gCAAgC;wBAClC,sBAAsB"}
|