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
package/src/HotIO.ts ADDED
@@ -0,0 +1,128 @@
1
+ import * as fs from "fs";
2
+ import * as fse from "fs-extra";
3
+
4
+ /**
5
+ * Handles IO for the server.
6
+ */
7
+ export class HotIO
8
+ {
9
+ /**
10
+ * Read a text file.
11
+ */
12
+ static async readTextFile (path: string): Promise<string>
13
+ {
14
+ return (await new Promise (
15
+ (resolve: any, reject: any): void =>
16
+ {
17
+ fs.readFile (path, (err: NodeJS.ErrnoException, data: Buffer): void =>
18
+ {
19
+ if (err != null)
20
+ throw err;
21
+
22
+ let content: string = data.toString ();
23
+
24
+ resolve (content);
25
+ });
26
+ }));
27
+ }
28
+
29
+ /**
30
+ * Write to a text file.
31
+ */
32
+ static async writeTextFile (path: string, content: string): Promise<string>
33
+ {
34
+ return (await new Promise (
35
+ (resolve: any, reject: any): void =>
36
+ {
37
+ fs.writeFile (path, content, (err: NodeJS.ErrnoException): void =>
38
+ {
39
+ if (err != null)
40
+ throw err;
41
+
42
+ resolve ();
43
+ });
44
+ }));
45
+ }
46
+
47
+ /**
48
+ * Make a directory.
49
+ */
50
+ static async mkdir (path: string): Promise<void>
51
+ {
52
+ return (await new Promise (
53
+ (resolve: any, reject: any): void =>
54
+ {
55
+ fs.mkdir (path, { recursive: true },
56
+ (err: NodeJS.ErrnoException, path: string) =>
57
+ {
58
+ if (err != null)
59
+ throw err;
60
+
61
+ resolve ();
62
+ });
63
+ }));
64
+ }
65
+
66
+ /**
67
+ * Copy files to a location.
68
+ */
69
+ static async copyFiles (src: string, dest: string): Promise<void>
70
+ {
71
+ return (fse.copy (src, dest));
72
+ }
73
+
74
+ /**
75
+ * Copy a file to a location.
76
+ */
77
+ static async copyFile (src: string, dest: string, flags?: number): Promise<void>
78
+ {
79
+ return (fse.copyFile (src, dest, flags));
80
+ }
81
+
82
+ /**
83
+ * Move a file to a location.
84
+ */
85
+ static async moveFile (src: string, dest: string, options: fse.MoveOptions = { overwrite: false }): Promise<void>
86
+ {
87
+ return (fse.move (src, dest, options));
88
+ }
89
+
90
+ /**
91
+ * Checks if a file is at a location.
92
+ */
93
+ static async exists (path: string): Promise<boolean>
94
+ {
95
+ return (new Promise<boolean> ((resolve, reject) =>
96
+ {
97
+ fs.stat (path, (err: NodeJS.ErrnoException, stats: fs.Stats) =>
98
+ {
99
+ if (err != null)
100
+ {
101
+ if (err.code === "ENOENT")
102
+ resolve (false);
103
+ else
104
+ throw err;
105
+ }
106
+
107
+ resolve (true);
108
+ });
109
+ }));
110
+ }
111
+
112
+ /**
113
+ * List files at a location.
114
+ */
115
+ static async listFiles (path: string): Promise<string[]>
116
+ {
117
+ return (new Promise<string[]> ((resolve, reject) =>
118
+ {
119
+ fs.readdir (path, (err: NodeJS.ErrnoException, files: string[]) =>
120
+ {
121
+ if (err != null)
122
+ throw err;
123
+
124
+ resolve (files);
125
+ });
126
+ }));
127
+ }
128
+ }
package/src/HotLog.ts ADDED
@@ -0,0 +1,158 @@
1
+ /**
2
+ * The logging level.
3
+ */
4
+ export enum HotLogLevel
5
+ {
6
+ /**
7
+ * Prints only info messages.
8
+ */
9
+ Info,
10
+ /**
11
+ * Prints only warning messages.
12
+ */
13
+ Warning,
14
+ /**
15
+ * Prints only error messages.
16
+ */
17
+ Error,
18
+ /**
19
+ * Prints all messages.
20
+ */
21
+ Verbose,
22
+ /**
23
+ * Prints all messages, except verbose.
24
+ */
25
+ All,
26
+ /**
27
+ * Doesn't print any message.
28
+ */
29
+ None
30
+ }
31
+
32
+ /**
33
+ * The logger.
34
+ */
35
+ export class HotLog
36
+ {
37
+ /**
38
+ * The logging level.
39
+ */
40
+ logLevel: HotLogLevel;
41
+
42
+ constructor (logLevel: HotLogLevel = HotLogLevel.All)
43
+ {
44
+ this.logLevel = logLevel;
45
+ }
46
+
47
+ /**
48
+ * Log a message.
49
+ */
50
+ log (level: HotLogLevel, message: string)
51
+ {
52
+ if (this.logLevel === HotLogLevel.Verbose)
53
+ {
54
+ if (level === HotLogLevel.Error)
55
+ this.error (message);
56
+
57
+ if (level === HotLogLevel.Warning)
58
+ this.warning (message);
59
+
60
+ if ((level === HotLogLevel.Info) ||
61
+ (level === HotLogLevel.Verbose))
62
+ {
63
+ this.info (message);
64
+ }
65
+ }
66
+
67
+ if (this.logLevel === HotLogLevel.All)
68
+ {
69
+ if (level === HotLogLevel.Error)
70
+ this.error (message);
71
+
72
+ if (level === HotLogLevel.Warning)
73
+ this.warning (message);
74
+
75
+ if (level === HotLogLevel.Info)
76
+ this.info (message);
77
+ }
78
+
79
+ if (this.logLevel === HotLogLevel.Error)
80
+ {
81
+ if (level === HotLogLevel.Error)
82
+ this.error (message);
83
+ }
84
+
85
+ if (this.logLevel === HotLogLevel.Warning)
86
+ {
87
+ if (level === HotLogLevel.Warning)
88
+ this.warning (message);
89
+ }
90
+
91
+ if (this.logLevel === HotLogLevel.Info)
92
+ {
93
+ if (level === HotLogLevel.Info)
94
+ this.info (message);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Log a verbose message.
100
+ */
101
+ verbose (message: string)
102
+ {
103
+ if (this.logLevel === HotLogLevel.Verbose)
104
+ console.info (message);
105
+ }
106
+
107
+ /**
108
+ * Log a message.
109
+ */
110
+ info (message: string)
111
+ {
112
+ if ((this.logLevel === HotLogLevel.All) ||
113
+ (this.logLevel === HotLogLevel.Verbose) ||
114
+ (this.logLevel === HotLogLevel.Info))
115
+ {
116
+ console.info (message);
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Log a warning.
122
+ */
123
+ warning (message: string)
124
+ {
125
+ if ((this.logLevel === HotLogLevel.All) ||
126
+ (this.logLevel === HotLogLevel.Verbose) ||
127
+ (this.logLevel === HotLogLevel.Warning))
128
+ {
129
+ console.warn (message);
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Log an error message.
135
+ */
136
+ error (message: string | Error)
137
+ {
138
+ if ((this.logLevel === HotLogLevel.All) ||
139
+ (this.logLevel === HotLogLevel.Verbose) ||
140
+ (this.logLevel === HotLogLevel.Error))
141
+ {
142
+ let msg: string = "";
143
+
144
+ if (typeof (message) === "string")
145
+ msg = message;
146
+ else
147
+ {
148
+ if (message.message != null)
149
+ msg = message.message;
150
+
151
+ if (message.stack != null)
152
+ msg = message.stack;
153
+ }
154
+
155
+ console.error (msg);
156
+ }
157
+ }
158
+ }
package/src/HotPage.ts ADDED
@@ -0,0 +1,206 @@
1
+ import { Hot } from "./Hot";
2
+ import { HotFile } from "./HotFile";
3
+ import { HotStaq } from "./HotStaq";
4
+ import { HotAPI } from "./HotAPI";
5
+ import { HotTestElement } from "./HotTestElement";
6
+ import { HotTestMap, HotTestPath } from "./HotTestMap";
7
+
8
+ /**
9
+ * A page to preprocess.
10
+ */
11
+ export interface IHotPage
12
+ {
13
+ /**
14
+ * The processor to use.
15
+ */
16
+ processor: HotStaq;
17
+ /**
18
+ * The name of the page.
19
+ */
20
+ name?: string;
21
+ /**
22
+ * The route used to get to this page.
23
+ */
24
+ route?: string;
25
+ /**
26
+ * The name of the page. File ordering matters here.
27
+ * Every file is processed incrementally.
28
+ */
29
+ files?: HotFile[];
30
+ /**
31
+ * The associated tester name.
32
+ */
33
+ testerName?: string;
34
+ /**
35
+ * The associated tester map.
36
+ */
37
+ testerMap?: string;
38
+ /**
39
+ * The elements to test on this page.
40
+ */
41
+ testElements?: { [name: string]: HotTestElement; };
42
+ /**
43
+ * The test paths to test on this page.
44
+ */
45
+ testPaths?: { [name: string]: HotTestPath; };
46
+ }
47
+
48
+ /**
49
+ * A page to preprocess.
50
+ */
51
+ export class HotPage implements IHotPage
52
+ {
53
+ /**
54
+ * The processor to use.
55
+ */
56
+ processor: HotStaq;
57
+ /**
58
+ * The name of the page.
59
+ */
60
+ name: string;
61
+ /**
62
+ * The route used to get to this page.
63
+ */
64
+ route: string;
65
+ /**
66
+ * The name of the page. File ordering matters here.
67
+ * Every file is processed incrementally.
68
+ */
69
+ files: HotFile[];
70
+ /**
71
+ * The associated tester name.
72
+ */
73
+ testerName: string;
74
+ /**
75
+ * The associated tester map.
76
+ */
77
+ testerMap: string;
78
+ /**
79
+ * The elements to test on this page.
80
+ */
81
+ testElements: { [name: string]: HotTestElement; };
82
+ /**
83
+ * The test paths to test on this page.
84
+ */
85
+ testPaths: { [name: string]: HotTestPath; };
86
+
87
+ constructor (copy: IHotPage | HotStaq)
88
+ {
89
+ if (copy instanceof HotStaq)
90
+ {
91
+ this.processor = copy;
92
+ this.name = "";
93
+ this.testerName = "";
94
+ this.testerMap = "";
95
+ this.route = "";
96
+ this.files = [];
97
+ this.testElements = {};
98
+ this.testPaths = {};
99
+ }
100
+ else
101
+ {
102
+ this.processor = copy.processor;
103
+ this.name = copy.name || "";
104
+ this.testerName = copy.testerName || "";
105
+ this.testerMap = copy.testerMap || "";
106
+ this.route = copy.route || "";
107
+ this.files = copy.files || [];
108
+ this.testElements = copy.testElements || {};
109
+ this.testPaths = copy.testPaths || {};
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Add a file to process. It's recommend to load the file prior to
115
+ * adding it to a page if it's about to be used.
116
+ */
117
+ async addFile (file: HotFile): Promise<void>
118
+ {
119
+ file.page = this;
120
+
121
+ this.files.push (file);
122
+ }
123
+
124
+ /**
125
+ * Get the API associated with this page.
126
+ */
127
+ getAPI (): HotAPI
128
+ {
129
+ return (this.processor.api);
130
+ }
131
+
132
+ /**
133
+ * Get the tester API associated with this page.
134
+ */
135
+ getTesterAPI (): HotAPI
136
+ {
137
+ return (this.processor.testerAPI);
138
+ }
139
+
140
+ /**
141
+ * Add all files in the page. Could decrease page loading performance.
142
+ * It's recommend to load the file prior to adding it to a page.
143
+ */
144
+ async load (file: HotFile): Promise<void>
145
+ {
146
+ for (let iIdx = 0; iIdx < this.files.length; iIdx++)
147
+ {
148
+ let file: HotFile = this.files[iIdx];
149
+
150
+ await file.load ();
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Process a page and get the result.
156
+ */
157
+ async process (args: any = null): Promise<string>
158
+ {
159
+ let output: string = "";
160
+
161
+ for (let iIdx = 0; iIdx < this.files.length; iIdx++)
162
+ {
163
+ let file: HotFile = this.files[iIdx];
164
+
165
+ Hot.Output = "";
166
+ file.page = this;
167
+
168
+ output += await file.process (args);
169
+ }
170
+
171
+ return (output);
172
+ }
173
+
174
+ /**
175
+ * Add a test element.
176
+ */
177
+ addTestElement (elm: HotTestElement): void
178
+ {
179
+ if (this.testElements[elm.name] != null)
180
+ throw new Error (`Test element ${elm.name} already exists!`);
181
+
182
+ this.testElements[elm.name] = elm;
183
+ }
184
+
185
+ /**
186
+ * Get a test element.
187
+ */
188
+ getTestElement (name: string): HotTestElement
189
+ {
190
+ if (this.testElements[name] == null)
191
+ throw new Error (`Test element ${name} doest not exist!`);
192
+
193
+ return (this.testElements[name]);
194
+ }
195
+
196
+ /**
197
+ * Create a test path.
198
+ */
199
+ createTestPath (pathName: string, driverFunc: HotTestPath): void
200
+ {
201
+ if (this.testPaths[pathName] != null)
202
+ throw new Error (`Test path ${pathName} already exists!`);
203
+
204
+ this.testPaths[pathName] = driverFunc;
205
+ }
206
+ }
@@ -0,0 +1,137 @@
1
+ import { HotServer } from "./HotServer";
2
+ import { HotRouteMethod, HTTPMethod, ServerExecutionFunction, TestCaseFunction, TestCaseObject } from "./HotRouteMethod";
3
+ import { HotClient } from "./HotClient";
4
+ import { HotLog } from "./HotLog";
5
+
6
+ /**
7
+ * The route to use.
8
+ */
9
+ export class HotRoute
10
+ {
11
+ /**
12
+ * The server that maintains the connections.
13
+ */
14
+ connection: HotServer | HotClient;
15
+ /**
16
+ * The associated logger.
17
+ */
18
+ logger: HotLog;
19
+ /**
20
+ * The route.
21
+ */
22
+ route: string;
23
+ /**
24
+ * The version.
25
+ */
26
+ version: string;
27
+ /**
28
+ * The prefix to add to the beginning of each route method.
29
+ */
30
+ prefix: string;
31
+ /**
32
+ * The authorization credentials to be used by the client
33
+ * when connecting to the server.
34
+ */
35
+ authCredentials: any;
36
+ /**
37
+ * The calls that can be made.
38
+ */
39
+ methods: HotRouteMethod[];
40
+ /**
41
+ * The errors and their JSON that can be thrown. Can be:
42
+ * * not_authorized
43
+ */
44
+ errors: { [error: string]: any };
45
+
46
+ constructor (connection: HotServer | HotClient, route: string, methods: HotRouteMethod[] = [])
47
+ {
48
+ this.connection = connection;
49
+ this.logger = null;
50
+
51
+ if (this.connection != null)
52
+ {
53
+ if (this.connection.processor != null)
54
+ this.logger = this.connection.processor.logger;
55
+ }
56
+
57
+ this.route = route;
58
+ this.version = "v1";
59
+ this.prefix = "";
60
+ this.authCredentials = null;
61
+ this.methods = methods;
62
+ this.errors = {
63
+ "not_authorized": HotRoute.createError ("Not authorized.")
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Create an error JSON object.
69
+ */
70
+ static createError (message: string): any
71
+ {
72
+ return ({ error: message });
73
+ }
74
+
75
+ /**
76
+ * Add an API method to this route.
77
+ *
78
+ * @param method The name of the method to add. If a HotRouteMethod is supplied, the
79
+ * rest of the arguments supplied will be ignored.
80
+ */
81
+ addMethod (
82
+ method: HotRouteMethod | string,
83
+ executeFunction: ServerExecutionFunction = null,
84
+ type: HTTPMethod = HTTPMethod.POST,
85
+ testCases: (string | TestCaseFunction)[] | TestCaseFunction[] | TestCaseObject[] = null
86
+ ): void
87
+ {
88
+ if (typeof (method) === "string")
89
+ method = new HotRouteMethod (this, method, executeFunction, type, null, null, null, testCases);
90
+
91
+ this.methods.push (method);
92
+ }
93
+
94
+ /**
95
+ * Get a method by it's name.
96
+ */
97
+ getMethod (name: string): HotRouteMethod
98
+ {
99
+ let foundMethod: HotRouteMethod = null;
100
+
101
+ for (let iIdx = 0; iIdx < this.methods.length; iIdx++)
102
+ {
103
+ let method: HotRouteMethod = this.methods[iIdx];
104
+
105
+ if (method.name === name)
106
+ {
107
+ foundMethod = method;
108
+
109
+ break;
110
+ }
111
+ }
112
+
113
+ return (foundMethod);
114
+ }
115
+
116
+ /**
117
+ * Executes before all routes have been registered.
118
+ */
119
+ onPreRegister: () => Promise<void> = null;
120
+ /**
121
+ * Executes when first registering this route with Express. If
122
+ * this returns false, the route will not be registered.
123
+ */
124
+ onRegister: () => Promise<boolean> = null;
125
+ /**
126
+ * Executes after all routes have been registered.
127
+ */
128
+ onPostRegister: () => Promise<void> = null;
129
+
130
+ /**
131
+ * Executes when authorizing a called method.
132
+ * The value returned from here will be passed to onExecute in the
133
+ * called HotRouteMethod. Undefined returning from here will mean
134
+ * the authorization failed.
135
+ */
136
+ onAuthorizeUser: (req: any, res: any) => Promise<any> = null;
137
+ }