Skip to content

Commit 1b4b11c

Browse files
committed
reorganize core upstream of smithy-client
1 parent ba2b4d0 commit 1b4b11c

16 files changed

+96
-72
lines changed

.changeset/unlucky-books-think.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@smithy/middleware-compression": patch
3+
"@smithy/middleware-endpoint": patch
4+
"@smithy/smithy-client": patch
5+
"@smithy/core": patch
6+
---
7+
8+
reorganize smithy/core to be upstream of smithy/smithy-client

packages/core/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@
4646
},
4747
"license": "Apache-2.0",
4848
"dependencies": {
49-
"@smithy/middleware-endpoint": "workspace:^",
50-
"@smithy/middleware-retry": "workspace:^",
5149
"@smithy/middleware-serde": "workspace:^",
5250
"@smithy/protocol-http": "workspace:^",
53-
"@smithy/smithy-client": "workspace:^",
5451
"@smithy/types": "workspace:^",
5552
"@smithy/util-body-length-browser": "workspace:^",
5653
"@smithy/util-middleware": "workspace:^",
54+
"@smithy/util-stream": "workspace:^",
5755
"@smithy/util-utf8": "workspace:^",
5856
"tslib": "^2.6.2"
5957
},

packages/core/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
export * from "./getSmithyContext";
12
export * from "./middleware-http-auth-scheme";
23
export * from "./middleware-http-signing";
3-
export * from "./util-identity-and-auth";
4-
export * from "./getSmithyContext";
54
export * from "./normalizeProvider";
5+
export { createPaginator } from "./pagination/createPaginator";
6+
export * from "./protocols/collect-stream-body";
67
export * from "./protocols/requestBuilder";
8+
export * from "./protocols/resolve-path";
9+
export * from "./protocols/extended-encode-uri-component";
710
export * from "./setFeature";
8-
export { createPaginator } from "./pagination/createPaginator";
11+
export * from "./util-identity-and-auth";

packages/core/src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint";
21
import {
32
HandlerExecutionContext,
43
HttpAuthSchemeParameters,
@@ -20,7 +19,7 @@ export const httpAuthSchemeEndpointRuleSetMiddlewareOptions: SerializeHandlerOpt
2019
name: "httpAuthSchemeMiddleware",
2120
override: true,
2221
relation: "before",
23-
toMiddleware: endpointMiddlewareOptions.name!,
22+
toMiddleware: "endpointV2Middleware",
2423
};
2524

2625
/**

packages/core/src/middleware-http-signing/getHttpSigningMiddleware.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { retryMiddlewareOptions } from "@smithy/middleware-retry";
21
import { FinalizeRequestHandlerOptions, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
32

43
import { httpSigningMiddleware } from "./httpSigningMiddleware";
@@ -13,7 +12,7 @@ export const httpSigningMiddlewareOptions: FinalizeRequestHandlerOptions & Relat
1312
aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
1413
override: true,
1514
relation: "after",
16-
toMiddleware: retryMiddlewareOptions.name!,
15+
toMiddleware: "retryMiddleware",
1716
};
1817

1918
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { SerdeContext } from "@smithy/types";
2+
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream";
3+
4+
/**
5+
* @internal
6+
*
7+
* Collect low-level response body stream to Uint8Array.
8+
*/
9+
export const collectBody = async (
10+
streamBody: any = new Uint8Array(),
11+
context: {
12+
streamCollector: SerdeContext["streamCollector"];
13+
}
14+
): Promise<Uint8ArrayBlobAdapter> => {
15+
if (streamBody instanceof Uint8Array) {
16+
return Uint8ArrayBlobAdapter.mutate(streamBody);
17+
}
18+
19+
if (!streamBody) {
20+
return Uint8ArrayBlobAdapter.mutate(new Uint8Array());
21+
}
22+
23+
const fromContext = context.streamCollector(streamBody);
24+
25+
return Uint8ArrayBlobAdapter.mutate(await fromContext);
26+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @internal
3+
*
4+
* Function that wraps encodeURIComponent to encode additional characters
5+
* to fully adhere to RFC 3986.
6+
*/
7+
export function extendedEncodeURIComponent(str: string): string {
8+
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
9+
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
10+
});
11+
}

packages/core/src/protocols/requestBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { HttpRequest } from "@smithy/protocol-http";
2-
import { resolvedPath } from "@smithy/smithy-client";
32
import type { SerdeContext } from "@smithy/types";
43

4+
import { resolvedPath } from "./resolve-path";
5+
56
/**
67
* @internal
78
* used in code-generated serde.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";
2+
3+
/**
4+
* @internal
5+
*/
6+
export const resolvedPath = (
7+
resolvedPath: string,
8+
input: unknown,
9+
memberName: string,
10+
labelValueProvider: () => string | undefined,
11+
uriLabel: string,
12+
isGreedyLabel: boolean
13+
): string => {
14+
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
15+
const labelValue = labelValueProvider() as string;
16+
if (labelValue.length <= 0) {
17+
throw new Error("Empty value provided for input HTTP label: " + memberName + ".");
18+
}
19+
resolvedPath = resolvedPath.replace(
20+
uriLabel,
21+
isGreedyLabel
22+
? labelValue
23+
.split("/")
24+
.map((segment) => extendedEncodeURIComponent(segment))
25+
.join("/")
26+
: extendedEncodeURIComponent(labelValue)
27+
);
28+
} else {
29+
throw new Error("No value provided for input HTTP label: " + memberName + ".");
30+
}
31+
return resolvedPath;
32+
};

packages/core/src/submodules/cbor/parseCborBody.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { collectBody } from "@smithy/core";
12
import { HttpRequest as __HttpRequest } from "@smithy/protocol-http";
2-
import { collectBody } from "@smithy/smithy-client";
33
import { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types";
44
import { calculateBodyLength } from "@smithy/util-body-length-browser";
55

packages/smithy-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
},
2424
"license": "Apache-2.0",
2525
"dependencies": {
26+
"@smithy/core": "workspace:^",
2627
"@smithy/middleware-endpoint": "workspace:^",
2728
"@smithy/middleware-stack": "workspace:^",
2829
"@smithy/protocol-http": "workspace:^",
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,5 @@
1-
import { SerdeContext } from "@smithy/types";
2-
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream";
3-
41
/**
52
* @internal
6-
*
7-
* Collect low-level response body stream to Uint8Array.
3+
* Backwards compatibility re-export.
84
*/
9-
export const collectBody = async (
10-
streamBody: any = new Uint8Array(),
11-
context: {
12-
streamCollector: SerdeContext["streamCollector"];
13-
}
14-
): Promise<Uint8ArrayBlobAdapter> => {
15-
if (streamBody instanceof Uint8Array) {
16-
return Uint8ArrayBlobAdapter.mutate(streamBody);
17-
}
18-
19-
if (!streamBody) {
20-
return Uint8ArrayBlobAdapter.mutate(new Uint8Array());
21-
}
22-
23-
const fromContext = context.streamCollector(streamBody);
24-
25-
return Uint8ArrayBlobAdapter.mutate(await fromContext);
26-
};
5+
export { collectBody } from "@smithy/core";
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
/**
22
* @internal
3-
*
4-
* Function that wraps encodeURIComponent to encode additional characters
5-
* to fully adhere to RFC 3986.
3+
* Backwards compatibility re-export.
64
*/
7-
export function extendedEncodeURIComponent(str: string): string {
8-
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
9-
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
10-
});
11-
}
5+
export { extendedEncodeURIComponent } from "@smithy/core";
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
1-
import { extendedEncodeURIComponent } from "./extended-encode-uri-component";
2-
31
/**
42
* @internal
3+
* Backwards compatibility re-export.
54
*/
6-
export const resolvedPath = (
7-
resolvedPath: string,
8-
input: unknown,
9-
memberName: string,
10-
labelValueProvider: () => string | undefined,
11-
uriLabel: string,
12-
isGreedyLabel: boolean
13-
): string => {
14-
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
15-
const labelValue = labelValueProvider() as string;
16-
if (labelValue.length <= 0) {
17-
throw new Error("Empty value provided for input HTTP label: " + memberName + ".");
18-
}
19-
resolvedPath = resolvedPath.replace(
20-
uriLabel,
21-
isGreedyLabel
22-
? labelValue
23-
.split("/")
24-
.map((segment) => extendedEncodeURIComponent(segment))
25-
.join("/")
26-
: extendedEncodeURIComponent(labelValue)
27-
);
28-
} else {
29-
throw new Error("No value provided for input HTTP label: " + memberName + ".");
30-
}
31-
return resolvedPath;
32-
};
5+
export { resolvedPath } from "@smithy/core";

0 commit comments

Comments
 (0)