typed-pub-sub
v5.0.0
Published
Lightweight wrapper for typed PubSub events
Downloads
543
Readme
Typed PubSub Events
A lightweight wrapper for sending typed data using PubSub events and parsing it in a Firebase function.
Usage
This library can be using with Inversify
Loading the module into the Inversify container
container.load(
new PubSubModule({
projectId: 'google-cloud-project-id'
})
)
Defining events
export interface PublishBlogPostEvent {
userId: string;
postId: string;
}
export const MigrateDatabase = PubSubEvent.make<void>('migrate');
export const PublishBlogPost = PubSubEvent.make<PublishBlogPostEvent>('publishBlogPost', {
userId: 'string',
postId: 'string'
})
Sending events
async function triggerPublishPost(userId: string, postId: string) {
const event = PublishProgram.create({
userId, postId
});
return this.pubSubService.publishMessage(event);
}
Register a Firebase function
export const publishBlogPost = createPubSubFunction(PublishBlogPost, (data) => {
console.log(data.userId, data.postId);
});