-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pluggable runtime specific config (#404)
* feat: support pluggable runtime config * export runtimeConfig.runtime.ts to manually set the client to be compatible with specific runtime * get rid of rollup, instead using browser property to swap runtime config * add endpoint to the serializer utilities and insert it when building a request * chore: set prettier-vscode as default formatter
- Loading branch information
1 parent
1493cc3
commit 8be08fc
Showing
32 changed files
with
455 additions
and
485 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
"editor.tabSize": 2, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
} | ||
} |
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,6 +1,4 @@ | ||
/coverage/ | ||
/docs/ | ||
*.ts | ||
!*.d.ts | ||
tsconfig.test.json | ||
*.tsbuildinfo |
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
147 changes: 106 additions & 41 deletions
147
clients/node/client-rds-data-node/RDSDataConfiguration.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 |
---|---|---|
@@ -1,60 +1,125 @@ | ||
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node"; | ||
import { Hash } from "@aws-sdk/hash-node"; | ||
import { NodeHttpHandler } from "@aws-sdk/node-http-handler"; | ||
import { defaultProvider as regionDefaultProvider } from "@aws-sdk/region-provider"; | ||
import { parseUrl } from "@aws-sdk/url-parser-node"; | ||
import { calculateBodyLength } from "@aws-sdk/util-body-length-node"; | ||
import { streamCollector } from '@aws-sdk/stream-collector-node'; | ||
import { RestJsonProtocol } from "@aws-sdk/protocol-rest-json"; | ||
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node'; | ||
import { fromBase64, toBase64 } from '@aws-sdk/util-base64-node'; | ||
import { defaultUserAgent } from '@aws-sdk/util-user-agent-node'; | ||
import { AwsAuthConfiguration, AwsAuthConfigurationInput } from '@aws-sdk/signing-middleware'; | ||
import { UserAgentConfig, UserAgentConfigInput } from '@aws-sdk/middleware-user-agent'; | ||
import { RetryConfig, RetryConfigInput } from '@aws-sdk/retry-middleware'; | ||
import { name, version } from './package.json'; | ||
import { | ||
AwsAuthConfiguration, | ||
AwsAuthConfigurationInput | ||
} from "@aws-sdk/signing-middleware"; | ||
import { | ||
UserAgentConfig, | ||
UserAgentConfigInput | ||
} from "@aws-sdk/middleware-user-agent"; | ||
import { RetryConfig, RetryConfigInput } from "@aws-sdk/retry-middleware"; | ||
import { | ||
RegionConfiguration, | ||
RegionConfigurationInput, | ||
EndpointsConfig, | ||
EndpointsConfigInput, | ||
ProtocolConfig, | ||
ProtocolConfigInput, | ||
AWSClientRuntimeConfiguration | ||
} from '@aws-sdk/config-resolver'; | ||
|
||
export type AWSClientRuntimeResolvedConfiguration = Required<AWSClientRuntimeConfiguration>; | ||
|
||
export const RDSRuntimeConfiguration: AWSClientRuntimeResolvedConfiguration = { | ||
protocolDefaultProvider: (handler) => new RestJsonProtocol(handler), | ||
signingName: "rds-data", | ||
service: "rds-data", | ||
httpHandler: new NodeHttpHandler(), | ||
sha256: Hash.bind(null, "sha256"), | ||
credentialDefaultProvider, | ||
regionDefaultProvider, | ||
urlParser: parseUrl, | ||
bodyLengthChecker: calculateBodyLength, | ||
streamCollector, | ||
base64Decoder: fromBase64, | ||
base64Encoder: toBase64, | ||
utf8Decoder: fromUtf8, | ||
utf8Encoder: toUtf8, | ||
defaultUserAgent: defaultUserAgent(name, version) | ||
ProtocolConfigInput | ||
} from "@aws-sdk/config-resolver"; | ||
import { | ||
Credentials, | ||
Provider, | ||
HashConstructor, | ||
UrlParser, | ||
Protocol, | ||
StreamCollector, | ||
Decoder, | ||
Encoder | ||
} from "@aws-sdk/types"; | ||
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http"; | ||
|
||
export interface RDSDataRuntimeDependencies { | ||
/** | ||
* The HTTP handler to use. Fetch in browser and Https in Nodejs | ||
*/ | ||
httpHandler?: HttpHandler; | ||
|
||
/** | ||
* A constructor for a class implementing the @aws-sdk/types.Hash interface that computes the SHA-256 HMAC or checksum of a string or binary buffer | ||
*/ | ||
sha256?: HashConstructor; | ||
|
||
/** | ||
* Default credentials provider; Not available in browser runtime | ||
*/ | ||
credentialDefaultProvider?: (input: any) => Provider<Credentials>; | ||
|
||
/** | ||
* Provider function that return promise of a region string | ||
*/ | ||
regionDefaultProvider?: (input: any) => Provider<string>; | ||
|
||
/** | ||
* The function that will be used to convert strings into HTTP endpoints | ||
*/ | ||
urlParser?: UrlParser; | ||
|
||
/** | ||
* A function that can calculate the length of a request body. | ||
*/ | ||
bodyLengthChecker?: (body: any) => number | undefined; | ||
|
||
/** | ||
* A function that converts a stream into an array of bytes. | ||
*/ | ||
streamCollector?: StreamCollector; | ||
|
||
/** | ||
* The function that will be used to convert a base64-encoded string to a byte array | ||
*/ | ||
base64Decoder?: Decoder; | ||
|
||
/** | ||
* The function that will be used to convert binary data to a base64-encoded string | ||
*/ | ||
base64Encoder?: Encoder; | ||
|
||
/** | ||
* The function that will be used to convert a UTF8-encoded string to a byte array | ||
*/ | ||
utf8Decoder?: Decoder; | ||
|
||
/** | ||
* The function that will be used to convert binary data to a UTF-8 encoded string | ||
*/ | ||
utf8Encoder?: Encoder; | ||
|
||
/** | ||
* The function that will be used to populate default value in 'User-Agent' header | ||
*/ | ||
defaultUserAgent?: string; | ||
|
||
/** | ||
* The function that will be used to populate serializing protocol | ||
*/ | ||
protocolDefaultProvider?: ( | ||
handler: HttpHandler | ||
) => Protocol<HttpRequest, HttpResponse>; | ||
|
||
/** | ||
* The service name with which to sign requests. | ||
*/ | ||
signingName?: string; | ||
|
||
/** | ||
* The service name with which to construct endpoints. | ||
*/ | ||
service?: string; | ||
} | ||
|
||
export type RDSDataConfiguration = AWSClientRuntimeConfiguration & | ||
export type RDSDataConfiguration = RDSDataRuntimeDependencies & | ||
AwsAuthConfigurationInput & | ||
RegionConfigurationInput & | ||
RetryConfigInput & | ||
EndpointsConfigInput & | ||
ProtocolConfigInput & | ||
UserAgentConfigInput | ||
UserAgentConfigInput; | ||
|
||
export type RDSDataResolvedConfiguration = AWSClientRuntimeResolvedConfiguration & | ||
export type RDSDataResolvedConfiguration = Required< | ||
RDSDataRuntimeDependencies | ||
> & | ||
AwsAuthConfiguration.Resolved & | ||
RegionConfiguration.Resolved & | ||
RetryConfig.Resolved & | ||
EndpointsConfig.Resolved & | ||
ProtocolConfig.Resolved & | ||
UserAgentConfig.Resolved | ||
UserAgentConfig.Resolved; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.