@stemy/backend 3.4.0 → 3.4.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.
@@ -2,7 +2,7 @@ import { dirname, basename, join, resolve } from 'path';
2
2
  import { json } from 'body-parser';
3
3
  import { sign, verify } from 'jsonwebtoken';
4
4
  import { injectable, scoped, Lifecycle, injectAll, singleton, inject, isFactoryProvider, container } from 'tsyringe';
5
- import { createParamDecorator, BadRequestError, HttpError, getMetadataArgsStorage, Authorized, Post, UploadedFile, Body, Get, Param, QueryParam, Res, QueryParams, Controller, UnauthorizedError, CurrentUser, Middleware, useContainer, useExpressServer } from 'routing-controllers';
5
+ import { getMetadataArgsStorage, HttpError, Authorized, Post, UploadedFile, Body, Get, Param, QueryParam, Res, QueryParams, Controller, UnauthorizedError, CurrentUser, BadRequestError, Middleware, createParamDecorator, useContainer, useExpressServer } from 'routing-controllers';
6
6
  import { OnMessage, ConnectedSocket, MessageBody, SocketController, Middleware as Middleware$1, useContainer as useContainer$1, useSocketServer } from 'socket-controllers';
7
7
  import { routingControllersToSpec } from 'routing-controllers-openapi';
8
8
  import { defaultMetadataStorage } from 'class-transformer/storage';
@@ -14,8 +14,7 @@ import { Subscription, Observable, Subject, from } from 'rxjs';
14
14
  import { canReportError } from 'rxjs/internal/util/canReportError';
15
15
  import { mkdir, unlink, readFile as readFile$1, writeFile as writeFile$1, lstat, readdir, access, constants, lstatSync, readFileSync, existsSync } from 'fs';
16
16
  import { ObjectId, GridFSBucket } from 'mongodb';
17
- import { Types, model, connect } from 'mongoose';
18
- import { getValue as getValue$1, setValue } from 'mongoose/lib/utils';
17
+ import { Types, connect, model } from 'mongoose';
19
18
  import { Readable, PassThrough } from 'stream';
20
19
  import sharp_ from 'sharp';
21
20
  import { ObjectId as ObjectId$1 } from 'bson';
@@ -34,8 +33,10 @@ import { createTransport } from 'nodemailer';
34
33
  import * as Handlebars from 'handlebars';
35
34
  import { compare } from 'bcrypt';
36
35
  import moment from 'moment';
36
+ import { getModelForClass } from '@typegoose/typegoose';
37
+ import { getValue as getValue$1, setValue } from 'mongoose/lib/utils';
37
38
 
38
- var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
+ var __awaiter$x = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
40
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
41
  return new (P || (P = Promise))(function (resolve, reject) {
41
42
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -187,146 +188,6 @@ function convertValue(value, type) {
187
188
  }
188
189
  return value;
189
190
  }
190
- function injectServices(schema, services) {
191
- const serviceMap = {};
192
- Object.keys(services).forEach(prop => {
193
- schema
194
- .virtual(prop)
195
- .get(() => {
196
- const diContainer = diContainers.appContainer;
197
- serviceMap[prop] = serviceMap[prop] || (!diContainer ? {} : diContainer.resolve(services[prop]));
198
- return serviceMap[prop];
199
- });
200
- });
201
- }
202
- function paginate(model, where, params) {
203
- return model.countDocuments(where).then(count => {
204
- let query = model.find(where);
205
- if (isString(params.sort)) {
206
- query = query.sort(params.sort);
207
- }
208
- if (isArray(params.populate)) {
209
- params.populate.forEach(field => {
210
- query = query.populate(field);
211
- });
212
- }
213
- return (params.limit > 0 ? query.skip(params.page * params.limit).limit(params.limit) : query).then(items => {
214
- const meta = { total: count };
215
- return { count, items, meta };
216
- });
217
- });
218
- }
219
- function lookupStages(from, localField, as = null, foreignField = "_id", shouldUnwind = true) {
220
- as = as || localField.replace("Id", "");
221
- const stages = [
222
- {
223
- $lookup: {
224
- from,
225
- localField,
226
- foreignField,
227
- as
228
- }
229
- },
230
- {
231
- $unwind: {
232
- path: `$${as}`,
233
- preserveNullAndEmptyArrays: true
234
- }
235
- }
236
- ];
237
- if (!shouldUnwind) {
238
- stages.splice(1, 1);
239
- }
240
- return stages;
241
- }
242
- function letsLookupStage(from, pipeline, as = null, letFields = null) {
243
- as = as || from;
244
- letFields = letFields || { id: "$_id" };
245
- return {
246
- $lookup: {
247
- from,
248
- let: letFields,
249
- pipeline,
250
- as
251
- }
252
- };
253
- }
254
- function matchStage(match) {
255
- return { $match: match };
256
- }
257
- function matchField(field, filter, when) {
258
- return { field, filter, when };
259
- }
260
- function matchFieldStages(...fields) {
261
- const match = {};
262
- fields.forEach(field => {
263
- if (field.when) {
264
- match[field.field] = field.filter;
265
- }
266
- });
267
- return Object.keys(match).length > 0 ? [matchStage(match)] : [];
268
- }
269
- function projectStage(fields) {
270
- return { $project: fields };
271
- }
272
- function unwindStage(fieldOrOpts) {
273
- return { $unwind: fieldOrOpts };
274
- }
275
- function hydratePopulated(modelType, json) {
276
- let object = modelType.hydrate(json);
277
- for (const [path, obj] of Object.entries(modelType.schema.obj)) {
278
- let { ref, type } = obj;
279
- if (Array.isArray(type) && type.length > 0) {
280
- ref = type[0].ref;
281
- }
282
- if (!ref)
283
- continue;
284
- const value = getValue$1(path, json);
285
- const hydrateVal = val => {
286
- if (val == null || val instanceof Types.ObjectId)
287
- return val;
288
- return hydratePopulated(model(ref), val);
289
- };
290
- if (Array.isArray(value)) {
291
- setValue(path, value.map(hydrateVal), object);
292
- continue;
293
- }
294
- setValue(path, hydrateVal(value), object);
295
- }
296
- return object;
297
- }
298
- function paginateAggregations(model, aggregations, params, metaProjection = {}) {
299
- return __awaiter$w(this, void 0, void 0, function* () {
300
- const sortField = !isString(params.sort) || !params.sort ? null : (params.sort.startsWith("-") ? params.sort.substr(1) : params.sort);
301
- const sortAggregation = !sortField ? [] : [{
302
- $sort: { [sortField]: sortField == params.sort ? 1 : -1 }
303
- }];
304
- const result = yield model.aggregate([
305
- ...aggregations,
306
- ...sortAggregation,
307
- {
308
- $group: {
309
- _id: "results",
310
- result: { $push: "$$CURRENT" }
311
- }
312
- },
313
- {
314
- $project: {
315
- _id: 0,
316
- items: params.limit > 0 ? { $slice: ["$result", params.page * params.limit, params.limit] } : "$result",
317
- count: { $size: "$result" },
318
- meta: Object.assign({ total: { $size: "$result" } }, metaProjection)
319
- }
320
- }
321
- ]);
322
- const pagination = result[0];
323
- if (!pagination) {
324
- return { items: [], count: 0, meta: { total: 0 } };
325
- }
326
- pagination.items = pagination.items.map(i => hydratePopulated(model, i));
327
- return pagination;
328
- });
329
- }
330
191
  const cropInterface = {
331
192
  x: "number",
332
193
  y: "number",
@@ -353,7 +214,7 @@ function toCropRegion(cropInfo) {
353
214
  };
354
215
  }
355
216
  function toImage(src, params, meta) {
356
- return __awaiter$w(this, void 0, void 0, function* () {
217
+ return __awaiter$x(this, void 0, void 0, function* () {
357
218
  // Default params and meta
358
219
  params = params || {};
359
220
  meta = meta || {};
@@ -491,7 +352,7 @@ function readFile(path) {
491
352
  });
492
353
  }
493
354
  function readAndDeleteFile(path, timeout = 5000) {
494
- return __awaiter$w(this, void 0, void 0, function* () {
355
+ return __awaiter$x(this, void 0, void 0, function* () {
495
356
  const data = yield readFile(path);
496
357
  setTimeout(() => {
497
358
  unlink(path, () => {
@@ -501,7 +362,7 @@ function readAndDeleteFile(path, timeout = 5000) {
501
362
  });
502
363
  }
503
364
  function writeFile(path, data) {
504
- return __awaiter$w(this, void 0, void 0, function* () {
365
+ return __awaiter$x(this, void 0, void 0, function* () {
505
366
  yield mkdirRecursive(dirname(path));
506
367
  return new Promise((res, rej) => {
507
368
  writeFile$1(path, data, err => {
@@ -556,43 +417,6 @@ function getFunctionParams(func) {
556
417
  });
557
418
  return params;
558
419
  }
559
- function ResolveEntity(model, extraCheck) {
560
- const modelName = model.modelName;
561
- const paramName = modelName.toLowerCase();
562
- return createParamDecorator({
563
- required: false,
564
- value: (action) => __awaiter$w(this, void 0, void 0, function* () {
565
- const req = action.request;
566
- const token = req.header(`x-${paramName}-token`);
567
- const id = req.params[`${paramName}Id`];
568
- if (!id && !token) {
569
- throw new BadRequestError(`${modelName} id or token should be defined!`);
570
- }
571
- const query = !token
572
- ? model.findById(id)
573
- : model.findOne({ token });
574
- let doc = null;
575
- if (isFunction(extraCheck)) {
576
- try {
577
- doc = yield valueToPromise(extraCheck(query, action));
578
- }
579
- catch (e) {
580
- throw new BadRequestError(`${modelName} check error: ${e.message || e}`);
581
- }
582
- }
583
- else {
584
- doc = yield query;
585
- }
586
- if (!doc) {
587
- throw new HttpError(404, !token
588
- ? `${modelName} could not be found with id: ${id}`
589
- : `${modelName} could not be found with token: ${token}`);
590
- }
591
- action.request[paramName] = doc;
592
- return doc;
593
- })
594
- });
595
- }
596
420
  function getFileName(path, withExtension = false) {
597
421
  const name = basename(path || "");
598
422
  return withExtension ? name : name.split(".").slice(0, -1).join(".");
@@ -957,7 +781,7 @@ var __decorate$x = (this && this.__decorate) || function (decorators, target, ke
957
781
  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;
958
782
  return c > 3 && r && Object.defineProperty(target, key, r), r;
959
783
  };
960
- var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
784
+ var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
961
785
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
962
786
  return new (P || (P = Promise))(function (resolve, reject) {
963
787
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -993,7 +817,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
993
817
  }
994
818
  static fileTypeFromBuffer(buffer) {
995
819
  var _a;
996
- return __awaiter$v(this, void 0, void 0, function* () {
820
+ return __awaiter$w(this, void 0, void 0, function* () {
997
821
  const type = ((_a = yield fromBuffer(buffer)) !== null && _a !== void 0 ? _a : { ext: "txt", mime: "text/plain" });
998
822
  if (AssetProcessor_1.checkTextFileType(type)) {
999
823
  return AssetProcessor_1.fixTextFileType(type, buffer);
@@ -1020,7 +844,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
1020
844
  return imageTypes.indexOf(contentType) >= 0;
1021
845
  }
1022
846
  static copyImageMeta(buffer, metadata, fileType) {
1023
- return __awaiter$v(this, void 0, void 0, function* () {
847
+ return __awaiter$w(this, void 0, void 0, function* () {
1024
848
  if (fileType.mime === "image/svg+xml") {
1025
849
  const match = /<svg([^<>]+)>/gi.exec(buffer.toString("utf8"));
1026
850
  if (match && match.length > 1) {
@@ -1059,7 +883,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
1059
883
  });
1060
884
  }
1061
885
  process(buffer, metadata, fileType) {
1062
- return __awaiter$v(this, void 0, void 0, function* () {
886
+ return __awaiter$w(this, void 0, void 0, function* () {
1063
887
  if (AssetProcessor_1.isImage(fileType.mime)) {
1064
888
  buffer = yield AssetProcessor_1.copyImageMeta(buffer, metadata, fileType);
1065
889
  }
@@ -1136,7 +960,7 @@ var __decorate$v = (this && this.__decorate) || function (decorators, target, ke
1136
960
  var __metadata$p = (this && this.__metadata) || function (k, v) {
1137
961
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1138
962
  };
1139
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
963
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1140
964
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1141
965
  return new (P || (P = Promise))(function (resolve, reject) {
1142
966
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1162,7 +986,7 @@ let MongoConnector = class MongoConnector {
1162
986
  return this.fsBucket;
1163
987
  }
1164
988
  connect() {
1165
- return __awaiter$u(this, void 0, void 0, function* () {
989
+ return __awaiter$v(this, void 0, void 0, function* () {
1166
990
  if (this.db)
1167
991
  return this.db;
1168
992
  this.conn = (yield connect(this.configuration.resolve("mongoUri"), {
@@ -1182,7 +1006,7 @@ MongoConnector = __decorate$v([
1182
1006
  __metadata$p("design:paramtypes", [Configuration])
1183
1007
  ], MongoConnector);
1184
1008
 
1185
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1009
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1186
1010
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1187
1011
  return new (P || (P = Promise))(function (resolve, reject) {
1188
1012
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1204,7 +1028,7 @@ class BaseEntity {
1204
1028
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1205
1029
  }
1206
1030
  load() {
1207
- return __awaiter$t(this, void 0, void 0, function* () {
1031
+ return __awaiter$u(this, void 0, void 0, function* () {
1208
1032
  const res = yield this.collection.findOne({ _id: this.mId });
1209
1033
  this.deleted = !res;
1210
1034
  this.data = res || {};
@@ -1219,7 +1043,7 @@ class BaseEntity {
1219
1043
  }
1220
1044
  }
1221
1045
 
1222
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1046
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1223
1047
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1224
1048
  return new (P || (P = Promise))(function (resolve, reject) {
1225
1049
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1246,7 +1070,7 @@ class Asset extends BaseEntity {
1246
1070
  return this.bucket.openDownloadStream(this.mId);
1247
1071
  }
1248
1072
  unlink() {
1249
- return __awaiter$s(this, void 0, void 0, function* () {
1073
+ return __awaiter$t(this, void 0, void 0, function* () {
1250
1074
  return deleteFromBucket(this.bucket, this.mId);
1251
1075
  });
1252
1076
  }
@@ -1254,7 +1078,7 @@ class Asset extends BaseEntity {
1254
1078
  return streamToBuffer(this.stream);
1255
1079
  }
1256
1080
  download(metadata) {
1257
- return __awaiter$s(this, void 0, void 0, function* () {
1081
+ return __awaiter$t(this, void 0, void 0, function* () {
1258
1082
  metadata = Object.assign(this.metadata, metadata || {});
1259
1083
  metadata.downloadCount = isNaN(metadata.downloadCount) || !metadata.firstDownload
1260
1084
  ? 1
@@ -1266,18 +1090,18 @@ class Asset extends BaseEntity {
1266
1090
  });
1267
1091
  }
1268
1092
  getImage(params = null) {
1269
- return __awaiter$s(this, void 0, void 0, function* () {
1093
+ return __awaiter$t(this, void 0, void 0, function* () {
1270
1094
  return toImage(this.stream, params, this.metadata);
1271
1095
  });
1272
1096
  }
1273
1097
  downloadImage(params, metadata) {
1274
- return __awaiter$s(this, void 0, void 0, function* () {
1098
+ return __awaiter$t(this, void 0, void 0, function* () {
1275
1099
  return toImage(yield this.download(metadata), params, this.metadata);
1276
1100
  });
1277
1101
  }
1278
1102
  }
1279
1103
 
1280
- var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1104
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1281
1105
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1282
1106
  return new (P || (P = Promise))(function (resolve, reject) {
1283
1107
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1298,17 +1122,17 @@ class TempAsset {
1298
1122
  return bufferToStream(this.buffer);
1299
1123
  }
1300
1124
  unlink() {
1301
- return __awaiter$r(this, void 0, void 0, function* () {
1125
+ return __awaiter$s(this, void 0, void 0, function* () {
1302
1126
  throw new Error(`Temp asset '${this.id}' can not be removed!`);
1303
1127
  });
1304
1128
  }
1305
1129
  getBuffer() {
1306
- return __awaiter$r(this, void 0, void 0, function* () {
1130
+ return __awaiter$s(this, void 0, void 0, function* () {
1307
1131
  return this.buffer;
1308
1132
  });
1309
1133
  }
1310
1134
  download(metadata) {
1311
- return __awaiter$r(this, void 0, void 0, function* () {
1135
+ return __awaiter$s(this, void 0, void 0, function* () {
1312
1136
  return this.stream;
1313
1137
  });
1314
1138
  }
@@ -1320,12 +1144,12 @@ class TempAsset {
1320
1144
  return this.downloadImage(params);
1321
1145
  }
1322
1146
  save() {
1323
- return __awaiter$r(this, void 0, void 0, function* () {
1147
+ return __awaiter$s(this, void 0, void 0, function* () {
1324
1148
  return this;
1325
1149
  });
1326
1150
  }
1327
1151
  load() {
1328
- return __awaiter$r(this, void 0, void 0, function* () {
1152
+ return __awaiter$s(this, void 0, void 0, function* () {
1329
1153
  return this;
1330
1154
  });
1331
1155
  }
@@ -1348,7 +1172,7 @@ var __decorate$u = (this && this.__decorate) || function (decorators, target, ke
1348
1172
  var __metadata$o = (this && this.__metadata) || function (k, v) {
1349
1173
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1350
1174
  };
1351
- var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1175
+ var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1352
1176
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1353
1177
  return new (P || (P = Promise))(function (resolve, reject) {
1354
1178
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1366,7 +1190,7 @@ let Assets = class Assets {
1366
1190
  this.collection = (_a = connector.database) === null || _a === void 0 ? void 0 : _a.collection("assets.files");
1367
1191
  }
1368
1192
  write(stream, contentType = null, metadata = null) {
1369
- return __awaiter$q(this, void 0, void 0, function* () {
1193
+ return __awaiter$r(this, void 0, void 0, function* () {
1370
1194
  const uploadStream = copyStream(stream);
1371
1195
  const buffer = yield streamToBuffer(stream);
1372
1196
  let fileType = { ext: "", mime: contentType };
@@ -1384,7 +1208,7 @@ let Assets = class Assets {
1384
1208
  });
1385
1209
  }
1386
1210
  writeBuffer(buffer, metadata = null, contentType = null) {
1387
- return __awaiter$q(this, void 0, void 0, function* () {
1211
+ return __awaiter$r(this, void 0, void 0, function* () {
1388
1212
  let fileType = { ext: "", mime: contentType };
1389
1213
  try {
1390
1214
  fileType = yield AssetProcessor.fileTypeFromBuffer(buffer);
@@ -1401,13 +1225,13 @@ let Assets = class Assets {
1401
1225
  });
1402
1226
  }
1403
1227
  writeUrl(url, metadata = null) {
1404
- return __awaiter$q(this, void 0, void 0, function* () {
1228
+ return __awaiter$r(this, void 0, void 0, function* () {
1405
1229
  const buffer = (yield axios({ url, responseType: "arraybuffer" })).data;
1406
1230
  return this.writeBuffer(buffer, metadata);
1407
1231
  });
1408
1232
  }
1409
1233
  download(url, contentType = null) {
1410
- return __awaiter$q(this, void 0, void 0, function* () {
1234
+ return __awaiter$r(this, void 0, void 0, function* () {
1411
1235
  let buffer = (yield axios({ url, responseType: "arraybuffer" })).data;
1412
1236
  let fileType = { ext: "", mime: contentType };
1413
1237
  try {
@@ -1428,18 +1252,18 @@ let Assets = class Assets {
1428
1252
  });
1429
1253
  }
1430
1254
  read(id) {
1431
- return __awaiter$q(this, void 0, void 0, function* () {
1255
+ return __awaiter$r(this, void 0, void 0, function* () {
1432
1256
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
1433
1257
  });
1434
1258
  }
1435
1259
  find(where) {
1436
- return __awaiter$q(this, void 0, void 0, function* () {
1260
+ return __awaiter$r(this, void 0, void 0, function* () {
1437
1261
  const data = yield this.collection.findOne(where);
1438
1262
  return !data ? null : new Asset(data._id, data, this.collection, this.bucket);
1439
1263
  });
1440
1264
  }
1441
1265
  findMany(where) {
1442
- return __awaiter$q(this, void 0, void 0, function* () {
1266
+ return __awaiter$r(this, void 0, void 0, function* () {
1443
1267
  const cursor = this.collection.find(where);
1444
1268
  const items = (yield cursor.toArray()) || [];
1445
1269
  const result = [];
@@ -1452,13 +1276,13 @@ let Assets = class Assets {
1452
1276
  });
1453
1277
  }
1454
1278
  deleteMany(where) {
1455
- return __awaiter$q(this, void 0, void 0, function* () {
1279
+ return __awaiter$r(this, void 0, void 0, function* () {
1456
1280
  const assets = yield this.findMany(where);
1457
1281
  return Promise.all(assets.map(a => a.unlink()));
1458
1282
  });
1459
1283
  }
1460
1284
  unlink(id) {
1461
- return __awaiter$q(this, void 0, void 0, function* () {
1285
+ return __awaiter$r(this, void 0, void 0, function* () {
1462
1286
  const asset = yield this.read(id);
1463
1287
  if (!asset)
1464
1288
  return null;
@@ -1466,7 +1290,7 @@ let Assets = class Assets {
1466
1290
  });
1467
1291
  }
1468
1292
  upload(stream, fileType, metadata) {
1469
- return __awaiter$q(this, void 0, void 0, function* () {
1293
+ return __awaiter$r(this, void 0, void 0, function* () {
1470
1294
  const contentType = fileType.mime.trim();
1471
1295
  metadata = Object.assign({
1472
1296
  downloadCount: 0,
@@ -1503,7 +1327,7 @@ Assets = __decorate$u([
1503
1327
  __metadata$o("design:paramtypes", [MongoConnector, AssetProcessor])
1504
1328
  ], Assets);
1505
1329
 
1506
- var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1330
+ var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1507
1331
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1508
1332
  return new (P || (P = Promise))(function (resolve, reject) {
1509
1333
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1534,7 +1358,7 @@ class LazyAsset extends BaseEntity {
1534
1358
  return this.data.assetId;
1535
1359
  }
1536
1360
  unlink() {
1537
- return __awaiter$p(this, void 0, void 0, function* () {
1361
+ return __awaiter$q(this, void 0, void 0, function* () {
1538
1362
  yield this.load();
1539
1363
  if (!this.progressId) {
1540
1364
  yield this.collection.deleteOne({ _id: this.mId });
@@ -1557,7 +1381,7 @@ class LazyAsset extends BaseEntity {
1557
1381
  });
1558
1382
  }
1559
1383
  loadAsset() {
1560
- return __awaiter$p(this, void 0, void 0, function* () {
1384
+ return __awaiter$q(this, void 0, void 0, function* () {
1561
1385
  yield this.load();
1562
1386
  if (this.deleted)
1563
1387
  return null;
@@ -1573,14 +1397,14 @@ class LazyAsset extends BaseEntity {
1573
1397
  });
1574
1398
  }
1575
1399
  writeAsset(asset) {
1576
- return __awaiter$p(this, void 0, void 0, function* () {
1400
+ return __awaiter$q(this, void 0, void 0, function* () {
1577
1401
  this.data.assetId = asset.id;
1578
1402
  yield this.save();
1579
1403
  return asset;
1580
1404
  });
1581
1405
  }
1582
1406
  startWorkingOnAsset(fromLoad) {
1583
- return __awaiter$p(this, void 0, void 0, function* () {
1407
+ return __awaiter$q(this, void 0, void 0, function* () {
1584
1408
  this.data.progressId = (yield this.progresses.create()).id;
1585
1409
  this.data.assetId = null;
1586
1410
  yield this.save();
@@ -1601,7 +1425,7 @@ var __metadata$n = (this && this.__metadata) || function (k, v) {
1601
1425
  var __param$7 = (this && this.__param) || function (paramIndex, decorator) {
1602
1426
  return function (target, key) { decorator(target, key, paramIndex); }
1603
1427
  };
1604
- var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1428
+ var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1605
1429
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1606
1430
  return new (P || (P = Promise))(function (resolve, reject) {
1607
1431
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1640,7 +1464,7 @@ let JobManager = class JobManager {
1640
1464
  .pipe(map(t => t.params)).subscribe(cb);
1641
1465
  }
1642
1466
  process(jobType, params = {}) {
1643
- return __awaiter$o(this, void 0, void 0, function* () {
1467
+ return __awaiter$p(this, void 0, void 0, function* () {
1644
1468
  let instance = null;
1645
1469
  try {
1646
1470
  instance = this.resolveJobInstance(jobType, params);
@@ -1653,12 +1477,12 @@ let JobManager = class JobManager {
1653
1477
  });
1654
1478
  }
1655
1479
  enqueueWithName(name, params = {}) {
1656
- return __awaiter$o(this, void 0, void 0, function* () {
1480
+ return __awaiter$p(this, void 0, void 0, function* () {
1657
1481
  return this.sendToWorkers(this.tryResolveFromName(name, params), params);
1658
1482
  });
1659
1483
  }
1660
1484
  enqueue(jobType, params = {}) {
1661
- return __awaiter$o(this, void 0, void 0, function* () {
1485
+ return __awaiter$p(this, void 0, void 0, function* () {
1662
1486
  return this.sendToWorkers(this.tryResolveAndInit(jobType, params), params);
1663
1487
  });
1664
1488
  }
@@ -1685,7 +1509,7 @@ let JobManager = class JobManager {
1685
1509
  });
1686
1510
  }
1687
1511
  startProcessing() {
1688
- return __awaiter$o(this, void 0, void 0, function* () {
1512
+ return __awaiter$p(this, void 0, void 0, function* () {
1689
1513
  if (this.processing)
1690
1514
  return null;
1691
1515
  this.processing = true;
@@ -1702,7 +1526,7 @@ let JobManager = class JobManager {
1702
1526
  this.workerPull = socket("pull");
1703
1527
  yield this.workerPull.connect(pullHost);
1704
1528
  console.log(`Worker consumer connected to: ${pullHost}`);
1705
- this.workerPull.on("message", (name, args, uniqId) => __awaiter$o(this, void 0, void 0, function* () {
1529
+ this.workerPull.on("message", (name, args, uniqId) => __awaiter$p(this, void 0, void 0, function* () {
1706
1530
  try {
1707
1531
  const jobName = name.toString("utf8");
1708
1532
  const jobParams = JSON.parse(args.toString("utf8"));
@@ -1781,7 +1605,7 @@ let JobManager = class JobManager {
1781
1605
  return container.resolve(jobType);
1782
1606
  }
1783
1607
  sendToWorkers(jobName, params) {
1784
- return __awaiter$o(this, void 0, void 0, function* () {
1608
+ return __awaiter$p(this, void 0, void 0, function* () {
1785
1609
  const publisher = yield this.apiPush;
1786
1610
  const uniqueId = new ObjectId$1().toHexString();
1787
1611
  yield publisher.send([jobName, JSON.stringify(params), uniqueId]);
@@ -1796,7 +1620,7 @@ JobManager = __decorate$t([
1796
1620
  __metadata$n("design:paramtypes", [Configuration, Object, Array])
1797
1621
  ], JobManager);
1798
1622
 
1799
- var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1623
+ var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1800
1624
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1801
1625
  return new (P || (P = Promise))(function (resolve, reject) {
1802
1626
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1835,7 +1659,7 @@ class Progress extends BaseEntity {
1835
1659
  return this;
1836
1660
  }
1837
1661
  createSubProgress(progressValue, max, message) {
1838
- return __awaiter$n(this, void 0, void 0, function* () {
1662
+ return __awaiter$o(this, void 0, void 0, function* () {
1839
1663
  if (max <= 0 && progressValue > 0) {
1840
1664
  yield this.advance(progressValue);
1841
1665
  }
@@ -1847,7 +1671,7 @@ class Progress extends BaseEntity {
1847
1671
  });
1848
1672
  }
1849
1673
  setMax(max) {
1850
- return __awaiter$n(this, void 0, void 0, function* () {
1674
+ return __awaiter$o(this, void 0, void 0, function* () {
1851
1675
  if (isNaN(max) || max <= 0) {
1852
1676
  throw "Max progress value must be bigger than zero";
1853
1677
  }
@@ -1856,19 +1680,19 @@ class Progress extends BaseEntity {
1856
1680
  });
1857
1681
  }
1858
1682
  setMessage(message) {
1859
- return __awaiter$n(this, void 0, void 0, function* () {
1683
+ return __awaiter$o(this, void 0, void 0, function* () {
1860
1684
  this.data.message = message;
1861
1685
  yield this.save();
1862
1686
  });
1863
1687
  }
1864
1688
  setError(error) {
1865
- return __awaiter$n(this, void 0, void 0, function* () {
1689
+ return __awaiter$o(this, void 0, void 0, function* () {
1866
1690
  this.data.error = error;
1867
1691
  yield this.save();
1868
1692
  });
1869
1693
  }
1870
1694
  advance(value = 1) {
1871
- return __awaiter$n(this, void 0, void 0, function* () {
1695
+ return __awaiter$o(this, void 0, void 0, function* () {
1872
1696
  if (isNaN(value) || value <= 0) {
1873
1697
  throw "Advance value must be bigger than zero";
1874
1698
  }
@@ -1880,7 +1704,7 @@ class Progress extends BaseEntity {
1880
1704
  });
1881
1705
  }
1882
1706
  cancel() {
1883
- return __awaiter$n(this, void 0, void 0, function* () {
1707
+ return __awaiter$o(this, void 0, void 0, function* () {
1884
1708
  this.data.canceled = true;
1885
1709
  yield this.save();
1886
1710
  });
@@ -1937,7 +1761,7 @@ class SubProgress {
1937
1761
  return this;
1938
1762
  }
1939
1763
  createSubProgress(progressValue, max, message) {
1940
- return __awaiter$n(this, void 0, void 0, function* () {
1764
+ return __awaiter$o(this, void 0, void 0, function* () {
1941
1765
  if (max <= 0 && progressValue > 0) {
1942
1766
  yield this.advance(progressValue);
1943
1767
  }
@@ -1948,7 +1772,7 @@ class SubProgress {
1948
1772
  });
1949
1773
  }
1950
1774
  setMax(max) {
1951
- return __awaiter$n(this, void 0, void 0, function* () {
1775
+ return __awaiter$o(this, void 0, void 0, function* () {
1952
1776
  if (isNaN(max) || max <= 0) {
1953
1777
  throw "Max progress value must be bigger than zero";
1954
1778
  }
@@ -1957,21 +1781,21 @@ class SubProgress {
1957
1781
  });
1958
1782
  }
1959
1783
  setMessage(message) {
1960
- return __awaiter$n(this, void 0, void 0, function* () {
1784
+ return __awaiter$o(this, void 0, void 0, function* () {
1961
1785
  if (!this.parent)
1962
1786
  return null;
1963
1787
  yield this.parent.setMessage(message);
1964
1788
  });
1965
1789
  }
1966
1790
  setError(error) {
1967
- return __awaiter$n(this, void 0, void 0, function* () {
1791
+ return __awaiter$o(this, void 0, void 0, function* () {
1968
1792
  if (!this.parent)
1969
1793
  return null;
1970
1794
  yield this.parent.setError(error);
1971
1795
  });
1972
1796
  }
1973
1797
  advance(value = 1) {
1974
- return __awaiter$n(this, void 0, void 0, function* () {
1798
+ return __awaiter$o(this, void 0, void 0, function* () {
1975
1799
  if (isNaN(value) || value <= 0) {
1976
1800
  throw "Advance value must be bigger than zero";
1977
1801
  }
@@ -1980,14 +1804,14 @@ class SubProgress {
1980
1804
  });
1981
1805
  }
1982
1806
  cancel() {
1983
- return __awaiter$n(this, void 0, void 0, function* () {
1807
+ return __awaiter$o(this, void 0, void 0, function* () {
1984
1808
  if (!this.parent)
1985
1809
  return null;
1986
1810
  yield this.parent.cancel();
1987
1811
  });
1988
1812
  }
1989
1813
  save() {
1990
- return __awaiter$n(this, void 0, void 0, function* () {
1814
+ return __awaiter$o(this, void 0, void 0, function* () {
1991
1815
  const ratio = this.max > 0 ? this.mCurrent / this.max : 0;
1992
1816
  const newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
1993
1817
  const current = this.parent.current;
@@ -1997,7 +1821,7 @@ class SubProgress {
1997
1821
  });
1998
1822
  }
1999
1823
  load() {
2000
- return __awaiter$n(this, void 0, void 0, function* () {
1824
+ return __awaiter$o(this, void 0, void 0, function* () {
2001
1825
  return null;
2002
1826
  });
2003
1827
  }
@@ -2015,7 +1839,7 @@ var __decorate$s = (this && this.__decorate) || function (decorators, target, ke
2015
1839
  var __metadata$m = (this && this.__metadata) || function (k, v) {
2016
1840
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2017
1841
  };
2018
- var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1842
+ var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2019
1843
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2020
1844
  return new (P || (P = Promise))(function (resolve, reject) {
2021
1845
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2036,9 +1860,9 @@ let Progresses = class Progresses {
2036
1860
  });
2037
1861
  }
2038
1862
  waitToFinish(id) {
2039
- return __awaiter$m(this, void 0, void 0, function* () {
1863
+ return __awaiter$n(this, void 0, void 0, function* () {
2040
1864
  return Promise.race([
2041
- this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
1865
+ this.waitForProgress(id, () => __awaiter$n(this, void 0, void 0, function* () {
2042
1866
  let progress = this.progresses[id];
2043
1867
  if (!progress || progress.percent < 100) {
2044
1868
  progress = yield this.get(id);
@@ -2048,25 +1872,25 @@ let Progresses = class Progresses {
2048
1872
  }
2049
1873
  return progress;
2050
1874
  }), 500),
2051
- this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
1875
+ this.waitForProgress(id, () => __awaiter$n(this, void 0, void 0, function* () {
2052
1876
  return this.progresses[id] || null;
2053
1877
  }), 25)
2054
1878
  ]);
2055
1879
  });
2056
1880
  }
2057
1881
  get(id) {
2058
- return __awaiter$m(this, void 0, void 0, function* () {
1882
+ return __awaiter$n(this, void 0, void 0, function* () {
2059
1883
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
2060
1884
  });
2061
1885
  }
2062
1886
  find(where) {
2063
- return __awaiter$m(this, void 0, void 0, function* () {
1887
+ return __awaiter$n(this, void 0, void 0, function* () {
2064
1888
  const data = yield this.collection.findOne(where);
2065
1889
  return !data ? null : new Progress(data._id, data, this.collection);
2066
1890
  });
2067
1891
  }
2068
1892
  create(max = 100) {
2069
- return __awaiter$m(this, void 0, void 0, function* () {
1893
+ return __awaiter$n(this, void 0, void 0, function* () {
2070
1894
  if (isNaN(max) || max <= 0) {
2071
1895
  throw new Error(`Max progress value must be bigger than zero`);
2072
1896
  }
@@ -2082,13 +1906,13 @@ let Progresses = class Progresses {
2082
1906
  });
2083
1907
  }
2084
1908
  remove(id) {
2085
- return __awaiter$m(this, void 0, void 0, function* () {
1909
+ return __awaiter$n(this, void 0, void 0, function* () {
2086
1910
  yield this.collection.deleteOne({ _id: new ObjectId$1(id) });
2087
1911
  return id;
2088
1912
  });
2089
1913
  }
2090
1914
  waitForProgress(id, cb, delay) {
2091
- return __awaiter$m(this, void 0, void 0, function* () {
1915
+ return __awaiter$n(this, void 0, void 0, function* () {
2092
1916
  let isFinished = false;
2093
1917
  let progress = null;
2094
1918
  let waitTime = 0;
@@ -2127,7 +1951,7 @@ var __decorate$r = (this && this.__decorate) || function (decorators, target, ke
2127
1951
  var __metadata$l = (this && this.__metadata) || function (k, v) {
2128
1952
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2129
1953
  };
2130
- var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1954
+ var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2131
1955
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2132
1956
  return new (P || (P = Promise))(function (resolve, reject) {
2133
1957
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2145,7 +1969,7 @@ let LazyAssets = class LazyAssets {
2145
1969
  this.collection = connector.database.collection("lazyassets");
2146
1970
  }
2147
1971
  create(jobType, jobParams = {}, jobQue = "main") {
2148
- return __awaiter$l(this, void 0, void 0, function* () {
1972
+ return __awaiter$m(this, void 0, void 0, function* () {
2149
1973
  const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
2150
1974
  const data = {
2151
1975
  jobName,
@@ -2160,12 +1984,12 @@ let LazyAssets = class LazyAssets {
2160
1984
  });
2161
1985
  }
2162
1986
  read(id) {
2163
- return __awaiter$l(this, void 0, void 0, function* () {
1987
+ return __awaiter$m(this, void 0, void 0, function* () {
2164
1988
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
2165
1989
  });
2166
1990
  }
2167
1991
  find(where) {
2168
- return __awaiter$l(this, void 0, void 0, function* () {
1992
+ return __awaiter$m(this, void 0, void 0, function* () {
2169
1993
  const data = yield this.collection.findOne(where);
2170
1994
  return !data
2171
1995
  ? null
@@ -2173,7 +1997,7 @@ let LazyAssets = class LazyAssets {
2173
1997
  });
2174
1998
  }
2175
1999
  unlink(id) {
2176
- return __awaiter$l(this, void 0, void 0, function* () {
2000
+ return __awaiter$m(this, void 0, void 0, function* () {
2177
2001
  const asset = yield this.read(id);
2178
2002
  if (!asset)
2179
2003
  return null;
@@ -2199,7 +2023,7 @@ var __decorate$q = (this && this.__decorate) || function (decorators, target, ke
2199
2023
  var __metadata$k = (this && this.__metadata) || function (k, v) {
2200
2024
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2201
2025
  };
2202
- var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2026
+ var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2203
2027
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2204
2028
  return new (P || (P = Promise))(function (resolve, reject) {
2205
2029
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2214,7 +2038,7 @@ let AssetResolver = class AssetResolver {
2214
2038
  this.lazyAssets = lazyAssets;
2215
2039
  }
2216
2040
  resolve(id, lazy = false) {
2217
- return __awaiter$k(this, void 0, void 0, function* () {
2041
+ return __awaiter$l(this, void 0, void 0, function* () {
2218
2042
  let asset = null;
2219
2043
  if (lazy) {
2220
2044
  const lazyAsset = yield this.lazyAssets.read(id);
@@ -2272,7 +2096,7 @@ var __decorate$o = (this && this.__decorate) || function (decorators, target, ke
2272
2096
  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;
2273
2097
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2274
2098
  };
2275
- var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2099
+ var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2276
2100
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2277
2101
  return new (P || (P = Promise))(function (resolve, reject) {
2278
2102
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2283,12 +2107,12 @@ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P,
2283
2107
  };
2284
2108
  let CacheProcessor = class CacheProcessor {
2285
2109
  serialize(data) {
2286
- return __awaiter$j(this, void 0, void 0, function* () {
2110
+ return __awaiter$k(this, void 0, void 0, function* () {
2287
2111
  return data;
2288
2112
  });
2289
2113
  }
2290
2114
  deserialize(data) {
2291
- return __awaiter$j(this, void 0, void 0, function* () {
2115
+ return __awaiter$k(this, void 0, void 0, function* () {
2292
2116
  return data;
2293
2117
  });
2294
2118
  }
@@ -2307,7 +2131,7 @@ var __decorate$n = (this && this.__decorate) || function (decorators, target, ke
2307
2131
  var __metadata$i = (this && this.__metadata) || function (k, v) {
2308
2132
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2309
2133
  };
2310
- var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2134
+ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2311
2135
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2312
2136
  return new (P || (P = Promise))(function (resolve, reject) {
2313
2137
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2323,7 +2147,7 @@ let Cache = class Cache {
2323
2147
  this.cacheProcessor = cacheProcessor;
2324
2148
  }
2325
2149
  prepare() {
2326
- return __awaiter$i(this, void 0, void 0, function* () {
2150
+ return __awaiter$j(this, void 0, void 0, function* () {
2327
2151
  if (this.collection)
2328
2152
  return;
2329
2153
  if (!this.connector.database) {
@@ -2334,7 +2158,7 @@ let Cache = class Cache {
2334
2158
  });
2335
2159
  }
2336
2160
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2337
- return __awaiter$i(this, void 0, void 0, function* () {
2161
+ return __awaiter$j(this, void 0, void 0, function* () {
2338
2162
  yield this.prepare();
2339
2163
  const item = {
2340
2164
  _id: key,
@@ -2351,7 +2175,7 @@ let Cache = class Cache {
2351
2175
  });
2352
2176
  }
2353
2177
  get(key) {
2354
- return __awaiter$i(this, void 0, void 0, function* () {
2178
+ return __awaiter$j(this, void 0, void 0, function* () {
2355
2179
  yield this.prepare();
2356
2180
  let item = yield this.collection.findOne({ _id: key });
2357
2181
  const now = Math.round(new Date().getTime() / 1000);
@@ -2365,7 +2189,7 @@ let Cache = class Cache {
2365
2189
  });
2366
2190
  }
2367
2191
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
2368
- return __awaiter$i(this, void 0, void 0, function* () {
2192
+ return __awaiter$j(this, void 0, void 0, function* () {
2369
2193
  try {
2370
2194
  return yield this.get(key);
2371
2195
  }
@@ -2375,7 +2199,7 @@ let Cache = class Cache {
2375
2199
  });
2376
2200
  }
2377
2201
  delete(key) {
2378
- return __awaiter$i(this, void 0, void 0, function* () {
2202
+ return __awaiter$j(this, void 0, void 0, function* () {
2379
2203
  yield this.prepare();
2380
2204
  yield this.collection.deleteOne({ _id: key });
2381
2205
  });
@@ -2393,7 +2217,7 @@ var __decorate$m = (this && this.__decorate) || function (decorators, target, ke
2393
2217
  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;
2394
2218
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2395
2219
  };
2396
- var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2220
+ var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2397
2221
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2398
2222
  return new (P || (P = Promise))(function (resolve, reject) {
2399
2223
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2404,7 +2228,7 @@ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P,
2404
2228
  };
2405
2229
  let EndpointProvider = class EndpointProvider {
2406
2230
  configure(app) {
2407
- return __awaiter$h(this, void 0, void 0, function* () {
2231
+ return __awaiter$i(this, void 0, void 0, function* () {
2408
2232
  console.log(`Express app is mounted to: ${app.mountpath}`);
2409
2233
  });
2410
2234
  }
@@ -2426,7 +2250,7 @@ var __metadata$h = (this && this.__metadata) || function (k, v) {
2426
2250
  var __param$6 = (this && this.__param) || function (paramIndex, decorator) {
2427
2251
  return function (target, key) { decorator(target, key, paramIndex); }
2428
2252
  };
2429
- var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2253
+ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2430
2254
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2431
2255
  return new (P || (P = Promise))(function (resolve, reject) {
2432
2256
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2440,7 +2264,7 @@ let Fixtures = class Fixtures {
2440
2264
  this.fixtures = fixtures;
2441
2265
  }
2442
2266
  load() {
2443
- return __awaiter$g(this, void 0, void 0, function* () {
2267
+ return __awaiter$h(this, void 0, void 0, function* () {
2444
2268
  if (!this.fixtures)
2445
2269
  return;
2446
2270
  for (let fixture of this.fixtures) {
@@ -2456,7 +2280,7 @@ Fixtures = __decorate$l([
2456
2280
  __metadata$h("design:paramtypes", [Array])
2457
2281
  ], Fixtures);
2458
2282
 
2459
- var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2283
+ var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2460
2284
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2461
2285
  return new (P || (P = Promise))(function (resolve, reject) {
2462
2286
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2477,7 +2301,7 @@ class GalleryImage {
2477
2301
  this.targetSize = !size ? { width: thumbSize, height: thumbSize } : size;
2478
2302
  }
2479
2303
  serve(id) {
2480
- return __awaiter$f(this, void 0, void 0, function* () {
2304
+ return __awaiter$g(this, void 0, void 0, function* () {
2481
2305
  const isThumb = id == this.thumb;
2482
2306
  if (yield this.handler.hasResult(isThumb)) {
2483
2307
  return this.handler.serveResult(isThumb);
@@ -2544,7 +2368,7 @@ var __decorate$j = (this && this.__decorate) || function (decorators, target, ke
2544
2368
  var __metadata$f = (this && this.__metadata) || function (k, v) {
2545
2369
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2546
2370
  };
2547
- var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2371
+ var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2548
2372
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2549
2373
  return new (P || (P = Promise))(function (resolve, reject) {
2550
2374
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2563,7 +2387,7 @@ let Gallery = class Gallery {
2563
2387
  this.output = join(this.config.resolve("cacheDir"), "gallery");
2564
2388
  }
2565
2389
  getFolder(folder, size = null) {
2566
- return __awaiter$e(this, void 0, void 0, function* () {
2390
+ return __awaiter$f(this, void 0, void 0, function* () {
2567
2391
  this.cache[folder] = this.cache[folder] || new Promise(resolve => {
2568
2392
  lstat(join(this.dir, folder), (err, stats) => {
2569
2393
  if (err || !stats.isDirectory()) {
@@ -2584,7 +2408,7 @@ let Gallery = class Gallery {
2584
2408
  return;
2585
2409
  }
2586
2410
  const promises = files.map(file => {
2587
- return new Promise((resolve) => __awaiter$e(this, void 0, void 0, function* () {
2411
+ return new Promise((resolve) => __awaiter$f(this, void 0, void 0, function* () {
2588
2412
  const filePath = join(path, file);
2589
2413
  const absoluteFilePath = join(this.dir, filePath);
2590
2414
  lstat(absoluteFilePath, (err, stats) => {
@@ -2617,7 +2441,7 @@ let Gallery = class Gallery {
2617
2441
  });
2618
2442
  },
2619
2443
  writeResult: (isThumb, buffer) => {
2620
- return new Promise((res, rej) => __awaiter$e(this, void 0, void 0, function* () {
2444
+ return new Promise((res, rej) => __awaiter$f(this, void 0, void 0, function* () {
2621
2445
  const resultPath = getResultPath(isThumb);
2622
2446
  yield mkdirRecursive(dirname(resultPath));
2623
2447
  writeFile$1(resultPath, buffer, err => {
@@ -2674,7 +2498,7 @@ var __decorate$i = (this && this.__decorate) || function (decorators, target, ke
2674
2498
  var __metadata$e = (this && this.__metadata) || function (k, v) {
2675
2499
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2676
2500
  };
2677
- var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2501
+ var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2678
2502
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2679
2503
  return new (P || (P = Promise))(function (resolve, reject) {
2680
2504
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2692,7 +2516,7 @@ let IdGenerator = class IdGenerator {
2692
2516
  this.parts = config.resolve("idParts");
2693
2517
  }
2694
2518
  generate(checkCb) {
2695
- return __awaiter$d(this, void 0, void 0, function* () {
2519
+ return __awaiter$e(this, void 0, void 0, function* () {
2696
2520
  let id = null;
2697
2521
  let tries = 0;
2698
2522
  let notGood = true;
@@ -2760,7 +2584,7 @@ var __decorate$g = (this && this.__decorate) || function (decorators, target, ke
2760
2584
  var __metadata$c = (this && this.__metadata) || function (k, v) {
2761
2585
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2762
2586
  };
2763
- var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2587
+ var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2764
2588
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2765
2589
  return new (P || (P = Promise))(function (resolve, reject) {
2766
2590
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2775,7 +2599,7 @@ let Translator = class Translator {
2775
2599
  this.cache = {};
2776
2600
  }
2777
2601
  getDictionary(language) {
2778
- return __awaiter$c(this, void 0, void 0, function* () {
2602
+ return __awaiter$d(this, void 0, void 0, function* () {
2779
2603
  const dictionary = yield this.translationProvider.getDictionary(language);
2780
2604
  this.cache[language] = dictionary;
2781
2605
  return dictionary;
@@ -2841,7 +2665,7 @@ var __decorate$f = (this && this.__decorate) || function (decorators, target, ke
2841
2665
  var __metadata$b = (this && this.__metadata) || function (k, v) {
2842
2666
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2843
2667
  };
2844
- var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2668
+ var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2845
2669
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2846
2670
  return new (P || (P = Promise))(function (resolve, reject) {
2847
2671
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2873,9 +2697,9 @@ let TemplateRenderer = class TemplateRenderer {
2873
2697
  return this.initPromise;
2874
2698
  }
2875
2699
  parseTemplates(dir, dirPath) {
2876
- return __awaiter$b(this, void 0, void 0, function* () {
2700
+ return __awaiter$c(this, void 0, void 0, function* () {
2877
2701
  return new Promise(resolve => {
2878
- readdir(dir, (err, files) => __awaiter$b(this, void 0, void 0, function* () {
2702
+ readdir(dir, (err, files) => __awaiter$c(this, void 0, void 0, function* () {
2879
2703
  for (let file of files) {
2880
2704
  const path = join(dir, file);
2881
2705
  if (lstatSync(path).isDirectory()) {
@@ -2896,7 +2720,7 @@ let TemplateRenderer = class TemplateRenderer {
2896
2720
  });
2897
2721
  }
2898
2722
  render(template, language, context) {
2899
- return __awaiter$b(this, void 0, void 0, function* () {
2723
+ return __awaiter$c(this, void 0, void 0, function* () {
2900
2724
  yield this.init();
2901
2725
  yield this.translator.getDictionary(language);
2902
2726
  if (!this.templates[template]) {
@@ -2923,7 +2747,7 @@ var __decorate$e = (this && this.__decorate) || function (decorators, target, ke
2923
2747
  var __metadata$a = (this && this.__metadata) || function (k, v) {
2924
2748
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2925
2749
  };
2926
- var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2750
+ var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2927
2751
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2928
2752
  return new (P || (P = Promise))(function (resolve, reject) {
2929
2753
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2949,7 +2773,7 @@ let MailSender = class MailSender {
2949
2773
  return this.renderer.translator;
2950
2774
  }
2951
2775
  sendMail(language, options) {
2952
- return __awaiter$a(this, void 0, void 0, function* () {
2776
+ return __awaiter$b(this, void 0, void 0, function* () {
2953
2777
  const subject = yield this.translator.getTranslation(language, options.subject || "-");
2954
2778
  const html = yield this.renderer.render(options.template, language, options.context);
2955
2779
  return this.transporter.sendMail({
@@ -2977,7 +2801,7 @@ var __decorate$d = (this && this.__decorate) || function (decorators, target, ke
2977
2801
  var __metadata$9 = (this && this.__metadata) || function (k, v) {
2978
2802
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2979
2803
  };
2980
- var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2804
+ var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2981
2805
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2982
2806
  return new (P || (P = Promise))(function (resolve, reject) {
2983
2807
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2992,7 +2816,7 @@ let MemoryCache = class MemoryCache {
2992
2816
  this.cacheMap = new Map();
2993
2817
  }
2994
2818
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2995
- return __awaiter$9(this, void 0, void 0, function* () {
2819
+ return __awaiter$a(this, void 0, void 0, function* () {
2996
2820
  const now = Math.round(new Date().getTime() / 1000);
2997
2821
  const expTimestamp = Math.min(isNaN(ttl) ? Number.MAX_SAFE_INTEGER : ttl, 3600);
2998
2822
  this.cacheMap.set(key, {
@@ -3005,7 +2829,7 @@ let MemoryCache = class MemoryCache {
3005
2829
  });
3006
2830
  }
3007
2831
  get(key) {
3008
- return __awaiter$9(this, void 0, void 0, function* () {
2832
+ return __awaiter$a(this, void 0, void 0, function* () {
3009
2833
  let item = this.cacheMap.get(key);
3010
2834
  const now = Math.round(new Date().getTime() / 1000);
3011
2835
  let expTimestamp = 3600;
@@ -3027,7 +2851,7 @@ let MemoryCache = class MemoryCache {
3027
2851
  });
3028
2852
  }
3029
2853
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
3030
- return __awaiter$9(this, void 0, void 0, function* () {
2854
+ return __awaiter$a(this, void 0, void 0, function* () {
3031
2855
  try {
3032
2856
  return yield this.get(key);
3033
2857
  }
@@ -3037,7 +2861,7 @@ let MemoryCache = class MemoryCache {
3037
2861
  });
3038
2862
  }
3039
2863
  delete(key) {
3040
- return __awaiter$9(this, void 0, void 0, function* () {
2864
+ return __awaiter$a(this, void 0, void 0, function* () {
3041
2865
  this.cacheMap.delete(key);
3042
2866
  yield this.cacheMap.delete(key);
3043
2867
  });
@@ -3055,7 +2879,7 @@ var __decorate$c = (this && this.__decorate) || function (decorators, target, ke
3055
2879
  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;
3056
2880
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3057
2881
  };
3058
- var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2882
+ var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3059
2883
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3060
2884
  return new (P || (P = Promise))(function (resolve, reject) {
3061
2885
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3072,17 +2896,17 @@ const sampleUser = {
3072
2896
  };
3073
2897
  let UserManager = class UserManager {
3074
2898
  getByCredentials(credentials) {
3075
- return __awaiter$8(this, void 0, void 0, function* () {
2899
+ return __awaiter$9(this, void 0, void 0, function* () {
3076
2900
  return (sampleUser.email == credentials.email) ? sampleUser : yield Promise.reject("message.login.error");
3077
2901
  });
3078
2902
  }
3079
2903
  getById(id) {
3080
- return __awaiter$8(this, void 0, void 0, function* () {
2904
+ return __awaiter$9(this, void 0, void 0, function* () {
3081
2905
  return (sampleUser.id == id) ? sampleUser : null;
3082
2906
  });
3083
2907
  }
3084
2908
  serialize(user) {
3085
- return __awaiter$8(this, void 0, void 0, function* () {
2909
+ return __awaiter$9(this, void 0, void 0, function* () {
3086
2910
  const res = Object.assign({}, user);
3087
2911
  delete res.password;
3088
2912
  return res;
@@ -3175,7 +2999,7 @@ var __metadata$7 = (this && this.__metadata) || function (k, v) {
3175
2999
  var __param$5 = (this && this.__param) || function (paramIndex, decorator) {
3176
3000
  return function (target, key) { decorator(target, key, paramIndex); }
3177
3001
  };
3178
- var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3002
+ var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3179
3003
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3180
3004
  return new (P || (P = Promise))(function (resolve, reject) {
3181
3005
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3190,7 +3014,7 @@ let AssetsController = class AssetsController {
3190
3014
  this.assetResolver = assetResolver;
3191
3015
  }
3192
3016
  upload(file) {
3193
- return __awaiter$7(this, void 0, void 0, function* () {
3017
+ return __awaiter$8(this, void 0, void 0, function* () {
3194
3018
  try {
3195
3019
  const contentType = file.mimetype === "application/octet-stream" ? null : file.mimetype;
3196
3020
  const asset = yield this.assets.writeBuffer(file.buffer, { filename: file.filename }, contentType);
@@ -3203,7 +3027,7 @@ let AssetsController = class AssetsController {
3203
3027
  });
3204
3028
  }
3205
3029
  uploadUrl(body) {
3206
- return __awaiter$7(this, void 0, void 0, function* () {
3030
+ return __awaiter$8(this, void 0, void 0, function* () {
3207
3031
  try {
3208
3032
  const asset = yield this.assets.writeUrl(body.url, body);
3209
3033
  return asset.toJSON();
@@ -3215,13 +3039,13 @@ let AssetsController = class AssetsController {
3215
3039
  });
3216
3040
  }
3217
3041
  getFile(id, lazy, res) {
3218
- return __awaiter$7(this, void 0, void 0, function* () {
3042
+ return __awaiter$8(this, void 0, void 0, function* () {
3219
3043
  const asset = yield this.getAsset("Asset", id, lazy, res);
3220
3044
  return asset.download();
3221
3045
  });
3222
3046
  }
3223
3047
  getImageRotation(id, params, res, rotation = 0) {
3224
- return __awaiter$7(this, void 0, void 0, function* () {
3048
+ return __awaiter$8(this, void 0, void 0, function* () {
3225
3049
  const asset = yield this.getAsset("Image", id, params.lazy, res);
3226
3050
  if (rotation !== 0) {
3227
3051
  params.rotation = params.rotation || rotation;
@@ -3230,18 +3054,18 @@ let AssetsController = class AssetsController {
3230
3054
  });
3231
3055
  }
3232
3056
  getImage(id, params, res) {
3233
- return __awaiter$7(this, void 0, void 0, function* () {
3057
+ return __awaiter$8(this, void 0, void 0, function* () {
3234
3058
  return this.getImageRotation(id, params, res);
3235
3059
  });
3236
3060
  }
3237
3061
  getFileByName(name, res) {
3238
- return __awaiter$7(this, void 0, void 0, function* () {
3062
+ return __awaiter$8(this, void 0, void 0, function* () {
3239
3063
  const asset = yield this.getAssetByName("Asset", name, res);
3240
3064
  return asset.download();
3241
3065
  });
3242
3066
  }
3243
3067
  getImageByName(name, params, res) {
3244
- return __awaiter$7(this, void 0, void 0, function* () {
3068
+ return __awaiter$8(this, void 0, void 0, function* () {
3245
3069
  const asset = yield this.getAssetByName("Image", name, res);
3246
3070
  return asset.downloadImage(params);
3247
3071
  });
@@ -3260,7 +3084,7 @@ let AssetsController = class AssetsController {
3260
3084
  }
3261
3085
  }
3262
3086
  getAsset(type, id, lazy, res) {
3263
- return __awaiter$7(this, void 0, void 0, function* () {
3087
+ return __awaiter$8(this, void 0, void 0, function* () {
3264
3088
  const asset = yield this.assetResolver.resolve(id, lazy);
3265
3089
  if (!asset) {
3266
3090
  throw new HttpError(404, `${type} with id: '${id}' not found.`);
@@ -3270,7 +3094,7 @@ let AssetsController = class AssetsController {
3270
3094
  });
3271
3095
  }
3272
3096
  getAssetByName(type, filename, res) {
3273
- return __awaiter$7(this, void 0, void 0, function* () {
3097
+ return __awaiter$8(this, void 0, void 0, function* () {
3274
3098
  const asset = yield this.assets.find({ filename });
3275
3099
  if (!asset) {
3276
3100
  throw new HttpError(404, `${type} with filename: '${filename}' not found.`);
@@ -3349,7 +3173,7 @@ var __metadata$6 = (this && this.__metadata) || function (k, v) {
3349
3173
  var __param$4 = (this && this.__param) || function (paramIndex, decorator) {
3350
3174
  return function (target, key) { decorator(target, key, paramIndex); }
3351
3175
  };
3352
- var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3176
+ var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3353
3177
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3354
3178
  return new (P || (P = Promise))(function (resolve, reject) {
3355
3179
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3364,7 +3188,7 @@ let AuthController = class AuthController {
3364
3188
  this.userManager = userManager;
3365
3189
  }
3366
3190
  login(credentials, res) {
3367
- return __awaiter$6(this, void 0, void 0, function* () {
3191
+ return __awaiter$7(this, void 0, void 0, function* () {
3368
3192
  let user = null;
3369
3193
  try {
3370
3194
  user = yield this.userManager.getByCredentials(credentials);
@@ -3451,7 +3275,7 @@ var __metadata$4 = (this && this.__metadata) || function (k, v) {
3451
3275
  var __param$2 = (this && this.__param) || function (paramIndex, decorator) {
3452
3276
  return function (target, key) { decorator(target, key, paramIndex); }
3453
3277
  };
3454
- var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3278
+ var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3455
3279
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3456
3280
  return new (P || (P = Promise))(function (resolve, reject) {
3457
3281
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3468,7 +3292,7 @@ let ProgressesController = class ProgressesController {
3468
3292
  this.connectionType = !mainEndpoint ? "polling" : "socket";
3469
3293
  }
3470
3294
  getProgress(id) {
3471
- return __awaiter$5(this, void 0, void 0, function* () {
3295
+ return __awaiter$6(this, void 0, void 0, function* () {
3472
3296
  const progress = yield this.progresses.get(id);
3473
3297
  if (!progress)
3474
3298
  return null;
@@ -3500,7 +3324,7 @@ var __decorate$6 = (this && this.__decorate) || function (decorators, target, ke
3500
3324
  var __metadata$3 = (this && this.__metadata) || function (k, v) {
3501
3325
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3502
3326
  };
3503
- var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3327
+ var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3504
3328
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3505
3329
  return new (P || (P = Promise))(function (resolve, reject) {
3506
3330
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3518,7 +3342,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3518
3342
  return this.configuration.resolve("nodeEnv") === "development";
3519
3343
  }
3520
3344
  error(error, req, res, next) {
3521
- return __awaiter$4(this, void 0, void 0, function* () {
3345
+ return __awaiter$5(this, void 0, void 0, function* () {
3522
3346
  const result = yield this.getResult(error, req, res);
3523
3347
  if (this.isDev) {
3524
3348
  console.log("ERROR", result, res.statusCode);
@@ -3527,7 +3351,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3527
3351
  });
3528
3352
  }
3529
3353
  getResult(error, req, res) {
3530
- return __awaiter$4(this, void 0, void 0, function* () {
3354
+ return __awaiter$5(this, void 0, void 0, function* () {
3531
3355
  const result = {};
3532
3356
  if (error instanceof BadRequestError) {
3533
3357
  res.status(400);
@@ -3673,7 +3497,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
3673
3497
  var __param = (this && this.__param) || function (paramIndex, decorator) {
3674
3498
  return function (target, key) { decorator(target, key, paramIndex); }
3675
3499
  };
3676
- var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3500
+ var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3677
3501
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3678
3502
  return new (P || (P = Promise))(function (resolve, reject) {
3679
3503
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3688,7 +3512,7 @@ let ProgressController = class ProgressController {
3688
3512
  this.socketServer = socketServer;
3689
3513
  }
3690
3514
  advanceProgress(client, progressId) {
3691
- return __awaiter$3(this, void 0, void 0, function* () {
3515
+ return __awaiter$4(this, void 0, void 0, function* () {
3692
3516
  const progress = yield this.progresses.get(progressId);
3693
3517
  if (!progress)
3694
3518
  return;
@@ -3702,7 +3526,7 @@ let ProgressController = class ProgressController {
3702
3526
  });
3703
3527
  }
3704
3528
  setProgressInterest(client, progressId) {
3705
- return __awaiter$3(this, void 0, void 0, function* () {
3529
+ return __awaiter$4(this, void 0, void 0, function* () {
3706
3530
  const progress = yield this.progresses.get(progressId);
3707
3531
  if (!progress)
3708
3532
  return;
@@ -3753,6 +3577,53 @@ CompressionMiddleware = __decorate([
3753
3577
  Middleware$1()
3754
3578
  ], CompressionMiddleware);
3755
3579
 
3580
+ var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3581
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3582
+ return new (P || (P = Promise))(function (resolve, reject) {
3583
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3584
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3585
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3586
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3587
+ });
3588
+ };
3589
+ function setupStatic(rootFolder, container) {
3590
+ return __awaiter$3(this, void 0, void 0, function* () {
3591
+ const browserFolder = resolve(rootFolder || __dirname, `public_html`);
3592
+ const app = container.get(EXPRESS);
3593
+ const ep = container.get(EndpointProvider);
3594
+ console.log(browserFolder, existsSync(browserFolder));
3595
+ if (existsSync(browserFolder)) {
3596
+ console.log(`public_html exists. setting up static files serving...`);
3597
+ app.use(static$1(browserFolder, {
3598
+ maxAge: "1y"
3599
+ }));
3600
+ }
3601
+ else {
3602
+ console.log(`public_html does not exist on path: "${browserFolder}"`);
3603
+ }
3604
+ yield ep.configure(app);
3605
+ });
3606
+ }
3607
+
3608
+ class BaseDoc {
3609
+ /**
3610
+ * Casts this to DocumentType<this> to allow using document methods in get/set-s
3611
+ */
3612
+ cast() {
3613
+ return this;
3614
+ }
3615
+ /**
3616
+ * Gets a pre-compiled model from typegoose cache by its class type
3617
+ * @param type
3618
+ */
3619
+ model(type) {
3620
+ return getModelForClass(type);
3621
+ }
3622
+ }
3623
+ // @ts-ignore
3624
+ const PrimitiveArray = Types.Array;
3625
+ const DocumentArray = Types.DocumentArray;
3626
+
3756
3627
  class Tree {
3757
3628
  constructor(container, exists, path) {
3758
3629
  this.container = container;
@@ -3957,45 +3828,6 @@ var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P,
3957
3828
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3958
3829
  });
3959
3830
  };
3960
- function setupStatic(rootFolder, container) {
3961
- return __awaiter$2(this, void 0, void 0, function* () {
3962
- const browserFolder = resolve(rootFolder || __dirname, `public_html`);
3963
- const app = container.get(EXPRESS);
3964
- const ep = container.get(EndpointProvider);
3965
- console.log(browserFolder, existsSync(browserFolder));
3966
- if (existsSync(browserFolder)) {
3967
- console.log(`public_html exists. setting up static files serving...`);
3968
- app.use(static$1(browserFolder, {
3969
- maxAge: "1y"
3970
- }));
3971
- }
3972
- else {
3973
- console.log(`public_html does not exist on path: "${browserFolder}"`);
3974
- }
3975
- yield ep.configure(app);
3976
- });
3977
- }
3978
-
3979
- class BaseDoc {
3980
- /**
3981
- * Casts this to DocumentType<this> to allow using document methods in get/set-s
3982
- */
3983
- cast() {
3984
- return this;
3985
- }
3986
- }
3987
- const DocumentArray = Types.DocumentArray;
3988
- const PrimitiveArray = Types.Array;
3989
-
3990
- var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3991
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3992
- return new (P || (P = Promise))(function (resolve, reject) {
3993
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3994
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3995
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3996
- step((generator = generator.apply(thisArg, _arguments || [])).next());
3997
- });
3998
- };
3999
3831
  class LazyAssetGenerator {
4000
3832
  constructor(assetResolver, progresses, lazyId) {
4001
3833
  this.assetResolver = assetResolver;
@@ -4009,7 +3841,7 @@ class LazyAssetGenerator {
4009
3841
  return this.assetResolver.lazyAssets;
4010
3842
  }
4011
3843
  process(messaging) {
4012
- return __awaiter$1(this, void 0, void 0, function* () {
3844
+ return __awaiter$2(this, void 0, void 0, function* () {
4013
3845
  const lazyAsset = yield this.lazyAssets.read(this.lazyId);
4014
3846
  let progress = yield this.progresses.get(lazyAsset.progressId);
4015
3847
  if (!progress || progress.canceled)
@@ -4033,6 +3865,227 @@ class LazyAssetGenerator {
4033
3865
  }
4034
3866
  }
4035
3867
 
3868
+ var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3869
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3870
+ return new (P || (P = Promise))(function (resolve, reject) {
3871
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3872
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3873
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3874
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3875
+ });
3876
+ };
3877
+ const pluginsKey = "typegoose:plugins";
3878
+ /**
3879
+ * A mongoose/typegoose plugin to inject services from the main di container to a schema as virtuals
3880
+ * @param schema
3881
+ * @param services
3882
+ */
3883
+ function injectServices(schema, services) {
3884
+ const serviceMap = {};
3885
+ if (!isObject(services)) {
3886
+ throw new Error(`services object should be defined to inject services to schema!`);
3887
+ }
3888
+ Object.keys(services).forEach(prop => {
3889
+ schema
3890
+ .virtual(prop)
3891
+ .get(() => {
3892
+ const diContainer = diContainers.appContainer;
3893
+ serviceMap[prop] = serviceMap[prop] || (!diContainer ? {} : diContainer.resolve(services[prop]));
3894
+ return serviceMap[prop];
3895
+ });
3896
+ });
3897
+ }
3898
+ /**
3899
+ * Decorates a property to inject a service with the help of the injectServices mongoose/typegoose plugin
3900
+ * @param token optional InjectionToken to use
3901
+ * @return PropertyDecorator
3902
+ */
3903
+ function service(token) {
3904
+ return (target, propertyKey) => {
3905
+ var _a;
3906
+ const propertyType = Reflect.getOwnMetadata("design:type", target, propertyKey);
3907
+ const plugins = Array.from((_a = Reflect.getMetadata(pluginsKey, target.constructor)) !== null && _a !== void 0 ? _a : []);
3908
+ let plugin = plugins.find(t => t.mongoosePlugin === injectServices);
3909
+ if (!plugin) {
3910
+ plugin = { mongoosePlugin: injectServices, options: {} };
3911
+ plugins.push(plugin);
3912
+ }
3913
+ plugin.options = Object.assign(plugin.options || {}, { [propertyKey]: token !== null && token !== void 0 ? token : propertyType });
3914
+ Reflect.defineMetadata(pluginsKey, plugins, target.constructor);
3915
+ };
3916
+ }
3917
+ /**
3918
+ * Paginate using a typegoose model using a simple where query and pagination params
3919
+ * @param model Typegoose model
3920
+ * @param where Simple query to filter the results
3921
+ * @param params Pagination params
3922
+ */
3923
+ function paginate(model, where, params) {
3924
+ return model.countDocuments(where).then(count => {
3925
+ let query = model.find(where);
3926
+ if (isString(params.sort)) {
3927
+ query = query.sort(params.sort);
3928
+ }
3929
+ if (isArray(params.populate)) {
3930
+ params.populate.forEach(field => {
3931
+ query = query.populate(field);
3932
+ });
3933
+ }
3934
+ return (params.limit > 0 ? query.skip(params.page * params.limit).limit(params.limit) : query).then(items => {
3935
+ const meta = { total: count };
3936
+ return { count, items, meta };
3937
+ });
3938
+ });
3939
+ }
3940
+ function lookupStages(from, localField, as = null, foreignField = "_id", shouldUnwind = true) {
3941
+ as = as || localField.replace("Id", "");
3942
+ const stages = [
3943
+ {
3944
+ $lookup: {
3945
+ from,
3946
+ localField,
3947
+ foreignField,
3948
+ as
3949
+ }
3950
+ },
3951
+ {
3952
+ $unwind: {
3953
+ path: `$${as}`,
3954
+ preserveNullAndEmptyArrays: true
3955
+ }
3956
+ }
3957
+ ];
3958
+ if (!shouldUnwind) {
3959
+ stages.splice(1, 1);
3960
+ }
3961
+ return stages;
3962
+ }
3963
+ function letsLookupStage(from, pipeline, as = null, letFields = null) {
3964
+ as = as || from;
3965
+ letFields = letFields || { id: "$_id" };
3966
+ return {
3967
+ $lookup: {
3968
+ from,
3969
+ let: letFields,
3970
+ pipeline,
3971
+ as
3972
+ }
3973
+ };
3974
+ }
3975
+ function matchStage(match) {
3976
+ return { $match: match };
3977
+ }
3978
+ function matchField(field, filter, when) {
3979
+ return { field, filter, when };
3980
+ }
3981
+ function matchFieldStages(...fields) {
3982
+ const match = {};
3983
+ fields.forEach(field => {
3984
+ if (field.when) {
3985
+ match[field.field] = field.filter;
3986
+ }
3987
+ });
3988
+ return Object.keys(match).length > 0 ? [matchStage(match)] : [];
3989
+ }
3990
+ function projectStage(fields) {
3991
+ return { $project: fields };
3992
+ }
3993
+ function unwindStage(fieldOrOpts) {
3994
+ return { $unwind: fieldOrOpts };
3995
+ }
3996
+ function hydratePopulated(modelType, json) {
3997
+ let object = modelType.hydrate(json);
3998
+ for (const [path, obj] of Object.entries(modelType.schema.obj)) {
3999
+ let { ref, type } = obj;
4000
+ if (Array.isArray(type) && type.length > 0) {
4001
+ ref = type[0].ref;
4002
+ }
4003
+ if (!ref)
4004
+ continue;
4005
+ const value = getValue$1(path, json);
4006
+ const hydrateVal = val => {
4007
+ if (val == null || val instanceof Types.ObjectId)
4008
+ return val;
4009
+ return hydratePopulated(model(ref), val);
4010
+ };
4011
+ if (Array.isArray(value)) {
4012
+ setValue(path, value.map(hydrateVal), object);
4013
+ continue;
4014
+ }
4015
+ setValue(path, hydrateVal(value), object);
4016
+ }
4017
+ return object;
4018
+ }
4019
+ function paginateAggregations(model, aggregations, params, metaProjection = {}) {
4020
+ return __awaiter$1(this, void 0, void 0, function* () {
4021
+ const sortField = !isString(params.sort) || !params.sort ? null : (params.sort.startsWith("-") ? params.sort.substr(1) : params.sort);
4022
+ const sortAggregation = !sortField ? [] : [{
4023
+ $sort: { [sortField]: sortField == params.sort ? 1 : -1 }
4024
+ }];
4025
+ const result = yield model.aggregate([
4026
+ ...aggregations,
4027
+ ...sortAggregation,
4028
+ {
4029
+ $group: {
4030
+ _id: "results",
4031
+ result: { $push: "$$CURRENT" }
4032
+ }
4033
+ },
4034
+ {
4035
+ $project: {
4036
+ _id: 0,
4037
+ items: params.limit > 0 ? { $slice: ["$result", params.page * params.limit, params.limit] } : "$result",
4038
+ count: { $size: "$result" },
4039
+ meta: Object.assign({ total: { $size: "$result" } }, metaProjection)
4040
+ }
4041
+ }
4042
+ ]);
4043
+ const pagination = result[0];
4044
+ if (!pagination) {
4045
+ return { items: [], count: 0, meta: { total: 0 } };
4046
+ }
4047
+ pagination.items = pagination.items.map(i => hydratePopulated(model, i));
4048
+ return pagination;
4049
+ });
4050
+ }
4051
+ function ResolveEntity(model, extraCheck) {
4052
+ const modelName = model.modelName;
4053
+ const paramName = modelName.toLowerCase();
4054
+ return createParamDecorator({
4055
+ required: false,
4056
+ value: (action) => __awaiter$1(this, void 0, void 0, function* () {
4057
+ const req = action.request;
4058
+ const token = req.header(`x-${paramName}-token`);
4059
+ const id = req.params[`${paramName}Id`];
4060
+ if (!id && !token) {
4061
+ throw new BadRequestError(`${modelName} id or token should be defined!`);
4062
+ }
4063
+ const query = !token
4064
+ ? model.findById(id)
4065
+ : model.findOne({ token });
4066
+ let doc = null;
4067
+ if (isFunction(extraCheck)) {
4068
+ try {
4069
+ doc = yield valueToPromise(extraCheck(query, action));
4070
+ }
4071
+ catch (e) {
4072
+ throw new BadRequestError(`${modelName} check error: ${e.message || e}`);
4073
+ }
4074
+ }
4075
+ else {
4076
+ doc = yield query;
4077
+ }
4078
+ if (!doc) {
4079
+ throw new HttpError(404, !token
4080
+ ? `${modelName} could not be found with id: ${id}`
4081
+ : `${modelName} could not be found with token: ${token}`);
4082
+ }
4083
+ action.request[paramName] = doc;
4084
+ return doc;
4085
+ })
4086
+ });
4087
+ }
4088
+
4036
4089
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4037
4090
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4038
4091
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -4294,5 +4347,5 @@ function setupBackend(config, providers, parent) {
4294
4347
  * Generated bundle index. Do not edit.
4295
4348
  */
4296
4349
 
4297
- 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, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, 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, runCommand, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, writeFile };
4350
+ 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, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, PrimitiveArray, Progresses, ResolveEntity, SOCKET_SERVER, TemplateRenderer, TranslationProvider, Translator, Type, UserManager, assign, broadcast, bufferToStream, colorize, convertValue, copy, copyStream, 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, runCommand, service, setupBackend, streamToBuffer, toImage, ucFirst, uniqueItems, unwindStage, valueToPromise, writeFile };
4298
4351
  //# sourceMappingURL=stemy-backend.js.map