Skip to content

Commit 4d91a5a

Browse files
committed
fix: remove dependency on @types/aws-lambda
1 parent 1cb9601 commit 4d91a5a

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@commitlint/config-conventional": "^11.0.0",
3131
"@semantic-release/git": "^9.0.0",
3232
"@tsconfig/node12": "^1.0.7",
33-
"@types/aws-lambda": "^8.10.68",
3433
"@types/node": "12",
3534
"@types/pino": "^6.0.0",
3635
"@types/sinon": "^9.0.10",

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Context } from 'aws-lambda';
21
import pino, { BaseLogger, DestinationStream, LoggerOptions, LevelMapping } from 'pino';
32
import { GlobalContextStorageProvider, ContextStorageProvider, ContextMap } from './context';
43

@@ -7,6 +6,13 @@ export interface ExtendedPinoOptions extends LoggerOptions {
76
streamWriter?: (str: string | Uint8Array) => boolean;
87
}
98

9+
interface LambdaContext {
10+
awsRequestId: string;
11+
12+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13+
[key: string]: any;
14+
}
15+
1016
interface LamdbaEvent {
1117
headers?: {
1218
[key: string]: string;
@@ -70,7 +76,7 @@ const pinolambda = ({ levels, options }: PinoLambdaExtensionOptions): Destinatio
7076
});
7177

7278
export type PinoLambdaLogger = BaseLogger & {
73-
withRequest: (event: LamdbaEvent, context: Context) => void;
79+
withRequest: (event: LamdbaEvent, context: LambdaContext) => void;
7480
};
7581

7682
/**
@@ -108,7 +114,7 @@ export default (extendedPinoOptions?: ExtendedPinoOptions): PinoLambdaLogger =>
108114
const configuredLevel = logger.level;
109115

110116
// extend the base logger
111-
logger.withRequest = (event: LamdbaEvent, context: Context): void => {
117+
logger.withRequest = (event: LamdbaEvent, context: LambdaContext): void => {
112118
const ctx: ContextMap = {
113119
awsRequestId: context.awsRequestId,
114120
};

src/tests/index.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Context } from 'aws-lambda';
21
import tap from 'tap';
32
import sinon from 'sinon';
43
import pino, { PinoLambdaLogger } from '../index';
@@ -24,7 +23,7 @@ tap.test('should log an info message with data', (t) => {
2423
tap.test('should log an info message with requestId', (t) => {
2524
const [log, output] = createLogger();
2625

27-
log.withRequest({}, { awsRequestId: '12345' } as Context);
26+
log.withRequest({}, { awsRequestId: '12345' });
2827
log.info('Message with request ID');
2928
t.matchSnapshot(output.buffer);
3029
t.end();
@@ -33,7 +32,7 @@ tap.test('should log an info message with requestId', (t) => {
3332
tap.test('should log an error message with requestId', (t) => {
3433
const [log, output] = createLogger();
3534

36-
log.withRequest({}, { awsRequestId: '12345' } as Context);
35+
log.withRequest({}, { awsRequestId: '12345' });
3736
log.error('Message with request ID');
3837
t.matchSnapshot(output.buffer);
3938
t.end();

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,6 @@
668668
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.7.tgz#677bd9117e8164dc319987dd6ff5fc1ba6fbf18b"
669669
integrity sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A==
670670

671-
"@types/aws-lambda@^8.10.68":
672-
version "8.10.68"
673-
resolved "https://registry.yarnpkg.com/@types/aws-lambda/-/aws-lambda-8.10.68.tgz#51d5727e49e5ae13303adb10e2e8ffee7df12c71"
674-
integrity sha512-0/0ghix1WXU8xJxvRx/VtmAesLR6+dPFWrNhQ90Pq6oOYN3x+oRVPnjjYNOIRuEd7fmKovl7s6ILCXMnbDr4Mg==
675-
676671
"@types/json-schema@^7.0.3":
677672
version "7.0.6"
678673
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"

0 commit comments

Comments
 (0)