<commit_before>// Type definitions for nedb-promise based on the definitions for nedb from DefinitelyTyped.
// Project: https://github.com/louischatriot/nedb
// Definitions by: <NAME> <https://github.com/reppners>
//                 <NAME>   <http://github.com/marcelbuesing>

export class NeDBDataStore {

  constructor();
  constructor(path:string);
  constructor(options: DataStoreOptions);

  persistence: Persistence;

  /**
   * Load the database from the datafile, and trigger the execution of buffered commands if any
   */
  loadDatabase():Promise<void>;

  /**
   * Get an array of all the data in the database
   */
  getAllData():Array<any>;


  /**
   * Reset all currently defined indexes
   */
  resetIndexes(newData:any):void;

  /**
   * Ensure an index is kept for this field. Same parameters as lib/indexes
   * For now this function is synchronous, we need to test how much time it takes
   * We use an async API for consistency with the rest of the code
   * @param {String} options.fieldName
   * @param {Boolean} options.unique
   * @param {Boolean} options.sparse
   * @param {Function} cb Optional callback, signature: err
   */
  ensureIndex(options:EnsureIndexOptions):Promise<void>;

  /**
   * Remove an index
   * @param {String} fieldName
   * @param {Function} cb Optional callback, signature: err
   */
  removeIndex(fieldName:string):Promise<void>;

  /**
   * Add one or several document(s) to all indexes
   */
  addToIndexes<T>(doc:T):void;
  addToIndexes<T>(doc:Array<T>):void;

  /**
   * Remove one or several document(s) from all indexes
   */
  removeFromIndexes<T>(doc:T):void;
  removeFromIndexes<T>(doc:Array<T>):void;

  /**
   * Update one or several documents in all indexes
   * To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs
   * If one update violates a constraint, all changes are rolled back
   */
  updateIndexes<T>(oldDoc:T, newDoc:T):void;
  updateIndexes<T>(updates:Array<{oldDoc:T; newDoc:T;}>):void;

  /**
   * Return the list of candidates for a given query
   * Crude implementation for now, we return the candidates given by the first usable index if any
   * We try the following query types, in this order: basic match, $in match, comparison match
   * One way to make it better would be to enable the use of multiple indexes if the first usable index
   * returns too much data. I may do it in the future.
   *
   * TODO: needs to be moved to the Cursor module
   */
  getCandidates(query:any):void;

  /**
   * Insert a new document
   * @param {Function} cb Optional callback, signature: err, insertedDoc
   */
  insert<T>(newDoc:T):Promise<T>;

  /**
   * Count all documents matching the query
   * @param {any} query MongoDB-style query
   */
  count(query:any):Promise<number>;
  count(query:any):CursorCount;

  /**
   * Find all documents matching the query
   * If no callback is passed, we return the cursor so that user can limit, skip and finally exec
   * @param {any} query MongoDB-style query
   * @param {any} projection MongoDB-style projection
   */
  find<T>(query:any, projection:T):Promise<Array<T>>;
  find<T>(query:any, projection:T):Cursor<T>;

  /**
   * Find all documents matching the query
   * If no callback is passed, we return the cursor so that user can limit, skip and finally exec
   * * @param {any} query MongoDB-style query
   */
  find<T>(query:any):Promise<Array<T>>;
  find<T>(query:any):Cursor<T>;

  /**
   * Find one document matching the query
   * @param {any} query MongoDB-style query
   * @param {any} projection MongoDB-style projection
   */
  findOne<T>(query:any, projection:T):Promise<T>;

  /**
   * Find one document matching the query
   * @param {any} query MongoDB-style query
   */
  findOne<T>(query:any):Promise<T>;

  /**
   * Update all docs matching query
   * For now, very naive implementation (recalculating the whole database)
   * @param {any} query
   * @param {any} updateQuery
   * @param {Object} options Optional options
   *                 options.multi If true, can update multiple documents (defaults to false)
   *                 options.upsert If true, document is inserted if the query doesn't match anything
   * @param {Function} cb Optional callback, signature: numReplaced, affected docs, upsert (set to true if the update was in fact an upsert)
   *
   * @api private Use Datastore.update which has the same signature
   */
  update(query:any, updateQuery:any, options?:UpdateOptions): Promise<[number, any, boolean]> | Promise<[number, any]> | Promise<number>;

  /**
   * Remove all docs matching the query
   * For now very naive implementation (similar to update)<commit_msg>Remove union type from return type of the update function<commit_after>// Type definitions for nedb-promise based on the definitions for nedb from DefinitelyTyped.
// Project: https://github.com/louischatriot/nedb
// Definitions by: <NAME> <https://github.com/reppners>
//                 <NAME>   <http://github.com/marcelbuesing>

export class NeDBDataStore {

  constructor();
  constructor(path:string);
  constructor(options: DataStoreOptions);

  persistence: Persistence;

  /**
   * Load the database from the datafile, and trigger the execution of buffered commands if any
   */
  loadDatabase():Promise<void>;

  /**
   * Get an array of all the data in the database
   */
  getAllData():Array<any>;


  /**
   * Reset all currently defined indexes
   */
  resetIndexes(newData:any):void;

  /**
   * Ensure an index is kept for this field. Same parameters as lib/indexes
   * For now this function is synchronous, we need to test how much time it takes
   * We use an async API for consistency with the rest of the code
   * @param {String} options.fieldName
   * @param {Boolean} options.unique
   * @param {Boolean} options.sparse
   * @param {Function} cb Optional callback, signature: err
   */
  ensureIndex(options:EnsureIndexOptions):Promise<void>;

  /**
   * Remove an index
   * @param {String} fieldName
   * @param {Function} cb Optional callback, signature: err
   */
  removeIndex(fieldName:string):Promise<void>;

  /**
   * Add one or several document(s) to all indexes
   */
  addToIndexes<T>(doc:T):void;
  addToIndexes<T>(doc:Array<T>):void;

  /**
   * Remove one or several document(s) from all indexes
   */
  removeFromIndexes<T>(doc:T):void;
  removeFromIndexes<T>(doc:Array<T>):void;

  /**
   * Update one or several documents in all indexes
   * To update multiple documents, oldDoc must be an array of { oldDoc, newDoc } pairs
   * If one update violates a constraint, all changes are rolled back
   */
  updateIndexes<T>(oldDoc:T, newDoc:T):void;
  updateIndexes<T>(updates:Array<{oldDoc:T; newDoc:T;}>):void;

  /**
   * Return the list of candidates for a given query
   * Crude implementation for now, we return the candidates given by the first usable index if any
   * We try the following query types, in this order: basic match, $in match, comparison match
   * One way to make it better would be to enable the use of multiple indexes if the first usable index
   * returns too much data. I may do it in the future.
   *
   * TODO: needs to be moved to the Cursor module
   */
  getCandidates(query:any):void;

  /**
   * Insert a new document
   * @param {Function} cb Optional callback, signature: err, insertedDoc
   */
  insert<T>(newDoc:T):Promise<T>;

  /**
   * Count all documents matching the query
   * @param {any} query MongoDB-style query
   */
  count(query:any):Promise<number>;
  count(query:any):CursorCount;

  /**
   * Find all documents matching the query
   * If no callback is passed, we return the cursor so that user can limit, skip and finally exec
   * @param {any} query MongoDB-style query
   * @param {any} projection MongoDB-style projection
   */
  find<T>(query:any, projection:T):Promise<Array<T>>;
  find<T>(query:any, projection:T):Cursor<T>;

  /**
   * Find all documents matching the query
   * If no callback is passed, we return the cursor so that user can limit, skip and finally exec
   * * @param {any} query MongoDB-style query
   */
  find<T>(query:any):Promise<Array<T>>;
  find<T>(query:any):Cursor<T>;

  /**
   * Find one document matching the query
   * @param {any} query MongoDB-style query
   * @param {any} projection MongoDB-style projection
   */
  findOne<T>(query:any, projection:T):Promise<T>;

  /**
   * Find one document matching the query
   * @param {any} query MongoDB-style query
   */
  findOne<T>(query:any):Promise<T>;

  /**
   * Update all docs matching query
   * For now, very naive implementation (recalculating the whole database)
   * @param {any} query
   * @param {any} updateQuery
   * @param {Object} options Optional options
   *                 options.multi If true, can update multiple documents (defaults to false)
   *                 options.upsert If true, document is inserted if the query doesn't match anything
   * @param {Function} cb Optional callback, signature: numReplaced, affected docs, upsert (set to true if the update was in fact an upsert)
   *
   * @api private Use Datastore.update which has the same signature
   */
  update(query:any, updateQuery:any, options?:UpdateOptions): Promise<any>;

  /**
   * Remove all docs matching the query
   * For now very naive implementation (similar to update)
{'fraction_non_alphanumeric': 0.10785576303927881, 'fraction_numerical': 0.0, 'mean_word_length': 3.5303840544482257, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, 'https://': 4, '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': '2909282', 'n_tokens_mistral': 2790, 'n_tokens_neox': 2694, 'n_words': 995}