<commit_before>// Type definitions for Mongoose 3.8.5
// Project: http://mongoosejs.com/
// Definitions by: horiuchi <https://github.com/horiuchi/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

///<reference types="node" />

declare module "mongoose" {
  function connect(uri: string, options?: ConnectionOptions , callback?: (err: any) => void): Mongoose;
  function createConnection(): Connection;
  function createConnection(uri: string, options?: ConnectionOptions): Connection;
  function createConnection(host: string, database_name: string, port?: number, options?: ConnectionOptions): Connection;
  function disconnect(callback?: (err?: any) => void): Mongoose;

  function model<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
  function modelNames(): string[];
  function plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose;

  function get(key: string): any;
  function set(key: string, value: any): void;

  var mongo: any;
  var mquery: any;
  var version: string;
  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<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
    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;
    Promise: any;
  }

  export interface Connection extends NodeJS.EventEmitter {
    constructor(base: Mongoose): Connection;

    close(callback?: (err: any) => void): Connection;
    collection(name: string, options?: Object): Collection;
    model<T extends Document>(name: string, schema?: Schema, collection?: string): Model<T>;
    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 {
    //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeOrderedBulkOp
    initializeOrderedBulkOp(options?: CollectionOptions): OrderedBulkOperation;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeUnorderedBulkOp
    initializeUnorderedBulkOp(options?: CollectionOptions): UnorderedBulkOperation;
  }

  export interface CollectionOptions {
    //The write concern.
    w?: number | string;
    //The write concern timeout.
    wtimeout?: number;
    //Specify a journal write concern.
    j?: boolean;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html
  export interface OrderedBulkOperation {
    length: number;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#execute
    execute(callback: MongoCallback<BulkWriteResult>): void;
    execute(options?: FSyncOptions): Promise<BulkWriteResult>;
    execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#find
    find(selector: Object): FindOperatorsOrdered;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#insert
    insert(doc: Object): OrderedBulkOperation;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html
  export interface UnorderedBulkOperation {
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#execute
    execute(callback: MongoCallback<BulkWriteResult>): void;
    execute(options?: FSyncOptions): Promise<BulkWriteResult>;
    execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#find
    find(selector: Object): FindOperatorsUnordered;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#insert
    insert(doc: Object): UnorderedBulkOperation;
  }

  export interface MongoCallback<T> {
    (error: MongoError, result: T): void;
  }

  // http://mongodb.github.io/node-mongodb-native/2.1/api/MongoError.html
  export class MongoError extends Error {
    constructor(message: string);
    static create(options: Object): MongoError;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/BulkWriteResult.html
  export interface BulkWriteResult {
    ok: number;
    nInserted: number;
    nUpdated: number;
    nUpserted: number;
    nModified: number;
    nRemoved: number;

    getInsertedIds(): Array<Object>;
    getLastOp(): Object;
    getRawResponse(): Object;
    getUpsertedIdAt(index: number): Object;
    getUpsertedIds(): Array<Object>;
    getWriteConcernError(): WriteConcernError;
    getWriteErrorAt(index: number): WriteError;
    getWriteErrorCount(): number;
    getWriteErrors(): Array<Object>;
    hasWriteErrors(): boolean;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteError.html
  export interface WriteError {
    //Write concern error code.
    code: number;
    //Write concern error original bulk operation index.
    index: number;
    //Write concern error message.
    errmsg: string;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteConcernError.html
  export interface WriteConcernError {
    //Write concern error code.
    code: number;
    //Write concern error message.
    errmsg: string;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#removeUser
  export interface FSyncOptions {
    w?: number | string;
    wtimeout?: number;
    j?: boolean;
    fsync?: boolean
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsOrdered.html
  export interface FindOperatorsOrdered {
    delete(): OrderedBulkOperation;
    deleteOne(): OrderedBulkOperation;
    replaceOne(doc: Object): OrderedBulkOperation;
    update(doc: Object): OrderedBulkOperation;
    updateOne(doc: Object): OrderedBulkOperation;
    upsert(): FindOperatorsOrdered;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsUnordered.html
  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;
	  static isValid(id?: string|number):boolean;
    }
  }

  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: (doc: Document, next?: HookNextFunction) => any ): 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;

  }

  // 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<T extends Document> extends NodeJS.EventEmitter {
    new(doc?: Object, fields?: Object, skipInit?: boolean): T;
<commit_msg>mongoose capped types fix<commit_after>// Type definitions for Mongoose 3.8.5
// Project: http://mongoosejs.com/
// Definitions by: horiuchi <https://github.com/horiuchi/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

///<reference types="node" />

declare module "mongoose" {
  function connect(uri: string, options?: ConnectionOptions , callback?: (err: any) => void): Mongoose;
  function createConnection(): Connection;
  function createConnection(uri: string, options?: ConnectionOptions): Connection;
  function createConnection(host: string, database_name: string, port?: number, options?: ConnectionOptions): Connection;
  function disconnect(callback?: (err?: any) => void): Mongoose;

  function model<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
  function modelNames(): string[];
  function plugin(plugin: (schema: Schema, options?: Object) => void, options?: Object): Mongoose;

  function get(key: string): any;
  function set(key: string, value: any): void;

  var mongo: any;
  var mquery: any;
  var version: string;
  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<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
    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;
    Promise: any;
  }

  export interface Connection extends NodeJS.EventEmitter {
    constructor(base: Mongoose): Connection;

    close(callback?: (err: any) => void): Connection;
    collection(name: string, options?: Object): Collection;
    model<T extends Document>(name: string, schema?: Schema, collection?: string): Model<T>;
    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 {
    //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeOrderedBulkOp
    initializeOrderedBulkOp(options?: CollectionOptions): OrderedBulkOperation;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/Collection.html#initializeUnorderedBulkOp
    initializeUnorderedBulkOp(options?: CollectionOptions): UnorderedBulkOperation;
  }

  export interface CollectionOptions {
    //The write concern.
    w?: number | string;
    //The write concern timeout.
    wtimeout?: number;
    //Specify a journal write concern.
    j?: boolean;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html
  export interface OrderedBulkOperation {
    length: number;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#execute
    execute(callback: MongoCallback<BulkWriteResult>): void;
    execute(options?: FSyncOptions): Promise<BulkWriteResult>;
    execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#find
    find(selector: Object): FindOperatorsOrdered;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/OrderedBulkOperation.html#insert
    insert(doc: Object): OrderedBulkOperation;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html
  export interface UnorderedBulkOperation {
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#execute
    execute(callback: MongoCallback<BulkWriteResult>): void;
    execute(options?: FSyncOptions): Promise<BulkWriteResult>;
    execute(options: FSyncOptions, callback: MongoCallback<BulkWriteResult>): void;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#find
    find(selector: Object): FindOperatorsUnordered;
    //http://mongodb.github.io/node-mongodb-native/2.1/api/UnorderedBulkOperation.html#insert
    insert(doc: Object): UnorderedBulkOperation;
  }

  export interface MongoCallback<T> {
    (error: MongoError, result: T): void;
  }

  // http://mongodb.github.io/node-mongodb-native/2.1/api/MongoError.html
  export class MongoError extends Error {
    constructor(message: string);
    static create(options: Object): MongoError;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/BulkWriteResult.html
  export interface BulkWriteResult {
    ok: number;
    nInserted: number;
    nUpdated: number;
    nUpserted: number;
    nModified: number;
    nRemoved: number;

    getInsertedIds(): Array<Object>;
    getLastOp(): Object;
    getRawResponse(): Object;
    getUpsertedIdAt(index: number): Object;
    getUpsertedIds(): Array<Object>;
    getWriteConcernError(): WriteConcernError;
    getWriteErrorAt(index: number): WriteError;
    getWriteErrorCount(): number;
    getWriteErrors(): Array<Object>;
    hasWriteErrors(): boolean;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteError.html
  export interface WriteError {
    //Write concern error code.
    code: number;
    //Write concern error original bulk operation index.
    index: number;
    //Write concern error message.
    errmsg: string;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/WriteConcernError.html
  export interface WriteConcernError {
    //Write concern error code.
    code: number;
    //Write concern error message.
    errmsg: string;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/Admin.html#removeUser
  export interface FSyncOptions {
    w?: number | string;
    wtimeout?: number;
    j?: boolean;
    fsync?: boolean
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsOrdered.html
  export interface FindOperatorsOrdered {
    delete(): OrderedBulkOperation;
    deleteOne(): OrderedBulkOperation;
    replaceOne(doc: Object): OrderedBulkOperation;
    update(doc: Object): OrderedBulkOperation;
    updateOne(doc: Object): OrderedBulkOperation;
    upsert(): FindOperatorsOrdered;
  }

  //http://mongodb.github.io/node-mongodb-native/2.1/api/FindOperatorsUnordered.html
  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;
	  static isValid(id?: string|number):boolean;
    }
  }

  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: (doc: Document, next?: HookNextFunction) => any ): 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;

  }

  // 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|number|Object;
    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<T extends Document> extends NodeJS.EventEmitter {
    new(doc?: Object, fields?: Object, skipInit?: boolean): T;

{'fraction_non_alphanumeric': 0.12811937226652945, 'fraction_numerical': 0.0039447731755424065, 'mean_word_length': 3.752037489812551, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 65, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4000927', 'n_tokens_mistral': 6948, 'n_tokens_neox': 6767, 'n_words': 1749}