Skip to content

Commit

Permalink
chore(parameters): update generics names in SSMProvider (#1413)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi authored Apr 14, 2023
1 parent 5c6d527 commit 9460ccc
Show file tree
Hide file tree
Showing 8 changed files with 8,095 additions and 26,737 deletions.
34,621 changes: 7,979 additions & 26,642 deletions package-lock.json

Large diffs are not rendered by default.

84 changes: 43 additions & 41 deletions packages/parameters/src/ssm/SSMProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
SSMGetMultipleOutput,
SSMGetParametersByNameOutput,
SSMGetParametersByNameOutputInterface,
SSMGetParametersByNameOptionsInterface,
SSMGetParametersByNameOptions,
SSMSplitBatchAndDecryptParametersOutputType,
SSMGetParametersByNameFromCacheOutputType,
} from '../types/SSMProvider';
Expand Down Expand Up @@ -319,11 +319,11 @@ class SSMProvider extends BaseProvider {
* @param {SSMGetOptions} options - Options to configure the provider
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
public async get<T = undefined, O extends SSMGetOptions | undefined = SSMGetOptions>(
public async get<ExplicitUserProvidedType = undefined, InferredFromOptionsType extends SSMGetOptions | undefined = SSMGetOptions>(
name: string,
options?: O & SSMGetOptions
): Promise<SSMGetOutput<T, O> | undefined> {
return super.get(name, options) as Promise<SSMGetOutput<T, O> | undefined>;
options?: InferredFromOptionsType & SSMGetOptions
): Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> {
return super.get(name, options) as Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
}

/**
Expand Down Expand Up @@ -356,11 +356,11 @@ class SSMProvider extends BaseProvider {
* @param {SSMGetMultipleOptions} options - Options to configure the retrieval
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
public async getMultiple<T = undefined, O extends SSMGetMultipleOptionsUnion | undefined = undefined>(
public async getMultiple<ExplicitUserProvidedType = undefined, InferredFromOptionsType extends SSMGetMultipleOptionsUnion | undefined = undefined>(
path: string,
options?: O & SSMGetMultipleOptions
): Promise<SSMGetMultipleOutput<T, O> | undefined> {
return super.getMultiple(path, options) as Promise<SSMGetMultipleOutput<T, O> | undefined>;
options?: InferredFromOptionsType & SSMGetMultipleOptions
): Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> {
return super.getMultiple(path, options) as Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
}

/**
Expand Down Expand Up @@ -409,19 +409,21 @@ class SSMProvider extends BaseProvider {
* └────────────────────┘
* ```
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - Object containing parameter names and any optional overrides
* @param {SSMGetParametersByNameOptionsInterface} options - Options to configure the retrieval
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - Object containing parameter names and any optional overrides
* @param {SSMGetParametersByNameOptions} options - Options to configure the retrieval
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
public async getParametersByName<T = undefined>(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
options?: SSMGetParametersByNameOptionsInterface
): Promise<SSMGetParametersByNameOutput<T>> {
const configs = { ...{
decrypt: this.resolveDecryptionConfigValue({}) || false,
maxAge: DEFAULT_MAX_AGE_SECS,
throwOnError: true,
}, ...options };
public async getParametersByName<ExplicitUserProvidedType = undefined>(
parameters: Record<string, SSMGetParametersByNameOptions>,
options?: SSMGetParametersByNameOptions
): Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>> {
const configs = {
...{
decrypt: this.resolveDecryptionConfigValue({}) || false,
maxAge: DEFAULT_MAX_AGE_SECS,
throwOnError: true,
}, ...options
};

let response: Record<string, unknown> = {};

Expand Down Expand Up @@ -464,7 +466,7 @@ class SSMProvider extends BaseProvider {
}
}

return response as unknown as Promise<SSMGetParametersByNameOutput<T>>;
return response as unknown as Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>>;
}

/**
Expand Down Expand Up @@ -537,12 +539,12 @@ class SSMProvider extends BaseProvider {
/**
* Retrieve multiple items by name from AWS Systems Manager.
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {throwOnError} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
* @param {boolean} decrypt - Whether to decrypt the parameters or not
*/
protected async _getParametersByName(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
parameters: Record<string, SSMGetParametersByNameOptions>,
throwOnError: boolean,
decrypt: boolean
): Promise<SSMGetParametersByNameOutputInterface> {
Expand Down Expand Up @@ -570,12 +572,12 @@ class SSMProvider extends BaseProvider {
/**
* Slice batch and fetch parameters using GetPrameters API by max permissible batch size
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {throwOnError} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
* @param {boolean} decrypt - Whether to decrypt the parameters or not
*/
protected async getParametersBatchByName(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
parameters: Record<string, SSMGetParametersByNameOptions>,
throwOnError: boolean,
decrypt: boolean
): Promise<SSMGetParametersByNameOutputInterface> {
Expand Down Expand Up @@ -610,13 +612,13 @@ class SSMProvider extends BaseProvider {
/**
* Fetch each parameter from batch that hasn't expired from cache
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
*/
protected async getParametersByNameFromCache(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>
parameters: Record<string, SSMGetParametersByNameOptions>
): Promise<SSMGetParametersByNameFromCacheOutputType> {
const cached: Record<string, string | Record<string, unknown>> = {};
const toFetch: Record<string, SSMGetParametersByNameOptionsInterface> = {};
const toFetch: Record<string, SSMGetParametersByNameOptions> = {};

for (const [ parameterName, parameterOptions ] of Object.entries(parameters)) {
const cacheKey = [ parameterName, parameterOptions.transform ].toString();
Expand All @@ -638,12 +640,12 @@ class SSMProvider extends BaseProvider {
/**
* Slice object into chunks of max permissible batch size and fetch parameters
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {boolean} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
* @param {boolean} decrypt - Whether to decrypt the parameters or not
*/
protected async getParametersByNameInChunks(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
parameters: Record<string, SSMGetParametersByNameOptions>,
throwOnError: boolean,
decrypt: boolean
): Promise<SSMGetParametersByNameOutputInterface> {
Expand All @@ -663,7 +665,7 @@ class SSMProvider extends BaseProvider {
acc[chunkIndex][parameterName] = parameterOptions;

return acc;
}, [] as Record<string, SSMGetParametersByNameOptionsInterface>[]);
}, [] as Record<string, SSMGetParametersByNameOptions>[]);

// Fetch each chunk and merge results
for (const chunk of chunks) {
Expand All @@ -685,11 +687,11 @@ class SSMProvider extends BaseProvider {
/**
* Fetch parameters by name while also decrypting them
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {boolean} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
*/
protected async getParametersByNameWithDecryptOption(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
parameters: Record<string, SSMGetParametersByNameOptions>,
throwOnError: boolean
): Promise<SSMGetParametersByNameOutputInterface> {
const response: Record<string, unknown> = {};
Expand Down Expand Up @@ -752,15 +754,15 @@ class SSMProvider extends BaseProvider {
/**
* Split parameters that can be fetched by GetParameters vs GetParameter.
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {SSMGetParametersByNameOptionsInterface} configs - The configs passed down
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {SSMGetParametersByNameOptions} configs - The configs passed down
*/
protected static splitBatchAndDecryptParameters(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
configs: SSMGetParametersByNameOptionsInterface
parameters: Record<string, SSMGetParametersByNameOptions>,
configs: SSMGetParametersByNameOptions
): SSMSplitBatchAndDecryptParametersOutputType {
const parametersToFetchInBatch: Record<string, SSMGetParametersByNameOptionsInterface> = {};
const parametersToDecrypt: Record<string, SSMGetParametersByNameOptionsInterface> = {};
const parametersToFetchInBatch: Record<string, SSMGetParametersByNameOptions> = {};
const parametersToDecrypt: Record<string, SSMGetParametersByNameOptions> = {};

for (const [ parameterName, parameterOptions ] of Object.entries(parameters)) {
const overrides = parameterOptions;
Expand Down Expand Up @@ -807,12 +809,12 @@ class SSMProvider extends BaseProvider {
* Transform and cache the response from GetParameters API call
*
* @param {GetParametersCommandOutput} response - The response from the GetParameters API call
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
* @param {boolean} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
*/
protected transformAndCacheGetParametersResponse(
response: GetParametersCommandOutput,
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
parameters: Record<string, SSMGetParametersByNameOptions>,
throwOnError: boolean
): Record<string, unknown> {
const processedParameters: Record<string, unknown> = {};
Expand Down
12 changes: 8 additions & 4 deletions packages/parameters/src/ssm/getParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SSMProvider, DEFAULT_PROVIDERS } from './SSMProvider';
import type {
SSMGetOptions,
SSMGetOutput,
SSMGetOptionsUnion,
} from '../types/SSMProvider';

/**
Expand Down Expand Up @@ -139,17 +140,20 @@ import type {
* @param {SSMGetOptions} options - Options to configure the provider
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
const getParameter = <T = undefined, O extends SSMGetOptions | undefined = SSMGetOptions>(
const getParameter = async <
ExplicitUserProvidedType = undefined,
InferredFromOptionsType extends SSMGetOptionsUnion | undefined = SSMGetOptionsUnion
>(
name: string,
options?: O & SSMGetOptions
): Promise<SSMGetOutput<T, O> | undefined> => {
options?: InferredFromOptionsType & SSMGetOptions
): Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> => {
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
DEFAULT_PROVIDERS.ssm = new SSMProvider();
}

return (
DEFAULT_PROVIDERS.ssm as SSMProvider
).get(name, options) as Promise<SSMGetOutput<T, O> | undefined>;
).get(name, options) as Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
};

export {
Expand Down
11 changes: 7 additions & 4 deletions packages/parameters/src/ssm/getParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,20 @@ import type {
* @param {SSMGetMultipleOptions} options - Options to configure the provider
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
const getParameters = <T = undefined, O extends SSMGetMultipleOptionsUnion | undefined = SSMGetMultipleOptionsUnion>(
const getParameters = async <
ExplicitUserProvidedType = undefined,
InferredFromOptionsType extends SSMGetMultipleOptionsUnion | undefined = SSMGetMultipleOptionsUnion
>(
path: string,
options?: O & SSMGetMultipleOptions
): Promise<SSMGetMultipleOutput<T, O> | undefined> => {
options?: InferredFromOptionsType & SSMGetMultipleOptions
): Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> => {
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
DEFAULT_PROVIDERS.ssm = new SSMProvider();
}

return (
DEFAULT_PROVIDERS.ssm as SSMProvider
).getMultiple(path, options) as Promise<SSMGetMultipleOutput<T, O> | undefined>;
).getMultiple(path, options) as Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
};

export {
Expand Down
16 changes: 8 additions & 8 deletions packages/parameters/src/ssm/getParametersByName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SSMProvider, DEFAULT_PROVIDERS } from './SSMProvider';
import type {
SSMGetParametersByNameOptionsInterface,
SSMGetParametersByNameOptions,
SSMGetParametersByNameOutput,
} from '../types/SSMProvider';

Expand Down Expand Up @@ -157,21 +157,21 @@ import type {
*
* For more usage examples, see [our documentation](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/).
*
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - The path of the parameters to retrieve
* @param {SSMGetParametersByNameOptionsInterface} options - Options to configure the provider
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - The path of the parameters to retrieve
* @param {SSMGetParametersByNameOptions} options - Options to configure the provider
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
*/
const getParametersByName = <T = undefined>(
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
options?: SSMGetParametersByNameOptionsInterface
): Promise<SSMGetParametersByNameOutput<T>> => {
const getParametersByName = async <ExplicitUserProvidedType = undefined>(
parameters: Record<string, SSMGetParametersByNameOptions>,
options?: SSMGetParametersByNameOptions
): Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>> => {
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
DEFAULT_PROVIDERS.ssm = new SSMProvider();
}

return (
DEFAULT_PROVIDERS.ssm as SSMProvider
).getParametersByName(parameters, options) as Promise<SSMGetParametersByNameOutput<T>>;
).getParametersByName(parameters, options) as Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>>;
};

export {
Expand Down
Loading

0 comments on commit 9460ccc

Please sign in to comment.