@stacksjs/action-runner 0.74.4

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2023 Open Web Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @stacksjs/action-runner
2
+
3
+ How a package runs an action by name, without depending on the action layer.
4
+
5
+ Running an action belongs to `@stacksjs/actions`: it resolves the action file
6
+ and spawns it. But three packages need to ask for that without *being* the
7
+ action layer:
8
+
9
+ - `@stacksjs/queue`, when a job names an action instead of handing over a function
10
+ - `@stacksjs/scheduler`, for `Schedule.action('...')`
11
+ - `@stacksjs/dns`, whose `addDomain` / `removeDomain` shell out to the domain actions
12
+
13
+ and `@stacksjs/actions` imports all three. Importing it back closed a cycle in
14
+ every case.
15
+
16
+ So the capability is declared here, in a package that depends on nothing that
17
+ can lead back to it, and `@stacksjs/actions` supplies it by the act of being
18
+ imported at all.
19
+
20
+ ```ts
21
+ import { runNamedAction } from '@stacksjs/action-runner'
22
+
23
+ await runNamedAction('SendWelcomeEmail')
24
+ ```
25
+
26
+ If nothing registered a runner, this falls back to importing `@stacksjs/actions`
27
+ directly, and throws if that is not available either. It never silently does
28
+ nothing: a job marked complete, or a scheduled task reported as run, with its
29
+ work undone is the one outcome these callers must never produce.
@@ -0,0 +1,29 @@
1
+ import type { Action } from '@stacksjs/enums';
2
+ import type { ActionOptions } from '@stacksjs/types';
3
+ /**
4
+ * Supply the runner. Called by `@stacksjs/actions` on import; an application
5
+ * embedding any of these packages on its own can call it with a runner of its
6
+ * own.
7
+ */
8
+ export declare function setActionRunner(runner: ActionRunner): void;
9
+ /** The registered runner, if the action layer has been loaded. */
10
+ export declare function getActionRunner(): ActionRunner | null;
11
+ /**
12
+ * Run an action by name.
13
+ *
14
+ * Prefers whatever registered itself. Falls back to importing the action
15
+ * package directly, because a worker or a scheduler process can reach a task
16
+ * before anything has pulled the action layer in - that import is the old
17
+ * behaviour, kept so this cannot break a caller that was working.
18
+ *
19
+ * When neither is available it throws. Silently doing nothing would leave a
20
+ * job marked complete, or a scheduled task reported as run, with its work
21
+ * undone - the one outcome these callers must never produce.
22
+ */
23
+ export declare function runNamedAction(action: Action | string, options?: ActionOptions): Promise<any>;
24
+ /**
25
+ * The options a runner accepts, matching `runAction`'s own second parameter.
26
+ * `DeployOptions` and friends are interfaces, so a structural stand-in like
27
+ * `Record<string, unknown>` would not accept them.
28
+ */
29
+ export type ActionRunner = (action: Action | string, options?: ActionOptions) => Promise<any>;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ var n=null;function e(t){n=t}function s(){return n}async function c(t,o){if(n)return await n(t,o);let i=await import("@stacksjs/actions").catch(()=>null);if(i?.runAction)return n=i.runAction,await n(t,o);throw Error(`Asked to run the action "${t}", but no action runner is available. Import @stacksjs/actions in this process, or register one with setActionRunner() from @stacksjs/action-runner.`)}export{s as getActionRunner,c as runNamedAction,e as setActionRunner};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@stacksjs/action-runner",
3
+ "type": "module",
4
+ "version": "0.74.4",
5
+ "description": "How a package runs an action by name, without depending on the action layer.",
6
+ "author": "Chris Breuer",
7
+ "contributors": [
8
+ "Chris Breuer <chris@stacksjs.com>"
9
+ ],
10
+ "license": "MIT",
11
+ "funding": "https://github.com/sponsors/chrisbbreuer",
12
+ "homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/action-runner#readme",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/stacksjs/stacks.git",
16
+ "directory": "./storage/framework/core/action-runner"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/stacksjs/stacks/issues"
20
+ },
21
+ "keywords": [
22
+ "actions",
23
+ "runner",
24
+ "stacks"
25
+ ],
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "bun": "./dist/index.js",
30
+ "import": "./dist/index.js"
31
+ },
32
+ "./*": {
33
+ "import": "./dist/*"
34
+ }
35
+ },
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "files": [
39
+ "README.md",
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "bun build.ts",
44
+ "typecheck": "bun --bun tsc --noEmit"
45
+ },
46
+ "dependencies": {
47
+ "@stacksjs/enums": "0.74.4",
48
+ "@stacksjs/types": "0.74.4"
49
+ }
50
+ }