@flink-app/flink 0.12.1-alpha.0 → 0.12.1-alpha.1
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/bin/flink.ts +6 -13
- package/dist/bin/flink.js +3 -10
- package/dist/cli/build.js +3 -3
- package/dist/cli/clean.js +2 -2
- package/dist/cli/cli-utils.js +1 -1
- package/dist/cli/run.js +2 -2
- package/dist/src/FlinkApp.d.ts +1 -1
- package/dist/src/FlinkApp.js +77 -77
- package/dist/src/FlinkErrors.d.ts +1 -1
- package/dist/src/FlinkErrors.js +5 -5
- package/dist/src/FlinkHttpHandler.d.ts +7 -7
- package/dist/src/FlinkHttpHandler.js +1 -1
- package/dist/src/FlinkJob.d.ts +2 -2
- package/dist/src/FlinkLog.d.ts +2 -2
- package/dist/src/FlinkRepo.d.ts +6 -2
- package/dist/src/FlinkRepo.js +19 -10
- package/dist/src/FlinkResponse.d.ts +2 -2
- package/dist/src/FsUtils.js +7 -7
- package/dist/src/TypeScriptCompiler.js +83 -68
- package/dist/src/TypeScriptUtils.js +11 -33
- package/dist/src/index.js +5 -1
- package/dist/src/mock-data-generator.js +1 -1
- package/dist/src/utils.js +6 -6
- package/package.json +6 -6
- package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
- package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
- package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
- package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
- package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
- package/spec/mock-project/dist/src/index.js +6 -2
- package/src/FlinkApp.ts +5 -5
- package/src/FlinkRepo.ts +13 -4
- package/src/TypeScriptCompiler.ts +13 -2
- package/src/TypeScriptUtils.ts +110 -164
- package/cli/generate-schemas.ts +0 -153
- package/dist/cli/generate-schemas.d.ts +0 -2
- package/dist/cli/generate-schemas.js +0 -140
package/bin/flink.ts
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const commands = [
|
|
4
|
-
"build",
|
|
5
|
-
"generate" /* 'generate' is alias for 'build' */,
|
|
6
|
-
"run",
|
|
7
|
-
"clean",
|
|
8
|
-
"generate-schemas",
|
|
9
|
-
"help",
|
|
10
|
-
];
|
|
3
|
+
const commands = ["build", "generate" /* 'generate' is alias for 'build' */, "run", "clean", "help"];
|
|
11
4
|
|
|
12
5
|
const argv = process.argv.slice(2);
|
|
13
6
|
let argCommand = argv[0];
|
|
14
7
|
|
|
15
8
|
if (!argCommand || argv[0] === "help") {
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
console.log(`Usage: flink [${commands.join("|")}]`);
|
|
10
|
+
process.exit();
|
|
18
11
|
}
|
|
19
12
|
|
|
20
13
|
if (!commands.includes(argv[0])) {
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
console.log(`Invalid command: ${argCommand}`);
|
|
15
|
+
process.exit(1);
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
if (argCommand === "generate") {
|
|
26
|
-
|
|
19
|
+
argCommand = "build";
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
const cmd = require("../cli/" + argCommand);
|
package/dist/bin/flink.js
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
var commands = [
|
|
5
|
-
"build",
|
|
6
|
-
"generate" /* 'generate' is alias for 'build' */,
|
|
7
|
-
"run",
|
|
8
|
-
"clean",
|
|
9
|
-
"generate-schemas",
|
|
10
|
-
"help",
|
|
11
|
-
];
|
|
4
|
+
var commands = ["build", "generate" /* 'generate' is alias for 'build' */, "run", "clean", "help"];
|
|
12
5
|
var argv = process.argv.slice(2);
|
|
13
6
|
var argCommand = argv[0];
|
|
14
7
|
if (!argCommand || argv[0] === "help") {
|
|
15
|
-
console.log("Usage: flink ["
|
|
8
|
+
console.log("Usage: flink [".concat(commands.join("|"), "]"));
|
|
16
9
|
process.exit();
|
|
17
10
|
}
|
|
18
11
|
if (!commands.includes(argv[0])) {
|
|
19
|
-
console.log("Invalid command: "
|
|
12
|
+
console.log("Invalid command: ".concat(argCommand));
|
|
20
13
|
process.exit(1);
|
|
21
14
|
}
|
|
22
15
|
if (argCommand === "generate") {
|
package/dist/cli/build.js
CHANGED
|
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
-
while (_) try {
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
19
|
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;
|
|
20
20
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
21
|
switch (op[0]) {
|
|
@@ -57,7 +57,7 @@ module.exports = function run(args) {
|
|
|
57
57
|
if (args[0] && !args[0].startsWith("--")) {
|
|
58
58
|
dir = args[0];
|
|
59
59
|
}
|
|
60
|
-
exclude = cli_utils_1.getOption(args, "exclude", "/spec");
|
|
60
|
+
exclude = (0, cli_utils_1.getOption)(args, "exclude", "/spec");
|
|
61
61
|
return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
|
|
62
62
|
case 1:
|
|
63
63
|
_a.sent();
|
|
@@ -68,7 +68,7 @@ module.exports = function run(args) {
|
|
|
68
68
|
return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(exclude.split(",")), compiler.parseJobs(), compiler.generateStartScript()])];
|
|
69
69
|
case 2:
|
|
70
70
|
_a.sent();
|
|
71
|
-
console.log("Compilation done, took "
|
|
71
|
+
console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
|
|
72
72
|
compiler.emit();
|
|
73
73
|
return [2 /*return*/];
|
|
74
74
|
}
|
package/dist/cli/clean.js
CHANGED
|
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
-
while (_) try {
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
19
|
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;
|
|
20
20
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
21
|
switch (op[0]) {
|
|
@@ -58,7 +58,7 @@ module.exports = function run(args) {
|
|
|
58
58
|
return [4 /*yield*/, TypeScriptCompiler_1.default.clean(dir)];
|
|
59
59
|
case 1:
|
|
60
60
|
cleanedFolder = _a.sent();
|
|
61
|
-
console.log("Cleaned directory "
|
|
61
|
+
console.log("Cleaned directory ".concat(cleanedFolder));
|
|
62
62
|
return [2 /*return*/];
|
|
63
63
|
}
|
|
64
64
|
});
|
package/dist/cli/cli-utils.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getOption = void 0;
|
|
4
4
|
function getOption(args, name, defaultValue, opts) {
|
|
5
5
|
if (opts === void 0) { opts = {}; }
|
|
6
|
-
var option = "--"
|
|
6
|
+
var option = "--".concat(name);
|
|
7
7
|
if (args.includes(option)) {
|
|
8
8
|
if (opts.isBoolean && args[args.indexOf(option) + 1] !== "false") {
|
|
9
9
|
return true;
|
package/dist/cli/run.js
CHANGED
|
@@ -15,7 +15,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
15
15
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
16
|
function step(op) {
|
|
17
17
|
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
-
while (_) try {
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
19
|
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;
|
|
20
20
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
21
|
switch (op[0]) {
|
|
@@ -81,7 +81,7 @@ module.exports = function run(args) {
|
|
|
81
81
|
return [4 /*yield*/, Promise.all([compiler.parseRepos(), compiler.parseHandlers(), compiler.parseJobs(), compiler.generateStartScript(entry)])];
|
|
82
82
|
case 2:
|
|
83
83
|
_a.sent();
|
|
84
|
-
console.log("Compilation done, took "
|
|
84
|
+
console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
|
|
85
85
|
compiler.emit();
|
|
86
86
|
forkedProcess = require("child_process").fork(dir + "/dist/.flink/start.js");
|
|
87
87
|
forkedProcess.on("exit", function (code) {
|
package/dist/src/FlinkApp.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { HandlerFile, HttpMethod, QueryParamMetadata, RouteProps } from "./Flink
|
|
|
9
9
|
import { FlinkJobFile } from "./FlinkJob";
|
|
10
10
|
import { FlinkPlugin } from "./FlinkPlugin";
|
|
11
11
|
import { FlinkRepo } from "./FlinkRepo";
|
|
12
|
-
export
|
|
12
|
+
export type JSONSchema = JSONSchema7;
|
|
13
13
|
/**
|
|
14
14
|
* This will be populated at compile time when the apps handlers
|
|
15
15
|
* are picked up by TypeScript compiler
|
package/dist/src/FlinkApp.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
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;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -66,7 +66,7 @@ var FlinkLog_1 = require("./FlinkLog");
|
|
|
66
66
|
var mock_data_generator_1 = __importDefault(require("./mock-data-generator"));
|
|
67
67
|
var utils_1 = require("./utils");
|
|
68
68
|
var ajv = new ajv_1.default();
|
|
69
|
-
ajv_formats_1.default(ajv);
|
|
69
|
+
(0, ajv_formats_1.default)(ajv);
|
|
70
70
|
var defaultCorsOptions = {
|
|
71
71
|
allowedHeaders: "",
|
|
72
72
|
credentials: true,
|
|
@@ -129,10 +129,10 @@ var FlinkApp = /** @class */ (function () {
|
|
|
129
129
|
configurable: true
|
|
130
130
|
});
|
|
131
131
|
FlinkApp.prototype.start = function () {
|
|
132
|
-
var _a;
|
|
133
132
|
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
-
var startTime, offsetTime, _i,
|
|
133
|
+
var startTime, offsetTime, _i, _a, type, _b, _c, plugin, db;
|
|
135
134
|
var _this = this;
|
|
135
|
+
var _d;
|
|
136
136
|
return __generator(this, function (_e) {
|
|
137
137
|
switch (_e.label) {
|
|
138
138
|
case 0:
|
|
@@ -143,13 +143,13 @@ var FlinkApp = /** @class */ (function () {
|
|
|
143
143
|
_e.sent();
|
|
144
144
|
if (this.debug) {
|
|
145
145
|
offsetTime = Date.now();
|
|
146
|
-
FlinkLog_1.log.bgColorLog("cyan", "Init db took "
|
|
146
|
+
FlinkLog_1.log.bgColorLog("cyan", "Init db took ".concat(offsetTime - startTime, " ms"));
|
|
147
147
|
}
|
|
148
148
|
return [4 /*yield*/, this.buildContext()];
|
|
149
149
|
case 2:
|
|
150
150
|
_e.sent();
|
|
151
151
|
if (this.debug) {
|
|
152
|
-
FlinkLog_1.log.bgColorLog("cyan", "Build context took "
|
|
152
|
+
FlinkLog_1.log.bgColorLog("cyan", "Build context took ".concat(Date.now() - offsetTime, " ms"));
|
|
153
153
|
offsetTime = Date.now();
|
|
154
154
|
}
|
|
155
155
|
if (this.isSchedulingEnabled) {
|
|
@@ -159,28 +159,28 @@ var FlinkApp = /** @class */ (function () {
|
|
|
159
159
|
FlinkLog_1.log.info("🚫 Scheduling is disabled");
|
|
160
160
|
}
|
|
161
161
|
if (!this.disableHttpServer) {
|
|
162
|
-
this.expressApp = express_1.default();
|
|
163
|
-
this.expressApp.use(cors_1.default(this.corsOpts));
|
|
162
|
+
this.expressApp = (0, express_1.default)();
|
|
163
|
+
this.expressApp.use((0, cors_1.default)(this.corsOpts));
|
|
164
164
|
if (this.rawContentTypes) {
|
|
165
|
-
for (_i = 0,
|
|
166
|
-
type =
|
|
165
|
+
for (_i = 0, _a = this.rawContentTypes; _i < _a.length; _i++) {
|
|
166
|
+
type = _a[_i];
|
|
167
167
|
this.expressApp.use(express_1.default.raw({ type: type }));
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
this.expressApp.use(body_parser_1.default.json(this.jsonOptions));
|
|
171
171
|
if (this.accessLog.enabled) {
|
|
172
|
-
this.expressApp.use(morgan_1.default(this.accessLog.format));
|
|
172
|
+
this.expressApp.use((0, morgan_1.default)(this.accessLog.format));
|
|
173
173
|
}
|
|
174
174
|
this.expressApp.use(function (req, res, next) {
|
|
175
|
-
req.reqId = uuid_1.v4();
|
|
175
|
+
req.reqId = (0, uuid_1.v4)();
|
|
176
176
|
next();
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
_b = 0, _c = this.plugins;
|
|
180
180
|
_e.label = 3;
|
|
181
181
|
case 3:
|
|
182
|
-
if (!(
|
|
183
|
-
plugin =
|
|
182
|
+
if (!(_b < _c.length)) return [3 /*break*/, 9];
|
|
183
|
+
plugin = _c[_b];
|
|
184
184
|
db = void 0;
|
|
185
185
|
if (!plugin.db) return [3 /*break*/, 5];
|
|
186
186
|
return [4 /*yield*/, this.initPluginDb(plugin)];
|
|
@@ -194,16 +194,16 @@ var FlinkApp = /** @class */ (function () {
|
|
|
194
194
|
_e.sent();
|
|
195
195
|
_e.label = 7;
|
|
196
196
|
case 7:
|
|
197
|
-
FlinkLog_1.log.info("Initialized plugin '"
|
|
197
|
+
FlinkLog_1.log.info("Initialized plugin '".concat(plugin.id, "'"));
|
|
198
198
|
_e.label = 8;
|
|
199
199
|
case 8:
|
|
200
|
-
|
|
200
|
+
_b++;
|
|
201
201
|
return [3 /*break*/, 3];
|
|
202
202
|
case 9: return [4 /*yield*/, this.registerAutoRegisterableHandlers()];
|
|
203
203
|
case 10:
|
|
204
204
|
_e.sent();
|
|
205
205
|
if (this.debug) {
|
|
206
|
-
FlinkLog_1.log.bgColorLog("cyan", "Register handlers took "
|
|
206
|
+
FlinkLog_1.log.bgColorLog("cyan", "Register handlers took ".concat(Date.now() - offsetTime, " ms"));
|
|
207
207
|
offsetTime = Date.now();
|
|
208
208
|
}
|
|
209
209
|
if (!this.isSchedulingEnabled) return [3 /*break*/, 12];
|
|
@@ -211,7 +211,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
211
211
|
case 11:
|
|
212
212
|
_e.sent();
|
|
213
213
|
if (this.debug) {
|
|
214
|
-
FlinkLog_1.log.bgColorLog("cyan", "Register jobs took "
|
|
214
|
+
FlinkLog_1.log.bgColorLog("cyan", "Register jobs took ".concat(Date.now() - offsetTime, " ms"));
|
|
215
215
|
offsetTime = Date.now();
|
|
216
216
|
}
|
|
217
217
|
_e.label = 12;
|
|
@@ -221,7 +221,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
221
221
|
setTimeout(function () {
|
|
222
222
|
if (!_this.disableHttpServer) {
|
|
223
223
|
_this.expressApp.use(function (req, res, next) {
|
|
224
|
-
res.status(404).json(FlinkErrors_1.notFound());
|
|
224
|
+
res.status(404).json((0, FlinkErrors_1.notFound)());
|
|
225
225
|
});
|
|
226
226
|
}
|
|
227
227
|
_this.routingConfigured = true;
|
|
@@ -231,8 +231,8 @@ var FlinkApp = /** @class */ (function () {
|
|
|
231
231
|
this.started = true;
|
|
232
232
|
}
|
|
233
233
|
else {
|
|
234
|
-
(
|
|
235
|
-
FlinkLog_1.log.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '"
|
|
234
|
+
(_d = this.expressApp) === null || _d === void 0 ? void 0 : _d.listen(this.port, function () {
|
|
235
|
+
FlinkLog_1.log.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '".concat(_this.name, "' is running and waiting for connections on ").concat(_this.port));
|
|
236
236
|
_this.started = true;
|
|
237
237
|
});
|
|
238
238
|
}
|
|
@@ -254,18 +254,18 @@ var FlinkApp = /** @class */ (function () {
|
|
|
254
254
|
}
|
|
255
255
|
var routeProps = __assign(__assign({}, (handler.Route || {})), routePropsOverride);
|
|
256
256
|
if (!routeProps.method) {
|
|
257
|
-
FlinkLog_1.log.error("Failed to register handler '"
|
|
257
|
+
FlinkLog_1.log.error("Failed to register handler '".concat(handler.__file, "': Missing 'method' in route props, either set it or name handler file with HTTP method as prefix"));
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
260
|
if (!routeProps.path) {
|
|
261
|
-
FlinkLog_1.log.error("Failed to register handler '"
|
|
261
|
+
FlinkLog_1.log.error("Failed to register handler '".concat(handler.__file, "': Missing 'path' in route props"));
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
264
|
var dup = this.handlers.find(function (h) { return h.routeProps.path === routeProps.path && h.routeProps.method === routeProps.method; });
|
|
265
|
-
var methodAndPath = routeProps.method.toUpperCase()
|
|
265
|
+
var methodAndPath = "".concat(routeProps.method.toUpperCase(), " ").concat(routeProps.path);
|
|
266
266
|
if (dup) {
|
|
267
267
|
// TODO: Not sure if there is a case where you'd want to overwrite a route?
|
|
268
|
-
FlinkLog_1.log.warn(methodAndPath
|
|
268
|
+
FlinkLog_1.log.warn("".concat(methodAndPath, " overlaps existing route"));
|
|
269
269
|
}
|
|
270
270
|
var handlerConfig = {
|
|
271
271
|
routeProps: __assign(__assign({}, routeProps), { method: routeProps.method, path: routeProps.path }),
|
|
@@ -277,10 +277,10 @@ var FlinkApp = /** @class */ (function () {
|
|
|
277
277
|
paramsMetadata: handler.__params || [],
|
|
278
278
|
};
|
|
279
279
|
if (((_c = handler.__schemas) === null || _c === void 0 ? void 0 : _c.reqSchema) && !((_d = handlerConfig.schema) === null || _d === void 0 ? void 0 : _d.reqSchema)) {
|
|
280
|
-
FlinkLog_1.log.warn("Expected request schema "
|
|
280
|
+
FlinkLog_1.log.warn("Expected request schema ".concat(handler.__schemas.reqSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
|
|
281
281
|
}
|
|
282
282
|
if (((_e = handler.__schemas) === null || _e === void 0 ? void 0 : _e.resSchema) && !((_f = handlerConfig.schema) === null || _f === void 0 ? void 0 : _f.resSchema)) {
|
|
283
|
-
FlinkLog_1.log.warn("Expected response schema "
|
|
283
|
+
FlinkLog_1.log.warn("Expected response schema ".concat(handler.__schemas.resSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
|
|
284
284
|
}
|
|
285
285
|
this.registerHandler(handlerConfig, handler.default);
|
|
286
286
|
};
|
|
@@ -290,10 +290,10 @@ var FlinkApp = /** @class */ (function () {
|
|
|
290
290
|
var routeProps = handlerConfig.routeProps, _a = handlerConfig.schema, schema = _a === void 0 ? {} : _a;
|
|
291
291
|
var method = routeProps.method;
|
|
292
292
|
if (!method) {
|
|
293
|
-
FlinkLog_1.log.error("Route "
|
|
293
|
+
FlinkLog_1.log.error("Route ".concat(routeProps.path, " is missing http method"));
|
|
294
294
|
}
|
|
295
295
|
if (method) {
|
|
296
|
-
var methodAndRoute_1 = method.toUpperCase()
|
|
296
|
+
var methodAndRoute_1 = "".concat(method.toUpperCase(), " ").concat(routeProps.path);
|
|
297
297
|
if (this.disableHttpServer) {
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
@@ -314,28 +314,28 @@ var FlinkApp = /** @class */ (function () {
|
|
|
314
314
|
return [4 /*yield*/, this.authenticate(req, routeProps.permissions)];
|
|
315
315
|
case 1:
|
|
316
316
|
if (!(_a.sent())) {
|
|
317
|
-
return [2 /*return*/, res.status(401).json(FlinkErrors_1.unauthorized())];
|
|
317
|
+
return [2 /*return*/, res.status(401).json((0, FlinkErrors_1.unauthorized)())];
|
|
318
318
|
}
|
|
319
319
|
_a.label = 2;
|
|
320
320
|
case 2:
|
|
321
321
|
if (validateReq_1) {
|
|
322
322
|
valid = validateReq_1(req.body);
|
|
323
323
|
if (!valid) {
|
|
324
|
-
FlinkLog_1.log.warn(methodAndRoute_1
|
|
325
|
-
FlinkLog_1.log.debug("Invalid json: "
|
|
324
|
+
FlinkLog_1.log.warn("".concat(methodAndRoute_1, ": Bad request ").concat(JSON.stringify(validateReq_1.errors, null, 2)));
|
|
325
|
+
FlinkLog_1.log.debug("Invalid json: ".concat(JSON.stringify(req.body)));
|
|
326
326
|
return [2 /*return*/, res.status(400).json({
|
|
327
327
|
status: 400,
|
|
328
328
|
error: {
|
|
329
|
-
id: uuid_1.v4(),
|
|
329
|
+
id: (0, uuid_1.v4)(),
|
|
330
330
|
title: "Bad request",
|
|
331
|
-
detail: "Schema did not validate "
|
|
331
|
+
detail: "Schema did not validate ".concat(JSON.stringify(validateReq_1.errors)),
|
|
332
332
|
},
|
|
333
333
|
})];
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
if (routeProps.mockApi && schema.resSchema) {
|
|
337
|
-
FlinkLog_1.log.warn("Mock response for "
|
|
338
|
-
data = mock_data_generator_1.default(schema.resSchema);
|
|
337
|
+
FlinkLog_1.log.warn("Mock response for ".concat(req.method.toUpperCase(), " ").concat(req.path));
|
|
338
|
+
data = (0, mock_data_generator_1.default)(schema.resSchema);
|
|
339
339
|
res.status(200).json({
|
|
340
340
|
status: 200,
|
|
341
341
|
data: data,
|
|
@@ -361,29 +361,29 @@ var FlinkApp = /** @class */ (function () {
|
|
|
361
361
|
return [2 /*return*/, res.status(err_1.status).json({
|
|
362
362
|
status: err_1.status,
|
|
363
363
|
error: {
|
|
364
|
-
id: err_1.error.id || uuid_1.v4(),
|
|
365
|
-
title: err_1.error.title || "Unhandled error: "
|
|
364
|
+
id: err_1.error.id || (0, uuid_1.v4)(),
|
|
365
|
+
title: err_1.error.title || "Unhandled error: ".concat(err_1.error.code || err_1.status),
|
|
366
366
|
detail: err_1.error.detail,
|
|
367
367
|
code: err_1.error.code,
|
|
368
368
|
},
|
|
369
369
|
})];
|
|
370
370
|
}
|
|
371
|
-
FlinkLog_1.log.warn("Handler '"
|
|
371
|
+
FlinkLog_1.log.warn("Handler '".concat(methodAndRoute_1, "' threw unhandled exception ").concat(err_1));
|
|
372
372
|
console.error(err_1);
|
|
373
|
-
return [2 /*return*/, res.status(500).json(FlinkErrors_1.internalServerError(err_1))];
|
|
373
|
+
return [2 /*return*/, res.status(500).json((0, FlinkErrors_1.internalServerError)(err_1))];
|
|
374
374
|
case 6:
|
|
375
|
-
if (validateRes_1 && !utils_1.isError(handlerRes)) {
|
|
375
|
+
if (validateRes_1 && !(0, utils_1.isError)(handlerRes)) {
|
|
376
376
|
valid = validateRes_1(JSON.parse(JSON.stringify(handlerRes.data)));
|
|
377
377
|
if (!valid) {
|
|
378
|
-
FlinkLog_1.log.warn("["
|
|
379
|
-
FlinkLog_1.log.debug("Invalid json: "
|
|
378
|
+
FlinkLog_1.log.warn("[".concat(req.reqId, "] ").concat(methodAndRoute_1, ": Bad response ").concat(JSON.stringify(validateRes_1.errors, null, 2)));
|
|
379
|
+
FlinkLog_1.log.debug("Invalid json: ".concat(JSON.stringify(handlerRes.data)));
|
|
380
380
|
// log.debug(JSON.stringify(schema, null, 2));
|
|
381
381
|
return [2 /*return*/, res.status(500).json({
|
|
382
382
|
status: 500,
|
|
383
383
|
error: {
|
|
384
|
-
id: uuid_1.v4(),
|
|
384
|
+
id: (0, uuid_1.v4)(),
|
|
385
385
|
title: "Bad response",
|
|
386
|
-
detail: "Schema did not validate "
|
|
386
|
+
detail: "Schema did not validate ".concat(JSON.stringify(validateRes_1.errors)),
|
|
387
387
|
},
|
|
388
388
|
})];
|
|
389
389
|
}
|
|
@@ -395,12 +395,12 @@ var FlinkApp = /** @class */ (function () {
|
|
|
395
395
|
});
|
|
396
396
|
}); });
|
|
397
397
|
if (this.handlerRouteCache.has(methodAndRoute_1)) {
|
|
398
|
-
FlinkLog_1.log.error("Cannot register handler "
|
|
398
|
+
FlinkLog_1.log.error("Cannot register handler ".concat(methodAndRoute_1, " - route already registered"));
|
|
399
399
|
return process.exit(1); // TODO: Do we need to exit?
|
|
400
400
|
}
|
|
401
401
|
else {
|
|
402
402
|
this.handlerRouteCache.set(methodAndRoute_1, JSON.stringify(routeProps));
|
|
403
|
-
FlinkLog_1.log.info("Registered route "
|
|
403
|
+
FlinkLog_1.log.info("Registered route ".concat(methodAndRoute_1));
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
};
|
|
@@ -411,38 +411,38 @@ var FlinkApp = /** @class */ (function () {
|
|
|
411
411
|
* Will not register any handlers added programmatically.
|
|
412
412
|
*/
|
|
413
413
|
FlinkApp.prototype.registerAutoRegisterableHandlers = function () {
|
|
414
|
-
var _a, _b, _c;
|
|
415
414
|
return __awaiter(this, void 0, void 0, function () {
|
|
416
|
-
var _i, autoRegisteredHandlers_1,
|
|
415
|
+
var _i, autoRegisteredHandlers_1, _a, handler, assumedHttpMethod, pathParams, _b, _c, param;
|
|
416
|
+
var _d, _e, _f;
|
|
417
417
|
return __generator(this, function (_g) {
|
|
418
418
|
for (_i = 0, autoRegisteredHandlers_1 = exports.autoRegisteredHandlers; _i < autoRegisteredHandlers_1.length; _i++) {
|
|
419
|
-
|
|
419
|
+
_a = autoRegisteredHandlers_1[_i], handler = _a.handler, assumedHttpMethod = _a.assumedHttpMethod;
|
|
420
420
|
if (!handler.Route) {
|
|
421
|
-
FlinkLog_1.log.error("Missing Props in handler "
|
|
421
|
+
FlinkLog_1.log.error("Missing Props in handler ".concat(handler.__file));
|
|
422
422
|
continue;
|
|
423
423
|
}
|
|
424
424
|
if (!handler.default) {
|
|
425
|
-
FlinkLog_1.log.error("Missing exported handler function in handler "
|
|
425
|
+
FlinkLog_1.log.error("Missing exported handler function in handler ".concat(handler.__file));
|
|
426
426
|
continue;
|
|
427
427
|
}
|
|
428
|
-
if (!!((
|
|
429
|
-
pathParams = utils_1.getPathParams(handler.Route.path);
|
|
430
|
-
for (
|
|
431
|
-
param =
|
|
428
|
+
if (!!((_d = handler.__params) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
429
|
+
pathParams = (0, utils_1.getPathParams)(handler.Route.path);
|
|
430
|
+
for (_b = 0, _c = handler.__params; _b < _c.length; _b++) {
|
|
431
|
+
param = _c[_b];
|
|
432
432
|
if (!pathParams.includes(param.name)) {
|
|
433
|
-
FlinkLog_1.log.error("Handler "
|
|
433
|
+
FlinkLog_1.log.error("Handler ".concat(handler.__file, " has param ").concat(param.name, " but it is not present in the path '").concat(handler.Route.path, "'"));
|
|
434
434
|
throw new Error("Invalid/missing handler path param");
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
if (pathParams.length !== handler.__params.length) {
|
|
438
|
-
FlinkLog_1.log.warn("Handler "
|
|
438
|
+
FlinkLog_1.log.warn("Handler ".concat(handler.__file, " has ").concat(handler.__params.length, " typed params but the path '").concat(handler.Route.path, "' has ").concat(pathParams.length, " params"));
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
this.registerHandler({
|
|
442
442
|
routeProps: __assign(__assign({}, handler.Route), { method: handler.Route.method || assumedHttpMethod, origin: this.name }),
|
|
443
443
|
schema: {
|
|
444
|
-
reqSchema: (
|
|
445
|
-
resSchema: (
|
|
444
|
+
reqSchema: (_e = handler.__schemas) === null || _e === void 0 ? void 0 : _e.reqSchema,
|
|
445
|
+
resSchema: (_f = handler.__schemas) === null || _f === void 0 ? void 0 : _f.resSchema,
|
|
446
446
|
},
|
|
447
447
|
queryMetadata: handler.__query || [],
|
|
448
448
|
paramsMetadata: handler.__params || [],
|
|
@@ -462,29 +462,29 @@ var FlinkApp = /** @class */ (function () {
|
|
|
462
462
|
}
|
|
463
463
|
_loop_1 = function (jobProps, jobFn, __file) {
|
|
464
464
|
if (jobProps.cron && jobProps.interval) {
|
|
465
|
-
FlinkLog_1.log.error("Cannot register job "
|
|
465
|
+
FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both cron and interval are set in ").concat(__file));
|
|
466
466
|
return "continue";
|
|
467
467
|
}
|
|
468
468
|
if (jobProps.cron && jobProps.afterDelay) {
|
|
469
|
-
FlinkLog_1.log.error("Cannot register job "
|
|
469
|
+
FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both cron and afterDelay are set in ").concat(__file));
|
|
470
470
|
return "continue";
|
|
471
471
|
}
|
|
472
472
|
if (jobProps.interval && jobProps.afterDelay) {
|
|
473
|
-
FlinkLog_1.log.error("Cannot register job "
|
|
473
|
+
FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both interval and afterDelay are set in ").concat(__file));
|
|
474
474
|
return "continue";
|
|
475
475
|
}
|
|
476
476
|
if (this_1.scheduler.existsById(jobProps.id)) {
|
|
477
|
-
FlinkLog_1.log.error("Job with id "
|
|
477
|
+
FlinkLog_1.log.error("Job with id ".concat(jobProps.id, " is already registered, found duplicate in ").concat(__file));
|
|
478
478
|
return "continue";
|
|
479
479
|
}
|
|
480
|
-
FlinkLog_1.log.debug("Registering job "
|
|
480
|
+
FlinkLog_1.log.debug("Registering job ".concat(jobProps.id, ": ").concat(JSON.stringify(jobProps), " from ").concat(__file));
|
|
481
481
|
var task = new toad_scheduler_1.AsyncTask(jobProps.id, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
482
482
|
return __generator(this, function (_a) {
|
|
483
483
|
switch (_a.label) {
|
|
484
484
|
case 0: return [4 /*yield*/, jobFn({ ctx: this.ctx })];
|
|
485
485
|
case 1:
|
|
486
486
|
_a.sent();
|
|
487
|
-
FlinkLog_1.log.debug("Job "
|
|
487
|
+
FlinkLog_1.log.debug("Job ".concat(jobProps.id, " completed"));
|
|
488
488
|
if (jobProps.afterDelay) {
|
|
489
489
|
// afterDelay runs only once, so we remove the job
|
|
490
490
|
this.scheduler.removeById(jobProps.id);
|
|
@@ -493,7 +493,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
493
493
|
}
|
|
494
494
|
});
|
|
495
495
|
}); }, function (err) {
|
|
496
|
-
FlinkLog_1.log.error("Job "
|
|
496
|
+
FlinkLog_1.log.error("Job ".concat(jobProps.id, " threw unhandled exception ").concat(err));
|
|
497
497
|
console.error(err);
|
|
498
498
|
});
|
|
499
499
|
if (jobProps.cron) {
|
|
@@ -505,7 +505,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
505
505
|
}
|
|
506
506
|
else if (jobProps.interval) {
|
|
507
507
|
var job = new toad_scheduler_1.SimpleIntervalJob({
|
|
508
|
-
milliseconds: ms_1.default(jobProps.interval),
|
|
508
|
+
milliseconds: (0, ms_1.default)(jobProps.interval),
|
|
509
509
|
runImmediately: false, // TODO: Expose to props?
|
|
510
510
|
}, task, {
|
|
511
511
|
id: jobProps.id,
|
|
@@ -515,7 +515,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
515
515
|
}
|
|
516
516
|
else if (jobProps.afterDelay !== undefined) {
|
|
517
517
|
var job = new toad_scheduler_1.SimpleIntervalJob({
|
|
518
|
-
milliseconds: ms_1.default(jobProps.afterDelay),
|
|
518
|
+
milliseconds: (0, ms_1.default)(jobProps.afterDelay),
|
|
519
519
|
runImmediately: false,
|
|
520
520
|
}, task, {
|
|
521
521
|
id: jobProps.id,
|
|
@@ -524,7 +524,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
524
524
|
this_1.scheduler.addSimpleIntervalJob(job);
|
|
525
525
|
}
|
|
526
526
|
else {
|
|
527
|
-
FlinkLog_1.log.error("Cannot register job "
|
|
527
|
+
FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - no cron, interval or once set in ").concat(__file));
|
|
528
528
|
return "continue";
|
|
529
529
|
}
|
|
530
530
|
};
|
|
@@ -555,7 +555,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
555
555
|
_a = autoRegisteredRepos_1[_i], collectionName = _a.collectionName, repoInstanceName = _a.repoInstanceName, Repo = _a.Repo;
|
|
556
556
|
repoInstance = new Repo(collectionName, this.db);
|
|
557
557
|
this.repos[repoInstanceName] = repoInstance;
|
|
558
|
-
FlinkLog_1.log.info("Registered repo "
|
|
558
|
+
FlinkLog_1.log.info("Registered repo ".concat(repoInstanceName));
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
else if (exports.autoRegisteredRepos.length > 0) {
|
|
@@ -563,7 +563,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
563
563
|
}
|
|
564
564
|
pluginCtx = this.plugins.reduce(function (out, plugin) {
|
|
565
565
|
if (out[plugin.id]) {
|
|
566
|
-
throw new Error("Plugin "
|
|
566
|
+
throw new Error("Plugin ".concat(plugin.id, " is already registered"));
|
|
567
567
|
}
|
|
568
568
|
out[plugin.id] = plugin.ctx;
|
|
569
569
|
return out;
|
|
@@ -631,7 +631,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
631
631
|
if (!plugin.db) return [3 /*break*/, 5];
|
|
632
632
|
if (!plugin.db.useHostDb) return [3 /*break*/, 1];
|
|
633
633
|
if (!this.db) {
|
|
634
|
-
FlinkLog_1.log.error("Plugin '"
|
|
634
|
+
FlinkLog_1.log.error("Plugin '".concat(this.name, " configured to use host app db, but no db exists in FlinkApp'"));
|
|
635
635
|
}
|
|
636
636
|
else {
|
|
637
637
|
return [2 /*return*/, this.db];
|
|
@@ -642,14 +642,14 @@ var FlinkApp = /** @class */ (function () {
|
|
|
642
642
|
_a.label = 2;
|
|
643
643
|
case 2:
|
|
644
644
|
_a.trys.push([2, 4, , 5]);
|
|
645
|
-
FlinkLog_1.log.debug("Connecting to '"
|
|
645
|
+
FlinkLog_1.log.debug("Connecting to '".concat(plugin.id, "' db"));
|
|
646
646
|
return [4 /*yield*/, mongodb_1.MongoClient.connect(plugin.db.uri, this.getMongoConnectionOptions())];
|
|
647
647
|
case 3:
|
|
648
648
|
client = _a.sent();
|
|
649
649
|
return [2 /*return*/, client.db()];
|
|
650
650
|
case 4:
|
|
651
651
|
err_3 = _a.sent();
|
|
652
|
-
FlinkLog_1.log.error("Failed to connect to db defined in plugin '"
|
|
652
|
+
FlinkLog_1.log.error("Failed to connect to db defined in plugin '".concat(plugin.id, "': ") + err_3);
|
|
653
653
|
return [3 /*break*/, 5];
|
|
654
654
|
case 5: return [2 /*return*/];
|
|
655
655
|
}
|
|
@@ -662,7 +662,7 @@ var FlinkApp = /** @class */ (function () {
|
|
|
662
662
|
switch (_a.label) {
|
|
663
663
|
case 0:
|
|
664
664
|
if (!this.auth) {
|
|
665
|
-
throw new Error("Attempting to authenticate request ("
|
|
665
|
+
throw new Error("Attempting to authenticate request (".concat(req.method, " ").concat(req.path, ") but no authPlugin is set"));
|
|
666
666
|
}
|
|
667
667
|
return [4 /*yield*/, this.auth.authenticateRequest(req, permissions)];
|
|
668
668
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FlinkResponse } from "./FlinkResponse";
|
|
2
|
-
export
|
|
2
|
+
export type FlinkError = undefined;
|
|
3
3
|
export declare function notFound(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
4
4
|
export declare function conflict(detail?: string, code?: string): FlinkResponse<FlinkError>;
|
|
5
5
|
export declare function badRequest(detail?: string, code?: string): FlinkResponse<FlinkError>;
|