@stemy/backend 2.9.7 → 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,7 +1268,7 @@
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) {
@@ -1315,7 +1315,7 @@
1315
1315
  });
1316
1316
  };
1317
1317
  AssetProcessor.prototype.process = function (buffer, metadata, fileType) {
1318
- return __awaiter$u(this, void 0, void 0, function () {
1318
+ return __awaiter$v(this, void 0, void 0, function () {
1319
1319
  return __generator(this, function (_b) {
1320
1320
  switch (_b.label) {
1321
1321
  case 0:
@@ -1413,7 +1413,7 @@
1413
1413
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
1414
1414
  return Reflect.metadata(k, v);
1415
1415
  };
1416
- var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1416
+ var __awaiter$u = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1417
1417
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1418
1418
  return new (P || (P = Promise))(function (resolve, reject) {
1419
1419
  function fulfilled(value) { try {
@@ -1461,7 +1461,7 @@
1461
1461
  configurable: true
1462
1462
  });
1463
1463
  MongoConnector.prototype.connect = function () {
1464
- return __awaiter$t(this, void 0, void 0, function () {
1464
+ return __awaiter$u(this, void 0, void 0, function () {
1465
1465
  var _a;
1466
1466
  return __generator(this, function (_b) {
1467
1467
  switch (_b.label) {
@@ -1493,7 +1493,7 @@
1493
1493
  __metadata$o("design:paramtypes", [exports.Configuration])
1494
1494
  ], exports.MongoConnector);
1495
1495
 
1496
- var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1496
+ var __awaiter$t = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1497
1497
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1498
1498
  return new (P || (P = Promise))(function (resolve, reject) {
1499
1499
  function fulfilled(value) { try {
@@ -1529,7 +1529,7 @@
1529
1529
  return this.collection.updateOne({ _id: this.mId }, { $set: this.toJSON() });
1530
1530
  };
1531
1531
  BaseEntity.prototype.load = function () {
1532
- return __awaiter$s(this, void 0, void 0, function () {
1532
+ return __awaiter$t(this, void 0, void 0, function () {
1533
1533
  var res;
1534
1534
  return __generator(this, function (_a) {
1535
1535
  switch (_a.label) {
@@ -1552,7 +1552,7 @@
1552
1552
  return BaseEntity;
1553
1553
  }());
1554
1554
 
1555
- var __awaiter$r = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1555
+ var __awaiter$s = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
1556
1556
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1557
1557
  return new (P || (P = Promise))(function (resolve, reject) {
1558
1558
  function fulfilled(value) { try {
@@ -1605,7 +1605,7 @@
1605
1605
  };
1606
1606
  };
1607
1607
  Asset.toImage = function (stream, meta, params) {
1608
- return __awaiter$r(this, void 0, void 0, function () {
1608
+ return __awaiter$s(this, void 0, void 0, function () {
1609
1609
  var crop, buffer, cropBefore, cropAfter, imgMeta, width, height, e_1;
1610
1610
  return __generator(this, function (_a) {
1611
1611
  switch (_a.label) {
@@ -1727,7 +1727,7 @@
1727
1727
  configurable: true
1728
1728
  });
1729
1729
  Asset.prototype.unlink = function () {
1730
- return __awaiter$r(this, void 0, void 0, function () {
1730
+ return __awaiter$s(this, void 0, void 0, function () {
1731
1731
  return __generator(this, function (_a) {
1732
1732
  return [2 /*return*/, deleteFromBucket(this.bucket, this.mId)];
1733
1733
  });
@@ -1737,7 +1737,7 @@
1737
1737
  return streamToBuffer(this.stream);
1738
1738
  };
1739
1739
  Asset.prototype.download = function (metadata) {
1740
- return __awaiter$r(this, void 0, void 0, function () {
1740
+ return __awaiter$s(this, void 0, void 0, function () {
1741
1741
  return __generator(this, function (_a) {
1742
1742
  switch (_a.label) {
1743
1743
  case 0:
@@ -1757,14 +1757,14 @@
1757
1757
  };
1758
1758
  Asset.prototype.getImage = function (params) {
1759
1759
  if (params === void 0) { params = null; }
1760
- return __awaiter$r(this, void 0, void 0, function () {
1760
+ return __awaiter$s(this, void 0, void 0, function () {
1761
1761
  return __generator(this, function (_a) {
1762
1762
  return [2 /*return*/, Asset.toImage(this.stream, this.metadata, params)];
1763
1763
  });
1764
1764
  });
1765
1765
  };
1766
1766
  Asset.prototype.downloadImage = function (params, metadata) {
1767
- return __awaiter$r(this, void 0, void 0, function () {
1767
+ return __awaiter$s(this, void 0, void 0, function () {
1768
1768
  var _a, _b;
1769
1769
  return __generator(this, function (_c) {
1770
1770
  switch (_c.label) {
@@ -1779,6 +1779,93 @@
1779
1779
  return Asset;
1780
1780
  }(BaseEntity));
1781
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
+
1782
1869
  var __decorate$t = (this && this.__decorate) || function (decorators, target, key, desc) {
1783
1870
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1784
1871
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1901,6 +1988,43 @@
1901
1988
  });
1902
1989
  });
1903
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
+ };
1904
2028
  Assets.prototype.read = function (id) {
1905
2029
  return __awaiter$q(this, void 0, void 0, function () {
1906
2030
  return __generator(this, function (_b) {
@@ -1924,7 +2048,7 @@
1924
2048
  Assets.prototype.findMany = function (where) {
1925
2049
  return __awaiter$q(this, void 0, void 0, function () {
1926
2050
  var cursor, items, result, items_1, items_1_1, item;
1927
- var e_3, _b;
2051
+ var e_4, _b;
1928
2052
  return __generator(this, function (_c) {
1929
2053
  switch (_c.label) {
1930
2054
  case 0:
@@ -1941,12 +2065,12 @@
1941
2065
  result.push(new Asset(item._id, item, this.collection, this.bucket));
1942
2066
  }
1943
2067
  }
1944
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
2068
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
1945
2069
  finally {
1946
2070
  try {
1947
2071
  if (items_1_1 && !items_1_1.done && (_b = items_1.return)) _b.call(items_1);
1948
2072
  }
1949
- finally { if (e_3) throw e_3.error; }
2073
+ finally { if (e_4) throw e_4.error; }
1950
2074
  }
1951
2075
  return [2 /*return*/, result];
1952
2076
  }