@arturwojnar/hermes-postgresql
Version:
Production-Ready TypeScript Outbox Pattern for PostgreSQL
25 lines • 955 B
JavaScript
import { toServerSystemClock } from '../common/helpers.js';
import { incrementWAL } from '../common/lsn.js';
import { offset } from '../common/offset.js';
import { Bytes } from './types.js';
const createStandbyStatusUpdate = (lsn) => {
const x = Buffer.alloc(34);
const pos = offset(Bytes.Int8);
const lsnInt = incrementWAL(lsn);
x[0] = 'r'.charCodeAt(0);
x.writeBigUInt64BE(lsnInt, pos.value());
x.writeBigUInt64BE(lsnInt, pos.addInt64());
x.writeBigUInt64BE(lsnInt, pos.addInt64());
x.writeBigInt64BE(toServerSystemClock(Date.now()), pos.addInt64());
x.writeUInt8(0, pos.addInt8());
return x;
};
const sendStandbyStatusUpdate = (stream, getLastAcknowledgedLsn) => () => {
if (!stream) {
return;
}
const statusUpdate = createStandbyStatusUpdate(getLastAcknowledgedLsn());
stream.write(statusUpdate);
};
export { sendStandbyStatusUpdate };
//# sourceMappingURL=sendStandbyStatusUpdate.js.map