@stemy/backend 3.5.2 → 3.5.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.
@@ -27,7 +27,7 @@ import socket_io from 'socket.io';
27
27
  import { v4 } from 'uuid';
28
28
  import { createTransport } from 'nodemailer';
29
29
  import * as Handlebars from 'handlebars';
30
- import { routingControllersToSpec, OpenAPI } from 'routing-controllers-openapi';
30
+ import { routingControllersToSpec, OpenAPI, getStatusCode } from 'routing-controllers-openapi';
31
31
  import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
32
32
  import { defaultMetadataStorage } from 'class-transformer/storage';
33
33
  import { ValidatorConstraint, ValidationTypes, Min, Max, IsOptional, IsBoolean } from 'class-validator';
@@ -61,7 +61,7 @@ var __decorate$B = (this && this.__decorate) || function (decorators, target, ke
61
61
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
62
62
  return c > 3 && r && Object.defineProperty(target, key, r), r;
63
63
  };
64
- var __awaiter$y = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
64
+ var __awaiter$z = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
65
65
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
66
66
  return new (P || (P = Promise))(function (resolve, reject) {
67
67
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -97,7 +97,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
97
97
  }
98
98
  static fileTypeFromBuffer(buffer) {
99
99
  var _a;
100
- return __awaiter$y(this, void 0, void 0, function* () {
100
+ return __awaiter$z(this, void 0, void 0, function* () {
101
101
  const type = ((_a = yield fromBuffer(buffer)) !== null && _a !== void 0 ? _a : { ext: "txt", mime: "text/plain" });
102
102
  if (AssetProcessor_1.checkTextFileType(type)) {
103
103
  return AssetProcessor_1.fixTextFileType(type, buffer);
@@ -124,7 +124,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
124
124
  return imageTypes.indexOf(contentType) >= 0;
125
125
  }
126
126
  static copyImageMeta(buffer, metadata, fileType) {
127
- return __awaiter$y(this, void 0, void 0, function* () {
127
+ return __awaiter$z(this, void 0, void 0, function* () {
128
128
  if (fileType.mime === "image/svg+xml") {
129
129
  const match = /<svg([^<>]+)>/gi.exec(buffer.toString("utf8"));
130
130
  if (match && match.length > 1) {
@@ -163,7 +163,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
163
163
  });
164
164
  }
165
165
  process(buffer, metadata, fileType) {
166
- return __awaiter$y(this, void 0, void 0, function* () {
166
+ return __awaiter$z(this, void 0, void 0, function* () {
167
167
  if (AssetProcessor_1.isImage(fileType.mime)) {
168
168
  buffer = yield AssetProcessor_1.copyImageMeta(buffer, metadata, fileType);
169
169
  }
@@ -179,7 +179,7 @@ AssetProcessor = AssetProcessor_1 = __decorate$B([
179
179
  scoped(Lifecycle.ContainerScoped)
180
180
  ], AssetProcessor);
181
181
 
182
- var __awaiter$x = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
182
+ var __awaiter$y = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
183
183
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
184
184
  return new (P || (P = Promise))(function (resolve, reject) {
185
185
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -357,7 +357,7 @@ function toCropRegion(cropInfo) {
357
357
  };
358
358
  }
359
359
  function toImage(src, params, meta) {
360
- return __awaiter$x(this, void 0, void 0, function* () {
360
+ return __awaiter$y(this, void 0, void 0, function* () {
361
361
  // Default params and meta
362
362
  params = params || {};
363
363
  meta = meta || {};
@@ -495,7 +495,7 @@ function readFile(path) {
495
495
  });
496
496
  }
497
497
  function readAndDeleteFile(path, timeout = 5000) {
498
- return __awaiter$x(this, void 0, void 0, function* () {
498
+ return __awaiter$y(this, void 0, void 0, function* () {
499
499
  const data = yield readFile(path);
500
500
  setTimeout(() => {
501
501
  unlink(path, () => {
@@ -505,7 +505,7 @@ function readAndDeleteFile(path, timeout = 5000) {
505
505
  });
506
506
  }
507
507
  function writeFile(path, data) {
508
- return __awaiter$x(this, void 0, void 0, function* () {
508
+ return __awaiter$y(this, void 0, void 0, function* () {
509
509
  yield mkdirRecursive(dirname(path));
510
510
  return new Promise((res, rej) => {
511
511
  writeFile$1(path, data, err => {
@@ -817,6 +817,11 @@ function jsonHighlight(input, colorOptions) {
817
817
  }
818
818
  function replaceSpecialChars(str, to = "-") {
819
819
  return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
820
+ }
821
+ function flatten(arr) {
822
+ return arr.reduce((flat, toFlatten) => {
823
+ return flat.concat(isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
824
+ }, []);
820
825
  }
821
826
 
822
827
  var __decorate$A = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -886,7 +891,7 @@ var __decorate$z = (this && this.__decorate) || function (decorators, target, ke
886
891
  var __metadata$t = (this && this.__metadata) || function (k, v) {
887
892
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
888
893
  };
889
- var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
894
+ var __awaiter$x = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
890
895
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
891
896
  return new (P || (P = Promise))(function (resolve, reject) {
892
897
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -912,7 +917,7 @@ let MongoConnector = class MongoConnector {
912
917
  return this.fsBucket;
913
918
  }
914
919
  connect() {
915
- return __awaiter$w(this, void 0, void 0, function* () {
920
+ return __awaiter$x(this, void 0, void 0, function* () {
916
921
  if (this.db)
917
922
  return this.db;
918
923
  this.conn = (yield connect(this.configuration.resolve("mongoUri"), {
@@ -931,7 +936,7 @@ MongoConnector = __decorate$z([
931
936
  __metadata$t("design:paramtypes", [Configuration])
932
937
  ], MongoConnector);
933
938
 
934
- var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
939
+ var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
935
940
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
936
941
  return new (P || (P = Promise))(function (resolve, reject) {
937
942
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -953,7 +958,7 @@ class BaseEntity {
953
958
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
954
959
  }
955
960
  load() {
956
- return __awaiter$v(this, void 0, void 0, function* () {
961
+ return __awaiter$w(this, void 0, void 0, function* () {
957
962
  const res = yield this.collection.findOne({ _id: this.mId });
958
963
  this.deleted = !res;
959
964
  this.data = res || {};
@@ -968,7 +973,7 @@ class BaseEntity {
968
973
  }
969
974
  }
970
975
 
971
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
976
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
972
977
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
973
978
  return new (P || (P = Promise))(function (resolve, reject) {
974
979
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -995,7 +1000,7 @@ class Asset extends BaseEntity {
995
1000
  return this.bucket.openDownloadStream(this.mId);
996
1001
  }
997
1002
  unlink() {
998
- return __awaiter$u(this, void 0, void 0, function* () {
1003
+ return __awaiter$v(this, void 0, void 0, function* () {
999
1004
  return deleteFromBucket(this.bucket, this.mId);
1000
1005
  });
1001
1006
  }
@@ -1003,7 +1008,7 @@ class Asset extends BaseEntity {
1003
1008
  return streamToBuffer(this.stream);
1004
1009
  }
1005
1010
  download(metadata) {
1006
- return __awaiter$u(this, void 0, void 0, function* () {
1011
+ return __awaiter$v(this, void 0, void 0, function* () {
1007
1012
  metadata = Object.assign(this.metadata, metadata || {});
1008
1013
  metadata.downloadCount = isNaN(metadata.downloadCount) || !metadata.firstDownload
1009
1014
  ? 1
@@ -1015,18 +1020,18 @@ class Asset extends BaseEntity {
1015
1020
  });
1016
1021
  }
1017
1022
  getImage(params = null) {
1018
- return __awaiter$u(this, void 0, void 0, function* () {
1023
+ return __awaiter$v(this, void 0, void 0, function* () {
1019
1024
  return toImage(this.stream, params, this.metadata);
1020
1025
  });
1021
1026
  }
1022
1027
  downloadImage(params, metadata) {
1023
- return __awaiter$u(this, void 0, void 0, function* () {
1028
+ return __awaiter$v(this, void 0, void 0, function* () {
1024
1029
  return toImage(yield this.download(metadata), params, this.metadata);
1025
1030
  });
1026
1031
  }
1027
1032
  }
1028
1033
 
1029
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1034
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1030
1035
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1031
1036
  return new (P || (P = Promise))(function (resolve, reject) {
1032
1037
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1047,17 +1052,17 @@ class TempAsset {
1047
1052
  return bufferToStream(this.buffer);
1048
1053
  }
1049
1054
  unlink() {
1050
- return __awaiter$t(this, void 0, void 0, function* () {
1055
+ return __awaiter$u(this, void 0, void 0, function* () {
1051
1056
  throw new Error(`Temp asset '${this.id}' can not be removed!`);
1052
1057
  });
1053
1058
  }
1054
1059
  getBuffer() {
1055
- return __awaiter$t(this, void 0, void 0, function* () {
1060
+ return __awaiter$u(this, void 0, void 0, function* () {
1056
1061
  return this.buffer;
1057
1062
  });
1058
1063
  }
1059
1064
  download(metadata) {
1060
- return __awaiter$t(this, void 0, void 0, function* () {
1065
+ return __awaiter$u(this, void 0, void 0, function* () {
1061
1066
  return this.stream;
1062
1067
  });
1063
1068
  }
@@ -1069,12 +1074,12 @@ class TempAsset {
1069
1074
  return this.downloadImage(params);
1070
1075
  }
1071
1076
  save() {
1072
- return __awaiter$t(this, void 0, void 0, function* () {
1077
+ return __awaiter$u(this, void 0, void 0, function* () {
1073
1078
  return this;
1074
1079
  });
1075
1080
  }
1076
1081
  load() {
1077
- return __awaiter$t(this, void 0, void 0, function* () {
1082
+ return __awaiter$u(this, void 0, void 0, function* () {
1078
1083
  return this;
1079
1084
  });
1080
1085
  }
@@ -1097,7 +1102,7 @@ var __decorate$y = (this && this.__decorate) || function (decorators, target, ke
1097
1102
  var __metadata$s = (this && this.__metadata) || function (k, v) {
1098
1103
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1099
1104
  };
1100
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1105
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1101
1106
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1102
1107
  return new (P || (P = Promise))(function (resolve, reject) {
1103
1108
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1115,7 +1120,7 @@ let Assets = class Assets {
1115
1120
  this.collection = (_a = connector.database) === null || _a === void 0 ? void 0 : _a.collection("assets.files");
1116
1121
  }
1117
1122
  write(stream, contentType = null, metadata = null) {
1118
- return __awaiter$s(this, void 0, void 0, function* () {
1123
+ return __awaiter$t(this, void 0, void 0, function* () {
1119
1124
  const uploadStream = copyStream(stream);
1120
1125
  const buffer = yield streamToBuffer(stream);
1121
1126
  let fileType = { ext: "", mime: contentType };
@@ -1133,7 +1138,7 @@ let Assets = class Assets {
1133
1138
  });
1134
1139
  }
1135
1140
  writeBuffer(buffer, metadata = null, contentType = null) {
1136
- return __awaiter$s(this, void 0, void 0, function* () {
1141
+ return __awaiter$t(this, void 0, void 0, function* () {
1137
1142
  let fileType = { ext: "", mime: contentType };
1138
1143
  try {
1139
1144
  fileType = yield AssetProcessor.fileTypeFromBuffer(buffer);
@@ -1150,7 +1155,7 @@ let Assets = class Assets {
1150
1155
  });
1151
1156
  }
1152
1157
  writeUrl(url, metadata = null) {
1153
- return __awaiter$s(this, void 0, void 0, function* () {
1158
+ return __awaiter$t(this, void 0, void 0, function* () {
1154
1159
  metadata = metadata || {};
1155
1160
  metadata.filename = metadata.filename || url;
1156
1161
  metadata.uploadTime = new Date().getTime();
@@ -1163,7 +1168,7 @@ let Assets = class Assets {
1163
1168
  });
1164
1169
  }
1165
1170
  download(url, contentType = null) {
1166
- return __awaiter$s(this, void 0, void 0, function* () {
1171
+ return __awaiter$t(this, void 0, void 0, function* () {
1167
1172
  let buffer = (yield axios({ url, responseType: "arraybuffer" })).data;
1168
1173
  let fileType = { ext: "", mime: contentType };
1169
1174
  try {
@@ -1184,18 +1189,18 @@ let Assets = class Assets {
1184
1189
  });
1185
1190
  }
1186
1191
  read(id) {
1187
- return __awaiter$s(this, void 0, void 0, function* () {
1192
+ return __awaiter$t(this, void 0, void 0, function* () {
1188
1193
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
1189
1194
  });
1190
1195
  }
1191
1196
  find(where) {
1192
- return __awaiter$s(this, void 0, void 0, function* () {
1197
+ return __awaiter$t(this, void 0, void 0, function* () {
1193
1198
  const data = yield this.collection.findOne(where);
1194
1199
  return !data ? null : new Asset(data._id, data, this.collection, this.bucket);
1195
1200
  });
1196
1201
  }
1197
1202
  findMany(where) {
1198
- return __awaiter$s(this, void 0, void 0, function* () {
1203
+ return __awaiter$t(this, void 0, void 0, function* () {
1199
1204
  const cursor = this.collection.find(where);
1200
1205
  const items = (yield cursor.toArray()) || [];
1201
1206
  const result = [];
@@ -1208,13 +1213,13 @@ let Assets = class Assets {
1208
1213
  });
1209
1214
  }
1210
1215
  deleteMany(where) {
1211
- return __awaiter$s(this, void 0, void 0, function* () {
1216
+ return __awaiter$t(this, void 0, void 0, function* () {
1212
1217
  const assets = yield this.findMany(where);
1213
1218
  return Promise.all(assets.map(a => a.unlink()));
1214
1219
  });
1215
1220
  }
1216
1221
  unlink(id) {
1217
- return __awaiter$s(this, void 0, void 0, function* () {
1222
+ return __awaiter$t(this, void 0, void 0, function* () {
1218
1223
  const asset = yield this.read(id);
1219
1224
  if (!asset)
1220
1225
  return null;
@@ -1222,7 +1227,7 @@ let Assets = class Assets {
1222
1227
  });
1223
1228
  }
1224
1229
  upload(stream, fileType, metadata) {
1225
- return __awaiter$s(this, void 0, void 0, function* () {
1230
+ return __awaiter$t(this, void 0, void 0, function* () {
1226
1231
  const contentType = fileType.mime.trim();
1227
1232
  metadata = Object.assign({
1228
1233
  downloadCount: 0,
@@ -1259,7 +1264,7 @@ Assets = __decorate$y([
1259
1264
  __metadata$s("design:paramtypes", [MongoConnector, AssetProcessor])
1260
1265
  ], Assets);
1261
1266
 
1262
- var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1267
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1263
1268
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1264
1269
  return new (P || (P = Promise))(function (resolve, reject) {
1265
1270
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1291,7 +1296,7 @@ class LazyAsset extends BaseEntity {
1291
1296
  return this.data.assetId;
1292
1297
  }
1293
1298
  unlink() {
1294
- return __awaiter$r(this, void 0, void 0, function* () {
1299
+ return __awaiter$s(this, void 0, void 0, function* () {
1295
1300
  yield this.load();
1296
1301
  if (!this.progressId) {
1297
1302
  yield this.collection.deleteOne({ _id: this.mId });
@@ -1314,7 +1319,7 @@ class LazyAsset extends BaseEntity {
1314
1319
  });
1315
1320
  }
1316
1321
  loadAsset() {
1317
- return __awaiter$r(this, void 0, void 0, function* () {
1322
+ return __awaiter$s(this, void 0, void 0, function* () {
1318
1323
  yield this.load();
1319
1324
  if (this.deleted)
1320
1325
  return null;
@@ -1330,14 +1335,14 @@ class LazyAsset extends BaseEntity {
1330
1335
  });
1331
1336
  }
1332
1337
  writeAsset(asset) {
1333
- return __awaiter$r(this, void 0, void 0, function* () {
1338
+ return __awaiter$s(this, void 0, void 0, function* () {
1334
1339
  this.data.assetId = asset.id;
1335
1340
  yield this.save();
1336
1341
  return asset;
1337
1342
  });
1338
1343
  }
1339
1344
  startWorkingOnAsset(fromLoad) {
1340
- return __awaiter$r(this, void 0, void 0, function* () {
1345
+ return __awaiter$s(this, void 0, void 0, function* () {
1341
1346
  this.data.progressId = (yield this.progresses.create()).id;
1342
1347
  this.data.assetId = null;
1343
1348
  yield this.save();
@@ -1384,7 +1389,7 @@ var __metadata$q = (this && this.__metadata) || function (k, v) {
1384
1389
  var __param$8 = (this && this.__param) || function (paramIndex, decorator) {
1385
1390
  return function (target, key) { decorator(target, key, paramIndex); }
1386
1391
  };
1387
- var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1392
+ var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1388
1393
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1389
1394
  return new (P || (P = Promise))(function (resolve, reject) {
1390
1395
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1424,7 +1429,7 @@ let JobManager = class JobManager {
1424
1429
  .pipe(map(t => t.params)).subscribe(cb);
1425
1430
  }
1426
1431
  process(jobType, params = {}) {
1427
- return __awaiter$q(this, void 0, void 0, function* () {
1432
+ return __awaiter$r(this, void 0, void 0, function* () {
1428
1433
  let instance = null;
1429
1434
  try {
1430
1435
  instance = this.resolveJobInstance(jobType, params);
@@ -1437,12 +1442,12 @@ let JobManager = class JobManager {
1437
1442
  });
1438
1443
  }
1439
1444
  enqueueWithName(name, params = {}) {
1440
- return __awaiter$q(this, void 0, void 0, function* () {
1445
+ return __awaiter$r(this, void 0, void 0, function* () {
1441
1446
  return this.sendToWorkers(this.tryResolveFromName(name, params), params);
1442
1447
  });
1443
1448
  }
1444
1449
  enqueue(jobType, params = {}) {
1445
- return __awaiter$q(this, void 0, void 0, function* () {
1450
+ return __awaiter$r(this, void 0, void 0, function* () {
1446
1451
  return this.sendToWorkers(this.tryResolveAndInit(jobType, params), params);
1447
1452
  });
1448
1453
  }
@@ -1469,7 +1474,7 @@ let JobManager = class JobManager {
1469
1474
  });
1470
1475
  }
1471
1476
  startProcessing() {
1472
- return __awaiter$q(this, void 0, void 0, function* () {
1477
+ return __awaiter$r(this, void 0, void 0, function* () {
1473
1478
  if (this.processing)
1474
1479
  return null;
1475
1480
  this.processing = true;
@@ -1486,7 +1491,7 @@ let JobManager = class JobManager {
1486
1491
  this.workerPull = socket("pull");
1487
1492
  yield this.workerPull.connect(pullHost);
1488
1493
  this.logger.log("job-manager", `Worker consumer connected to: ${pullHost}`);
1489
- this.workerPull.on("message", (name, args, uniqId) => __awaiter$q(this, void 0, void 0, function* () {
1494
+ this.workerPull.on("message", (name, args, uniqId) => __awaiter$r(this, void 0, void 0, function* () {
1490
1495
  try {
1491
1496
  const jobName = name.toString("utf8");
1492
1497
  const jobParams = JSON.parse(args.toString("utf8"));
@@ -1565,7 +1570,7 @@ let JobManager = class JobManager {
1565
1570
  return container.resolve(jobType);
1566
1571
  }
1567
1572
  sendToWorkers(jobName, params) {
1568
- return __awaiter$q(this, void 0, void 0, function* () {
1573
+ return __awaiter$r(this, void 0, void 0, function* () {
1569
1574
  const publisher = yield this.apiPush;
1570
1575
  const uniqueId = new ObjectId$1().toHexString();
1571
1576
  yield publisher.send([jobName, JSON.stringify(params), uniqueId]);
@@ -1582,7 +1587,7 @@ JobManager = __decorate$w([
1582
1587
  Logger, Object, Array])
1583
1588
  ], JobManager);
1584
1589
 
1585
- var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1590
+ var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1586
1591
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1587
1592
  return new (P || (P = Promise))(function (resolve, reject) {
1588
1593
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1621,7 +1626,7 @@ class Progress extends BaseEntity {
1621
1626
  return this;
1622
1627
  }
1623
1628
  createSubProgress(progressValue, max, message) {
1624
- return __awaiter$p(this, void 0, void 0, function* () {
1629
+ return __awaiter$q(this, void 0, void 0, function* () {
1625
1630
  if (max <= 0 && progressValue > 0) {
1626
1631
  yield this.advance(progressValue);
1627
1632
  }
@@ -1633,7 +1638,7 @@ class Progress extends BaseEntity {
1633
1638
  });
1634
1639
  }
1635
1640
  setMax(max) {
1636
- return __awaiter$p(this, void 0, void 0, function* () {
1641
+ return __awaiter$q(this, void 0, void 0, function* () {
1637
1642
  if (isNaN(max) || max <= 0) {
1638
1643
  throw "Max progress value must be bigger than zero";
1639
1644
  }
@@ -1642,19 +1647,19 @@ class Progress extends BaseEntity {
1642
1647
  });
1643
1648
  }
1644
1649
  setMessage(message) {
1645
- return __awaiter$p(this, void 0, void 0, function* () {
1650
+ return __awaiter$q(this, void 0, void 0, function* () {
1646
1651
  this.data.message = message;
1647
1652
  yield this.save();
1648
1653
  });
1649
1654
  }
1650
1655
  setError(error) {
1651
- return __awaiter$p(this, void 0, void 0, function* () {
1656
+ return __awaiter$q(this, void 0, void 0, function* () {
1652
1657
  this.data.error = error;
1653
1658
  yield this.save();
1654
1659
  });
1655
1660
  }
1656
1661
  advance(value = 1) {
1657
- return __awaiter$p(this, void 0, void 0, function* () {
1662
+ return __awaiter$q(this, void 0, void 0, function* () {
1658
1663
  if (isNaN(value) || value <= 0) {
1659
1664
  throw "Advance value must be bigger than zero";
1660
1665
  }
@@ -1666,7 +1671,7 @@ class Progress extends BaseEntity {
1666
1671
  });
1667
1672
  }
1668
1673
  cancel() {
1669
- return __awaiter$p(this, void 0, void 0, function* () {
1674
+ return __awaiter$q(this, void 0, void 0, function* () {
1670
1675
  this.data.canceled = true;
1671
1676
  yield this.save();
1672
1677
  });
@@ -1723,7 +1728,7 @@ class SubProgress {
1723
1728
  return this;
1724
1729
  }
1725
1730
  createSubProgress(progressValue, max, message) {
1726
- return __awaiter$p(this, void 0, void 0, function* () {
1731
+ return __awaiter$q(this, void 0, void 0, function* () {
1727
1732
  if (max <= 0 && progressValue > 0) {
1728
1733
  yield this.advance(progressValue);
1729
1734
  }
@@ -1734,7 +1739,7 @@ class SubProgress {
1734
1739
  });
1735
1740
  }
1736
1741
  setMax(max) {
1737
- return __awaiter$p(this, void 0, void 0, function* () {
1742
+ return __awaiter$q(this, void 0, void 0, function* () {
1738
1743
  if (isNaN(max) || max <= 0) {
1739
1744
  throw "Max progress value must be bigger than zero";
1740
1745
  }
@@ -1743,21 +1748,21 @@ class SubProgress {
1743
1748
  });
1744
1749
  }
1745
1750
  setMessage(message) {
1746
- return __awaiter$p(this, void 0, void 0, function* () {
1751
+ return __awaiter$q(this, void 0, void 0, function* () {
1747
1752
  if (!this.parent)
1748
1753
  return null;
1749
1754
  yield this.parent.setMessage(message);
1750
1755
  });
1751
1756
  }
1752
1757
  setError(error) {
1753
- return __awaiter$p(this, void 0, void 0, function* () {
1758
+ return __awaiter$q(this, void 0, void 0, function* () {
1754
1759
  if (!this.parent)
1755
1760
  return null;
1756
1761
  yield this.parent.setError(error);
1757
1762
  });
1758
1763
  }
1759
1764
  advance(value = 1) {
1760
- return __awaiter$p(this, void 0, void 0, function* () {
1765
+ return __awaiter$q(this, void 0, void 0, function* () {
1761
1766
  if (isNaN(value) || value <= 0) {
1762
1767
  throw "Advance value must be bigger than zero";
1763
1768
  }
@@ -1766,14 +1771,14 @@ class SubProgress {
1766
1771
  });
1767
1772
  }
1768
1773
  cancel() {
1769
- return __awaiter$p(this, void 0, void 0, function* () {
1774
+ return __awaiter$q(this, void 0, void 0, function* () {
1770
1775
  if (!this.parent)
1771
1776
  return null;
1772
1777
  yield this.parent.cancel();
1773
1778
  });
1774
1779
  }
1775
1780
  save() {
1776
- return __awaiter$p(this, void 0, void 0, function* () {
1781
+ return __awaiter$q(this, void 0, void 0, function* () {
1777
1782
  const ratio = this.max > 0 ? this.mCurrent / this.max : 0;
1778
1783
  const newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
1779
1784
  const current = this.parent.current;
@@ -1783,7 +1788,7 @@ class SubProgress {
1783
1788
  });
1784
1789
  }
1785
1790
  load() {
1786
- return __awaiter$p(this, void 0, void 0, function* () {
1791
+ return __awaiter$q(this, void 0, void 0, function* () {
1787
1792
  return null;
1788
1793
  });
1789
1794
  }
@@ -1801,7 +1806,7 @@ var __decorate$v = (this && this.__decorate) || function (decorators, target, ke
1801
1806
  var __metadata$p = (this && this.__metadata) || function (k, v) {
1802
1807
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1803
1808
  };
1804
- var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1809
+ var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1805
1810
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1806
1811
  return new (P || (P = Promise))(function (resolve, reject) {
1807
1812
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1822,9 +1827,9 @@ let Progresses = class Progresses {
1822
1827
  });
1823
1828
  }
1824
1829
  waitToFinish(id) {
1825
- return __awaiter$o(this, void 0, void 0, function* () {
1830
+ return __awaiter$p(this, void 0, void 0, function* () {
1826
1831
  return Promise.race([
1827
- this.waitForProgress(id, () => __awaiter$o(this, void 0, void 0, function* () {
1832
+ this.waitForProgress(id, () => __awaiter$p(this, void 0, void 0, function* () {
1828
1833
  let progress = this.progresses[id];
1829
1834
  if (!progress || progress.percent < 100) {
1830
1835
  progress = yield this.get(id);
@@ -1834,25 +1839,25 @@ let Progresses = class Progresses {
1834
1839
  }
1835
1840
  return progress;
1836
1841
  }), 500),
1837
- this.waitForProgress(id, () => __awaiter$o(this, void 0, void 0, function* () {
1842
+ this.waitForProgress(id, () => __awaiter$p(this, void 0, void 0, function* () {
1838
1843
  return this.progresses[id] || null;
1839
1844
  }), 25)
1840
1845
  ]);
1841
1846
  });
1842
1847
  }
1843
1848
  get(id) {
1844
- return __awaiter$o(this, void 0, void 0, function* () {
1849
+ return __awaiter$p(this, void 0, void 0, function* () {
1845
1850
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
1846
1851
  });
1847
1852
  }
1848
1853
  find(where) {
1849
- return __awaiter$o(this, void 0, void 0, function* () {
1854
+ return __awaiter$p(this, void 0, void 0, function* () {
1850
1855
  const data = yield this.collection.findOne(where);
1851
1856
  return !data ? null : new Progress(data._id, data, this.collection);
1852
1857
  });
1853
1858
  }
1854
1859
  create(max = 100) {
1855
- return __awaiter$o(this, void 0, void 0, function* () {
1860
+ return __awaiter$p(this, void 0, void 0, function* () {
1856
1861
  if (isNaN(max) || max <= 0) {
1857
1862
  throw new Error(`Max progress value must be bigger than zero`);
1858
1863
  }
@@ -1868,13 +1873,13 @@ let Progresses = class Progresses {
1868
1873
  });
1869
1874
  }
1870
1875
  remove(id) {
1871
- return __awaiter$o(this, void 0, void 0, function* () {
1876
+ return __awaiter$p(this, void 0, void 0, function* () {
1872
1877
  yield this.collection.deleteOne({ _id: new ObjectId$1(id) });
1873
1878
  return id;
1874
1879
  });
1875
1880
  }
1876
1881
  waitForProgress(id, cb, delay) {
1877
- return __awaiter$o(this, void 0, void 0, function* () {
1882
+ return __awaiter$p(this, void 0, void 0, function* () {
1878
1883
  let isFinished = false;
1879
1884
  let progress = null;
1880
1885
  let waitTime = 0;
@@ -1913,7 +1918,7 @@ var __decorate$u = (this && this.__decorate) || function (decorators, target, ke
1913
1918
  var __metadata$o = (this && this.__metadata) || function (k, v) {
1914
1919
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1915
1920
  };
1916
- var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1921
+ var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1917
1922
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1918
1923
  return new (P || (P = Promise))(function (resolve, reject) {
1919
1924
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1932,7 +1937,7 @@ let LazyAssets = class LazyAssets {
1932
1937
  this.collection = connector.database.collection("lazyassets");
1933
1938
  }
1934
1939
  create(jobType, jobParams = {}, jobQue = "main") {
1935
- return __awaiter$n(this, void 0, void 0, function* () {
1940
+ return __awaiter$o(this, void 0, void 0, function* () {
1936
1941
  const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
1937
1942
  const data = {
1938
1943
  jobName,
@@ -1947,12 +1952,12 @@ let LazyAssets = class LazyAssets {
1947
1952
  });
1948
1953
  }
1949
1954
  read(id) {
1950
- return __awaiter$n(this, void 0, void 0, function* () {
1955
+ return __awaiter$o(this, void 0, void 0, function* () {
1951
1956
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
1952
1957
  });
1953
1958
  }
1954
1959
  find(where) {
1955
- return __awaiter$n(this, void 0, void 0, function* () {
1960
+ return __awaiter$o(this, void 0, void 0, function* () {
1956
1961
  const data = yield this.collection.findOne(where);
1957
1962
  return !data
1958
1963
  ? null
@@ -1960,7 +1965,7 @@ let LazyAssets = class LazyAssets {
1960
1965
  });
1961
1966
  }
1962
1967
  unlink(id) {
1963
- return __awaiter$n(this, void 0, void 0, function* () {
1968
+ return __awaiter$o(this, void 0, void 0, function* () {
1964
1969
  const asset = yield this.read(id);
1965
1970
  if (!asset)
1966
1971
  return null;
@@ -1987,7 +1992,7 @@ var __decorate$t = (this && this.__decorate) || function (decorators, target, ke
1987
1992
  var __metadata$n = (this && this.__metadata) || function (k, v) {
1988
1993
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1989
1994
  };
1990
- var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1995
+ var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1991
1996
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1992
1997
  return new (P || (P = Promise))(function (resolve, reject) {
1993
1998
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2002,7 +2007,7 @@ let AssetResolver = class AssetResolver {
2002
2007
  this.lazyAssets = lazyAssets;
2003
2008
  }
2004
2009
  resolve(id, lazy = false) {
2005
- return __awaiter$m(this, void 0, void 0, function* () {
2010
+ return __awaiter$n(this, void 0, void 0, function* () {
2006
2011
  let asset = null;
2007
2012
  if (lazy) {
2008
2013
  const lazyAsset = yield this.lazyAssets.read(id);
@@ -2061,7 +2066,7 @@ var __decorate$r = (this && this.__decorate) || function (decorators, target, ke
2061
2066
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2062
2067
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2063
2068
  };
2064
- var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2069
+ var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2065
2070
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2066
2071
  return new (P || (P = Promise))(function (resolve, reject) {
2067
2072
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2072,12 +2077,12 @@ var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P,
2072
2077
  };
2073
2078
  let CacheProcessor = class CacheProcessor {
2074
2079
  serialize(data) {
2075
- return __awaiter$l(this, void 0, void 0, function* () {
2080
+ return __awaiter$m(this, void 0, void 0, function* () {
2076
2081
  return data;
2077
2082
  });
2078
2083
  }
2079
2084
  deserialize(data) {
2080
- return __awaiter$l(this, void 0, void 0, function* () {
2085
+ return __awaiter$m(this, void 0, void 0, function* () {
2081
2086
  return data;
2082
2087
  });
2083
2088
  }
@@ -2096,7 +2101,7 @@ var __decorate$q = (this && this.__decorate) || function (decorators, target, ke
2096
2101
  var __metadata$l = (this && this.__metadata) || function (k, v) {
2097
2102
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2098
2103
  };
2099
- var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2104
+ var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2100
2105
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2101
2106
  return new (P || (P = Promise))(function (resolve, reject) {
2102
2107
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2112,7 +2117,7 @@ let Cache = class Cache {
2112
2117
  this.cacheProcessor = cacheProcessor;
2113
2118
  }
2114
2119
  prepare() {
2115
- return __awaiter$k(this, void 0, void 0, function* () {
2120
+ return __awaiter$l(this, void 0, void 0, function* () {
2116
2121
  if (this.collection)
2117
2122
  return;
2118
2123
  if (!this.connector.database) {
@@ -2123,7 +2128,7 @@ let Cache = class Cache {
2123
2128
  });
2124
2129
  }
2125
2130
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2126
- return __awaiter$k(this, void 0, void 0, function* () {
2131
+ return __awaiter$l(this, void 0, void 0, function* () {
2127
2132
  yield this.prepare();
2128
2133
  const item = {
2129
2134
  _id: key,
@@ -2140,7 +2145,7 @@ let Cache = class Cache {
2140
2145
  });
2141
2146
  }
2142
2147
  get(key) {
2143
- return __awaiter$k(this, void 0, void 0, function* () {
2148
+ return __awaiter$l(this, void 0, void 0, function* () {
2144
2149
  yield this.prepare();
2145
2150
  let item = yield this.collection.findOne({ _id: key });
2146
2151
  const now = Math.round(new Date().getTime() / 1000);
@@ -2154,7 +2159,7 @@ let Cache = class Cache {
2154
2159
  });
2155
2160
  }
2156
2161
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
2157
- return __awaiter$k(this, void 0, void 0, function* () {
2162
+ return __awaiter$l(this, void 0, void 0, function* () {
2158
2163
  try {
2159
2164
  return yield this.get(key);
2160
2165
  }
@@ -2164,7 +2169,7 @@ let Cache = class Cache {
2164
2169
  });
2165
2170
  }
2166
2171
  delete(key) {
2167
- return __awaiter$k(this, void 0, void 0, function* () {
2172
+ return __awaiter$l(this, void 0, void 0, function* () {
2168
2173
  yield this.prepare();
2169
2174
  yield this.collection.deleteOne({ _id: key });
2170
2175
  });
@@ -2182,7 +2187,7 @@ var __decorate$p = (this && this.__decorate) || function (decorators, target, ke
2182
2187
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2183
2188
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2184
2189
  };
2185
- var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2190
+ var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2186
2191
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2187
2192
  return new (P || (P = Promise))(function (resolve, reject) {
2188
2193
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2193,7 +2198,7 @@ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P,
2193
2198
  };
2194
2199
  let EndpointProvider = class EndpointProvider {
2195
2200
  configure(app) {
2196
- return __awaiter$j(this, void 0, void 0, function* () {
2201
+ return __awaiter$k(this, void 0, void 0, function* () {
2197
2202
  console.log(`Express app is mounted to: ${app.mountpath}`);
2198
2203
  });
2199
2204
  }
@@ -2215,7 +2220,7 @@ var __metadata$k = (this && this.__metadata) || function (k, v) {
2215
2220
  var __param$7 = (this && this.__param) || function (paramIndex, decorator) {
2216
2221
  return function (target, key) { decorator(target, key, paramIndex); }
2217
2222
  };
2218
- var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2223
+ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2219
2224
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2220
2225
  return new (P || (P = Promise))(function (resolve, reject) {
2221
2226
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2229,7 +2234,7 @@ let Fixtures = class Fixtures {
2229
2234
  this.fixtures = fixtures;
2230
2235
  }
2231
2236
  load() {
2232
- return __awaiter$i(this, void 0, void 0, function* () {
2237
+ return __awaiter$j(this, void 0, void 0, function* () {
2233
2238
  if (!this.fixtures)
2234
2239
  return;
2235
2240
  for (let fixture of this.fixtures) {
@@ -2245,7 +2250,7 @@ Fixtures = __decorate$o([
2245
2250
  __metadata$k("design:paramtypes", [Array])
2246
2251
  ], Fixtures);
2247
2252
 
2248
- var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2253
+ var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2249
2254
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2250
2255
  return new (P || (P = Promise))(function (resolve, reject) {
2251
2256
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2266,7 +2271,7 @@ class GalleryImage {
2266
2271
  this.targetSize = !size ? { width: thumbSize, height: thumbSize } : size;
2267
2272
  }
2268
2273
  serve(id) {
2269
- return __awaiter$h(this, void 0, void 0, function* () {
2274
+ return __awaiter$i(this, void 0, void 0, function* () {
2270
2275
  const isThumb = id == this.thumb;
2271
2276
  if (yield this.handler.hasResult(isThumb)) {
2272
2277
  return this.handler.serveResult(isThumb);
@@ -2333,7 +2338,7 @@ var __decorate$m = (this && this.__decorate) || function (decorators, target, ke
2333
2338
  var __metadata$i = (this && this.__metadata) || function (k, v) {
2334
2339
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2335
2340
  };
2336
- var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2341
+ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2337
2342
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2338
2343
  return new (P || (P = Promise))(function (resolve, reject) {
2339
2344
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2352,7 +2357,7 @@ let Gallery = class Gallery {
2352
2357
  this.output = join(this.config.resolve("cacheDir"), "gallery");
2353
2358
  }
2354
2359
  getFolder(folder, size = null) {
2355
- return __awaiter$g(this, void 0, void 0, function* () {
2360
+ return __awaiter$h(this, void 0, void 0, function* () {
2356
2361
  this.cache[folder] = this.cache[folder] || new Promise(resolve => {
2357
2362
  lstat(join(this.dir, folder), (err, stats) => {
2358
2363
  if (err || !stats.isDirectory()) {
@@ -2373,7 +2378,7 @@ let Gallery = class Gallery {
2373
2378
  return;
2374
2379
  }
2375
2380
  const promises = files.map(file => {
2376
- return new Promise((resolve) => __awaiter$g(this, void 0, void 0, function* () {
2381
+ return new Promise((resolve) => __awaiter$h(this, void 0, void 0, function* () {
2377
2382
  const filePath = join(path, file);
2378
2383
  const absoluteFilePath = join(this.dir, filePath);
2379
2384
  lstat(absoluteFilePath, (err, stats) => {
@@ -2406,7 +2411,7 @@ let Gallery = class Gallery {
2406
2411
  });
2407
2412
  },
2408
2413
  writeResult: (isThumb, buffer) => {
2409
- return new Promise((res, rej) => __awaiter$g(this, void 0, void 0, function* () {
2414
+ return new Promise((res, rej) => __awaiter$h(this, void 0, void 0, function* () {
2410
2415
  const resultPath = getResultPath(isThumb);
2411
2416
  yield mkdirRecursive(dirname(resultPath));
2412
2417
  writeFile$1(resultPath, buffer, err => {
@@ -2463,7 +2468,7 @@ var __decorate$l = (this && this.__decorate) || function (decorators, target, ke
2463
2468
  var __metadata$h = (this && this.__metadata) || function (k, v) {
2464
2469
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2465
2470
  };
2466
- var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2471
+ var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2467
2472
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2468
2473
  return new (P || (P = Promise))(function (resolve, reject) {
2469
2474
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2481,7 +2486,7 @@ let IdGenerator = class IdGenerator {
2481
2486
  this.parts = config.resolve("idParts");
2482
2487
  }
2483
2488
  generate(checkCb) {
2484
- return __awaiter$f(this, void 0, void 0, function* () {
2489
+ return __awaiter$g(this, void 0, void 0, function* () {
2485
2490
  let id = null;
2486
2491
  let tries = 0;
2487
2492
  let notGood = true;
@@ -2549,7 +2554,7 @@ var __decorate$j = (this && this.__decorate) || function (decorators, target, ke
2549
2554
  var __metadata$f = (this && this.__metadata) || function (k, v) {
2550
2555
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2551
2556
  };
2552
- var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2557
+ var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2553
2558
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2554
2559
  return new (P || (P = Promise))(function (resolve, reject) {
2555
2560
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2564,7 +2569,7 @@ let Translator = class Translator {
2564
2569
  this.cache = {};
2565
2570
  }
2566
2571
  getDictionary(language) {
2567
- return __awaiter$e(this, void 0, void 0, function* () {
2572
+ return __awaiter$f(this, void 0, void 0, function* () {
2568
2573
  const dictionary = yield this.translationProvider.getDictionary(language);
2569
2574
  this.cache[language] = dictionary;
2570
2575
  return dictionary;
@@ -2630,7 +2635,7 @@ var __decorate$i = (this && this.__decorate) || function (decorators, target, ke
2630
2635
  var __metadata$e = (this && this.__metadata) || function (k, v) {
2631
2636
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2632
2637
  };
2633
- var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2638
+ var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2634
2639
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2635
2640
  return new (P || (P = Promise))(function (resolve, reject) {
2636
2641
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2662,9 +2667,9 @@ let TemplateRenderer = class TemplateRenderer {
2662
2667
  return this.initPromise;
2663
2668
  }
2664
2669
  parseTemplates(dir, dirPath) {
2665
- return __awaiter$d(this, void 0, void 0, function* () {
2670
+ return __awaiter$e(this, void 0, void 0, function* () {
2666
2671
  return new Promise(resolve => {
2667
- readdir(dir, (err, files) => __awaiter$d(this, void 0, void 0, function* () {
2672
+ readdir(dir, (err, files) => __awaiter$e(this, void 0, void 0, function* () {
2668
2673
  for (let file of files) {
2669
2674
  const path = join(dir, file);
2670
2675
  if (lstatSync(path).isDirectory()) {
@@ -2685,7 +2690,7 @@ let TemplateRenderer = class TemplateRenderer {
2685
2690
  });
2686
2691
  }
2687
2692
  render(template, language, context) {
2688
- return __awaiter$d(this, void 0, void 0, function* () {
2693
+ return __awaiter$e(this, void 0, void 0, function* () {
2689
2694
  yield this.init();
2690
2695
  yield this.translator.getDictionary(language);
2691
2696
  if (!this.templates[template]) {
@@ -2712,7 +2717,7 @@ var __decorate$h = (this && this.__decorate) || function (decorators, target, ke
2712
2717
  var __metadata$d = (this && this.__metadata) || function (k, v) {
2713
2718
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2714
2719
  };
2715
- var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2720
+ var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2716
2721
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2717
2722
  return new (P || (P = Promise))(function (resolve, reject) {
2718
2723
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2738,7 +2743,7 @@ let MailSender = class MailSender {
2738
2743
  return this.renderer.translator;
2739
2744
  }
2740
2745
  sendMail(language, options) {
2741
- return __awaiter$c(this, void 0, void 0, function* () {
2746
+ return __awaiter$d(this, void 0, void 0, function* () {
2742
2747
  const subject = yield this.translator.getTranslation(language, options.subject || "-");
2743
2748
  const html = yield this.renderer.render(options.template, language, options.context);
2744
2749
  return this.transporter.sendMail({
@@ -2766,7 +2771,7 @@ var __decorate$g = (this && this.__decorate) || function (decorators, target, ke
2766
2771
  var __metadata$c = (this && this.__metadata) || function (k, v) {
2767
2772
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2768
2773
  };
2769
- var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2774
+ var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2770
2775
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2771
2776
  return new (P || (P = Promise))(function (resolve, reject) {
2772
2777
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2781,7 +2786,7 @@ let MemoryCache = class MemoryCache {
2781
2786
  this.cacheMap = new Map();
2782
2787
  }
2783
2788
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2784
- return __awaiter$b(this, void 0, void 0, function* () {
2789
+ return __awaiter$c(this, void 0, void 0, function* () {
2785
2790
  const now = Math.round(new Date().getTime() / 1000);
2786
2791
  const expTimestamp = Math.min(isNaN(ttl) ? Number.MAX_SAFE_INTEGER : ttl, 3600);
2787
2792
  this.cacheMap.set(key, {
@@ -2794,7 +2799,7 @@ let MemoryCache = class MemoryCache {
2794
2799
  });
2795
2800
  }
2796
2801
  get(key) {
2797
- return __awaiter$b(this, void 0, void 0, function* () {
2802
+ return __awaiter$c(this, void 0, void 0, function* () {
2798
2803
  let item = this.cacheMap.get(key);
2799
2804
  const now = Math.round(new Date().getTime() / 1000);
2800
2805
  let expTimestamp = 3600;
@@ -2816,7 +2821,7 @@ let MemoryCache = class MemoryCache {
2816
2821
  });
2817
2822
  }
2818
2823
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
2819
- return __awaiter$b(this, void 0, void 0, function* () {
2824
+ return __awaiter$c(this, void 0, void 0, function* () {
2820
2825
  try {
2821
2826
  return yield this.get(key);
2822
2827
  }
@@ -2826,7 +2831,7 @@ let MemoryCache = class MemoryCache {
2826
2831
  });
2827
2832
  }
2828
2833
  delete(key) {
2829
- return __awaiter$b(this, void 0, void 0, function* () {
2834
+ return __awaiter$c(this, void 0, void 0, function* () {
2830
2835
  this.cacheMap.delete(key);
2831
2836
  yield this.cacheMap.delete(key);
2832
2837
  });
@@ -2897,8 +2902,18 @@ var __metadata$b = (this && this.__metadata) || function (k, v) {
2897
2902
  var __param$6 = (this && this.__param) || function (paramIndex, decorator) {
2898
2903
  return function (target, key) { decorator(target, key, paramIndex); }
2899
2904
  };
2905
+ var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2906
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2907
+ return new (P || (P = Promise))(function (resolve, reject) {
2908
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2909
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2910
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2911
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2912
+ });
2913
+ };
2900
2914
  let OpenApi = class OpenApi {
2901
- constructor(customValidation = null) {
2915
+ constructor(container, customValidation) {
2916
+ this.container = container;
2902
2917
  this.customValidation = customValidation;
2903
2918
  this.docs = null;
2904
2919
  }
@@ -2912,6 +2927,56 @@ let OpenApi = class OpenApi {
2912
2927
  this.docsStr = JSON.stringify(this.apiDocs);
2913
2928
  return this.docsStr;
2914
2929
  }
2930
+ schemaToExample(src, req) {
2931
+ var _a, _b, _c;
2932
+ return __awaiter$b(this, void 0, void 0, function* () {
2933
+ if (src.$ref) {
2934
+ const schemas = this.apiDocs.components.schemas;
2935
+ return this.schemaToExample(schemas[src.$ref.replace("#/components/schemas/", "")], req);
2936
+ }
2937
+ let schema = src;
2938
+ if (schema.oneOf) {
2939
+ schema = Object.assign({}, schema, schema.oneOf[0]);
2940
+ }
2941
+ if (schema.type === "object") {
2942
+ const result = {};
2943
+ yield Promise.all(Object.keys(schema.properties).map((key) => __awaiter$b(this, void 0, void 0, function* () {
2944
+ result[key] = yield this.schemaToExample(schema.properties[key], req);
2945
+ })));
2946
+ return result;
2947
+ }
2948
+ if (schema.type === "array") {
2949
+ return [yield this.schemaToExample(schema.items, req)];
2950
+ }
2951
+ if (schema.type === "string") {
2952
+ if (isDefined(schema.default)) {
2953
+ if (isFunction(schema.default)) {
2954
+ return schema.default(this.container);
2955
+ }
2956
+ return schema.default;
2957
+ }
2958
+ if (schema.format == "date") {
2959
+ return new Date().toISOString().substr(0, 10);
2960
+ }
2961
+ if (schema.format == "date-time") {
2962
+ return new Date().toISOString();
2963
+ }
2964
+ if (schema.enum) {
2965
+ return schema.enum[0];
2966
+ }
2967
+ return "string";
2968
+ }
2969
+ if (schema.type === "number") {
2970
+ return (_a = schema.default) !== null && _a !== void 0 ? _a : 0;
2971
+ }
2972
+ else if (schema.type === "boolean") {
2973
+ return (_b = schema.default) !== null && _b !== void 0 ? _b : false;
2974
+ }
2975
+ else {
2976
+ return (_c = schema.default) !== null && _c !== void 0 ? _c : null;
2977
+ }
2978
+ });
2979
+ }
2915
2980
  createApiDocs() {
2916
2981
  const storage = getMetadataArgsStorage();
2917
2982
  const docs = routingControllersToSpec(storage);
@@ -2947,8 +3012,9 @@ let OpenApi = class OpenApi {
2947
3012
  };
2948
3013
  OpenApi = __decorate$e([
2949
3014
  singleton(),
2950
- __param$6(0, inject(OPENAPI_VALIDATION)),
2951
- __metadata$b("design:paramtypes", [Object])
3015
+ __param$6(0, inject(DI_CONTAINER)),
3016
+ __param$6(1, inject(OPENAPI_VALIDATION)),
3017
+ __metadata$b("design:paramtypes", [Object, Object])
2952
3018
  ], OpenApi);
2953
3019
 
2954
3020
  var __decorate$d = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -3946,6 +4012,42 @@ function IsDocumented(summary = null) {
3946
4012
  operation.tags = ["Documented"].concat(operation.tags || []);
3947
4013
  return operation;
3948
4014
  });
4015
+ }
4016
+ function JsonResponse(description = "Success", statusCode = null) {
4017
+ return OpenAPI((operation, route) => {
4018
+ const status = statusCode !== null && statusCode !== void 0 ? statusCode : getStatusCode(route) + "";
4019
+ operation.responses = operation.responses || {};
4020
+ operation.responses[status] = {
4021
+ description,
4022
+ content: {
4023
+ "application/json": {}
4024
+ }
4025
+ };
4026
+ return operation;
4027
+ });
4028
+ }
4029
+ function ResponseType(type, options = {}) {
4030
+ return OpenAPI((operation, route) => {
4031
+ var _a;
4032
+ const contentType = "application/json";
4033
+ const statusCode = (_a = options === null || options === void 0 ? void 0 : options.statusCode) !== null && _a !== void 0 ? _a : getStatusCode(route) + "";
4034
+ const reference = {
4035
+ $ref: `#/components/schemas/${type.name}`,
4036
+ };
4037
+ const schema = options.isArray
4038
+ ? { items: reference, type: "array" }
4039
+ : reference;
4040
+ operation.responses = operation.responses || {};
4041
+ operation.responses[statusCode] = {
4042
+ description: options.description || "Success",
4043
+ content: {
4044
+ [contentType]: {
4045
+ schema
4046
+ }
4047
+ }
4048
+ };
4049
+ return operation;
4050
+ });
3949
4051
  }
3950
4052
 
3951
4053
  var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -4492,5 +4594,5 @@ function setupBackend(config, providers, parent) {
4492
4594
  * Generated bundle index. Do not edit.
4493
4595
  */
4494
4596
 
4495
- export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, writeFile, Logger as ɵa };
4597
+ export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, BaseDoc, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, DocumentArray, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsDocumented, IsFile, IsObjectId, JOB, JobManager, JsonResponse, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, OPENAPI_VALIDATION, OpenApi, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, ResponseType, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, createIdString, createServices, createTransformer, deleteFile, deleteFromBucket, filter, firstItem, flatten, getConstructorName, getExtension, getFileName, getFunctionParams, getType, getValue, groupBy, hydratePopulated, idToString, injectServices, isArray, isBoolean, isConstructor, isDate, isDefined, isFunction, isInterface, isNullOrUndefined, isObject, isObjectId, isPrimitive, isString, isType, jsonHighlight, lastItem, lcFirst, letsLookupStage, lookupStages, matchField, matchFieldStages, matchStage, md5, mkdirRecursive, multiSubscription, observableFromFunction, padLeft, padRight, paginate, paginateAggregations, projectStage, promiseTimeout, rand, random, readAndDeleteFile, readFile, regroup, replaceSpecialChars, resolveUser, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, writeFile, Logger as ɵa };
4496
4598
  //# sourceMappingURL=stemy-backend.js.map