Skip to content

Commit f851c11

Browse files
committed
chore(maintenance): migrate parameters utility to biome
1 parent 8b0cae4 commit f851c11

22 files changed

+53
-94
lines changed

packages/parameters/src/appconfig/AppConfigProvider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class AppConfigProvider extends BaseProvider {
292292
): Promise<Uint8Array | undefined> {
293293
if (
294294
!this.configurationTokenStore.has(name) ||
295+
// biome-ignore lint/style/noNonNullAssertion: we check if the value is in the map before accessing it
295296
this.configurationTokenStore.get(name)!.expiration <= Date.now()
296297
) {
297298
const sessionOptions: StartConfigurationSessionCommandInput = {
@@ -356,7 +357,7 @@ class AppConfigProvider extends BaseProvider {
356357
protected async _getMultiple(
357358
_path: string,
358359
_sdkOptions?: unknown
359-
): Promise<void> {
360+
): Promise<Record<string, unknown> | undefined> {
360361
throw new Error('Method not implemented.');
361362
}
362363
}

packages/parameters/src/base/BaseProvider.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ abstract class BaseProvider implements BaseProviderInterface {
9797
name: string,
9898
options?: GetOptionsInterface
9999
): Promise<unknown | undefined> {
100-
const configs = new GetOptions(options, this.envVarsService);
100+
const configs = new GetOptions(this.envVarsService, options);
101101
const key = [name, configs.transform].toString();
102102

103103
if (!configs.forceFetch && !this.hasKeyExpiredInCache(key)) {
@@ -136,16 +136,15 @@ abstract class BaseProvider implements BaseProviderInterface {
136136
path: string,
137137
options?: GetMultipleOptionsInterface
138138
): Promise<unknown> {
139-
const configs = new GetMultipleOptions(options, this.envVarsService);
139+
const configs = new GetMultipleOptions(this.envVarsService, options);
140140
const key = [path, configs.transform].toString();
141141

142142
if (!configs.forceFetch && !this.hasKeyExpiredInCache(key)) {
143-
// If the code enters in this block, then the key must exist & not have been expired
144-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
143+
// biome-ignore lint/style/noNonNullAssertion: If the code enters in this block, then the key must exist & not have been expired
145144
return this.store.get(key)!.value as Record<string, unknown>;
146145
}
147146

148-
let values;
147+
let values: Record<string, unknown> | undefined;
149148
try {
150149
values = await this._getMultiple(path, options);
151150
if (!isRecord(values)) {
@@ -216,7 +215,7 @@ abstract class BaseProvider implements BaseProviderInterface {
216215
protected abstract _getMultiple(
217216
path: string,
218217
options?: unknown
219-
): Promise<Record<string, unknown> | void>;
218+
): Promise<Record<string, unknown> | undefined>;
220219
}
221220

222221
export { BaseProvider };

packages/parameters/src/base/GetMultipleOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GetOptions } from './GetOptions.js';
2-
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
2+
import type { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
33
import type { GetMultipleOptionsInterface } from '../types/BaseProvider.js';
44

55
/**
@@ -14,8 +14,8 @@ class GetMultipleOptions
1414
public throwOnTransformError = false;
1515

1616
public constructor(
17+
envVarsService: EnvironmentVariablesService,
1718
options: GetMultipleOptionsInterface = {},
18-
envVarsService: EnvironmentVariablesService
1919
) {
2020
super(options, envVarsService);
2121

packages/parameters/src/base/GetOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
1+
import type { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
22
import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
33
import type {
44
GetOptionsInterface,
@@ -17,8 +17,8 @@ class GetOptions implements GetOptionsInterface {
1717
public transform?: TransformOptions;
1818

1919
public constructor(
20+
envVarsService: EnvironmentVariablesService,
2021
options: GetOptionsInterface = {},
21-
envVarsService: EnvironmentVariablesService
2222
) {
2323
Object.assign(this, options);
2424

packages/parameters/src/base/transformValue.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const transformValue = (
6666
if (isJsonTransform || isAutoJsonTransform) {
6767
return JSON.parse(value) as JSONValue;
6868
// If the transform is `binary` or `auto` and the key ends with `.binary`, decode the value from base64
69-
} else if (isBinaryTransform || isAutoBinaryTransform) {
69+
}
70+
if (isBinaryTransform || isAutoBinaryTransform) {
7071
return new TextDecoder('utf-8').decode(fromBase64(value, 'base64'));
7172
}
7273
} catch (error) {

packages/parameters/src/config/EnvironmentVariablesService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigServiceInterface } from '../types/ConfigServiceInterface.js';
1+
import type { ConfigServiceInterface } from '../types/ConfigServiceInterface.js';
22
import { DEFAULT_MAX_AGE_SECS } from '../constants.js';
33
import { EnvironmentVariablesService as CommonEnvironmentVariablesService } from '@aws-lambda-powertools/commons';
44

@@ -20,8 +20,8 @@ class EnvironmentVariablesService
2020

2121
if (maxAge.length === 0) return undefined;
2222

23-
const maxAgeAsNumber = parseInt(maxAge, 10);
24-
if (isNaN(maxAgeAsNumber)) {
23+
const maxAgeAsNumber = Number.parseInt(maxAge, 10);
24+
if (Number.isNaN(maxAgeAsNumber)) {
2525
console.warn(
2626
`Invalid value for ${this.parametersMaxAgeVariable} environment variable: [${maxAge}], using default value of ${DEFAULT_MAX_AGE_SECS} seconds`
2727
);

packages/parameters/src/secrets/SecretsProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class SecretsProvider extends BaseProvider {
245245
protected async _getMultiple(
246246
_path: string,
247247
_options?: unknown
248-
): Promise<void> {
248+
): Promise<Record<string, unknown> | undefined> {
249249
throw new Error('Method not implemented.');
250250
}
251251
}

packages/parameters/src/ssm/SSMProvider.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type {
2727
SSMSplitBatchAndDecryptParametersOutputType,
2828
SSMGetParametersByNameFromCacheOutputType,
2929
} from '../types/SSMProvider.js';
30+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
3031

3132
/**
3233
* ## Intro
@@ -550,9 +551,7 @@ class SSMProvider extends BaseProvider {
550551
* The parameter name returned by SSM will contain the full path.
551552
* However, for readability, we should return only the part after the path.
552553
**/
553-
554-
// If the parameter is present in the response, then it has a Name
555-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
554+
// biome-ignore lint/style/noNonNullAssertion: If the parameter is present in the response, then it has a Name
556555
let name = parameter.Name!;
557556
name = name.replace(path, '');
558557
if (name.startsWith('/')) {
@@ -656,8 +655,7 @@ class SSMProvider extends BaseProvider {
656655
)) {
657656
const cacheKey = [parameterName, parameterOptions.transform].toString();
658657
if (!this.hasKeyExpiredInCache(cacheKey)) {
659-
// Since we know the key exists in the cache, we can safely use the non-null assertion operator
660-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
658+
// biome-ignore lint/style/noNonNullAssertion: Since we know the key exists in the cache, we can safely use the non-null assertion operator
661659
cached[parameterName] = this.store.get(cacheKey)!.value as Record<
662660
string,
663661
string | Record<string, unknown>
@@ -867,13 +865,12 @@ class SSMProvider extends BaseProvider {
867865
const processedParameters: Record<string, unknown> = {};
868866

869867
for (const parameter of response.Parameters || []) {
870-
// If the parameter is present in the response, then it has a Name
871-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
868+
// biome-ignore lint/style/noNonNullAssertion: If the parameter is present in the response, then it has a Name
872869
const parameterName = parameter.Name!;
873870
const parameterValue = parameter.Value;
874871
const parameterOptions = parameters[parameterName];
875872

876-
let value;
873+
let value: string | JSONValue | Uint8Array | undefined;
877874
// NOTE: if transform is set, we do it before caching to reduce number of operations
878875
if (parameterValue && parameterOptions.transform) {
879876
value = transformValue(

packages/parameters/src/types/BaseProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Transform } from '../constants.js';
1+
import type { Transform } from '../constants.js';
22

33
/**
44
* Type for the transform option.
@@ -74,7 +74,7 @@ interface BaseProviderInterface {
7474
getMultiple(
7575
path: string,
7676
options?: GetMultipleOptionsInterface
77-
): Promise<unknown | void>;
77+
): Promise<unknown | unknown>;
7878
clearCache?(): void;
7979
}
8080

packages/parameters/tests/e2e/appConfigProvider.class.test.functionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Context } from 'aws-lambda';
22
import { Transform } from '../../src/constants.js';
33
import { AppConfigProvider } from '../../src/appconfig/AppConfigProvider.js';
4-
import { AppConfigGetOptions } from '../../src/types/AppConfigProvider.js';
4+
import type { AppConfigGetOptions } from '../../src/types/AppConfigProvider.js';
55
import { TinyLogger } from '../helpers/tinyLogger.js';
66
import { middleware } from '../helpers/sdkMiddlewareRequestCounter.js';
77
import { AppConfigDataClient } from '@aws-sdk/client-appconfigdata';

packages/parameters/tests/e2e/appConfigProvider.class.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import {
7171
* is created after the previous one. This is necessary because we share the same AppConfig
7272
* application and environment for all tests.
7373
*/
74-
describe(`Parameters E2E tests, AppConfig provider`, () => {
74+
describe('Parameters E2E tests, AppConfig provider', () => {
7575
const testStack = new TestStack({
7676
stackNameProps: {
7777
stackNamePrefix: RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/dynamoDBProvider.class.test.functionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Context } from 'aws-lambda';
22
import { Transform } from '../../src/constants.js';
33
import { DynamoDBProvider } from '../../src/dynamodb/DynamoDBProvider.js';
4-
import {
4+
import type {
55
DynamoDBGetOptions,
66
DynamoDBGetMultipleOptions,
77
} from '../../src/types/DynamoDBProvider.js';

packages/parameters/tests/e2e/dynamoDBProvider.class.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import {
9595
* Test 9
9696
* Get a cached parameter and force retrieval. This also uses the same custom SDK client that counts the number of calls to DynamoDB.
9797
*/
98-
describe(`Parameters E2E tests, dynamoDB provider`, () => {
98+
describe('Parameters E2E tests, dynamoDB provider', () => {
9999
const testStack = new TestStack({
100100
stackNameProps: {
101101
stackNamePrefix: RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/secretsProvider.class.test.functionCode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Context } from 'aws-lambda';
1+
import type { Context } from 'aws-lambda';
22
import { TinyLogger } from '../helpers/tinyLogger.js';
33
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
44
import { middleware } from '../helpers/sdkMiddlewareRequestCounter.js';
55
import { Transform } from '../../src/constants.js';
66
import { SecretsProvider } from '../../src/secrets/SecretsProvider.js';
7-
import { SecretsGetOptions } from '../../src/types/SecretsProvider.js';
7+
import type { SecretsGetOptions } from '../../src/types/SecretsProvider.js';
88

99
const logger = new TinyLogger();
1010
const defaultProvider = new SecretsProvider();

packages/parameters/tests/e2e/secretsProvider.class.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
* Make sure to add the right permissions to the lambda function to access the resources. We use our `ResourceAccessGranter` to add permissions.
3737
*
3838
*/
39-
describe(`Parameters E2E tests, Secrets Manager provider`, () => {
39+
describe('Parameters E2E tests, Secrets Manager provider', () => {
4040
const testStack = new TestStack({
4141
stackNameProps: {
4242
stackNamePrefix: RESOURCE_NAME_PREFIX,

packages/parameters/tests/e2e/ssmProvider.class.test.functionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Context } from 'aws-lambda';
22
import { SSMProvider } from '../../src/ssm/SSMProvider.js';
3-
import {
3+
import type {
44
SSMGetOptions,
55
SSMGetMultipleOptions,
66
SSMGetParametersByNameOptions,

packages/parameters/tests/e2e/ssmProvider.class.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ import {
7070
* get parameter twice, but force fetch 2nd time, we count number of SDK requests and
7171
* check that we made two API calls
7272
*/
73-
describe(`Parameters E2E tests, SSM provider`, () => {
73+
describe('Parameters E2E tests, SSM provider', () => {
7474
const testStack = new TestStack({
7575
stackNameProps: {
7676
stackNamePrefix: RESOURCE_NAME_PREFIX,

packages/parameters/tests/helpers/resources.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getRuntimeKey,
99
type TestStack,
1010
} from '@aws-lambda-powertools/testing-utils';
11-
import { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
11+
import type { TestNodejsFunction } from '@aws-lambda-powertools/testing-utils/resources/lambda';
1212
import { TestDynamodbTable } from '@aws-lambda-powertools/testing-utils/resources/dynamodb';
1313
import { marshall } from '@aws-sdk/util-dynamodb';
1414
import { CfnOutput, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
@@ -18,15 +18,15 @@ import {
1818
ConfigurationType,
1919
DeploymentStrategy,
2020
HostedConfiguration,
21-
IEnvironment,
21+
type IEnvironment,
2222
RolloutStrategy,
23-
CfnHostedConfigurationVersion,
23+
type CfnHostedConfigurationVersion,
2424
} from 'aws-cdk-lib/aws-appconfig';
2525
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
2626
import type { SecretProps } from 'aws-cdk-lib/aws-secretsmanager';
2727
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
2828
import type { StringParameterProps } from 'aws-cdk-lib/aws-ssm';
29-
import { IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';
29+
import { type IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';
3030
import {
3131
AwsCustomResource,
3232
AwsCustomResourcePolicy,
@@ -266,7 +266,7 @@ class TestAppConfigWithProfiles extends Construct {
266266
}
267267
);
268268

269-
profiles.forEach((profile) => {
269+
for (const profile of profiles) {
270270
const config = new HostedConfiguration(
271271
testStack.stack,
272272
`hc-${randomUUID()}`,
@@ -291,7 +291,7 @@ class TestAppConfigWithProfiles extends Construct {
291291
config.node.defaultChild as CfnHostedConfigurationVersion
292292
).applyRemovalPolicy(RemovalPolicy.DESTROY);
293293
this.profiles.push(config);
294-
});
294+
};
295295
}
296296

297297
/**
@@ -300,7 +300,9 @@ class TestAppConfigWithProfiles extends Construct {
300300
* @param fn The function to add the environment variables to
301301
*/
302302
public addEnvVariablesToFunction(fn: TestNodejsFunction): void {
303+
// biome-ignore lint/style/noNonNullAssertion: we know this is called after the AppConfig resources are created
303304
fn.addEnvironment('APPLICATION_NAME', this.application.name!);
305+
// biome-ignore lint/style/noNonNullAssertion: we know this is called after the AppConfig resources are created
304306
fn.addEnvironment('ENVIRONMENT_NAME', this.environment.name!);
305307
fn.addEnvironment(
306308
'FREEFORM_JSON_NAME',
@@ -326,9 +328,10 @@ class TestAppConfigWithProfiles extends Construct {
326328
* @param fn The function to grant access to the profiles
327329
*/
328330
public grantReadData(fn: TestNodejsFunction): void {
329-
this.profiles.forEach((profile) => {
331+
for (const profile of this.profiles) {
330332
const appConfigConfigurationArn = Stack.of(fn).formatArn({
331333
service: 'appconfig',
334+
// biome-ignore lint/style/noNonNullAssertion: we know this is called after the AppConfig resources are created
332335
resource: `application/${profile.application.applicationId}/environment/${profile.deployTo![0].environmentId}/configuration/${profile.configurationProfileId}`,
333336
});
334337

@@ -342,7 +345,7 @@ class TestAppConfigWithProfiles extends Construct {
342345
resources: [appConfigConfigurationArn],
343346
})
344347
);
345-
});
348+
};
346349
}
347350
}
348351

packages/parameters/tests/unit/AppConfigProvider.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { AppConfigProvider } from '../../src/appconfig/index.js';
77
import { ExpirableValue } from '../../src/base/ExpirableValue.js';
8-
import { AppConfigProviderOptions } from '../../src/types/AppConfigProvider.js';
8+
import type { AppConfigProviderOptions } from '../../src/types/AppConfigProvider.js';
99
import {
1010
AppConfigDataClient,
1111
GetLatestConfigurationCommand,

packages/parameters/tests/unit/BaseProvider.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,7 @@ describe('Class: GetOptions', () => {
633633
getParametersMaxAge: jest.fn(),
634634
};
635635
const options = new GetOptions(
636-
undefined,
637-
envVarsService as unknown as EnvironmentVariablesService
636+
envVarsService as unknown as EnvironmentVariablesService,
638637
);
639638

640639
// Assess
@@ -649,8 +648,7 @@ describe('Class: GetMultipleOptions', () => {
649648
getParametersMaxAge: jest.fn(),
650649
};
651650
const options = new GetMultipleOptions(
652-
undefined,
653-
envVarsService as unknown as EnvironmentVariablesService
651+
envVarsService as unknown as EnvironmentVariablesService,
654652
);
655653

656654
// Assess

0 commit comments

Comments
 (0)