@stemy/backend 3.4.0 → 3.4.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.
@@ -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);
@@ -2253,6 +2077,7 @@ const socketIO = socket_io;
2253
2077
  let BackendProvider = class BackendProvider {
2254
2078
  constructor() {
2255
2079
  this.express = express();
2080
+ this.express.set("trust proxy", true);
2256
2081
  this.server = createServer(this.express);
2257
2082
  }
2258
2083
  get io() {
@@ -2272,7 +2097,7 @@ var __decorate$o = (this && this.__decorate) || function (decorators, target, ke
2272
2097
  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
2098
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2274
2099
  };
2275
- var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2100
+ var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2276
2101
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2277
2102
  return new (P || (P = Promise))(function (resolve, reject) {
2278
2103
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2283,12 +2108,12 @@ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P,
2283
2108
  };
2284
2109
  let CacheProcessor = class CacheProcessor {
2285
2110
  serialize(data) {
2286
- return __awaiter$j(this, void 0, void 0, function* () {
2111
+ return __awaiter$k(this, void 0, void 0, function* () {
2287
2112
  return data;
2288
2113
  });
2289
2114
  }
2290
2115
  deserialize(data) {
2291
- return __awaiter$j(this, void 0, void 0, function* () {
2116
+ return __awaiter$k(this, void 0, void 0, function* () {
2292
2117
  return data;
2293
2118
  });
2294
2119
  }
@@ -2307,7 +2132,7 @@ var __decorate$n = (this && this.__decorate) || function (decorators, target, ke
2307
2132
  var __metadata$i = (this && this.__metadata) || function (k, v) {
2308
2133
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2309
2134
  };
2310
- var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2135
+ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2311
2136
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2312
2137
  return new (P || (P = Promise))(function (resolve, reject) {
2313
2138
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2323,7 +2148,7 @@ let Cache = class Cache {
2323
2148
  this.cacheProcessor = cacheProcessor;
2324
2149
  }
2325
2150
  prepare() {
2326
- return __awaiter$i(this, void 0, void 0, function* () {
2151
+ return __awaiter$j(this, void 0, void 0, function* () {
2327
2152
  if (this.collection)
2328
2153
  return;
2329
2154
  if (!this.connector.database) {
@@ -2334,7 +2159,7 @@ let Cache = class Cache {
2334
2159
  });
2335
2160
  }
2336
2161
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2337
- return __awaiter$i(this, void 0, void 0, function* () {
2162
+ return __awaiter$j(this, void 0, void 0, function* () {
2338
2163
  yield this.prepare();
2339
2164
  const item = {
2340
2165
  _id: key,
@@ -2351,7 +2176,7 @@ let Cache = class Cache {
2351
2176
  });
2352
2177
  }
2353
2178
  get(key) {
2354
- return __awaiter$i(this, void 0, void 0, function* () {
2179
+ return __awaiter$j(this, void 0, void 0, function* () {
2355
2180
  yield this.prepare();
2356
2181
  let item = yield this.collection.findOne({ _id: key });
2357
2182
  const now = Math.round(new Date().getTime() / 1000);
@@ -2365,7 +2190,7 @@ let Cache = class Cache {
2365
2190
  });
2366
2191
  }
2367
2192
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
2368
- return __awaiter$i(this, void 0, void 0, function* () {
2193
+ return __awaiter$j(this, void 0, void 0, function* () {
2369
2194
  try {
2370
2195
  return yield this.get(key);
2371
2196
  }
@@ -2375,7 +2200,7 @@ let Cache = class Cache {
2375
2200
  });
2376
2201
  }
2377
2202
  delete(key) {
2378
- return __awaiter$i(this, void 0, void 0, function* () {
2203
+ return __awaiter$j(this, void 0, void 0, function* () {
2379
2204
  yield this.prepare();
2380
2205
  yield this.collection.deleteOne({ _id: key });
2381
2206
  });
@@ -2393,7 +2218,7 @@ var __decorate$m = (this && this.__decorate) || function (decorators, target, ke
2393
2218
  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
2219
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2395
2220
  };
2396
- var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2221
+ var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2397
2222
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2398
2223
  return new (P || (P = Promise))(function (resolve, reject) {
2399
2224
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2404,7 +2229,7 @@ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P,
2404
2229
  };
2405
2230
  let EndpointProvider = class EndpointProvider {
2406
2231
  configure(app) {
2407
- return __awaiter$h(this, void 0, void 0, function* () {
2232
+ return __awaiter$i(this, void 0, void 0, function* () {
2408
2233
  console.log(`Express app is mounted to: ${app.mountpath}`);
2409
2234
  });
2410
2235
  }
@@ -2426,7 +2251,7 @@ var __metadata$h = (this && this.__metadata) || function (k, v) {
2426
2251
  var __param$6 = (this && this.__param) || function (paramIndex, decorator) {
2427
2252
  return function (target, key) { decorator(target, key, paramIndex); }
2428
2253
  };
2429
- var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2254
+ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2430
2255
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2431
2256
  return new (P || (P = Promise))(function (resolve, reject) {
2432
2257
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2440,7 +2265,7 @@ let Fixtures = class Fixtures {
2440
2265
  this.fixtures = fixtures;
2441
2266
  }
2442
2267
  load() {
2443
- return __awaiter$g(this, void 0, void 0, function* () {
2268
+ return __awaiter$h(this, void 0, void 0, function* () {
2444
2269
  if (!this.fixtures)
2445
2270
  return;
2446
2271
  for (let fixture of this.fixtures) {
@@ -2456,7 +2281,7 @@ Fixtures = __decorate$l([
2456
2281
  __metadata$h("design:paramtypes", [Array])
2457
2282
  ], Fixtures);
2458
2283
 
2459
- var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2284
+ var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2460
2285
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2461
2286
  return new (P || (P = Promise))(function (resolve, reject) {
2462
2287
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2477,7 +2302,7 @@ class GalleryImage {
2477
2302
  this.targetSize = !size ? { width: thumbSize, height: thumbSize } : size;
2478
2303
  }
2479
2304
  serve(id) {
2480
- return __awaiter$f(this, void 0, void 0, function* () {
2305
+ return __awaiter$g(this, void 0, void 0, function* () {
2481
2306
  const isThumb = id == this.thumb;
2482
2307
  if (yield this.handler.hasResult(isThumb)) {
2483
2308
  return this.handler.serveResult(isThumb);
@@ -2544,7 +2369,7 @@ var __decorate$j = (this && this.__decorate) || function (decorators, target, ke
2544
2369
  var __metadata$f = (this && this.__metadata) || function (k, v) {
2545
2370
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2546
2371
  };
2547
- var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2372
+ var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2548
2373
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2549
2374
  return new (P || (P = Promise))(function (resolve, reject) {
2550
2375
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2563,7 +2388,7 @@ let Gallery = class Gallery {
2563
2388
  this.output = join(this.config.resolve("cacheDir"), "gallery");
2564
2389
  }
2565
2390
  getFolder(folder, size = null) {
2566
- return __awaiter$e(this, void 0, void 0, function* () {
2391
+ return __awaiter$f(this, void 0, void 0, function* () {
2567
2392
  this.cache[folder] = this.cache[folder] || new Promise(resolve => {
2568
2393
  lstat(join(this.dir, folder), (err, stats) => {
2569
2394
  if (err || !stats.isDirectory()) {
@@ -2584,7 +2409,7 @@ let Gallery = class Gallery {
2584
2409
  return;
2585
2410
  }
2586
2411
  const promises = files.map(file => {
2587
- return new Promise((resolve) => __awaiter$e(this, void 0, void 0, function* () {
2412
+ return new Promise((resolve) => __awaiter$f(this, void 0, void 0, function* () {
2588
2413
  const filePath = join(path, file);
2589
2414
  const absoluteFilePath = join(this.dir, filePath);
2590
2415
  lstat(absoluteFilePath, (err, stats) => {
@@ -2617,7 +2442,7 @@ let Gallery = class Gallery {
2617
2442
  });
2618
2443
  },
2619
2444
  writeResult: (isThumb, buffer) => {
2620
- return new Promise((res, rej) => __awaiter$e(this, void 0, void 0, function* () {
2445
+ return new Promise((res, rej) => __awaiter$f(this, void 0, void 0, function* () {
2621
2446
  const resultPath = getResultPath(isThumb);
2622
2447
  yield mkdirRecursive(dirname(resultPath));
2623
2448
  writeFile$1(resultPath, buffer, err => {
@@ -2674,7 +2499,7 @@ var __decorate$i = (this && this.__decorate) || function (decorators, target, ke
2674
2499
  var __metadata$e = (this && this.__metadata) || function (k, v) {
2675
2500
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2676
2501
  };
2677
- var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2502
+ var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2678
2503
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2679
2504
  return new (P || (P = Promise))(function (resolve, reject) {
2680
2505
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2692,7 +2517,7 @@ let IdGenerator = class IdGenerator {
2692
2517
  this.parts = config.resolve("idParts");
2693
2518
  }
2694
2519
  generate(checkCb) {
2695
- return __awaiter$d(this, void 0, void 0, function* () {
2520
+ return __awaiter$e(this, void 0, void 0, function* () {
2696
2521
  let id = null;
2697
2522
  let tries = 0;
2698
2523
  let notGood = true;
@@ -2760,7 +2585,7 @@ var __decorate$g = (this && this.__decorate) || function (decorators, target, ke
2760
2585
  var __metadata$c = (this && this.__metadata) || function (k, v) {
2761
2586
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2762
2587
  };
2763
- var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2588
+ var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2764
2589
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2765
2590
  return new (P || (P = Promise))(function (resolve, reject) {
2766
2591
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2775,7 +2600,7 @@ let Translator = class Translator {
2775
2600
  this.cache = {};
2776
2601
  }
2777
2602
  getDictionary(language) {
2778
- return __awaiter$c(this, void 0, void 0, function* () {
2603
+ return __awaiter$d(this, void 0, void 0, function* () {
2779
2604
  const dictionary = yield this.translationProvider.getDictionary(language);
2780
2605
  this.cache[language] = dictionary;
2781
2606
  return dictionary;
@@ -2841,7 +2666,7 @@ var __decorate$f = (this && this.__decorate) || function (decorators, target, ke
2841
2666
  var __metadata$b = (this && this.__metadata) || function (k, v) {
2842
2667
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2843
2668
  };
2844
- var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2669
+ var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2845
2670
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2846
2671
  return new (P || (P = Promise))(function (resolve, reject) {
2847
2672
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2873,9 +2698,9 @@ let TemplateRenderer = class TemplateRenderer {
2873
2698
  return this.initPromise;
2874
2699
  }
2875
2700
  parseTemplates(dir, dirPath) {
2876
- return __awaiter$b(this, void 0, void 0, function* () {
2701
+ return __awaiter$c(this, void 0, void 0, function* () {
2877
2702
  return new Promise(resolve => {
2878
- readdir(dir, (err, files) => __awaiter$b(this, void 0, void 0, function* () {
2703
+ readdir(dir, (err, files) => __awaiter$c(this, void 0, void 0, function* () {
2879
2704
  for (let file of files) {
2880
2705
  const path = join(dir, file);
2881
2706
  if (lstatSync(path).isDirectory()) {
@@ -2896,7 +2721,7 @@ let TemplateRenderer = class TemplateRenderer {
2896
2721
  });
2897
2722
  }
2898
2723
  render(template, language, context) {
2899
- return __awaiter$b(this, void 0, void 0, function* () {
2724
+ return __awaiter$c(this, void 0, void 0, function* () {
2900
2725
  yield this.init();
2901
2726
  yield this.translator.getDictionary(language);
2902
2727
  if (!this.templates[template]) {
@@ -2923,7 +2748,7 @@ var __decorate$e = (this && this.__decorate) || function (decorators, target, ke
2923
2748
  var __metadata$a = (this && this.__metadata) || function (k, v) {
2924
2749
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2925
2750
  };
2926
- var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2751
+ var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2927
2752
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2928
2753
  return new (P || (P = Promise))(function (resolve, reject) {
2929
2754
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2949,7 +2774,7 @@ let MailSender = class MailSender {
2949
2774
  return this.renderer.translator;
2950
2775
  }
2951
2776
  sendMail(language, options) {
2952
- return __awaiter$a(this, void 0, void 0, function* () {
2777
+ return __awaiter$b(this, void 0, void 0, function* () {
2953
2778
  const subject = yield this.translator.getTranslation(language, options.subject || "-");
2954
2779
  const html = yield this.renderer.render(options.template, language, options.context);
2955
2780
  return this.transporter.sendMail({
@@ -2977,7 +2802,7 @@ var __decorate$d = (this && this.__decorate) || function (decorators, target, ke
2977
2802
  var __metadata$9 = (this && this.__metadata) || function (k, v) {
2978
2803
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2979
2804
  };
2980
- var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2805
+ var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2981
2806
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2982
2807
  return new (P || (P = Promise))(function (resolve, reject) {
2983
2808
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2992,7 +2817,7 @@ let MemoryCache = class MemoryCache {
2992
2817
  this.cacheMap = new Map();
2993
2818
  }
2994
2819
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2995
- return __awaiter$9(this, void 0, void 0, function* () {
2820
+ return __awaiter$a(this, void 0, void 0, function* () {
2996
2821
  const now = Math.round(new Date().getTime() / 1000);
2997
2822
  const expTimestamp = Math.min(isNaN(ttl) ? Number.MAX_SAFE_INTEGER : ttl, 3600);
2998
2823
  this.cacheMap.set(key, {
@@ -3005,7 +2830,7 @@ let MemoryCache = class MemoryCache {
3005
2830
  });
3006
2831
  }
3007
2832
  get(key) {
3008
- return __awaiter$9(this, void 0, void 0, function* () {
2833
+ return __awaiter$a(this, void 0, void 0, function* () {
3009
2834
  let item = this.cacheMap.get(key);
3010
2835
  const now = Math.round(new Date().getTime() / 1000);
3011
2836
  let expTimestamp = 3600;
@@ -3027,7 +2852,7 @@ let MemoryCache = class MemoryCache {
3027
2852
  });
3028
2853
  }
3029
2854
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
3030
- return __awaiter$9(this, void 0, void 0, function* () {
2855
+ return __awaiter$a(this, void 0, void 0, function* () {
3031
2856
  try {
3032
2857
  return yield this.get(key);
3033
2858
  }
@@ -3037,7 +2862,7 @@ let MemoryCache = class MemoryCache {
3037
2862
  });
3038
2863
  }
3039
2864
  delete(key) {
3040
- return __awaiter$9(this, void 0, void 0, function* () {
2865
+ return __awaiter$a(this, void 0, void 0, function* () {
3041
2866
  this.cacheMap.delete(key);
3042
2867
  yield this.cacheMap.delete(key);
3043
2868
  });
@@ -3055,7 +2880,7 @@ var __decorate$c = (this && this.__decorate) || function (decorators, target, ke
3055
2880
  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
2881
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3057
2882
  };
3058
- var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2883
+ var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3059
2884
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3060
2885
  return new (P || (P = Promise))(function (resolve, reject) {
3061
2886
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3072,17 +2897,17 @@ const sampleUser = {
3072
2897
  };
3073
2898
  let UserManager = class UserManager {
3074
2899
  getByCredentials(credentials) {
3075
- return __awaiter$8(this, void 0, void 0, function* () {
2900
+ return __awaiter$9(this, void 0, void 0, function* () {
3076
2901
  return (sampleUser.email == credentials.email) ? sampleUser : yield Promise.reject("message.login.error");
3077
2902
  });
3078
2903
  }
3079
2904
  getById(id) {
3080
- return __awaiter$8(this, void 0, void 0, function* () {
2905
+ return __awaiter$9(this, void 0, void 0, function* () {
3081
2906
  return (sampleUser.id == id) ? sampleUser : null;
3082
2907
  });
3083
2908
  }
3084
2909
  serialize(user) {
3085
- return __awaiter$8(this, void 0, void 0, function* () {
2910
+ return __awaiter$9(this, void 0, void 0, function* () {
3086
2911
  const res = Object.assign({}, user);
3087
2912
  delete res.password;
3088
2913
  return res;
@@ -3175,7 +3000,7 @@ var __metadata$7 = (this && this.__metadata) || function (k, v) {
3175
3000
  var __param$5 = (this && this.__param) || function (paramIndex, decorator) {
3176
3001
  return function (target, key) { decorator(target, key, paramIndex); }
3177
3002
  };
3178
- var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3003
+ var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3179
3004
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3180
3005
  return new (P || (P = Promise))(function (resolve, reject) {
3181
3006
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3190,7 +3015,7 @@ let AssetsController = class AssetsController {
3190
3015
  this.assetResolver = assetResolver;
3191
3016
  }
3192
3017
  upload(file) {
3193
- return __awaiter$7(this, void 0, void 0, function* () {
3018
+ return __awaiter$8(this, void 0, void 0, function* () {
3194
3019
  try {
3195
3020
  const contentType = file.mimetype === "application/octet-stream" ? null : file.mimetype;
3196
3021
  const asset = yield this.assets.writeBuffer(file.buffer, { filename: file.filename }, contentType);
@@ -3203,7 +3028,7 @@ let AssetsController = class AssetsController {
3203
3028
  });
3204
3029
  }
3205
3030
  uploadUrl(body) {
3206
- return __awaiter$7(this, void 0, void 0, function* () {
3031
+ return __awaiter$8(this, void 0, void 0, function* () {
3207
3032
  try {
3208
3033
  const asset = yield this.assets.writeUrl(body.url, body);
3209
3034
  return asset.toJSON();
@@ -3215,13 +3040,13 @@ let AssetsController = class AssetsController {
3215
3040
  });
3216
3041
  }
3217
3042
  getFile(id, lazy, res) {
3218
- return __awaiter$7(this, void 0, void 0, function* () {
3043
+ return __awaiter$8(this, void 0, void 0, function* () {
3219
3044
  const asset = yield this.getAsset("Asset", id, lazy, res);
3220
3045
  return asset.download();
3221
3046
  });
3222
3047
  }
3223
3048
  getImageRotation(id, params, res, rotation = 0) {
3224
- return __awaiter$7(this, void 0, void 0, function* () {
3049
+ return __awaiter$8(this, void 0, void 0, function* () {
3225
3050
  const asset = yield this.getAsset("Image", id, params.lazy, res);
3226
3051
  if (rotation !== 0) {
3227
3052
  params.rotation = params.rotation || rotation;
@@ -3230,18 +3055,18 @@ let AssetsController = class AssetsController {
3230
3055
  });
3231
3056
  }
3232
3057
  getImage(id, params, res) {
3233
- return __awaiter$7(this, void 0, void 0, function* () {
3058
+ return __awaiter$8(this, void 0, void 0, function* () {
3234
3059
  return this.getImageRotation(id, params, res);
3235
3060
  });
3236
3061
  }
3237
3062
  getFileByName(name, res) {
3238
- return __awaiter$7(this, void 0, void 0, function* () {
3063
+ return __awaiter$8(this, void 0, void 0, function* () {
3239
3064
  const asset = yield this.getAssetByName("Asset", name, res);
3240
3065
  return asset.download();
3241
3066
  });
3242
3067
  }
3243
3068
  getImageByName(name, params, res) {
3244
- return __awaiter$7(this, void 0, void 0, function* () {
3069
+ return __awaiter$8(this, void 0, void 0, function* () {
3245
3070
  const asset = yield this.getAssetByName("Image", name, res);
3246
3071
  return asset.downloadImage(params);
3247
3072
  });
@@ -3260,7 +3085,7 @@ let AssetsController = class AssetsController {
3260
3085
  }
3261
3086
  }
3262
3087
  getAsset(type, id, lazy, res) {
3263
- return __awaiter$7(this, void 0, void 0, function* () {
3088
+ return __awaiter$8(this, void 0, void 0, function* () {
3264
3089
  const asset = yield this.assetResolver.resolve(id, lazy);
3265
3090
  if (!asset) {
3266
3091
  throw new HttpError(404, `${type} with id: '${id}' not found.`);
@@ -3270,7 +3095,7 @@ let AssetsController = class AssetsController {
3270
3095
  });
3271
3096
  }
3272
3097
  getAssetByName(type, filename, res) {
3273
- return __awaiter$7(this, void 0, void 0, function* () {
3098
+ return __awaiter$8(this, void 0, void 0, function* () {
3274
3099
  const asset = yield this.assets.find({ filename });
3275
3100
  if (!asset) {
3276
3101
  throw new HttpError(404, `${type} with filename: '${filename}' not found.`);
@@ -3349,7 +3174,7 @@ var __metadata$6 = (this && this.__metadata) || function (k, v) {
3349
3174
  var __param$4 = (this && this.__param) || function (paramIndex, decorator) {
3350
3175
  return function (target, key) { decorator(target, key, paramIndex); }
3351
3176
  };
3352
- var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3177
+ var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3353
3178
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3354
3179
  return new (P || (P = Promise))(function (resolve, reject) {
3355
3180
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3364,7 +3189,7 @@ let AuthController = class AuthController {
3364
3189
  this.userManager = userManager;
3365
3190
  }
3366
3191
  login(credentials, res) {
3367
- return __awaiter$6(this, void 0, void 0, function* () {
3192
+ return __awaiter$7(this, void 0, void 0, function* () {
3368
3193
  let user = null;
3369
3194
  try {
3370
3195
  user = yield this.userManager.getByCredentials(credentials);
@@ -3451,7 +3276,7 @@ var __metadata$4 = (this && this.__metadata) || function (k, v) {
3451
3276
  var __param$2 = (this && this.__param) || function (paramIndex, decorator) {
3452
3277
  return function (target, key) { decorator(target, key, paramIndex); }
3453
3278
  };
3454
- var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3279
+ var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3455
3280
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3456
3281
  return new (P || (P = Promise))(function (resolve, reject) {
3457
3282
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3468,7 +3293,7 @@ let ProgressesController = class ProgressesController {
3468
3293
  this.connectionType = !mainEndpoint ? "polling" : "socket";
3469
3294
  }
3470
3295
  getProgress(id) {
3471
- return __awaiter$5(this, void 0, void 0, function* () {
3296
+ return __awaiter$6(this, void 0, void 0, function* () {
3472
3297
  const progress = yield this.progresses.get(id);
3473
3298
  if (!progress)
3474
3299
  return null;
@@ -3500,7 +3325,7 @@ var __decorate$6 = (this && this.__decorate) || function (decorators, target, ke
3500
3325
  var __metadata$3 = (this && this.__metadata) || function (k, v) {
3501
3326
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3502
3327
  };
3503
- var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3328
+ var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3504
3329
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3505
3330
  return new (P || (P = Promise))(function (resolve, reject) {
3506
3331
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3518,7 +3343,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3518
3343
  return this.configuration.resolve("nodeEnv") === "development";
3519
3344
  }
3520
3345
  error(error, req, res, next) {
3521
- return __awaiter$4(this, void 0, void 0, function* () {
3346
+ return __awaiter$5(this, void 0, void 0, function* () {
3522
3347
  const result = yield this.getResult(error, req, res);
3523
3348
  if (this.isDev) {
3524
3349
  console.log("ERROR", result, res.statusCode);
@@ -3527,7 +3352,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3527
3352
  });
3528
3353
  }
3529
3354
  getResult(error, req, res) {
3530
- return __awaiter$4(this, void 0, void 0, function* () {
3355
+ return __awaiter$5(this, void 0, void 0, function* () {
3531
3356
  const result = {};
3532
3357
  if (error instanceof BadRequestError) {
3533
3358
  res.status(400);
@@ -3673,7 +3498,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
3673
3498
  var __param = (this && this.__param) || function (paramIndex, decorator) {
3674
3499
  return function (target, key) { decorator(target, key, paramIndex); }
3675
3500
  };
3676
- var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3501
+ var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3677
3502
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3678
3503
  return new (P || (P = Promise))(function (resolve, reject) {
3679
3504
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3688,7 +3513,7 @@ let ProgressController = class ProgressController {
3688
3513
  this.socketServer = socketServer;
3689
3514
  }
3690
3515
  advanceProgress(client, progressId) {
3691
- return __awaiter$3(this, void 0, void 0, function* () {
3516
+ return __awaiter$4(this, void 0, void 0, function* () {
3692
3517
  const progress = yield this.progresses.get(progressId);
3693
3518
  if (!progress)
3694
3519
  return;
@@ -3702,7 +3527,7 @@ let ProgressController = class ProgressController {
3702
3527
  });
3703
3528
  }
3704
3529
  setProgressInterest(client, progressId) {
3705
- return __awaiter$3(this, void 0, void 0, function* () {
3530
+ return __awaiter$4(this, void 0, void 0, function* () {
3706
3531
  const progress = yield this.progresses.get(progressId);
3707
3532
  if (!progress)
3708
3533
  return;
@@ -3753,6 +3578,53 @@ CompressionMiddleware = __decorate([
3753
3578
  Middleware$1()
3754
3579
  ], CompressionMiddleware);
3755
3580
 
3581
+ var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3582
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3583
+ return new (P || (P = Promise))(function (resolve, reject) {
3584
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3585
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3586
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3587
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3588
+ });
3589
+ };
3590
+ function setupStatic(rootFolder, container) {
3591
+ return __awaiter$3(this, void 0, void 0, function* () {
3592
+ const browserFolder = resolve(rootFolder || __dirname, `public_html`);
3593
+ const app = container.get(EXPRESS);
3594
+ const ep = container.get(EndpointProvider);
3595
+ console.log(browserFolder, existsSync(browserFolder));
3596
+ if (existsSync(browserFolder)) {
3597
+ console.log(`public_html exists. setting up static files serving...`);
3598
+ app.use(static$1(browserFolder, {
3599
+ maxAge: "1y"
3600
+ }));
3601
+ }
3602
+ else {
3603
+ console.log(`public_html does not exist on path: "${browserFolder}"`);
3604
+ }
3605
+ yield ep.configure(app);
3606
+ });
3607
+ }
3608
+
3609
+ class BaseDoc {
3610
+ /**
3611
+ * Casts this to DocumentType<this> to allow using document methods in get/set-s
3612
+ */
3613
+ cast() {
3614
+ return this;
3615
+ }
3616
+ /**
3617
+ * Gets a pre-compiled model from typegoose cache by its class type
3618
+ * @param type
3619
+ */
3620
+ model(type) {
3621
+ return getModelForClass(type);
3622
+ }
3623
+ }
3624
+ // @ts-ignore
3625
+ const PrimitiveArray = Types.Array;
3626
+ const DocumentArray = Types.DocumentArray;
3627
+
3756
3628
  class Tree {
3757
3629
  constructor(container, exists, path) {
3758
3630
  this.container = container;
@@ -3957,45 +3829,6 @@ var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P,
3957
3829
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3958
3830
  });
3959
3831
  };
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
3832
  class LazyAssetGenerator {
4000
3833
  constructor(assetResolver, progresses, lazyId) {
4001
3834
  this.assetResolver = assetResolver;
@@ -4009,7 +3842,7 @@ class LazyAssetGenerator {
4009
3842
  return this.assetResolver.lazyAssets;
4010
3843
  }
4011
3844
  process(messaging) {
4012
- return __awaiter$1(this, void 0, void 0, function* () {
3845
+ return __awaiter$2(this, void 0, void 0, function* () {
4013
3846
  const lazyAsset = yield this.lazyAssets.read(this.lazyId);
4014
3847
  let progress = yield this.progresses.get(lazyAsset.progressId);
4015
3848
  if (!progress || progress.canceled)
@@ -4033,6 +3866,227 @@ class LazyAssetGenerator {
4033
3866
  }
4034
3867
  }
4035
3868
 
3869
+ var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3870
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3871
+ return new (P || (P = Promise))(function (resolve, reject) {
3872
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3873
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3874
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3875
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
3876
+ });
3877
+ };
3878
+ const pluginsKey = "typegoose:plugins";
3879
+ /**
3880
+ * A mongoose/typegoose plugin to inject services from the main di container to a schema as virtuals
3881
+ * @param schema
3882
+ * @param services
3883
+ */
3884
+ function injectServices(schema, services) {
3885
+ const serviceMap = {};
3886
+ if (!isObject(services)) {
3887
+ throw new Error(`services object should be defined to inject services to schema!`);
3888
+ }
3889
+ Object.keys(services).forEach(prop => {
3890
+ schema
3891
+ .virtual(prop)
3892
+ .get(() => {
3893
+ const diContainer = diContainers.appContainer;
3894
+ serviceMap[prop] = serviceMap[prop] || (!diContainer ? {} : diContainer.resolve(services[prop]));
3895
+ return serviceMap[prop];
3896
+ });
3897
+ });
3898
+ }
3899
+ /**
3900
+ * Decorates a property to inject a service with the help of the injectServices mongoose/typegoose plugin
3901
+ * @param token optional InjectionToken to use
3902
+ * @return PropertyDecorator
3903
+ */
3904
+ function service(token) {
3905
+ return (target, propertyKey) => {
3906
+ var _a;
3907
+ const propertyType = Reflect.getOwnMetadata("design:type", target, propertyKey);
3908
+ const plugins = Array.from((_a = Reflect.getMetadata(pluginsKey, target.constructor)) !== null && _a !== void 0 ? _a : []);
3909
+ let plugin = plugins.find(t => t.mongoosePlugin === injectServices);
3910
+ if (!plugin) {
3911
+ plugin = { mongoosePlugin: injectServices, options: {} };
3912
+ plugins.push(plugin);
3913
+ }
3914
+ plugin.options = Object.assign(plugin.options || {}, { [propertyKey]: token !== null && token !== void 0 ? token : propertyType });
3915
+ Reflect.defineMetadata(pluginsKey, plugins, target.constructor);
3916
+ };
3917
+ }
3918
+ /**
3919
+ * Paginate using a typegoose model using a simple where query and pagination params
3920
+ * @param model Typegoose model
3921
+ * @param where Simple query to filter the results
3922
+ * @param params Pagination params
3923
+ */
3924
+ function paginate(model, where, params) {
3925
+ return model.countDocuments(where).then(count => {
3926
+ let query = model.find(where);
3927
+ if (isString(params.sort)) {
3928
+ query = query.sort(params.sort);
3929
+ }
3930
+ if (isArray(params.populate)) {
3931
+ params.populate.forEach(field => {
3932
+ query = query.populate(field);
3933
+ });
3934
+ }
3935
+ return (params.limit > 0 ? query.skip(params.page * params.limit).limit(params.limit) : query).then(items => {
3936
+ const meta = { total: count };
3937
+ return { count, items, meta };
3938
+ });
3939
+ });
3940
+ }
3941
+ function lookupStages(from, localField, as = null, foreignField = "_id", shouldUnwind = true) {
3942
+ as = as || localField.replace("Id", "");
3943
+ const stages = [
3944
+ {
3945
+ $lookup: {
3946
+ from,
3947
+ localField,
3948
+ foreignField,
3949
+ as
3950
+ }
3951
+ },
3952
+ {
3953
+ $unwind: {
3954
+ path: `$${as}`,
3955
+ preserveNullAndEmptyArrays: true
3956
+ }
3957
+ }
3958
+ ];
3959
+ if (!shouldUnwind) {
3960
+ stages.splice(1, 1);
3961
+ }
3962
+ return stages;
3963
+ }
3964
+ function letsLookupStage(from, pipeline, as = null, letFields = null) {
3965
+ as = as || from;
3966
+ letFields = letFields || { id: "$_id" };
3967
+ return {
3968
+ $lookup: {
3969
+ from,
3970
+ let: letFields,
3971
+ pipeline,
3972
+ as
3973
+ }
3974
+ };
3975
+ }
3976
+ function matchStage(match) {
3977
+ return { $match: match };
3978
+ }
3979
+ function matchField(field, filter, when) {
3980
+ return { field, filter, when };
3981
+ }
3982
+ function matchFieldStages(...fields) {
3983
+ const match = {};
3984
+ fields.forEach(field => {
3985
+ if (field.when) {
3986
+ match[field.field] = field.filter;
3987
+ }
3988
+ });
3989
+ return Object.keys(match).length > 0 ? [matchStage(match)] : [];
3990
+ }
3991
+ function projectStage(fields) {
3992
+ return { $project: fields };
3993
+ }
3994
+ function unwindStage(fieldOrOpts) {
3995
+ return { $unwind: fieldOrOpts };
3996
+ }
3997
+ function hydratePopulated(modelType, json) {
3998
+ let object = modelType.hydrate(json);
3999
+ for (const [path, obj] of Object.entries(modelType.schema.obj)) {
4000
+ let { ref, type } = obj;
4001
+ if (Array.isArray(type) && type.length > 0) {
4002
+ ref = type[0].ref;
4003
+ }
4004
+ if (!ref)
4005
+ continue;
4006
+ const value = getValue$1(path, json);
4007
+ const hydrateVal = val => {
4008
+ if (val == null || val instanceof Types.ObjectId)
4009
+ return val;
4010
+ return hydratePopulated(model(ref), val);
4011
+ };
4012
+ if (Array.isArray(value)) {
4013
+ setValue(path, value.map(hydrateVal), object);
4014
+ continue;
4015
+ }
4016
+ setValue(path, hydrateVal(value), object);
4017
+ }
4018
+ return object;
4019
+ }
4020
+ function paginateAggregations(model, aggregations, params, metaProjection = {}) {
4021
+ return __awaiter$1(this, void 0, void 0, function* () {
4022
+ const sortField = !isString(params.sort) || !params.sort ? null : (params.sort.startsWith("-") ? params.sort.substr(1) : params.sort);
4023
+ const sortAggregation = !sortField ? [] : [{
4024
+ $sort: { [sortField]: sortField == params.sort ? 1 : -1 }
4025
+ }];
4026
+ const result = yield model.aggregate([
4027
+ ...aggregations,
4028
+ ...sortAggregation,
4029
+ {
4030
+ $group: {
4031
+ _id: "results",
4032
+ result: { $push: "$$CURRENT" }
4033
+ }
4034
+ },
4035
+ {
4036
+ $project: {
4037
+ _id: 0,
4038
+ items: params.limit > 0 ? { $slice: ["$result", params.page * params.limit, params.limit] } : "$result",
4039
+ count: { $size: "$result" },
4040
+ meta: Object.assign({ total: { $size: "$result" } }, metaProjection)
4041
+ }
4042
+ }
4043
+ ]);
4044
+ const pagination = result[0];
4045
+ if (!pagination) {
4046
+ return { items: [], count: 0, meta: { total: 0 } };
4047
+ }
4048
+ pagination.items = pagination.items.map(i => hydratePopulated(model, i));
4049
+ return pagination;
4050
+ });
4051
+ }
4052
+ function ResolveEntity(model, extraCheck) {
4053
+ const modelName = model.modelName;
4054
+ const paramName = modelName.toLowerCase();
4055
+ return createParamDecorator({
4056
+ required: false,
4057
+ value: (action) => __awaiter$1(this, void 0, void 0, function* () {
4058
+ const req = action.request;
4059
+ const token = req.header(`x-${paramName}-token`);
4060
+ const id = req.params[`${paramName}Id`];
4061
+ if (!id && !token) {
4062
+ throw new BadRequestError(`${modelName} id or token should be defined!`);
4063
+ }
4064
+ const query = !token
4065
+ ? model.findById(id)
4066
+ : model.findOne({ token });
4067
+ let doc = null;
4068
+ if (isFunction(extraCheck)) {
4069
+ try {
4070
+ doc = yield valueToPromise(extraCheck(query, action));
4071
+ }
4072
+ catch (e) {
4073
+ throw new BadRequestError(`${modelName} check error: ${e.message || e}`);
4074
+ }
4075
+ }
4076
+ else {
4077
+ doc = yield query;
4078
+ }
4079
+ if (!doc) {
4080
+ throw new HttpError(404, !token
4081
+ ? `${modelName} could not be found with id: ${id}`
4082
+ : `${modelName} could not be found with token: ${token}`);
4083
+ }
4084
+ action.request[paramName] = doc;
4085
+ return doc;
4086
+ })
4087
+ });
4088
+ }
4089
+
4036
4090
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4037
4091
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4038
4092
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -4294,5 +4348,5 @@ function setupBackend(config, providers, parent) {
4294
4348
  * Generated bundle index. Do not edit.
4295
4349
  */
4296
4350
 
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 };
4351
+ 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
4352
  //# sourceMappingURL=stemy-backend.js.map