|
1 | | -import { HttpRequest } from "@smithy/protocol-http"; |
2 | | -import { resolvedPath } from "@smithy/smithy-client"; |
3 | | -import type { SerdeContext } from "@smithy/types"; |
4 | | - |
5 | 1 | /** |
6 | 2 | * @internal |
7 | | - * used in code-generated serde. |
| 3 | + * Backwards compatibility re-export. |
8 | 4 | */ |
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"; |
0 commit comments