Skip to content

Commit 7d52276

Browse files
committed
chore(commons): simplify config service interface
1 parent 52c65cd commit 7d52276

File tree

15 files changed

+181
-56
lines changed

15 files changed

+181
-56
lines changed

Diff for: packages/commons/src/config/EnvironmentVariablesService.ts

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

33
/**
44
* Class EnvironmentVariablesService
@@ -13,7 +13,7 @@ import { ConfigService } from './ConfigService.js';
1313
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
1414
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/#environment-variables
1515
*/
16-
class EnvironmentVariablesService implements ConfigService {
16+
class EnvironmentVariablesService implements ConfigServiceInterface {
1717
/**
1818
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/#environment-variables
1919
* @protected

Diff for: packages/commons/src/config/ConfigService.ts renamed to packages/commons/src/types/ConfigServiceInterface.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
*
44
* This class defines common methods and variables that can be set by the developer
55
* in the runtime.
6-
*
7-
* @class
8-
* @abstract
96
*/
10-
abstract class ConfigService {
7+
interface ConfigServiceInterface {
118
/**
129
* It returns the value of an environment variable that has given name.
1310
*
1411
* @param {string} name
1512
* @returns {string}
1613
*/
17-
public abstract get(name: string): string;
14+
get(name: string): string;
1815

1916
/**
2017
* It returns the value of the POWERTOOLS_SERVICE_NAME environment variable.
2118
*
2219
* @returns {string}
2320
*/
24-
public abstract getServiceName(): string;
21+
getServiceName(): string;
2522

2623
/**
2724
* It returns the value of the _X_AMZN_TRACE_ID environment variable.
@@ -33,22 +30,22 @@ abstract class ConfigService {
3330
*
3431
* @returns {string|undefined}
3532
*/
36-
public abstract getXrayTraceId(): string | undefined;
33+
getXrayTraceId(): string | undefined;
3734

3835
/**
3936
* It returns true if the `POWERTOOLS_DEV` environment variable is set to truthy value.
4037
*
4138
* @returns {boolean}
4239
*/
43-
public abstract isDevMode(): boolean;
40+
isDevMode(): boolean;
4441

4542
/**
4643
* It returns true if the string value represents a boolean true value.
4744
*
4845
* @param {string} value
4946
* @returns boolean
5047
*/
51-
public abstract isValueTrue(value: string): boolean;
48+
isValueTrue(value: string): boolean;
5249
}
5350

54-
export { ConfigService };
51+
export type { ConfigServiceInterface };

Diff for: packages/commons/src/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export type {
1616
LambdaInterface,
1717
HandlerMethodDecorator,
1818
} from './LambdaInterface.js';
19+
export type { ConfigServiceInterface } from './ConfigServiceInterface.js';

Diff for: packages/idempotency/src/types/ConfigServiceInterface.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
interface ConfigServiceInterface {
2-
get(name: string): string;
3-
4-
getServiceName(): string;
1+
import type { ConfigServiceInterface as ConfigServiceBaseInterface } from '@aws-lambda-powertools/commons/types';
52

3+
/**
4+
* Interface ConfigServiceInterface
5+
*
6+
* @interface
7+
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
8+
* @see https://docs.powertools.aws.dev/lambda-typescript/latest/#environment-variables
9+
*/
10+
interface ConfigServiceInterface extends ConfigServiceBaseInterface {
11+
/**
12+
* It returns the value of the AWS_LAMBDA_FUNCTION_NAME environment variable.
13+
*
14+
* @returns {string}
15+
*/
616
getFunctionName(): string;
717

18+
/**
19+
* It returns whether the idempotency feature is enabled or not.
20+
*
21+
* Reads the value of the POWERTOOLS_IDEMPOTENCY_DISABLED environment variable.
22+
*
23+
* @returns {boolean}
24+
*/
825
getIdempotencyEnabled(): boolean;
926
}
1027

Diff for: packages/logger/src/types/ConfigServiceInterface.ts

+3-24
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1+
import type { ConfigServiceInterface as ConfigServiceBaseInterface } from '@aws-lambda-powertools/commons/types';
2+
13
/**
24
* Interface ConfigServiceInterface
35
*
46
* @interface
57
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
68
* @see https://docs.powertools.aws.dev/lambda/typescript/latest/#environment-variables
79
*/
8-
interface ConfigServiceInterface {
9-
/**
10-
* It returns the value of an environment variable that has given name.
11-
*
12-
* @param {string} name
13-
* @returns {string}
14-
*/
15-
get(name: string): string;
16-
10+
interface ConfigServiceInterface extends ConfigServiceBaseInterface {
1711
/**
1812
* It returns the value of the `AWS_LAMBDA_LOG_LEVEL` environment variable.
1913
*
@@ -58,21 +52,6 @@ interface ConfigServiceInterface {
5852
* @returns {string|undefined}
5953
*/
6054
getSampleRateValue(): number | undefined;
61-
62-
/**
63-
* It returns the value of the POWERTOOLS_SERVICE_NAME environment variable.
64-
*
65-
* @returns {string}
66-
*/
67-
getServiceName(): string;
68-
69-
/**
70-
* It returns true if the string value represents a boolean true value.
71-
*
72-
* @param {string} value
73-
* @returns boolean
74-
*/
75-
isValueTrue(value: string): boolean;
7655
}
7756

7857
export type { ConfigServiceInterface };

Diff for: packages/logger/tests/unit/Logger.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ describe('Class: Logger', () => {
369369
getServiceName(): string {
370370
return 'my-backend-service';
371371
},
372+
getXrayTraceId(): string | undefined {
373+
return undefined;
374+
},
372375
isDevMode(): boolean {
373376
return false;
374377
},

Diff for: packages/logger/tests/unit/middleware/middy.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ describe('Middy middleware', () => {
292292
getServiceName(): string {
293293
return 'my-backend-service';
294294
},
295+
getXrayTraceId(): string | undefined {
296+
return undefined;
297+
},
295298
isDevMode(): boolean {
296299
return false;
297300
},

Diff for: packages/metrics/src/config/EnvironmentVariablesService.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class EnvironmentVariablesService
77
{
88
private namespaceVariable = 'POWERTOOLS_METRICS_NAMESPACE';
99

10+
/**
11+
* It returns the value of the POWERTOOLS_METRICS_NAMESPACE environment variable.
12+
*
13+
* @returns {string}
14+
*/
1015
public getNamespace(): string {
1116
return this.get(this.namespaceVariable);
1217
}

Diff for: packages/metrics/src/types/ConfigServiceInterface.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
interface ConfigServiceInterface {
2-
get?(name: string): string;
3-
getNamespace(): string;
4-
getServiceName(): string;
1+
import type { ConfigServiceInterface as ConfigServiceBaseInterface } from '@aws-lambda-powertools/commons/types';
2+
3+
/**
4+
* Interface ConfigServiceInterface
5+
*
6+
* @interface
7+
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
8+
* @see https://docs.powertools.aws.dev/lambda-typescript/latest/#environment-variables
9+
*/
10+
interface ConfigServiceInterface extends ConfigServiceBaseInterface {
511
/**
6-
* It returns the value of the POWERTOOLS_DEV environment variable.
12+
* It returns the value of the POWERTOOLS_METRICS_NAMESPACE environment variable.
713
*
8-
* @returns {boolean}
14+
* @returns {string}
915
*/
10-
isDevMode(): boolean;
16+
getNamespace(): string;
1117
}
1218

1319
export type { ConfigServiceInterface };

Diff for: packages/metrics/tests/unit/Metrics.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,15 @@ describe('Class: Metrics', () => {
242242
getServiceName(): string {
243243
return 'test-service';
244244
},
245+
getXrayTraceId(): string | undefined {
246+
return 'test-trace-id';
247+
},
245248
isDevMode(): boolean {
246249
return false;
247250
},
251+
isValueTrue(value: string): boolean {
252+
return value === 'true';
253+
},
248254
};
249255
const metricsOptions: MetricsOptions = {
250256
customConfigService: configService,

Diff for: packages/parameters/src/config/EnvironmentVariablesService.ts

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class EnvironmentVariablesService
1010
private parametersMaxAgeVariable = 'POWERTOOLS_PARAMETERS_MAX_AGE';
1111
private ssmDecryptVariable = 'POWERTOOLS_PARAMETERS_SSM_DECRYPT';
1212

13+
/**
14+
* It returns the value of the POWERTOOLS_PARAMETERS_MAX_AGE environment variable.
15+
*
16+
* @returns {number|undefined}
17+
*/
1318
public getParametersMaxAge(): number | undefined {
1419
const maxAge = this.get(this.parametersMaxAgeVariable);
1520

@@ -25,6 +30,11 @@ class EnvironmentVariablesService
2530
}
2631
}
2732

33+
/**
34+
* It returns the value of the POWERTOOLS_PARAMETERS_SSM_DECRYPT environment variable.
35+
*
36+
* @returns {string}
37+
*/
2838
public getSSMDecrypt(): string {
2939
return this.get(this.ssmDecryptVariable);
3040
}

Diff for: packages/parameters/src/types/ConfigServiceInterface.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
interface ConfigServiceInterface {
2-
get?(name: string): string;
3-
4-
getServiceName(): string;
1+
import type { ConfigServiceInterface as ConfigServiceBaseInterface } from '@aws-lambda-powertools/commons/types';
52

3+
/**
4+
* Interface ConfigServiceInterface
5+
*
6+
* @interface
7+
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
8+
* @see https://docs.powertools.aws.dev/lambda-typescript/latest/#environment-variables
9+
*/
10+
interface ConfigServiceInterface extends ConfigServiceBaseInterface {
11+
/**
12+
* It returns the value of the POWERTOOLS_PARAMETERS_MAX_AGE environment variable.
13+
*
14+
* @returns {number|undefined}
15+
*/
616
getParametersMaxAge(): number | undefined;
7-
17+
/**
18+
* It returns the value of the POWERTOOLS_PARAMETERS_SSM_DECRYPT environment variable.
19+
*
20+
* @returns {string}
21+
*/
822
getSSMDecrypt(): string;
923
}
1024

Diff for: packages/tracer/src/config/EnvironmentVariablesService.ts

+30
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,56 @@ class EnvironmentVariablesService
1414
private tracerCaptureResponseVariable = 'POWERTOOLS_TRACER_CAPTURE_RESPONSE';
1515
private tracingEnabledVariable = 'POWERTOOLS_TRACE_ENABLED';
1616

17+
/**
18+
* It returns the value of the AWS_EXECUTION_ENV environment variable.
19+
*
20+
* @returns {string}
21+
*/
1722
public getAwsExecutionEnv(): string {
1823
return this.get(this.awsExecutionEnv);
1924
}
2025

26+
/**
27+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS environment variable.
28+
*
29+
* @returns {string}
30+
*/
2131
public getCaptureHTTPsRequests(): string {
2232
return this.get(this.tracerCaptureHTTPsRequestsVariable);
2333
}
2434

35+
/**
36+
* It returns the value of the AWS_SAM_LOCAL environment variable.
37+
*
38+
* @returns {string}
39+
*/
2540
public getSamLocal(): string {
2641
return this.get(this.samLocalVariable);
2742
}
2843

44+
/**
45+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_ERROR environment variable.
46+
*
47+
* @returns {string}
48+
*/
2949
public getTracingCaptureError(): string {
3050
return this.get(this.tracerCaptureErrorVariable);
3151
}
3252

53+
/**
54+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_RESPONSE environment variable.
55+
*
56+
* @returns {string}
57+
*/
3358
public getTracingCaptureResponse(): string {
3459
return this.get(this.tracerCaptureResponseVariable);
3560
}
3661

62+
/**
63+
* It returns the value of the POWERTOOLS_TRACE_ENABLED environment variable.
64+
*
65+
* @returns {string}
66+
*/
3767
public getTracingEnabled(): string {
3868
return this.get(this.tracingEnabledVariable);
3969
}

Diff for: packages/tracer/src/types/ConfigServiceInterface.ts

+43-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
1-
interface ConfigServiceInterface {
2-
get(name: string): string;
1+
import type { ConfigServiceInterface as ConfigServiceBaseInterface } from '@aws-lambda-powertools/commons/types';
32

3+
/**
4+
* Interface ConfigServiceInterface
5+
*
6+
* @interface
7+
* @see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime
8+
* @see https://docs.powertools.aws.dev/lambda-typescript/latest/#environment-variables
9+
*/
10+
interface ConfigServiceInterface extends ConfigServiceBaseInterface {
11+
/**
12+
* It returns the value of the AWS_EXECUTION_ENV environment variable.
13+
*
14+
* @returns {string}
15+
*/
16+
getAwsExecutionEnv(): string;
17+
18+
/**
19+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_HTTPS_REQUESTS environment variable.
20+
*
21+
* @returns {string}
22+
*/
423
getCaptureHTTPsRequests(): string;
524

6-
getTracingEnabled(): string;
25+
/**
26+
* It returns the value of the AWS_SAM_LOCAL environment variable.
27+
*
28+
* @returns {string}
29+
*/
30+
getSamLocal(): string;
731

8-
getServiceName(): string;
32+
/**
33+
* It returns the value of the POWERTOOLS_TRACE_ENABLED environment variable.
34+
*
35+
* @returns {string}
36+
*/
37+
getTracingEnabled(): string;
938

39+
/**
40+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_RESPONSE environment variable.
41+
*
42+
* @returns {string}
43+
*/
1044
getTracingCaptureResponse(): string;
1145

46+
/**
47+
* It returns the value of the POWERTOOLS_TRACER_CAPTURE_ERROR environment variable.
48+
*
49+
* @returns {string}
50+
*/
1251
getTracingCaptureError(): string;
1352
}
1453

0 commit comments

Comments
 (0)