Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const event = {
domain: User,
eventName: UserCreatedSuccess,
eventData: {
username: 'newUserName',
email: 'test@test.com',
originalImageUrl: 'some url',
}
};
const { schemas, supportedEvents
} = await loadRegistry();
// Step 1: check if event domain is defined and event is defined in it
const supportedEventStatus = supportedEvents[event.domain
][event.eventName
];
if (supportedEventStatus === undefined) {
// oops, event is not defined. Throw error
throw new Error('event is not defined in the registry');
}
// if you sent the schema over the wire using describe, recreate a joi object
const joiSchema = Joi.build(schemas[event.domain
][event.eventName
]);
const { error
} = joiSchema.validate(event);
if (error === undefined) {
// event is valid, raise the event
} else {
// event is invalid. raise error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment