@stemy/backend 3.1.0 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,7 @@
33
33
  var Handlebars__namespace = /*#__PURE__*/_interopNamespace(Handlebars);
34
34
  var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
35
35
 
36
- /*! *****************************************************************************
36
+ /******************************************************************************
37
37
  Copyright (c) Microsoft Corporation.
38
38
 
39
39
  Permission to use, copy, modify, and/or distribute this software for any
@@ -195,7 +195,11 @@
195
195
  var __createBinding = Object.create ? (function (o, m, k, k2) {
196
196
  if (k2 === undefined)
197
197
  k2 = k;
198
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
198
+ var desc = Object.getOwnPropertyDescriptor(m, k);
199
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
200
+ desc = { enumerable: true, get: function () { return m[k]; } };
201
+ }
202
+ Object.defineProperty(o, k2, desc);
199
203
  }) : (function (o, m, k, k2) {
200
204
  if (k2 === undefined)
201
205
  k2 = k;
@@ -349,6 +353,11 @@
349
353
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
350
354
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
351
355
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
356
+ }
357
+ function __classPrivateFieldIn(state, receiver) {
358
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
359
+ throw new TypeError("Cannot use 'in' operator on non-object");
360
+ return typeof state === "function" ? receiver === state : state.has(receiver);
352
361
  }
353
362
 
354
363
  var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -455,6 +464,22 @@
455
464
  function lastItem(value) {
456
465
  return value[value.length - 1];
457
466
  }
467
+ function regroup(value, comparator) {
468
+ var result = [];
469
+ if (!isArray(value) || value.length == 0)
470
+ return result;
471
+ value = Array.from(value);
472
+ result.push([value.shift()]);
473
+ value.forEach(function (item) {
474
+ var group = result.find(function (g) { return g.some(function (a) { return comparator(a, item); }); });
475
+ if (group) {
476
+ group.push(item);
477
+ return;
478
+ }
479
+ result.push([item]);
480
+ });
481
+ return result;
482
+ }
458
483
  function getValue(obj, key, defaultValue, treeFallback) {
459
484
  if (treeFallback === void 0) { treeFallback = false; }
460
485
  key = key || "";
@@ -1099,7 +1124,6 @@
1099
1124
  falseColor: exports.ConsoleColor.FgRed,
1100
1125
  nullColor: exports.ConsoleColor.BgMagenta
1101
1126
  };
1102
- var MAX_TIMEOUT = 120000;
1103
1127
  function colorize(input, color) {
1104
1128
  return "" + color + input + exports.ConsoleColor.Reset;
1105
1129
  }
@@ -2402,6 +2426,7 @@
2402
2426
  }
2403
2427
  };
2404
2428
  this.processing = false;
2429
+ this.maxTimeout = this.config.resolve("jobTimeout");
2405
2430
  }
2406
2431
  JobManager.prototype.on = function (message, cb) {
2407
2432
  return this.messages
@@ -2493,7 +2518,7 @@
2493
2518
  _a.sent();
2494
2519
  console.log("Worker consumer connected to: " + pullHost);
2495
2520
  this.workerPull.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
2496
- var jobName, jobParams, timerId, jobNameLog, jobArgsLog, e_1, e_2;
2521
+ var jobName, jobParams, timerId, e_1, e_2;
2497
2522
  return __generator(this, function (_a) {
2498
2523
  switch (_a.label) {
2499
2524
  case 0:
@@ -2501,22 +2526,20 @@
2501
2526
  jobName = name.toString("utf8");
2502
2527
  jobParams = JSON.parse(args.toString("utf8"));
2503
2528
  timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
2504
- jobNameLog = "\u001B[36m\"" + jobName + "\"\u001B[0m";
2505
- jobArgsLog = "\n" + jsonHighlight(jobParams);
2506
2529
  console.time(timerId);
2507
- console.timeLog(timerId, "Started working on background job: " + jobNameLog + " with args: " + jobArgsLog + "\n\n");
2530
+ console.timeLog(timerId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
2508
2531
  this.messageBridge.sendMessage("job-started", { name: jobName });
2509
2532
  _a.label = 1;
2510
2533
  case 1:
2511
2534
  _a.trys.push([1, 3, , 4]);
2512
- return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(MAX_TIMEOUT, true)])];
2535
+ return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(this.maxTimeout, true)])];
2513
2536
  case 2:
2514
2537
  _a.sent();
2515
- console.timeLog(timerId, "Finished working on background job: " + jobNameLog + "\n\n");
2538
+ console.timeLog(timerId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
2516
2539
  return [3 /*break*/, 4];
2517
2540
  case 3:
2518
2541
  e_1 = _a.sent();
2519
- console.timeLog(timerId, "Background job failed: " + jobNameLog + "\n" + e_1.message + "\n\n");
2542
+ console.timeLog(timerId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
2520
2543
  return [3 /*break*/, 4];
2521
2544
  case 4:
2522
2545
  console.timeEnd(timerId);
@@ -3168,7 +3191,7 @@
3168
3191
  isFinished = progress.percent >= 100;
3169
3192
  }
3170
3193
  if (!!isFinished) return [3 /*break*/, 4];
3171
- if (waitTime >= MAX_TIMEOUT) {
3194
+ if (waitTime >= this.jobMan.maxTimeout) {
3172
3195
  throw new Error("Progress with id: " + id + " probably never will be finished!");
3173
3196
  }
3174
3197
  return [4 /*yield*/, promiseTimeout(delay)];
@@ -5914,7 +5937,7 @@
5914
5937
  new Parameter("mongoDb", "node-backend"),
5915
5938
  new Parameter("mongoUser", null),
5916
5939
  new Parameter("mongoPassword", null),
5917
- new Parameter("nodeEnv", "development"),
5940
+ new Parameter("nodeEnv", "production"),
5918
5941
  new Parameter("appPort", 80),
5919
5942
  new Parameter("zmqPort", 3000),
5920
5943
  new Parameter("zmqBackPort", 3100),
@@ -5926,6 +5949,7 @@
5926
5949
  new Parameter("idPrefix", "ID-"),
5927
5950
  new Parameter("idParts", [4, 4]),
5928
5951
  new Parameter("jsonLimit", "250mb"),
5952
+ new Parameter("jobTimeout", 5 * 60 * 1000),
5929
5953
  new Parameter("cacheCollection", "cache"),
5930
5954
  ];
5931
5955
  // Convert parameters to providers
@@ -6001,12 +6025,13 @@
6001
6025
  });
6002
6026
  restOptions = config.restOptions || {};
6003
6027
  restOptions.defaultErrorHandler = false;
6004
- restOptions.cors = {
6028
+ restOptions.cors = Object.assign({
6005
6029
  credentials: true,
6030
+ exposedHeaders: ["content-disposition"],
6006
6031
  origin: function (origin, callback) {
6007
6032
  callback(null, true);
6008
6033
  }
6009
- };
6034
+ }, restOptions.cors || {});
6010
6035
  restOptions.routePrefix = config.routePrefix || "/api";
6011
6036
  restOptions.routePrefix = restOptions.routePrefix == "/" ? "" : restOptions.routePrefix;
6012
6037
  restOptions.middlewares = [exports.ErrorHandlerMiddleware, ContainerMiddleware, exports.LanguageMiddleware, RequestStartedMiddleware, RequestEndedMiddleware]
@@ -6227,6 +6252,7 @@
6227
6252
  exports.random = random;
6228
6253
  exports.readAndDeleteFile = readAndDeleteFile;
6229
6254
  exports.readFile = readFile;
6255
+ exports.regroup = regroup;
6230
6256
  exports.runCommand = runCommand;
6231
6257
  exports.setupBackend = setupBackend;
6232
6258
  exports.streamToBuffer = streamToBuffer;