UNPKG

pg-trx-outbox

Version:

Transactional outbox of Postgres for Node.js with little Event Sourcing

21 lines (20 loc) 893 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FSM = void 0; const robot3_1 = require("robot3"); class FSM { options; transfer; constructor(options, transfer) { this.options = options; this.transfer = transfer; } fsm = (0, robot3_1.interpret)((0, robot3_1.createMachine)('wait', { wait: (0, robot3_1.state)((0, robot3_1.transition)('poll', 'processing'), (0, robot3_1.transition)('notify', 'processing'), (0, robot3_1.transition)('manual', 'processing')), processing: (0, robot3_1.invoke)(() => this.transfer.transferMessages(), (0, robot3_1.transition)('done', 'wait'), (0, robot3_1.transition)('error', 'wait', (0, robot3_1.action)((_, { error }) => this.options.outboxOptions?.onError?.(error)))), }), () => { }); send(event) { return this.fsm.send(event); } } exports.FSM = FSM;