@stemy/backend 2.7.4 → 2.8.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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-resque'), require('node-cron'), require('ioredis'), require('socket.io-client'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
3
3
  typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-resque', 'node-cron', 'ioredis', 'socket.io-client', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', 'bcrypt', 'moment'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global['body-parser'], global.jsonwebtoken, global.tsyringe, global['routing-controllers'], global['socket-controllers'], global['routing-controllers-openapi'], global['class-transformer/storage'], global['class-validator'], global['class-validator-jsonschema'], global.child_process, global.crypto, global.rxjs, global.rxjs['internal/util/canReportError'], global.fs, global.mongoose, global['mongoose-lib-utils'], global.stream, global.bson, global.fontkit, global['file-type'], global.sharp, global.axios, global.mongodb, global.dotenv, global['node-resque'], global['node-cron'], global.ioredis, global.socket['io-client'], global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
5
- }(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeResque, nodeCron, ioredis, socket_io_client, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-resque"], global["node-cron"], global.ioredis, global.socket["io-client"], global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
5
+ })(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeResque, nodeCron, ioredis, socket_io_client, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -15,14 +15,12 @@
15
15
  var d = Object.getOwnPropertyDescriptor(e, k);
16
16
  Object.defineProperty(n, k, d.get ? d : {
17
17
  enumerable: true,
18
- get: function () {
19
- return e[k];
20
- }
18
+ get: function () { return e[k]; }
21
19
  });
22
20
  }
23
21
  });
24
22
  }
25
- n['default'] = e;
23
+ n["default"] = e;
26
24
  return Object.freeze(n);
27
25
  }
28
26
 
@@ -108,7 +106,7 @@
108
106
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
109
107
  return Reflect.metadata(metadataKey, metadataValue);
110
108
  }
111
- function __awaiter$v(thisArg, _arguments, P, generator) {
109
+ function __awaiter$w(thisArg, _arguments, P, generator) {
112
110
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
113
111
  return new (P || (P = Promise))(function (resolve, reject) {
114
112
  function fulfilled(value) { try {
@@ -355,7 +353,7 @@
355
353
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
356
354
  }
357
355
 
358
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
356
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
359
357
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
360
358
  return new (P || (P = Promise))(function (resolve, reject) {
361
359
  function fulfilled(value) { try {
@@ -597,7 +595,7 @@
597
595
  }
598
596
  function paginateAggregations(model, aggregations, params, metaProjection) {
599
597
  if (metaProjection === void 0) { metaProjection = {}; }
600
- return __awaiter$u(this, void 0, void 0, function () {
598
+ return __awaiter$v(this, void 0, void 0, function () {
601
599
  var sortField, sortAggregation, result, pagination;
602
600
  var _a;
603
601
  return __generator(this, function (_b) {
@@ -708,7 +706,7 @@
708
706
  }
709
707
  function readAndDeleteFile(path, timeout) {
710
708
  if (timeout === void 0) { timeout = 5000; }
711
- return __awaiter$u(this, void 0, void 0, function () {
709
+ return __awaiter$v(this, void 0, void 0, function () {
712
710
  var data;
713
711
  return __generator(this, function (_a) {
714
712
  switch (_a.label) {
@@ -725,7 +723,7 @@
725
723
  });
726
724
  }
727
725
  function writeFile(path$1, data) {
728
- return __awaiter$u(this, void 0, void 0, function () {
726
+ return __awaiter$v(this, void 0, void 0, function () {
729
727
  return __generator(this, function (_a) {
730
728
  switch (_a.label) {
731
729
  case 0: return [4 /*yield*/, mkdirRecursive(path.dirname(path$1))];
@@ -813,7 +811,7 @@
813
811
  var paramName = modelName.toLowerCase();
814
812
  return routingControllers.createParamDecorator({
815
813
  required: false,
816
- value: function (action) { return __awaiter$u(_this, void 0, void 0, function () {
814
+ value: function (action) { return __awaiter$v(_this, void 0, void 0, function () {
817
815
  var req, token, id, query, doc, _a, _b, e_3;
818
816
  return __generator(this, function (_c) {
819
817
  switch (_c.label) {
@@ -1188,7 +1186,7 @@
1188
1186
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1189
1187
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1190
1188
  };
1191
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1189
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1192
1190
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1193
1191
  return new (P || (P = Promise))(function (resolve, reject) {
1194
1192
  function fulfilled(value) { try {
@@ -1208,8 +1206,8 @@
1208
1206
  });
1209
1207
  };
1210
1208
  var AssetProcessor_1;
1211
- var sharp$3 = sharp___default['default'];
1212
- var fontKit = fontKit___default['default'];
1209
+ var sharp$3 = sharp___default["default"];
1210
+ var fontKit = fontKit___default["default"];
1213
1211
  var fontTypes = [
1214
1212
  "application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
1215
1213
  "font/woff", "font/woff2", "font/otf", "font/ttf", "font/datafork"
@@ -1225,7 +1223,7 @@
1225
1223
  function AssetProcessor() {
1226
1224
  }
1227
1225
  AssetProcessor.getMimeType = function (buffer, mimeType) {
1228
- return __awaiter$t(this, void 0, void 0, function () {
1226
+ return __awaiter$u(this, void 0, void 0, function () {
1229
1227
  var e_1;
1230
1228
  return __generator(this, function (_a) {
1231
1229
  switch (_a.label) {
@@ -1266,7 +1264,7 @@
1266
1264
  return imageTypes.indexOf(contentType) >= 0;
1267
1265
  };
1268
1266
  AssetProcessor.copyImageMeta = function (buffer, metadata) {
1269
- return __awaiter$t(this, void 0, void 0, function () {
1267
+ return __awaiter$u(this, void 0, void 0, function () {
1270
1268
  var output;
1271
1269
  return __generator(this, function (_a) {
1272
1270
  switch (_a.label) {
@@ -1290,7 +1288,7 @@
1290
1288
  });
1291
1289
  };
1292
1290
  AssetProcessor.prototype.process = function (buffer, metadata, contentType) {
1293
- return __awaiter$t(this, void 0, void 0, function () {
1291
+ return __awaiter$u(this, void 0, void 0, function () {
1294
1292
  return __generator(this, function (_a) {
1295
1293
  switch (_a.label) {
1296
1294
  case 0:
@@ -1335,7 +1333,7 @@
1335
1333
  exports.Configuration = /** @class */ (function () {
1336
1334
  function Configuration(params) {
1337
1335
  var _this = this;
1338
- dotenv__default['default'].config();
1336
+ dotenv__default["default"].config();
1339
1337
  this.paramMap = {};
1340
1338
  (params || []).forEach(function (param) { return _this.add(param); });
1341
1339
  }
@@ -1357,9 +1355,11 @@
1357
1355
  }).replace(/\./gi, "_").replace(/^_/, "").toUpperCase();
1358
1356
  var envValue = process.env[envName];
1359
1357
  if (typeof envValue !== "undefined") {
1360
- return isFunction(param.resolver)
1358
+ var value = isFunction(param.resolver)
1361
1359
  ? param.resolver(envValue)
1362
1360
  : convertValue(envValue, getType(param.defaultValue));
1361
+ console.log("Processing param value", name, envName, envValue, value);
1362
+ return value;
1363
1363
  }
1364
1364
  return param.defaultValue;
1365
1365
  };
@@ -1386,7 +1386,7 @@
1386
1386
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
1387
1387
  return Reflect.metadata(k, v);
1388
1388
  };
1389
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1389
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1390
1390
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1391
1391
  return new (P || (P = Promise))(function (resolve, reject) {
1392
1392
  function fulfilled(value) { try {
@@ -1434,7 +1434,7 @@
1434
1434
  configurable: true
1435
1435
  });
1436
1436
  MongoConnector.prototype.connect = function () {
1437
- return __awaiter$s(this, void 0, void 0, function () {
1437
+ return __awaiter$t(this, void 0, void 0, function () {
1438
1438
  var _a;
1439
1439
  return __generator(this, function (_b) {
1440
1440
  switch (_b.label) {
@@ -1466,6 +1466,65 @@
1466
1466
  __metadata$o("design:paramtypes", [exports.Configuration])
1467
1467
  ], exports.MongoConnector);
1468
1468
 
1469
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1470
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1471
+ return new (P || (P = Promise))(function (resolve, reject) {
1472
+ function fulfilled(value) { try {
1473
+ step(generator.next(value));
1474
+ }
1475
+ catch (e) {
1476
+ reject(e);
1477
+ } }
1478
+ function rejected(value) { try {
1479
+ step(generator["throw"](value));
1480
+ }
1481
+ catch (e) {
1482
+ reject(e);
1483
+ } }
1484
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1485
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1486
+ });
1487
+ };
1488
+ var BaseEntity = /** @class */ (function () {
1489
+ function BaseEntity(mId, data, collection) {
1490
+ this.mId = mId;
1491
+ this.data = data;
1492
+ this.collection = collection;
1493
+ }
1494
+ Object.defineProperty(BaseEntity.prototype, "id", {
1495
+ get: function () {
1496
+ return this.mId.toHexString();
1497
+ },
1498
+ enumerable: false,
1499
+ configurable: true
1500
+ });
1501
+ BaseEntity.prototype.save = function () {
1502
+ return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1503
+ };
1504
+ BaseEntity.prototype.load = function () {
1505
+ return __awaiter$s(this, void 0, void 0, function () {
1506
+ var res;
1507
+ return __generator(this, function (_a) {
1508
+ switch (_a.label) {
1509
+ case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.mId })];
1510
+ case 1:
1511
+ res = _a.sent();
1512
+ this.deleted = !res;
1513
+ this.data = res || {};
1514
+ return [2 /*return*/, this];
1515
+ }
1516
+ });
1517
+ });
1518
+ };
1519
+ BaseEntity.prototype.toJSON = function () {
1520
+ var ret = Object.assign({}, this.data);
1521
+ delete ret._id;
1522
+ ret.id = this.id;
1523
+ return ret;
1524
+ };
1525
+ return BaseEntity;
1526
+ }());
1527
+
1469
1528
  var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1470
1529
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1471
1530
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1485,21 +1544,19 @@
1485
1544
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1486
1545
  });
1487
1546
  };
1488
- var sharp$2 = sharp___default['default'];
1547
+ var sharp$2 = sharp___default["default"];
1489
1548
  var cropInterface = {
1490
1549
  x: "number",
1491
1550
  y: "number",
1492
1551
  w: "number",
1493
1552
  h: "number"
1494
1553
  };
1495
- var Asset = /** @class */ (function () {
1496
- function Asset(fileId, filename, contentType, metadata, bucket, collection) {
1497
- this.fileId = fileId;
1498
- this.filename = filename;
1499
- this.contentType = contentType;
1500
- this.metadata = metadata;
1501
- this.bucket = bucket;
1502
- this.collection = collection;
1554
+ var Asset = /** @class */ (function (_super) {
1555
+ __extends(Asset, _super);
1556
+ function Asset(id, data, collection, bucket) {
1557
+ var _this = _super.call(this, id, data, collection) || this;
1558
+ _this.bucket = bucket;
1559
+ return _this;
1503
1560
  }
1504
1561
  Asset.toCropRegion = function (cropInfo) {
1505
1562
  var crop = cropInfo;
@@ -1614,16 +1671,30 @@
1614
1671
  });
1615
1672
  });
1616
1673
  };
1617
- Object.defineProperty(Asset.prototype, "id", {
1674
+ Object.defineProperty(Asset.prototype, "filename", {
1675
+ get: function () {
1676
+ return this.data.filename;
1677
+ },
1678
+ enumerable: false,
1679
+ configurable: true
1680
+ });
1681
+ Object.defineProperty(Asset.prototype, "contentType", {
1682
+ get: function () {
1683
+ return this.data.contentType;
1684
+ },
1685
+ enumerable: false,
1686
+ configurable: true
1687
+ });
1688
+ Object.defineProperty(Asset.prototype, "metadata", {
1618
1689
  get: function () {
1619
- return this.fileId.toHexString();
1690
+ return this.data.metadata;
1620
1691
  },
1621
1692
  enumerable: false,
1622
1693
  configurable: true
1623
1694
  });
1624
1695
  Object.defineProperty(Asset.prototype, "stream", {
1625
1696
  get: function () {
1626
- return this.bucket.openDownloadStream(this.fileId);
1697
+ return this.bucket.openDownloadStream(this.mId);
1627
1698
  },
1628
1699
  enumerable: false,
1629
1700
  configurable: true
@@ -1631,7 +1702,7 @@
1631
1702
  Asset.prototype.unlink = function () {
1632
1703
  return __awaiter$r(this, void 0, void 0, function () {
1633
1704
  return __generator(this, function (_a) {
1634
- return [2 /*return*/, deleteFromBucket(this.bucket, this.fileId)];
1705
+ return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
1635
1706
  });
1636
1707
  });
1637
1708
  };
@@ -1649,7 +1720,7 @@
1649
1720
  : metadata.downloadCount + 1;
1650
1721
  metadata.firstDownload = metadata.firstDownload || new Date();
1651
1722
  metadata.lastDownload = new Date();
1652
- return [4 /*yield*/, this.collection.updateOne({ _id: this.fileId }, { $set: { metadata: metadata } })];
1723
+ return [4 /*yield*/, this.collection.updateOne({ _id: this.mId }, { $set: { metadata: metadata } })];
1653
1724
  case 1:
1654
1725
  _a.sent();
1655
1726
  return [2 /*return*/, this.stream];
@@ -1678,16 +1749,8 @@
1678
1749
  });
1679
1750
  });
1680
1751
  };
1681
- Asset.prototype.toJSON = function () {
1682
- return {
1683
- id: this.id,
1684
- filename: this.filename,
1685
- contentType: this.contentType,
1686
- metadata: this.metadata
1687
- };
1688
- };
1689
1752
  return Asset;
1690
- }());
1753
+ }(BaseEntity));
1691
1754
 
1692
1755
  var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
1693
1756
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1775,8 +1838,12 @@
1775
1838
  reject(error.message || error);
1776
1839
  })
1777
1840
  .on("finish", function () {
1778
- var asset = new Asset(uploaderStream.id, metadata.filename, contentType, metadata, _this.bucket, _this.collection);
1779
- _this.collection.updateOne({ _id: uploaderStream.id }, { $set: asset.toJSON() }).then(function () {
1841
+ var asset = new Asset(uploaderStream.id, {
1842
+ filename: metadata.filename,
1843
+ contentType: contentType,
1844
+ metadata: metadata
1845
+ }, _this.collection, _this.bucket);
1846
+ asset.save().then(function () {
1780
1847
  resolve(asset);
1781
1848
  }, function (error) {
1782
1849
  reject(error.message || error);
@@ -1811,7 +1878,7 @@
1811
1878
  var buffer;
1812
1879
  return __generator(this, function (_b) {
1813
1880
  switch (_b.label) {
1814
- case 0: return [4 /*yield*/, axios__default['default']({ url: url, responseType: "arraybuffer" })];
1881
+ case 0: return [4 /*yield*/, axios__default["default"]({ url: url, responseType: "arraybuffer" })];
1815
1882
  case 1:
1816
1883
  buffer = (_b.sent()).data;
1817
1884
  return [2 /*return*/, this.writeBuffer(buffer, metadata)];
@@ -1834,7 +1901,39 @@
1834
1901
  case 0: return [4 /*yield*/, this.collection.findOne(where)];
1835
1902
  case 1:
1836
1903
  data = _b.sent();
1837
- return [2 /*return*/, !data ? null : new Asset(data._id, data.filename, data.contentType, data.metadata, this.bucket, this.collection)];
1904
+ return [2 /*return*/, !data ? null : new Asset(data._id, data, this.collection, this.bucket)];
1905
+ }
1906
+ });
1907
+ });
1908
+ };
1909
+ Assets.prototype.findMany = function (where) {
1910
+ return __awaiter$q(this, void 0, void 0, function () {
1911
+ var cursor, items, result, items_1, items_1_1, item;
1912
+ var e_2, _b;
1913
+ return __generator(this, function (_c) {
1914
+ switch (_c.label) {
1915
+ case 0:
1916
+ cursor = this.collection.find(where);
1917
+ return [4 /*yield*/, cursor.toArray()];
1918
+ case 1:
1919
+ items = (_c.sent()) || [];
1920
+ result = [];
1921
+ try {
1922
+ for (items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
1923
+ item = items_1_1.value;
1924
+ if (!item)
1925
+ continue;
1926
+ result.push(new Asset(item._id, item, this.collection, this.bucket));
1927
+ }
1928
+ }
1929
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1930
+ finally {
1931
+ try {
1932
+ if (items_1_1 && !items_1_1.done && (_b = items_1.return)) _b.call(items_1);
1933
+ }
1934
+ finally { if (e_2) throw e_2.error; }
1935
+ }
1936
+ return [2 /*return*/, result];
1838
1937
  }
1839
1938
  });
1840
1939
  });
@@ -1881,36 +1980,46 @@
1881
1980
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1882
1981
  });
1883
1982
  };
1884
- var LazyAsset = /** @class */ (function () {
1885
- function LazyAsset(lazyId, jobName, jobParams, jobQue, mProgressId, mAssetId, assets, progresses, jobMan, collection) {
1886
- this.lazyId = lazyId;
1887
- this.jobName = jobName;
1888
- this.jobParams = jobParams;
1889
- this.jobQue = jobQue;
1890
- this.mProgressId = mProgressId;
1891
- this.mAssetId = mAssetId;
1892
- this.assets = assets;
1893
- this.progresses = progresses;
1894
- this.jobMan = jobMan;
1895
- this.collection = collection;
1983
+ var LazyAsset = /** @class */ (function (_super) {
1984
+ __extends(LazyAsset, _super);
1985
+ function LazyAsset(id, data, collection, assets, progresses, jobMan) {
1986
+ var _this = _super.call(this, id, data, collection) || this;
1987
+ _this.assets = assets;
1988
+ _this.progresses = progresses;
1989
+ _this.jobMan = jobMan;
1990
+ return _this;
1896
1991
  }
1897
- Object.defineProperty(LazyAsset.prototype, "id", {
1992
+ Object.defineProperty(LazyAsset.prototype, "jobName", {
1898
1993
  get: function () {
1899
- return this.lazyId.toHexString();
1994
+ return this.data.jobName;
1995
+ },
1996
+ enumerable: false,
1997
+ configurable: true
1998
+ });
1999
+ Object.defineProperty(LazyAsset.prototype, "jobParams", {
2000
+ get: function () {
2001
+ return this.data.jobParams;
2002
+ },
2003
+ enumerable: false,
2004
+ configurable: true
2005
+ });
2006
+ Object.defineProperty(LazyAsset.prototype, "jobQue", {
2007
+ get: function () {
2008
+ return this.data.jobQue;
1900
2009
  },
1901
2010
  enumerable: false,
1902
2011
  configurable: true
1903
2012
  });
1904
2013
  Object.defineProperty(LazyAsset.prototype, "progressId", {
1905
2014
  get: function () {
1906
- return this.mProgressId;
2015
+ return this.data.progressId;
1907
2016
  },
1908
2017
  enumerable: false,
1909
2018
  configurable: true
1910
2019
  });
1911
2020
  Object.defineProperty(LazyAsset.prototype, "assetId", {
1912
2021
  get: function () {
1913
- return this.mAssetId;
2022
+ return this.data.assetId;
1914
2023
  },
1915
2024
  enumerable: false,
1916
2025
  configurable: true
@@ -1919,41 +2028,50 @@
1919
2028
  return __awaiter$p(this, void 0, void 0, function () {
1920
2029
  return __generator(this, function (_a) {
1921
2030
  switch (_a.label) {
1922
- case 0: return [4 /*yield*/, this.collection.deleteOne({ _id: this.lazyId })];
2031
+ case 0: return [4 /*yield*/, this.load()];
1923
2032
  case 1:
1924
2033
  _a.sent();
1925
- return [2 /*return*/, deleteFromBucket(this.assets.bucket, new bson.ObjectId(this.mAssetId))];
2034
+ if (!!this.progressId) return [3 /*break*/, 3];
2035
+ return [4 /*yield*/, this.collection.deleteOne({ _id: this.mId })];
2036
+ case 2:
2037
+ _a.sent();
2038
+ _a.label = 3;
2039
+ case 3: return [2 /*return*/, deleteFromBucket(this.assets.bucket, new bson.ObjectId(this.assetId))];
1926
2040
  }
1927
2041
  });
1928
2042
  });
1929
2043
  };
1930
2044
  LazyAsset.prototype.startWorking = function () {
1931
2045
  var _this = this;
1932
- if (this.mProgressId)
1933
- return;
1934
- this.startWorkingOnAsset().then(function () {
1935
- console.log("Started working on lazy asset: " + _this.id);
1936
- }).catch(function (reason) {
1937
- console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
2046
+ this.load().then(function () {
2047
+ if (_this.deleted)
2048
+ return;
2049
+ var progressPromise = !_this.progressId ? Promise.resolve(null) : _this.progresses.get(_this.progressId).then(function (p) { return p.cancel(); });
2050
+ progressPromise.then(function () {
2051
+ _this.startWorkingOnAsset().then(function () {
2052
+ console.log("Started working on lazy asset: " + _this.id);
2053
+ }).catch(function (reason) {
2054
+ console.log("Can't start working on lazy asset: " + _this.id + "\nReason: " + reason);
2055
+ });
2056
+ });
1938
2057
  });
1939
2058
  };
1940
2059
  LazyAsset.prototype.loadAsset = function () {
1941
2060
  return __awaiter$p(this, void 0, void 0, function () {
1942
- var data;
1943
2061
  return __generator(this, function (_a) {
1944
2062
  switch (_a.label) {
1945
- case 0:
1946
- if (this.mAssetId) {
1947
- return [2 /*return*/, this.assets.read(this.mAssetId)];
1948
- }
1949
- if (!this.mProgressId) return [3 /*break*/, 3];
1950
- return [4 /*yield*/, this.progresses.waitToFinish(this.mProgressId)];
2063
+ case 0: return [4 /*yield*/, this.load()];
1951
2064
  case 1:
1952
2065
  _a.sent();
1953
- return [4 /*yield*/, this.collection.findOne({ _id: this.lazyId })];
2066
+ if (this.deleted)
2067
+ return [2 /*return*/, null];
2068
+ if (this.assetId) {
2069
+ return [2 /*return*/, this.assets.read(this.assetId)];
2070
+ }
2071
+ if (!this.progressId) return [3 /*break*/, 3];
2072
+ return [4 /*yield*/, this.progresses.waitToFinish(this.progressId)];
1954
2073
  case 2:
1955
- data = _a.sent();
1956
- this.mAssetId = data.assetId;
2074
+ _a.sent();
1957
2075
  return [2 /*return*/, this.loadAsset()];
1958
2076
  case 3: return [4 /*yield*/, this.startWorkingOnAsset()];
1959
2077
  case 4:
@@ -1968,7 +2086,7 @@
1968
2086
  return __generator(this, function (_a) {
1969
2087
  switch (_a.label) {
1970
2088
  case 0:
1971
- this.mAssetId = asset.id;
2089
+ this.data.assetId = asset.id;
1972
2090
  return [4 /*yield*/, this.save()];
1973
2091
  case 1:
1974
2092
  _a.sent();
@@ -1977,32 +2095,19 @@
1977
2095
  });
1978
2096
  });
1979
2097
  };
1980
- LazyAsset.prototype.save = function () {
1981
- return this.collection.updateOne({ _id: this.lazyId }, { $set: this.toJSON() });
1982
- };
1983
- LazyAsset.prototype.toJSON = function () {
1984
- return {
1985
- id: this.id,
1986
- jobName: this.jobName,
1987
- jobParams: this.jobParams,
1988
- jobQue: this.jobQue,
1989
- progressId: this.progressId,
1990
- assetId: this.assetId,
1991
- };
1992
- };
1993
2098
  LazyAsset.prototype.startWorkingOnAsset = function () {
1994
2099
  return __awaiter$p(this, void 0, void 0, function () {
1995
- var progress;
2100
+ var id;
1996
2101
  return __generator(this, function (_a) {
1997
2102
  switch (_a.label) {
1998
2103
  case 0: return [4 /*yield*/, this.progresses.create()];
1999
2104
  case 1:
2000
- progress = _a.sent();
2001
- this.mProgressId = progress.id;
2105
+ id = (_a.sent()).id;
2106
+ this.data.progressId = id;
2002
2107
  return [4 /*yield*/, this.save()];
2003
2108
  case 2:
2004
2109
  _a.sent();
2005
- return [4 /*yield*/, this.jobMan.enqueueWithName(this.jobName, Object.assign(Object.assign({}, this.jobParams), { lazyId: this.id }))];
2110
+ return [4 /*yield*/, this.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, this.data.jobParams), { lazyId: this.id }))];
2006
2111
  case 3:
2007
2112
  _a.sent();
2008
2113
  return [2 /*return*/];
@@ -2011,7 +2116,7 @@
2011
2116
  });
2012
2117
  };
2013
2118
  return LazyAsset;
2014
- }());
2119
+ }(BaseEntity));
2015
2120
 
2016
2121
  var __decorate$s = (this && this.__decorate) || function (decorators, target, key, desc) {
2017
2122
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -2049,7 +2154,7 @@
2049
2154
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2050
2155
  });
2051
2156
  };
2052
- var IORedis = ioredis__default['default'];
2157
+ var IORedis = ioredis__default["default"];
2053
2158
  exports.JobManager = /** @class */ (function () {
2054
2159
  function JobManager(config, container, jobTypes) {
2055
2160
  var _this = this;
@@ -2322,61 +2427,58 @@
2322
2427
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2323
2428
  });
2324
2429
  };
2325
- var Progress = /** @class */ (function () {
2326
- function Progress(progressId, mCurrent, mMax, mMessage, mError, client, collection) {
2327
- this.progressId = progressId;
2328
- this.mCurrent = mCurrent;
2329
- this.mMax = mMax;
2330
- this.mMessage = mMessage;
2331
- this.mError = mError;
2332
- this.client = client;
2333
- this.collection = collection;
2430
+ var Progress = /** @class */ (function (_super) {
2431
+ __extends(Progress, _super);
2432
+ function Progress(id, data, collection, client) {
2433
+ var _this = _super.call(this, id, data, collection) || this;
2434
+ _this.client = client;
2435
+ return _this;
2334
2436
  }
2335
- Object.defineProperty(Progress.prototype, "id", {
2437
+ Object.defineProperty(Progress.prototype, "current", {
2336
2438
  get: function () {
2337
- return this.progressId.toHexString();
2439
+ return this.data.current;
2338
2440
  },
2339
2441
  enumerable: false,
2340
2442
  configurable: true
2341
2443
  });
2342
- Object.defineProperty(Progress.prototype, "current", {
2444
+ Object.defineProperty(Progress.prototype, "max", {
2343
2445
  get: function () {
2344
- return this.mCurrent;
2446
+ return this.data.max;
2345
2447
  },
2346
2448
  enumerable: false,
2347
2449
  configurable: true
2348
2450
  });
2349
- Object.defineProperty(Progress.prototype, "max", {
2451
+ Object.defineProperty(Progress.prototype, "message", {
2350
2452
  get: function () {
2351
- return this.mMax;
2453
+ return this.data.message;
2352
2454
  },
2353
2455
  enumerable: false,
2354
2456
  configurable: true
2355
2457
  });
2356
- Object.defineProperty(Progress.prototype, "message", {
2458
+ Object.defineProperty(Progress.prototype, "error", {
2357
2459
  get: function () {
2358
- return this.mMessage;
2460
+ return this.data.error;
2359
2461
  },
2360
2462
  enumerable: false,
2361
2463
  configurable: true
2362
2464
  });
2363
- Object.defineProperty(Progress.prototype, "error", {
2465
+ Object.defineProperty(Progress.prototype, "canceled", {
2364
2466
  get: function () {
2365
- return this.mError;
2467
+ return this.data.canceled;
2366
2468
  },
2367
2469
  enumerable: false,
2368
2470
  configurable: true
2369
2471
  });
2370
2472
  Object.defineProperty(Progress.prototype, "percent", {
2371
2473
  get: function () {
2372
- return this.mMax > 0 ? Math.round(this.mCurrent / this.mMax * 100) : 0;
2474
+ return this.max > 0 ? Math.round(this.current / this.max * 100) : 0;
2373
2475
  },
2374
2476
  enumerable: false,
2375
2477
  configurable: true
2376
2478
  });
2377
2479
  Object.defineProperty(Progress.prototype, "remaining", {
2378
2480
  get: function () {
2379
- return this.mMax > 0 ? this.mMax - this.mCurrent : 0;
2481
+ return this.max > 0 ? this.max - this.current : 0;
2380
2482
  },
2381
2483
  enumerable: false,
2382
2484
  configurable: true
@@ -2393,12 +2495,12 @@
2393
2495
  _a.label = 2;
2394
2496
  case 2:
2395
2497
  if (!(message !== null)) return [3 /*break*/, 4];
2396
- this.mMessage = message;
2498
+ this.data.message = message;
2397
2499
  return [4 /*yield*/, this.save()];
2398
2500
  case 3:
2399
2501
  _a.sent();
2400
2502
  _a.label = 4;
2401
- case 4: return [2 /*return*/, new SubProgress(this, this.mCurrent, progressValue, Math.max(max, 1))];
2503
+ case 4: return [2 /*return*/, new SubProgress(this, this.current, progressValue, Math.max(max, 1))];
2402
2504
  }
2403
2505
  });
2404
2506
  });
@@ -2411,7 +2513,21 @@
2411
2513
  if (isNaN(max) || max <= 0) {
2412
2514
  throw "Max progress value must be bigger than zero";
2413
2515
  }
2414
- this.mMax = max;
2516
+ this.data.max = max;
2517
+ return [4 /*yield*/, this.save()];
2518
+ case 1:
2519
+ _a.sent();
2520
+ return [2 /*return*/];
2521
+ }
2522
+ });
2523
+ });
2524
+ };
2525
+ Progress.prototype.setMessage = function (message) {
2526
+ return __awaiter$n(this, void 0, void 0, function () {
2527
+ return __generator(this, function (_a) {
2528
+ switch (_a.label) {
2529
+ case 0:
2530
+ this.data.message = message;
2415
2531
  return [4 /*yield*/, this.save()];
2416
2532
  case 1:
2417
2533
  _a.sent();
@@ -2425,7 +2541,7 @@
2425
2541
  return __generator(this, function (_a) {
2426
2542
  switch (_a.label) {
2427
2543
  case 0:
2428
- this.mError = error;
2544
+ this.data.error = error;
2429
2545
  return [4 /*yield*/, this.save()];
2430
2546
  case 1:
2431
2547
  _a.sent();
@@ -2443,9 +2559,14 @@
2443
2559
  if (isNaN(value) || value <= 0) {
2444
2560
  throw "Advance value must be bigger than zero";
2445
2561
  }
2446
- this.mCurrent = Math.min(this.mMax, this.mCurrent + value);
2447
- return [4 /*yield*/, this.save()];
2562
+ return [4 /*yield*/, this.load()];
2448
2563
  case 1:
2564
+ _a.sent();
2565
+ if (this.deleted || this.canceled)
2566
+ return [2 /*return*/, null];
2567
+ this.data.current = Math.min(this.max, this.current + value);
2568
+ return [4 /*yield*/, this.save()];
2569
+ case 2:
2449
2570
  _a.sent();
2450
2571
  if (!this.client)
2451
2572
  return [2 /*return*/];
@@ -2455,34 +2576,36 @@
2455
2576
  });
2456
2577
  });
2457
2578
  };
2458
- Progress.prototype.toJSON = function () {
2459
- return {
2460
- id: this.id,
2461
- current: this.current,
2462
- max: this.max,
2463
- message: this.message,
2464
- error: this.error
2465
- };
2466
- };
2467
- Progress.prototype.save = function () {
2468
- return this.collection.updateOne({ _id: this.progressId }, { $set: this.toJSON() });
2579
+ Progress.prototype.cancel = function () {
2580
+ return __awaiter$n(this, void 0, void 0, function () {
2581
+ return __generator(this, function (_a) {
2582
+ switch (_a.label) {
2583
+ case 0:
2584
+ this.data.canceled = true;
2585
+ return [4 /*yield*/, this.save()];
2586
+ case 1:
2587
+ _a.sent();
2588
+ return [2 /*return*/];
2589
+ }
2590
+ });
2591
+ });
2469
2592
  };
2470
2593
  return Progress;
2471
- }());
2594
+ }(BaseEntity));
2472
2595
  var SubProgress = /** @class */ (function () {
2473
- function SubProgress(parent, progressFrom, progressValue, max) {
2474
- if (max === void 0) { max = 100; }
2596
+ function SubProgress(parent, progressFrom, progressValue, mMax) {
2597
+ if (mMax === void 0) { mMax = 100; }
2475
2598
  this.parent = parent;
2476
2599
  this.progressFrom = progressFrom;
2477
2600
  this.progressValue = progressValue;
2478
- this.max = max;
2601
+ this.mMax = mMax;
2479
2602
  if (progressFrom < 0) {
2480
2603
  throw "Progress from must be bigger than or zero";
2481
2604
  }
2482
2605
  if (progressValue <= 0) {
2483
2606
  throw "Progress value must be bigger than zero";
2484
2607
  }
2485
- this.currentValue = 0;
2608
+ this.mCurrent = 0;
2486
2609
  }
2487
2610
  Object.defineProperty(SubProgress.prototype, "id", {
2488
2611
  get: function () {
@@ -2491,13 +2614,24 @@
2491
2614
  enumerable: false,
2492
2615
  configurable: true
2493
2616
  });
2617
+ Object.defineProperty(SubProgress.prototype, "current", {
2618
+ get: function () {
2619
+ return this.mCurrent;
2620
+ },
2621
+ enumerable: false,
2622
+ configurable: true
2623
+ });
2624
+ Object.defineProperty(SubProgress.prototype, "max", {
2625
+ get: function () {
2626
+ return this.mMax;
2627
+ },
2628
+ enumerable: false,
2629
+ configurable: true
2630
+ });
2494
2631
  Object.defineProperty(SubProgress.prototype, "message", {
2495
2632
  get: function () {
2496
2633
  return this.parent.message;
2497
2634
  },
2498
- set: function (value) {
2499
- this.parent.message = value;
2500
- },
2501
2635
  enumerable: false,
2502
2636
  configurable: true
2503
2637
  });
@@ -2505,9 +2639,6 @@
2505
2639
  get: function () {
2506
2640
  return this.parent.error;
2507
2641
  },
2508
- set: function (value) {
2509
- this.parent.error = value;
2510
- },
2511
2642
  enumerable: false,
2512
2643
  configurable: true
2513
2644
  });
@@ -2518,16 +2649,16 @@
2518
2649
  enumerable: false,
2519
2650
  configurable: true
2520
2651
  });
2521
- Object.defineProperty(SubProgress.prototype, "current", {
2652
+ Object.defineProperty(SubProgress.prototype, "remaining", {
2522
2653
  get: function () {
2523
- return this.currentValue;
2654
+ return this.max - this.mCurrent;
2524
2655
  },
2525
2656
  enumerable: false,
2526
2657
  configurable: true
2527
2658
  });
2528
- Object.defineProperty(SubProgress.prototype, "remaining", {
2659
+ Object.defineProperty(SubProgress.prototype, "canceled", {
2529
2660
  get: function () {
2530
- return this.max - this.currentValue;
2661
+ return !this.parent || this.parent.canceled;
2531
2662
  },
2532
2663
  enumerable: false,
2533
2664
  configurable: true
@@ -2544,8 +2675,7 @@
2544
2675
  _a.label = 2;
2545
2676
  case 2:
2546
2677
  if (!(message !== null)) return [3 /*break*/, 4];
2547
- this.message = message;
2548
- return [4 /*yield*/, this.parent.save()];
2678
+ return [4 /*yield*/, this.setMessage(message)];
2549
2679
  case 3:
2550
2680
  _a.sent();
2551
2681
  _a.label = 4;
@@ -2562,7 +2692,7 @@
2562
2692
  if (isNaN(max) || max <= 0) {
2563
2693
  throw "Max progress value must be bigger than zero";
2564
2694
  }
2565
- this.max = max;
2695
+ this.mMax = max;
2566
2696
  return [4 /*yield*/, this.save()];
2567
2697
  case 1:
2568
2698
  _a.sent();
@@ -2571,13 +2701,29 @@
2571
2701
  });
2572
2702
  });
2573
2703
  };
2704
+ SubProgress.prototype.setMessage = function (message) {
2705
+ return __awaiter$n(this, void 0, void 0, function () {
2706
+ return __generator(this, function (_a) {
2707
+ switch (_a.label) {
2708
+ case 0:
2709
+ if (!this.parent)
2710
+ return [2 /*return*/, null];
2711
+ return [4 /*yield*/, this.parent.setMessage(message)];
2712
+ case 1:
2713
+ _a.sent();
2714
+ return [2 /*return*/];
2715
+ }
2716
+ });
2717
+ });
2718
+ };
2574
2719
  SubProgress.prototype.setError = function (error) {
2575
2720
  return __awaiter$n(this, void 0, void 0, function () {
2576
2721
  return __generator(this, function (_a) {
2577
2722
  switch (_a.label) {
2578
2723
  case 0:
2579
- this.error = error || null;
2580
- return [4 /*yield*/, this.save()];
2724
+ if (!this.parent)
2725
+ return [2 /*return*/, null];
2726
+ return [4 /*yield*/, this.parent.setError(error)];
2581
2727
  case 1:
2582
2728
  _a.sent();
2583
2729
  return [2 /*return*/];
@@ -2594,7 +2740,7 @@
2594
2740
  if (isNaN(value) || value <= 0) {
2595
2741
  throw "Advance value must be bigger than zero";
2596
2742
  }
2597
- this.currentValue = Math.min(this.max, this.currentValue + value);
2743
+ this.mCurrent = Math.min(this.max, this.mCurrent + value);
2598
2744
  return [4 /*yield*/, this.save()];
2599
2745
  case 1:
2600
2746
  _a.sent();
@@ -2603,13 +2749,28 @@
2603
2749
  });
2604
2750
  });
2605
2751
  };
2752
+ SubProgress.prototype.cancel = function () {
2753
+ return __awaiter$n(this, void 0, void 0, function () {
2754
+ return __generator(this, function (_a) {
2755
+ switch (_a.label) {
2756
+ case 0:
2757
+ if (!this.parent)
2758
+ return [2 /*return*/, null];
2759
+ return [4 /*yield*/, this.parent.cancel()];
2760
+ case 1:
2761
+ _a.sent();
2762
+ return [2 /*return*/];
2763
+ }
2764
+ });
2765
+ });
2766
+ };
2606
2767
  SubProgress.prototype.save = function () {
2607
2768
  return __awaiter$n(this, void 0, void 0, function () {
2608
2769
  var ratio, newProgress, current;
2609
2770
  return __generator(this, function (_a) {
2610
2771
  switch (_a.label) {
2611
2772
  case 0:
2612
- ratio = this.max > 0 ? this.currentValue / this.max : 0;
2773
+ ratio = this.max > 0 ? this.mCurrent / this.max : 0;
2613
2774
  newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
2614
2775
  current = this.parent.current;
2615
2776
  if (newProgress <= current)
@@ -2622,6 +2783,13 @@
2622
2783
  });
2623
2784
  });
2624
2785
  };
2786
+ SubProgress.prototype.load = function () {
2787
+ return __awaiter$n(this, void 0, void 0, function () {
2788
+ return __generator(this, function (_a) {
2789
+ return [2 /*return*/, null];
2790
+ });
2791
+ });
2792
+ };
2625
2793
  SubProgress.prototype.toJSON = function () {
2626
2794
  return this.parent.toJSON();
2627
2795
  };
@@ -2661,7 +2829,7 @@
2661
2829
  step((generator = generator.apply(thisArg, _arguments || [])).next());
2662
2830
  });
2663
2831
  };
2664
- var socketIOClient = socket_io_client__default['default'];
2832
+ var socketIOClient = socket_io_client__default["default"];
2665
2833
  exports.Progresses = /** @class */ (function () {
2666
2834
  function Progresses(connector, config) {
2667
2835
  this.connector = connector;
@@ -2717,7 +2885,7 @@
2717
2885
  case 0: return [4 /*yield*/, this.collection.findOne(where)];
2718
2886
  case 1:
2719
2887
  data = _a.sent();
2720
- return [2 /*return*/, !data ? null : new Progress(data._id, data.current, data.max, data.message, data.error, this.client, this.collection)];
2888
+ return [2 /*return*/, !data ? null : new Progress(data._id, data, this.collection, this.client)];
2721
2889
  }
2722
2890
  });
2723
2891
  });
@@ -2725,20 +2893,24 @@
2725
2893
  Progresses.prototype.create = function (max) {
2726
2894
  if (max === void 0) { max = 100; }
2727
2895
  return __awaiter$m(this, void 0, void 0, function () {
2728
- var res;
2896
+ var data, res;
2729
2897
  return __generator(this, function (_a) {
2730
2898
  switch (_a.label) {
2731
2899
  case 0:
2732
2900
  if (isNaN(max) || max <= 0) {
2733
2901
  throw "Max progress value must be bigger than zero";
2734
2902
  }
2735
- return [4 /*yield*/, this.collection.insertOne({
2736
- current: 0,
2737
- max: max
2738
- })];
2903
+ data = {
2904
+ current: 0,
2905
+ max: max,
2906
+ message: "",
2907
+ error: "",
2908
+ canceled: false
2909
+ };
2910
+ return [4 /*yield*/, this.collection.insertOne(data)];
2739
2911
  case 1:
2740
2912
  res = _a.sent();
2741
- return [2 /*return*/, new Progress(res.insertedId, 0, max, "", "", this.client, this.collection)];
2913
+ return [2 /*return*/, new Progress(res.insertedId, data, this.collection, this.client)];
2742
2914
  }
2743
2915
  });
2744
2916
  });
@@ -2808,19 +2980,25 @@
2808
2980
  if (jobParams === void 0) { jobParams = {}; }
2809
2981
  if (jobQue === void 0) { jobQue = "main"; }
2810
2982
  return __awaiter$l(this, void 0, void 0, function () {
2811
- var jobName, res;
2983
+ var jobName, data, existingAsset, res;
2812
2984
  return __generator(this, function (_a) {
2813
2985
  switch (_a.label) {
2814
2986
  case 0:
2815
2987
  jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
2816
- return [4 /*yield*/, this.collection.insertOne({
2817
- jobName: jobName,
2818
- jobParams: jobParams,
2819
- jobQue: jobQue
2820
- })];
2988
+ data = {
2989
+ jobName: jobName,
2990
+ jobParams: jobParams,
2991
+ jobQue: jobQue
2992
+ };
2993
+ return [4 /*yield*/, this.find(data)];
2821
2994
  case 1:
2995
+ existingAsset = _a.sent();
2996
+ if (existingAsset)
2997
+ return [2 /*return*/, existingAsset];
2998
+ return [4 /*yield*/, this.collection.insertOne(data)];
2999
+ case 2:
2822
3000
  res = _a.sent();
2823
- return [2 /*return*/, new LazyAsset(res.insertedId, jobName, jobParams, jobQue, null, null, this.assets, this.progresses, this.jobMan, this.collection)];
3001
+ return [2 /*return*/, new LazyAsset(res.insertedId, data, this.collection, this.assets, this.progresses, this.jobMan)];
2824
3002
  }
2825
3003
  });
2826
3004
  });
@@ -2842,7 +3020,7 @@
2842
3020
  data = _a.sent();
2843
3021
  return [2 /*return*/, !data
2844
3022
  ? null
2845
- : new LazyAsset(data._id, data.jobName, data.jobParams, data.jobQue, data.progressId, data.assetId, this.assets, this.progresses, this.jobMan, this.collection)];
3023
+ : new LazyAsset(data._id, data, this.collection, this.assets, this.progresses, this.jobMan)];
2846
3024
  }
2847
3025
  });
2848
3026
  });
@@ -2961,8 +3139,8 @@
2961
3139
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
2962
3140
  return Reflect.metadata(k, v);
2963
3141
  };
2964
- var express = express___default['default'];
2965
- var socketIO = socket_io__default['default'];
3142
+ var express = express___default["default"];
3143
+ var socketIO = socket_io__default["default"];
2966
3144
  exports.BackendProvider = /** @class */ (function () {
2967
3145
  function BackendProvider() {
2968
3146
  this.express = express();
@@ -3353,7 +3531,7 @@
3353
3531
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3354
3532
  });
3355
3533
  };
3356
- var sharp$1 = sharp___default['default'];
3534
+ var sharp$1 = sharp___default["default"];
3357
3535
  var bigSize = 1500;
3358
3536
  var thumbSize = 250;
3359
3537
  var GalleryImage = /** @class */ (function () {
@@ -3480,7 +3658,7 @@
3480
3658
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3481
3659
  });
3482
3660
  };
3483
- var sharp = sharp___default['default'];
3661
+ var sharp = sharp___default["default"];
3484
3662
  exports.Gallery = /** @class */ (function () {
3485
3663
  function Gallery(config, galleryCache) {
3486
3664
  this.config = config;
@@ -3719,7 +3897,7 @@
3719
3897
  this.cache = {};
3720
3898
  }
3721
3899
  TranslationProvider.prototype.getDictionary = function (language) {
3722
- this.cache[language] = this.cache[language] || axios__default['default'].get(this.config.resolve("translationsTemplate").replace("[lang]", language)).then(function (r) { return r.data; }, function (reason) { return ({
3900
+ this.cache[language] = this.cache[language] || axios__default["default"].get(this.config.resolve("translationsTemplate").replace("[lang]", language)).then(function (r) { return r.data; }, function (reason) { return ({
3723
3901
  message: reason
3724
3902
  }); });
3725
3903
  return this.cache[language];
@@ -4875,9 +5053,9 @@
4875
5053
  function RequestEndedMiddleware() {
4876
5054
  }
4877
5055
  RequestEndedMiddleware.prototype.use = function (request, response, next) {
4878
- request.ended = moment__default['default']();
5056
+ request.ended = moment__default["default"]();
4879
5057
  var diff = request.ended.diff(request.started);
4880
- var duration = moment__default['default'].duration(diff);
5058
+ var duration = moment__default["default"].duration(diff);
4881
5059
  console.log("Request '" + request.id + "' ended at: " + request.ended.format("YYYY-MM-DD HH:mm:ss") + " [" + request.method + "] " + request.url);
4882
5060
  console.log("Request '" + request.id + "' lasted: " + duration.asMilliseconds() + "ms");
4883
5061
  next(null);
@@ -4904,7 +5082,7 @@
4904
5082
  }
4905
5083
  RequestStartedMiddleware.prototype.use = function (request, response, next) {
4906
5084
  request.id = new bson.ObjectId().toHexString();
4907
- request.started = moment__default['default']();
5085
+ request.started = moment__default["default"]();
4908
5086
  console.log("Request '" + request.id + "' started at: " + request.started.format("YYYY-MM-DD HH:mm:ss") + " [" + request.method + "] " + request.url);
4909
5087
  next(null);
4910
5088
  };
@@ -5047,8 +5225,9 @@
5047
5225
  ], CompressionMiddleware);
5048
5226
 
5049
5227
  var Tree = /** @class */ (function () {
5050
- function Tree(container, path) {
5228
+ function Tree(container, exists, path) {
5051
5229
  this.container = container;
5230
+ this.exists = exists;
5052
5231
  this.path = path;
5053
5232
  this.map = new Map();
5054
5233
  }
@@ -5060,7 +5239,7 @@
5060
5239
  configurable: true
5061
5240
  });
5062
5241
  Tree.prototype.resolveService = function () {
5063
- return this.container.resolve(this.path);
5242
+ return !this.exists ? null : this.container.resolve(this.path);
5064
5243
  };
5065
5244
  Tree.prototype.resolveLeaves = function () {
5066
5245
  var map;
@@ -5102,7 +5281,7 @@
5102
5281
  parentTree = parentTree.resolveAncestor(path);
5103
5282
  }
5104
5283
  catch (e) {
5105
- parentTree = new Tree(this.container, "");
5284
+ parentTree = new Tree(this.container, false, "");
5106
5285
  }
5107
5286
  var pathParts = path.split(".");
5108
5287
  var tree = this;
@@ -5136,7 +5315,7 @@
5136
5315
  Tree.prototype.resolvePath = function (path, throwError) {
5137
5316
  if (throwError === void 0) { throwError = true; }
5138
5317
  var absolutePath = !this.path ? path : this.path + "." + path;
5139
- var tree = new Tree(this.container, absolutePath);
5318
+ var tree = new Tree(this.container, false, absolutePath);
5140
5319
  try {
5141
5320
  tree = this.resolveAncestor(path);
5142
5321
  }
@@ -5155,29 +5334,21 @@
5155
5334
  return tree;
5156
5335
  };
5157
5336
  Tree.prototype.addPath = function (path) {
5158
- var e_2, _a;
5159
5337
  if (!isString(path) || path.length == 0) {
5160
5338
  return this;
5161
5339
  }
5162
5340
  var pathParts = path.split(".");
5341
+ var maxIx = pathParts.length - 1;
5163
5342
  var tree = this;
5164
5343
  path = this.path;
5165
- try {
5166
- for (var pathParts_2 = __values(pathParts), pathParts_2_1 = pathParts_2.next(); !pathParts_2_1.done; pathParts_2_1 = pathParts_2.next()) {
5167
- var part = pathParts_2_1.value;
5168
- if (!tree.map.has(part)) {
5169
- tree.map.set(part, new Tree(this.container, !path ? part : path + "." + part));
5170
- }
5171
- tree = tree.map.get(part);
5172
- path = tree.path;
5344
+ for (var ix = 0; ix <= maxIx; ix++) {
5345
+ var part = pathParts[ix];
5346
+ if (!tree.map.has(part)) {
5347
+ tree.map.set(part, new Tree(this.container, false, !path ? part : path + "." + part));
5173
5348
  }
5174
- }
5175
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
5176
- finally {
5177
- try {
5178
- if (pathParts_2_1 && !pathParts_2_1.done && (_a = pathParts_2.return)) _a.call(pathParts_2);
5179
- }
5180
- finally { if (e_2) throw e_2.error; }
5349
+ tree = tree.map.get(part);
5350
+ tree.exists = tree.exists || ix == maxIx;
5351
+ path = tree.path;
5181
5352
  }
5182
5353
  return this;
5183
5354
  };
@@ -5192,7 +5363,7 @@
5192
5363
  container["wrapperContainer"] = this;
5193
5364
  this.tokens = [];
5194
5365
  this.tokenSet = new Set();
5195
- this.myTree = new Tree(this, "");
5366
+ this.root = new Tree(this, false, "");
5196
5367
  }
5197
5368
  Object.defineProperty(DiContainer.prototype, "registeredTokens", {
5198
5369
  get: function () {
@@ -5204,7 +5375,7 @@
5204
5375
  });
5205
5376
  Object.defineProperty(DiContainer.prototype, "tree", {
5206
5377
  get: function () {
5207
- return this.myTree;
5378
+ return this.root;
5208
5379
  },
5209
5380
  enumerable: false,
5210
5381
  configurable: true
@@ -5268,7 +5439,7 @@
5268
5439
  this.tokenSet.add(token);
5269
5440
  this.tokens.push(token);
5270
5441
  if (isString(token)) {
5271
- this.myTree.addPath(token);
5442
+ this.root.addPath(token);
5272
5443
  }
5273
5444
  return this;
5274
5445
  };
@@ -5306,7 +5477,7 @@
5306
5477
  console.log(browserFolder, fs.existsSync(browserFolder));
5307
5478
  if (fs.existsSync(browserFolder)) {
5308
5479
  console.log("public_html exists. setting up static files serving...");
5309
- app.use(express_['static'](browserFolder, {
5480
+ app.use(express_["static"](browserFolder, {
5310
5481
  maxAge: "1y"
5311
5482
  }));
5312
5483
  }
@@ -5372,29 +5543,36 @@
5372
5543
  return [4 /*yield*/, this.progresses.get(lazyAsset.progressId)];
5373
5544
  case 2:
5374
5545
  progress = _a.sent();
5546
+ if (!progress || progress.canceled)
5547
+ return [2 /*return*/, null];
5375
5548
  _a.label = 3;
5376
5549
  case 3:
5377
- _a.trys.push([3, 6, , 8]);
5550
+ _a.trys.push([3, 7, , 9]);
5378
5551
  return [4 /*yield*/, this.generate(progress)];
5379
5552
  case 4:
5380
5553
  asset = _a.sent();
5381
- return [4 /*yield*/, lazyAsset.writeAsset(asset)];
5554
+ return [4 /*yield*/, progress.load()];
5382
5555
  case 5:
5383
- _a.sent();
5384
- return [3 /*break*/, 8];
5556
+ progress = _a.sent();
5557
+ if (!progress || progress.canceled)
5558
+ return [2 /*return*/, null];
5559
+ return [4 /*yield*/, lazyAsset.writeAsset(asset)];
5385
5560
  case 6:
5561
+ _a.sent();
5562
+ return [3 /*break*/, 9];
5563
+ case 7:
5386
5564
  e_1 = _a.sent();
5387
5565
  return [4 /*yield*/, progress.setError(e_1.message || e_1)];
5388
- case 7:
5566
+ case 8:
5389
5567
  _a.sent();
5390
5568
  throw e_1;
5391
- case 8:
5392
- if (!(progress.remaining > 0)) return [3 /*break*/, 10];
5393
- return [4 /*yield*/, progress.advance(progress.remaining)];
5394
5569
  case 9:
5570
+ if (!(progress.remaining > 0)) return [3 /*break*/, 11];
5571
+ return [4 /*yield*/, progress.advance(progress.remaining)];
5572
+ case 10:
5395
5573
  _a.sent();
5396
- _a.label = 10;
5397
- case 10: return [2 /*return*/];
5574
+ _a.label = 11;
5575
+ case 11: return [2 /*return*/];
5398
5576
  }
5399
5577
  });
5400
5578
  });
@@ -5799,5 +5977,5 @@
5799
5977
 
5800
5978
  Object.defineProperty(exports, '__esModule', { value: true });
5801
5979
 
5802
- })));
5980
+ }));
5803
5981
  //# sourceMappingURL=stemy-backend.umd.js.map