From 0da5208e59b7d55aae3e564a4203e1b1a0578023 Mon Sep 17 00:00:00 2001 From: CaselIT Date: Sat, 19 Nov 2016 18:33:06 +0100 Subject: [PATCH] Added GridFS --- mongodb/index.d.ts | 119 +++++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 36 deletions(-) diff --git a/mongodb/index.d.ts b/mongodb/index.d.ts index 49f092a0f1..28a56d23b2 100644 --- a/mongodb/index.d.ts +++ b/mongodb/index.d.ts @@ -8,6 +8,7 @@ /// import {EventEmitter} from 'events'; +import { Readable, Writable } from "stream"; // Class documentation : http://mongodb.github.io/node-mongodb-native/2.1/api/MongoClient.html export class MongoClient { @@ -1112,26 +1113,11 @@ export interface WriteOpResult { result: any; } -//http://mongodb.github.io/node-mongodb-native/2.1/api/external-Readable.html -export interface Readable { - pause(): void; - pipe(destination: Writable, options?: Object): void; - read(size: number): string | Buffer | void; - resume(): void; - setEncoding(encoding: string): void; - unpipe(destination?: Writable): void; - unshift(stream: Buffer | string): void; - wrap(stream: Stream): void; -} - -export interface Writable { } -export interface Stream { } - //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#~resultCallback export type CursorResult = any | void | boolean; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html -export interface Cursor extends Readable, NodeJS.EventEmitter { +export interface Cursor extends Readable { sortValue: string; timeout: boolean; @@ -1184,16 +1170,12 @@ export interface Cursor extends Readable, NodeJS.EventEmitter { // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next next(): Promise; next(callback: MongoCallback): void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#pause - pause(): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#pipe pipe(destination: Writable, options?: Object): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#project project(value: Object): Cursor; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#read read(size: number): string | Buffer | void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#resume - resume(): void; // http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#next returnKey(returnKey: Object): Cursor; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#rewind @@ -1221,8 +1203,6 @@ export interface Cursor extends Readable, NodeJS.EventEmitter { unpipe(destination?: Writable): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#unshift unshift(stream: Buffer | string): void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#wrap - wrap(stream: Stream): void; } //http://mongodb.github.io/node-mongodb-native/2.1/api/Cursor.html#count @@ -1248,7 +1228,7 @@ export interface EndCallback { export type AggregationCursorResult = any | void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html -export interface AggregationCursor extends Readable, NodeJS.EventEmitter { +export interface AggregationCursor extends Readable { // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#batchSize batchSize(value: number): AggregationCursor; // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#clone @@ -1278,8 +1258,6 @@ export interface AggregationCursor extends Readable, NodeJS.EventEmitter { next(callback: MongoCallback): void; // http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#out out(destination: string): AggregationCursor; - //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#pause - pause(): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#pipe pipe(destination: Writable, options?: Object): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#project @@ -1288,8 +1266,6 @@ export interface AggregationCursor extends Readable, NodeJS.EventEmitter { read(size: number): string | Buffer | void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#redact redact(document: Object): AggregationCursor; - //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#resume - resume(): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#rewind rewind(): AggregationCursor; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#setEncoding @@ -1307,12 +1283,10 @@ export interface AggregationCursor extends Readable, NodeJS.EventEmitter { unshift(stream: Buffer | string): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#unwind unwind(field: string): AggregationCursor; - //http://mongodb.github.io/node-mongodb-native/2.1/api/AggregationCursor.html#wrap - wrap(stream: Stream): void; } //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html -export interface CommandCursor extends Readable, NodeJS.EventEmitter { +export interface CommandCursor extends Readable { // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#batchSize batchSize(value: number): CommandCursor; // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#clone @@ -1329,14 +1303,10 @@ export interface CommandCursor extends Readable, NodeJS.EventEmitter { // http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#next next(): Promise; next(callback: MongoCallback): void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#pause - pause(): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#pipe pipe(destination: Writable, options?: Object): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#read read(size: number): string | Buffer | void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#resume - resume(): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#rewind rewind(): CommandCursor; //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#setEncoding @@ -1350,6 +1320,83 @@ export interface CommandCursor extends Readable, NodeJS.EventEmitter { unpipe(destination?: Writable): void; //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#unshift unshift(stream: Buffer | string): void; - //http://mongodb.github.io/node-mongodb-native/2.1/api/CommandCursor.html#wrap - wrap(stream: Stream): void; +} + +// http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html +export class GridFSBucket { + constructor(db: Db, options?: GridFSBucketOptions); + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#delete + delete(id: ObjectID, callback?: GridFSBucketErrorCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#drop + drop(callback?: GridFSBucketErrorCallback): void; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#find + find(filter?: Object, options?: GridFSBucketFindOptions): Cursor; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openDownloadStream + openDownloadStream(id: ObjectID, options?: { start: number, end: number }): GridFSBucketReadStream; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openDownloadStreamByName + openDownloadStreamByName(filename: string, options?: { revision: number, start: number, end: number }): GridFSBucketReadStream; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStream + openUploadStream(filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStreamWithId + openUploadStreamWithId(id: string | number | Object, filename: string, options?: GridFSBucketOpenUploadStreamOptions): GridFSBucketWriteStream; + // http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#rename + rename(id: ObjectID, filename: string, callback?: GridFSBucketErrorCallback): void; +} + +// http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html +export interface GridFSBucketOptions { + bucketName?: string; + chunkSizeBytes?: number; + writeConcern?: Object; + ReadPreference?: Object; +} + +// http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#~errorCallback +export interface GridFSBucketErrorCallback { + (err?: MongoError): void; +} + +// http://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#find +export interface GridFSBucketFindOptions { + batchSize?: number; + limit?: number; + maxTimeMS?: number; + noCursorTimeout?: boolean; + skip?: number; + sort?: Object; +} + +// https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucket.html#openUploadStream +export interface GridFSBucketOpenUploadStreamOptions { + chunkSizeBytes?: number, + metadata?: Object, + contentType?: string, + aliases?: Array +} + +// https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketReadStream.html +export class GridFSBucketReadStream extends Readable { + constructor(chunks: Collection, files: Collection, readPreference: Object, filter: Object, options?: GridFSBucketReadStreamOptions); +} + +// https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketReadStream.html +export interface GridFSBucketReadStreamOptions { + sort?: number, + skip?: number, + start?: number, + end?: number +} + +// https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketWriteStream.html +export class GridFSBucketWriteStream extends Writable{ + constructor(bucket: GridFSBucket, filename:string, options?: GridFSBucketWriteStreamOptions); +} + +// https://mongodb.github.io/node-mongodb-native/2.1/api/GridFSBucketWriteStream.html +export interface GridFSBucketWriteStreamOptions { + id?: string | number | Object, + chunkSizeBytes?: number, + w?: number, + wtimeout?: number, + j?: number }