Skip to content

Commit

Permalink
feat(clients): support util functions to consume response streams
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Aug 29, 2022
1 parent 15f00e6 commit 1340185
Show file tree
Hide file tree
Showing 115 changed files with 409 additions and 107 deletions.
2 changes: 2 additions & 0 deletions clients/client-backupstorage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"@aws-sdk/util-body-length-node": "*",
"@aws-sdk/util-defaults-mode-browser": "*",
"@aws-sdk/util-defaults-mode-node": "*",
"@aws-sdk/util-stream-browser": "*",
"@aws-sdk/util-stream-node": "*",
"@aws-sdk/util-user-agent-browser": "*",
"@aws-sdk/util-user-agent-node": "*",
"@aws-sdk/util-utf8-browser": "*",
Expand Down
7 changes: 7 additions & 0 deletions clients/client-backupstorage/src/BackupStorageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
Provider as __Provider,
Provider,
RegionInfoProvider,
SdkStreamMixinInjector as __SdkStreamMixinInjector,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
Expand Down Expand Up @@ -214,6 +215,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* The {@link DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
*/
defaultsMode?: DefaultsMode | Provider<DefaultsMode>;

/**
* The internal function that inject utilities to runtime-specific stream to help users consume the data
* @internal
*/
sdkStreamMixin?: __SdkStreamMixinInjector;
}

type BackupStorageClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand Down
6 changes: 5 additions & 1 deletion clients/client-backupstorage/src/commands/GetChunkCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -92,7 +93,10 @@ export class GetChunkCommand extends $Command<
return serializeAws_restJson1GetChunkCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetChunkCommandOutput> {
private deserialize(
output: __HttpResponse,
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetChunkCommandOutput> {
return deserializeAws_restJson1GetChunkCommand(output, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -92,7 +93,10 @@ export class GetObjectMetadataCommand extends $Command<
return serializeAws_restJson1GetObjectMetadataCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetObjectMetadataCommandOutput> {
private deserialize(
output: __HttpResponse,
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetObjectMetadataCommandOutput> {
return deserializeAws_restJson1GetObjectMetadataCommand(output, context);
}

Expand Down
11 changes: 6 additions & 5 deletions clients/client-backupstorage/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType } from "@aws-sdk/smithy-client";
import { SdkStream } from "@aws-sdk/types";
import { Readable } from "stream";

import { BackupStorageServiceException as __BaseException } from "./BackupStorageServiceException";
Expand Down Expand Up @@ -250,7 +251,7 @@ export interface GetChunkOutput {
/**
* Chunk data
*/
Data: Readable | ReadableStream | Blob | undefined;
Data: SdkStream<Readable | ReadableStream | Blob> | undefined;

/**
* Data length
Expand Down Expand Up @@ -310,7 +311,7 @@ export interface GetObjectMetadataOutput {
/**
* Metadata blob.
*/
MetadataBlob?: Readable | ReadableStream | Blob;
MetadataBlob?: SdkStream<Readable | ReadableStream | Blob>;

/**
* The size of MetadataBlob.
Expand Down Expand Up @@ -440,7 +441,7 @@ export interface NotifyObjectCompleteInput {
/**
* Optional metadata associated with an Object. Maximum length is 4MB.
*/
MetadataBlob?: Readable | ReadableStream | Blob;
MetadataBlob?: SdkStream<Readable | ReadableStream | Blob>;

/**
* The size of MetadataBlob.
Expand Down Expand Up @@ -510,7 +511,7 @@ export interface PutChunkInput {
/**
* Data to be uploaded
*/
Data: Readable | ReadableStream | Blob | undefined;
Data: SdkStream<Readable | ReadableStream | Blob> | undefined;

/**
* Data length
Expand Down Expand Up @@ -559,7 +560,7 @@ export interface PutObjectInput {
/**
* Inline chunk data to be uploaded.
*/
InlineChunk?: Readable | ReadableStream | Blob;
InlineChunk?: SdkStream<Readable | ReadableStream | Blob>;

/**
* Length of the inline chunk data.
Expand Down
9 changes: 5 additions & 4 deletions clients/client-backupstorage/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
Endpoint as __Endpoint,
ResponseMetadata as __ResponseMetadata,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -413,7 +414,7 @@ const deserializeAws_restJson1DeleteObjectCommandError = async (

export const deserializeAws_restJson1GetChunkCommand = async (
output: __HttpResponse,
context: __SerdeContext
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetChunkCommandOutput> => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetChunkCommandError(output, context);
Expand All @@ -427,7 +428,7 @@ export const deserializeAws_restJson1GetChunkCommand = async (
Checksum: [, output.headers["x-amz-checksum"]],
ChecksumAlgorithm: [, output.headers["x-amz-checksum-algorithm"]],
});
const data: any = output.body;
const data: any = context.sdkStreamMixin(output.body);
contents.Data = data;
return contents;
};
Expand Down Expand Up @@ -476,7 +477,7 @@ const deserializeAws_restJson1GetChunkCommandError = async (

export const deserializeAws_restJson1GetObjectMetadataCommand = async (
output: __HttpResponse,
context: __SerdeContext
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetObjectMetadataCommandOutput> => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetObjectMetadataCommandError(output, context);
Expand All @@ -491,7 +492,7 @@ export const deserializeAws_restJson1GetObjectMetadataCommand = async (
MetadataBlobChecksum: [, output.headers["x-amz-checksum"]],
MetadataBlobChecksumAlgorithm: [, output.headers["x-amz-checksum-algorithm"]],
});
const data: any = output.body;
const data: any = context.sdkStreamMixin(output.body);
contents.MetadataBlob = data;
return contents;
};
Expand Down
2 changes: 2 additions & 0 deletions clients/client-backupstorage/src/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { sdkStreamMixin } from "@aws-sdk/util-stream-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser";
import { BackupStorageClientConfig } from "./BackupStorageClient";
Expand Down Expand Up @@ -40,6 +41,7 @@ export const getRuntimeConfig = (config: BackupStorageClientConfig) => {
region: config?.region ?? invalidProvider("Region is missing"),
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE),
sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
sha256: config?.sha256 ?? Sha256,
streamCollector: config?.streamCollector ?? streamCollector,
useDualstackEndpoint: config?.useDualstackEndpoint ?? (() => Promise.resolve(DEFAULT_USE_DUALSTACK_ENDPOINT)),
Expand Down
2 changes: 2 additions & 0 deletions clients/client-backupstorage/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler as RequestHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { sdkStreamMixin } from "@aws-sdk/util-stream-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
import { BackupStorageClientConfig } from "./BackupStorageClient";
Expand Down Expand Up @@ -58,6 +59,7 @@ export const getRuntimeConfig = (config: BackupStorageClientConfig) => {
...NODE_RETRY_MODE_CONFIG_OPTIONS,
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
}),
sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config?.streamCollector ?? streamCollector,
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
Expand Down
3 changes: 2 additions & 1 deletion clients/client-cloudsearch-domain/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType } from "@aws-sdk/smithy-client";
import { SdkStream } from "@aws-sdk/types";
import { Readable } from "stream";

import { CloudSearchDomainServiceException as __BaseException } from "./CloudSearchDomainServiceException";
Expand Down Expand Up @@ -598,7 +599,7 @@ export interface UploadDocumentsRequest {
/**
* <p>A batch of documents formatted in JSON or HTML.</p>
*/
documents: Readable | ReadableStream | Blob | undefined;
documents: SdkStream<Readable | ReadableStream | Blob> | undefined;

/**
* <p>The format of the batch you are uploading. Amazon CloudSearch supports two document batch formats:</p>
Expand Down
2 changes: 2 additions & 0 deletions clients/client-codeartifact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"@aws-sdk/util-body-length-node": "*",
"@aws-sdk/util-defaults-mode-browser": "*",
"@aws-sdk/util-defaults-mode-node": "*",
"@aws-sdk/util-stream-browser": "*",
"@aws-sdk/util-stream-node": "*",
"@aws-sdk/util-user-agent-browser": "*",
"@aws-sdk/util-user-agent-node": "*",
"@aws-sdk/util-utf8-browser": "*",
Expand Down
7 changes: 7 additions & 0 deletions clients/client-codeartifact/src/CodeartifactClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
Provider as __Provider,
Provider,
RegionInfoProvider,
SdkStreamMixinInjector as __SdkStreamMixinInjector,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
Expand Down Expand Up @@ -361,6 +362,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* The {@link DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
*/
defaultsMode?: DefaultsMode | Provider<DefaultsMode>;

/**
* The internal function that inject utilities to runtime-specific stream to help users consume the data
* @internal
*/
sdkStreamMixin?: __SdkStreamMixinInjector;
}

type CodeartifactClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -96,7 +97,10 @@ export class GetPackageVersionAssetCommand extends $Command<
return serializeAws_restJson1GetPackageVersionAssetCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetPackageVersionAssetCommandOutput> {
private deserialize(
output: __HttpResponse,
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetPackageVersionAssetCommandOutput> {
return deserializeAws_restJson1GetPackageVersionAssetCommand(output, context);
}

Expand Down
3 changes: 2 additions & 1 deletion clients/client-codeartifact/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType } from "@aws-sdk/smithy-client";
import { SdkStream } from "@aws-sdk/types";
import { Readable } from "stream";

import { CodeartifactServiceException as __BaseException } from "./CodeartifactServiceException";
Expand Down Expand Up @@ -1978,7 +1979,7 @@ export interface GetPackageVersionAssetResult {
/**
* <p> The binary file, or asset, that is downloaded.</p>
*/
asset?: Readable | ReadableStream | Blob;
asset?: SdkStream<Readable | ReadableStream | Blob>;

/**
* <p>
Expand Down
5 changes: 3 additions & 2 deletions clients/client-codeartifact/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import {
Endpoint as __Endpoint,
ResponseMetadata as __ResponseMetadata,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -2188,7 +2189,7 @@ const deserializeAws_restJson1GetDomainPermissionsPolicyCommandError = async (

export const deserializeAws_restJson1GetPackageVersionAssetCommand = async (
output: __HttpResponse,
context: __SerdeContext
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetPackageVersionAssetCommandOutput> => {
if (output.statusCode !== 200 && output.statusCode >= 300) {
return deserializeAws_restJson1GetPackageVersionAssetCommandError(output, context);
Expand All @@ -2199,7 +2200,7 @@ export const deserializeAws_restJson1GetPackageVersionAssetCommand = async (
packageVersion: [, output.headers["x-packageversion"]],
packageVersionRevision: [, output.headers["x-packageversionrevision"]],
});
const data: any = output.body;
const data: any = context.sdkStreamMixin(output.body);
contents.asset = data;
return contents;
};
Expand Down
2 changes: 2 additions & 0 deletions clients/client-codeartifact/src/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { sdkStreamMixin } from "@aws-sdk/util-stream-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-browser";
import { CodeartifactClientConfig } from "./CodeartifactClient";
Expand Down Expand Up @@ -40,6 +41,7 @@ export const getRuntimeConfig = (config: CodeartifactClientConfig) => {
region: config?.region ?? invalidProvider("Region is missing"),
requestHandler: config?.requestHandler ?? new RequestHandler(defaultConfigProvider),
retryMode: config?.retryMode ?? (async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE),
sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
sha256: config?.sha256 ?? Sha256,
streamCollector: config?.streamCollector ?? streamCollector,
useDualstackEndpoint: config?.useDualstackEndpoint ?? (() => Promise.resolve(DEFAULT_USE_DUALSTACK_ENDPOINT)),
Expand Down
2 changes: 2 additions & 0 deletions clients/client-codeartifact/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler as RequestHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { sdkStreamMixin } from "@aws-sdk/util-stream-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { fromUtf8, toUtf8 } from "@aws-sdk/util-utf8-node";
import { CodeartifactClientConfig } from "./CodeartifactClient";
Expand Down Expand Up @@ -58,6 +59,7 @@ export const getRuntimeConfig = (config: CodeartifactClientConfig) => {
...NODE_RETRY_MODE_CONFIG_OPTIONS,
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
}),
sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config?.streamCollector ?? streamCollector,
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
Expand Down
2 changes: 2 additions & 0 deletions clients/client-ebs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"@aws-sdk/util-body-length-node": "*",
"@aws-sdk/util-defaults-mode-browser": "*",
"@aws-sdk/util-defaults-mode-node": "*",
"@aws-sdk/util-stream-browser": "*",
"@aws-sdk/util-stream-node": "*",
"@aws-sdk/util-user-agent-browser": "*",
"@aws-sdk/util-user-agent-node": "*",
"@aws-sdk/util-utf8-browser": "*",
Expand Down
7 changes: 7 additions & 0 deletions clients/client-ebs/src/EBSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
Provider as __Provider,
Provider,
RegionInfoProvider,
SdkStreamMixinInjector as __SdkStreamMixinInjector,
StreamCollector as __StreamCollector,
UrlParser as __UrlParser,
UserAgent as __UserAgent,
Expand Down Expand Up @@ -202,6 +203,12 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__
* The {@link DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
*/
defaultsMode?: DefaultsMode | Provider<DefaultsMode>;

/**
* The internal function that inject utilities to runtime-specific stream to help users consume the data
* @internal
*/
sdkStreamMixin?: __SdkStreamMixinInjector;
}

type EBSClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions>> &
Expand Down
6 changes: 5 additions & 1 deletion clients/client-ebs/src/commands/GetSnapshotBlockCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -92,7 +93,10 @@ export class GetSnapshotBlockCommand extends $Command<
return serializeAws_restJson1GetSnapshotBlockCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<GetSnapshotBlockCommandOutput> {
private deserialize(
output: __HttpResponse,
context: __SerdeContext & __SdkStreamSerdeContext
): Promise<GetSnapshotBlockCommandOutput> {
return deserializeAws_restJson1GetSnapshotBlockCommand(output, context);
}

Expand Down
Loading

0 comments on commit 1340185

Please sign in to comment.