@stemy/backend 3.3.1 → 3.4.2

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, 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,66 +417,6 @@ function getFunctionParams(func) {
556
417
  });
557
418
  return params;
558
419
  }
559
- function proxyFunction(name) {
560
- return function () {
561
- const args = Array.from(arguments);
562
- args.unshift(this);
563
- return this.helper[name].apply(this.helper, args);
564
- };
565
- }
566
- function proxyFunctions(schema, helper, paramName = null) {
567
- paramName = paramName || lcFirst(getConstructorName(helper)).replace(/helper$/gi, "");
568
- const descriptors = Object.getOwnPropertyDescriptors(helper.prototype);
569
- Object.keys(descriptors).forEach(name => {
570
- const func = descriptors[name].value;
571
- if (isFunction(func) && name !== "constructor") {
572
- const paramNames = getFunctionParams(func);
573
- if (paramNames[0] == paramName) {
574
- schema.methods[name] = proxyFunction(name);
575
- }
576
- }
577
- });
578
- injectServices(schema, {
579
- "helper": helper
580
- });
581
- }
582
- function ResolveEntity(model, extraCheck) {
583
- const modelName = model.modelName;
584
- const paramName = modelName.toLowerCase();
585
- return createParamDecorator({
586
- required: false,
587
- value: (action) => __awaiter$w(this, void 0, void 0, function* () {
588
- const req = action.request;
589
- const token = req.header(`x-${paramName}-token`);
590
- const id = req.params[`${paramName}Id`];
591
- if (!id && !token) {
592
- throw new BadRequestError(`${modelName} id or token should be defined!`);
593
- }
594
- const query = !token
595
- ? model.findById(id)
596
- : model.findOne({ token });
597
- let doc = null;
598
- if (isFunction(extraCheck)) {
599
- try {
600
- doc = yield valueToPromise(extraCheck(query, action));
601
- }
602
- catch (e) {
603
- throw new BadRequestError(`${modelName} check error: ${e.message || e}`);
604
- }
605
- }
606
- else {
607
- doc = yield query;
608
- }
609
- if (!doc) {
610
- throw new HttpError(404, !token
611
- ? `${modelName} could not be found with id: ${id}`
612
- : `${modelName} could not be found with token: ${token}`);
613
- }
614
- action.request[paramName] = doc;
615
- return doc;
616
- })
617
- });
618
- }
619
420
  function getFileName(path, withExtension = false) {
620
421
  const name = basename(path || "");
621
422
  return withExtension ? name : name.split(".").slice(0, -1).join(".");
@@ -980,7 +781,7 @@ var __decorate$x = (this && this.__decorate) || function (decorators, target, ke
980
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;
981
782
  return c > 3 && r && Object.defineProperty(target, key, r), r;
982
783
  };
983
- var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
784
+ var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
984
785
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
985
786
  return new (P || (P = Promise))(function (resolve, reject) {
986
787
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1016,7 +817,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
1016
817
  }
1017
818
  static fileTypeFromBuffer(buffer) {
1018
819
  var _a;
1019
- return __awaiter$v(this, void 0, void 0, function* () {
820
+ return __awaiter$w(this, void 0, void 0, function* () {
1020
821
  const type = ((_a = yield fromBuffer(buffer)) !== null && _a !== void 0 ? _a : { ext: "txt", mime: "text/plain" });
1021
822
  if (AssetProcessor_1.checkTextFileType(type)) {
1022
823
  return AssetProcessor_1.fixTextFileType(type, buffer);
@@ -1043,7 +844,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
1043
844
  return imageTypes.indexOf(contentType) >= 0;
1044
845
  }
1045
846
  static copyImageMeta(buffer, metadata, fileType) {
1046
- return __awaiter$v(this, void 0, void 0, function* () {
847
+ return __awaiter$w(this, void 0, void 0, function* () {
1047
848
  if (fileType.mime === "image/svg+xml") {
1048
849
  const match = /<svg([^<>]+)>/gi.exec(buffer.toString("utf8"));
1049
850
  if (match && match.length > 1) {
@@ -1082,7 +883,7 @@ let AssetProcessor = AssetProcessor_1 = class AssetProcessor {
1082
883
  });
1083
884
  }
1084
885
  process(buffer, metadata, fileType) {
1085
- return __awaiter$v(this, void 0, void 0, function* () {
886
+ return __awaiter$w(this, void 0, void 0, function* () {
1086
887
  if (AssetProcessor_1.isImage(fileType.mime)) {
1087
888
  buffer = yield AssetProcessor_1.copyImageMeta(buffer, metadata, fileType);
1088
889
  }
@@ -1159,7 +960,7 @@ var __decorate$v = (this && this.__decorate) || function (decorators, target, ke
1159
960
  var __metadata$p = (this && this.__metadata) || function (k, v) {
1160
961
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1161
962
  };
1162
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
963
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1163
964
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1164
965
  return new (P || (P = Promise))(function (resolve, reject) {
1165
966
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1185,7 +986,7 @@ let MongoConnector = class MongoConnector {
1185
986
  return this.fsBucket;
1186
987
  }
1187
988
  connect() {
1188
- return __awaiter$u(this, void 0, void 0, function* () {
989
+ return __awaiter$v(this, void 0, void 0, function* () {
1189
990
  if (this.db)
1190
991
  return this.db;
1191
992
  this.conn = (yield connect(this.configuration.resolve("mongoUri"), {
@@ -1194,6 +995,7 @@ let MongoConnector = class MongoConnector {
1194
995
  pass: this.configuration.resolve("mongoPassword")
1195
996
  })).connection;
1196
997
  this.db = this.conn.db;
998
+ console.log("DB INSTANCE", getType(this.db));
1197
999
  this.fsBucket = new GridFSBucket(this.db, { bucketName: "assets" });
1198
1000
  });
1199
1001
  }
@@ -1204,7 +1006,7 @@ MongoConnector = __decorate$v([
1204
1006
  __metadata$p("design:paramtypes", [Configuration])
1205
1007
  ], MongoConnector);
1206
1008
 
1207
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1009
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1208
1010
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1209
1011
  return new (P || (P = Promise))(function (resolve, reject) {
1210
1012
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1226,7 +1028,7 @@ class BaseEntity {
1226
1028
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1227
1029
  }
1228
1030
  load() {
1229
- return __awaiter$t(this, void 0, void 0, function* () {
1031
+ return __awaiter$u(this, void 0, void 0, function* () {
1230
1032
  const res = yield this.collection.findOne({ _id: this.mId });
1231
1033
  this.deleted = !res;
1232
1034
  this.data = res || {};
@@ -1241,7 +1043,7 @@ class BaseEntity {
1241
1043
  }
1242
1044
  }
1243
1045
 
1244
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1046
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1245
1047
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1246
1048
  return new (P || (P = Promise))(function (resolve, reject) {
1247
1049
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1268,7 +1070,7 @@ class Asset extends BaseEntity {
1268
1070
  return this.bucket.openDownloadStream(this.mId);
1269
1071
  }
1270
1072
  unlink() {
1271
- return __awaiter$s(this, void 0, void 0, function* () {
1073
+ return __awaiter$t(this, void 0, void 0, function* () {
1272
1074
  return deleteFromBucket(this.bucket, this.mId);
1273
1075
  });
1274
1076
  }
@@ -1276,7 +1078,7 @@ class Asset extends BaseEntity {
1276
1078
  return streamToBuffer(this.stream);
1277
1079
  }
1278
1080
  download(metadata) {
1279
- return __awaiter$s(this, void 0, void 0, function* () {
1081
+ return __awaiter$t(this, void 0, void 0, function* () {
1280
1082
  metadata = Object.assign(this.metadata, metadata || {});
1281
1083
  metadata.downloadCount = isNaN(metadata.downloadCount) || !metadata.firstDownload
1282
1084
  ? 1
@@ -1288,18 +1090,18 @@ class Asset extends BaseEntity {
1288
1090
  });
1289
1091
  }
1290
1092
  getImage(params = null) {
1291
- return __awaiter$s(this, void 0, void 0, function* () {
1093
+ return __awaiter$t(this, void 0, void 0, function* () {
1292
1094
  return toImage(this.stream, params, this.metadata);
1293
1095
  });
1294
1096
  }
1295
1097
  downloadImage(params, metadata) {
1296
- return __awaiter$s(this, void 0, void 0, function* () {
1098
+ return __awaiter$t(this, void 0, void 0, function* () {
1297
1099
  return toImage(yield this.download(metadata), params, this.metadata);
1298
1100
  });
1299
1101
  }
1300
1102
  }
1301
1103
 
1302
- var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1104
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1303
1105
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1304
1106
  return new (P || (P = Promise))(function (resolve, reject) {
1305
1107
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1320,17 +1122,17 @@ class TempAsset {
1320
1122
  return bufferToStream(this.buffer);
1321
1123
  }
1322
1124
  unlink() {
1323
- return __awaiter$r(this, void 0, void 0, function* () {
1125
+ return __awaiter$s(this, void 0, void 0, function* () {
1324
1126
  throw new Error(`Temp asset '${this.id}' can not be removed!`);
1325
1127
  });
1326
1128
  }
1327
1129
  getBuffer() {
1328
- return __awaiter$r(this, void 0, void 0, function* () {
1130
+ return __awaiter$s(this, void 0, void 0, function* () {
1329
1131
  return this.buffer;
1330
1132
  });
1331
1133
  }
1332
1134
  download(metadata) {
1333
- return __awaiter$r(this, void 0, void 0, function* () {
1135
+ return __awaiter$s(this, void 0, void 0, function* () {
1334
1136
  return this.stream;
1335
1137
  });
1336
1138
  }
@@ -1342,12 +1144,12 @@ class TempAsset {
1342
1144
  return this.downloadImage(params);
1343
1145
  }
1344
1146
  save() {
1345
- return __awaiter$r(this, void 0, void 0, function* () {
1147
+ return __awaiter$s(this, void 0, void 0, function* () {
1346
1148
  return this;
1347
1149
  });
1348
1150
  }
1349
1151
  load() {
1350
- return __awaiter$r(this, void 0, void 0, function* () {
1152
+ return __awaiter$s(this, void 0, void 0, function* () {
1351
1153
  return this;
1352
1154
  });
1353
1155
  }
@@ -1370,7 +1172,7 @@ var __decorate$u = (this && this.__decorate) || function (decorators, target, ke
1370
1172
  var __metadata$o = (this && this.__metadata) || function (k, v) {
1371
1173
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1372
1174
  };
1373
- var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1175
+ var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1374
1176
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1375
1177
  return new (P || (P = Promise))(function (resolve, reject) {
1376
1178
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1388,7 +1190,7 @@ let Assets = class Assets {
1388
1190
  this.collection = (_a = connector.database) === null || _a === void 0 ? void 0 : _a.collection("assets.files");
1389
1191
  }
1390
1192
  write(stream, contentType = null, metadata = null) {
1391
- return __awaiter$q(this, void 0, void 0, function* () {
1193
+ return __awaiter$r(this, void 0, void 0, function* () {
1392
1194
  const uploadStream = copyStream(stream);
1393
1195
  const buffer = yield streamToBuffer(stream);
1394
1196
  let fileType = { ext: "", mime: contentType };
@@ -1406,7 +1208,7 @@ let Assets = class Assets {
1406
1208
  });
1407
1209
  }
1408
1210
  writeBuffer(buffer, metadata = null, contentType = null) {
1409
- return __awaiter$q(this, void 0, void 0, function* () {
1211
+ return __awaiter$r(this, void 0, void 0, function* () {
1410
1212
  let fileType = { ext: "", mime: contentType };
1411
1213
  try {
1412
1214
  fileType = yield AssetProcessor.fileTypeFromBuffer(buffer);
@@ -1423,13 +1225,13 @@ let Assets = class Assets {
1423
1225
  });
1424
1226
  }
1425
1227
  writeUrl(url, metadata = null) {
1426
- return __awaiter$q(this, void 0, void 0, function* () {
1228
+ return __awaiter$r(this, void 0, void 0, function* () {
1427
1229
  const buffer = (yield axios({ url, responseType: "arraybuffer" })).data;
1428
1230
  return this.writeBuffer(buffer, metadata);
1429
1231
  });
1430
1232
  }
1431
1233
  download(url, contentType = null) {
1432
- return __awaiter$q(this, void 0, void 0, function* () {
1234
+ return __awaiter$r(this, void 0, void 0, function* () {
1433
1235
  let buffer = (yield axios({ url, responseType: "arraybuffer" })).data;
1434
1236
  let fileType = { ext: "", mime: contentType };
1435
1237
  try {
@@ -1450,18 +1252,18 @@ let Assets = class Assets {
1450
1252
  });
1451
1253
  }
1452
1254
  read(id) {
1453
- return __awaiter$q(this, void 0, void 0, function* () {
1255
+ return __awaiter$r(this, void 0, void 0, function* () {
1454
1256
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
1455
1257
  });
1456
1258
  }
1457
1259
  find(where) {
1458
- return __awaiter$q(this, void 0, void 0, function* () {
1260
+ return __awaiter$r(this, void 0, void 0, function* () {
1459
1261
  const data = yield this.collection.findOne(where);
1460
1262
  return !data ? null : new Asset(data._id, data, this.collection, this.bucket);
1461
1263
  });
1462
1264
  }
1463
1265
  findMany(where) {
1464
- return __awaiter$q(this, void 0, void 0, function* () {
1266
+ return __awaiter$r(this, void 0, void 0, function* () {
1465
1267
  const cursor = this.collection.find(where);
1466
1268
  const items = (yield cursor.toArray()) || [];
1467
1269
  const result = [];
@@ -1474,13 +1276,13 @@ let Assets = class Assets {
1474
1276
  });
1475
1277
  }
1476
1278
  deleteMany(where) {
1477
- return __awaiter$q(this, void 0, void 0, function* () {
1279
+ return __awaiter$r(this, void 0, void 0, function* () {
1478
1280
  const assets = yield this.findMany(where);
1479
1281
  return Promise.all(assets.map(a => a.unlink()));
1480
1282
  });
1481
1283
  }
1482
1284
  unlink(id) {
1483
- return __awaiter$q(this, void 0, void 0, function* () {
1285
+ return __awaiter$r(this, void 0, void 0, function* () {
1484
1286
  const asset = yield this.read(id);
1485
1287
  if (!asset)
1486
1288
  return null;
@@ -1488,7 +1290,7 @@ let Assets = class Assets {
1488
1290
  });
1489
1291
  }
1490
1292
  upload(stream, fileType, metadata) {
1491
- return __awaiter$q(this, void 0, void 0, function* () {
1293
+ return __awaiter$r(this, void 0, void 0, function* () {
1492
1294
  const contentType = fileType.mime.trim();
1493
1295
  metadata = Object.assign({
1494
1296
  downloadCount: 0,
@@ -1525,7 +1327,7 @@ Assets = __decorate$u([
1525
1327
  __metadata$o("design:paramtypes", [MongoConnector, AssetProcessor])
1526
1328
  ], Assets);
1527
1329
 
1528
- var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1330
+ var __awaiter$q = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1529
1331
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1530
1332
  return new (P || (P = Promise))(function (resolve, reject) {
1531
1333
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1556,7 +1358,7 @@ class LazyAsset extends BaseEntity {
1556
1358
  return this.data.assetId;
1557
1359
  }
1558
1360
  unlink() {
1559
- return __awaiter$p(this, void 0, void 0, function* () {
1361
+ return __awaiter$q(this, void 0, void 0, function* () {
1560
1362
  yield this.load();
1561
1363
  if (!this.progressId) {
1562
1364
  yield this.collection.deleteOne({ _id: this.mId });
@@ -1579,7 +1381,7 @@ class LazyAsset extends BaseEntity {
1579
1381
  });
1580
1382
  }
1581
1383
  loadAsset() {
1582
- return __awaiter$p(this, void 0, void 0, function* () {
1384
+ return __awaiter$q(this, void 0, void 0, function* () {
1583
1385
  yield this.load();
1584
1386
  if (this.deleted)
1585
1387
  return null;
@@ -1595,14 +1397,14 @@ class LazyAsset extends BaseEntity {
1595
1397
  });
1596
1398
  }
1597
1399
  writeAsset(asset) {
1598
- return __awaiter$p(this, void 0, void 0, function* () {
1400
+ return __awaiter$q(this, void 0, void 0, function* () {
1599
1401
  this.data.assetId = asset.id;
1600
1402
  yield this.save();
1601
1403
  return asset;
1602
1404
  });
1603
1405
  }
1604
1406
  startWorkingOnAsset(fromLoad) {
1605
- return __awaiter$p(this, void 0, void 0, function* () {
1407
+ return __awaiter$q(this, void 0, void 0, function* () {
1606
1408
  this.data.progressId = (yield this.progresses.create()).id;
1607
1409
  this.data.assetId = null;
1608
1410
  yield this.save();
@@ -1623,7 +1425,7 @@ var __metadata$n = (this && this.__metadata) || function (k, v) {
1623
1425
  var __param$7 = (this && this.__param) || function (paramIndex, decorator) {
1624
1426
  return function (target, key) { decorator(target, key, paramIndex); }
1625
1427
  };
1626
- var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1428
+ var __awaiter$p = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1627
1429
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1628
1430
  return new (P || (P = Promise))(function (resolve, reject) {
1629
1431
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1662,7 +1464,7 @@ let JobManager = class JobManager {
1662
1464
  .pipe(map(t => t.params)).subscribe(cb);
1663
1465
  }
1664
1466
  process(jobType, params = {}) {
1665
- return __awaiter$o(this, void 0, void 0, function* () {
1467
+ return __awaiter$p(this, void 0, void 0, function* () {
1666
1468
  let instance = null;
1667
1469
  try {
1668
1470
  instance = this.resolveJobInstance(jobType, params);
@@ -1675,12 +1477,12 @@ let JobManager = class JobManager {
1675
1477
  });
1676
1478
  }
1677
1479
  enqueueWithName(name, params = {}) {
1678
- return __awaiter$o(this, void 0, void 0, function* () {
1480
+ return __awaiter$p(this, void 0, void 0, function* () {
1679
1481
  return this.sendToWorkers(this.tryResolveFromName(name, params), params);
1680
1482
  });
1681
1483
  }
1682
1484
  enqueue(jobType, params = {}) {
1683
- return __awaiter$o(this, void 0, void 0, function* () {
1485
+ return __awaiter$p(this, void 0, void 0, function* () {
1684
1486
  return this.sendToWorkers(this.tryResolveAndInit(jobType, params), params);
1685
1487
  });
1686
1488
  }
@@ -1707,7 +1509,7 @@ let JobManager = class JobManager {
1707
1509
  });
1708
1510
  }
1709
1511
  startProcessing() {
1710
- return __awaiter$o(this, void 0, void 0, function* () {
1512
+ return __awaiter$p(this, void 0, void 0, function* () {
1711
1513
  if (this.processing)
1712
1514
  return null;
1713
1515
  this.processing = true;
@@ -1724,7 +1526,7 @@ let JobManager = class JobManager {
1724
1526
  this.workerPull = socket("pull");
1725
1527
  yield this.workerPull.connect(pullHost);
1726
1528
  console.log(`Worker consumer connected to: ${pullHost}`);
1727
- 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* () {
1728
1530
  try {
1729
1531
  const jobName = name.toString("utf8");
1730
1532
  const jobParams = JSON.parse(args.toString("utf8"));
@@ -1803,7 +1605,7 @@ let JobManager = class JobManager {
1803
1605
  return container.resolve(jobType);
1804
1606
  }
1805
1607
  sendToWorkers(jobName, params) {
1806
- return __awaiter$o(this, void 0, void 0, function* () {
1608
+ return __awaiter$p(this, void 0, void 0, function* () {
1807
1609
  const publisher = yield this.apiPush;
1808
1610
  const uniqueId = new ObjectId$1().toHexString();
1809
1611
  yield publisher.send([jobName, JSON.stringify(params), uniqueId]);
@@ -1818,7 +1620,7 @@ JobManager = __decorate$t([
1818
1620
  __metadata$n("design:paramtypes", [Configuration, Object, Array])
1819
1621
  ], JobManager);
1820
1622
 
1821
- var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1623
+ var __awaiter$o = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1822
1624
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1823
1625
  return new (P || (P = Promise))(function (resolve, reject) {
1824
1626
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -1857,7 +1659,7 @@ class Progress extends BaseEntity {
1857
1659
  return this;
1858
1660
  }
1859
1661
  createSubProgress(progressValue, max, message) {
1860
- return __awaiter$n(this, void 0, void 0, function* () {
1662
+ return __awaiter$o(this, void 0, void 0, function* () {
1861
1663
  if (max <= 0 && progressValue > 0) {
1862
1664
  yield this.advance(progressValue);
1863
1665
  }
@@ -1869,7 +1671,7 @@ class Progress extends BaseEntity {
1869
1671
  });
1870
1672
  }
1871
1673
  setMax(max) {
1872
- return __awaiter$n(this, void 0, void 0, function* () {
1674
+ return __awaiter$o(this, void 0, void 0, function* () {
1873
1675
  if (isNaN(max) || max <= 0) {
1874
1676
  throw "Max progress value must be bigger than zero";
1875
1677
  }
@@ -1878,19 +1680,19 @@ class Progress extends BaseEntity {
1878
1680
  });
1879
1681
  }
1880
1682
  setMessage(message) {
1881
- return __awaiter$n(this, void 0, void 0, function* () {
1683
+ return __awaiter$o(this, void 0, void 0, function* () {
1882
1684
  this.data.message = message;
1883
1685
  yield this.save();
1884
1686
  });
1885
1687
  }
1886
1688
  setError(error) {
1887
- return __awaiter$n(this, void 0, void 0, function* () {
1689
+ return __awaiter$o(this, void 0, void 0, function* () {
1888
1690
  this.data.error = error;
1889
1691
  yield this.save();
1890
1692
  });
1891
1693
  }
1892
1694
  advance(value = 1) {
1893
- return __awaiter$n(this, void 0, void 0, function* () {
1695
+ return __awaiter$o(this, void 0, void 0, function* () {
1894
1696
  if (isNaN(value) || value <= 0) {
1895
1697
  throw "Advance value must be bigger than zero";
1896
1698
  }
@@ -1902,7 +1704,7 @@ class Progress extends BaseEntity {
1902
1704
  });
1903
1705
  }
1904
1706
  cancel() {
1905
- return __awaiter$n(this, void 0, void 0, function* () {
1707
+ return __awaiter$o(this, void 0, void 0, function* () {
1906
1708
  this.data.canceled = true;
1907
1709
  yield this.save();
1908
1710
  });
@@ -1959,7 +1761,7 @@ class SubProgress {
1959
1761
  return this;
1960
1762
  }
1961
1763
  createSubProgress(progressValue, max, message) {
1962
- return __awaiter$n(this, void 0, void 0, function* () {
1764
+ return __awaiter$o(this, void 0, void 0, function* () {
1963
1765
  if (max <= 0 && progressValue > 0) {
1964
1766
  yield this.advance(progressValue);
1965
1767
  }
@@ -1970,7 +1772,7 @@ class SubProgress {
1970
1772
  });
1971
1773
  }
1972
1774
  setMax(max) {
1973
- return __awaiter$n(this, void 0, void 0, function* () {
1775
+ return __awaiter$o(this, void 0, void 0, function* () {
1974
1776
  if (isNaN(max) || max <= 0) {
1975
1777
  throw "Max progress value must be bigger than zero";
1976
1778
  }
@@ -1979,21 +1781,21 @@ class SubProgress {
1979
1781
  });
1980
1782
  }
1981
1783
  setMessage(message) {
1982
- return __awaiter$n(this, void 0, void 0, function* () {
1784
+ return __awaiter$o(this, void 0, void 0, function* () {
1983
1785
  if (!this.parent)
1984
1786
  return null;
1985
1787
  yield this.parent.setMessage(message);
1986
1788
  });
1987
1789
  }
1988
1790
  setError(error) {
1989
- return __awaiter$n(this, void 0, void 0, function* () {
1791
+ return __awaiter$o(this, void 0, void 0, function* () {
1990
1792
  if (!this.parent)
1991
1793
  return null;
1992
1794
  yield this.parent.setError(error);
1993
1795
  });
1994
1796
  }
1995
1797
  advance(value = 1) {
1996
- return __awaiter$n(this, void 0, void 0, function* () {
1798
+ return __awaiter$o(this, void 0, void 0, function* () {
1997
1799
  if (isNaN(value) || value <= 0) {
1998
1800
  throw "Advance value must be bigger than zero";
1999
1801
  }
@@ -2002,14 +1804,14 @@ class SubProgress {
2002
1804
  });
2003
1805
  }
2004
1806
  cancel() {
2005
- return __awaiter$n(this, void 0, void 0, function* () {
1807
+ return __awaiter$o(this, void 0, void 0, function* () {
2006
1808
  if (!this.parent)
2007
1809
  return null;
2008
1810
  yield this.parent.cancel();
2009
1811
  });
2010
1812
  }
2011
1813
  save() {
2012
- return __awaiter$n(this, void 0, void 0, function* () {
1814
+ return __awaiter$o(this, void 0, void 0, function* () {
2013
1815
  const ratio = this.max > 0 ? this.mCurrent / this.max : 0;
2014
1816
  const newProgress = this.progressFrom + Math.round(this.progressValue * ratio);
2015
1817
  const current = this.parent.current;
@@ -2019,7 +1821,7 @@ class SubProgress {
2019
1821
  });
2020
1822
  }
2021
1823
  load() {
2022
- return __awaiter$n(this, void 0, void 0, function* () {
1824
+ return __awaiter$o(this, void 0, void 0, function* () {
2023
1825
  return null;
2024
1826
  });
2025
1827
  }
@@ -2037,7 +1839,7 @@ var __decorate$s = (this && this.__decorate) || function (decorators, target, ke
2037
1839
  var __metadata$m = (this && this.__metadata) || function (k, v) {
2038
1840
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2039
1841
  };
2040
- var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1842
+ var __awaiter$n = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2041
1843
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2042
1844
  return new (P || (P = Promise))(function (resolve, reject) {
2043
1845
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2058,9 +1860,9 @@ let Progresses = class Progresses {
2058
1860
  });
2059
1861
  }
2060
1862
  waitToFinish(id) {
2061
- return __awaiter$m(this, void 0, void 0, function* () {
1863
+ return __awaiter$n(this, void 0, void 0, function* () {
2062
1864
  return Promise.race([
2063
- this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
1865
+ this.waitForProgress(id, () => __awaiter$n(this, void 0, void 0, function* () {
2064
1866
  let progress = this.progresses[id];
2065
1867
  if (!progress || progress.percent < 100) {
2066
1868
  progress = yield this.get(id);
@@ -2070,25 +1872,25 @@ let Progresses = class Progresses {
2070
1872
  }
2071
1873
  return progress;
2072
1874
  }), 500),
2073
- this.waitForProgress(id, () => __awaiter$m(this, void 0, void 0, function* () {
1875
+ this.waitForProgress(id, () => __awaiter$n(this, void 0, void 0, function* () {
2074
1876
  return this.progresses[id] || null;
2075
1877
  }), 25)
2076
1878
  ]);
2077
1879
  });
2078
1880
  }
2079
1881
  get(id) {
2080
- return __awaiter$m(this, void 0, void 0, function* () {
1882
+ return __awaiter$n(this, void 0, void 0, function* () {
2081
1883
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
2082
1884
  });
2083
1885
  }
2084
1886
  find(where) {
2085
- return __awaiter$m(this, void 0, void 0, function* () {
1887
+ return __awaiter$n(this, void 0, void 0, function* () {
2086
1888
  const data = yield this.collection.findOne(where);
2087
1889
  return !data ? null : new Progress(data._id, data, this.collection);
2088
1890
  });
2089
1891
  }
2090
1892
  create(max = 100) {
2091
- return __awaiter$m(this, void 0, void 0, function* () {
1893
+ return __awaiter$n(this, void 0, void 0, function* () {
2092
1894
  if (isNaN(max) || max <= 0) {
2093
1895
  throw new Error(`Max progress value must be bigger than zero`);
2094
1896
  }
@@ -2104,13 +1906,13 @@ let Progresses = class Progresses {
2104
1906
  });
2105
1907
  }
2106
1908
  remove(id) {
2107
- return __awaiter$m(this, void 0, void 0, function* () {
1909
+ return __awaiter$n(this, void 0, void 0, function* () {
2108
1910
  yield this.collection.deleteOne({ _id: new ObjectId$1(id) });
2109
1911
  return id;
2110
1912
  });
2111
1913
  }
2112
1914
  waitForProgress(id, cb, delay) {
2113
- return __awaiter$m(this, void 0, void 0, function* () {
1915
+ return __awaiter$n(this, void 0, void 0, function* () {
2114
1916
  let isFinished = false;
2115
1917
  let progress = null;
2116
1918
  let waitTime = 0;
@@ -2149,7 +1951,7 @@ var __decorate$r = (this && this.__decorate) || function (decorators, target, ke
2149
1951
  var __metadata$l = (this && this.__metadata) || function (k, v) {
2150
1952
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2151
1953
  };
2152
- var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1954
+ var __awaiter$m = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2153
1955
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2154
1956
  return new (P || (P = Promise))(function (resolve, reject) {
2155
1957
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2167,7 +1969,7 @@ let LazyAssets = class LazyAssets {
2167
1969
  this.collection = connector.database.collection("lazyassets");
2168
1970
  }
2169
1971
  create(jobType, jobParams = {}, jobQue = "main") {
2170
- return __awaiter$l(this, void 0, void 0, function* () {
1972
+ return __awaiter$m(this, void 0, void 0, function* () {
2171
1973
  const jobName = this.jobMan.tryResolve(jobType, Object.assign(Object.assign({}, jobParams), { lazyId: "" }));
2172
1974
  const data = {
2173
1975
  jobName,
@@ -2182,12 +1984,12 @@ let LazyAssets = class LazyAssets {
2182
1984
  });
2183
1985
  }
2184
1986
  read(id) {
2185
- return __awaiter$l(this, void 0, void 0, function* () {
1987
+ return __awaiter$m(this, void 0, void 0, function* () {
2186
1988
  return !id ? null : this.find({ _id: new ObjectId$1(id) });
2187
1989
  });
2188
1990
  }
2189
1991
  find(where) {
2190
- return __awaiter$l(this, void 0, void 0, function* () {
1992
+ return __awaiter$m(this, void 0, void 0, function* () {
2191
1993
  const data = yield this.collection.findOne(where);
2192
1994
  return !data
2193
1995
  ? null
@@ -2195,7 +1997,7 @@ let LazyAssets = class LazyAssets {
2195
1997
  });
2196
1998
  }
2197
1999
  unlink(id) {
2198
- return __awaiter$l(this, void 0, void 0, function* () {
2000
+ return __awaiter$m(this, void 0, void 0, function* () {
2199
2001
  const asset = yield this.read(id);
2200
2002
  if (!asset)
2201
2003
  return null;
@@ -2221,7 +2023,7 @@ var __decorate$q = (this && this.__decorate) || function (decorators, target, ke
2221
2023
  var __metadata$k = (this && this.__metadata) || function (k, v) {
2222
2024
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2223
2025
  };
2224
- var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2026
+ var __awaiter$l = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2225
2027
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2226
2028
  return new (P || (P = Promise))(function (resolve, reject) {
2227
2029
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2236,7 +2038,7 @@ let AssetResolver = class AssetResolver {
2236
2038
  this.lazyAssets = lazyAssets;
2237
2039
  }
2238
2040
  resolve(id, lazy = false) {
2239
- return __awaiter$k(this, void 0, void 0, function* () {
2041
+ return __awaiter$l(this, void 0, void 0, function* () {
2240
2042
  let asset = null;
2241
2043
  if (lazy) {
2242
2044
  const lazyAsset = yield this.lazyAssets.read(id);
@@ -2294,7 +2096,7 @@ var __decorate$o = (this && this.__decorate) || function (decorators, target, ke
2294
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;
2295
2097
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2296
2098
  };
2297
- var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2099
+ var __awaiter$k = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2298
2100
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2299
2101
  return new (P || (P = Promise))(function (resolve, reject) {
2300
2102
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2305,12 +2107,12 @@ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P,
2305
2107
  };
2306
2108
  let CacheProcessor = class CacheProcessor {
2307
2109
  serialize(data) {
2308
- return __awaiter$j(this, void 0, void 0, function* () {
2110
+ return __awaiter$k(this, void 0, void 0, function* () {
2309
2111
  return data;
2310
2112
  });
2311
2113
  }
2312
2114
  deserialize(data) {
2313
- return __awaiter$j(this, void 0, void 0, function* () {
2115
+ return __awaiter$k(this, void 0, void 0, function* () {
2314
2116
  return data;
2315
2117
  });
2316
2118
  }
@@ -2329,7 +2131,7 @@ var __decorate$n = (this && this.__decorate) || function (decorators, target, ke
2329
2131
  var __metadata$i = (this && this.__metadata) || function (k, v) {
2330
2132
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2331
2133
  };
2332
- var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2134
+ var __awaiter$j = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2333
2135
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2334
2136
  return new (P || (P = Promise))(function (resolve, reject) {
2335
2137
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2345,7 +2147,7 @@ let Cache = class Cache {
2345
2147
  this.cacheProcessor = cacheProcessor;
2346
2148
  }
2347
2149
  prepare() {
2348
- return __awaiter$i(this, void 0, void 0, function* () {
2150
+ return __awaiter$j(this, void 0, void 0, function* () {
2349
2151
  if (this.collection)
2350
2152
  return;
2351
2153
  if (!this.connector.database) {
@@ -2356,7 +2158,7 @@ let Cache = class Cache {
2356
2158
  });
2357
2159
  }
2358
2160
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
2359
- return __awaiter$i(this, void 0, void 0, function* () {
2161
+ return __awaiter$j(this, void 0, void 0, function* () {
2360
2162
  yield this.prepare();
2361
2163
  const item = {
2362
2164
  _id: key,
@@ -2373,7 +2175,7 @@ let Cache = class Cache {
2373
2175
  });
2374
2176
  }
2375
2177
  get(key) {
2376
- return __awaiter$i(this, void 0, void 0, function* () {
2178
+ return __awaiter$j(this, void 0, void 0, function* () {
2377
2179
  yield this.prepare();
2378
2180
  let item = yield this.collection.findOne({ _id: key });
2379
2181
  const now = Math.round(new Date().getTime() / 1000);
@@ -2387,7 +2189,7 @@ let Cache = class Cache {
2387
2189
  });
2388
2190
  }
2389
2191
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
2390
- return __awaiter$i(this, void 0, void 0, function* () {
2192
+ return __awaiter$j(this, void 0, void 0, function* () {
2391
2193
  try {
2392
2194
  return yield this.get(key);
2393
2195
  }
@@ -2397,7 +2199,7 @@ let Cache = class Cache {
2397
2199
  });
2398
2200
  }
2399
2201
  delete(key) {
2400
- return __awaiter$i(this, void 0, void 0, function* () {
2202
+ return __awaiter$j(this, void 0, void 0, function* () {
2401
2203
  yield this.prepare();
2402
2204
  yield this.collection.deleteOne({ _id: key });
2403
2205
  });
@@ -2415,7 +2217,7 @@ var __decorate$m = (this && this.__decorate) || function (decorators, target, ke
2415
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;
2416
2218
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2417
2219
  };
2418
- var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2220
+ var __awaiter$i = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2419
2221
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2420
2222
  return new (P || (P = Promise))(function (resolve, reject) {
2421
2223
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2426,7 +2228,7 @@ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P,
2426
2228
  };
2427
2229
  let EndpointProvider = class EndpointProvider {
2428
2230
  configure(app) {
2429
- return __awaiter$h(this, void 0, void 0, function* () {
2231
+ return __awaiter$i(this, void 0, void 0, function* () {
2430
2232
  console.log(`Express app is mounted to: ${app.mountpath}`);
2431
2233
  });
2432
2234
  }
@@ -2448,7 +2250,7 @@ var __metadata$h = (this && this.__metadata) || function (k, v) {
2448
2250
  var __param$6 = (this && this.__param) || function (paramIndex, decorator) {
2449
2251
  return function (target, key) { decorator(target, key, paramIndex); }
2450
2252
  };
2451
- var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2253
+ var __awaiter$h = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2452
2254
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2453
2255
  return new (P || (P = Promise))(function (resolve, reject) {
2454
2256
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2462,7 +2264,7 @@ let Fixtures = class Fixtures {
2462
2264
  this.fixtures = fixtures;
2463
2265
  }
2464
2266
  load() {
2465
- return __awaiter$g(this, void 0, void 0, function* () {
2267
+ return __awaiter$h(this, void 0, void 0, function* () {
2466
2268
  if (!this.fixtures)
2467
2269
  return;
2468
2270
  for (let fixture of this.fixtures) {
@@ -2478,7 +2280,7 @@ Fixtures = __decorate$l([
2478
2280
  __metadata$h("design:paramtypes", [Array])
2479
2281
  ], Fixtures);
2480
2282
 
2481
- var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2283
+ var __awaiter$g = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2482
2284
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2483
2285
  return new (P || (P = Promise))(function (resolve, reject) {
2484
2286
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2499,7 +2301,7 @@ class GalleryImage {
2499
2301
  this.targetSize = !size ? { width: thumbSize, height: thumbSize } : size;
2500
2302
  }
2501
2303
  serve(id) {
2502
- return __awaiter$f(this, void 0, void 0, function* () {
2304
+ return __awaiter$g(this, void 0, void 0, function* () {
2503
2305
  const isThumb = id == this.thumb;
2504
2306
  if (yield this.handler.hasResult(isThumb)) {
2505
2307
  return this.handler.serveResult(isThumb);
@@ -2566,7 +2368,7 @@ var __decorate$j = (this && this.__decorate) || function (decorators, target, ke
2566
2368
  var __metadata$f = (this && this.__metadata) || function (k, v) {
2567
2369
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2568
2370
  };
2569
- var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2371
+ var __awaiter$f = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2570
2372
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2571
2373
  return new (P || (P = Promise))(function (resolve, reject) {
2572
2374
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2585,7 +2387,7 @@ let Gallery = class Gallery {
2585
2387
  this.output = join(this.config.resolve("cacheDir"), "gallery");
2586
2388
  }
2587
2389
  getFolder(folder, size = null) {
2588
- return __awaiter$e(this, void 0, void 0, function* () {
2390
+ return __awaiter$f(this, void 0, void 0, function* () {
2589
2391
  this.cache[folder] = this.cache[folder] || new Promise(resolve => {
2590
2392
  lstat(join(this.dir, folder), (err, stats) => {
2591
2393
  if (err || !stats.isDirectory()) {
@@ -2606,7 +2408,7 @@ let Gallery = class Gallery {
2606
2408
  return;
2607
2409
  }
2608
2410
  const promises = files.map(file => {
2609
- 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* () {
2610
2412
  const filePath = join(path, file);
2611
2413
  const absoluteFilePath = join(this.dir, filePath);
2612
2414
  lstat(absoluteFilePath, (err, stats) => {
@@ -2639,7 +2441,7 @@ let Gallery = class Gallery {
2639
2441
  });
2640
2442
  },
2641
2443
  writeResult: (isThumb, buffer) => {
2642
- 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* () {
2643
2445
  const resultPath = getResultPath(isThumb);
2644
2446
  yield mkdirRecursive(dirname(resultPath));
2645
2447
  writeFile$1(resultPath, buffer, err => {
@@ -2696,7 +2498,7 @@ var __decorate$i = (this && this.__decorate) || function (decorators, target, ke
2696
2498
  var __metadata$e = (this && this.__metadata) || function (k, v) {
2697
2499
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2698
2500
  };
2699
- var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2501
+ var __awaiter$e = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2700
2502
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2701
2503
  return new (P || (P = Promise))(function (resolve, reject) {
2702
2504
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2714,7 +2516,7 @@ let IdGenerator = class IdGenerator {
2714
2516
  this.parts = config.resolve("idParts");
2715
2517
  }
2716
2518
  generate(checkCb) {
2717
- return __awaiter$d(this, void 0, void 0, function* () {
2519
+ return __awaiter$e(this, void 0, void 0, function* () {
2718
2520
  let id = null;
2719
2521
  let tries = 0;
2720
2522
  let notGood = true;
@@ -2782,7 +2584,7 @@ var __decorate$g = (this && this.__decorate) || function (decorators, target, ke
2782
2584
  var __metadata$c = (this && this.__metadata) || function (k, v) {
2783
2585
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2784
2586
  };
2785
- var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2587
+ var __awaiter$d = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2786
2588
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2787
2589
  return new (P || (P = Promise))(function (resolve, reject) {
2788
2590
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2797,7 +2599,7 @@ let Translator = class Translator {
2797
2599
  this.cache = {};
2798
2600
  }
2799
2601
  getDictionary(language) {
2800
- return __awaiter$c(this, void 0, void 0, function* () {
2602
+ return __awaiter$d(this, void 0, void 0, function* () {
2801
2603
  const dictionary = yield this.translationProvider.getDictionary(language);
2802
2604
  this.cache[language] = dictionary;
2803
2605
  return dictionary;
@@ -2863,7 +2665,7 @@ var __decorate$f = (this && this.__decorate) || function (decorators, target, ke
2863
2665
  var __metadata$b = (this && this.__metadata) || function (k, v) {
2864
2666
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2865
2667
  };
2866
- var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2668
+ var __awaiter$c = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2867
2669
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2868
2670
  return new (P || (P = Promise))(function (resolve, reject) {
2869
2671
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2895,9 +2697,9 @@ let TemplateRenderer = class TemplateRenderer {
2895
2697
  return this.initPromise;
2896
2698
  }
2897
2699
  parseTemplates(dir, dirPath) {
2898
- return __awaiter$b(this, void 0, void 0, function* () {
2700
+ return __awaiter$c(this, void 0, void 0, function* () {
2899
2701
  return new Promise(resolve => {
2900
- 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* () {
2901
2703
  for (let file of files) {
2902
2704
  const path = join(dir, file);
2903
2705
  if (lstatSync(path).isDirectory()) {
@@ -2918,7 +2720,7 @@ let TemplateRenderer = class TemplateRenderer {
2918
2720
  });
2919
2721
  }
2920
2722
  render(template, language, context) {
2921
- return __awaiter$b(this, void 0, void 0, function* () {
2723
+ return __awaiter$c(this, void 0, void 0, function* () {
2922
2724
  yield this.init();
2923
2725
  yield this.translator.getDictionary(language);
2924
2726
  if (!this.templates[template]) {
@@ -2945,7 +2747,7 @@ var __decorate$e = (this && this.__decorate) || function (decorators, target, ke
2945
2747
  var __metadata$a = (this && this.__metadata) || function (k, v) {
2946
2748
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2947
2749
  };
2948
- var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2750
+ var __awaiter$b = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2949
2751
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2950
2752
  return new (P || (P = Promise))(function (resolve, reject) {
2951
2753
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -2971,7 +2773,7 @@ let MailSender = class MailSender {
2971
2773
  return this.renderer.translator;
2972
2774
  }
2973
2775
  sendMail(language, options) {
2974
- return __awaiter$a(this, void 0, void 0, function* () {
2776
+ return __awaiter$b(this, void 0, void 0, function* () {
2975
2777
  const subject = yield this.translator.getTranslation(language, options.subject || "-");
2976
2778
  const html = yield this.renderer.render(options.template, language, options.context);
2977
2779
  return this.transporter.sendMail({
@@ -2999,7 +2801,7 @@ var __decorate$d = (this && this.__decorate) || function (decorators, target, ke
2999
2801
  var __metadata$9 = (this && this.__metadata) || function (k, v) {
3000
2802
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3001
2803
  };
3002
- var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2804
+ var __awaiter$a = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3003
2805
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3004
2806
  return new (P || (P = Promise))(function (resolve, reject) {
3005
2807
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3014,7 +2816,7 @@ let MemoryCache = class MemoryCache {
3014
2816
  this.cacheMap = new Map();
3015
2817
  }
3016
2818
  set(key, value, ttl, expirationTimestamp = null, tags = {}) {
3017
- return __awaiter$9(this, void 0, void 0, function* () {
2819
+ return __awaiter$a(this, void 0, void 0, function* () {
3018
2820
  const now = Math.round(new Date().getTime() / 1000);
3019
2821
  const expTimestamp = Math.min(isNaN(ttl) ? Number.MAX_SAFE_INTEGER : ttl, 3600);
3020
2822
  this.cacheMap.set(key, {
@@ -3027,7 +2829,7 @@ let MemoryCache = class MemoryCache {
3027
2829
  });
3028
2830
  }
3029
2831
  get(key) {
3030
- return __awaiter$9(this, void 0, void 0, function* () {
2832
+ return __awaiter$a(this, void 0, void 0, function* () {
3031
2833
  let item = this.cacheMap.get(key);
3032
2834
  const now = Math.round(new Date().getTime() / 1000);
3033
2835
  let expTimestamp = 3600;
@@ -3049,7 +2851,7 @@ let MemoryCache = class MemoryCache {
3049
2851
  });
3050
2852
  }
3051
2853
  getOrSet(key, valueCb, ttl, expirationTimestamp = null, tags = {}) {
3052
- return __awaiter$9(this, void 0, void 0, function* () {
2854
+ return __awaiter$a(this, void 0, void 0, function* () {
3053
2855
  try {
3054
2856
  return yield this.get(key);
3055
2857
  }
@@ -3059,7 +2861,7 @@ let MemoryCache = class MemoryCache {
3059
2861
  });
3060
2862
  }
3061
2863
  delete(key) {
3062
- return __awaiter$9(this, void 0, void 0, function* () {
2864
+ return __awaiter$a(this, void 0, void 0, function* () {
3063
2865
  this.cacheMap.delete(key);
3064
2866
  yield this.cacheMap.delete(key);
3065
2867
  });
@@ -3077,7 +2879,7 @@ var __decorate$c = (this && this.__decorate) || function (decorators, target, ke
3077
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;
3078
2880
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3079
2881
  };
3080
- var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2882
+ var __awaiter$9 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3081
2883
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3082
2884
  return new (P || (P = Promise))(function (resolve, reject) {
3083
2885
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3094,17 +2896,17 @@ const sampleUser = {
3094
2896
  };
3095
2897
  let UserManager = class UserManager {
3096
2898
  getByCredentials(credentials) {
3097
- return __awaiter$8(this, void 0, void 0, function* () {
2899
+ return __awaiter$9(this, void 0, void 0, function* () {
3098
2900
  return (sampleUser.email == credentials.email) ? sampleUser : yield Promise.reject("message.login.error");
3099
2901
  });
3100
2902
  }
3101
2903
  getById(id) {
3102
- return __awaiter$8(this, void 0, void 0, function* () {
2904
+ return __awaiter$9(this, void 0, void 0, function* () {
3103
2905
  return (sampleUser.id == id) ? sampleUser : null;
3104
2906
  });
3105
2907
  }
3106
2908
  serialize(user) {
3107
- return __awaiter$8(this, void 0, void 0, function* () {
2909
+ return __awaiter$9(this, void 0, void 0, function* () {
3108
2910
  const res = Object.assign({}, user);
3109
2911
  delete res.password;
3110
2912
  return res;
@@ -3197,7 +2999,7 @@ var __metadata$7 = (this && this.__metadata) || function (k, v) {
3197
2999
  var __param$5 = (this && this.__param) || function (paramIndex, decorator) {
3198
3000
  return function (target, key) { decorator(target, key, paramIndex); }
3199
3001
  };
3200
- var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3002
+ var __awaiter$8 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3201
3003
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3202
3004
  return new (P || (P = Promise))(function (resolve, reject) {
3203
3005
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3212,7 +3014,7 @@ let AssetsController = class AssetsController {
3212
3014
  this.assetResolver = assetResolver;
3213
3015
  }
3214
3016
  upload(file) {
3215
- return __awaiter$7(this, void 0, void 0, function* () {
3017
+ return __awaiter$8(this, void 0, void 0, function* () {
3216
3018
  try {
3217
3019
  const contentType = file.mimetype === "application/octet-stream" ? null : file.mimetype;
3218
3020
  const asset = yield this.assets.writeBuffer(file.buffer, { filename: file.filename }, contentType);
@@ -3225,7 +3027,7 @@ let AssetsController = class AssetsController {
3225
3027
  });
3226
3028
  }
3227
3029
  uploadUrl(body) {
3228
- return __awaiter$7(this, void 0, void 0, function* () {
3030
+ return __awaiter$8(this, void 0, void 0, function* () {
3229
3031
  try {
3230
3032
  const asset = yield this.assets.writeUrl(body.url, body);
3231
3033
  return asset.toJSON();
@@ -3237,13 +3039,13 @@ let AssetsController = class AssetsController {
3237
3039
  });
3238
3040
  }
3239
3041
  getFile(id, lazy, res) {
3240
- return __awaiter$7(this, void 0, void 0, function* () {
3042
+ return __awaiter$8(this, void 0, void 0, function* () {
3241
3043
  const asset = yield this.getAsset("Asset", id, lazy, res);
3242
3044
  return asset.download();
3243
3045
  });
3244
3046
  }
3245
3047
  getImageRotation(id, params, res, rotation = 0) {
3246
- return __awaiter$7(this, void 0, void 0, function* () {
3048
+ return __awaiter$8(this, void 0, void 0, function* () {
3247
3049
  const asset = yield this.getAsset("Image", id, params.lazy, res);
3248
3050
  if (rotation !== 0) {
3249
3051
  params.rotation = params.rotation || rotation;
@@ -3252,18 +3054,18 @@ let AssetsController = class AssetsController {
3252
3054
  });
3253
3055
  }
3254
3056
  getImage(id, params, res) {
3255
- return __awaiter$7(this, void 0, void 0, function* () {
3057
+ return __awaiter$8(this, void 0, void 0, function* () {
3256
3058
  return this.getImageRotation(id, params, res);
3257
3059
  });
3258
3060
  }
3259
3061
  getFileByName(name, res) {
3260
- return __awaiter$7(this, void 0, void 0, function* () {
3062
+ return __awaiter$8(this, void 0, void 0, function* () {
3261
3063
  const asset = yield this.getAssetByName("Asset", name, res);
3262
3064
  return asset.download();
3263
3065
  });
3264
3066
  }
3265
3067
  getImageByName(name, params, res) {
3266
- return __awaiter$7(this, void 0, void 0, function* () {
3068
+ return __awaiter$8(this, void 0, void 0, function* () {
3267
3069
  const asset = yield this.getAssetByName("Image", name, res);
3268
3070
  return asset.downloadImage(params);
3269
3071
  });
@@ -3282,7 +3084,7 @@ let AssetsController = class AssetsController {
3282
3084
  }
3283
3085
  }
3284
3086
  getAsset(type, id, lazy, res) {
3285
- return __awaiter$7(this, void 0, void 0, function* () {
3087
+ return __awaiter$8(this, void 0, void 0, function* () {
3286
3088
  const asset = yield this.assetResolver.resolve(id, lazy);
3287
3089
  if (!asset) {
3288
3090
  throw new HttpError(404, `${type} with id: '${id}' not found.`);
@@ -3292,7 +3094,7 @@ let AssetsController = class AssetsController {
3292
3094
  });
3293
3095
  }
3294
3096
  getAssetByName(type, filename, res) {
3295
- return __awaiter$7(this, void 0, void 0, function* () {
3097
+ return __awaiter$8(this, void 0, void 0, function* () {
3296
3098
  const asset = yield this.assets.find({ filename });
3297
3099
  if (!asset) {
3298
3100
  throw new HttpError(404, `${type} with filename: '${filename}' not found.`);
@@ -3371,7 +3173,7 @@ var __metadata$6 = (this && this.__metadata) || function (k, v) {
3371
3173
  var __param$4 = (this && this.__param) || function (paramIndex, decorator) {
3372
3174
  return function (target, key) { decorator(target, key, paramIndex); }
3373
3175
  };
3374
- var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3176
+ var __awaiter$7 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3375
3177
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3376
3178
  return new (P || (P = Promise))(function (resolve, reject) {
3377
3179
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3386,20 +3188,21 @@ let AuthController = class AuthController {
3386
3188
  this.userManager = userManager;
3387
3189
  }
3388
3190
  login(credentials, res) {
3389
- return __awaiter$6(this, void 0, void 0, function* () {
3191
+ return __awaiter$7(this, void 0, void 0, function* () {
3192
+ let user = null;
3390
3193
  try {
3391
- const user = yield this.userManager.getByCredentials(credentials);
3392
- const valid = yield compare(credentials.password, user.password);
3393
- if (valid !== true)
3394
- throw "message.login.error";
3395
- return {
3396
- token: sign({ id: user._id || user.id }, this.config.resolve("jwtSecret")),
3397
- user: yield this.userManager.serialize(user)
3398
- };
3194
+ user = yield this.userManager.getByCredentials(credentials);
3399
3195
  }
3400
3196
  catch (reason) {
3401
3197
  throw new HttpError(401, reason);
3402
3198
  }
3199
+ const valid = !user ? false : yield compare(credentials.password, user.password);
3200
+ if (valid !== true)
3201
+ throw new UnauthorizedError(`message.login.error`);
3202
+ return {
3203
+ token: sign({ id: user._id || user.id }, this.config.resolve("jwtSecret")),
3204
+ user: yield this.userManager.serialize(user)
3205
+ };
3403
3206
  });
3404
3207
  }
3405
3208
  getProfile(user) {
@@ -3472,7 +3275,7 @@ var __metadata$4 = (this && this.__metadata) || function (k, v) {
3472
3275
  var __param$2 = (this && this.__param) || function (paramIndex, decorator) {
3473
3276
  return function (target, key) { decorator(target, key, paramIndex); }
3474
3277
  };
3475
- var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3278
+ var __awaiter$6 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3476
3279
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3477
3280
  return new (P || (P = Promise))(function (resolve, reject) {
3478
3281
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3489,7 +3292,7 @@ let ProgressesController = class ProgressesController {
3489
3292
  this.connectionType = !mainEndpoint ? "polling" : "socket";
3490
3293
  }
3491
3294
  getProgress(id) {
3492
- return __awaiter$5(this, void 0, void 0, function* () {
3295
+ return __awaiter$6(this, void 0, void 0, function* () {
3493
3296
  const progress = yield this.progresses.get(id);
3494
3297
  if (!progress)
3495
3298
  return null;
@@ -3521,7 +3324,7 @@ var __decorate$6 = (this && this.__decorate) || function (decorators, target, ke
3521
3324
  var __metadata$3 = (this && this.__metadata) || function (k, v) {
3522
3325
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3523
3326
  };
3524
- var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3327
+ var __awaiter$5 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3525
3328
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3526
3329
  return new (P || (P = Promise))(function (resolve, reject) {
3527
3330
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3539,7 +3342,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3539
3342
  return this.configuration.resolve("nodeEnv") === "development";
3540
3343
  }
3541
3344
  error(error, req, res, next) {
3542
- return __awaiter$4(this, void 0, void 0, function* () {
3345
+ return __awaiter$5(this, void 0, void 0, function* () {
3543
3346
  const result = yield this.getResult(error, req, res);
3544
3347
  if (this.isDev) {
3545
3348
  console.log("ERROR", result, res.statusCode);
@@ -3548,7 +3351,7 @@ let ErrorHandlerMiddleware = class ErrorHandlerMiddleware {
3548
3351
  });
3549
3352
  }
3550
3353
  getResult(error, req, res) {
3551
- return __awaiter$4(this, void 0, void 0, function* () {
3354
+ return __awaiter$5(this, void 0, void 0, function* () {
3552
3355
  const result = {};
3553
3356
  if (error instanceof BadRequestError) {
3554
3357
  res.status(400);
@@ -3694,7 +3497,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
3694
3497
  var __param = (this && this.__param) || function (paramIndex, decorator) {
3695
3498
  return function (target, key) { decorator(target, key, paramIndex); }
3696
3499
  };
3697
- var __awaiter$3 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3500
+ var __awaiter$4 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3698
3501
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3699
3502
  return new (P || (P = Promise))(function (resolve, reject) {
3700
3503
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -3709,7 +3512,7 @@ let ProgressController = class ProgressController {
3709
3512
  this.socketServer = socketServer;
3710
3513
  }
3711
3514
  advanceProgress(client, progressId) {
3712
- return __awaiter$3(this, void 0, void 0, function* () {
3515
+ return __awaiter$4(this, void 0, void 0, function* () {
3713
3516
  const progress = yield this.progresses.get(progressId);
3714
3517
  if (!progress)
3715
3518
  return;
@@ -3723,7 +3526,7 @@ let ProgressController = class ProgressController {
3723
3526
  });
3724
3527
  }
3725
3528
  setProgressInterest(client, progressId) {
3726
- return __awaiter$3(this, void 0, void 0, function* () {
3529
+ return __awaiter$4(this, void 0, void 0, function* () {
3727
3530
  const progress = yield this.progresses.get(progressId);
3728
3531
  if (!progress)
3729
3532
  return;
@@ -3774,6 +3577,53 @@ CompressionMiddleware = __decorate([
3774
3577
  Middleware$1()
3775
3578
  ], CompressionMiddleware);
3776
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
+
3777
3627
  class Tree {
3778
3628
  constructor(container, exists, path) {
3779
3629
  this.container = container;
@@ -3978,34 +3828,6 @@ var __awaiter$2 = (this && this.__awaiter) || function (thisArg, _arguments, P,
3978
3828
  step((generator = generator.apply(thisArg, _arguments || [])).next());
3979
3829
  });
3980
3830
  };
3981
- function setupStatic(rootFolder, container) {
3982
- return __awaiter$2(this, void 0, void 0, function* () {
3983
- const browserFolder = resolve(rootFolder || __dirname, `public_html`);
3984
- const app = container.get(EXPRESS);
3985
- const ep = container.get(EndpointProvider);
3986
- console.log(browserFolder, existsSync(browserFolder));
3987
- if (existsSync(browserFolder)) {
3988
- console.log(`public_html exists. setting up static files serving...`);
3989
- app.use(static$1(browserFolder, {
3990
- maxAge: "1y"
3991
- }));
3992
- }
3993
- else {
3994
- console.log(`public_html does not exist on path: "${browserFolder}"`);
3995
- }
3996
- yield ep.configure(app);
3997
- });
3998
- }
3999
-
4000
- var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4001
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4002
- return new (P || (P = Promise))(function (resolve, reject) {
4003
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4004
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
4005
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
4006
- step((generator = generator.apply(thisArg, _arguments || [])).next());
4007
- });
4008
- };
4009
3831
  class LazyAssetGenerator {
4010
3832
  constructor(assetResolver, progresses, lazyId) {
4011
3833
  this.assetResolver = assetResolver;
@@ -4019,7 +3841,7 @@ class LazyAssetGenerator {
4019
3841
  return this.assetResolver.lazyAssets;
4020
3842
  }
4021
3843
  process(messaging) {
4022
- return __awaiter$1(this, void 0, void 0, function* () {
3844
+ return __awaiter$2(this, void 0, void 0, function* () {
4023
3845
  const lazyAsset = yield this.lazyAssets.read(this.lazyId);
4024
3846
  let progress = yield this.progresses.get(lazyAsset.progressId);
4025
3847
  if (!progress || progress.canceled)
@@ -4043,6 +3865,227 @@ class LazyAssetGenerator {
4043
3865
  }
4044
3866
  }
4045
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
+
4046
4089
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4047
4090
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4048
4091
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -4304,5 +4347,5 @@ function setupBackend(config, providers, parent) {
4304
4347
  * Generated bundle index. Do not edit.
4305
4348
  */
4306
4349
 
4307
- export { AssetImageParams, AssetProcessor, AssetResolver, Assets, AuthController, BackendProvider, Cache, CacheProcessor, Configuration, ConsoleColor, DI_CONTAINER, EXPRESS, EndpointProvider, ErrorHandlerMiddleware, FIXTURE, Fixtures, Gallery, GalleryCache, GalleryController, HTTP_SERVER, IdGenerator, IsFile, IsObjectId, JOB, JobManager, LanguageMiddleware, LazyAssetGenerator, LazyAssets, MailSender, MemoryCache, MongoConnector, PARAMETER, Parameter, 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, proxyFunction, proxyFunctions, 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 };
4308
4351
  //# sourceMappingURL=stemy-backend.js.map