@stemy/backend 3.1.2 → 3.1.5

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) {
@@ -2404,18 +2413,21 @@
2404
2413
  this.container = container;
2405
2414
  this.jobTypes = jobTypes || [];
2406
2415
  this.jobs = this.jobTypes.reduce(function (res, jobType) {
2407
- res[getConstructorName(jobType)] = function (jobParams) {
2408
- var job = _this.resolveJobInstance(jobType, jobParams);
2409
- return job.process(_this.messageBridge);
2416
+ var jobName = getConstructorName(jobType);
2417
+ res[jobName] = function (jobParams, uniqueId) {
2418
+ var job = _this.resolveJobInstance(jobType, jobParams, uniqueId);
2419
+ var messageBridge = {
2420
+ sendMessage: function (message, params) {
2421
+ params.uniqueId = uniqueId;
2422
+ _this.workerPush.send([message, JSON.stringify(params)]);
2423
+ }
2424
+ };
2425
+ messageBridge.sendMessage("job-started", { name: jobName });
2426
+ return job.process(messageBridge);
2410
2427
  };
2411
2428
  return res;
2412
2429
  }, {});
2413
2430
  this.messages = new rxjs.Subject();
2414
- this.messageBridge = {
2415
- sendMessage: function (message, params) {
2416
- _this.workerPush.send([message, JSON.stringify(params)]);
2417
- }
2418
- };
2419
2431
  this.processing = false;
2420
2432
  this.maxTimeout = this.config.resolve("jobTimeout");
2421
2433
  }
@@ -2508,32 +2520,31 @@
2508
2520
  case 2:
2509
2521
  _a.sent();
2510
2522
  console.log("Worker consumer connected to: " + pullHost);
2511
- this.workerPull.on("message", function (name, args, uniqueId) { return __awaiter$o(_this, void 0, void 0, function () {
2512
- var jobName, jobParams, timerId, e_1, e_2;
2523
+ this.workerPull.on("message", function (name, args, uniqId) { return __awaiter$o(_this, void 0, void 0, function () {
2524
+ var jobName, jobParams, uniqueId, e_1, e_2;
2513
2525
  return __generator(this, function (_a) {
2514
2526
  switch (_a.label) {
2515
2527
  case 0:
2516
2528
  _a.trys.push([0, 5, , 6]);
2517
2529
  jobName = name.toString("utf8");
2518
2530
  jobParams = JSON.parse(args.toString("utf8"));
2519
- timerId = uniqueId === null || uniqueId === void 0 ? void 0 : uniqueId.toString("utf8");
2520
- console.time(timerId);
2521
- console.timeLog(timerId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
2522
- this.messageBridge.sendMessage("job-started", { name: jobName });
2531
+ uniqueId = uniqId === null || uniqId === void 0 ? void 0 : uniqId.toString("utf8");
2532
+ console.time(uniqueId);
2533
+ console.timeLog(uniqueId, "Started working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + " with args: \n" + jsonHighlight(jobParams) + "\n\n");
2523
2534
  _a.label = 1;
2524
2535
  case 1:
2525
2536
  _a.trys.push([1, 3, , 4]);
2526
- return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams), promiseTimeout(this.maxTimeout, true)])];
2537
+ return [4 /*yield*/, Promise.race([this.jobs[jobName](jobParams, uniqueId), promiseTimeout(this.maxTimeout, true)])];
2527
2538
  case 2:
2528
2539
  _a.sent();
2529
- console.timeLog(timerId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
2540
+ console.timeLog(uniqueId, "Finished working on background job: " + colorize(jobName, exports.ConsoleColor.FgCyan) + "\n\n");
2530
2541
  return [3 /*break*/, 4];
2531
2542
  case 3:
2532
2543
  e_1 = _a.sent();
2533
- console.timeLog(timerId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
2544
+ console.timeLog(uniqueId, "Background job failed: " + colorize(jobName, exports.ConsoleColor.FgRed) + "\n" + e_1 + "\n\n");
2534
2545
  return [3 /*break*/, 4];
2535
2546
  case 4:
2536
- console.timeEnd(timerId);
2547
+ console.timeEnd(uniqueId);
2537
2548
  return [3 /*break*/, 6];
2538
2549
  case 5:
2539
2550
  e_2 = _a.sent();
@@ -2592,26 +2603,29 @@
2592
2603
  }
2593
2604
  return this.tryResolve(jobType, params);
2594
2605
  };
2595
- JobManager.prototype.resolveJobInstance = function (jobType, params) {
2606
+ JobManager.prototype.resolveJobInstance = function (jobType, params, uniqueId) {
2607
+ if (uniqueId === void 0) { uniqueId = null; }
2596
2608
  var container = this.container.createChildContainer();
2597
2609
  Object.keys(params).map(function (name) {
2598
2610
  container.register(name, { useValue: params[name] });
2599
2611
  });
2612
+ container.register("uniqueId", { useValue: uniqueId });
2600
2613
  container.register(jobType, jobType);
2601
2614
  return container.resolve(jobType);
2602
2615
  };
2603
2616
  JobManager.prototype.sendToWorkers = function (jobName, params) {
2604
2617
  return __awaiter$o(this, void 0, void 0, function () {
2605
- var publisher;
2618
+ var publisher, uniqueId;
2606
2619
  return __generator(this, function (_a) {
2607
2620
  switch (_a.label) {
2608
2621
  case 0: return [4 /*yield*/, this.apiPush];
2609
2622
  case 1:
2610
2623
  publisher = _a.sent();
2611
- return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), new bson.ObjectId().toHexString()])];
2624
+ uniqueId = new bson.ObjectId().toHexString();
2625
+ return [4 /*yield*/, publisher.send([jobName, JSON.stringify(params), uniqueId])];
2612
2626
  case 2:
2613
2627
  _a.sent();
2614
- return [2 /*return*/];
2628
+ return [2 /*return*/, uniqueId];
2615
2629
  }
2616
2630
  });
2617
2631
  });
@@ -6016,12 +6030,13 @@
6016
6030
  });
6017
6031
  restOptions = config.restOptions || {};
6018
6032
  restOptions.defaultErrorHandler = false;
6019
- restOptions.cors = {
6033
+ restOptions.cors = Object.assign({
6020
6034
  credentials: true,
6035
+ exposedHeaders: ["content-disposition"],
6021
6036
  origin: function (origin, callback) {
6022
6037
  callback(null, true);
6023
6038
  }
6024
- };
6039
+ }, restOptions.cors || {});
6025
6040
  restOptions.routePrefix = config.routePrefix || "/api";
6026
6041
  restOptions.routePrefix = restOptions.routePrefix == "/" ? "" : restOptions.routePrefix;
6027
6042
  restOptions.middlewares = [exports.ErrorHandlerMiddleware, ContainerMiddleware, exports.LanguageMiddleware, RequestStartedMiddleware, RequestEndedMiddleware]