Skip to content

Commit d07b0ab

Browse files
authored
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
1 parent 72faecc commit d07b0ab

30 files changed

+262
-183
lines changed

.changeset/silent-rockets-turn.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@smithy/middleware-compression": minor
3+
"@smithy/middleware-endpoint": minor
4+
"@smithy/core": minor
5+
---
6+
7+
feature detection for custom endpoint and gzip

.changeset/unlucky-books-think.md

+8
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
"import": "./dist-es/submodules/cbor/index.js",
3838
"require": "./dist-cjs/submodules/cbor/index.js",
3939
"types": "./dist-types/submodules/cbor/index.d.ts"
40+
},
41+
"./protocols": {
42+
"module": "./dist-es/submodules/protocols/index.js",
43+
"node": "./dist-cjs/submodules/protocols/index.js",
44+
"import": "./dist-es/submodules/protocols/index.js",
45+
"require": "./dist-cjs/submodules/protocols/index.js",
46+
"types": "./dist-types/submodules/protocols/index.d.ts"
4047
}
4148
},
4249
"author": {
@@ -46,14 +53,12 @@
4653
},
4754
"license": "Apache-2.0",
4855
"dependencies": {
49-
"@smithy/middleware-endpoint": "workspace:^",
50-
"@smithy/middleware-retry": "workspace:^",
5156
"@smithy/middleware-serde": "workspace:^",
5257
"@smithy/protocol-http": "workspace:^",
53-
"@smithy/smithy-client": "workspace:^",
5458
"@smithy/types": "workspace:^",
5559
"@smithy/util-body-length-browser": "workspace:^",
5660
"@smithy/util-middleware": "workspace:^",
61+
"@smithy/util-stream": "workspace:^",
5762
"@smithy/util-utf8": "workspace:^",
5863
"tslib": "^2.6.2"
5964
},
@@ -70,6 +75,8 @@
7075
"files": [
7176
"./cbor.d.ts",
7277
"./cbor.js",
78+
"./protocols.d.ts",
79+
"./protocols.js",
7380
"dist-*/**"
7481
],
7582
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",

packages/core/protocols.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@smithy/core/protocols" {
6+
export * from "@smithy/core/dist-types/submodules/protocols/index.d";
7+
}

packages/core/protocols.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
/**
3+
* Do not edit:
4+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
5+
*/
6+
module.exports = require("./dist-cjs/submodules/protocols/index.js");

packages/core/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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";
6-
export * from "./protocols/requestBuilder";
75
export { createPaginator } from "./pagination/createPaginator";
6+
export * from "./protocols/requestBuilder";
7+
export * from "./setFeature";
8+
export * from "./util-identity-and-auth";

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

+1-2
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

+1-2
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
/**
+2-105
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,5 @@
1-
import { HttpRequest } from "@smithy/protocol-http";
2-
import { resolvedPath } from "@smithy/smithy-client";
3-
import type { SerdeContext } from "@smithy/types";
4-
51
/**
62
* @internal
7-
* used in code-generated serde.
3+
* Backwards compatibility re-export.
84
*/
9-
export function requestBuilder(input: any, context: SerdeContext): RequestBuilder {
10-
return new RequestBuilder(input, context);
11-
}
12-
13-
/**
14-
* @internal
15-
*/
16-
export class RequestBuilder {
17-
private query: Record<string, string> = {};
18-
private method = "";
19-
private headers: Record<string, string> = {};
20-
private path = "";
21-
private body: any = null;
22-
private hostname = "";
23-
24-
private resolvePathStack: Array<(path: string) => void> = [];
25-
26-
public constructor(
27-
private input: any,
28-
private context: SerdeContext
29-
) {}
30-
31-
public async build() {
32-
const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
33-
this.path = basePath;
34-
for (const resolvePath of this.resolvePathStack) {
35-
resolvePath(this.path);
36-
}
37-
return new HttpRequest({
38-
protocol,
39-
hostname: this.hostname || hostname,
40-
port,
41-
method: this.method,
42-
path: this.path,
43-
query: this.query,
44-
body: this.body,
45-
headers: this.headers,
46-
});
47-
}
48-
49-
/**
50-
* Brevity setter for "hostname".
51-
*/
52-
public hn(hostname: string) {
53-
this.hostname = hostname;
54-
return this;
55-
}
56-
57-
/**
58-
* Brevity initial builder for "basepath".
59-
*/
60-
public bp(uriLabel: string) {
61-
this.resolvePathStack.push((basePath: string) => {
62-
this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
63-
});
64-
return this;
65-
}
66-
67-
/**
68-
* Brevity incremental builder for "path".
69-
*/
70-
public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) {
71-
this.resolvePathStack.push((path: string) => {
72-
this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
73-
});
74-
return this;
75-
}
76-
77-
/**
78-
* Brevity setter for "headers".
79-
*/
80-
public h(headers: Record<string, string>) {
81-
this.headers = headers;
82-
return this;
83-
}
84-
85-
/**
86-
* Brevity setter for "query".
87-
*/
88-
public q(query: Record<string, string>) {
89-
this.query = query;
90-
return this;
91-
}
92-
93-
/**
94-
* Brevity setter for "body".
95-
*/
96-
public b(body: any) {
97-
this.body = body;
98-
return this;
99-
}
100-
101-
/**
102-
* Brevity setter for "method".
103-
*/
104-
public m(method: string) {
105-
this.method = method;
106-
return this;
107-
}
108-
}
5+
export { requestBuilder } from "@smithy/core/protocols";

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { collectBody } from "@smithy/core/protocols";
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

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+
};
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./collect-stream-body";
2+
export * from "./extended-encode-uri-component";
3+
export * from "./requestBuilder";
4+
export * from "./resolve-path";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { resolvedPath } from "@smithy/core/protocols";
2+
import { HttpRequest } from "@smithy/protocol-http";
3+
import type { SerdeContext } from "@smithy/types";
4+
5+
/**
6+
* @internal
7+
* used in code-generated serde.
8+
*/
9+
export function requestBuilder(input: any, context: SerdeContext): RequestBuilder {
10+
return new RequestBuilder(input, context);
11+
}
12+
13+
/**
14+
* @internal
15+
*/
16+
export class RequestBuilder {
17+
private query: Record<string, string> = {};
18+
private method = "";
19+
private headers: Record<string, string> = {};
20+
private path = "";
21+
private body: any = null;
22+
private hostname = "";
23+
24+
private resolvePathStack: Array<(path: string) => void> = [];
25+
26+
public constructor(
27+
private input: any,
28+
private context: SerdeContext
29+
) {}
30+
31+
public async build() {
32+
const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
33+
this.path = basePath;
34+
for (const resolvePath of this.resolvePathStack) {
35+
resolvePath(this.path);
36+
}
37+
return new HttpRequest({
38+
protocol,
39+
hostname: this.hostname || hostname,
40+
port,
41+
method: this.method,
42+
path: this.path,
43+
query: this.query,
44+
body: this.body,
45+
headers: this.headers,
46+
});
47+
}
48+
49+
/**
50+
* Brevity setter for "hostname".
51+
*/
52+
public hn(hostname: string) {
53+
this.hostname = hostname;
54+
return this;
55+
}
56+
57+
/**
58+
* Brevity initial builder for "basepath".
59+
*/
60+
public bp(uriLabel: string) {
61+
this.resolvePathStack.push((basePath: string) => {
62+
this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
63+
});
64+
return this;
65+
}
66+
67+
/**
68+
* Brevity incremental builder for "path".
69+
*/
70+
public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) {
71+
this.resolvePathStack.push((path: string) => {
72+
this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
73+
});
74+
return this;
75+
}
76+
77+
/**
78+
* Brevity setter for "headers".
79+
*/
80+
public h(headers: Record<string, string>) {
81+
this.headers = headers;
82+
return this;
83+
}
84+
85+
/**
86+
* Brevity setter for "query".
87+
*/
88+
public q(query: Record<string, string>) {
89+
this.query = query;
90+
return this;
91+
}
92+
93+
/**
94+
* Brevity setter for "body".
95+
*/
96+
public b(body: any) {
97+
this.body = body;
98+
return this;
99+
}
100+
101+
/**
102+
* Brevity setter for "method".
103+
*/
104+
public m(method: string) {
105+
this.method = method;
106+
return this;
107+
}
108+
}

0 commit comments

Comments
 (0)