├── .gitignore ├── .travis.yml ├── Gruntfile.js ├── LICENSE-MIT ├── README.md ├── app ├── app.d.ts ├── config.ts ├── controllers │ ├── index.ts │ └── users_controller.ts ├── main.ts ├── models │ └── user_model.ts └── server.ts ├── build └── .ignore ├── config ├── config.json ├── config_test.json └── coverage_blanket.js ├── package.json ├── test ├── controllers │ ├── index.spec.ts │ └── users_controller.spec.ts ├── models │ ├── mongoose_mock.ts │ ├── user_model.spec.ts │ └── user_model_mock.ts └── test.d.ts └── ts-definitions ├── asyncblock ├── asyncblock-tests.js ├── asyncblock-tests.js.map ├── asyncblock-tests.ts └── asyncblock.d.ts ├── express └── express.d.ts ├── mocha └── mocha.d.ts ├── node └── node.d.ts ├── should └── should.d.ts ├── sinon └── sinon-1.5.d.ts ├── superagent └── superagent.d.ts └── supertest └── supertest.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | .idea 3 | /build/ 4 | /app/**/*.js 5 | /app/**/*.js.map 6 | /test/**/*.js 7 | /test/**/*.js.map 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.10 4 | before_script: 5 | - npm install -g grunt-cli 6 | services: 7 | - mongodb 8 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function (grunt) { 4 | 5 | grunt.initConfig({ 6 | env: { 7 | test: { 8 | NODE_ENV: 'test' 9 | }, 10 | dev: { 11 | NODE_ENV: 'development' 12 | }, 13 | prod: { 14 | NODE_ENV: 'production' 15 | } 16 | }, 17 | 18 | typescript: { 19 | app: { 20 | src: ['app/**/*.ts'], 21 | options: { 22 | module: 'commonjs', 23 | sourcemap: true 24 | } 25 | }, 26 | 27 | test: { 28 | src: ['test/**/*.ts'], 29 | options: { 30 | module: 'commonjs', 31 | sourcemap: true 32 | } 33 | } 34 | }, 35 | 36 | mochaTest: { 37 | test: { 38 | options: { 39 | reporter: 'spec', 40 | require: 'config/coverage_blanket', 41 | quiet: false 42 | }, 43 | src: ['test/**/*.js'] 44 | }, 45 | coverage: { 46 | options: { 47 | reporter: 'html-cov', 48 | quiet: true, 49 | captureFile: 'build/coverage.html' 50 | }, 51 | src: ['test/**/*.js'] 52 | }, 53 | 'travis-cov': { 54 | options: { 55 | reporter: 'travis-cov' 56 | }, 57 | src: ['test/**/*.js'] 58 | } 59 | }, 60 | 61 | watch: { 62 | app: { 63 | files: ['app/**/*.ts'], 64 | tasks: ['typescript', '_runTests'] 65 | }, 66 | config: { 67 | files: ['config/**/*.js', 'config/**/*.json'], 68 | tasks: ['_runTests'] 69 | }, 70 | test: { 71 | files: ['test/**/*.ts'], 72 | tasks: ['typescript:test', '_runTests'] 73 | }, 74 | definitions: { 75 | files: ['ts-definitions/**/*.d.ts'], 76 | tasks: ['typescript', '_runTests'] 77 | } 78 | }, 79 | 80 | // monitors the compiled .js files so that external builders (e.g. WebStorm) trigger restart 81 | nodemon: { 82 | dev: { 83 | options: { 84 | file: 'app/main.js', 85 | watchedExtensions: ['js', 'json'], 86 | watchedFolders: ['app', 'config', 'test'] 87 | } 88 | } 89 | }, 90 | 91 | // execute 'grunt curl' manually to refresh the external definition files 92 | curl: { 93 | 'ts-definitions/express/express.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/express/express.d.ts', 94 | 'ts-definitions/mocha/mocha.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/mocha/mocha.d.ts', 95 | 'ts-definitions/node/node.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/node/node.d.ts', 96 | 'ts-definitions/should/should.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/should/should.d.ts', 97 | 'ts-definitions/sinon/sinon-1.5.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/sinon/sinon-1.5.d.ts', 98 | 'ts-definitions/superagent/superagent.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/superagent/superagent.d.ts', 99 | 'ts-definitions/supertest/supertest.d.ts': 'https://github.com/borisyankov/DefinitelyTyped/raw/master/supertest/supertest.d.ts' 100 | } 101 | }); 102 | 103 | // These plugins provide necessary tasks 104 | grunt.loadNpmTasks('grunt-env'); 105 | grunt.loadNpmTasks('grunt-typescript'); 106 | grunt.loadNpmTasks('grunt-mocha-test'); 107 | grunt.loadNpmTasks('grunt-contrib-watch'); 108 | grunt.loadNpmTasks('grunt-nodemon'); 109 | grunt.loadNpmTasks('grunt-curl'); 110 | 111 | // Task aliases 112 | grunt.registerTask('_runTests', ['env:test', 'mochaTest']); 113 | grunt.registerTask('test', ['typescript', '_runTests']); 114 | grunt.registerTask('dev', ['env:dev', 'nodemon']); 115 | grunt.registerTask('prod', ['env:prod', 'nodemon']); 116 | 117 | // Default task 118 | grunt.registerTask('default', ['test']); 119 | }; 120 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Alex Varju 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-express-mongoose-example [![Build Status](https://secure.travis-ci.org/varju/node-express-mongoose-example.png?branch=master)](http://travis-ci.org/varju/node-express-mongoose-example) 2 | 3 | Simple project to explore building a fully testable Node application. 4 | 5 | ## Demo endpoints 6 | 7 | List the available routes: 8 | ``` 9 | curl http://localhost:9650/ 10 | ``` 11 | 12 | Create a user: 13 | ``` 14 | curl -X POST http://localhost:9650/users -H "Content-Type: application/json" -d '{ "name": "my user" }' 15 | ``` 16 | 17 | Find a user: 18 | ``` 19 | curl http://localhost:9650/users/522e6095ae775c30b6000002 20 | ``` 21 | -------------------------------------------------------------------------------- /app/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /app/config.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | function extendDeep(target:Object, toCopy:Object) { 4 | for (var name in toCopy) { 5 | if (typeof toCopy[name] === 'object') { 6 | target[name] = extendDeep(target[name], toCopy[name]); 7 | } else { 8 | target[name] = toCopy[name]; 9 | } 10 | } 11 | return target; 12 | } 13 | 14 | /** 15 | * raw configuration properties, with local overrides 16 | */ 17 | export var props = require('../config/config.json'); 18 | try { 19 | var configOverrides = require('../config/config_overrides.json'); 20 | extendDeep(props, configOverrides); 21 | } catch (e) { 22 | // file probably doesn't exist 23 | } 24 | 25 | if ('test' === process.env.NODE_ENV) { 26 | var testOverrides = require('../config/config_test.json'); 27 | extendDeep(props, testOverrides); 28 | } 29 | -------------------------------------------------------------------------------- /app/controllers/index.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import fs = require('fs'); 4 | 5 | module.exports = (app:ExpressApplication) => { 6 | // load all the other controllers in this directory 7 | fs.readdirSync(__dirname). 8 | filter((file) => { 9 | return file !== "index.js" && (/.js$/).test(file); 10 | }). 11 | forEach((file) => { 12 | var name = file.substr(0, file.indexOf('.')); 13 | require('./' + name)(app); 14 | }); 15 | 16 | // define our root controller 17 | app.get('/', (req, res) => { 18 | var allRoutes = []; 19 | for (var method in app.routes) { 20 | var methodRoutes = app.routes[method]; 21 | for (var i = 0; i < methodRoutes.length; i++) { 22 | var route = methodRoutes[i]; 23 | allRoutes.push(method.toUpperCase() + " " + route.path); 24 | } 25 | } 26 | 27 | res.send({ routes: allRoutes }); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /app/controllers/users_controller.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var asyncblock = require('asyncblock'); 4 | 5 | import User = require('../../app/models/user_model'); 6 | 7 | module.exports = (app:ExpressApplication) => { 8 | 9 | app.post('/users', (req, res, next) => { 10 | asyncblock((flow) => { 11 | flow.errorCallback = next; 12 | 13 | var userTemplate = req.body; 14 | new User(userTemplate).validate().sync(); 15 | 16 | var user = User.create(userTemplate).sync(); 17 | res.send(201, { id: user.id }); 18 | }); 19 | }); 20 | 21 | app.get('/users/:id', (req, res, next) => { 22 | asyncblock((flow) => { 23 | flow.errorCallback = next; 24 | 25 | var id = req.param('id'); 26 | var user = User.findById(id).sync(); 27 | if (null === user) { 28 | res.send(404); 29 | } else { 30 | res.status(200).send({ 31 | id: user.id, 32 | name: user.name 33 | }); 34 | } 35 | }); 36 | }); 37 | 38 | }; 39 | -------------------------------------------------------------------------------- /app/main.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import http = require('http'); 4 | import server = require('./server'); 5 | 6 | http.createServer(server.app).listen(server.app.get('port'), () => { 7 | console.log('Express server listening on port ' + server.app.get('port')); 8 | }); 9 | -------------------------------------------------------------------------------- /app/models/user_model.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var mongoose = require('mongoose'); 4 | 5 | var userSchema = new mongoose.Schema({ 6 | name: { 7 | type: String, 8 | required: true 9 | } 10 | }); 11 | 12 | var User = mongoose.model('users', userSchema); 13 | export = User; 14 | -------------------------------------------------------------------------------- /app/server.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | // enable source transformation 4 | var asyncblock = require('asyncblock'); 5 | asyncblock.enableTransform(); 6 | 7 | // start our mongo connection 8 | import config = require('./config'); 9 | var mongoose = require('mongoose'); 10 | mongoose.connect(config.props.mongo.uri); 11 | 12 | // create our web server 13 | import express = require('express'); 14 | export var app = express(); 15 | app.set('port', config.props.server.port); 16 | app.use(express.bodyParser()); 17 | app.use(express.methodOverride()); 18 | 19 | // define our controllers 20 | app.use(app.router); 21 | require('./controllers')(app); 22 | 23 | // register a global error handler 24 | app.use((err, req, res, next) => { 25 | switch (err.name) { 26 | case 'ValidationError': 27 | // mongoose validation errors 28 | res.send(400, { error: err.toString() }); 29 | break; 30 | default: 31 | // unknown error type 32 | next(err); 33 | } 34 | }); 35 | 36 | // catch unhandled errors 37 | if ('development' === app.get('env')) { 38 | app.use(express.errorHandler()); 39 | } 40 | -------------------------------------------------------------------------------- /build/.ignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varju/typescript-node-mocha-example/5cecc4f081b5defce10446646695ea6b03ae5283/build/.ignore -------------------------------------------------------------------------------- /config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "server": { 3 | "port": 9650 4 | }, 5 | "mongo": { 6 | "uri": "mongodb://localhost/node-express-mongoose-example" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /config/config_test.json: -------------------------------------------------------------------------------- 1 | { 2 | "mongo": { 3 | "uri": "mongodb://localhost/node-express-mongoose-example-test" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /config/coverage_blanket.js: -------------------------------------------------------------------------------- 1 | require('blanket')({ 2 | // Only files that match the pattern will be instrumented 3 | pattern: '/app/' 4 | }); 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-express-mongoose-example", 3 | "version": "0.1.0", 4 | "homepage": "https://github.com/varju/node-express-mongoose-example", 5 | "author": { 6 | "name": "Alex Varju", 7 | "email": "alex@varju.ca" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/varju/node-express-mongoose-example.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/varju/node-express-mongoose-example/issues" 15 | }, 16 | "licenses": [ 17 | { 18 | "type": "MIT", 19 | "url": "https://github.com/varju/node-express-mongoose-example/blob/master/LICENSE-MIT" 20 | } 21 | ], 22 | "engines": { 23 | "node": ">= 0.10.0" 24 | }, 25 | "scripts": { 26 | "test": "grunt test", 27 | "travis-cov": { 28 | "threshold": 95 29 | } 30 | }, 31 | "dependencies": { 32 | "express": "~3.4.0", 33 | "mongoose": "~3.6.19", 34 | "asyncblock": "~2.1.14" 35 | }, 36 | "devDependencies": { 37 | "grunt": "~0.4.1", 38 | "grunt-typescript": "~0.2.4", 39 | "grunt-curl": "~1.1.1", 40 | "grunt-contrib-nodeunit": "~0.2.0", 41 | "grunt-contrib-watch": "~0.4.0", 42 | "grunt-mocha-test": "~0.6.3", 43 | "grunt-nodemon": "~0.1.1", 44 | "grunt-env": "~0.4.0", 45 | "mocha": "~1.12.1", 46 | "supertest": "~0.7.1", 47 | "should": "~1.2.2", 48 | "travis-cov": "~0.2.4", 49 | "blanket": "~1.1.5", 50 | "sinon": "~1.7.3" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/controllers/index.spec.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import should = require('should'); 4 | import request = require('supertest'); 5 | 6 | import server = require('../../app/server'); 7 | 8 | describe('root controller', () => { 9 | describe('GET /', () => { 10 | it('should list all the routes', (done) => { 11 | request(server.app). 12 | get('/'). 13 | end((err, res) => { 14 | should.ifError(err); 15 | res.should.have.status(200); 16 | res.should.be.json; 17 | res.body.should.have.property('routes'); 18 | var routes = res.body.routes; 19 | routes.should.include('GET /'); 20 | routes.should.include('GET /users/:id'); 21 | routes.should.include('POST /users'); 22 | done(); 23 | }); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/controllers/users_controller.spec.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import should = require('should'); 4 | import request = require('supertest'); 5 | 6 | import server = require('../../app/server'); 7 | import userModelMock = require('../models/user_model_mock'); 8 | 9 | describe('users controller', () => { 10 | var userMock = new userModelMock.UserMock(); 11 | userMock.register(); 12 | 13 | describe('POST /users', () => { 14 | it('should create a user', (done) => { 15 | userMock.allowValidate(); 16 | userMock.allowCreate({ id: 'mockId'}); 17 | 18 | request(server.app). 19 | post('/users'). 20 | send({ name: 'my user' }). 21 | end((err, res) => { 22 | should.ifError(err); 23 | res.should.have.status(201); 24 | res.should.be.json; 25 | res.body.id.should.eql('mockId'); 26 | done(); 27 | }); 28 | }); 29 | 30 | it('should fail if the name is missing', (done) => { 31 | userMock.failValidate(); 32 | 33 | request(server.app). 34 | post('/users'). 35 | send({}). 36 | end((err, res) => { 37 | should.ifError(err); 38 | res.should.have.status(400); 39 | res.should.be.json; 40 | res.body.should.eql({ error: 'ValidationError: Validator \"mockerr\" failed for path mockpath' }); 41 | done(); 42 | }); 43 | }); 44 | }); 45 | 46 | describe('GET /users/:id', () => { 47 | it('should load a user', (done) => { 48 | var user = {name: 'fred', id: '123'}; 49 | userMock.allowFindById(user); 50 | 51 | request(server.app). 52 | get('/users/' + user.id). 53 | end((err, res) => { 54 | should.ifError(err); 55 | res.should.have.status(200); 56 | res.should.be.json; 57 | res.body.should.eql(user); 58 | done(); 59 | }); 60 | }); 61 | 62 | it("should fail if the user doesn't exist", (done) => { 63 | userMock.allowFindById(null); 64 | 65 | request(server.app). 66 | get('/users/000000000000000000000000'). 67 | end((err, res) => { 68 | should.ifError(err); 69 | res.should.have.status(404); 70 | done(); 71 | }); 72 | }); 73 | 74 | it("should fail if mongo is down", (done) => { 75 | userMock.failFindById(); 76 | 77 | request(server.app). 78 | get('/users/000000000000000000000000'). 79 | end((err, res) => { 80 | should.ifError(err); 81 | res.should.have.status(500); 82 | done(); 83 | }); 84 | }); 85 | }); 86 | }); 87 | -------------------------------------------------------------------------------- /test/models/mongoose_mock.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | var sinon = require('sinon'); 4 | var mongoose = require('mongoose'); 5 | 6 | export class MongooseMock { 7 | modelToMock:any; 8 | 9 | constructor(modelToMock:any) { 10 | this.modelToMock = modelToMock; 11 | } 12 | 13 | sandbox:any; 14 | instanceMock:any; 15 | classMock:any; 16 | 17 | /** 18 | * replace the model with a mock implementation 19 | */ 20 | 21 | public register() { 22 | var _this = this; 23 | 24 | beforeEach(() => { 25 | _this.sandbox = sinon.sandbox.create(); 26 | 27 | _this.instanceMock = _this.sandbox.mock(_this.modelToMock.prototype); 28 | _this.classMock = _this.sandbox.mock(_this.modelToMock); 29 | }); 30 | 31 | afterEach(() => { 32 | _this.instanceMock.verify(); 33 | _this.classMock.verify(); 34 | 35 | _this.sandbox.restore(); 36 | }); 37 | } 38 | 39 | /* 40 | * instance mocks 41 | */ 42 | 43 | allowValidate() { 44 | this.instanceMock.expects('validate').once().callsArgAsync(0); 45 | } 46 | 47 | failValidate() { 48 | var error = new mongoose.Error.ValidationError({}); 49 | error.errors = { mock: new mongoose.Error.ValidatorError('mockpath', 'mockerr') }; 50 | this.instanceMock.expects('validate').once().callsArgWithAsync(0, error); 51 | } 52 | 53 | /* 54 | * class mocks 55 | */ 56 | 57 | allowCreate(result) { 58 | this.classMock.expects('create').once().callsArgWithAsync(1, null, result); 59 | } 60 | 61 | allowFindById(result) { 62 | this.classMock.expects('findById').once().callsArgWithAsync(1, null, result); 63 | } 64 | 65 | failFindById() { 66 | this.classMock.expects('findById').callsArgWithAsync(1, new Error('not found')); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /test/models/user_model.spec.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import should = require('should'); 4 | 5 | import User = require('../../app/models/user_model'); 6 | 7 | describe('user model', () => { 8 | beforeEach((done) => { 9 | // clear the database 10 | User.remove({}, done); 11 | }); 12 | 13 | describe('create', () => { 14 | it('should store a new user', (done) => { 15 | var user = new User({name: 'joe cool'}); 16 | user.save((err, persistedUser) => { 17 | should.ifError(err); 18 | persistedUser.name.should.eql('joe cool'); 19 | persistedUser.id.should.match(/^[0-9a-f]{24}$/); 20 | 21 | User.findById(persistedUser.id, (err, foundUser) => { 22 | foundUser.name.should.eql('joe cool'); 23 | foundUser.id.should.eql(persistedUser.id); 24 | done(); 25 | }); 26 | }); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /test/models/user_model_mock.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import mongooseMock = require('./mongoose_mock'); 4 | import User = require('../../app/models/user_model'); 5 | 6 | export class UserMock extends mongooseMock.MongooseMock { 7 | constructor() { 8 | super(User); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/test.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | -------------------------------------------------------------------------------- /ts-definitions/asyncblock/asyncblock-tests.js: -------------------------------------------------------------------------------- 1 | //# sourceMappingURL=asyncblock-tests.js.map 2 | -------------------------------------------------------------------------------- /ts-definitions/asyncblock/asyncblock-tests.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"asyncblock-tests.js","sourceRoot":"","sources":["asyncblock-tests.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /ts-definitions/asyncblock/asyncblock-tests.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varju/typescript-node-mocha-example/5cecc4f081b5defce10446646695ea6b03ae5283/ts-definitions/asyncblock/asyncblock-tests.ts -------------------------------------------------------------------------------- /ts-definitions/asyncblock/asyncblock.d.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/varju/typescript-node-mocha-example/5cecc4f081b5defce10446646695ea6b03ae5283/ts-definitions/asyncblock/asyncblock.d.ts -------------------------------------------------------------------------------- /ts-definitions/express/express.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Express 3.1 2 | // Project: http://expressjs.com 3 | // Definitions by: Boris Yankov 4 | // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /* =================== USAGE =================== 7 | 8 | import express = require('express'); 9 | var app = express(); 10 | 11 | =============================================== */ 12 | 13 | /// 14 | 15 | interface Route { 16 | path: string; 17 | 18 | method: string; 19 | 20 | callbacks: Function[]; 21 | 22 | regexp: any; 23 | 24 | /** 25 | * Check if this route matches `path`, if so 26 | * populate `.params`. 27 | */ 28 | match(path: string): boolean; 29 | } 30 | declare var Route: { 31 | /** 32 | * Initialize `Route` with the given HTTP `method`, `path`, 33 | * and an array of `callbacks` and `options`. 34 | * 35 | * Options: 36 | * 37 | * - `sensitive` enable case-sensitive routes 38 | * - `strict` enable strict matching for trailing slashes 39 | * 40 | * @param method 41 | * @param path 42 | * @param callbacks 43 | * @param options 44 | */ 45 | new (method: string, path: string, callbacks: Function[], options: any): Route; 46 | } 47 | 48 | interface Handler { 49 | (req: ExpressServerRequest, res: ExpressServerResponse, next?: Function): void; 50 | } 51 | 52 | interface CookieOptions { 53 | maxAge?: number; 54 | signed?: boolean; 55 | expires?: Date; 56 | httpOnly?: boolean; 57 | path?: string; 58 | domain?: string; 59 | secure?: boolean; 60 | } 61 | 62 | interface Errback { (err: Error): void; } 63 | 64 | 65 | interface ExpressSession { 66 | /** 67 | * Update reset `.cookie.maxAge` to prevent 68 | * the cookie from expiring when the 69 | * session is still active. 70 | * 71 | * @return {Session} for chaining 72 | * @api public 73 | */ 74 | touch(): ExpressSession; 75 | 76 | /** 77 | * Reset `.maxAge` to `.originalMaxAge`. 78 | */ 79 | resetMaxAge(): ExpressSession; 80 | 81 | /** 82 | * Save the session data with optional callback `fn(err)`. 83 | */ 84 | save(fn: Function): ExpressSession; 85 | 86 | /** 87 | * Re-loads the session data _without_ altering 88 | * the maxAge properties. Invokes the callback `fn(err)`, 89 | * after which time if no exception has occurred the 90 | * `req.session` property will be a new `Session` object, 91 | * although representing the same session. 92 | */ 93 | reload(fn: Function): ExpressSession; 94 | 95 | /** 96 | * Destroy `this` session. 97 | */ 98 | destroy(fn: Function): ExpressSession; 99 | 100 | /** 101 | * Regenerate this request's session. 102 | */ 103 | regenerate(fn: Function): ExpressSession; 104 | 105 | user: any; 106 | 107 | error: string; 108 | 109 | success: string; 110 | 111 | views: any; 112 | } 113 | declare var ExpressSession: { 114 | /** 115 | * Create a new `Session` with the given request and `data`. 116 | */ 117 | new (req: ExpressServerRequest, data: any): ExpressSession; 118 | } 119 | 120 | interface ExpressServerRequest { 121 | 122 | session: ExpressSession; 123 | 124 | /** 125 | * Return request header. 126 | * 127 | * The `Referrer` header field is special-cased, 128 | * both `Referrer` and `Referer` are interchangeable. 129 | * 130 | * Examples: 131 | * 132 | * req.get('Content-Type'); 133 | * // => "text/plain" 134 | * 135 | * req.get('content-type'); 136 | * // => "text/plain" 137 | * 138 | * req.get('Something'); 139 | * // => undefined 140 | * 141 | * Aliased as `req.header()`. 142 | * 143 | * @param name 144 | */ 145 | get (name: string): string; 146 | 147 | header(name: string): string; 148 | 149 | /** 150 | * Check if the given `type(s)` is acceptable, returning 151 | * the best match when true, otherwise `undefined`, in which 152 | * case you should respond with 406 "Not Acceptable". 153 | * 154 | * The `type` value may be a single mime type string 155 | * such as "application/json", the extension name 156 | * such as "json", a comma-delimted list such as "json, html, text/plain", 157 | * or an array `["json", "html", "text/plain"]`. When a list 158 | * or array is given the _best_ match, if any is returned. 159 | * 160 | * Examples: 161 | * 162 | * // Accept: text/html 163 | * req.accepts('html'); 164 | * // => "html" 165 | * 166 | * // Accept: text/*, application/json 167 | * req.accepts('html'); 168 | * // => "html" 169 | * req.accepts('text/html'); 170 | * // => "text/html" 171 | * req.accepts('json, text'); 172 | * // => "json" 173 | * req.accepts('application/json'); 174 | * // => "application/json" 175 | * 176 | * // Accept: text/*, application/json 177 | * req.accepts('image/png'); 178 | * req.accepts('png'); 179 | * // => undefined 180 | * 181 | * // Accept: text/*;q=.5, application/json 182 | * req.accepts(['html', 'json']); 183 | * req.accepts('html, json'); 184 | * // => "json" 185 | */ 186 | accepts(type: string): string; 187 | 188 | accepts(type: string[]): string; 189 | 190 | /** 191 | * Check if the given `charset` is acceptable, 192 | * otherwise you should respond with 406 "Not Acceptable". 193 | * 194 | * @param charset 195 | */ 196 | acceptsCharset(charset: string): boolean; 197 | 198 | /** 199 | * Check if the given `lang` is acceptable, 200 | * otherwise you should respond with 406 "Not Acceptable". 201 | * 202 | * @param lang 203 | */ 204 | acceptsLanguage(lang: string): boolean; 205 | 206 | /** 207 | * Parse Range header field, 208 | * capping to the given `size`. 209 | * 210 | * Unspecified ranges such as "0-" require 211 | * knowledge of your resource length. In 212 | * the case of a byte range this is of course 213 | * the total number of bytes. If the Range 214 | * header field is not given `null` is returned, 215 | * `-1` when unsatisfiable, `-2` when syntactically invalid. 216 | * 217 | * NOTE: remember that ranges are inclusive, so 218 | * for example "Range: users=0-3" should respond 219 | * with 4 users when available, not 3. 220 | * 221 | * @param size 222 | */ 223 | range(size: number): Array; 224 | 225 | /** 226 | * Return an array of Accepted media types 227 | * ordered from highest quality to lowest. 228 | * 229 | * Examples: 230 | * 231 | * [ { value: 'application/json', 232 | * quality: 1, 233 | * type: 'application', 234 | * subtype: 'json' }, 235 | * { value: 'text/html', 236 | * quality: 0.5, 237 | * type: 'text', 238 | * subtype: 'html' } ] 239 | */ 240 | accepted: Array; 241 | 242 | /** 243 | * Return an array of Accepted languages 244 | * ordered from highest quality to lowest. 245 | * 246 | * Examples: 247 | * 248 | * Accept-Language: en;q=.5, en-us 249 | * ['en-us', 'en'] 250 | */ 251 | acceptedLanguages: Array; 252 | 253 | /** 254 | * Return an array of Accepted charsets 255 | * ordered from highest quality to lowest. 256 | * 257 | * Examples: 258 | * 259 | * Accept-Charset: iso-8859-5;q=.2, unicode-1-1;q=0.8 260 | * ['unicode-1-1', 'iso-8859-5'] 261 | */ 262 | acceptedCharsets: Array; 263 | 264 | /** 265 | * Return the value of param `name` when present or `defaultValue`. 266 | * 267 | * - Checks route placeholders, ex: _/user/:id_ 268 | * - Checks body params, ex: id=12, {"id":12} 269 | * - Checks query string params, ex: ?id=12 270 | * 271 | * To utilize request bodies, `req.body` 272 | * should be an object. This can be done by using 273 | * the `connect.bodyParser()` middleware. 274 | * 275 | * @param name 276 | * @param defaultValue 277 | */ 278 | param(name: string, defaultValue?: any): string; 279 | 280 | /** 281 | * Check if the incoming request contains the "Content-Type" 282 | * header field, and it contains the give mime `type`. 283 | * 284 | * Examples: 285 | * 286 | * // With Content-Type: text/html; charset=utf-8 287 | * req.is('html'); 288 | * req.is('text/html'); 289 | * req.is('text/*'); 290 | * // => true 291 | * 292 | * // When Content-Type is application/json 293 | * req.is('json'); 294 | * req.is('application/json'); 295 | * req.is('application/*'); 296 | * // => true 297 | * 298 | * req.is('html'); 299 | * // => false 300 | * 301 | * @param type 302 | */ 303 | is(type: string): boolean; 304 | 305 | /** 306 | * Return the protocol string "http" or "https" 307 | * when requested with TLS. When the "trust proxy" 308 | * setting is enabled the "X-Forwarded-Proto" header 309 | * field will be trusted. If you're running behind 310 | * a reverse proxy that supplies https for you this 311 | * may be enabled. 312 | */ 313 | protocol: string; 314 | 315 | /** 316 | * Short-hand for: 317 | * 318 | * req.protocol == 'https' 319 | */ 320 | secure: boolean; 321 | 322 | /** 323 | * Return the remote address, or when 324 | * "trust proxy" is `true` return 325 | * the upstream addr. 326 | */ 327 | ip: string; 328 | 329 | /** 330 | * When "trust proxy" is `true`, parse 331 | * the "X-Forwarded-For" ip address list. 332 | * 333 | * For example if the value were "client, proxy1, proxy2" 334 | * you would receive the array `["client", "proxy1", "proxy2"]` 335 | * where "proxy2" is the furthest down-stream. 336 | */ 337 | ips: string[]; 338 | 339 | /** 340 | * Return basic auth credentials. 341 | * 342 | * Examples: 343 | * 344 | * // http://tobi:hello@example.com 345 | * req.auth 346 | * // => { username: 'tobi', password: 'hello' } 347 | */ 348 | auth: any; 349 | 350 | /** 351 | * Return subdomains as an array. 352 | * 353 | * Subdomains are the dot-separated parts of the host before the main domain of 354 | * the app. By default, the domain of the app is assumed to be the last two 355 | * parts of the host. This can be changed by setting "subdomain offset". 356 | * 357 | * For example, if the domain is "tobi.ferrets.example.com": 358 | * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`. 359 | * If "subdomain offset" is 3, req.subdomains is `["tobi"]`. 360 | */ 361 | subdomains: string[]; 362 | 363 | /** 364 | * Short-hand for `url.parse(req.url).pathname`. 365 | */ 366 | path: string; 367 | 368 | /** 369 | * Parse the "Host" header field hostname. 370 | */ 371 | host: string; 372 | 373 | /** 374 | * Check if the request is fresh, aka 375 | * Last-Modified and/or the ETag 376 | * still match. 377 | */ 378 | fresh: boolean; 379 | 380 | /** 381 | * Check if the request is stale, aka 382 | * "Last-Modified" and / or the "ETag" for the 383 | * resource has changed. 384 | */ 385 | stale: boolean; 386 | 387 | /** 388 | * Check if the request was an _XMLHttpRequest_. 389 | */ 390 | xhr: boolean; 391 | 392 | //body: { username: string; password: string; remember: boolean; title: string; }; 393 | body: any; 394 | 395 | //cookies: { string; remember: boolean; }; 396 | cookies: any; 397 | 398 | method: string; 399 | 400 | params: any; 401 | 402 | user: any; 403 | 404 | files: any; 405 | 406 | /** 407 | * Clear cookie `name`. 408 | * 409 | * @param name 410 | * @param options 411 | */ 412 | clearCookie(name: string, options?: any): ExpressServerResponse; 413 | 414 | query: any; 415 | 416 | route: any; 417 | 418 | signedCookies: any; 419 | 420 | originalUrl: string; 421 | } 422 | 423 | interface ExpressServerResponse { 424 | /** 425 | * Set status `code`. 426 | * 427 | * @param code 428 | */ 429 | status(code: number): ExpressServerResponse; 430 | 431 | /** 432 | * Set Link header field with the given `links`. 433 | * 434 | * Examples: 435 | * 436 | * res.links({ 437 | * next: 'http://api.example.com/users?page=2', 438 | * last: 'http://api.example.com/users?page=5' 439 | * }); 440 | * 441 | * @param links 442 | */ 443 | links(links: any): ExpressServerResponse; 444 | 445 | /** 446 | * Send a response. 447 | * 448 | * Examples: 449 | * 450 | * res.send(new Buffer('wahoo')); 451 | * res.send({ some: 'json' }); 452 | * res.send('

some html

'); 453 | * res.send(404, 'Sorry, cant find that'); 454 | * res.send(404); 455 | */ 456 | send(status: number): ExpressServerResponse; 457 | 458 | send(bodyOrStatus: any): ExpressServerResponse; 459 | 460 | send(status: number, body: any): ExpressServerResponse; 461 | 462 | 463 | /** 464 | * Send JSON response. 465 | * 466 | * Examples: 467 | * 468 | * res.json(null); 469 | * res.json({ user: 'tj' }); 470 | * res.json(500, 'oh noes!'); 471 | * res.json(404, 'I dont have that'); 472 | */ 473 | json(status: number): ExpressServerResponse; 474 | 475 | json(bodyOrStatus: any): ExpressServerResponse; 476 | 477 | json(status: number, body: any): ExpressServerResponse; 478 | 479 | /** 480 | * Send JSON response with JSONP callback support. 481 | * 482 | * Examples: 483 | * 484 | * res.jsonp(null); 485 | * res.jsonp({ user: 'tj' }); 486 | * res.jsonp(500, 'oh noes!'); 487 | * res.jsonp(404, 'I dont have that'); 488 | */ 489 | jsonp(status: number): ExpressServerResponse; 490 | 491 | jsonp(bodyOrStatus: any): ExpressServerResponse; 492 | 493 | jsonp(status: number, body: any): ExpressServerResponse; 494 | 495 | /** 496 | * Transfer the file at the given `path`. 497 | * 498 | * Automatically sets the _Content-Type_ response header field. 499 | * The callback `fn(err)` is invoked when the transfer is complete 500 | * or when an error occurs. Be sure to check `res.sentHeader` 501 | * if you wish to attempt responding, as the header and some data 502 | * may have already been transferred. 503 | * 504 | * Options: 505 | * 506 | * - `maxAge` defaulting to 0 507 | * - `root` root directory for relative filenames 508 | * 509 | * Examples: 510 | * 511 | * The following example illustrates how `res.sendfile()` may 512 | * be used as an alternative for the `static()` middleware for 513 | * dynamic situations. The code backing `res.sendfile()` is actually 514 | * the same code, so HTTP cache support etc is identical. 515 | * 516 | * app.get('/user/:uid/photos/:file', function(req, res){ 517 | * var uid = req.params.uid 518 | * , file = req.params.file; 519 | * 520 | * req.user.mayViewFilesFrom(uid, function(yes){ 521 | * if (yes) { 522 | * res.sendfile('/uploads/' + uid + '/' + file); 523 | * } else { 524 | * res.send(403, 'Sorry! you cant see that.'); 525 | * } 526 | * }); 527 | * }); 528 | */ 529 | sendfile(path: string): void; 530 | 531 | sendfile(path: string, options: any): void; 532 | 533 | sendfile(path: string, fn: Errback): void; 534 | 535 | sendfile(path: string, options: any, fn: Errback): void; 536 | 537 | /** 538 | * Transfer the file at the given `path` as an attachment. 539 | * 540 | * Optionally providing an alternate attachment `filename`, 541 | * and optional callback `fn(err)`. The callback is invoked 542 | * when the data transfer is complete, or when an error has 543 | * ocurred. Be sure to check `res.headerSent` if you plan to respond. 544 | * 545 | * This method uses `res.sendfile()`. 546 | */ 547 | download(path: string): void; 548 | 549 | download(path: string, filename: string): void; 550 | 551 | download(path: string, fn: Errback): void; 552 | 553 | download(path: string, filename: string, fn: Errback): void; 554 | 555 | /** 556 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 557 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 558 | * 559 | * Examples: 560 | * 561 | * res.type('.html'); 562 | * res.type('html'); 563 | * res.type('json'); 564 | * res.type('application/json'); 565 | * res.type('png'); 566 | * 567 | * @param type 568 | */ 569 | contentType(type: string): ExpressServerResponse; 570 | 571 | /** 572 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 573 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 574 | * 575 | * Examples: 576 | * 577 | * res.type('.html'); 578 | * res.type('html'); 579 | * res.type('json'); 580 | * res.type('application/json'); 581 | * res.type('png'); 582 | * 583 | * @param type 584 | */ 585 | type(type: string): ExpressServerResponse; 586 | 587 | /** 588 | * Respond to the Acceptable formats using an `obj` 589 | * of mime-type callbacks. 590 | * 591 | * This method uses `req.accepted`, an array of 592 | * acceptable types ordered by their quality values. 593 | * When "Accept" is not present the _first_ callback 594 | * is invoked, otherwise the first match is used. When 595 | * no match is performed the server responds with 596 | * 406 "Not Acceptable". 597 | * 598 | * Content-Type is set for you, however if you choose 599 | * you may alter this within the callback using `res.type()` 600 | * or `res.set('Content-Type', ...)`. 601 | * 602 | * res.format({ 603 | * 'text/plain': function(){ 604 | * res.send('hey'); 605 | * }, 606 | * 607 | * 'text/html': function(){ 608 | * res.send('

hey

'); 609 | * }, 610 | * 611 | * 'appliation/json': function(){ 612 | * res.send({ message: 'hey' }); 613 | * } 614 | * }); 615 | * 616 | * In addition to canonicalized MIME types you may 617 | * also use extnames mapped to these types: 618 | * 619 | * res.format({ 620 | * text: function(){ 621 | * res.send('hey'); 622 | * }, 623 | * 624 | * html: function(){ 625 | * res.send('

hey

'); 626 | * }, 627 | * 628 | * json: function(){ 629 | * res.send({ message: 'hey' }); 630 | * } 631 | * }); 632 | * 633 | * By default Express passes an `Error` 634 | * with a `.status` of 406 to `next(err)` 635 | * if a match is not made. If you provide 636 | * a `.default` callback it will be invoked 637 | * instead. 638 | * 639 | * @param obj 640 | */ 641 | format(obj: any): ExpressServerResponse; 642 | 643 | /** 644 | * Set _Content-Disposition_ header to _attachment_ with optional `filename`. 645 | * 646 | * @param filename 647 | */ 648 | attachment(filename?: string): ExpressServerResponse; 649 | 650 | /** 651 | * Set header `field` to `val`, or pass 652 | * an object of header fields. 653 | * 654 | * Examples: 655 | * 656 | * res.set('Foo', ['bar', 'baz']); 657 | * res.set('Accept', 'application/json'); 658 | * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' }); 659 | * 660 | * Aliased as `res.header()`. 661 | */ 662 | set (field: any): void; 663 | 664 | set (field: string, value?: string): void; 665 | 666 | header(field: any): void; 667 | 668 | header(field: string, value?: string): void; 669 | 670 | /** 671 | * Get value for header `field`. 672 | * 673 | * @param field 674 | */ 675 | get (field: string): string; 676 | 677 | /** 678 | * Clear cookie `name`. 679 | * 680 | * @param name 681 | * @param options 682 | */ 683 | clearCookie(name: string, options?: any): ExpressServerResponse; 684 | 685 | /** 686 | * Set cookie `name` to `val`, with the given `options`. 687 | * 688 | * Options: 689 | * 690 | * - `maxAge` max-age in milliseconds, converted to `expires` 691 | * - `signed` sign the cookie 692 | * - `path` defaults to "/" 693 | * 694 | * Examples: 695 | * 696 | * // "Remember Me" for 15 minutes 697 | * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true }); 698 | * 699 | * // save as above 700 | * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true }) 701 | */ 702 | cookie(name: string, val: string, options: CookieOptions); 703 | 704 | cookie(name: string, val: any, options: CookieOptions); 705 | 706 | cookie(name: string, val: any); 707 | 708 | /** 709 | * Set the location header to `url`. 710 | * 711 | * The given `url` can also be the name of a mapped url, for 712 | * example by default express supports "back" which redirects 713 | * to the _Referrer_ or _Referer_ headers or "/". 714 | * 715 | * Examples: 716 | * 717 | * res.location('/foo/bar').; 718 | * res.location('http://example.com'); 719 | * res.location('../login'); // /blog/post/1 -> /blog/login 720 | * 721 | * Mounting: 722 | * 723 | * When an application is mounted and `res.location()` 724 | * is given a path that does _not_ lead with "/" it becomes 725 | * relative to the mount-point. For example if the application 726 | * is mounted at "/blog", the following would become "/blog/login". 727 | * 728 | * res.location('login'); 729 | * 730 | * While the leading slash would result in a location of "/login": 731 | * 732 | * res.location('/login'); 733 | * 734 | * @param url 735 | */ 736 | location(url: string); 737 | 738 | /** 739 | * Redirect to the given `url` with optional response `status` 740 | * defaulting to 302. 741 | * 742 | * The resulting `url` is determined by `res.location()`, so 743 | * it will play nicely with mounted apps, relative paths, 744 | * `"back"` etc. 745 | * 746 | * Examples: 747 | * 748 | * res.redirect('/foo/bar'); 749 | * res.redirect('http://example.com'); 750 | * res.redirect(301, 'http://example.com'); 751 | * res.redirect('http://example.com', 301); 752 | * res.redirect('../login'); // /blog/post/1 -> /blog/login 753 | */ 754 | redirect(url: string): void; 755 | 756 | redirect(status: number, url: string): void; 757 | 758 | redirect(url: string, status: number): void; 759 | 760 | /** 761 | * Render `view` with the given `options` and optional callback `fn`. 762 | * When a callback function is given a response will _not_ be made 763 | * automatically, otherwise a response of _200_ and _text/html_ is given. 764 | * 765 | * Options: 766 | * 767 | * - `cache` boolean hinting to the engine it should cache 768 | * - `filename` filename of the view being rendered 769 | */ 770 | render(view: string): void; 771 | 772 | render(view: string, options: any): void; 773 | 774 | render(view: string, callback: (err: Error, html: any) => void ): void; 775 | 776 | render(view: string, options: any, callback: (err: Error, html: any) => void ): void; 777 | 778 | locals: any; 779 | 780 | charset: string; 781 | } 782 | 783 | interface ExpressRequestFunction { 784 | (req: ExpressServerRequest, res: ExpressServerResponse, next: Function): any; 785 | } 786 | 787 | interface ExpressApplication { 788 | /** 789 | * Initialize the server. 790 | * 791 | * - setup default configuration 792 | * - setup default middleware 793 | * - setup route reflection methods 794 | */ 795 | init(); 796 | 797 | /** 798 | * Initialize application configuration. 799 | */ 800 | defaultConfiguration(); 801 | 802 | /** 803 | * Proxy `connect#use()` to apply settings to 804 | * mounted applications. 805 | **/ 806 | use(route: string, callback?: Function): ExpressApplication; 807 | 808 | use(route: string, server: ExpressApplication): ExpressApplication; 809 | 810 | use(callback: Function): ExpressApplication; 811 | 812 | use(server: ExpressApplication): ExpressApplication; 813 | 814 | /** 815 | * Register the given template engine callback `fn` 816 | * as `ext`. 817 | * 818 | * By default will `require()` the engine based on the 819 | * file extension. For example if you try to render 820 | * a "foo.jade" file Express will invoke the following internally: 821 | * 822 | * app.engine('jade', require('jade').__express); 823 | * 824 | * For engines that do not provide `.__express` out of the box, 825 | * or if you wish to "map" a different extension to the template engine 826 | * you may use this method. For example mapping the EJS template engine to 827 | * ".html" files: 828 | * 829 | * app.engine('html', require('ejs').renderFile); 830 | * 831 | * In this case EJS provides a `.renderFile()` method with 832 | * the same signature that Express expects: `(path, options, callback)`, 833 | * though note that it aliases this method as `ejs.__express` internally 834 | * so if you're using ".ejs" extensions you dont need to do anything. 835 | * 836 | * Some template engines do not follow this convention, the 837 | * [Consolidate.js](https://github.com/visionmedia/consolidate.js) 838 | * library was created to map all of node's popular template 839 | * engines to follow this convention, thus allowing them to 840 | * work seamlessly within Express. 841 | */ 842 | engine(ext: string, fn: Function): ExpressApplication; 843 | 844 | /** 845 | * Map the given param placeholder `name`(s) to the given callback(s). 846 | * 847 | * Parameter mapping is used to provide pre-conditions to routes 848 | * which use normalized placeholders. For example a _:user_id_ parameter 849 | * could automatically load a user's information from the database without 850 | * any additional code, 851 | * 852 | * The callback uses the samesignature as middleware, the only differencing 853 | * being that the value of the placeholder is passed, in this case the _id_ 854 | * of the user. Once the `next()` function is invoked, just like middleware 855 | * it will continue on to execute the route, or subsequent parameter functions. 856 | * 857 | * app.param('user_id', function(req, res, next, id){ 858 | * User.find(id, function(err, user){ 859 | * if (err) { 860 | * next(err); 861 | * } else if (user) { 862 | * req.user = user; 863 | * next(); 864 | * } else { 865 | * next(new Error('failed to load user')); 866 | * } 867 | * }); 868 | * }); 869 | * 870 | * @param name 871 | * @param fn 872 | */ 873 | param(name: string, fn: Function): ExpressApplication; 874 | 875 | param(name: Array, fn: Function): ExpressApplication; 876 | 877 | /** 878 | * Assign `setting` to `val`, or return `setting`'s value. 879 | * 880 | * app.set('foo', 'bar'); 881 | * app.get('foo'); 882 | * // => "bar" 883 | * 884 | * Mounted servers inherit their parent server's settings. 885 | * 886 | * @param setting 887 | * @param val 888 | */ 889 | set (setting: string, val: string): ExpressApplication; 890 | 891 | /** 892 | * Return the app's absolute pathname 893 | * based on the parent(s) that have 894 | * mounted it. 895 | * 896 | * For example if the application was 897 | * mounted as "/admin", which itself 898 | * was mounted as "/blog" then the 899 | * return value would be "/blog/admin". 900 | */ 901 | path(): string; 902 | 903 | /** 904 | * Check if `setting` is enabled (truthy). 905 | * 906 | * app.enabled('foo') 907 | * // => false 908 | * 909 | * app.enable('foo') 910 | * app.enabled('foo') 911 | * // => true 912 | */ 913 | enabled(setting: string): boolean; 914 | 915 | /** 916 | * Check if `setting` is disabled. 917 | * 918 | * app.disabled('foo') 919 | * // => true 920 | * 921 | * app.enable('foo') 922 | * app.disabled('foo') 923 | * // => false 924 | * 925 | * @param setting 926 | */ 927 | disabled(setting: string): boolean; 928 | 929 | /** 930 | * Enable `setting`. 931 | * 932 | * @param setting 933 | */ 934 | enable(setting: string): ExpressApplication; 935 | 936 | /** 937 | * Disable `setting`. 938 | * 939 | * @param setting 940 | */ 941 | disable(setting: string): ExpressApplication; 942 | 943 | /** 944 | * Configure callback for zero or more envs, 945 | * when no `env` is specified that callback will 946 | * be invoked for all environments. Any combination 947 | * can be used multiple times, in any order desired. 948 | * 949 | * Examples: 950 | * 951 | * app.configure(function(){ 952 | * // executed for all envs 953 | * }); 954 | * 955 | * app.configure('stage', function(){ 956 | * // executed staging env 957 | * }); 958 | * 959 | * app.configure('stage', 'production', function(){ 960 | * // executed for stage and production 961 | * }); 962 | * 963 | * Note: 964 | * 965 | * These callbacks are invoked immediately, and 966 | * are effectively sugar for the following: 967 | * 968 | * var env = process.env.NODE_ENV || 'development'; 969 | * 970 | * switch (env) { 971 | * case 'development': 972 | * ... 973 | * break; 974 | * case 'stage': 975 | * ... 976 | * break; 977 | * case 'production': 978 | * ... 979 | * break; 980 | * } 981 | * 982 | * @param env 983 | * @param fn 984 | */ 985 | configure(env: string, fn: Function): ExpressApplication; 986 | 987 | configure(env0: string, env1: string, fn: Function): ExpressApplication; 988 | 989 | configure(env0: string, env1: string, env2: string, fn: Function): ExpressApplication; 990 | 991 | configure(env0: string, env1: string, env2: string, env3: string, fn: Function): ExpressApplication; 992 | 993 | configure(env0: string, env1: string, env2: string, env3: string, env4: string, fn: Function): ExpressApplication; 994 | 995 | configure(fn: Function): ExpressApplication; 996 | 997 | /** 998 | * Special-cased "all" method, applying the given route `path`, 999 | * middleware, and callback to _every_ HTTP method. 1000 | * 1001 | * @param path 1002 | * @param fn 1003 | */ 1004 | all(path: string, fn?: (req: ExpressServerRequest, res: ExpressServerResponse, next: Function) => any): ExpressApplication; 1005 | 1006 | all(path: string, ...callbacks: Function[]): void; 1007 | 1008 | /** 1009 | * Render the given view `name` name with `options` 1010 | * and a callback accepting an error and the 1011 | * rendered template string. 1012 | * 1013 | * Example: 1014 | * 1015 | * app.render('email', { name: 'Tobi' }, function(err, html){ 1016 | * // ... 1017 | * }) 1018 | * 1019 | * @param name 1020 | * @param options or fn 1021 | * @param fn 1022 | */ 1023 | render(name: string, options: string, fn: Function); 1024 | 1025 | render(name: string, fn: Function); 1026 | 1027 | get(name: string, ...handlers: ExpressRequestFunction[]): any; 1028 | get(name: RegExp, ...handlers: ExpressRequestFunction[]): any; 1029 | 1030 | post(name: string, ...handlers: ExpressRequestFunction[]): any; 1031 | post(name: RegExp, ...handlers: ExpressRequestFunction[]): any; 1032 | 1033 | put(name: string, ...handlers: ExpressRequestFunction[]): any; 1034 | put(name: RegExp, ...handlers: ExpressRequestFunction[]): any; 1035 | 1036 | del(name: string, ...handlers: ExpressRequestFunction[]): any; 1037 | del(name: RegExp, ...handlers: ExpressRequestFunction[]): any; 1038 | 1039 | /** 1040 | * Listen for connections. 1041 | * 1042 | * A node `http.Server` is returned, with this 1043 | * application (which is a `Function`) as its 1044 | * callback. If you wish to create both an HTTP 1045 | * and HTTPS server you may do so with the "http" 1046 | * and "https" modules as shown here: 1047 | * 1048 | * var http = require('http') 1049 | * , https = require('https') 1050 | * , express = require('express') 1051 | * , app = express(); 1052 | * 1053 | * http.createServer(app).listen(80); 1054 | * https.createServer({ ... }, app).listen(443); 1055 | */ 1056 | listen(port: number, hostname: string, backlog: number, callback: Function): void; 1057 | 1058 | listen(port: number, callback: Function): void; 1059 | 1060 | listen(path: string, callback?: Function): void; 1061 | 1062 | listen(handle: any, listeningListener?: Function): void; 1063 | 1064 | render(view: string, callback: (err: Error, html) => void ): void; 1065 | 1066 | render(view: string, optionss: any, callback: (err: Error, html) => void ): void; 1067 | 1068 | route: Route; 1069 | 1070 | router: string; 1071 | 1072 | settings: any; 1073 | 1074 | resource: any; 1075 | 1076 | map: any; 1077 | 1078 | locals: any; 1079 | 1080 | /** 1081 | * The app.routes object houses all of the routes defined mapped by the 1082 | * associated HTTP verb. This object may be used for introspection 1083 | * capabilities, for example Express uses this internally not only for 1084 | * routing but to provide default OPTIONS behaviour unless app.options() 1085 | * is used. Your application or framework may also remove routes by 1086 | * simply by removing them from this object. 1087 | */ 1088 | routes: any; 1089 | } 1090 | 1091 | interface Express extends ExpressApplication { 1092 | /** 1093 | * Framework version. 1094 | */ 1095 | version: string; 1096 | 1097 | /** 1098 | * Expose mime. 1099 | */ 1100 | mime: string; 1101 | 1102 | (): ExpressApplication; 1103 | 1104 | /** 1105 | * Create an express application. 1106 | */ 1107 | createApplication(): ExpressApplication; 1108 | 1109 | createServer(): ExpressApplication; 1110 | 1111 | application: any; 1112 | 1113 | request: ExpressServerRequest; 1114 | 1115 | response: ExpressServerResponse; 1116 | } 1117 | 1118 | 1119 | declare module "express" { 1120 | function express(): Express; 1121 | 1122 | module express { 1123 | /** 1124 | * Body parser: 1125 | * 1126 | * Parse request bodies, supports _application/json_, 1127 | * _application/x-www-form-urlencoded_, and _multipart/form-data_. 1128 | * 1129 | * This is equivalent to: 1130 | * 1131 | * app.use(connect.json()); 1132 | * app.use(connect.urlencoded()); 1133 | * app.use(connect.multipart()); 1134 | * 1135 | * Examples: 1136 | * 1137 | * connect() 1138 | * .use(connect.bodyParser()) 1139 | * .use(function(req, res) { 1140 | * res.end('viewing user ' + req.body.user.name); 1141 | * }); 1142 | * 1143 | * $ curl -d 'user[name]=tj' http://local/ 1144 | * $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://local/ 1145 | * 1146 | * View [json](json.html), [urlencoded](urlencoded.html), and [multipart](multipart.html) for more info. 1147 | * 1148 | * @param options 1149 | */ 1150 | export function bodyParser(options?: any): Handler; 1151 | 1152 | /** 1153 | * Error handler: 1154 | * 1155 | * Development error handler, providing stack traces 1156 | * and error message responses for requests accepting text, html, 1157 | * or json. 1158 | * 1159 | * Text: 1160 | * 1161 | * By default, and when _text/plain_ is accepted a simple stack trace 1162 | * or error message will be returned. 1163 | * 1164 | * JSON: 1165 | * 1166 | * When _application/json_ is accepted, connect will respond with 1167 | * an object in the form of `{ "error": error }`. 1168 | * 1169 | * HTML: 1170 | * 1171 | * When accepted connect will output a nice html stack trace. 1172 | */ 1173 | export function errorHandler(opts?: any): Handler; 1174 | 1175 | /** 1176 | * Method Override: 1177 | * 1178 | * Provides faux HTTP method support. 1179 | * 1180 | * Pass an optional `key` to use when checking for 1181 | * a method override, othewise defaults to _\_method_. 1182 | * The original method is available via `req.originalMethod`. 1183 | * 1184 | * @param key 1185 | */ 1186 | export function methodOverride(key?: string): Handler; 1187 | 1188 | /** 1189 | * Cookie parser: 1190 | * 1191 | * Parse _Cookie_ header and populate `req.cookies` 1192 | * with an object keyed by the cookie names. Optionally 1193 | * you may enabled signed cookie support by passing 1194 | * a `secret` string, which assigns `req.secret` so 1195 | * it may be used by other middleware. 1196 | * 1197 | * Examples: 1198 | * 1199 | * connect() 1200 | * .use(connect.cookieParser('optional secret string')) 1201 | * .use(function(req, res, next){ 1202 | * res.end(JSON.stringify(req.cookies)); 1203 | * }) 1204 | * 1205 | * @param secret 1206 | */ 1207 | export function cookieParser(secret?: string): Handler; 1208 | 1209 | /** 1210 | * Session: 1211 | * 1212 | * Setup session store with the given `options`. 1213 | * 1214 | * Session data is _not_ saved in the cookie itself, however 1215 | * cookies are used, so we must use the [cookieParser()](cookieParser.html) 1216 | * middleware _before_ `session()`. 1217 | * 1218 | * Examples: 1219 | * 1220 | * connect() 1221 | * .use(connect.cookieParser()) 1222 | * .use(connect.session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }})) 1223 | * 1224 | * Options: 1225 | * 1226 | * - `key` cookie name defaulting to `connect.sid` 1227 | * - `store` session store instance 1228 | * - `secret` session cookie is signed with this secret to prevent tampering 1229 | * - `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }` 1230 | * - `proxy` trust the reverse proxy when setting secure cookies (via "x-forwarded-proto") 1231 | * 1232 | * Cookie option: 1233 | * 1234 | * By default `cookie.maxAge` is `null`, meaning no "expires" parameter is set 1235 | * so the cookie becomes a browser-session cookie. When the user closes the 1236 | * browser the cookie (and session) will be removed. 1237 | * 1238 | * ## req.session 1239 | * 1240 | * To store or access session data, simply use the request property `req.session`, 1241 | * which is (generally) serialized as JSON by the store, so nested objects 1242 | * are typically fine. For example below is a user-specific view counter: 1243 | * 1244 | * connect() 1245 | * .use(connect.favicon()) 1246 | * .use(connect.cookieParser()) 1247 | * .use(connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) 1248 | * .use(function(req, res, next){ 1249 | * var sess = req.session; 1250 | * if (sess.views) { 1251 | * res.setHeader('Content-Type', 'text/html'); 1252 | * res.write('

views: ' + sess.views + '

'); 1253 | * res.write('

expires in: ' + (sess.cookie.maxAge / 1000) + 's

'); 1254 | * res.end(); 1255 | * sess.views++; 1256 | * } else { 1257 | * sess.views = 1; 1258 | * res.end('welcome to the session demo. refresh!'); 1259 | * } 1260 | * } 1261 | * )).listen(3000); 1262 | * 1263 | * ## Session#regenerate() 1264 | * 1265 | * To regenerate the session simply invoke the method, once complete 1266 | * a new SID and `Session` instance will be initialized at `req.session`. 1267 | * 1268 | * req.session.regenerate(function(err){ 1269 | * // will have a new session here 1270 | * }); 1271 | * 1272 | * ## Session#destroy() 1273 | * 1274 | * Destroys the session, removing `req.session`, will be re-generated next request. 1275 | * 1276 | * req.session.destroy(function(err){ 1277 | * // cannot access session here 1278 | * }); 1279 | * 1280 | * ## Session#reload() 1281 | * 1282 | * Reloads the session data. 1283 | * 1284 | * req.session.reload(function(err){ 1285 | * // session updated 1286 | * }); 1287 | * 1288 | * ## Session#save() 1289 | * 1290 | * Save the session. 1291 | * 1292 | * req.session.save(function(err){ 1293 | * // session saved 1294 | * }); 1295 | * 1296 | * ## Session#touch() 1297 | * 1298 | * Updates the `.maxAge` property. Typically this is 1299 | * not necessary to call, as the session middleware does this for you. 1300 | * 1301 | * ## Session#cookie 1302 | * 1303 | * Each session has a unique cookie object accompany it. This allows 1304 | * you to alter the session cookie per visitor. For example we can 1305 | * set `req.session.cookie.expires` to `false` to enable the cookie 1306 | * to remain for only the duration of the user-agent. 1307 | * 1308 | * ## Session#maxAge 1309 | * 1310 | * Alternatively `req.session.cookie.maxAge` will return the time 1311 | * remaining in milliseconds, which we may also re-assign a new value 1312 | * to adjust the `.expires` property appropriately. The following 1313 | * are essentially equivalent 1314 | * 1315 | * var hour = 3600000; 1316 | * req.session.cookie.expires = new Date(Date.now() + hour); 1317 | * req.session.cookie.maxAge = hour; 1318 | * 1319 | * For example when `maxAge` is set to `60000` (one minute), and 30 seconds 1320 | * has elapsed it will return `30000` until the current request has completed, 1321 | * at which time `req.session.touch()` is called to reset `req.session.maxAge` 1322 | * to its original value. 1323 | * 1324 | * req.session.cookie.maxAge; 1325 | * // => 30000 1326 | * 1327 | * Session Store Implementation: 1328 | * 1329 | * Every session store _must_ implement the following methods 1330 | * 1331 | * - `.get(sid, callback)` 1332 | * - `.set(sid, session, callback)` 1333 | * - `.destroy(sid, callback)` 1334 | * 1335 | * Recommended methods include, but are not limited to: 1336 | * 1337 | * - `.length(callback)` 1338 | * - `.clear(callback)` 1339 | * 1340 | * For an example implementation view the [connect-redis](http://github.com/visionmedia/connect-redis) repo. 1341 | * 1342 | * @param options 1343 | */ 1344 | export function session(options?: any): Handler; 1345 | 1346 | /** 1347 | * Hash the given `sess` object omitting changes 1348 | * to `.cookie`. 1349 | * 1350 | * @param sess 1351 | */ 1352 | export function hash(sess: string): string; 1353 | 1354 | /** 1355 | * Static: 1356 | * 1357 | * Static file server with the given `root` path. 1358 | * 1359 | * Examples: 1360 | * 1361 | * var oneDay = 86400000; 1362 | * 1363 | * connect() 1364 | * .use(connect.static(__dirname + '/public')) 1365 | * 1366 | * connect() 1367 | * .use(connect.static(__dirname + '/public', { maxAge: oneDay })) 1368 | * 1369 | * Options: 1370 | * 1371 | * - `maxAge` Browser cache maxAge in milliseconds. defaults to 0 1372 | * - `hidden` Allow transfer of hidden files. defaults to false 1373 | * - `redirect` Redirect to trailing "/" when the pathname is a dir. defaults to true 1374 | * 1375 | * @param root 1376 | * @param options 1377 | */ 1378 | export function static(root: string, options?: any): Handler; 1379 | 1380 | /** 1381 | * Basic Auth: 1382 | * 1383 | * Enfore basic authentication by providing a `callback(user, pass)`, 1384 | * which must return `true` in order to gain access. Alternatively an async 1385 | * method is provided as well, invoking `callback(user, pass, callback)`. Populates 1386 | * `req.user`. The final alternative is simply passing username / password 1387 | * strings. 1388 | * 1389 | * Simple username and password 1390 | * 1391 | * connect(connect.basicAuth('username', 'password')); 1392 | * 1393 | * Callback verification 1394 | * 1395 | * connect() 1396 | * .use(connect.basicAuth(function(user, pass){ 1397 | * return 'tj' == user & 'wahoo' == pass; 1398 | * })) 1399 | * 1400 | * Async callback verification, accepting `fn(err, user)`. 1401 | * 1402 | * connect() 1403 | * .use(connect.basicAuth(function(user, pass, fn){ 1404 | * User.authenticate({ user: user, pass: pass }, fn); 1405 | * })) 1406 | * 1407 | * @param callback or username 1408 | * @param realm 1409 | */ 1410 | export function basicAuth(callback: Function, realm: string); 1411 | 1412 | export function basicAuth(callback: string, realm: string); 1413 | 1414 | export function basicAuth(callback: Function); 1415 | 1416 | /** 1417 | * Compress: 1418 | * 1419 | * Compress response data with gzip/deflate. 1420 | * 1421 | * Filter: 1422 | * 1423 | * A `filter` callback function may be passed to 1424 | * replace the default logic of: 1425 | * 1426 | * exports.filter = function(req, res){ 1427 | * return /json|text|javascript/.test(res.getHeader('Content-Type')); 1428 | * }; 1429 | * 1430 | * Options: 1431 | * 1432 | * All remaining options are passed to the gzip/deflate 1433 | * creation functions. Consult node's docs for additional details. 1434 | * 1435 | * - `chunkSize` (default: 16*1024) 1436 | * - `windowBits` 1437 | * - `level`: 0-9 where 0 is no compression, and 9 is slow but best compression 1438 | * - `memLevel`: 1-9 low is slower but uses less memory, high is fast but uses more 1439 | * - `strategy`: compression strategy 1440 | * 1441 | * @param options 1442 | */ 1443 | export function compress(options?: any): Handler; 1444 | 1445 | /** 1446 | * Cookie Session: 1447 | * 1448 | * Cookie session middleware. 1449 | * 1450 | * var app = connect(); 1451 | * app.use(connect.cookieParser()); 1452 | * app.use(connect.cookieSession({ secret: 'tobo!', cookie: { maxAge: 60 * 60 * 1000 }})); 1453 | * 1454 | * Options: 1455 | * 1456 | * - `key` cookie name defaulting to `connect.sess` 1457 | * - `secret` prevents cookie tampering 1458 | * - `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }` 1459 | * - `proxy` trust the reverse proxy when setting secure cookies (via "x-forwarded-proto") 1460 | * 1461 | * Clearing sessions: 1462 | * 1463 | * To clear the session simply set its value to `null`, 1464 | * `cookieSession()` will then respond with a 1970 Set-Cookie. 1465 | * 1466 | * req.session = null; 1467 | * 1468 | * @param options 1469 | */ 1470 | export function cookieSession(options?: any): Handler; 1471 | 1472 | /** 1473 | * Anti CSRF: 1474 | * 1475 | * CRSF protection middleware. 1476 | * 1477 | * By default this middleware generates a token named "_csrf" 1478 | * which should be added to requests which mutate 1479 | * state, within a hidden form field, query-string etc. This 1480 | * token is validated against the visitor's `req.session._csrf` 1481 | * property. 1482 | * 1483 | * The default `value` function checks `req.body` generated 1484 | * by the `bodyParser()` middleware, `req.query` generated 1485 | * by `query()`, and the "X-CSRF-Token" header field. 1486 | * 1487 | * This middleware requires session support, thus should be added 1488 | * somewhere _below_ `session()` and `cookieParser()`. 1489 | * 1490 | * Options: 1491 | * 1492 | * - `value` a function accepting the request, returning the token 1493 | * 1494 | * @param options 1495 | */ 1496 | export function csrf(options: any); 1497 | 1498 | /** 1499 | * Directory: 1500 | * 1501 | * Serve directory listings with the given `root` path. 1502 | * 1503 | * Options: 1504 | * 1505 | * - `hidden` display hidden (dot) files. Defaults to false. 1506 | * - `icons` display icons. Defaults to false. 1507 | * - `filter` Apply this filter function to files. Defaults to false. 1508 | * 1509 | * @param root 1510 | * @param options 1511 | */ 1512 | export function directory(root: string, options?: any): Handler; 1513 | 1514 | /** 1515 | * Favicon: 1516 | * 1517 | * By default serves the connect favicon, or the favicon 1518 | * located by the given `path`. 1519 | * 1520 | * Options: 1521 | * 1522 | * - `maxAge` cache-control max-age directive, defaulting to 1 day 1523 | * 1524 | * Examples: 1525 | * 1526 | * Serve default favicon: 1527 | * 1528 | * connect() 1529 | * .use(connect.favicon()) 1530 | * 1531 | * Serve favicon before logging for brevity: 1532 | * 1533 | * connect() 1534 | * .use(connect.favicon()) 1535 | * .use(connect.logger('dev')) 1536 | * 1537 | * Serve custom favicon: 1538 | * 1539 | * connect() 1540 | * .use(connect.favicon('public/favicon.ico)) 1541 | * 1542 | * @param path 1543 | * @param options 1544 | */ 1545 | export function favicon(path?: string, options?: any); 1546 | 1547 | /** 1548 | * JSON: 1549 | * 1550 | * Parse JSON request bodies, providing the 1551 | * parsed object as `req.body`. 1552 | * 1553 | * Options: 1554 | * 1555 | * - `strict` when `false` anything `JSON.parse()` accepts will be parsed 1556 | * - `reviver` used as the second "reviver" argument for JSON.parse 1557 | * - `limit` byte limit disabled by default 1558 | * 1559 | * @param options 1560 | */ 1561 | export function json(options?: any): Handler; 1562 | 1563 | /** 1564 | * Limit: 1565 | * 1566 | * Limit request bodies to the given size in `bytes`. 1567 | * 1568 | * A string representation of the bytesize may also be passed, 1569 | * for example "5mb", "200kb", "1gb", etc. 1570 | * 1571 | * connect() 1572 | * .use(connect.limit('5.5mb')) 1573 | * .use(handleImageUpload) 1574 | */ 1575 | export function limit(bytes: number): Handler; 1576 | 1577 | export function limit(bytes: string): Handler; 1578 | 1579 | /** 1580 | * Logger: 1581 | * 1582 | * Log requests with the given `options` or a `format` string. 1583 | * 1584 | * Options: 1585 | * 1586 | * - `format` Format string, see below for tokens 1587 | * - `stream` Output stream, defaults to _stdout_ 1588 | * - `buffer` Buffer duration, defaults to 1000ms when _true_ 1589 | * - `immediate` Write log line on request instead of response (for response times) 1590 | * 1591 | * Tokens: 1592 | * 1593 | * - `:req[header]` ex: `:req[Accept]` 1594 | * - `:res[header]` ex: `:res[Content-Length]` 1595 | * - `:http-version` 1596 | * - `:response-time` 1597 | * - `:remote-addr` 1598 | * - `:date` 1599 | * - `:method` 1600 | * - `:url` 1601 | * - `:referrer` 1602 | * - `:user-agent` 1603 | * - `:status` 1604 | * 1605 | * Formats: 1606 | * 1607 | * Pre-defined formats that ship with connect: 1608 | * 1609 | * - `default` ':remote-addr - - [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"' 1610 | * - `short` ':remote-addr - :method :url HTTP/:http-version :status :res[content-length] - :response-time ms' 1611 | * - `tiny` ':method :url :status :res[content-length] - :response-time ms' 1612 | * - `dev` concise output colored by response status for development use 1613 | * 1614 | * Examples: 1615 | * 1616 | * connect.logger() // default 1617 | * connect.logger('short') 1618 | * connect.logger('tiny') 1619 | * connect.logger({ immediate: true, format: 'dev' }) 1620 | * connect.logger(':method :url - :referrer') 1621 | * connect.logger(':req[content-type] -> :res[content-type]') 1622 | * connect.logger(function(tokens, req, res){ return 'some format string' }) 1623 | * 1624 | * Defining Tokens: 1625 | * 1626 | * To define a token, simply invoke `connect.logger.token()` with the 1627 | * name and a callback function. The value returned is then available 1628 | * as ":type" in this case. 1629 | * 1630 | * connect.logger.token('type', function(req, res){ return req.headers['content-type']; }) 1631 | * 1632 | * Defining Formats: 1633 | * 1634 | * All default formats are defined this way, however it's public API as well: 1635 | * 1636 | * connect.logger.format('name', 'string or function') 1637 | */ 1638 | export function logger(options: string): Handler; 1639 | 1640 | export function logger(options: Function): Handler; 1641 | 1642 | export function logger(options?: any): Handler; 1643 | 1644 | /** 1645 | * Compile `fmt` into a function. 1646 | * 1647 | * @param fmt 1648 | */ 1649 | export function compile(fmt: string): Handler; 1650 | 1651 | /** 1652 | * Define a token function with the given `name`, 1653 | * and callback `fn(req, res)`. 1654 | * 1655 | * @param name 1656 | * @param fn 1657 | */ 1658 | export function token(name: string, fn: Function): any; 1659 | 1660 | /** 1661 | * Define a `fmt` with the given `name`. 1662 | */ 1663 | export function format(name: string, str: string): any; 1664 | 1665 | export function format(name: string, str: Function): any; 1666 | 1667 | /** 1668 | * Query: 1669 | * 1670 | * Automatically parse the query-string when available, 1671 | * populating the `req.query` object. 1672 | * 1673 | * Examples: 1674 | * 1675 | * connect() 1676 | * .use(connect.query()) 1677 | * .use(function(req, res){ 1678 | * res.end(JSON.stringify(req.query)); 1679 | * }); 1680 | * 1681 | * The `options` passed are provided to qs.parse function. 1682 | */ 1683 | export function query(options: any): Handler; 1684 | 1685 | /** 1686 | * Reponse time: 1687 | * 1688 | * Adds the `X-Response-Time` header displaying the response 1689 | * duration in milliseconds. 1690 | */ 1691 | export function responseTime(): Handler; 1692 | 1693 | /** 1694 | * Static cache: 1695 | * 1696 | * Enables a memory cache layer on top of 1697 | * the `static()` middleware, serving popular 1698 | * static files. 1699 | * 1700 | * By default a maximum of 128 objects are 1701 | * held in cache, with a max of 256k each, 1702 | * totalling ~32mb. 1703 | * 1704 | * A Least-Recently-Used (LRU) cache algo 1705 | * is implemented through the `Cache` object, 1706 | * simply rotating cache objects as they are 1707 | * hit. This means that increasingly popular 1708 | * objects maintain their positions while 1709 | * others get shoved out of the stack and 1710 | * garbage collected. 1711 | * 1712 | * Benchmarks: 1713 | * 1714 | * static(): 2700 rps 1715 | * node-static: 5300 rps 1716 | * static() + staticCache(): 7500 rps 1717 | * 1718 | * Options: 1719 | * 1720 | * - `maxObjects` max cache objects [128] 1721 | * - `maxLength` max cache object length 256kb 1722 | */ 1723 | export function staticCache(options: any): Handler; 1724 | 1725 | /** 1726 | * Timeout: 1727 | * 1728 | * Times out the request in `ms`, defaulting to `5000`. The 1729 | * method `req.clearTimeout()` is added to revert this behaviour 1730 | * programmatically within your application's middleware, routes, etc. 1731 | * 1732 | * The timeout error is passed to `next()` so that you may customize 1733 | * the response behaviour. This error has the `.timeout` property as 1734 | * well as `.status == 408`. 1735 | */ 1736 | export function timeout(ms: number): Handler; 1737 | 1738 | /** 1739 | * Vhost: 1740 | * 1741 | * Setup vhost for the given `hostname` and `server`. 1742 | * 1743 | * connect() 1744 | * .use(connect.vhost('foo.com', fooApp)) 1745 | * .use(connect.vhost('bar.com', barApp)) 1746 | * .use(connect.vhost('*.com', mainApp)) 1747 | * 1748 | * The `server` may be a Connect server or 1749 | * a regular Node `http.Server`. 1750 | * 1751 | * @param hostname 1752 | * @param server 1753 | */ 1754 | export function vhost(hostname: string, server: any): Handler; 1755 | 1756 | export function urlencoded(): any; 1757 | 1758 | export function multipart(): any; 1759 | } 1760 | 1761 | export = express; 1762 | } 1763 | -------------------------------------------------------------------------------- /ts-definitions/mocha/mocha.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for mocha 1.9.0 2 | // Project: http://visionmedia.github.io/mocha/ 3 | // Definitions by: Kazi Manzur Rashid 4 | // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | interface Mocha { 7 | setup(options: MochaSetupOptions); 8 | run(callback: () => void); 9 | } 10 | 11 | interface MochaSetupOptions { 12 | slow: number; 13 | timeout: number; 14 | ui: string; 15 | } 16 | 17 | declare var describe : { 18 | (description: string, spec: () => void): void; 19 | only(description: string, spec: () => void): void; 20 | skip(description: string, spec: () => void): void; 21 | timeout(ms: number); 22 | } 23 | 24 | declare var it: { 25 | (expectation: string, assertion?: () => void): void; 26 | (expectation: string, assertion?: (done: (error?: Error) => void) => void): void; 27 | only(expectation: string, assertion?: () => void): void; 28 | only(expectation: string, assertion?: (done: (error?: Error) => void) => void): void; 29 | skip(expectation: string, assertion?: () => void): void; 30 | skip(expectation: string, assertion?: (done: (error?: Error) => void) => void): void; 31 | timeout(ms: number); 32 | }; 33 | 34 | declare function before(action: () => void): void; 35 | 36 | declare function before(action: (done: (failReason?) => void) => void): void; 37 | 38 | declare function after(action: () => void): void; 39 | 40 | declare function after(action: (done: (failReason?) => void) => void): void; 41 | 42 | declare function beforeEach(action: () => void): void; 43 | 44 | declare function beforeEach(action: (done: (failReason?) => void) => void): void; 45 | 46 | declare function afterEach(action: () => void): void; 47 | 48 | declare function afterEach(action: (done: (failReason?) => void) => void): void; 49 | 50 | -------------------------------------------------------------------------------- /ts-definitions/node/node.d.ts: -------------------------------------------------------------------------------- 1 | /************************************************ 2 | * * 3 | * Node.js v0.10.1 API * 4 | * * 5 | ************************************************/ 6 | 7 | /************************************************ 8 | * * 9 | * GLOBAL * 10 | * * 11 | ************************************************/ 12 | declare var process: NodeProcess; 13 | declare var global: any; 14 | 15 | declare var __filename: string; 16 | declare var __dirname: string; 17 | 18 | declare function setTimeout(callback: () => void , ms: number): any; 19 | declare function clearTimeout(timeoutId: any): void; 20 | declare function setInterval(callback: () => void , ms: number): any; 21 | declare function clearInterval(intervalId: any): void; 22 | declare function setImmediate(callback: () => void ): any; 23 | declare function clearImmediate(immediateId: any): void; 24 | 25 | declare var require: { 26 | (id: string): any; 27 | resolve(id:string): string; 28 | cache: any; 29 | extensions: any; 30 | main: any; 31 | } 32 | 33 | declare var module: { 34 | exports: any; 35 | require(id: string): any; 36 | id: string; 37 | filename: string; 38 | loaded: boolean; 39 | parent: any; 40 | children: any[]; 41 | } 42 | 43 | // Same as module.exports 44 | declare var exports: any; 45 | declare var SlowBuffer: { 46 | new (str: string, encoding?: string): NodeBuffer; 47 | new (size: number): NodeBuffer; 48 | new (array: any[]): NodeBuffer; 49 | prototype: NodeBuffer; 50 | isBuffer(obj: any): boolean; 51 | byteLength(string: string, encoding?: string): number; 52 | concat(list: NodeBuffer[], totalLength?: number): NodeBuffer; 53 | }; 54 | declare var Buffer: { 55 | new (str: string, encoding?: string): NodeBuffer; 56 | new (size: number): NodeBuffer; 57 | new (array: any[]): NodeBuffer; 58 | prototype: NodeBuffer; 59 | isBuffer(obj: any): boolean; 60 | byteLength(string: string, encoding?: string): number; 61 | concat(list: NodeBuffer[], totalLength?: number): NodeBuffer; 62 | } 63 | 64 | /************************************************ 65 | * * 66 | * INTERFACES * 67 | * * 68 | ************************************************/ 69 | 70 | interface EventEmitter { 71 | addListener(event: string, listener: Function): void; 72 | on(event: string, listener: Function): void; 73 | once(event: string, listener: Function): void; 74 | removeListener(event: string, listener: Function): void; 75 | removeAllListeners(event?: string): void; 76 | setMaxListeners(n: number): void; 77 | listeners(event: string): Function[]; 78 | emit(event: string, arg1?: any, arg2?: any): void; 79 | } 80 | 81 | interface WritableStream extends EventEmitter { 82 | writable: boolean; 83 | write(str: string, encoding?: string, fd?: string): boolean; 84 | write(buffer: NodeBuffer): boolean; 85 | end(): void; 86 | end(str: string, enconding: string): void; 87 | end(buffer: NodeBuffer): void; 88 | destroy(): void; 89 | destroySoon(): void; 90 | } 91 | 92 | interface ReadableStream extends EventEmitter { 93 | readable: boolean; 94 | setEncoding(encoding: string): void; 95 | pause(): void; 96 | resume(): void; 97 | destroy(): void; 98 | pipe(destination: WritableStream, options?: { end?: boolean; }): void; 99 | } 100 | 101 | interface NodeProcess extends EventEmitter { 102 | stdout: WritableStream; 103 | stderr: WritableStream; 104 | stdin: ReadableStream; 105 | argv: string[]; 106 | execPath: string; 107 | abort(): void; 108 | chdir(directory: string): void; 109 | cwd(): void; 110 | env: any; 111 | exit(code?: number): void; 112 | getgid(): number; 113 | setgid(id: number): void; 114 | setgid(id: string): void; 115 | getuid(): number; 116 | setuid(id: number): void; 117 | setuid(id: string): void; 118 | version: string; 119 | versions: { http_parser: string; node: string; v8: string; ares: string; uv: string; zlib: string; openssl: string; }; 120 | config: { 121 | target_defaults: { 122 | cflags: any[]; 123 | default_configuration: string; 124 | defines: string[]; 125 | include_dirs: string[]; 126 | libraries: string[]; 127 | }; 128 | variables: { 129 | clang: number; 130 | host_arch: string; 131 | node_install_npm: boolean; 132 | node_install_waf: boolean; 133 | node_prefix: string; 134 | node_shared_openssl: boolean; 135 | node_shared_v8: boolean; 136 | node_shared_zlib: boolean; 137 | node_use_dtrace: boolean; 138 | node_use_etw: boolean; 139 | node_use_openssl: boolean; 140 | target_arch: string; 141 | v8_no_strict_aliasing: number; 142 | v8_use_snapshot: boolean; 143 | visibility: string; 144 | }; 145 | }; 146 | kill(pid: number, signal?: string): void; 147 | pid: number; 148 | title: string; 149 | arch: string; 150 | platform: string; 151 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; 152 | nextTick(callback: Function): void; 153 | umask(mask?: number): number; 154 | uptime(): number; 155 | hrtime(time?:number[]): number[]; 156 | } 157 | 158 | // Buffer class 159 | interface NodeBuffer { 160 | [index: number]: number; 161 | write(string: string, offset?: number, length?: number, encoding?: string): number; 162 | toString(encoding?: string, start?: number, end?: number): string; 163 | length: number; 164 | copy(targetBuffer: NodeBuffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): void; 165 | slice(start?: number, end?: number): NodeBuffer; 166 | readUInt8(offset: number, noAsset?: boolean): number; 167 | readUInt16LE(offset: number, noAssert?: boolean): number; 168 | readUInt16BE(offset: number, noAssert?: boolean): number; 169 | readUInt32LE(offset: number, noAssert?: boolean): number; 170 | readUInt32BE(offset: number, noAssert?: boolean): number; 171 | readInt8(offset: number, noAssert?: boolean): number; 172 | readInt16LE(offset: number, noAssert?: boolean): number; 173 | readInt16BE(offset: number, noAssert?: boolean): number; 174 | readInt32LE(offset: number, noAssert?: boolean): number; 175 | readInt32BE(offset: number, noAssert?: boolean): number; 176 | readFloatLE(offset: number, noAssert?: boolean): number; 177 | readFloatBE(offset: number, noAssert?: boolean): number; 178 | readDoubleLE(offset: number, noAssert?: boolean): number; 179 | readDoubleBE(offset: number, noAssert?: boolean): number; 180 | writeUInt8(value: number, offset: number, noAssert?: boolean): void; 181 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; 182 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; 183 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; 184 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; 185 | writeInt8(value: number, offset: number, noAssert?: boolean): void; 186 | writeInt16LE(value: number, offset: number, noAssert?: boolean): void; 187 | writeInt16BE(value: number, offset: number, noAssert?: boolean): void; 188 | writeInt32LE(value: number, offset: number, noAssert?: boolean): void; 189 | writeInt32BE(value: number, offset: number, noAssert?: boolean): void; 190 | writeFloatLE(value: number, offset: number, noAssert?: boolean): void; 191 | writeFloatBE(value: number, offset: number, noAssert?: boolean): void; 192 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; 193 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; 194 | fill(value: any, offset?: number, end?: number): void; 195 | INSPECT_MAX_BYTES: number; 196 | } 197 | 198 | /************************************************ 199 | * * 200 | * MODULES * 201 | * * 202 | ************************************************/ 203 | declare module "querystring" { 204 | export function stringify(obj: any, sep?: string, eq?: string): string; 205 | export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; 206 | export function escape(): any; 207 | export function unescape(): any; 208 | } 209 | 210 | declare module "events" { 211 | export interface NodeEventEmitter { 212 | addListener(event: string, listener: Function): void; 213 | on(event: string, listener: Function): any; 214 | once(event: string, listener: Function): void; 215 | removeListener(event: string, listener: Function): void; 216 | removeAllListeners(event?: string): void; 217 | setMaxListeners(n: number): void; 218 | listeners(event: string): Function[]; 219 | emit(event: string, arg1?: any, arg2?: any): void; 220 | } 221 | 222 | export class EventEmitter implements NodeEventEmitter { 223 | addListener(event: string, listener: Function): void; 224 | on(event: string, listener: Function): any; 225 | once(event: string, listener: Function): void; 226 | removeListener(event: string, listener: Function): void; 227 | removeAllListeners(event?: string): void; 228 | setMaxListeners(n: number): void; 229 | listeners(event: string): Function[]; 230 | emit(event: string, arg1?: any, arg2?: any): void; 231 | } 232 | } 233 | 234 | declare module "http" { 235 | import events = require("events"); 236 | import net = require("net"); 237 | import stream = require("stream"); 238 | 239 | export interface Server extends events.NodeEventEmitter { 240 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): void; 241 | listen(path: string, callback?: Function): void; 242 | listen(handle: any, listeningListener?: Function): void; 243 | close(cb?: any): void; 244 | maxHeadersCount: number; 245 | } 246 | export interface ServerRequest extends events.NodeEventEmitter, stream.ReadableStream { 247 | method: string; 248 | url: string; 249 | headers: any; 250 | trailers: string; 251 | httpVersion: string; 252 | setEncoding(encoding?: string): void; 253 | pause(): void; 254 | resume(): void; 255 | connection: net.NodeSocket; 256 | } 257 | export interface ServerResponse extends events.NodeEventEmitter, stream.WritableStream { 258 | // Extended base methods 259 | write(str: string, encoding?: string, fd?: string): boolean; 260 | write(buffer: NodeBuffer): boolean; 261 | 262 | writeContinue(): void; 263 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 264 | writeHead(statusCode: number, headers?: any): void; 265 | statusCode: number; 266 | setHeader(name: string, value: string): void; 267 | sendDate: boolean; 268 | getHeader(name: string): string; 269 | removeHeader(name: string): void; 270 | write(chunk: any, encoding?: string): any; 271 | addTrailers(headers: any): void; 272 | end(data?: any, encoding?: string): void; 273 | } 274 | export interface ClientRequest extends events.NodeEventEmitter, stream.WritableStream { 275 | // Extended base methods 276 | write(str: string, encoding?: string, fd?: string): boolean; 277 | write(buffer: NodeBuffer): boolean; 278 | 279 | write(chunk: any, encoding?: string): void; 280 | end(data?: any, encoding?: string): void; 281 | abort(): void; 282 | setTimeout(timeout: number, callback?: Function): void; 283 | setNoDelay(noDelay?: Function): void; 284 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 285 | } 286 | export interface ClientResponse extends events.NodeEventEmitter, stream.ReadableStream { 287 | statusCode: number; 288 | httpVersion: string; 289 | headers: any; 290 | trailers: any; 291 | setEncoding(encoding?: string): void; 292 | pause(): void; 293 | resume(): void; 294 | } 295 | export interface Agent { maxSockets: number; sockets: any; requests: any; } 296 | 297 | export var STATUS_CODES: any; 298 | export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server; 299 | export function createClient(port?: number, host?: string): any; 300 | export function request(options: any, callback?: Function): ClientRequest; 301 | export function get(options: any, callback?: Function): ClientRequest; 302 | export var globalAgent: Agent; 303 | } 304 | 305 | declare module "cluster" { 306 | import child_process = require("child_process"); 307 | 308 | export interface ClusterSettings { 309 | exec: string; 310 | args: string[]; 311 | silent: boolean; 312 | } 313 | export interface Worker { 314 | id: string; 315 | process: child_process.ChildProcess; 316 | suicide: boolean; 317 | send(message: any, sendHandle?: any): void; 318 | destroy(): void; 319 | disconnect(): void; 320 | } 321 | 322 | 323 | export var settings: ClusterSettings; 324 | export var isMaster: boolean; 325 | export var isWorker: boolean; 326 | export function setupMaster(settings?: ClusterSettings): void; 327 | export function fork(env?: any): Worker; 328 | export function disconnect(callback?: Function): void; 329 | export var workers: any; 330 | 331 | // Event emitter 332 | export function addListener(event: string, listener: Function): void; 333 | export function on(event: string, listener: Function): any; 334 | export function once(event: string, listener: Function): void; 335 | export function removeListener(event: string, listener: Function): void; 336 | export function removeAllListeners(event?: string): void; 337 | export function setMaxListeners(n: number): void; 338 | export function listeners(event: string): Function[]; 339 | export function emit(event: string, arg1?: any, arg2?: any): void; 340 | } 341 | 342 | declare module "zlib" { 343 | import stream = require("stream"); 344 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 345 | 346 | export interface Gzip extends stream.ReadWriteStream { } 347 | export interface Gunzip extends stream.ReadWriteStream { } 348 | export interface Deflate extends stream.ReadWriteStream { } 349 | export interface Inflate extends stream.ReadWriteStream { } 350 | export interface DeflateRaw extends stream.ReadWriteStream { } 351 | export interface InflateRaw extends stream.ReadWriteStream { } 352 | export interface Unzip extends stream.ReadWriteStream { } 353 | 354 | export function createGzip(options?: ZlibOptions): Gzip; 355 | export function createGunzip(options?: ZlibOptions): Gunzip; 356 | export function createDeflate(options?: ZlibOptions): Deflate; 357 | export function createInflate(options?: ZlibOptions): Inflate; 358 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 359 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 360 | export function createUnzip(options?: ZlibOptions): Unzip; 361 | 362 | export function deflate(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 363 | export function deflateRaw(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 364 | export function gzip(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 365 | export function gunzip(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 366 | export function inflate(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 367 | export function inflateRaw(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 368 | export function unzip(buf: NodeBuffer, callback: (error: Error, result: any) =>void ): void; 369 | 370 | // Constants 371 | export var Z_NO_FLUSH: number; 372 | export var Z_PARTIAL_FLUSH: number; 373 | export var Z_SYNC_FLUSH: number; 374 | export var Z_FULL_FLUSH: number; 375 | export var Z_FINISH: number; 376 | export var Z_BLOCK: number; 377 | export var Z_TREES: number; 378 | export var Z_OK: number; 379 | export var Z_STREAM_END: number; 380 | export var Z_NEED_DICT: number; 381 | export var Z_ERRNO: number; 382 | export var Z_STREAM_ERROR: number; 383 | export var Z_DATA_ERROR: number; 384 | export var Z_MEM_ERROR: number; 385 | export var Z_BUF_ERROR: number; 386 | export var Z_VERSION_ERROR: number; 387 | export var Z_NO_COMPRESSION: number; 388 | export var Z_BEST_SPEED: number; 389 | export var Z_BEST_COMPRESSION: number; 390 | export var Z_DEFAULT_COMPRESSION: number; 391 | export var Z_FILTERED: number; 392 | export var Z_HUFFMAN_ONLY: number; 393 | export var Z_RLE: number; 394 | export var Z_FIXED: number; 395 | export var Z_DEFAULT_STRATEGY: number; 396 | export var Z_BINARY: number; 397 | export var Z_TEXT: number; 398 | export var Z_ASCII: number; 399 | export var Z_UNKNOWN: number; 400 | export var Z_DEFLATED: number; 401 | export var Z_NULL: number; 402 | } 403 | 404 | declare module "os" { 405 | export function tmpDir(): string; 406 | export function hostname(): string; 407 | export function type(): string; 408 | export function platform(): string; 409 | export function arch(): string; 410 | export function release(): string; 411 | export function uptime(): number; 412 | export function loadavg(): number[]; 413 | export function totalmem(): number; 414 | export function freemem(): number; 415 | export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; 416 | export function networkInterfaces(): any; 417 | export var EOL: string; 418 | } 419 | 420 | declare module "https" { 421 | import tls = require("tls"); 422 | import events = require("events"); 423 | import http = require("http"); 424 | 425 | export interface ServerOptions { 426 | pfx?: any; 427 | key?: any; 428 | passphrase?: string; 429 | cert?: any; 430 | ca?: any; 431 | crl?: any; 432 | ciphers?: string; 433 | honorCipherOrder?: boolean; 434 | requestCert?: boolean; 435 | rejectUnauthorized?: boolean; 436 | NPNProtocols?: any; 437 | SNICallback?: (servername: string) => any; 438 | } 439 | 440 | export interface RequestOptions { 441 | host?: string; 442 | hostname?: string; 443 | port?: number; 444 | path?: string; 445 | method?: string; 446 | headers?: any; 447 | auth?: string; 448 | agent?: any; 449 | pfx?: any; 450 | key?: any; 451 | passphrase?: string; 452 | cert?: any; 453 | ca?: any; 454 | ciphers?: string; 455 | rejectUnauthorized?: boolean; 456 | } 457 | 458 | export interface NodeAgent { 459 | maxSockets: number; 460 | sockets: any; 461 | requests: any; 462 | } 463 | export var Agent: { 464 | new (options?: RequestOptions): NodeAgent; 465 | }; 466 | export interface Server extends tls.Server { } 467 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 468 | export function request(options: RequestOptions, callback?: (res: events.NodeEventEmitter) =>void ): http.ClientRequest; 469 | export function get(options: RequestOptions, callback?: (res: events.NodeEventEmitter) =>void ): http.ClientRequest; 470 | export var globalAgent: NodeAgent; 471 | } 472 | 473 | declare module "punycode" { 474 | export function decode(string: string): string; 475 | export function encode(string: string): string; 476 | export function toUnicode(domain: string): string; 477 | export function toASCII(domain: string): string; 478 | export var ucs2: ucs2; 479 | interface ucs2 { 480 | decode(string: string): string; 481 | encode(codePoints: number[]): string; 482 | } 483 | export var version: any; 484 | } 485 | 486 | declare module "repl" { 487 | import stream = require("stream"); 488 | import events = require("events"); 489 | 490 | export interface ReplOptions { 491 | prompt?: string; 492 | input?: stream.ReadableStream; 493 | output?: stream.WritableStream; 494 | terminal?: boolean; 495 | eval?: Function; 496 | useColors?: boolean; 497 | useGlobal?: boolean; 498 | ignoreUndefined?: boolean; 499 | writer?: Function; 500 | } 501 | export function start(options: ReplOptions): events.NodeEventEmitter; 502 | } 503 | 504 | declare module "readline" { 505 | import events = require("events"); 506 | import stream = require("stream"); 507 | 508 | export interface ReadLine extends events.NodeEventEmitter { 509 | setPrompt(prompt: string, length: number): void; 510 | prompt(preserveCursor?: boolean): void; 511 | question(query: string, callback: Function): void; 512 | pause(): void; 513 | resume(): void; 514 | close(): void; 515 | write(data: any, key?: any): void; 516 | } 517 | export interface ReadLineOptions { 518 | input: stream.ReadableStream; 519 | output: stream.WritableStream; 520 | completer?: Function; 521 | terminal?: boolean; 522 | } 523 | export function createInterface(options: ReadLineOptions): ReadLine; 524 | } 525 | 526 | declare module "vm" { 527 | export interface Context { } 528 | export interface Script { 529 | runInThisContext(): void; 530 | runInNewContext(sandbox?: Context): void; 531 | } 532 | export function runInThisContext(code: string, filename?: string): void; 533 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 534 | export function runInContext(code: string, context: Context, filename?: string): void; 535 | export function createContext(initSandbox?: Context): Context; 536 | export function createScript(code: string, filename?: string): Script; 537 | } 538 | 539 | declare module "child_process" { 540 | import events = require("events"); 541 | import stream = require("stream"); 542 | 543 | export interface ChildProcess extends events.NodeEventEmitter { 544 | stdin: stream.WritableStream; 545 | stdout: stream.ReadableStream; 546 | stderr: stream.ReadableStream; 547 | pid: number; 548 | kill(signal?: string): void; 549 | send(message: any, sendHandle: any): void; 550 | disconnect(): void; 551 | } 552 | 553 | export function spawn(command: string, args?: string[], options?: { 554 | cwd?: string; 555 | stdio?: any; 556 | custom?: any; 557 | env?: any; 558 | detached?: boolean; 559 | }): ChildProcess; 560 | export function exec(command: string, options: { 561 | cwd?: string; 562 | stdio?: any; 563 | customFds?: any; 564 | env?: any; 565 | encoding?: string; 566 | timeout?: number; 567 | maxBuffer?: number; 568 | killSignal?: string; 569 | }, callback: (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) =>void ): ChildProcess; 570 | export function exec(command: string, callback: (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) =>void ): ChildProcess; 571 | export function execFile(file: string, args: string[], options: { 572 | cwd?: string; 573 | stdio?: any; 574 | customFds?: any; 575 | env?: any; 576 | encoding?: string; 577 | timeout?: number; 578 | maxBuffer?: string; 579 | killSignal?: string; 580 | }, callback: (error: Error, stdout: NodeBuffer, stderr: NodeBuffer) =>void ): ChildProcess; 581 | export function fork(modulePath: string, args?: string[], options?: { 582 | cwd?: string; 583 | env?: any; 584 | encoding?: string; 585 | }): ChildProcess; 586 | } 587 | 588 | declare module "url" { 589 | export interface Url { 590 | href: string; 591 | protocol: string; 592 | auth: string; 593 | hostname: string; 594 | port: string; 595 | host: string; 596 | pathname: string; 597 | search: string; 598 | query: string; 599 | slashes: boolean; 600 | } 601 | 602 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 603 | export function format(url: Url): string; 604 | export function resolve(from: string, to: string): string; 605 | } 606 | 607 | declare module "dns" { 608 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 609 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 610 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 611 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 612 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 613 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 614 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 615 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 616 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 617 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 618 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 619 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 620 | } 621 | 622 | declare module "net" { 623 | import stream = require("stream"); 624 | 625 | export interface NodeSocket extends stream.ReadWriteStream { 626 | // Extended base methods 627 | write(str: string, encoding?: string, fd?: string): boolean; 628 | write(buffer: NodeBuffer): boolean; 629 | 630 | connect(port: number, host?: string, connectionListener?: Function): void; 631 | connect(path: string, connectionListener?: Function): void; 632 | bufferSize: number; 633 | setEncoding(encoding?: string): void; 634 | write(data: any, encoding?: string, callback?: Function): void; 635 | end(data?: any, encoding?: string): void; 636 | destroy(): void; 637 | pause(): void; 638 | resume(): void; 639 | setTimeout(timeout: number, callback?: Function): void; 640 | setNoDelay(noDelay?: boolean): void; 641 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 642 | address(): { port: number; family: string; address: string; }; 643 | remoteAddress: string; 644 | remotePort: number; 645 | bytesRead: number; 646 | bytesWritten: number; 647 | } 648 | 649 | export var Socket: { 650 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): NodeSocket; 651 | }; 652 | 653 | export interface Server extends NodeSocket { 654 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): void; 655 | listen(path: string, listeningListener?: Function): void; 656 | listen(handle: any, listeningListener?: Function): void; 657 | close(callback?: Function): void; 658 | address(): { port: number; family: string; address: string; }; 659 | maxConnections: number; 660 | connections: number; 661 | } 662 | export function createServer(connectionListener?: (socket: NodeSocket) =>void ): Server; 663 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: NodeSocket) =>void ): Server; 664 | export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): NodeSocket; 665 | export function connect(port: number, host?: string, connectionListener?: Function): NodeSocket; 666 | export function connect(path: string, connectionListener?: Function): NodeSocket; 667 | export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): NodeSocket; 668 | export function createConnection(port: number, host?: string, connectionListener?: Function): NodeSocket; 669 | export function createConnection(path: string, connectionListener?: Function): NodeSocket; 670 | export function isIP(input: string): number; 671 | export function isIPv4(input: string): boolean; 672 | export function isIPv6(input: string): boolean; 673 | } 674 | 675 | declare module "dgram" { 676 | import events = require("events"); 677 | 678 | export function createSocket(type: string, callback?: Function): Socket; 679 | 680 | interface Socket extends events.NodeEventEmitter { 681 | send(buf: NodeBuffer, offset: number, length: number, port: number, address: string, callback?: Function): void; 682 | bind(port: number, address?: string): void; 683 | close(): void; 684 | address: { address: string; family: string; port: number; }; 685 | setBroadcast(flag: boolean): void; 686 | setMulticastTTL(ttl: number): void; 687 | setMulticastLoopback(flag: boolean): void; 688 | addMembership(multicastAddress: string, multicastInterface?: string): void; 689 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 690 | } 691 | } 692 | 693 | declare module "fs" { 694 | import stream = require("stream"); 695 | 696 | interface Stats { 697 | isFile(): boolean; 698 | isDirectory(): boolean; 699 | isBlockDevice(): boolean; 700 | isCharacterDevice(): boolean; 701 | isSymbolicLink(): boolean; 702 | isFIFO(): boolean; 703 | isSocket(): boolean; 704 | dev: number; 705 | ino: number; 706 | mode: number; 707 | nlink: number; 708 | uid: number; 709 | gid: number; 710 | rdev: number; 711 | size: number; 712 | blksize: number; 713 | blocks: number; 714 | atime: Date; 715 | mtime: Date; 716 | ctime: Date; 717 | } 718 | 719 | interface FSWatcher extends EventEmitter { 720 | close(): void; 721 | } 722 | 723 | export interface ReadStream extends stream.ReadableStream { } 724 | export interface WriteStream extends stream.WritableStream { } 725 | 726 | export function rename(oldPath: string, newPath: string, callback?: Function): void; 727 | export function renameSync(oldPath: string, newPath: string): void; 728 | export function truncate(fd: string, len: number, callback?: Function): void; 729 | export function truncateSync(fd: string, len: number): void; 730 | export function chown(path: string, uid: number, gid: number, callback?: Function): void; 731 | export function chownSync(path: string, uid: number, gid: number): void; 732 | export function fchown(fd: string, uid: number, gid: number, callback?: Function): void; 733 | export function fchownSync(fd: string, uid: number, gid: number): void; 734 | export function lchown(path: string, uid: number, gid: number, callback?: Function): void; 735 | export function lchownSync(path: string, uid: number, gid: number): void; 736 | export function chmod(path: string, mode: string, callback?: Function): void; 737 | export function chmodSync(path: string, mode: string): void; 738 | export function fchmod(fd: string, mode: string, callback?: Function): void; 739 | export function fchmodSync(fd: string, mode: string): void; 740 | export function lchmod(path: string, mode: string, callback?: Function): void; 741 | export function lchmodSync(path: string, mode: string): void; 742 | export function stat(path: string, callback?: (err: Error, stats: Stats) =>any): Stats; 743 | export function lstat(path: string, callback?: (err: Error, stats: Stats) =>any): Stats; 744 | export function fstat(fd: string, callback?: (err: Error, stats: Stats) =>any): Stats; 745 | export function statSync(path: string): Stats; 746 | export function lstatSync(path: string): Stats; 747 | export function fstatSync(fd: string): Stats; 748 | export function link(srcpath: string, dstpath: string, callback?: Function): void; 749 | export function linkSync(srcpath: string, dstpath: string): void; 750 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: Function): void; 751 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 752 | export function readlink(path: string, callback?: (err: Error, linkString: string) =>any): void; 753 | export function realpath(path: string, callback?: (err: Error, resolvedPath: string) =>any): void; 754 | export function realpath(path: string, cache: string, callback: (err: Error, resolvedPath: string) =>any): void; 755 | export function realpathSync(path: string, cache?: string): void; 756 | export function unlink(path: string, callback?: Function): void; 757 | export function unlinkSync(path: string): void; 758 | export function rmdir(path: string, callback?: Function): void; 759 | export function rmdirSync(path: string): void; 760 | export function mkdir(path: string, mode?: string, callback?: Function): void; 761 | export function mkdirSync(path: string, mode?: string): void; 762 | export function readdir(path: string, callback?: (err: Error, files: string[]) => void): void; 763 | export function readdirSync(path: string): string[]; 764 | export function close(fd: string, callback?: Function): void; 765 | export function closeSync(fd: string): void; 766 | export function open(path: string, flags: string, mode?: string, callback?: (err: Error, fd: string) =>any): void; 767 | export function openSync(path: string, flags: string, mode?: string): void; 768 | export function utimes(path: string, atime: number, mtime: number, callback?: Function): void; 769 | export function utimesSync(path: string, atime: number, mtime: number): void; 770 | export function futimes(fd: string, atime: number, mtime: number, callback?: Function): void; 771 | export function futimesSync(fd: string, atime: number, mtime: number): void; 772 | export function fsync(fd: string, callback?: Function): void; 773 | export function fsyncSync(fd: string): void; 774 | export function write(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, written: number, buffer: NodeBuffer) =>any): void; 775 | export function writeSync(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number): void; 776 | export function read(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number, callback?: (err: Error, bytesRead: number, buffer: NodeBuffer) => void): void; 777 | export function readSync(fd: string, buffer: NodeBuffer, offset: number, length: number, position: number): any[]; 778 | export function readFile(filename: string, options: { encoding?: string; flag?: string; }, callback: (err: Error, data: any) => void ): void; 779 | export function readFile(filename: string, callback: (err: Error, data: NodeBuffer) => void ): void; 780 | export function readFileSync(filename: string): NodeBuffer; 781 | export function readFileSync(filename: string, options: { encoding?: string; flag?: string; }): any; 782 | export function writeFile(filename: string, data: any, callback?: (err: Error) => void): void; 783 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; 784 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 785 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: Error) => void): void; 786 | export function appendFile(filename: string, data: any, callback?: (err: Error) => void): void; 787 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 788 | export function watchFile(filename: string, listener: { curr: Stats; prev: Stats; }): void; 789 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: { curr: Stats; prev: Stats; }): void; 790 | export function unwatchFile(filename: string, listener?: Stats): void; 791 | export function watch(filename: string, options?: { persistent?: boolean; }, listener?: (event: string, filename: string) =>any): FSWatcher; 792 | export function exists(path: string, callback?: (exists: boolean) =>void ): void; 793 | export function existsSync(path: string): boolean; 794 | export function createReadStream(path: string, options?: { 795 | flags?: string; 796 | encoding?: string; 797 | fd?: string; 798 | mode?: number; 799 | bufferSize?: number; 800 | }): ReadStream; 801 | export function createWriteStream(path: string, options?: { 802 | flags?: string; 803 | encoding?: string; 804 | string?: string; 805 | }): WriteStream; 806 | } 807 | 808 | declare module "path" { 809 | export function normalize(p: string): string; 810 | export function join(...paths: any[]): string; 811 | export function resolve(to: string): string; 812 | export function resolve(from: string, to: string): string; 813 | export function resolve(from: string, from2: string, to: string): string; 814 | export function resolve(from: string, from2: string, from3: string, to: string): string; 815 | export function resolve(from: string, from2: string, from3: string, from4: string, to: string): string; 816 | export function resolve(from: string, from2: string, from3: string, from4: string, from5: string, to: string): string; 817 | export function relative(from: string, to: string): string; 818 | export function dirname(p: string): string; 819 | export function basename(p: string, ext?: string): string; 820 | export function extname(p: string): string; 821 | export var sep: string; 822 | } 823 | 824 | declare module "string_decoder" { 825 | export interface NodeStringDecoder { 826 | write(buffer: NodeBuffer): string; 827 | detectIncompleteChar(buffer: NodeBuffer): number; 828 | } 829 | export var StringDecoder: { 830 | new (encoding: string): NodeStringDecoder; 831 | }; 832 | } 833 | 834 | declare module "tls" { 835 | import crypto = require("crypto"); 836 | import net = require("net"); 837 | import stream = require("stream"); 838 | 839 | var CLIENT_RENEG_LIMIT: number; 840 | var CLIENT_RENEG_WINDOW: number; 841 | 842 | export interface TlsOptions { 843 | pfx?: any; //string or buffer 844 | key?: any; //string or buffer 845 | passphrase?: string; 846 | cert?: any; 847 | ca?: any; //string or buffer 848 | crl?: any; //string or string array 849 | ciphers?: string; 850 | honorCipherOrder?: any; 851 | requestCert?: boolean; 852 | rejectUnauthorized?: boolean; 853 | NPNProtocols?: any; //array or Buffer; 854 | SNICallback?: (servername: string) => any; 855 | } 856 | 857 | export interface ConnectionOptions { 858 | host?: string; 859 | port?: number; 860 | socket?: net.NodeSocket; 861 | pfx?: any; //string | Buffer 862 | key?: any; //string | Buffer 863 | passphrase?: string; 864 | cert?: any; //string | Buffer 865 | ca?: any; //Array of string | Buffer 866 | rejectUnauthorized?: boolean; 867 | NPNProtocols?: any; //Array of string | Buffer 868 | servername?: string; 869 | } 870 | 871 | export interface Server extends net.Server { 872 | // Extended base methods 873 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): void; 874 | listen(path: string, listeningListener?: Function): void; 875 | listen(handle: any, listeningListener?: Function): void; 876 | 877 | listen(port: number, host?: string, callback?: Function): void; 878 | close(): void; 879 | address(): { port: number; family: string; address: string; }; 880 | addContext(hostName: string, credentials: { 881 | key: string; 882 | cert: string; 883 | ca: string; 884 | }): void; 885 | maxConnections: number; 886 | connections: number; 887 | } 888 | 889 | export interface ClearTextStream extends stream.ReadWriteStream { 890 | authorized: boolean; 891 | authorizationError: Error; 892 | getPeerCertificate(): any; 893 | getCipher: { 894 | name: string; 895 | version: string; 896 | }; 897 | address: { 898 | port: number; 899 | family: string; 900 | address: string; 901 | }; 902 | remoteAddress: string; 903 | remotePort: number; 904 | } 905 | 906 | export interface SecurePair { 907 | encrypted: any; 908 | cleartext: any; 909 | } 910 | 911 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 912 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 913 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 914 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 915 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 916 | } 917 | 918 | declare module "crypto" { 919 | export interface CredentialDetails { 920 | pfx: string; 921 | key: string; 922 | passphrase: string; 923 | cert: string; 924 | ca: any; //string | string array 925 | crl: any; //string | string array 926 | ciphers: string; 927 | } 928 | export interface Credentials { context?: any; } 929 | export function createCredentials(details: CredentialDetails): Credentials; 930 | export function createHash(algorithm: string): Hash; 931 | export function createHmac(algorithm: string, key: string): Hmac; 932 | interface Hash { 933 | update(data: any, input_encoding?: string): Hash; 934 | digest(encoding?: string): string; 935 | } 936 | interface Hmac { 937 | update(data: any): void; 938 | digest(encoding?: string): void; 939 | } 940 | export function createCipher(algorithm: string, password: any): Cipher; 941 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 942 | interface Cipher { 943 | update(data: any, input_encoding?: string, output_encoding?: string): string; 944 | final(output_encoding?: string): string; 945 | setAutoPadding(auto_padding: boolean): void; 946 | createDecipher(algorithm: string, password: any): Decipher; 947 | createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 948 | } 949 | interface Decipher { 950 | update(data: any, input_encoding?: string, output_encoding?: string): void; 951 | final(output_encoding?: string): string; 952 | setAutoPadding(auto_padding: boolean): void; 953 | } 954 | export function createSign(algorithm: string): Signer; 955 | interface Signer { 956 | update(data: any): void; 957 | sign(private_key: string, output_format: string): string; 958 | } 959 | export function createVerify(algorith: string): Verify; 960 | interface Verify { 961 | update(data: any): void; 962 | verify(object: string, signature: string, signature_format?: string): boolean; 963 | } 964 | export function createDiffieHellman(prime_length: number): DiffieHellman; 965 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 966 | interface DiffieHellman { 967 | generateKeys(encoding?: string): string; 968 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 969 | getPrime(encoding?: string): string; 970 | getGenerator(encoding: string): string; 971 | getPublicKey(encoding?: string): string; 972 | getPrivateKey(encoding?: string): string; 973 | setPublicKey(public_key: string, encoding?: string): void; 974 | setPrivateKey(public_key: string, encoding?: string): void; 975 | } 976 | export function getDiffieHellman(group_name: string): DiffieHellman; 977 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: string) => any): void; 978 | export function randomBytes(size: number, callback?: (err: Error, buf: NodeBuffer) =>void ): void; 979 | } 980 | 981 | declare module "stream" { 982 | import events = require("events"); 983 | 984 | export interface WritableStream extends events.NodeEventEmitter { 985 | writable: boolean; 986 | write(str: string, encoding?: string, fd?: string): boolean; 987 | write(buffer: NodeBuffer): boolean; 988 | end(): void; 989 | end(str: string, enconding: string): void; 990 | end(buffer: NodeBuffer): void; 991 | destroy(): void; 992 | destroySoon(): void; 993 | } 994 | 995 | export interface ReadableStream extends events.NodeEventEmitter { 996 | readable: boolean; 997 | setEncoding(encoding: string): void; 998 | pause(): void; 999 | resume(): void; 1000 | destroy(): void; 1001 | pipe(destination: T, options?: { end?: boolean; }): T; 1002 | } 1003 | 1004 | export interface ReadableOptions { 1005 | highWaterMark?: number; 1006 | encoding?: string; 1007 | objectMode?: boolean; 1008 | } 1009 | 1010 | export class Readable extends events.EventEmitter implements ReadableStream { 1011 | readable: boolean; 1012 | constructor(opts?: ReadableOptions); 1013 | setEncoding(encoding: string): void; 1014 | pause(): void; 1015 | resume(): void; 1016 | destroy(): void; 1017 | pipe(destination: T, options?: { end?: boolean; }): T; 1018 | _read(): void; 1019 | push(chunk: any, encoding?: string): boolean; 1020 | } 1021 | 1022 | export interface ReadWriteStream extends ReadableStream, WritableStream { } 1023 | } 1024 | 1025 | declare module "util" { 1026 | export function format(format: any, ...param: any[]): string; 1027 | export function debug(string: string): void; 1028 | export function error(...param: any[]): void; 1029 | export function puts(...param: any[]): void; 1030 | export function print(...param: any[]): void; 1031 | export function log(string: string): void; 1032 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 1033 | export function isArray(object: any): boolean; 1034 | export function isRegExp(object: any): boolean; 1035 | export function isDate(object: any): boolean; 1036 | export function isError(object: any): boolean; 1037 | export function inherits(constructor: any, superConstructor: any): void; 1038 | } 1039 | 1040 | declare module "assert" { 1041 | function internal (booleanValue: boolean, message?: string): void; 1042 | module internal { 1043 | export function fail(actual: any, expected: any, message: string, operator: string): void; 1044 | export function assert(value: any, message: string): void; 1045 | export function ok(value: any, message?: string): void; 1046 | export function equal(actual: any, expected: any, message?: string): void; 1047 | export function notEqual(actual: any, expected: any, message?: string): void; 1048 | export function deepEqual(actual: any, expected: any, message?: string): void; 1049 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 1050 | export function strictEqual(actual: any, expected: any, message?: string): void; 1051 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 1052 | export function throws(block: any, error?: any, messsage?: string): void; 1053 | export function doesNotThrow(block: any, error?: any, messsage?: string): void; 1054 | export function ifError(value: any): void; 1055 | } 1056 | 1057 | export = internal; 1058 | } 1059 | 1060 | declare module "tty" { 1061 | import net = require("net"); 1062 | 1063 | export function isatty(fd: string): boolean; 1064 | export interface ReadStream extends net.NodeSocket { 1065 | isRaw: boolean; 1066 | setRawMode(mode: boolean): void; 1067 | } 1068 | export interface WriteStream extends net.NodeSocket { 1069 | columns: number; 1070 | rows: number; 1071 | } 1072 | } 1073 | 1074 | declare module "domain" { 1075 | import events = require("events"); 1076 | 1077 | export interface Domain extends events.NodeEventEmitter { } 1078 | 1079 | export function create(): Domain; 1080 | export function run(fn: Function): void; 1081 | export function add(emitter: events.NodeEventEmitter): void; 1082 | export function remove(emitter: events.NodeEventEmitter): void; 1083 | export function bind(cb: (er: Error, data: any) =>any): any; 1084 | export function intercept(cb: (data: any) => any): any; 1085 | export function dispose(): void; 1086 | } 1087 | -------------------------------------------------------------------------------- /ts-definitions/should/should.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for should.js 1.2.2 2 | // Project: https://github.com/visionmedia/should.js 3 | // Definitions by: Alex Varju 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | interface Object { 7 | should: ShouldAssertion; 8 | } 9 | 10 | interface ShouldAssertion { 11 | // basic grammar 12 | an: ShouldAssertion; 13 | // a: ShouldAssertion; 14 | and: ShouldAssertion; 15 | be: ShouldAssertion; 16 | have: ShouldAssertion; 17 | with: ShouldAssertion; 18 | not: ShouldAssertion; 19 | 20 | // validators 21 | arguments: ShouldAssertion; 22 | empty: ShouldAssertion; 23 | ok: ShouldAssertion; 24 | true: ShouldAssertion; 25 | false: ShouldAssertion; 26 | eql(expected: any, description?: string): ShouldAssertion; 27 | equal(expected: any, description?: string): ShouldAssertion; 28 | within(start: number, finish: number, description?: string): ShouldAssertion; 29 | approximately(value: number, delta: number, description?: string): ShouldAssertion; 30 | a(expected: any, description?: string): ShouldAssertion; 31 | instanceof(constructor: Function, description?: string): ShouldAssertion; 32 | above(n: number, description?: string): ShouldAssertion; 33 | below(n: number, description?: string): ShouldAssertion; 34 | match(regexp: RegExp, description?: string): ShouldAssertion; 35 | length(n: number, description?: string): ShouldAssertion; 36 | property(name: string, description?: string): ShouldAssertion; 37 | property(name: string, val: any, description?: string): ShouldAssertion; 38 | ownProperty(name: string, description?: string): ShouldAssertion; 39 | include(obj: any, description?: string): ShouldAssertion; 40 | includeEql(obj: Array, description?: string): ShouldAssertion; 41 | contain(obj: any): ShouldAssertion; 42 | keys(...allKeys: string[]): ShouldAssertion; 43 | keys(allKeys: string[]): ShouldAssertion; 44 | header(field: string, val?: string): ShouldAssertion; 45 | status(code: number): ShouldAssertion; 46 | json: ShouldAssertion; 47 | html: ShouldAssertion; 48 | throw(message?: any): ShouldAssertion; 49 | 50 | // aliases 51 | instanceOf(constructor: Function, description?: string): ShouldAssertion; 52 | throwError(message?: any): ShouldAssertion; 53 | lengthOf(n: number, description?: string): ShouldAssertion; 54 | key(key: string): ShouldAssertion; 55 | haveOwnProperty(name: string, description?: string): ShouldAssertion; 56 | greaterThan(n: number, description?: string): ShouldAssertion; 57 | lessThan(n: number, description?: string): ShouldAssertion; 58 | } 59 | 60 | interface ShouldInternal { 61 | // should.js's extras 62 | exist(actual: any): void; 63 | exists(actual: any): void; 64 | not: ShouldInternal; 65 | } 66 | 67 | interface Internal extends ShouldInternal { 68 | // node.js's assert functions 69 | fail(actual: any, expected: any, message: string, operator: string): void; 70 | assert(value: any, message: string): void; 71 | ok(value: any, message?: string): void; 72 | equal(actual: any, expected: any, message?: string): void; 73 | notEqual(actual: any, expected: any, message?: string): void; 74 | deepEqual(actual: any, expected: any, message?: string): void; 75 | notDeepEqual(actual: any, expected: any, message?: string): void; 76 | strictEqual(actual: any, expected: any, message?: string): void; 77 | notStrictEqual(actual: any, expected: any, message?: string): void; 78 | throws(block: any, error?: any, message?: string): void; 79 | doesNotThrow(block: any, message?: string): void; 80 | ifError(value: any): void; 81 | } 82 | 83 | declare module "should" { 84 | export = Internal; 85 | } 86 | -------------------------------------------------------------------------------- /ts-definitions/sinon/sinon-1.5.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Sinon 1.5 2 | // Project: http://sinonjs.org/ 3 | // Definitions by: William Sears 4 | // DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | interface SinonSpyCallApi { 7 | // Properties 8 | thisValue: any; 9 | args: any[]; 10 | exception: any; 11 | returnValue: any; 12 | 13 | // Methods 14 | calledOn(obj: any): boolean; 15 | calledWith(...args: any[]): boolean; 16 | calledWithExactly(...args: any[]): boolean; 17 | calledWithMatch(...args: SinonMatcher[]): boolean; 18 | notCalledWith(...args: any[]): boolean; 19 | notCalledWithMatch(...args: SinonMatcher[]): boolean; 20 | returned(value: any): boolean; 21 | threw(): boolean; 22 | threw(type: string): boolean; 23 | threw(obj: any): boolean; 24 | callArg(pos: number): void; 25 | callArgOn(pos: number, obj: any, ...args: any[]): void; 26 | callArgWith(pos: number, ...args: any[]): void; 27 | callArgOnWith(pos: number, obj: any, ...args: any[]): void; 28 | yield(...args: any[]): void; 29 | yieldOn(obj: any, ...args: any[]): void; 30 | yieldTo(property: string, ...args: any[]): void; 31 | yieldToOn(property: string, obj: any, ...args: any[]): void; 32 | } 33 | 34 | interface SinonSpyCall extends SinonSpyCallApi { 35 | calledBefore(call: SinonSpyCall): boolean; 36 | calledAfter(call: SinonSpyCall): boolean; 37 | calledWithNew(call: SinonSpyCall): boolean; 38 | } 39 | 40 | interface SinonSpy extends SinonSpyCallApi { 41 | // Properties 42 | callCount: number; 43 | called: boolean; 44 | notCalled: boolean; 45 | calledOnce: boolean; 46 | calledTwice: boolean; 47 | calledThrice: boolean; 48 | firstCall: SinonSpyCall; 49 | secondCall: SinonSpyCall; 50 | thirdCall: SinonSpyCall; 51 | lastCall: SinonSpyCall; 52 | thisValues: any[]; 53 | args: any[][]; 54 | exceptions: any[]; 55 | returnValues: any[]; 56 | 57 | // Methods 58 | (...args: any[]): any; 59 | calledBefore(anotherSpy: SinonSpy): boolean; 60 | calledAfter(anotherSpy: SinonSpy): boolean; 61 | calledWithNew(spy: SinonSpy): boolean; 62 | withArgs(...args: any[]): SinonSpy; 63 | alwaysCalledOn(obj: any); 64 | alwaysCalledWith(...args: any[]); 65 | alwaysCalledWithExactly(...args: any[]); 66 | alwaysCalledWithMatch(...args: SinonMatcher[]); 67 | neverCalledWith(...args: any[]); 68 | neverCalledWithMatch(...args: SinonMatcher[]); 69 | alwaysThrew(): boolean; 70 | alwaysThrew(type: string); 71 | alwaysThrew(obj: any); 72 | alwaysReturned(): boolean; 73 | invokeCallback(...args: any[]): void; 74 | getCall(n: number): SinonSpyCall; 75 | reset(): void; 76 | printf(format: string, ...args: any[]); 77 | restore(): void; 78 | } 79 | 80 | interface SinonSpyStatic { 81 | (): SinonSpy; 82 | (func: any): SinonSpy; 83 | (obj: any, method: string): SinonSpy; 84 | } 85 | 86 | interface SinonStatic { 87 | spy: SinonSpyStatic; 88 | } 89 | 90 | interface SinonStub extends SinonSpy { 91 | resetBehavior(): void; 92 | returns(obj: any): SinonStub; 93 | returnsArg(index: number): SinonStub; 94 | throws(type?: string): SinonStub; 95 | throws(obj: any): SinonStub; 96 | callsArg(index: number): SinonStub; 97 | callsArgOn(index: number, context: any): SinonStub; 98 | callsArgWith(index: number, ...args: any[]): SinonStub; 99 | callsArgOnWith(index: number, context: any, ...args: any[]): SinonStub; 100 | callsArgAsync(index: number): SinonStub; 101 | callsArgOnAsync(index: number, context: any): SinonStub; 102 | callsArgWithAsync(index: number, ...args: any[]): SinonStub; 103 | callsArgOnWithAsync(index: number, context: any, ...args: any[]): SinonStub; 104 | yields(...args: any[]): SinonStub; 105 | yieldsOn(context: any, ...args: any[]): SinonStub; 106 | yieldsTo(property: string, ...args: any[]): SinonStub; 107 | yieldsToOn(property: string, context: any, ...args: any[]): SinonStub; 108 | yieldsAsync(...args: any[]): SinonStub; 109 | yieldsOnAsync(context: any, ...args: any[]): SinonStub; 110 | yieldsToAsync(property: string, ...args: any[]): SinonStub; 111 | yieldsToOnAsync(property: string, context: any, ...args: any[]): SinonStub; 112 | withArgs(...args: any[]): SinonStub; 113 | } 114 | 115 | interface SinonStubStatic { 116 | (): SinonStub; 117 | (obj: any): SinonStub; 118 | (obj: any, method: string): SinonStub; 119 | (obj: any, method: string, func: any): SinonStub; 120 | } 121 | 122 | interface SinonStatic { 123 | stub: SinonStubStatic; 124 | } 125 | 126 | interface SinonExpectation { 127 | atLeast(n: number): SinonExpectation; 128 | atMost(n: number): SinonExpectation; 129 | never(): SinonExpectation; 130 | once(): SinonExpectation; 131 | twice(): SinonExpectation; 132 | thrice(): SinonExpectation; 133 | exactly(n: number): SinonExpectation; 134 | withArgs(...args: any[]): SinonExpectation; 135 | withExactArgs(...args: any[]): SinonExpectation; 136 | on(obj: any): SinonExpectation; 137 | verify(): SinonExpectation; 138 | restore(): void; 139 | } 140 | 141 | interface SinonExpectationStatic { 142 | create(methodName?: string): SinonExpectation; 143 | } 144 | 145 | interface SinonMock { 146 | expects(method: string): SinonExpectation; 147 | restore(): void; 148 | verify(): void; 149 | } 150 | 151 | interface SinonMockStatic { 152 | (): SinonExpectation; 153 | (obj: any): SinonMock; 154 | } 155 | 156 | interface SinonStatic { 157 | expectation: SinonExpectationStatic; 158 | mock: SinonMockStatic; 159 | } 160 | 161 | interface SinonFakeTimers { 162 | now: number; 163 | create(now: number): SinonFakeTimers; 164 | setTimeout(callback: (...args: any[]) => void , timeout: number, ...args: any[]): number; 165 | clearTimeout(id: number): void; 166 | setInterval(callback: (...args: any[]) => void , timeout: number, ...args: any[]): number; 167 | clearInterval(id: number): void; 168 | tick(ms: number): number; 169 | reset(): void; 170 | Date(): Date; 171 | Date(year: number): Date; 172 | Date(year: number, month: number): Date; 173 | Date(year: number, month: number, day: number): Date; 174 | Date(year: number, month: number, day: number, hour: number): Date; 175 | Date(year: number, month: number, day: number, hour: number, minute: number): Date; 176 | Date(year: number, month: number, day: number, hour: number, minute: number, second: number): Date; 177 | Date(year: number, month: number, day: number, hour: number, minute: number, second: number, ms: number): Date; 178 | restore(): void; 179 | } 180 | 181 | interface SinonFakeTimersStatic { 182 | (): SinonFakeTimers; 183 | (...timers: string[]): SinonFakeTimers; 184 | (now: number, ...timers: string[]): SinonFakeTimers; 185 | } 186 | 187 | interface SinonStatic { 188 | useFakeTimers: SinonFakeTimersStatic; 189 | clock: SinonFakeTimers; 190 | } 191 | 192 | interface SinonFakeXMLHttpRequest { 193 | // Properties 194 | onCreate: (xhr: SinonFakeXMLHttpRequest) => void; 195 | url: string; 196 | method: string; 197 | requestHeaders: any; 198 | requestBody: string; 199 | status: number; 200 | statusText: string; 201 | async: boolean; 202 | username: string; 203 | password: string; 204 | responseXML: Document; 205 | getResponseHeader(header: string): string; 206 | getAllResponseHeaders(): any; 207 | 208 | // Methods 209 | restore(): void; 210 | useFilters: boolean; 211 | addFilter(filter: (method, url, async, username, password) => boolean): void; 212 | setResponseHeaders(headers: any): void; 213 | setResponseBody(body: string): void; 214 | respond(status: number, headers: any, body: string): void; 215 | autoRespond(ms: number): void; 216 | } 217 | 218 | interface SinonFakeXMLHttpRequestStatic { 219 | (): SinonFakeXMLHttpRequest; 220 | } 221 | 222 | interface SinonStatic { 223 | useFakeXMLHttpRequest: SinonFakeXMLHttpRequestStatic; 224 | FakeXMLHttpRequest: SinonFakeXMLHttpRequest; 225 | } 226 | 227 | interface SinonFakeServer { 228 | // Properties 229 | autoRespond: boolean; 230 | autoRespondAfter: number; 231 | fakeHTTPMethods: boolean; 232 | getHTTPMethod: (request: SinonFakeXMLHttpRequest) => string; 233 | 234 | // Methods 235 | respondWith(body: string): void; 236 | respondWith(response: any[]): void; 237 | respondWith(fn: (xhr: SinonFakeXMLHttpRequest) => void ): void; 238 | respondWith(url: string, body: string): void; 239 | respondWith(url: string, response: any[]): void; 240 | respondWith(url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void; 241 | respondWith(method: string, url: string, body: string): void; 242 | respondWith(method: string, url: string, response: any[]): void; 243 | respondWith(method: string, url: string, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void; 244 | respondWith(url: RegExp, body: string): void; 245 | respondWith(url: RegExp, response: any[]): void; 246 | respondWith(url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void; 247 | respondWith(method: string, url: RegExp, body: string): void; 248 | respondWith(method: string, url: RegExp, response: any[]): void; 249 | respondWith(method: string, url: RegExp, fn: (xhr: SinonFakeXMLHttpRequest) => void ): void; 250 | respond(): void; 251 | restore(): void; 252 | } 253 | 254 | interface SinonFakeServerStatic { 255 | create(): SinonFakeServer; 256 | } 257 | 258 | interface SinonStatic { 259 | fakeServer: SinonFakeServerStatic; 260 | fakeServerWithClock: SinonFakeServerStatic; 261 | } 262 | 263 | interface SinonExposeOptions { 264 | prefix?: string; 265 | includeFail?: boolean; 266 | } 267 | 268 | interface SinonAssert { 269 | // Properties 270 | failException: string; 271 | fail: (message?: string) => void; // Overridable 272 | pass: (assertion: any) => void; // Overridable 273 | 274 | // Methods 275 | notCalled(spy: SinonSpy): void; 276 | called(spy: SinonSpy): void; 277 | calledOnce(spy: SinonSpy): void; 278 | calledTwice(spy: SinonSpy): void; 279 | calledThrice(spy: SinonSpy): void; 280 | callCount(spy: SinonSpy, count: number): void; 281 | callOrder(...spies: SinonSpy[]): void; 282 | calledOn(spy: SinonSpy, obj: any): void; 283 | alwaysCalledOn(spy: SinonSpy, obj: any): void; 284 | calledWith(spy: SinonSpy, ...args: any[]): void; 285 | alwaysCalledWith(spy: SinonSpy, ...args: any[]): void; 286 | neverCalledWith(spy: SinonSpy, ...args: any[]): void; 287 | calledWithExactly(spy: SinonSpy, ...args: any[]): void; 288 | alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void; 289 | calledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; 290 | alwaysCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; 291 | neverCalledWithMatch(spy: SinonSpy, ...args: SinonMatcher[]): void; 292 | threw(spy: SinonSpy): void; 293 | threw(spy: SinonSpy, exception: string): void; 294 | threw(spy: SinonSpy, exception: any): void; 295 | alwaysThrew(spy: SinonSpy): void; 296 | alwaysThrew(spy: SinonSpy, exception: string): void; 297 | alwaysThrew(spy: SinonSpy, exception: any): void; 298 | expose(obj: any, options?: SinonExposeOptions): void; 299 | } 300 | 301 | interface SinonStatic { 302 | assert: SinonAssert; 303 | } 304 | 305 | interface SinonMatcher { 306 | and(expr: SinonMatcher): SinonMatcher; 307 | or(expr: SinonMatcher): SinonMatcher; 308 | } 309 | 310 | interface SinonMatch { 311 | (value: number): SinonMatcher; 312 | (value: string): SinonMatcher; 313 | (expr: RegExp): SinonMatcher; 314 | (obj: any): SinonMatcher; 315 | (callback: (value: any) => boolean): SinonMatcher; 316 | any: SinonMatcher; 317 | defined: SinonMatcher; 318 | truthy: SinonMatcher; 319 | falsy: SinonMatcher; 320 | bool: SinonMatcher; 321 | number: SinonMatcher; 322 | string: SinonMatcher; 323 | object: SinonMatcher; 324 | func: SinonMatcher; 325 | array: SinonMatcher; 326 | regexp: SinonMatcher; 327 | date: SinonMatcher; 328 | same(obj: any): SinonMatcher; 329 | typeOf(type: string): SinonMatcher; 330 | instanceOf(type: any): SinonMatcher; 331 | has(property: string, expect?: any): SinonMatcher; 332 | hasOwn(property: string, expect?: any): SinonMatcher; 333 | } 334 | 335 | interface SinonStatic { 336 | match: SinonMatch; 337 | } 338 | 339 | interface SinonSandboxConfig { 340 | injectInto?: any; 341 | properties?: string[]; 342 | useFakeTimers?: any; 343 | useFakeServer?: any; 344 | } 345 | 346 | interface SinonSandbox { 347 | clock: SinonFakeTimers; 348 | requests: SinonFakeXMLHttpRequest; 349 | server: SinonFakeServer; 350 | spy(): SinonSpy; 351 | stub(): SinonStub; 352 | mock(): SinonMock; 353 | useFakeTimers: SinonFakeTimers; 354 | useFakeXMLHttpRequest: SinonFakeXMLHttpRequest; 355 | restore(): void; 356 | } 357 | 358 | interface SinonSandboxStatic { 359 | create(): SinonSandbox; 360 | create(config: SinonSandboxConfig): SinonSandbox; 361 | } 362 | 363 | interface SinonStatic { 364 | sandbox: SinonSandboxStatic; 365 | } 366 | 367 | interface SinonTestConfig { 368 | injectIntoThis?: boolean; 369 | injectInto?: any; 370 | properties?: string[]; 371 | useFakeTimers?: boolean; 372 | useFakeServer?: boolean; 373 | } 374 | 375 | interface SinonTestWrapper extends SinonSandbox { 376 | (...args: any[]): any; 377 | } 378 | 379 | interface SinonStatic { 380 | config: SinonTestConfig; 381 | test(fn: (...args: any[]) => any): SinonTestWrapper; 382 | testCase(tests: any): any; 383 | } 384 | 385 | // Utility overridables 386 | interface SinonStatic { 387 | format: (obj: any) => string; 388 | log: (message: string) => void; 389 | } 390 | 391 | declare var sinon: SinonStatic; 392 | -------------------------------------------------------------------------------- /ts-definitions/superagent/superagent.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for SuperAgent 0.15.4 2 | // Project: https://github.com/visionmedia/superagent 3 | // Definitions by: Alex Varju 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare module "superagent" { 9 | export interface Response { 10 | text: string; 11 | body: any; 12 | files: any; 13 | header: any; 14 | type: string; 15 | charset: string; 16 | status: number; 17 | statusType: number; 18 | info: boolean; 19 | ok: boolean; 20 | redirect: boolean; 21 | clientError: boolean; 22 | serverError: boolean; 23 | error: any; 24 | accepted: boolean; 25 | noContent: boolean; 26 | badRequest: boolean; 27 | unauthorized: boolean; 28 | notAcceptable: boolean; 29 | notFound: boolean; 30 | forbidden: boolean; 31 | get(header: string): string; 32 | } 33 | 34 | export interface Request { 35 | attach(field: string, file: string, filename: string): Request; 36 | redirects(n: number): Request; 37 | part(): Request; 38 | set(field: string, val: string): Request; 39 | set(field: Object): Request; 40 | get(field: string): string; 41 | type(val: string): Request; 42 | query(val: Object): Request; 43 | send(data: string): Request; 44 | send(data: Object): Request; 45 | write(data: string, encoding: string): boolean; 46 | write(data: NodeBuffer, encoding: string): boolean; 47 | pipe(stream: WritableStream, options?: Object): WritableStream; 48 | buffer(val: boolean): Request; 49 | timeout(ms: number): Request; 50 | clearTimeout(): Request; 51 | abort(): void; 52 | auth(user: string, name: string): Request; 53 | field(name: string, val: string): Request; 54 | end(callback?: (err: Error, res: Response) => void): Request; 55 | } 56 | 57 | export interface Agent { 58 | get(url: string, callback?: (err: Error, res: Response) => void): Request; 59 | post(url: string, callback?: (err: Error, res: Response) => void): Request; 60 | put(url: string, callback?: (err: Error, res: Response) => void): Request; 61 | head(url: string, callback?: (err: Error, res: Response) => void): Request; 62 | del(url: string, callback?: (err: Error, res: Response) => void): Request; 63 | options(url: string, callback?: (err: Error, res: Response) => void): Request; 64 | trace(url: string, callback?: (err: Error, res: Response) => void): Request; 65 | copy(url: string, callback?: (err: Error, res: Response) => void): Request; 66 | lock(url: string, callback?: (err: Error, res: Response) => void): Request; 67 | mkcol(url: string, callback?: (err: Error, res: Response) => void): Request; 68 | move(url: string, callback?: (err: Error, res: Response) => void): Request; 69 | propfind(url: string, callback?: (err: Error, res: Response) => void): Request; 70 | proppatch(url: string, callback?: (err: Error, res: Response) => void): Request; 71 | unlock(url: string, callback?: (err: Error, res: Response) => void): Request; 72 | report(url: string, callback?: (err: Error, res: Response) => void): Request; 73 | mkactivity(url: string, callback?: (err: Error, res: Response) => void): Request; 74 | checkout(url: string, callback?: (err: Error, res: Response) => void): Request; 75 | merge(url: string, callback?: (err: Error, res: Response) => void): Request; 76 | //m-search(url: string, callback?: (err: Error, res: Response) => void): Request; 77 | notify(url: string, callback?: (err: Error, res: Response) => void): Request; 78 | subscribe(url: string, callback?: (err: Error, res: Response) => void): Request; 79 | unsubscribe(url: string, callback?: (err: Error, res: Response) => void): Request; 80 | patch(url: string, callback?: (err: Error, res: Response) => void): Request; 81 | parse(fn: Function): Request; 82 | } 83 | 84 | export function agent(): Agent; 85 | } 86 | -------------------------------------------------------------------------------- /ts-definitions/supertest/supertest.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for SuperTest 0.8.0 2 | // Project: https://github.com/visionmedia/supertest 3 | // Definitions by: Alex Varju 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare module "supertest" { 9 | import superagent = require('superagent'); 10 | 11 | module supertest { 12 | interface Test extends superagent.Request { 13 | url: string; 14 | serverAddress(app: any, path: string): string; 15 | expect(status: number, callback?: (err: Error, res: superagent.Response) => void): Test; 16 | expect(status: number, body: string, callback?: (err: Error, res: superagent.Response) => void): Test; 17 | expect(body: string, callback?: (err: Error, res: superagent.Response) => void): Test; 18 | expect(body: RegExp, callback?: (err: Error, res: superagent.Response) => void): Test; 19 | expect(body: Object, callback?: (err: Error, res: superagent.Response) => void): Test; 20 | expect(field: string, val: string, callback?: (err: Error, res: superagent.Response) => void): Test; 21 | expect(field: string, val: RegExp, callback?: (err: Error, res: superagent.Response) => void): Test; 22 | } 23 | 24 | interface SuperTest { 25 | get(url: string): Test; 26 | post(url: string): Test; 27 | put(url: string): Test; 28 | head(url: string): Test; 29 | del(url: string): Test; 30 | options(url: string): Test; 31 | trace(url: string): Test; 32 | copy(url: string): Test; 33 | lock(url: string): Test; 34 | mkcol(url: string): Test; 35 | move(url: string): Test; 36 | propfind(url: string): Test; 37 | proppatch(url: string): Test; 38 | unlock(url: string): Test; 39 | report(url: string): Test; 40 | mkactivity(url: string): Test; 41 | checkout(url: string): Test; 42 | merge(url: string): Test; 43 | //m-search(url: string): Test; 44 | notify(url: string): Test; 45 | subscribe(url: string): Test; 46 | unsubscribe(url: string): Test; 47 | patch(url: string): Test; 48 | } 49 | } 50 | 51 | function supertest(app: any): supertest.SuperTest; 52 | export = supertest; 53 | } 54 | --------------------------------------------------------------------------------