Skip to content

Commit 0124e1f

Browse files
authored
style(parameters): apply stricter linting (#4577)
1 parent 9f45ef3 commit 0124e1f

25 files changed

+543
-601
lines changed

packages/parameters/src/appconfig/AppConfigProvider.ts

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@ import type {
1414
} from '../types/AppConfigProvider.js';
1515

1616
/**
17-
* ## Intro
18-
* The Parameters utility provides an AppConfigProvider that allows to retrieve configuration profiles from AWS AppConfig.
19-
*
20-
* ## Getting started
17+
* The Parameters utility provides an `AppConfigProvider` that allows to retrieve configuration profiles from AWS AppConfig.
2118
*
2219
* This utility supports AWS SDK v3 for JavaScript only (`@aws-sdk/client-appconfigdata`). This allows the utility to be modular, and you to install only
2320
* the SDK packages you need and keep your bundle size small.
2421
*
25-
* ## Basic usage
22+
* **Basic usage**
2623
*
2724
* @example
2825
* ```typescript
@@ -41,9 +38,7 @@ import type {
4138
* ```
4239
* If you want to retrieve configs without customizing the provider, you can use the {@link getAppConfig} function instead.
4340
*
44-
* ## Advanced usage
45-
*
46-
* ### Caching
41+
* **Caching**
4742
*
4843
* By default, the provider will cache parameters retrieved in-memory for 5 seconds.
4944
* You can adjust how long values should be kept in cache by using the `maxAge` parameter.
@@ -82,7 +77,7 @@ import type {
8277
* };
8378
* ```
8479
*
85-
* ### Transformations
80+
* **Transformations**
8681
*
8782
* For configurations stored as freeform JSON, Freature Flag, you can use the transform argument for deserialization. This will return a JavaScript object instead of a string.
8883
*
@@ -118,7 +113,7 @@ import type {
118113
* };
119114
* ```
120115
*
121-
* ### Extra SDK options
116+
* **Extra SDK options**
122117
*
123118
* When retrieving a configuration profile, you can pass extra options to the AWS SDK v3 for JavaScript client by using the `sdkOptions` parameter.
124119
*
@@ -144,7 +139,7 @@ import type {
144139
*
145140
* This object accepts the same options as the [AWS SDK v3 for JavaScript AppConfigData client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-appconfigdata/interfaces/startconfigurationsessioncommandinput.html).
146141
*
147-
* ### Customize AWS SDK v3 for JavaScript client
142+
* **Customize AWS SDK v3 for JavaScript client**
148143
*
149144
* By default, the provider will create a new AppConfigData client using the default configuration.
150145
*
@@ -192,21 +187,20 @@ class AppConfigProvider extends BaseProvider {
192187
private readonly application?: string;
193188
private readonly environment: string;
194189

195-
/**
196-
* It initializes the AppConfigProvider class.
197-
* *
198-
* @param {AppConfigProviderOptions} options - The configuration object.
199-
*/
200-
public constructor(options: AppConfigProviderOptions) {
190+
public constructor({
191+
application,
192+
environment,
193+
clientConfig,
194+
awsSdkV3Client,
195+
}: AppConfigProviderOptions) {
201196
super({
202197
awsSdkV3ClientPrototype: AppConfigDataClient as new (
203198
config?: unknown
204199
) => AppConfigDataClient,
205-
clientConfig: options.clientConfig,
206-
awsSdkV3Client: options.awsSdkV3Client,
200+
clientConfig,
201+
awsSdkV3Client,
207202
});
208203

209-
const { application, environment } = options;
210204
this.application = application ?? getServiceName();
211205
if (!this.application || this.application.trim().length === 0) {
212206
throw new Error(
@@ -235,26 +229,23 @@ class AppConfigProvider extends BaseProvider {
235229
* };
236230
* ```
237231
*
238-
* You can customize the retrieval of the configuration profile by passing options to the function:
239-
* * `maxAge` - The maximum age of the value in cache before fetching a new one (in seconds) (default: 5)
240-
* * `forceFetch` - Whether to always fetch a new value from the store regardless if already available in cache
241-
* * `transform` - Whether to transform the value before returning it. Supported values: `json`, `binary`
242-
* * `sdkOptions` - Extra options to pass to the AWS SDK v3 for JavaScript client
243-
*
244-
* For usage examples check {@link AppConfigProvider}.
245-
*
246-
* @param {string} name - The name of the configuration profile or its ID
247-
* @param {AppConfigGetOptions} options - Options to configure the provider
248232
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/features/parameters/
233+
*
234+
* @param name - The name of the configuration profile to retrieve
235+
* @param options - Optional options to configure the provider
236+
* @param options.maxAge - Optional maximum age of the value in the cache, in seconds (default: `5`)
237+
* @param options.forceFetch - Optional flag to always fetch a new value from the store regardless if already available in cache (default: `false`)
238+
* @param options.transform - Optional transform to be applied, can be `json` or `binary`
239+
* @param options.sdkOptions - Optional additional options to pass to the AWS SDK v3 client, supports all options from {@link StartConfigurationSessionCommandInput | `StartConfigurationSessionCommandInput`} except `ApplicationIdentifier`, `EnvironmentIdentifier`, and `ConfigurationProfileIdentifier`
249240
*/
250-
public async get<
241+
public get<
251242
ExplicitUserProvidedType = undefined,
252243
InferredFromOptionsType extends
253244
| AppConfigGetOptions
254245
| undefined = AppConfigGetOptions,
255246
>(
256247
name: string,
257-
options?: InferredFromOptionsType & AppConfigGetOptions
248+
options?: NonNullable<InferredFromOptionsType & AppConfigGetOptions>
258249
): Promise<
259250
| AppConfigGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
260251
| undefined
@@ -287,12 +278,16 @@ class AppConfigProvider extends BaseProvider {
287278
* polls the configuration multiple times, we return the most recent value by returning the cached
288279
* one if an empty response is returned by AppConfig.
289280
*
290-
* @param {string} name - Name of the configuration or its ID
291-
* @param {AppConfigGetOptions} options - SDK options to propagate to `StartConfigurationSession` API call
281+
* @param name - Name of the configuration or its ID
282+
* @param options - SDK options to propagate to `StartConfigurationSession` API call
283+
* @param options.maxAge - Maximum age of the value in the cache, in seconds.
284+
* @param options.forceFetch - Force fetch the value from the parameter store, ignoring the cache.
285+
* @param options.sdkOptions - Additional options to pass to the AWS SDK v3 client. Supports all options from {@link StartConfigurationSessionCommandInput | `StartConfigurationSessionCommandInput`} except `ApplicationIdentifier`, `EnvironmentIdentifier`, and `ConfigurationProfileIdentifier`.
286+
* @param options.transform - Optional transform to be applied, can be 'json' or 'binary'.
292287
*/
293288
protected async _get(
294289
name: string,
295-
options?: AppConfigGetOptions
290+
options?: NonNullable<AppConfigGetOptions>
296291
): Promise<Uint8Array | undefined> {
297292
if (
298293
!this.configurationTokenStore.has(name) ||
@@ -339,7 +334,7 @@ class AppConfigProvider extends BaseProvider {
339334
/** When the response is not empty, stash the result locally before returning
340335
* See AppConfig docs:
341336
* {@link https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-the-configuration.html}
342-
**/
337+
*/
343338
if (
344339
response.Configuration !== undefined &&
345340
response.Configuration?.length > 0
@@ -358,7 +353,7 @@ class AppConfigProvider extends BaseProvider {
358353
*
359354
* @throws Not Implemented Error.
360355
*/
361-
protected async _getMultiple(
356+
protected _getMultiple(
362357
_path: string,
363358
_sdkOptions?: unknown
364359
): Promise<Record<string, unknown> | undefined> {

packages/parameters/src/appconfig/getAppConfig.ts

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,30 @@ import type {
66
import { AppConfigProvider } from './AppConfigProvider.js';
77

88
/**
9-
* ## Intro
10-
* The Parameters utility provides an AppConfigProvider that allows to retrieve configuration profiles from AWS AppConfig.
9+
* The Parameters utility provides an `AppConfigProvider` that allows to retrieve configuration profiles from AWS AppConfig.
1110
*
12-
* ## Getting started
13-
*
14-
* This utility supports AWS SDK v3 for JavaScript only. This allows the utility to be modular, and you to install only
11+
* This utility supports AWS SDK v3 for JavaScript only (`@aws-sdk/client-appconfigdata`). This allows the utility to be modular, and you to install only
1512
* the SDK packages you need and keep your bundle size small.
1613
*
17-
* To use the provider, you must install the Parameters utility and the AWS SDK v3 for JavaScript for AppConfig:
18-
*
19-
* ```sh
20-
* npm install @aws-lambda-powertools/parameters @aws-sdk/client-appconfigdata
21-
* ```
22-
*
23-
* ## Basic usage
14+
* **Basic usage**
2415
*
2516
* @example
2617
* ```typescript
2718
* import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
2819
*
20+
* const encodedConfig = await getAppConfig('my-config', {
21+
* application: 'my-app',
22+
* environment: 'prod',
23+
* });
24+
* const config = new TextDecoder('utf-8').decode(encodedConfig);
25+
*
2926
* export const handler = async (): Promise<void> => {
30-
* // Retrieve a configuration profile
31-
* const encodedConfig = await getAppConfig('my-config', {
32-
* application: 'my-app',
33-
* environment: 'prod',
34-
* });
35-
* const config = new TextDecoder('utf-8').decode(encodedConfig);
27+
* // Use the config variable as needed
28+
* console.log(config);
3629
* };
3730
* ```
3831
*
39-
* ## Advanced usage
40-
*
41-
* ### Caching
32+
* **Caching**
4233
*
4334
* By default, the provider will cache parameters retrieved in-memory for 5 seconds.
4435
* You can adjust how long values should be kept in cache by using the `maxAge` parameter.
@@ -47,13 +38,15 @@ import { AppConfigProvider } from './AppConfigProvider.js';
4738
* ```typescript
4839
* import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
4940
*
41+
* const encodedConfig = await getAppConfig('my-config', {
42+
* application: 'my-app',
43+
* environment: 'prod',
44+
* maxAge: 10, // Cache for 10 seconds
45+
* });
46+
* const config = new TextDecoder('utf-8').decode(encodedConfig);
47+
*
5048
* export const handler = async (): Promise<void> => {
51-
* // Retrieve a configuration profile and cache it for 10 seconds
52-
* const encodedConfig = await getAppConfig('my-config', {
53-
* application: 'my-app',
54-
* environment: 'prod',
55-
* });
56-
* const config = new TextDecoder('utf-8').decode(encodedConfig);
49+
* // Use the config variable as needed
5750
* };
5851
* ```
5952
*
@@ -63,32 +56,37 @@ import { AppConfigProvider } from './AppConfigProvider.js';
6356
* ```typescript
6457
* import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
6558
*
59+
* const encodedConfig = await getAppConfig('my-config', {
60+
* application: 'my-app',
61+
* environment: 'prod',
62+
* forceFetch: true, // Always fetch the latest value
63+
* });
64+
* const config = new TextDecoder('utf-8').decode(encodedConfig);
65+
*
6666
* export const handler = async (): Promise<void> => {
67-
* // Retrieve a config and always fetch the latest value
68-
* const config = await getAppConfig('my-config', {
69-
* application: 'my-app',
70-
* environment: 'prod',
71-
* forceFetch: true,
72-
* });
73-
* const config = new TextDecoder('utf-8').decode(encodedConfig);
67+
* // Use the config variable as needed
68+
* console.log
7469
* };
7570
* ```
7671
*
77-
* ### Transformations
72+
* **Transformations**
7873
*
7974
* For configurations stored as freeform JSON, Freature Flag, you can use the transform argument for deserialization. This will return a JavaScript object instead of a string.
8075
*
8176
* @example
8277
* ```typescript
8378
* import { getAppConfig } from '@aws-lambda-powertools/parameters/appconfig';
8479
*
80+
* // Retrieve a JSON config and parse it as JSON
81+
* const encodedConfig = await getAppConfig('my-config', {
82+
* application: 'my-app',
83+
* environment: 'prod',
84+
* transform: 'json'
85+
* });
86+
*
8587
* export const handler = async (): Promise<void> => {
86-
* // Retrieve a JSON config or Feature Flag and parse it as JSON
87-
* const config = await getAppConfig('my-config', {
88-
* application: 'my-app',
89-
* environment: 'prod',
90-
* transform: 'json'
91-
* });
88+
* // Use the config variable as needed
89+
* console.log(config);
9290
* };
9391
* ```
9492
*
@@ -108,7 +106,7 @@ import { AppConfigProvider } from './AppConfigProvider.js';
108106
* };
109107
* ```
110108
*
111-
* ### Extra SDK options
109+
* **Extra SDK options**
112110
*
113111
* When retrieving a configuration profile, you can pass extra options to the AWS SDK v3 for JavaScript client by using the `sdkOptions` parameter.
114112
*
@@ -131,15 +129,18 @@ import { AppConfigProvider } from './AppConfigProvider.js';
131129
*
132130
* This object accepts the same options as the [AWS SDK v3 for JavaScript AppConfigData client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-appconfigdata/interfaces/startconfigurationsessioncommandinput.html).
133131
*
134-
* ### Built-in provider class
132+
* For greater flexibility such as configuring the underlying SDK client used by built-in providers, you can use the {@link AppConfigProvider | `AppConfigProvider`} class.
135133
*
136-
* For greater flexibility such as configuring the underlying SDK client used by built-in providers, you can use the {@link AppConfigProvider} class.
137-
*
138-
* For more usage examples, see [our documentation](https://docs.powertools.aws.dev/lambda/typescript/latest/features/parameters/).
139-
*
140-
* @param {string} name - The name of the configuration profile or its ID
141-
* @param {GetAppConfigOptions} options - Options to configure the provider
142134
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/features/parameters/
135+
*
136+
* @param name - The name of the configuration profile to retrieve
137+
* @param options - Options to configure the provider
138+
* @param options.application - The application ID or the application name
139+
* @param options.environment - The environment ID or the environment name
140+
* @param options.maxAge - Optional maximum age of the value in the cache, in seconds (default: `5`)
141+
* @param options.forceFetch - Optional flag to always fetch a new value from the store regardless if already available in cache (default: `false`)
142+
* @param options.transform - Optional transform to be applied, can be `json` or `binary`
143+
* @param options.sdkOptions - Optional additional options to pass to the AWS SDK v3 client, supports all options from {@link StartConfigurationSessionCommandInput | `StartConfigurationSessionCommandInput`} except `ApplicationIdentifier`, `EnvironmentIdentifier`, and `ConfigurationProfileIdentifier`
143144
*/
144145
const getAppConfig = <
145146
ExplicitUserProvidedType = undefined,
@@ -148,7 +149,7 @@ const getAppConfig = <
148149
| undefined = GetAppConfigOptions,
149150
>(
150151
name: string,
151-
options: InferredFromOptionsType & GetAppConfigOptions
152+
options: NonNullable<InferredFromOptionsType & GetAppConfigOptions>
152153
): Promise<
153154
| AppConfigGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
154155
| undefined

0 commit comments

Comments
 (0)