@aws-amplify/predictions 4.0.40 → 4.0.41-unstable.4

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.
@@ -96555,7 +96555,7 @@ function () {
96555
96555
  this.params = null;
96556
96556
  this.opts = null;
96557
96557
  this.completedParts = [];
96558
- this.cancel = false; // Progress reporting
96558
+ this.uploadId = null; // Progress reporting
96559
96559
 
96560
96560
  this.bytesUploaded = 0;
96561
96561
  this.totalBytesToUpload = 0;
@@ -96568,20 +96568,22 @@ function () {
96568
96568
 
96569
96569
  AWSS3ProviderManagedUpload.prototype.upload = function () {
96570
96570
  return __awaiter(this, void 0, void 0, function () {
96571
- var _a, putObjectCommand, uploadId, numberOfPartsToUpload, parts, start;
96571
+ var _a, putObjectCommand, _b, numberOfPartsToUpload, parts, start, error_1;
96572
96572
 
96573
96573
  var _this = this;
96574
96574
 
96575
- return __generator(this, function (_b) {
96576
- switch (_b.label) {
96575
+ return __generator(this, function (_c) {
96576
+ switch (_c.label) {
96577
96577
  case 0:
96578
+ _c.trys.push([0, 10,, 12]);
96579
+
96578
96580
  _a = this;
96579
96581
  return [4
96580
96582
  /*yield*/
96581
96583
  , this.validateAndSanitizeBody(this.params.Body)];
96582
96584
 
96583
96585
  case 1:
96584
- _a.body = _b.sent();
96586
+ _a.body = _c.sent();
96585
96587
  this.totalBytesToUpload = this.byteLength(this.body);
96586
96588
  if (!(this.totalBytesToUpload <= this.minPartSize)) return [3
96587
96589
  /*break*/
@@ -96594,107 +96596,113 @@ function () {
96594
96596
  , this.s3client.send(putObjectCommand)];
96595
96597
 
96596
96598
  case 2:
96599
+ // Step 1: Initiate the multi part upload
96600
+ _b = this;
96597
96601
  return [4
96598
96602
  /*yield*/
96599
96603
  , this.createMultiPartUpload()];
96600
96604
 
96601
96605
  case 3:
96602
- uploadId = _b.sent();
96606
+ // Step 1: Initiate the multi part upload
96607
+ _b.uploadId = _c.sent();
96603
96608
  numberOfPartsToUpload = Math.ceil(this.totalBytesToUpload / this.minPartSize);
96604
96609
  parts = this.createParts();
96605
96610
  start = 0;
96606
- _b.label = 4;
96611
+ _c.label = 4;
96607
96612
 
96608
96613
  case 4:
96609
96614
  if (!(start < numberOfPartsToUpload)) return [3
96610
96615
  /*break*/
96611
- , 9];
96612
- /** This first block will try to cancel the upload if the cancel
96613
- * request came before any parts uploads have started.
96614
- **/
96616
+ , 7]; // Upload as many as `queueSize` parts simultaneously
96615
96617
 
96616
96618
  return [4
96617
96619
  /*yield*/
96618
- , this.checkIfUploadCancelled(uploadId)];
96620
+ , this.uploadParts(this.uploadId, parts.slice(start, start + this.queueSize))];
96619
96621
 
96620
96622
  case 5:
96621
- /** This first block will try to cancel the upload if the cancel
96622
- * request came before any parts uploads have started.
96623
- **/
96624
- _b.sent(); // Upload as many as `queueSize` parts simultaneously
96625
-
96626
-
96627
- return [4
96628
- /*yield*/
96629
- , this.uploadParts(uploadId, parts.slice(start, start + this.queueSize))];
96630
-
96631
- case 6:
96632
96623
  // Upload as many as `queueSize` parts simultaneously
96633
- _b.sent();
96634
- /** Call cleanup a second time in case there were part upload requests
96635
- * in flight. This is to ensure that all parts are cleaned up.
96636
- */
96637
-
96638
-
96639
- return [4
96640
- /*yield*/
96641
- , this.checkIfUploadCancelled(uploadId)];
96642
-
96643
- case 7:
96644
- /** Call cleanup a second time in case there were part upload requests
96645
- * in flight. This is to ensure that all parts are cleaned up.
96646
- */
96647
- _b.sent();
96624
+ _c.sent();
96648
96625
 
96649
- _b.label = 8;
96626
+ _c.label = 6;
96650
96627
 
96651
- case 8:
96628
+ case 6:
96652
96629
  start += this.queueSize;
96653
96630
  return [3
96654
96631
  /*break*/
96655
96632
  , 4];
96656
96633
 
96657
- case 9:
96634
+ case 7:
96658
96635
  parts.map(function (part) {
96659
96636
  _this.removeEventListener(part);
96660
96637
  });
96661
96638
  return [4
96662
96639
  /*yield*/
96663
- , this.finishMultiPartUpload(uploadId)];
96640
+ , this.finishMultiPartUpload(this.uploadId)];
96664
96641
 
96665
- case 10:
96642
+ case 8:
96666
96643
  // Step 3: Finalize the upload such that S3 can recreate the file
96667
96644
  return [2
96668
96645
  /*return*/
96669
- , _b.sent()];
96646
+ , _c.sent()];
96647
+
96648
+ case 9:
96649
+ return [3
96650
+ /*break*/
96651
+ , 12];
96652
+
96653
+ case 10:
96654
+ error_1 = _c.sent(); // if any error is thrown, call cleanup
96655
+
96656
+ return [4
96657
+ /*yield*/
96658
+ , this.cleanup(this.uploadId)];
96659
+
96660
+ case 11:
96661
+ // if any error is thrown, call cleanup
96662
+ _c.sent();
96663
+
96664
+ logger.error('Error. Cancelling the multipart upload.');
96665
+ throw error_1;
96666
+
96667
+ case 12:
96668
+ return [2
96669
+ /*return*/
96670
+ ];
96670
96671
  }
96671
96672
  });
96672
96673
  });
96673
96674
  };
96674
96675
 
96675
96676
  AWSS3ProviderManagedUpload.prototype.createParts = function () {
96676
- var parts = [];
96677
+ try {
96678
+ var parts = [];
96679
+
96680
+ for (var bodyStart = 0; bodyStart < this.totalBytesToUpload;) {
96681
+ var bodyEnd = Math.min(bodyStart + this.minPartSize, this.totalBytesToUpload);
96682
+ parts.push({
96683
+ bodyPart: this.body.slice(bodyStart, bodyEnd),
96684
+ partNumber: parts.length + 1,
96685
+ emitter: new events__WEBPACK_IMPORTED_MODULE_3__["EventEmitter"](),
96686
+ _lastUploadedBytes: 0
96687
+ });
96688
+ bodyStart += this.minPartSize;
96689
+ }
96677
96690
 
96678
- for (var bodyStart = 0; bodyStart < this.totalBytesToUpload;) {
96679
- var bodyEnd = Math.min(bodyStart + this.minPartSize, this.totalBytesToUpload);
96680
- parts.push({
96681
- bodyPart: this.body.slice(bodyStart, bodyEnd),
96682
- partNumber: parts.length + 1,
96683
- emitter: new events__WEBPACK_IMPORTED_MODULE_3__["EventEmitter"](),
96684
- _lastUploadedBytes: 0
96685
- });
96686
- bodyStart += this.minPartSize;
96691
+ return parts;
96692
+ } catch (error) {
96693
+ logger.error(error);
96694
+ throw error;
96687
96695
  }
96688
-
96689
- return parts;
96690
96696
  };
96691
96697
 
96692
96698
  AWSS3ProviderManagedUpload.prototype.createMultiPartUpload = function () {
96693
96699
  return __awaiter(this, void 0, void 0, function () {
96694
- var createMultiPartUploadCommand, response;
96700
+ var createMultiPartUploadCommand, response, error_2;
96695
96701
  return __generator(this, function (_a) {
96696
96702
  switch (_a.label) {
96697
96703
  case 0:
96704
+ _a.trys.push([0, 2,, 3]);
96705
+
96698
96706
  createMultiPartUploadCommand = new _aws_sdk_client_s3__WEBPACK_IMPORTED_MODULE_1__["CreateMultipartUploadCommand"](this.params);
96699
96707
  return [4
96700
96708
  /*yield*/
@@ -96706,6 +96714,16 @@ function () {
96706
96714
  return [2
96707
96715
  /*return*/
96708
96716
  , response.UploadId];
96717
+
96718
+ case 2:
96719
+ error_2 = _a.sent();
96720
+ logger.error(error_2);
96721
+ throw error_2;
96722
+
96723
+ case 3:
96724
+ return [2
96725
+ /*return*/
96726
+ ];
96709
96727
  }
96710
96728
  });
96711
96729
  });
@@ -96718,7 +96736,7 @@ function () {
96718
96736
 
96719
96737
  AWSS3ProviderManagedUpload.prototype.uploadParts = function (uploadId, parts) {
96720
96738
  return __awaiter(this, void 0, void 0, function () {
96721
- var allResults, i, error_1;
96739
+ var allResults, i, error_3;
96722
96740
 
96723
96741
  var _this = this;
96724
96742
 
@@ -96782,12 +96800,9 @@ function () {
96782
96800
  , 3];
96783
96801
 
96784
96802
  case 2:
96785
- error_1 = _a.sent();
96786
- logger.error('error happened while uploading a part. Cancelling the multipart upload', error_1);
96787
- this.cancelUpload();
96788
- return [2
96789
- /*return*/
96790
- ];
96803
+ error_3 = _a.sent();
96804
+ logger.error('Error happened while uploading a part. Cancelling the multipart upload');
96805
+ throw error_3;
96791
96806
 
96792
96807
  case 3:
96793
96808
  return [2
@@ -96800,7 +96815,7 @@ function () {
96800
96815
 
96801
96816
  AWSS3ProviderManagedUpload.prototype.finishMultiPartUpload = function (uploadId) {
96802
96817
  return __awaiter(this, void 0, void 0, function () {
96803
- var input, completeUploadCommand, data, error_2;
96818
+ var input, completeUploadCommand, data, error_4;
96804
96819
  return __generator(this, function (_a) {
96805
96820
  switch (_a.label) {
96806
96821
  case 0:
@@ -96829,59 +96844,11 @@ function () {
96829
96844
  , data.Key];
96830
96845
 
96831
96846
  case 3:
96832
- error_2 = _a.sent();
96833
- logger.error('error happened while finishing the upload. Cancelling the multipart upload', error_2);
96834
- this.cancelUpload();
96835
- return [2
96836
- /*return*/
96837
- ];
96838
-
96839
- case 4:
96840
- return [2
96841
- /*return*/
96842
- ];
96843
- }
96844
- });
96845
- });
96846
- };
96847
-
96848
- AWSS3ProviderManagedUpload.prototype.checkIfUploadCancelled = function (uploadId) {
96849
- return __awaiter(this, void 0, void 0, function () {
96850
- var errorMessage, error_3;
96851
- return __generator(this, function (_a) {
96852
- switch (_a.label) {
96853
- case 0:
96854
- if (!this.cancel) return [3
96855
- /*break*/
96856
- , 5];
96857
- errorMessage = 'Upload was cancelled.';
96858
- _a.label = 1;
96859
-
96860
- case 1:
96861
- _a.trys.push([1, 3,, 4]);
96862
-
96863
- return [4
96864
- /*yield*/
96865
- , this.cleanup(uploadId)];
96866
-
96867
- case 2:
96868
- _a.sent();
96869
-
96870
- return [3
96871
- /*break*/
96872
- , 4];
96873
-
96874
- case 3:
96875
- error_3 = _a.sent();
96876
- errorMessage += " " + error_3.message;
96877
- return [3
96878
- /*break*/
96879
- , 4];
96847
+ error_4 = _a.sent();
96848
+ logger.error('Error happened while finishing the upload.');
96849
+ throw error_4;
96880
96850
 
96881
96851
  case 4:
96882
- throw new Error(errorMessage);
96883
-
96884
- case 5:
96885
96852
  return [2
96886
96853
  /*return*/
96887
96854
  ];
@@ -96890,10 +96857,6 @@ function () {
96890
96857
  });
96891
96858
  };
96892
96859
 
96893
- AWSS3ProviderManagedUpload.prototype.cancelUpload = function () {
96894
- this.cancel = true;
96895
- };
96896
-
96897
96860
  AWSS3ProviderManagedUpload.prototype.cleanup = function (uploadId) {
96898
96861
  return __awaiter(this, void 0, void 0, function () {
96899
96862
  var input, data;
@@ -96925,7 +96888,7 @@ function () {
96925
96888
  data = _a.sent();
96926
96889
 
96927
96890
  if (data && data.Parts && data.Parts.length > 0) {
96928
- throw new Error('Multi Part upload clean up failed');
96891
+ throw new Error('Multipart upload clean up failed.');
96929
96892
  }
96930
96893
 
96931
96894
  return [2