@unchainedshop/core-events
Version:
This package defines the event module which ensures the emitted events are written to the database as an Event History and offers a core module to search for events.
22 lines (20 loc) • 620 B
text/typescript
import { getEmitHistoryAdapter, setEmitHistoryAdapter, EmitAdapter } from '@unchainedshop/events';
import { RawPayloadType } from '@unchainedshop/events';
export const configureEventHistoryAdapter = (
createFn: ({ type, payload }: RawPayloadType<any> & { type: string }) => Promise<unknown>,
) => {
if (!getEmitHistoryAdapter()) {
const adapter: EmitAdapter = {
subscribe: () => {
// Do nothing
},
publish: async (eventName, { payload }) => {
await createFn({
type: eventName,
payload,
});
},
};
setEmitHistoryAdapter(adapter);
}
};