@flink-app/flink 0.3.8 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.vscode/notes.txt +11 -0
  2. package/dist/bin/flink.js +2 -2
  3. package/dist/cli/build.js +3 -3
  4. package/dist/cli/clean.js +2 -2
  5. package/dist/cli/cli-utils.js +1 -1
  6. package/dist/cli/generate-schemas.js +20 -16
  7. package/dist/cli/run.js +2 -2
  8. package/dist/src/FlinkApp.d.ts +1 -1
  9. package/dist/src/FlinkApp.js +54 -50
  10. package/dist/src/FlinkErrors.d.ts +1 -1
  11. package/dist/src/FlinkErrors.js +5 -5
  12. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  13. package/dist/src/FlinkLog.js +5 -5
  14. package/dist/src/FlinkRepo.js +1 -1
  15. package/dist/src/FlinkResponse.d.ts +2 -2
  16. package/dist/src/FsUtils.js +4 -4
  17. package/dist/src/TypeScriptCompiler.js +67 -63
  18. package/dist/src/TypeScriptUtils.js +1 -1
  19. package/dist/src/index.js +5 -1
  20. package/dist/src/mock-data-generator.js +1 -1
  21. package/dist/src/utils.js +9 -9
  22. package/package.json +2 -2
  23. package/readme.md +14 -10
  24. package/spec/mock-project/dist/src/handlers/GetCar.js +59 -0
  25. package/spec/mock-project/dist/src/handlers/GetCar2.js +61 -0
  26. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +55 -0
  27. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +55 -0
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +55 -0
  29. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +57 -0
  30. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +57 -0
  31. package/{dist/cli/generate.js → spec/mock-project/dist/src/handlers/GetCarWithOmitSchema.js} +19 -14
  32. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +60 -0
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +60 -0
  34. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +56 -0
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +58 -0
  36. package/spec/mock-project/dist/src/handlers/PostCar.js +57 -0
  37. package/{dist/cli/generate-schema.js → spec/mock-project/dist/src/handlers/PostLogin.js} +18 -14
  38. package/spec/mock-project/dist/src/handlers/PutCar.js +57 -0
  39. package/spec/mock-project/dist/src/index.js +79 -0
  40. package/spec/mock-project/dist/src/repos/CarRepo.js +26 -0
  41. package/spec/mock-project/dist/src/schemas/Car.js +2 -0
  42. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +2 -0
  43. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +2 -0
  44. package/src/FlinkApp.ts +446 -510
  45. package/dist/cli/generate-schema.d.ts +0 -2
  46. package/dist/cli/generate.d.ts +0 -2
  47. package/dist/src/FlinkTsParser.d.ts +0 -2
  48. package/dist/src/FlinkTsParser.js +0 -219
  49. package/dist/src/FlinkTsUtils.d.ts +0 -16
  50. package/dist/src/FlinkTsUtils.js +0 -118
@@ -0,0 +1,11 @@
1
+ 1. Build time: Convert interfaces to JSON schemas
2
+
3
+
4
+ ./.flink/schemas
5
+
6
+ 2. Run time: Read JSON schemas from dir ./.flink/schemas/*.ts
7
+
8
+
9
+
10
+
11
+ flink prepare
package/dist/bin/flink.js CHANGED
@@ -12,11 +12,11 @@ var commands = [
12
12
  var argv = process.argv.slice(2);
13
13
  var argCommand = argv[0];
14
14
  if (!argCommand || argv[0] === "help") {
15
- console.log("Usage: flink [" + commands.join("|") + "]");
15
+ console.log("Usage: flink [".concat(commands.join("|"), "]"));
16
16
  process.exit();
17
17
  }
18
18
  if (!commands.includes(argv[0])) {
19
- console.log("Invalid command: " + argCommand);
19
+ console.log("Invalid command: ".concat(argCommand));
20
20
  process.exit(1);
21
21
  }
22
22
  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();
@@ -72,7 +72,7 @@ module.exports = function run(args) {
72
72
  ])];
73
73
  case 2:
74
74
  _a.sent();
75
- console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
75
+ console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
76
76
  compiler.emit();
77
77
  return [2 /*return*/];
78
78
  }
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 " + cleanedFolder);
61
+ console.log("Cleaned directory ".concat(cleanedFolder));
62
62
  return [2 /*return*/];
63
63
  }
64
64
  });
@@ -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 = "--" + name;
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;
@@ -26,7 +26,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
26
26
  function verb(n) { return function (v) { return step([n, v]); }; }
27
27
  function step(op) {
28
28
  if (f) throw new TypeError("Generator is already executing.");
29
- while (_) try {
29
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
30
  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;
31
31
  if (y = 0, t) op = [op[0] & 2, t.value];
32
32
  switch (op[0]) {
@@ -47,10 +47,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
48
  }
49
49
  };
50
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
51
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
52
- to[j] = from[i];
53
- return to;
50
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
51
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
52
+ if (ar || !(i in from)) {
53
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
54
+ ar[i] = from[i];
55
+ }
56
+ }
57
+ return to.concat(ar || Array.prototype.slice.call(from));
54
58
  };
55
59
  Object.defineProperty(exports, "__esModule", { value: true });
56
60
  var path_1 = require("path");
@@ -72,19 +76,19 @@ module.exports = function run(args) {
72
76
  if (args[0] && !args[0].startsWith("--")) {
73
77
  dir = args[0];
74
78
  }
75
- verbose = cli_utils_1.getOption(args, "verbose", false, {
79
+ verbose = (0, cli_utils_1.getOption)(args, "verbose", false, {
76
80
  isBoolean: true,
77
81
  });
78
- typesDir = cli_utils_1.getOption(args, "types-dir", "./src/schemas");
79
- outFile = cli_utils_1.getOption(args, "out-file", "./.flink/generated-schemas.json");
82
+ typesDir = (0, cli_utils_1.getOption)(args, "types-dir", "./src/schemas");
83
+ outFile = (0, cli_utils_1.getOption)(args, "out-file", "./.flink/generated-schemas.json");
80
84
  project = new ts_morph_1.Project({
81
- tsConfigFilePath: path_1.join(dir, "tsconfig.json"),
85
+ tsConfigFilePath: (0, path_1.join)(dir, "tsconfig.json"),
82
86
  skipAddingFilesFromTsConfig: true,
83
87
  compilerOptions: {
84
88
  noEmit: true,
85
89
  },
86
90
  });
87
- project.addSourceFilesAtPaths(path_1.join(dir, typesDir, "**/*.ts"));
91
+ project.addSourceFilesAtPaths((0, path_1.join)(dir, typesDir, "**/*.ts"));
88
92
  console.log("Found", project.getSourceFiles().length, "files");
89
93
  schemaDeclarations = [];
90
94
  generator = initJsonSchemaGenerator(project);
@@ -92,11 +96,11 @@ module.exports = function run(args) {
92
96
  for (_i = 0, _a = project.getSourceFiles(); _i < _a.length; _i++) {
93
97
  sf = _a[_i];
94
98
  if (sf.getDefaultExportSymbol()) {
95
- console.warn("WARN: Schema file " + sf.getBaseName() + " has default export, but only named exports are picked up by json schemas parser");
99
+ console.warn("WARN: Schema file ".concat(sf.getBaseName(), " has default export, but only named exports are picked up by json schemas parser"));
96
100
  }
97
101
  sourceFileInterfaceDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.InterfaceDeclaration);
98
102
  sourceFileEnumDeclarations = sf.getChildrenOfKind(ts_morph_1.SyntaxKind.EnumDeclaration);
99
- sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations), sourceFileInterfaceDeclarations);
103
+ sourceFileDeclarations = __spreadArray(__spreadArray([], sourceFileEnumDeclarations, true), sourceFileInterfaceDeclarations, true);
100
104
  schemaDeclarations.push.apply(schemaDeclarations, sourceFileDeclarations.map(function (d) { return d.compilerNode; }));
101
105
  verbose &&
102
106
  console.log("Found", sourceFileDeclarations.length, "schema(s) in file", sf.getBaseName());
@@ -120,8 +124,8 @@ module.exports = function run(args) {
120
124
  $ref: "#/definitions/Schemas",
121
125
  definitions: {},
122
126
  });
123
- file = path_1.join(dir, outFile);
124
- return [4 /*yield*/, FsUtils_1.writeJsonFile(file, mergedSchemas, {
127
+ file = (0, path_1.join)(dir, outFile);
128
+ return [4 /*yield*/, (0, FsUtils_1.writeJsonFile)(file, mergedSchemas, {
125
129
  ensureDir: true,
126
130
  })];
127
131
  case 1:
@@ -133,8 +137,8 @@ module.exports = function run(args) {
133
137
  });
134
138
  };
135
139
  function initJsonSchemaGenerator(project) {
136
- var formatter = ts_json_schema_generator_1.createFormatter({});
137
- var parser = ts_json_schema_generator_1.createParser(project.getProgram().compilerObject, {});
140
+ var formatter = (0, ts_json_schema_generator_1.createFormatter)({});
141
+ var parser = (0, ts_json_schema_generator_1.createParser)(project.getProgram().compilerObject, {});
138
142
  var generator = new ts_json_schema_generator_1.SchemaGenerator(project.getProgram().compilerObject, parser, formatter, { expose: "export" });
139
143
  return generator;
140
144
  }
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]) {
@@ -75,7 +75,7 @@ module.exports = function run(args) {
75
75
  ])];
76
76
  case 2:
77
77
  _a.sent();
78
- console.log("Compilation done, took " + (Date.now() - startTime) + "ms");
78
+ console.log("Compilation done, took ".concat(Date.now() - startTime, "ms"));
79
79
  compiler.emit();
80
80
  require("child_process").fork(dir + "/dist/.flink/start.js");
81
81
  return [2 /*return*/];
@@ -6,7 +6,7 @@ import { FlinkContext } from "./FlinkContext";
6
6
  import { HandlerFile, HttpMethod, QueryParamMetadata, RouteProps } from "./FlinkHttpHandler";
7
7
  import { FlinkPlugin } from "./FlinkPlugin";
8
8
  import { FlinkRepo } from "./FlinkRepo";
9
- export declare type JSONSchema = JSONSchema7;
9
+ export type JSONSchema = JSONSchema7;
10
10
  /**
11
11
  * This will be populated at compile time when the apps handlers
12
12
  * are picked up by typescript compiler
@@ -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]) {
@@ -63,7 +63,7 @@ var FlinkErrors_1 = require("./FlinkErrors");
63
63
  var mock_data_generator_1 = __importDefault(require("./mock-data-generator"));
64
64
  var utils_1 = require("./utils");
65
65
  var ajv = new ajv_1.default();
66
- ajv_formats_1.default(ajv);
66
+ (0, ajv_formats_1.default)(ajv);
67
67
  var defaultCorsOptions = {
68
68
  allowedHeaders: "",
69
69
  credentials: true,
@@ -125,24 +125,24 @@ var FlinkApp = /** @class */ (function () {
125
125
  _c.sent();
126
126
  if (this.debug) {
127
127
  offsetTime = Date.now();
128
- node_color_log_1.default.bgColorLog("cyan", "Init db took " + (offsetTime - startTime) + " ms");
128
+ node_color_log_1.default.bgColorLog("cyan", "Init db took ".concat(offsetTime - startTime, " ms"));
129
129
  }
130
130
  return [4 /*yield*/, this.buildContext()];
131
131
  case 2:
132
132
  _c.sent();
133
133
  if (this.debug) {
134
- node_color_log_1.default.bgColorLog("cyan", "Build context took " + (Date.now() - offsetTime) + " ms");
134
+ node_color_log_1.default.bgColorLog("cyan", "Build context took ".concat(Date.now() - offsetTime, " ms"));
135
135
  offsetTime = Date.now();
136
136
  }
137
137
  if (this.debug) {
138
- node_color_log_1.default.bgColorLog("cyan", "Registered JSON schemas took " + (Date.now() - offsetTime) + " ms");
138
+ node_color_log_1.default.bgColorLog("cyan", "Registered JSON schemas took ".concat(Date.now() - offsetTime, " ms"));
139
139
  offsetTime = Date.now();
140
140
  }
141
- this.expressApp = express_1.default();
142
- this.expressApp.use(cors_1.default(this.corsOpts));
141
+ this.expressApp = (0, express_1.default)();
142
+ this.expressApp.use((0, cors_1.default)(this.corsOpts));
143
143
  this.expressApp.use(body_parser_1.default.json());
144
144
  this.expressApp.use(function (req, res, next) {
145
- req.reqId = uuid_1.v4();
145
+ req.reqId = (0, uuid_1.v4)();
146
146
  next();
147
147
  });
148
148
  _i = 0, _b = this.plugins;
@@ -163,7 +163,7 @@ var FlinkApp = /** @class */ (function () {
163
163
  _c.sent();
164
164
  _c.label = 7;
165
165
  case 7:
166
- node_color_log_1.default.info("Initialized plugin '" + plugin.id + "'");
166
+ node_color_log_1.default.info("Initialized plugin '".concat(plugin.id, "'"));
167
167
  _c.label = 8;
168
168
  case 8:
169
169
  _i++;
@@ -172,19 +172,19 @@ var FlinkApp = /** @class */ (function () {
172
172
  case 10:
173
173
  _c.sent();
174
174
  if (this.debug) {
175
- node_color_log_1.default.bgColorLog("cyan", "Register handlers took " + (Date.now() - offsetTime) + " ms");
175
+ node_color_log_1.default.bgColorLog("cyan", "Register handlers took ".concat(Date.now() - offsetTime, " ms"));
176
176
  offsetTime = Date.now();
177
177
  }
178
178
  // Register 404 with slight delay to allow all manually added routes to be added
179
179
  // TODO: Is there a better solution to force this handler to always run last?
180
180
  setTimeout(function () {
181
181
  _this.expressApp.use(function (req, res, next) {
182
- res.status(404).json(FlinkErrors_1.notFound());
182
+ res.status(404).json((0, FlinkErrors_1.notFound)());
183
183
  });
184
184
  _this.routingConfigured = true;
185
185
  });
186
186
  (_a = this.expressApp) === null || _a === void 0 ? void 0 : _a.listen(this.port, function () {
187
- node_color_log_1.default.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '" + _this.name + "' is running and waiting for connections on " + _this.port);
187
+ node_color_log_1.default.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '".concat(_this.name, "' is running and waiting for connections on ").concat(_this.port));
188
188
  _this.started = true;
189
189
  });
190
190
  return [2 /*return*/, this];
@@ -205,21 +205,18 @@ var FlinkApp = /** @class */ (function () {
205
205
  }
206
206
  var routeProps = __assign(__assign({}, (handler.Route || {})), routePropsOverride);
207
207
  if (!routeProps.method) {
208
- node_color_log_1.default.error("Failed to register handler '" + handler.__file + "': Missing 'method' in route props, either set it or name handler file with HTTP method as prefix");
208
+ node_color_log_1.default.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"));
209
209
  return;
210
210
  }
211
211
  if (!routeProps.path) {
212
- node_color_log_1.default.error("Failed to register handler '" + handler.__file + "': Missing 'path' in route props");
212
+ node_color_log_1.default.error("Failed to register handler '".concat(handler.__file, "': Missing 'path' in route props"));
213
213
  return;
214
214
  }
215
- var dup = this.handlers.find(function (h) {
216
- return h.routeProps.path === routeProps.path &&
217
- h.routeProps.method === routeProps.method;
218
- });
219
- var methodAndPath = routeProps.method.toUpperCase() + " " + routeProps.path;
215
+ var dup = this.handlers.find(function (h) { return h.routeProps.path === routeProps.path && h.routeProps.method === routeProps.method; });
216
+ var methodAndPath = "".concat(routeProps.method.toUpperCase(), " ").concat(routeProps.path);
220
217
  if (dup) {
221
218
  // TODO: Not sure if there is a case where you'd want to overwrite a route?
222
- node_color_log_1.default.warn(methodAndPath + " overlaps existing route");
219
+ node_color_log_1.default.warn("".concat(methodAndPath, " overlaps existing route"));
223
220
  }
224
221
  var handlerConfig = {
225
222
  routeProps: __assign(__assign({}, routeProps), { method: routeProps.method, path: routeProps.path }),
@@ -231,10 +228,10 @@ var FlinkApp = /** @class */ (function () {
231
228
  paramsMetadata: handler.__params || [],
232
229
  };
233
230
  if (((_c = handler.__schemas) === null || _c === void 0 ? void 0 : _c.reqSchema) && !((_d = handlerConfig.schema) === null || _d === void 0 ? void 0 : _d.reqSchema)) {
234
- node_color_log_1.default.warn("Expected request schema " + handler.__schemas.reqSchema + " for handler " + methodAndPath + " but no such schema was found");
231
+ node_color_log_1.default.warn("Expected request schema ".concat(handler.__schemas.reqSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
235
232
  }
236
233
  if (((_e = handler.__schemas) === null || _e === void 0 ? void 0 : _e.resSchema) && !((_f = handlerConfig.schema) === null || _f === void 0 ? void 0 : _f.resSchema)) {
237
- node_color_log_1.default.warn("Expected response schema " + handler.__schemas.resSchema + " for handler " + methodAndPath + " but no such schema was found");
234
+ node_color_log_1.default.warn("Expected response schema ".concat(handler.__schemas.resSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
238
235
  }
239
236
  this.registerHandler(handlerConfig, handler.default);
240
237
  };
@@ -245,10 +242,10 @@ var FlinkApp = /** @class */ (function () {
245
242
  var method = routeProps.method;
246
243
  var app = this.expressApp;
247
244
  if (!method) {
248
- node_color_log_1.default.error("Route " + routeProps.path + " is missing http method");
245
+ node_color_log_1.default.error("Route ".concat(routeProps.path, " is missing http method"));
249
246
  }
250
247
  if (method) {
251
- var methodAndRoute_1 = method.toUpperCase() + " " + routeProps.path;
248
+ var methodAndRoute_1 = "".concat(method.toUpperCase(), " ").concat(routeProps.path);
252
249
  app[method](routeProps.path, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
253
250
  var validate, valid, data, handlerRes, err_1, validate, valid;
254
251
  return __generator(this, function (_a) {
@@ -258,7 +255,7 @@ var FlinkApp = /** @class */ (function () {
258
255
  return [4 /*yield*/, this.authenticate(req, routeProps.permissions)];
259
256
  case 1:
260
257
  if (!(_a.sent())) {
261
- return [2 /*return*/, res.status(401).json(FlinkErrors_1.unauthorized())];
258
+ return [2 /*return*/, res.status(401).json((0, FlinkErrors_1.unauthorized)())];
262
259
  }
263
260
  _a.label = 2;
264
261
  case 2:
@@ -266,21 +263,21 @@ var FlinkApp = /** @class */ (function () {
266
263
  validate = ajv.compile(schema.reqSchema);
267
264
  valid = validate(req.body);
268
265
  if (!valid) {
269
- node_color_log_1.default.warn(methodAndRoute_1 + ": Bad request " + JSON.stringify(validate.errors, null, 2));
270
- node_color_log_1.default.debug("Invalid json: " + JSON.stringify(req.body));
266
+ node_color_log_1.default.warn("".concat(methodAndRoute_1, ": Bad request ").concat(JSON.stringify(validate.errors, null, 2)));
267
+ node_color_log_1.default.debug("Invalid json: ".concat(JSON.stringify(req.body)));
271
268
  return [2 /*return*/, res.status(400).json({
272
269
  status: 400,
273
270
  error: {
274
- id: uuid_1.v4(),
271
+ id: (0, uuid_1.v4)(),
275
272
  title: "Bad request",
276
- detail: "Schema did not validate " + JSON.stringify(validate.errors),
273
+ detail: "Schema did not validate ".concat(JSON.stringify(validate.errors)),
277
274
  },
278
275
  })];
279
276
  }
280
277
  }
281
278
  if (routeProps.mockApi && schema.resSchema) {
282
- node_color_log_1.default.warn("Mock response for " + req.method.toUpperCase() + " " + req.path);
283
- data = mock_data_generator_1.default(schema.resSchema);
279
+ node_color_log_1.default.warn("Mock response for ".concat(req.method.toUpperCase(), " ").concat(req.path));
280
+ data = (0, mock_data_generator_1.default)(schema.resSchema);
284
281
  res.status(200).json({
285
282
  status: 200,
286
283
  data: data,
@@ -301,22 +298,23 @@ var FlinkApp = /** @class */ (function () {
301
298
  return [3 /*break*/, 6];
302
299
  case 5:
303
300
  err_1 = _a.sent();
304
- node_color_log_1.default.warn("Handler '" + methodAndRoute_1 + "' threw unhandled exception " + err_1);
305
- return [2 /*return*/, res.status(500).json(FlinkErrors_1.internalServerError(err_1))];
301
+ node_color_log_1.default.warn("Handler '".concat(methodAndRoute_1, "' threw unhandled exception ").concat(err_1));
302
+ console.error(err_1);
303
+ return [2 /*return*/, res.status(500).json((0, FlinkErrors_1.internalServerError)(err_1))];
306
304
  case 6:
307
- if (schema.resSchema && !utils_1.isError(handlerRes)) {
305
+ if (schema.resSchema && !(0, utils_1.isError)(handlerRes)) {
308
306
  validate = ajv.compile(schema.resSchema);
309
307
  valid = validate(JSON.parse(JSON.stringify(handlerRes.data)));
310
308
  if (!valid) {
311
- node_color_log_1.default.warn("[" + req.reqId + "] " + methodAndRoute_1 + ": Bad response " + JSON.stringify(validate.errors, null, 2));
312
- node_color_log_1.default.debug("Invalid json: " + JSON.stringify(handlerRes.data));
309
+ node_color_log_1.default.warn("[".concat(req.reqId, "] ").concat(methodAndRoute_1, ": Bad response ").concat(JSON.stringify(validate.errors, null, 2)));
310
+ node_color_log_1.default.debug("Invalid json: ".concat(JSON.stringify(handlerRes.data)));
313
311
  // log.debug(JSON.stringify(schema, null, 2));
314
312
  return [2 /*return*/, res.status(500).json({
315
313
  status: 500,
316
314
  error: {
317
- id: uuid_1.v4(),
315
+ id: (0, uuid_1.v4)(),
318
316
  title: "Bad response",
319
- detail: "Schema did not validate " + JSON.stringify(validate.errors),
317
+ detail: "Schema did not validate ".concat(JSON.stringify(validate.errors)),
320
318
  },
321
319
  })];
322
320
  }
@@ -328,12 +326,12 @@ var FlinkApp = /** @class */ (function () {
328
326
  });
329
327
  }); });
330
328
  if (this.handlerRouteCache.has(methodAndRoute_1)) {
331
- node_color_log_1.default.error("Cannot register handler " + methodAndRoute_1 + " - route already registered");
329
+ node_color_log_1.default.error("Cannot register handler ".concat(methodAndRoute_1, " - route already registered"));
332
330
  return process.exit(1); // TODO: Do we need to exit?
333
331
  }
334
332
  else {
335
333
  this.handlerRouteCache.set(methodAndRoute_1, JSON.stringify(routeProps));
336
- node_color_log_1.default.info("Registered route " + methodAndRoute_1);
334
+ node_color_log_1.default.info("Registered route ".concat(methodAndRoute_1));
337
335
  }
338
336
  }
339
337
  };
@@ -351,11 +349,11 @@ var FlinkApp = /** @class */ (function () {
351
349
  for (_i = 0, autoRegisteredHandlers_1 = exports.autoRegisteredHandlers; _i < autoRegisteredHandlers_1.length; _i++) {
352
350
  _c = autoRegisteredHandlers_1[_i], handler = _c.handler, assumedHttpMethod = _c.assumedHttpMethod;
353
351
  if (!handler.Route) {
354
- node_color_log_1.default.error("Missing Props in handler " + handler.__file);
352
+ node_color_log_1.default.error("Missing Props in handler ".concat(handler.__file));
355
353
  continue;
356
354
  }
357
355
  if (!handler.default) {
358
- node_color_log_1.default.error("Missing exported handler function in handler " + handler.__file);
356
+ node_color_log_1.default.error("Missing exported handler function in handler ".concat(handler.__file));
359
357
  continue;
360
358
  }
361
359
  this.registerHandler({
@@ -374,6 +372,8 @@ var FlinkApp = /** @class */ (function () {
374
372
  };
375
373
  FlinkApp.prototype.addRepo = function (instanceName, repoInstance) {
376
374
  this.repos[instanceName] = repoInstance;
375
+ // TODO: Find out if we need to set ctx here or wanted not to if plugin has its own context
376
+ // repoInstance.ctx = this.ctx;
377
377
  };
378
378
  /**
379
379
  * Constructs the app context. Will inject context in all components
@@ -381,14 +381,14 @@ var FlinkApp = /** @class */ (function () {
381
381
  */
382
382
  FlinkApp.prototype.buildContext = function () {
383
383
  return __awaiter(this, void 0, void 0, function () {
384
- var _i, autoRegisteredRepos_1, _a, collectionName, repoInstanceName, Repo, repoInstance, pluginCtx;
385
- return __generator(this, function (_b) {
384
+ var _i, autoRegisteredRepos_1, _a, collectionName, repoInstanceName, Repo, repoInstance, pluginCtx, _b, _c, repo;
385
+ return __generator(this, function (_d) {
386
386
  if (this.dbOpts) {
387
387
  for (_i = 0, autoRegisteredRepos_1 = exports.autoRegisteredRepos; _i < autoRegisteredRepos_1.length; _i++) {
388
388
  _a = autoRegisteredRepos_1[_i], collectionName = _a.collectionName, repoInstanceName = _a.repoInstanceName, Repo = _a.Repo;
389
389
  repoInstance = new Repo(collectionName, this.db);
390
390
  this.repos[repoInstanceName] = repoInstance;
391
- node_color_log_1.default.info("Registered repo " + repoInstanceName);
391
+ node_color_log_1.default.info("Registered repo ".concat(repoInstanceName));
392
392
  }
393
393
  }
394
394
  else if (exports.autoRegisteredRepos.length > 0) {
@@ -396,7 +396,7 @@ var FlinkApp = /** @class */ (function () {
396
396
  }
397
397
  pluginCtx = this.plugins.reduce(function (out, plugin) {
398
398
  if (out[plugin.id]) {
399
- throw new Error("Plugin " + plugin.id + " is already registered");
399
+ throw new Error("Plugin ".concat(plugin.id, " is already registered"));
400
400
  }
401
401
  out[plugin.id] = plugin.ctx;
402
402
  return out;
@@ -406,6 +406,10 @@ var FlinkApp = /** @class */ (function () {
406
406
  plugins: pluginCtx,
407
407
  auth: this.auth,
408
408
  };
409
+ for (_b = 0, _c = Object.values(this.repos); _b < _c.length; _b++) {
410
+ repo = _c[_b];
411
+ repo.ctx = this.ctx;
412
+ }
409
413
  return [2 /*return*/];
410
414
  });
411
415
  });
@@ -463,7 +467,7 @@ var FlinkApp = /** @class */ (function () {
463
467
  if (!plugin.db) return [3 /*break*/, 5];
464
468
  if (!plugin.db.useHostDb) return [3 /*break*/, 1];
465
469
  if (!this.db) {
466
- node_color_log_1.default.error("Plugin '" + this.name + " configured to use host app db, but no db exists in FlinkApp'");
470
+ node_color_log_1.default.error("Plugin '".concat(this.name, " configured to use host app db, but no db exists in FlinkApp'"));
467
471
  }
468
472
  else {
469
473
  return [2 /*return*/, this.db];
@@ -474,7 +478,7 @@ var FlinkApp = /** @class */ (function () {
474
478
  _a.label = 2;
475
479
  case 2:
476
480
  _a.trys.push([2, 4, , 5]);
477
- node_color_log_1.default.debug("Connecting to '" + plugin.id + "' db");
481
+ node_color_log_1.default.debug("Connecting to '".concat(plugin.id, "' db"));
478
482
  return [4 /*yield*/, mongodb_1.default.connect(plugin.db.uri, {
479
483
  useUnifiedTopology: true,
480
484
  })];
@@ -483,7 +487,7 @@ var FlinkApp = /** @class */ (function () {
483
487
  return [2 /*return*/, client.db()];
484
488
  case 4:
485
489
  err_3 = _a.sent();
486
- node_color_log_1.default.error("Failed to connect to db defined in plugin '" + plugin.id + "': " + err_3);
490
+ node_color_log_1.default.error("Failed to connect to db defined in plugin '".concat(plugin.id, "': ") + err_3);
487
491
  return [3 /*break*/, 5];
488
492
  case 5: return [2 /*return*/];
489
493
  }
@@ -496,7 +500,7 @@ var FlinkApp = /** @class */ (function () {
496
500
  switch (_a.label) {
497
501
  case 0:
498
502
  if (!this.auth) {
499
- throw new Error("Attempting to authenticate request (" + req.method + " " + req.path + ") but no authPlugin is set");
503
+ throw new Error("Attempting to authenticate request (".concat(req.method, " ").concat(req.path, ") but no authPlugin is set"));
500
504
  }
501
505
  return [4 /*yield*/, this.auth.authenticateRequest(req, permissions)];
502
506
  case 1: return [2 /*return*/, _a.sent()];
@@ -1,5 +1,5 @@
1
1
  import { FlinkResponse } from "./FlinkResponse";
2
- export declare type FlinkError = undefined;
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>;
@@ -6,7 +6,7 @@ function notFound(detail, code) {
6
6
  return {
7
7
  status: 404,
8
8
  error: {
9
- id: uuid_1.v4(),
9
+ id: (0, uuid_1.v4)(),
10
10
  title: "Not Found",
11
11
  detail: detail || "The requested resource does not exist",
12
12
  code: code || "notFound"
@@ -18,7 +18,7 @@ function conflict(detail, code) {
18
18
  return {
19
19
  status: 409,
20
20
  error: {
21
- id: uuid_1.v4(),
21
+ id: (0, uuid_1.v4)(),
22
22
  title: "Conflict",
23
23
  detail: detail || "An identical entity exits",
24
24
  code: code || "conflict"
@@ -30,7 +30,7 @@ function badRequest(detail, code) {
30
30
  return {
31
31
  status: 400,
32
32
  error: {
33
- id: uuid_1.v4(),
33
+ id: (0, uuid_1.v4)(),
34
34
  title: "Bad Request",
35
35
  detail: detail || "Invalid request",
36
36
  code: code || "badRequest"
@@ -42,7 +42,7 @@ function unauthorized(detail, code) {
42
42
  return {
43
43
  status: 401,
44
44
  error: {
45
- id: uuid_1.v4(),
45
+ id: (0, uuid_1.v4)(),
46
46
  title: "Unauthorized",
47
47
  detail: detail || "User not logged in or or not allowed to access resource",
48
48
  code: code || "badRequest"
@@ -54,7 +54,7 @@ function internalServerError(detail, code) {
54
54
  return {
55
55
  status: 500,
56
56
  error: {
57
- id: uuid_1.v4(),
57
+ id: (0, uuid_1.v4)(),
58
58
  title: "Internal Server Error",
59
59
  detail: detail || "Something unexpected went wrong",
60
60
  code: code || "internalServerError"
@@ -9,12 +9,12 @@ export declare enum HttpMethod {
9
9
  put = "put",
10
10
  delete = "delete"
11
11
  }
12
- declare type Params = Request["params"];
13
- declare type Query = Request["query"];
12
+ type Params = Request["params"];
13
+ type Query = Request["query"];
14
14
  /**
15
15
  * Flink request extends express Request but adds reqId and user object.
16
16
  */
17
- export declare type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
17
+ export type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
18
18
  reqId: string;
19
19
  user?: any;
20
20
  };
@@ -68,7 +68,7 @@ export interface RouteProps {
68
68
  * Http handler function that handlers implements in order to
69
69
  * handle HTTP requests and return a JSON response.
70
70
  */
71
- export declare type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema = any, P extends Params = Params, Q extends Query = Query> = (props: {
71
+ export type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema = any, P extends Params = Params, Q extends Query = Query> = (props: {
72
72
  req: FlinkRequest<ReqSchema, P, Q>;
73
73
  ctx: Ctx;
74
74
  origin?: string;
@@ -79,14 +79,14 @@ export declare type Handler<Ctx extends FlinkContext, ReqSchema = any, ResSchema
79
79
  *
80
80
  * Just syntactic sugar on top op `HandlerFn`
81
81
  */
82
- export declare type GetHandler<Ctx extends FlinkContext, ResSchema = any, P extends Params = Params, Q extends Query = Query> = Handler<Ctx, any, ResSchema, P, Q>;
82
+ export type GetHandler<Ctx extends FlinkContext, ResSchema = any, P extends Params = Params, Q extends Query = Query> = Handler<Ctx, any, ResSchema, P, Q>;
83
83
  /**
84
84
  * Type for Handler file. Describes shape of exports when using
85
85
  * syntax like:
86
86
  *
87
87
  * `import * as FooHandler from "./src/handlers/FooHandler"
88
88
  */
89
- export declare type HandlerFile = {
89
+ export type HandlerFile = {
90
90
  default: Handler<any, any, any, any, any>;
91
91
  Route?: RouteProps;
92
92
  /**
@@ -109,7 +109,7 @@ export declare type HandlerFile = {
109
109
  */
110
110
  __params?: QueryParamMetadata[];
111
111
  };
112
- export declare type QueryParamMetadata = {
112
+ export type QueryParamMetadata = {
113
113
  name: string;
114
114
  description: string;
115
115
  };