1.0.0 • Published 11 months ago
pg-tbus v1.0.0
PG-TBus
End-to-end typesafe tasks and integration events on postgres made easy.
Usage
- Define integration events
const account_created_event = defineEvent({
event_name: 'account_created',
schema: Type.Object({
account_id: Type.String({ format: 'uuid' }),
}),
});
- Initialize pg-tbus
const bus = createTBus('my_service', { db: { connectionString: connectionString }, schema: schema });
- Register eventHandler
bus.registerHandler(
createEventHandler({
// should be unique for this bus handler
task_name: 'send_email',
eventDef: account_created_event,
handler: async (props) => {
// do something with the data
},
})
);
- Start the pg-tbus
bus.start();
- Emit the event
await bus.publish(account_created_event.from({ account_id: '1234' }));
Tasks
- Define task(s)
const send_email_task = defineTask({
task_name: 'send_email',
queue: 'email_svc',
schema: Type.Object({ email: Type.String() }),
});
- Register task
bus.registerTask(
createTaskHandler({
taskDef: send_email_task,
handler: async (props) => {
//send email to props.input.email
},
})
);
- Create task from somewhere else
await bus.send(send_email_task.from({ email: 'test@test.com' }));
For more usage, see tests/bus.ts
1.0.0
11 months ago
0.1.8
12 months ago
0.1.7
12 months ago
0.1.9
12 months ago
0.1.4
12 months ago
0.1.6
12 months ago
0.1.5
12 months ago
0.1.2
1 year ago
0.1.3
12 months ago
0.1.1
1 year ago
0.1.0
1 year ago
0.0.10
1 year ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.1
1 year ago