Make Subscriber interface generic
rhyek opened this issue · 5 comments
rhyek commented
Make Subsrciber
interface generic such that I can define custom notification events + payload types like so:
interface NotificationEvents {
'inserted-row': {
tableName: string;
row: Record;
};
}
export default class PgListenerService extends BaseService {
subscriber: Subscriber<NotificationEvents>;
constructor() {
super();
this.subscriber = createSubscriber({ connectionString: envs.pgDbUrl });
process.on('exit', () => {
this.subscriber.close();
});
}
async init() {
this.subscriber.notifications.on('inserted-row', payload => {
payload.tableName; // string instead of any
});
await this.subscriber.connect();
await this.subscriber.listenTo('inserted-row');
}
}
andywer commented
Wow, I had to double-check that it really isn’t generic yet... Don’t ask me why it’s not. Let’s fix it 👍
rhyek commented
It looks pretty slick. Any chance of it being published today? Would like to use it for something I'm currently working on. 😁