UNPKG

mongoose-transaction-plugin

Version:

A mongoose plugin for transaction-like semantics between multiple documents.

51 lines (50 loc) 1.73 kB
/// <reference types="node" /> import * as mongoose from 'mongoose'; import * as Bluebird from 'bluebird'; import * as events from 'events'; export interface IHistory { col: string; oid: any; shardKeyName: string; shardKey: any; op: 'insert' | 'remove' | 'update'; query: string; } export interface IRollback { col: string; oid: any; shardKeyName: string; shardKey: any; } export interface ITransaction extends mongoose.Document { history: IHistory[]; rollback: IRollback[]; state: string; id: string; } export declare class Transaction extends events.EventEmitter { static TRANSACTION_EXPIRE_THRESHOLD: number; private static model; private static connection; static readonly getModel: mongoose.Model<ITransaction>; private transaction; private participants; static initialize(connection: mongoose.Connection): void; begin(): Bluebird.Disposer<void | this>; static scope<R>(doInTransactionScope: (t: Transaction) => Bluebird<R> | Promise<R>): Bluebird<R> | Promise<R>; readonly _id: mongoose.Types.ObjectId; cancel(): Promise<void>; private static rollback; private static commitHistory; private static commitHistoryRemove; private static commitHistoryUpdate; static recommit(transaction: ITransaction): Promise<void>; private static validate; private static makeHistory; commit(): Promise<void>; insertDoc(doc: mongoose.Document, retry?: boolean): any; removeDoc(doc: mongoose.Document): void; findOne<T extends mongoose.Document>(model: mongoose.Model<T>, cond: Object, fields?: Object, options?: Object): Promise<T>; private setRollbackHistory; private static getShardKey; }