hotstaq 0.5.24

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.
Files changed (299) hide show
  1. package/.eslintignore +17 -0
  2. package/.eslintrc.js +11 -0
  3. package/.vscode/launch.json +199 -0
  4. package/.vscode/settings.json +2 -0
  5. package/.vscode/tasks.json +78 -0
  6. package/CONTRIBUTING.md +157 -0
  7. package/README.md +126 -0
  8. package/bin/hotstaq +3 -0
  9. package/bin/hotstaq.cmd +1 -0
  10. package/build/src/Hot.d.ts +167 -0
  11. package/build/src/Hot.d.ts.map +1 -0
  12. package/build/src/Hot.js +365 -0
  13. package/build/src/Hot.js.map +1 -0
  14. package/build/src/HotAPI.d.ts +130 -0
  15. package/build/src/HotAPI.d.ts.map +1 -0
  16. package/build/src/HotAPI.js +353 -0
  17. package/build/src/HotAPI.js.map +1 -0
  18. package/build/src/HotAgentAPI.d.ts +22 -0
  19. package/build/src/HotAgentAPI.d.ts.map +1 -0
  20. package/build/src/HotAgentAPI.js +85 -0
  21. package/build/src/HotAgentAPI.js.map +1 -0
  22. package/build/src/HotAgentRoute.d.ts +17 -0
  23. package/build/src/HotAgentRoute.d.ts.map +1 -0
  24. package/build/src/HotAgentRoute.js +109 -0
  25. package/build/src/HotAgentRoute.js.map +1 -0
  26. package/build/src/HotBuilder.d.ts +52 -0
  27. package/build/src/HotBuilder.d.ts.map +1 -0
  28. package/build/src/HotBuilder.js +239 -0
  29. package/build/src/HotBuilder.js.map +1 -0
  30. package/build/src/HotClient.d.ts +31 -0
  31. package/build/src/HotClient.d.ts.map +1 -0
  32. package/build/src/HotClient.js +19 -0
  33. package/build/src/HotClient.js.map +1 -0
  34. package/build/src/HotComponent.d.ts +118 -0
  35. package/build/src/HotComponent.d.ts.map +1 -0
  36. package/build/src/HotComponent.js +89 -0
  37. package/build/src/HotComponent.js.map +1 -0
  38. package/build/src/HotCreator.d.ts +92 -0
  39. package/build/src/HotCreator.d.ts.map +1 -0
  40. package/build/src/HotCreator.js +465 -0
  41. package/build/src/HotCreator.js.map +1 -0
  42. package/build/src/HotDB.d.ts +69 -0
  43. package/build/src/HotDB.d.ts.map +1 -0
  44. package/build/src/HotDB.js +29 -0
  45. package/build/src/HotDB.js.map +1 -0
  46. package/build/src/HotDBConnectionInterface.d.ts +40 -0
  47. package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
  48. package/build/src/HotDBConnectionInterface.js +3 -0
  49. package/build/src/HotDBConnectionInterface.js.map +1 -0
  50. package/build/src/HotFile.d.ts +134 -0
  51. package/build/src/HotFile.d.ts.map +1 -0
  52. package/build/src/HotFile.js +454 -0
  53. package/build/src/HotFile.js.map +1 -0
  54. package/build/src/HotHTTPServer.d.ts +162 -0
  55. package/build/src/HotHTTPServer.d.ts.map +1 -0
  56. package/build/src/HotHTTPServer.js +863 -0
  57. package/build/src/HotHTTPServer.js.map +1 -0
  58. package/build/src/HotIO.d.ts +39 -0
  59. package/build/src/HotIO.d.ts.map +1 -0
  60. package/build/src/HotIO.js +195 -0
  61. package/build/src/HotIO.js.map +1 -0
  62. package/build/src/HotLog.d.ts +60 -0
  63. package/build/src/HotLog.d.ts.map +1 -0
  64. package/build/src/HotLog.js +126 -0
  65. package/build/src/HotLog.js.map +1 -0
  66. package/build/src/HotPage.d.ts +125 -0
  67. package/build/src/HotPage.d.ts.map +1 -0
  68. package/build/src/HotPage.js +178 -0
  69. package/build/src/HotPage.js.map +1 -0
  70. package/build/src/HotRoute.d.ts +82 -0
  71. package/build/src/HotRoute.d.ts.map +1 -0
  72. package/build/src/HotRoute.js +83 -0
  73. package/build/src/HotRoute.js.map +1 -0
  74. package/build/src/HotRouteMethod.d.ts +129 -0
  75. package/build/src/HotRouteMethod.d.ts.map +1 -0
  76. package/build/src/HotRouteMethod.js +84 -0
  77. package/build/src/HotRouteMethod.js.map +1 -0
  78. package/build/src/HotServer.d.ts +152 -0
  79. package/build/src/HotServer.d.ts.map +1 -0
  80. package/build/src/HotServer.js +109 -0
  81. package/build/src/HotServer.js.map +1 -0
  82. package/build/src/HotSetAsWeb.d.ts +2 -0
  83. package/build/src/HotSetAsWeb.d.ts.map +1 -0
  84. package/build/src/HotSetAsWeb.js +5 -0
  85. package/build/src/HotSetAsWeb.js.map +1 -0
  86. package/build/src/HotStaq.d.ts +601 -0
  87. package/build/src/HotStaq.d.ts.map +1 -0
  88. package/build/src/HotStaq.js +1258 -0
  89. package/build/src/HotStaq.js.map +1 -0
  90. package/build/src/HotStaqWeb.d.ts +18 -0
  91. package/build/src/HotStaqWeb.d.ts.map +1 -0
  92. package/build/src/HotStaqWeb.js +44 -0
  93. package/build/src/HotStaqWeb.js.map +1 -0
  94. package/build/src/HotTestDriver.d.ts +63 -0
  95. package/build/src/HotTestDriver.d.ts.map +1 -0
  96. package/build/src/HotTestDriver.js +187 -0
  97. package/build/src/HotTestDriver.js.map +1 -0
  98. package/build/src/HotTestElement.d.ts +71 -0
  99. package/build/src/HotTestElement.d.ts.map +1 -0
  100. package/build/src/HotTestElement.js +37 -0
  101. package/build/src/HotTestElement.js.map +1 -0
  102. package/build/src/HotTestMap.d.ts +83 -0
  103. package/build/src/HotTestMap.d.ts.map +1 -0
  104. package/build/src/HotTestMap.js +58 -0
  105. package/build/src/HotTestMap.js.map +1 -0
  106. package/build/src/HotTestSeleniumDriver.d.ts +82 -0
  107. package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
  108. package/build/src/HotTestSeleniumDriver.js +398 -0
  109. package/build/src/HotTestSeleniumDriver.js.map +1 -0
  110. package/build/src/HotTester.d.ts +188 -0
  111. package/build/src/HotTester.d.ts.map +1 -0
  112. package/build/src/HotTester.js +623 -0
  113. package/build/src/HotTester.js.map +1 -0
  114. package/build/src/HotTesterAPI.d.ts +15 -0
  115. package/build/src/HotTesterAPI.d.ts.map +1 -0
  116. package/build/src/HotTesterAPI.js +161 -0
  117. package/build/src/HotTesterAPI.js.map +1 -0
  118. package/build/src/HotTesterMocha.d.ts +50 -0
  119. package/build/src/HotTesterMocha.d.ts.map +1 -0
  120. package/build/src/HotTesterMocha.js +205 -0
  121. package/build/src/HotTesterMocha.js.map +1 -0
  122. package/build/src/HotTesterMochaSelenium.d.ts +70 -0
  123. package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
  124. package/build/src/HotTesterMochaSelenium.js +257 -0
  125. package/build/src/HotTesterMochaSelenium.js.map +1 -0
  126. package/build/src/HotTesterServer.d.ts +114 -0
  127. package/build/src/HotTesterServer.d.ts.map +1 -0
  128. package/build/src/HotTesterServer.js +575 -0
  129. package/build/src/HotTesterServer.js.map +1 -0
  130. package/build/src/api.d.ts +33 -0
  131. package/build/src/api.d.ts.map +1 -0
  132. package/build/src/api.js +78 -0
  133. package/build/src/api.js.map +1 -0
  134. package/build/src/cli.d.ts +2 -0
  135. package/build/src/cli.d.ts.map +1 -0
  136. package/build/src/cli.js +935 -0
  137. package/build/src/cli.js.map +1 -0
  138. package/build/src/schemas/HotDBInflux.d.ts +63 -0
  139. package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
  140. package/build/src/schemas/HotDBInflux.js +239 -0
  141. package/build/src/schemas/HotDBInflux.js.map +1 -0
  142. package/build/src/schemas/HotDBMigration.d.ts +19 -0
  143. package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
  144. package/build/src/schemas/HotDBMigration.js +15 -0
  145. package/build/src/schemas/HotDBMigration.js.map +1 -0
  146. package/build/src/schemas/HotDBMySQL.d.ts +65 -0
  147. package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
  148. package/build/src/schemas/HotDBMySQL.js +387 -0
  149. package/build/src/schemas/HotDBMySQL.js.map +1 -0
  150. package/build/src/schemas/HotDBSchema.d.ts +15 -0
  151. package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
  152. package/build/src/schemas/HotDBSchema.js +19 -0
  153. package/build/src/schemas/HotDBSchema.js.map +1 -0
  154. package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
  155. package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
  156. package/build/src/schemas/influx/InfluxSchema.js +33 -0
  157. package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
  158. package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
  159. package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
  160. package/build/src/schemas/mysql/MySQLSchema.js +151 -0
  161. package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
  162. package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
  163. package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
  164. package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
  165. package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
  166. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
  167. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
  168. package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
  169. package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
  170. package/build-web/HotStaq.js +2 -0
  171. package/build-web/HotStaq.min.js +125 -0
  172. package/builder/docker/Dockerfile.linux.gen +42 -0
  173. package/builder/docker/README.md +36 -0
  174. package/builder/docker/app/start.sh +8 -0
  175. package/builder/docker/dockerignore +3 -0
  176. package/builder/docker/scripts/build.bat +11 -0
  177. package/builder/docker/scripts/build.sh +11 -0
  178. package/builder/docker/scripts/start-app.bat +7 -0
  179. package/builder/docker/scripts/start-app.sh +7 -0
  180. package/builder/docker/scripts/stop-app.bat +5 -0
  181. package/builder/docker/scripts/stop-app.sh +5 -0
  182. package/builder/docker-compose/docker-compose.gen.yaml +41 -0
  183. package/builder/docker-compose/env-skeleton +4 -0
  184. package/creator/project/.vscode/launch.json +59 -0
  185. package/creator/project/README.md +20 -0
  186. package/creator/project/gitignore +118 -0
  187. package/creator/project/npmignore +118 -0
  188. package/creator/public/api-test.hott +28 -0
  189. package/creator/public/index.hott +12 -0
  190. package/creator/ts/src/AppAPI.ts +30 -0
  191. package/creator/ts/src/HelloWorld.ts +39 -0
  192. package/creator/ts/src/WebExport.ts +7 -0
  193. package/creator/ts/tsconfig-web.json +73 -0
  194. package/creator/ts/tsconfig.json +73 -0
  195. package/creator/ts/webpack-api.config.js +57 -0
  196. package/dbstart.sh +19 -0
  197. package/dbstop.sh +4 -0
  198. package/docs/.nojekyll +1 -0
  199. package/docs/README.md +128 -0
  200. package/docs/classes/Hot.md +477 -0
  201. package/docs/classes/HotAPI.md +369 -0
  202. package/docs/classes/HotClient.md +95 -0
  203. package/docs/classes/HotComponent.md +279 -0
  204. package/docs/classes/HotDB.md +247 -0
  205. package/docs/classes/HotDBInflux.md +404 -0
  206. package/docs/classes/HotDBMigration.md +80 -0
  207. package/docs/classes/HotDBMySQL.md +310 -0
  208. package/docs/classes/HotDBSchema.md +51 -0
  209. package/docs/classes/HotFile.md +353 -0
  210. package/docs/classes/HotHTTPServer.md +700 -0
  211. package/docs/classes/HotLog.md +162 -0
  212. package/docs/classes/HotPage.md +357 -0
  213. package/docs/classes/HotRoute.md +312 -0
  214. package/docs/classes/HotRouteMethod.md +271 -0
  215. package/docs/classes/HotServer.md +311 -0
  216. package/docs/classes/HotStaq.md +1153 -0
  217. package/docs/classes/HotTestDestination.md +58 -0
  218. package/docs/classes/HotTestDriver.md +332 -0
  219. package/docs/classes/HotTestElement.md +88 -0
  220. package/docs/classes/HotTestElementOptions.md +71 -0
  221. package/docs/classes/HotTestMap.md +92 -0
  222. package/docs/classes/HotTestSeleniumDriver.md +529 -0
  223. package/docs/classes/HotTester.md +653 -0
  224. package/docs/classes/HotTesterAPI.md +493 -0
  225. package/docs/classes/HotTesterMocha.md +843 -0
  226. package/docs/classes/HotTesterMochaSelenium.md +896 -0
  227. package/docs/classes/HotTesterServer.md +633 -0
  228. package/docs/classes/InfluxSchema.md +74 -0
  229. package/docs/classes/MySQLSchema.md +199 -0
  230. package/docs/classes/MySQLSchemaField.md +330 -0
  231. package/docs/classes/MySQLSchemaTable.md +176 -0
  232. package/docs/enums/ConnectionStatus.md +43 -0
  233. package/docs/enums/DeveloperMode.md +38 -0
  234. package/docs/enums/EventExecutionType.md +43 -0
  235. package/docs/enums/HTTPMethod.md +32 -0
  236. package/docs/enums/HotDBGenerationType.md +30 -0
  237. package/docs/enums/HotLogLevel.md +88 -0
  238. package/docs/interfaces/HotDBConnectionInterface.md +116 -0
  239. package/docs/interfaces/HotDestination.md +62 -0
  240. package/docs/interfaces/HotSite.md +187 -0
  241. package/docs/interfaces/HotSiteMapPath.md +37 -0
  242. package/docs/interfaces/HotSiteRoute.md +79 -0
  243. package/docs/interfaces/HotStartOptions.md +115 -0
  244. package/docs/interfaces/HotTestPage.md +44 -0
  245. package/docs/interfaces/HotTestStop.md +62 -0
  246. package/docs/interfaces/IHotComponent.md +135 -0
  247. package/docs/interfaces/IHotStaq.md +118 -0
  248. package/docs/interfaces/IHotTestElement.md +54 -0
  249. package/docs/interfaces/IHotTestElementOptions.md +43 -0
  250. package/docs/interfaces/MySQLResults.md +43 -0
  251. package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
  252. package/docs/modules.md +162 -0
  253. package/package.json +65 -0
  254. package/selenium-start.sh +7 -0
  255. package/selenium-stop.sh +3 -0
  256. package/src/Hot.ts +319 -0
  257. package/src/HotAPI.ts +378 -0
  258. package/src/HotAgentAPI.ts +43 -0
  259. package/src/HotAgentRoute.ts +44 -0
  260. package/src/HotBuilder.ts +221 -0
  261. package/src/HotClient.ts +40 -0
  262. package/src/HotComponent.ts +158 -0
  263. package/src/HotCreator.ts +482 -0
  264. package/src/HotDB.ts +79 -0
  265. package/src/HotDBConnectionInterface.ts +40 -0
  266. package/src/HotFile.ts +617 -0
  267. package/src/HotHTTPServer.ts +954 -0
  268. package/src/HotIO.ts +128 -0
  269. package/src/HotLog.ts +158 -0
  270. package/src/HotPage.ts +206 -0
  271. package/src/HotRoute.ts +137 -0
  272. package/src/HotRouteMethod.ts +216 -0
  273. package/src/HotServer.ts +211 -0
  274. package/src/HotSetAsWeb.ts +3 -0
  275. package/src/HotStaq.ts +1877 -0
  276. package/src/HotStaqWeb.ts +59 -0
  277. package/src/HotTestDriver.ts +172 -0
  278. package/src/HotTestElement.ts +97 -0
  279. package/src/HotTestMap.ts +130 -0
  280. package/src/HotTestSeleniumDriver.ts +374 -0
  281. package/src/HotTester.ts +697 -0
  282. package/src/HotTesterAPI.ts +126 -0
  283. package/src/HotTesterMocha.ts +133 -0
  284. package/src/HotTesterMochaSelenium.ts +189 -0
  285. package/src/HotTesterServer.ts +551 -0
  286. package/src/api.ts +102 -0
  287. package/src/cli.ts +1147 -0
  288. package/src/schemas/HotDBInflux.ts +211 -0
  289. package/src/schemas/HotDBMigration.ts +24 -0
  290. package/src/schemas/HotDBMySQL.ts +312 -0
  291. package/src/schemas/HotDBSchema.ts +21 -0
  292. package/src/schemas/influx/InfluxSchema.ts +19 -0
  293. package/src/schemas/mysql/MySQLSchema.ts +90 -0
  294. package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
  295. package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
  296. package/tsconfig-web.json +74 -0
  297. package/tsconfig.json +73 -0
  298. package/webpack.config.js +51 -0
  299. package/webpack.config.tests.js +56 -0
@@ -0,0 +1,551 @@
1
+ import * as http from "http";
2
+ import * as https from "https";
3
+ import * as fs from "fs";
4
+ import { F_OK } from "constants";
5
+
6
+ import express from "express";
7
+
8
+ import { HotServer } from "./HotServer";
9
+ import { HotStaq } from "./HotStaq";
10
+ import { HotRoute } from "./HotRoute";
11
+ import { HotRouteMethod, HTTPMethod } from "./HotRouteMethod";
12
+ import { HotTesterAPI } from "./HotTesterAPI";
13
+ import { DeveloperMode } from "./Hot";
14
+ import { HotLogLevel } from "./HotLog";
15
+ import { EventExecutionType, HotAPI } from "./HotAPI";
16
+ import { HotTester } from "./HotTester";
17
+
18
+ /**
19
+ * An API server for use during testing.
20
+ */
21
+ export class HotTesterServer extends HotServer
22
+ {
23
+ /**
24
+ * The express app to use.
25
+ */
26
+ expressApp: express.Express;
27
+ /**
28
+ * The HTTP listener to use.
29
+ */
30
+ httpListener: http.Server;
31
+ /**
32
+ * The HTTPS listener to use.
33
+ */
34
+ httpsListener: https.Server;
35
+ /**
36
+ * Any non-static routes that need to be added. These
37
+ * will be added during the preregistration phase, before
38
+ * all API routes are added.
39
+ */
40
+ routes: {
41
+ /**
42
+ * The type of route.
43
+ */
44
+ type: HTTPMethod;
45
+ /**
46
+ * The type of route.
47
+ */
48
+ route: string;
49
+ /**
50
+ * The method to execute when this route is hit.
51
+ */
52
+ method: (req: express.Request, res: express.Response) => Promise<void>;
53
+ }[];
54
+
55
+ constructor (processor: HotStaq | HotServer, httpPort: number = null, httpsPort: number = null)
56
+ {
57
+ super (processor);
58
+
59
+ this.listenAddress = "127.0.0.1";
60
+ this.expressApp = express ();
61
+ this.httpListener = null;
62
+ this.httpsListener = null;
63
+ this.routes = [];
64
+
65
+ if (process.env.TESTER_LISTEN_ADDR != null)
66
+ {
67
+ if (process.env.TESTER_LISTEN_ADDR !== "")
68
+ this.listenAddress = process.env.TESTER_LISTEN_ADDR;
69
+ }
70
+
71
+ if (process.env.TESTER_USE_HTTP != null)
72
+ {
73
+ this.ssl = {
74
+ cert: "",
75
+ key: "",
76
+ ca: ""
77
+ };
78
+ }
79
+
80
+ if (httpPort != null)
81
+ this.ports.http = httpPort;
82
+
83
+ if (httpsPort != null)
84
+ this.ports.https = httpsPort;
85
+
86
+ if (process.env.TESTER_HTTP_PORT != null)
87
+ {
88
+ if (process.env.TESTER_HTTP_PORT !== "")
89
+ this.ports.http = parseInt (process.env.TESTER_HTTP_PORT);
90
+ }
91
+
92
+ if (process.env.TESTER_HTTPS_PORT != null)
93
+ {
94
+ if (process.env.TESTER_HTTPS_PORT !== "")
95
+ this.ports.https = parseInt (process.env.TESTER_HTTPS_PORT);
96
+ }
97
+
98
+ if (process.env.TESTER_HTTPS_SSL_CERT != null)
99
+ {
100
+ if (process.env.TESTER_HTTPS_SSL_CERT !== "")
101
+ this.ssl.cert = process.env.TESTER_HTTPS_SSL_CERT;
102
+
103
+ if (process.env.TESTER_HTTPS_SSL_KEY !== "")
104
+ this.ssl.key = process.env.TESTER_HTTPS_SSL_KEY;
105
+
106
+ if (process.env.TESTER_HTTPS_SSL_CA !== "")
107
+ this.ssl.ca = process.env.TESTER_HTTPS_SSL_CA;
108
+ }
109
+
110
+ let testerJSONLimit: string = "1mb";
111
+
112
+ if (process.env.TESTER_JSON_LIMIT != null)
113
+ {
114
+ if (process.env.TESTER_JSON_LIMIT !== "")
115
+ testerJSONLimit = process.env.TESTER_JSON_LIMIT;
116
+ }
117
+
118
+ this.expressApp.options ("*", (req: express.Request, res: express.Response, next: express.NextFunction) =>
119
+ {
120
+ res.header ("Access-Control-Allow-Origin", "*");
121
+ res.header ("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
122
+ res.header ("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
123
+
124
+ res.statusCode = 204;
125
+ res.setHeader ("Content-Length", "0");
126
+ res.end ();
127
+ });
128
+ this.expressApp.use ((req: express.Request, res: express.Response, next: express.NextFunction) =>
129
+ {
130
+ res.header ("Access-Control-Allow-Origin", "*");
131
+ res.header ("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
132
+ res.header ("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
133
+
134
+ next ();
135
+ });
136
+ this.expressApp.use (express.urlencoded ({ "extended": true }));
137
+ this.expressApp.use (express.json ({ "limit": testerJSONLimit }));
138
+ }
139
+
140
+ /**
141
+ * Add a tester for use later.
142
+ */
143
+ addTester (tester: HotTester): void
144
+ {
145
+ this.processor.logger.verbose (`Added tester ${tester.name}`);
146
+ this.processor.addTester (tester);
147
+ }
148
+
149
+ /**
150
+ * Execute tests.
151
+ */
152
+ async executeTests (testerName: string, mapName: string): Promise<void>
153
+ {
154
+ this.processor.logger.verbose (`Executing tests ${testerName} using map name ${mapName}`);
155
+ return (this.processor.executeTests (testerName, mapName));
156
+ }
157
+
158
+ /**
159
+ * Execute all web tests for all maps in the HotSite testing web object.
160
+ */
161
+ async executeAllWebTests (testerName: string): Promise<void>
162
+ {
163
+ return (this.processor.executeAllWebTests (testerName));
164
+ }
165
+
166
+ /**
167
+ * Execute all api tests for all maps in the HotSite testing api object.
168
+ */
169
+ async executeAllAPITests (testerName: string): Promise<void>
170
+ {
171
+ return (this.processor.executeAllAPITests (testerName));
172
+ }
173
+
174
+ /**
175
+ * Add a route. This will be registered before any APIs are registered.
176
+ */
177
+ addRoute (route: string, method: (req: express.Request, res: express.Response) => Promise<void>,
178
+ type: HTTPMethod = HTTPMethod.GET): void
179
+ {
180
+ let newRoute = {
181
+ type: type,
182
+ route: route,
183
+ method: method
184
+ };
185
+
186
+ this.processor.logger.verbose (`Added route ${route}`);
187
+ this.routes.push (newRoute);
188
+ }
189
+
190
+ /**
191
+ * Register a route.
192
+ */
193
+ async registerRoute (route: HotRoute): Promise<void>
194
+ {
195
+ if (route.onRegister != null)
196
+ {
197
+ if (await route.onRegister () === false)
198
+ return;
199
+ }
200
+
201
+ this.clearErrorHandlingRoutes ();
202
+ this.preregisterRoute ();
203
+
204
+ for (let iIdx = 0; iIdx < route.methods.length; iIdx++)
205
+ {
206
+ let method: HotRouteMethod = route.methods[iIdx];
207
+
208
+ if (method.isRegistered === true)
209
+ continue;
210
+
211
+ if (method.onRegister != null)
212
+ {
213
+ if (await method.onRegister () === false)
214
+ continue;
215
+ }
216
+
217
+ let methodName: string = "/";
218
+
219
+ if (route.version !== "")
220
+ methodName += `${route.version}/`;
221
+
222
+ if (route.prefix !== "")
223
+ methodName += `${route.prefix}/`;
224
+
225
+ if (route.route !== "")
226
+ methodName += `${route.route}/`;
227
+
228
+ methodName += method.name;
229
+ method.isRegistered = true;
230
+
231
+ this.expressApp[method.type] (methodName,
232
+ async (req: express.Request, res: express.Response) =>
233
+ {
234
+ let hasAuthorization: boolean = true;
235
+ let authorizationValue: any = null;
236
+ let jsonObj: any = req.body;
237
+ let queryObj: any = req.query;
238
+ let api: HotAPI = route.connection.api;
239
+ let thisObj: any = route;
240
+
241
+ if (api.executeEventsUsing === EventExecutionType.HotAPI)
242
+ thisObj = api;
243
+
244
+ if (api.executeEventsUsing === EventExecutionType.HotMethod)
245
+ thisObj = method;
246
+
247
+ this.logger.verbose (`${req.method} ${methodName}, JSON: ${JSON.stringify (jsonObj)}, Query: ${JSON.stringify (queryObj)}`);
248
+
249
+ if (method.onServerAuthorize != null)
250
+ {
251
+ try
252
+ {
253
+ authorizationValue =
254
+ await method.onServerAuthorize.call (thisObj, req, res, jsonObj, queryObj);
255
+ }
256
+ catch (ex)
257
+ {
258
+ this.logger.verbose (`Authorization error: ${ex.message}`);
259
+ res.json ({ error: ex.message });
260
+ hasAuthorization = false;
261
+
262
+ return;
263
+ }
264
+
265
+ if (authorizationValue === undefined)
266
+ hasAuthorization = false;
267
+ }
268
+ else
269
+ {
270
+ if (route.onAuthorizeUser != null)
271
+ {
272
+ authorizationValue = await route.onAuthorizeUser (req, res);
273
+
274
+ if (authorizationValue === undefined)
275
+ hasAuthorization = false;
276
+ }
277
+ }
278
+
279
+ this.logger.verbose (`${req.method} ${methodName}, Authorized: ${hasAuthorization}, Authorization Value: ${authorizationValue}`);
280
+
281
+ if (hasAuthorization === true)
282
+ {
283
+ if (method.onServerExecute != null)
284
+ {
285
+ try
286
+ {
287
+ let result: any =
288
+ await method.onServerExecute.call (
289
+ thisObj, req, res, authorizationValue, jsonObj, queryObj);
290
+
291
+ this.logger.verbose (`${req.method} ${methodName}, Response: ${result}`);
292
+
293
+ if (result !== undefined)
294
+ res.json (result);
295
+ }
296
+ catch (ex)
297
+ {
298
+ this.logger.verbose (`Execution error: ${ex.message}`);
299
+ res.json ({ error: ex.message });
300
+ }
301
+ }
302
+ }
303
+ else
304
+ {
305
+ res.json (route.errors["not_authorized"]);
306
+ this.logger.verbose (`${req.method} ${methodName}, not_authorized`);
307
+ }
308
+ });
309
+ }
310
+
311
+ this.setErrorHandlingRoutes ();
312
+ }
313
+
314
+ /**
315
+ * Check if a file exists.
316
+ */
317
+ static async checkIfFileExists (filepath: string): Promise<boolean>
318
+ {
319
+ return (await new Promise<boolean> ((resolve, reject) =>
320
+ {
321
+ fs.access (filepath, F_OK, (err: NodeJS.ErrnoException) =>
322
+ {
323
+ if (err != null)
324
+ resolve (false);
325
+
326
+ resolve (true);
327
+ });
328
+ }));
329
+ }
330
+
331
+ /**
332
+ * The routes to add before registering a route.
333
+ */
334
+ preregisterRoute (): void
335
+ {
336
+ this.expressApp.use ((req: express.Request, res: express.Response, next: any): void =>
337
+ {
338
+ const url: string = `${req.protocol}://${req.hostname}${req.originalUrl}`;
339
+ this.logger.verbose (`Requested: ${url}`);
340
+
341
+ next ();
342
+ });
343
+
344
+ for (let iIdx = 0; iIdx < this.routes.length; iIdx++)
345
+ {
346
+ let route = this.routes[iIdx];
347
+
348
+ this.expressApp[route.type] (route.route, route.method);
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Set the error handlers. This will create two express routes at the bottom of the
354
+ * route stack. The first will be to capture any 404 errors, the second would be to
355
+ * catch any remaining errors.
356
+ */
357
+ setErrorHandlingRoutes (
358
+ handle404: (req: express.Request, res: express.Response, next: any) => void = null,
359
+ handleOther: (err: any, req: express.Request, res: express.Response, next: any) => void = null
360
+ ): void
361
+ {
362
+ if (handle404 == null)
363
+ {
364
+ handle404 = (req: express.Request, res: express.Response, next: any): void =>
365
+ {
366
+ this.logger.verbose (`404 ${JSON.stringify (req.url)} Method: ${req.method}`);
367
+ res.status (404).send ({ error: "404" });
368
+ };
369
+ }
370
+
371
+ if (handleOther == null)
372
+ {
373
+ handleOther = (err: any, req: express.Request, res: express.Response, next: any): void =>
374
+ {
375
+ let stack: string = "";
376
+ let msg: string = "";
377
+
378
+ if (err != null)
379
+ {
380
+ stack = err.stack;
381
+ msg = err.message;
382
+ }
383
+
384
+ this.logger.verbose (`500 Server error ${JSON.stringify (stack)}`);
385
+ res.status (500).send ({ error: `Server error: ${msg}` });
386
+ };
387
+ }
388
+
389
+ this.expressApp.use (handle404);
390
+ this.expressApp.use (handleOther);
391
+ }
392
+
393
+ /**
394
+ * Clear the last two express routes, which are reserved for the
395
+ * error handlers.
396
+ */
397
+ clearErrorHandlingRoutes (): void
398
+ {
399
+ if (this.expressApp._router == null)
400
+ return;
401
+
402
+ let stackCount: number = this.expressApp._router.stack.length;
403
+
404
+ for (let iIdx = 0; iIdx < stackCount; iIdx++)
405
+ {
406
+ let elm: any = this.expressApp._router.stack[iIdx];
407
+
408
+ if (elm != null)
409
+ {
410
+ let name: string = elm.name;
411
+
412
+ if ((name === "handle404") || (name === "handleOther"))
413
+ {
414
+ (<any[]>this.expressApp._router.stack).splice (iIdx, 1);
415
+ iIdx--;
416
+ stackCount = this.expressApp._router.stack.length;
417
+ }
418
+ }
419
+ }
420
+ }
421
+
422
+ /**
423
+ * Start listening for requests.
424
+ */
425
+ async listen (): Promise<void>
426
+ {
427
+ let promise: Promise<void> = new Promise<void> (
428
+ async (resolve, reject) =>
429
+ {
430
+ let completedSetup = () =>
431
+ {
432
+ let protocol: string = "http";
433
+ let port: number = this.ports.http;
434
+
435
+ if (this.ssl.cert !== "")
436
+ {
437
+ protocol = "https";
438
+ port = this.ports.https;
439
+ }
440
+
441
+ this.logger.info (`Tester server running at ${protocol}://${this.listenAddress}:${port}/`);
442
+ resolve ();
443
+ };
444
+
445
+ if (this.api != null)
446
+ {
447
+ if (this.api.onPreRegister != null)
448
+ {
449
+ let continueRegistering: boolean = await this.api.onPreRegister ();
450
+
451
+ if (continueRegistering === false)
452
+ return;
453
+ }
454
+
455
+ await this.api.registerRoutes ();
456
+
457
+ if (this.api.onPostRegister != null)
458
+ {
459
+ let continueOn: boolean = await this.api.onPostRegister ();
460
+
461
+ if (continueOn === false)
462
+ return;
463
+ }
464
+ }
465
+
466
+ if (this.ssl.cert === "")
467
+ {
468
+ this.httpListener = http.createServer (this.expressApp);
469
+ this.httpListener.listen (this.ports.http, this.listenAddress, completedSetup);
470
+ }
471
+ else
472
+ {
473
+ if (this.redirectHTTPtoHTTPS === true)
474
+ {
475
+ this.httpListener = http.createServer ((req: http.IncomingMessage, res: http.ServerResponse) =>
476
+ {
477
+ let host: string = req.headers["host"];
478
+
479
+ res.writeHead (301, {
480
+ "Location": `https://${host}${req.url}`
481
+ });
482
+ res.end ();
483
+ });
484
+ this.httpListener.listen (this.ports.http, this.listenAddress, () =>
485
+ {
486
+ this.logger.info (`Redirecting HTTP(${this.ports.http}) traffic to HTTPS(${this.ports.https})`);
487
+ });
488
+ }
489
+
490
+ this.httpsListener = https.createServer ({
491
+ cert: this.ssl.cert,
492
+ key: this.ssl.key,
493
+ ca: this.ssl.ca
494
+ }, this.expressApp);
495
+ this.httpsListener.listen (this.ports.https, this.listenAddress, completedSetup);
496
+ }
497
+ });
498
+
499
+ return (promise);
500
+ }
501
+
502
+ /**
503
+ * Setup the tester api.
504
+ */
505
+ async setupTesterAPI (baseUrl: string): Promise<void>
506
+ {
507
+ let api: HotTesterAPI = new HotTesterAPI (baseUrl, this);
508
+ this.processor.testerAPI = api;
509
+ this.api = api;
510
+ await this.api.registerRoutes ();
511
+ }
512
+
513
+ /**
514
+ * Start the server.
515
+ *
516
+ * @param httpPort The HTTP port to listen on.
517
+ * @param httpsPort The HTTPS port to listen on.
518
+ * @param processor The HotStaq or parent server being used for communication.
519
+ */
520
+ static async startServer (baseUrl: string = `http://127.0.0.1:8182`,
521
+ httpPort: number = 8182, httpsPort: number = 4142,
522
+ processor: HotServer | HotStaq = null,
523
+ logLevel: HotLogLevel = HotLogLevel.Info):
524
+ Promise<{ processor: HotServer | HotStaq; server: HotTesterServer; }>
525
+ {
526
+ if (processor == null)
527
+ {
528
+ processor = new HotStaq ();
529
+ processor.mode = DeveloperMode.Development;
530
+ }
531
+
532
+ let webServer: HotTesterServer = new HotTesterServer (processor, httpPort, httpsPort);
533
+ webServer.logger.logLevel = logLevel;
534
+
535
+ processor.logger.verbose (`Starting tester server...`);
536
+
537
+ await webServer.setupTesterAPI (baseUrl);
538
+ await webServer.listen ();
539
+
540
+ return ({ processor: processor, server: webServer });
541
+ }
542
+
543
+ /**
544
+ * Shutdown the server.
545
+ */
546
+ async shutdown (): Promise<void>
547
+ {
548
+ this.httpListener.close ();
549
+ this.expressApp = null;
550
+ }
551
+ }
package/src/api.ts ADDED
@@ -0,0 +1,102 @@
1
+ import { HotStaq, HotStartOptions, IHotStaq,
2
+ HotSite, HotSiteRoute, HotSiteMapPath } from "./HotStaq";
3
+ import { Hot, DeveloperMode } from "./Hot";
4
+ import { HotComponent, IHotComponent } from "./HotComponent";
5
+ import { HotFile } from "./HotFile";
6
+ import { HotLog, HotLogLevel } from "./HotLog";
7
+ import { HotPage } from "./HotPage";
8
+
9
+ // Server stuff
10
+ import { HotAPI, EventExecutionType } from "./HotAPI";
11
+ import { HotRoute } from "./HotRoute";
12
+ import { HotRouteMethod, HTTPMethod, ServerAuthorizationFunction, ServerExecutionFunction } from "./HotRouteMethod";
13
+ import { HotServer } from "./HotServer";
14
+ import { HotHTTPServer } from "./HotHTTPServer";
15
+ import { HotClient } from "./HotClient";
16
+
17
+ // Testing stuff
18
+ import { HotTestDriver } from "./HotTestDriver";
19
+ import { IHotTestElement, HotTestElement, HotTestElementOptions, IHotTestElementOptions } from "./HotTestElement";
20
+ import { HotTester, HotTestStop, HotDestination } from "./HotTester";
21
+ import { HotTesterAPI } from "./HotTesterAPI";
22
+ import { HotTesterMocha } from "./HotTesterMocha";
23
+ import { HotTesterMochaSelenium } from "./HotTesterMochaSelenium";
24
+ import { HotTesterServer } from "./HotTesterServer";
25
+ import { HotTestMap, HotTestDestination, HotTestPath, HotTestPage } from "./HotTestMap";
26
+ import { HotTestSeleniumDriver } from "./HotTestSeleniumDriver";
27
+
28
+ // Database stuff
29
+ import { HotDB, ConnectionStatus } from "./HotDB";
30
+ import { HotDBConnectionInterface } from "./HotDBConnectionInterface";
31
+ import { HotDBGenerationType, HotDBSchema } from "./schemas/HotDBSchema";
32
+
33
+ // MySQL specific database stuff
34
+ import { HotDBMySQL, MySQLResults } from "./schemas/HotDBMySQL";
35
+ import { HotDBMigration } from "./schemas/HotDBMigration";
36
+ import { MySQLSchema } from "./schemas/mysql/MySQLSchema";
37
+ import { MySQLSchemaFieldResult, MySQLSchemaField } from "./schemas/mysql/MySQLSchemaField";
38
+ import { MySQLSchemaTable } from "./schemas/mysql/MySQLSchemaTable";
39
+
40
+ // Influx specific stuff
41
+ import { HotDBInflux } from "./schemas/HotDBInflux";
42
+ import { InfluxSchema } from "./schemas/influx/InfluxSchema";
43
+
44
+ HotStaq.isWeb = false;
45
+
46
+ export {
47
+ HotStaq,
48
+ HotStartOptions,
49
+ IHotStaq,
50
+ HotSite,
51
+ HotSiteRoute,
52
+ HotSiteMapPath,
53
+ Hot,
54
+ DeveloperMode,
55
+ HotComponent,
56
+ IHotComponent,
57
+ HotAPI,
58
+ EventExecutionType,
59
+ HotFile,
60
+ HotLog,
61
+ HotLogLevel,
62
+ HotPage,
63
+ HotDB,
64
+ ConnectionStatus,
65
+ HotRoute,
66
+ HotRouteMethod,
67
+ HTTPMethod,
68
+ ServerAuthorizationFunction,
69
+ ServerExecutionFunction,
70
+ HotServer,
71
+ HotHTTPServer,
72
+ HotClient,
73
+ HotTesterServer,
74
+ HotTester,
75
+ HotTestStop,
76
+ HotDestination,
77
+ HotTesterAPI,
78
+ HotTesterMocha,
79
+ HotTesterMochaSelenium,
80
+ HotTestMap,
81
+ HotTestDestination,
82
+ HotTestPath,
83
+ HotTestPage,
84
+ HotTestSeleniumDriver,
85
+ HotTestElement,
86
+ IHotTestElement,
87
+ HotTestElementOptions,
88
+ IHotTestElementOptions,
89
+ HotTestDriver,
90
+ HotDBGenerationType,
91
+ HotDBConnectionInterface,
92
+ HotDBSchema,
93
+ HotDBMySQL,
94
+ HotDBMigration,
95
+ MySQLResults,
96
+ MySQLSchema,
97
+ MySQLSchemaFieldResult,
98
+ MySQLSchemaField,
99
+ MySQLSchemaTable,
100
+ HotDBInflux,
101
+ InfluxSchema
102
+ };