Skip to content

Commit 7777163

Browse files
committed
style(parameters): apply stricter linting
1 parent 7f09718 commit 7777163

File tree

11 files changed

+98
-118
lines changed

11 files changed

+98
-118
lines changed

packages/parameters/src/appconfig/AppConfigProvider.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { getServiceName } from '@aws-lambda-powertools/commons/utils/env';
2-
import type {
3-
AppConfigDataClientConfig,
4-
StartConfigurationSessionCommandInput,
5-
} from '@aws-sdk/client-appconfigdata';
2+
import type { StartConfigurationSessionCommandInput } from '@aws-sdk/client-appconfigdata';
63
import {
74
AppConfigDataClient,
85
GetLatestConfigurationCommand,
@@ -190,26 +187,20 @@ class AppConfigProvider extends BaseProvider {
190187
private readonly application?: string;
191188
private readonly environment: string;
192189

193-
/**
194-
* initializes an `AppConfigProvider` class instance.
195-
*
196-
* @param options - The configuration object.
197-
* @param options.environment - The environment ID or the environment name.
198-
* @param options.application - Optional application ID or the application name.
199-
* @param options.clientConfig - Optional configuration to pass during client initialization, e.g. AWS region. Mutually exclusive with `awsSdkV3Client`. Accepts the same configuration object as the AWS SDK v3 client ({@link AppConfigDataClientConfig | `AppConfigDataClientConfig`}).
200-
* @param options.awsSdkV3Client - Optional ({@link AppConfigDataClient | `AppConfigDataClient`}) instance to pass during `AppConfigProvider` class instantiation. Mutually exclusive with `clientConfig`.
201-
*
202-
*/
203-
public constructor(options: AppConfigProviderOptions) {
190+
public constructor({
191+
application,
192+
environment,
193+
clientConfig,
194+
awsSdkV3Client,
195+
}: AppConfigProviderOptions) {
204196
super({
205197
awsSdkV3ClientPrototype: AppConfigDataClient as new (
206198
config?: unknown
207199
) => AppConfigDataClient,
208-
clientConfig: options.clientConfig,
209-
awsSdkV3Client: options.awsSdkV3Client,
200+
clientConfig,
201+
awsSdkV3Client,
210202
});
211203

212-
const { application, environment } = options;
213204
this.application = application ?? getServiceName();
214205
if (!this.application || this.application.trim().length === 0) {
215206
throw new Error(
@@ -254,7 +245,7 @@ class AppConfigProvider extends BaseProvider {
254245
| undefined = AppConfigGetOptions,
255246
>(
256247
name: string,
257-
options?: InferredFromOptionsType & AppConfigGetOptions
248+
options?: NonNullable<InferredFromOptionsType & AppConfigGetOptions>
258249
): Promise<
259250
| AppConfigGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
260251
| undefined
@@ -296,7 +287,7 @@ class AppConfigProvider extends BaseProvider {
296287
*/
297288
protected async _get(
298289
name: string,
299-
options?: AppConfigGetOptions
290+
options?: NonNullable<AppConfigGetOptions>
300291
): Promise<Uint8Array | undefined> {
301292
if (
302293
!this.configurationTokenStore.has(name) ||

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 or its ID
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 - The maximum age (in seconds) to keep values in cache. Default: 5 seconds.
141+
* @param options.forceFetch - Whether to skip the cache and always fetch the latest value from the store. Default: `false`.
142+
* @param options.transform - Optional transformation to apply to the retrieved value. Supported options are: 'json' and 'binary'.
143+
* @param options.sdkOptions - Optional extra options to pass to the AWS SDK v3 for JavaScript client when retrieving the configuration profile.
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

packages/parameters/src/dynamodb/DynamoDBProvider.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,6 @@ class DynamoDBProvider extends BaseProvider {
234234
protected tableName: string;
235235
protected valueAttr = 'value';
236236

237-
/**
238-
* Initialize a DynamoDBProvider class instance.
239-
*
240-
* @param config - The configuration object.
241-
* @param config.tableName - The DynamoDB table name.
242-
* @param config.keyAttr - Optional DynamoDB table key attribute name. Defaults to 'id'.
243-
* @param config.sortAttr - Optional DynamoDB table sort attribute name. Defaults to 'sk'.
244-
* @param config.valueAttr - Optional DynamoDB table value attribute name. Defaults to 'value'.
245-
* @param config.clientConfig - Optional configuration to pass during client initialization, e.g. AWS region. Mutually exclusive with `awsSdkV3Client`, accepts the same options as the AWS SDK v3 client ({@link DynamoDBClient | `DynamoDBClient`}).
246-
* @param config.awsSdkV3Client - Optional AWS SDK v3 client to pass during DynamoDBProvider class instantiation. Mutually exclusive with `clientConfig`, should be an instance of {@link DynamoDBClient | `DynamoDBClient`}.
247-
*/
248237
public constructor(config: DynamoDBProviderOptions) {
249238
super({
250239
awsSdkV3ClientPrototype: DynamoDBClient as new (
@@ -293,7 +282,7 @@ class DynamoDBProvider extends BaseProvider {
293282
| undefined = DynamoDBGetOptions,
294283
>(
295284
name: string,
296-
options?: InferredFromOptionsType & DynamoDBGetOptions
285+
options?: NonNullable<InferredFromOptionsType & DynamoDBGetOptions>
297286
): Promise<
298287
| DynamoDBGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
299288
| undefined
@@ -338,7 +327,7 @@ class DynamoDBProvider extends BaseProvider {
338327
| undefined = DynamoDBGetMultipleOptions,
339328
>(
340329
path: string,
341-
options?: InferredFromOptionsType & DynamoDBGetMultipleOptions
330+
options?: NonNullable<InferredFromOptionsType & DynamoDBGetMultipleOptions>
342331
): Promise<
343332
| DynamoDBGetMultipleOutput<
344333
ExplicitUserProvidedType,
@@ -362,12 +351,12 @@ class DynamoDBProvider extends BaseProvider {
362351
* @param options - Options to customize the retrieval
363352
* @param options.maxAge - Maximum age of the value in the cache, in seconds.
364353
* @param options.sdkOptions - Additional options to pass to the AWS SDK v3 client, supports all options from {@link GetItemCommandInput | `GetItemCommandInput`} except `Key`, `TableName`, and `ProjectionExpression`.
365-
* @param params.forceFetch - Force fetch the value from the parameter store, ignoring the cache.
354+
* @param options.forceFetch - Force fetch the value from the parameter store, ignoring the cache.
366355
* @param options.transform - Transform to be applied, can be 'json' or 'binary'.
367356
*/
368357
protected async _get(
369358
name: string,
370-
options?: DynamoDBGetOptions
359+
options?: NonNullable<DynamoDBGetOptions>
371360
): Promise<JSONValue | undefined> {
372361
const sdkOptions: GetItemCommandInput = {
373362
...(options?.sdkOptions || {}),
@@ -396,7 +385,7 @@ class DynamoDBProvider extends BaseProvider {
396385
*/
397386
protected async _getMultiple(
398387
path: string,
399-
options?: DynamoDBGetMultipleOptions
388+
options?: NonNullable<DynamoDBGetMultipleOptions>
400389
): Promise<Record<string, JSONValue>> {
401390
const sdkOptions: QueryCommandInput = {
402391
...(options?.sdkOptions || {}),

packages/parameters/src/secrets/SecretsProvider.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,7 @@ import type {
140140
class SecretsProvider extends BaseProvider {
141141
public declare client: SecretsManagerClient;
142142

143-
/**
144-
* Initialize a `SecretsProvider` class.
145-
*
146-
* @param config - The configuration object.
147-
* @param config.clientConfig - Optional configuration to pass during client initialization, e.g. AWS region. Mutually exclusive with `awsSdkV3Client`.
148-
* @param config.awsSdkV3Client - Optional AWS SDK v3 client to pass during {@link SecretsProvider | `SecretsProvider`} class instantiation. Mutually exclusive with `clientConfig`.
149-
*/
150-
public constructor(config?: SecretsProviderOptions) {
143+
public constructor(config?: NonNullable<SecretsProviderOptions>) {
151144
super({
152145
awsSdkV3ClientPrototype: SecretsManagerClient as new (
153146
config?: unknown
@@ -187,7 +180,7 @@ class SecretsProvider extends BaseProvider {
187180
| undefined = SecretsGetOptions,
188181
>(
189182
name: string,
190-
options?: InferredFromOptionsType & SecretsGetOptions
183+
options?: NonNullable<InferredFromOptionsType & SecretsGetOptions>
191184
): Promise<
192185
| SecretsGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
193186
| undefined
@@ -217,7 +210,7 @@ class SecretsProvider extends BaseProvider {
217210
*/
218211
protected async _get(
219212
name: string,
220-
options?: SecretsGetOptions
213+
options?: NonNullable<SecretsGetOptions>
221214
): Promise<string | Uint8Array | undefined> {
222215
const sdkOptions: GetSecretValueCommandInput = {
223216
...(options?.sdkOptions || {}),

packages/parameters/src/secrets/getSecret.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import { SecretsProvider } from './SecretsProvider.js';
9797
* @param options.forceFetch - Whether to always fetch a new value from the store regardless if already available in cache (default: `false`)
9898
* @param options.transform - Whether to transform the value before returning it. Supported values: `json`, `binary`
9999
* @param options.sdkOptions - Extra options to pass to the AWS SDK v3 for JavaScript client, accepts the same configuration object as the AWS SDK v3 client ({@link SecretsManagerClientConfig | `SecretsManagerClientConfig`}).
100-
* @param options.decrypt - Whether to decrypt the value before returning it. (default: `false`)
101100
*/
102101
const getSecret = <
103102
ExplicitUserProvidedType = undefined,
@@ -106,7 +105,7 @@ const getSecret = <
106105
| undefined = SecretsGetOptions,
107106
>(
108107
name: string,
109-
options?: InferredFromOptionsType & SecretsGetOptions
108+
options?: NonNullable<InferredFromOptionsType & SecretsGetOptions>
110109
): Promise<
111110
| SecretsGetOutput<ExplicitUserProvidedType, InferredFromOptionsType>
112111
| undefined

0 commit comments

Comments
 (0)