Merge pull request #964 from nikeee/master

Update mongodb.d.ts
This commit is contained in:
Diullei Gomes
2013-08-28 17:16:15 -07:00
2 changed files with 150 additions and 71 deletions
+1
View File
@@ -148,6 +148,7 @@ List of Definitions
* [Meteor](https://www.meteor.com) (by [Dave Allen](https://github.com/fullflavedave))
* [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov) and [Theodore Brown](https://github.com/theodorejb/))
* [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield))
* [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee))
* [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz))
* [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov))
* [Node.js](http://nodejs.org/) (from TypeScript samples)
+149 -71
View File
@@ -5,19 +5,25 @@
/// <reference path='../node/node.d.ts' />
declare module "mongodb" {
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html
export class MongoClient{
constructor(serverConfig: any, options: any);
static connect(uri: string, options: any, callback: (err: any, db: Db) => void);
static connect(uri: string, callback: (err: any, db: Db) => void);
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html
export class MongoClient{
constructor(serverConfig: any, options: any);
static connect(uri: string, options: any, callback: (err: any, db: Db) => void);
static connect(uri: string, callback: (err: any, db: Db) => void);
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/server.html
export class Server {
constructor (host: string, port: number, opts?: ServerOptions);
public connect();
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/db.html
export class Db {
constructor (databaseName: string, serverConfig: Server, db_options?: DBOptions);
constructor (databaseName: string, serverConfig: Server, dbOptions?: DbCreateOptions);
public db(dbName: string): Db;
@@ -97,8 +103,27 @@ declare module "mongodb" {
public addListener(event: string, handler:(param: any) => any);
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-bson-generated/objectid.html
// Last update: doc. version 1.3.13 (28.08.2013)
export class ObjectID {
constructor (s: string);
// Returns the ObjectID id as a 24 byte hex string representation
public toHexString() : string;
// Compares the equality of this ObjectID with otherID.
public equals(otherID: ObjectID) : boolean;
// Returns the generation date (accurate up to the second) that this ID was generated.
public getTimestamp(): Date;
// Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID.
// time an integer number representing a number of seconds.
public static createFromTime(time: number): ObjectID;
// Creates an ObjectID from a hex string representation of an ObjectID.
// hexString create a ObjectID from a passed in 24 byte hexstring.
public static createFromHexString(hexString: string): ObjectID;
}
export interface SocketOptions {
@@ -126,82 +151,118 @@ declare module "mongodb" {
createPk: () => number;
}
export interface DBOptions {
//- if true, use native BSON parser
// See : http://mongodb.github.io/node-mongodb-native/api-generated/db.html
// Current definition by documentation version 1.3.13 (28.08.2013)
export interface DbCreateOptions {
// the write concern for the operation where < 1 is no acknowlegement of write and w >= 1, w = majority or tag acknowledges the write.
w?: string;
// set the timeout for waiting for write concern to finish (combines with w option).
wtimeout?: number;
// write waits for fsync before returning. default:false.
fsync?: boolean;
// write waits for journal sync before returning. default:false.
journal?: boolean;
// the prefered read preference. use 'ReadPreference' class.
readPreference?: string;
// use c++ bson parser. default:false.
native_parser?: boolean;
//- sets strict mode , if true then existing collections cant be “recreated” etc.
strict?: boolean;
//- custom primary key factory to generate _id values (see Custom primary keys).
pk?: PKFactory;
//- generation of objectid is delegated to the mongodb server instead of the driver. default is false
// force server to create _id fields instead of client. default:false.
forceServerObjectId?: boolean;
//- specify the number of milliseconds between connection attempts default:5000
retryMiliSeconds?: number;
//- specify the number of retries for connection attempts default:3
numberOfRetries?: number;
//- enable/disable reaper (true/false) default:false
reaper?: boolean;
//- specify the number of milliseconds between each reaper attempt default:10000
reaperInterval?: number;
//- specify the number of milliseconds for timing out callbacks that dont return default:30000
reaperTimeout?: number;
//- driver expects Buffer raw bson document, default:false
// custom primary key factory to generate _id values (see Custom primary keys).
pkFactory?: PKFactory;
// serialize functions. default:false.
serializeFunctions?: boolean;
// peform operations using raw bson buffers. default:false.
raw?: boolean;
// record query statistics during execution. default:false.
recordQueryStats?: boolean;
// number of miliseconds between retries. default:5000.
retryMiliSeconds?: number;
// number of retries off connection. default:5.
numberOfRetries?: number;
// an object representing a logger that you want to use, needs to support functions debug, log, error. default:null.
logger?: Object
// force setting of SlaveOk flag on queries (only use when explicitly connecting to a secondary server). default:null.
slaveOk?: number;
// when deserializing a Long will fit it into a Number if its smaller than 53 bits. default:true.
promoteLongs?: boolean;
}
export class ReadPreference {
public static PRIMARY: string;
public static PRIMARY_PREFERRED: string;
public static SECONDARY: string;
public static SECONDARY_PREFERRED: string;
public static NEAREST: string;
}
// See : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html
// Current definition by documentation version 1.3.13 (28.08.2013)
export interface CollectionCreateOptions {
// {true | {w:n, wtimeout:n} | {fsync:true}, default:false}, executes with a getLastError command returning the results of the command on MongoDB.
safe?: boolean;
// {Boolean, default:false}, serialize functions on the document.
// the prefered read preference. use 'ReadPreference' class.
readPreference?: string;
// Allow reads from secondaries. default:false.
slaveOk?: boolean;
// serialize functions on the document. default:false.
serializeFunctions?: boolean;
// {Boolean, default:false}, perform all operations using raw bson objects.
// perform all operations using raw bson objects. default:false.
raw?: boolean;
// object overriding the basic ObjectID primary key generation.
pkFactory?: PKFactory;
// {Boolean, default:false}, create a capped collection.
capped?: boolean;
// {Number}, the size of the capped collection in bytes.
size?: number;
// {Number}, the maximum number of documents in the capped collection.
max?: number;
// {Boolean, default:false}, create an index on the _id field of the document, not created automatically on capped collections.
autoIndexId?: boolean;
// {String}, the prefered read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
readPreference?: string;
}
// Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html
export interface Collection {
//constructor (db: Db, collectionName: string, pkFactory, options);
constructor (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions);
insert(query: any, callback: (err: any, result: any) => void): void;
insert(query: any, options: { safe?: any; continueOnError?: boolean; keepGoing?: boolean; serializeFunctions?: boolean; }, callback: (err: any, result: any) => void): void;
remove(selector, callback?: (err: any, result: any) => void);
remove(selector, options: { safe?: any; single?: boolean; }, callback?: (err: any, result: any) => void);
rename(newName: String, callback?: (err, result) => void);
save(doc: any, callback : (err, result) => void);
save(doc: any, options: { safe: any; }, callback : (err, result) => void);
update(selector: any, document: any, callback?: (err: any, result: any) => void): void;
update(selector: any, document: any, options: { safe?; upsert?; multi?; serializeFunctions?; }, callback: (err: any, result: any) => void): void;
distinct(key: string, query: Object, callback: (err, result) => void);
distinct(key: string, query: Object, options: { readPreferences; }, callback: (err, result) => void);
count(callback: (err, result) => void);
count(query: Object, callback: (err, result) => void);
count(query: Object, options: { readPreferences; }, callback: (err, result) => void);
drop(callback?: (err, result) => void);
findAndModify(query: Object, sort: any[], doc: Object, callback: (err, result) => void);
findAndModify(query: Object, sort: any[], doc: Object, options: { safe?: any; remove?: boolean; upsert?: boolean; new?: boolean; }, callback: (err, result) => void);
findAndRemove(query : Object, sort? : any[], callback?: (err, result) => void);
findAndRemove(query : Object, sort? : any[], options?: { safe; }, callback?: (err, result) => void);
find(callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, callback?: (err: any, result: Cursor) => void): Cursor;
@@ -209,7 +270,7 @@ declare module "mongodb" {
find(selector: any, fields: any, options: CollectionFindOptions, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, skip: number, limit: number, callback?: (err: any, result: Cursor) => void): Cursor;
find(selector: any, fields: any, skip: number, limit: number, timeout: number, callback?: (err: any, result: Cursor) => void): Cursor;
findOne(callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, callback?: (err: any, result: any) => void): Cursor;
@@ -217,14 +278,14 @@ declare module "mongodb" {
findOne(selector: any, fields: any, options: CollectionFindOptions, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, skip: number, limit: number, callback?: (err: any, result: any) => void): Cursor;
findOne(selector: any, fields: any, skip: number, limit: number, timeout: number, callback?: (err: any, result: any) => void): Cursor;
createIndex(fieldOrSpec, options: IndexOptions, callback: (err: Error, indexName: string) => void);
ensureIndex(fieldOrSpec, options: IndexOptions, callback: (err: Error, indexName: string) => void);
indexInformation(options, callback);
dropIndex(name, callback);
dropAllIndexes(callback);
// dropIndexes = dropAllIndexes
reIndex(callback);
mapReduce(map, reduce, options, callback);
group(keys, condition, initial, reduce, finalize, command, options, callback);
@@ -237,7 +298,7 @@ declare module "mongodb" {
aggregate(pipeline: any[], callback: (err: Error, results: any) => void);
aggregate(pipeline: any[], options, callback: (err: Error, results: any) => void);
stats(options, callback);
hint;
}
@@ -249,32 +310,49 @@ declare module "mongodb" {
v?: number;
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursor.html
// Last update: doc. version 1.3.13 (29.08.2013)
export class Cursor {
constructor (db, collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read, returnKey, maxScan, min, max, showDiskLoc, comment, awaitdata, numberOfRetries, dbName, tailableRetryInterval, exhaust, partial);
// INTERNAL TYPE
// constructor (db: Db, collection: Collection, selector, fields, skip, limit, sort, hint, explain, snapshot, timeout, tailable, batchSize, slaveOk, raw, read, returnKey, maxScan, min, max, showDiskLoc, comment, awaitdata, numberOfRetries, dbName, tailableRetryInterval, exhaust, partial);
// constructor(db: Db, collection: Collection, selector, fields, options);
rewind() : Cursor;
toArray(callback: (err: any, results: any[]) => any) : void;
each(callback: (err: Error, item: any) => void) : void;
count(callback: (err: any, count: number) => void) : void;
count(applySkipLimit: boolean, callback: (err: any, count: number) => void) : void;
sort(keyOrList : any, callback? : (err, result) => void): Cursor;
sort(keyOrList : String, direction : any, callback? : (err, result) => void): Cursor;
sort(keyOrList: any, callback? : (err, result) => void): Cursor;
// this determines how the results are sorted. "asc", "ascending" or 1 for asceding order while "desc", "desceding or -1 for descending order. Note that the strings are case insensitive.
sort(keyOrList: String, direction : string, callback : (err, result) => void): Cursor;
limit(limit: number, callback?: (err, result) => void): Cursor;
setReadPreference(readPreferences, tags, callback?): Cursor;
setReadPreference(preference: string, callback?): Cursor;
skip(skip: number, callback?: (err, result) => void): Cursor;
batchSize(batchSize, callback: (err, result) => void): Cursor;
batchSize(batchSize, callback?: (err, result) => void): Cursor;
nextObject(callback: (err:any, doc: any) => void);
explain(callback: (err, result) => void);
//stream(): CursorStream;
nextObject(callback: (err: any, doc: any) => void) : void;
explain(callback: (err, result) => void) : void;
close(callback?: (err, result) => void);
isClosed(): Boolean;
stream(): CursorStream;
static INIT;
static OPEN;
static CLOSED;
close(callback: (err, result) => void) : void;
isClosed(): boolean;
public static INIT: number;
public static OPEN: number;
public static CLOSED: number;
public static GET_MORE: number;
}
// Class documentation : http://mongodb.github.io/node-mongodb-native/api-generated/cursorstream.html
// Last update: doc. version 1.3.13 (29.08.2013)
export class CursorStream {
constructor(cursor: Cursor);
public pause();
public resume();
public destroy();
}
export interface CollectionFindOptions {
@@ -310,4 +388,4 @@ declare module "mongodb" {
pkFactory?: any;
readPreferences?: string;
}
}
}