// Generated by typings // Source: https://raw.githubusercontent.com/typed-typings/npm-mpromise/a3585faef66f665f3af6ad4e773bbdd35b50a6a9/index.d.ts declare module '~mongoose~mpromise/index' { import {EventEmitter} from 'events'; /** * An mpromise can be in any of three states, pending, fulfilled (success), or rejected (error). Once it is either fulfilled or rejected it's state can no longer be changed. */ class Promise extends EventEmitter implements PromiseLike { /** * The constructor accepts an optional function which is executed when the promise is first resolved (either fulfilled or rejected). */ constructor(fn?: (err: any, arg: T, ...sink: any[]) => void); /** * Fulfilling a promise with values * If the promise has already been fulfilled or rejected, no action is taken. */ fulfill(arg?: T, ...sink: any[]): void; /** * Rejecting a promise with a reason. * If the promise has already been fulfilled or rejected, no action is taken. */ reject(reason: any): void; /** * Node.js callback style promise resolution (err, args...). * If the promise has already been fulfilled or rejected, no action is taken. */ resolve(reason?: any, arg?: T, ...sink: any[]): this; /** * To register a function for execution when the promise is fulfilled, pass it to onFulfill. When executed it will receive the arguments passed to fulfill(). * The function will only be called once when the promise is fulfilled, never when rejected. * * Registering a function with onFulfill after the promise has already been fulfilled results in the immediate execution of the function with the original arguments used to fulfill the promise. */ onFulfill(fn: (arg: T, ...sink: any[]) => void): this; /** * To register a function for execution when the promise is rejected, pass it to onReject. When executed it will receive the argument passed to reject(). * The function will only be called once when the promise is rejected, never when fulfilled. * * Registering a function with onReject after the promise has already been rejected results in the immediate execution of the function with the original argument used to reject the promise. */ onReject(fn: (reason: any) => void): this; /** * Allows registration of node.js style callbacks (err, args..) to handle either promise resolution type (fulfill or reject). */ onResolve(fn: (err: any, arg: T, ...sink: any[]) => void): this; /** * Creates a new promise and returns it. If onFulfill or onReject are passed, they are added as SUCCESS/ERROR callbacks to this promise after the nextTick. * * Conforms to promises/A+ specification and passes its tests. */ then(onFulfill?: (arg: T, ...sink: any[]) => void | PromiseLike, onReject?: (reason: any) => void | PromiseLike): Promise; then(onFulfill?: (arg: T, ...sink: any[]) => R | PromiseLike, onReject?: (reason: any) => R | PromiseLike): Promise; /** * Signifies that this promise was the last in a chain of then()s: if a handler passed to the call to then which produced this promise throws, the exception be rethrown. You can pass an OnReject handler to end so that exceptions will be handled (like a final catch clause); This method returns it's promise for easy use with return. */ end(fn?: (reason: any) => void): Promise; /** * Allows direct promise to promise chaining (especially useful by a outside aggregating function). It doesn't use the asynchronous resolve algorithm and so excepts only another Promise as it's argument. */ chain(promise: PromiseLike): Promise; // ====================== // Undocumented functions // ====================== all(fn: (arg: T, ...sink: any[]) => R[] | PromiseLike | PromiseLike>): Promise; on(event: string, callback: Function): this; static fulfilled(): Promise; static fulfilled(value: T, ...sink: any[]): Promise; static rejected(reason: any): Promise; static deferred(): Promise.Deferred; static deferred(): Promise.Deferred; static hook(array: any[]): Promise; } namespace Promise { const SUCCESS: 'complete'; const FAILURE: 'err'; interface Deferred { promise: Promise; callback: Function; reject(reason: any): void; resolve(reason?: any, arg?: T, ...sink: any[]): this; } } export = Promise; } // Generated by typings // Source: https://raw.githubusercontent.com/louy/typed-mongoose/d31d5e6880fb7291290563294237e092b6e09db2/index.d.ts declare module 'mongoose' { import * as Promise from '~mongoose~mpromise/index'; export {Promise}; export function connect(uri: string, options?: ConnectionOptions, callback?: (err: any) => void): Mongoose; export function createConnection(): Connection; export function createConnection(uri: string, options?: ConnectionOptions): Connection; export function createConnection(host: string, database_name: string, port?: number, options?: ConnectionOptions): Connection; export function disconnect(callback?: (err?: any) => void): Mongoose; export function model(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model; export function modelNames(): string[]; export function plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose; export function get(key: string): any; export function set(key: string, value: any): void; export var mongo: any; export var mquery: any; export var version: string; export var connection: Connection; export class Mongoose { connect(uri: string, options?: ConnectOpenOptionsBase, callback?: (err: any) => void): Mongoose; createConnection(): Connection; createConnection(uri: string, options?: Object): Connection; createConnection(host: string, database_name: string, port?: number, options?: ConnectOpenOptionsBase): Connection; disconnect(callback?: (err?: any) => void): Mongoose; get(key: string): any; model(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model; modelNames(): string[]; plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose; set(key: string, value: any): void; mongo: any; mquery: any; version: string; connection: Connection; } export interface Connection extends NodeJS.EventEmitter { constructor(base: Mongoose): Connection; close(callback?: (err: any) => void): Connection; collection(name: string, options?: Object): Collection; model(name: string, schema?: Schema, collection?: string): Model; modelNames(): string[]; open(host: string, database?: string, port?: number, options?: OpenSetConnectionOptions, callback?: (err: any) => void): Connection; openSet(uris: string, database?: string, options?: OpenSetConnectionOptions, callback?: (err: any) => void): Connection; db: any; collections: { [index: string]: Collection }; readyState: number; } export interface ConnectOpenOptionsBase { db?: any; server?: any; replset?: any; /** Username for authentication if not supplied in the URI. */ user?: string; /** Password for authentication if not supplied in the URI. */ pass?: string; /** Options for authentication */ auth?: any; } export interface ConnectionOptions extends ConnectOpenOptionsBase { /** Passed to the underlying driver's Mongos instance. */ mongos?: MongosOptions; } interface OpenSetConnectionOptions extends ConnectOpenOptionsBase { /** If true, enables High Availability support for mongos */ mongos?: boolean; } interface MongosOptions { /** Turn on high availability monitoring. (default: true) */ ha?: boolean; /** Time between each replicaset status check. (default: 5000) */ haInterval?: number; /** * Number of connections in the connection pool for each * server instance. (default: 5 (for legacy reasons)) */ poolSize?: number; /** * Use ssl connection (needs to have a mongod server with * ssl support). (default: false). */ ssl?: boolean; /** * Validate mongod server certificate against ca * (needs to have a mongod server with ssl support, 2.4 or higher) * (default: true) */ sslValidate?: boolean; /** Turn on high availability monitoring. */ sslCA?: (Buffer | string)[]; sslKey?: Buffer | string; sslPass?: Buffer | string; socketOptions?: { noDelay?: boolean; keepAlive?: number; connectionTimeoutMS?: number; socketTimeoutMS?: number; }; } export interface Collection { drop(callback?: (err: any) => void): Promise; initializeOrderedBulkOp(options?: BulkOpOptions): OrderedBulkOperation; initializeUnorderedBulkOp(options?: BulkOpOptions): UnorderedBulkOperation; } export interface BulkOpOptions { w?: number | string; wtimeout?: number; j?: boolean; } export interface OrderedBulkOperation { length: number; execute(callback: MongoCallback): void; execute(options?: FSyncOptions): Promise; execute(options: FSyncOptions, callback: MongoCallback): void; find(selector: Object): FindOperatorsOrdered; insert(doc: Object): OrderedBulkOperation; } export interface UnorderedBulkOperation { execute(callback: MongoCallback): void; execute(options?: FSyncOptions): Promise; execute(options: FSyncOptions, callback: MongoCallback): void; find(selector: Object): FindOperatorsUnordered; insert(doc: Object): UnorderedBulkOperation; } export interface MongoCallback { (error: MongoError, result: T): void; } export class MongoError extends Error { constructor(message: string); static create(options: Object): MongoError; } export interface BulkWriteResult { ok: number; nInserted: number; nUpdated: number; nUpserted: number; nModified: number; nRemoved: number; getInsertedIds(): Array; getLastOp(): Object; getRawResponse(): Object; getUpsertedIdAt(index: number): Object; getUpsertedIds(): Array; getWriteConcernError(): WriteConcernError; getWriteErrorAt(index: number): WriteError; getWriteErrorCount(): number; getWriteErrors(): Array; hasWriteErrors(): boolean; } export interface WriteError { code: number; index: number; errmsg: string; } export interface WriteConcernError { code: number; errmsg: string; } export interface FSyncOptions { w?: number | string; wtimeout?: number; j?: boolean; fsync?: boolean } export interface FindOperatorsOrdered { delete(): OrderedBulkOperation; deleteOne(): OrderedBulkOperation; replaceOne(doc: Object): OrderedBulkOperation; update(doc: Object): OrderedBulkOperation; updateOne(doc: Object): OrderedBulkOperation; upsert(): FindOperatorsOrdered; } export interface FindOperatorsUnordered { length: number; remove(): UnorderedBulkOperation; removeOne(): UnorderedBulkOperation; replaceOne(doc: Object): UnorderedBulkOperation; update(doc: Object): UnorderedBulkOperation; updateOne(doc: Object): UnorderedBulkOperation; upsert(): FindOperatorsUnordered; } export class SchemaType { } export class VirtualType { get(fn: Function): VirtualType; set(fn: Function): VirtualType; } export module Types { export class ObjectId { constructor(id?: string | number); toHexString(): string; equals(other: ObjectId): boolean; getTimestamp(): Date; isValid(): boolean; static createFromTime(time: number): ObjectId; static createFromHexString(hexString: string): ObjectId; } } export class Schema { static Types: { String: String; ObjectId: Types.ObjectId; OId: Types.ObjectId; Mixed: any; }; methods: any; statics: any; constructor(schema?: Object, options?: Object); add(obj: Object, prefix?: string): void; eachPath(fn: (path: string, type: any) => void): Schema; get(key: string): any; index(fields: Object, options?: Object): Schema; indexes(): void; method(name: string, fn: Function): Schema; method(method: Object): Schema; path(path: string): any; path(path: string, constructor: any): Schema; pathType(path: string): string; plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Schema; pre(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; pre(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; post(method: string, fn: HookSyncCallback, errorCb?: HookErrorCallback): Schema; post(method: string, isAsync: boolean, fn: HookAsyncCallback, errorCb?: HookErrorCallback): Schema; requiredPaths(): string[]; set(key: string, value: any): void; static(name: string, fn: Function): Schema; virtual(name: string, options?: Object): VirtualType; virtualpath(name: string): VirtualType; toJSON(): Object; } // hook functions: https://github.com/vkarpov15/hooks-fixed export interface HookSyncCallback { (next: HookNextFunction, ...hookArgs:any[]): any; } export interface HookAsyncCallback { (next: HookNextFunction, done: HookDoneFunction, ...hookArgs:any[]): any; } export interface HookErrorCallback { (error: Error): any; } export interface HookNextFunction { (error: Error): any; (...hookArgs:any[]): any; } export interface HookDoneFunction { (error: Error): any; (...hookArgs:any[]): any; } export interface SchemaOption { autoIndex?: boolean; bufferCommands?: boolean; capped?: boolean; collection?: string; id?: boolean; _id?: boolean; minimize?: boolean; read?: string; safe?: boolean; shardKey?: boolean; strict?: boolean; toJSON?: Object; toObject?: Object; versionKey?: boolean; } export interface Model extends NodeJS.EventEmitter { new (doc?: Object): T; aggregate(...aggregations: Object[]): Aggregate; aggregate(aggregation: Object, callback: (err: any, res: T[]) => void): Promise; aggregate(aggregation1: Object, aggregation2: Object, callback: (err: any, res: T[]) => void): Promise; aggregate(aggregation1: Object, aggregation2: Object, aggregation3: Object, callback: (err: any, res: T[]) => void): Promise; count(conditions: Object, callback?: (err: any, count: number) => void): Query; create(doc: Object, fn?: (err: any, res: T) => void): Promise; create(doc1: Object, doc2: Object, fn?: (err: any, res1: T, res2: T) => void): Promise; create(doc1: Object, doc2: Object, doc3: Object, fn?: (err: any, res1: T, res2: T, res3: T) => void): Promise; discriminator(name: string, schema: Schema): Model; distinct(field: string, callback?: (err: any, res: T[]) => void): Query; distinct(field: string, conditions: Object, callback?: (err: any, res: T[]) => void): Query; ensureIndexes(callback: (err: any) => void): Promise; find(cond: Object, callback?: (err: any, res: T[]) => void): Query; find(cond: Object, fields: Object, callback?: (err: any, res: T[]) => void): Query; find(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T[]) => void): Query; findById(id: string, callback?: (err: any, res: T) => void): Query; findById(id: string, fields: Object, callback?: (err: any, res: T) => void): Query; findById(id: string, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query; findByIdAndRemove(id: string, callback?: (err: any, res: T) => void): Query; findByIdAndRemove(id: string, options: Object, callback?: (err: any, res: T) => void): Query; findByIdAndUpdate(id: string, update: Object, callback?: (err: any, res: T) => void): Query; findByIdAndUpdate(id: string, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; findOne(cond?: Object, callback?: (err: any, res: T) => void): Query; findOne(cond: Object, fields: Object, callback?: (err: any, res: T) => void): Query; findOne(cond: Object, fields: Object, options: Object, callback?: (err: any, res: T) => void): Query; findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query; findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query; findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query; findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; geoNear(point: { type: string; coordinates: number[] }, options: Object, callback?: (err: any, res: T[]) => void): Query; geoNear(point: number[], options: Object, callback?: (err: any, res: T[]) => void): Query; geoSearch(cond: Object, options: GeoSearchOption, callback?: (err: any, res: T[]) => void): Query; increment(): T; mapReduce(options: MapReduceOption, callback?: (err: any, res: MapReduceResult[]) => void): Promise[]>; mapReduce(options: MapReduceOption2, callback?: (err: any, res: MapReduceResult[]) => void): Promise[]>; model(name: string): Model; populate(doc: U, options: Object, callback?: (err: any, res: U) => void): Promise; populate(doc: U[], options: Object, callback?: (err: any, res: U[]) => void): Promise; update(cond: Object, update: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query; update(cond: Object, update: Object, options: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query; remove(cond: Object, callback?: (err: any) => void): Query<{}>; save(callback?: (err: any, result: T, numberAffected: number) => void): Query; where(path: string, val?: Object): Query; $where(argument: string): Query; $where(argument: Function): Query; base: Mongoose; collection: Collection; db: any; discriminators: any; modelName: string; schema: Schema; } export interface FindAndUpdateOption { new?: boolean; upsert?: boolean; sort?: Object; select?: Object; } export interface GeoSearchOption { near: number[]; maxDistance: number; limit?: number; lean?: boolean; } export interface MapReduceOption { map: () => void; reduce: (key: Key, vals: T[]) => Val; query?: Object; limit?: number; keeptemp?: boolean; finalize?: (key: Key, val: Val) => Val; scope?: Object; jsMode?: boolean; verbose?: boolean; out?: { inline?: number; replace?: string; reduce?: string; merge?: string; }; } export interface MapReduceOption2 { map: string; reduce: (key: Key, vals: T[]) => Val; query?: Object; limit?: number; keeptemp?: boolean; finalize?: (key: Key, val: Val) => Val; scope?: Object; jsMode?: boolean; verbose?: boolean; out?: { inline?: number; replace?: string; reduce?: string; merge?: string; }; } export interface MapReduceResult { _id: Key; value: Val; } export class Query { exec(callback?: (err: any, res: T) => void): Promise; exec(operation: string, callback?: (err: any, res: T) => void): Promise; exec(operation: Function, callback?: (err: any, res: T) => void): Promise; all(val: number): Query; all(path: string, val: number): Query; and(array: Object[]): Query; box(val: Object): Query; box(a: number[], b: number[]): Query; batchSize(val: number): Query; cast(model: Model, obj: Object): U; //center(): Query; //centerSphere(path: string, val: Object): Query; circle(area: Object): Query; circle(path: string, area: Object): Query; comment(val: any): Query; count(callback?: (err: any, count: number) => void): Query; count(criteria: Object, callback?: (err: any, count: number) => void): Query; distinct(callback?: (err: any, res: T) => void): Query; distinct(field: string, callback?: (err: any, res: T) => void): Query; distinct(criteria: Object, field: string, callback?: (err: any, res: T) => void): Query; distinct(criteria: Query, field: string, callback?: (err: any, res: T) => void): Query; elemMatch(criteria: Object): Query; elemMatch(criteria: (elem: Query) => void): Query; elemMatch(path: string, criteria: Object): Query; elemMatch(path: string, criteria: (elem: Query) => void): Query; equals(val: Object): Query; exists(val?: boolean): Query; exists(path: string, val?: boolean): Query; find(callback?: (err: any, res: T) => void): Query; find(criteria: Object, callback?: (err: any, res: T) => void): Query; findOne(callback?: (err: any, res: T) => void): Query; findOne(criteria: Object, callback?: (err: any, res: T) => void): Query; findOneAndRemove(callback?: (err: any, res: T) => void): Query; findOneAndRemove(cond: Object, callback?: (err: any, res: T) => void): Query; findOneAndRemove(cond: Object, options: Object, callback?: (err: any, res: T) => void): Query; findOneAndUpdate(callback?: (err: any, res: T) => void): Query; findOneAndUpdate(update: Object, callback?: (err: any, res: T) => void): Query; findOneAndUpdate(cond: Object, update: Object, callback?: (err: any, res: T) => void): Query; findOneAndUpdate(cond: Object, update: Object, options: FindAndUpdateOption, callback?: (err: any, res: T) => void): Query; geometry(object: Object): Query; gt(val: number): Query; gt(path: string, val: number): Query; gte(val: number): Query; gte(path: string, val: number): Query; hint(val: Object): Query; in(val: any[]): Query; in(path: string, val: any[]): Query; intersects(arg?: Object): Query; lean(bool?: boolean): Query; limit(val: number): Query; lt(val: number): Query; lt(path: string, val: number): Query; lte(val: number): Query; lte(path: string, val: number): Query; maxDistance(val: number): Query; maxDistance(path: string, val: number): Query; maxScan(val: number): Query; merge(source: Query): Query; merge(source: Object): Query; mod(val: number[]): Query; mod(path: string, val: number[]): Query; ne(val: any): Query; ne(path: string, val: any): Query; near(val: Object): Query; near(path: string, val: Object): Query; nearSphere(val: Object): Query; nearSphere(path: string, val: Object): Query; nin(val: any[]): Query; nin(path: string, val: any[]): Query; nor(array: Object[]): Query; or(array: Object[]): Query; polygon(...coordinatePairs: number[][]): Query; polygon(path: string, ...coordinatePairs: number[][]): Query; populate(path: string, select?: string, match?: Object, options?: Object): Query; populate(path: string, select: string, model: string, match?: Object, options?: Object): Query; populate(opt: PopulateOption): Query; read(pref: string, tags?: Object[]): Query; regex(val: RegExp): Query; regex(path: string, val: RegExp): Query; remove(callback?: (err: any, res: T) => void): Query; remove(criteria: Object, callback?: (err: any, res: T) => void): Query; select(arg: string): Query; select(arg: Object): Query; select(arg: string): Query; select(arg: Object): Query; setOptions(options: Object): Query; size(val: number): Query; size(path: string, val: number): Query; skip(val: number): Query; slaveOk(v?: boolean): Query; slice(val: number): Query; slice(val: number[]): Query; slice(path: string, val: number): Query; slice(path: string, val: number[]): Query; snapshot(v?: boolean): Query; sort(arg: Object): Query; sort(arg: string): Query; stream(options?: { transform?: Function; }): QueryStream; tailable(v?: boolean): Query; toConstructor(): Query; update(callback?: (err: any, affectedRows: number, doc: T) => void): Query; update(doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; update(criteria: Object, doc: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; update(criteria: Object, doc: Object, options: Object, callback?: (err: any, affectedRows: number, doc: T) => void): Query; where(path?: string, val?: any): Query; where(path?: Object, val?: any): Query; within(val?: Object): Query; within(coordinate: number[], ...coordinatePairs: number[][]): Query; $where(argument: string): Query; $where(argument: Function): Query; static use$geoWithin: boolean; } export interface PopulateOption { path: string; select?: string; model?: string; match?: Object; options?: Object; } export interface QueryStream extends NodeJS.EventEmitter { destory(err?: any): void; pause(): void; resume(): void; pipe(destination: T, options?: { end?: boolean; }): T; paused: number; readable: boolean; } export interface Document { id?: string | number; _id: Types.ObjectId; equals(doc: Document): boolean; get(path: string, type?: new (...args: any[]) => any): any; inspect(options?: Object): string; invalidate(path: string, errorMsg: string, value: any): void; invalidate(path: string, error: Error, value: any): void; isDirectModified(path: string): boolean; isInit(path: string): boolean; isModified(path?: string): boolean; isSelected(path: string): boolean; markModified(path: string): void; modifiedPaths(): string[]; populate(callback?: (err: any, res: T) => void): Document; populate(path?: string, callback?: (err: any, res: T) => void): Document; populate(opt: PopulateOption, callback?: (err: any, res: T) => void): Document; populated(path: string): any; remove(callback?: (err: any) => void): Query; save(callback?: (err: any, res: T) => void): Promise; set(path: string, val: any, type?: new (...args: any[]) => any, options?: Object): void; set(path: string, val: any, options?: Object): void; set(value: Object): void; toJSON(options?: Object): Object; toObject(options?: Object): Object; toObject(options?: Object): T; toString(): string; update(doc: Object, options?: Object, callback?: (err: any, affectedRows: number, raw: any) => void): Query; validate(cb: (err: any) => void): void; isNew: boolean; errors: Object; schema: Object; } export class Aggregate { constructor(...options: Object[]); append(...options: Object[]): Aggregate; group(arg: Object): Aggregate; limit(num: number): Aggregate; match(arg: Object): Aggregate; near(parameters: Object): Aggregate; project(arg: string): Aggregate; project(arg: Object): Aggregate; select(filter: string): Aggregate; skip(num: number): Aggregate; sort(arg: string): Aggregate; sort(arg: Object): Aggregate; unwind(fiels: string, ...rest: string[]): Aggregate; exec(callback?: (err: any, result: T) => void): Promise; read(pref: string, ...tags: Object[]): Aggregate; } }