Skip to content

Commit

Permalink
chore(parser): add parser subpath exports to package.json (#2179)
Browse files Browse the repository at this point in the history
* add exports and type version to package json, including index.js

* use index.js as import for coverage

* use package lock from main

* fix envelope path and add types to exports

* use explicit exports instead of *

* import type

* make export types explicit

* adjust imports in tests for coverage, removed unused exports

* remove duplicate imports
  • Loading branch information
am29d authored Mar 11, 2024
1 parent a9f5d79 commit b348b95
Show file tree
Hide file tree
Showing 39 changed files with 4,029 additions and 2,366 deletions.
6,188 changes: 3,872 additions & 2,316 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@
"types": "./lib/esm/index.d.ts",
"default": "./lib/esm/index.js"
}
},
"./middleware": {
"require": "./lib/cjs/middleware/parser.js",
"import": "./lib/esm/middleware/parser.js"
},
"./schemas": {
"require": "./lib/cjs/schemas/index.js",
"import": "./lib/esm/schemas/index.js"
},
"./envelopes": {
"require": "./lib/cjs/envelopes/index.js",
"import": "./lib/esm/envelopes/index.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"
],
"envelopes": [
"./lib/cjs/envelopes/index.d.ts",
"./lib/esm/envelopes/index.d.ts"
]
}
},
"main": "./lib/cjs/index.js",
Expand Down
13 changes: 13 additions & 0 deletions packages/parser/src/envelopes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { apiGatewayEnvelope } from './apigw.js';
export { apiGatewayV2Envelope } from './apigwv2.js';
export { cloudWatchEnvelope } from './cloudwatch.js';
export { dynamoDDStreamEnvelope } from './dynamodb.js';
export { eventBridgeEnvelope } from './event-bridge.js';
export { kafkaEnvelope } from './kafka.js';
export { kinesisEnvelope } from './kinesis.js';
export { kinesisFirehoseEnvelope } from './kinesis-firehose.js';
export { lambdaFunctionUrlEnvelope } from './lambda.js';
export { snsEnvelope, snsSqsEnvelope } from './sns.js';
export { sqsEnvelope } from './sqs.js';
export { vpcLatticeEnvelope } from './vpc-lattice.js';
export { vpcLatticeV2Envelope } from './vpc-latticev2.js';
1 change: 1 addition & 0 deletions packages/parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { parser } from './parser.js';
4 changes: 1 addition & 3 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { type ParserOptions } from './types/ParserOptions.js';
*
* @param options
*/
const parser = <S extends ZodSchema>(
export const parser = <S extends ZodSchema>(
options: ParserOptions<S>
): HandlerMethodDecorator => {
return (_target, _propertyKey, descriptor) => {
Expand All @@ -55,5 +55,3 @@ const parser = <S extends ZodSchema>(
return descriptor;
};
};

export { parser };
33 changes: 33 additions & 0 deletions packages/parser/src/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export { AlbSchema, AlbMultiValueHeadersSchema } from './alb.js';
export { APIGatewayProxyEventSchema } from './apigw.js';
export { APIGatewayProxyEventV2Schema } from './apigwv2.js';
export {
CloudFormationCustomResourceCreateSchema,
CloudFormationCustomResourceDeleteSchema,
CloudFormationCustomResourceUpdateSchema,
} from './cloudformation-custom-resource.js';
export {
CloudWatchLogEventSchema,
CloudWatchLogsDecodeSchema,
CloudWatchLogsSchema,
} from './cloudwatch.js';
export { DynamoDBStreamSchema } from './dynamodb.js';
export { EventBridgeSchema } from './eventbridge.js';
export { KafkaMskEventSchema, KafkaSelfManagedEventSchema } from './kafka.js';
export { KinesisDataStreamSchema } from './kinesis.js';
export {
KinesisFirehoseSchema,
KinesisFirehoseSqsSchema,
} from './kinesis-firehose.js';
export { LambdaFunctionUrlSchema } from './lambda.js';
export {
S3SqsEventNotificationSchema,
S3EventNotificationEventBridgeSchema,
S3ObjectLambdaEventSchema,
S3Schema,
} from './s3.js';
export { SesSchema } from './ses.js';
export { SnsSchema } from './sns.js';
export { SqsSchema } from './sqs.js';
export { VpcLatticeSchema } from './vpc-lattice.js';
export { VpcLatticeV2Schema } from './vpc-latticev2.js';
4 changes: 1 addition & 3 deletions packages/parser/src/types/ParserOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { ZodSchema } from 'zod';
import { Envelope } from './envelope.js';

type ParserOptions<S extends ZodSchema> = {
export type ParserOptions<S extends ZodSchema> = {
schema: S;
envelope?: Envelope;
};

export { type ParserOptions };
31 changes: 31 additions & 0 deletions packages/parser/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export type { ParserOptions } from './ParserOptions.js';
export type { Envelope } from './envelope.js';

export type {
ALBEvent,
APIGatewayProxyEvent,
ALBMultiValueHeadersEvent,
APIGatewayProxyEventV2,
S3Event,
S3EventNotificationEventBridge,
S3SqsEventNotification,
SnsEvent,
SqsEvent,
DynamoDBStreamEvent,
CloudWatchLogsEvent,
CloudFormationCustomResourceCreateEvent,
CloudFormationCustomResourceDeleteEvent,
CloudFormationCustomResourceUpdateEvent,
EventBridgeEvent,
KafkaSelfManagedEvent,
KafkaMskEvent,
KinesisDataStreamEvent,
KinesisDataStreamRecord,
KinesisDataStreamRecordPayload,
KinesisFireHoseEvent,
KinesisFireHoseSqsEvent,
LambdaFunctionUrlEvent,
SesEvent,
VpcLatticeEvent,
VpcLatticeEventV2,
} from './schema.js';
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/envelopes/apigwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import { generateMock } from '@anatine/zod-mock';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { APIGatewayProxyEvent } from '../../../src/types/schema.js';
import { apiGatewayEnvelope } from '../../../src/envelopes/apigw';
import { APIGatewayProxyEvent } from '../../../src/types/';
import { apiGatewayEnvelope } from '../../../src/envelopes/';

describe('ApigwEnvelope ', () => {
it('should parse custom schema in envelope', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/apigwv2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TestEvents, TestSchema } from '../schema/utils.js';
import { generateMock } from '@anatine/zod-mock';
import { APIGatewayProxyEventV2 } from 'aws-lambda';
import { apiGatewayV2Envelope } from '../../../src/envelopes/apigwv2';
import { apiGatewayV2Envelope } from '../../../src/envelopes/';

describe('ApiGwV2Envelope ', () => {
it('should parse custom schema in envelope', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/envelopes/cloudwatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { gzipSync } from 'node:zlib';
import {
CloudWatchLogEventSchema,
CloudWatchLogsDecodeSchema,
} from '../../../src/schemas/cloudwatch.js';
} from '../../../src/schemas/';
import { TestSchema } from '../schema/utils.js';
import { cloudWatchEnvelope } from '../../../src/envelopes/cloudwatch';
import { cloudWatchEnvelope } from '../../../src/envelopes/';

describe('CloudWatch', () => {
it('should parse custom schema in envelope', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/dynamodb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { generateMock } from '@anatine/zod-mock';
import { TestEvents } from '../schema/utils.js';
import { DynamoDBStreamEvent } from 'aws-lambda';
import { z } from 'zod';
import { dynamoDDStreamEnvelope } from '../../../src/envelopes/dynamodb';
import { dynamoDDStreamEnvelope } from '../../../src/envelopes/';

describe('DynamoDB', () => {
const schema = z.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/eventbridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TestEvents, TestSchema } from '../schema/utils.js';
import { generateMock } from '@anatine/zod-mock';
import { EventBridgeEvent } from 'aws-lambda';
import { eventBridgeEnvelope } from '../../../src/envelopes/event-bridge.js';
import { eventBridgeEnvelope } from '../../../src/envelopes/';

describe('EventBridgeEnvelope ', () => {
it('should parse eventbridge event', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/kafka.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { generateMock } from '@anatine/zod-mock';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { MSKEvent, SelfManagedKafkaEvent } from 'aws-lambda';
import { kafkaEnvelope } from '../../../src/envelopes/kafka';
import { kafkaEnvelope } from '../../../src/envelopes/';

describe('Kafka', () => {
it('should parse MSK kafka envelope', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/envelopes/kinesis-firehose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { TestEvents, TestSchema } from '../schema/utils.js';
import { generateMock } from '@anatine/zod-mock';
import { KinesisFirehoseSchema } from '../../../src/schemas/kinesis-firehose.js';
import { KinesisFirehoseSchema } from '../../../src/schemas/';
import { z } from 'zod';
import { kinesisFirehoseEnvelope } from '../../../src/envelopes/kinesis-firehose';
import { kinesisFirehoseEnvelope } from '../../../src/envelopes/';

describe('Kinesis Firehose Envelope', () => {
it('should parse records for PutEvent', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/kinesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { generateMock } from '@anatine/zod-mock';
import { KinesisStreamEvent } from 'aws-lambda';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { kinesisEnvelope } from '../../../src/envelopes/kinesis';
import { kinesisEnvelope } from '../../../src/envelopes/';

describe('Kinesis', () => {
it('should parse Kinesis Stream event', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { TestEvents, TestSchema } from '../schema/utils.js';
import { generateMock } from '@anatine/zod-mock';
import { APIGatewayProxyEventV2 } from 'aws-lambda';
import { lambdaFunctionUrlEnvelope } from '../../../src/envelopes/lambda';
import { lambdaFunctionUrlEnvelope } from '../../../src/envelopes/';

describe('Lambda Functions Url ', () => {
it('should parse custom schema in envelope', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/sns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { z } from 'zod';
import { generateMock } from '@anatine/zod-mock';
import { SNSEvent, SQSEvent } from 'aws-lambda';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { snsEnvelope, snsSqsEnvelope } from '../../../src/envelopes/sns';
import { snsEnvelope, snsSqsEnvelope } from '../../../src/envelopes/';

describe('SNS Envelope', () => {
it('should parse custom schema in envelope', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/envelopes/sqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { generateMock } from '@anatine/zod-mock';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { SQSEvent } from 'aws-lambda';
import { sqsEnvelope } from '../../../src/envelopes/sqs';
import { sqsEnvelope } from '../../../src/envelopes/';

describe('SqsEnvelope ', () => {
it('should parse custom schema in envelope', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/envelopes/vpc-lattice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import { generateMock } from '@anatine/zod-mock';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { VpcLatticeSchema } from '../../../src/schemas/vpc-lattice.js';
import { VpcLatticeSchema } from '../../../src/schemas/';
import { z } from 'zod';
import { vpcLatticeEnvelope } from '../../../src/envelopes/vpc-lattice';
import { vpcLatticeEnvelope } from '../../../src/envelopes/';

describe('VPC Lattice envelope', () => {
it('should parse VPC Lattice event', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/envelopes/vpc-latticev2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

import { generateMock } from '@anatine/zod-mock';
import { VpcLatticeSchema } from '../../../src/schemas/vpc-lattice.js';
import { VpcLatticeSchema } from '../../../src/schemas/';
import { z } from 'zod';
import { TestEvents, TestSchema } from '../schema/utils.js';
import { vpcLatticeV2Envelope } from '../../../src/envelopes/vpc-latticev2';
import { vpcLatticeV2Envelope } from '../../../src/envelopes/';

describe('VPC Lattice envelope', () => {
it('should parse VPC Lattice event', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/parser/tests/unit/parser.decorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* @group unit/parser
*/

import { LambdaInterface } from '@aws-lambda-powertools/commons/lib/esm/types';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/lib/esm/types';
import { Context, EventBridgeEvent } from 'aws-lambda';
import { parser } from '../../src/parser';
import { parser } from '../../src/index.js';
import { TestSchema, TestEvents } from './schema/utils';
import { generateMock } from '@anatine/zod-mock';
import { eventBridgeEnvelope } from '../../src/envelopes/event-bridge';
import { EventBridgeSchema } from '../../src/schemas/eventbridge';
import { eventBridgeEnvelope } from '../../src/envelopes/index.js';
import { EventBridgeSchema } from '../../src/schemas/index.js';
import { z } from 'zod';

describe('Parser Decorator', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/parser/tests/unit/parser.middy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import middy from '@middy/core';
import { Context } from 'aws-lambda';
import { parser } from '../../src/middleware/parser.js';
import { generateMock } from '@anatine/zod-mock';
import { SqsSchema } from '../../src/schemas/sqs.js';
import { SqsSchema } from '../../src/schemas/index.js';
import { z, type ZodSchema } from 'zod';
import { sqsEnvelope } from '../../src/envelopes/sqs';
import { sqsEnvelope } from '../../src/envelopes/index.js';
import { TestSchema } from './schema/utils';

describe('Middleware: parser', () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/parser/tests/unit/schema/alb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*
* @group unit/parser/schema/
*/
import {
AlbSchema,
AlbMultiValueHeadersSchema,
} from '../../../src/schemas/alb.js';
import { AlbSchema, AlbMultiValueHeadersSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('ALB ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/apigw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/parser/schema/
*/

import { APIGatewayProxyEventSchema } from '../../../src/schemas/apigw.js';
import { APIGatewayProxyEventSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('APIGateway ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/apigwv2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/parser/schema/
*/

import { APIGatewayProxyEventV2Schema } from '../../../src/schemas/apigwv2.js';
import { APIGatewayProxyEventV2Schema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('API GW v2 ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
CloudFormationCustomResourceCreateSchema,
CloudFormationCustomResourceUpdateSchema,
CloudFormationCustomResourceDeleteSchema,
} from '../../../src/schemas/cloudformation-custom-resource.js';
} from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('CloudFormationCustomResource ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/cloudwatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/parser/schema/
*/

import { CloudWatchLogsSchema } from '../../../src/schemas/cloudwatch.js';
import { CloudWatchLogsSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('CloudWatchLogs ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/dynamodb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/parser/schema/
*/

import { DynamoDBStreamSchema } from '../../../src/schemas/dynamodb.js';
import { DynamoDBStreamSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('DynamoDB ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/eventbridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @group unit/parser/schema/
*/

import { EventBridgeSchema } from '../../../src/schemas/eventbridge.js';
import { EventBridgeSchema } from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('EventBridge ', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/unit/schema/kafka.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import {
KafkaMskEventSchema,
KafkaSelfManagedEventSchema,
} from '../../../src/schemas/kafka.js';
} from '../../../src/schemas/';
import { TestEvents } from './utils.js';

describe('Kafka ', () => {
Expand Down
Loading

0 comments on commit b348b95

Please sign in to comment.