From 98c163185eaa7971d57bc52d076aee4004ea7841 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Mon, 5 May 2014 12:03:18 +0300 Subject: [PATCH 1/6] Added ServerRequest interface to express request interface - to support streaming functions. --- express/express.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/express/express.d.ts b/express/express.d.ts index 562dbf3013..eafc4c5966 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -240,7 +240,7 @@ declare module "express" { count: number; } - interface Request extends Express.Request { + interface Request extends http.ServerRequest, Express.Request { session: Session; From 8984db91f521bb6ed78d2cc1de12e8e920cb8098 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Mon, 5 May 2014 13:38:56 +0300 Subject: [PATCH 2/6] Added gridfs-stream --- gridfs-stream/gridfs-stream.d.ts | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 gridfs-stream/gridfs-stream.d.ts diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts new file mode 100644 index 0000000000..11bc3adb20 --- /dev/null +++ b/gridfs-stream/gridfs-stream.d.ts @@ -0,0 +1,66 @@ +// Type definitions for gridfs-stream 0.5.0 +// Project: https://github.com/aheckmann/gridfs-stream +// Definitions by: Lior Mualem + +/* =================== USAGE =================== + + import express = require('express'); + var app = express(); + + =============================================== */ + +/// +/// + +declare module GridFSStream { + export interface Range { + startPos: number; + endPos: number; + } + + export interface Options { + _id?: string; + filename?: string; + mode?: string; + + range?: Range; + + // any other options from the GridStore may be passed too, e.g. + chunkSize?: number; + content_type?: string; + root?: string; + metadata?: any; + } + + export interface WriteStream extends NodeJS.WritableStream { + } + + export interface ReadStream extends NodeJS.ReadableStream { + } +} + +declare module "gridfs-stream" { + import mongo = require('mongodb'); + + // Merged declaration, g is both a callable function and a namespace + function g(db: any, mongo: any): g.Grid; + + module g { + + export class Grid { + files: mongo.Collection; + collection: mongo.Collection; + + createWriteStream(options?: GridFSStream.Options) : GridFSStream.WriteStream; + createReadStream(options?: GridFSStream.Options) : GridFSStream.ReadStream; + createWriteStream(options?: string) : GridFSStream.WriteStream; + createReadStream(options?: string) : GridFSStream.ReadStream; + + remove(options: GridFSStream.Options, callback: (err: Error) => void); + exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void); + } + } + + export = g; +} + From 15d6ae5cb1b62152294bb3ff6064039591a641c1 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Mon, 5 May 2014 13:55:12 +0300 Subject: [PATCH 3/6] Added gridfs-stream tests. --- gridfs-stream/gridfs-stream-tests.ts | 37 ++++++++++++++++++++++++++++ gridfs-stream/gridfs-stream.d.ts | 12 ++++----- 2 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 gridfs-stream/gridfs-stream-tests.ts diff --git a/gridfs-stream/gridfs-stream-tests.ts b/gridfs-stream/gridfs-stream-tests.ts new file mode 100644 index 0000000000..c9ca457c2a --- /dev/null +++ b/gridfs-stream/gridfs-stream-tests.ts @@ -0,0 +1,37 @@ +/// +/// +/// + +// Samples from: +// https://github.com/aheckmann/gridfs-stream + +import fs = require('fs'); +import mongo = require('mongodb'); +import Grid = require('gridfs-stream'); + +// create or use an existing mongodb-native db instance +var db = new mongo.Db('gridfs-stream-test', new mongo.Server("127.0.0.1", 27017)); +var gfs = Grid(db, mongo); + +// streaming to gridfs +var writestream = gfs.createWriteStream({ + filename: 'my_file.txt' +}); +fs.createReadStream('blob.txt').pipe(writestream); + +// streaming from gridfs +var readstream = gfs.createReadStream({ + filename: 'my_file.txt' +}); + +//error handling, e.g. file does not exist +readstream.on('error', function (err: any) { + console.log('An error occurred!', err); + throw err; +}); + +var bufs: Array = []; +readstream.on('data', function(d: any){ bufs.push(d); }); +readstream.on('end', function() { + var buf = Buffer.concat(bufs); +}); diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts index 11bc3adb20..515f56a4c6 100644 --- a/gridfs-stream/gridfs-stream.d.ts +++ b/gridfs-stream/gridfs-stream.d.ts @@ -51,13 +51,13 @@ declare module "gridfs-stream" { files: mongo.Collection; collection: mongo.Collection; - createWriteStream(options?: GridFSStream.Options) : GridFSStream.WriteStream; - createReadStream(options?: GridFSStream.Options) : GridFSStream.ReadStream; - createWriteStream(options?: string) : GridFSStream.WriteStream; - createReadStream(options?: string) : GridFSStream.ReadStream; + createWriteStream(options?: GridFSStream.Options): GridFSStream.WriteStream; + createReadStream(options?: GridFSStream.Options): GridFSStream.ReadStream; + createWriteStream(options?: string): GridFSStream.WriteStream; + createReadStream(options?: string): GridFSStream.ReadStream; - remove(options: GridFSStream.Options, callback: (err: Error) => void); - exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void); + remove(options: GridFSStream.Options, callback: (err: Error) => void): void; + exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void): void; } } From 6d4beebae948d211a5f6c4cea4ffc53e85bde026 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Mon, 5 May 2014 14:57:59 +0300 Subject: [PATCH 4/6] Added missing parameters in the gridfs-stream stream objects. --- gridfs-stream/gridfs-stream.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts index 515f56a4c6..65b134a1d5 100644 --- a/gridfs-stream/gridfs-stream.d.ts +++ b/gridfs-stream/gridfs-stream.d.ts @@ -33,9 +33,16 @@ declare module GridFSStream { } export interface WriteStream extends NodeJS.WritableStream { + writable: boolean; + name: string; + id: string; + options: Options; + mode: string; } export interface ReadStream extends NodeJS.ReadableStream { + readable: boolean; + paused: boolean; } } From ca4444fdb9f8f990d0d3a40ce8dca992cc354c61 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Wed, 7 May 2014 10:52:29 +0300 Subject: [PATCH 5/6] Updated fixed "collection" function in gridfs-stream interface --- gridfs-stream/gridfs-stream.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts index 65b134a1d5..e5b55c66d9 100644 --- a/gridfs-stream/gridfs-stream.d.ts +++ b/gridfs-stream/gridfs-stream.d.ts @@ -55,8 +55,9 @@ declare module "gridfs-stream" { module g { export class Grid { + files: mongo.Collection; - collection: mongo.Collection; + collection(name?: string): mongo.Collection; createWriteStream(options?: GridFSStream.Options): GridFSStream.WriteStream; createReadStream(options?: GridFSStream.Options): GridFSStream.ReadStream; From bd37a32450fc31440cbee647297833c881e80279 Mon Sep 17 00:00:00 2001 From: Lior Mualem Date: Thu, 8 May 2014 16:27:10 +0300 Subject: [PATCH 6/6] Cleanup the gridfs-stream definitions file. --- CONTRIBUTORS.md | 1 + gridfs-stream/gridfs-stream.d.ts | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index bc62882748..fed4173177 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -88,6 +88,7 @@ All definitions files include a header with the author and editors, so at some p * [GoJS](http://gojs.net/) (by [Barbara Duckworth](https://github.com/barbara42)) * [Greasemonkey](http://www.greasespot.net/) (by [Kota Saito](https://github.com/kotas)) * [GreenSock Animation Platform (GSAP)](http://www.greensock.com/get-started-js/) (by [Robert S.](https://github.com/codeBelt)) +* [gridfs-stream](https://github.com/aheckmann/gridfs-stream) (by [Lior Mualem](https://github.com/liorm)) * [Grunt JS](http://gruntjs.com/) (by [Jeff May](https://github.com/jeffmay), [Basarat Ali Syed](https://github.com/basarat) and [San Chen](https://github.com/bigsan)) * [Google API Client](https://code.google.com/p/google-api-javascript-client/) (by [Frank M](https://github.com/sgtfrankieboy)) * [Google App Engine Channel API](https://developers.google.com/appengine/docs/java/channel/javascript) (by [vvakame](https://github.com/vvakame)) diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts index e5b55c66d9..a8ad5f9ed3 100644 --- a/gridfs-stream/gridfs-stream.d.ts +++ b/gridfs-stream/gridfs-stream.d.ts @@ -1,13 +1,7 @@ // Type definitions for gridfs-stream 0.5.0 // Project: https://github.com/aheckmann/gridfs-stream // Definitions by: Lior Mualem - -/* =================== USAGE =================== - - import express = require('express'); - var app = express(); - - =============================================== */ +// Definitions: https://github.com/borisyankov/DefinitelyTyped /// ///