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,1260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (_) try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
|
+
};
|
|
75
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
+
exports.HotStaq = void 0;
|
|
77
|
+
var fs = __importStar(require("fs"));
|
|
78
|
+
var ppath = __importStar(require("path"));
|
|
79
|
+
var cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
80
|
+
var validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
81
|
+
var HotPage_1 = require("./HotPage");
|
|
82
|
+
var HotFile_1 = require("./HotFile");
|
|
83
|
+
var HotLog_1 = require("./HotLog");
|
|
84
|
+
var Hot_1 = require("./Hot");
|
|
85
|
+
var HotClient_1 = require("./HotClient");
|
|
86
|
+
var HotTesterAPI_1 = require("./HotTesterAPI");
|
|
87
|
+
var HotTestMap_1 = require("./HotTestMap");
|
|
88
|
+
var HotTesterMocha = null;
|
|
89
|
+
var HotTesterMochaSelenium = null;
|
|
90
|
+
var HotTestSeleniumDriver = null;
|
|
91
|
+
/**
|
|
92
|
+
* The main class that handles all HTML preprocessing, then outputs the
|
|
93
|
+
* results.
|
|
94
|
+
*/
|
|
95
|
+
var HotStaq = /** @class */ (function () {
|
|
96
|
+
function HotStaq(copy) {
|
|
97
|
+
if (copy === void 0) { copy = {}; }
|
|
98
|
+
this.api = copy.api || null;
|
|
99
|
+
this.testerAPI = copy.testerAPI || null;
|
|
100
|
+
this.mode = copy.mode || Hot_1.DeveloperMode.Production;
|
|
101
|
+
this.pages = copy.pages || {};
|
|
102
|
+
this.components = copy.components || {};
|
|
103
|
+
this.files = copy.files || {};
|
|
104
|
+
this.hotSite = copy.hotSite || null;
|
|
105
|
+
this.apiContent = "\n\t\t\tvar %api_name% = %api_exported_name%.%api_name%;\n\t\t\tvar newHotClient = new HotClient (processor);\n\t\t\tvar newapi = new %api_name% (%base_url%, newHotClient);\n\t\t\tnewHotClient.api = newapi;\n\t\t\tprocessor.api = newapi;";
|
|
106
|
+
this.testerApiContent = "\n\t\t\tvar HotTesterAPI = HotStaqWeb.HotTesterAPI;\n\t\t\tvar newHotTesterClient = new HotClient (processor);\n\t\t\tvar newtesterapi = new HotTesterAPI (%base_tester_url%, newHotTesterClient);\n\t\t\tnewHotTesterClient.testerAPI = newtesterapi;\n\t\t\tprocessor.testerAPI = newtesterapi;";
|
|
107
|
+
this.pageContent =
|
|
108
|
+
"<!DOCTYPE html>\n<html>\n\n<head>\n\t<title>%title%</title>\n\n\t<script type = \"text/javascript\" src = \"%hotstaq_js_src%\"></script>\n\t<script type = \"text/javascript\">\n\t\twindow.HotStaq = HotStaqWeb.HotStaq;\n\t\twindow.HotClient = HotStaqWeb.HotClient;\n\t\twindow.HotAPI = HotStaqWeb.HotAPI;\n\t\twindow.Hot = HotStaqWeb.Hot;\n\t</script>\n\n%apis_to_load%\n\n\t<script type = \"text/javascript\">\n\t\tfunction hotstaq_startApp ()\n\t\t{\n\t\t\tlet tempMode = 0;\n\n\t\t\tif (window[\"Hot\"] != null)\n\t\t\t\ttempMode = Hot.Mode;\n\n\t\t\t%load_hot_site%\n\n\t\t\tvar processor = new HotStaq ();\n\t\t\tvar promises = [];\n\t\t\t%developer_mode%\n\n\t\t\t%api_code%\n\n\t\t\t%public_secrets%\n\t\t\t%tester_api%\n\t\t\t%load_files%\n\n\t\t\tprocessor.mode = tempMode;\n\n\t\t\tPromise.all (promises).then (function ()\n\t\t\t\t{\n\t\t\t\t\tHotStaq.displayUrl ({\n\t\t\t\t\t\t\turl: \"%url%\",\n\t\t\t\t\t\t\tname: \"%title%\",\n\t\t\t\t\t\t\tprocessor: processor,\n\t\t\t\t\t\t\targs: %args%,\n\t\t\t\t\t\t\ttesterName: %tester_name%,\n\t\t\t\t\t\t\ttesterMap: %tester_map%,\n\t\t\t\t\t\t\ttesterAPIBaseUrl: %tester_api_base_url%,\n\t\t\t\t\t\t\ttesterLaunchpadUrl: %tester_launchpad_url%\n\t\t\t\t\t\t});\n\t\t\t\t});\n\t\t}\n\n\t\thotstaq_startApp ();\n\t</script>\n</head>\n\n<body>\n</body>\n\n</html>";
|
|
109
|
+
this.logger = new HotLog_1.HotLog(HotLog_1.HotLogLevel.None);
|
|
110
|
+
this.publicSecrets = {};
|
|
111
|
+
this.testers = {};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parse a boolean value.
|
|
115
|
+
*/
|
|
116
|
+
HotStaq.parseBoolean = function (value) {
|
|
117
|
+
value = value.toLowerCase();
|
|
118
|
+
if (value === "true")
|
|
119
|
+
return (true);
|
|
120
|
+
if (value === "false")
|
|
121
|
+
return (false);
|
|
122
|
+
if (value === "yes")
|
|
123
|
+
return (true);
|
|
124
|
+
if (value === "no")
|
|
125
|
+
return (false);
|
|
126
|
+
if (value === "yep")
|
|
127
|
+
return (true);
|
|
128
|
+
if (value === "nah")
|
|
129
|
+
return (false);
|
|
130
|
+
try {
|
|
131
|
+
if (parseInt(value) != 0)
|
|
132
|
+
return (true);
|
|
133
|
+
}
|
|
134
|
+
catch (ex) {
|
|
135
|
+
}
|
|
136
|
+
return (false);
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Check if a required parameter exists inside an object. If it exists, return the value.
|
|
140
|
+
*/
|
|
141
|
+
HotStaq.getParam = function (name, objWithParam, required, throwException) {
|
|
142
|
+
if (required === void 0) { required = true; }
|
|
143
|
+
if (throwException === void 0) { throwException = true; }
|
|
144
|
+
var value = objWithParam[name];
|
|
145
|
+
if (value == null) {
|
|
146
|
+
if (required === true) {
|
|
147
|
+
if (throwException === true)
|
|
148
|
+
throw new Error("Missing required parameter ".concat(name, "."));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (typeof (value) === "string") {
|
|
152
|
+
if (required === true) {
|
|
153
|
+
if (value === "") {
|
|
154
|
+
if (throwException === true)
|
|
155
|
+
throw new Error("Missing required parameter ".concat(name, "."));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return (value);
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Check if a required parameter exists inside an object. If it exists, return the value.
|
|
163
|
+
* If it does not exist, return a default value instead.
|
|
164
|
+
*/
|
|
165
|
+
HotStaq.getParamDefault = function (name, objWithParam, defaultValue) {
|
|
166
|
+
var value = objWithParam[name];
|
|
167
|
+
if (value == null)
|
|
168
|
+
return (defaultValue);
|
|
169
|
+
if (typeof (value) === "string") {
|
|
170
|
+
if (value === "")
|
|
171
|
+
return (defaultValue);
|
|
172
|
+
}
|
|
173
|
+
return (value);
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Wait for a number of milliseconds.
|
|
177
|
+
*/
|
|
178
|
+
HotStaq.wait = function (numMilliseconds) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
183
|
+
setTimeout(function () {
|
|
184
|
+
resolve();
|
|
185
|
+
}, numMilliseconds);
|
|
186
|
+
})];
|
|
187
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Add a page.
|
|
194
|
+
*/
|
|
195
|
+
HotStaq.prototype.addPage = function (page) {
|
|
196
|
+
this.pages[page.name] = page;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Get a page to process.
|
|
200
|
+
*/
|
|
201
|
+
HotStaq.prototype.getPage = function (pageName) {
|
|
202
|
+
return (this.pages[pageName]);
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Add a file.
|
|
206
|
+
*/
|
|
207
|
+
HotStaq.prototype.addFile = function (file) {
|
|
208
|
+
var name = file.name;
|
|
209
|
+
if (name === "")
|
|
210
|
+
name = file.localFile;
|
|
211
|
+
if (name === "")
|
|
212
|
+
name = file.url;
|
|
213
|
+
this.files[name] = file;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Get a file.
|
|
217
|
+
*/
|
|
218
|
+
HotStaq.prototype.getFile = function (name) {
|
|
219
|
+
if (this.files[name] == null)
|
|
220
|
+
throw new Error("Unable to find file ".concat(name));
|
|
221
|
+
return (this.files[name]);
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Add and register a component.
|
|
225
|
+
*/
|
|
226
|
+
HotStaq.prototype.addComponent = function (component) {
|
|
227
|
+
this.components[component.name] = component;
|
|
228
|
+
this.registerComponent(component);
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Register a component for use as a HTML tag.
|
|
232
|
+
*/
|
|
233
|
+
HotStaq.prototype.registerComponent = function (component) {
|
|
234
|
+
customElements.define(component.tag, /** @class */ (function (_super) {
|
|
235
|
+
__extends(class_1, _super);
|
|
236
|
+
function class_1() {
|
|
237
|
+
var _this = _super.call(this) || this;
|
|
238
|
+
/// @fixme Is this bad? Could create race conditions.
|
|
239
|
+
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
240
|
+
var key, event_1, _a, iIdx, attr, attrName, attrValue, str, newDOM, shadow, iIdx, child;
|
|
241
|
+
return __generator(this, function (_b) {
|
|
242
|
+
switch (_b.label) {
|
|
243
|
+
case 0:
|
|
244
|
+
this.onclick = component.click.bind(component);
|
|
245
|
+
for (key in component.events) {
|
|
246
|
+
event_1 = component.events[key];
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
this.addEventListener(event_1.type, event_1.func, event_1.options);
|
|
249
|
+
}
|
|
250
|
+
_a = component;
|
|
251
|
+
return [4 /*yield*/, component.onCreated(this)];
|
|
252
|
+
case 1:
|
|
253
|
+
_a.htmlElement = _b.sent();
|
|
254
|
+
if (!(component.handleAttributes != null)) return [3 /*break*/, 3];
|
|
255
|
+
return [4 /*yield*/, component.handleAttributes(this.attributes)];
|
|
256
|
+
case 2:
|
|
257
|
+
_b.sent();
|
|
258
|
+
return [3 /*break*/, 4];
|
|
259
|
+
case 3:
|
|
260
|
+
for (iIdx = 0; iIdx < this.attributes.length; iIdx++) {
|
|
261
|
+
attr = this.attributes[iIdx];
|
|
262
|
+
attrName = attr.name.toLowerCase();
|
|
263
|
+
attrValue = attr.value;
|
|
264
|
+
if (attrName === "id")
|
|
265
|
+
component.name = attrValue;
|
|
266
|
+
if (attrName === "name")
|
|
267
|
+
component.name = attrValue;
|
|
268
|
+
if (attrName === "value")
|
|
269
|
+
component.value = attrValue;
|
|
270
|
+
}
|
|
271
|
+
_b.label = 4;
|
|
272
|
+
case 4: return [4 /*yield*/, component.output()];
|
|
273
|
+
case 5:
|
|
274
|
+
str = _b.sent();
|
|
275
|
+
newDOM = new DOMParser().parseFromString(str, "text/html");
|
|
276
|
+
shadow = this.attachShadow({ mode: "open" });
|
|
277
|
+
for (iIdx = 0; iIdx < newDOM.body.children.length; iIdx++) {
|
|
278
|
+
child = newDOM.body.children[iIdx];
|
|
279
|
+
shadow.appendChild(child);
|
|
280
|
+
}
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}); })();
|
|
285
|
+
return _this;
|
|
286
|
+
}
|
|
287
|
+
return class_1;
|
|
288
|
+
}(HTMLElement)), component.elementOptions);
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Get a component to process.
|
|
292
|
+
*/
|
|
293
|
+
HotStaq.prototype.getComponent = function (name) {
|
|
294
|
+
return (this.components[name]);
|
|
295
|
+
};
|
|
296
|
+
/**
|
|
297
|
+
* Add a new HTML element(s) to the current document.
|
|
298
|
+
*/
|
|
299
|
+
HotStaq.addHtml = function (parent, html) {
|
|
300
|
+
var foundParent = null;
|
|
301
|
+
if (typeof (parent) === "string")
|
|
302
|
+
foundParent = document.querySelector(parent);
|
|
303
|
+
else
|
|
304
|
+
foundParent = parent;
|
|
305
|
+
if (foundParent == null)
|
|
306
|
+
throw new Error("Unable to find parent ".concat(parent, "!"));
|
|
307
|
+
var result = null;
|
|
308
|
+
if (typeof (html) === "string") {
|
|
309
|
+
var newDOM = new DOMParser().parseFromString(html, "text/html");
|
|
310
|
+
var results = [];
|
|
311
|
+
for (var iIdx = 0; iIdx < newDOM.body.children.length; iIdx++) {
|
|
312
|
+
var child = newDOM.body.children[iIdx];
|
|
313
|
+
results.push(foundParent.appendChild(child));
|
|
314
|
+
}
|
|
315
|
+
return (results);
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
result = foundParent.appendChild(html);
|
|
319
|
+
return (result);
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Check if a HotSite's name is valid.
|
|
323
|
+
*/
|
|
324
|
+
HotStaq.checkHotSiteName = function (hotsiteName, throwException) {
|
|
325
|
+
if (throwException === void 0) { throwException = false; }
|
|
326
|
+
var throwTheException = function () {
|
|
327
|
+
if (throwException === true)
|
|
328
|
+
throw new Error("HotSite ".concat(hotsiteName, " has an invalid name! The name cannot be empty and must have a valid NPM module name."));
|
|
329
|
+
};
|
|
330
|
+
var results = (0, validate_npm_package_name_1.default)(hotsiteName);
|
|
331
|
+
if (results.errors != null) {
|
|
332
|
+
if (results.errors.length > 0)
|
|
333
|
+
throwTheException();
|
|
334
|
+
}
|
|
335
|
+
return (true);
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* In the supplied content, replace a key in a ${KEY} with a value.
|
|
339
|
+
*
|
|
340
|
+
* @returns The content with the correct values.
|
|
341
|
+
*/
|
|
342
|
+
HotStaq.replaceKey = function (content, key, value) {
|
|
343
|
+
var finalStr = content.replace(new RegExp("\\$\\{".concat(key, "\\}"), "g"), value);
|
|
344
|
+
return (finalStr);
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Get a value from a HotSite object.
|
|
348
|
+
*
|
|
349
|
+
* @returns Returns the value from the hotsite object. Returns null if it doesn't exist.
|
|
350
|
+
*/
|
|
351
|
+
HotStaq.getValueFromHotSiteObj = function (hotsite, params) {
|
|
352
|
+
var value = null;
|
|
353
|
+
if (hotsite != null) {
|
|
354
|
+
var prevValue = hotsite;
|
|
355
|
+
// Go through each object in the list of parameters and
|
|
356
|
+
// get the value of the final parameter.
|
|
357
|
+
for (var iIdx = 0; iIdx < params.length; iIdx++) {
|
|
358
|
+
var param = params[iIdx];
|
|
359
|
+
if (prevValue[param] == null) {
|
|
360
|
+
prevValue = null;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
prevValue = prevValue[param];
|
|
364
|
+
}
|
|
365
|
+
if (prevValue != null)
|
|
366
|
+
value = prevValue;
|
|
367
|
+
}
|
|
368
|
+
return (value);
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Load from a HotSite.json file. Be sure to load and attach any testers before
|
|
372
|
+
* loading a HotSite.
|
|
373
|
+
*/
|
|
374
|
+
HotStaq.prototype.loadHotSite = function (path) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
376
|
+
var jsonStr, res, routes, testerUrl, tester, driver, setupTester, key, route, file, page, mapName, testMap, destinations, iIdx, dest, key2, dest, key, api, mapName, testMap, iIdx, map, _a, _b, _i, key, component, componentUrl, res, newComponent;
|
|
377
|
+
var _this = this;
|
|
378
|
+
return __generator(this, function (_c) {
|
|
379
|
+
switch (_c.label) {
|
|
380
|
+
case 0:
|
|
381
|
+
jsonStr = "";
|
|
382
|
+
if (!(HotStaq.isWeb === true)) return [3 /*break*/, 2];
|
|
383
|
+
this.logger.info("Retrieving HotSite ".concat(path));
|
|
384
|
+
return [4 /*yield*/, (0, cross_fetch_1.default)(path)];
|
|
385
|
+
case 1:
|
|
386
|
+
res = _c.sent();
|
|
387
|
+
this.logger.info("Retrieved site ".concat(path));
|
|
388
|
+
jsonStr = res.text();
|
|
389
|
+
return [3 /*break*/, 4];
|
|
390
|
+
case 2:
|
|
391
|
+
path = ppath.normalize(path);
|
|
392
|
+
this.logger.info("Retrieving HotSite ".concat(path));
|
|
393
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
394
|
+
fs.readFile(path, function (err, data) {
|
|
395
|
+
if (err != null)
|
|
396
|
+
throw err;
|
|
397
|
+
var content = data.toString();
|
|
398
|
+
_this.logger.info("Retrieved site ".concat(path));
|
|
399
|
+
resolve(content);
|
|
400
|
+
});
|
|
401
|
+
})];
|
|
402
|
+
case 3:
|
|
403
|
+
jsonStr = _c.sent();
|
|
404
|
+
_c.label = 4;
|
|
405
|
+
case 4:
|
|
406
|
+
this.hotSite = JSON.parse(jsonStr);
|
|
407
|
+
HotStaq.checkHotSiteName(this.hotSite.name, true);
|
|
408
|
+
this.hotSite.hotsitePath = path;
|
|
409
|
+
routes = this.hotSite.routes;
|
|
410
|
+
testerUrl = "http://127.0.0.1:8182";
|
|
411
|
+
tester = null;
|
|
412
|
+
driver = null;
|
|
413
|
+
if (HotStaq.isWeb === false) {
|
|
414
|
+
if (this.mode === Hot_1.DeveloperMode.Development) {
|
|
415
|
+
if (this.hotSite.testing != null) {
|
|
416
|
+
setupTester = function (parentObj) {
|
|
417
|
+
var createNewTester = true;
|
|
418
|
+
if (parentObj.createNewTester != null)
|
|
419
|
+
createNewTester = parentObj.createNewTester;
|
|
420
|
+
var testerName = "Tester";
|
|
421
|
+
if (parentObj.tester != null)
|
|
422
|
+
testerName = parentObj.tester;
|
|
423
|
+
if (parentObj.testerName != null)
|
|
424
|
+
testerName = parentObj.testerName;
|
|
425
|
+
if (createNewTester === true) {
|
|
426
|
+
/// @fixme Find a way to securely allow devs to use their own drivers and testers...
|
|
427
|
+
/// @fixme Hack for dealing with WebPack's bs.
|
|
428
|
+
HotTesterMocha = require("./HotTesterMocha").HotTesterMocha;
|
|
429
|
+
HotTesterMochaSelenium = require("./HotTesterMochaSelenium").HotTesterMochaSelenium;
|
|
430
|
+
HotTestSeleniumDriver = require("./HotTestSeleniumDriver").HotTestSeleniumDriver;
|
|
431
|
+
if (parentObj.testerAPIUrl === "")
|
|
432
|
+
testerUrl = parentObj.testerAPIUrl;
|
|
433
|
+
if (parentObj.driver === "HotTestSeleniumDriver")
|
|
434
|
+
driver = new HotTestSeleniumDriver();
|
|
435
|
+
if (parentObj.tester === "HotTesterMocha")
|
|
436
|
+
tester = new HotTesterMocha(_this, testerName, testerUrl, driver);
|
|
437
|
+
if (parentObj.tester === "HotTesterMochaSelenium")
|
|
438
|
+
tester = new HotTesterMochaSelenium(_this, testerName, testerUrl);
|
|
439
|
+
}
|
|
440
|
+
else
|
|
441
|
+
tester = _this.testers[testerName];
|
|
442
|
+
};
|
|
443
|
+
if (this.hotSite.testing.web != null)
|
|
444
|
+
setupTester(this.hotSite.testing.web);
|
|
445
|
+
if (this.hotSite.testing.api != null)
|
|
446
|
+
setupTester(this.hotSite.testing.api);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (routes != null) {
|
|
451
|
+
for (key in routes) {
|
|
452
|
+
route = routes[key];
|
|
453
|
+
file = new HotFile_1.HotFile(route);
|
|
454
|
+
page = new HotPage_1.HotPage({
|
|
455
|
+
processor: this,
|
|
456
|
+
name: route.name || "",
|
|
457
|
+
route: key,
|
|
458
|
+
files: [file]
|
|
459
|
+
});
|
|
460
|
+
if (tester != null) {
|
|
461
|
+
if (this.mode === Hot_1.DeveloperMode.Development) {
|
|
462
|
+
mapName = route.name;
|
|
463
|
+
testMap = null;
|
|
464
|
+
if (route.map != null) {
|
|
465
|
+
if (typeof (route.map) === "string") {
|
|
466
|
+
if (tester.testMaps[route.map] == null)
|
|
467
|
+
throw new Error("Test map ".concat(route.map, " does not exist!"));
|
|
468
|
+
tester.testMaps[mapName] = tester.testMaps[route.map];
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
testMap = new HotTestMap_1.HotTestMap();
|
|
472
|
+
destinations = null;
|
|
473
|
+
if (route.map instanceof Array) {
|
|
474
|
+
destinations = [];
|
|
475
|
+
for (iIdx = 0; iIdx < route.map.length; iIdx++) {
|
|
476
|
+
dest = route.map[iIdx];
|
|
477
|
+
destinations.push(new HotTestMap_1.HotTestDestination(dest));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
destinations = {};
|
|
482
|
+
for (key2 in route.map) {
|
|
483
|
+
dest = route.map[key2];
|
|
484
|
+
destinations[key2] = new HotTestMap_1.HotTestDestination(dest);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
testMap.destinations = destinations;
|
|
488
|
+
}
|
|
489
|
+
tester.testMaps[mapName] = testMap;
|
|
490
|
+
}
|
|
491
|
+
if (route.destinationOrder != null)
|
|
492
|
+
tester.testMaps[mapName].destinationOrder = route.destinationOrder;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
this.addPage(page);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (this.hotSite.apis != null) {
|
|
499
|
+
for (key in this.hotSite.apis) {
|
|
500
|
+
api = this.hotSite.apis[key];
|
|
501
|
+
if (api.map == null)
|
|
502
|
+
continue;
|
|
503
|
+
if (HotStaq.isWeb === false) {
|
|
504
|
+
if (this.mode === Hot_1.DeveloperMode.Development) {
|
|
505
|
+
mapName = key;
|
|
506
|
+
testMap = new HotTestMap_1.HotTestMap();
|
|
507
|
+
testMap.destinations = [];
|
|
508
|
+
for (iIdx = 0; iIdx < api.map.length; iIdx++) {
|
|
509
|
+
map = api.map[iIdx];
|
|
510
|
+
testMap.destinations.push(new HotTestMap_1.HotTestDestination(map));
|
|
511
|
+
}
|
|
512
|
+
if (tester == null)
|
|
513
|
+
throw new Error("A tester was not created first! You must specify one in the CLI or in HotSite.json.");
|
|
514
|
+
tester.testMaps[mapName] = testMap;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (!(HotStaq.isWeb === true)) return [3 /*break*/, 8];
|
|
520
|
+
_a = [];
|
|
521
|
+
for (_b in this.hotSite.components)
|
|
522
|
+
_a.push(_b);
|
|
523
|
+
_i = 0;
|
|
524
|
+
_c.label = 5;
|
|
525
|
+
case 5:
|
|
526
|
+
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
527
|
+
key = _a[_i];
|
|
528
|
+
component = this.hotSite.components[key];
|
|
529
|
+
componentUrl = component.url;
|
|
530
|
+
return [4 /*yield*/, (0, cross_fetch_1.default)(componentUrl)];
|
|
531
|
+
case 6:
|
|
532
|
+
res = _c.sent();
|
|
533
|
+
newComponent = eval(res);
|
|
534
|
+
this.addComponent(newComponent);
|
|
535
|
+
_c.label = 7;
|
|
536
|
+
case 7:
|
|
537
|
+
_i++;
|
|
538
|
+
return [3 /*break*/, 5];
|
|
539
|
+
case 8:
|
|
540
|
+
if (this.hotSite.routes == null)
|
|
541
|
+
this.hotSite.routes = {};
|
|
542
|
+
return [4 /*yield*/, this.loadHotFiles(this.hotSite.files)];
|
|
543
|
+
case 9:
|
|
544
|
+
_c.sent();
|
|
545
|
+
if (tester != null)
|
|
546
|
+
this.addTester(tester);
|
|
547
|
+
return [2 /*return*/];
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Load an array of files. If a file already has content, it will not be reloaded
|
|
554
|
+
* unless forceContentLoading is set to true.
|
|
555
|
+
*/
|
|
556
|
+
HotStaq.prototype.loadHotFiles = function (files, forceContentLoading) {
|
|
557
|
+
if (forceContentLoading === void 0) { forceContentLoading = false; }
|
|
558
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
559
|
+
var _a, _b, _i, key, file, newFile, loadContent;
|
|
560
|
+
return __generator(this, function (_c) {
|
|
561
|
+
switch (_c.label) {
|
|
562
|
+
case 0:
|
|
563
|
+
_a = [];
|
|
564
|
+
for (_b in files)
|
|
565
|
+
_a.push(_b);
|
|
566
|
+
_i = 0;
|
|
567
|
+
_c.label = 1;
|
|
568
|
+
case 1:
|
|
569
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
570
|
+
key = _a[_i];
|
|
571
|
+
file = files[key];
|
|
572
|
+
newFile = null;
|
|
573
|
+
if (HotStaq.isWeb === true) {
|
|
574
|
+
newFile = new HotFile_1.HotFile({
|
|
575
|
+
"name": key
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
newFile = new HotFile_1.HotFile({
|
|
580
|
+
"name": key
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
if (file.url != null)
|
|
584
|
+
newFile.url = file.url;
|
|
585
|
+
if (HotStaq.isWeb === false) {
|
|
586
|
+
if (file.localFile != null)
|
|
587
|
+
newFile.localFile = file.localFile;
|
|
588
|
+
}
|
|
589
|
+
loadContent = true;
|
|
590
|
+
if (file.content != null) {
|
|
591
|
+
newFile.content = file.content;
|
|
592
|
+
loadContent = false;
|
|
593
|
+
}
|
|
594
|
+
if (forceContentLoading === true)
|
|
595
|
+
loadContent = true;
|
|
596
|
+
if (!(loadContent === true)) return [3 /*break*/, 3];
|
|
597
|
+
return [4 /*yield*/, newFile.load()];
|
|
598
|
+
case 2:
|
|
599
|
+
_c.sent();
|
|
600
|
+
_c.label = 3;
|
|
601
|
+
case 3:
|
|
602
|
+
this.addFile(newFile);
|
|
603
|
+
_c.label = 4;
|
|
604
|
+
case 4:
|
|
605
|
+
_i++;
|
|
606
|
+
return [3 /*break*/, 1];
|
|
607
|
+
case 5: return [2 /*return*/];
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* Generate the content to send to a client.
|
|
614
|
+
*/
|
|
615
|
+
HotStaq.prototype.generateContent = function (routeKey, name, url, jsSrcPath, passArgs, args) {
|
|
616
|
+
var _this = this;
|
|
617
|
+
if (name === void 0) { name = ""; }
|
|
618
|
+
if (url === void 0) { url = "./"; }
|
|
619
|
+
if (jsSrcPath === void 0) { jsSrcPath = "./js/HotStaq.js"; }
|
|
620
|
+
if (passArgs === void 0) { passArgs = true; }
|
|
621
|
+
if (args === void 0) { args = null; }
|
|
622
|
+
var apiScripts = "";
|
|
623
|
+
var apiCode = "";
|
|
624
|
+
var publicSecrets = "";
|
|
625
|
+
/// @todo Optimize this function as much as possible.
|
|
626
|
+
// Load the API string.
|
|
627
|
+
if (this.hotSite != null) {
|
|
628
|
+
if (this.hotSite.server.globalApi != null) {
|
|
629
|
+
if (this.hotSite.server.globalApi !== "") {
|
|
630
|
+
var globalApi = this.hotSite.apis[this.hotSite.server.globalApi];
|
|
631
|
+
if (globalApi == null)
|
|
632
|
+
this.logger.warning("API with name ".concat(this.hotSite.server.globalApi, " doesn't exist!"));
|
|
633
|
+
else {
|
|
634
|
+
var sendJSContent = true;
|
|
635
|
+
if (globalApi.jsapi == null) {
|
|
636
|
+
sendJSContent = false;
|
|
637
|
+
this.logger.warning("API with name ".concat(this.hotSite.server.globalApi, " doesn't have a jsapi set. Will not send js content to client."));
|
|
638
|
+
}
|
|
639
|
+
if (globalApi.libraryName == null) {
|
|
640
|
+
sendJSContent = false;
|
|
641
|
+
this.logger.warning("API with name ".concat(this.hotSite.server.globalApi, " doesn't have a libraryName set. Will not send js content to client."));
|
|
642
|
+
}
|
|
643
|
+
if (globalApi.apiName == null) {
|
|
644
|
+
sendJSContent = false;
|
|
645
|
+
this.logger.warning("API with name ".concat(this.hotSite.server.globalApi, " doesn't have a apiName set. Will not send js content to client."));
|
|
646
|
+
}
|
|
647
|
+
if (sendJSContent === true) {
|
|
648
|
+
apiScripts += "\t<script type = \"text/javascript\" src = \"".concat(globalApi.jsapi, "\"></script>\n");
|
|
649
|
+
var baseUrl = "\"\"";
|
|
650
|
+
if (this.api != null)
|
|
651
|
+
baseUrl = "\"".concat(this.api.baseUrl, "\"");
|
|
652
|
+
var tempAPIContent = this.apiContent;
|
|
653
|
+
tempAPIContent = tempAPIContent.replace(/\%api\_name\%/g, globalApi.apiName);
|
|
654
|
+
tempAPIContent = tempAPIContent.replace(/\%api\_exported\_name\%/g, globalApi.libraryName);
|
|
655
|
+
tempAPIContent = tempAPIContent.replace(/\%base\_url\%/g, baseUrl);
|
|
656
|
+
apiCode += tempAPIContent;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if (this.hotSite.apis != null) {
|
|
662
|
+
var route = this.hotSite.routes[routeKey];
|
|
663
|
+
if (route != null) {
|
|
664
|
+
if (route.api != null) {
|
|
665
|
+
var api = this.hotSite.apis[route.api];
|
|
666
|
+
if (api == null)
|
|
667
|
+
throw new Error("Unable to find API ".concat(route.api));
|
|
668
|
+
var sendJSContent = true;
|
|
669
|
+
if (api.jsapi == null) {
|
|
670
|
+
sendJSContent = false;
|
|
671
|
+
this.logger.warning("API with name ".concat(route.api, " doesn't have a jsapi set. Will not send js content to client."));
|
|
672
|
+
}
|
|
673
|
+
if (api.libraryName == null) {
|
|
674
|
+
sendJSContent = false;
|
|
675
|
+
this.logger.warning("API with name ".concat(route.api, " doesn't have a libraryName set. Will not send js content to client."));
|
|
676
|
+
}
|
|
677
|
+
if (api.apiName == null) {
|
|
678
|
+
sendJSContent = false;
|
|
679
|
+
this.logger.warning("API with name ".concat(route.api, " doesn't have a apiName set. Will not send js content to client."));
|
|
680
|
+
}
|
|
681
|
+
if (sendJSContent === true) {
|
|
682
|
+
var jsapipath = api.jsapi;
|
|
683
|
+
apiScripts += "\t<script type = \"text/javascript\" src = \"".concat(jsapipath, "\"></script>\n");
|
|
684
|
+
var baseUrl = "\"\"";
|
|
685
|
+
if (this.api != null)
|
|
686
|
+
baseUrl = "\"".concat(this.api.baseUrl, "\"");
|
|
687
|
+
var tempAPIContent = this.apiContent;
|
|
688
|
+
tempAPIContent = tempAPIContent.replace(/\%api\_name\%/g, api.apiName);
|
|
689
|
+
tempAPIContent = tempAPIContent.replace(/\%api\_exported\_name\%/g, api.libraryName);
|
|
690
|
+
tempAPIContent = tempAPIContent.replace(/\%base\_url\%/g, baseUrl);
|
|
691
|
+
apiCode += tempAPIContent;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
if (this.hotSite.server != null) {
|
|
697
|
+
if (this.hotSite.server.jsSrcPath != null)
|
|
698
|
+
jsSrcPath = this.hotSite.server.jsSrcPath;
|
|
699
|
+
}
|
|
700
|
+
if (this.hotSite.publicSecrets != null) {
|
|
701
|
+
for (var key in this.hotSite.publicSecrets) {
|
|
702
|
+
var secret = this.hotSite.publicSecrets[key];
|
|
703
|
+
var value = undefined;
|
|
704
|
+
if (typeof (secret) === "string")
|
|
705
|
+
value = JSON.stringify(secret);
|
|
706
|
+
else {
|
|
707
|
+
if (HotStaq.isWeb === false) {
|
|
708
|
+
if (this.api != null) {
|
|
709
|
+
if (this.api.connection == null)
|
|
710
|
+
throw new Error("Cannot pass secrets from the API if there's no connection!");
|
|
711
|
+
var serverConn = this.api.connection;
|
|
712
|
+
if (secret.passSecretFromAPI != null)
|
|
713
|
+
value = JSON.stringify(serverConn.secrets[key]);
|
|
714
|
+
}
|
|
715
|
+
if (secret.env != null) {
|
|
716
|
+
/// @fixme @secvul Is this a security vulnerability? Need to verify that
|
|
717
|
+
/// only the server has access to this. At this point, I think only the
|
|
718
|
+
/// server has access.
|
|
719
|
+
var envKey = secret.env;
|
|
720
|
+
value = JSON.stringify(process.env[envKey]);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
publicSecrets += "processor.publicSecrets[\"".concat(key, "\"] = ").concat(value, ";\n");
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
var content = this.pageContent;
|
|
729
|
+
var fixContent = function (tempContent) {
|
|
730
|
+
var developerModeStr = "";
|
|
731
|
+
var testerAPIStr = "";
|
|
732
|
+
if (_this.mode === Hot_1.DeveloperMode.Development) {
|
|
733
|
+
developerModeStr = "tempMode = HotStaqWeb.DeveloperMode.Development;";
|
|
734
|
+
testerAPIStr = _this.testerApiContent;
|
|
735
|
+
if (_this.hotSite != null) {
|
|
736
|
+
if (_this.hotSite.testing != null) {
|
|
737
|
+
if (_this.hotSite.testing.web.testerAPIUrl == null)
|
|
738
|
+
_this.hotSite.testing.web.testerAPIUrl = "http://127.0.0.1:8182";
|
|
739
|
+
testerAPIStr = testerAPIStr.replace(/\%base\_tester\_url\%/g, "\"".concat(_this.hotSite.testing.web.testerAPIUrl, "\""));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
var loadFiles = "";
|
|
744
|
+
if (Object.keys(_this.files).length > 0) {
|
|
745
|
+
loadFiles += "var files = {};\n\n";
|
|
746
|
+
for (var key in _this.files) {
|
|
747
|
+
var file = _this.files[key];
|
|
748
|
+
var fileUrl = "\"".concat(file.url, "\"");
|
|
749
|
+
var fileContent = "";
|
|
750
|
+
if (file.content !== "") {
|
|
751
|
+
var escapedContent = JSON.stringify(file.content);
|
|
752
|
+
// Find any script tags and interrupt them so the HTML parsers
|
|
753
|
+
// don't get confused.
|
|
754
|
+
escapedContent = escapedContent.replace(new RegExp("\\<script", "gmi"), "<scr\" + \"ipt");
|
|
755
|
+
escapedContent = escapedContent.replace(new RegExp("\\<\\/script", "gmi"), "</scr\" + \"ipt");
|
|
756
|
+
fileContent = ", \"content\": ".concat(escapedContent);
|
|
757
|
+
}
|
|
758
|
+
loadFiles += "\t\t\tfiles[\"".concat(key, "\"] = { \"url\": ").concat(fileUrl).concat(fileContent, " };\n");
|
|
759
|
+
}
|
|
760
|
+
loadFiles += "\t\t\tpromises.push (processor.loadHotFiles (files));\n";
|
|
761
|
+
}
|
|
762
|
+
tempContent = tempContent.replace(/\%title\%/g, name);
|
|
763
|
+
if (passArgs === true)
|
|
764
|
+
tempContent = tempContent.replace(/\%args\%/g, "Hot.Arguments");
|
|
765
|
+
if (args != null)
|
|
766
|
+
tempContent = tempContent.replace(/\%args\%/g, JSON.stringify(args));
|
|
767
|
+
var testerMap = routeKey;
|
|
768
|
+
var testerUrl = "";
|
|
769
|
+
var testerLaunchpadUrl = "";
|
|
770
|
+
var testerName = "Tester";
|
|
771
|
+
if (_this.hotSite != null) {
|
|
772
|
+
if (_this.hotSite.testing != null) {
|
|
773
|
+
if (_this.hotSite.testing.web.tester != null)
|
|
774
|
+
testerName = _this.hotSite.testing.web.tester;
|
|
775
|
+
if (_this.hotSite.testing.web.testerName != null)
|
|
776
|
+
testerName = _this.hotSite.testing.web.testerName;
|
|
777
|
+
if (_this.hotSite.testing.web.testerAPIUrl != null)
|
|
778
|
+
testerUrl = _this.hotSite.testing.web.testerAPIUrl;
|
|
779
|
+
if (_this.hotSite.testing.web.launchpadUrl != null)
|
|
780
|
+
testerLaunchpadUrl = _this.hotSite.testing.web.launchpadUrl;
|
|
781
|
+
}
|
|
782
|
+
if (_this.hotSite.routes != null) {
|
|
783
|
+
if (_this.hotSite.routes[routeKey] != null) {
|
|
784
|
+
var route = _this.hotSite.routes[routeKey];
|
|
785
|
+
testerMap = route.name;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
tempContent = tempContent.replace(/\%hotstaq\_js\_src\%/g, jsSrcPath);
|
|
790
|
+
tempContent = tempContent.replace(/\%developer\_mode\%/g, developerModeStr);
|
|
791
|
+
tempContent = tempContent.replace(/\%tester\_api\%/g, testerAPIStr);
|
|
792
|
+
tempContent = tempContent.replace(/\%apis\_to\_load\%/g, apiScripts);
|
|
793
|
+
tempContent = tempContent.replace(/\%load\_hot\_site\%/g, ""); /// @fixme Should this only be done server-side?
|
|
794
|
+
tempContent = tempContent.replace(/\%load\_files\%/g, loadFiles);
|
|
795
|
+
tempContent = tempContent.replace(/\%api\_code\%/g, apiCode);
|
|
796
|
+
tempContent = tempContent.replace(/\%public\_secrets\%/g, publicSecrets);
|
|
797
|
+
tempContent = tempContent.replace(/\%url\%/g, url);
|
|
798
|
+
tempContent = tempContent.replace(/\%tester\_name\%/g, "\"".concat(testerName, "\""));
|
|
799
|
+
tempContent = tempContent.replace(/\%tester\_map\%/g, "\"".concat(testerMap, "\""));
|
|
800
|
+
tempContent = tempContent.replace(/\%tester\_api\_base\_url\%/g, "\"".concat(testerUrl, "\""));
|
|
801
|
+
tempContent = tempContent.replace(/\%tester\_launchpad\_url\%/g, "\"".concat(testerLaunchpadUrl, "\""));
|
|
802
|
+
return (tempContent);
|
|
803
|
+
};
|
|
804
|
+
content = fixContent(content);
|
|
805
|
+
return (content);
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Create the Express routes from the given pages. Be sure to load the
|
|
809
|
+
* pages first before doing this. This method is meant to be used for
|
|
810
|
+
* customized Express applications. If you wish to use the loaded routes
|
|
811
|
+
* from this HotStaq object with HotHTTPServer, be sure to use
|
|
812
|
+
* the loadHotSite method in HotHTTPServer.
|
|
813
|
+
*/
|
|
814
|
+
HotStaq.prototype.createExpressRoutes = function (expressApp, jsSrcPath) {
|
|
815
|
+
if (jsSrcPath === void 0) { jsSrcPath = "./js/HotStaq.js"; }
|
|
816
|
+
var _loop_1 = function (key) {
|
|
817
|
+
var page = this_1.pages[key];
|
|
818
|
+
var content = this_1.generateContent(page.route, page.name, page.files[0].url, jsSrcPath);
|
|
819
|
+
expressApp.get(page.route, function (req, res) {
|
|
820
|
+
res.send(content);
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
var this_1 = this;
|
|
824
|
+
for (var key in this.pages) {
|
|
825
|
+
_loop_1(key);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Add a tester for use later.
|
|
830
|
+
*/
|
|
831
|
+
HotStaq.prototype.addTester = function (tester) {
|
|
832
|
+
this.testers[tester.name] = tester;
|
|
833
|
+
};
|
|
834
|
+
/**
|
|
835
|
+
* Get the list of maps for testing from the HotSite.
|
|
836
|
+
*/
|
|
837
|
+
HotStaq.prototype.getWebTestingMaps = function () {
|
|
838
|
+
if (this.hotSite == null)
|
|
839
|
+
throw new Error("No HotSite was loaded!");
|
|
840
|
+
if (this.hotSite.testing == null)
|
|
841
|
+
throw new Error("The HotSite does not have a testing object!");
|
|
842
|
+
if (this.hotSite.testing.web == null)
|
|
843
|
+
throw new Error("The HotSite does not have a testing web object!");
|
|
844
|
+
if (this.hotSite.testing.web.maps == null)
|
|
845
|
+
throw new Error("The HotSite testing object does not have any maps!");
|
|
846
|
+
return (this.hotSite.testing.web.maps);
|
|
847
|
+
};
|
|
848
|
+
/**
|
|
849
|
+
* Get the list of maps for testing from the HotSite.
|
|
850
|
+
*/
|
|
851
|
+
HotStaq.prototype.getAPITestingMaps = function () {
|
|
852
|
+
if (this.hotSite == null)
|
|
853
|
+
throw new Error("No HotSite was loaded!");
|
|
854
|
+
if (this.hotSite.testing == null)
|
|
855
|
+
throw new Error("The HotSite does not have a testing object!");
|
|
856
|
+
if (this.hotSite.testing.api == null)
|
|
857
|
+
throw new Error("The HotSite does not have a testing api object!");
|
|
858
|
+
if (this.hotSite.testing.api.maps == null)
|
|
859
|
+
throw new Error("The HotSite testing object does not have any maps!");
|
|
860
|
+
return (this.hotSite.testing.api.maps);
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* Get a route's key from a route's name.
|
|
864
|
+
*/
|
|
865
|
+
HotStaq.prototype.getRouteKeyFromName = function (name) {
|
|
866
|
+
var foundKey = "";
|
|
867
|
+
if (this.hotSite != null) {
|
|
868
|
+
if (this.hotSite.routes != null) {
|
|
869
|
+
for (var key in this.hotSite.routes) {
|
|
870
|
+
var route = this.hotSite.routes[key];
|
|
871
|
+
if (route.name === name) {
|
|
872
|
+
foundKey = key;
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return (foundKey);
|
|
879
|
+
};
|
|
880
|
+
/**
|
|
881
|
+
* Get a route from a route's name.
|
|
882
|
+
*/
|
|
883
|
+
HotStaq.prototype.getRouteFromName = function (name) {
|
|
884
|
+
var foundRoute = null;
|
|
885
|
+
var foundKey = this.getRouteKeyFromName(name);
|
|
886
|
+
if (foundKey !== "")
|
|
887
|
+
foundRoute = this.hotSite.routes[foundKey];
|
|
888
|
+
return (foundRoute);
|
|
889
|
+
};
|
|
890
|
+
/**
|
|
891
|
+
* Execute tests.
|
|
892
|
+
*
|
|
893
|
+
* @param testerName The tester to use to execute tests.
|
|
894
|
+
* @param mapName The map or maps to use to navigate through tests.
|
|
895
|
+
*/
|
|
896
|
+
HotStaq.prototype.executeTests = function (testerName, mapName) {
|
|
897
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
898
|
+
var tester;
|
|
899
|
+
return __generator(this, function (_a) {
|
|
900
|
+
tester = this.testers[testerName];
|
|
901
|
+
if (tester == null)
|
|
902
|
+
throw new Error("Unable to execute tests. Tester ".concat(testerName, " does not exist!"));
|
|
903
|
+
return [2 /*return*/, (tester.execute(mapName))];
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
/**
|
|
908
|
+
* Execute all web tests from the HotSite testing web object.
|
|
909
|
+
*
|
|
910
|
+
* @param testerName The tester to use to execute tests.
|
|
911
|
+
*/
|
|
912
|
+
HotStaq.prototype.executeAllWebTests = function (testerName) {
|
|
913
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
914
|
+
var maps, tester, iIdx, mapName;
|
|
915
|
+
return __generator(this, function (_a) {
|
|
916
|
+
switch (_a.label) {
|
|
917
|
+
case 0:
|
|
918
|
+
maps = this.getWebTestingMaps();
|
|
919
|
+
tester = this.testers[testerName];
|
|
920
|
+
if (tester == null)
|
|
921
|
+
throw new Error("Unable to execute tests. Tester ".concat(testerName, " does not exist!"));
|
|
922
|
+
iIdx = 0;
|
|
923
|
+
_a.label = 1;
|
|
924
|
+
case 1:
|
|
925
|
+
if (!(iIdx < maps.length)) return [3 /*break*/, 4];
|
|
926
|
+
mapName = maps[iIdx];
|
|
927
|
+
return [4 /*yield*/, this.executeTests(testerName, mapName)];
|
|
928
|
+
case 2:
|
|
929
|
+
_a.sent();
|
|
930
|
+
_a.label = 3;
|
|
931
|
+
case 3:
|
|
932
|
+
iIdx++;
|
|
933
|
+
return [3 /*break*/, 1];
|
|
934
|
+
case 4: return [2 /*return*/];
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
};
|
|
939
|
+
/**
|
|
940
|
+
* Execute all api tests from the HotSite testing api object.
|
|
941
|
+
*
|
|
942
|
+
* @param testerName The tester to use to execute tests.
|
|
943
|
+
*/
|
|
944
|
+
HotStaq.prototype.executeAllAPITests = function (testerName) {
|
|
945
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
946
|
+
var maps, tester, iIdx, mapName;
|
|
947
|
+
return __generator(this, function (_a) {
|
|
948
|
+
switch (_a.label) {
|
|
949
|
+
case 0:
|
|
950
|
+
maps = this.getAPITestingMaps();
|
|
951
|
+
tester = this.testers[testerName];
|
|
952
|
+
if (tester == null)
|
|
953
|
+
throw new Error("Unable to execute tests. Tester ".concat(testerName, " does not exist!"));
|
|
954
|
+
iIdx = 0;
|
|
955
|
+
_a.label = 1;
|
|
956
|
+
case 1:
|
|
957
|
+
if (!(iIdx < maps.length)) return [3 /*break*/, 4];
|
|
958
|
+
mapName = maps[iIdx];
|
|
959
|
+
return [4 /*yield*/, this.executeTests(testerName, mapName)];
|
|
960
|
+
case 2:
|
|
961
|
+
_a.sent();
|
|
962
|
+
_a.label = 3;
|
|
963
|
+
case 3:
|
|
964
|
+
iIdx++;
|
|
965
|
+
return [3 /*break*/, 1];
|
|
966
|
+
case 4: return [2 /*return*/];
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
};
|
|
971
|
+
/**
|
|
972
|
+
* Process a page and get the result.
|
|
973
|
+
*/
|
|
974
|
+
HotStaq.prototype.process = function (pageName, args) {
|
|
975
|
+
if (args === void 0) { args = null; }
|
|
976
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
977
|
+
var page, result;
|
|
978
|
+
return __generator(this, function (_a) {
|
|
979
|
+
switch (_a.label) {
|
|
980
|
+
case 0:
|
|
981
|
+
page = this.getPage(pageName);
|
|
982
|
+
return [4 /*yield*/, page.process(args)];
|
|
983
|
+
case 1:
|
|
984
|
+
result = _a.sent();
|
|
985
|
+
return [2 /*return*/, (result)];
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
});
|
|
989
|
+
};
|
|
990
|
+
/**
|
|
991
|
+
* Process a local file and get the result.
|
|
992
|
+
*/
|
|
993
|
+
HotStaq.processLocalFile = function (localFilepath, name, args) {
|
|
994
|
+
if (name === void 0) { name = localFilepath; }
|
|
995
|
+
if (args === void 0) { args = null; }
|
|
996
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
997
|
+
var processor, file, page, result;
|
|
998
|
+
return __generator(this, function (_a) {
|
|
999
|
+
switch (_a.label) {
|
|
1000
|
+
case 0:
|
|
1001
|
+
processor = new HotStaq();
|
|
1002
|
+
file = new HotFile_1.HotFile({
|
|
1003
|
+
"localFile": localFilepath
|
|
1004
|
+
});
|
|
1005
|
+
return [4 /*yield*/, file.load()];
|
|
1006
|
+
case 1:
|
|
1007
|
+
_a.sent();
|
|
1008
|
+
page = new HotPage_1.HotPage({
|
|
1009
|
+
"processor": processor,
|
|
1010
|
+
"name": name,
|
|
1011
|
+
"files": [file]
|
|
1012
|
+
});
|
|
1013
|
+
processor.addPage(page);
|
|
1014
|
+
return [4 /*yield*/, processor.process(name, args)];
|
|
1015
|
+
case 2:
|
|
1016
|
+
result = _a.sent();
|
|
1017
|
+
return [2 /*return*/, (result)];
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
});
|
|
1021
|
+
};
|
|
1022
|
+
/**
|
|
1023
|
+
* Process a url and get the result.
|
|
1024
|
+
*/
|
|
1025
|
+
HotStaq.processUrl = function (options) {
|
|
1026
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1027
|
+
var file, page, result;
|
|
1028
|
+
return __generator(this, function (_a) {
|
|
1029
|
+
switch (_a.label) {
|
|
1030
|
+
case 0:
|
|
1031
|
+
file = new HotFile_1.HotFile({
|
|
1032
|
+
"url": options.url
|
|
1033
|
+
});
|
|
1034
|
+
return [4 /*yield*/, file.load()];
|
|
1035
|
+
case 1:
|
|
1036
|
+
_a.sent();
|
|
1037
|
+
page = new HotPage_1.HotPage({
|
|
1038
|
+
"processor": options.processor,
|
|
1039
|
+
"name": options.name,
|
|
1040
|
+
"files": [file],
|
|
1041
|
+
"testerName": options.testerName,
|
|
1042
|
+
"testerMap": options.testerMap
|
|
1043
|
+
});
|
|
1044
|
+
options.processor.addPage(page);
|
|
1045
|
+
return [4 /*yield*/, options.processor.process(options.name, options.args)];
|
|
1046
|
+
case 2:
|
|
1047
|
+
result = _a.sent();
|
|
1048
|
+
return [2 /*return*/, (result)];
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
});
|
|
1052
|
+
};
|
|
1053
|
+
/**
|
|
1054
|
+
* Process content and get the result.
|
|
1055
|
+
*/
|
|
1056
|
+
HotStaq.processContent = function (processor, content, name, args) {
|
|
1057
|
+
if (args === void 0) { args = null; }
|
|
1058
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1059
|
+
var file, page, result;
|
|
1060
|
+
return __generator(this, function (_a) {
|
|
1061
|
+
switch (_a.label) {
|
|
1062
|
+
case 0:
|
|
1063
|
+
file = new HotFile_1.HotFile({
|
|
1064
|
+
"content": content
|
|
1065
|
+
});
|
|
1066
|
+
return [4 /*yield*/, file.load()];
|
|
1067
|
+
case 1:
|
|
1068
|
+
_a.sent();
|
|
1069
|
+
page = new HotPage_1.HotPage({
|
|
1070
|
+
"processor": processor,
|
|
1071
|
+
"name": name,
|
|
1072
|
+
"files": [file]
|
|
1073
|
+
});
|
|
1074
|
+
processor.addPage(page);
|
|
1075
|
+
return [4 /*yield*/, processor.process(name, args)];
|
|
1076
|
+
case 2:
|
|
1077
|
+
result = _a.sent();
|
|
1078
|
+
return [2 /*return*/, (result)];
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
});
|
|
1082
|
+
};
|
|
1083
|
+
/**
|
|
1084
|
+
* When the window has finished loading, execute the function.
|
|
1085
|
+
* This is meant for web browser use only.
|
|
1086
|
+
*/
|
|
1087
|
+
HotStaq.onReady = function (readyFunc) {
|
|
1088
|
+
if ((document.readyState === "complete") || (document.readyState === "interactive"))
|
|
1089
|
+
readyFunc();
|
|
1090
|
+
else
|
|
1091
|
+
window.addEventListener("load", readyFunc);
|
|
1092
|
+
};
|
|
1093
|
+
/**
|
|
1094
|
+
* Replace the current HTML page with the output.
|
|
1095
|
+
* This is meant for web browser use only.
|
|
1096
|
+
*/
|
|
1097
|
+
HotStaq.useOutput = function (output) {
|
|
1098
|
+
document.open();
|
|
1099
|
+
document.write(output);
|
|
1100
|
+
document.close();
|
|
1101
|
+
};
|
|
1102
|
+
/**
|
|
1103
|
+
* Wait for testers to load.
|
|
1104
|
+
*
|
|
1105
|
+
* @fixme This does not wait for ALL testers to finish loading. Only
|
|
1106
|
+
* the first one.
|
|
1107
|
+
*/
|
|
1108
|
+
HotStaq.waitForTesters = function () {
|
|
1109
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1110
|
+
return __generator(this, function (_a) {
|
|
1111
|
+
switch (_a.label) {
|
|
1112
|
+
case 0:
|
|
1113
|
+
if (!(HotStaq.isReadyForTesting === false)) return [3 /*break*/, 2];
|
|
1114
|
+
return [4 /*yield*/, HotStaq.wait(10)];
|
|
1115
|
+
case 1:
|
|
1116
|
+
_a.sent();
|
|
1117
|
+
return [3 /*break*/, 0];
|
|
1118
|
+
case 2:
|
|
1119
|
+
if (!(HotStaq.onReadyForTesting != null)) return [3 /*break*/, 4];
|
|
1120
|
+
return [4 /*yield*/, HotStaq.onReadyForTesting()];
|
|
1121
|
+
case 3:
|
|
1122
|
+
_a.sent();
|
|
1123
|
+
_a.label = 4;
|
|
1124
|
+
case 4: return [2 /*return*/];
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
});
|
|
1128
|
+
};
|
|
1129
|
+
/**
|
|
1130
|
+
* Process and replace the current HTML page with the hott script from the given url.
|
|
1131
|
+
* This is meant for web browser use only.
|
|
1132
|
+
*/
|
|
1133
|
+
HotStaq.displayUrl = function (url, name, processor, args) {
|
|
1134
|
+
if (name === void 0) { name = null; }
|
|
1135
|
+
if (processor === void 0) { processor = null; }
|
|
1136
|
+
if (args === void 0) { args = null; }
|
|
1137
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1138
|
+
var _this = this;
|
|
1139
|
+
return __generator(this, function (_a) {
|
|
1140
|
+
return [2 /*return*/, (new Promise(function (resolve, reject) {
|
|
1141
|
+
HotStaq.onReady(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1142
|
+
var options, client, testerAPI, output;
|
|
1143
|
+
return __generator(this, function (_a) {
|
|
1144
|
+
switch (_a.label) {
|
|
1145
|
+
case 0:
|
|
1146
|
+
options = {
|
|
1147
|
+
"url": ""
|
|
1148
|
+
};
|
|
1149
|
+
if (name == null) {
|
|
1150
|
+
if (typeof (url) === "string")
|
|
1151
|
+
options.name = url;
|
|
1152
|
+
else
|
|
1153
|
+
options.name = url.name;
|
|
1154
|
+
}
|
|
1155
|
+
else
|
|
1156
|
+
options.name = name;
|
|
1157
|
+
if (options.name === "") {
|
|
1158
|
+
if (typeof (url) === "string")
|
|
1159
|
+
options.name = url;
|
|
1160
|
+
else
|
|
1161
|
+
options.name = url.name;
|
|
1162
|
+
}
|
|
1163
|
+
if (typeof (url) === "string")
|
|
1164
|
+
options.url = url;
|
|
1165
|
+
else {
|
|
1166
|
+
options.url = url.url;
|
|
1167
|
+
if (processor == null) {
|
|
1168
|
+
if (url.processor != null)
|
|
1169
|
+
processor = url.processor;
|
|
1170
|
+
}
|
|
1171
|
+
if (args == null) {
|
|
1172
|
+
if (url.args != null)
|
|
1173
|
+
args = url.args;
|
|
1174
|
+
}
|
|
1175
|
+
if (url.testerMap != null)
|
|
1176
|
+
options.testerMap = url.testerMap;
|
|
1177
|
+
if (url.testerName != null)
|
|
1178
|
+
options.testerName = url.testerName;
|
|
1179
|
+
if (url.testerAPIBaseUrl != null)
|
|
1180
|
+
options.testerAPIBaseUrl = url.testerAPIBaseUrl;
|
|
1181
|
+
}
|
|
1182
|
+
if (processor == null)
|
|
1183
|
+
processor = new HotStaq();
|
|
1184
|
+
if (processor.mode === Hot_1.DeveloperMode.Development) {
|
|
1185
|
+
if (processor.testerAPI == null) {
|
|
1186
|
+
if (options.testerAPIBaseUrl == null)
|
|
1187
|
+
options.testerAPIBaseUrl = "";
|
|
1188
|
+
if (options.testerAPIBaseUrl === "")
|
|
1189
|
+
options.testerAPIBaseUrl = "http://127.0.0.1:8182";
|
|
1190
|
+
client = new HotClient_1.HotClient(processor);
|
|
1191
|
+
testerAPI = new HotTesterAPI_1.HotTesterAPI(options.testerAPIBaseUrl, client);
|
|
1192
|
+
testerAPI.connection.api = testerAPI;
|
|
1193
|
+
processor.testerAPI = testerAPI;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
options.processor = processor;
|
|
1197
|
+
options.args = args;
|
|
1198
|
+
return [4 /*yield*/, HotStaq.processUrl(options)];
|
|
1199
|
+
case 1:
|
|
1200
|
+
output = _a.sent();
|
|
1201
|
+
if (processor.mode === Hot_1.DeveloperMode.Development) {
|
|
1202
|
+
output +=
|
|
1203
|
+
"<script type = \"text/javascript\">\n\tfunction hotstaq_isDocumentReady ()\n\t{\n\t\tif (window[\"Hot\"] != null)\n\t\t{\n\t\t\tif (Hot.Mode === HotStaqWeb.DeveloperMode.Development)\n\t\t\t{\n\t\t\t\tlet func = function ()\n\t\t\t\t\t{\n\t\t\t\t\t\tif (Hot.TesterAPI != null)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlet testPaths = {};\n\t\t\t\t\t\t\tlet testElements = JSON.stringify (Hot.CurrentPage.testElements);\n\t\t\t\t\t\t\tlet testMaps = JSON.stringify (Hot.CurrentPage.testMaps);\n\n\t\t\t\t\t\t\tfor (let key in Hot.CurrentPage.testPaths)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlet testPath = Hot.CurrentPage.testPaths[key];\n\n\t\t\t\t\t\t\t\ttestPaths[key] = testPath.toString ();\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet testPathsStr = JSON.stringify (testPaths);\n\n\t\t\t\t\t\t\tHot.TesterAPI.tester.pageLoaded ({\n\t\t\t\t\t\t\t\t\ttesterName: Hot.CurrentPage.testerName,\n\t\t\t\t\t\t\t\t\ttesterMap: Hot.CurrentPage.testerMap,\n\t\t\t\t\t\t\t\t\tpageName: Hot.CurrentPage.name,\n\t\t\t\t\t\t\t\t\ttestElements: testElements,\n\t\t\t\t\t\t\t\t\ttestPaths: testPathsStr\n\t\t\t\t\t\t\t\t}).then (function (resp)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif (resp.error != null)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tif (resp.error !== \"\")\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new Error (resp.error);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tHotStaqWeb.HotStaq.isReadyForTesting = true;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\n\t\t\t\tif ((document.readyState === \"complete\") || (document.readyState === \"interactive\"))\n\t\t\t\t\tfunc ();\n\t\t\t\telse\n\t\t\t\t\tdocument.addEventListener (\"DOMContentLoaded\", func);\n\t\t\t}\n\t\t}\n\t}\n\n\thotstaq_isDocumentReady ();\n</script>";
|
|
1204
|
+
}
|
|
1205
|
+
HotStaq.useOutput(output);
|
|
1206
|
+
resolve(processor);
|
|
1207
|
+
return [2 /*return*/];
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}); });
|
|
1211
|
+
}))];
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
};
|
|
1215
|
+
/**
|
|
1216
|
+
* Process and replace the current HTML page with the hott script.
|
|
1217
|
+
* This is meant for web browser use only.
|
|
1218
|
+
*/
|
|
1219
|
+
HotStaq.displayContent = function (content, name, processor) {
|
|
1220
|
+
if (processor === void 0) { processor = null; }
|
|
1221
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1222
|
+
var _this = this;
|
|
1223
|
+
return __generator(this, function (_a) {
|
|
1224
|
+
return [2 /*return*/, (new Promise(function (resolve, reject) {
|
|
1225
|
+
HotStaq.onReady(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1226
|
+
var output;
|
|
1227
|
+
return __generator(this, function (_a) {
|
|
1228
|
+
switch (_a.label) {
|
|
1229
|
+
case 0:
|
|
1230
|
+
if (processor == null)
|
|
1231
|
+
processor = new HotStaq();
|
|
1232
|
+
return [4 /*yield*/, HotStaq.processContent(processor, content, name)];
|
|
1233
|
+
case 1:
|
|
1234
|
+
output = _a.sent();
|
|
1235
|
+
HotStaq.useOutput(output);
|
|
1236
|
+
resolve(processor);
|
|
1237
|
+
return [2 /*return*/];
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
}); });
|
|
1241
|
+
}))];
|
|
1242
|
+
});
|
|
1243
|
+
});
|
|
1244
|
+
};
|
|
1245
|
+
/**
|
|
1246
|
+
* Indicates if this is a web build.
|
|
1247
|
+
*/
|
|
1248
|
+
HotStaq.isWeb = false;
|
|
1249
|
+
/**
|
|
1250
|
+
* Indicates if this is ready for testing.
|
|
1251
|
+
*/
|
|
1252
|
+
HotStaq.isReadyForTesting = false;
|
|
1253
|
+
/**
|
|
1254
|
+
* Executes this event when this page is ready for testing.
|
|
1255
|
+
*/
|
|
1256
|
+
HotStaq.onReadyForTesting = null;
|
|
1257
|
+
return HotStaq;
|
|
1258
|
+
}());
|
|
1259
|
+
exports.HotStaq = HotStaq;
|
|
1260
|
+
//# sourceMappingURL=HotStaq.js.map
|