-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added typing for patterns and exposed logger
- Loading branch information
Showing
12 changed files
with
236 additions
and
56 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/lambda-powertools-middleware-correlation-ids/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import middy from "@middy/core"; | ||
import { | ||
Context, | ||
SQSRecord, | ||
Handler, | ||
DynamoDBRecord, | ||
DynamoDBStreamEvent, | ||
Callback, | ||
FirehoseTransformationEvent, | ||
FirehoseTransformationResult, | ||
KinesisStreamEvent, | ||
} from "aws-lambda"; | ||
import Log from "@dazn/lambda-powertools-logger"; | ||
import CorrelationIds from "@dazn/lambda-powertools-correlation-ids"; | ||
|
||
export default function <T, R, C extends Context = Context>(params: { | ||
sampleDebugLogRate: number; | ||
}): middy.MiddlewareObject<T, R, C>; | ||
|
||
export type ExtractedCorrelationIdAndLogger = { | ||
logger: Log; | ||
correlationIds: CorrelationIds; | ||
}; | ||
|
||
export type SQSEvent = { | ||
Records: (SQSRecord & ExtractedCorrelationIdAndLogger)[]; | ||
}; | ||
|
||
export type SQSHandler = Handler<SQSEvent, void>; | ||
|
||
export type KinesisContext<T> = Context & { | ||
parsedKinesisEvents: ((T & ExtractedCorrelationIdAndLogger) | undefined)[]; | ||
}; | ||
|
||
export type KinesisStreamHandler = <T>( | ||
event: KinesisStreamEvent, | ||
context: KinesisContext<T>, | ||
callback: Callback<void> | ||
) => void | Promise<void>; | ||
|
||
export type FirehoseContext<T> = Context & { | ||
parsedFirehoseEvents: ((T & ExtractedCorrelationIdAndLogger) | undefined)[]; | ||
}; | ||
|
||
export type FirehoseTransformationHandler = <T>( | ||
event: FirehoseTransformationEvent, | ||
context: FirehoseContext<T>, | ||
callback: Callback<FirehoseTransformationResult> | ||
) => void | Promise<FirehoseTransformationResult>; | ||
|
||
export type DynamoStreamsContext = Context & { | ||
parsedDynamoDbEvents: (DynamoDBRecord & ExtractedCorrelationIdAndLogger)[]; | ||
}; | ||
|
||
export type DynamoDBStreamHandler = ( | ||
event: DynamoDBStreamEvent, | ||
context: DynamoStreamsContext, | ||
callback: Callback<void> | ||
) => void | Promise<void>; | ||
|
||
export { Log }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 13 additions & 7 deletions
20
packages/lambda-powertools-middleware-correlation-ids/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import middy from "@middy/core"; | ||
import { Callback, Context } from "aws-lambda"; | ||
export * from "@dazn/lambda-powertools-middleware-correlation-ids"; | ||
|
||
declare type EventType<T, C> = T extends ( | ||
event: infer EventArgType, | ||
context: C, | ||
callback: Callback<any> | ||
) => void | ||
? EventArgType | ||
: T extends (event: infer EventArgType, context: C) => Promise<any> | ||
? EventArgType | ||
: never; | ||
|
||
declare type HandlerReturnType<T, C> = T extends ( | ||
event: any, | ||
context: C | ||
) => Promise<infer RetType> | ||
? RetType | ||
: T extends ( | ||
event: any, | ||
context: C, | ||
callback: Callback<infer RetType> | ||
) => void | ||
? RetType | ||
: never; | ||
|
||
declare type AsyncHandler<C extends Context> = | ||
| ((event: any, context: C, callback: Callback<any>) => void) | ||
| ((event: any, context: C) => Promise<any>); | ||
|
||
export default function < | ||
H extends AsyncHandler<C>, | ||
C extends Context = Context | ||
>(f: H): middy.Middy<EventType<H, C>, HandlerReturnType<H, C>, C>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 27 additions & 21 deletions
48
packages/lambda-powertools-pattern-basic/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import middy from "@middy/core"; | ||
import { Callback, Context } from "aws-lambda"; | ||
export * from "@dazn/lambda-powertools-middleware-correlation-ids"; | ||
|
||
declare type EventType<T, C> = T extends ( | ||
event: infer EventArgType, | ||
context: C, | ||
callback: Callback<any> | ||
) => void | ||
? EventArgType | ||
: T extends (event: infer EventArgType, context: C) => Promise<any> | ||
? EventArgType | ||
: never; | ||
|
||
declare type HandlerReturnType<T, C> = T extends ( | ||
event: any, | ||
context: C | ||
) => Promise<infer RetType> | ||
? RetType | ||
: T extends ( | ||
event: any, | ||
context: C, | ||
callback: Callback<infer RetType> | ||
) => void | ||
? RetType | ||
: never; | ||
|
||
declare type AsyncHandler<C extends Context> = | ||
| ((event: any, context: C, callback: Callback<any>) => void) | ||
| ((event: any, context: C) => Promise<any>); | ||
|
||
declare enum FILTERING_MODE { | ||
BLACKLIST = "BLACKLIST", | ||
WHITELIST = "WHITELIST", | ||
} | ||
|
||
declare namespace dazn__lambda_powertools_pattern_obfuscate { | ||
const FILTERING_MODE: FILTERING_MODE; | ||
|
||
function obfuscaterPattern< | ||
H extends AsyncHandler<C>, | ||
C extends Context = Context | ||
>( | ||
obfuscationFilters: string[], | ||
f: H, | ||
filterOnAfter?: boolean, | ||
filteringMode?: FILTERING_MODE | ||
): middy.Middy<EventType<H, C>, HandlerReturnType<H, C>, C>; | ||
} | ||
|
||
export default dazn__lambda_powertools_pattern_obfuscate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.