typed-topics
v0.0.2
Published
Subscribable topics with runtime schema validation
Downloads
2
Maintainers
Readme
Typed Topic is a module for pub-sub with runtime type checking. The runtime type checking can be accomplished with Joi schemas or a user provided library and matching schemas.
const schema = Joi.object().keys({
category: Joi.string().alphanum().min(1).required(),
action: Joi.string().alphanum().min(1).required()
});
const topic = new TypedTopic({ type: 'analyticsEvents', schema, validator: Joi });
topic.subscribe(event => console.log(event));
// prints event + some metadata
topic.log({ category: 'buy-button', action: 'click' });
// throws error due to schema violation
topic.log({ category: 12 });
// cancels all subscriptions (additional calls to topic.log() have no effect)
topic.close();
Getting Started
The Typed Topic module can be loaded as:
- A CommonJS / Node module available at npmjs
- A
script
tag (creates the global variabletypedTopic
)
Examples
Coming soon, see the spec file for now.