Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/parser/src/envelopes/sns-sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ export const SnsSqsEnvelope = {
}>(
(acc, record, index) => {
const parsed = parseRecord(record, index);
if (!parsed.success) {
if (parsed.success) {
acc.records.push(parsed.data);
} else {
acc.success = false;
acc.errors[index] = parsed.error;
} else {
acc.records.push(parsed.data);
}
return acc;
},
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/parserDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const parser = <

const { schema, envelope, safeParse } = options;

descriptor.value = async function (
descriptor.value = function (
this: Handler,
...args: [ParserOutput<TSchema, TEnvelope, TSafeParse>, Context, Callback]
) {
Expand Down
8 changes: 5 additions & 3 deletions packages/parser/src/schemas/appsync-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ const AppSyncEventsSubscribeSchema = AppSyncEventsBaseSchema.extend({

export {
AppSyncEventsBaseSchema,
AppSyncCognitoIdentity,
AppSyncIamIdentity,
AppSyncLambdaAuthIdentity,
AppSyncOidcIdentity,
AppSyncEventsRequestSchema,
AppSyncEventsInfoSchema,
AppSyncEventsPublishSchema,
AppSyncEventsSubscribeSchema,
};
export {
AppSyncCognitoIdentity,
AppSyncIamIdentity,
AppSyncOidcIdentity,
} from './appsync-shared.js';
6 changes: 4 additions & 2 deletions packages/parser/src/schemas/appsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ const AppSyncBatchResolverSchema = z.array(AppSyncResolverSchema);
export {
AppSyncResolverSchema,
AppSyncBatchResolverSchema,
AppSyncLambdaIdentity,
};
export {
AppSyncCognitoIdentity,
AppSyncIamIdentity,
AppSyncOidcIdentity,
AppSyncLambdaIdentity,
};
} from './appsync-shared.js';
2 changes: 1 addition & 1 deletion packages/parser/src/schemas/cognito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const PostConfirmationTriggerSchema = CognitoTriggerBaseSchema.extend({
* }
* ```
*
* * @see {@link https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html | Amazon Cognito Developer Guide}
* @see {@link https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-authentication.html | Amazon Cognito Developer Guide}
*/
const PreAuthenticationTriggerSchema = CognitoTriggerBaseSchema.extend({
triggerSource: z.literal('PreAuthentication_Authentication'),
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/schemas/kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const KafkaRecordSchema = z.object({
z.record(
z.string(),
z.array(z.number()).transform((value) => {
return String.fromCharCode(...value);
return String.fromCodePoint(...value);
})
)
),
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/types/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type ParserOutput<
/**
* The parser function that can parse the data using the provided schema and envelope
* we use function overloads to provide the correct return type based on the provided envelope
**/
*/
type ParseFunction = {
// No envelope, no safeParse
<T extends StandardSchemaV1>(
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/tests/types/parser.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Parser types', () => {
envelope: SqsEnvelope,
})
)
.handler(async (event) => {
.handler((event) => {
expectTypeOf(event).toEqualTypeOf<User[]>();
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/parser/tests/unit/parser.decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'node:timers/promises';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
import type { Context } from 'aws-lambda';
import { describe, expect, it } from 'vitest';
Expand Down Expand Up @@ -30,6 +31,7 @@ describe('Decorator: parser', () => {
class TestClass implements LambdaInterface {
@parser({ schema: extendedSchema })
public async handler(event: event, _context: Context): Promise<event> {
await setTimeout(1); // simulate some processing time
return event;
}

Expand All @@ -38,6 +40,7 @@ describe('Decorator: parser', () => {
event: z.infer<typeof schema>,
_context: Context
): Promise<unknown> {
await setTimeout(1); // simulate some processing time
return this.anotherMethod(event);
}

Expand All @@ -49,6 +52,7 @@ describe('Decorator: parser', () => {
event: ParsedResult<unknown, event>,
_context: Context
): Promise<ParsedResult<unknown, event>> {
await setTimeout(1); // simulate some processing time
return event;
}

Expand All @@ -61,10 +65,11 @@ describe('Decorator: parser', () => {
event: ParsedResult<event, event>,
_context: Context
): Promise<ParsedResult> {
await setTimeout(1); // simulate some processing time
return event;
}

private async anotherMethod(event: unknown): Promise<unknown> {
private anotherMethod(event: unknown): unknown {
return event;
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/parser/tests/unit/parser.middy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Middleware: parser', () => {
const event = structuredClone(baseEventBridgeEvent);

// Act & Assess
expect(
await expect(
middy()
.use(parser({ schema: z.string(), envelope: SqsEnvelope }))
.handler((event) => event)(event as unknown as string[], {} as Context)
Expand All @@ -68,7 +68,7 @@ describe('Middleware: parser', () => {
event.Records[1].body = undefined;

// Act & Assess
expect(
await expect(
handlerWithSchemaAndEnvelope(event as unknown as string[], {} as Context)
).rejects.toThrow();
});
Expand All @@ -91,7 +91,7 @@ describe('Middleware: parser', () => {
const event = structuredClone(JSONPayload);

// Act & Assess
expect(
await expect(
middy((event) => event).use(parser({ schema: z.number() }))(
event as unknown as number,
{} as Context
Expand Down
18 changes: 9 additions & 9 deletions packages/parser/tests/unit/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Parser', () => {
});
const JSONPayload = { name: 'John', age: 18 };

it('parses an event with schema and envelope', async () => {
it('parses an event with schema and envelope', () => {
// Prepare
const event = structuredClone(baseSqsEvent);
event.Records[1].body = 'bar';
Expand All @@ -37,15 +37,15 @@ describe('Parser', () => {
expect(result).toStrictEqual(['Test message.', 'bar']);
});

it('throws when envelope does not match', async () => {
it('throws when envelope does not match', () => {
// Prepare
const event = structuredClone(baseEventBridgeEvent);

// Act & Assess
expect(() => parse(event, SqsEnvelope, z.string())).toThrow();
});

it('throws when schema does not match', async () => {
it('throws when schema does not match', () => {
// Prepare
const event = structuredClone(baseSqsEvent);
// @ts-expect-error - setting an invalid body
Expand All @@ -55,7 +55,7 @@ describe('Parser', () => {
expect(() => parse(event, SqsEnvelope, z.string())).toThrow();
});

it('parses the event successfully', async () => {
it('parses the event successfully', () => {
// Prepare
const event = 42;

Expand All @@ -66,15 +66,15 @@ describe('Parser', () => {
expect(result).toEqual(event);
});

it('throws when the event does not match the schema', async () => {
it('throws when the event does not match the schema', () => {
// Prepare
const event = structuredClone(JSONPayload);

// Act & Assess
expect(() => parse(event, undefined, z.number())).toThrow();
});

it('returns the payload when using safeParse', async () => {
it('returns the payload when using safeParse', () => {
// Prepare
const event = structuredClone(JSONPayload);

Expand All @@ -88,7 +88,7 @@ describe('Parser', () => {
});
});

it('returns the error when using safeParse and the payload is invalid', async () => {
it('returns the error when using safeParse and the payload is invalid', () => {
// Prepare
const event = structuredClone(JSONPayload);

Expand All @@ -103,7 +103,7 @@ describe('Parser', () => {
});
});

it('returns the payload when using safeParse with envelope', async () => {
it('returns the payload when using safeParse with envelope', () => {
// Prepare
const detail = structuredClone(JSONPayload);
const event = structuredClone(baseEventBridgeEvent);
Expand All @@ -119,7 +119,7 @@ describe('Parser', () => {
});
});

it('returns an error when using safeParse with envelope and the payload is invalid', async () => {
it('returns an error when using safeParse with envelope and the payload is invalid', () => {
// Prepare
const event = structuredClone(baseEventBridgeEvent);

Expand Down
Loading