Skip to content

Commit

Permalink
feat(clients): use inline nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 13, 2021
1 parent b594ee8 commit 6c0e1fa
Show file tree
Hide file tree
Showing 1,096 changed files with 10,423 additions and 13,163 deletions.
36 changes: 16 additions & 20 deletions clients/client-accessanalyzer/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler";
import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
Expand All @@ -20,24 +19,21 @@ export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
return {
...clientSharedValues,
runtime: "browser",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
(_: unknown) => () => Promise.reject(new Error("Credential is missing"))
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, DEFAULT_MAX_ATTEMPTS),
region: coalesce(config.region, invalidProvider("Region is missing")),
requestHandler: coalesce(config.requestHandler, new FetchHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, () => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: coalesce(config.sha256, Sha256),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config.region ?? invalidProvider("Region is missing"),
requestHandler: config.requestHandler ?? new FetchHttpHandler(),
retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: config.sha256 ?? Sha256,
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
3 changes: 1 addition & 2 deletions clients/client-accessanalyzer/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";

Expand All @@ -11,6 +10,6 @@ export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
return {
...browserDefaults,
runtime: "react-native",
sha256: coalesce(config.sha256, Sha256),
sha256: config.sha256 ?? Sha256,
};
};
11 changes: 5 additions & 6 deletions clients/client-accessanalyzer/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defaultRegionInfoProvider } from "./endpoints";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { Logger as __Logger } from "@aws-sdk/types";
import { parseUrl } from "@aws-sdk/url-parser";
import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
Expand All @@ -9,9 +8,9 @@ import { AccessAnalyzerClientConfig } from "./AccessAnalyzerClient";
*/
export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => ({
apiVersion: "2019-11-01",
disableHostPrefix: coalesce(config.disableHostPrefix, false),
logger: coalesce(config.logger, {} as __Logger),
regionInfoProvider: coalesce(config.regionInfoProvider, defaultRegionInfoProvider),
serviceId: coalesce(config.serviceId, "AccessAnalyzer"),
urlParser: coalesce(config.urlParser, parseUrl),
disableHostPrefix: config.disableHostPrefix ?? false,
logger: config.logger ?? ({} as __Logger),
regionInfoProvider: config.regionInfoProvider ?? defaultRegionInfoProvider,
serviceId: config.serviceId ?? "AccessAnalyzer",
urlParser: config.urlParser ?? parseUrl,
});
36 changes: 16 additions & 20 deletions clients/client-accessanalyzer/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Hash } from "@aws-sdk/hash-node";
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@aws-sdk/middleware-retry";
import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
Expand All @@ -23,24 +22,21 @@ export const getRuntimeConfig = (config: AccessAnalyzerClientConfig) => {
return {
...clientSharedValues,
runtime: "node",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
decorateDefaultCredentialProvider(credentialDefaultProvider)
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS)),
region: coalesce(config.region, loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)),
requestHandler: coalesce(config.requestHandler, new NodeHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS)),
sha256: coalesce(config.sha256, Hash.bind(null, "sha256")),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: config.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: config.requestHandler ?? new NodeHttpHandler(),
retryModeProvider: config.retryModeProvider ?? loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: config.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
36 changes: 16 additions & 20 deletions clients/client-acm-pca/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler";
import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
Expand All @@ -20,24 +19,21 @@ export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
return {
...clientSharedValues,
runtime: "browser",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
(_: unknown) => () => Promise.reject(new Error("Credential is missing"))
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, DEFAULT_MAX_ATTEMPTS),
region: coalesce(config.region, invalidProvider("Region is missing")),
requestHandler: coalesce(config.requestHandler, new FetchHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, () => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: coalesce(config.sha256, Sha256),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config.region ?? invalidProvider("Region is missing"),
requestHandler: config.requestHandler ?? new FetchHttpHandler(),
retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: config.sha256 ?? Sha256,
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
3 changes: 1 addition & 2 deletions clients/client-acm-pca/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { ACMPCAClientConfig } from "./ACMPCAClient";
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";

Expand All @@ -11,6 +10,6 @@ export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
return {
...browserDefaults,
runtime: "react-native",
sha256: coalesce(config.sha256, Sha256),
sha256: config.sha256 ?? Sha256,
};
};
11 changes: 5 additions & 6 deletions clients/client-acm-pca/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defaultRegionInfoProvider } from "./endpoints";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { Logger as __Logger } from "@aws-sdk/types";
import { parseUrl } from "@aws-sdk/url-parser";
import { ACMPCAClientConfig } from "./ACMPCAClient";
Expand All @@ -9,9 +8,9 @@ import { ACMPCAClientConfig } from "./ACMPCAClient";
*/
export const getRuntimeConfig = (config: ACMPCAClientConfig) => ({
apiVersion: "2017-08-22",
disableHostPrefix: coalesce(config.disableHostPrefix, false),
logger: coalesce(config.logger, {} as __Logger),
regionInfoProvider: coalesce(config.regionInfoProvider, defaultRegionInfoProvider),
serviceId: coalesce(config.serviceId, "ACM PCA"),
urlParser: coalesce(config.urlParser, parseUrl),
disableHostPrefix: config.disableHostPrefix ?? false,
logger: config.logger ?? ({} as __Logger),
regionInfoProvider: config.regionInfoProvider ?? defaultRegionInfoProvider,
serviceId: config.serviceId ?? "ACM PCA",
urlParser: config.urlParser ?? parseUrl,
});
36 changes: 16 additions & 20 deletions clients/client-acm-pca/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Hash } from "@aws-sdk/hash-node";
import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@aws-sdk/middleware-retry";
import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider";
import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node";
import { calculateBodyLength } from "@aws-sdk/util-body-length-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
Expand All @@ -23,24 +22,21 @@ export const getRuntimeConfig = (config: ACMPCAClientConfig) => {
return {
...clientSharedValues,
runtime: "node",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
decorateDefaultCredentialProvider(credentialDefaultProvider)
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS)),
region: coalesce(config.region, loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)),
requestHandler: coalesce(config.requestHandler, new NodeHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS)),
sha256: coalesce(config.sha256, Hash.bind(null, "sha256")),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? decorateDefaultCredentialProvider(credentialDefaultProvider),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
region: config.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
requestHandler: config.requestHandler ?? new NodeHttpHandler(),
retryModeProvider: config.retryModeProvider ?? loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS),
sha256: config.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
36 changes: 16 additions & 20 deletions clients/client-acm/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Sha256 } from "@aws-crypto/sha256-browser";
import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler";
import { invalidProvider } from "@aws-sdk/invalid-dependency";
import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser";
import { calculateBodyLength } from "@aws-sdk/util-body-length-browser";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-browser";
Expand All @@ -20,24 +19,21 @@ export const getRuntimeConfig = (config: ACMClientConfig) => {
return {
...clientSharedValues,
runtime: "browser",
base64Decoder: coalesce(config.base64Decoder, fromBase64),
base64Encoder: coalesce(config.base64Encoder, toBase64),
bodyLengthChecker: coalesce(config.bodyLengthChecker, calculateBodyLength),
credentialDefaultProvider: coalesce(
config.credentialDefaultProvider,
(_: unknown) => () => Promise.reject(new Error("Credential is missing"))
),
defaultUserAgentProvider: coalesce(
config.defaultUserAgentProvider,
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version })
),
maxAttempts: coalesce(config.maxAttempts, DEFAULT_MAX_ATTEMPTS),
region: coalesce(config.region, invalidProvider("Region is missing")),
requestHandler: coalesce(config.requestHandler, new FetchHttpHandler()),
retryModeProvider: coalesce(config.retryModeProvider, () => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: coalesce(config.sha256, Sha256),
streamCollector: coalesce(config.streamCollector, streamCollector),
utf8Decoder: coalesce(config.utf8Decoder, fromUtf8),
utf8Encoder: coalesce(config.utf8Encoder, toUtf8),
base64Decoder: config.base64Decoder ?? fromBase64,
base64Encoder: config.base64Encoder ?? toBase64,
bodyLengthChecker: config.bodyLengthChecker ?? calculateBodyLength,
credentialDefaultProvider:
config.credentialDefaultProvider ?? ((_: unknown) => () => Promise.reject(new Error("Credential is missing"))),
defaultUserAgentProvider:
config.defaultUserAgentProvider ??
defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
region: config.region ?? invalidProvider("Region is missing"),
requestHandler: config.requestHandler ?? new FetchHttpHandler(),
retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)),
sha256: config.sha256 ?? Sha256,
streamCollector: config.streamCollector ?? streamCollector,
utf8Decoder: config.utf8Decoder ?? fromUtf8,
utf8Encoder: config.utf8Encoder ?? toUtf8,
};
};
3 changes: 1 addition & 2 deletions clients/client-acm/runtimeConfig.native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Sha256 } from "@aws-crypto/sha256-js";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { ACMClientConfig } from "./ACMClient";
import { getRuntimeConfig as getBrowserRuntimeConfig } from "./runtimeConfig.browser";

Expand All @@ -11,6 +10,6 @@ export const getRuntimeConfig = (config: ACMClientConfig) => {
return {
...browserDefaults,
runtime: "react-native",
sha256: coalesce(config.sha256, Sha256),
sha256: config.sha256 ?? Sha256,
};
};
11 changes: 5 additions & 6 deletions clients/client-acm/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defaultRegionInfoProvider } from "./endpoints";
import { nullishCoalescing as coalesce } from "@aws-sdk/smithy-client";
import { Logger as __Logger } from "@aws-sdk/types";
import { parseUrl } from "@aws-sdk/url-parser";
import { ACMClientConfig } from "./ACMClient";
Expand All @@ -9,9 +8,9 @@ import { ACMClientConfig } from "./ACMClient";
*/
export const getRuntimeConfig = (config: ACMClientConfig) => ({
apiVersion: "2015-12-08",
disableHostPrefix: coalesce(config.disableHostPrefix, false),
logger: coalesce(config.logger, {} as __Logger),
regionInfoProvider: coalesce(config.regionInfoProvider, defaultRegionInfoProvider),
serviceId: coalesce(config.serviceId, "ACM"),
urlParser: coalesce(config.urlParser, parseUrl),
disableHostPrefix: config.disableHostPrefix ?? false,
logger: config.logger ?? ({} as __Logger),
regionInfoProvider: config.regionInfoProvider ?? defaultRegionInfoProvider,
serviceId: config.serviceId ?? "ACM",
urlParser: config.urlParser ?? parseUrl,
});
Loading

0 comments on commit 6c0e1fa

Please sign in to comment.