-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
30 changed files
with
262 additions
and
183 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@smithy/middleware-compression": minor | ||
"@smithy/middleware-endpoint": minor | ||
"@smithy/core": minor | ||
--- | ||
|
||
feature detection for custom endpoint and gzip |
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,8 @@ | ||
--- | ||
"@smithy/middleware-compression": patch | ||
"@smithy/middleware-endpoint": patch | ||
"@smithy/smithy-client": patch | ||
"@smithy/core": patch | ||
--- | ||
|
||
reorganize smithy/core to be upstream of smithy/smithy-client |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
export * from "./getSmithyContext"; | ||
export * from "./middleware-http-auth-scheme"; | ||
export * from "./middleware-http-signing"; | ||
export * from "./util-identity-and-auth"; | ||
export * from "./getSmithyContext"; | ||
export * from "./normalizeProvider"; | ||
export * from "./protocols/requestBuilder"; | ||
export { createPaginator } from "./pagination/createPaginator"; | ||
export * from "./protocols/requestBuilder"; | ||
export * from "./setFeature"; | ||
export * from "./util-identity-and-auth"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,5 @@ | ||
import { HttpRequest } from "@smithy/protocol-http"; | ||
import { resolvedPath } from "@smithy/smithy-client"; | ||
import type { SerdeContext } from "@smithy/types"; | ||
|
||
/** | ||
* @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.
26 changes: 26 additions & 0 deletions
26
packages/core/src/submodules/protocols/collect-stream-body.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,26 @@ | ||
import { SerdeContext } from "@smithy/types"; | ||
import { Uint8ArrayBlobAdapter } from "@smithy/util-stream"; | ||
|
||
/** | ||
* @internal | ||
* | ||
* Collect low-level response body stream to Uint8Array. | ||
*/ | ||
export const collectBody = async ( | ||
streamBody: any = new Uint8Array(), | ||
context: { | ||
streamCollector: SerdeContext["streamCollector"]; | ||
} | ||
): Promise<Uint8ArrayBlobAdapter> => { | ||
if (streamBody instanceof Uint8Array) { | ||
return Uint8ArrayBlobAdapter.mutate(streamBody); | ||
} | ||
|
||
if (!streamBody) { | ||
return Uint8ArrayBlobAdapter.mutate(new Uint8Array()); | ||
} | ||
|
||
const fromContext = context.streamCollector(streamBody); | ||
|
||
return Uint8ArrayBlobAdapter.mutate(await fromContext); | ||
}; |
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
packages/core/src/submodules/protocols/extended-encode-uri-component.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,11 @@ | ||
/** | ||
* @internal | ||
* | ||
* Function that wraps encodeURIComponent to encode additional characters | ||
* to fully adhere to RFC 3986. | ||
*/ | ||
export function extendedEncodeURIComponent(str: string): string { | ||
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) { | ||
return "%" + c.charCodeAt(0).toString(16).toUpperCase(); | ||
}); | ||
} |
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; | ||
} | ||
} |
Oops, something went wrong.