@stemy/backend 3.1.6 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('fontkit'), require('file-type'), require('sharp'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('rxjs/operators'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
3
- typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'fontkit', 'file-type', 'sharp', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', 'rxjs/operators', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', 'bcrypt', 'moment'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.fontkit, global["file-type"], global.sharp, global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.rxjs.operators, global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
5
- })(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, fontKit_, fileType, sharp_, axios, mongodb, dotenv, nodeCron, zeromq, operators, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('path'), require('body-parser'), require('jsonwebtoken'), require('tsyringe'), require('routing-controllers'), require('socket-controllers'), require('routing-controllers-openapi'), require('class-transformer/storage'), require('class-validator'), require('class-validator-jsonschema'), require('child_process'), require('crypto'), require('rxjs'), require('rxjs/internal/util/canReportError'), require('fs'), require('mongoose'), require('mongoose/lib/utils'), require('stream'), require('bson'), require('sharp'), require('fontkit'), require('file-type'), require('axios'), require('mongodb'), require('dotenv'), require('node-cron'), require('zeromq'), require('rxjs/operators'), require('http'), require('express'), require('socket.io'), require('uuid'), require('nodemailer'), require('handlebars'), require('bcrypt'), require('moment')) :
3
+ typeof define === 'function' && define.amd ? define('@stemy/backend', ['exports', 'path', 'body-parser', 'jsonwebtoken', 'tsyringe', 'routing-controllers', 'socket-controllers', 'routing-controllers-openapi', 'class-transformer/storage', 'class-validator', 'class-validator-jsonschema', 'child_process', 'crypto', 'rxjs', 'rxjs/internal/util/canReportError', 'fs', 'mongoose', 'mongoose/lib/utils', 'stream', 'bson', 'sharp', 'fontkit', 'file-type', 'axios', 'mongodb', 'dotenv', 'node-cron', 'zeromq', 'rxjs/operators', 'http', 'express', 'socket.io', 'uuid', 'nodemailer', 'handlebars', 'bcrypt', 'moment'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy.backend = {}), global.path, global["body-parser"], global.jsonwebtoken, global.tsyringe, global["routing-controllers"], global["socket-controllers"], global["routing-controllers-openapi"], global["class-transformer/storage"], global["class-validator"], global["class-validator-jsonschema"], global.child_process, global.crypto, global.rxjs, global.rxjs["internal/util/canReportError"], global.fs, global.mongoose, global["mongoose-lib-utils"], global.stream, global.bson, global.sharp, global.fontkit, global["file-type"], global.axios, global.mongodb, global.dotenv, global["node-cron"], global.zeromq, global.rxjs.operators, global.http, global.express, global.socket.io, global.uuid, global.nodemailer, global.handlebars, global.bcrypt, global.moment));
5
+ })(this, (function (exports, path, bodyParser, jsonwebtoken, tsyringe, routingControllers, socketControllers, routingControllersOpenapi, storage, classValidator, classValidatorJsonschema, child_process, crypto, rxjs, canReportError, fs, mongoose, utils, stream, bson, sharp_, fontKit_, fileType, axios, mongodb, dotenv, nodeCron, zeromq, operators, http, express_, socket_io, uuid, nodemailer, Handlebars, bcrypt, moment) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -24,8 +24,8 @@
24
24
  return Object.freeze(n);
25
25
  }
26
26
 
27
- var fontKit___default = /*#__PURE__*/_interopDefaultLegacy(fontKit_);
28
27
  var sharp___default = /*#__PURE__*/_interopDefaultLegacy(sharp_);
28
+ var fontKit___default = /*#__PURE__*/_interopDefaultLegacy(fontKit_);
29
29
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
30
30
  var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
31
31
  var express___default = /*#__PURE__*/_interopDefaultLegacy(express_);
@@ -379,6 +379,7 @@
379
379
  step((generator = generator.apply(thisArg, _arguments || [])).next());
380
380
  });
381
381
  };
382
+ var sharp$3 = sharp___default["default"];
382
383
  var diContainers = {
383
384
  appContainer: null
384
385
  };
@@ -458,6 +459,9 @@
458
459
  return "";
459
460
  return value[0].toLowerCase() + value.substr(1);
460
461
  }
462
+ function isObjectId(id) {
463
+ return typeof id === "string" && id.length == 24 && !isNaN(Number("0x" + id));
464
+ }
461
465
  function firstItem(value) {
462
466
  return value[0];
463
467
  }
@@ -480,6 +484,9 @@
480
484
  });
481
485
  return result;
482
486
  }
487
+ function uniqueItems(value) {
488
+ return value.filter(function (v, ix) { return value.indexOf(v) === ix; });
489
+ }
483
490
  function getValue(obj, key, defaultValue, treeFallback) {
484
491
  if (treeFallback === void 0) { treeFallback = false; }
485
492
  key = key || "";
@@ -556,7 +563,7 @@
556
563
  });
557
564
  });
558
565
  }
559
- function lookupPipelines(from, localField, as, foreignField, shouldUnwind) {
566
+ function lookupStages(from, localField, as, foreignField, shouldUnwind) {
560
567
  if (as === void 0) { as = null; }
561
568
  if (foreignField === void 0) { foreignField = "_id"; }
562
569
  if (shouldUnwind === void 0) { shouldUnwind = true; }
@@ -569,15 +576,31 @@
569
576
  foreignField: foreignField,
570
577
  as: as
571
578
  }
572
- },
573
- {
579
+ }
580
+ ];
581
+ if (shouldUnwind) {
582
+ pipelines.push({
574
583
  $unwind: {
575
584
  path: "$" + as,
576
585
  preserveNullAndEmptyArrays: true
577
586
  }
587
+ });
588
+ }
589
+ return pipelines;
590
+ }
591
+ function letsLookupStage(from, pipeline, as, letFields) {
592
+ if (as === void 0) { as = null; }
593
+ if (letFields === void 0) { letFields = null; }
594
+ as = as || from;
595
+ letFields = letFields || { id: "$_id" };
596
+ return {
597
+ $lookup: {
598
+ from: from,
599
+ let: letFields,
600
+ pipeline: pipeline,
601
+ as: as
578
602
  }
579
- ];
580
- return shouldUnwind ? pipelines : pipelines.slice(0, 0);
603
+ };
581
604
  }
582
605
  function hydratePopulated(modelType, json) {
583
606
  var e_2, _a;
@@ -656,6 +679,120 @@
656
679
  });
657
680
  });
658
681
  }
682
+ var cropInterface = {
683
+ x: "number",
684
+ y: "number",
685
+ w: "number",
686
+ h: "number"
687
+ };
688
+ function toCropRegion(cropInfo) {
689
+ var crop = cropInfo;
690
+ if (isString(cropInfo)) {
691
+ try {
692
+ crop = JSON.parse(cropInfo);
693
+ }
694
+ catch (e) {
695
+ return null;
696
+ }
697
+ }
698
+ if (!isInterface(crop, cropInterface))
699
+ return null;
700
+ return {
701
+ width: Math.round(crop.w),
702
+ height: Math.round(crop.h),
703
+ top: Math.round(crop.y),
704
+ left: Math.round(crop.x)
705
+ };
706
+ }
707
+ function toImage(src, params, meta) {
708
+ return __awaiter$w(this, void 0, void 0, function () {
709
+ var crop, buffer, _a, cropBefore, cropAfter, img, _b, width, height, canvasScaleX, canvasScaleY, e_3;
710
+ return __generator(this, function (_c) {
711
+ switch (_c.label) {
712
+ case 0:
713
+ // Default params and meta
714
+ params = params || {};
715
+ meta = meta || {};
716
+ crop = toCropRegion(meta.crop);
717
+ // Return the src if there are no params and no default crop exists
718
+ if (meta.extension === "svg" || (Object.keys(params).length == 0 && !crop)) {
719
+ return [2 /*return*/, src];
720
+ }
721
+ // Parse params
722
+ params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
723
+ params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
724
+ params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
725
+ params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
726
+ params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
727
+ params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
728
+ if (!(src instanceof stream.Readable)) return [3 /*break*/, 2];
729
+ return [4 /*yield*/, streamToBuffer(src)];
730
+ case 1:
731
+ _a = _c.sent();
732
+ return [3 /*break*/, 3];
733
+ case 2:
734
+ _a = src;
735
+ _c.label = 3;
736
+ case 3:
737
+ buffer = _a;
738
+ _c.label = 4;
739
+ case 4:
740
+ _c.trys.push([4, 9, , 10]);
741
+ cropBefore = toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
742
+ cropAfter = toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
743
+ img = sharp$3(buffer);
744
+ return [4 /*yield*/, img.metadata()];
745
+ case 5:
746
+ _b = _c.sent(), width = _b.width, height = _b.height;
747
+ // Crop before resize
748
+ if (cropBefore) {
749
+ width = cropBefore.width;
750
+ height = cropBefore.height;
751
+ img = img.extract(cropBefore);
752
+ }
753
+ else if (crop) {
754
+ width = crop.width;
755
+ height = crop.height;
756
+ img = img.extract(crop);
757
+ }
758
+ canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
759
+ canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
760
+ if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
761
+ width = Math.round(width * params.canvasScaleX);
762
+ height = Math.round(height * params.canvasScaleY);
763
+ img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
764
+ }
765
+ // Resize image
766
+ if (params.scaleX !== 1 || params.scaleY !== 1) {
767
+ width = Math.round(width * params.scaleX);
768
+ height = Math.round(height * params.scaleY);
769
+ img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
770
+ }
771
+ // Crop after resize
772
+ if (cropAfter) {
773
+ img = img.extract(cropAfter);
774
+ }
775
+ if (!(params.rotation !== 0)) return [3 /*break*/, 7];
776
+ return [4 /*yield*/, img.toBuffer()];
777
+ case 6:
778
+ buffer = _c.sent();
779
+ img = sharp$3(buffer).rotate(params.rotation);
780
+ _c.label = 7;
781
+ case 7: return [4 /*yield*/, img.toBuffer()];
782
+ case 8:
783
+ buffer = _c.sent();
784
+ src = src instanceof stream.Readable ? bufferToStream(buffer) : buffer;
785
+ return [2 /*return*/, src];
786
+ case 9:
787
+ e_3 = _c.sent();
788
+ console.log("Image conversion error", e_3);
789
+ src = src instanceof stream.Readable ? bufferToStream(buffer) : buffer;
790
+ return [2 /*return*/, src];
791
+ case 10: return [2 /*return*/];
792
+ }
793
+ });
794
+ });
795
+ }
659
796
  function bufferToStream(buffer) {
660
797
  var readStream = new stream.PassThrough();
661
798
  readStream.end(buffer);
@@ -840,7 +977,7 @@
840
977
  return routingControllers.createParamDecorator({
841
978
  required: false,
842
979
  value: function (action) { return __awaiter$w(_this, void 0, void 0, function () {
843
- var req, token, id, query, doc, _a, _b, e_3;
980
+ var req, token, id, query, doc, _a, _b, e_4;
844
981
  return __generator(this, function (_c) {
845
982
  switch (_c.label) {
846
983
  case 0:
@@ -872,8 +1009,8 @@
872
1009
  _a[_b] = (_c.sent()) || doc;
873
1010
  return [2 /*return*/, action.request[paramName]];
874
1011
  case 4:
875
- e_3 = _c.sent();
876
- throw new routingControllers.BadRequestError(modelName + " check error: " + (e_3.message || e_3));
1012
+ e_4 = _c.sent();
1013
+ throw new routingControllers.BadRequestError(modelName + " check error: " + (e_4.message || e_4));
877
1014
  case 5:
878
1015
  action.request[paramName] = doc;
879
1016
  return [2 /*return*/, doc];
@@ -976,7 +1113,7 @@
976
1113
  var defaultPredicate = function () { return true; };
977
1114
  var ɵ0 = defaultPredicate;
978
1115
  function copyRecursive(target, source, predicate) {
979
- var e_4, _a;
1116
+ var e_5, _a;
980
1117
  predicate = predicate || defaultPredicate;
981
1118
  if (isPrimitive(source) || isDate(source) || isFunction(source))
982
1119
  return source;
@@ -1020,12 +1157,12 @@
1020
1157
  target.set(key, !shouldCopy(key, value) ? value : copyRecursive(target.get(key), value, predicate));
1021
1158
  }
1022
1159
  }
1023
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
1160
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
1024
1161
  finally {
1025
1162
  try {
1026
1163
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1027
1164
  }
1028
- finally { if (e_4) throw e_4.error; }
1165
+ finally { if (e_5) throw e_5.error; }
1029
1166
  }
1030
1167
  }
1031
1168
  return target;
@@ -1152,6 +1289,10 @@
1152
1289
  }
1153
1290
  return "" + color + match + exports.ConsoleColor.Reset;
1154
1291
  });
1292
+ }
1293
+ function replaceSpecialChars(str, to) {
1294
+ if (to === void 0) { to = "-"; }
1295
+ return ("" + str).replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
1155
1296
  }
1156
1297
 
1157
1298
  var __decorate$x = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -1299,7 +1440,7 @@
1299
1440
  });
1300
1441
  };
1301
1442
  var AssetProcessor_1;
1302
- var sharp$3 = sharp___default["default"];
1443
+ var sharp$2 = sharp___default["default"];
1303
1444
  var fontKit = fontKit___default["default"];
1304
1445
  var fontTypes = [
1305
1446
  "application/font-woff", "application/font-woff2", "application/x-font-opentype", "application/x-font-truetype", "application/x-font-datafork",
@@ -1388,7 +1529,7 @@
1388
1529
  }
1389
1530
  return [2 /*return*/, buffer];
1390
1531
  }
1391
- return [4 /*yield*/, sharp$3(buffer).rotate().toBuffer({ resolveWithObject: true })];
1532
+ return [4 /*yield*/, sharp$2(buffer).rotate().toBuffer({ resolveWithObject: true })];
1392
1533
  case 1:
1393
1534
  output = _b.sent();
1394
1535
  Object.assign(metadata, output.info);
@@ -1664,13 +1805,6 @@
1664
1805
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1665
1806
  });
1666
1807
  };
1667
- var sharp$2 = sharp___default["default"];
1668
- var cropInterface = {
1669
- x: "number",
1670
- y: "number",
1671
- w: "number",
1672
- h: "number"
1673
- };
1674
1808
  var Asset = /** @class */ (function (_super) {
1675
1809
  __extends(Asset, _super);
1676
1810
  function Asset(id, data, collection, bucket) {
@@ -1678,103 +1812,6 @@
1678
1812
  _this.bucket = bucket;
1679
1813
  return _this;
1680
1814
  }
1681
- Asset.toCropRegion = function (cropInfo) {
1682
- var crop = cropInfo;
1683
- if (isString(cropInfo)) {
1684
- try {
1685
- crop = JSON.parse(cropInfo);
1686
- }
1687
- catch (e) {
1688
- return null;
1689
- }
1690
- }
1691
- if (!isInterface(crop, cropInterface))
1692
- return null;
1693
- return {
1694
- width: Math.round(crop.w),
1695
- height: Math.round(crop.h),
1696
- top: Math.round(crop.y),
1697
- left: Math.round(crop.x)
1698
- };
1699
- };
1700
- Asset.toImage = function (stream, meta, params) {
1701
- return __awaiter$s(this, void 0, void 0, function () {
1702
- var crop, buffer, cropBefore, cropAfter, img, _a, width, height, canvasScaleX, canvasScaleY, _b, e_1;
1703
- return __generator(this, function (_c) {
1704
- switch (_c.label) {
1705
- case 0:
1706
- params = params || {};
1707
- crop = Asset.toCropRegion(meta.crop);
1708
- // Return the stream if there is no params and no default crop exists
1709
- if ((meta === null || meta === void 0 ? void 0 : meta.extension) === "svg" || (Object.keys(params).length == 0 && !crop)) {
1710
- return [2 /*return*/, stream];
1711
- }
1712
- // Parse params
1713
- params.rotation = isNaN(params.rotation) ? 0 : Math.round(params.rotation / 90) * 90;
1714
- params.canvasScaleX = isNaN(params.canvasScaleX) ? 1 : Number(params.canvasScaleX);
1715
- params.canvasScaleY = isNaN(params.canvasScaleY) ? 1 : Number(params.canvasScaleY);
1716
- params.scaleX = isNaN(params.scaleX) ? 1 : Number(params.scaleX);
1717
- params.scaleY = isNaN(params.scaleY) ? 1 : Number(params.scaleY);
1718
- params.crop = isBoolean(params.crop) ? params.crop : params.crop == "true";
1719
- return [4 /*yield*/, streamToBuffer(stream)];
1720
- case 1:
1721
- buffer = _c.sent();
1722
- _c.label = 2;
1723
- case 2:
1724
- _c.trys.push([2, 7, , 8]);
1725
- cropBefore = Asset.toCropRegion(params.cropBefore || (params.crop ? meta.cropBefore : null));
1726
- cropAfter = Asset.toCropRegion(params.cropAfter || (params.crop ? meta.cropAfter : null));
1727
- img = sharp$2(buffer);
1728
- return [4 /*yield*/, img.metadata()];
1729
- case 3:
1730
- _a = _c.sent(), width = _a.width, height = _a.height;
1731
- // Crop before resize
1732
- if (cropBefore) {
1733
- width = cropBefore.width;
1734
- height = cropBefore.height;
1735
- img = img.extract(cropBefore);
1736
- }
1737
- else if (crop) {
1738
- width = crop.width;
1739
- height = crop.height;
1740
- img = img.extract(crop);
1741
- }
1742
- canvasScaleX = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleX) || 1;
1743
- canvasScaleY = (meta === null || meta === void 0 ? void 0 : meta.canvasScaleY) || 1;
1744
- if (params.canvasScaleX !== canvasScaleX || params.canvasScaleY !== canvasScaleY) {
1745
- width = Math.round(width * params.canvasScaleX);
1746
- height = Math.round(height * params.canvasScaleY);
1747
- img = img.resize({ width: width, height: height, background: "#00000000", fit: "contain" });
1748
- }
1749
- // Resize image
1750
- if (params.scaleX !== 1 || params.scaleY !== 1) {
1751
- width = Math.round(width * params.scaleX);
1752
- height = Math.round(height * params.scaleY);
1753
- img = img.resize({ width: width, height: height, background: "#00000000", fit: "fill" });
1754
- }
1755
- // Crop after resize
1756
- if (cropAfter) {
1757
- img = img.extract(cropAfter);
1758
- }
1759
- if (!(params.rotation !== 0)) return [3 /*break*/, 5];
1760
- return [4 /*yield*/, img.toBuffer()];
1761
- case 4:
1762
- buffer = _c.sent();
1763
- img = sharp$2(buffer).rotate(params.rotation);
1764
- _c.label = 5;
1765
- case 5:
1766
- _b = bufferToStream;
1767
- return [4 /*yield*/, img.toBuffer()];
1768
- case 6: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
1769
- case 7:
1770
- e_1 = _c.sent();
1771
- console.log("Asset image conversion error", e_1);
1772
- return [2 /*return*/, bufferToStream(buffer)];
1773
- case 8: return [2 /*return*/];
1774
- }
1775
- });
1776
- });
1777
- };
1778
1815
  Object.defineProperty(Asset.prototype, "filename", {
1779
1816
  get: function () {
1780
1817
  return this.data.filename;
@@ -1836,19 +1873,19 @@
1836
1873
  if (params === void 0) { params = null; }
1837
1874
  return __awaiter$s(this, void 0, void 0, function () {
1838
1875
  return __generator(this, function (_a) {
1839
- return [2 /*return*/, Asset.toImage(this.stream, this.metadata, params)];
1876
+ return [2 /*return*/, toImage(this.stream, params, this.metadata)];
1840
1877
  });
1841
1878
  });
1842
1879
  };
1843
1880
  Asset.prototype.downloadImage = function (params, metadata) {
1844
1881
  return __awaiter$s(this, void 0, void 0, function () {
1845
- var _a, _b;
1846
- return __generator(this, function (_c) {
1847
- switch (_c.label) {
1882
+ var _a;
1883
+ return __generator(this, function (_b) {
1884
+ switch (_b.label) {
1848
1885
  case 0:
1849
- _b = (_a = Asset).toImage;
1886
+ _a = toImage;
1850
1887
  return [4 /*yield*/, this.download(metadata)];
1851
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), this.metadata, params])];
1888
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent(), params, this.metadata])];
1852
1889
  }
1853
1890
  });
1854
1891
  });
@@ -1913,7 +1950,7 @@
1913
1950
  };
1914
1951
  TempAsset.prototype.downloadImage = function (params, metadata) {
1915
1952
  Object.assign(this.metadata, metadata || {});
1916
- return Asset.toImage(this.stream, this.metadata, params);
1953
+ return toImage(this.stream, params, this.metadata);
1917
1954
  };
1918
1955
  TempAsset.prototype.getImage = function (params) {
1919
1956
  return this.downloadImage(params);
@@ -2154,6 +2191,19 @@
2154
2191
  });
2155
2192
  });
2156
2193
  };
2194
+ Assets.prototype.deleteMany = function (where) {
2195
+ return __awaiter$q(this, void 0, void 0, function () {
2196
+ var assets;
2197
+ return __generator(this, function (_b) {
2198
+ switch (_b.label) {
2199
+ case 0: return [4 /*yield*/, this.findMany(where)];
2200
+ case 1:
2201
+ assets = _b.sent();
2202
+ return [2 /*return*/, Promise.all(assets.map(function (a) { return a.unlink(); }))];
2203
+ }
2204
+ });
2205
+ });
2206
+ };
2157
2207
  Assets.prototype.unlink = function (id) {
2158
2208
  return __awaiter$q(this, void 0, void 0, function () {
2159
2209
  var asset;
@@ -4832,6 +4882,19 @@
4832
4882
  });
4833
4883
  });
4834
4884
  };
4885
+ AssetsController.prototype.getFile = function (id, lazy, res) {
4886
+ return __awaiter$7(this, void 0, void 0, function () {
4887
+ var asset;
4888
+ return __generator(this, function (_c) {
4889
+ switch (_c.label) {
4890
+ case 0: return [4 /*yield*/, this.getAsset("Asset", id, lazy, res)];
4891
+ case 1:
4892
+ asset = _c.sent();
4893
+ return [2 /*return*/, asset.download()];
4894
+ }
4895
+ });
4896
+ });
4897
+ };
4835
4898
  AssetsController.prototype.getImageRotation = function (id, params, res, rotation) {
4836
4899
  if (rotation === void 0) { rotation = 0; }
4837
4900
  return __awaiter$7(this, void 0, void 0, function () {
@@ -4856,12 +4919,12 @@
4856
4919
  });
4857
4920
  });
4858
4921
  };
4859
- AssetsController.prototype.getFile = function (id, lazy, res) {
4922
+ AssetsController.prototype.getFileByName = function (name, res) {
4860
4923
  return __awaiter$7(this, void 0, void 0, function () {
4861
4924
  var asset;
4862
4925
  return __generator(this, function (_c) {
4863
4926
  switch (_c.label) {
4864
- case 0: return [4 /*yield*/, this.getAsset("Asset", id, lazy, res)];
4927
+ case 0: return [4 /*yield*/, this.getAssetByName("Asset", name, res)];
4865
4928
  case 1:
4866
4929
  asset = _c.sent();
4867
4930
  return [2 /*return*/, asset.download()];
@@ -4869,10 +4932,35 @@
4869
4932
  });
4870
4933
  });
4871
4934
  };
4872
- AssetsController.prototype.getAsset = function (type, id, lazy, res) {
4935
+ AssetsController.prototype.getImageByName = function (name, params, res) {
4936
+ return __awaiter$7(this, void 0, void 0, function () {
4937
+ var asset;
4938
+ return __generator(this, function (_c) {
4939
+ switch (_c.label) {
4940
+ case 0: return [4 /*yield*/, this.getAssetByName("Image", name, res)];
4941
+ case 1:
4942
+ asset = _c.sent();
4943
+ return [2 /*return*/, asset.downloadImage(params)];
4944
+ }
4945
+ });
4946
+ });
4947
+ };
4948
+ AssetsController.prototype.setAssetHeaders = function (type, asset, res) {
4873
4949
  var _a, _b;
4950
+ if ((_a = asset.metadata) === null || _a === void 0 ? void 0 : _a.classified) {
4951
+ throw new routingControllers.HttpError(403, type + " is classified, and can be only downloaded from a custom url.");
4952
+ }
4953
+ var ext = (_b = asset.metadata) === null || _b === void 0 ? void 0 : _b.extension;
4954
+ if (ext) {
4955
+ res.header("content-disposition", "inline; filename=" + asset.filename + "." + ext);
4956
+ }
4957
+ if (asset.contentType) {
4958
+ res.header("content-type", asset.contentType);
4959
+ }
4960
+ };
4961
+ AssetsController.prototype.getAsset = function (type, id, lazy, res) {
4874
4962
  return __awaiter$7(this, void 0, void 0, function () {
4875
- var asset, ext;
4963
+ var asset;
4876
4964
  return __generator(this, function (_c) {
4877
4965
  switch (_c.label) {
4878
4966
  case 0: return [4 /*yield*/, this.assetResolver.resolve(id, lazy)];
@@ -4881,16 +4969,24 @@
4881
4969
  if (!asset) {
4882
4970
  throw new routingControllers.HttpError(404, type + " with id: '" + id + "' not found.");
4883
4971
  }
4884
- if ((_a = asset.metadata) === null || _a === void 0 ? void 0 : _a.classified) {
4885
- throw new routingControllers.HttpError(403, type + " is classified, and can be only downloaded from a custom url.");
4886
- }
4887
- ext = (_b = asset.metadata) === null || _b === void 0 ? void 0 : _b.extension;
4888
- if (ext) {
4889
- res.header("content-disposition", "inline; filename=" + asset.filename + "." + ext);
4890
- }
4891
- if (asset.contentType) {
4892
- res.header("content-type", asset.contentType);
4972
+ this.setAssetHeaders(type, asset, res);
4973
+ return [2 /*return*/, asset];
4974
+ }
4975
+ });
4976
+ });
4977
+ };
4978
+ AssetsController.prototype.getAssetByName = function (type, filename, res) {
4979
+ return __awaiter$7(this, void 0, void 0, function () {
4980
+ var asset;
4981
+ return __generator(this, function (_c) {
4982
+ switch (_c.label) {
4983
+ case 0: return [4 /*yield*/, this.assets.find({ filename: filename })];
4984
+ case 1:
4985
+ asset = _c.sent();
4986
+ if (!asset) {
4987
+ throw new routingControllers.HttpError(404, type + " with filename: '" + filename + "' not found.");
4893
4988
  }
4989
+ this.setAssetHeaders(type, asset, res);
4894
4990
  return [2 /*return*/, asset];
4895
4991
  }
4896
4992
  });
@@ -4914,6 +5010,13 @@
4914
5010
  __metadata$7("design:paramtypes", [Object]),
4915
5011
  __metadata$7("design:returntype", Promise)
4916
5012
  ], AssetsController.prototype, "uploadUrl", null);
5013
+ __decorate$a([
5014
+ routingControllers.Get("/:id"),
5015
+ __param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParam("lazy")), __param$5(2, routingControllers.Res()),
5016
+ __metadata$7("design:type", Function),
5017
+ __metadata$7("design:paramtypes", [String, Boolean, Object]),
5018
+ __metadata$7("design:returntype", Promise)
5019
+ ], AssetsController.prototype, "getFile", null);
4917
5020
  __decorate$a([
4918
5021
  routingControllers.Get("/image/:id/:rotation"),
4919
5022
  __param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParams()), __param$5(2, routingControllers.Res()), __param$5(3, routingControllers.Param("rotation")),
@@ -4929,12 +5032,19 @@
4929
5032
  __metadata$7("design:returntype", Promise)
4930
5033
  ], AssetsController.prototype, "getImage", null);
4931
5034
  __decorate$a([
4932
- routingControllers.Get("/:id"),
4933
- __param$5(0, routingControllers.Param("id")), __param$5(1, routingControllers.QueryParam("lazy")), __param$5(2, routingControllers.Res()),
5035
+ routingControllers.Get("/by-name/:id"),
5036
+ __param$5(0, routingControllers.Param("name")), __param$5(1, routingControllers.Res()),
4934
5037
  __metadata$7("design:type", Function),
4935
- __metadata$7("design:paramtypes", [String, Boolean, Object]),
5038
+ __metadata$7("design:paramtypes", [String, Object]),
4936
5039
  __metadata$7("design:returntype", Promise)
4937
- ], AssetsController.prototype, "getFile", null);
5040
+ ], AssetsController.prototype, "getFileByName", null);
5041
+ __decorate$a([
5042
+ routingControllers.Get("/by-name/image/:id"),
5043
+ __param$5(0, routingControllers.Param("name")), __param$5(1, routingControllers.QueryParams()), __param$5(2, routingControllers.Res()),
5044
+ __metadata$7("design:type", Function),
5045
+ __metadata$7("design:paramtypes", [String, Object, Object]),
5046
+ __metadata$7("design:returntype", Promise)
5047
+ ], AssetsController.prototype, "getImageByName", null);
4938
5048
  AssetsController = __decorate$a([
4939
5049
  tsyringe.injectable(),
4940
5050
  routingControllers.Controller("/assets"),
@@ -6078,6 +6188,8 @@
6078
6188
  diContainer = parent.createChildContainer();
6079
6189
  allProviders.forEach(function (provider) {
6080
6190
  if (isType(provider)) {
6191
+ if (tsyringe.container.isRegistered(provider))
6192
+ return;
6081
6193
  diContainer.register(provider, provider);
6082
6194
  return;
6083
6195
  }
@@ -6239,13 +6351,15 @@
6239
6351
  exports.isInterface = isInterface;
6240
6352
  exports.isNullOrUndefined = isNullOrUndefined;
6241
6353
  exports.isObject = isObject;
6354
+ exports.isObjectId = isObjectId;
6242
6355
  exports.isPrimitive = isPrimitive;
6243
6356
  exports.isString = isString;
6244
6357
  exports.isType = isType;
6245
6358
  exports.jsonHighlight = jsonHighlight;
6246
6359
  exports.lastItem = lastItem;
6247
6360
  exports.lcFirst = lcFirst;
6248
- exports.lookupPipelines = lookupPipelines;
6361
+ exports.letsLookupStage = letsLookupStage;
6362
+ exports.lookupStages = lookupStages;
6249
6363
  exports.md5 = md5;
6250
6364
  exports.mkdirRecursive = mkdirRecursive;
6251
6365
  exports.multiSubscription = multiSubscription;
@@ -6262,10 +6376,13 @@
6262
6376
  exports.readAndDeleteFile = readAndDeleteFile;
6263
6377
  exports.readFile = readFile;
6264
6378
  exports.regroup = regroup;
6379
+ exports.replaceSpecialChars = replaceSpecialChars;
6265
6380
  exports.runCommand = runCommand;
6266
6381
  exports.setupBackend = setupBackend;
6267
6382
  exports.streamToBuffer = streamToBuffer;
6383
+ exports.toImage = toImage;
6268
6384
  exports.ucFirst = ucFirst;
6385
+ exports.uniqueItems = uniqueItems;
6269
6386
  exports.valueToPromise = valueToPromise;
6270
6387
  exports.writeFile = writeFile;
6271
6388