Skip to content

Commit 9adf184

Browse files
committed
reorganize core and smithy-client
1 parent a7e6a52 commit 9adf184

20 files changed

+146
-116
lines changed

packages/core/package.json

Lines changed: 9 additions & 0 deletions
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": {
@@ -68,6 +75,8 @@
6875
"files": [
6976
"./cbor.d.ts",
7077
"./cbor.js",
78+
"./protocols.d.ts",
79+
"./protocols.js",
7180
"dist-*/**"
7281
],
7382
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",

packages/core/protocols.d.ts

Lines changed: 7 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { collectBody } from "@smithy/core";
1+
import { collectBody } from "@smithy/core/protocols";
22
import { HttpRequest as __HttpRequest } from "@smithy/protocol-http";
33
import { HeaderBag as __HeaderBag, HttpResponse, SerdeContext as __SerdeContext, SerdeContext } from "@smithy/types";
44
import { calculateBodyLength } from "@smithy/util-body-length-browser";
Lines changed: 4 additions & 0 deletions
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";
Lines changed: 108 additions & 0 deletions
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+
}

packages/core/tsconfig.cjs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"outDir": "dist-cjs",
55
"rootDir": "src",
66
"paths": {
7-
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"]
7+
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
8+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
89
}
910
},
1011
"extends": "../../tsconfig.cjs.json",

packages/core/tsconfig.es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"outDir": "dist-es",
66
"rootDir": "src",
77
"paths": {
8-
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"]
8+
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
9+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
910
}
1011
},
1112
"extends": "../../tsconfig.es.json",

packages/core/tsconfig.types.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"declarationDir": "dist-types",
55
"rootDir": "src",
66
"paths": {
7-
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"]
7+
"@smithy/core/cbor": ["./src/submodules/cbor/index.ts"],
8+
"@smithy/core/protocols": ["./src/submodules/protocols/index.ts"]
89
}
910
},
1011
"extends": "../../tsconfig.types.json",

packages/smithy-client/src/collect-stream-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* @internal
33
* Backwards compatibility re-export.
44
*/
5-
export { collectBody } from "@smithy/core";
5+
export { collectBody } from "@smithy/core/protocols";

packages/smithy-client/src/extended-encode-uri-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* @internal
33
* Backwards compatibility re-export.
44
*/
5-
export { extendedEncodeURIComponent } from "@smithy/core";
5+
export { extendedEncodeURIComponent } from "@smithy/core/protocols";

packages/smithy-client/src/resolve-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* @internal
33
* Backwards compatibility re-export.
44
*/
5-
export { resolvedPath } from "@smithy/core";
5+
export { resolvedPath } from "@smithy/core/protocols";

0 commit comments

Comments
 (0)