Skip to content

Commit

Permalink
Separate global config from service config
Browse files Browse the repository at this point in the history
ConfigurationServicePlaceholders references all clients, this means when a single client is deep imported it still transitively references all clients.

The impact of this is TypeScript needs to parse all type definitions in the SDK, and there is no way for a project to avoid this.

By separating client config from global config clients can be deep imported without pulling all type definitions in, greatly reducing build time
  • Loading branch information
JakeGinnivan committed Aug 15, 2020
1 parent daefd06 commit ea14d77
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 274 deletions.
267 changes: 267 additions & 0 deletions lib/config-base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
import {Agent as httpAgent} from 'http';
import {Agent as httpsAgent} from 'https';
import {AWSError} from './error';
import {Credentials, CredentialsOptions} from './credentials';
import {CredentialProviderChain} from './credentials/credential_provider_chain';

export class ConfigBase extends ConfigurationOptions{
constructor(options?: ConfigurationOptions);
/**
* Loads credentials from the configuration object.
*/
getCredentials(callback: (err: AWSError) => void): void;
/**
* Loads configuration data from a JSON file into this config object.
* Loading configuration will reset all existing configuration on the object.
* This feature is not supported in the browser environment of the SDK.
*
* @param {string} path - the path relative to your process's current working directory to load configuration from.
*/
loadFromPath(path: string): ConfigBase;
/**
* Updates the current configuration object with new options.
*
* @param {ConfigurationOptions} options - a map of option keys and values.
* @param {boolean} allowUnknownKeys - Whether unknown keys can be set on the configuration object.
*/
update(options: ConfigurationOptions & {[key: string]: any}, allowUnknownKeys: true): void;
/**
* Updates the current configuration object with new options.
*
* @param {ConfigurationOptions} options - a map of option keys and values.
* @param {boolean} allowUnknownKeys - Defaults to false. Whether unknown keys can be set on the configuration object.
*/
update(options: ConfigurationOptions, allowUnknownKeys?: false): void;
/**
* Gets the promise dependency the SDK will use wherever Promises are returned.
*/
getPromisesDependency(): typeof Promise | void;
/**
* Sets the promise dependency the SDK will use wherever Promises are returned.
* @param {function} dep - a reference to a Promise constructor
*/
setPromisesDependency(dep: any): void;
}

export interface HTTPOptions {
/**
* the URL to proxy requests through.
*/
proxy?: string;
/**
* the Agent object to perform HTTP requests with.
* Used for connection pooling.
* Defaults to the global agent (http.globalAgent) for non-SSL connections.
*/
agent?: httpAgent | httpsAgent;
/**
* The maximum time in milliseconds that the connection phase of the request
* should be allowed to take. This only limits the connection phase and has
* no impact once the socket has established a connection.
* Used in node.js environments only.
*/
connectTimeout?: number;
/**
* The number of milliseconds to wait before giving up on a connection attempt.
* Defaults to two minutes (120000).
*/
timeout?: number;
/**
* Whether the SDK will send asynchronous HTTP requests.
* Used in the browser environment only.
* Set to false to send requests synchronously.
* Defaults to true (async on).
*/
xhrAsync?: boolean;
/**
* Sets the 'withCredentials' property of an XMLHttpRequest object.
* Used in the browser environment only.
* Defaults to false.
*/
xhrWithCredentials?: boolean;
}
export interface Logger {
write?: (chunk: any, encoding?: string, callback?: () => void) => void
log?: (...messages: any[]) => void;
}
export interface ParamValidation {
/**
* Validates that a value meets the min constraint.
* This is enabled by default when paramValidation is set to true.
*/
min?: boolean
/**
* Validates that a value meets the max constraint.
*/
max?: boolean
/**
* Validates that a string value matches a regular expression.
*/
pattern?: boolean
/**
* Validates that a string value matches one of the allowable enum values.
*/
enum?: boolean
}
export interface RetryDelayOptions {
/**
* The base number of milliseconds to use in the exponential backoff for operation retries.
* Defaults to 100 ms.
*/
base?: number
/**
* A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds. If the result is a non-zero negative value, no further retry attempts will be made.
* The base option will be ignored if this option is supplied.
*/
customBackoff?: (retryCount: number, err?: Error) => number
}

export abstract class ConfigurationOptions {

/**
* Whether to compute checksums for payload bodies when the service accepts it.
* Currently supported in S3 only.
*/
computeChecksums?: boolean
/**
* Whether types are converted when parsing response data.
*/
convertResponseTypes?: boolean
/**
* Whether to apply a clock skew correction and retry requests that fail because of an skewed client clock.
*/
correctClockSkew?: boolean
/**
* Sets a custom User-Agent string.
* In node environments this will set the User-Agent header, but
* browser environments this will set the X-Amz-User-Agent header.
*/
customUserAgent?: string
/**
* The AWS credentials to sign requests with.
*/
credentials?: Credentials|CredentialsOptions|null
/**
* The provider chain used to resolve credentials if no static credentials property is set.
*/
credentialProvider?: CredentialProviderChain
/**
* AWS access key ID.
*
* @deprecated
*/
accessKeyId?: string
/**
* AWS secret access key.
*
* @deprecated
*/
secretAccessKey?: string
/**
* AWS session token.
*
* @deprecated
*/
sessionToken?: string
/**
* A set of options to pass to the low-level HTTP request.
*/
httpOptions?: HTTPOptions
/**
* An object that responds to .write() (like a stream) or .log() (like the console object) in order to log information about requests.
*/
logger?: Logger
/**
* The maximum amount of redirects to follow for a service request.
*/
maxRedirects?: number
/**
* The maximum amount of retries to perform for a service request.
*/
maxRetries?: number
/**
* Returns whether input parameters should be validated against the operation description before sending the request.
* Defaults to true.
* Pass a map to enable any of the following specific validation features: min|max|pattern|enum
*/
paramValidation?: ParamValidation|boolean
/**
* The region to send service requests to.
*/
region?: string
/**
* Returns A set of options to configure the retry delay on retryable errors.
*/
retryDelayOptions?: RetryDelayOptions
/**
* Whether the provided endpoint addresses an individual bucket.
* false if it addresses the root API endpoint.
*/
s3BucketEndpoint?: boolean
/**
* Whether to disable S3 body signing when using signature version v4.
*/
s3DisableBodySigning?: boolean
/**
* Whether to force path style URLs for S3 objects.
*/
s3ForcePathStyle?: boolean
/**
* When region is set to 'us-east-1', whether to send s3 request to global endpoints
* or 'us-east-1' regional endpoints. This config is only applicable to S3 client;
* Defaults to 'legacy'
*/
s3UsEast1RegionalEndpoint?: "regional"|"legacy"
/**
* Whether to override the request region with the region inferred
* from requested resource's ARN. Only available for S3 buckets
* Defaults to `true`
*/
s3UseArnRegion?: boolean
/**
* Whether the signature to sign requests with (overriding the API configuration) is cached.
*/
signatureCache?: boolean
/**
* The signature version to sign requests with (overriding the API configuration).
* Possible values: 'v2'|'v3'|'v4'
*/
signatureVersion?: "v2"|"v3"|"v4"|string
/**
* Whether SSL is enabled for requests.
*/
sslEnabled?: boolean
/**
* An offset value in milliseconds to apply to all signing times.
*/
systemClockOffset?: number
/**
* Whether to use the Accelerate endpoint with the S3 service.
*/
useAccelerateEndpoint?: boolean
/**
* Whether to validate the CRC32 checksum of HTTP response bodies returned
* by DynamoDB.
*/
dynamoDbCrc32?: boolean;
/**
* Whether to enable endpoint discovery for operations that allow optionally using an endpoint returned by
* the service.
*/
endpointDiscoveryEnabled?: boolean;
/**
* The size of the global cache storing endpoints from endpoint
* discovery operations. Once endpoint cache is created, updating this setting
* cannot change existing cache size.
*/
endpointCacheSize?: number;
/**
* Whether to marshal request parameters to the prefix of hostname.
*/
hostPrefixEnabled?: boolean;
/**
* Whether to send sts request to global endpoints or
* regional endpoints.
*/
stsRegionalEndpoints?: "legacy"|"regional";
}
Loading

0 comments on commit ea14d77

Please sign in to comment.