import { RelationsCache, Row, SqlValue, DataTransaction, DataChange } from '../util/types.js'; export type Timestamp = string; export type Tag = string; export type ShadowKey = string; export interface OplogEntry { namespace: string; tablename: string; primaryKey: string; rowid: number; optype: OpType; timestamp: string; newRow?: string; oldRow?: string; clearTags: string; } export interface OplogEntryChanges { namespace: string; tablename: string; primaryKeyCols: { [key: string]: string | number; }; optype: ChangesOpType; changes: OplogColumnChanges; tag: Tag | null; clearTags: Tag[]; } export interface ShadowEntryChanges { namespace: string; tablename: string; primaryKeyCols: { [key: string]: string | number; }; optype: ChangesOpType; changes: OplogColumnChanges; fullRow: Row; tags: Tag[]; } export interface OplogColumnChanges { [columnName: string]: { value: SqlValue; timestamp: number; }; } export interface OplogTableChanges { [qualifiedTablenameStr: string]: { [primaryKey: string]: [Timestamp, OplogEntryChanges]; }; } export interface PendingChanges { [qualifiedTablenameStr: string]: { [primaryKey: string]: ShadowEntryChanges; }; } export type OpType = 'DELETE' | 'INSERT' | 'UPDATE' | 'COMPENSATION' | 'GONE'; export type ChangesOpType = 'DELETE' | 'UPSERT' | 'GONE'; export declare const OPTYPES: { insert: 'INSERT'; update: 'UPDATE'; delete: 'DELETE'; upsert: 'UPSERT'; compensation: 'COMPENSATION'; gone: 'GONE'; }; export interface ShadowEntry { namespace: string; tablename: string; primaryKey: string; tags: string; } export declare const shadowTagsDefault = "[]"; export declare const stringToOpType: (opTypeStr: string) => OpType; export declare const localEntryToChanges: (entry: OplogEntry, tag: Tag, relations: RelationsCache) => OplogEntryChanges; export declare const remoteEntryToChanges: (entry: OplogEntry, relations: RelationsCache) => ShadowEntryChanges; /** * Convert a list of `OplogEntry`s into a nested `OplogTableChanges` map of * `{tableName: {primaryKey: entryChanges}}` where the entryChanges has the * most recent `optype` and column `value` from all of the operations. * Multiple OplogEntries that point to the same row will be merged to a * single OpLogEntryChanges object. * * @param operations Array of local oplog entries. * @param genTag Function that generates a tag from a timestamp. * @returns An object of oplog table changes. */ export declare const localOperationsToTableChanges: (operations: OplogEntry[], genTag: (timestamp: Date) => Tag, relations: RelationsCache) => OplogTableChanges; export declare const remoteOperationsToTableChanges: (operations: OplogEntry[], relations: RelationsCache) => PendingChanges; export declare function extractPK(c: DataChange): string; export declare const fromTransaction: (transaction: DataTransaction, _relations: RelationsCache, namespace: string) => OplogEntry[]; export declare const toTransactions: (opLogEntries: OplogEntry[], relations: RelationsCache) => DataTransaction[]; export declare const getShadowPrimaryKey: (oplogEntry: OplogEntry | OplogEntryChanges | ShadowEntryChanges) => ShadowKey; export declare const encodeTags: (tags: Tag[]) => string; export declare const decodeTags: (tags: string) => Tag[]; export declare const opLogEntryToChange: (entry: OplogEntry, relations: RelationsCache) => DataChange; /** * Convert a primary key to a string the same way our triggers do when generating oplog entries. * * Takes the object that contains the primary key and serializes it to JSON in a non-prettified * way with column sorting. * * @param primaryKeyObj object representing all columns of a primary key * @returns a stringified JSON with stable sorting on column names */ export declare const primaryKeyToStr: >(primaryKeyObj: T) => string; export declare const generateTag: (instanceId: string, timestamp: Date | number) => Tag;