@xeplr/actions 1.3.1 → 1.4.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 +2 -1
- package/lib/registry.js +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ var moved = await actions.runAction(actions.builtins.dbMove, {
|
|
|
64
64
|
|---|---|
|
|
65
65
|
| `register(def)` / `register(name, def)` | Add an action. Throws without `name` or `execute`, or with a `requires` module that is not installed (`ActionMissingDependencyError`). Re-registering a name replaces it. |
|
|
66
66
|
| `get(name)` / `has(name)` | Look one up. |
|
|
67
|
-
| `list()` | `[{ name, description, inputSchema, outputSchema, requires }]` — serializable, for an actions endpoint. |
|
|
67
|
+
| `list()` | `[{ name, description, inputSchema, outputSchema, requires, event }]` — serializable, for an actions endpoint. `event` is `null` for an ordinary action. |
|
|
68
68
|
| `clear()` | Empty the registry. |
|
|
69
69
|
| `runAction({ name, input, system?, timeoutMs? })` | Run a registered action. Never throws. |
|
|
70
70
|
| `runAction(nameOrDef, input, { system, timeoutMs, metaStore }?)` | Same, by name or with an action module directly. |
|
|
@@ -91,6 +91,7 @@ var moved = await actions.runAction(actions.builtins.dbMove, {
|
|
|
91
91
|
| `outputSchema` | Optional documentation of the return value. |
|
|
92
92
|
| `requires` | Module names checked with `require.resolve` at `register()`. |
|
|
93
93
|
| `execute({ input, system, metaStore })` | Returns (or resolves to) the output. |
|
|
94
|
+
| `event` | Optional. Makes this a **screen function** rather than a step: the event it is written for — `beforeLoad`, `beforeSave`, `afterSave`, `beforeDelete`, `onError` (run by `@xeplr/factory` around a screen's records) or `decide` (run by `@xeplr/workflow-engine` to choose a flow's next step). A screen names one per event and pickers offer only the functions for that event. It is called with the event's context — `execute(ctx)`, not `{ input, system }` — and never as a workflow step. |
|
|
94
95
|
|
|
95
96
|
### `runAction` result
|
|
96
97
|
|
package/lib/registry.js
CHANGED
|
@@ -9,8 +9,17 @@
|
|
|
9
9
|
// outputSchema : array? — optional; documents what the action returns
|
|
10
10
|
// requires : string[]? — peer-dep module names checked at register time
|
|
11
11
|
// execute : function — async ({ input, system }) => output
|
|
12
|
+
// event : string? — a SCREEN FUNCTION, not a step: the event it
|
|
13
|
+
// is written for ('beforeSave', 'decide', …).
|
|
14
|
+
// Called with that event's own context instead
|
|
15
|
+
// of { input, system } — see the README.
|
|
12
16
|
// }
|
|
13
17
|
//
|
|
18
|
+
// One registry for both, because one app registers both and the two readers
|
|
19
|
+
// (a screen's events, a workflow's arrows and steps) live in one process. What
|
|
20
|
+
// an `event` means is the reader's business: this package only keeps it, and
|
|
21
|
+
// lists it, so a picker can offer each event only the functions written for it.
|
|
22
|
+
//
|
|
14
23
|
// Two call forms:
|
|
15
24
|
// register(name, def) → traditional
|
|
16
25
|
// register(def) → module-export style: `def.name` is used
|
|
@@ -33,6 +42,9 @@ function register(nameOrDef, def) {
|
|
|
33
42
|
if (typeof action.execute !== 'function') {
|
|
34
43
|
throw new Error('register: action "' + action.name + '" must have an `execute` function');
|
|
35
44
|
}
|
|
45
|
+
if (action.event !== undefined && (typeof action.event !== 'string' || !action.event.trim())) {
|
|
46
|
+
throw new Error('register: action "' + action.name + '" has an `event` that is not a name — e.g. "beforeSave"');
|
|
47
|
+
}
|
|
36
48
|
|
|
37
49
|
// Sanity-check peer deps.
|
|
38
50
|
if (Array.isArray(action.requires)) {
|
|
@@ -48,6 +60,7 @@ function register(nameOrDef, def) {
|
|
|
48
60
|
inputSchema: Array.isArray(action.inputSchema) ? action.inputSchema : [],
|
|
49
61
|
outputSchema: action.outputSchema || null,
|
|
50
62
|
requires: Array.isArray(action.requires) ? action.requires.slice() : [],
|
|
63
|
+
event: action.event || null,
|
|
51
64
|
execute: action.execute
|
|
52
65
|
});
|
|
53
66
|
}
|
|
@@ -64,7 +77,8 @@ function list() {
|
|
|
64
77
|
description: def.description,
|
|
65
78
|
inputSchema: def.inputSchema,
|
|
66
79
|
outputSchema: def.outputSchema,
|
|
67
|
-
requires: def.requires
|
|
80
|
+
requires: def.requires,
|
|
81
|
+
event: def.event
|
|
68
82
|
});
|
|
69
83
|
});
|
|
70
84
|
return out;
|
package/package.json
CHANGED