Skip to content

Commit abd3832

Browse files
authored
chore(maintenance): migrate parameters utility to biome (#2812)
1 parent 4d44b91 commit abd3832

39 files changed

+194
-253
lines changed

packages/parameters/package.json

+7-21
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
2121
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
2222
"build": "npm run build:esm & npm run build:cjs",
23-
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
24-
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
23+
"lint": "biome lint .",
24+
"lint:fix": "biome check --write .",
2525
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
2626
},
2727
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/parameters#readme",
@@ -89,26 +89,17 @@
8989
"lib/cjs/types/BaseProvider.d.ts",
9090
"lib/esm/types/BaseProvider.d.ts"
9191
],
92-
"base": [
93-
"lib/cjs/base/index.d.ts",
94-
"lib/esm/base/index.d.ts"
95-
],
92+
"base": ["lib/cjs/base/index.d.ts", "lib/esm/base/index.d.ts"],
9693
"ssm/types": [
9794
"lib/cjs/types/SSMProvider.d.ts",
9895
"lib/esm/types/SSMProvider.d.ts"
9996
],
100-
"ssm": [
101-
"lib/cjs/ssm/index.d.ts",
102-
"lib/esm/ssm/index.d.ts"
103-
],
97+
"ssm": ["lib/cjs/ssm/index.d.ts", "lib/esm/ssm/index.d.ts"],
10498
"secrets/types": [
10599
"lib/cjs/types/SecretsProvider.d.ts",
106100
"lib/esm/types/SecretsProvider.d.ts"
107101
],
108-
"secrets": [
109-
"lib/cjs/secrets/index.d.ts",
110-
"lib/esm/secrets/index.d.ts"
111-
],
102+
"secrets": ["lib/cjs/secrets/index.d.ts", "lib/esm/secrets/index.d.ts"],
112103
"dynamodb/types": [
113104
"./lib/cjs/types/DynamoDBProvider.d.ts",
114105
"./lib/esm/types/DynamoDBProvider.d.ts"
@@ -125,17 +116,12 @@
125116
"lib/cjs/appconfig/index.d.ts",
126117
"lib/esm/appconfig/index.d.ts"
127118
],
128-
"errors": [
129-
"lib/cjs/errors.d.ts",
130-
"lib/esm/errors.d.ts"
131-
]
119+
"errors": ["lib/cjs/errors.d.ts", "lib/esm/errors.d.ts"]
132120
}
133121
},
134122
"types": "./lib/cjs/index.d.ts",
135123
"main": "./lib/cjs/index.js",
136-
"files": [
137-
"lib"
138-
],
124+
"files": ["lib"],
139125
"repository": {
140126
"type": "git",
141127
"url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git"

packages/parameters/src/appconfig/AppConfigProvider.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { BaseProvider } from '../base/BaseProvider.js';
21
import {
32
AppConfigDataClient,
4-
StartConfigurationSessionCommand,
53
GetLatestConfigurationCommand,
4+
StartConfigurationSessionCommand,
65
} from '@aws-sdk/client-appconfigdata';
76
import type { StartConfigurationSessionCommandInput } from '@aws-sdk/client-appconfigdata';
7+
import { BaseProvider } from '../base/BaseProvider.js';
8+
import { APPCONFIG_TOKEN_EXPIRATION } from '../constants.js';
89
import type {
9-
AppConfigProviderOptions,
1010
AppConfigGetOptions,
1111
AppConfigGetOutput,
12+
AppConfigProviderOptions,
1213
} from '../types/AppConfigProvider.js';
13-
import { APPCONFIG_TOKEN_EXPIRATION } from '../constants.js';
1414

1515
/**
1616
* ## Intro
@@ -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/appconfig/getAppConfig.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { AppConfigProvider } from './AppConfigProvider.js';
21
import { DEFAULT_PROVIDERS } from '../base/index.js';
32
import type {
43
AppConfigGetOutput,
54
GetAppConfigOptions,
65
} from '../types/AppConfigProvider.js';
6+
import { AppConfigProvider } from './AppConfigProvider.js';
77

88
/**
99
* ## Intro

packages/parameters/src/base/BaseProvider.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import {
55
isSdkClient,
66
isString,
77
} from '@aws-lambda-powertools/commons';
8-
import { GetOptions } from './GetOptions.js';
9-
import { GetMultipleOptions } from './GetMultipleOptions.js';
10-
import { ExpirableValue } from './ExpirableValue.js';
11-
import { GetParameterError, TransformParameterError } from '../errors.js';
128
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
13-
import { transformValue } from './transformValue.js';
9+
import { GetParameterError, TransformParameterError } from '../errors.js';
1410
import type {
1511
BaseProviderInterface,
1612
GetMultipleOptionsInterface,
1713
GetOptionsInterface,
1814
} from '../types/BaseProvider.js';
15+
import { ExpirableValue } from './ExpirableValue.js';
16+
import { GetMultipleOptions } from './GetMultipleOptions.js';
17+
import { GetOptions } from './GetOptions.js';
18+
import { transformValue } from './transformValue.js';
1919

2020
/**
2121
* Base class for all providers.
@@ -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

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

55
/**
66
* Options for the `getMultiple` method.
@@ -14,10 +14,10 @@ class GetMultipleOptions
1414
public throwOnTransformError = false;
1515

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

2222
if (options.throwOnTransformError !== undefined) {
2323
this.throwOnTransformError = options.throwOnTransformError;

packages/parameters/src/base/GetOptions.ts

+3-3
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-
options: GetOptionsInterface = {},
21-
envVarsService: EnvironmentVariablesService
20+
envVarsService: EnvironmentVariablesService,
21+
options: GetOptionsInterface = {}
2222
) {
2323
Object.assign(this, options);
2424

packages/parameters/src/base/transformValue.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
21
import { isString } from '@aws-lambda-powertools/commons';
2+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
33
import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
44
import {
55
TRANSFORM_METHOD_BINARY,
@@ -58,16 +58,20 @@ const transformValue = (
5858

5959
try {
6060
// If the value is a Uint8Array, decode it to a string first
61-
if (value instanceof Uint8Array) {
62-
value = new TextDecoder('utf-8').decode(value);
63-
}
61+
const valueToTransform =
62+
value instanceof Uint8Array
63+
? new TextDecoder('utf-8').decode(value)
64+
: value;
6465

6566
// If the transform is `json` or `auto` and the key ends with `.json`, parse the value as JSON
6667
if (isJsonTransform || isAutoJsonTransform) {
67-
return JSON.parse(value) as JSONValue;
68+
return JSON.parse(valueToTransform) as JSONValue;
6869
// If the transform is `binary` or `auto` and the key ends with `.binary`, decode the value from base64
69-
} else if (isBinaryTransform || isAutoBinaryTransform) {
70-
return new TextDecoder('utf-8').decode(fromBase64(value, 'base64'));
70+
}
71+
if (isBinaryTransform || isAutoBinaryTransform) {
72+
return new TextDecoder('utf-8').decode(
73+
fromBase64(valueToTransform, 'base64')
74+
);
7175
}
7276
} catch (error) {
7377
if (throwOnTransformError)

packages/parameters/src/config/EnvironmentVariablesService.ts

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

55
class EnvironmentVariablesService
66
extends CommonEnvironmentVariablesService
@@ -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/dynamodb/DynamoDBProvider.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { BaseProvider } from '../base/BaseProvider.js';
1+
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
22
import {
33
DynamoDBClient,
4+
type DynamoDBPaginationConfiguration,
45
GetItemCommand,
56
paginateQuery,
6-
type DynamoDBPaginationConfiguration,
7+
} from '@aws-sdk/client-dynamodb';
8+
import type {
9+
GetItemCommandInput,
10+
QueryCommandInput,
711
} from '@aws-sdk/client-dynamodb';
812
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';
13+
import { BaseProvider } from '../base/BaseProvider.js';
914
import type {
10-
DynamoDBProviderOptions,
11-
DynamoDBGetOptions,
1215
DynamoDBGetMultipleOptions,
13-
DynamoDBGetOutput,
1416
DynamoDBGetMultipleOutput,
17+
DynamoDBGetOptions,
18+
DynamoDBGetOutput,
19+
DynamoDBProviderOptions,
1520
} from '../types/DynamoDBProvider.js';
16-
import type {
17-
GetItemCommandInput,
18-
QueryCommandInput,
19-
} from '@aws-sdk/client-dynamodb';
20-
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
2121

2222
/**
2323
* ## Intro
@@ -248,9 +248,8 @@ class DynamoDBProvider extends BaseProvider {
248248
*/
249249
public constructor(config: DynamoDBProviderOptions) {
250250
super({
251-
awsSdkV3Client: config.awsSdkV3Client,
252-
clientConfig: config.clientConfig,
253251
proto: DynamoDBClient as new (config?: unknown) => DynamoDBClient,
252+
...config,
254253
});
255254

256255
const { tableName, keyAttr, sortAttr, valueAttr } = config;

packages/parameters/src/secrets/SecretsProvider.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { BaseProvider } from '../base/BaseProvider.js';
21
import {
3-
SecretsManagerClient,
42
GetSecretValueCommand,
3+
SecretsManagerClient,
54
} from '@aws-sdk/client-secrets-manager';
65
import type { GetSecretValueCommandInput } from '@aws-sdk/client-secrets-manager';
6+
import { BaseProvider } from '../base/BaseProvider.js';
77
import type {
8-
SecretsProviderOptions,
98
SecretsGetOptions,
109
SecretsGetOutput,
10+
SecretsProviderOptions,
1111
} from '../types/SecretsProvider.js';
1212

1313
/**
@@ -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/secrets/getSecret.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { DEFAULT_PROVIDERS } from '../base/DefaultProviders.js';
2-
import { SecretsProvider } from './SecretsProvider.js';
32
import type {
43
SecretsGetOptions,
54
SecretsGetOutput,
65
} from '../types/SecretsProvider.js';
6+
import { SecretsProvider } from './SecretsProvider.js';
77

88
/**
99
* ## Intro

0 commit comments

Comments
 (0)