5.0.0 • Published 1 year ago

typed-pub-sub v5.0.0

Weekly downloads
223
License
MIT
Repository
github
Last release
1 year ago

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

1 year ago

4.0.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago