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