Skip to content

feat(eventstream-serde-universal): omit unknown event type #1325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { Message } from "@aws-sdk/types";

describe("getUnmarshalledStream", () => {
it("emits parsed message on data", async () => {
it("emits parsed payload on data", async () => {
const expectedMessages: Array<Message> = [
{
headers: {
Expand Down Expand Up @@ -124,4 +124,23 @@ describe("getUnmarshalledStream", () => {
"This is a modeled exception event that would be thrown in deserializer."
);
});

it("omit the unknown event type", async () => {
const source = async function* () {
yield recordEventMessage;
};
const unmarshallerStream = getUnmarshalledStream(source(), {
eventMarshaller: new EventStreamMarshaller(toUtf8, fromUtf8),
deserializer: message =>
Promise.resolve({
$unknown: message
} as any), //deserializer that parse anything into unknown event
toUtf8
});
const messages: Array<Message> = [];
for await (const message of unmarshallerStream) {
messages.push(message[Object.keys(message)[0]]);
}
expect(messages.length).toEqual(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export function getUnmarshalledStream<T extends { [key: string]: any }>(
const event = {
[message.headers[":event-type"].value as string]: message
};
yield await options.deserializer(event);
const deserialized = await options.deserializer(event);
if (deserialized.$unknown) continue;
yield deserialized;
} else {
throw Error(
`Unrecognizable event type: ${message.headers[":event-type"].value}`
Expand Down