-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
146 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Do not edit: | ||
* This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
*/ | ||
declare module "@smithy/core/protocols" { | ||
export * from "@smithy/core/dist-types/submodules/protocols/index.d"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
/** | ||
* Do not edit: | ||
* This is a compatibility redirect for contexts that do not understand package.json exports field. | ||
*/ | ||
module.exports = require("./dist-cjs/submodules/protocols/index.js"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,5 @@ | ||
import { HttpRequest } from "@smithy/protocol-http"; | ||
import type { SerdeContext } from "@smithy/types"; | ||
|
||
import { resolvedPath } from "./resolve-path"; | ||
|
||
/** | ||
* @internal | ||
* used in code-generated serde. | ||
* Backwards compatibility re-export. | ||
*/ | ||
export function requestBuilder(input: any, context: SerdeContext): RequestBuilder { | ||
return new RequestBuilder(input, context); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export class RequestBuilder { | ||
private query: Record<string, string> = {}; | ||
private method = ""; | ||
private headers: Record<string, string> = {}; | ||
private path = ""; | ||
private body: any = null; | ||
private hostname = ""; | ||
|
||
private resolvePathStack: Array<(path: string) => void> = []; | ||
|
||
public constructor( | ||
private input: any, | ||
private context: SerdeContext | ||
) {} | ||
|
||
public async build() { | ||
const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint(); | ||
this.path = basePath; | ||
for (const resolvePath of this.resolvePathStack) { | ||
resolvePath(this.path); | ||
} | ||
return new HttpRequest({ | ||
protocol, | ||
hostname: this.hostname || hostname, | ||
port, | ||
method: this.method, | ||
path: this.path, | ||
query: this.query, | ||
body: this.body, | ||
headers: this.headers, | ||
}); | ||
} | ||
|
||
/** | ||
* Brevity setter for "hostname". | ||
*/ | ||
public hn(hostname: string) { | ||
this.hostname = hostname; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity initial builder for "basepath". | ||
*/ | ||
public bp(uriLabel: string) { | ||
this.resolvePathStack.push((basePath: string) => { | ||
this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel; | ||
}); | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity incremental builder for "path". | ||
*/ | ||
public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) { | ||
this.resolvePathStack.push((path: string) => { | ||
this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel); | ||
}); | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "headers". | ||
*/ | ||
public h(headers: Record<string, string>) { | ||
this.headers = headers; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "query". | ||
*/ | ||
public q(query: Record<string, string>) { | ||
this.query = query; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "body". | ||
*/ | ||
public b(body: any) { | ||
this.body = body; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "method". | ||
*/ | ||
public m(method: string) { | ||
this.method = method; | ||
return this; | ||
} | ||
} | ||
export { requestBuilder } from "@smithy/core/protocols"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./collect-stream-body"; | ||
export * from "./extended-encode-uri-component"; | ||
export * from "./requestBuilder"; | ||
export * from "./resolve-path"; |
File renamed without changes.
108 changes: 108 additions & 0 deletions
108
packages/core/src/submodules/protocols/requestBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { resolvedPath } from "@smithy/core/protocols"; | ||
import { HttpRequest } from "@smithy/protocol-http"; | ||
import type { SerdeContext } from "@smithy/types"; | ||
|
||
/** | ||
* @internal | ||
* used in code-generated serde. | ||
*/ | ||
export function requestBuilder(input: any, context: SerdeContext): RequestBuilder { | ||
return new RequestBuilder(input, context); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export class RequestBuilder { | ||
private query: Record<string, string> = {}; | ||
private method = ""; | ||
private headers: Record<string, string> = {}; | ||
private path = ""; | ||
private body: any = null; | ||
private hostname = ""; | ||
|
||
private resolvePathStack: Array<(path: string) => void> = []; | ||
|
||
public constructor( | ||
private input: any, | ||
private context: SerdeContext | ||
) {} | ||
|
||
public async build() { | ||
const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint(); | ||
this.path = basePath; | ||
for (const resolvePath of this.resolvePathStack) { | ||
resolvePath(this.path); | ||
} | ||
return new HttpRequest({ | ||
protocol, | ||
hostname: this.hostname || hostname, | ||
port, | ||
method: this.method, | ||
path: this.path, | ||
query: this.query, | ||
body: this.body, | ||
headers: this.headers, | ||
}); | ||
} | ||
|
||
/** | ||
* Brevity setter for "hostname". | ||
*/ | ||
public hn(hostname: string) { | ||
this.hostname = hostname; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity initial builder for "basepath". | ||
*/ | ||
public bp(uriLabel: string) { | ||
this.resolvePathStack.push((basePath: string) => { | ||
this.path = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + uriLabel; | ||
}); | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity incremental builder for "path". | ||
*/ | ||
public p(memberName: string, labelValueProvider: () => string | undefined, uriLabel: string, isGreedyLabel: boolean) { | ||
this.resolvePathStack.push((path: string) => { | ||
this.path = resolvedPath(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel); | ||
}); | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "headers". | ||
*/ | ||
public h(headers: Record<string, string>) { | ||
this.headers = headers; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "query". | ||
*/ | ||
public q(query: Record<string, string>) { | ||
this.query = query; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "body". | ||
*/ | ||
public b(body: any) { | ||
this.body = body; | ||
return this; | ||
} | ||
|
||
/** | ||
* Brevity setter for "method". | ||
*/ | ||
public m(method: string) { | ||
this.method = method; | ||
return this; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters