Skip to content

Commit 22f1c9f

Browse files
committed
Used the helper function in the kinesis schema example
1 parent bddcb82 commit 22f1c9f

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

packages/parser/src/schemas/kinesis.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
import { gunzipSync } from 'node:zlib';
21
import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64';
2+
import { Base64Encoded } from 'src/helpers/index.js';
33
import { z } from 'zod';
44
import type { KinesisDataStreamEvent } from '../types/schema.js';
55
import { DynamoDBStreamToKinesisRecord } from './dynamodb.js';
66

7-
const decoder = new TextDecoder();
8-
97
const KinesisDataStreamRecordPayload = z.object({
108
kinesisSchemaVersion: z.string(),
119
partitionKey: z.string(),
1210
sequenceNumber: z.string(),
1311
approximateArrivalTimestamp: z.number(),
14-
data: z.string().transform((data) => {
15-
const decompressed = decompress(data);
16-
const decoded = decoder.decode(fromBase64(data, 'base64'));
17-
try {
18-
// If data was not compressed, try to parse it as JSON otherwise it must be string
19-
return decompressed === data ? JSON.parse(decoded) : decompressed;
20-
} catch {
21-
return decoded;
22-
}
23-
}),
12+
data: Base64Encoded(z.any()),
2413
});
2514

26-
const decompress = (data: string): string => {
27-
try {
28-
return JSON.parse(gunzipSync(fromBase64(data, 'base64')).toString('utf8'));
29-
} catch {
30-
return data;
31-
}
32-
};
33-
3415
const KinesisDataStreamRecord = z.object({
3516
eventSource: z.literal('aws:kinesis'),
3617
eventVersion: z.string(),

0 commit comments

Comments
 (0)