@cdk8s/awscdk-resolver 0.0.131 → 0.0.133

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.
Files changed (58) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +20 -20
  4. package/node_modules/@aws-sdk/client-sso/package.json +17 -17
  5. package/node_modules/@aws-sdk/client-sso-oidc/package.json +21 -21
  6. package/node_modules/@aws-sdk/client-sts/package.json +19 -19
  7. package/node_modules/@aws-sdk/core/package.json +3 -3
  8. package/node_modules/@aws-sdk/credential-provider-http/package.json +5 -5
  9. package/node_modules/@aws-sdk/credential-provider-ini/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  11. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  12. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  13. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  14. package/node_modules/@aws-sdk/region-config-resolver/package.json +2 -2
  15. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  16. package/node_modules/@aws-sdk/util-endpoints/package.json +2 -2
  17. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  18. package/node_modules/@smithy/core/package.json +4 -4
  19. package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
  20. package/node_modules/@smithy/middleware-content-length/package.json +3 -3
  21. package/node_modules/@smithy/middleware-retry/package.json +4 -4
  22. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  23. package/node_modules/@smithy/protocol-http/dist-cjs/index.js +30 -8
  24. package/node_modules/@smithy/protocol-http/dist-es/httpRequest.js +13 -8
  25. package/node_modules/@smithy/protocol-http/dist-types/httpRequest.d.ts +31 -1
  26. package/node_modules/@smithy/protocol-http/dist-types/ts3.4/httpRequest.d.ts +31 -1
  27. package/node_modules/@smithy/protocol-http/package.json +1 -1
  28. package/node_modules/@smithy/smithy-client/package.json +3 -3
  29. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  30. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  31. package/node_modules/@smithy/util-stream/dist-cjs/headStream.browser.js +36 -0
  32. package/node_modules/@smithy/util-stream/dist-cjs/headStream.js +46 -0
  33. package/node_modules/@smithy/util-stream/dist-cjs/index.js +7 -1
  34. package/node_modules/@smithy/util-stream/dist-cjs/sdk-stream-mixin.browser.js +3 -3
  35. package/node_modules/@smithy/util-stream/dist-cjs/splitStream.browser.js +11 -0
  36. package/node_modules/@smithy/util-stream/dist-cjs/splitStream.js +17 -0
  37. package/node_modules/@smithy/util-stream/dist-cjs/stream-type-check.js +9 -0
  38. package/node_modules/@smithy/util-stream/dist-es/headStream.browser.js +31 -0
  39. package/node_modules/@smithy/util-stream/dist-es/headStream.js +41 -0
  40. package/node_modules/@smithy/util-stream/dist-es/index.js +3 -0
  41. package/node_modules/@smithy/util-stream/dist-es/sdk-stream-mixin.browser.js +3 -3
  42. package/node_modules/@smithy/util-stream/dist-es/splitStream.browser.js +7 -0
  43. package/node_modules/@smithy/util-stream/dist-es/splitStream.js +13 -0
  44. package/node_modules/@smithy/util-stream/dist-es/stream-type-check.js +2 -0
  45. package/node_modules/@smithy/util-stream/dist-types/headStream.browser.d.ts +8 -0
  46. package/node_modules/@smithy/util-stream/dist-types/headStream.d.ts +9 -0
  47. package/node_modules/@smithy/util-stream/dist-types/index.d.ts +3 -0
  48. package/node_modules/@smithy/util-stream/dist-types/splitStream.browser.d.ts +5 -0
  49. package/node_modules/@smithy/util-stream/dist-types/splitStream.d.ts +8 -0
  50. package/node_modules/@smithy/util-stream/dist-types/stream-type-check.d.ts +4 -0
  51. package/node_modules/@smithy/util-stream/dist-types/ts3.4/headStream.browser.d.ts +8 -0
  52. package/node_modules/@smithy/util-stream/dist-types/ts3.4/headStream.d.ts +9 -0
  53. package/node_modules/@smithy/util-stream/dist-types/ts3.4/index.d.ts +3 -0
  54. package/node_modules/@smithy/util-stream/dist-types/ts3.4/splitStream.browser.d.ts +8 -0
  55. package/node_modules/@smithy/util-stream/dist-types/ts3.4/splitStream.d.ts +14 -0
  56. package/node_modules/@smithy/util-stream/dist-types/ts3.4/stream-type-check.d.ts +4 -0
  57. package/node_modules/@smithy/util-stream/package.json +12 -6
  58. package/package.json +6 -6
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/middleware-content-length",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline middleware-content-length",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
- "@smithy/protocol-http": "^4.0.3",
26
+ "@smithy/protocol-http": "^4.0.4",
27
27
  "@smithy/types": "^3.3.0",
28
28
  "tslib": "^2.6.2"
29
29
  },
@@ -47,7 +47,7 @@
47
47
  "directory": "packages/middleware-content-length"
48
48
  },
49
49
  "devDependencies": {
50
- "@smithy/util-test": "^0.2.4",
50
+ "@smithy/util-test": "^0.2.5",
51
51
  "concurrently": "7.0.0",
52
52
  "downlevel-dts": "0.10.1",
53
53
  "rimraf": "3.0.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/middleware-retry",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline middleware-retry",
@@ -32,9 +32,9 @@
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
34
  "@smithy/node-config-provider": "^3.1.4",
35
- "@smithy/protocol-http": "^4.0.3",
35
+ "@smithy/protocol-http": "^4.0.4",
36
36
  "@smithy/service-error-classification": "^3.0.3",
37
- "@smithy/smithy-client": "^3.1.7",
37
+ "@smithy/smithy-client": "^3.1.8",
38
38
  "@smithy/types": "^3.3.0",
39
39
  "@smithy/util-middleware": "^3.0.3",
40
40
  "@smithy/util-retry": "^3.0.3",
@@ -42,7 +42,7 @@
42
42
  "uuid": "^9.0.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@smithy/util-test": "^0.2.4",
45
+ "@smithy/util-test": "^0.2.5",
46
46
  "@types/uuid": "^8.3.0",
47
47
  "concurrently": "7.0.0",
48
48
  "downlevel-dts": "0.10.1",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/node-http-handler",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "Provides a way to make requests",
5
5
  "scripts": {
6
6
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
@@ -26,7 +26,7 @@
26
26
  "types": "./dist-types/index.d.ts",
27
27
  "dependencies": {
28
28
  "@smithy/abort-controller": "^3.1.1",
29
- "@smithy/protocol-http": "^4.0.3",
29
+ "@smithy/protocol-http": "^4.0.4",
30
30
  "@smithy/querystring-builder": "^3.0.3",
31
31
  "@smithy/types": "^3.3.0",
32
32
  "tslib": "^2.6.2"
@@ -24,6 +24,7 @@ __export(src_exports, {
24
24
  Fields: () => Fields,
25
25
  HttpRequest: () => HttpRequest,
26
26
  HttpResponse: () => HttpResponse,
27
+ IHttpRequest: () => import_types.HttpRequest,
27
28
  getHttpHandlerExtensionConfiguration: () => getHttpHandlerExtensionConfiguration,
28
29
  isValidHostname: () => isValidHostname,
29
30
  resolveHttpHandlerRuntimeConfig: () => resolveHttpHandlerRuntimeConfig
@@ -156,6 +157,7 @@ __name(_Fields, "Fields");
156
157
  var Fields = _Fields;
157
158
 
158
159
  // src/httpRequest.ts
160
+
159
161
  var _HttpRequest = class _HttpRequest {
160
162
  constructor(options) {
161
163
  this.method = options.method || "GET";
@@ -170,20 +172,40 @@ var _HttpRequest = class _HttpRequest {
170
172
  this.password = options.password;
171
173
  this.fragment = options.fragment;
172
174
  }
175
+ /**
176
+ * Note: this does not deep-clone the body.
177
+ */
178
+ static clone(request) {
179
+ const cloned = new _HttpRequest({
180
+ ...request,
181
+ headers: { ...request.headers }
182
+ });
183
+ if (cloned.query) {
184
+ cloned.query = cloneQuery(cloned.query);
185
+ }
186
+ return cloned;
187
+ }
188
+ /**
189
+ * This method only actually asserts that request is the interface {@link IHttpRequest},
190
+ * and not necessarily this concrete class. Left in place for API stability.
191
+ *
192
+ * Do not call instance methods on the input of this function, and
193
+ * do not assume it has the HttpRequest prototype.
194
+ */
173
195
  static isInstance(request) {
174
- if (!request)
196
+ if (!request) {
175
197
  return false;
198
+ }
176
199
  const req = request;
177
200
  return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
178
201
  }
202
+ /**
203
+ * @deprecated use static HttpRequest.clone(request) instead. It's not safe to call
204
+ * this method because {@link HttpRequest.isInstance} incorrectly
205
+ * asserts that IHttpRequest (interface) objects are of type HttpRequest (class).
206
+ */
179
207
  clone() {
180
- const cloned = new _HttpRequest({
181
- ...this,
182
- headers: { ...this.headers }
183
- });
184
- if (cloned.query)
185
- cloned.query = cloneQuery(cloned.query);
186
- return cloned;
208
+ return _HttpRequest.clone(this);
187
209
  }
188
210
  };
189
211
  __name(_HttpRequest, "HttpRequest");
@@ -16,9 +16,20 @@ export class HttpRequest {
16
16
  this.password = options.password;
17
17
  this.fragment = options.fragment;
18
18
  }
19
+ static clone(request) {
20
+ const cloned = new HttpRequest({
21
+ ...request,
22
+ headers: { ...request.headers },
23
+ });
24
+ if (cloned.query) {
25
+ cloned.query = cloneQuery(cloned.query);
26
+ }
27
+ return cloned;
28
+ }
19
29
  static isInstance(request) {
20
- if (!request)
30
+ if (!request) {
21
31
  return false;
32
+ }
22
33
  const req = request;
23
34
  return ("method" in req &&
24
35
  "protocol" in req &&
@@ -28,13 +39,7 @@ export class HttpRequest {
28
39
  typeof req["headers"] === "object");
29
40
  }
30
41
  clone() {
31
- const cloned = new HttpRequest({
32
- ...this,
33
- headers: { ...this.headers },
34
- });
35
- if (cloned.query)
36
- cloned.query = cloneQuery(cloned.query);
37
- return cloned;
42
+ return HttpRequest.clone(this);
38
43
  }
39
44
  }
40
45
  function cloneQuery(query) {
@@ -2,8 +2,23 @@ import { HeaderBag, HttpMessage, HttpRequest as IHttpRequest, QueryParameterBag,
2
2
  type HttpRequestOptions = Partial<HttpMessage> & Partial<URI> & {
3
3
  method?: string;
4
4
  };
5
+ /**
6
+ * Use the distinct IHttpRequest interface from @smithy/types instead.
7
+ * This should not be used due to
8
+ * overlapping with the concrete class' name.
9
+ *
10
+ * This is not marked deprecated since that would mark the concrete class
11
+ * deprecated as well.
12
+ */
5
13
  export interface HttpRequest extends IHttpRequest {
6
14
  }
15
+ /**
16
+ * @public
17
+ */
18
+ export { IHttpRequest };
19
+ /**
20
+ * @public
21
+ */
7
22
  export declare class HttpRequest implements HttpMessage, URI {
8
23
  method: string;
9
24
  protocol: string;
@@ -17,7 +32,22 @@ export declare class HttpRequest implements HttpMessage, URI {
17
32
  fragment?: string;
18
33
  body?: any;
19
34
  constructor(options: HttpRequestOptions);
35
+ /**
36
+ * Note: this does not deep-clone the body.
37
+ */
38
+ static clone(request: IHttpRequest): HttpRequest;
39
+ /**
40
+ * This method only actually asserts that request is the interface {@link IHttpRequest},
41
+ * and not necessarily this concrete class. Left in place for API stability.
42
+ *
43
+ * Do not call instance methods on the input of this function, and
44
+ * do not assume it has the HttpRequest prototype.
45
+ */
20
46
  static isInstance(request: unknown): request is HttpRequest;
47
+ /**
48
+ * @deprecated use static HttpRequest.clone(request) instead. It's not safe to call
49
+ * this method because {@link HttpRequest.isInstance} incorrectly
50
+ * asserts that IHttpRequest (interface) objects are of type HttpRequest (class).
51
+ */
21
52
  clone(): HttpRequest;
22
53
  }
23
- export {};
@@ -2,8 +2,23 @@ import { HeaderBag, HttpMessage, HttpRequest as IHttpRequest, QueryParameterBag,
2
2
  type HttpRequestOptions = Partial<HttpMessage> & Partial<URI> & {
3
3
  method?: string;
4
4
  };
5
+ /**
6
+ * Use the distinct IHttpRequest interface from @smithy/types instead.
7
+ * This should not be used due to
8
+ * overlapping with the concrete class' name.
9
+ *
10
+ * This is not marked deprecated since that would mark the concrete class
11
+ * deprecated as well.
12
+ */
5
13
  export interface HttpRequest extends IHttpRequest {
6
14
  }
15
+ /**
16
+ * @public
17
+ */
18
+ export { IHttpRequest };
19
+ /**
20
+ * @public
21
+ */
7
22
  export declare class HttpRequest implements HttpMessage, URI {
8
23
  method: string;
9
24
  protocol: string;
@@ -17,7 +32,22 @@ export declare class HttpRequest implements HttpMessage, URI {
17
32
  fragment?: string;
18
33
  body?: any;
19
34
  constructor(options: HttpRequestOptions);
35
+ /**
36
+ * Note: this does not deep-clone the body.
37
+ */
38
+ static clone(request: IHttpRequest): HttpRequest;
39
+ /**
40
+ * This method only actually asserts that request is the interface {@link IHttpRequest},
41
+ * and not necessarily this concrete class. Left in place for API stability.
42
+ *
43
+ * Do not call instance methods on the input of this function, and
44
+ * do not assume it has the HttpRequest prototype.
45
+ */
20
46
  static isInstance(request: unknown): request is HttpRequest;
47
+ /**
48
+ * @deprecated use static HttpRequest.clone(request) instead. It's not safe to call
49
+ * this method because {@link HttpRequest.isInstance} incorrectly
50
+ * asserts that IHttpRequest (interface) objects are of type HttpRequest (class).
51
+ */
21
52
  clone(): HttpRequest;
22
53
  }
23
- export {};
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/protocol-http",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline protocol-http",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/smithy-client",
3
- "version": "3.1.7",
3
+ "version": "3.1.8",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline smithy-client",
@@ -25,9 +25,9 @@
25
25
  "dependencies": {
26
26
  "@smithy/middleware-endpoint": "^3.0.5",
27
27
  "@smithy/middleware-stack": "^3.0.3",
28
- "@smithy/protocol-http": "^4.0.3",
28
+ "@smithy/protocol-http": "^4.0.4",
29
29
  "@smithy/types": "^3.3.0",
30
- "@smithy/util-stream": "^3.0.6",
30
+ "@smithy/util-stream": "^3.1.0",
31
31
  "tslib": "^2.6.2"
32
32
  },
33
33
  "engines": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/util-defaults-mode-browser",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline util-defaults-mode-browser",
@@ -23,7 +23,7 @@
23
23
  "license": "Apache-2.0",
24
24
  "dependencies": {
25
25
  "@smithy/property-provider": "^3.1.3",
26
- "@smithy/smithy-client": "^3.1.7",
26
+ "@smithy/smithy-client": "^3.1.8",
27
27
  "@smithy/types": "^3.3.0",
28
28
  "bowser": "^2.11.0",
29
29
  "tslib": "^2.6.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/util-defaults-mode-node",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline util-defaults-mode-node",
@@ -26,7 +26,7 @@
26
26
  "@smithy/credential-provider-imds": "^3.1.4",
27
27
  "@smithy/node-config-provider": "^3.1.4",
28
28
  "@smithy/property-provider": "^3.1.3",
29
- "@smithy/smithy-client": "^3.1.7",
29
+ "@smithy/smithy-client": "^3.1.8",
30
30
  "@smithy/types": "^3.3.0",
31
31
  "tslib": "^2.6.2"
32
32
  },
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.headStream = void 0;
4
+ async function headStream(stream, bytes) {
5
+ var _a;
6
+ let byteLengthCounter = 0;
7
+ const chunks = [];
8
+ const reader = stream.getReader();
9
+ let isDone = false;
10
+ while (!isDone) {
11
+ const { done, value } = await reader.read();
12
+ if (value) {
13
+ chunks.push(value);
14
+ byteLengthCounter += (_a = value === null || value === void 0 ? void 0 : value.byteLength) !== null && _a !== void 0 ? _a : 0;
15
+ }
16
+ if (byteLengthCounter >= bytes) {
17
+ break;
18
+ }
19
+ isDone = done;
20
+ }
21
+ reader.releaseLock();
22
+ const collected = new Uint8Array(Math.min(bytes, byteLengthCounter));
23
+ let offset = 0;
24
+ for (const chunk of chunks) {
25
+ if (chunk.byteLength > collected.byteLength - offset) {
26
+ collected.set(chunk.subarray(0, collected.byteLength - offset), offset);
27
+ break;
28
+ }
29
+ else {
30
+ collected.set(chunk, offset);
31
+ }
32
+ offset += chunk.length;
33
+ }
34
+ return collected;
35
+ }
36
+ exports.headStream = headStream;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.headStream = void 0;
4
+ const stream_1 = require("stream");
5
+ const headStream_browser_1 = require("./headStream.browser");
6
+ const stream_type_check_1 = require("./stream-type-check");
7
+ const headStream = (stream, bytes) => {
8
+ if ((0, stream_type_check_1.isReadableStream)(stream)) {
9
+ return (0, headStream_browser_1.headStream)(stream, bytes);
10
+ }
11
+ return new Promise((resolve, reject) => {
12
+ const collector = new Collector();
13
+ collector.limit = bytes;
14
+ stream.pipe(collector);
15
+ stream.on("error", (err) => {
16
+ collector.end();
17
+ reject(err);
18
+ });
19
+ collector.on("error", reject);
20
+ collector.on("finish", function () {
21
+ const bytes = new Uint8Array(Buffer.concat(this.buffers));
22
+ resolve(bytes);
23
+ });
24
+ });
25
+ };
26
+ exports.headStream = headStream;
27
+ class Collector extends stream_1.Writable {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.buffers = [];
31
+ this.limit = Infinity;
32
+ this.bytesBuffered = 0;
33
+ }
34
+ _write(chunk, encoding, callback) {
35
+ var _a;
36
+ this.buffers.push(chunk);
37
+ this.bytesBuffered += (_a = chunk.byteLength) !== null && _a !== void 0 ? _a : 0;
38
+ if (this.bytesBuffered >= this.limit) {
39
+ const excess = this.bytesBuffered - this.limit;
40
+ const tailBuffer = this.buffers[this.buffers.length - 1];
41
+ this.buffers[this.buffers.length - 1] = tailBuffer.subarray(0, tailBuffer.byteLength - excess);
42
+ this.emit("finish");
43
+ }
44
+ callback();
45
+ }
46
+ }
@@ -79,11 +79,17 @@ var Uint8ArrayBlobAdapter = _Uint8ArrayBlobAdapter;
79
79
  // src/index.ts
80
80
  __reExport(src_exports, require("././getAwsChunkedEncodingStream"), module.exports);
81
81
  __reExport(src_exports, require("././sdk-stream-mixin"), module.exports);
82
+ __reExport(src_exports, require("././splitStream"), module.exports);
83
+ __reExport(src_exports, require("././headStream"), module.exports);
84
+ __reExport(src_exports, require("././stream-type-check"), module.exports);
82
85
  // Annotate the CommonJS export names for ESM import in node:
83
86
 
84
87
  0 && (module.exports = {
85
88
  Uint8ArrayBlobAdapter,
86
89
  getAwsChunkedEncodingStream,
87
- sdkStreamMixin
90
+ sdkStreamMixin,
91
+ splitStream,
92
+ headStream,
93
+ isReadableStream
88
94
  });
89
95
 
@@ -5,10 +5,11 @@ const fetch_http_handler_1 = require("@smithy/fetch-http-handler");
5
5
  const util_base64_1 = require("@smithy/util-base64");
6
6
  const util_hex_encoding_1 = require("@smithy/util-hex-encoding");
7
7
  const util_utf8_1 = require("@smithy/util-utf8");
8
+ const stream_type_check_1 = require("./stream-type-check");
8
9
  const ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed.";
9
10
  const sdkStreamMixin = (stream) => {
10
11
  var _a, _b;
11
- if (!isBlobInstance(stream) && !isReadableStreamInstance(stream)) {
12
+ if (!isBlobInstance(stream) && !(0, stream_type_check_1.isReadableStream)(stream)) {
12
13
  const name = ((_b = (_a = stream === null || stream === void 0 ? void 0 : stream.__proto__) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) || stream;
13
14
  throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${name}`);
14
15
  }
@@ -55,7 +56,7 @@ const sdkStreamMixin = (stream) => {
55
56
  if (isBlobInstance(stream)) {
56
57
  return blobToWebStream(stream);
57
58
  }
58
- else if (isReadableStreamInstance(stream)) {
59
+ else if ((0, stream_type_check_1.isReadableStream)(stream)) {
59
60
  return stream;
60
61
  }
61
62
  else {
@@ -66,4 +67,3 @@ const sdkStreamMixin = (stream) => {
66
67
  };
67
68
  exports.sdkStreamMixin = sdkStreamMixin;
68
69
  const isBlobInstance = (stream) => typeof Blob === "function" && stream instanceof Blob;
69
- const isReadableStreamInstance = (stream) => typeof ReadableStream === "function" && stream instanceof ReadableStream;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitStream = void 0;
4
+ async function splitStream(stream) {
5
+ if (typeof stream.stream === "function") {
6
+ stream = stream.stream();
7
+ }
8
+ const readableStream = stream;
9
+ return readableStream.tee();
10
+ }
11
+ exports.splitStream = splitStream;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.splitStream = void 0;
4
+ const stream_1 = require("stream");
5
+ const splitStream_browser_1 = require("./splitStream.browser");
6
+ const stream_type_check_1 = require("./stream-type-check");
7
+ async function splitStream(stream) {
8
+ if ((0, stream_type_check_1.isReadableStream)(stream)) {
9
+ return (0, splitStream_browser_1.splitStream)(stream);
10
+ }
11
+ const stream1 = new stream_1.PassThrough();
12
+ const stream2 = new stream_1.PassThrough();
13
+ stream.pipe(stream1);
14
+ stream.pipe(stream2);
15
+ return [stream1, stream2];
16
+ }
17
+ exports.splitStream = splitStream;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isReadableStream = void 0;
4
+ const isReadableStream = (stream) => {
5
+ var _a;
6
+ return typeof ReadableStream === "function" &&
7
+ (((_a = stream === null || stream === void 0 ? void 0 : stream.constructor) === null || _a === void 0 ? void 0 : _a.name) === ReadableStream.name || stream instanceof ReadableStream);
8
+ };
9
+ exports.isReadableStream = isReadableStream;
@@ -0,0 +1,31 @@
1
+ export async function headStream(stream, bytes) {
2
+ let byteLengthCounter = 0;
3
+ const chunks = [];
4
+ const reader = stream.getReader();
5
+ let isDone = false;
6
+ while (!isDone) {
7
+ const { done, value } = await reader.read();
8
+ if (value) {
9
+ chunks.push(value);
10
+ byteLengthCounter += value?.byteLength ?? 0;
11
+ }
12
+ if (byteLengthCounter >= bytes) {
13
+ break;
14
+ }
15
+ isDone = done;
16
+ }
17
+ reader.releaseLock();
18
+ const collected = new Uint8Array(Math.min(bytes, byteLengthCounter));
19
+ let offset = 0;
20
+ for (const chunk of chunks) {
21
+ if (chunk.byteLength > collected.byteLength - offset) {
22
+ collected.set(chunk.subarray(0, collected.byteLength - offset), offset);
23
+ break;
24
+ }
25
+ else {
26
+ collected.set(chunk, offset);
27
+ }
28
+ offset += chunk.length;
29
+ }
30
+ return collected;
31
+ }
@@ -0,0 +1,41 @@
1
+ import { Writable } from "stream";
2
+ import { headStream as headWebStream } from "./headStream.browser";
3
+ import { isReadableStream } from "./stream-type-check";
4
+ export const headStream = (stream, bytes) => {
5
+ if (isReadableStream(stream)) {
6
+ return headWebStream(stream, bytes);
7
+ }
8
+ return new Promise((resolve, reject) => {
9
+ const collector = new Collector();
10
+ collector.limit = bytes;
11
+ stream.pipe(collector);
12
+ stream.on("error", (err) => {
13
+ collector.end();
14
+ reject(err);
15
+ });
16
+ collector.on("error", reject);
17
+ collector.on("finish", function () {
18
+ const bytes = new Uint8Array(Buffer.concat(this.buffers));
19
+ resolve(bytes);
20
+ });
21
+ });
22
+ };
23
+ class Collector extends Writable {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.buffers = [];
27
+ this.limit = Infinity;
28
+ this.bytesBuffered = 0;
29
+ }
30
+ _write(chunk, encoding, callback) {
31
+ this.buffers.push(chunk);
32
+ this.bytesBuffered += chunk.byteLength ?? 0;
33
+ if (this.bytesBuffered >= this.limit) {
34
+ const excess = this.bytesBuffered - this.limit;
35
+ const tailBuffer = this.buffers[this.buffers.length - 1];
36
+ this.buffers[this.buffers.length - 1] = tailBuffer.subarray(0, tailBuffer.byteLength - excess);
37
+ this.emit("finish");
38
+ }
39
+ callback();
40
+ }
41
+ }
@@ -1,3 +1,6 @@
1
1
  export * from "./blob/Uint8ArrayBlobAdapter";
2
2
  export * from "./getAwsChunkedEncodingStream";
3
3
  export * from "./sdk-stream-mixin";
4
+ export * from "./splitStream";
5
+ export * from "./headStream";
6
+ export * from "./stream-type-check";
@@ -2,9 +2,10 @@ import { streamCollector } from "@smithy/fetch-http-handler";
2
2
  import { toBase64 } from "@smithy/util-base64";
3
3
  import { toHex } from "@smithy/util-hex-encoding";
4
4
  import { toUtf8 } from "@smithy/util-utf8";
5
+ import { isReadableStream } from "./stream-type-check";
5
6
  const ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed.";
6
7
  export const sdkStreamMixin = (stream) => {
7
- if (!isBlobInstance(stream) && !isReadableStreamInstance(stream)) {
8
+ if (!isBlobInstance(stream) && !isReadableStream(stream)) {
8
9
  const name = stream?.__proto__?.constructor?.name || stream;
9
10
  throw new Error(`Unexpected stream implementation, expect Blob or ReadableStream, got ${name}`);
10
11
  }
@@ -51,7 +52,7 @@ export const sdkStreamMixin = (stream) => {
51
52
  if (isBlobInstance(stream)) {
52
53
  return blobToWebStream(stream);
53
54
  }
54
- else if (isReadableStreamInstance(stream)) {
55
+ else if (isReadableStream(stream)) {
55
56
  return stream;
56
57
  }
57
58
  else {
@@ -61,4 +62,3 @@ export const sdkStreamMixin = (stream) => {
61
62
  });
62
63
  };
63
64
  const isBlobInstance = (stream) => typeof Blob === "function" && stream instanceof Blob;
64
- const isReadableStreamInstance = (stream) => typeof ReadableStream === "function" && stream instanceof ReadableStream;
@@ -0,0 +1,7 @@
1
+ export async function splitStream(stream) {
2
+ if (typeof stream.stream === "function") {
3
+ stream = stream.stream();
4
+ }
5
+ const readableStream = stream;
6
+ return readableStream.tee();
7
+ }
@@ -0,0 +1,13 @@
1
+ import { PassThrough } from "stream";
2
+ import { splitStream as splitWebStream } from "./splitStream.browser";
3
+ import { isReadableStream } from "./stream-type-check";
4
+ export async function splitStream(stream) {
5
+ if (isReadableStream(stream)) {
6
+ return splitWebStream(stream);
7
+ }
8
+ const stream1 = new PassThrough();
9
+ const stream2 = new PassThrough();
10
+ stream.pipe(stream1);
11
+ stream.pipe(stream2);
12
+ return [stream1, stream2];
13
+ }
@@ -0,0 +1,2 @@
1
+ export const isReadableStream = (stream) => typeof ReadableStream === "function" &&
2
+ (stream?.constructor?.name === ReadableStream.name || stream instanceof ReadableStream);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @internal
3
+ * @param stream
4
+ * @param bytes - read head bytes from the stream and discard the rest of it.
5
+ *
6
+ * Caution: the input stream must be destroyed separately, this function does not do so.
7
+ */
8
+ export declare function headStream(stream: ReadableStream, bytes: number): Promise<Uint8Array>;