@nrfcloud/lambda-helpers 1.1.8 → 1.1.9
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/npm/validateInput.d.ts +16 -2
- package/npm/validateInput.js +7 -1
- package/package.json +3 -3
package/npm/validateInput.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import type { MiddlewareObj } from '@middy/core';
|
|
2
2
|
import type { Static, StaticDecode, TSchema } from '@sinclair/typebox';
|
|
3
3
|
import type { ValueError } from '@sinclair/typebox/compiler';
|
|
4
|
-
import type { APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Context } from 'aws-lambda';
|
|
4
|
+
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2, APIGatewayProxyStructuredResultV2, Context } from 'aws-lambda';
|
|
5
5
|
export declare class ValidationFailedError extends Error {
|
|
6
6
|
readonly errors: ValueError[];
|
|
7
7
|
constructor(errors: ValueError[], message?: string);
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The event properties used by `validateInput` to construct the default input.
|
|
11
|
+
*
|
|
12
|
+
* Both REST API (v1, `APIGatewayProxyEvent`) and HTTP API (v2, `APIGatewayProxyEventV2`) events satisfy this.
|
|
13
|
+
*/
|
|
14
|
+
type ValidateInputEvent = Pick<APIGatewayProxyEvent | APIGatewayProxyEventV2, 'headers' | 'body' | 'pathParameters' | 'queryStringParameters'>;
|
|
15
|
+
/**
|
|
16
|
+
* Validates the input of a Lambda function.
|
|
17
|
+
*
|
|
18
|
+
* Use the `Event` type parameter to specify the type of the event passed
|
|
19
|
+
* to `mapInput`, e.g. `validateInput<typeof Schema, APIGatewayProxyEvent>(Schema, (event) => ({ method: event.httpMethod }))`.
|
|
20
|
+
* It is inferred from `mapInput` if its parameter is typed explicitly.
|
|
21
|
+
*/
|
|
22
|
+
export declare const validateInput: <Schema extends TSchema, Event extends ValidateInputEvent = APIGatewayProxyEventV2>(schema: Schema, mapInput?: (e: Event) => unknown) => MiddlewareObj<Event, APIGatewayProxyStructuredResultV2, Error, Context & ValidInput<Schema>>;
|
|
10
23
|
export type ValidInput<Schema extends TSchema> = {
|
|
11
24
|
/**
|
|
12
25
|
* @deprecated Use `decodedInput` instead
|
|
@@ -16,3 +29,4 @@ export type ValidInput<Schema extends TSchema> = {
|
|
|
16
29
|
validInput: Static<Schema>;
|
|
17
30
|
decodedInput: StaticDecode<Schema>;
|
|
18
31
|
};
|
|
32
|
+
export {};
|
package/npm/validateInput.js
CHANGED
|
@@ -10,7 +10,13 @@ export class ValidationFailedError extends Error {
|
|
|
10
10
|
this.name = 'ValidationFailedError';
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Validates the input of a Lambda function.
|
|
15
|
+
*
|
|
16
|
+
* Use the `Event` type parameter to specify the type of the event passed
|
|
17
|
+
* to `mapInput`, e.g. `validateInput<typeof Schema, APIGatewayProxyEvent>(Schema, (event) => ({ method: event.httpMethod }))`.
|
|
18
|
+
* It is inferred from `mapInput` if its parameter is typed explicitly.
|
|
19
|
+
*/ export const validateInput = (schema, mapInput)=>{
|
|
14
20
|
const v = validateWithTypeBox(schema);
|
|
15
21
|
return {
|
|
16
22
|
before: async (req)=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nrfcloud/lambda-helpers",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Helper functions for AWS Lambda functions used in nRF Cloud.",
|
|
5
5
|
"homepage": "https://github.com/nRFCloud/lambda-helpers#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@bifravst/prettier-config": "2.0.
|
|
37
|
+
"@bifravst/prettier-config": "2.0.7",
|
|
38
38
|
"@swc/core": "1.16.22",
|
|
39
39
|
"@types/aws-lambda": "8.10.164",
|
|
40
40
|
"@types/node": "26.6.6",
|
|
41
41
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
42
|
-
"prettier": "3.
|
|
42
|
+
"prettier": "3.10.1",
|
|
43
43
|
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
44
44
|
},
|
|
45
45
|
"prettier": "@bifravst/prettier-config",
|