From e0751b49d5a07b4504283a6a34f9706789e446fc Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Mon, 10 Jul 2023 14:56:51 -0600 Subject: [PATCH] chore(packages): re-export types from @smithy/types (#4900) --- packages/types/package.json | 1 + packages/types/src/abort.ts | 54 +- packages/types/src/auth.ts | 62 +- packages/types/src/checksum.ts | 71 +-- packages/types/src/client.ts | 38 +- packages/types/src/command.ts | 22 +- packages/types/src/connection.ts | 1 + packages/types/src/connection/config.ts | 7 - packages/types/src/connection/index.ts | 3 - packages/types/src/connection/manager.ts | 33 - packages/types/src/connection/pool.ts | 28 - packages/types/src/crypto.ts | 66 +- packages/types/src/encode.ts | 25 +- packages/types/src/endpoint.ts | 97 +-- packages/types/src/eventStream.ts | 160 +---- packages/types/src/http.ts | 105 +--- .../src/identity/AwsCredentialIdentity.ts | 28 +- packages/types/src/identity/Identity.ts | 17 +- packages/types/src/logger.ts | 17 +- packages/types/src/middleware.ts | 582 ++---------------- packages/types/src/pagination.ts | 29 +- packages/types/src/profile.ts | 25 +- packages/types/src/response.ts | 47 +- packages/types/src/retry.ts | 159 +---- packages/types/src/serde.ts | 129 +--- packages/types/src/shapes.ts | 79 +-- packages/types/src/signature.ts | 183 +----- packages/types/src/stream.ts | 25 +- packages/types/src/transfer.ts | 44 +- packages/types/src/uri.ts | 19 +- packages/types/src/util.ts | 182 +----- packages/types/src/waiter.ts | 42 +- 32 files changed, 164 insertions(+), 2216 deletions(-) create mode 100644 packages/types/src/connection.ts delete mode 100644 packages/types/src/connection/config.ts delete mode 100644 packages/types/src/connection/index.ts delete mode 100644 packages/types/src/connection/manager.ts delete mode 100644 packages/types/src/connection/pool.ts diff --git a/packages/types/package.json b/packages/types/package.json index 7aa0b2a3894b..b368457b84ec 100755 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -41,6 +41,7 @@ "directory": "packages/types" }, "dependencies": { + "@smithy/types": "1.1.0", "tslib": "^2.5.0" }, "devDependencies": { diff --git a/packages/types/src/abort.ts b/packages/types/src/abort.ts index 344e1f99abc8..dad6079f81c9 100644 --- a/packages/types/src/abort.ts +++ b/packages/types/src/abort.ts @@ -1,53 +1 @@ -/** - * @public - */ -export interface AbortHandler { - (this: AbortSignal, ev: any): any; -} - -/** - * @public - * - * Holders of an AbortSignal object may query if the associated operation has - * been aborted and register an onabort handler. - * - * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal - */ -export interface AbortSignal { - /** - * Whether the action represented by this signal has been cancelled. - */ - readonly aborted: boolean; - - /** - * A function to be invoked when the action represented by this signal has - * been cancelled. - */ - onabort: AbortHandler | Function | null; -} - -/** - * @public - * - * The AWS SDK uses a Controller/Signal model to allow for cooperative - * cancellation of asynchronous operations. When initiating such an operation, - * the caller can create an AbortController and then provide linked signal to - * subtasks. This allows a single source to communicate to multiple consumers - * that an action has been aborted without dictating how that cancellation - * should be handled. - * - * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController - */ -export interface AbortController { - /** - * An object that reports whether the action associated with this - * `AbortController` has been cancelled. - */ - readonly signal: AbortSignal; - - /** - * Declares the operation associated with this AbortController to have been - * cancelled. - */ - abort(): void; -} +export { AbortController, AbortHandler, AbortSignal } from "@smithy/types"; diff --git a/packages/types/src/auth.ts b/packages/types/src/auth.ts index 50fd33f13539..6626c16d5c78 100644 --- a/packages/types/src/auth.ts +++ b/packages/types/src/auth.ts @@ -1,61 +1 @@ -/** - * @internal - * - * Authentication schemes represent a way that the service will authenticate the customer’s identity. - */ -export interface AuthScheme { - /** - * @example "sigv4a" or "sigv4" - */ - name: "sigv4" | "sigv4a" | string; - /** - * @example "s3" - */ - signingName: string; - /** - * @example "us-east-1" - */ - signingRegion: string; - /** - * @example ["*"] - * @example ["us-west-2", "us-east-1"] - */ - signingRegionSet?: string[]; - /** - * @deprecated this field was renamed to signingRegion. - */ - signingScope?: never; - properties: Record; -} - -// As described in the Smithy documentation: -// https://github.com/awslabs/smithy/blob/main/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy -/** - * @internal - */ -export interface HttpAuthDefinition { - /** - * Defines the location of where the Auth is serialized. - */ - in: HttpAuthLocation; - - /** - * Defines the name of the HTTP header or query string parameter - * that contains the Auth. - */ - name: string; - - /** - * Defines the security scheme to use on the `Authorization` header value. - * This can only be set if the "in" property is set to {@link HttpAuthLocation.HEADER}. - */ - scheme?: string; -} - -/** - * @internal - */ -export enum HttpAuthLocation { - HEADER = "header", - QUERY = "query", -} +export { AuthScheme, HttpAuthDefinition, HttpAuthLocation } from "@smithy/types"; diff --git a/packages/types/src/checksum.ts b/packages/types/src/checksum.ts index 5d1324ee18aa..f805d7291b98 100644 --- a/packages/types/src/checksum.ts +++ b/packages/types/src/checksum.ts @@ -1,70 +1 @@ -import { SourceData } from "./crypto"; - -/** - * @public - * - * An object that provides a checksum of data provided in chunks to `update`. - * The checksum may be performed incrementally as chunks are received or all - * at once when the checksum is finalized, depending on the underlying - * implementation. - * - * It's recommended to compute checksum incrementally to avoid reading the - * entire payload in memory. - * - * A class that implements this interface may accept an optional secret key in its - * constructor while computing checksum value, when using HMAC. If provided, - * this secret key would be used when computing checksum. - */ -export interface Checksum { - /** - * Constant length of the digest created by the algorithm in bytes. - */ - digestLength?: number; - - /** - * Creates a new checksum object that contains a deep copy of the internal - * state of the current `Checksum` object. - */ - copy?(): Checksum; - - /** - * Returns the digest of all of the data passed. - */ - digest(): Promise; - - /** - * Allows marking a checksum for checksums that support the ability - * to mark and reset. - * - * @param readLimit - The maximum limit of bytes that can be read - * before the mark position becomes invalid. - */ - mark?(readLimit: number): void; - - /** - * Resets the checksum to its initial value. - */ - reset(): void; - - /** - * Adds a chunk of data for which checksum needs to be computed. - * This can be called many times with new data as it is streamed. - * - * Implementations may override this method which passes second param - * which makes Checksum object stateless. - * - * @param chunk - The buffer to update checksum with. - */ - update(chunk: Uint8Array): void; -} - -/** - * @public - * - * A constructor for a Checksum that may be used to calculate an HMAC. Implementing - * classes should not directly hold the provided key in memory beyond the - * lexical scope of the constructor. - */ -export interface ChecksumConstructor { - new (secret?: SourceData): Checksum; -} +export { Checksum, ChecksumConstructor } from "@smithy/types"; diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index da86d4782dec..d6b3dcf95e8d 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -1,37 +1 @@ -import { Command } from "./command"; -import { MiddlewareStack } from "./middleware"; -import { MetadataBearer } from "./response"; - -/** - * @public - * - * function definition for different overrides of client's 'send' function. - */ -interface InvokeFunction { - ( - command: Command, - options?: any - ): Promise; - ( - command: Command, - options: any, - cb: (err: any, data?: OutputType) => void - ): void; - ( - command: Command, - options?: any, - cb?: (err: any, data?: OutputType) => void - ): Promise | void; -} - -/** - * A general interface for service clients, idempotent to browser or node clients - * This type corresponds to SmithyClient(https://github.com/aws/aws-sdk-js-v3/blob/main/packages/smithy-client/src/client.ts). - * It's provided for using without importing the SmithyClient class. - */ -export interface Client { - readonly config: ResolvedClientConfiguration; - middlewareStack: MiddlewareStack; - send: InvokeFunction; - destroy: () => void; -} +export { Client } from "@smithy/types"; diff --git a/packages/types/src/command.ts b/packages/types/src/command.ts index 962326e4bb42..388726706d71 100644 --- a/packages/types/src/command.ts +++ b/packages/types/src/command.ts @@ -1,21 +1 @@ -import { Handler, MiddlewareStack } from "./middleware"; -import { MetadataBearer } from "./response"; - -/** - * @public - */ -export interface Command< - ClientInput extends object, - InputType extends ClientInput, - ClientOutput extends MetadataBearer, - OutputType extends ClientOutput, - ResolvedConfiguration -> { - readonly input: InputType; - readonly middlewareStack: MiddlewareStack; - resolveMiddleware( - stack: MiddlewareStack, - configuration: ResolvedConfiguration, - options: any - ): Handler; -} +export { Command } from "@smithy/types"; diff --git a/packages/types/src/connection.ts b/packages/types/src/connection.ts new file mode 100644 index 000000000000..efcb4d777971 --- /dev/null +++ b/packages/types/src/connection.ts @@ -0,0 +1 @@ +export { ConnectConfiguration, ConnectionManager, ConnectionManagerConfiguration, ConnectionPool } from "@smithy/types"; diff --git a/packages/types/src/connection/config.ts b/packages/types/src/connection/config.ts deleted file mode 100644 index 65567f914014..000000000000 --- a/packages/types/src/connection/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface ConnectConfiguration { - /** - * The maximum time in milliseconds that the connection phase of a request - * may take before the connection attempt is abandoned. - */ - requestTimeout?: number; -} diff --git a/packages/types/src/connection/index.ts b/packages/types/src/connection/index.ts deleted file mode 100644 index 5009fa68084e..000000000000 --- a/packages/types/src/connection/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./config"; -export * from "./manager"; -export * from "./pool"; \ No newline at end of file diff --git a/packages/types/src/connection/manager.ts b/packages/types/src/connection/manager.ts deleted file mode 100644 index d45ec907634b..000000000000 --- a/packages/types/src/connection/manager.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { RequestContext } from "../transfer"; -import { ConnectConfiguration } from "./config"; - -export interface ConnectionManagerConfiguration { - /** - * Maximum number of allowed concurrent requests per connection. - */ - maxConcurrency?: number; - - /** - * Disables concurrent requests per connection. - */ - disableConcurrency?: boolean; -} - -export interface ConnectionManager { - /** - * Retrieves a connection from the connection pool if available, - * otherwise establish a new connection - */ - lease(requestContext: RequestContext, connectionConfiguration: ConnectConfiguration): T; - - /** - * Releases the connection back to the pool making it potentially - * re-usable by other requests. - */ - release(requestContext: RequestContext, connection: T): void; - - /** - * Destroys the connection manager. All connections will be closed. - */ - destroy(): void; -} diff --git a/packages/types/src/connection/pool.ts b/packages/types/src/connection/pool.ts deleted file mode 100644 index 48295a91f0c3..000000000000 --- a/packages/types/src/connection/pool.ts +++ /dev/null @@ -1,28 +0,0 @@ -export interface ConnectionPool { - /** - * Retrieve the first connection in the pool - */ - poll(): T | void; - - /** - * Release the connection back to the pool making it potentially - * re-usable by other requests. - */ - offerLast(connection: T): void; - - /** - * Removes the connection from the pool, and destroys it. - */ - destroy(connection: T): void; - - /** - * Implements the iterable protocol and allows arrays to be consumed - * by most syntaxes expecting iterables, such as the spread syntax - * and for...of loops - */ - [Symbol.iterator](): Iterator; -} - -export interface CacheKey { - destination: string; -} diff --git a/packages/types/src/crypto.ts b/packages/types/src/crypto.ts index 27a049fe09f9..aeeea5027676 100644 --- a/packages/types/src/crypto.ts +++ b/packages/types/src/crypto.ts @@ -1,65 +1 @@ -/** - * @public - */ -export type SourceData = string | ArrayBuffer | ArrayBufferView; - -/** - * @public - * - * An object that provides a hash of data provided in chunks to `update`. The - * hash may be performed incrementally as chunks are received or all at once - * when the hash is finalized, depending on the underlying implementation. - * - * @deprecated use {@link Checksum} - */ -export interface Hash { - /** - * Adds a chunk of data to the hash. If a buffer is provided, the `encoding` - * argument will be ignored. If a string is provided without a specified - * encoding, implementations must assume UTF-8 encoding. - * - * Not all encodings are supported on all platforms, though all must support - * UTF-8. - */ - update(toHash: SourceData, encoding?: "utf8" | "ascii" | "latin1"): void; - - /** - * Finalizes the hash and provides a promise that will be fulfilled with the - * raw bytes of the calculated hash. - */ - digest(): Promise; -} - -/** - * @public - * - * A constructor for a hash that may be used to calculate an HMAC. Implementing - * classes should not directly hold the provided key in memory beyond the - * lexical scope of the constructor. - * - * @deprecated use {@link ChecksumConstructor} - */ -export interface HashConstructor { - new (secret?: SourceData): Hash; -} - -/** - * @public - * - * A function that calculates the hash of a data stream. Determining the hash - * will consume the stream, so only replayable streams should be provided to an - * implementation of this interface. - */ -export interface StreamHasher { - (hashCtor: HashConstructor, stream: StreamType): Promise; -} - -/** - * @public - * - * A function that returns a promise fulfilled with bytes from a - * cryptographically secure pseudorandom number generator. - */ -export interface randomValues { - (byteLength: number): Promise; -} +export { Hash, HashConstructor, StreamHasher, randomValues, SourceData } from "@smithy/types"; diff --git a/packages/types/src/encode.ts b/packages/types/src/encode.ts index 2f0754a10449..128ee570075b 100644 --- a/packages/types/src/encode.ts +++ b/packages/types/src/encode.ts @@ -1,24 +1 @@ -import { Message } from "./eventStream"; - -export interface MessageEncoder { - encode(message: Message): Uint8Array; -} - -export interface MessageDecoder { - decode(message: ArrayBufferView): Message; - feed(message: ArrayBufferView): void; - endOfStream(): void; - getMessage(): AvailableMessage; - getAvailableMessages(): AvailableMessages; -} - -export interface AvailableMessage { - getMessage(): Message | undefined; - - isEndOfStream(): boolean; -} - -export interface AvailableMessages { - getMessages(): Message[]; - isEndOfStream(): boolean; -} +export { MessageDecoder, MessageEncoder, AvailableMessage, AvailableMessages } from "@smithy/types"; diff --git a/packages/types/src/endpoint.ts b/packages/types/src/endpoint.ts index e6d3f5205d1c..ff3c7ded7a34 100644 --- a/packages/types/src/endpoint.ts +++ b/packages/types/src/endpoint.ts @@ -1,88 +1,9 @@ -import { AuthScheme } from "./auth"; - -/** - * @public - */ -export interface EndpointPartition { - name: string; - dnsSuffix: string; - dualStackDnsSuffix: string; - supportsFIPS: boolean; - supportsDualStack: boolean; -} - -/** - * @public - */ -export interface EndpointARN { - partition: string; - service: string; - region: string; - accountId: string; - resourceId: Array; -} - -/** - * @public - */ -export enum EndpointURLScheme { - HTTP = "http", - HTTPS = "https", -} - -/** - * @public - */ -export interface EndpointURL { - /** - * The URL scheme such as http or https. - */ - scheme: EndpointURLScheme; - - /** - * The authority is the host and optional port component of the URL. - */ - authority: string; - - /** - * The parsed path segment of the URL. - * This value is as-is as provided by the user. - */ - path: string; - - /** - * The parsed path segment of the URL. - * This value is guranteed to start and end with a "/". - */ - normalizedPath: string; - - /** - * A boolean indicating whether the authority is an IP address. - */ - isIp: boolean; -} - -/** - * @public - */ -export type EndpointObjectProperty = - | string - | boolean - | { [key: string]: EndpointObjectProperty } - | EndpointObjectProperty[]; - -/** - * @public - */ -export interface EndpointV2 { - url: URL; - properties?: { - authSchemes?: AuthScheme[]; - } & Record; - headers?: Record; -} - -/** - * @public - */ -export type EndpointParameters = { [name: string]: undefined | string | boolean }; +export { + EndpointARN, + EndpointPartition, + EndpointURLScheme, + EndpointURL, + EndpointObjectProperty, + EndpointV2, + EndpointParameters, +} from "@smithy/types"; diff --git a/packages/types/src/eventStream.ts b/packages/types/src/eventStream.ts index ae1400e3ca19..e4c04a9b64c7 100644 --- a/packages/types/src/eventStream.ts +++ b/packages/types/src/eventStream.ts @@ -1,136 +1,24 @@ -import { HttpRequest } from "./http"; -import { - FinalizeHandler, - FinalizeHandlerArguments, - FinalizeHandlerOutput, - HandlerExecutionContext, -} from "./middleware"; -import { MetadataBearer } from "./response"; -/** - * @public - * - * An event stream message. The headers and body properties will always be - * defined, with empty headers represented as an object with no keys and an - * empty body represented as a zero-length Uint8Array. - */ -export interface Message { - headers: MessageHeaders; - body: Uint8Array; -} - -/** - * @public - */ -export type MessageHeaders = Record; - -type HeaderValue = { type: K; value: V }; - -export type BooleanHeaderValue = HeaderValue<"boolean", boolean>; -export type ByteHeaderValue = HeaderValue<"byte", number>; -export type ShortHeaderValue = HeaderValue<"short", number>; -export type IntegerHeaderValue = HeaderValue<"integer", number>; -export type LongHeaderValue = HeaderValue<"long", Int64>; -export type BinaryHeaderValue = HeaderValue<"binary", Uint8Array>; -export type StringHeaderValue = HeaderValue<"string", string>; -export type TimestampHeaderValue = HeaderValue<"timestamp", Date>; -export type UuidHeaderValue = HeaderValue<"uuid", string>; - -/** - * @public - */ -export type MessageHeaderValue = - | BooleanHeaderValue - | ByteHeaderValue - | ShortHeaderValue - | IntegerHeaderValue - | LongHeaderValue - | BinaryHeaderValue - | StringHeaderValue - | TimestampHeaderValue - | UuidHeaderValue; - -/** - * @public - */ -export interface Int64 { - readonly bytes: Uint8Array; - valueOf: () => number; - toString: () => string; -} - -/** - * @public - * - * Util functions for serializing or deserializing event stream - */ -export interface EventStreamSerdeContext { - eventStreamMarshaller: EventStreamMarshaller; -} - -/** - * @public - * - * A function which deserializes binary event stream message into modeled shape. - */ -export interface EventStreamMarshallerDeserFn { - (body: StreamType, deserializer: (input: Record) => Promise): AsyncIterable; -} - -/** - * @public - * - * A function that serializes modeled shape into binary stream message. - */ -export interface EventStreamMarshallerSerFn { - (input: AsyncIterable, serializer: (event: T) => Message): StreamType; -} - -/** - * @public - * - * An interface which provides functions for serializing and deserializing binary event stream - * to/from corresponsing modeled shape. - */ -export interface EventStreamMarshaller { - deserialize: EventStreamMarshallerDeserFn; - serialize: EventStreamMarshallerSerFn; -} - -/** - * @public - */ -export interface EventStreamRequestSigner { - sign(request: HttpRequest): Promise; -} - -/** - * @public - */ -export interface EventStreamPayloadHandler { - handle: ( - next: FinalizeHandler, - args: FinalizeHandlerArguments, - context?: HandlerExecutionContext - ) => Promise>; -} - -/** - * @public - */ -export interface EventStreamPayloadHandlerProvider { - (options: any): EventStreamPayloadHandler; -} - -/** - * @public - */ -export interface EventStreamSerdeProvider { - (options: any): EventStreamMarshaller; -} - -/** - * @public - */ -export interface EventStreamSignerProvider { - (options: any): EventStreamRequestSigner; -} +export { + Message, + MessageHeaders, + BooleanHeaderValue, + ByteHeaderValue, + ShortHeaderValue, + IntegerHeaderValue, + LongHeaderValue, + BinaryHeaderValue, + StringHeaderValue, + TimestampHeaderValue, + UuidHeaderValue, + MessageHeaderValue, + Int64, + EventStreamSerdeContext, + EventStreamMarshaller, + EventStreamMarshallerDeserFn, + EventStreamMarshallerSerFn, + EventStreamPayloadHandler, + EventStreamPayloadHandlerProvider, + EventStreamRequestSigner, + EventStreamSerdeProvider, + EventStreamSignerProvider, +} from "@smithy/types"; diff --git a/packages/types/src/http.ts b/packages/types/src/http.ts index 4cb9f938d860..bcc1080b6c9f 100644 --- a/packages/types/src/http.ts +++ b/packages/types/src/http.ts @@ -1,5 +1,13 @@ -import { AbortSignal } from "./abort"; -import { URI } from "./uri"; +import { HttpResponse } from "@smithy/types"; +export { + Endpoint, + HeaderBag, + HttpHandlerOptions, + HttpMessage, + HttpRequest, + HttpResponse, + QueryParameterBag, +} from "@smithy/types"; /** * @public @@ -25,84 +33,6 @@ export interface Headers extends Map { withoutHeader(headerName: string): Headers; } -/** - * @public - * - * A mapping of header names to string values. Multiple values for the same - * header should be represented as a single string with values separated by - * `, `. - * - * Keys should be considered case insensitive, even if this is not enforced by a - * particular implementation. For example, given the following HeaderBag, where - * keys differ only in case: - * - * ```json - * { - * 'x-amz-date': '2000-01-01T00:00:00Z', - * 'X-Amz-Date': '2001-01-01T00:00:00Z' - * } - * ``` - * - * The SDK may at any point during processing remove one of the object - * properties in favor of the other. The headers may or may not be combined, and - * the SDK will not deterministically select which header candidate to use. - */ -export type HeaderBag = Record; - -/** - * @public - * - * Represents an HTTP message with headers and an optional static or streaming - * body. bode: ArrayBuffer | ArrayBufferView | string | Uint8Array | Readable | ReadableStream; - */ -export interface HttpMessage { - headers: HeaderBag; - body?: any; -} - -/** - * @public - * - * A mapping of query parameter names to strings or arrays of strings, with the - * second being used when a parameter contains a list of values. Value can be set - * to null when query is not in key-value pairs shape - */ -export type QueryParameterBag = Record | null>; - -/** - * @public - * - * @deprecated use {@link EndpointV2} from `@aws-sdk/types`. - */ -export interface Endpoint { - protocol: string; - hostname: string; - port?: number; - path: string; - query?: QueryParameterBag; -} - -/** - * @public - * - * Interface an HTTP request class. Contains - * addressing information in addition to standard message properties. - */ -export interface HttpRequest extends HttpMessage, URI { - method: string; -} - -/** - * @public - * - * Represents an HTTP message as received in reply to a request. Contains a - * numeric status code in addition to standard message properties. - */ -export interface HttpResponse extends HttpMessage { - statusCode: number; - reason?: string; -} - /** * @public * @@ -112,18 +42,3 @@ export interface HttpResponse extends HttpMessage { export interface ResolvedHttpResponse extends HttpResponse { body: string; } - -/** - * @public - * - * Represents the options that may be passed to an Http Handler. - */ -export interface HttpHandlerOptions { - abortSignal?: AbortSignal; - - /** - * The maximum time in milliseconds that the connection phase of a request - * may take before the connection attempt is abandoned. - */ - requestTimeout?: number; -} diff --git a/packages/types/src/identity/AwsCredentialIdentity.ts b/packages/types/src/identity/AwsCredentialIdentity.ts index d0bdf3ff1665..1113d9c37c04 100644 --- a/packages/types/src/identity/AwsCredentialIdentity.ts +++ b/packages/types/src/identity/AwsCredentialIdentity.ts @@ -1,27 +1 @@ -import { Identity, IdentityProvider } from "./Identity"; - -/** - * @public - */ -export interface AwsCredentialIdentity extends Identity { - /** - * AWS access key ID - */ - readonly accessKeyId: string; - - /** - * AWS secret access key - */ - readonly secretAccessKey: string; - - /** - * A security or session token to use with these credentials. Usually - * present for temporary credentials. - */ - readonly sessionToken?: string; -} - -/** - * @public - */ -export type AwsCredentialIdentityProvider = IdentityProvider; +export { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@smithy/types"; diff --git a/packages/types/src/identity/Identity.ts b/packages/types/src/identity/Identity.ts index 2a2833da36ea..4175fd3468f0 100644 --- a/packages/types/src/identity/Identity.ts +++ b/packages/types/src/identity/Identity.ts @@ -1,16 +1 @@ -/** - * @public - */ -export interface Identity { - /** - * A `Date` when the identity or credential will no longer be accepted. - */ - readonly expiration?: Date; -} - -/** - * @public - */ -export interface IdentityProvider { - (identityProperties?: Record): Promise; -} +export { Identity, IdentityProvider } from "@smithy/types"; diff --git a/packages/types/src/logger.ts b/packages/types/src/logger.ts index a7875acec264..09dc00b9359e 100644 --- a/packages/types/src/logger.ts +++ b/packages/types/src/logger.ts @@ -1,3 +1,6 @@ +import { Logger } from "@smithy/types"; +export { Logger } from "@smithy/types"; + /** * @public * @@ -19,17 +22,3 @@ export interface LoggerOptions { logger?: Logger; logLevel?: LogLevel; } - -/** - * @public - * - * Represents a logger object that is available in HandlerExecutionContext - * throughout the middleware stack. - */ -export interface Logger { - trace?: (...content: any[]) => void; - debug: (...content: any[]) => void; - info: (...content: any[]) => void; - warn: (...content: any[]) => void; - error: (...content: any[]) => void; -} diff --git a/packages/types/src/middleware.ts b/packages/types/src/middleware.ts index 2377d3f77c38..3ae51bd9a83d 100644 --- a/packages/types/src/middleware.ts +++ b/packages/types/src/middleware.ts @@ -1,542 +1,40 @@ -import { AuthScheme, HttpAuthDefinition } from "./auth"; -import { EndpointV2 } from "./endpoint"; -import { Logger } from "./logger"; -import { UserAgent } from "./util"; - -/** - * @public - */ -export interface InitializeHandlerArguments { - /** - * User input to a command. Reflects the userland representation of the - * union of data types the command can effectively handle. - */ - input: Input; -} - -/** - * @public - */ -export interface InitializeHandlerOutput extends DeserializeHandlerOutput { - output: Output; -} - -/** - * @public - */ -export interface SerializeHandlerArguments extends InitializeHandlerArguments { - /** - * The user input serialized as a request object. The request object is unknown, - * so you cannot modify it directly. When work with request, you need to guard its - * type to e.g. HttpRequest with 'instanceof' operand - * - * During the build phase of the execution of a middleware stack, a built - * request may or may not be available. - */ - request?: unknown; -} - -/** - * @public - */ -export interface SerializeHandlerOutput extends InitializeHandlerOutput {} - -/** - * @public - */ -export interface BuildHandlerArguments extends FinalizeHandlerArguments {} - -/** - * @public - */ -export interface BuildHandlerOutput extends InitializeHandlerOutput {} - -/** - * @public - */ -export interface FinalizeHandlerArguments extends SerializeHandlerArguments { - /** - * The user input serialized as a request. - */ - request: unknown; -} - -/** - * @public - */ -export interface FinalizeHandlerOutput extends InitializeHandlerOutput {} - -/** - * @public - */ -export interface DeserializeHandlerArguments extends FinalizeHandlerArguments {} - -/** - * @public - */ -export interface DeserializeHandlerOutput { - /** - * The raw response object from runtime is deserialized to structured output object. - * The response object is unknown so you cannot modify it directly. When work with - * response, you need to guard its type to e.g. HttpResponse with 'instanceof' operand. - * - * During the deserialize phase of the execution of a middleware stack, a deserialized - * response may or may not be available - */ - response: unknown; - output?: Output; -} - -/** - * @public - */ -export interface InitializeHandler { - /** - * Asynchronously converts an input object into an output object. - * - * @param args - An object containing a input to the command as well as any - * associated or previously generated execution artifacts. - */ - (args: InitializeHandlerArguments): Promise>; -} - -/** - * @public - */ -export type Handler = InitializeHandler; - -/** - * @public - */ -export interface SerializeHandler { - /** - * Asynchronously converts an input object into an output object. - * - * @param args - An object containing a input to the command as well as any - * associated or previously generated execution artifacts. - */ - (args: SerializeHandlerArguments): Promise>; -} - -/** - * @public - */ -export interface FinalizeHandler { - /** - * Asynchronously converts an input object into an output object. - * - * @param args - An object containing a input to the command as well as any - * associated or previously generated execution artifacts. - */ - (args: FinalizeHandlerArguments): Promise>; -} - -/** - * @public - */ -export interface BuildHandler { - (args: BuildHandlerArguments): Promise>; -} - -/** - * @public - */ -export interface DeserializeHandler { - (args: DeserializeHandlerArguments): Promise>; -} - -/** - * @public - * - * A factory function that creates functions implementing the `Handler` - * interface. - */ -export interface InitializeMiddleware { - /** - * @param next - The handler to invoke after this middleware has operated on - * the user input and before this middleware operates on the output. - * - * @param context - Invariant data and functions for use by the handler. - */ - (next: InitializeHandler, context: HandlerExecutionContext): InitializeHandler; -} - -/** - * @public - * - * A factory function that creates functions implementing the `BuildHandler` - * interface. - */ -export interface SerializeMiddleware { - /** - * @param next - The handler to invoke after this middleware has operated on - * the user input and before this middleware operates on the output. - * - * @param context - Invariant data and functions for use by the handler. - */ - (next: SerializeHandler, context: HandlerExecutionContext): SerializeHandler; -} - -/** - * @public - * - * A factory function that creates functions implementing the `FinalizeHandler` - * interface. - */ -export interface FinalizeRequestMiddleware { - /** - * @param next - The handler to invoke after this middleware has operated on - * the user input and before this middleware operates on the output. - * - * @param context - Invariant data and functions for use by the handler. - */ - (next: FinalizeHandler, context: HandlerExecutionContext): FinalizeHandler; -} - -/** - * @public - */ -export interface BuildMiddleware { - (next: BuildHandler, context: HandlerExecutionContext): BuildHandler; -} - -/** - * @public - */ -export interface DeserializeMiddleware { - (next: DeserializeHandler, context: HandlerExecutionContext): DeserializeHandler; -} - -/** - * @public - */ -export type MiddlewareType = - | InitializeMiddleware - | SerializeMiddleware - | BuildMiddleware - | FinalizeRequestMiddleware - | DeserializeMiddleware; - -/** - * @public - * - * A factory function that creates the terminal handler atop which a middleware - * stack sits. - */ -export interface Terminalware { - (context: HandlerExecutionContext): DeserializeHandler; -} - -/** - * @public - */ -export type Step = "initialize" | "serialize" | "build" | "finalizeRequest" | "deserialize"; - -/** - * @public - */ -export type Priority = "high" | "normal" | "low"; - -/** - * @public - */ -export interface HandlerOptions { - /** - * Handlers are ordered using a "step" that describes the stage of command - * execution at which the handler will be executed. The available steps are: - * - * - initialize: The input is being prepared. Examples of typical - * initialization tasks include injecting default options computing - * derived parameters. - * - serialize: The input is complete and ready to be serialized. Examples - * of typical serialization tasks include input validation and building - * an HTTP request from user input. - * - build: The input has been serialized into an HTTP request, but that - * request may require further modification. Any request alterations - * will be applied to all retries. Examples of typical build tasks - * include injecting HTTP headers that describe a stable aspect of the - * request, such as `Content-Length` or a body checksum. - * - finalizeRequest: The request is being prepared to be sent over the wire. The - * request in this stage should already be semantically complete and - * should therefore only be altered as match the recipient's - * expectations. Examples of typical finalization tasks include request - * signing and injecting hop-by-hop headers. - * - deserialize: The response has arrived, the middleware here will deserialize - * the raw response object to structured response - * - * Unlike initialization and build handlers, which are executed once - * per operation execution, finalization and deserialize handlers will be - * executed foreach HTTP request sent. - * - * @defaultValue 'initialize' - */ - step?: Step; - - /** - * A list of strings to any that identify the general purpose or important - * characteristics of a given handler. - */ - tags?: Array; - - /** - * A unique name to refer to a middleware - */ - name?: string; - - /** - * A flag to override the existing middleware with the same name. Without - * setting it, adding middleware with duplicated name will throw an exception. - * @internal - */ - override?: boolean; -} -/** - * @public - */ -export interface AbsoluteLocation { - /** - * By default middleware will be added to individual step in un-guaranteed order. - * In the case that - * - * @defaultValue 'normal' - */ - priority?: Priority; -} - -/** - * @public - */ -export type Relation = "before" | "after"; - -/** - * @public - */ -export interface RelativeLocation { - /** - * Specify the relation to be before or after a know middleware. - */ - relation: Relation; - - /** - * A known middleware name to indicate inserting middleware's location. - */ - toMiddleware: string; -} - -/** - * @public - */ -export type RelativeMiddlewareOptions = RelativeLocation & Omit; - -/** - * @public - */ -export interface InitializeHandlerOptions extends HandlerOptions { - step?: "initialize"; -} - -/** - * @public - */ -export interface SerializeHandlerOptions extends HandlerOptions { - step: "serialize"; -} - -/** - * @public - */ -export interface BuildHandlerOptions extends HandlerOptions { - step: "build"; -} - -/** - * @public - */ -export interface FinalizeRequestHandlerOptions extends HandlerOptions { - step: "finalizeRequest"; -} - -/** - * @public - */ -export interface DeserializeHandlerOptions extends HandlerOptions { - step: "deserialize"; -} - -/** - * @public - * - * A stack storing middleware. It can be resolved into a handler. It supports 2 - * approaches for adding middleware: - * 1. Adding middleware to specific step with `add()`. The order of middleware - * added into same step is determined by order of adding them. If one middleware - * needs to be executed at the front of the step or at the end of step, set - * `priority` options to `high` or `low`. - * 2. Adding middleware to location relative to known middleware with `addRelativeTo()`. - * This is useful when given middleware must be executed before or after specific - * middleware(`toMiddleware`). You can add a middleware relatively to another - * middleware which also added relatively. But eventually, this relative middleware - * chain **must** be 'anchored' by a middleware that added using `add()` API - * with absolute `step` and `priority`. This mothod will throw if specified - * `toMiddleware` is not found. - */ -export interface MiddlewareStack extends Pluggable { - /** - * Add middleware to the stack to be executed during the "initialize" step, - * optionally specifying a priority, tags and name - */ - add(middleware: InitializeMiddleware, options?: InitializeHandlerOptions & AbsoluteLocation): void; - - /** - * Add middleware to the stack to be executed during the "serialize" step, - * optionally specifying a priority, tags and name - */ - add(middleware: SerializeMiddleware, options: SerializeHandlerOptions & AbsoluteLocation): void; - - /** - * Add middleware to the stack to be executed during the "build" step, - * optionally specifying a priority, tags and name - */ - add(middleware: BuildMiddleware, options: BuildHandlerOptions & AbsoluteLocation): void; - - /** - * Add middleware to the stack to be executed during the "finalizeRequest" step, - * optionally specifying a priority, tags and name - */ - add( - middleware: FinalizeRequestMiddleware, - options: FinalizeRequestHandlerOptions & AbsoluteLocation - ): void; - - /** - * Add middleware to the stack to be executed during the "deserialize" step, - * optionally specifying a priority, tags and name - */ - add(middleware: DeserializeMiddleware, options: DeserializeHandlerOptions & AbsoluteLocation): void; - - /** - * Add middleware to a stack position before or after a known middleware,optionally - * specifying name and tags. - */ - addRelativeTo(middleware: MiddlewareType, options: RelativeMiddlewareOptions): void; - - /** - * Apply a customization function to mutate the middleware stack, often - * used for customizations that requires mutating multiple middleware. - */ - use(pluggable: Pluggable): void; - - /** - * Create a shallow clone of this stack. Step bindings and handler priorities - * and tags are preserved in the copy. - */ - clone(): MiddlewareStack; - - /** - * Removes middleware from the stack. - * - * If a string is provided, it will be treated as middleware name. If a middleware - * is inserted with the given name, it will be removed. - * - * If a middleware class is provided, all usages thereof will be removed. - */ - remove(toRemove: MiddlewareType | string): boolean; - - /** - * Removes middleware that contains given tag - * - * Multiple middleware will potentially be removed - */ - removeByTag(toRemove: string): boolean; - - /** - * Create a stack containing the middlewares in this stack as well as the - * middlewares in the `from` stack. Neither source is modified, and step - * bindings and handler priorities and tags are preserved in the copy. - */ - concat( - from: MiddlewareStack - ): MiddlewareStack; - - /** - * Returns a list of the current order of middleware in the stack. - * This does not execute the middleware functions, nor does it - * provide a reference to the stack itself. - */ - identify(): string[]; - - /** - * Builds a single handler function from zero or more middleware classes and - * a core handler. The core handler is meant to send command objects to AWS - * services and return promises that will resolve with the operation result - * or be rejected with an error. - * - * When a composed handler is invoked, the arguments will pass through all - * middleware in a defined order, and the return from the innermost handler - * will pass through all middleware in the reverse of that order. - */ - resolve( - handler: DeserializeHandler, - context: HandlerExecutionContext - ): InitializeHandler; -} - -/** - * @public - * - * Data and helper objects that are not expected to change from one execution of - * a composed handler to another. - */ -export interface HandlerExecutionContext { - /** - * A logger that may be invoked by any handler during execution of an - * operation. - */ - logger?: Logger; - - /** - * Additional user agent that inferred by middleware. It can be used to save - * the internal user agent sections without overriding the `customUserAgent` - * config in clients. - */ - userAgent?: UserAgent; - - /** - * Resolved by the endpointMiddleware function of `@aws-sdk/middleware-endpoint` - * in the serialization stage. - */ - endpointV2?: EndpointV2; - - /** - * Set at the same time as endpointV2. - */ - authSchemes?: AuthScheme[]; - - /** - * The current auth configuration that has been set by any auth middleware and - * that will prevent from being set more than once. - */ - currentAuthConfig?: HttpAuthDefinition; - - /** - * Used by DynamoDbDocumentClient. - */ - dynamoDbDocumentClientOptions?: Partial<{ - overrideInputFilterSensitiveLog(...args: any[]): string | void; - overrideOutputFilterSensitiveLog(...args: any[]): string | void; - }>; - - [key: string]: any; -} - -/** - * @public - */ -export interface Pluggable { - /** - * A function that mutate the passed in middleware stack. Functions implementing - * this interface can add, remove, modify existing middleware stack from clients - * or commands - */ - applyToStack: (stack: MiddlewareStack) => void; -} +export { + AbsoluteLocation, + BuildHandler, + BuildHandlerArguments, + BuildHandlerOptions, + BuildHandlerOutput, + BuildMiddleware, + DeserializeHandler, + DeserializeHandlerArguments, + DeserializeHandlerOptions, + DeserializeHandlerOutput, + DeserializeMiddleware, + FinalizeHandler, + FinalizeHandlerArguments, + FinalizeHandlerOutput, + FinalizeRequestHandlerOptions, + FinalizeRequestMiddleware, + Handler, + HandlerExecutionContext, + HandlerOptions, + InitializeHandler, + InitializeHandlerArguments, + InitializeHandlerOptions, + InitializeHandlerOutput, + InitializeMiddleware, + MiddlewareStack, + MiddlewareType, + Pluggable, + Priority, + Relation, + RelativeLocation, + RelativeMiddlewareOptions, + SerializeHandler, + SerializeHandlerArguments, + SerializeHandlerOptions, + SerializeHandlerOutput, + SerializeMiddleware, + Step, + Terminalware, +} from "@smithy/types"; diff --git a/packages/types/src/pagination.ts b/packages/types/src/pagination.ts index fe0ce58ab69e..af791b0f4d72 100644 --- a/packages/types/src/pagination.ts +++ b/packages/types/src/pagination.ts @@ -1,28 +1 @@ -import { Client } from "./client"; - -/** - * @public - * - * Expected type definition of a paginator. - */ -export type Paginator = AsyncGenerator; - -/** - * @public - * - * Expected paginator configuration passed to an operation. Services will extend - * this interface definition and may type client further. - */ -export interface PaginationConfiguration { - client: Client; - pageSize?: number; - startingToken?: any; - /** - * For some APIs, such as CloudWatchLogs events, the next page token will always - * be present. - * - * When true, this config field will have the paginator stop when the token doesn't change - * instead of when it is not present. - */ - stopOnSameToken?: boolean; -} +export { PaginationConfiguration, Paginator } from "@smithy/types"; diff --git a/packages/types/src/profile.ts b/packages/types/src/profile.ts index 12223c3b247d..9916f3bfcf8a 100644 --- a/packages/types/src/profile.ts +++ b/packages/types/src/profile.ts @@ -1,24 +1 @@ -/** - * @public - */ -export type IniSection = Record; - -/** - * @public - * - * @deprecated Please use {@link IniSection} - */ -export interface Profile extends IniSection {} - -/** - * @public - */ -export type ParsedIniData = Record; - -/** - * @public - */ -export interface SharedConfigFiles { - credentialsFile: ParsedIniData; - configFile: ParsedIniData; -} +export { IniSection, Profile, ParsedIniData, SharedConfigFiles } from "@smithy/types"; diff --git a/packages/types/src/response.ts b/packages/types/src/response.ts index 5e8a497cacb2..d2fcecd6c090 100644 --- a/packages/types/src/response.ts +++ b/packages/types/src/response.ts @@ -1,49 +1,4 @@ -/** - * @internal - */ -export interface ResponseMetadata { - /** - * The status code of the last HTTP response received for this operation. - */ - httpStatusCode?: number; - - /** - * A unique identifier for the last request sent for this operation. Often - * requested by AWS service teams to aid in debugging. - */ - requestId?: string; - - /** - * A secondary identifier for the last request sent. Used for debugging. - */ - extendedRequestId?: string; - - /** - * A tertiary identifier for the last request sent. Used for debugging. - */ - cfId?: string; - - /** - * The number of times this operation was attempted. - */ - attempts?: number; - - /** - * The total amount of time (in milliseconds) that was spent waiting between - * retry attempts. - */ - totalRetryDelay?: number; -} - -/** - * @public - */ -export interface MetadataBearer { - /** - * Metadata pertaining to this request. - */ - $metadata: ResponseMetadata; -} +export { MetadataBearer, ResponseMetadata } from "@smithy/types"; /** * @internal diff --git a/packages/types/src/retry.ts b/packages/types/src/retry.ts index ee3ba0b72708..8fc946ad8363 100644 --- a/packages/types/src/retry.ts +++ b/packages/types/src/retry.ts @@ -1,147 +1,12 @@ -/** - * @public - */ -export type RetryErrorType = - /** - * This is a connection level error such as a socket timeout, socket connect - * error, tls negotiation timeout etc... - * Typically these should never be applied for non-idempotent request types - * since in this scenario, it's impossible to know whether the operation had - * a side effect on the server. - */ - | "TRANSIENT" - - /** - * This is an error where the server explicitly told the client to back off, - * such as a 429 or 503 Http error. - */ - | "THROTTLING" - - /** - * This is a server error that isn't explicitly throttling but is considered - * by the client to be something that should be retried. - */ - | "SERVER_ERROR" - - /** - * Doesn't count against any budgets. This could be something like a 401 - * challenge in Http. - */ - | "CLIENT_ERROR"; - -/** - * @public - */ -export interface RetryErrorInfo { - errorType: RetryErrorType; - - /** - * Protocol hint. This could come from Http's 'retry-after' header or - * something from MQTT or any other protocol that has the ability to convey - * retry info from a peer. - * - * @returns the Date after which a retry should be attempted. - */ - retryAfterHint?: Date; -} - -/** - * @public - */ -export interface RetryBackoffStrategy { - /** - * @returns the number of milliseconds to wait before retrying an action. - */ - computeNextBackoffDelay(retryAttempt: number): number; -} - -/** - * @public - */ -export interface StandardRetryBackoffStrategy extends RetryBackoffStrategy { - /** - * Sets the delayBase used to compute backoff delays. - * @param delayBase - - */ - setDelayBase(delayBase: number): void; -} - -/** - * @public - */ -export interface RetryStrategyOptions { - backoffStrategy: RetryBackoffStrategy; - - maxRetriesBase: number; -} - -/** - * @public - */ -export interface RetryToken { - /** - * @returns the current count of retry. - */ - getRetryCount(): number; - - /** - * @returns the number of milliseconds to wait before retrying an action. - */ - getRetryDelay(): number; -} - -/** - * @public - */ -export interface StandardRetryToken extends RetryToken { - /** - * @returns the cost of the last retry attempt. - */ - getRetryCost(): number | undefined; -} - -/** - * @public - */ -export interface RetryStrategyV2 { - /** - * Called before any retries (for the first call to the operation). It either - * returns a retry token or an error upon the failure to acquire a token prior. - * - * tokenScope is arbitrary and out of scope for this component. However, - * adding it here offers us a lot of future flexibility for outage detection. - * For example, it could be "us-east-1" on a shared retry strategy, or - * "us-west-2-c:dynamodb". - */ - acquireInitialRetryToken(retryTokenScope: string): Promise; - - /** - * After a failed operation call, this function is invoked to refresh the - * retryToken returned by acquireInitialRetryToken(). This function can - * either choose to allow another retry and send a new or updated token, - * or reject the retry attempt and report the error either in an exception - * or returning an error. - */ - refreshRetryTokenForRetry(tokenToRenew: RetryToken, errorInfo: RetryErrorInfo): Promise; - - /** - * Upon successful completion of the operation, this function is called - * to record that the operation was successful. - */ - recordSuccess(token: RetryToken): void; -} - -/** - * @public - */ -export type ExponentialBackoffJitterType = "DEFAULT" | "NONE" | "FULL" | "DECORRELATED"; - -/** - * @public - */ -export interface ExponentialBackoffStrategyOptions { - jitterType: ExponentialBackoffJitterType; - - /* Scaling factor to add for the backoff in milliseconds. Default is 25ms */ - backoffScaleValue?: number; -} +export { + ExponentialBackoffJitterType, + ExponentialBackoffStrategyOptions, + RetryBackoffStrategy, + RetryErrorInfo, + RetryErrorType, + RetryStrategyOptions, + RetryStrategyV2, + RetryToken, + StandardRetryBackoffStrategy, + StandardRetryToken, +} from "@smithy/types"; diff --git a/packages/types/src/serde.ts b/packages/types/src/serde.ts index f7d75733b5e8..1881d40fb4e4 100644 --- a/packages/types/src/serde.ts +++ b/packages/types/src/serde.ts @@ -1,73 +1,15 @@ -import { Endpoint } from "./http"; -import { RequestHandler } from "./transfer"; -import { Decoder, Encoder, Provider } from "./util"; - -/** - * @public - * - * Interface for object requires an Endpoint set. - */ -export interface EndpointBearer { - /* TODO(endpointsv2) post-release */ - // Keep using Endpoint V1 interface in serde - // After all services have onboard EndpointV2, we need to migrate it to Endpoint V2 interface too. - endpoint: Provider; -} - -/** - * @public - */ -export interface StreamCollector { - /** - * A function that converts a stream into an array of bytes. - * - * @param stream - The low-level native stream from browser or Nodejs runtime - */ - (stream: any): Promise; -} - -/** - * @public - * - * Request and Response serde util functions and settings for AWS services - */ -export interface SerdeContext extends EndpointBearer { - base64Encoder: Encoder; - base64Decoder: Decoder; - utf8Encoder: Encoder; - utf8Decoder: Decoder; - streamCollector: StreamCollector; - requestHandler: RequestHandler; - disableHostPrefix: boolean; -} - -/** - * @public - */ -export interface RequestSerializer { - /** - * Converts the provided `input` into a request object - * - * @param input - The user input to serialize. - * - * @param context - Context containing runtime-specific util functions. - */ - (input: any, context: Context): Promise; -} - -/** - * @public - */ -export interface ResponseDeserializer { - /** - * Converts the output of an operation into JavaScript types. - * - * @param output - The HTTP response received from the service - * - * @param context - context containing runtime-specific util functions. - */ - (output: ResponseType, context: Context): Promise; -} +export { + EndpointBearer, + StreamCollector, + SerdeContext, + ResponseDeserializer, + RequestSerializer, + SdkStreamMixin, + SdkStream, + WithSdkStreamMixin, + SdkStreamMixinInjector, + SdkStreamSerdeContext, +} from "@smithy/types"; /** * @public @@ -90,50 +32,3 @@ declare global { */ export interface Blob {} } - -/** - * The interface contains mix-in utility functions to transfer the runtime-specific - * stream implementation to specified format. Each stream can ONLY be transformed - * once. - */ -export interface SdkStreamMixin { - transformToByteArray: () => Promise; - transformToString: (encoding?: string) => Promise; - transformToWebStream: () => ReadableStream; -} - -/** - * @public - * - * The type describing a runtime-specific stream implementation with mix-in - * utility functions. - */ -export type SdkStream = BaseStream & SdkStreamMixin; - -/** - * @public - * - * Indicates that the member of type T with - * key StreamKey have been extended - * with the SdkStreamMixin helper methods. - */ -export type WithSdkStreamMixin = { - [key in keyof T]: key extends StreamKey ? SdkStream : T[key]; -}; - -/** - * Interface for internal function to inject stream utility functions - * implementation - * - * @internal - */ -export interface SdkStreamMixinInjector { - (stream: unknown): SdkStreamMixin; -} - -/** - * @internal - */ -export interface SdkStreamSerdeContext { - sdkStreamMixin: SdkStreamMixinInjector; -} diff --git a/packages/types/src/shapes.ts b/packages/types/src/shapes.ts index c1f31bd88432..bc19cc78e9b9 100644 --- a/packages/types/src/shapes.ts +++ b/packages/types/src/shapes.ts @@ -1,78 +1 @@ -import { HttpResponse } from "./http"; -import { MetadataBearer } from "./response"; - -/** - * @public - * - * A document type represents an untyped JSON-like value. - * - * Not all protocols support document types, and the serialization format of a - * document type is protocol specific. All JSON protocols SHOULD support - * document types and they SHOULD serialize document types inline as normal - * JSON values. - */ -export type DocumentType = null | boolean | number | string | DocumentType[] | { [prop: string]: DocumentType }; - -/** - * @public - * - * A structure shape with the error trait. - * https://smithy.io/2.0/spec/behavior-traits.html#smithy-api-retryable-trait - */ -export interface RetryableTrait { - /** - * Indicates that the error is a retryable throttling error. - */ - readonly throttling?: boolean; -} - -/** - * @public - * - * Type that is implemented by all Smithy shapes marked with the - * error trait. - * @deprecated - */ -export interface SmithyException { - /** - * The shape ID name of the exception. - */ - readonly name: string; - - /** - * Whether the client or server are at fault. - */ - readonly $fault: "client" | "server"; - - /** - * The service that encountered the exception. - */ - readonly $service?: string; - - /** - * Indicates that an error MAY be retried by the client. - */ - readonly $retryable?: RetryableTrait; - - /** - * Reference to low-level HTTP response object. - */ - readonly $response?: HttpResponse; -} - -/** - * @public - * - * @deprecated See {@link https://aws.amazon.com/blogs/developer/service-error-handling-modular-aws-sdk-js/} - * - * This type should not be used in your application. - * Users of the AWS SDK for JavaScript v3 service clients should prefer to - * use the specific Exception classes corresponding to each operation. - * These can be found as code in the deserializer for the operation's Command class, - * or as declarations in the service model file in codegen/sdk-codegen/aws-models. - * - * If no exceptions are enumerated by a particular Command operation, - * the base exception for the service should be used. Each client exports - * a base ServiceException prefixed with the service name. - */ -export type SdkError = Error & Partial & Partial; +export { DocumentType, RetryableTrait, SmithyException, SdkError } from "@smithy/types"; diff --git a/packages/types/src/signature.ts b/packages/types/src/signature.ts index f1a2b3f89f37..cbabd7573a0d 100644 --- a/packages/types/src/signature.ts +++ b/packages/types/src/signature.ts @@ -1,168 +1,15 @@ -import { Message } from "./eventStream"; -import { HttpRequest } from "./http"; - -/** - * @public - * - * A `Date` object, a unix (epoch) timestamp in seconds, or a string that can be - * understood by the JavaScript `Date` constructor. - */ -export type DateInput = number | string | Date; - -/** - * @public - */ -export interface SigningArguments { - /** - * The date and time to be used as signature metadata. This value should be - * a Date object, a unix (epoch) timestamp, or a string that can be - * understood by the JavaScript `Date` constructor.If not supplied, the - * value returned by `new Date()` will be used. - */ - signingDate?: DateInput; - - /** - * The service signing name. It will override the service name of the signer - * in current invocation - */ - signingService?: string; - - /** - * The region name to sign the request. It will override the signing region of the - * signer in current invocation - */ - signingRegion?: string; -} - -/** - * @public - */ -export interface RequestSigningArguments extends SigningArguments { - /** - * A set of strings whose members represents headers that cannot be signed. - * All headers in the provided request will have their names converted to - * lower case and then checked for existence in the unsignableHeaders set. - */ - unsignableHeaders?: Set; - - /** - * A set of strings whose members represents headers that should be signed. - * Any values passed here will override those provided via unsignableHeaders, - * allowing them to be signed. - * - * All headers in the provided request will have their names converted to - * lower case before signing. - */ - signableHeaders?: Set; -} - -/** - * @public - */ -export interface RequestPresigningArguments extends RequestSigningArguments { - /** - * The number of seconds before the presigned URL expires - */ - expiresIn?: number; - - /** - * A set of strings whose representing headers that should not be hoisted - * to presigned request's query string. If not supplied, the presigner - * moves all the AWS-specific headers (starting with `x-amz-`) to the request - * query string. If supplied, these headers remain in the presigned request's - * header. - * All headers in the provided request will have their names converted to - * lower case and then checked for existence in the unhoistableHeaders set. - */ - unhoistableHeaders?: Set; -} - -/** - * @public - */ -export interface EventSigningArguments extends SigningArguments { - priorSignature: string; -} - -/** - * @public - */ -export interface RequestPresigner { - /** - * Signs a request for future use. - * - * The request will be valid until either the provided `expiration` time has - * passed or the underlying credentials have expired. - * - * @param requestToSign - The request that should be signed. - * @param options - Additional signing options. - */ - presign(requestToSign: HttpRequest, options?: RequestPresigningArguments): Promise; -} - -/** - * @public - * - * An object that signs request objects with AWS credentials using one of the - * AWS authentication protocols. - */ -export interface RequestSigner { - /** - * Sign the provided request for immediate dispatch. - */ - sign(requestToSign: HttpRequest, options?: RequestSigningArguments): Promise; -} - -/** - * @public - */ -export interface StringSigner { - /** - * Sign the provided `stringToSign` for use outside of the context of - * request signing. Typical uses include signed policy generation. - */ - sign(stringToSign: string, options?: SigningArguments): Promise; -} - -/** - * @public - */ -export interface FormattedEvent { - headers: Uint8Array; - payload: Uint8Array; -} -/** - * @public - */ -export interface EventSigner { - /** - * Sign the individual event of the event stream. - */ - sign(event: FormattedEvent, options: EventSigningArguments): Promise; -} - -/** - * @public - */ -export interface SignableMessage { - message: Message; - - priorSignature: string; -} - -/** - * @public - */ -export interface SignedMessage { - message: Message; - - signature: string; -} - -/** - * @public - */ -export interface MessageSigner { - signMessage(message: SignableMessage, args: SigningArguments): Promise; - sign(event: SignableMessage, options: SigningArguments): Promise; -} +export { + DateInput, + EventSigner, + EventSigningArguments, + FormattedEvent, + MessageSigner, + RequestSigningArguments, + RequestPresigner, + RequestPresigningArguments, + RequestSigner, + SignableMessage, + SignedMessage, + SigningArguments, + StringSigner, +} from "@smithy/types"; diff --git a/packages/types/src/stream.ts b/packages/types/src/stream.ts index 375f09a5f4dd..9092844a60fe 100644 --- a/packages/types/src/stream.ts +++ b/packages/types/src/stream.ts @@ -1,24 +1 @@ -import { ChecksumConstructor } from "./checksum"; -import { HashConstructor, StreamHasher } from "./crypto"; -import { BodyLengthCalculator, Encoder } from "./util"; - -/** - * @public - */ -export interface GetAwsChunkedEncodingStreamOptions { - base64Encoder?: Encoder; - bodyLengthChecker: BodyLengthCalculator; - checksumAlgorithmFn?: ChecksumConstructor | HashConstructor; - checksumLocationName?: string; - streamHasher?: StreamHasher; -} - -/** - * @public - * - * A function that returns Readable Stream which follows aws-chunked encoding stream. - * It optionally adds checksum if options are provided. - */ -export interface GetAwsChunkedEncodingStream { - (readableStream: StreamType, options: GetAwsChunkedEncodingStreamOptions): StreamType; -} +export { GetAwsChunkedEncodingStream, GetAwsChunkedEncodingStreamOptions } from "@smithy/types"; diff --git a/packages/types/src/transfer.ts b/packages/types/src/transfer.ts index b1eefe81b8ef..04a7f87a889e 100644 --- a/packages/types/src/transfer.ts +++ b/packages/types/src/transfer.ts @@ -1,37 +1,7 @@ -/** - * @public - */ -export type RequestHandlerOutput = { response: ResponseType }; - -/** - * @public - */ -export interface RequestHandler { - /** - * metadata contains information of a handler. For example - * 'h2' refers this handler is for handling HTTP/2 requests, - * whereas 'h1' refers handling HTTP1 requests - */ - metadata?: RequestHandlerMetadata; - destroy?: () => void; - handle: (request: RequestType, handlerOptions?: HandlerOptions) => Promise>; -} - -/** - * @public - */ -export interface RequestHandlerMetadata { - handlerProtocol: RequestHandlerProtocol | string; -} - -// Values from ALPN Protocol IDs -// https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids -export enum RequestHandlerProtocol { - HTTP_0_9 = "http/0.9", - HTTP_1_0 = "http/1.0", - TDS_8_0 = "tds/8.0", -} - -export interface RequestContext { - destination: URL; -} +export { + RequestContext, + RequestHandler, + RequestHandlerMetadata, + RequestHandlerOutput, + RequestHandlerProtocol, +} from "@smithy/types"; diff --git a/packages/types/src/uri.ts b/packages/types/src/uri.ts index 3aff9296a3f5..297dfe46ca84 100644 --- a/packages/types/src/uri.ts +++ b/packages/types/src/uri.ts @@ -1,18 +1 @@ -import { QueryParameterBag } from "./http"; - -/** - * @internal - * - * Represents the components parts of a Uniform Resource Identifier used to - * construct the target location of a Request. - */ -export type URI = { - protocol: string; - hostname: string; - port?: number; - path: string; - query?: QueryParameterBag; - username?: string; - password?: string; - fragment?: string; -}; +export { URI } from "@smithy/types"; diff --git a/packages/types/src/util.ts b/packages/types/src/util.ts index 32cdf49a2737..e7e43e620c43 100644 --- a/packages/types/src/util.ts +++ b/packages/types/src/util.ts @@ -1,168 +1,14 @@ -import { Endpoint } from "./http"; -import { FinalizeHandler, FinalizeHandlerArguments, FinalizeHandlerOutput } from "./middleware"; -import { MetadataBearer } from "./response"; - -/** - * @public - * - * A function that, given a TypedArray of bytes, can produce a string - * representation thereof. - * - * @example An encoder function that converts bytes to hexadecimal - * representation would return `'deadbeef'` when given - * `new Uint8Array([0xde, 0xad, 0xbe, 0xef])`. - */ -export interface Encoder { - (input: Uint8Array): string; -} - -/** - * @public - * - * A function that, given a string, can derive the bytes represented by that - * string. - * - * @example A decoder function that converts bytes to hexadecimal - * representation would return `new Uint8Array([0xde, 0xad, 0xbe, 0xef])` when - * given the string `'deadbeef'`. - */ -export interface Decoder { - (input: string): Uint8Array; -} - -/** - * @public - * - * A function that, when invoked, returns a promise that will be fulfilled with - * a value of type T. - * - * @example A function that reads credentials from shared SDK configuration - * files, assuming roles and collecting MFA tokens as necessary. - */ -export interface Provider { - (): Promise; -} - -/** - * @public - * - * A function that, when invoked, returns a promise that will be fulfilled with - * a value of type T. It memoizes the result from the previous invocation - * instead of calling the underlying resources every time. - * - * You can force the provider to refresh the memoized value by invoke the - * function with optional parameter hash with `forceRefresh` boolean key and - * value `true`. - * - * @example A function that reads credentials from IMDS service that could - * return expired credentials. The SDK will keep using the expired credentials - * until an unretryable service error requiring a force refresh of the - * credentials. - */ -export interface MemoizedProvider { - (options?: { forceRefresh?: boolean }): Promise; -} - -/** - * @public - * - * A function that, given a request body, determines the - * length of the body. This is used to determine the Content-Length - * that should be sent with a request. - * - * @example A function that reads a file stream and calculates - * the size of the file. - */ -export interface BodyLengthCalculator { - (body: any): number | undefined; -} - -/** - * @public - * - * Interface that specifies the retry behavior - */ -export interface RetryStrategy { - /** - * The retry mode describing how the retry strategy control the traffic flow. - */ - mode?: string; - /** - * the retry behavior the will invoke the next handler and handle the retry accordingly. - * This function should also update the $metadata from the response accordingly. - * @see {@link ResponseMetadata} - */ - retry: ( - next: FinalizeHandler, - args: FinalizeHandlerArguments - ) => Promise>; -} - -/** - * @public - * - * Parses a URL in string form into an Endpoint object. - */ -export interface UrlParser { - (url: string | URL): Endpoint; -} - -/** - * @public - * - * Object containing regionalization information of - * AWS services. - */ -export interface RegionInfo { - hostname: string; - partition: string; - path?: string; - signingService?: string; - signingRegion?: string; -} - -/** - * @public - * - * Options to pass when calling {@link RegionInfoProvider} - */ -export interface RegionInfoProviderOptions { - /** - * Enables IPv6/IPv4 dualstack endpoint. - * @defaultValue false - */ - useDualstackEndpoint: boolean; - /** - * Enables FIPS compatible endpoints. - * @defaultValue false - */ - useFipsEndpoint: boolean; -} - -/** - * @public - * - * Function returns designated service's regionalization - * information from given region. Each service client - * comes with its regionalization provider. it serves - * to provide the default values of related configurations - */ -export interface RegionInfoProvider { - (region: string, options?: RegionInfoProviderOptions): Promise; -} - -/** - * @public - * - * A tuple that represents an API name and optional version - * of a library built using the AWS SDK. - */ -export type UserAgentPair = [name: string, version?: string]; - -/** - * @public - * - * User agent data that to be put into the request's user - * agent. - */ -export type UserAgent = UserAgentPair[]; +export { + Encoder, + Decoder, + Provider, + UserAgentPair, + UserAgent, + UrlParser, + MemoizedProvider, + BodyLengthCalculator, + RegionInfo, + RegionInfoProviderOptions, + RegionInfoProvider, + RetryStrategy, +} from "@smithy/types"; diff --git a/packages/types/src/waiter.ts b/packages/types/src/waiter.ts index 146954da18eb..bb98020d94e0 100644 --- a/packages/types/src/waiter.ts +++ b/packages/types/src/waiter.ts @@ -1,41 +1 @@ -import { AbortController } from "./abort"; - -/** - * @public - */ -export interface WaiterConfiguration { - /** - * Required service client - */ - client: Client; - - /** - * The amount of time in seconds a user is willing to wait for a waiter to complete. - */ - maxWaitTime: number; - - /** - * @deprecated Use abortSignal - * Abort controller. Used for ending the waiter early. - */ - abortController?: AbortController; - - /** - * Abort Signal. Used for ending the waiter early. - */ - abortSignal?: AbortController["signal"]; - - /** - * The minimum amount of time to delay between retries in seconds. This is the - * floor of the exponential backoff. This value defaults to service default - * if not specified. This value MUST be less than or equal to maxDelay and greater than 0. - */ - minDelay?: number; - - /** - * The maximum amount of time to delay between retries in seconds. This is the - * ceiling of the exponential backoff. This value defaults to service default - * if not specified. If specified, this value MUST be greater than or equal to 1. - */ - maxDelay?: number; -} +export { WaiterConfiguration } from "@smithy/types";