@flink-app/flink 0.12.1-alpha.0 → 0.12.1-alpha.10

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 (45) hide show
  1. package/bin/flink.ts +6 -13
  2. package/dist/bin/flink.js +3 -10
  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/run.js +2 -2
  7. package/dist/src/FlinkApp.d.ts +6 -3
  8. package/dist/src/FlinkApp.js +109 -78
  9. package/dist/src/FlinkErrors.d.ts +1 -1
  10. package/dist/src/FlinkErrors.js +5 -5
  11. package/dist/src/FlinkHttpHandler.d.ts +7 -7
  12. package/dist/src/FlinkHttpHandler.js +1 -1
  13. package/dist/src/FlinkJob.d.ts +2 -2
  14. package/dist/src/FlinkLog.d.ts +2 -2
  15. package/dist/src/FlinkRepo.d.ts +17 -8
  16. package/dist/src/FlinkRepo.js +44 -20
  17. package/dist/src/FlinkResponse.d.ts +2 -2
  18. package/dist/src/FsUtils.js +7 -7
  19. package/dist/src/TypeScriptCompiler.js +83 -68
  20. package/dist/src/TypeScriptUtils.js +11 -33
  21. package/dist/src/index.js +5 -1
  22. package/dist/src/mock-data-generator.js +1 -1
  23. package/dist/src/utils.js +6 -6
  24. package/package.json +7 -7
  25. package/spec/FlinkRepo.spec.ts +11 -0
  26. package/spec/mock-project/dist/src/handlers/GetCar.js +10 -12
  27. package/spec/mock-project/dist/src/handlers/GetCar2.js +11 -13
  28. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +8 -10
  29. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +8 -10
  30. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +8 -10
  31. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +10 -12
  32. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +10 -12
  33. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +10 -12
  34. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +10 -12
  35. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +10 -12
  36. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +10 -12
  37. package/spec/mock-project/dist/src/handlers/PostCar.js +10 -12
  38. package/spec/mock-project/dist/src/handlers/PostLogin.js +11 -13
  39. package/spec/mock-project/dist/src/handlers/PutCar.js +10 -12
  40. package/spec/mock-project/dist/src/index.js +6 -2
  41. package/src/FlinkApp.ts +33 -8
  42. package/src/FlinkRepo.ts +30 -11
  43. package/src/TypeScriptCompiler.ts +13 -2
  44. package/src/TypeScriptUtils.ts +110 -164
  45. package/cli/generate-schemas.ts +0 -153
@@ -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, _b, type, _c, _d, plugin, db;
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 " + (offsetTime - startTime) + " ms");
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 " + (Date.now() - offsetTime) + " ms");
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, _b = this.rawContentTypes; _i < _b.length; _i++) {
166
- type = _b[_i];
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
- _c = 0, _d = this.plugins;
179
+ _b = 0, _c = this.plugins;
180
180
  _e.label = 3;
181
181
  case 3:
182
- if (!(_c < _d.length)) return [3 /*break*/, 9];
183
- plugin = _d[_c];
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 '" + plugin.id + "'");
197
+ FlinkLog_1.log.info("Initialized plugin '".concat(plugin.id, "'"));
198
198
  _e.label = 8;
199
199
  case 8:
200
- _c++;
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 " + (Date.now() - offsetTime) + " ms");
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 " + (Date.now() - offsetTime) + " ms");
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
- (_a = this.expressApp) === null || _a === void 0 ? void 0 : _a.listen(this.port, function () {
235
- FlinkLog_1.log.fontColorLog("magenta", "\u26A1\uFE0F HTTP server '" + _this.name + "' is running and waiting for connections on " + _this.port);
234
+ this.expressServer = (_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
  }
@@ -241,6 +241,36 @@ var FlinkApp = /** @class */ (function () {
241
241
  });
242
242
  });
243
243
  };
244
+ FlinkApp.prototype.stop = function () {
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var _this = this;
247
+ return __generator(this, function (_a) {
248
+ switch (_a.label) {
249
+ case 0:
250
+ FlinkLog_1.log.info("🛑 Stopping Flink app...");
251
+ if (!this.scheduler) return [3 /*break*/, 2];
252
+ return [4 /*yield*/, this.scheduler.stop()];
253
+ case 1:
254
+ _a.sent();
255
+ _a.label = 2;
256
+ case 2:
257
+ if (this.expressServer) {
258
+ return [2 /*return*/, new Promise(function (resolve, reject) {
259
+ var int = setTimeout(function () {
260
+ reject("Failed to stop HTTP server in time");
261
+ }, 2000);
262
+ _this.expressServer.close(function () {
263
+ clearInterval(int);
264
+ FlinkLog_1.log.info("HTTP server stopped");
265
+ resolve();
266
+ });
267
+ })];
268
+ }
269
+ return [2 /*return*/];
270
+ }
271
+ });
272
+ });
273
+ };
244
274
  /**
245
275
  * Manually registers a handler.
246
276
  *
@@ -254,18 +284,18 @@ var FlinkApp = /** @class */ (function () {
254
284
  }
255
285
  var routeProps = __assign(__assign({}, (handler.Route || {})), routePropsOverride);
256
286
  if (!routeProps.method) {
257
- FlinkLog_1.log.error("Failed to register handler '" + handler.__file + "': Missing 'method' in route props, either set it or name handler file with HTTP method as prefix");
287
+ 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
288
  return;
259
289
  }
260
290
  if (!routeProps.path) {
261
- FlinkLog_1.log.error("Failed to register handler '" + handler.__file + "': Missing 'path' in route props");
291
+ FlinkLog_1.log.error("Failed to register handler '".concat(handler.__file, "': Missing 'path' in route props"));
262
292
  return;
263
293
  }
264
294
  var dup = this.handlers.find(function (h) { return h.routeProps.path === routeProps.path && h.routeProps.method === routeProps.method; });
265
- var methodAndPath = routeProps.method.toUpperCase() + " " + routeProps.path;
295
+ var methodAndPath = "".concat(routeProps.method.toUpperCase(), " ").concat(routeProps.path);
266
296
  if (dup) {
267
297
  // TODO: Not sure if there is a case where you'd want to overwrite a route?
268
- FlinkLog_1.log.warn(methodAndPath + " overlaps existing route");
298
+ FlinkLog_1.log.warn("".concat(methodAndPath, " overlaps existing route"));
269
299
  }
270
300
  var handlerConfig = {
271
301
  routeProps: __assign(__assign({}, routeProps), { method: routeProps.method, path: routeProps.path }),
@@ -277,10 +307,10 @@ var FlinkApp = /** @class */ (function () {
277
307
  paramsMetadata: handler.__params || [],
278
308
  };
279
309
  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 " + handler.__schemas.reqSchema + " for handler " + methodAndPath + " but no such schema was found");
310
+ FlinkLog_1.log.warn("Expected request schema ".concat(handler.__schemas.reqSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
281
311
  }
282
312
  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 " + handler.__schemas.resSchema + " for handler " + methodAndPath + " but no such schema was found");
313
+ FlinkLog_1.log.warn("Expected response schema ".concat(handler.__schemas.resSchema, " for handler ").concat(methodAndPath, " but no such schema was found"));
284
314
  }
285
315
  this.registerHandler(handlerConfig, handler.default);
286
316
  };
@@ -290,10 +320,10 @@ var FlinkApp = /** @class */ (function () {
290
320
  var routeProps = handlerConfig.routeProps, _a = handlerConfig.schema, schema = _a === void 0 ? {} : _a;
291
321
  var method = routeProps.method;
292
322
  if (!method) {
293
- FlinkLog_1.log.error("Route " + routeProps.path + " is missing http method");
323
+ FlinkLog_1.log.error("Route ".concat(routeProps.path, " is missing http method"));
294
324
  }
295
325
  if (method) {
296
- var methodAndRoute_1 = method.toUpperCase() + " " + routeProps.path;
326
+ var methodAndRoute_1 = "".concat(method.toUpperCase(), " ").concat(routeProps.path);
297
327
  if (this.disableHttpServer) {
298
328
  return;
299
329
  }
@@ -314,28 +344,28 @@ var FlinkApp = /** @class */ (function () {
314
344
  return [4 /*yield*/, this.authenticate(req, routeProps.permissions)];
315
345
  case 1:
316
346
  if (!(_a.sent())) {
317
- return [2 /*return*/, res.status(401).json(FlinkErrors_1.unauthorized())];
347
+ return [2 /*return*/, res.status(401).json((0, FlinkErrors_1.unauthorized)())];
318
348
  }
319
349
  _a.label = 2;
320
350
  case 2:
321
351
  if (validateReq_1) {
322
352
  valid = validateReq_1(req.body);
323
353
  if (!valid) {
324
- FlinkLog_1.log.warn(methodAndRoute_1 + ": Bad request " + JSON.stringify(validateReq_1.errors, null, 2));
325
- FlinkLog_1.log.debug("Invalid json: " + JSON.stringify(req.body));
354
+ FlinkLog_1.log.warn("".concat(methodAndRoute_1, ": Bad request ").concat(JSON.stringify(validateReq_1.errors, null, 2)));
355
+ FlinkLog_1.log.debug("Invalid json: ".concat(JSON.stringify(req.body)));
326
356
  return [2 /*return*/, res.status(400).json({
327
357
  status: 400,
328
358
  error: {
329
- id: uuid_1.v4(),
359
+ id: (0, uuid_1.v4)(),
330
360
  title: "Bad request",
331
- detail: "Schema did not validate " + JSON.stringify(validateReq_1.errors),
361
+ detail: "Schema did not validate ".concat(JSON.stringify(validateReq_1.errors)),
332
362
  },
333
363
  })];
334
364
  }
335
365
  }
336
366
  if (routeProps.mockApi && schema.resSchema) {
337
- FlinkLog_1.log.warn("Mock response for " + req.method.toUpperCase() + " " + req.path);
338
- data = mock_data_generator_1.default(schema.resSchema);
367
+ FlinkLog_1.log.warn("Mock response for ".concat(req.method.toUpperCase(), " ").concat(req.path));
368
+ data = (0, mock_data_generator_1.default)(schema.resSchema);
339
369
  res.status(200).json({
340
370
  status: 200,
341
371
  data: data,
@@ -361,29 +391,29 @@ var FlinkApp = /** @class */ (function () {
361
391
  return [2 /*return*/, res.status(err_1.status).json({
362
392
  status: err_1.status,
363
393
  error: {
364
- id: err_1.error.id || uuid_1.v4(),
365
- title: err_1.error.title || "Unhandled error: " + (err_1.error.code || err_1.status),
394
+ id: err_1.error.id || (0, uuid_1.v4)(),
395
+ title: err_1.error.title || "Unhandled error: ".concat(err_1.error.code || err_1.status),
366
396
  detail: err_1.error.detail,
367
397
  code: err_1.error.code,
368
398
  },
369
399
  })];
370
400
  }
371
- FlinkLog_1.log.warn("Handler '" + methodAndRoute_1 + "' threw unhandled exception " + err_1);
401
+ FlinkLog_1.log.warn("Handler '".concat(methodAndRoute_1, "' threw unhandled exception ").concat(err_1));
372
402
  console.error(err_1);
373
- return [2 /*return*/, res.status(500).json(FlinkErrors_1.internalServerError(err_1))];
403
+ return [2 /*return*/, res.status(500).json((0, FlinkErrors_1.internalServerError)(err_1))];
374
404
  case 6:
375
- if (validateRes_1 && !utils_1.isError(handlerRes)) {
405
+ if (validateRes_1 && !(0, utils_1.isError)(handlerRes)) {
376
406
  valid = validateRes_1(JSON.parse(JSON.stringify(handlerRes.data)));
377
407
  if (!valid) {
378
- FlinkLog_1.log.warn("[" + req.reqId + "] " + methodAndRoute_1 + ": Bad response " + JSON.stringify(validateRes_1.errors, null, 2));
379
- FlinkLog_1.log.debug("Invalid json: " + JSON.stringify(handlerRes.data));
408
+ FlinkLog_1.log.warn("[".concat(req.reqId, "] ").concat(methodAndRoute_1, ": Bad response ").concat(JSON.stringify(validateRes_1.errors, null, 2)));
409
+ FlinkLog_1.log.debug("Invalid json: ".concat(JSON.stringify(handlerRes.data)));
380
410
  // log.debug(JSON.stringify(schema, null, 2));
381
411
  return [2 /*return*/, res.status(500).json({
382
412
  status: 500,
383
413
  error: {
384
- id: uuid_1.v4(),
414
+ id: (0, uuid_1.v4)(),
385
415
  title: "Bad response",
386
- detail: "Schema did not validate " + JSON.stringify(validateRes_1.errors),
416
+ detail: "Schema did not validate ".concat(JSON.stringify(validateRes_1.errors)),
387
417
  },
388
418
  })];
389
419
  }
@@ -395,12 +425,12 @@ var FlinkApp = /** @class */ (function () {
395
425
  });
396
426
  }); });
397
427
  if (this.handlerRouteCache.has(methodAndRoute_1)) {
398
- FlinkLog_1.log.error("Cannot register handler " + methodAndRoute_1 + " - route already registered");
428
+ FlinkLog_1.log.error("Cannot register handler ".concat(methodAndRoute_1, " - route already registered"));
399
429
  return process.exit(1); // TODO: Do we need to exit?
400
430
  }
401
431
  else {
402
432
  this.handlerRouteCache.set(methodAndRoute_1, JSON.stringify(routeProps));
403
- FlinkLog_1.log.info("Registered route " + methodAndRoute_1);
433
+ FlinkLog_1.log.info("Registered route ".concat(methodAndRoute_1));
404
434
  }
405
435
  }
406
436
  };
@@ -411,38 +441,38 @@ var FlinkApp = /** @class */ (function () {
411
441
  * Will not register any handlers added programmatically.
412
442
  */
413
443
  FlinkApp.prototype.registerAutoRegisterableHandlers = function () {
414
- var _a, _b, _c;
415
444
  return __awaiter(this, void 0, void 0, function () {
416
- var _i, autoRegisteredHandlers_1, _d, handler, assumedHttpMethod, pathParams, _e, _f, param;
445
+ var _i, autoRegisteredHandlers_1, _a, handler, assumedHttpMethod, pathParams, _b, _c, param;
446
+ var _d, _e, _f;
417
447
  return __generator(this, function (_g) {
418
448
  for (_i = 0, autoRegisteredHandlers_1 = exports.autoRegisteredHandlers; _i < autoRegisteredHandlers_1.length; _i++) {
419
- _d = autoRegisteredHandlers_1[_i], handler = _d.handler, assumedHttpMethod = _d.assumedHttpMethod;
449
+ _a = autoRegisteredHandlers_1[_i], handler = _a.handler, assumedHttpMethod = _a.assumedHttpMethod;
420
450
  if (!handler.Route) {
421
- FlinkLog_1.log.error("Missing Props in handler " + handler.__file);
451
+ FlinkLog_1.log.error("Missing Props in handler ".concat(handler.__file));
422
452
  continue;
423
453
  }
424
454
  if (!handler.default) {
425
- FlinkLog_1.log.error("Missing exported handler function in handler " + handler.__file);
455
+ FlinkLog_1.log.error("Missing exported handler function in handler ".concat(handler.__file));
426
456
  continue;
427
457
  }
428
- if (!!((_a = handler.__params) === null || _a === void 0 ? void 0 : _a.length)) {
429
- pathParams = utils_1.getPathParams(handler.Route.path);
430
- for (_e = 0, _f = handler.__params; _e < _f.length; _e++) {
431
- param = _f[_e];
458
+ if (!!((_d = handler.__params) === null || _d === void 0 ? void 0 : _d.length)) {
459
+ pathParams = (0, utils_1.getPathParams)(handler.Route.path);
460
+ for (_b = 0, _c = handler.__params; _b < _c.length; _b++) {
461
+ param = _c[_b];
432
462
  if (!pathParams.includes(param.name)) {
433
- FlinkLog_1.log.error("Handler " + handler.__file + " has param " + param.name + " but it is not present in the path '" + handler.Route.path + "'");
463
+ 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
464
  throw new Error("Invalid/missing handler path param");
435
465
  }
436
466
  }
437
467
  if (pathParams.length !== handler.__params.length) {
438
- FlinkLog_1.log.warn("Handler " + handler.__file + " has " + handler.__params.length + " typed params but the path '" + handler.Route.path + "' has " + pathParams.length + " params");
468
+ 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
469
  }
440
470
  }
441
471
  this.registerHandler({
442
472
  routeProps: __assign(__assign({}, handler.Route), { method: handler.Route.method || assumedHttpMethod, origin: this.name }),
443
473
  schema: {
444
- reqSchema: (_b = handler.__schemas) === null || _b === void 0 ? void 0 : _b.reqSchema,
445
- resSchema: (_c = handler.__schemas) === null || _c === void 0 ? void 0 : _c.resSchema,
474
+ reqSchema: (_e = handler.__schemas) === null || _e === void 0 ? void 0 : _e.reqSchema,
475
+ resSchema: (_f = handler.__schemas) === null || _f === void 0 ? void 0 : _f.resSchema,
446
476
  },
447
477
  queryMetadata: handler.__query || [],
448
478
  paramsMetadata: handler.__params || [],
@@ -462,29 +492,29 @@ var FlinkApp = /** @class */ (function () {
462
492
  }
463
493
  _loop_1 = function (jobProps, jobFn, __file) {
464
494
  if (jobProps.cron && jobProps.interval) {
465
- FlinkLog_1.log.error("Cannot register job " + jobProps.id + " - both cron and interval are set in " + __file);
495
+ FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both cron and interval are set in ").concat(__file));
466
496
  return "continue";
467
497
  }
468
498
  if (jobProps.cron && jobProps.afterDelay) {
469
- FlinkLog_1.log.error("Cannot register job " + jobProps.id + " - both cron and afterDelay are set in " + __file);
499
+ FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both cron and afterDelay are set in ").concat(__file));
470
500
  return "continue";
471
501
  }
472
502
  if (jobProps.interval && jobProps.afterDelay) {
473
- FlinkLog_1.log.error("Cannot register job " + jobProps.id + " - both interval and afterDelay are set in " + __file);
503
+ FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - both interval and afterDelay are set in ").concat(__file));
474
504
  return "continue";
475
505
  }
476
506
  if (this_1.scheduler.existsById(jobProps.id)) {
477
- FlinkLog_1.log.error("Job with id " + jobProps.id + " is already registered, found duplicate in " + __file);
507
+ FlinkLog_1.log.error("Job with id ".concat(jobProps.id, " is already registered, found duplicate in ").concat(__file));
478
508
  return "continue";
479
509
  }
480
- FlinkLog_1.log.debug("Registering job " + jobProps.id + ": " + JSON.stringify(jobProps) + " from " + __file);
510
+ FlinkLog_1.log.debug("Registering job ".concat(jobProps.id, ": ").concat(JSON.stringify(jobProps), " from ").concat(__file));
481
511
  var task = new toad_scheduler_1.AsyncTask(jobProps.id, function () { return __awaiter(_this, void 0, void 0, function () {
482
512
  return __generator(this, function (_a) {
483
513
  switch (_a.label) {
484
514
  case 0: return [4 /*yield*/, jobFn({ ctx: this.ctx })];
485
515
  case 1:
486
516
  _a.sent();
487
- FlinkLog_1.log.debug("Job " + jobProps.id + " completed");
517
+ FlinkLog_1.log.debug("Job ".concat(jobProps.id, " completed"));
488
518
  if (jobProps.afterDelay) {
489
519
  // afterDelay runs only once, so we remove the job
490
520
  this.scheduler.removeById(jobProps.id);
@@ -493,7 +523,7 @@ var FlinkApp = /** @class */ (function () {
493
523
  }
494
524
  });
495
525
  }); }, function (err) {
496
- FlinkLog_1.log.error("Job " + jobProps.id + " threw unhandled exception " + err);
526
+ FlinkLog_1.log.error("Job ".concat(jobProps.id, " threw unhandled exception ").concat(err));
497
527
  console.error(err);
498
528
  });
499
529
  if (jobProps.cron) {
@@ -505,7 +535,7 @@ var FlinkApp = /** @class */ (function () {
505
535
  }
506
536
  else if (jobProps.interval) {
507
537
  var job = new toad_scheduler_1.SimpleIntervalJob({
508
- milliseconds: ms_1.default(jobProps.interval),
538
+ milliseconds: (0, ms_1.default)(jobProps.interval),
509
539
  runImmediately: false, // TODO: Expose to props?
510
540
  }, task, {
511
541
  id: jobProps.id,
@@ -515,7 +545,7 @@ var FlinkApp = /** @class */ (function () {
515
545
  }
516
546
  else if (jobProps.afterDelay !== undefined) {
517
547
  var job = new toad_scheduler_1.SimpleIntervalJob({
518
- milliseconds: ms_1.default(jobProps.afterDelay),
548
+ milliseconds: (0, ms_1.default)(jobProps.afterDelay),
519
549
  runImmediately: false,
520
550
  }, task, {
521
551
  id: jobProps.id,
@@ -524,7 +554,7 @@ var FlinkApp = /** @class */ (function () {
524
554
  this_1.scheduler.addSimpleIntervalJob(job);
525
555
  }
526
556
  else {
527
- FlinkLog_1.log.error("Cannot register job " + jobProps.id + " - no cron, interval or once set in " + __file);
557
+ FlinkLog_1.log.error("Cannot register job ".concat(jobProps.id, " - no cron, interval or once set in ").concat(__file));
528
558
  return "continue";
529
559
  }
530
560
  };
@@ -553,9 +583,9 @@ var FlinkApp = /** @class */ (function () {
553
583
  if (this.dbOpts) {
554
584
  for (_i = 0, autoRegisteredRepos_1 = exports.autoRegisteredRepos; _i < autoRegisteredRepos_1.length; _i++) {
555
585
  _a = autoRegisteredRepos_1[_i], collectionName = _a.collectionName, repoInstanceName = _a.repoInstanceName, Repo = _a.Repo;
556
- repoInstance = new Repo(collectionName, this.db);
586
+ repoInstance = new Repo(collectionName, this.db, this.dbClient);
557
587
  this.repos[repoInstanceName] = repoInstance;
558
- FlinkLog_1.log.info("Registered repo " + repoInstanceName);
588
+ FlinkLog_1.log.info("Registered repo ".concat(repoInstanceName));
559
589
  }
560
590
  }
561
591
  else if (exports.autoRegisteredRepos.length > 0) {
@@ -563,7 +593,7 @@ var FlinkApp = /** @class */ (function () {
563
593
  }
564
594
  pluginCtx = this.plugins.reduce(function (out, plugin) {
565
595
  if (out[plugin.id]) {
566
- throw new Error("Plugin " + plugin.id + " is already registered");
596
+ throw new Error("Plugin ".concat(plugin.id, " is already registered"));
567
597
  }
568
598
  out[plugin.id] = plugin.ctx;
569
599
  return out;
@@ -599,6 +629,7 @@ var FlinkApp = /** @class */ (function () {
599
629
  case 2:
600
630
  client = _a.sent();
601
631
  this.db = client.db();
632
+ this.dbClient = client;
602
633
  return [3 /*break*/, 4];
603
634
  case 3:
604
635
  err_2 = _a.sent();
@@ -631,7 +662,7 @@ var FlinkApp = /** @class */ (function () {
631
662
  if (!plugin.db) return [3 /*break*/, 5];
632
663
  if (!plugin.db.useHostDb) return [3 /*break*/, 1];
633
664
  if (!this.db) {
634
- FlinkLog_1.log.error("Plugin '" + this.name + " configured to use host app db, but no db exists in FlinkApp'");
665
+ FlinkLog_1.log.error("Plugin '".concat(this.name, " configured to use host app db, but no db exists in FlinkApp'"));
635
666
  }
636
667
  else {
637
668
  return [2 /*return*/, this.db];
@@ -642,14 +673,14 @@ var FlinkApp = /** @class */ (function () {
642
673
  _a.label = 2;
643
674
  case 2:
644
675
  _a.trys.push([2, 4, , 5]);
645
- FlinkLog_1.log.debug("Connecting to '" + plugin.id + "' db");
676
+ FlinkLog_1.log.debug("Connecting to '".concat(plugin.id, "' db"));
646
677
  return [4 /*yield*/, mongodb_1.MongoClient.connect(plugin.db.uri, this.getMongoConnectionOptions())];
647
678
  case 3:
648
679
  client = _a.sent();
649
680
  return [2 /*return*/, client.db()];
650
681
  case 4:
651
682
  err_3 = _a.sent();
652
- FlinkLog_1.log.error("Failed to connect to db defined in plugin '" + plugin.id + "': " + err_3);
683
+ FlinkLog_1.log.error("Failed to connect to db defined in plugin '".concat(plugin.id, "': ") + err_3);
653
684
  return [3 /*break*/, 5];
654
685
  case 5: return [2 /*return*/];
655
686
  }
@@ -662,7 +693,7 @@ var FlinkApp = /** @class */ (function () {
662
693
  switch (_a.label) {
663
694
  case 0:
664
695
  if (!this.auth) {
665
- throw new Error("Attempting to authenticate request (" + req.method + " " + req.path + ") but no authPlugin is set");
696
+ throw new Error("Attempting to authenticate request (".concat(req.method, " ").concat(req.path, ") but no authPlugin is set"));
666
697
  }
667
698
  return [4 /*yield*/, this.auth.authenticateRequest(req, permissions)];
668
699
  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
  };
@@ -7,4 +7,4 @@ var HttpMethod;
7
7
  HttpMethod["post"] = "post";
8
8
  HttpMethod["put"] = "put";
9
9
  HttpMethod["delete"] = "delete";
10
- })(HttpMethod = exports.HttpMethod || (exports.HttpMethod = {}));
10
+ })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
@@ -1,5 +1,5 @@
1
1
  import { FlinkContext } from "./FlinkContext";
2
- export declare type FlinkJobProps = {
2
+ export type FlinkJobProps = {
3
3
  /**
4
4
  * Id of job, must be unique
5
5
  */
@@ -48,7 +48,7 @@ export interface FlinkJob<C extends FlinkContext> {
48
48
  *
49
49
  * `import * as FooJob from "./src/jobs/FooJob"
50
50
  */
51
- export declare type FlinkJobFile = {
51
+ export type FlinkJobFile = {
52
52
  default: FlinkJob<any>;
53
53
  Job: FlinkJobProps;
54
54
  /**