diff --git a/docs/utilities/parser.md b/docs/utilities/parser.md index e4dcd5dfdd..da315c47c8 100644 --- a/docs/utilities/parser.md +++ b/docs/utilities/parser.md @@ -44,7 +44,7 @@ Both are also able to parse either an object or JSON string as an input. Be cautious when using multiple decorators that expect event to have a specific structure, the order of evaluation for decorators is from bottom to top. === "Middy middleware" - ```typescript hl_lines="34" + ```typescript hl_lines="22" --8<-- "examples/snippets/parser/middy.ts" ``` @@ -157,7 +157,7 @@ If you want to extend a schema and transform a JSON stringified payload to an ob If you want to parse a DynamoDB stream event with unmarshalling, you can use the helper function `DynamoDBMarshalled`: === "DynamoDBStreamSchema with DynamoDBMarshalled" - ```typescript hl_lines="17" + ```typescript hl_lines="18" --8<-- "examples/snippets/parser/extendDynamoDBStreamSchema.ts" ``` @@ -180,12 +180,12 @@ Envelopes can be used via envelope parameter available in middy and decorator. Here's an example of parsing a custom schema in an event coming from EventBridge, where all you want is what's inside the detail key. === "Middy middleware" - ```typescript hl_lines="5 36" + ```typescript hl_lines="23" --8<-- "examples/snippets/parser/envelopeMiddy.ts" ``` === "Decorator" - ```typescript hl_lines="5 26 30" + ```typescript hl_lines="26" --8<-- "examples/snippets/parser/envelopeDecorator.ts" ``` @@ -230,26 +230,24 @@ The `ParsedResult` object will have `success`, `data`, or `error` and `original If the parsing is successful, the `data` field will contain the parsed event, otherwise you can access the `error` field and the `originalEvent` to handle the error and recover the original event. === "Middy middleware" - ```typescript hl_lines="32 35 38 39 44" + ```typescript hl_lines="23 28 32-33" --8<-- "examples/snippets/parser/safeParseMiddy.ts" ``` 1. Use `safeParse` option to parse the event without throwing an error - 2. Check if the result is successful or not and handle the error accordingly - 3. Use `data` to access the parsed event - 4. Use `error` to handle the error message - 5. Use `originalEvent` to get the original event and recover + 2. Use `data` to access the parsed event when successful + 3. Use `error` to handle the error message + 4. Use `originalEvent` to get the original event and recover === "Decorator" - ```typescript hl_lines="29 35 37 40 41" + ```typescript hl_lines="33 41 45-46" --8<-- "examples/snippets/parser/safeParseDecorator.ts" ``` 1. Use `safeParse` option to parse the event without throwing an error - 2. Check if the result is successful or not and handle the error accordingly - 3. Use `data` to access the parsed event - 4. Use `error` to handle the error message - 5. Use `originalEvent` to get the original event and recover + 2. Use `data` to access the parsed event when successful + 3. Use `error` to handle the error message + 4. Use `originalEvent` to get the original event and recover ## Manual parsing @@ -316,7 +314,7 @@ If you are you use middy middleware, you don't need to do this. === "handlerDecorator.test.ts" - ```typescript hl_lines="26" + ```typescript hl_lines="27" --8<-- "examples/snippets/parser/unitTestDecorator.ts" ``` @@ -338,7 +336,7 @@ This also works when using `safeParse` option. === "handlerSafeParse.test.ts" - ```typescript hl_lines="21-29 35 45" + ```typescript hl_lines="21-30 36 46" --8<-- "examples/snippets/parser/unitTestSafeParse.ts" ``` diff --git a/examples/snippets/parser/envelopeDecorator.ts b/examples/snippets/parser/envelopeDecorator.ts index 5b04d80488..5fd09d23e1 100644 --- a/examples/snippets/parser/envelopeDecorator.ts +++ b/examples/snippets/parser/envelopeDecorator.ts @@ -1,7 +1,7 @@ import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; import type { Context } from 'aws-lambda'; import { z } from 'zod'; diff --git a/examples/snippets/parser/envelopeMiddy.ts b/examples/snippets/parser/envelopeMiddy.ts index 0a6034970f..0a20ad1132 100644 --- a/examples/snippets/parser/envelopeMiddy.ts +++ b/examples/snippets/parser/envelopeMiddy.ts @@ -1,8 +1,7 @@ import { Logger } from '@aws-lambda-powertools/logger'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; import { parser } from '@aws-lambda-powertools/parser/middleware'; import middy from '@middy/core'; -import type { Context } from 'aws-lambda'; import { z } from 'zod'; const logger = new Logger(); @@ -20,18 +19,11 @@ const orderSchema = z.object({ optionalField: z.string().optional(), }); -type Order = z.infer; - -const lambdaHandler = async ( - event: Order, - _context: Context -): Promise => { - for (const item of event.items) { - // item is parsed as OrderItem - logger.info('Processing item', { item }); - } -}; - -export const handler = middy(lambdaHandler).use( - parser({ schema: orderSchema, envelope: EventBridgeEnvelope }) -); +export const handler = middy() + .use(parser({ schema: orderSchema, envelope: EventBridgeEnvelope })) + .handler(async (event): Promise => { + for (const item of event.items) { + // item is parsed as OrderItem + logger.info('Processing item', { item }); + } + }); diff --git a/examples/snippets/parser/extend.ts b/examples/snippets/parser/extend.ts index 8dca184aa4..d49cf406dd 100644 --- a/examples/snippets/parser/extend.ts +++ b/examples/snippets/parser/extend.ts @@ -1,7 +1,7 @@ import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser'; -import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas'; +import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge'; import type { Context } from 'aws-lambda'; import { z } from 'zod'; diff --git a/examples/snippets/parser/extendDynamoDBStreamSchema.ts b/examples/snippets/parser/extendDynamoDBStreamSchema.ts index 86639f5cfb..30fc8abe2e 100644 --- a/examples/snippets/parser/extendDynamoDBStreamSchema.ts +++ b/examples/snippets/parser/extendDynamoDBStreamSchema.ts @@ -1,5 +1,6 @@ import { DynamoDBMarshalled } from '@aws-lambda-powertools/parser/helpers/dynamodb'; import { + DynamoDBStreamChangeRecordBase, DynamoDBStreamRecord, DynamoDBStreamSchema, } from '@aws-lambda-powertools/parser/schemas/dynamodb'; @@ -13,7 +14,7 @@ const customSchema = z.object({ const extendedSchema = DynamoDBStreamSchema.extend({ Records: z.array( DynamoDBStreamRecord.extend({ - dynamodb: z.object({ + dynamodb: DynamoDBStreamChangeRecordBase.extend({ NewImage: DynamoDBMarshalled(customSchema).optional(), }), }) diff --git a/examples/snippets/parser/handlerSafeParseDecorator.ts b/examples/snippets/parser/handlerSafeParseDecorator.ts index ac081c5e66..2c6afbe2ce 100644 --- a/examples/snippets/parser/handlerSafeParseDecorator.ts +++ b/examples/snippets/parser/handlerSafeParseDecorator.ts @@ -1,7 +1,7 @@ import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; import type { EventBridgeEvent, ParsedResult, diff --git a/examples/snippets/parser/manual.ts b/examples/snippets/parser/manual.ts index 839f62bafd..c0b33295d0 100644 --- a/examples/snippets/parser/manual.ts +++ b/examples/snippets/parser/manual.ts @@ -1,6 +1,6 @@ import { Logger } from '@aws-lambda-powertools/logger'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; -import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; +import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge'; import type { EventBridgeEvent } from '@aws-lambda-powertools/parser/types'; import type { Context } from 'aws-lambda'; import { z } from 'zod'; diff --git a/examples/snippets/parser/manualSafeParse.ts b/examples/snippets/parser/manualSafeParse.ts index 63dc0ac204..5af37162da 100644 --- a/examples/snippets/parser/manualSafeParse.ts +++ b/examples/snippets/parser/manualSafeParse.ts @@ -1,6 +1,6 @@ import { Logger } from '@aws-lambda-powertools/logger'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; -import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; +import { EventBridgeSchema } from '@aws-lambda-powertools/parser/schemas/eventbridge'; import type { EventBridgeEvent } from '@aws-lambda-powertools/parser/types'; import type { Context } from 'aws-lambda'; import { z } from 'zod'; diff --git a/examples/snippets/parser/middy.ts b/examples/snippets/parser/middy.ts index 763fa8246a..e8c19fb3cf 100644 --- a/examples/snippets/parser/middy.ts +++ b/examples/snippets/parser/middy.ts @@ -1,7 +1,6 @@ import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser/middleware'; import middy from '@middy/core'; -import type { Context } from 'aws-lambda'; import { z } from 'zod'; const logger = new Logger(); @@ -19,18 +18,11 @@ const orderSchema = z.object({ optionalField: z.string().optional(), }); -type Order = z.infer; - -const lambdaHandler = async ( - event: Order, - _context: Context -): Promise => { - for (const item of event.items) { - // item is parsed as OrderItem - logger.info('Processing item', { item }); - } -}; - -export const handler = middy(lambdaHandler).use( - parser({ schema: orderSchema }) -); +export const handler = middy() + .use(parser({ schema: orderSchema })) + .handler(async (event): Promise => { + for (const item of event.items) { + // item is parsed as OrderItem + logger.info('Processing item', { item }); + } + }); diff --git a/examples/snippets/parser/safeParseDecorator.ts b/examples/snippets/parser/safeParseDecorator.ts index a9e466be92..67caf35c6e 100644 --- a/examples/snippets/parser/safeParseDecorator.ts +++ b/examples/snippets/parser/safeParseDecorator.ts @@ -1,7 +1,7 @@ import type { LambdaInterface } from '@aws-lambda-powertools/commons/types'; import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser'; -import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes'; +import { EventBridgeEnvelope } from '@aws-lambda-powertools/parser/envelopes/eventbridge'; import type { EventBridgeEvent, ParsedResult, @@ -30,20 +30,19 @@ class Lambda implements LambdaInterface { @parser({ schema: orderSchema, envelope: EventBridgeEnvelope, - safeParse: true, - }) // (1)! + safeParse: true, // (1)! + }) public async handler( event: ParsedResult, _context: Context ): Promise { if (event.success) { - // (2)! for (const item of event.data.items) { - logger.info('Processing item', { item }); // (3)! + logger.info('Processing item', { item }); // (2)! } } else { - logger.error('Failed to parse event', event.error); // (4)! - logger.error('Original event is: ', event.originalEvent); // (5)! + logger.error('Failed to parse event', { error: event.error }); // (3)! + logger.error('Original event is ', { original: event.originalEvent }); // (4)! } } } diff --git a/examples/snippets/parser/safeParseMiddy.ts b/examples/snippets/parser/safeParseMiddy.ts index d73bc49096..e7efb5cb2b 100644 --- a/examples/snippets/parser/safeParseMiddy.ts +++ b/examples/snippets/parser/safeParseMiddy.ts @@ -1,11 +1,6 @@ import { Logger } from '@aws-lambda-powertools/logger'; import { parser } from '@aws-lambda-powertools/parser/middleware'; -import type { - EventBridgeEvent, - ParsedResult, -} from '@aws-lambda-powertools/parser/types'; import middy from '@middy/core'; -import type { Context } from 'aws-lambda'; import { z } from 'zod'; const logger = new Logger(); @@ -23,23 +18,17 @@ const orderSchema = z.object({ optionalField: z.string().optional(), }); -type Order = z.infer; - -const lambdaHandler = async ( - event: ParsedResult, - _context: Context -): Promise => { - if (event.success) { - // (2)! - for (const item of event.data.items) { - logger.info('Processing item', { item }); // (3)! +export const handler = middy() + .use( + parser({ schema: orderSchema, safeParse: true }) // (1)! + ) + .handler(async (event): Promise => { + if (event.success) { + for (const item of event.data.items) { + logger.info('Processing item', { item }); // (2)! + } + } else { + logger.error('Error parsing event', { event: event.error }); // (3)! + logger.error('Original event', { event: event.originalEvent }); // (4)! } - } else { - logger.error('Error parsing event', { event: event.error }); // (4)! - logger.error('Original event', { event: event.originalEvent }); // (5)! - } -}; - -export const handler = middy(lambdaHandler).use( - parser({ schema: orderSchema, safeParse: true }) // (1)! -); + }); diff --git a/examples/snippets/parser/unitTestDecorator.ts b/examples/snippets/parser/unitTestDecorator.ts index 3e327a6224..5653cabd3c 100644 --- a/examples/snippets/parser/unitTestDecorator.ts +++ b/examples/snippets/parser/unitTestDecorator.ts @@ -1,4 +1,5 @@ import type { Context } from 'aws-lambda'; +import { describe, expect, it } from 'vitest'; import { handler } from './decorator.js'; import type { Order } from './schema.js'; diff --git a/examples/snippets/parser/unitTestSafeParse.ts b/examples/snippets/parser/unitTestSafeParse.ts index bc2e80a220..cad6f08006 100644 --- a/examples/snippets/parser/unitTestSafeParse.ts +++ b/examples/snippets/parser/unitTestSafeParse.ts @@ -3,6 +3,7 @@ import type { ParsedResult, } from '@aws-lambda-powertools/parser/types'; import type { Context } from 'aws-lambda'; +import { describe, expect, it } from 'vitest'; import { handler } from './safeParseDecorator.js'; import type { Order } from './schema.js'; diff --git a/packages/parser/package.json b/packages/parser/package.json index 9619e754a3..a613d41369 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -41,208 +41,94 @@ } }, "./middleware": { - "require": "./lib/cjs/middleware/parser.js", - "import": "./lib/esm/middleware/parser.js" + "require": { + "types": "./lib/cjs/middleware/index.d.ts", + "default": "./lib/cjs/middleware/index.js" + }, + "import": { + "types": "./lib/esm/middleware/index.d.ts", + "default": "./lib/esm/middleware/index.js" + } }, "./schemas": { - "require": "./lib/cjs/schemas/index.js", - "import": "./lib/esm/schemas/index.js" - }, - "./schemas/alb": { - "require": "./lib/cjs/schemas/alb.js", - "import": "./lib/esm/schemas/alb.js" - }, - "./schemas/api-gateway": { - "require": "./lib/cjs/schemas/apigw.js", - "import": "./lib/esm/schemas/apigw.js" - }, - "./schemas/api-gatewayv2": { - "require": "./lib/cjs/schemas/apigwv2.js", - "import": "./lib/esm/schemas/apigwv2.js" - }, - "./schemas/appsync": { - "require": "./lib/cjs/schemas/appsync.js", - "import": "./lib/esm/schemas/appsync.js" - }, - "./schemas/cloudformation-custom-resources": { - "require": "./lib/cjs/schemas/cloudformation-custom-resources.js", - "import": "./lib/esm/schemas/cloudformation-custom-resources.js" - }, - "./schemas/cloudwatch": { - "require": "./lib/cjs/schemas/cloudwatch.js", - "import": "./lib/esm/schemas/cloudwatch.js" - }, - "./schemas/dynamodb": { - "require": "./lib/cjs/schemas/dynamodb.js", - "import": "./lib/esm/schemas/dynamodb.js" - }, - "./schemas/eventbridge": { - "require": "./lib/cjs/schemas/eventbridge.js", - "import": "./lib/esm/schemas/eventbridge.js" - }, - "./schemas/kafka": { - "require": "./lib/cjs/schemas/kafka.js", - "import": "./lib/esm/schemas/kafka.js" - }, - "./schemas/kinesis": { - "require": "./lib/cjs/schemas/kinesis.js", - "import": "./lib/esm/schemas/kinesis.js" - }, - "./schemas/kinesis-firehose": { - "require": "./lib/cjs/schemas/kinesis-firehose.js", - "import": "./lib/esm/schemas/kinesis-firehose.js" - }, - "./schemas/lambda": { - "require": "./lib/cjs/schemas/lambda.js", - "import": "./lib/esm/schemas/lambda.js" - }, - "./schemas/s3": { - "require": "./lib/cjs/schemas/s3.js", - "import": "./lib/esm/schemas/s3.js" - }, - "./schemas/ses": { - "require": "./lib/cjs/schemas/ses.js", - "import": "./lib/esm/schemas/ses.js" - }, - "./schemas/sns": { - "require": "./lib/cjs/schemas/sns.js", - "import": "./lib/esm/schemas/sns.js" - }, - "./schemas/sqs": { - "require": "./lib/cjs/schemas/sqs.js", - "import": "./lib/esm/schemas/sqs.js" - }, - "./schemas/transfer-family": { - "require": "./lib/cjs/schemas/transfer-family.js", - "import": "./lib/esm/schemas/transfer-family.js" - }, - "./schemas/vpc-lattice": { - "require": "./lib/cjs/schemas/vpc-lattice.js", - "import": "./lib/esm/schemas/vpc-lattice.js" + "require": { + "types": "./lib/cjs/schemas/index.d.ts", + "default": "./lib/cjs/schemas/index.js" + }, + "import": { + "types": "./lib/esm/schemas/index.d.ts", + "default": "./lib/esm/schemas/index.js" + } }, - "./schemas/vpc-latticev2": { - "require": "./lib/cjs/schemas/vpc-latticev2.js", - "import": "./lib/esm/schemas/vpc-latticev2.js" + "./schemas/*": { + "require": { + "types": "./lib/cjs/schemas/*.d.ts", + "default": "./lib/cjs/schemas/*.js" + }, + "import": { + "types": "./lib/esm/schemas/*.d.ts", + "default": "./lib/esm/schemas/*.js" + } }, "./envelopes": { - "require": "./lib/cjs/envelopes/index.js", - "import": "./lib/esm/envelopes/index.js" + "require": { + "types": "./lib/cjs/envelopes/index.d.ts", + "default": "./lib/cjs/envelopes/index.js" + }, + "import": { + "types": "./lib/esm/envelopes/index.d.ts", + "default": "./lib/esm/envelopes/index.js" + } }, "./envelopes/*": { - "require": "./lib/cjs/envelopes/*.js", - "import": "./lib/esm/envelopes/*.js" + "require": { + "types": "./lib/cjs/envelopes/*.d.ts", + "default": "./lib/cjs/envelopes/*.js" + }, + "import": { + "types": "./lib/esm/envelopes/*.d.ts", + "default": "./lib/esm/envelopes/*.js" + } }, "./helpers": { - "require": "./lib/cjs/helpers.js", - "import": "./lib/esm/helpers.js" + "require": { + "types": "./lib/cjs/helpers/index.d.ts", + "default": "./lib/cjs/helpers/index.js" + }, + "import": { + "types": "./lib/esm/helpers/index.d.ts", + "default": "./lib/esm/helpers/index.js" + } }, "./helpers/dynamodb": { - "require": "./lib/cjs/helpers/dynamodb.js", - "import": "./lib/esm/helpers/dynamodb.js" + "require": { + "types": "./lib/cjs/helpers/dynamodb.d.ts", + "default": "./lib/cjs/helpers/dynamodb.js" + }, + "import": { + "types": "./lib/esm/helpers/dynamodb.d.ts", + "default": "./lib/esm/helpers/dynamodb.js" + } }, "./types": { - "require": "./lib/cjs/types/index.js", - "import": "./lib/esm/types/index.js" - } - }, - "typesVersions": { - "*": { - "types": [ - "./lib/cjs/types/index.d.ts", - "./lib/esm/types/index.d.ts" - ], - "middleware": [ - "./lib/cjs/middleware/parser.d.ts", - "./lib/esm/middleware/parser.d.ts" - ], - "schemas": [ - "./lib/cjs/schemas/index.d.ts", - "./lib/esm/schemas/index.d.ts" - ], - "schemas/alb": [ - "./lib/cjs/schemas/alb.d.ts", - "./lib/esm/schemas/alb.d.ts" - ], - "schemas/api-gateway": [ - "./lib/cjs/schemas/apigw.d.ts", - "./lib/esm/schemas/apigw.d.ts" - ], - "schemas/api-gatewayv2": [ - "./lib/cjs/schemas/apigwv2.d.ts", - "./lib/esm/schemas/apigwv2.d.ts" - ], - "schemas/appsync": [ - "./lib/cjs/schemas/appsync.d.ts", - "./lib/esm/schemas/appsync.d.ts" - ], - "schemas/cloudformation-custom-resources": [ - "./lib/cjs/schemas/cloudformation-custom-resources.d.ts", - "./lib/esm/schemas/cloudformation-custom-resources.d.ts" - ], - "schemas/cloudwatch": [ - "./lib/cjs/schemas/cloudwatch.d.ts", - "./lib/esm/schemas/cloudwatch.d.ts" - ], - "schemas/dynamodb": [ - "./lib/cjs/schemas/dynamodb.d.ts", - "./lib/esm/schemas/dynamodb.d.ts" - ], - "schemas/eventbridge": [ - "./lib/cjs/schemas/eventbridge.d.ts", - "./lib/esm/schemas/eventbridge.d.ts" - ], - "schemas/kafka": [ - "./lib/cjs/schemas/kafka.d.ts", - "./lib/esm/schemas/kafka.d.ts" - ], - "schemas/kinesis": [ - "./lib/cjs/schemas/kinesis.d.ts", - "./lib/esm/schemas/kinesis.d.ts" - ], - "schemas/kinesis-firehose": [ - "./lib/cjs/schemas/kinesis-firehose.d.ts", - "./lib/esm/schemas/kinesis-firehose.d.ts" - ], - "schemas/lambda": [ - "./lib/cjs/schemas/lambda.d.ts", - "./lib/esm/schemas/lambda.d.ts" - ], - "schemas/s3": [ - "./lib/cjs/schemas/s3.d.ts", - "./lib/esm/schemas/s3.d.ts" - ], - "schemas/ses": [ - "./lib/cjs/schemas/ses.d.ts", - "./lib/esm/schemas/ses.d.ts" - ], - "schemas/sns": [ - "./lib/cjs/schemas/sns.d.ts", - "./lib/esm/schemas/sns.d.ts" - ], - "schemas/sqs": [ - "./lib/cjs/schemas/sqs.d.ts", - "./lib/esm/schemas/sqs.d.ts" - ], - "schemas/vpc-lattice": [ - "./lib/cjs/schemas/vpc-lattice.d.ts", - "./lib/esm/schemas/vpc-lattice.d.ts" - ], - "schemas/vpc-latticev2": [ - "./lib/cjs/schemas/vpc-latticev2.d.ts", - "./lib/esm/schemas/vpc-latticev2.d.ts" - ], - "envelopes": [ - "./lib/cjs/envelopes/index.d.ts", - "./lib/esm/envelopes/index.d.ts" - ], - "envelopes/*": [ - "./lib/cjs/envelopes/*.d.ts", - "./lib/esm/envelopes/*.d.ts" - ], - "helpers": [ - "./lib/cjs/helpers.d.ts", - "./lib/esm/helpers.d.ts" - ] + "require": { + "types": "./lib/cjs/types/index.d.ts", + "default": "./lib/cjs/types/index.js" + }, + "import": { + "types": "./lib/esm/types/index.d.ts", + "default": "./lib/esm/types/index.js" + } + }, + "./errors": { + "require": { + "types": "./lib/cjs/errors.d.ts", + "default": "./lib/cjs/errors.js" + }, + "import": { + "types": "./lib/esm/errors.d.ts", + "default": "./lib/esm/errors.js" + } } }, "main": "./lib/cjs/index.js", diff --git a/packages/parser/src/envelopes/api-gateway.ts b/packages/parser/src/envelopes/api-gateway.ts index 2ff9d3b8ab..0abaecc6d8 100644 --- a/packages/parser/src/envelopes/api-gateway.ts +++ b/packages/parser/src/envelopes/api-gateway.ts @@ -1,6 +1,6 @@ import type { ZodSchema, z } from 'zod'; import { ParseError } from '../errors.js'; -import { APIGatewayProxyEventSchema } from '../schemas/apigw.js'; +import { APIGatewayProxyEventSchema } from '../schemas/api-gateway.js'; import type { ParsedResult } from '../types/parser.js'; import { envelopeDiscriminator } from './envelope.js'; diff --git a/packages/parser/src/envelopes/api-gatewayv2.ts b/packages/parser/src/envelopes/api-gatewayv2.ts index 486fb74593..408bcde42c 100644 --- a/packages/parser/src/envelopes/api-gatewayv2.ts +++ b/packages/parser/src/envelopes/api-gatewayv2.ts @@ -1,6 +1,6 @@ import type { ZodSchema, z } from 'zod'; import { ParseError } from '../errors.js'; -import { APIGatewayProxyEventV2Schema } from '../schemas/apigwv2.js'; +import { APIGatewayProxyEventV2Schema } from '../schemas/api-gatewayv2.js'; import type { ParsedResult } from '../types/index.js'; import { envelopeDiscriminator } from './envelope.js'; diff --git a/packages/parser/src/helpers.ts b/packages/parser/src/helpers/index.ts similarity index 95% rename from packages/parser/src/helpers.ts rename to packages/parser/src/helpers/index.ts index 10915620d7..f24424d17b 100644 --- a/packages/parser/src/helpers.ts +++ b/packages/parser/src/helpers/index.ts @@ -1,7 +1,4 @@ import { type ZodTypeAny, z } from 'zod'; -/** - * @typedef {import('../schemas/alb').AlbSchema} AlbSchema - */ /** * A helper function to parse a JSON string and validate it against a schema. diff --git a/packages/parser/src/middleware/parser.ts b/packages/parser/src/middleware/index.ts similarity index 100% rename from packages/parser/src/middleware/parser.ts rename to packages/parser/src/middleware/index.ts diff --git a/packages/parser/src/schemas/apigw.ts b/packages/parser/src/schemas/api-gateway.ts similarity index 100% rename from packages/parser/src/schemas/apigw.ts rename to packages/parser/src/schemas/api-gateway.ts diff --git a/packages/parser/src/schemas/apigwv2.ts b/packages/parser/src/schemas/api-gatewayv2.ts similarity index 100% rename from packages/parser/src/schemas/apigwv2.ts rename to packages/parser/src/schemas/api-gatewayv2.ts diff --git a/packages/parser/src/schemas/dynamodb.ts b/packages/parser/src/schemas/dynamodb.ts index ee361b783b..00170ac672 100644 --- a/packages/parser/src/schemas/dynamodb.ts +++ b/packages/parser/src/schemas/dynamodb.ts @@ -230,5 +230,6 @@ export { DynamoDBStreamSchema, DynamoDBStreamRecord, DynamoDBStreamChangeRecord, + DynamoDBStreamChangeRecordBase, UserIdentity, }; diff --git a/packages/parser/src/schemas/index.ts b/packages/parser/src/schemas/index.ts index 18f3a35424..eedaaeb800 100644 --- a/packages/parser/src/schemas/index.ts +++ b/packages/parser/src/schemas/index.ts @@ -4,7 +4,7 @@ export { APIGatewayRequestAuthorizerEventSchema, APIGatewayTokenAuthorizerEventSchema, APIGatewayEventRequestContextSchema, -} from './apigw.js'; +} from './api-gateway.js'; export { AppSyncResolverSchema, AppSyncBatchResolverSchema, @@ -14,7 +14,7 @@ export { APIGatewayRequestAuthorizerEventV2Schema, APIGatewayRequestAuthorizerV2Schema, APIGatewayRequestContextV2Schema, -} from './apigwv2.js'; +} from './api-gatewayv2.js'; export { CloudFormationCustomResourceCreateSchema, CloudFormationCustomResourceDeleteSchema, diff --git a/packages/parser/src/schemas/lambda.ts b/packages/parser/src/schemas/lambda.ts index 0530f56d67..e5fe679329 100644 --- a/packages/parser/src/schemas/lambda.ts +++ b/packages/parser/src/schemas/lambda.ts @@ -1,4 +1,4 @@ -import { APIGatewayProxyEventV2Schema } from './apigwv2.js'; +import { APIGatewayProxyEventV2Schema } from './api-gatewayv2.js'; /** * Zod schema for Lambda Function URL follows the API Gateway HTTP APIs Payload Format Version 2.0. diff --git a/packages/parser/src/schemas/s3.ts b/packages/parser/src/schemas/s3.ts index c7d0b78541..650712a78a 100644 --- a/packages/parser/src/schemas/s3.ts +++ b/packages/parser/src/schemas/s3.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { JSONStringified } from '../helpers.js'; +import { JSONStringified } from '../helpers/index.js'; import { EventBridgeSchema } from './eventbridge.js'; import { SqsRecordSchema } from './sqs.js'; diff --git a/packages/parser/tests/unit/envelopes/api-gateway.test.ts b/packages/parser/tests/unit/envelopes/api-gateway.test.ts index 275d9d7c1b..83c6b3b455 100644 --- a/packages/parser/tests/unit/envelopes/api-gateway.test.ts +++ b/packages/parser/tests/unit/envelopes/api-gateway.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { ApiGatewayEnvelope } from '../../../src/envelopes/index.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { APIGatewayProxyEvent } from '../../../src/types/schema.js'; import { getTestEvent, omit } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/api-gatewayv2.test.ts b/packages/parser/tests/unit/envelopes/api-gatewayv2.test.ts index 99f90373a0..4d03b6f2f1 100644 --- a/packages/parser/tests/unit/envelopes/api-gatewayv2.test.ts +++ b/packages/parser/tests/unit/envelopes/api-gatewayv2.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { ApiGatewayV2Envelope } from '../../../src/envelopes/api-gatewayv2.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { APIGatewayProxyEventV2 } from '../../../src/types/schema.js'; import { getTestEvent, omit } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/cloudwatch.test.ts b/packages/parser/tests/unit/envelopes/cloudwatch.test.ts index 4e617e088d..139666b57d 100644 --- a/packages/parser/tests/unit/envelopes/cloudwatch.test.ts +++ b/packages/parser/tests/unit/envelopes/cloudwatch.test.ts @@ -4,7 +4,7 @@ import { ZodError, z } from 'zod'; import { ParseError } from '../../../src'; import { CloudWatchEnvelope } from '../../../src/envelopes/cloudwatch.js'; import { DecompressError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index'; import { getTestEvent } from '../helpers/utils.js'; const decompressRecordToJSON = ( diff --git a/packages/parser/tests/unit/envelopes/kafka.test.ts b/packages/parser/tests/unit/envelopes/kafka.test.ts index 70df419978..284bd89ea9 100644 --- a/packages/parser/tests/unit/envelopes/kafka.test.ts +++ b/packages/parser/tests/unit/envelopes/kafka.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { KafkaEnvelope } from '../../../src/envelopes/kafka.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import { getTestEvent } from '../helpers/utils.js'; describe('Envelope: Kafka', () => { diff --git a/packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts b/packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts index bf5476c412..77e788d87c 100644 --- a/packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts +++ b/packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { KinesisFirehoseEnvelope } from '../../../src/envelopes/kinesis-firehose.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { KinesisFireHoseEvent, KinesisFireHoseSqsEvent, diff --git a/packages/parser/tests/unit/envelopes/sns-sqs.test.ts b/packages/parser/tests/unit/envelopes/sns-sqs.test.ts index 93c193a227..8d8c0d7e07 100644 --- a/packages/parser/tests/unit/envelopes/sns-sqs.test.ts +++ b/packages/parser/tests/unit/envelopes/sns-sqs.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { SnsSqsEnvelope } from '../../../src/envelopes/sns-sqs.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { SqsEvent } from '../../../src/types/schema.js'; import { getTestEvent } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/sns.test.ts b/packages/parser/tests/unit/envelopes/sns.test.ts index ee0793fd0c..7e4eee6552 100644 --- a/packages/parser/tests/unit/envelopes/sns.test.ts +++ b/packages/parser/tests/unit/envelopes/sns.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { SnsEnvelope } from '../../../src/envelopes/sns.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { SnsEvent } from '../../../src/types/schema.js'; import { getTestEvent } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/sqs.test.ts b/packages/parser/tests/unit/envelopes/sqs.test.ts index 97a0539709..99fd3cb35f 100644 --- a/packages/parser/tests/unit/envelopes/sqs.test.ts +++ b/packages/parser/tests/unit/envelopes/sqs.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { SqsEnvelope } from '../../../src/envelopes/sqs.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { SqsEvent } from '../../../src/types/schema.js'; import { getTestEvent } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/vpc-lattice.test.ts b/packages/parser/tests/unit/envelopes/vpc-lattice.test.ts index 9a77317d81..1980db49e9 100644 --- a/packages/parser/tests/unit/envelopes/vpc-lattice.test.ts +++ b/packages/parser/tests/unit/envelopes/vpc-lattice.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { VpcLatticeEnvelope } from '../../../src/envelopes/vpc-lattice.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { VpcLatticeEvent } from '../../../src/types/index.js'; import { getTestEvent, omit } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts b/packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts index a3097b741e..49f5ec81bf 100644 --- a/packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts +++ b/packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'; import { ZodError, z } from 'zod'; import { VpcLatticeV2Envelope } from '../../../src/envelopes/vpc-latticev2.js'; import { ParseError } from '../../../src/errors.js'; -import { JSONStringified } from '../../../src/helpers.js'; +import { JSONStringified } from '../../../src/helpers/index.js'; import type { VpcLatticeEventV2 } from '../../../src/types/index.js'; import { getTestEvent, omit } from '../helpers/utils.js'; diff --git a/packages/parser/tests/unit/helpers.test.ts b/packages/parser/tests/unit/helpers.test.ts index fd4b73eb14..9811234c2d 100644 --- a/packages/parser/tests/unit/helpers.test.ts +++ b/packages/parser/tests/unit/helpers.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; import { z } from 'zod'; -import { JSONStringified } from '../../src/helpers.js'; import { DynamoDBMarshalled } from '../../src/helpers/dynamodb.js'; +import { JSONStringified } from '../../src/helpers/index.js'; import { AlbSchema } from '../../src/schemas/alb.js'; import { DynamoDBStreamRecord, diff --git a/packages/parser/tests/unit/parser.middy.test.ts b/packages/parser/tests/unit/parser.middy.test.ts index c6bfdb34cc..34a3f1caf8 100644 --- a/packages/parser/tests/unit/parser.middy.test.ts +++ b/packages/parser/tests/unit/parser.middy.test.ts @@ -5,7 +5,7 @@ import { z } from 'zod'; import { EventBridgeEnvelope } from '../../src/envelopes/eventbridge.js'; import { SqsEnvelope } from '../../src/envelopes/sqs.js'; import { ParseError } from '../../src/errors.js'; -import { parser } from '../../src/middleware/parser.js'; +import { parser } from '../../src/middleware/index.js'; import type { EventBridgeEvent, ParsedResult, diff --git a/packages/parser/typedoc.json b/packages/parser/typedoc.json index 0650b79fad..cc06598557 100644 --- a/packages/parser/typedoc.json +++ b/packages/parser/typedoc.json @@ -2,11 +2,11 @@ "extends": ["../../typedoc.base.json"], "entryPoints": [ "./src/index.ts", - "./src/middleware/parser.ts", + "./src/middleware/index.ts", "./src/types/index.ts", "./src/envelopes/index.ts", "./src/schemas/index.ts", - "./src/helpers.ts", + "./src/helpers/index.ts", "./src/helpers/dynamodb.ts" ], "readme": "README.md"