0z2i6v3u5t 1.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/.devcontainer/devcontainer.json +4 -0
- package/.devcontainer/setup.sh +11 -0
- package/.dockerignore +2 -0
- package/.github/CONTRIBUTING.md +52 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +59 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +43 -0
- package/.github/dependabot.yml +17 -0
- package/.github/workflows/codeql.yml +76 -0
- package/.github/workflows/publish_docs.yml +25 -0
- package/.github/workflows/test.yml +78 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc +1 -0
- package/.vscode/launch.json +42 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/Dockerfile +17 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/SECURITY.md +5 -0
- package/__tests__/actions/cacheTest.ts +58 -0
- package/__tests__/actions/randomNumber.ts +26 -0
- package/__tests__/actions/recursiveAction.ts +16 -0
- package/__tests__/actions/sleepTest.ts +24 -0
- package/__tests__/actions/status.ts +17 -0
- package/__tests__/actions/swagger.ts +76 -0
- package/__tests__/actions/validationTest.ts +63 -0
- package/__tests__/cli/cli.ts +126 -0
- package/__tests__/core/api.ts +632 -0
- package/__tests__/core/cache.ts +400 -0
- package/__tests__/core/chatRoom.ts +589 -0
- package/__tests__/core/cli.ts +349 -0
- package/__tests__/core/cluster.ts +132 -0
- package/__tests__/core/config.ts +78 -0
- package/__tests__/core/errors.ts +112 -0
- package/__tests__/core/log.ts +23 -0
- package/__tests__/core/middleware.ts +427 -0
- package/__tests__/core/plugins/partialPlugin.ts +94 -0
- package/__tests__/core/plugins/withPlugin.ts +88 -0
- package/__tests__/core/plugins/withoutPlugin.ts +81 -0
- package/__tests__/core/process.ts +42 -0
- package/__tests__/core/specHelper.ts +330 -0
- package/__tests__/core/staticFile/compression.ts +99 -0
- package/__tests__/core/staticFile/staticFile.ts +180 -0
- package/__tests__/core/tasks/customQueueFunction.ts +67 -0
- package/__tests__/core/tasks/fullWorkerFlow.ts +199 -0
- package/__tests__/core/tasks/tasks.ts +605 -0
- package/__tests__/integration/browser.ts +133 -0
- package/__tests__/integration/ioredis-mock.ts +194 -0
- package/__tests__/integration/sendBuffer.ts +97 -0
- package/__tests__/integration/sendFile.ts +24 -0
- package/__tests__/integration/sharedFingerprint.ts +82 -0
- package/__tests__/integration/taskFlow.ts +110 -0
- package/__tests__/jest.ts +5 -0
- package/__tests__/modules/action.ts +103 -0
- package/__tests__/modules/config.ts +19 -0
- package/__tests__/modules/utils/ensureNoTsHeaderOrSpecFiles.ts +24 -0
- package/__tests__/servers/web/allowedRequestHosts.ts +88 -0
- package/__tests__/servers/web/enableMultiples.ts +83 -0
- package/__tests__/servers/web/fileUpload.ts +79 -0
- package/__tests__/servers/web/jsonp.ts +57 -0
- package/__tests__/servers/web/nonMultiples.ts +83 -0
- package/__tests__/servers/web/rawBody.ts +208 -0
- package/__tests__/servers/web/returnErrorCodes.ts +55 -0
- package/__tests__/servers/web/routes/deepRoutes.ts +96 -0
- package/__tests__/servers/web/routes/routes.ts +579 -0
- package/__tests__/servers/web/routes/veryDeepRoutes.ts +92 -0
- package/__tests__/servers/web/web.ts +1031 -0
- package/__tests__/servers/websocket.ts +795 -0
- package/__tests__/tasks/runAction.ts +37 -0
- package/__tests__/template.ts.example +20 -0
- package/__tests__/testCliCommands/hello.ts +44 -0
- package/__tests__/testPlugin/public/plugin.html +1 -0
- package/__tests__/testPlugin/src/actions/pluginAction.ts +14 -0
- package/__tests__/testPlugin/src/bin/hello.ts +22 -0
- package/__tests__/testPlugin/src/initializers/pluginInitializer.ts +17 -0
- package/__tests__/testPlugin/src/tasks/pluginTask.ts +15 -0
- package/__tests__/testPlugin/tsconfig.json +10 -0
- package/__tests__/utils/utils.ts +492 -0
- package/app.json +23 -0
- package/bin/deploy-docs +39 -0
- package/client/ActionheroWebsocketClient.js +277 -0
- package/docker-compose.yml +73 -0
- package/package.json +24 -0
- package/public/chat.html +194 -0
- package/public/css/cosmo.css +12 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +115 -0
- package/public/javascript/.gitkeep +0 -0
- package/public/linkedSession.html +80 -0
- package/public/logo/actionhero-small.png +0 -0
- package/public/logo/actionhero.png +0 -0
- package/public/pixel.gif +0 -0
- package/public/simple.html +2 -0
- package/public/swagger.html +32 -0
- package/public/websocketLoadTest.html +322 -0
- package/src/actions/cacheTest.ts +58 -0
- package/src/actions/createChatRoom.ts +20 -0
- package/src/actions/randomNumber.ts +17 -0
- package/src/actions/recursiveAction.ts +13 -0
- package/src/actions/sendFile.ts +12 -0
- package/src/actions/sleepTest.ts +40 -0
- package/src/actions/status.ts +73 -0
- package/src/actions/swagger.ts +155 -0
- package/src/actions/validationTest.ts +36 -0
- package/src/bin/actionhero.ts +225 -0
- package/src/bin/methods/actions/list.ts +30 -0
- package/src/bin/methods/console.ts +26 -0
- package/src/bin/methods/generate/action.ts +58 -0
- package/src/bin/methods/generate/cli.ts +51 -0
- package/src/bin/methods/generate/initializer.ts +54 -0
- package/src/bin/methods/generate/plugin.ts +57 -0
- package/src/bin/methods/generate/server.ts +38 -0
- package/src/bin/methods/generate/task.ts +68 -0
- package/src/bin/methods/generate.ts +176 -0
- package/src/bin/methods/task/enqueue.ts +35 -0
- package/src/classes/action.ts +98 -0
- package/src/classes/actionProcessor.ts +463 -0
- package/src/classes/api.ts +51 -0
- package/src/classes/cli.ts +67 -0
- package/src/classes/config.ts +15 -0
- package/src/classes/connection.ts +321 -0
- package/src/classes/exceptionReporter.ts +9 -0
- package/src/classes/initializer.ts +59 -0
- package/src/classes/initializers.ts +5 -0
- package/src/classes/input.ts +9 -0
- package/src/classes/inputs.ts +34 -0
- package/src/classes/process/actionheroVersion.ts +15 -0
- package/src/classes/process/env.ts +16 -0
- package/src/classes/process/id.ts +34 -0
- package/src/classes/process/pid.ts +32 -0
- package/src/classes/process/projectRoot.ts +16 -0
- package/src/classes/process/typescript.ts +47 -0
- package/src/classes/process.ts +479 -0
- package/src/classes/server.ts +251 -0
- package/src/classes/task.ts +87 -0
- package/src/config/api.ts +107 -0
- package/src/config/errors.ts +162 -0
- package/src/config/logger.ts +113 -0
- package/src/config/plugins.ts +37 -0
- package/src/config/redis.ts +78 -0
- package/src/config/routes.ts +44 -0
- package/src/config/tasks.ts +84 -0
- package/src/config/web.ts +136 -0
- package/src/config/websocket.ts +62 -0
- package/src/index.ts +46 -0
- package/src/initializers/actions.ts +125 -0
- package/src/initializers/chatRoom.ts +214 -0
- package/src/initializers/connections.ts +124 -0
- package/src/initializers/exceptions.ts +155 -0
- package/src/initializers/params.ts +52 -0
- package/src/initializers/redis.ts +191 -0
- package/src/initializers/resque.ts +248 -0
- package/src/initializers/routes.ts +229 -0
- package/src/initializers/servers.ts +134 -0
- package/src/initializers/specHelper.ts +195 -0
- package/src/initializers/staticFile.ts +253 -0
- package/src/initializers/tasks.ts +188 -0
- package/src/modules/action.ts +89 -0
- package/src/modules/cache.ts +326 -0
- package/src/modules/chatRoom.ts +321 -0
- package/src/modules/config.ts +246 -0
- package/src/modules/log.ts +62 -0
- package/src/modules/redis.ts +93 -0
- package/src/modules/route.ts +59 -0
- package/src/modules/specHelper.ts +182 -0
- package/src/modules/task.ts +527 -0
- package/src/modules/utils/argv.ts +3 -0
- package/src/modules/utils/arrayStartingMatch.ts +21 -0
- package/src/modules/utils/arrayUnique.ts +15 -0
- package/src/modules/utils/collapseObjectToArray.ts +33 -0
- package/src/modules/utils/deepCopy.ts +3 -0
- package/src/modules/utils/ensureNoTsHeaderOrSpecFiles.ts +19 -0
- package/src/modules/utils/eventLoopDelay.ts +34 -0
- package/src/modules/utils/fileUtils.ts +119 -0
- package/src/modules/utils/filterObjectForLogging.ts +51 -0
- package/src/modules/utils/filterResponseForLogging.ts +53 -0
- package/src/modules/utils/getExternalIPAddress.ts +17 -0
- package/src/modules/utils/hashMerge.ts +63 -0
- package/src/modules/utils/isPlainObject.ts +45 -0
- package/src/modules/utils/isRunning.ts +7 -0
- package/src/modules/utils/parseCookies.ts +20 -0
- package/src/modules/utils/parseHeadersForClientAddress.ts +53 -0
- package/src/modules/utils/parseIPv6URI.ts +24 -0
- package/src/modules/utils/replaceDistWithSrc.ts +9 -0
- package/src/modules/utils/safeGlob.ts +6 -0
- package/src/modules/utils/sleep.ts +8 -0
- package/src/modules/utils/sortGlobalMiddleware.ts +17 -0
- package/src/modules/utils/sourceRelativeLinkPath.ts +29 -0
- package/src/modules/utils.ts +66 -0
- package/src/server.ts +20 -0
- package/src/servers/web.ts +894 -0
- package/src/servers/websocket.ts +304 -0
- package/src/tasks/runAction.ts +29 -0
- package/tea.yaml +9 -0
- package/templates/README.md.template +17 -0
- package/templates/action.ts.template +15 -0
- package/templates/boot.js.template +9 -0
- package/templates/cli.ts.template +15 -0
- package/templates/gitignore.template +23 -0
- package/templates/initializer.ts.template +17 -0
- package/templates/package-plugin.json.template +12 -0
- package/templates/package.json.template +45 -0
- package/templates/projectMap.txt +39 -0
- package/templates/projectServer.ts.template +20 -0
- package/templates/server.ts.template +37 -0
- package/templates/task.ts.template +16 -0
- package/templates/test/action.ts.template +13 -0
- package/templates/test/task.ts.template +20 -0
- package/tsconfig.json +11 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
import * as fs from "fs";
|
2
|
+
import * as path from "path";
|
3
|
+
import { config, utils, CLI, ParamsFrom } from "./../../../index";
|
4
|
+
|
5
|
+
export class GenerateServerCLI extends CLI {
|
6
|
+
name = "generate-server";
|
7
|
+
description = "Generate a new Server";
|
8
|
+
example = "actionhero generate server --name=<name>";
|
9
|
+
inputs = {
|
10
|
+
name: {
|
11
|
+
required: true as true,
|
12
|
+
description: "The name of the Server to generate",
|
13
|
+
letter: "n",
|
14
|
+
},
|
15
|
+
};
|
16
|
+
|
17
|
+
async run({ params }: { params: ParamsFrom<GenerateServerCLI> }) {
|
18
|
+
let templateBuffer = fs.readFileSync(
|
19
|
+
path.join(__dirname, "/../../../../templates/server.ts.template"),
|
20
|
+
);
|
21
|
+
let template = String(templateBuffer);
|
22
|
+
|
23
|
+
for (const [k, v] of Object.entries(params)) {
|
24
|
+
const regex = new RegExp("%%" + k + "%%", "g");
|
25
|
+
template = template.replace(regex, v);
|
26
|
+
}
|
27
|
+
|
28
|
+
const message = utils.fileUtils.createFileSafely(
|
29
|
+
utils.replaceDistWithSrc(
|
30
|
+
config.general.paths.server[0] + "/" + params.name + ".ts",
|
31
|
+
),
|
32
|
+
template,
|
33
|
+
);
|
34
|
+
console.log(message);
|
35
|
+
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import * as fs from "fs";
|
2
|
+
import * as path from "path";
|
3
|
+
import { config, utils, CLI, ParamsFrom } from "./../../../index";
|
4
|
+
|
5
|
+
export class GenerateTaskCLI extends CLI {
|
6
|
+
name = "generate-task";
|
7
|
+
description = "Generate a new Task";
|
8
|
+
example =
|
9
|
+
"actionhero generate task --name=<name> -queue=<queue> --description=[description] --frequency=[frequency]";
|
10
|
+
inputs = {
|
11
|
+
name: {
|
12
|
+
required: true as true,
|
13
|
+
description: "The name of the Task to generate",
|
14
|
+
letter: "n",
|
15
|
+
},
|
16
|
+
queue: {
|
17
|
+
required: true as true,
|
18
|
+
description: "The queue that this Task will run on",
|
19
|
+
letter: "q",
|
20
|
+
},
|
21
|
+
description: {
|
22
|
+
required: true as true,
|
23
|
+
description: "The description of this Task",
|
24
|
+
default: "an actionhero task",
|
25
|
+
letter: "d",
|
26
|
+
},
|
27
|
+
frequency: {
|
28
|
+
required: true as true,
|
29
|
+
description: "Should this Task run periodically? Frequency is in ms",
|
30
|
+
default: "0",
|
31
|
+
letter: "f",
|
32
|
+
},
|
33
|
+
};
|
34
|
+
|
35
|
+
async run({ params }: { params: ParamsFrom<GenerateTaskCLI> }) {
|
36
|
+
let taskTemplateBuffer = fs.readFileSync(
|
37
|
+
path.join(__dirname, "/../../../../templates/task.ts.template"),
|
38
|
+
);
|
39
|
+
let taskTemplate = String(taskTemplateBuffer);
|
40
|
+
|
41
|
+
let testTemplateBuffer = fs.readFileSync(
|
42
|
+
path.join(__dirname, "/../../../../templates/test/task.ts.template"),
|
43
|
+
);
|
44
|
+
let testTemplate = String(testTemplateBuffer);
|
45
|
+
|
46
|
+
for (const [k, v] of Object.entries(params)) {
|
47
|
+
const regex = new RegExp("%%" + k + "%%", "g");
|
48
|
+
taskTemplate = taskTemplate.replace(regex, v);
|
49
|
+
testTemplate = testTemplate.replace(regex, v);
|
50
|
+
}
|
51
|
+
|
52
|
+
let message = utils.fileUtils.createFileSafely(
|
53
|
+
utils.replaceDistWithSrc(
|
54
|
+
config.general.paths.task[0] + "/" + params.name + ".ts",
|
55
|
+
),
|
56
|
+
taskTemplate,
|
57
|
+
);
|
58
|
+
console.info(message);
|
59
|
+
|
60
|
+
message = utils.fileUtils.createFileSafely(
|
61
|
+
config.general.paths.test[0] + "/tasks/" + params.name + ".ts",
|
62
|
+
testTemplate,
|
63
|
+
);
|
64
|
+
console.info(message);
|
65
|
+
|
66
|
+
return true;
|
67
|
+
}
|
68
|
+
}
|
@@ -0,0 +1,176 @@
|
|
1
|
+
import * as fs from "fs";
|
2
|
+
import * as path from "path";
|
3
|
+
|
4
|
+
// import { api, projectRoot, CLI } from "./../../index";
|
5
|
+
// we need to load each component directly so we don't accidentally source `config... which doesn't exist`
|
6
|
+
import { CLI } from "./../../classes/cli";
|
7
|
+
import { projectRoot } from "./../../classes/process/projectRoot";
|
8
|
+
import {
|
9
|
+
createDirSafely,
|
10
|
+
createFileSafely,
|
11
|
+
} from "../../modules/utils/fileUtils";
|
12
|
+
|
13
|
+
export class GenerateCLI extends CLI {
|
14
|
+
name = "generate";
|
15
|
+
description = "Generate a new Actionhero Project in an empty directory";
|
16
|
+
initialize = false;
|
17
|
+
|
18
|
+
async run() {
|
19
|
+
const documents: {
|
20
|
+
[key: string]: string | NodeJS.ArrayBufferView;
|
21
|
+
} = {};
|
22
|
+
|
23
|
+
documents.projectMap = fs
|
24
|
+
.readFileSync(path.join(__dirname, "/../../../templates/projectMap.txt"))
|
25
|
+
.toString();
|
26
|
+
|
27
|
+
const oldFileMap = {
|
28
|
+
tsconfig: "tsconfig.json",
|
29
|
+
serverJs: "/templates/projectServer.ts.template",
|
30
|
+
configApiJs: "/src/config/api.ts",
|
31
|
+
configLoggerJs: "/src/config/logger.ts",
|
32
|
+
configRedisJs: "/src/config/redis.ts",
|
33
|
+
configTasksJs: "/src/config/tasks.ts",
|
34
|
+
configErrorsJs: "/src/config/errors.ts",
|
35
|
+
configPluginsJs: "/src/config/plugins.ts",
|
36
|
+
configRoutesJs: "/src/config/routes.ts",
|
37
|
+
configWebJs: "/src/config/web.ts",
|
38
|
+
configWebsocketJs: "/src/config/websocket.ts",
|
39
|
+
packageJson: "/package.json",
|
40
|
+
actionStatus: "/src/actions/status.ts",
|
41
|
+
actionChatRoom: "/src/actions/createChatRoom.ts",
|
42
|
+
actionSwagger: "/src/actions/swagger.ts",
|
43
|
+
publicIndex: "/public/index.html",
|
44
|
+
publicChat: "/public/chat.html",
|
45
|
+
publicSwagger: "/public/swagger.html",
|
46
|
+
publicLogo: "/public/logo/actionhero.png",
|
47
|
+
publicCss: "/public/css/cosmo.css",
|
48
|
+
exampleTest: "/__tests__/template.ts.example",
|
49
|
+
gitignore: "/templates/gitignore.template",
|
50
|
+
};
|
51
|
+
|
52
|
+
for (const [name, localPath] of Object.entries(oldFileMap)) {
|
53
|
+
const source = path.join(__dirname, "/../../../", localPath);
|
54
|
+
const extension = localPath.split(".")[1];
|
55
|
+
documents[name] = fs.readFileSync(source);
|
56
|
+
if (extension === "ts" || extension === "js" || extension === "json") {
|
57
|
+
documents[name] = documents[name]
|
58
|
+
.toString()
|
59
|
+
.replace('from "./../index"', 'from "actionhero"')
|
60
|
+
.replace('from ".."', 'from "actionhero"')
|
61
|
+
.replace('declare module ".."', 'declare module "actionhero"');
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
const AHversionNumber = JSON.parse(
|
66
|
+
documents.packageJson.toString(),
|
67
|
+
).version;
|
68
|
+
|
69
|
+
documents.packageJson = String(
|
70
|
+
fs.readFileSync(
|
71
|
+
path.join(__dirname, "/../../../templates/package.json.template"),
|
72
|
+
),
|
73
|
+
);
|
74
|
+
|
75
|
+
documents.packageJson = documents.packageJson.replace(
|
76
|
+
"%%versionNumber%%",
|
77
|
+
AHversionNumber,
|
78
|
+
);
|
79
|
+
|
80
|
+
documents.readmeMd = String(
|
81
|
+
fs.readFileSync(
|
82
|
+
path.join(__dirname, "/../../../templates/README.md.template"),
|
83
|
+
),
|
84
|
+
);
|
85
|
+
|
86
|
+
console.log("Generating a new actionhero project...");
|
87
|
+
|
88
|
+
[
|
89
|
+
"/src",
|
90
|
+
"/src/config",
|
91
|
+
"/src/actions",
|
92
|
+
"/src/tasks",
|
93
|
+
"/src/initializers",
|
94
|
+
"/src/servers",
|
95
|
+
"/src/bin",
|
96
|
+
"/log",
|
97
|
+
"/pids",
|
98
|
+
"/public",
|
99
|
+
"/public/javascript",
|
100
|
+
"/public/css",
|
101
|
+
"/public/logo",
|
102
|
+
"/__tests__",
|
103
|
+
"/__tests__/actions",
|
104
|
+
"/__tests__/tasks",
|
105
|
+
].forEach((dir) => {
|
106
|
+
try {
|
107
|
+
const message = createDirSafely(projectRoot + dir);
|
108
|
+
console.log(message);
|
109
|
+
} catch (error) {
|
110
|
+
console.log(error.toString());
|
111
|
+
}
|
112
|
+
});
|
113
|
+
|
114
|
+
const newFileMap = {
|
115
|
+
"/tsconfig.json": "tsconfig",
|
116
|
+
"/src/server.ts": "serverJs",
|
117
|
+
"/src/config/api.ts": "configApiJs",
|
118
|
+
"/src/config/logger.ts": "configLoggerJs",
|
119
|
+
"/src/config/redis.ts": "configRedisJs",
|
120
|
+
"/src/config/tasks.ts": "configTasksJs",
|
121
|
+
"/src/config/errors.ts": "configErrorsJs",
|
122
|
+
"/src/config/plugins.ts": "configPluginsJs",
|
123
|
+
"/src/config/routes.ts": "configRoutesJs",
|
124
|
+
"/src/config/web.ts": "configWebJs",
|
125
|
+
"/src/config/websocket.ts": "configWebsocketJs",
|
126
|
+
"/package.json": "packageJson",
|
127
|
+
"/src/actions/status.ts": "actionStatus",
|
128
|
+
"/src/actions/createChatRoom.ts": "actionChatRoom",
|
129
|
+
"/src/actions/swagger.ts": "actionSwagger",
|
130
|
+
"/public/index.html": "publicIndex",
|
131
|
+
"/public/chat.html": "publicChat",
|
132
|
+
"/public/swagger.html": "publicSwagger",
|
133
|
+
"/public/css/cosmo.css": "publicCss",
|
134
|
+
"/public/logo/actionhero.png": "publicLogo",
|
135
|
+
"/README.md": "readmeMd",
|
136
|
+
"/__tests__/actions/status.ts": "exampleTest",
|
137
|
+
"/.gitignore": "gitignore",
|
138
|
+
};
|
139
|
+
|
140
|
+
for (const [file, name] of Object.entries(newFileMap)) {
|
141
|
+
try {
|
142
|
+
const message = createFileSafely(projectRoot + file, documents[name]);
|
143
|
+
console.log(message);
|
144
|
+
} catch (error) {
|
145
|
+
console.log(error.toString());
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
console.log("");
|
150
|
+
console.log(
|
151
|
+
"Generation Complete. Your project directory should look like this:",
|
152
|
+
);
|
153
|
+
|
154
|
+
console.log("");
|
155
|
+
documents.projectMap
|
156
|
+
.toString()
|
157
|
+
.split("\n")
|
158
|
+
.forEach((line) => {
|
159
|
+
console.log(line);
|
160
|
+
});
|
161
|
+
|
162
|
+
console.log(
|
163
|
+
`
|
164
|
+
-------------------------------------------------------------------------------------------------------------------
|
165
|
+
You need to run \`npm install\` to install dependencies, and then \`npm run build\` to build the .js from this .ts project.
|
166
|
+
Then, run 'npm run dev' to start your server
|
167
|
+
|
168
|
+
❤️ the Actionhero Team
|
169
|
+
www.actionherojs.com
|
170
|
+
-------------------------------------------------------------------------------------------------------------------
|
171
|
+
`,
|
172
|
+
);
|
173
|
+
|
174
|
+
return true;
|
175
|
+
}
|
176
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { api, log, task, CLI, ParamsFrom } from "./../../../index";
|
2
|
+
|
3
|
+
export class TaskEnqueueCLI extends CLI {
|
4
|
+
name = "task-enqueue";
|
5
|
+
description = "Enqueue a defined Task into your actionhero cluster";
|
6
|
+
example =
|
7
|
+
"actionhero task enqueue --name=[taskName] --args=[JSON-encoded args]";
|
8
|
+
inputs = {
|
9
|
+
name: {
|
10
|
+
required: true as true,
|
11
|
+
description: "The name of the Task to enqueue",
|
12
|
+
letter: "n",
|
13
|
+
},
|
14
|
+
args: {
|
15
|
+
required: false,
|
16
|
+
description: "Arguments to the Task (JSON encoded)",
|
17
|
+
letter: "a",
|
18
|
+
},
|
19
|
+
};
|
20
|
+
|
21
|
+
async run({ params }: { params: ParamsFrom<TaskEnqueueCLI> }) {
|
22
|
+
if (!api.tasks.tasks[params.name]) {
|
23
|
+
throw new Error('Task "' + params.name + '" not found');
|
24
|
+
}
|
25
|
+
|
26
|
+
let args = {};
|
27
|
+
if (params.args) {
|
28
|
+
args = JSON.parse(params.args);
|
29
|
+
}
|
30
|
+
|
31
|
+
const toRun = await task.enqueue(params.name, args);
|
32
|
+
log(`enqueued: ${toRun}`, "info");
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { api } from "../index";
|
2
|
+
import type { ActionheroLogLevel } from "../modules/log";
|
3
|
+
import { ActionProcessor } from "./actionProcessor";
|
4
|
+
import { connectionVerbs } from "./connection";
|
5
|
+
import { Inputs } from "./inputs";
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Create a new Actionhero Action. The required properties of an action. These can be defined statically (this.name) or as methods which return a value.
|
9
|
+
*```js
|
10
|
+
* import { Action } from "actionhero";
|
11
|
+
*
|
12
|
+
* export default class RandomNumber extends Action {
|
13
|
+
* constructor () {
|
14
|
+
* super()
|
15
|
+
* this.name = 'randomNumber'
|
16
|
+
* this.description = 'I am an API method which will generate a random number'
|
17
|
+
* this.outputExample = { randomNumber: 0.1234 }
|
18
|
+
* }
|
19
|
+
* async run ({ response }) {
|
20
|
+
* response.randomNumber = Math.random()
|
21
|
+
* }
|
22
|
+
*}
|
23
|
+
*```
|
24
|
+
*/
|
25
|
+
export abstract class Action {
|
26
|
+
/**The name of the Action*/
|
27
|
+
name: string;
|
28
|
+
/**The description of the Action (default this.name)*/
|
29
|
+
description: string;
|
30
|
+
/**The version of this Action (default: 1) */
|
31
|
+
version?: number | string;
|
32
|
+
//*An example response payload (default: {})
|
33
|
+
outputExample?: object;
|
34
|
+
/**The inputs of the Action (default: {}) */
|
35
|
+
inputs?: Inputs;
|
36
|
+
/**The Middleware specific to this Action (default: []). Middleware is described by the string names of the middleware. */
|
37
|
+
middleware?: Array<string>;
|
38
|
+
/**Are there connections from any servers which cannot use this Action (default: [])? */
|
39
|
+
blockedConnectionTypes?: Array<string>;
|
40
|
+
/**Under what level should connections to this Action be logged (default 'info')? */
|
41
|
+
logLevel?: ActionheroLogLevel;
|
42
|
+
/**If this Action is responding to a `web` request, and that request has a file extension like *.jpg, should Actionhero set the response headers to match that extension (default: true)? */
|
43
|
+
matchExtensionMimeType?: boolean;
|
44
|
+
/**Should this Action appear in api.documentation.documentation? (default: true)? */
|
45
|
+
toDocument?: boolean;
|
46
|
+
|
47
|
+
constructor() {
|
48
|
+
this.version = this.version ?? 1;
|
49
|
+
this.description = this.description ?? this.name;
|
50
|
+
this.inputs = this.inputs ?? {};
|
51
|
+
this.outputExample = this.outputExample ?? {};
|
52
|
+
this.middleware = this.middleware ?? [];
|
53
|
+
this.blockedConnectionTypes = this.blockedConnectionTypes ?? [];
|
54
|
+
this.logLevel = this.logLevel ?? "info";
|
55
|
+
this.toDocument = this.toDocument ?? true;
|
56
|
+
this.matchExtensionMimeType = this.matchExtensionMimeType ?? true;
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* The main "do something" method for this action. It can be `async`. Usually the goal of this run method is to return the data that you want to be sent to API consumers. If error is thrown in this method, it will be logged, caught, and returned to the client as `error`
|
61
|
+
* @param data The data about this connection, response, and params.
|
62
|
+
*/
|
63
|
+
abstract run(
|
64
|
+
data: Partial<ActionProcessor<Action>>,
|
65
|
+
): Promise<ActionResponse | void>;
|
66
|
+
|
67
|
+
validate() {
|
68
|
+
if (!this.name) {
|
69
|
+
throw new Error("name is required for this action");
|
70
|
+
}
|
71
|
+
if (!this.description) {
|
72
|
+
throw new Error(
|
73
|
+
`description is required for the action \`${this.name}\``,
|
74
|
+
);
|
75
|
+
}
|
76
|
+
if (!this.run || typeof this.run !== "function") {
|
77
|
+
throw new Error(`action \`${this.name}\` has no run method`);
|
78
|
+
}
|
79
|
+
if (
|
80
|
+
api.connections &&
|
81
|
+
([...connectionVerbs] as string[]).includes(this.name)
|
82
|
+
) {
|
83
|
+
throw new Error(
|
84
|
+
`action \`${this.name}\` is a reserved verb for connections. choose a new name`,
|
85
|
+
);
|
86
|
+
}
|
87
|
+
|
88
|
+
Object.keys(this.inputs).forEach((input) => {
|
89
|
+
if (api.params.globalSafeParams.includes(input)) {
|
90
|
+
throw new Error(
|
91
|
+
`input \`${input}\` in action \`${this.name}\` is a reserved param`,
|
92
|
+
);
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
export type ActionResponse = { [key: string]: any } | null | void;
|