hotstaq 0.5.3
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/.dockerignore +123 -0
- package/.eslintignore +17 -0
- package/.eslintrc.js +11 -0
- package/.vscode/launch.json +201 -0
- package/.vscode/settings.json +2 -0
- package/.vscode/tasks.json +88 -0
- package/CONTRIBUTING.md +157 -0
- package/LICENSE +21 -0
- package/README.md +128 -0
- package/bin/hotstaq +3 -0
- package/bin/hotstaq.cmd +1 -0
- package/build/src/Hot.d.ts +167 -0
- package/build/src/Hot.d.ts.map +1 -0
- package/build/src/Hot.js +365 -0
- package/build/src/Hot.js.map +1 -0
- package/build/src/HotAPI.d.ts +137 -0
- package/build/src/HotAPI.d.ts.map +1 -0
- package/build/src/HotAPI.js +353 -0
- package/build/src/HotAPI.js.map +1 -0
- package/build/src/HotAgentAPI.d.ts +22 -0
- package/build/src/HotAgentAPI.d.ts.map +1 -0
- package/build/src/HotAgentAPI.js +85 -0
- package/build/src/HotAgentAPI.js.map +1 -0
- package/build/src/HotAgentRoute.d.ts +17 -0
- package/build/src/HotAgentRoute.d.ts.map +1 -0
- package/build/src/HotAgentRoute.js +109 -0
- package/build/src/HotAgentRoute.js.map +1 -0
- package/build/src/HotBuilder.d.ts +52 -0
- package/build/src/HotBuilder.d.ts.map +1 -0
- package/build/src/HotBuilder.js +242 -0
- package/build/src/HotBuilder.js.map +1 -0
- package/build/src/HotClient.d.ts +31 -0
- package/build/src/HotClient.d.ts.map +1 -0
- package/build/src/HotClient.js +19 -0
- package/build/src/HotClient.js.map +1 -0
- package/build/src/HotComponent.d.ts +118 -0
- package/build/src/HotComponent.d.ts.map +1 -0
- package/build/src/HotComponent.js +89 -0
- package/build/src/HotComponent.js.map +1 -0
- package/build/src/HotCreator.d.ts +88 -0
- package/build/src/HotCreator.d.ts.map +1 -0
- package/build/src/HotCreator.js +445 -0
- package/build/src/HotCreator.js.map +1 -0
- package/build/src/HotDB.d.ts +69 -0
- package/build/src/HotDB.d.ts.map +1 -0
- package/build/src/HotDB.js +29 -0
- package/build/src/HotDB.js.map +1 -0
- package/build/src/HotDBConnectionInterface.d.ts +40 -0
- package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
- package/build/src/HotDBConnectionInterface.js +3 -0
- package/build/src/HotDBConnectionInterface.js.map +1 -0
- package/build/src/HotFile.d.ts +134 -0
- package/build/src/HotFile.d.ts.map +1 -0
- package/build/src/HotFile.js +454 -0
- package/build/src/HotFile.js.map +1 -0
- package/build/src/HotGenerator.d.ts +80 -0
- package/build/src/HotGenerator.d.ts.map +1 -0
- package/build/src/HotGenerator.js +342 -0
- package/build/src/HotGenerator.js.map +1 -0
- package/build/src/HotHTTPServer.d.ts +162 -0
- package/build/src/HotHTTPServer.d.ts.map +1 -0
- package/build/src/HotHTTPServer.js +863 -0
- package/build/src/HotHTTPServer.js.map +1 -0
- package/build/src/HotIO.d.ts +47 -0
- package/build/src/HotIO.d.ts.map +1 -0
- package/build/src/HotIO.js +232 -0
- package/build/src/HotIO.js.map +1 -0
- package/build/src/HotLog.d.ts +60 -0
- package/build/src/HotLog.d.ts.map +1 -0
- package/build/src/HotLog.js +126 -0
- package/build/src/HotLog.js.map +1 -0
- package/build/src/HotPage.d.ts +125 -0
- package/build/src/HotPage.d.ts.map +1 -0
- package/build/src/HotPage.js +178 -0
- package/build/src/HotPage.js.map +1 -0
- package/build/src/HotRoute.d.ts +82 -0
- package/build/src/HotRoute.d.ts.map +1 -0
- package/build/src/HotRoute.js +83 -0
- package/build/src/HotRoute.js.map +1 -0
- package/build/src/HotRouteMethod.d.ts +129 -0
- package/build/src/HotRouteMethod.d.ts.map +1 -0
- package/build/src/HotRouteMethod.js +84 -0
- package/build/src/HotRouteMethod.js.map +1 -0
- package/build/src/HotServer.d.ts +152 -0
- package/build/src/HotServer.d.ts.map +1 -0
- package/build/src/HotServer.js +109 -0
- package/build/src/HotServer.js.map +1 -0
- package/build/src/HotSetAsWeb.d.ts +2 -0
- package/build/src/HotSetAsWeb.d.ts.map +1 -0
- package/build/src/HotSetAsWeb.js +5 -0
- package/build/src/HotSetAsWeb.js.map +1 -0
- package/build/src/HotStaq.d.ts +603 -0
- package/build/src/HotStaq.d.ts.map +1 -0
- package/build/src/HotStaq.js +1260 -0
- package/build/src/HotStaq.js.map +1 -0
- package/build/src/HotStaqWeb.d.ts +18 -0
- package/build/src/HotStaqWeb.d.ts.map +1 -0
- package/build/src/HotStaqWeb.js +44 -0
- package/build/src/HotStaqWeb.js.map +1 -0
- package/build/src/HotTestDriver.d.ts +63 -0
- package/build/src/HotTestDriver.d.ts.map +1 -0
- package/build/src/HotTestDriver.js +187 -0
- package/build/src/HotTestDriver.js.map +1 -0
- package/build/src/HotTestElement.d.ts +71 -0
- package/build/src/HotTestElement.d.ts.map +1 -0
- package/build/src/HotTestElement.js +37 -0
- package/build/src/HotTestElement.js.map +1 -0
- package/build/src/HotTestMap.d.ts +83 -0
- package/build/src/HotTestMap.d.ts.map +1 -0
- package/build/src/HotTestMap.js +58 -0
- package/build/src/HotTestMap.js.map +1 -0
- package/build/src/HotTestSeleniumDriver.d.ts +86 -0
- package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
- package/build/src/HotTestSeleniumDriver.js +400 -0
- package/build/src/HotTestSeleniumDriver.js.map +1 -0
- package/build/src/HotTester.d.ts +188 -0
- package/build/src/HotTester.d.ts.map +1 -0
- package/build/src/HotTester.js +622 -0
- package/build/src/HotTester.js.map +1 -0
- package/build/src/HotTesterAPI.d.ts +15 -0
- package/build/src/HotTesterAPI.d.ts.map +1 -0
- package/build/src/HotTesterAPI.js +161 -0
- package/build/src/HotTesterAPI.js.map +1 -0
- package/build/src/HotTesterMocha.d.ts +50 -0
- package/build/src/HotTesterMocha.d.ts.map +1 -0
- package/build/src/HotTesterMocha.js +205 -0
- package/build/src/HotTesterMocha.js.map +1 -0
- package/build/src/HotTesterMochaSelenium.d.ts +70 -0
- package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
- package/build/src/HotTesterMochaSelenium.js +257 -0
- package/build/src/HotTesterMochaSelenium.js.map +1 -0
- package/build/src/HotTesterServer.d.ts +114 -0
- package/build/src/HotTesterServer.d.ts.map +1 -0
- package/build/src/HotTesterServer.js +575 -0
- package/build/src/HotTesterServer.js.map +1 -0
- package/build/src/api copy.d.ts +2 -0
- package/build/src/api copy.d.ts.map +1 -0
- package/build/src/api copy.js +153 -0
- package/build/src/api copy.js.map +1 -0
- package/build/src/api-web.d.ts +2 -0
- package/build/src/api-web.d.ts.map +1 -0
- package/build/src/api-web.js +45 -0
- package/build/src/api-web.js.map +1 -0
- package/build/src/api.d.ts +33 -0
- package/build/src/api.d.ts.map +1 -0
- package/build/src/api.js +78 -0
- package/build/src/api.js.map +1 -0
- package/build/src/cli.d.ts +2 -0
- package/build/src/cli.d.ts.map +1 -0
- package/build/src/cli.js +1040 -0
- package/build/src/cli.js.map +1 -0
- package/build/src/schemas/HotDBInflux.d.ts +63 -0
- package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
- package/build/src/schemas/HotDBInflux.js +239 -0
- package/build/src/schemas/HotDBInflux.js.map +1 -0
- package/build/src/schemas/HotDBMigration.d.ts +19 -0
- package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
- package/build/src/schemas/HotDBMigration.js +15 -0
- package/build/src/schemas/HotDBMigration.js.map +1 -0
- package/build/src/schemas/HotDBMySQL.d.ts +65 -0
- package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
- package/build/src/schemas/HotDBMySQL.js +387 -0
- package/build/src/schemas/HotDBMySQL.js.map +1 -0
- package/build/src/schemas/HotDBSchema.d.ts +15 -0
- package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
- package/build/src/schemas/HotDBSchema.js +19 -0
- package/build/src/schemas/HotDBSchema.js.map +1 -0
- package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
- package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
- package/build/src/schemas/influx/InfluxSchema.js +33 -0
- package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
- package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchema.js +151 -0
- package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
- package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
- package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
- package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
- package/build-web/HotStaq.js +2 -0
- package/build-web/HotStaq.min.js +119 -0
- package/build-web/HotStaqTests_HelloWorldAPI.js +133 -0
- package/builder/docker/Dockerfile.linux.gen +42 -0
- package/builder/docker/README.md +36 -0
- package/builder/docker/app/start.sh +8 -0
- package/builder/docker/dockerignore +3 -0
- package/builder/docker/scripts/build.bat +11 -0
- package/builder/docker/scripts/build.sh +11 -0
- package/builder/docker/scripts/start-app.bat +7 -0
- package/builder/docker/scripts/start-app.sh +7 -0
- package/builder/docker/scripts/stop-app.bat +5 -0
- package/builder/docker/scripts/stop-app.sh +5 -0
- package/builder/docker-compose/docker-compose.gen.yaml +41 -0
- package/builder/docker-compose/env-skeleton +4 -0
- package/creator/project/.vscode/launch.json +59 -0
- package/creator/project/README.md +20 -0
- package/creator/project/gitignore +118 -0
- package/creator/project/npmignore +118 -0
- package/creator/public/api-test.hott +28 -0
- package/creator/public/index.hott +12 -0
- package/creator/ts/src/AppAPI.ts +30 -0
- package/creator/ts/src/HelloWorld.ts +39 -0
- package/creator/ts/src/WebExport.ts +7 -0
- package/creator/ts/tsconfig-web.json +73 -0
- package/creator/ts/tsconfig.json +73 -0
- package/creator/ts/webpack-api.config.js +57 -0
- package/dbstart.sh +19 -0
- package/dbstop.sh +4 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +130 -0
- package/docs/classes/Hot.md +477 -0
- package/docs/classes/HotAPI.md +369 -0
- package/docs/classes/HotClient.md +95 -0
- package/docs/classes/HotComponent.md +279 -0
- package/docs/classes/HotDB.md +247 -0
- package/docs/classes/HotDBInflux.md +404 -0
- package/docs/classes/HotDBMigration.md +80 -0
- package/docs/classes/HotDBMySQL.md +310 -0
- package/docs/classes/HotDBSchema.md +51 -0
- package/docs/classes/HotFile.md +353 -0
- package/docs/classes/HotHTTPServer.md +700 -0
- package/docs/classes/HotLog.md +162 -0
- package/docs/classes/HotPage.md +357 -0
- package/docs/classes/HotRoute.md +312 -0
- package/docs/classes/HotRouteMethod.md +271 -0
- package/docs/classes/HotServer.md +311 -0
- package/docs/classes/HotStaq.md +1155 -0
- package/docs/classes/HotTestDestination.md +58 -0
- package/docs/classes/HotTestDriver.md +332 -0
- package/docs/classes/HotTestElement.md +88 -0
- package/docs/classes/HotTestElementOptions.md +71 -0
- package/docs/classes/HotTestMap.md +92 -0
- package/docs/classes/HotTestSeleniumDriver.md +542 -0
- package/docs/classes/HotTester.md +653 -0
- package/docs/classes/HotTesterAPI.md +493 -0
- package/docs/classes/HotTesterMocha.md +843 -0
- package/docs/classes/HotTesterMochaSelenium.md +896 -0
- package/docs/classes/HotTesterServer.md +633 -0
- package/docs/classes/InfluxSchema.md +74 -0
- package/docs/classes/MySQLSchema.md +199 -0
- package/docs/classes/MySQLSchemaField.md +330 -0
- package/docs/classes/MySQLSchemaTable.md +176 -0
- package/docs/enums/ConnectionStatus.md +43 -0
- package/docs/enums/DeveloperMode.md +38 -0
- package/docs/enums/EventExecutionType.md +43 -0
- package/docs/enums/HTTPMethod.md +32 -0
- package/docs/enums/HotDBGenerationType.md +30 -0
- package/docs/enums/HotLogLevel.md +88 -0
- package/docs/interfaces/HotDBConnectionInterface.md +116 -0
- package/docs/interfaces/HotDestination.md +62 -0
- package/docs/interfaces/HotSite.md +187 -0
- package/docs/interfaces/HotSiteMapPath.md +37 -0
- package/docs/interfaces/HotSiteRoute.md +79 -0
- package/docs/interfaces/HotStartOptions.md +115 -0
- package/docs/interfaces/HotTestPage.md +44 -0
- package/docs/interfaces/HotTestStop.md +62 -0
- package/docs/interfaces/IHotComponent.md +135 -0
- package/docs/interfaces/IHotStaq.md +118 -0
- package/docs/interfaces/IHotTestElement.md +54 -0
- package/docs/interfaces/IHotTestElementOptions.md +43 -0
- package/docs/interfaces/MySQLResults.md +43 -0
- package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
- package/docs/modules.md +182 -0
- package/package.json +65 -0
- package/selenium-start.sh +7 -0
- package/selenium-stop.sh +3 -0
- package/src/Hot.ts +319 -0
- package/src/HotAPI.ts +386 -0
- package/src/HotAgentAPI.ts +43 -0
- package/src/HotAgentRoute.ts +44 -0
- package/src/HotBuilder.ts +221 -0
- package/src/HotClient.ts +40 -0
- package/src/HotComponent.ts +158 -0
- package/src/HotCreator.ts +470 -0
- package/src/HotDB.ts +79 -0
- package/src/HotDBConnectionInterface.ts +40 -0
- package/src/HotFile.ts +617 -0
- package/src/HotGenerator.ts +446 -0
- package/src/HotHTTPServer.ts +954 -0
- package/src/HotIO.ts +160 -0
- package/src/HotLog.ts +158 -0
- package/src/HotPage.ts +206 -0
- package/src/HotRoute.ts +137 -0
- package/src/HotRouteMethod.ts +216 -0
- package/src/HotServer.ts +211 -0
- package/src/HotSetAsWeb.ts +3 -0
- package/src/HotStaq.ts +1881 -0
- package/src/HotTestDriver.ts +171 -0
- package/src/HotTestElement.ts +97 -0
- package/src/HotTestMap.ts +130 -0
- package/src/HotTestSeleniumDriver.ts +381 -0
- package/src/HotTester.ts +696 -0
- package/src/HotTesterAPI.ts +126 -0
- package/src/HotTesterMocha.ts +133 -0
- package/src/HotTesterMochaSelenium.ts +189 -0
- package/src/HotTesterServer.ts +551 -0
- package/src/api-web.ts +48 -0
- package/src/api.ts +103 -0
- package/src/cli.ts +1225 -0
- package/src/schemas/HotDBInflux.ts +211 -0
- package/src/schemas/HotDBMigration.ts +24 -0
- package/src/schemas/HotDBMySQL.ts +312 -0
- package/src/schemas/HotDBSchema.ts +21 -0
- package/src/schemas/influx/InfluxSchema.ts +19 -0
- package/src/schemas/mysql/MySQLSchema.ts +90 -0
- package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
- package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
- package/temp/HotStaqWeb.ts +59 -0
- package/tsconfig-generator.json +17 -0
- package/tsconfig-web.json +74 -0
- package/tsconfig.json +73 -0
- package/webpack.config.generator.js +41 -0
- package/webpack.config.js +53 -0
- package/webpack.config.tests.js +56 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { DeveloperMode } from "./Hot";
|
|
2
|
+
import { HotTestDriver } from "./HotTestDriver";
|
|
3
|
+
import { HotRoute } from "./HotRoute";
|
|
4
|
+
import { HotServer } from "./HotServer";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Available HTTP methods.
|
|
8
|
+
*/
|
|
9
|
+
export enum HTTPMethod
|
|
10
|
+
{
|
|
11
|
+
GET = "get",
|
|
12
|
+
POST = "post"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A function that will be executed by the server when first registering with Express.
|
|
17
|
+
* If this returns false, this route method will not be registered.
|
|
18
|
+
*/
|
|
19
|
+
export type ServerRegistrationFunction = () => Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* A function that will be executed by the server.
|
|
22
|
+
*/
|
|
23
|
+
export type ServerExecutionFunction =
|
|
24
|
+
(req: any, res: any, authorizedValue: any, jsonObj: any, queryObj: any) => Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* A function that will be executed by the client.
|
|
27
|
+
*/
|
|
28
|
+
export type ClientExecutionFunction = (...args: any[]) => Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* A function that will be executed by the server for authorization. Any value
|
|
31
|
+
* returned from this function will be passed to the ServerExecutionFunction.
|
|
32
|
+
* If an undefined value is returned, this indicates the server was not able
|
|
33
|
+
* to authenticate the user, so the ServerExecutionFunction will not be
|
|
34
|
+
* executed.
|
|
35
|
+
*/
|
|
36
|
+
export type ServerAuthorizationFunction = (req: any, res: any, jsonObj: any, queryObj: any) => Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* The test case function to execute.
|
|
39
|
+
*/
|
|
40
|
+
export type TestCaseFunction = ((driver: HotTestDriver) => Promise<any>) | ((driver: HotTestDriver) => any);
|
|
41
|
+
/**
|
|
42
|
+
* The test case object to pass.
|
|
43
|
+
*/
|
|
44
|
+
export interface TestCaseObject
|
|
45
|
+
{
|
|
46
|
+
/**
|
|
47
|
+
* The name of the test case.
|
|
48
|
+
*/
|
|
49
|
+
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* The function to execute.
|
|
52
|
+
*/
|
|
53
|
+
func: TestCaseFunction;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* An API method to make.
|
|
58
|
+
*/
|
|
59
|
+
export class HotRouteMethod
|
|
60
|
+
{
|
|
61
|
+
/**
|
|
62
|
+
* The parent route.
|
|
63
|
+
*/
|
|
64
|
+
parentRoute: HotRoute;
|
|
65
|
+
/**
|
|
66
|
+
* The api call name.
|
|
67
|
+
*/
|
|
68
|
+
name: string;
|
|
69
|
+
/**
|
|
70
|
+
* The api call name.
|
|
71
|
+
*/
|
|
72
|
+
type: HTTPMethod;
|
|
73
|
+
/**
|
|
74
|
+
* Has this method been registered with the server? This
|
|
75
|
+
* prevents the method from being reregistered.
|
|
76
|
+
*/
|
|
77
|
+
isRegistered: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Has this method been registered with the server? This
|
|
80
|
+
* prevents the method from being reregistered.
|
|
81
|
+
*/
|
|
82
|
+
executeSetup: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The authorization credentials to be used by the client
|
|
85
|
+
* when connecting to the server.
|
|
86
|
+
*/
|
|
87
|
+
authCredentials: any;
|
|
88
|
+
/**
|
|
89
|
+
* The test case objects to execute during tests.
|
|
90
|
+
*/
|
|
91
|
+
testCases: {
|
|
92
|
+
[name: string]: TestCaseObject;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
constructor (route: HotRoute, name: string,
|
|
96
|
+
onExecute: ServerExecutionFunction | ClientExecutionFunction = null,
|
|
97
|
+
type: HTTPMethod = HTTPMethod.POST, onServerAuthorize: ServerAuthorizationFunction = null,
|
|
98
|
+
onRegister: ServerRegistrationFunction = null, authCredentials: any = null,
|
|
99
|
+
testCases: (string | TestCaseFunction)[] | TestCaseFunction[] | TestCaseObject[] = null)
|
|
100
|
+
{
|
|
101
|
+
this.parentRoute = route;
|
|
102
|
+
this.name = name;
|
|
103
|
+
this.type = type;
|
|
104
|
+
this.isRegistered = false;
|
|
105
|
+
this.executeSetup = false;
|
|
106
|
+
this.authCredentials = authCredentials;
|
|
107
|
+
this.onServerAuthorize = onServerAuthorize;
|
|
108
|
+
this.onRegister = onRegister;
|
|
109
|
+
this.testCases = {};
|
|
110
|
+
|
|
111
|
+
if (this.parentRoute.connection.processor.mode === DeveloperMode.Development)
|
|
112
|
+
{
|
|
113
|
+
if (testCases != null)
|
|
114
|
+
{
|
|
115
|
+
for (let iIdx = 0; iIdx < testCases.length; iIdx++)
|
|
116
|
+
{
|
|
117
|
+
let obj = testCases[iIdx];
|
|
118
|
+
|
|
119
|
+
if (typeof (obj) === "string")
|
|
120
|
+
{
|
|
121
|
+
const name: string = obj;
|
|
122
|
+
const func: TestCaseFunction = (<TestCaseFunction>testCases[iIdx + 1]);
|
|
123
|
+
|
|
124
|
+
this.addTestCase (name, func);
|
|
125
|
+
iIdx++;
|
|
126
|
+
}
|
|
127
|
+
else
|
|
128
|
+
this.addTestCase (obj);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (this.parentRoute.connection instanceof HotServer)
|
|
134
|
+
this.onServerExecute = onExecute;
|
|
135
|
+
//else
|
|
136
|
+
//this.onClientExecute = onExecute;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Executes before all routes have been registered.
|
|
141
|
+
*/
|
|
142
|
+
onPreRegister?: () => Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Executes when first registering this method with Express. If
|
|
145
|
+
* this returns false, the method will not be registered.
|
|
146
|
+
*/
|
|
147
|
+
onRegister?: ServerRegistrationFunction;
|
|
148
|
+
/**
|
|
149
|
+
* Executes after all routes have been registered.
|
|
150
|
+
*/
|
|
151
|
+
onPostRegister?: () => Promise<void>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Executes when authorizing a called method. If this method
|
|
155
|
+
* is set, this will not call onAuthorize for the parent HotRoute.
|
|
156
|
+
* The value returned from here will be passed to onExecute.
|
|
157
|
+
* Undefined returning from here will mean the authorization failed.
|
|
158
|
+
* If any exceptions are thrown from this function, they will be sent
|
|
159
|
+
* to the server as an { error: string; } object with the exception
|
|
160
|
+
* message as the error.
|
|
161
|
+
*/
|
|
162
|
+
onServerAuthorize?: ServerAuthorizationFunction;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Executes when executing a called method from the server side.
|
|
166
|
+
* This will stringify any JSON object and send it as a JSON response.
|
|
167
|
+
* If undefined is returned no response will be sent to the server.
|
|
168
|
+
* So the developer would have to send a response using "res".
|
|
169
|
+
* If any exceptions are thrown from this function, they will be sent
|
|
170
|
+
* to the server as an { error: string; } object with the exception
|
|
171
|
+
* message as the error.
|
|
172
|
+
*/
|
|
173
|
+
onServerExecute?: ServerExecutionFunction;
|
|
174
|
+
/**
|
|
175
|
+
* Executes when executing a called method from the client side.
|
|
176
|
+
* @fixme Is this necessary?
|
|
177
|
+
*/
|
|
178
|
+
onClientExecute?: ClientExecutionFunction;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Add a new test case.
|
|
182
|
+
*/
|
|
183
|
+
addTestCase (newTestCase: TestCaseObject | string | TestCaseFunction,
|
|
184
|
+
testCaseFunction: TestCaseFunction = null): void
|
|
185
|
+
{
|
|
186
|
+
if (typeof (newTestCase) === "string")
|
|
187
|
+
{
|
|
188
|
+
const name: string = newTestCase;
|
|
189
|
+
const func: TestCaseFunction = testCaseFunction;
|
|
190
|
+
|
|
191
|
+
this.testCases[name] = {
|
|
192
|
+
name: name,
|
|
193
|
+
func: func
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (typeof (newTestCase) === "function")
|
|
200
|
+
{
|
|
201
|
+
const testCaseId: number = Object.keys (this.testCases).length;
|
|
202
|
+
const name: string = `${this.parentRoute.route}/${this.name} test case ${testCaseId}`;
|
|
203
|
+
const func: TestCaseFunction = (<TestCaseFunction>newTestCase);
|
|
204
|
+
|
|
205
|
+
this.testCases[name] = {
|
|
206
|
+
name: name,
|
|
207
|
+
func: func
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const testCase: TestCaseObject = (<TestCaseObject>newTestCase);
|
|
214
|
+
this.testCases[testCase.name] = testCase;
|
|
215
|
+
}
|
|
216
|
+
}
|
package/src/HotServer.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { HotStaq } from "./HotStaq";
|
|
2
|
+
import { HotLog } from "./HotLog";
|
|
3
|
+
import { HotAPI } from "./HotAPI";
|
|
4
|
+
import { HotRoute } from "./HotRoute";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The type of server.
|
|
8
|
+
*/
|
|
9
|
+
export enum HotServerType
|
|
10
|
+
{
|
|
11
|
+
HTTP,
|
|
12
|
+
WebSockets
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The server.
|
|
17
|
+
*/
|
|
18
|
+
export interface IHotServer
|
|
19
|
+
{
|
|
20
|
+
/**
|
|
21
|
+
* The processor to use.
|
|
22
|
+
*/
|
|
23
|
+
processor: HotStaq;
|
|
24
|
+
/**
|
|
25
|
+
* The server type.
|
|
26
|
+
*/
|
|
27
|
+
serverType: string;
|
|
28
|
+
/**
|
|
29
|
+
* The API to use.
|
|
30
|
+
*/
|
|
31
|
+
api: HotAPI;
|
|
32
|
+
/**
|
|
33
|
+
* The network address to listen on.
|
|
34
|
+
*/
|
|
35
|
+
listenAddress: string;
|
|
36
|
+
/**
|
|
37
|
+
* The ports to use.
|
|
38
|
+
*/
|
|
39
|
+
ports: {
|
|
40
|
+
http: number;
|
|
41
|
+
https: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* SSL settings.
|
|
45
|
+
*/
|
|
46
|
+
ssl: {
|
|
47
|
+
/**
|
|
48
|
+
* The SSL certificate to use.
|
|
49
|
+
*/
|
|
50
|
+
cert: string;
|
|
51
|
+
/**
|
|
52
|
+
* The SSL certificate key to use.
|
|
53
|
+
*/
|
|
54
|
+
key: string;
|
|
55
|
+
/**
|
|
56
|
+
* The SSL certificate CA to use.
|
|
57
|
+
*/
|
|
58
|
+
ca: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Redirect HTTP traffic to HTTPS.
|
|
62
|
+
*/
|
|
63
|
+
redirectHTTPtoHTTPS: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The type of server.
|
|
66
|
+
*/
|
|
67
|
+
type: HotServerType;
|
|
68
|
+
/**
|
|
69
|
+
* The logger.
|
|
70
|
+
*/
|
|
71
|
+
logger: HotLog;
|
|
72
|
+
/**
|
|
73
|
+
* Any secrets associated with this server.
|
|
74
|
+
*/
|
|
75
|
+
secrets: any;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The server.
|
|
80
|
+
*/
|
|
81
|
+
export class HotServer implements IHotServer
|
|
82
|
+
{
|
|
83
|
+
/**
|
|
84
|
+
* The processor to use.
|
|
85
|
+
*/
|
|
86
|
+
processor: HotStaq;
|
|
87
|
+
/**
|
|
88
|
+
* The server type.
|
|
89
|
+
*/
|
|
90
|
+
serverType: string;
|
|
91
|
+
/**
|
|
92
|
+
* The API to use.
|
|
93
|
+
*/
|
|
94
|
+
api: HotAPI;
|
|
95
|
+
/**
|
|
96
|
+
* The network address to listen on.
|
|
97
|
+
*/
|
|
98
|
+
listenAddress: string;
|
|
99
|
+
/**
|
|
100
|
+
* The ports to use.
|
|
101
|
+
*/
|
|
102
|
+
ports: {
|
|
103
|
+
http: number;
|
|
104
|
+
https: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* SSL settings.
|
|
108
|
+
*/
|
|
109
|
+
ssl: {
|
|
110
|
+
/**
|
|
111
|
+
* The SSL certificate to use.
|
|
112
|
+
*/
|
|
113
|
+
cert: string;
|
|
114
|
+
/**
|
|
115
|
+
* The SSL certificate key to use.
|
|
116
|
+
*/
|
|
117
|
+
key: string;
|
|
118
|
+
/**
|
|
119
|
+
* The SSL certificate CA to use.
|
|
120
|
+
*/
|
|
121
|
+
ca: string;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Redirect HTTP traffic to HTTPS.
|
|
125
|
+
*/
|
|
126
|
+
redirectHTTPtoHTTPS: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* The type of server.
|
|
129
|
+
*/
|
|
130
|
+
type: HotServerType;
|
|
131
|
+
/**
|
|
132
|
+
* The logger.
|
|
133
|
+
*/
|
|
134
|
+
logger: HotLog;
|
|
135
|
+
/**
|
|
136
|
+
* Any secrets associated with this server.
|
|
137
|
+
*/
|
|
138
|
+
secrets: any;
|
|
139
|
+
|
|
140
|
+
constructor (processor: HotStaq | HotServer)
|
|
141
|
+
{
|
|
142
|
+
if (processor instanceof HotStaq)
|
|
143
|
+
{
|
|
144
|
+
this.processor = processor;
|
|
145
|
+
this.serverType = "Server";
|
|
146
|
+
this.api = null;
|
|
147
|
+
this.listenAddress = "0.0.0.0";
|
|
148
|
+
this.ports = {
|
|
149
|
+
http: 80,
|
|
150
|
+
https: 443
|
|
151
|
+
};
|
|
152
|
+
this.ssl = {
|
|
153
|
+
cert: "",
|
|
154
|
+
key: "",
|
|
155
|
+
ca: ""
|
|
156
|
+
};
|
|
157
|
+
this.redirectHTTPtoHTTPS = true;
|
|
158
|
+
this.type = HotServerType.HTTP;
|
|
159
|
+
this.logger = processor.logger;
|
|
160
|
+
this.secrets = {};
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
{
|
|
164
|
+
this.processor = processor.processor;
|
|
165
|
+
this.serverType = processor.serverType || "Server";
|
|
166
|
+
this.api = processor.api || null;
|
|
167
|
+
this.listenAddress = processor.listenAddress || "0.0.0.0";
|
|
168
|
+
this.ports = processor.ports || {
|
|
169
|
+
http: 80,
|
|
170
|
+
https: 443
|
|
171
|
+
};
|
|
172
|
+
this.ssl = processor.ssl || {
|
|
173
|
+
cert: "",
|
|
174
|
+
key: "",
|
|
175
|
+
ca: ""
|
|
176
|
+
};
|
|
177
|
+
this.redirectHTTPtoHTTPS = processor.redirectHTTPtoHTTPS != null ? processor.redirectHTTPtoHTTPS : true;
|
|
178
|
+
this.type = processor.type || HotServerType.HTTP;
|
|
179
|
+
this.logger = processor.logger;
|
|
180
|
+
this.secrets = processor.secrets || {};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Set an API to this server. This will also set the associated
|
|
186
|
+
* processor to this API as well.
|
|
187
|
+
*/
|
|
188
|
+
async setAPI (api: HotAPI): Promise<void>
|
|
189
|
+
{
|
|
190
|
+
this.processor.api = api;
|
|
191
|
+
this.api = api;
|
|
192
|
+
|
|
193
|
+
//if (registerRoutes === true)
|
|
194
|
+
//await this.api.registerRoutes ();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Register a route with the server.
|
|
199
|
+
*/
|
|
200
|
+
async registerRoute? (route: HotRoute): Promise<void>;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Start listening for requests.
|
|
204
|
+
*/
|
|
205
|
+
async listen? (): Promise<void>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Shutdown the server.
|
|
209
|
+
*/
|
|
210
|
+
async shutdown? (): Promise<void>;
|
|
211
|
+
}
|