@stemy/backend 5.0.10 → 5.1.1

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.
@@ -624,8 +624,14 @@ function gunzipPromised(data, opts) {
624
624
  });
625
625
  });
626
626
  }
627
- function deleteFromBucket(bucket, fileId) {
627
+ function deleteFromBucket(bucket, id) {
628
+ const fileId = id instanceof ObjectId ? id : new ObjectId(id);
628
629
  return new Promise(((resolve, reject) => {
630
+ if (!id) {
631
+ // We don't care about empty id
632
+ resolve(null);
633
+ return;
634
+ }
629
635
  bucket.delete(fileId, error => {
630
636
  let err = error;
631
637
  if (error) {
@@ -935,12 +941,6 @@ Configuration = __decorate([
935
941
  ], Configuration);
936
942
 
937
943
  let MongoConnector = class MongoConnector {
938
- constructor(configuration) {
939
- this.configuration = configuration;
940
- this.conn = null;
941
- this.db = null;
942
- this.fsBucket = null;
943
- }
944
944
  get connection() {
945
945
  return this.conn;
946
946
  }
@@ -950,6 +950,12 @@ let MongoConnector = class MongoConnector {
950
950
  get bucket() {
951
951
  return this.fsBucket;
952
952
  }
953
+ constructor(configuration) {
954
+ this.configuration = configuration;
955
+ this.conn = null;
956
+ this.db = null;
957
+ this.fsBucket = null;
958
+ }
953
959
  connect() {
954
960
  return __awaiter(this, void 0, void 0, function* () {
955
961
  if (this.db)
@@ -970,14 +976,14 @@ MongoConnector = __decorate([
970
976
  ], MongoConnector);
971
977
 
972
978
  class BaseEntity {
979
+ get id() {
980
+ return this.mId.toHexString();
981
+ }
973
982
  constructor(mId, data, collection) {
974
983
  this.mId = mId;
975
984
  this.data = data;
976
985
  this.collection = collection;
977
986
  }
978
- get id() {
979
- return this.mId.toHexString();
980
- }
981
987
  save() {
982
988
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
983
989
  }
@@ -1000,10 +1006,6 @@ class BaseEntity {
1000
1006
  }
1001
1007
 
1002
1008
  class Asset extends BaseEntity {
1003
- constructor(id, data, collection, bucket) {
1004
- super(id, data, collection);
1005
- this.bucket = bucket;
1006
- }
1007
1009
  get filename() {
1008
1010
  return this.data.filename;
1009
1011
  }
@@ -1016,11 +1018,21 @@ class Asset extends BaseEntity {
1016
1018
  get stream() {
1017
1019
  return this.bucket.openDownloadStream(this.mId);
1018
1020
  }
1021
+ constructor(id, data, collection, bucket) {
1022
+ super(id, data, collection);
1023
+ this.bucket = bucket;
1024
+ }
1019
1025
  unlink() {
1020
1026
  return __awaiter(this, void 0, void 0, function* () {
1021
1027
  return deleteFromBucket(this.bucket, this.mId);
1022
1028
  });
1023
1029
  }
1030
+ setMeta(metadata) {
1031
+ return __awaiter(this, void 0, void 0, function* () {
1032
+ metadata = Object.assign(this.metadata, metadata || {});
1033
+ yield this.collection.updateOne({ _id: this.mId }, { $set: { metadata } });
1034
+ });
1035
+ }
1024
1036
  getBuffer() {
1025
1037
  return streamToBuffer(this.stream);
1026
1038
  }
@@ -1049,6 +1061,9 @@ class Asset extends BaseEntity {
1049
1061
  }
1050
1062
 
1051
1063
  class TempAsset {
1064
+ get stream() {
1065
+ return bufferToStream(this.buffer);
1066
+ }
1052
1067
  constructor(buffer, filename, contentType, metadata) {
1053
1068
  this.buffer = buffer;
1054
1069
  this.filename = filename;
@@ -1056,14 +1071,16 @@ class TempAsset {
1056
1071
  this.metadata = metadata;
1057
1072
  this.id = new ObjectId$1().toHexString();
1058
1073
  }
1059
- get stream() {
1060
- return bufferToStream(this.buffer);
1061
- }
1062
1074
  unlink() {
1063
1075
  return __awaiter(this, void 0, void 0, function* () {
1064
1076
  throw new Error(`Temp asset '${this.id}' can not be removed!`);
1065
1077
  });
1066
1078
  }
1079
+ setMeta(meta) {
1080
+ return __awaiter(this, void 0, void 0, function* () {
1081
+ Object.assign(this.metadata, meta || {});
1082
+ });
1083
+ }
1067
1084
  getBuffer() {
1068
1085
  return __awaiter(this, void 0, void 0, function* () {
1069
1086
  return this.buffer;
@@ -1256,12 +1273,6 @@ Assets = __decorate([
1256
1273
  ], Assets);
1257
1274
 
1258
1275
  class LazyAsset extends BaseEntity {
1259
- constructor(id, data, collection, logger, assets, progresses) {
1260
- super(id, data, collection);
1261
- this.logger = logger;
1262
- this.assets = assets;
1263
- this.progresses = progresses;
1264
- }
1265
1276
  get jobName() {
1266
1277
  return this.data.jobName;
1267
1278
  }
@@ -1271,12 +1282,24 @@ class LazyAsset extends BaseEntity {
1271
1282
  get jobQue() {
1272
1283
  return this.data.jobQue;
1273
1284
  }
1285
+ get createdAt() {
1286
+ return this.data.createdAt;
1287
+ }
1288
+ get updatedAt() {
1289
+ return this.data.updatedAt;
1290
+ }
1274
1291
  get progressId() {
1275
1292
  return this.data.progressId;
1276
1293
  }
1277
1294
  get assetId() {
1278
1295
  return this.data.assetId;
1279
1296
  }
1297
+ constructor(id, data, collection, logger, assets, progresses) {
1298
+ super(id, data, collection);
1299
+ this.logger = logger;
1300
+ this.assets = assets;
1301
+ this.progresses = progresses;
1302
+ }
1280
1303
  unlink() {
1281
1304
  return __awaiter(this, void 0, void 0, function* () {
1282
1305
  yield this.load();
@@ -1318,16 +1341,21 @@ class LazyAsset extends BaseEntity {
1318
1341
  }
1319
1342
  writeAsset(asset) {
1320
1343
  return __awaiter(this, void 0, void 0, function* () {
1344
+ this.data.updatedAt = new Date();
1321
1345
  this.data.assetId = asset.id;
1346
+ yield asset.setMeta({ lazyId: this.id });
1322
1347
  yield this.save();
1323
1348
  return asset;
1324
1349
  });
1325
1350
  }
1326
1351
  startWorkingOnAsset(fromLoad) {
1327
1352
  return __awaiter(this, void 0, void 0, function* () {
1353
+ const oldAsset = this.data.assetId;
1354
+ this.data.updatedAt = new Date();
1328
1355
  this.data.progressId = (yield this.progresses.create()).id;
1329
1356
  this.data.assetId = null;
1330
1357
  yield this.save();
1358
+ yield deleteFromBucket(this.assets.bucket, oldAsset);
1331
1359
  const jobParams = JSON.parse(yield gunzipPromised(this.data.jobParams));
1332
1360
  yield this.progresses.jobMan.enqueueWithName(this.data.jobName, Object.assign(Object.assign({}, jobParams), { lazyId: this.id, fromLoad }));
1333
1361
  });
@@ -1538,9 +1566,6 @@ JobManager = __decorate([
1538
1566
  ], JobManager);
1539
1567
 
1540
1568
  class Progress extends BaseEntity {
1541
- constructor(id, data, collection) {
1542
- super(id, data, collection);
1543
- }
1544
1569
  get current() {
1545
1570
  return this.data.current;
1546
1571
  }
@@ -1562,6 +1587,9 @@ class Progress extends BaseEntity {
1562
1587
  get remaining() {
1563
1588
  return this.max > 0 ? this.max - this.current : 0;
1564
1589
  }
1590
+ constructor(id, data, collection) {
1591
+ super(id, data, collection);
1592
+ }
1565
1593
  setMessageBridge(messageBridge) {
1566
1594
  this.messageBridge = messageBridge || this.messageBridge;
1567
1595
  return this;
@@ -1627,19 +1655,6 @@ class Progress extends BaseEntity {
1627
1655
  }
1628
1656
  }
1629
1657
  class SubProgress {
1630
- constructor(parent, progressFrom, progressValue, mMax = 100) {
1631
- this.parent = parent;
1632
- this.progressFrom = progressFrom;
1633
- this.progressValue = progressValue;
1634
- this.mMax = mMax;
1635
- if (progressFrom < 0) {
1636
- throw "Progress from must be bigger than or zero";
1637
- }
1638
- if (progressValue <= 0) {
1639
- throw "Progress value must be bigger than zero";
1640
- }
1641
- this.mCurrent = 0;
1642
- }
1643
1658
  get id() {
1644
1659
  return this.parent.id;
1645
1660
  }
@@ -1664,6 +1679,19 @@ class SubProgress {
1664
1679
  get canceled() {
1665
1680
  return !this.parent || this.parent.canceled;
1666
1681
  }
1682
+ constructor(parent, progressFrom, progressValue, mMax = 100) {
1683
+ this.parent = parent;
1684
+ this.progressFrom = progressFrom;
1685
+ this.progressValue = progressValue;
1686
+ this.mMax = mMax;
1687
+ if (progressFrom < 0) {
1688
+ throw "Progress from must be bigger than or zero";
1689
+ }
1690
+ if (progressValue <= 0) {
1691
+ throw "Progress value must be bigger than zero";
1692
+ }
1693
+ this.mCurrent = 0;
1694
+ }
1667
1695
  setMessageBridge(messageBridge) {
1668
1696
  if (!this.parent)
1669
1697
  return this;
@@ -1849,11 +1877,13 @@ let LazyAssets = class LazyAssets {
1849
1877
  const data = {
1850
1878
  jobName,
1851
1879
  jobParams,
1852
- jobQue
1880
+ jobQue,
1853
1881
  };
1854
1882
  const existingAsset = yield this.find(data);
1855
1883
  if (existingAsset)
1856
1884
  return existingAsset;
1885
+ data.createdAt = new Date();
1886
+ data.updatedAt = data.createdAt;
1857
1887
  const res = yield this.collection.insertOne(data);
1858
1888
  return new LazyAsset(res.insertedId, data, this.collection, this.logger, this.assets, this.progresses);
1859
1889
  });
@@ -1963,11 +1993,6 @@ IsObjectId = __decorate([
1963
1993
  ], IsObjectId);
1964
1994
 
1965
1995
  let OpenApi = class OpenApi {
1966
- constructor(container, customValidation) {
1967
- this.container = container;
1968
- this.customValidation = customValidation;
1969
- this.docs = null;
1970
- }
1971
1996
  get apiDocs() {
1972
1997
  if (!this.docs)
1973
1998
  this.docs = this.createApiDocs();
@@ -1978,6 +2003,11 @@ let OpenApi = class OpenApi {
1978
2003
  this.docsStr = JSON.stringify(this.apiDocs);
1979
2004
  return this.docsStr;
1980
2005
  }
2006
+ constructor(container, customValidation) {
2007
+ this.container = container;
2008
+ this.customValidation = customValidation;
2009
+ this.docs = null;
2010
+ }
1981
2011
  schemaToExample(src, req) {
1982
2012
  var _a, _b, _c;
1983
2013
  return __awaiter(this, void 0, void 0, function* () {
@@ -2108,10 +2138,6 @@ Fixtures = __decorate([
2108
2138
 
2109
2139
  const express = express_;
2110
2140
  let BackendProvider = class BackendProvider {
2111
- constructor(config, container) {
2112
- this.config = config;
2113
- this.container = container;
2114
- }
2115
2141
  get io() {
2116
2142
  this.ioServer = this.ioServer || new Server(this.server, {
2117
2143
  path: "/socket",
@@ -2145,6 +2171,10 @@ let BackendProvider = class BackendProvider {
2145
2171
  this.httpServer = this.httpServer || createServer(this.express);
2146
2172
  return this.httpServer;
2147
2173
  }
2174
+ constructor(config, container) {
2175
+ this.config = config;
2176
+ this.container = container;
2177
+ }
2148
2178
  quickStart() {
2149
2179
  return __awaiter(this, void 0, void 0, function* () {
2150
2180
  const port = this.config.resolve("appPort");
@@ -2640,6 +2670,9 @@ TemplateRenderer = __decorate([
2640
2670
  ], TemplateRenderer);
2641
2671
 
2642
2672
  let MailSender = class MailSender {
2673
+ get translator() {
2674
+ return this.renderer.translator;
2675
+ }
2643
2676
  constructor(config, renderer) {
2644
2677
  this.config = config;
2645
2678
  this.renderer = renderer;
@@ -2652,9 +2685,6 @@ let MailSender = class MailSender {
2652
2685
  }
2653
2686
  });
2654
2687
  }
2655
- get translator() {
2656
- return this.renderer.translator;
2657
- }
2658
2688
  sendMail(language, options) {
2659
2689
  return __awaiter(this, void 0, void 0, function* () {
2660
2690
  const subject = yield this.translator.getTranslation(language, options.subject || "-");
@@ -3400,13 +3430,13 @@ TerminalController$1 = __decorate([
3400
3430
  ], TerminalController$1);
3401
3431
 
3402
3432
  let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3433
+ get isDev() {
3434
+ return this.configuration.resolve("nodeEnv") === "development";
3435
+ }
3403
3436
  constructor(configuration, translator) {
3404
3437
  this.configuration = configuration;
3405
3438
  this.translator = translator;
3406
3439
  }
3407
- get isDev() {
3408
- return this.configuration.resolve("nodeEnv") === "development";
3409
- }
3410
3440
  error(error, req, res, next) {
3411
3441
  var _a;
3412
3442
  return __awaiter(this, void 0, void 0, function* () {
@@ -3754,15 +3784,15 @@ CompressionMiddleware = __decorate([
3754
3784
  ], CompressionMiddleware);
3755
3785
 
3756
3786
  class Tree {
3787
+ get parentTree() {
3788
+ return this.container.parent.tree;
3789
+ }
3757
3790
  constructor(container, exists, path) {
3758
3791
  this.container = container;
3759
3792
  this.exists = exists;
3760
3793
  this.path = path;
3761
3794
  this.map = new Map();
3762
3795
  }
3763
- get parentTree() {
3764
- return this.container.parent.tree;
3765
- }
3766
3796
  resolveService() {
3767
3797
  return !this.exists ? null : this.container.resolve(this.path);
3768
3798
  }
@@ -3868,6 +3898,13 @@ class Tree {
3868
3898
  }
3869
3899
 
3870
3900
  class DiContainer {
3901
+ get registeredTokens() {
3902
+ var _a;
3903
+ return (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.registeredTokens) || []).concat(this.tokens);
3904
+ }
3905
+ get tree() {
3906
+ return this.root;
3907
+ }
3871
3908
  constructor(container, parent = null) {
3872
3909
  this.container = container;
3873
3910
  this.parent = parent;
@@ -3876,13 +3913,6 @@ class DiContainer {
3876
3913
  this.tokenSet = new Set();
3877
3914
  this.root = new Tree(this, false, "");
3878
3915
  }
3879
- get registeredTokens() {
3880
- var _a;
3881
- return (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.registeredTokens) || []).concat(this.tokens);
3882
- }
3883
- get tree() {
3884
- return this.root;
3885
- }
3886
3916
  beforeResolution(token, callback, options) {
3887
3917
  this.container.beforeResolution(token, callback, options);
3888
3918
  }
@@ -4116,17 +4146,17 @@ function ResponseType(type, options = {}) {
4116
4146
  }
4117
4147
 
4118
4148
  class LazyAssetGenerator {
4119
- constructor(assetResolver, progresses, lazyId) {
4120
- this.assetResolver = assetResolver;
4121
- this.progresses = progresses;
4122
- this.lazyId = lazyId;
4123
- }
4124
4149
  get assets() {
4125
4150
  return this.assetResolver.assets;
4126
4151
  }
4127
4152
  get lazyAssets() {
4128
4153
  return this.assetResolver.lazyAssets;
4129
4154
  }
4155
+ constructor(assetResolver, progresses, lazyId) {
4156
+ this.assetResolver = assetResolver;
4157
+ this.progresses = progresses;
4158
+ this.lazyId = lazyId;
4159
+ }
4130
4160
  process(messaging) {
4131
4161
  return __awaiter(this, void 0, void 0, function* () {
4132
4162
  const lazyAsset = yield this.lazyAssets.read(this.lazyId);