@middy/core 2.5.0 → 2.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +17 -15
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context as LambdaContext,
|
|
3
|
-
Handler as LambdaHandler
|
|
3
|
+
Handler as LambdaHandler,
|
|
4
|
+
Callback as LambdaCallback
|
|
4
5
|
} from 'aws-lambda'
|
|
5
6
|
|
|
6
7
|
declare type PluginHook = () => void
|
|
7
8
|
declare type PluginHookWithMiddlewareName = (middlewareName: string) => void
|
|
8
|
-
declare type PluginHookPromise = () => Promise<
|
|
9
|
+
declare type PluginHookPromise = (request: Request) => Promise<unknown> | unknown
|
|
9
10
|
|
|
10
11
|
interface PluginObject {
|
|
11
12
|
beforePrefetch?: PluginHook
|
|
@@ -17,7 +18,7 @@ interface PluginObject {
|
|
|
17
18
|
requestEnd?: PluginHookPromise
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
interface Request<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
21
|
+
interface Request<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> {
|
|
21
22
|
event: TEvent
|
|
22
23
|
context: TContext
|
|
23
24
|
response: TResult | null
|
|
@@ -27,17 +28,19 @@ interface Request<TEvent = any, TResult = any, TErr = Error, TContext extends La
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
declare type MiddlewareFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
31
|
+
declare type MiddlewareFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> = (request: Request<TEvent, TResult, TErr, TContext>) => any
|
|
31
32
|
|
|
32
|
-
export interface MiddlewareObj<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
33
|
+
export interface MiddlewareObj<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> {
|
|
33
34
|
before?: MiddlewareFn<TEvent, TResult, TErr, TContext>
|
|
34
35
|
after?: MiddlewareFn<TEvent, TResult, TErr, TContext>
|
|
35
|
-
onError?: MiddlewareFn<TEvent, TResult, TErr>
|
|
36
|
+
onError?: MiddlewareFn<TEvent, TResult, TErr, TContext>
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
// The AWS provided Handler type uses void | Promise<TResult> so we have no choice but to follow and suppress the linter warning
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
41
|
+
type MiddyInputHandler<TEvent, TResult, TContext extends LambdaContext = LambdaContext> = (event: TEvent, context: TContext, callback: LambdaCallback<TResult>) => void | Promise<TResult>
|
|
39
42
|
|
|
40
|
-
export interface MiddyfiedHandler<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
43
|
+
export interface MiddyfiedHandler<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> extends MiddyInputHandler<TEvent, TResult, TContext> {
|
|
41
44
|
use: UseFn<TEvent, TResult, TErr, TContext>
|
|
42
45
|
applyMiddleware: AttachMiddlewareObj<TEvent, TResult, TErr, TContext>
|
|
43
46
|
before: AttachMiddlewareFn<TEvent, TResult, TErr, TContext>
|
|
@@ -48,19 +51,18 @@ export interface MiddyfiedHandler<TEvent = any, TResult = any, TErr = Error, TCo
|
|
|
48
51
|
after: Array<MiddlewareFn<TEvent, TResult, TErr, TContext>>
|
|
49
52
|
onError: Array<MiddlewareFn<TEvent, TResult, TErr, TContext>>
|
|
50
53
|
}
|
|
51
|
-
(event: TEvent, context: TContext): Promise<TResult>
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
declare type AttachMiddlewareFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
56
|
+
declare type AttachMiddlewareFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> = (middleware: MiddlewareFn) => MiddyfiedHandler<TEvent, TResult, TErr, TContext>
|
|
55
57
|
|
|
56
|
-
declare type AttachMiddlewareObj<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
58
|
+
declare type AttachMiddlewareObj<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> = (middleware: MiddlewareObj) => MiddyfiedHandler<TEvent, TResult, TErr, TContext>
|
|
57
59
|
|
|
58
|
-
declare type UseFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
60
|
+
declare type UseFn<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> =
|
|
59
61
|
(middlewares: MiddlewareObj<TEvent, TResult, TErr, TContext> | Array<MiddlewareObj<TEvent, TResult, TErr, TContext>>) => MiddyfiedHandler<TEvent, TResult, TErr, TContext>
|
|
60
62
|
|
|
61
|
-
declare type MiddlewareHandler<THandler extends LambdaHandler<any, any>, TContext> =
|
|
63
|
+
declare type MiddlewareHandler<THandler extends LambdaHandler<any, any>, TContext extends LambdaContext = LambdaContext> =
|
|
62
64
|
THandler extends LambdaHandler<infer TEvent, infer TResult> // always true
|
|
63
|
-
?
|
|
65
|
+
? MiddyInputHandler<TEvent, TResult, TContext>
|
|
64
66
|
: never
|
|
65
67
|
|
|
66
68
|
/**
|
|
@@ -68,7 +70,7 @@ declare type MiddlewareHandler<THandler extends LambdaHandler<any, any>, TContex
|
|
|
68
70
|
* @param handler your original AWS Lambda function
|
|
69
71
|
* @param plugin wraps around each middleware and handler to add custom lifecycle behaviours (e.g. to profile performance)
|
|
70
72
|
*/
|
|
71
|
-
declare function middy<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext =
|
|
73
|
+
declare function middy<TEvent = any, TResult = any, TErr = Error, TContext extends LambdaContext = LambdaContext> (handler?: MiddlewareHandler<LambdaHandler<TEvent, TResult>, TContext>, plugin?: PluginObject): MiddyfiedHandler<TEvent, TResult, TErr, TContext>
|
|
72
74
|
|
|
73
75
|
declare namespace middy {
|
|
74
76
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/core",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.4",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"engines": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@types/aws-lambda": "^8.10.76",
|
|
46
46
|
"@types/node": "^16.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a4134a579c757a9fdfed3006877ba2c0ec8a2cfa"
|
|
49
49
|
}
|