From d07b0aba6f02b47d391001327d95ee9a3b4bbf2e Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 15 Oct 2024 12:34:33 -0400 Subject: [PATCH] chore: feature detection for gzip and endpoint override (#1429) * chore: feature detection for gzip and endpoint override * reorganize core upstream of smithy-client * update lockfile * reorganize core and smithy-client --- .changeset/silent-rockets-turn.md | 7 ++ .changeset/unlucky-books-think.md | 8 ++ packages/core/package.json | 13 ++- packages/core/protocols.d.ts | 7 ++ packages/core/protocols.js | 6 + packages/core/src/index.ts | 7 +- .../getHttpAuthSchemeEndpointRuleSetPlugin.ts | 3 +- .../getHttpSigningMiddleware.ts | 3 +- packages/core/src/protocols/requestBuilder.ts | 107 +---------------- .../core/src/submodules/cbor/parseCborBody.ts | 2 +- .../protocols}/collect-stream-body.spec.ts | 0 .../protocols/collect-stream-body.ts | 26 +++++ .../extended-encode-uri-component.spec.ts | 0 .../extended-encode-uri-component.ts | 11 ++ .../core/src/submodules/protocols/index.ts | 4 + .../protocols/requestBuilder.spec.ts | 0 .../submodules/protocols/requestBuilder.ts | 108 ++++++++++++++++++ .../src/submodules/protocols/resolve-path.ts | 32 ++++++ packages/core/tsconfig.cjs.json | 3 +- packages/core/tsconfig.es.json | 3 +- packages/core/tsconfig.types.json | 3 +- packages/middleware-compression/package.json | 1 + .../src/compressionMiddleware.ts | 11 +- packages/middleware-endpoint/package.json | 1 + .../src/endpointMiddleware.ts | 5 + packages/smithy-client/package.json | 1 + .../smithy-client/src/collect-stream-body.ts | 25 +--- .../src/extended-encode-uri-component.ts | 10 +- packages/smithy-client/src/resolve-path.ts | 31 +---- yarn.lock | 7 +- 30 files changed, 262 insertions(+), 183 deletions(-) create mode 100644 .changeset/silent-rockets-turn.md create mode 100644 .changeset/unlucky-books-think.md create mode 100644 packages/core/protocols.d.ts create mode 100644 packages/core/protocols.js rename packages/{smithy-client/src => core/src/submodules/protocols}/collect-stream-body.spec.ts (100%) create mode 100644 packages/core/src/submodules/protocols/collect-stream-body.ts rename packages/{smithy-client/src => core/src/submodules/protocols}/extended-encode-uri-component.spec.ts (100%) create mode 100644 packages/core/src/submodules/protocols/extended-encode-uri-component.ts create mode 100644 packages/core/src/submodules/protocols/index.ts rename packages/core/src/{ => submodules}/protocols/requestBuilder.spec.ts (100%) create mode 100644 packages/core/src/submodules/protocols/requestBuilder.ts create mode 100644 packages/core/src/submodules/protocols/resolve-path.ts diff --git a/.changeset/silent-rockets-turn.md b/.changeset/silent-rockets-turn.md new file mode 100644 index 00000000000..48e641f55df --- /dev/null +++ b/.changeset/silent-rockets-turn.md @@ -0,0 +1,7 @@ +--- +"@smithy/middleware-compression": minor +"@smithy/middleware-endpoint": minor +"@smithy/core": minor +--- + +feature detection for custom endpoint and gzip diff --git a/.changeset/unlucky-books-think.md b/.changeset/unlucky-books-think.md new file mode 100644 index 00000000000..2326019b704 --- /dev/null +++ b/.changeset/unlucky-books-think.md @@ -0,0 +1,8 @@ +--- +"@smithy/middleware-compression": patch +"@smithy/middleware-endpoint": patch +"@smithy/smithy-client": patch +"@smithy/core": patch +--- + +reorganize smithy/core to be upstream of smithy/smithy-client diff --git a/packages/core/package.json b/packages/core/package.json index 00682e53ab9..35d1444f271 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -37,6 +37,13 @@ "import": "./dist-es/submodules/cbor/index.js", "require": "./dist-cjs/submodules/cbor/index.js", "types": "./dist-types/submodules/cbor/index.d.ts" + }, + "./protocols": { + "module": "./dist-es/submodules/protocols/index.js", + "node": "./dist-cjs/submodules/protocols/index.js", + "import": "./dist-es/submodules/protocols/index.js", + "require": "./dist-cjs/submodules/protocols/index.js", + "types": "./dist-types/submodules/protocols/index.d.ts" } }, "author": { @@ -46,14 +53,12 @@ }, "license": "Apache-2.0", "dependencies": { - "@smithy/middleware-endpoint": "workspace:^", - "@smithy/middleware-retry": "workspace:^", "@smithy/middleware-serde": "workspace:^", "@smithy/protocol-http": "workspace:^", - "@smithy/smithy-client": "workspace:^", "@smithy/types": "workspace:^", "@smithy/util-body-length-browser": "workspace:^", "@smithy/util-middleware": "workspace:^", + "@smithy/util-stream": "workspace:^", "@smithy/util-utf8": "workspace:^", "tslib": "^2.6.2" }, @@ -70,6 +75,8 @@ "files": [ "./cbor.d.ts", "./cbor.js", + "./protocols.d.ts", + "./protocols.js", "dist-*/**" ], "homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core", diff --git a/packages/core/protocols.d.ts b/packages/core/protocols.d.ts new file mode 100644 index 00000000000..e0afd4e85b1 --- /dev/null +++ b/packages/core/protocols.d.ts @@ -0,0 +1,7 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@smithy/core/protocols" { + export * from "@smithy/core/dist-types/submodules/protocols/index.d"; +} diff --git a/packages/core/protocols.js b/packages/core/protocols.js new file mode 100644 index 00000000000..43e0c426c44 --- /dev/null +++ b/packages/core/protocols.js @@ -0,0 +1,6 @@ + +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +module.exports = require("./dist-cjs/submodules/protocols/index.js"); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8081ce9db1e..1dcdba11994 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,7 +1,8 @@ +export * from "./getSmithyContext"; export * from "./middleware-http-auth-scheme"; export * from "./middleware-http-signing"; -export * from "./util-identity-and-auth"; -export * from "./getSmithyContext"; export * from "./normalizeProvider"; -export * from "./protocols/requestBuilder"; export { createPaginator } from "./pagination/createPaginator"; +export * from "./protocols/requestBuilder"; +export * from "./setFeature"; +export * from "./util-identity-and-auth"; diff --git a/packages/core/src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts b/packages/core/src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts index 4bea7d6048d..dad45ffc170 100644 --- a/packages/core/src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts +++ b/packages/core/src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts @@ -1,4 +1,3 @@ -import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint"; import { HandlerExecutionContext, HttpAuthSchemeParameters, @@ -20,7 +19,7 @@ export const httpAuthSchemeEndpointRuleSetMiddlewareOptions: SerializeHandlerOpt name: "httpAuthSchemeMiddleware", override: true, relation: "before", - toMiddleware: endpointMiddlewareOptions.name!, + toMiddleware: "endpointV2Middleware", }; /** diff --git a/packages/core/src/middleware-http-signing/getHttpSigningMiddleware.ts b/packages/core/src/middleware-http-signing/getHttpSigningMiddleware.ts index 1f167e8202b..396b22d88a6 100644 --- a/packages/core/src/middleware-http-signing/getHttpSigningMiddleware.ts +++ b/packages/core/src/middleware-http-signing/getHttpSigningMiddleware.ts @@ -1,4 +1,3 @@ -import { retryMiddlewareOptions } from "@smithy/middleware-retry"; import { FinalizeRequestHandlerOptions, Pluggable, RelativeMiddlewareOptions } from "@smithy/types"; import { httpSigningMiddleware } from "./httpSigningMiddleware"; @@ -13,7 +12,7 @@ export const httpSigningMiddlewareOptions: FinalizeRequestHandlerOptions & Relat aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"], override: true, relation: "after", - toMiddleware: retryMiddlewareOptions.name!, + toMiddleware: "retryMiddleware", }; /** diff --git a/packages/core/src/protocols/requestBuilder.ts b/packages/core/src/protocols/requestBuilder.ts index 7abd252f00f..8e2f2effcd0 100644 --- a/packages/core/src/protocols/requestBuilder.ts +++ b/packages/core/src/protocols/requestBuilder.ts @@ -1,108 +1,5 @@ -import { HttpRequest } from "@smithy/protocol-http"; -import { resolvedPath } from "@smithy/smithy-client"; -import type { SerdeContext } from "@smithy/types"; - /** * @internal - * used in code-generated serde. + * Backwards compatibility re-export. */ -export function requestBuilder(input: any, context: SerdeContext): RequestBuilder { - return new RequestBuilder(input, context); -} - -/** - * @internal - */ -export class RequestBuilder { - private query: Record = {}; - private method = ""; - private headers: Record = {}; - private path = ""; - private body: any = null; - private hostname = ""; - - private resolvePathStack: Array<(path: string) => void> = []; - - public constructor( - private input: any, - private context: SerdeContext - ) {} - - public async build() { - const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint(); - this.path = basePath; - for (const resolvePath of this.resolvePathStack) { - resolvePath(this.path); - } - return new HttpRequest({ - protocol, - hostname: this.hostname || hostname, - port, - method: this.method, - path: this.path, - query: this.query, - body: this.body, - headers: this.headers, - }); - } - - /** - * Brevity setter for "hostname". - */ - public hn(hostname: string) { - this.hostname = hostname; - return this; - } - - /** - * Brevity initial builder for "basepath". - */ - public bp(uriLabel: string) { - this.resolvePathStack.push((basePath: string) => { - this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel; - }); - return this; - } - - /** - * Brevity incremental builder for "path". - */ - public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) { - this.resolvePathStack.push((path: string) => { - this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel); - }); - return this; - } - - /** - * Brevity setter for "headers". - */ - public h(headers: Record) { - this.headers = headers; - return this; - } - - /** - * Brevity setter for "query". - */ - public q(query: Record) { - this.query = query; - return this; - } - - /** - * Brevity setter for "body". - */ - public b(body: any) { - this.body = body; - return this; - } - - /** - * Brevity setter for "method". - */ - public m(method: string) { - this.method = method; - return this; - } -} +export { requestBuilder } from "@smithy/core/protocols"; diff --git a/packages/core/src/submodules/cbor/parseCborBody.ts b/packages/core/src/submodules/cbor/parseCborBody.ts index 32bbe0b7ba5..40cc72302f0 100644 --- a/packages/core/src/submodules/cbor/parseCborBody.ts +++ b/packages/core/src/submodules/cbor/parseCborBody.ts @@ -1,5 +1,5 @@ +import { collectBody } from "@smithy/core/protocols"; import { HttpRequest as __HttpRequest } from "@smithy/protocol-http"; -import { collectBody } from "@smithy/smithy-client"; import { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types"; import { calculateBodyLength } from "@smithy/util-body-length-browser"; diff --git a/packages/smithy-client/src/collect-stream-body.spec.ts b/packages/core/src/submodules/protocols/collect-stream-body.spec.ts similarity index 100% rename from packages/smithy-client/src/collect-stream-body.spec.ts rename to packages/core/src/submodules/protocols/collect-stream-body.spec.ts diff --git a/packages/core/src/submodules/protocols/collect-stream-body.ts b/packages/core/src/submodules/protocols/collect-stream-body.ts new file mode 100644 index 00000000000..a20b5211b5e --- /dev/null +++ b/packages/core/src/submodules/protocols/collect-stream-body.ts @@ -0,0 +1,26 @@ +import { SerdeContext } from "@smithy/types"; +import { Uint8ArrayBlobAdapter } from "@smithy/util-stream"; + +/** + * @internal + * + * Collect low-level response body stream to Uint8Array. + */ +export const collectBody = async ( + streamBody: any = new Uint8Array(), + context: { + streamCollector: SerdeContext["streamCollector"]; + } +): Promise => { + if (streamBody instanceof Uint8Array) { + return Uint8ArrayBlobAdapter.mutate(streamBody); + } + + if (!streamBody) { + return Uint8ArrayBlobAdapter.mutate(new Uint8Array()); + } + + const fromContext = context.streamCollector(streamBody); + + return Uint8ArrayBlobAdapter.mutate(await fromContext); +}; diff --git a/packages/smithy-client/src/extended-encode-uri-component.spec.ts b/packages/core/src/submodules/protocols/extended-encode-uri-component.spec.ts similarity index 100% rename from packages/smithy-client/src/extended-encode-uri-component.spec.ts rename to packages/core/src/submodules/protocols/extended-encode-uri-component.spec.ts diff --git a/packages/core/src/submodules/protocols/extended-encode-uri-component.ts b/packages/core/src/submodules/protocols/extended-encode-uri-component.ts new file mode 100644 index 00000000000..367d35b087e --- /dev/null +++ b/packages/core/src/submodules/protocols/extended-encode-uri-component.ts @@ -0,0 +1,11 @@ +/** + * @internal + * + * Function that wraps encodeURIComponent to encode additional characters + * to fully adhere to RFC 3986. + */ +export function extendedEncodeURIComponent(str: string): string { + return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { + return "%" + c.charCodeAt(0).toString(16).toUpperCase(); + }); +} diff --git a/packages/core/src/submodules/protocols/index.ts b/packages/core/src/submodules/protocols/index.ts new file mode 100644 index 00000000000..a5de22f1a4a --- /dev/null +++ b/packages/core/src/submodules/protocols/index.ts @@ -0,0 +1,4 @@ +export * from "./collect-stream-body"; +export * from "./extended-encode-uri-component"; +export * from "./requestBuilder"; +export * from "./resolve-path"; diff --git a/packages/core/src/protocols/requestBuilder.spec.ts b/packages/core/src/submodules/protocols/requestBuilder.spec.ts similarity index 100% rename from packages/core/src/protocols/requestBuilder.spec.ts rename to packages/core/src/submodules/protocols/requestBuilder.spec.ts diff --git a/packages/core/src/submodules/protocols/requestBuilder.ts b/packages/core/src/submodules/protocols/requestBuilder.ts new file mode 100644 index 00000000000..c6d2dfc7e83 --- /dev/null +++ b/packages/core/src/submodules/protocols/requestBuilder.ts @@ -0,0 +1,108 @@ +import { resolvedPath } from "@smithy/core/protocols"; +import { HttpRequest } from "@smithy/protocol-http"; +import type { SerdeContext } from "@smithy/types"; + +/** + * @internal + * used in code-generated serde. + */ +export function requestBuilder(input: any, context: SerdeContext): RequestBuilder { + return new RequestBuilder(input, context); +} + +/** + * @internal + */ +export class RequestBuilder { + private query: Record = {}; + private method = ""; + private headers: Record = {}; + private path = ""; + private body: any = null; + private hostname = ""; + + private resolvePathStack: Array<(path: string) => void> = []; + + public constructor( + private input: any, + private context: SerdeContext + ) {} + + public async build() { + const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint(); + this.path = basePath; + for (const resolvePath of this.resolvePathStack) { + resolvePath(this.path); + } + return new HttpRequest({ + protocol, + hostname: this.hostname || hostname, + port, + method: this.method, + path: this.path, + query: this.query, + body: this.body, + headers: this.headers, + }); + } + + /** + * Brevity setter for "hostname". + */ + public hn(hostname: string) { + this.hostname = hostname; + return this; + } + + /** + * Brevity initial builder for "basepath". + */ + public bp(uriLabel: string) { + this.resolvePathStack.push((basePath: string) => { + this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel; + }); + return this; + } + + /** + * Brevity incremental builder for "path". + */ + public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) { + this.resolvePathStack.push((path: string) => { + this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel); + }); + return this; + } + + /** + * Brevity setter for "headers". + */ + public h(headers: Record) { + this.headers = headers; + return this; + } + + /** + * Brevity setter for "query". + */ + public q(query: Record) { + this.query = query; + return this; + } + + /** + * Brevity setter for "body". + */ + public b(body: any) { + this.body = body; + return this; + } + + /** + * Brevity setter for "method". + */ + public m(method: string) { + this.method = method; + return this; + } +} diff --git a/packages/core/src/submodules/protocols/resolve-path.ts b/packages/core/src/submodules/protocols/resolve-path.ts new file mode 100644 index 00000000000..53a86bb198d --- /dev/null +++ b/packages/core/src/submodules/protocols/resolve-path.ts @@ -0,0 +1,32 @@ +import { extendedEncodeURIComponent } from "./extended-encode-uri-component"; + +/** + * @internal + */ +export const resolvedPath = ( + resolvedPath: string, + input: unknown, + memberName: string, + labelValueProvider: () => string | undefined, + uriLabel: string, + isGreedyLabel: boolean +): string => { + if (input != null && (input as Record)[memberName] !== undefined) { + const labelValue = labelValueProvider() as string; + if (labelValue.length <= 0) { + throw new Error("Empty value provided for input HTTP label: " + memberName + "."); + } + resolvedPath = resolvedPath.replace( + uriLabel, + isGreedyLabel + ? labelValue + .split("/") + .map((segment) => extendedEncodeURIComponent(segment)) + .join("/") + : extendedEncodeURIComponent(labelValue) + ); + } else { + throw new Error("No value provided for input HTTP label: " + memberName + "."); + } + return resolvedPath; +}; diff --git a/packages/core/tsconfig.cjs.json b/packages/core/tsconfig.cjs.json index 369e51b86bc..fea7954e681 100644 --- a/packages/core/tsconfig.cjs.json +++ b/packages/core/tsconfig.cjs.json @@ -4,7 +4,8 @@ "outDir": "dist-cjs", "rootDir": "src", "paths": { - "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"] + "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"], + "@smithy/core/protocols": ["./src/submodules/protocols/index.ts"] } }, "extends": "../../tsconfig.cjs.json", diff --git a/packages/core/tsconfig.es.json b/packages/core/tsconfig.es.json index 310918c39d3..0519270a909 100644 --- a/packages/core/tsconfig.es.json +++ b/packages/core/tsconfig.es.json @@ -5,7 +5,8 @@ "outDir": "dist-es", "rootDir": "src", "paths": { - "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"] + "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"], + "@smithy/core/protocols": ["./src/submodules/protocols/index.ts"] } }, "extends": "../../tsconfig.es.json", diff --git a/packages/core/tsconfig.types.json b/packages/core/tsconfig.types.json index a50f3dbebad..3ebde5c3ede 100644 --- a/packages/core/tsconfig.types.json +++ b/packages/core/tsconfig.types.json @@ -4,7 +4,8 @@ "declarationDir": "dist-types", "rootDir": "src", "paths": { - "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"] + "@smithy/core/cbor": ["./src/submodules/cbor/index.ts"], + "@smithy/core/protocols": ["./src/submodules/protocols/index.ts"] } }, "extends": "../../tsconfig.types.json", diff --git a/packages/middleware-compression/package.json b/packages/middleware-compression/package.json index 6392a56f1fb..cd2f1a4d529 100644 --- a/packages/middleware-compression/package.json +++ b/packages/middleware-compression/package.json @@ -15,6 +15,7 @@ "main": "./dist-cjs/index.js", "module": "./dist-es/index.js", "dependencies": { + "@smithy/core": "workspace:^", "@smithy/is-array-buffer": "workspace:^", "@smithy/node-config-provider": "workspace:^", "@smithy/protocol-http": "workspace:^", diff --git a/packages/middleware-compression/src/compressionMiddleware.ts b/packages/middleware-compression/src/compressionMiddleware.ts index 13f810537c7..8063fbc5ead 100644 --- a/packages/middleware-compression/src/compressionMiddleware.ts +++ b/packages/middleware-compression/src/compressionMiddleware.ts @@ -1,3 +1,4 @@ +import { setFeature } from "@smithy/core"; import { HttpRequest } from "@smithy/protocol-http"; import { AbsoluteLocation, @@ -6,6 +7,7 @@ import { BuildHandlerOptions, BuildHandlerOutput, BuildMiddleware, + HandlerExecutionContext, MetadataBearer, } from "@smithy/types"; @@ -39,7 +41,10 @@ export const compressionMiddleware = config: CompressionResolvedConfig & CompressionPreviouslyResolved, middlewareConfig: CompressionMiddlewareConfig ): BuildMiddleware => - (next: BuildHandler): BuildHandler => + ( + next: BuildHandler, + context: HandlerExecutionContext + ): BuildHandler => async (args: BuildHandlerArguments): Promise> => { if (!HttpRequest.isInstance(args.request)) { return next(args); @@ -88,6 +93,10 @@ export const compressionMiddleware = updatedHeaders = { ...headers, "content-encoding": algorithm }; } + if (updatedHeaders["content-encoding"].includes("gzip")) { + setFeature(context, "GZIP_REQUEST_COMPRESSION", "L"); + } + // We've matched on one supported algorithm in the // priority-ordered list, so we're finished. break; diff --git a/packages/middleware-endpoint/package.json b/packages/middleware-endpoint/package.json index cd66a3f20a3..d39a336b695 100644 --- a/packages/middleware-endpoint/package.json +++ b/packages/middleware-endpoint/package.json @@ -23,6 +23,7 @@ }, "license": "Apache-2.0", "dependencies": { + "@smithy/core": "workspace:^", "@smithy/middleware-serde": "workspace:^", "@smithy/node-config-provider": "workspace:^", "@smithy/shared-ini-file-loader": "workspace:^", diff --git a/packages/middleware-endpoint/src/endpointMiddleware.ts b/packages/middleware-endpoint/src/endpointMiddleware.ts index e4c4202e754..c84c4aa6feb 100644 --- a/packages/middleware-endpoint/src/endpointMiddleware.ts +++ b/packages/middleware-endpoint/src/endpointMiddleware.ts @@ -1,3 +1,4 @@ +import { setFeature } from "@smithy/core"; import { AuthScheme, EndpointParameters, @@ -38,6 +39,10 @@ export const endpointMiddleware = ({ context: HandlerExecutionContext ): SerializeHandler => async (args: SerializeHandlerArguments): Promise> => { + if (config.endpoint) { + setFeature(context, "ENDPOINT_OVERRIDE", "N"); + } + const endpoint: EndpointV2 = await getEndpointFromInstructions( args.input, { diff --git a/packages/smithy-client/package.json b/packages/smithy-client/package.json index 1e5c599d9c8..e926390986f 100644 --- a/packages/smithy-client/package.json +++ b/packages/smithy-client/package.json @@ -23,6 +23,7 @@ }, "license": "Apache-2.0", "dependencies": { + "@smithy/core": "workspace:^", "@smithy/middleware-endpoint": "workspace:^", "@smithy/middleware-stack": "workspace:^", "@smithy/protocol-http": "workspace:^", diff --git a/packages/smithy-client/src/collect-stream-body.ts b/packages/smithy-client/src/collect-stream-body.ts index a20b5211b5e..33378b80af3 100644 --- a/packages/smithy-client/src/collect-stream-body.ts +++ b/packages/smithy-client/src/collect-stream-body.ts @@ -1,26 +1,5 @@ -import { SerdeContext } from "@smithy/types"; -import { Uint8ArrayBlobAdapter } from "@smithy/util-stream"; - /** * @internal - * - * Collect low-level response body stream to Uint8Array. + * Backwards compatibility re-export. */ -export const collectBody = async ( - streamBody: any = new Uint8Array(), - context: { - streamCollector: SerdeContext["streamCollector"]; - } -): Promise => { - if (streamBody instanceof Uint8Array) { - return Uint8ArrayBlobAdapter.mutate(streamBody); - } - - if (!streamBody) { - return Uint8ArrayBlobAdapter.mutate(new Uint8Array()); - } - - const fromContext = context.streamCollector(streamBody); - - return Uint8ArrayBlobAdapter.mutate(await fromContext); -}; +export { collectBody } from "@smithy/core/protocols"; diff --git a/packages/smithy-client/src/extended-encode-uri-component.ts b/packages/smithy-client/src/extended-encode-uri-component.ts index 367d35b087e..ced666a6491 100644 --- a/packages/smithy-client/src/extended-encode-uri-component.ts +++ b/packages/smithy-client/src/extended-encode-uri-component.ts @@ -1,11 +1,5 @@ /** * @internal - * - * Function that wraps encodeURIComponent to encode additional characters - * to fully adhere to RFC 3986. + * Backwards compatibility re-export. */ -export function extendedEncodeURIComponent(str: string): string { - return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { - return "%" + c.charCodeAt(0).toString(16).toUpperCase(); - }); -} +export { extendedEncodeURIComponent } from "@smithy/core/protocols"; diff --git a/packages/smithy-client/src/resolve-path.ts b/packages/smithy-client/src/resolve-path.ts index 53a86bb198d..2a3204fc943 100644 --- a/packages/smithy-client/src/resolve-path.ts +++ b/packages/smithy-client/src/resolve-path.ts @@ -1,32 +1,5 @@ -import { extendedEncodeURIComponent } from "./extended-encode-uri-component"; - /** * @internal + * Backwards compatibility re-export. */ -export const resolvedPath = ( - resolvedPath: string, - input: unknown, - memberName: string, - labelValueProvider: () => string | undefined, - uriLabel: string, - isGreedyLabel: boolean -): string => { - if (input != null && (input as Record)[memberName] !== undefined) { - const labelValue = labelValueProvider() as string; - if (labelValue.length <= 0) { - throw new Error("Empty value provided for input HTTP label: " + memberName + "."); - } - resolvedPath = resolvedPath.replace( - uriLabel, - isGreedyLabel - ? labelValue - .split("/") - .map((segment) => extendedEncodeURIComponent(segment)) - .join("/") - : extendedEncodeURIComponent(labelValue) - ); - } else { - throw new Error("No value provided for input HTTP label: " + memberName + "."); - } - return resolvedPath; -}; +export { resolvedPath } from "@smithy/core/protocols"; diff --git a/yarn.lock b/yarn.lock index c79df3326c8..d5f30deb4ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2270,14 +2270,12 @@ __metadata: version: 0.0.0-use.local resolution: "@smithy/core@workspace:packages/core" dependencies: - "@smithy/middleware-endpoint": "workspace:^" - "@smithy/middleware-retry": "workspace:^" "@smithy/middleware-serde": "workspace:^" "@smithy/protocol-http": "workspace:^" - "@smithy/smithy-client": "workspace:^" "@smithy/types": "workspace:^" "@smithy/util-body-length-browser": "workspace:^" "@smithy/util-middleware": "workspace:^" + "@smithy/util-stream": "workspace:^" "@smithy/util-utf8": "workspace:^" "@types/node": ^16.18.96 concurrently: 7.0.0 @@ -2541,6 +2539,7 @@ __metadata: version: 0.0.0-use.local resolution: "@smithy/middleware-compression@workspace:packages/middleware-compression" dependencies: + "@smithy/core": "workspace:^" "@smithy/is-array-buffer": "workspace:^" "@smithy/node-config-provider": "workspace:^" "@smithy/protocol-http": "workspace:^" @@ -2576,6 +2575,7 @@ __metadata: version: 0.0.0-use.local resolution: "@smithy/middleware-endpoint@workspace:packages/middleware-endpoint" dependencies: + "@smithy/core": "workspace:^" "@smithy/middleware-serde": "workspace:^" "@smithy/node-config-provider": "workspace:^" "@smithy/shared-ini-file-loader": "workspace:^" @@ -2788,6 +2788,7 @@ __metadata: version: 0.0.0-use.local resolution: "@smithy/smithy-client@workspace:packages/smithy-client" dependencies: + "@smithy/core": "workspace:^" "@smithy/middleware-endpoint": "workspace:^" "@smithy/middleware-stack": "workspace:^" "@smithy/protocol-http": "workspace:^"