Last active
April 5, 2020 06:26
-
-
Save abhinavdhasmana/af617d24dc26599b0345489959668312 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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