Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clients): support util functions to consume response streams #3795

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 17 additions & 2 deletions clients/client-backupstorage/src/commands/GetChunkCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStream as __SdkStream,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand All @@ -25,7 +27,17 @@ import {
} from "../protocols/Aws_restJson1";

export interface GetChunkCommandInput extends GetChunkInput {}
export interface GetChunkCommandOutput extends GetChunkOutput, __MetadataBearer {}
type GetChunkCommandOutputType = __MetadataBearer &
Omit<GetChunkOutput, "Data"> & {
/**
* For *`GetChunkOutput["Data"]`*, see {@link GetChunkOutput.Data}.
*/
Data: __SdkStream<Required<GetChunkOutput>["Data"]>;
};
/**
* This interface extends from `GetChunkOutput` interface. There are more parameters than `Data` defined in {@link GetChunkOutput}
*/
export interface GetChunkCommandOutput extends GetChunkCommandOutputType {}

/**
* Gets the specified object's chunk.
Expand Down Expand Up @@ -92,7 +104,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,8 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStream as __SdkStream,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand All @@ -25,7 +27,17 @@ import {
} from "../protocols/Aws_restJson1";

export interface GetObjectMetadataCommandInput extends GetObjectMetadataInput {}
export interface GetObjectMetadataCommandOutput extends GetObjectMetadataOutput, __MetadataBearer {}
type GetObjectMetadataCommandOutputType = __MetadataBearer &
Omit<GetObjectMetadataOutput, "MetadataBlob"> & {
/**
* For *`GetObjectMetadataOutput["MetadataBlob"]`*, see {@link GetObjectMetadataOutput.MetadataBlob}.
*/
MetadataBlob?: __SdkStream<Required<GetObjectMetadataOutput>["MetadataBlob"]>;
};
/**
* This interface extends from `GetObjectMetadataOutput` interface. There are more parameters than `MetadataBlob` defined in {@link GetObjectMetadataOutput}
*/
export interface GetObjectMetadataCommandOutput extends GetObjectMetadataCommandOutputType {}

/**
* Get metadata associated with an Object.
Expand Down Expand Up @@ -92,7 +104,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
7 changes: 5 additions & 2 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 @@ -428,6 +429,7 @@ export const deserializeAws_restJson1GetChunkCommand = async (
ChecksumAlgorithm: [, output.headers["x-amz-checksum-algorithm"]],
});
const data: any = output.body;
context.sdkStreamMixin(data);
contents.Data = data;
return contents;
};
Expand Down Expand Up @@ -476,7 +478,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 @@ -492,6 +494,7 @@ export const deserializeAws_restJson1GetObjectMetadataCommand = async (
MetadataBlobChecksumAlgorithm: [, output.headers["x-amz-checksum-algorithm"]],
});
const data: any = output.body;
context.sdkStreamMixin(data);
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
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,8 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStream as __SdkStream,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand All @@ -25,7 +27,17 @@ import {
} from "../protocols/Aws_restJson1";

export interface GetPackageVersionAssetCommandInput extends GetPackageVersionAssetRequest {}
export interface GetPackageVersionAssetCommandOutput extends GetPackageVersionAssetResult, __MetadataBearer {}
type GetPackageVersionAssetCommandOutputType = __MetadataBearer &
Omit<GetPackageVersionAssetResult, "asset"> & {
/**
* For *`GetPackageVersionAssetResult["asset"]`*, see {@link GetPackageVersionAssetResult.asset}.
*/
asset?: __SdkStream<Required<GetPackageVersionAssetResult>["asset"]>;
};
/**
* This interface extends from `GetPackageVersionAssetResult` interface. There are more parameters than `asset` defined in {@link GetPackageVersionAssetResult}
*/
export interface GetPackageVersionAssetCommandOutput extends GetPackageVersionAssetCommandOutputType {}

/**
* <p>
Expand Down Expand Up @@ -96,7 +108,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
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 @@ -2200,6 +2201,7 @@ export const deserializeAws_restJson1GetPackageVersionAssetCommand = async (
packageVersionRevision: [, output.headers["x-packageversionrevision"]],
});
const data: any = output.body;
context.sdkStreamMixin(data);
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
19 changes: 17 additions & 2 deletions clients/client-ebs/src/commands/GetSnapshotBlockCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SdkStream as __SdkStream,
SdkStreamSerdeContext as __SdkStreamSerdeContext,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

Expand All @@ -25,7 +27,17 @@ import {
} from "../protocols/Aws_restJson1";

export interface GetSnapshotBlockCommandInput extends GetSnapshotBlockRequest {}
export interface GetSnapshotBlockCommandOutput extends GetSnapshotBlockResponse, __MetadataBearer {}
type GetSnapshotBlockCommandOutputType = __MetadataBearer &
Omit<GetSnapshotBlockResponse, "BlockData"> & {
/**
* For *`GetSnapshotBlockResponse["BlockData"]`*, see {@link GetSnapshotBlockResponse.BlockData}.
*/
BlockData?: __SdkStream<Required<GetSnapshotBlockResponse>["BlockData"]>;
};
/**
* This interface extends from `GetSnapshotBlockResponse` interface. There are more parameters than `BlockData` defined in {@link GetSnapshotBlockResponse}
*/
export interface GetSnapshotBlockCommandOutput extends GetSnapshotBlockCommandOutputType {}

/**
* <p>Returns the data in a block in an Amazon Elastic Block Store snapshot.</p>
Expand Down Expand Up @@ -92,7 +104,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