@arturwojnar/hermes-postgresql
Version:
Production-Ready TypeScript Outbox Pattern for PostgreSQL
66 lines (65 loc) • 2.07 kB
TypeScript
import { NonEmptyString } from '@arturwojnar/hermes';
import { type SlotName } from '../common/consts.js';
import type { Lsn } from '../common/lsn.js';
declare enum MessageType {
Begin = "B",
Insert = "I",
Commit = "C",
Other = "Other"
}
declare enum Bytes {
Int8 = 1,
Int16 = 2,
Int32 = 4,
Int64 = 8
}
declare enum TopLevelType {
XLogData = "w",
PrimaryKeepaliveMessage = "k"
}
type LogicalReplicationState = {
lastProcessedLsn: Lsn;
timestamp: Date;
publication: string;
slotName: SlotName;
};
type ColumnType = 'bigint' | 'text' | 'jsonb' | 'uint';
type ColumnConfig<Keys extends string | number | symbol = string | number | symbol> = {
[key in Keys]: ColumnType;
};
type MessageId = NonEmptyString<'MessageId'>;
type OnDataProcessingResult<InsertResult> = {
topLevelType: TopLevelType.PrimaryKeepaliveMessage;
messageType: MessageType.Other;
shouldPong: boolean;
} | {
topLevelType: TopLevelType.XLogData;
messageType: MessageType.Begin;
transactionId: number;
lsn: Lsn;
timestamp: Date;
} | {
topLevelType: TopLevelType.XLogData;
messageType: MessageType.Insert;
result: InsertResult;
} | {
topLevelType: TopLevelType.XLogData;
messageType: MessageType.Commit;
commitLsn: Lsn;
transactionEndLsn: Lsn;
commitTimestamp: Date;
} | {
topLevelType: TopLevelType.XLogData;
messageType: MessageType.Other;
symbol: string;
};
type Transaction<InsertResult = unknown> = {
transactionId: number;
lsn: Lsn;
timestamp: Date;
results: InsertResult[];
};
type OnInsert<InsertResult = unknown> = (transaction: Transaction<InsertResult>, acknowledge: () => void) => Promise<void>;
declare const parseTopLevelType: (char: string) => TopLevelType;
declare const parseMessageType: (char: string) => MessageType;
export { Bytes, LogicalReplicationState, MessageType, OnDataProcessingResult, parseMessageType, parseTopLevelType, TopLevelType, type ColumnConfig, type ColumnType, type MessageId, type OnInsert, type Transaction, };