@stemy/backend 2.9.5 → 2.9.8

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.
@@ -106,7 +106,7 @@
106
106
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
107
107
  return Reflect.metadata(metadataKey, metadataValue);
108
108
  }
109
- function __awaiter$w(thisArg, _arguments, P, generator) {
109
+ function __awaiter$x(thisArg, _arguments, P, generator) {
110
110
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
111
111
  return new (P || (P = Promise))(function (resolve, reject) {
112
112
  function fulfilled(value) { try {
@@ -353,7 +353,7 @@
353
353
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
354
354
  }
355
355
 
356
- var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
356
+ var __awaiter$w = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
357
357
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
358
358
  return new (P || (P = Promise))(function (resolve, reject) {
359
359
  function fulfilled(value) { try {
@@ -595,7 +595,7 @@
595
595
  }
596
596
  function paginateAggregations(model, aggregations, params, metaProjection) {
597
597
  if (metaProjection === void 0) { metaProjection = {}; }
598
- return __awaiter$v(this, void 0, void 0, function () {
598
+ return __awaiter$w(this, void 0, void 0, function () {
599
599
  var sortField, sortAggregation, result, pagination;
600
600
  var _a;
601
601
  return __generator(this, function (_b) {
@@ -706,7 +706,7 @@
706
706
  }
707
707
  function readAndDeleteFile(path, timeout) {
708
708
  if (timeout === void 0) { timeout = 5000; }
709
- return __awaiter$v(this, void 0, void 0, function () {
709
+ return __awaiter$w(this, void 0, void 0, function () {
710
710
  var data;
711
711
  return __generator(this, function (_a) {
712
712
  switch (_a.label) {
@@ -723,7 +723,7 @@
723
723
  });
724
724
  }
725
725
  function writeFile(path$1, data) {
726
- return __awaiter$v(this, void 0, void 0, function () {
726
+ return __awaiter$w(this, void 0, void 0, function () {
727
727
  return __generator(this, function (_a) {
728
728
  switch (_a.label) {
729
729
  case 0: return [4 /*yield*/, mkdirRecursive(path.dirname(path$1))];
@@ -811,7 +811,7 @@
811
811
  var paramName = modelName.toLowerCase();
812
812
  return routingControllers.createParamDecorator({
813
813
  required: false,
814
- value: function (action) { return __awaiter$v(_this, void 0, void 0, function () {
814
+ value: function (action) { return __awaiter$w(_this, void 0, void 0, function () {
815
815
  var req, token, id, query, doc, _a, _b, e_3;
816
816
  return __generator(this, function (_c) {
817
817
  switch (_c.label) {
@@ -1186,7 +1186,7 @@
1186
1186
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1187
1187
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1188
1188
  };
1189
- var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1189
+ var __awaiter$v = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1190
1190
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1191
1191
  return new (P || (P = Promise))(function (resolve, reject) {
1192
1192
  function fulfilled(value) { try {
@@ -1234,7 +1234,7 @@
1234
1234
  };
1235
1235
  AssetProcessor.fileTypeFromBuffer = function (buffer) {
1236
1236
  var _a;
1237
- return __awaiter$u(this, void 0, void 0, function () {
1237
+ return __awaiter$v(this, void 0, void 0, function () {
1238
1238
  var type;
1239
1239
  return __generator(this, function (_b) {
1240
1240
  switch (_b.label) {
@@ -1268,13 +1268,13 @@
1268
1268
  return imageTypes.indexOf(contentType) >= 0;
1269
1269
  };
1270
1270
  AssetProcessor.copyImageMeta = function (buffer, metadata, fileType) {
1271
- return __awaiter$u(this, void 0, void 0, function () {
1271
+ return __awaiter$v(this, void 0, void 0, function () {
1272
1272
  var match, attrs, parts, output;
1273
1273
  return __generator(this, function (_b) {
1274
1274
  switch (_b.label) {
1275
1275
  case 0:
1276
1276
  if (fileType.mime === "image/svg+xml") {
1277
- match = /<svg(.+)>/gi.exec(buffer.toString("utf8"));
1277
+ match = /<svg([^<>]+)>/gi.exec(buffer.toString("utf8"));
1278
1278
  if (match && match.length > 1) {
1279
1279
  attrs = match[1].match(/([a-z]+)="([^"]+)"/gi);
1280
1280
  attrs.forEach(function (attr) {
@@ -1289,6 +1289,9 @@
1289
1289
  metadata.width = Number(parts[0]) + Number(parts[2]);
1290
1290
  metadata.height = Number(parts[1]) + Number(parts[3]);
1291
1291
  }
1292
+ if (!isNaN(metadata.width) && !isNaN(metadata.height)) {
1293
+ metadata.svgSize = { x: metadata.width, y: metadata.height };
1294
+ }
1292
1295
  }
1293
1296
  return [2 /*return*/, buffer];
1294
1297
  }
@@ -1312,7 +1315,7 @@
1312
1315
  });
1313
1316
  };
1314
1317
  AssetProcessor.prototype.process = function (buffer, metadata, fileType) {
1315
- return __awaiter$u(this, void 0, void 0, function () {
1318
+ return __awaiter$v(this, void 0, void 0, function () {
1316
1319
  return __generator(this, function (_b) {
1317
1320
  switch (_b.label) {
1318
1321
  case 0:
@@ -1410,7 +1413,7 @@
1410
1413
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
1411
1414
  return Reflect.metadata(k, v);
1412
1415
  };
1413
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1416
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1414
1417
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1415
1418
  return new (P || (P = Promise))(function (resolve, reject) {
1416
1419
  function fulfilled(value) { try {
@@ -1458,7 +1461,7 @@
1458
1461
  configurable: true
1459
1462
  });
1460
1463
  MongoConnector.prototype.connect = function () {
1461
- return __awaiter$t(this, void 0, void 0, function () {
1464
+ return __awaiter$u(this, void 0, void 0, function () {
1462
1465
  var _a;
1463
1466
  return __generator(this, function (_b) {
1464
1467
  switch (_b.label) {
@@ -1490,7 +1493,7 @@
1490
1493
  __metadata$o("design:paramtypes", [exports.Configuration])
1491
1494
  ], exports.MongoConnector);
1492
1495
 
1493
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1496
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1494
1497
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1495
1498
  return new (P || (P = Promise))(function (resolve, reject) {
1496
1499
  function fulfilled(value) { try {
@@ -1526,7 +1529,7 @@
1526
1529
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1527
1530
  };
1528
1531
  BaseEntity.prototype.load = function () {
1529
- return __awaiter$s(this, void 0, void 0, function () {
1532
+ return __awaiter$t(this, void 0, void 0, function () {
1530
1533
  var res;
1531
1534
  return __generator(this, function (_a) {
1532
1535
  switch (_a.label) {
@@ -1549,7 +1552,7 @@
1549
1552
  return BaseEntity;
1550
1553
  }());
1551
1554
 
1552
- var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1555
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1553
1556
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1554
1557
  return new (P || (P = Promise))(function (resolve, reject) {
1555
1558
  function fulfilled(value) { try {
@@ -1602,7 +1605,7 @@
1602
1605
  };
1603
1606
  };
1604
1607
  Asset.toImage = function (stream, meta, params) {
1605
- return __awaiter$r(this, void 0, void 0, function () {
1608
+ return __awaiter$s(this, void 0, void 0, function () {
1606
1609
  var crop, buffer, cropBefore, cropAfter, imgMeta, width, height, e_1;
1607
1610
  return __generator(this, function (_a) {
1608
1611
  switch (_a.label) {
@@ -1724,7 +1727,7 @@
1724
1727
  configurable: true
1725
1728
  });
1726
1729
  Asset.prototype.unlink = function () {
1727
- return __awaiter$r(this, void 0, void 0, function () {
1730
+ return __awaiter$s(this, void 0, void 0, function () {
1728
1731
  return __generator(this, function (_a) {
1729
1732
  return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
1730
1733
  });
@@ -1734,7 +1737,7 @@
1734
1737
  return streamToBuffer(this.stream);
1735
1738
  };
1736
1739
  Asset.prototype.download = function (metadata) {
1737
- return __awaiter$r(this, void 0, void 0, function () {
1740
+ return __awaiter$s(this, void 0, void 0, function () {
1738
1741
  return __generator(this, function (_a) {
1739
1742
  switch (_a.label) {
1740
1743
  case 0:
@@ -1754,14 +1757,14 @@
1754
1757
  };
1755
1758
  Asset.prototype.getImage = function (params) {
1756
1759
  if (params === void 0) { params = null; }
1757
- return __awaiter$r(this, void 0, void 0, function () {
1760
+ return __awaiter$s(this, void 0, void 0, function () {
1758
1761
  return __generator(this, function (_a) {
1759
1762
  return [2 /*return*/, Asset.toImage(this.stream, this.metadata, params)];
1760
1763
  });
1761
1764
  });
1762
1765
  };
1763
1766
  Asset.prototype.downloadImage = function (params, metadata) {
1764
- return __awaiter$r(this, void 0, void 0, function () {
1767
+ return __awaiter$s(this, void 0, void 0, function () {
1765
1768
  var _a, _b;
1766
1769
  return __generator(this, function (_c) {
1767
1770
  switch (_c.label) {
@@ -1776,6 +1779,93 @@
1776
1779
  return Asset;
1777
1780
  }(BaseEntity));
1778
1781
 
1782
+ var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1783
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1784
+ return new (P || (P = Promise))(function (resolve, reject) {
1785
+ function fulfilled(value) { try {
1786
+ step(generator.next(value));
1787
+ }
1788
+ catch (e) {
1789
+ reject(e);
1790
+ } }
1791
+ function rejected(value) { try {
1792
+ step(generator["throw"](value));
1793
+ }
1794
+ catch (e) {
1795
+ reject(e);
1796
+ } }
1797
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1798
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1799
+ });
1800
+ };
1801
+ var TempAsset = /** @class */ (function () {
1802
+ function TempAsset(buffer, filename, contentType, metadata) {
1803
+ this.buffer = buffer;
1804
+ this.filename = filename;
1805
+ this.contentType = contentType;
1806
+ this.metadata = metadata;
1807
+ this.id = new bson.ObjectId().toHexString();
1808
+ }
1809
+ Object.defineProperty(TempAsset.prototype, "stream", {
1810
+ get: function () {
1811
+ return bufferToStream(this.buffer);
1812
+ },
1813
+ enumerable: false,
1814
+ configurable: true
1815
+ });
1816
+ TempAsset.prototype.unlink = function () {
1817
+ return __awaiter$r(this, void 0, void 0, function () {
1818
+ return __generator(this, function (_a) {
1819
+ throw new Error("Temp asset '" + this.id + "' can not be removed!");
1820
+ });
1821
+ });
1822
+ };
1823
+ TempAsset.prototype.getBuffer = function () {
1824
+ return __awaiter$r(this, void 0, void 0, function () {
1825
+ return __generator(this, function (_a) {
1826
+ return [2 /*return*/, this.buffer];
1827
+ });
1828
+ });
1829
+ };
1830
+ TempAsset.prototype.download = function (metadata) {
1831
+ return __awaiter$r(this, void 0, void 0, function () {
1832
+ return __generator(this, function (_a) {
1833
+ return [2 /*return*/, this.stream];
1834
+ });
1835
+ });
1836
+ };
1837
+ TempAsset.prototype.downloadImage = function (params, metadata) {
1838
+ Object.assign(this.metadata, metadata || {});
1839
+ return Asset.toImage(this.stream, this.metadata, params);
1840
+ };
1841
+ TempAsset.prototype.getImage = function (params) {
1842
+ return this.downloadImage(params);
1843
+ };
1844
+ TempAsset.prototype.save = function () {
1845
+ return __awaiter$r(this, void 0, void 0, function () {
1846
+ return __generator(this, function (_a) {
1847
+ return [2 /*return*/, this];
1848
+ });
1849
+ });
1850
+ };
1851
+ TempAsset.prototype.load = function () {
1852
+ return __awaiter$r(this, void 0, void 0, function () {
1853
+ return __generator(this, function (_a) {
1854
+ return [2 /*return*/, this];
1855
+ });
1856
+ });
1857
+ };
1858
+ TempAsset.prototype.toJSON = function () {
1859
+ return {
1860
+ id: this.id,
1861
+ filename: this.filename,
1862
+ contentType: this.contentType,
1863
+ metadata: this.metadata
1864
+ };
1865
+ };
1866
+ return TempAsset;
1867
+ }());
1868
+
1779
1869
  var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
1780
1870
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1781
1871
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1898,6 +1988,43 @@
1898
1988
  });
1899
1989
  });
1900
1990
  };
1991
+ Assets.prototype.download = function (url, contentType) {
1992
+ if (contentType === void 0) { contentType = null; }
1993
+ return __awaiter$q(this, void 0, void 0, function () {
1994
+ var buffer, fileType, e_3, metadata;
1995
+ return __generator(this, function (_b) {
1996
+ switch (_b.label) {
1997
+ case 0: return [4 /*yield*/, axios__default["default"]({ url: url, responseType: "arraybuffer" })];
1998
+ case 1:
1999
+ buffer = (_b.sent()).data;
2000
+ fileType = { ext: "", mime: contentType };
2001
+ _b.label = 2;
2002
+ case 2:
2003
+ _b.trys.push([2, 4, , 5]);
2004
+ return [4 /*yield*/, exports.AssetProcessor.fileTypeFromBuffer(buffer)];
2005
+ case 3:
2006
+ fileType = _b.sent();
2007
+ return [3 /*break*/, 5];
2008
+ case 4:
2009
+ e_3 = _b.sent();
2010
+ if (!fileType.mime) {
2011
+ throw "Can't determine mime type";
2012
+ }
2013
+ console.log("Can't determine mime type", e_3);
2014
+ return [3 /*break*/, 5];
2015
+ case 5:
2016
+ metadata = {
2017
+ filename: url,
2018
+ extension: (fileType.ext || "").trim()
2019
+ };
2020
+ return [4 /*yield*/, this.assetProcessor.process(buffer, metadata, fileType)];
2021
+ case 6:
2022
+ buffer = _b.sent();
2023
+ return [2 /*return*/, new TempAsset(buffer, url, fileType.mime, metadata)];
2024
+ }
2025
+ });
2026
+ });
2027
+ };
1901
2028
  Assets.prototype.read = function (id) {
1902
2029
  return __awaiter$q(this, void 0, void 0, function () {
1903
2030
  return __generator(this, function (_b) {
@@ -1921,7 +2048,7 @@
1921
2048
  Assets.prototype.findMany = function (where) {
1922
2049
  return __awaiter$q(this, void 0, void 0, function () {
1923
2050
  var cursor, items, result, items_1, items_1_1, item;
1924
- var e_3, _b;
2051
+ var e_4, _b;
1925
2052
  return __generator(this, function (_c) {
1926
2053
  switch (_c.label) {
1927
2054
  case 0:
@@ -1938,12 +2065,12 @@
1938
2065
  result.push(new Asset(item._id, item, this.collection, this.bucket));
1939
2066
  }
1940
2067
  }
1941
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
2068
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1942
2069
  finally {
1943
2070
  try {
1944
2071
  if (items_1_1 && !items_1_1.done && (_b = items_1.return)) _b.call(items_1);
1945
2072
  }
1946
- finally { if (e_3) throw e_3.error; }
2073
+ finally { if (e_4) throw e_4.error; }
1947
2074
  }
1948
2075
  return [2 /*return*/, result];
1949
2076
  }