typed-pub-sub
TypeScript icon, indicating that this package has built-in type declarations

5.0.0 • Public • Published

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);
});

Readme

Keywords

Package Sidebar

Install

npm i typed-pub-sub

Weekly Downloads

24

Version

5.0.0

License

MIT

Unpacked Size

25 kB

Total Files

23

Last publish

Collaborators

  • dominicbartl