mongo-oplog2
Version:
Simple monitoring of MongoDB oplog.
76 lines (75 loc) • 2.11 kB
TypeScript
import { FilterQuery, Timestamp } from "mongodb";
export declare const opMap: Readonly<{
readonly i: "insert";
readonly insert: "i";
readonly d: "delete";
readonly delete: "d";
readonly n: "noop";
readonly noop: "n";
readonly u: "update";
readonly update: "i";
}>;
/**
* Converts from the operation code from the native MongoDB versions to
* friendlier names. Conversions are:
* i: insert
* d: delete
* n: noop
* u: update
* @param op MongoDB operation code
*/
export declare function getOpName(op: string): 'insert' | 'delete' | 'noop' | 'update';
/**
* Converts a number into a MongoDB `Timestamp`
* @param ts timestamp to convert
*/
export declare function getTimestamp(ts?: number | Timestamp | string): Timestamp;
/**
* Returns a new object without any of the specified keys.
* @param obj Initial object
* @param keys array of keys to be removed from the object
*/
export declare function omit(obj: any, keys: string[]): any;
/**
* Converts from `OplogDoc` format to `PrettyOplogDoc` format.
* @param oplogDoc a document in MongoDB OplogDoc format.
*/
export declare function prettify(oplogDoc: OplogDoc): PrettyOplogDoc;
/**
* Returns a `RegExp` used for filtering events.
* @param pattern regex pattern
*/
export declare function regex(pattern: string): RegExp;
/**
* Returns a promise that will resolve after a specified period of time.
* @param ms length of time before promise should resolve.
*/
export declare function timeout(ms: number): Promise<any>;
/**
* Defines the structure of a MongoDB oplog
* document.
*/
export interface OplogDoc {
ts: Timestamp;
op: string;
ns: string;
h: any;
o: any;
o2: any;
}
export declare type OplogQuery = FilterQuery<OplogDoc>;
/**
* Defines the structure of a "pretty" oplog document
* which is an alternate format for documents emitted
* the `on.(op, fn)` events.
*/
export interface PrettyOplogDoc {
criteria: any;
data: any;
namespace: string;
operation: string;
operationId: any;
targetId: any;
timestamp: Date;
ts: Timestamp;
}