Skip to content

Instantly share code, notes, and snippets.

@abhinavdhasmana
Last active April 5, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhinavdhasmana/af617d24dc26599b0345489959668312 to your computer and use it in GitHub Desktop.
Save abhinavdhasmana/af617d24dc26599b0345489959668312 to your computer and use it in GitHub Desktop.
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