Adding type assertions for collections as a whole (#36609)

* Adding type assertions for collections as a whole

* correct spaces and typescript version
This commit is contained in:
Jason Thorpe 2019-07-08 15:41:12 -07:00 committed by Armando Aguirre
parent eae899753b
commit 22c3c77865

25
types/nedb/index.d.ts vendored
View File

@ -4,6 +4,7 @@
// Anthony Nichols <https://github.com/anthonynichols>
// Alejandro Fernandez Haro <https://github.com/afharo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
@ -12,7 +13,7 @@ import { EventEmitter } from 'events';
export = Nedb;
export as namespace Nedb;
declare class Nedb extends EventEmitter {
declare class Nedb<G = any> extends EventEmitter {
constructor(pathOrOptions?: string | Nedb.DataStoreOptions);
persistence: Nedb.Persistence;
@ -49,20 +50,20 @@ declare class Nedb extends EventEmitter {
/**
* Add one or several document(s) to all indexes
*/
addToIndexes<T>(doc: T | T[]): void;
addToIndexes<T extends G>(doc: T | T[]): void;
/**
* Remove one or several document(s) from all indexes
*/
removeFromIndexes<T>(doc: T | T[]): void;
removeFromIndexes<T extends G>(doc: T | 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;
updateIndexes<T extends G>(oldDoc: T, newDoc: T): void;
updateIndexes<T extends G>(updates: Array<{ oldDoc: T; newDoc: T }>): void;
/**
* Return the list of candidates for a given query
@ -79,7 +80,7 @@ declare class Nedb extends EventEmitter {
* Insert a new document
* @param cb Optional callback, signature: err, insertedDoc
*/
insert<T>(newDoc: T, cb?: (err: Error, document: T) => void): void;
insert<T extends G>(newDoc: T, cb?: (err: Error, document: T) => void): void;
/**
* Count all documents matching the query
@ -94,28 +95,28 @@ declare class Nedb extends EventEmitter {
* @param query MongoDB-style query
* @param projection MongoDB-style projection
*/
find<T>(query: any, projection: T, callback: (err: Error, documents: T[]) => void): void;
find<T>(query: any, projection?: T): Nedb.Cursor<T>;
find<T extends G>(query: any, projection: T, callback: (err: Error, documents: T[]) => void): void;
find<T extends G>(query: any, projection?: T): Nedb.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, callback: (err: Error, documents: T[]) => void): void;
find<T extends G>(query: any, callback: (err: Error, documents: T[]) => void): void;
/**
* Find one document matching the query
* @param query MongoDB-style query
* @param projection MongoDB-style projection
*/
findOne<T>(query: any, projection: T, callback: (err: Error, document: T) => void): void;
findOne<T extends G>(query: any, projection: T, callback: (err: Error, document: T) => void): void;
/**
* Find one document matching the query
* @param query MongoDB-style query
*/
findOne<T>(query: any, callback: (err: Error, document: T) => void): void;
findOne<T extends G>(query: any, callback: (err: Error, document: T) => void): void;
/**
* Update all docs matching query v1.7.4 and prior signature.
@ -144,7 +145,7 @@ declare class Nedb extends EventEmitter {
*
* @api private Use Datastore.update which has the same signature
*/
update<T>(query: any, updateQuery: any, options?: Nedb.UpdateOptions, cb?: (err: Error, numberOfUpdated: number, affectedDocuments: any, upsert: boolean) => void): void;
update<T extends G>(query: any, updateQuery: any, options?: Nedb.UpdateOptions, cb?: (err: Error, numberOfUpdated: number, affectedDocuments: any, upsert: boolean) => void): void;
/**
* Remove all docs matching the query