@aws-sdk/lib-storage 3.85.0 → 3.86.0

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.86.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.85.0...v3.86.0) (2022-05-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **lib-storage:** add missing return keys ([#2700](https://github.com/aws/aws-sdk-js-v3/issues/2700)) ([cbab94e](https://github.com/aws/aws-sdk-js-v3/commit/cbab94e901aec4650ab9e0eb19a4515e44d4ba62))
12
+
13
+
14
+
15
+
16
+
6
17
  # [3.85.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.84.0...v3.85.0) (2022-05-05)
7
18
 
8
19
  **Note:** Version bump only for package @aws-sdk/lib-storage
package/README.md CHANGED
@@ -8,26 +8,28 @@
8
8
  Upload allows for easy and efficient uploading of buffers, blobs, or streams, using a configurable amount of concurrency to perform multipart uploads where possible. This abstraction enables uploading large files or streams of unknown size due to the use of multipart uploads under the hood.
9
9
 
10
10
  ```js
11
- import { Upload } from "@aws-sdk/lib-storage";
12
- import { S3Client, S3 } from "@aws-sdk/client-s3";
13
-
14
- const target = { Bucket, Key, Body };
15
- try {
16
- const parallelUploads3 = new Upload({
17
- client: new S3({}) || new S3Client({}),
18
- tags: [...], // optional tags
19
- queueSize: 4, // optional concurrency configuration
20
- partSize: 5MB, // optional size of each part
21
- leavePartsOnError: false, // optional manually handle dropped parts
22
- params: target,
23
- });
24
-
25
- parallelUploads3.on("httpUploadProgress", (progress) => {
26
- console.log(progress);
27
- });
28
-
29
- await parallelUploads3.done();
30
- } catch (e) {
31
- console.log(e);
32
- }
11
+ import { Upload } from "@aws-sdk/lib-storage";
12
+ import { S3Client, S3 } from "@aws-sdk/client-s3";
13
+
14
+ try {
15
+ const parallelUploads3 = new Upload({
16
+ client: new S3({}) || new S3Client({}),
17
+ params: { Bucket, Key, Body },
18
+
19
+ tags: [
20
+ /*...*/
21
+ ], // optional tags
22
+ queueSize: 4, // optional concurrency configuration
23
+ partSize: 1024 * 1024 * 5, // optional size of each part, in bytes, at least 5MB
24
+ leavePartsOnError: false, // optional manually handle dropped parts
25
+ });
26
+
27
+ parallelUploads3.on("httpUploadProgress", (progress) => {
28
+ console.log(progress);
29
+ });
30
+
31
+ await parallelUploads3.done();
32
+ } catch (e) {
33
+ console.log(e);
34
+ }
33
35
  ```
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Upload = void 0;
4
4
  const abort_controller_1 = require("@aws-sdk/abort-controller");
5
5
  const client_s3_1 = require("@aws-sdk/client-s3");
6
+ const smithy_client_1 = require("@aws-sdk/smithy-client");
6
7
  const events_1 = require("events");
7
8
  const bytelength_1 = require("./bytelength");
8
9
  const chunker_1 = require("./chunker");
@@ -37,13 +38,29 @@ class Upload extends events_1.EventEmitter {
37
38
  }
38
39
  on(event, listener) {
39
40
  this.uploadEvent = event;
40
- super.on(event, listener);
41
+ return super.on(event, listener);
41
42
  }
42
43
  async __uploadUsingPut(dataPart) {
43
44
  this.isMultiPart = false;
44
45
  const params = { ...this.params, Body: dataPart.data };
45
- const putResult = await this.client.send(new client_s3_1.PutObjectCommand(params));
46
- this.putResponse = putResult;
46
+ const [putResult, endpoint] = await Promise.all([
47
+ this.client.send(new client_s3_1.PutObjectCommand(params)),
48
+ this.client.config.endpoint(),
49
+ ]);
50
+ const locationKey = this.params
51
+ .Key.split("/")
52
+ .map((segment) => (0, smithy_client_1.extendedEncodeURIComponent)(segment))
53
+ .join("/");
54
+ const locationBucket = (0, smithy_client_1.extendedEncodeURIComponent)(this.params.Bucket);
55
+ const Location = this.client.config.forcePathStyle
56
+ ? `${endpoint.protocol}//${endpoint.hostname}/${locationBucket}/${locationKey}`
57
+ : `${endpoint.protocol}//${locationBucket}.${endpoint.hostname}/${locationKey}`;
58
+ this.singleUploadResult = {
59
+ ...putResult,
60
+ Bucket: this.params.Bucket,
61
+ Key: this.params.Key,
62
+ Location,
63
+ };
47
64
  const totalSize = (0, bytelength_1.byteLength)(dataPart.data);
48
65
  this.__notifyProgress({
49
66
  loaded: totalSize,
@@ -139,7 +156,7 @@ class Upload extends events_1.EventEmitter {
139
156
  result = await this.client.send(new client_s3_1.CompleteMultipartUploadCommand(uploadCompleteParams));
140
157
  }
141
158
  else {
142
- result = this.putResponse;
159
+ result = this.singleUploadResult;
143
160
  }
144
161
  if (this.tags.length) {
145
162
  await this.client.send(new client_s3_1.PutObjectTaggingCommand({
package/dist-es/Upload.js CHANGED
@@ -1,6 +1,7 @@
1
- import { __assign, __asyncValues, __awaiter, __extends, __generator } from "tslib";
1
+ import { __assign, __asyncValues, __awaiter, __extends, __generator, __read } from "tslib";
2
2
  import { AbortController } from "@aws-sdk/abort-controller";
3
3
  import { CompleteMultipartUploadCommand, CreateMultipartUploadCommand, PutObjectCommand, PutObjectTaggingCommand, UploadPartCommand, } from "@aws-sdk/client-s3";
4
+ import { extendedEncodeURIComponent } from "@aws-sdk/smithy-client";
4
5
  import { EventEmitter } from "events";
5
6
  import { byteLength } from "./bytelength";
6
7
  import { getChunk } from "./chunker";
@@ -49,20 +50,31 @@ var Upload = (function (_super) {
49
50
  };
50
51
  Upload.prototype.on = function (event, listener) {
51
52
  this.uploadEvent = event;
52
- _super.prototype.on.call(this, event, listener);
53
+ return _super.prototype.on.call(this, event, listener);
53
54
  };
54
55
  Upload.prototype.__uploadUsingPut = function (dataPart) {
55
56
  return __awaiter(this, void 0, void 0, function () {
56
- var params, putResult, totalSize;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
57
+ var params, _a, putResult, endpoint, locationKey, locationBucket, Location, totalSize;
58
+ return __generator(this, function (_b) {
59
+ switch (_b.label) {
59
60
  case 0:
60
61
  this.isMultiPart = false;
61
62
  params = __assign(__assign({}, this.params), { Body: dataPart.data });
62
- return [4, this.client.send(new PutObjectCommand(params))];
63
+ return [4, Promise.all([
64
+ this.client.send(new PutObjectCommand(params)),
65
+ this.client.config.endpoint(),
66
+ ])];
63
67
  case 1:
64
- putResult = _a.sent();
65
- this.putResponse = putResult;
68
+ _a = __read.apply(void 0, [_b.sent(), 2]), putResult = _a[0], endpoint = _a[1];
69
+ locationKey = this.params
70
+ .Key.split("/")
71
+ .map(function (segment) { return extendedEncodeURIComponent(segment); })
72
+ .join("/");
73
+ locationBucket = extendedEncodeURIComponent(this.params.Bucket);
74
+ Location = this.client.config.forcePathStyle
75
+ ? "".concat(endpoint.protocol, "//").concat(endpoint.hostname, "/").concat(locationBucket, "/").concat(locationKey)
76
+ : "".concat(endpoint.protocol, "//").concat(locationBucket, ".").concat(endpoint.hostname, "/").concat(locationKey);
77
+ this.singleUploadResult = __assign(__assign({}, putResult), { Bucket: this.params.Bucket, Key: this.params.Key, Location: Location });
66
78
  totalSize = byteLength(dataPart.data);
67
79
  this.__notifyProgress({
68
80
  loaded: totalSize,
@@ -206,7 +218,7 @@ var Upload = (function (_super) {
206
218
  result = _a.sent();
207
219
  return [3, 4];
208
220
  case 3:
209
- result = this.putResponse;
221
+ result = this.singleUploadResult;
210
222
  _a.label = 4;
211
223
  case 4:
212
224
  if (!this.tags.length) return [3, 6];
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { AbortSignal } from "@aws-sdk/abort-controller";
3
- import { ServiceOutputTypes } from "@aws-sdk/client-s3";
2
+ import { AbortMultipartUploadCommandOutput, CompleteMultipartUploadCommandOutput } from "@aws-sdk/client-s3";
4
3
  import { EventEmitter } from "events";
5
4
  import { BodyDataTypes, Options, Progress } from "./types";
6
5
  export interface RawDataPart {
@@ -28,16 +27,16 @@ export declare class Upload extends EventEmitter {
28
27
  private uploadId?;
29
28
  uploadEvent?: string;
30
29
  private isMultiPart;
31
- private putResponse?;
30
+ private singleUploadResult?;
32
31
  constructor(options: Options);
33
32
  abort(): Promise<void>;
34
- done(): Promise<ServiceOutputTypes>;
35
- on(event: "httpUploadProgress", listener: (progress: Progress) => void): any;
36
- __uploadUsingPut(dataPart: RawDataPart): Promise<void>;
37
- __createMultipartUpload(): Promise<void>;
38
- __doConcurrentUpload(dataFeeder: AsyncGenerator<RawDataPart, void, undefined>): Promise<void>;
39
- __doMultipartUpload(): Promise<ServiceOutputTypes>;
40
- __notifyProgress(progress: Progress): void;
41
- __abortTimeout(abortSignal: AbortSignal): Promise<ServiceOutputTypes>;
42
- __validateInput(): void;
33
+ done(): Promise<CompleteMultipartUploadCommandOutput | AbortMultipartUploadCommandOutput>;
34
+ on(event: "httpUploadProgress", listener: (progress: Progress) => void): this;
35
+ private __uploadUsingPut;
36
+ private __createMultipartUpload;
37
+ private __doConcurrentUpload;
38
+ private __doMultipartUpload;
39
+ private __notifyProgress;
40
+ private __abortTimeout;
41
+ private __validateInput;
43
42
  }
@@ -1,6 +1,5 @@
1
1
 
2
- import { AbortSignal } from "@aws-sdk/abort-controller";
3
- import { ServiceOutputTypes } from "@aws-sdk/client-s3";
2
+ import { AbortMultipartUploadCommandOutput, CompleteMultipartUploadCommandOutput } from "@aws-sdk/client-s3";
4
3
  import { EventEmitter } from "events";
5
4
  import { BodyDataTypes, Options, Progress } from "./types";
6
5
  export interface RawDataPart {
@@ -26,16 +25,16 @@ export declare class Upload extends EventEmitter {
26
25
  private uploadId?;
27
26
  uploadEvent?: string;
28
27
  private isMultiPart;
29
- private putResponse?;
28
+ private singleUploadResult?;
30
29
  constructor(options: Options);
31
30
  abort(): Promise<void>;
32
- done(): Promise<ServiceOutputTypes>;
33
- on(event: "httpUploadProgress", listener: (progress: Progress) => void): any;
34
- __uploadUsingPut(dataPart: RawDataPart): Promise<void>;
35
- __createMultipartUpload(): Promise<void>;
36
- __doConcurrentUpload(dataFeeder: AsyncGenerator<RawDataPart, void, undefined>): Promise<void>;
37
- __doMultipartUpload(): Promise<ServiceOutputTypes>;
38
- __notifyProgress(progress: Progress): void;
39
- __abortTimeout(abortSignal: AbortSignal): Promise<ServiceOutputTypes>;
40
- __validateInput(): void;
31
+ done(): Promise<CompleteMultipartUploadCommandOutput | AbortMultipartUploadCommandOutput>;
32
+ on(event: "httpUploadProgress", listener: (progress: Progress) => void): this;
33
+ private __uploadUsingPut;
34
+ private __createMultipartUpload;
35
+ private __doConcurrentUpload;
36
+ private __doMultipartUpload;
37
+ private __notifyProgress;
38
+ private __abortTimeout;
39
+ private __validateInput;
41
40
  }
@@ -7,6 +7,7 @@ export interface Progress {
7
7
  Bucket?: string;
8
8
  }
9
9
  export declare type BodyDataTypes = PutObjectCommandInput["Body"];
10
+
10
11
  export declare type ServiceClients = S3Client;
11
12
  export interface Configuration {
12
13
 
@@ -22,5 +23,5 @@ export interface Options extends Partial<Configuration> {
22
23
 
23
24
  params: PutObjectCommandInput;
24
25
 
25
- client: ServiceClients;
26
+ client: S3Client;
26
27
  }
@@ -7,6 +7,9 @@ export interface Progress {
7
7
  Bucket?: string;
8
8
  }
9
9
  export declare type BodyDataTypes = PutObjectCommandInput["Body"];
10
+ /**
11
+ * @deprecated redundant, use {@link S3Client} directly.
12
+ */
10
13
  export declare type ServiceClients = S3Client;
11
14
  export interface Configuration {
12
15
  /**
@@ -39,5 +42,5 @@ export interface Options extends Partial<Configuration> {
39
42
  * A service client.
40
43
  * This the target where we upload data.
41
44
  */
42
- client: ServiceClients;
45
+ client: S3Client;
43
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/lib-storage",
3
- "version": "3.85.0",
3
+ "version": "3.86.0",
4
4
  "description": "Storage higher order operation",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@aws-sdk/abort-controller": "3.78.0",
37
- "@aws-sdk/client-s3": "3.85.0",
37
+ "@aws-sdk/client-s3": "3.86.0",
38
38
  "@tsconfig/recommended": "1.0.1",
39
39
  "@types/node": "^14.11.2",
40
40
  "concurrently": "7.0.0",