Skip to content

Commit 188d7fb

Browse files
committed
fix(parser): parse sqs record as JSON and S3Schema in S3SqsEventNotificationRecordSchema
1 parent 4721dda commit 188d7fb

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: packages/parser/src/schemas/s3.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { z } from 'zod';
2+
import { JSONStringified } from '../helpers.js';
23
import { EventBridgeSchema } from './eventbridge.js';
34
import { SqsRecordSchema } from './sqs.js';
45

@@ -170,12 +171,15 @@ const S3Schema = z.object({
170171
});
171172

172173
const S3SqsEventNotificationRecordSchema = SqsRecordSchema.extend({
173-
body: z.string(),
174+
body: JSONStringified(S3Schema),
174175
});
175176

176177
/**
177178
* Zod schema for S3 -> SQS -> Lambda event notification.
178179
*
180+
* Each SQS record’s body field is automatically parsed from a JSON string
181+
* and then validated as an S3 event.
182+
*
179183
* @example
180184
* ```json
181185
* {

Diff for: packages/parser/tests/unit/schema/s3.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,15 @@ describe('Schema: S3', () => {
196196
filename: 'sqs-event',
197197
});
198198

199+
const expected = structuredClone(event);
200+
// @ts-expect-error - Modifying the expected result to account for transform
201+
expected.Records[0].body = JSON.parse(expected.Records[0].body);
202+
199203
// Prepare
200204
const result = S3SqsEventNotificationSchema.parse(event);
201205

202206
// Assess
203-
expect(result).toStrictEqual(event);
207+
expect(result).toStrictEqual(expected);
204208
});
205209

206210
it('throws if the S3 event notification SQS event is not valid', () => {

0 commit comments

Comments
 (0)