Skip to content

Commit 9460ccc

Browse files
authored
chore(parameters): update generics names in SSMProvider (#1413)
1 parent 5c6d527 commit 9460ccc

File tree

8 files changed

+8095
-26737
lines changed

8 files changed

+8095
-26737
lines changed

package-lock.json

Lines changed: 7979 additions & 26642 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/parameters/src/ssm/SSMProvider.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
SSMGetMultipleOutput,
2323
SSMGetParametersByNameOutput,
2424
SSMGetParametersByNameOutputInterface,
25-
SSMGetParametersByNameOptionsInterface,
25+
SSMGetParametersByNameOptions,
2626
SSMSplitBatchAndDecryptParametersOutputType,
2727
SSMGetParametersByNameFromCacheOutputType,
2828
} from '../types/SSMProvider';
@@ -319,11 +319,11 @@ class SSMProvider extends BaseProvider {
319319
* @param {SSMGetOptions} options - Options to configure the provider
320320
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
321321
*/
322-
public async get<T = undefined, O extends SSMGetOptions | undefined = SSMGetOptions>(
322+
public async get<ExplicitUserProvidedType = undefined, InferredFromOptionsType extends SSMGetOptions | undefined = SSMGetOptions>(
323323
name: string,
324-
options?: O & SSMGetOptions
325-
): Promise<SSMGetOutput<T, O> | undefined> {
326-
return super.get(name, options) as Promise<SSMGetOutput<T, O> | undefined>;
324+
options?: InferredFromOptionsType & SSMGetOptions
325+
): Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> {
326+
return super.get(name, options) as Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
327327
}
328328

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

366366
/**
@@ -409,19 +409,21 @@ class SSMProvider extends BaseProvider {
409409
* └────────────────────┘
410410
* ```
411411
*
412-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - Object containing parameter names and any optional overrides
413-
* @param {SSMGetParametersByNameOptionsInterface} options - Options to configure the retrieval
412+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - Object containing parameter names and any optional overrides
413+
* @param {SSMGetParametersByNameOptions} options - Options to configure the retrieval
414414
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
415415
*/
416-
public async getParametersByName<T = undefined>(
417-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
418-
options?: SSMGetParametersByNameOptionsInterface
419-
): Promise<SSMGetParametersByNameOutput<T>> {
420-
const configs = { ...{
421-
decrypt: this.resolveDecryptionConfigValue({}) || false,
422-
maxAge: DEFAULT_MAX_AGE_SECS,
423-
throwOnError: true,
424-
}, ...options };
416+
public async getParametersByName<ExplicitUserProvidedType = undefined>(
417+
parameters: Record<string, SSMGetParametersByNameOptions>,
418+
options?: SSMGetParametersByNameOptions
419+
): Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>> {
420+
const configs = {
421+
...{
422+
decrypt: this.resolveDecryptionConfigValue({}) || false,
423+
maxAge: DEFAULT_MAX_AGE_SECS,
424+
throwOnError: true,
425+
}, ...options
426+
};
425427

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

@@ -464,7 +466,7 @@ class SSMProvider extends BaseProvider {
464466
}
465467
}
466468

467-
return response as unknown as Promise<SSMGetParametersByNameOutput<T>>;
469+
return response as unknown as Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>>;
468470
}
469471

470472
/**
@@ -537,12 +539,12 @@ class SSMProvider extends BaseProvider {
537539
/**
538540
* Retrieve multiple items by name from AWS Systems Manager.
539541
*
540-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
542+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
541543
* @param {throwOnError} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
542544
* @param {boolean} decrypt - Whether to decrypt the parameters or not
543545
*/
544546
protected async _getParametersByName(
545-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
547+
parameters: Record<string, SSMGetParametersByNameOptions>,
546548
throwOnError: boolean,
547549
decrypt: boolean
548550
): Promise<SSMGetParametersByNameOutputInterface> {
@@ -570,12 +572,12 @@ class SSMProvider extends BaseProvider {
570572
/**
571573
* Slice batch and fetch parameters using GetPrameters API by max permissible batch size
572574
*
573-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
575+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
574576
* @param {throwOnError} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
575577
* @param {boolean} decrypt - Whether to decrypt the parameters or not
576578
*/
577579
protected async getParametersBatchByName(
578-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
580+
parameters: Record<string, SSMGetParametersByNameOptions>,
579581
throwOnError: boolean,
580582
decrypt: boolean
581583
): Promise<SSMGetParametersByNameOutputInterface> {
@@ -610,13 +612,13 @@ class SSMProvider extends BaseProvider {
610612
/**
611613
* Fetch each parameter from batch that hasn't expired from cache
612614
*
613-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
615+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
614616
*/
615617
protected async getParametersByNameFromCache(
616-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>
618+
parameters: Record<string, SSMGetParametersByNameOptions>
617619
): Promise<SSMGetParametersByNameFromCacheOutputType> {
618620
const cached: Record<string, string | Record<string, unknown>> = {};
619-
const toFetch: Record<string, SSMGetParametersByNameOptionsInterface> = {};
621+
const toFetch: Record<string, SSMGetParametersByNameOptions> = {};
620622

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

665667
return acc;
666-
}, [] as Record<string, SSMGetParametersByNameOptionsInterface>[]);
668+
}, [] as Record<string, SSMGetParametersByNameOptions>[]);
667669

668670
// Fetch each chunk and merge results
669671
for (const chunk of chunks) {
@@ -685,11 +687,11 @@ class SSMProvider extends BaseProvider {
685687
/**
686688
* Fetch parameters by name while also decrypting them
687689
*
688-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
690+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
689691
* @param {boolean} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
690692
*/
691693
protected async getParametersByNameWithDecryptOption(
692-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
694+
parameters: Record<string, SSMGetParametersByNameOptions>,
693695
throwOnError: boolean
694696
): Promise<SSMGetParametersByNameOutputInterface> {
695697
const response: Record<string, unknown> = {};
@@ -752,15 +754,15 @@ class SSMProvider extends BaseProvider {
752754
/**
753755
* Split parameters that can be fetched by GetParameters vs GetParameter.
754756
*
755-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
756-
* @param {SSMGetParametersByNameOptionsInterface} configs - The configs passed down
757+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
758+
* @param {SSMGetParametersByNameOptions} configs - The configs passed down
757759
*/
758760
protected static splitBatchAndDecryptParameters(
759-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
760-
configs: SSMGetParametersByNameOptionsInterface
761+
parameters: Record<string, SSMGetParametersByNameOptions>,
762+
configs: SSMGetParametersByNameOptions
761763
): SSMSplitBatchAndDecryptParametersOutputType {
762-
const parametersToFetchInBatch: Record<string, SSMGetParametersByNameOptionsInterface> = {};
763-
const parametersToDecrypt: Record<string, SSMGetParametersByNameOptionsInterface> = {};
764+
const parametersToFetchInBatch: Record<string, SSMGetParametersByNameOptions> = {};
765+
const parametersToDecrypt: Record<string, SSMGetParametersByNameOptions> = {};
764766

765767
for (const [ parameterName, parameterOptions ] of Object.entries(parameters)) {
766768
const overrides = parameterOptions;
@@ -807,12 +809,12 @@ class SSMProvider extends BaseProvider {
807809
* Transform and cache the response from GetParameters API call
808810
*
809811
* @param {GetParametersCommandOutput} response - The response from the GetParameters API call
810-
* @param {Record<string, SSMGetParametersByNameOptionsInterface>} parameters - An object of parameter names and their options
812+
* @param {Record<string, SSMGetParametersByNameOptions>} parameters - An object of parameter names and their options
811813
* @param {boolean} throwOnError - Whether to throw an error if any of the parameters' retrieval throws an error or handle them gracefully
812814
*/
813815
protected transformAndCacheGetParametersResponse(
814816
response: GetParametersCommandOutput,
815-
parameters: Record<string, SSMGetParametersByNameOptionsInterface>,
817+
parameters: Record<string, SSMGetParametersByNameOptions>,
816818
throwOnError: boolean
817819
): Record<string, unknown> {
818820
const processedParameters: Record<string, unknown> = {};

packages/parameters/src/ssm/getParameter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SSMProvider, DEFAULT_PROVIDERS } from './SSMProvider';
22
import type {
33
SSMGetOptions,
44
SSMGetOutput,
5+
SSMGetOptionsUnion,
56
} from '../types/SSMProvider';
67

78
/**
@@ -139,17 +140,20 @@ import type {
139140
* @param {SSMGetOptions} options - Options to configure the provider
140141
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
141142
*/
142-
const getParameter = <T = undefined, O extends SSMGetOptions | undefined = SSMGetOptions>(
143+
const getParameter = async <
144+
ExplicitUserProvidedType = undefined,
145+
InferredFromOptionsType extends SSMGetOptionsUnion | undefined = SSMGetOptionsUnion
146+
>(
143147
name: string,
144-
options?: O & SSMGetOptions
145-
): Promise<SSMGetOutput<T, O> | undefined> => {
148+
options?: InferredFromOptionsType & SSMGetOptions
149+
): Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> => {
146150
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
147151
DEFAULT_PROVIDERS.ssm = new SSMProvider();
148152
}
149153

150154
return (
151155
DEFAULT_PROVIDERS.ssm as SSMProvider
152-
).get(name, options) as Promise<SSMGetOutput<T, O> | undefined>;
156+
).get(name, options) as Promise<SSMGetOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
153157
};
154158

155159
export {

packages/parameters/src/ssm/getParameters.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,20 @@ import type {
141141
* @param {SSMGetMultipleOptions} options - Options to configure the provider
142142
* @see https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/
143143
*/
144-
const getParameters = <T = undefined, O extends SSMGetMultipleOptionsUnion | undefined = SSMGetMultipleOptionsUnion>(
144+
const getParameters = async <
145+
ExplicitUserProvidedType = undefined,
146+
InferredFromOptionsType extends SSMGetMultipleOptionsUnion | undefined = SSMGetMultipleOptionsUnion
147+
>(
145148
path: string,
146-
options?: O & SSMGetMultipleOptions
147-
): Promise<SSMGetMultipleOutput<T, O> | undefined> => {
149+
options?: InferredFromOptionsType & SSMGetMultipleOptions
150+
): Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined> => {
148151
if (!DEFAULT_PROVIDERS.hasOwnProperty('ssm')) {
149152
DEFAULT_PROVIDERS.ssm = new SSMProvider();
150153
}
151154

152155
return (
153156
DEFAULT_PROVIDERS.ssm as SSMProvider
154-
).getMultiple(path, options) as Promise<SSMGetMultipleOutput<T, O> | undefined>;
157+
).getMultiple(path, options) as Promise<SSMGetMultipleOutput<ExplicitUserProvidedType, InferredFromOptionsType> | undefined>;
155158
};
156159

157160
export {

packages/parameters/src/ssm/getParametersByName.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SSMProvider, DEFAULT_PROVIDERS } from './SSMProvider';
22
import type {
3-
SSMGetParametersByNameOptionsInterface,
3+
SSMGetParametersByNameOptions,
44
SSMGetParametersByNameOutput,
55
} from '../types/SSMProvider';
66

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

172172
return (
173173
DEFAULT_PROVIDERS.ssm as SSMProvider
174-
).getParametersByName(parameters, options) as Promise<SSMGetParametersByNameOutput<T>>;
174+
).getParametersByName(parameters, options) as Promise<SSMGetParametersByNameOutput<ExplicitUserProvidedType>>;
175175
};
176176

177177
export {

0 commit comments

Comments
 (0)