├── .gitignore ├── LICENSE ├── README.md ├── generators └── app │ ├── index.js │ └── templates │ ├── Gruntfile.js │ ├── _Dockerfile │ ├── _package_grunt.json │ ├── _package_gulp.json │ ├── app.ts │ ├── bin │ └── www │ ├── fixtures │ ├── data.ts │ └── load.ts │ ├── gulpfile.js │ ├── public │ └── stylesheets │ │ └── style.css │ ├── routes │ └── index.ts │ ├── tsd.json │ ├── typings │ ├── express │ │ └── express.d.ts │ ├── mime │ │ └── mime.d.ts │ ├── node │ │ └── node.d.ts │ ├── q │ │ └── Q.d.ts │ ├── serve-static │ │ └── serve-static.d.ts │ └── tsd.d.ts │ └── views │ ├── error.hbs │ ├── index.hbs │ └── layout.hbs └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Andrew Korolev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # generator-express-typescript 2 | [Yeoman](http://yeoman.io) generator for express.js projects written in TypeScript. 3 | 4 | ## What's in the box 5 | 6 | This generator creates project with some fancy tools onboard: 7 | 8 | 1. [Express.js](http://expressjs.com) - simple nodejs web framework 9 | 2. [TypeScript](https://github.com/Microsoft/TypeScript) - strongly-typed version of ES6 10 | 3. [tsd](https://github.com/DefinitelyTyped/tsd) - tool for managing TypeScript definitions for JS libraries 11 | 4. [grunt](http://gruntjs.com) or [gulp](http://gulpjs.com) - build tool 12 | 5. [Dockerfile](https://www.docker.com) - to run your project as a Docker container (optional) 13 | 14 | ## Getting Started 15 | 16 | First, install yeoman (if you haven't already) 17 | 18 | ``` 19 | $ npm install -g yo 20 | ``` 21 | 22 | To install generator-express-typescript from npm, run: 23 | 24 | ``` 25 | $ npm install -g generator-express-typescript 26 | ``` 27 | 28 | Finally, initiate the generator and answer some simple questions: 29 | 30 | ``` 31 | $ yo express-typescript 32 | ``` 33 | 34 | Notice, that you should have either grunt or gulp installed globally before launching this generator 35 | -------------------------------------------------------------------------------- /generators/app/index.js: -------------------------------------------------------------------------------- 1 | var generators = require('yeoman-generator'); 2 | var path = require('path'); 3 | var _ = require('lodash'); 4 | 5 | module.exports = generators.Base.extend({ 6 | initializing: function () { 7 | var generator = this; 8 | var done = this.async(); 9 | 10 | this.log('Running Express.js + TypeScript generator') 11 | 12 | this.prompt([ 13 | { 14 | type: 'list', 15 | name: 'builder', 16 | message: 'grunt or gulp?', 17 | choices: ['grunt', 'gulp'] 18 | }, 19 | { 20 | type: 'confirm', 21 | name: 'docker', 22 | message: 'create Dockerfile?' 23 | } 24 | ], function (answers) { 25 | generator.answers = answers; 26 | done(); 27 | }); 28 | }, 29 | 30 | writing: { 31 | dir: function () { 32 | this.directory('bin', 'bin'); 33 | this.directory('public', 'public'); 34 | this.directory('routes', 'routes'); 35 | this.directory('typings', 'typings'); 36 | this.directory('views', 'views'); 37 | this.directory('fixtures', 'fixtures'); 38 | }, 39 | app: function () { 40 | this.fs.copyTpl( 41 | this.templatePath('_package_' + this.answers.builder + '.json'), 42 | this.destinationPath('package.json'), 43 | { appname: _.kebabCase(path.basename(process.cwd())) } 44 | ); 45 | 46 | if (this.answers.docker) { 47 | this.fs.copyTpl( 48 | this.templatePath('_Dockerfile'), 49 | this.destinationPath('Dockerfile'), 50 | { builder: this.answers.builder } 51 | ); 52 | } 53 | }, 54 | projectfiles: function () { 55 | var generator = this; 56 | var files = ['app.ts', 'tsd.json']; 57 | 58 | if (this.answers.builder === 'grunt') { 59 | files.push('Gruntfile.js') 60 | } 61 | 62 | if (this.answers.builder === 'gulp') { 63 | files.push('gulpfile.js') 64 | } 65 | 66 | _.each( 67 | files, 68 | function (name) { 69 | generator.fs.copy( 70 | generator.templatePath(name), 71 | generator.destinationPath(name) 72 | ) 73 | } 74 | ); 75 | } 76 | }, 77 | 78 | install: { 79 | npmInstall: function () { 80 | var generator = this; 81 | generator.npmInstall(null, {skipInstall: this.options['skip-install']}, function () { 82 | generator.spawnCommandSync('tsd', ['install']); //tsd install --save node 83 | 84 | if (generator.answers.builder === 'grunt') { 85 | generator.spawnCommandSync('grunt', ['ts']); 86 | } else { 87 | generator.spawnCommandSync('gulp', ['ts']); 88 | } 89 | }); 90 | } 91 | } 92 | 93 | 94 | }); 95 | -------------------------------------------------------------------------------- /generators/app/templates/Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | grunt.initConfig({ 3 | ts: { 4 | default : { 5 | src: ["**/*.ts", "!node_modules/**", '!bin/**'], 6 | options: { 7 | module: 'commonjs' 8 | } 9 | } 10 | }, 11 | clean: { 12 | all: ['**/*.js', '**/*.js.map', '!node_modules/**', '!Gruntfile.js', '!bin/**', 'test/**/*.js', 'test/**/*.js.map'] 13 | } 14 | }); 15 | grunt.loadNpmTasks("grunt-ts"); 16 | grunt.loadNpmTasks('grunt-contrib-clean'); 17 | }; 18 | -------------------------------------------------------------------------------- /generators/app/templates/_Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nodesource/node:4.0 2 | 3 | RUN npm install -g tsd 4 | RUN npm install -g <%= builder %>-cli 5 | ADD package.json package.json 6 | ADD tsd.json tsd.json 7 | RUN npm install 8 | RUN tsd install 9 | 10 | ADD . . 11 | RUN <%= builder %> ts 12 | 13 | EXPOSE 3000 14 | 15 | CMD ["node", "bin/www"] 16 | -------------------------------------------------------------------------------- /generators/app/templates/_package_grunt.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= appname %>", 3 | "scripts": { 4 | "start": "node bin/www" 5 | }, 6 | "version": "0.0.0", 7 | "description": "", 8 | "license": "", 9 | "repository": "", 10 | "author": "", 11 | "keywords": [ 12 | "" 13 | ], 14 | "dependencies": { 15 | "body-parser": "~1.13.2", 16 | "cookie-parser": "~1.3.5", 17 | "debug": "~2.2.0", 18 | "express": "~4.13.1", 19 | "grunt": "^0.4.5", 20 | "grunt-contrib-clean": "^0.7.0", 21 | "grunt-ts": "^5.2.0", 22 | "hbs": "~3.1.0", 23 | "morgan": "~1.6.1", 24 | "q": "^1.4.1", 25 | "serve-favicon": "~2.3.0", 26 | "tsd": "^0.6.5" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /generators/app/templates/_package_gulp.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= appname %>", 3 | "scripts": { 4 | "start": "node bin/www" 5 | }, 6 | "version": "0.0.0", 7 | "description": "", 8 | "license": "", 9 | "repository": "", 10 | "author": "", 11 | "keywords": [ 12 | "" 13 | ], 14 | "dependencies": { 15 | "body-parser": "~1.13.2", 16 | "cookie-parser": "~1.3.5", 17 | "debug": "~2.2.0", 18 | "express": "~4.13.1", 19 | "gulp": "^3.9.0", 20 | "gulp-clean": "^0.3.1", 21 | "gulp-develop-server": "^0.5.0", 22 | "gulp-mocha": "^2.2.0", 23 | "gulp-typescript": "^2.10.0", 24 | "hbs": "~3.1.0", 25 | "morgan": "~1.6.1", 26 | "q": "^1.4.1", 27 | "serve-favicon": "~2.3.0", 28 | "superagent": "^1.7.1", 29 | "tsd": "^0.6.5", 30 | "underscore": "^1.8.3" 31 | }, 32 | "devDependencies": { 33 | "assert": "^1.3.0", 34 | "mongoose": "^4.3.6", 35 | "pow-mongodb-fixtures": "^0.13.0", 36 | "should": "^8.1.1", 37 | "should-http": "0.0.4", 38 | "supertest": "^1.1.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /generators/app/templates/app.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import {Request, Response} from "express"; 4 | var express = require('express'); 5 | var path = require('path'); 6 | var favicon = require('serve-favicon'); 7 | var logger = require('morgan'); 8 | var cookieParser = require('cookie-parser'); 9 | var bodyParser = require('body-parser'); 10 | 11 | var routes = require('./routes/index'); 12 | var app = express(); 13 | 14 | // view engine setup 15 | app.set('views', path.join(__dirname, 'views')); 16 | app.set('view engine', 'hbs'); 17 | 18 | // uncomment after placing your favicon in /public 19 | //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 20 | app.use(logger('dev')); 21 | app.use(bodyParser.json()); 22 | app.use(bodyParser.urlencoded({ extended: false })); 23 | app.use(cookieParser()); 24 | app.use(express.static(path.join(__dirname, 'public'))); 25 | 26 | app.use('/', routes); 27 | 28 | // catch 404 and forward to error handler 29 | app.use((req: Request, res: Response, next: Function) => { 30 | var err: any = new Error('Not Found'); 31 | err.status = 404; 32 | next(err); 33 | }); 34 | 35 | // error handlers 36 | 37 | // development error handler 38 | // will print stacktrace 39 | if (app.get('env') === 'development') { 40 | app.use(function(err: any, req: Request, res: Response, next: Function) { 41 | res.status(err.status || 500); 42 | res.render('error', { 43 | message: err.message, 44 | error: err 45 | }); 46 | }); 47 | } 48 | 49 | // production error handler 50 | // no stacktraces leaked to user 51 | app.use(function(err: any, req: Request, res: Response, next: Function) { 52 | res.status(err.status || 500); 53 | res.render('error', { 54 | message: err.message, 55 | error: {} 56 | }); 57 | }); 58 | 59 | 60 | module.exports = app; 61 | -------------------------------------------------------------------------------- /generators/app/templates/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('mosway:server'); 9 | var http = require('http'); 10 | 11 | /** 12 | * Get port from environment and store in Express. 13 | */ 14 | 15 | var port = normalizePort(process.env.PORT || '3000'); 16 | app.set('port', port); 17 | 18 | /** 19 | * Create HTTP server. 20 | */ 21 | 22 | var server = http.createServer(app); 23 | 24 | /** 25 | * Listen on provided port, on all network interfaces. 26 | */ 27 | 28 | server.listen(port); 29 | server.on('error', onError); 30 | server.on('listening', onListening); 31 | 32 | /** 33 | * Normalize a port into a number, string, or false. 34 | */ 35 | 36 | function normalizePort(val) { 37 | var port = parseInt(val, 10); 38 | 39 | if (isNaN(port)) { 40 | // named pipe 41 | return val; 42 | } 43 | 44 | if (port >= 0) { 45 | // port number 46 | return port; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | /** 53 | * Event listener for HTTP server "error" event. 54 | */ 55 | 56 | function onError(error) { 57 | if (error.syscall !== 'listen') { 58 | throw error; 59 | } 60 | 61 | var bind = typeof port === 'string' 62 | ? 'Pipe ' + port 63 | : 'Port ' + port; 64 | 65 | // handle specific listen errors with friendly messages 66 | switch (error.code) { 67 | case 'EACCES': 68 | console.error(bind + ' requires elevated privileges'); 69 | process.exit(1); 70 | break; 71 | case 'EADDRINUSE': 72 | console.error(bind + ' is already in use'); 73 | process.exit(1); 74 | break; 75 | default: 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Event listener for HTTP server "listening" event. 82 | */ 83 | 84 | function onListening() { 85 | var addr = server.address(); 86 | var bind = typeof addr === 'string' 87 | ? 'pipe ' + addr 88 | : 'port ' + addr.port; 89 | debug('Listening on ' + bind); 90 | } 91 | -------------------------------------------------------------------------------- /generators/app/templates/fixtures/data.ts: -------------------------------------------------------------------------------- 1 | export const data = [ 2 | { 3 | test: "Test" 4 | } 5 | ]; 6 | -------------------------------------------------------------------------------- /generators/app/templates/fixtures/load.ts: -------------------------------------------------------------------------------- 1 | let fixtures = require('pow-mongodb-fixtures').connect('test'); 2 | 3 | import {data} from "./data"; 4 | 5 | export function loadData(cb: any) { 6 | fixtures.clearAndLoad({ 7 | test: data 8 | }, cb); 9 | } 10 | -------------------------------------------------------------------------------- /generators/app/templates/gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var ts = require('gulp-typescript'); 3 | var clean = require('gulp-clean'); 4 | var server = require('gulp-develop-server'); 5 | var mocha = require('gulp-mocha'); 6 | 7 | var serverTS = ["**/*.ts", "!node_modules/**", '!bin/**']; 8 | 9 | gulp.task('ts', ['clean'], function() { 10 | return gulp 11 | .src(serverTS, {base: './'}) 12 | .pipe(ts({ module: 'commonjs', noImplicitAny: true })) 13 | .pipe(gulp.dest('./')); 14 | }); 15 | 16 | gulp.task('clean', function () { 17 | return gulp 18 | .src([ 19 | 'app.js', 20 | '**/*.js', 21 | '**/*.js.map', 22 | '!node_modules/**', 23 | '!gulpfile.js', 24 | '!bin/**' 25 | ], {read: false}) 26 | .pipe(clean()) 27 | }); 28 | 29 | gulp.task('load:fixtures', function (cb) { 30 | var load = require('./fixtures/load'); 31 | return load.loadData(cb); 32 | }); 33 | 34 | gulp.task('server:start', ['ts'], function() { 35 | server.listen({path: 'bin/www'}, function(error) { 36 | console.log(error); 37 | }); 38 | }); 39 | 40 | gulp.task('server:restart', ['ts'], function() { 41 | server.restart(); 42 | }); 43 | 44 | gulp.task('default', ['server:start'], function() { 45 | gulp.watch(serverTS, ['server:restart']); 46 | }); 47 | 48 | gulp.task('test', ['ts', 'load:fixtures'], function() { 49 | return gulp 50 | .src('test/*.js', {read: false}) 51 | // wait for dev server to start properly :( 52 | //.pipe(wait(600)) 53 | .pipe(mocha()) 54 | .once('error', function () { 55 | process.exit(1); 56 | }) 57 | .once('end', function () { 58 | process.exit(); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /generators/app/templates/public/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 50px; 3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; 4 | } 5 | 6 | a { 7 | color: #00B7FF; 8 | } 9 | -------------------------------------------------------------------------------- /generators/app/templates/routes/index.ts: -------------------------------------------------------------------------------- 1 | /// 2 | import {Request, Response} from "express"; 3 | var express = require('express'); 4 | var router = express.Router(); 5 | 6 | /* GET home page. */ 7 | router.get('/', function(req: Request, res: Response, next: Function) { 8 | res.render('index', { title: 'Express' }) 9 | }); 10 | 11 | module.exports = router; 12 | -------------------------------------------------------------------------------- /generators/app/templates/tsd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v4", 3 | "repo": "borisyankov/DefinitelyTyped", 4 | "ref": "master", 5 | "path": "typings", 6 | "bundle": "typings/tsd.d.ts", 7 | "installed": { 8 | "serve-static/serve-static.d.ts": { 9 | "commit": "8ea42cd8bb11863ed6f242d67c502288ebc45a7b" 10 | }, 11 | "node/node.d.ts": { 12 | "commit": "a9680ac2efd3add0d38cd0331f30ad497d9dd1e0" 13 | }, 14 | "express/express.d.ts": { 15 | "commit": "8ea42cd8bb11863ed6f242d67c502288ebc45a7b" 16 | }, 17 | "mime/mime.d.ts": { 18 | "commit": "8ea42cd8bb11863ed6f242d67c502288ebc45a7b" 19 | }, 20 | "q/Q.d.ts": { 21 | "commit": "11322524f8db9cdb921427cad84cd22fe2d4f965" 22 | }, 23 | "mongoose/mongoose.d.ts": { 24 | "commit": "93bae1bb4c887c1375a4c1f0c3bb849ff06b8ac6" 25 | }, 26 | "underscore/underscore.d.ts": { 27 | "commit": "3a666d1bff92e944488c25599ec56a4937c17c4e" 28 | }, 29 | "mocha/mocha.d.ts": { 30 | "commit": "a9680ac2efd3add0d38cd0331f30ad497d9dd1e0" 31 | }, 32 | "should/should.d.ts": { 33 | "commit": "a9680ac2efd3add0d38cd0331f30ad497d9dd1e0" 34 | }, 35 | "superagent/superagent.d.ts": { 36 | "commit": "a9680ac2efd3add0d38cd0331f30ad497d9dd1e0" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /generators/app/templates/typings/express/express.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Express 4.x 2 | // Project: http://expressjs.com 3 | // Definitions by: Boris Yankov 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /* =================== USAGE =================== 7 | 8 | import * as express from "express"; 9 | var app = express(); 10 | 11 | =============================================== */ 12 | 13 | /// 14 | /// 15 | 16 | declare module Express { 17 | 18 | // These open interfaces may be extended in an application-specific manner via declaration merging. 19 | // See for example method-override.d.ts (https://github.com/borisyankov/DefinitelyTyped/blob/master/method-override/method-override.d.ts) 20 | export interface Request { } 21 | export interface Response { } 22 | export interface Application { } 23 | } 24 | 25 | 26 | declare module "express" { 27 | import * as http from "http"; 28 | import * as serveStatic from "serve-static"; 29 | 30 | function e(): e.Express; 31 | 32 | module e { 33 | interface IRoute { 34 | path: string; 35 | stack: any; 36 | all(...handler: RequestHandler[]): IRoute; 37 | get(...handler: RequestHandler[]): IRoute; 38 | post(...handler: RequestHandler[]): IRoute; 39 | put(...handler: RequestHandler[]): IRoute; 40 | delete(...handler: RequestHandler[]): IRoute; 41 | patch(...handler: RequestHandler[]): IRoute; 42 | options(...handler: RequestHandler[]): IRoute; 43 | head(...handler: RequestHandler[]): IRoute; 44 | } 45 | 46 | interface IRouterMatcher { 47 | (name: string, ...handlers: RequestHandler[]): T; 48 | (name: RegExp, ...handlers: RequestHandler[]): T; 49 | } 50 | 51 | interface IRouter extends RequestHandler { 52 | /** 53 | * Map the given param placeholder `name`(s) to the given callback(s). 54 | * 55 | * Parameter mapping is used to provide pre-conditions to routes 56 | * which use normalized placeholders. For example a _:user_id_ parameter 57 | * could automatically load a user's information from the database without 58 | * any additional code, 59 | * 60 | * The callback uses the samesignature as middleware, the only differencing 61 | * being that the value of the placeholder is passed, in this case the _id_ 62 | * of the user. Once the `next()` function is invoked, just like middleware 63 | * it will continue on to execute the route, or subsequent parameter functions. 64 | * 65 | * app.param('user_id', function(req, res, next, id){ 66 | * User.find(id, function(err, user){ 67 | * if (err) { 68 | * next(err); 69 | * } else if (user) { 70 | * req.user = user; 71 | * next(); 72 | * } else { 73 | * next(new Error('failed to load user')); 74 | * } 75 | * }); 76 | * }); 77 | * 78 | * @param name 79 | * @param fn 80 | */ 81 | param(name: string, handler: RequestParamHandler): T; 82 | param(name: string, matcher: RegExp): T; 83 | param(name: string, mapper: (param: any) => any): T; 84 | // Alternatively, you can pass only a callback, in which case you have the opportunity to alter the app.param() API 85 | param(callback: (name: string, matcher: RegExp) => RequestParamHandler): T; 86 | 87 | /** 88 | * Special-cased "all" method, applying the given route `path`, 89 | * middleware, and callback to _every_ HTTP method. 90 | * 91 | * @param path 92 | * @param fn 93 | */ 94 | all: IRouterMatcher; 95 | get: IRouterMatcher; 96 | post: IRouterMatcher; 97 | put: IRouterMatcher; 98 | delete: IRouterMatcher; 99 | patch: IRouterMatcher; 100 | options: IRouterMatcher; 101 | head: IRouterMatcher; 102 | 103 | route(path: string): IRoute; 104 | 105 | use(...handler: RequestHandler[]): T; 106 | use(handler: ErrorRequestHandler): T; 107 | use(path: string, ...handler: RequestHandler[]): T; 108 | use(path: string, handler: ErrorRequestHandler): T; 109 | use(path: string[], ...handler: RequestHandler[]): T; 110 | use(path: string[], handler: ErrorRequestHandler): T; 111 | use(path: RegExp, ...handler: RequestHandler[]): T; 112 | use(path: RegExp, handler: ErrorRequestHandler): T; 113 | use(path:string, router:Router): T; 114 | } 115 | 116 | export function Router(options?: any): Router; 117 | 118 | export interface Router extends IRouter {} 119 | 120 | interface CookieOptions { 121 | maxAge?: number; 122 | signed?: boolean; 123 | expires?: Date; 124 | httpOnly?: boolean; 125 | path?: string; 126 | domain?: string; 127 | secure?: boolean; 128 | } 129 | 130 | interface Errback { (err: Error): void; } 131 | 132 | interface Request extends http.ServerRequest, Express.Request { 133 | 134 | /** 135 | * Return request header. 136 | * 137 | * The `Referrer` header field is special-cased, 138 | * both `Referrer` and `Referer` are interchangeable. 139 | * 140 | * Examples: 141 | * 142 | * req.get('Content-Type'); 143 | * // => "text/plain" 144 | * 145 | * req.get('content-type'); 146 | * // => "text/plain" 147 | * 148 | * req.get('Something'); 149 | * // => undefined 150 | * 151 | * Aliased as `req.header()`. 152 | * 153 | * @param name 154 | */ 155 | get (name: string): string; 156 | 157 | header(name: string): string; 158 | 159 | headers: { [key: string]: string; }; 160 | 161 | /** 162 | * Check if the given `type(s)` is acceptable, returning 163 | * the best match when true, otherwise `undefined`, in which 164 | * case you should respond with 406 "Not Acceptable". 165 | * 166 | * The `type` value may be a single mime type string 167 | * such as "application/json", the extension name 168 | * such as "json", a comma-delimted list such as "json, html, text/plain", 169 | * or an array `["json", "html", "text/plain"]`. When a list 170 | * or array is given the _best_ match, if any is returned. 171 | * 172 | * Examples: 173 | * 174 | * // Accept: text/html 175 | * req.accepts('html'); 176 | * // => "html" 177 | * 178 | * // Accept: text/*, application/json 179 | * req.accepts('html'); 180 | * // => "html" 181 | * req.accepts('text/html'); 182 | * // => "text/html" 183 | * req.accepts('json, text'); 184 | * // => "json" 185 | * req.accepts('application/json'); 186 | * // => "application/json" 187 | * 188 | * // Accept: text/*, application/json 189 | * req.accepts('image/png'); 190 | * req.accepts('png'); 191 | * // => undefined 192 | * 193 | * // Accept: text/*;q=.5, application/json 194 | * req.accepts(['html', 'json']); 195 | * req.accepts('html, json'); 196 | * // => "json" 197 | */ 198 | accepts(type: string): string; 199 | 200 | accepts(type: string[]): string; 201 | 202 | /** 203 | * Check if the given `charset` is acceptable, 204 | * otherwise you should respond with 406 "Not Acceptable". 205 | * 206 | * @param charset 207 | */ 208 | acceptsCharset(charset: string): boolean; 209 | 210 | /** 211 | * Check if the given `lang` is acceptable, 212 | * otherwise you should respond with 406 "Not Acceptable". 213 | * 214 | * @param lang 215 | */ 216 | acceptsLanguage(lang: string): boolean; 217 | 218 | /** 219 | * Parse Range header field, 220 | * capping to the given `size`. 221 | * 222 | * Unspecified ranges such as "0-" require 223 | * knowledge of your resource length. In 224 | * the case of a byte range this is of course 225 | * the total number of bytes. If the Range 226 | * header field is not given `null` is returned, 227 | * `-1` when unsatisfiable, `-2` when syntactically invalid. 228 | * 229 | * NOTE: remember that ranges are inclusive, so 230 | * for example "Range: users=0-3" should respond 231 | * with 4 users when available, not 3. 232 | * 233 | * @param size 234 | */ 235 | range(size: number): any[]; 236 | 237 | /** 238 | * Return an array of Accepted media types 239 | * ordered from highest quality to lowest. 240 | */ 241 | accepted: MediaType[]; 242 | 243 | /** 244 | * Return an array of Accepted languages 245 | * ordered from highest quality to lowest. 246 | * 247 | * Examples: 248 | * 249 | * Accept-Language: en;q=.5, en-us 250 | * ['en-us', 'en'] 251 | */ 252 | acceptedLanguages: any[]; 253 | 254 | /** 255 | * Return an array of Accepted charsets 256 | * ordered from highest quality to lowest. 257 | * 258 | * Examples: 259 | * 260 | * Accept-Charset: iso-8859-5;q=.2, unicode-1-1;q=0.8 261 | * ['unicode-1-1', 'iso-8859-5'] 262 | */ 263 | acceptedCharsets: any[]; 264 | 265 | /** 266 | * Return the value of param `name` when present or `defaultValue`. 267 | * 268 | * - Checks route placeholders, ex: _/user/:id_ 269 | * - Checks body params, ex: id=12, {"id":12} 270 | * - Checks query string params, ex: ?id=12 271 | * 272 | * To utilize request bodies, `req.body` 273 | * should be an object. This can be done by using 274 | * the `connect.bodyParser()` middleware. 275 | * 276 | * @param name 277 | * @param defaultValue 278 | */ 279 | param(name: string, defaultValue?: any): string; 280 | 281 | /** 282 | * Check if the incoming request contains the "Content-Type" 283 | * header field, and it contains the give mime `type`. 284 | * 285 | * Examples: 286 | * 287 | * // With Content-Type: text/html; charset=utf-8 288 | * req.is('html'); 289 | * req.is('text/html'); 290 | * req.is('text/*'); 291 | * // => true 292 | * 293 | * // When Content-Type is application/json 294 | * req.is('json'); 295 | * req.is('application/json'); 296 | * req.is('application/*'); 297 | * // => true 298 | * 299 | * req.is('html'); 300 | * // => false 301 | * 302 | * @param type 303 | */ 304 | is(type: string): boolean; 305 | 306 | /** 307 | * Return the protocol string "http" or "https" 308 | * when requested with TLS. When the "trust proxy" 309 | * setting is enabled the "X-Forwarded-Proto" header 310 | * field will be trusted. If you're running behind 311 | * a reverse proxy that supplies https for you this 312 | * may be enabled. 313 | */ 314 | protocol: string; 315 | 316 | /** 317 | * Short-hand for: 318 | * 319 | * req.protocol == 'https' 320 | */ 321 | secure: boolean; 322 | 323 | /** 324 | * Return the remote address, or when 325 | * "trust proxy" is `true` return 326 | * the upstream addr. 327 | */ 328 | ip: string; 329 | 330 | /** 331 | * When "trust proxy" is `true`, parse 332 | * the "X-Forwarded-For" ip address list. 333 | * 334 | * For example if the value were "client, proxy1, proxy2" 335 | * you would receive the array `["client", "proxy1", "proxy2"]` 336 | * where "proxy2" is the furthest down-stream. 337 | */ 338 | ips: string[]; 339 | 340 | /** 341 | * Return subdomains as an array. 342 | * 343 | * Subdomains are the dot-separated parts of the host before the main domain of 344 | * the app. By default, the domain of the app is assumed to be the last two 345 | * parts of the host. This can be changed by setting "subdomain offset". 346 | * 347 | * For example, if the domain is "tobi.ferrets.example.com": 348 | * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`. 349 | * If "subdomain offset" is 3, req.subdomains is `["tobi"]`. 350 | */ 351 | subdomains: string[]; 352 | 353 | /** 354 | * Short-hand for `url.parse(req.url).pathname`. 355 | */ 356 | path: string; 357 | 358 | /** 359 | * Parse the "Host" header field hostname. 360 | */ 361 | hostname: string; 362 | 363 | /** 364 | * @deprecated Use hostname instead. 365 | */ 366 | host: string; 367 | 368 | /** 369 | * Check if the request is fresh, aka 370 | * Last-Modified and/or the ETag 371 | * still match. 372 | */ 373 | fresh: boolean; 374 | 375 | /** 376 | * Check if the request is stale, aka 377 | * "Last-Modified" and / or the "ETag" for the 378 | * resource has changed. 379 | */ 380 | stale: boolean; 381 | 382 | /** 383 | * Check if the request was an _XMLHttpRequest_. 384 | */ 385 | xhr: boolean; 386 | 387 | //body: { username: string; password: string; remember: boolean; title: string; }; 388 | body: any; 389 | 390 | //cookies: { string; remember: boolean; }; 391 | cookies: any; 392 | 393 | method: string; 394 | 395 | params: any; 396 | 397 | user: any; 398 | 399 | authenticatedUser: any; 400 | 401 | /** 402 | * Clear cookie `name`. 403 | * 404 | * @param name 405 | * @param options 406 | */ 407 | clearCookie(name: string, options?: any): Response; 408 | 409 | query: any; 410 | 411 | route: any; 412 | 413 | signedCookies: any; 414 | 415 | originalUrl: string; 416 | 417 | url: string; 418 | 419 | baseUrl: string; 420 | 421 | app: Application; 422 | } 423 | 424 | interface MediaType { 425 | value: string; 426 | quality: number; 427 | type: string; 428 | subtype: string; 429 | } 430 | 431 | interface Send { 432 | (status: number, body?: any): Response; 433 | (body: any): Response; 434 | } 435 | 436 | interface Response extends http.ServerResponse, Express.Response { 437 | /** 438 | * Set status `code`. 439 | * 440 | * @param code 441 | */ 442 | status(code: number): Response; 443 | 444 | /** 445 | * Set the response HTTP status code to `statusCode` and send its string representation as the response body. 446 | * @link http://expressjs.com/4x/api.html#res.sendStatus 447 | * 448 | * Examples: 449 | * 450 | * res.sendStatus(200); // equivalent to res.status(200).send('OK') 451 | * res.sendStatus(403); // equivalent to res.status(403).send('Forbidden') 452 | * res.sendStatus(404); // equivalent to res.status(404).send('Not Found') 453 | * res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error') 454 | * 455 | * @param code 456 | */ 457 | sendStatus(code: number): Response; 458 | 459 | /** 460 | * Set Link header field with the given `links`. 461 | * 462 | * Examples: 463 | * 464 | * res.links({ 465 | * next: 'http://api.example.com/users?page=2', 466 | * last: 'http://api.example.com/users?page=5' 467 | * }); 468 | * 469 | * @param links 470 | */ 471 | links(links: any): Response; 472 | 473 | /** 474 | * Send a response. 475 | * 476 | * Examples: 477 | * 478 | * res.send(new Buffer('wahoo')); 479 | * res.send({ some: 'json' }); 480 | * res.send('

some html

'); 481 | * res.send(404, 'Sorry, cant find that'); 482 | * res.send(404); 483 | */ 484 | send: Send; 485 | 486 | /** 487 | * Send JSON response. 488 | * 489 | * Examples: 490 | * 491 | * res.json(null); 492 | * res.json({ user: 'tj' }); 493 | * res.json(500, 'oh noes!'); 494 | * res.json(404, 'I dont have that'); 495 | */ 496 | json: Send; 497 | 498 | /** 499 | * Send JSON response with JSONP callback support. 500 | * 501 | * Examples: 502 | * 503 | * res.jsonp(null); 504 | * res.jsonp({ user: 'tj' }); 505 | * res.jsonp(500, 'oh noes!'); 506 | * res.jsonp(404, 'I dont have that'); 507 | */ 508 | jsonp: Send; 509 | 510 | /** 511 | * Transfer the file at the given `path`. 512 | * 513 | * Automatically sets the _Content-Type_ response header field. 514 | * The callback `fn(err)` is invoked when the transfer is complete 515 | * or when an error occurs. Be sure to check `res.sentHeader` 516 | * if you wish to attempt responding, as the header and some data 517 | * may have already been transferred. 518 | * 519 | * Options: 520 | * 521 | * - `maxAge` defaulting to 0 (can be string converted by `ms`) 522 | * - `root` root directory for relative filenames 523 | * - `headers` object of headers to serve with file 524 | * - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them 525 | * 526 | * Other options are passed along to `send`. 527 | * 528 | * Examples: 529 | * 530 | * The following example illustrates how `res.sendFile()` may 531 | * be used as an alternative for the `static()` middleware for 532 | * dynamic situations. The code backing `res.sendFile()` is actually 533 | * the same code, so HTTP cache support etc is identical. 534 | * 535 | * app.get('/user/:uid/photos/:file', function(req, res){ 536 | * var uid = req.params.uid 537 | * , file = req.params.file; 538 | * 539 | * req.user.mayViewFilesFrom(uid, function(yes){ 540 | * if (yes) { 541 | * res.sendFile('/uploads/' + uid + '/' + file); 542 | * } else { 543 | * res.send(403, 'Sorry! you cant see that.'); 544 | * } 545 | * }); 546 | * }); 547 | * 548 | * @api public 549 | */ 550 | sendFile(path: string): void; 551 | sendFile(path: string, options: any): void; 552 | sendFile(path: string, fn: Errback): void; 553 | sendFile(path: string, options: any, fn: Errback): void; 554 | 555 | /** 556 | * @deprecated Use sendFile instead. 557 | */ 558 | sendfile(path: string): void; 559 | /** 560 | * @deprecated Use sendFile instead. 561 | */ 562 | sendfile(path: string, options: any): void; 563 | /** 564 | * @deprecated Use sendFile instead. 565 | */ 566 | sendfile(path: string, fn: Errback): void; 567 | /** 568 | * @deprecated Use sendFile instead. 569 | */ 570 | sendfile(path: string, options: any, fn: Errback): void; 571 | 572 | /** 573 | * Transfer the file at the given `path` as an attachment. 574 | * 575 | * Optionally providing an alternate attachment `filename`, 576 | * and optional callback `fn(err)`. The callback is invoked 577 | * when the data transfer is complete, or when an error has 578 | * ocurred. Be sure to check `res.headerSent` if you plan to respond. 579 | * 580 | * This method uses `res.sendfile()`. 581 | */ 582 | download(path: string): void; 583 | download(path: string, filename: string): void; 584 | download(path: string, fn: Errback): void; 585 | download(path: string, filename: string, fn: Errback): void; 586 | 587 | /** 588 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 589 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 590 | * 591 | * Examples: 592 | * 593 | * res.type('.html'); 594 | * res.type('html'); 595 | * res.type('json'); 596 | * res.type('application/json'); 597 | * res.type('png'); 598 | * 599 | * @param type 600 | */ 601 | contentType(type: string): Response; 602 | 603 | /** 604 | * Set _Content-Type_ response header with `type` through `mime.lookup()` 605 | * when it does not contain "/", or set the Content-Type to `type` otherwise. 606 | * 607 | * Examples: 608 | * 609 | * res.type('.html'); 610 | * res.type('html'); 611 | * res.type('json'); 612 | * res.type('application/json'); 613 | * res.type('png'); 614 | * 615 | * @param type 616 | */ 617 | type(type: string): Response; 618 | 619 | /** 620 | * Respond to the Acceptable formats using an `obj` 621 | * of mime-type callbacks. 622 | * 623 | * This method uses `req.accepted`, an array of 624 | * acceptable types ordered by their quality values. 625 | * When "Accept" is not present the _first_ callback 626 | * is invoked, otherwise the first match is used. When 627 | * no match is performed the server responds with 628 | * 406 "Not Acceptable". 629 | * 630 | * Content-Type is set for you, however if you choose 631 | * you may alter this within the callback using `res.type()` 632 | * or `res.set('Content-Type', ...)`. 633 | * 634 | * res.format({ 635 | * 'text/plain': function(){ 636 | * res.send('hey'); 637 | * }, 638 | * 639 | * 'text/html': function(){ 640 | * res.send('

hey

'); 641 | * }, 642 | * 643 | * 'appliation/json': function(){ 644 | * res.send({ message: 'hey' }); 645 | * } 646 | * }); 647 | * 648 | * In addition to canonicalized MIME types you may 649 | * also use extnames mapped to these types: 650 | * 651 | * res.format({ 652 | * text: function(){ 653 | * res.send('hey'); 654 | * }, 655 | * 656 | * html: function(){ 657 | * res.send('

hey

'); 658 | * }, 659 | * 660 | * json: function(){ 661 | * res.send({ message: 'hey' }); 662 | * } 663 | * }); 664 | * 665 | * By default Express passes an `Error` 666 | * with a `.status` of 406 to `next(err)` 667 | * if a match is not made. If you provide 668 | * a `.default` callback it will be invoked 669 | * instead. 670 | * 671 | * @param obj 672 | */ 673 | format(obj: any): Response; 674 | 675 | /** 676 | * Set _Content-Disposition_ header to _attachment_ with optional `filename`. 677 | * 678 | * @param filename 679 | */ 680 | attachment(filename?: string): Response; 681 | 682 | /** 683 | * Set header `field` to `val`, or pass 684 | * an object of header fields. 685 | * 686 | * Examples: 687 | * 688 | * res.set('Foo', ['bar', 'baz']); 689 | * res.set('Accept', 'application/json'); 690 | * res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' }); 691 | * 692 | * Aliased as `res.header()`. 693 | */ 694 | set(field: any): Response; 695 | set(field: string, value?: string): Response; 696 | 697 | header(field: any): Response; 698 | header(field: string, value?: string): Response; 699 | 700 | // Property indicating if HTTP headers has been sent for the response. 701 | headersSent: boolean; 702 | 703 | /** 704 | * Get value for header `field`. 705 | * 706 | * @param field 707 | */ 708 | get (field: string): string; 709 | 710 | /** 711 | * Clear cookie `name`. 712 | * 713 | * @param name 714 | * @param options 715 | */ 716 | clearCookie(name: string, options?: any): Response; 717 | 718 | /** 719 | * Set cookie `name` to `val`, with the given `options`. 720 | * 721 | * Options: 722 | * 723 | * - `maxAge` max-age in milliseconds, converted to `expires` 724 | * - `signed` sign the cookie 725 | * - `path` defaults to "/" 726 | * 727 | * Examples: 728 | * 729 | * // "Remember Me" for 15 minutes 730 | * res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true }); 731 | * 732 | * // save as above 733 | * res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true }) 734 | */ 735 | cookie(name: string, val: string, options: CookieOptions): Response; 736 | cookie(name: string, val: any, options: CookieOptions): Response; 737 | cookie(name: string, val: any): Response; 738 | 739 | /** 740 | * Set the location header to `url`. 741 | * 742 | * The given `url` can also be the name of a mapped url, for 743 | * example by default express supports "back" which redirects 744 | * to the _Referrer_ or _Referer_ headers or "/". 745 | * 746 | * Examples: 747 | * 748 | * res.location('/foo/bar').; 749 | * res.location('http://example.com'); 750 | * res.location('../login'); // /blog/post/1 -> /blog/login 751 | * 752 | * Mounting: 753 | * 754 | * When an application is mounted and `res.location()` 755 | * is given a path that does _not_ lead with "/" it becomes 756 | * relative to the mount-point. For example if the application 757 | * is mounted at "/blog", the following would become "/blog/login". 758 | * 759 | * res.location('login'); 760 | * 761 | * While the leading slash would result in a location of "/login": 762 | * 763 | * res.location('/login'); 764 | * 765 | * @param url 766 | */ 767 | location(url: string): Response; 768 | 769 | /** 770 | * Redirect to the given `url` with optional response `status` 771 | * defaulting to 302. 772 | * 773 | * The resulting `url` is determined by `res.location()`, so 774 | * it will play nicely with mounted apps, relative paths, 775 | * `"back"` etc. 776 | * 777 | * Examples: 778 | * 779 | * res.redirect('/foo/bar'); 780 | * res.redirect('http://example.com'); 781 | * res.redirect(301, 'http://example.com'); 782 | * res.redirect('http://example.com', 301); 783 | * res.redirect('../login'); // /blog/post/1 -> /blog/login 784 | */ 785 | redirect(url: string): void; 786 | redirect(status: number, url: string): void; 787 | redirect(url: string, status: number): void; 788 | 789 | /** 790 | * Render `view` with the given `options` and optional callback `fn`. 791 | * When a callback function is given a response will _not_ be made 792 | * automatically, otherwise a response of _200_ and _text/html_ is given. 793 | * 794 | * Options: 795 | * 796 | * - `cache` boolean hinting to the engine it should cache 797 | * - `filename` filename of the view being rendered 798 | */ 799 | render(view: string, options?: Object, callback?: (err: Error, html: string) => void ): void; 800 | render(view: string, callback?: (err: Error, html: string) => void ): void; 801 | 802 | locals: any; 803 | 804 | charset: string; 805 | } 806 | 807 | interface ErrorRequestHandler { 808 | (err: any, req: Request, res: Response, next: Function): any; 809 | } 810 | 811 | interface RequestHandler { 812 | (req: Request, res: Response, next: Function): any; 813 | } 814 | 815 | interface Handler extends RequestHandler {} 816 | 817 | interface RequestParamHandler { 818 | (req: Request, res: Response, next: Function, param: any): any; 819 | } 820 | 821 | interface Application extends IRouter, Express.Application { 822 | /** 823 | * Initialize the server. 824 | * 825 | * - setup default configuration 826 | * - setup default middleware 827 | * - setup route reflection methods 828 | */ 829 | init(): void; 830 | 831 | /** 832 | * Initialize application configuration. 833 | */ 834 | defaultConfiguration(): void; 835 | 836 | /** 837 | * Register the given template engine callback `fn` 838 | * as `ext`. 839 | * 840 | * By default will `require()` the engine based on the 841 | * file extension. For example if you try to render 842 | * a "foo.jade" file Express will invoke the following internally: 843 | * 844 | * app.engine('jade', require('jade').__express); 845 | * 846 | * For engines that do not provide `.__express` out of the box, 847 | * or if you wish to "map" a different extension to the template engine 848 | * you may use this method. For example mapping the EJS template engine to 849 | * ".html" files: 850 | * 851 | * app.engine('html', require('ejs').renderFile); 852 | * 853 | * In this case EJS provides a `.renderFile()` method with 854 | * the same signature that Express expects: `(path, options, callback)`, 855 | * though note that it aliases this method as `ejs.__express` internally 856 | * so if you're using ".ejs" extensions you dont need to do anything. 857 | * 858 | * Some template engines do not follow this convention, the 859 | * [Consolidate.js](https://github.com/visionmedia/consolidate.js) 860 | * library was created to map all of node's popular template 861 | * engines to follow this convention, thus allowing them to 862 | * work seamlessly within Express. 863 | */ 864 | engine(ext: string, fn: Function): Application; 865 | 866 | /** 867 | * Assign `setting` to `val`, or return `setting`'s value. 868 | * 869 | * app.set('foo', 'bar'); 870 | * app.get('foo'); 871 | * // => "bar" 872 | * app.set('foo', ['bar', 'baz']); 873 | * app.get('foo'); 874 | * // => ["bar", "baz"] 875 | * 876 | * Mounted servers inherit their parent server's settings. 877 | * 878 | * @param setting 879 | * @param val 880 | */ 881 | set(setting: string, val: any): Application; 882 | get: { 883 | (name: string): any; // Getter 884 | (name: string, ...handlers: RequestHandler[]): Application; 885 | (name: RegExp, ...handlers: RequestHandler[]): Application; 886 | }; 887 | 888 | /** 889 | * Return the app's absolute pathname 890 | * based on the parent(s) that have 891 | * mounted it. 892 | * 893 | * For example if the application was 894 | * mounted as "/admin", which itself 895 | * was mounted as "/blog" then the 896 | * return value would be "/blog/admin". 897 | */ 898 | path(): string; 899 | 900 | /** 901 | * Check if `setting` is enabled (truthy). 902 | * 903 | * app.enabled('foo') 904 | * // => false 905 | * 906 | * app.enable('foo') 907 | * app.enabled('foo') 908 | * // => true 909 | */ 910 | enabled(setting: string): boolean; 911 | 912 | /** 913 | * Check if `setting` is disabled. 914 | * 915 | * app.disabled('foo') 916 | * // => true 917 | * 918 | * app.enable('foo') 919 | * app.disabled('foo') 920 | * // => false 921 | * 922 | * @param setting 923 | */ 924 | disabled(setting: string): boolean; 925 | 926 | /** 927 | * Enable `setting`. 928 | * 929 | * @param setting 930 | */ 931 | enable(setting: string): Application; 932 | 933 | /** 934 | * Disable `setting`. 935 | * 936 | * @param setting 937 | */ 938 | disable(setting: string): Application; 939 | 940 | /** 941 | * Configure callback for zero or more envs, 942 | * when no `env` is specified that callback will 943 | * be invoked for all environments. Any combination 944 | * can be used multiple times, in any order desired. 945 | * 946 | * Examples: 947 | * 948 | * app.configure(function(){ 949 | * // executed for all envs 950 | * }); 951 | * 952 | * app.configure('stage', function(){ 953 | * // executed staging env 954 | * }); 955 | * 956 | * app.configure('stage', 'production', function(){ 957 | * // executed for stage and production 958 | * }); 959 | * 960 | * Note: 961 | * 962 | * These callbacks are invoked immediately, and 963 | * are effectively sugar for the following: 964 | * 965 | * var env = process.env.NODE_ENV || 'development'; 966 | * 967 | * switch (env) { 968 | * case 'development': 969 | * ... 970 | * break; 971 | * case 'stage': 972 | * ... 973 | * break; 974 | * case 'production': 975 | * ... 976 | * break; 977 | * } 978 | * 979 | * @param env 980 | * @param fn 981 | */ 982 | configure(fn: Function): Application; 983 | configure(env0: string, fn: Function): Application; 984 | configure(env0: string, env1: string, fn: Function): Application; 985 | configure(env0: string, env1: string, env2: string, fn: Function): Application; 986 | configure(env0: string, env1: string, env2: string, env3: string, fn: Function): Application; 987 | configure(env0: string, env1: string, env2: string, env3: string, env4: string, fn: Function): Application; 988 | 989 | /** 990 | * Render the given view `name` name with `options` 991 | * and a callback accepting an error and the 992 | * rendered template string. 993 | * 994 | * Example: 995 | * 996 | * app.render('email', { name: 'Tobi' }, function(err, html){ 997 | * // ... 998 | * }) 999 | * 1000 | * @param name 1001 | * @param options or fn 1002 | * @param fn 1003 | */ 1004 | render(name: string, options?: Object, callback?: (err: Error, html: string) => void): void; 1005 | render(name: string, callback: (err: Error, html: string) => void): void; 1006 | 1007 | 1008 | /** 1009 | * Listen for connections. 1010 | * 1011 | * A node `http.Server` is returned, with this 1012 | * application (which is a `Function`) as its 1013 | * callback. If you wish to create both an HTTP 1014 | * and HTTPS server you may do so with the "http" 1015 | * and "https" modules as shown here: 1016 | * 1017 | * var http = require('http') 1018 | * , https = require('https') 1019 | * , express = require('express') 1020 | * , app = express(); 1021 | * 1022 | * http.createServer(app).listen(80); 1023 | * https.createServer({ ... }, app).listen(443); 1024 | */ 1025 | listen(port: number, hostname: string, backlog: number, callback?: Function): http.Server; 1026 | listen(port: number, hostname: string, callback?: Function): http.Server; 1027 | listen(port: number, callback?: Function): http.Server; 1028 | listen(path: string, callback?: Function): http.Server; 1029 | listen(handle: any, listeningListener?: Function): http.Server; 1030 | 1031 | route(path: string): IRoute; 1032 | 1033 | router: string; 1034 | 1035 | settings: any; 1036 | 1037 | resource: any; 1038 | 1039 | map: any; 1040 | 1041 | locals: any; 1042 | 1043 | /** 1044 | * The app.routes object houses all of the routes defined mapped by the 1045 | * associated HTTP verb. This object may be used for introspection 1046 | * capabilities, for example Express uses this internally not only for 1047 | * routing but to provide default OPTIONS behaviour unless app.options() 1048 | * is used. Your application or framework may also remove routes by 1049 | * simply by removing them from this object. 1050 | */ 1051 | routes: any; 1052 | } 1053 | 1054 | interface Express extends Application { 1055 | /** 1056 | * Framework version. 1057 | */ 1058 | version: string; 1059 | 1060 | /** 1061 | * Expose mime. 1062 | */ 1063 | mime: string; 1064 | 1065 | (): Application; 1066 | 1067 | /** 1068 | * Create an express application. 1069 | */ 1070 | createApplication(): Application; 1071 | 1072 | createServer(): Application; 1073 | 1074 | application: any; 1075 | 1076 | request: Request; 1077 | 1078 | response: Response; 1079 | } 1080 | 1081 | var static: typeof serveStatic; 1082 | } 1083 | 1084 | export = e; 1085 | } 1086 | -------------------------------------------------------------------------------- /generators/app/templates/typings/mime/mime.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for mime 2 | // Project: https://github.com/broofa/node-mime 3 | // Definitions by: Jeff Goddard 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts 7 | 8 | declare module "mime" { 9 | export function lookup(path: string): string; 10 | export function extension(mime: string): string; 11 | export function load(filepath: string): void; 12 | export function define(mimes: Object): void; 13 | 14 | interface Charsets { 15 | lookup(mime: string): string; 16 | } 17 | 18 | export var charsets: Charsets; 19 | export var default_type: string; 20 | } 21 | -------------------------------------------------------------------------------- /generators/app/templates/typings/node/node.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Node.js v4.x 2 | // Project: http://nodejs.org/ 3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /************************************************ 7 | * * 8 | * Node.js v4.x API * 9 | * * 10 | ************************************************/ 11 | 12 | interface Error { 13 | stack?: string; 14 | } 15 | 16 | 17 | // compat for TypeScript 1.5.3 18 | // if you use with --target es3 or --target es5 and use below definitions, 19 | // use the lib.es6.d.ts that is bundled with TypeScript 1.5.3. 20 | interface MapConstructor {} 21 | interface WeakMapConstructor {} 22 | interface SetConstructor {} 23 | interface WeakSetConstructor {} 24 | 25 | /************************************************ 26 | * * 27 | * GLOBAL * 28 | * * 29 | ************************************************/ 30 | declare var process: NodeJS.Process; 31 | declare var global: NodeJS.Global; 32 | 33 | declare var __filename: string; 34 | declare var __dirname: string; 35 | 36 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 37 | declare function clearTimeout(timeoutId: NodeJS.Timer): void; 38 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; 39 | declare function clearInterval(intervalId: NodeJS.Timer): void; 40 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; 41 | declare function clearImmediate(immediateId: any): void; 42 | 43 | interface NodeRequireFunction { 44 | (id: string): any; 45 | } 46 | 47 | interface NodeRequire extends NodeRequireFunction { 48 | resolve(id:string): string; 49 | cache: any; 50 | extensions: any; 51 | main: any; 52 | } 53 | 54 | declare var require: NodeRequire; 55 | 56 | interface NodeModule { 57 | exports: any; 58 | require: NodeRequireFunction; 59 | id: string; 60 | filename: string; 61 | loaded: boolean; 62 | parent: any; 63 | children: any[]; 64 | } 65 | 66 | declare var module: NodeModule; 67 | 68 | // Same as module.exports 69 | declare var exports: any; 70 | declare var SlowBuffer: { 71 | new (str: string, encoding?: string): Buffer; 72 | new (size: number): Buffer; 73 | new (size: Uint8Array): Buffer; 74 | new (array: any[]): Buffer; 75 | prototype: Buffer; 76 | isBuffer(obj: any): boolean; 77 | byteLength(string: string, encoding?: string): number; 78 | concat(list: Buffer[], totalLength?: number): Buffer; 79 | }; 80 | 81 | 82 | // Buffer class 83 | interface Buffer extends NodeBuffer {} 84 | 85 | /** 86 | * Raw data is stored in instances of the Buffer class. 87 | * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. 88 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 89 | */ 90 | declare var Buffer: { 91 | /** 92 | * Allocates a new buffer containing the given {str}. 93 | * 94 | * @param str String to store in buffer. 95 | * @param encoding encoding to use, optional. Default is 'utf8' 96 | */ 97 | new (str: string, encoding?: string): Buffer; 98 | /** 99 | * Allocates a new buffer of {size} octets. 100 | * 101 | * @param size count of octets to allocate. 102 | */ 103 | new (size: number): Buffer; 104 | /** 105 | * Allocates a new buffer containing the given {array} of octets. 106 | * 107 | * @param array The octets to store. 108 | */ 109 | new (array: Uint8Array): Buffer; 110 | /** 111 | * Allocates a new buffer containing the given {array} of octets. 112 | * 113 | * @param array The octets to store. 114 | */ 115 | new (array: any[]): Buffer; 116 | prototype: Buffer; 117 | /** 118 | * Returns true if {obj} is a Buffer 119 | * 120 | * @param obj object to test. 121 | */ 122 | isBuffer(obj: any): obj is Buffer; 123 | /** 124 | * Returns true if {encoding} is a valid encoding argument. 125 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 126 | * 127 | * @param encoding string to test. 128 | */ 129 | isEncoding(encoding: string): boolean; 130 | /** 131 | * Gives the actual byte length of a string. encoding defaults to 'utf8'. 132 | * This is not the same as String.prototype.length since that returns the number of characters in a string. 133 | * 134 | * @param string string to test. 135 | * @param encoding encoding used to evaluate (defaults to 'utf8') 136 | */ 137 | byteLength(string: string, encoding?: string): number; 138 | /** 139 | * Returns a buffer which is the result of concatenating all the buffers in the list together. 140 | * 141 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 142 | * If the list has exactly one item, then the first item of the list is returned. 143 | * If the list has more than one item, then a new Buffer is created. 144 | * 145 | * @param list An array of Buffer objects to concatenate 146 | * @param totalLength Total length of the buffers when concatenated. 147 | * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. 148 | */ 149 | concat(list: Buffer[], totalLength?: number): Buffer; 150 | /** 151 | * The same as buf1.compare(buf2). 152 | */ 153 | compare(buf1: Buffer, buf2: Buffer): number; 154 | }; 155 | 156 | /************************************************ 157 | * * 158 | * GLOBAL INTERFACES * 159 | * * 160 | ************************************************/ 161 | declare module NodeJS { 162 | export interface ErrnoException extends Error { 163 | errno?: number; 164 | code?: string; 165 | path?: string; 166 | syscall?: string; 167 | stack?: string; 168 | } 169 | 170 | export interface EventEmitter { 171 | addListener(event: string, listener: Function): EventEmitter; 172 | on(event: string, listener: Function): EventEmitter; 173 | once(event: string, listener: Function): EventEmitter; 174 | removeListener(event: string, listener: Function): EventEmitter; 175 | removeAllListeners(event?: string): EventEmitter; 176 | setMaxListeners(n: number): void; 177 | listeners(event: string): Function[]; 178 | emit(event: string, ...args: any[]): boolean; 179 | } 180 | 181 | export interface ReadableStream extends EventEmitter { 182 | readable: boolean; 183 | read(size?: number): string|Buffer; 184 | setEncoding(encoding: string): void; 185 | pause(): void; 186 | resume(): void; 187 | pipe(destination: T, options?: { end?: boolean; }): T; 188 | unpipe(destination?: T): void; 189 | unshift(chunk: string): void; 190 | unshift(chunk: Buffer): void; 191 | wrap(oldStream: ReadableStream): ReadableStream; 192 | } 193 | 194 | export interface WritableStream extends EventEmitter { 195 | writable: boolean; 196 | write(buffer: Buffer|string, cb?: Function): boolean; 197 | write(str: string, encoding?: string, cb?: Function): boolean; 198 | end(): void; 199 | end(buffer: Buffer, cb?: Function): void; 200 | end(str: string, cb?: Function): void; 201 | end(str: string, encoding?: string, cb?: Function): void; 202 | } 203 | 204 | export interface ReadWriteStream extends ReadableStream, WritableStream {} 205 | 206 | export interface Process extends EventEmitter { 207 | stdout: WritableStream; 208 | stderr: WritableStream; 209 | stdin: ReadableStream; 210 | argv: string[]; 211 | execPath: string; 212 | abort(): void; 213 | chdir(directory: string): void; 214 | cwd(): string; 215 | env: any; 216 | exit(code?: number): void; 217 | getgid(): number; 218 | setgid(id: number): void; 219 | setgid(id: string): void; 220 | getuid(): number; 221 | setuid(id: number): void; 222 | setuid(id: string): void; 223 | version: string; 224 | versions: { 225 | http_parser: string; 226 | node: string; 227 | v8: string; 228 | ares: string; 229 | uv: string; 230 | zlib: string; 231 | openssl: string; 232 | }; 233 | config: { 234 | target_defaults: { 235 | cflags: any[]; 236 | default_configuration: string; 237 | defines: string[]; 238 | include_dirs: string[]; 239 | libraries: string[]; 240 | }; 241 | variables: { 242 | clang: number; 243 | host_arch: string; 244 | node_install_npm: boolean; 245 | node_install_waf: boolean; 246 | node_prefix: string; 247 | node_shared_openssl: boolean; 248 | node_shared_v8: boolean; 249 | node_shared_zlib: boolean; 250 | node_use_dtrace: boolean; 251 | node_use_etw: boolean; 252 | node_use_openssl: boolean; 253 | target_arch: string; 254 | v8_no_strict_aliasing: number; 255 | v8_use_snapshot: boolean; 256 | visibility: string; 257 | }; 258 | }; 259 | kill(pid: number, signal?: string): void; 260 | pid: number; 261 | title: string; 262 | arch: string; 263 | platform: string; 264 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; 265 | nextTick(callback: Function): void; 266 | umask(mask?: number): number; 267 | uptime(): number; 268 | hrtime(time?:number[]): number[]; 269 | 270 | // Worker 271 | send?(message: any, sendHandle?: any): void; 272 | } 273 | 274 | export interface Global { 275 | Array: typeof Array; 276 | ArrayBuffer: typeof ArrayBuffer; 277 | Boolean: typeof Boolean; 278 | Buffer: typeof Buffer; 279 | DataView: typeof DataView; 280 | Date: typeof Date; 281 | Error: typeof Error; 282 | EvalError: typeof EvalError; 283 | Float32Array: typeof Float32Array; 284 | Float64Array: typeof Float64Array; 285 | Function: typeof Function; 286 | GLOBAL: Global; 287 | Infinity: typeof Infinity; 288 | Int16Array: typeof Int16Array; 289 | Int32Array: typeof Int32Array; 290 | Int8Array: typeof Int8Array; 291 | Intl: typeof Intl; 292 | JSON: typeof JSON; 293 | Map: MapConstructor; 294 | Math: typeof Math; 295 | NaN: typeof NaN; 296 | Number: typeof Number; 297 | Object: typeof Object; 298 | Promise: Function; 299 | RangeError: typeof RangeError; 300 | ReferenceError: typeof ReferenceError; 301 | RegExp: typeof RegExp; 302 | Set: SetConstructor; 303 | String: typeof String; 304 | Symbol: Function; 305 | SyntaxError: typeof SyntaxError; 306 | TypeError: typeof TypeError; 307 | URIError: typeof URIError; 308 | Uint16Array: typeof Uint16Array; 309 | Uint32Array: typeof Uint32Array; 310 | Uint8Array: typeof Uint8Array; 311 | Uint8ClampedArray: Function; 312 | WeakMap: WeakMapConstructor; 313 | WeakSet: WeakSetConstructor; 314 | clearImmediate: (immediateId: any) => void; 315 | clearInterval: (intervalId: NodeJS.Timer) => void; 316 | clearTimeout: (timeoutId: NodeJS.Timer) => void; 317 | console: typeof console; 318 | decodeURI: typeof decodeURI; 319 | decodeURIComponent: typeof decodeURIComponent; 320 | encodeURI: typeof encodeURI; 321 | encodeURIComponent: typeof encodeURIComponent; 322 | escape: (str: string) => string; 323 | eval: typeof eval; 324 | global: Global; 325 | isFinite: typeof isFinite; 326 | isNaN: typeof isNaN; 327 | parseFloat: typeof parseFloat; 328 | parseInt: typeof parseInt; 329 | process: Process; 330 | root: Global; 331 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; 332 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 333 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 334 | undefined: typeof undefined; 335 | unescape: (str: string) => string; 336 | gc: () => void; 337 | v8debug?: any; 338 | } 339 | 340 | export interface Timer { 341 | ref() : void; 342 | unref() : void; 343 | } 344 | } 345 | 346 | /** 347 | * @deprecated 348 | */ 349 | interface NodeBuffer { 350 | [index: number]: number; 351 | write(string: string, offset?: number, length?: number, encoding?: string): number; 352 | toString(encoding?: string, start?: number, end?: number): string; 353 | toJSON(): any; 354 | length: number; 355 | equals(otherBuffer: Buffer): boolean; 356 | compare(otherBuffer: Buffer): number; 357 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 358 | slice(start?: number, end?: number): Buffer; 359 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 360 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 361 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 362 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 363 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 364 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 365 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 366 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 367 | readUInt8(offset: number, noAsset?: boolean): number; 368 | readUInt16LE(offset: number, noAssert?: boolean): number; 369 | readUInt16BE(offset: number, noAssert?: boolean): number; 370 | readUInt32LE(offset: number, noAssert?: boolean): number; 371 | readUInt32BE(offset: number, noAssert?: boolean): number; 372 | readInt8(offset: number, noAssert?: boolean): number; 373 | readInt16LE(offset: number, noAssert?: boolean): number; 374 | readInt16BE(offset: number, noAssert?: boolean): number; 375 | readInt32LE(offset: number, noAssert?: boolean): number; 376 | readInt32BE(offset: number, noAssert?: boolean): number; 377 | readFloatLE(offset: number, noAssert?: boolean): number; 378 | readFloatBE(offset: number, noAssert?: boolean): number; 379 | readDoubleLE(offset: number, noAssert?: boolean): number; 380 | readDoubleBE(offset: number, noAssert?: boolean): number; 381 | writeUInt8(value: number, offset: number, noAssert?: boolean): number; 382 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; 383 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; 384 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; 385 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; 386 | writeInt8(value: number, offset: number, noAssert?: boolean): number; 387 | writeInt16LE(value: number, offset: number, noAssert?: boolean): number; 388 | writeInt16BE(value: number, offset: number, noAssert?: boolean): number; 389 | writeInt32LE(value: number, offset: number, noAssert?: boolean): number; 390 | writeInt32BE(value: number, offset: number, noAssert?: boolean): number; 391 | writeFloatLE(value: number, offset: number, noAssert?: boolean): number; 392 | writeFloatBE(value: number, offset: number, noAssert?: boolean): number; 393 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; 394 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; 395 | fill(value: any, offset?: number, end?: number): Buffer; 396 | } 397 | 398 | /************************************************ 399 | * * 400 | * MODULES * 401 | * * 402 | ************************************************/ 403 | declare module "buffer" { 404 | export var INSPECT_MAX_BYTES: number; 405 | } 406 | 407 | declare module "querystring" { 408 | export interface StringifyOptions { 409 | encodeURIComponent?: Function; 410 | } 411 | 412 | export interface ParseOptions { 413 | maxKeys?: number; 414 | decodeURIComponent?: Function; 415 | } 416 | 417 | export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; 418 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; 419 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; 420 | export function escape(str: string): string; 421 | export function unescape(str: string): string; 422 | } 423 | 424 | declare module "events" { 425 | export class EventEmitter implements NodeJS.EventEmitter { 426 | static listenerCount(emitter: EventEmitter, event: string): number; 427 | 428 | addListener(event: string, listener: Function): EventEmitter; 429 | on(event: string, listener: Function): EventEmitter; 430 | once(event: string, listener: Function): EventEmitter; 431 | removeListener(event: string, listener: Function): EventEmitter; 432 | removeAllListeners(event?: string): EventEmitter; 433 | setMaxListeners(n: number): void; 434 | listeners(event: string): Function[]; 435 | emit(event: string, ...args: any[]): boolean; 436 | } 437 | } 438 | 439 | declare module "http" { 440 | import * as events from "events"; 441 | import * as net from "net"; 442 | import * as stream from "stream"; 443 | 444 | export interface RequestOptions { 445 | protocol?: string; 446 | host?: string; 447 | hostname?: string; 448 | family?: number; 449 | port?: number 450 | localAddress?: string; 451 | socketPath?: string; 452 | method?: string; 453 | path?: string; 454 | headers?: { [key: string]: any }; 455 | auth?: string; 456 | agent?: Agent; 457 | } 458 | 459 | export interface Server extends events.EventEmitter { 460 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; 461 | listen(port: number, hostname?: string, callback?: Function): Server; 462 | listen(path: string, callback?: Function): Server; 463 | listen(handle: any, listeningListener?: Function): Server; 464 | close(cb?: any): Server; 465 | address(): { port: number; family: string; address: string; }; 466 | maxHeadersCount: number; 467 | } 468 | /** 469 | * @deprecated Use IncomingMessage 470 | */ 471 | export interface ServerRequest extends IncomingMessage { 472 | connection: net.Socket; 473 | } 474 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 475 | // Extended base methods 476 | write(buffer: Buffer): boolean; 477 | write(buffer: Buffer, cb?: Function): boolean; 478 | write(str: string, cb?: Function): boolean; 479 | write(str: string, encoding?: string, cb?: Function): boolean; 480 | write(str: string, encoding?: string, fd?: string): boolean; 481 | 482 | writeContinue(): void; 483 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 484 | writeHead(statusCode: number, headers?: any): void; 485 | statusCode: number; 486 | statusMessage: string; 487 | setHeader(name: string, value: string): void; 488 | sendDate: boolean; 489 | getHeader(name: string): string; 490 | removeHeader(name: string): void; 491 | write(chunk: any, encoding?: string): any; 492 | addTrailers(headers: any): void; 493 | 494 | // Extended base methods 495 | end(): void; 496 | end(buffer: Buffer, cb?: Function): void; 497 | end(str: string, cb?: Function): void; 498 | end(str: string, encoding?: string, cb?: Function): void; 499 | end(data?: any, encoding?: string): void; 500 | } 501 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 502 | // Extended base methods 503 | write(buffer: Buffer): boolean; 504 | write(buffer: Buffer, cb?: Function): boolean; 505 | write(str: string, cb?: Function): boolean; 506 | write(str: string, encoding?: string, cb?: Function): boolean; 507 | write(str: string, encoding?: string, fd?: string): boolean; 508 | 509 | write(chunk: any, encoding?: string): void; 510 | abort(): void; 511 | setTimeout(timeout: number, callback?: Function): void; 512 | setNoDelay(noDelay?: boolean): void; 513 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 514 | 515 | // Extended base methods 516 | end(): void; 517 | end(buffer: Buffer, cb?: Function): void; 518 | end(str: string, cb?: Function): void; 519 | end(str: string, encoding?: string, cb?: Function): void; 520 | end(data?: any, encoding?: string): void; 521 | } 522 | export interface IncomingMessage extends events.EventEmitter, stream.Readable { 523 | httpVersion: string; 524 | headers: any; 525 | rawHeaders: string[]; 526 | trailers: any; 527 | rawTrailers: any; 528 | setTimeout(msecs: number, callback: Function): NodeJS.Timer; 529 | /** 530 | * Only valid for request obtained from http.Server. 531 | */ 532 | method?: string; 533 | /** 534 | * Only valid for request obtained from http.Server. 535 | */ 536 | url?: string; 537 | /** 538 | * Only valid for response obtained from http.ClientRequest. 539 | */ 540 | statusCode?: number; 541 | /** 542 | * Only valid for response obtained from http.ClientRequest. 543 | */ 544 | statusMessage?: string; 545 | socket: net.Socket; 546 | } 547 | /** 548 | * @deprecated Use IncomingMessage 549 | */ 550 | export interface ClientResponse extends IncomingMessage { } 551 | 552 | export interface AgentOptions { 553 | /** 554 | * Keep sockets around in a pool to be used by other requests in the future. Default = false 555 | */ 556 | keepAlive?: boolean; 557 | /** 558 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. 559 | * Only relevant if keepAlive is set to true. 560 | */ 561 | keepAliveMsecs?: number; 562 | /** 563 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity 564 | */ 565 | maxSockets?: number; 566 | /** 567 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. 568 | */ 569 | maxFreeSockets?: number; 570 | } 571 | 572 | export class Agent { 573 | maxSockets: number; 574 | sockets: any; 575 | requests: any; 576 | 577 | constructor(opts?: AgentOptions); 578 | 579 | /** 580 | * Destroy any sockets that are currently in use by the agent. 581 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, 582 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, 583 | * sockets may hang open for quite a long time before the server terminates them. 584 | */ 585 | destroy(): void; 586 | } 587 | 588 | export var METHODS: string[]; 589 | 590 | export var STATUS_CODES: { 591 | [errorCode: number]: string; 592 | [errorCode: string]: string; 593 | }; 594 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; 595 | export function createClient(port?: number, host?: string): any; 596 | export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; 597 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 598 | export var globalAgent: Agent; 599 | } 600 | 601 | declare module "cluster" { 602 | import * as child from "child_process"; 603 | import * as events from "events"; 604 | 605 | export interface ClusterSettings { 606 | exec?: string; 607 | args?: string[]; 608 | silent?: boolean; 609 | } 610 | 611 | export class Worker extends events.EventEmitter { 612 | id: string; 613 | process: child.ChildProcess; 614 | suicide: boolean; 615 | send(message: any, sendHandle?: any): void; 616 | kill(signal?: string): void; 617 | destroy(signal?: string): void; 618 | disconnect(): void; 619 | } 620 | 621 | export var settings: ClusterSettings; 622 | export var isMaster: boolean; 623 | export var isWorker: boolean; 624 | export function setupMaster(settings?: ClusterSettings): void; 625 | export function fork(env?: any): Worker; 626 | export function disconnect(callback?: Function): void; 627 | export var worker: Worker; 628 | export var workers: Worker[]; 629 | 630 | // Event emitter 631 | export function addListener(event: string, listener: Function): void; 632 | export function on(event: string, listener: Function): any; 633 | export function once(event: string, listener: Function): void; 634 | export function removeListener(event: string, listener: Function): void; 635 | export function removeAllListeners(event?: string): void; 636 | export function setMaxListeners(n: number): void; 637 | export function listeners(event: string): Function[]; 638 | export function emit(event: string, ...args: any[]): boolean; 639 | } 640 | 641 | declare module "zlib" { 642 | import * as stream from "stream"; 643 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 644 | 645 | export interface Gzip extends stream.Transform { } 646 | export interface Gunzip extends stream.Transform { } 647 | export interface Deflate extends stream.Transform { } 648 | export interface Inflate extends stream.Transform { } 649 | export interface DeflateRaw extends stream.Transform { } 650 | export interface InflateRaw extends stream.Transform { } 651 | export interface Unzip extends stream.Transform { } 652 | 653 | export function createGzip(options?: ZlibOptions): Gzip; 654 | export function createGunzip(options?: ZlibOptions): Gunzip; 655 | export function createDeflate(options?: ZlibOptions): Deflate; 656 | export function createInflate(options?: ZlibOptions): Inflate; 657 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 658 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 659 | export function createUnzip(options?: ZlibOptions): Unzip; 660 | 661 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 662 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any; 663 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 664 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; 665 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 666 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any; 667 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 668 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; 669 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 670 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any; 671 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 672 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; 673 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 674 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any; 675 | 676 | // Constants 677 | export var Z_NO_FLUSH: number; 678 | export var Z_PARTIAL_FLUSH: number; 679 | export var Z_SYNC_FLUSH: number; 680 | export var Z_FULL_FLUSH: number; 681 | export var Z_FINISH: number; 682 | export var Z_BLOCK: number; 683 | export var Z_TREES: number; 684 | export var Z_OK: number; 685 | export var Z_STREAM_END: number; 686 | export var Z_NEED_DICT: number; 687 | export var Z_ERRNO: number; 688 | export var Z_STREAM_ERROR: number; 689 | export var Z_DATA_ERROR: number; 690 | export var Z_MEM_ERROR: number; 691 | export var Z_BUF_ERROR: number; 692 | export var Z_VERSION_ERROR: number; 693 | export var Z_NO_COMPRESSION: number; 694 | export var Z_BEST_SPEED: number; 695 | export var Z_BEST_COMPRESSION: number; 696 | export var Z_DEFAULT_COMPRESSION: number; 697 | export var Z_FILTERED: number; 698 | export var Z_HUFFMAN_ONLY: number; 699 | export var Z_RLE: number; 700 | export var Z_FIXED: number; 701 | export var Z_DEFAULT_STRATEGY: number; 702 | export var Z_BINARY: number; 703 | export var Z_TEXT: number; 704 | export var Z_ASCII: number; 705 | export var Z_UNKNOWN: number; 706 | export var Z_DEFLATED: number; 707 | export var Z_NULL: number; 708 | } 709 | 710 | declare module "os" { 711 | export interface CpuInfo { 712 | model: string; 713 | speed: number; 714 | times: { 715 | user: number; 716 | nice: number; 717 | sys: number; 718 | idle: number; 719 | irq: number; 720 | } 721 | } 722 | 723 | export interface NetworkInterfaceInfo { 724 | address: string; 725 | netmask: string; 726 | family: string; 727 | mac: string; 728 | internal: boolean; 729 | } 730 | 731 | export function tmpdir(): string; 732 | export function homedir(): string; 733 | export function endianness(): string; 734 | export function hostname(): string; 735 | export function type(): string; 736 | export function platform(): string; 737 | export function arch(): string; 738 | export function release(): string; 739 | export function uptime(): number; 740 | export function loadavg(): number[]; 741 | export function totalmem(): number; 742 | export function freemem(): number; 743 | export function cpus(): CpuInfo[]; 744 | export function networkInterfaces(): {[index: string]: NetworkInterfaceInfo[]}; 745 | export var EOL: string; 746 | } 747 | 748 | declare module "https" { 749 | import * as tls from "tls"; 750 | import * as events from "events"; 751 | import * as http from "http"; 752 | 753 | export interface ServerOptions { 754 | pfx?: any; 755 | key?: any; 756 | passphrase?: string; 757 | cert?: any; 758 | ca?: any; 759 | crl?: any; 760 | ciphers?: string; 761 | honorCipherOrder?: boolean; 762 | requestCert?: boolean; 763 | rejectUnauthorized?: boolean; 764 | NPNProtocols?: any; 765 | SNICallback?: (servername: string) => any; 766 | } 767 | 768 | export interface RequestOptions extends http.RequestOptions{ 769 | pfx?: any; 770 | key?: any; 771 | passphrase?: string; 772 | cert?: any; 773 | ca?: any; 774 | ciphers?: string; 775 | rejectUnauthorized?: boolean; 776 | secureProtocol?: string; 777 | } 778 | 779 | export interface Agent { 780 | maxSockets: number; 781 | sockets: any; 782 | requests: any; 783 | } 784 | export var Agent: { 785 | new (options?: RequestOptions): Agent; 786 | }; 787 | export interface Server extends tls.Server { } 788 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 789 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 790 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 791 | export var globalAgent: Agent; 792 | } 793 | 794 | declare module "punycode" { 795 | export function decode(string: string): string; 796 | export function encode(string: string): string; 797 | export function toUnicode(domain: string): string; 798 | export function toASCII(domain: string): string; 799 | export var ucs2: ucs2; 800 | interface ucs2 { 801 | decode(string: string): number[]; 802 | encode(codePoints: number[]): string; 803 | } 804 | export var version: any; 805 | } 806 | 807 | declare module "repl" { 808 | import * as stream from "stream"; 809 | import * as events from "events"; 810 | 811 | export interface ReplOptions { 812 | prompt?: string; 813 | input?: NodeJS.ReadableStream; 814 | output?: NodeJS.WritableStream; 815 | terminal?: boolean; 816 | eval?: Function; 817 | useColors?: boolean; 818 | useGlobal?: boolean; 819 | ignoreUndefined?: boolean; 820 | writer?: Function; 821 | } 822 | export function start(options: ReplOptions): events.EventEmitter; 823 | } 824 | 825 | declare module "readline" { 826 | import * as events from "events"; 827 | import * as stream from "stream"; 828 | 829 | export interface ReadLine extends events.EventEmitter { 830 | setPrompt(prompt: string): void; 831 | prompt(preserveCursor?: boolean): void; 832 | question(query: string, callback: Function): void; 833 | pause(): void; 834 | resume(): void; 835 | close(): void; 836 | write(data: any, key?: any): void; 837 | } 838 | export interface ReadLineOptions { 839 | input: NodeJS.ReadableStream; 840 | output: NodeJS.WritableStream; 841 | completer?: Function; 842 | terminal?: boolean; 843 | } 844 | export function createInterface(options: ReadLineOptions): ReadLine; 845 | } 846 | 847 | declare module "vm" { 848 | export interface Context { } 849 | export interface Script { 850 | runInThisContext(): void; 851 | runInNewContext(sandbox?: Context): void; 852 | } 853 | export function runInThisContext(code: string, filename?: string): void; 854 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; 855 | export function runInContext(code: string, context: Context, filename?: string): void; 856 | export function createContext(initSandbox?: Context): Context; 857 | export function createScript(code: string, filename?: string): Script; 858 | } 859 | 860 | declare module "child_process" { 861 | import * as events from "events"; 862 | import * as stream from "stream"; 863 | 864 | export interface ChildProcess extends events.EventEmitter { 865 | stdin: stream.Writable; 866 | stdout: stream.Readable; 867 | stderr: stream.Readable; 868 | pid: number; 869 | kill(signal?: string): void; 870 | send(message: any, sendHandle?: any): void; 871 | disconnect(): void; 872 | unref(): void; 873 | } 874 | 875 | export function spawn(command: string, args?: string[], options?: { 876 | cwd?: string; 877 | stdio?: any; 878 | custom?: any; 879 | env?: any; 880 | detached?: boolean; 881 | }): ChildProcess; 882 | export function exec(command: string, options: { 883 | cwd?: string; 884 | stdio?: any; 885 | customFds?: any; 886 | env?: any; 887 | encoding?: string; 888 | timeout?: number; 889 | maxBuffer?: number; 890 | killSignal?: string; 891 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 892 | export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 893 | export function execFile(file: string, 894 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 895 | export function execFile(file: string, args?: string[], 896 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 897 | export function execFile(file: string, args?: string[], options?: { 898 | cwd?: string; 899 | stdio?: any; 900 | customFds?: any; 901 | env?: any; 902 | encoding?: string; 903 | timeout?: number; 904 | maxBuffer?: number; 905 | killSignal?: string; 906 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 907 | export function fork(modulePath: string, args?: string[], options?: { 908 | cwd?: string; 909 | env?: any; 910 | encoding?: string; 911 | }): ChildProcess; 912 | export function spawnSync(command: string, args?: string[], options?: { 913 | cwd?: string; 914 | input?: string | Buffer; 915 | stdio?: any; 916 | env?: any; 917 | uid?: number; 918 | gid?: number; 919 | timeout?: number; 920 | maxBuffer?: number; 921 | killSignal?: string; 922 | encoding?: string; 923 | }): { 924 | pid: number; 925 | output: string[]; 926 | stdout: string | Buffer; 927 | stderr: string | Buffer; 928 | status: number; 929 | signal: string; 930 | error: Error; 931 | }; 932 | export function execSync(command: string, options?: { 933 | cwd?: string; 934 | input?: string|Buffer; 935 | stdio?: any; 936 | env?: any; 937 | uid?: number; 938 | gid?: number; 939 | timeout?: number; 940 | maxBuffer?: number; 941 | killSignal?: string; 942 | encoding?: string; 943 | }): string | Buffer; 944 | export function execFileSync(command: string, args?: string[], options?: { 945 | cwd?: string; 946 | input?: string|Buffer; 947 | stdio?: any; 948 | env?: any; 949 | uid?: number; 950 | gid?: number; 951 | timeout?: number; 952 | maxBuffer?: number; 953 | killSignal?: string; 954 | encoding?: string; 955 | }): string | Buffer; 956 | } 957 | 958 | declare module "url" { 959 | export interface Url { 960 | href?: string; 961 | protocol?: string; 962 | auth?: string; 963 | hostname?: string; 964 | port?: string; 965 | host?: string; 966 | pathname?: string; 967 | search?: string; 968 | query?: any; // string | Object 969 | slashes?: boolean; 970 | hash?: string; 971 | path?: string; 972 | } 973 | 974 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 975 | export function format(url: Url): string; 976 | export function resolve(from: string, to: string): string; 977 | } 978 | 979 | declare module "dns" { 980 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 981 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 982 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 983 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 984 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 985 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 986 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 987 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 988 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 989 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 990 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 991 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 992 | } 993 | 994 | declare module "net" { 995 | import * as stream from "stream"; 996 | 997 | export interface Socket extends stream.Duplex { 998 | // Extended base methods 999 | write(buffer: Buffer): boolean; 1000 | write(buffer: Buffer, cb?: Function): boolean; 1001 | write(str: string, cb?: Function): boolean; 1002 | write(str: string, encoding?: string, cb?: Function): boolean; 1003 | write(str: string, encoding?: string, fd?: string): boolean; 1004 | 1005 | connect(port: number, host?: string, connectionListener?: Function): void; 1006 | connect(path: string, connectionListener?: Function): void; 1007 | bufferSize: number; 1008 | setEncoding(encoding?: string): void; 1009 | write(data: any, encoding?: string, callback?: Function): void; 1010 | destroy(): void; 1011 | pause(): void; 1012 | resume(): void; 1013 | setTimeout(timeout: number, callback?: Function): void; 1014 | setNoDelay(noDelay?: boolean): void; 1015 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 1016 | address(): { port: number; family: string; address: string; }; 1017 | unref(): void; 1018 | ref(): void; 1019 | 1020 | remoteAddress: string; 1021 | remoteFamily: string; 1022 | remotePort: number; 1023 | localAddress: string; 1024 | localPort: number; 1025 | bytesRead: number; 1026 | bytesWritten: number; 1027 | 1028 | // Extended base methods 1029 | end(): void; 1030 | end(buffer: Buffer, cb?: Function): void; 1031 | end(str: string, cb?: Function): void; 1032 | end(str: string, encoding?: string, cb?: Function): void; 1033 | end(data?: any, encoding?: string): void; 1034 | } 1035 | 1036 | export var Socket: { 1037 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 1038 | }; 1039 | 1040 | export interface Server extends Socket { 1041 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 1042 | listen(path: string, listeningListener?: Function): Server; 1043 | listen(handle: any, listeningListener?: Function): Server; 1044 | close(callback?: Function): Server; 1045 | address(): { port: number; family: string; address: string; }; 1046 | maxConnections: number; 1047 | connections: number; 1048 | } 1049 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server; 1050 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; 1051 | export function connect(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1052 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 1053 | export function connect(path: string, connectionListener?: Function): Socket; 1054 | export function createConnection(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1055 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 1056 | export function createConnection(path: string, connectionListener?: Function): Socket; 1057 | export function isIP(input: string): number; 1058 | export function isIPv4(input: string): boolean; 1059 | export function isIPv6(input: string): boolean; 1060 | } 1061 | 1062 | declare module "dgram" { 1063 | import * as events from "events"; 1064 | 1065 | interface RemoteInfo { 1066 | address: string; 1067 | port: number; 1068 | size: number; 1069 | } 1070 | 1071 | interface AddressInfo { 1072 | address: string; 1073 | family: string; 1074 | port: number; 1075 | } 1076 | 1077 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 1078 | 1079 | interface Socket extends events.EventEmitter { 1080 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 1081 | bind(port: number, address?: string, callback?: () => void): void; 1082 | close(): void; 1083 | address(): AddressInfo; 1084 | setBroadcast(flag: boolean): void; 1085 | setMulticastTTL(ttl: number): void; 1086 | setMulticastLoopback(flag: boolean): void; 1087 | addMembership(multicastAddress: string, multicastInterface?: string): void; 1088 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 1089 | } 1090 | } 1091 | 1092 | declare module "fs" { 1093 | import * as stream from "stream"; 1094 | import * as events from "events"; 1095 | 1096 | interface Stats { 1097 | isFile(): boolean; 1098 | isDirectory(): boolean; 1099 | isBlockDevice(): boolean; 1100 | isCharacterDevice(): boolean; 1101 | isSymbolicLink(): boolean; 1102 | isFIFO(): boolean; 1103 | isSocket(): boolean; 1104 | dev: number; 1105 | ino: number; 1106 | mode: number; 1107 | nlink: number; 1108 | uid: number; 1109 | gid: number; 1110 | rdev: number; 1111 | size: number; 1112 | blksize: number; 1113 | blocks: number; 1114 | atime: Date; 1115 | mtime: Date; 1116 | ctime: Date; 1117 | birthtime: Date; 1118 | } 1119 | 1120 | interface FSWatcher extends events.EventEmitter { 1121 | close(): void; 1122 | } 1123 | 1124 | export interface ReadStream extends stream.Readable { 1125 | close(): void; 1126 | } 1127 | export interface WriteStream extends stream.Writable { 1128 | close(): void; 1129 | bytesWritten: number; 1130 | } 1131 | 1132 | /** 1133 | * Asynchronous rename. 1134 | * @param oldPath 1135 | * @param newPath 1136 | * @param callback No arguments other than a possible exception are given to the completion callback. 1137 | */ 1138 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1139 | /** 1140 | * Synchronous rename 1141 | * @param oldPath 1142 | * @param newPath 1143 | */ 1144 | export function renameSync(oldPath: string, newPath: string): void; 1145 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1146 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1147 | export function truncateSync(path: string, len?: number): void; 1148 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1149 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1150 | export function ftruncateSync(fd: number, len?: number): void; 1151 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1152 | export function chownSync(path: string, uid: number, gid: number): void; 1153 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1154 | export function fchownSync(fd: number, uid: number, gid: number): void; 1155 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1156 | export function lchownSync(path: string, uid: number, gid: number): void; 1157 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1158 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1159 | export function chmodSync(path: string, mode: number): void; 1160 | export function chmodSync(path: string, mode: string): void; 1161 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1162 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1163 | export function fchmodSync(fd: number, mode: number): void; 1164 | export function fchmodSync(fd: number, mode: string): void; 1165 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1166 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1167 | export function lchmodSync(path: string, mode: number): void; 1168 | export function lchmodSync(path: string, mode: string): void; 1169 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1170 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1171 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1172 | export function statSync(path: string): Stats; 1173 | export function lstatSync(path: string): Stats; 1174 | export function fstatSync(fd: number): Stats; 1175 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1176 | export function linkSync(srcpath: string, dstpath: string): void; 1177 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1178 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 1179 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 1180 | export function readlinkSync(path: string): string; 1181 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1182 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; 1183 | export function realpathSync(path: string, cache?: { [path: string]: string }): string; 1184 | /* 1185 | * Asynchronous unlink - deletes the file specified in {path} 1186 | * 1187 | * @param path 1188 | * @param callback No arguments other than a possible exception are given to the completion callback. 1189 | */ 1190 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1191 | /* 1192 | * Synchronous unlink - deletes the file specified in {path} 1193 | * 1194 | * @param path 1195 | */ 1196 | export function unlinkSync(path: string): void; 1197 | /* 1198 | * Asynchronous rmdir - removes the directory specified in {path} 1199 | * 1200 | * @param path 1201 | * @param callback No arguments other than a possible exception are given to the completion callback. 1202 | */ 1203 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1204 | /* 1205 | * Synchronous rmdir - removes the directory specified in {path} 1206 | * 1207 | * @param path 1208 | */ 1209 | export function rmdirSync(path: string): void; 1210 | /* 1211 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1212 | * 1213 | * @param path 1214 | * @param callback No arguments other than a possible exception are given to the completion callback. 1215 | */ 1216 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1217 | /* 1218 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1219 | * 1220 | * @param path 1221 | * @param mode 1222 | * @param callback No arguments other than a possible exception are given to the completion callback. 1223 | */ 1224 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1225 | /* 1226 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1227 | * 1228 | * @param path 1229 | * @param mode 1230 | * @param callback No arguments other than a possible exception are given to the completion callback. 1231 | */ 1232 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1233 | /* 1234 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1235 | * 1236 | * @param path 1237 | * @param mode 1238 | * @param callback No arguments other than a possible exception are given to the completion callback. 1239 | */ 1240 | export function mkdirSync(path: string, mode?: number): void; 1241 | /* 1242 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1243 | * 1244 | * @param path 1245 | * @param mode 1246 | * @param callback No arguments other than a possible exception are given to the completion callback. 1247 | */ 1248 | export function mkdirSync(path: string, mode?: string): void; 1249 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 1250 | export function readdirSync(path: string): string[]; 1251 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1252 | export function closeSync(fd: number): void; 1253 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1254 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1255 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1256 | export function openSync(path: string, flags: string, mode?: number): number; 1257 | export function openSync(path: string, flags: string, mode?: string): number; 1258 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1259 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1260 | export function utimesSync(path: string, atime: number, mtime: number): void; 1261 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 1262 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1263 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1264 | export function futimesSync(fd: number, atime: number, mtime: number): void; 1265 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 1266 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1267 | export function fsyncSync(fd: number): void; 1268 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1269 | export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1270 | export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1271 | export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1272 | export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1273 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1274 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 1275 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1276 | /* 1277 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1278 | * 1279 | * @param fileName 1280 | * @param encoding 1281 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1282 | */ 1283 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1284 | /* 1285 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1286 | * 1287 | * @param fileName 1288 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1289 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1290 | */ 1291 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1292 | /* 1293 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1294 | * 1295 | * @param fileName 1296 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1297 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1298 | */ 1299 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1300 | /* 1301 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1302 | * 1303 | * @param fileName 1304 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1305 | */ 1306 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1307 | /* 1308 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1309 | * 1310 | * @param fileName 1311 | * @param encoding 1312 | */ 1313 | export function readFileSync(filename: string, encoding: string): string; 1314 | /* 1315 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1316 | * 1317 | * @param fileName 1318 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1319 | */ 1320 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 1321 | /* 1322 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1323 | * 1324 | * @param fileName 1325 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1326 | */ 1327 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 1328 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1329 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1330 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1331 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1332 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1333 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1334 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1335 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1336 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1337 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1338 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 1339 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 1340 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 1341 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 1342 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 1343 | export function exists(path: string, callback?: (exists: boolean) => void): void; 1344 | export function existsSync(path: string): boolean; 1345 | /** Constant for fs.access(). File is visible to the calling process. */ 1346 | export var F_OK: number; 1347 | /** Constant for fs.access(). File can be read by the calling process. */ 1348 | export var R_OK: number; 1349 | /** Constant for fs.access(). File can be written by the calling process. */ 1350 | export var W_OK: number; 1351 | /** Constant for fs.access(). File can be executed by the calling process. */ 1352 | export var X_OK: number; 1353 | /** Tests a user's permissions for the file specified by path. */ 1354 | export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; 1355 | export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; 1356 | /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ 1357 | export function accessSync(path: string, mode ?: number): void; 1358 | export function createReadStream(path: string, options?: { 1359 | flags?: string; 1360 | encoding?: string; 1361 | fd?: number; 1362 | mode?: number; 1363 | autoClose?: boolean; 1364 | }): ReadStream; 1365 | export function createWriteStream(path: string, options?: { 1366 | flags?: string; 1367 | encoding?: string; 1368 | fd?: number; 1369 | mode?: number; 1370 | }): WriteStream; 1371 | } 1372 | 1373 | declare module "path" { 1374 | 1375 | /** 1376 | * A parsed path object generated by path.parse() or consumed by path.format(). 1377 | */ 1378 | export interface ParsedPath { 1379 | /** 1380 | * The root of the path such as '/' or 'c:\' 1381 | */ 1382 | root: string; 1383 | /** 1384 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 1385 | */ 1386 | dir: string; 1387 | /** 1388 | * The file name including extension (if any) such as 'index.html' 1389 | */ 1390 | base: string; 1391 | /** 1392 | * The file extension (if any) such as '.html' 1393 | */ 1394 | ext: string; 1395 | /** 1396 | * The file name without extension (if any) such as 'index' 1397 | */ 1398 | name: string; 1399 | } 1400 | 1401 | /** 1402 | * Normalize a string path, reducing '..' and '.' parts. 1403 | * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. 1404 | * 1405 | * @param p string path to normalize. 1406 | */ 1407 | export function normalize(p: string): string; 1408 | /** 1409 | * Join all arguments together and normalize the resulting path. 1410 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1411 | * 1412 | * @param paths string paths to join. 1413 | */ 1414 | export function join(...paths: any[]): string; 1415 | /** 1416 | * Join all arguments together and normalize the resulting path. 1417 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1418 | * 1419 | * @param paths string paths to join. 1420 | */ 1421 | export function join(...paths: string[]): string; 1422 | /** 1423 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. 1424 | * 1425 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path. 1426 | * 1427 | * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. 1428 | * 1429 | * @param pathSegments string paths to join. Non-string arguments are ignored. 1430 | */ 1431 | export function resolve(...pathSegments: any[]): string; 1432 | /** 1433 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. 1434 | * 1435 | * @param path path to test. 1436 | */ 1437 | export function isAbsolute(path: string): boolean; 1438 | /** 1439 | * Solve the relative path from {from} to {to}. 1440 | * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. 1441 | * 1442 | * @param from 1443 | * @param to 1444 | */ 1445 | export function relative(from: string, to: string): string; 1446 | /** 1447 | * Return the directory name of a path. Similar to the Unix dirname command. 1448 | * 1449 | * @param p the path to evaluate. 1450 | */ 1451 | export function dirname(p: string): string; 1452 | /** 1453 | * Return the last portion of a path. Similar to the Unix basename command. 1454 | * Often used to extract the file name from a fully qualified path. 1455 | * 1456 | * @param p the path to evaluate. 1457 | * @param ext optionally, an extension to remove from the result. 1458 | */ 1459 | export function basename(p: string, ext?: string): string; 1460 | /** 1461 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path. 1462 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string 1463 | * 1464 | * @param p the path to evaluate. 1465 | */ 1466 | export function extname(p: string): string; 1467 | /** 1468 | * The platform-specific file separator. '\\' or '/'. 1469 | */ 1470 | export var sep: string; 1471 | /** 1472 | * The platform-specific file delimiter. ';' or ':'. 1473 | */ 1474 | export var delimiter: string; 1475 | /** 1476 | * Returns an object from a path string - the opposite of format(). 1477 | * 1478 | * @param pathString path to evaluate. 1479 | */ 1480 | export function parse(pathString: string): ParsedPath; 1481 | /** 1482 | * Returns a path string from an object - the opposite of parse(). 1483 | * 1484 | * @param pathString path to evaluate. 1485 | */ 1486 | export function format(pathObject: ParsedPath): string; 1487 | 1488 | export module posix { 1489 | export function normalize(p: string): string; 1490 | export function join(...paths: any[]): string; 1491 | export function resolve(...pathSegments: any[]): string; 1492 | export function isAbsolute(p: string): boolean; 1493 | export function relative(from: string, to: string): string; 1494 | export function dirname(p: string): string; 1495 | export function basename(p: string, ext?: string): string; 1496 | export function extname(p: string): string; 1497 | export var sep: string; 1498 | export var delimiter: string; 1499 | export function parse(p: string): ParsedPath; 1500 | export function format(pP: ParsedPath): string; 1501 | } 1502 | 1503 | export module win32 { 1504 | export function normalize(p: string): string; 1505 | export function join(...paths: any[]): string; 1506 | export function resolve(...pathSegments: any[]): string; 1507 | export function isAbsolute(p: string): boolean; 1508 | export function relative(from: string, to: string): string; 1509 | export function dirname(p: string): string; 1510 | export function basename(p: string, ext?: string): string; 1511 | export function extname(p: string): string; 1512 | export var sep: string; 1513 | export var delimiter: string; 1514 | export function parse(p: string): ParsedPath; 1515 | export function format(pP: ParsedPath): string; 1516 | } 1517 | } 1518 | 1519 | declare module "string_decoder" { 1520 | export interface NodeStringDecoder { 1521 | write(buffer: Buffer): string; 1522 | detectIncompleteChar(buffer: Buffer): number; 1523 | } 1524 | export var StringDecoder: { 1525 | new (encoding: string): NodeStringDecoder; 1526 | }; 1527 | } 1528 | 1529 | declare module "tls" { 1530 | import * as crypto from "crypto"; 1531 | import * as net from "net"; 1532 | import * as stream from "stream"; 1533 | 1534 | var CLIENT_RENEG_LIMIT: number; 1535 | var CLIENT_RENEG_WINDOW: number; 1536 | 1537 | export interface TlsOptions { 1538 | pfx?: any; //string or buffer 1539 | key?: any; //string or buffer 1540 | passphrase?: string; 1541 | cert?: any; 1542 | ca?: any; //string or buffer 1543 | crl?: any; //string or string array 1544 | ciphers?: string; 1545 | honorCipherOrder?: any; 1546 | requestCert?: boolean; 1547 | rejectUnauthorized?: boolean; 1548 | NPNProtocols?: any; //array or Buffer; 1549 | SNICallback?: (servername: string) => any; 1550 | } 1551 | 1552 | export interface ConnectionOptions { 1553 | host?: string; 1554 | port?: number; 1555 | socket?: net.Socket; 1556 | pfx?: any; //string | Buffer 1557 | key?: any; //string | Buffer 1558 | passphrase?: string; 1559 | cert?: any; //string | Buffer 1560 | ca?: any; //Array of string | Buffer 1561 | rejectUnauthorized?: boolean; 1562 | NPNProtocols?: any; //Array of string | Buffer 1563 | servername?: string; 1564 | } 1565 | 1566 | export interface Server extends net.Server { 1567 | // Extended base methods 1568 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; 1569 | listen(path: string, listeningListener?: Function): Server; 1570 | listen(handle: any, listeningListener?: Function): Server; 1571 | 1572 | listen(port: number, host?: string, callback?: Function): Server; 1573 | close(): Server; 1574 | address(): { port: number; family: string; address: string; }; 1575 | addContext(hostName: string, credentials: { 1576 | key: string; 1577 | cert: string; 1578 | ca: string; 1579 | }): void; 1580 | maxConnections: number; 1581 | connections: number; 1582 | } 1583 | 1584 | export interface ClearTextStream extends stream.Duplex { 1585 | authorized: boolean; 1586 | authorizationError: Error; 1587 | getPeerCertificate(): any; 1588 | getCipher: { 1589 | name: string; 1590 | version: string; 1591 | }; 1592 | address: { 1593 | port: number; 1594 | family: string; 1595 | address: string; 1596 | }; 1597 | remoteAddress: string; 1598 | remotePort: number; 1599 | } 1600 | 1601 | export interface SecurePair { 1602 | encrypted: any; 1603 | cleartext: any; 1604 | } 1605 | 1606 | export interface SecureContextOptions { 1607 | pfx?: any; //string | buffer 1608 | key?: any; //string | buffer 1609 | passphrase?: string; 1610 | cert?: any; // string | buffer 1611 | ca?: any; // string | buffer 1612 | crl?: any; // string | string[] 1613 | ciphers?: string; 1614 | honorCipherOrder?: boolean; 1615 | } 1616 | 1617 | export interface SecureContext { 1618 | context: any; 1619 | } 1620 | 1621 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 1622 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 1623 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1624 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1625 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1626 | export function createSecureContext(details: SecureContextOptions): SecureContext; 1627 | } 1628 | 1629 | declare module "crypto" { 1630 | export interface CredentialDetails { 1631 | pfx: string; 1632 | key: string; 1633 | passphrase: string; 1634 | cert: string; 1635 | ca: any; //string | string array 1636 | crl: any; //string | string array 1637 | ciphers: string; 1638 | } 1639 | export interface Credentials { context?: any; } 1640 | export function createCredentials(details: CredentialDetails): Credentials; 1641 | export function createHash(algorithm: string): Hash; 1642 | export function createHmac(algorithm: string, key: string): Hmac; 1643 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1644 | interface Hash { 1645 | update(data: any, input_encoding?: string): Hash; 1646 | digest(encoding: 'buffer'): Buffer; 1647 | digest(encoding: string): any; 1648 | digest(): Buffer; 1649 | } 1650 | interface Hmac { 1651 | update(data: any, input_encoding?: string): Hmac; 1652 | digest(encoding: 'buffer'): Buffer; 1653 | digest(encoding: string): any; 1654 | digest(): Buffer; 1655 | } 1656 | export function createCipher(algorithm: string, password: any): Cipher; 1657 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1658 | interface Cipher { 1659 | update(data: Buffer): Buffer; 1660 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1661 | final(): Buffer; 1662 | final(output_encoding: string): string; 1663 | setAutoPadding(auto_padding: boolean): void; 1664 | } 1665 | export function createDecipher(algorithm: string, password: any): Decipher; 1666 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1667 | interface Decipher { 1668 | update(data: Buffer): Buffer; 1669 | update(data: string, input_encoding?: string, output_encoding?: string): string; 1670 | final(): Buffer; 1671 | final(output_encoding: string): string; 1672 | setAutoPadding(auto_padding: boolean): void; 1673 | } 1674 | export function createSign(algorithm: string): Signer; 1675 | interface Signer extends NodeJS.WritableStream { 1676 | update(data: any): void; 1677 | sign(private_key: string, output_format: string): string; 1678 | } 1679 | export function createVerify(algorith: string): Verify; 1680 | interface Verify extends NodeJS.WritableStream { 1681 | update(data: any): void; 1682 | verify(object: string, signature: string, signature_format?: string): boolean; 1683 | } 1684 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1685 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1686 | interface DiffieHellman { 1687 | generateKeys(encoding?: string): string; 1688 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1689 | getPrime(encoding?: string): string; 1690 | getGenerator(encoding: string): string; 1691 | getPublicKey(encoding?: string): string; 1692 | getPrivateKey(encoding?: string): string; 1693 | setPublicKey(public_key: string, encoding?: string): void; 1694 | setPrivateKey(public_key: string, encoding?: string): void; 1695 | } 1696 | export function getDiffieHellman(group_name: string): DiffieHellman; 1697 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1698 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; 1699 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; 1700 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number, digest: string) : Buffer; 1701 | export function randomBytes(size: number): Buffer; 1702 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1703 | export function pseudoRandomBytes(size: number): Buffer; 1704 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1705 | } 1706 | 1707 | declare module "stream" { 1708 | import * as events from "events"; 1709 | 1710 | export class Stream extends events.EventEmitter { 1711 | pipe(destination: T, options?: { end?: boolean; }): T; 1712 | } 1713 | 1714 | export interface ReadableOptions { 1715 | highWaterMark?: number; 1716 | encoding?: string; 1717 | objectMode?: boolean; 1718 | } 1719 | 1720 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1721 | readable: boolean; 1722 | constructor(opts?: ReadableOptions); 1723 | _read(size: number): void; 1724 | read(size?: number): any; 1725 | setEncoding(encoding: string): void; 1726 | pause(): void; 1727 | resume(): void; 1728 | pipe(destination: T, options?: { end?: boolean; }): T; 1729 | unpipe(destination?: T): void; 1730 | unshift(chunk: any): void; 1731 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1732 | push(chunk: any, encoding?: string): boolean; 1733 | } 1734 | 1735 | export interface WritableOptions { 1736 | highWaterMark?: number; 1737 | decodeStrings?: boolean; 1738 | objectMode?: boolean; 1739 | } 1740 | 1741 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1742 | writable: boolean; 1743 | constructor(opts?: WritableOptions); 1744 | _write(chunk: any, encoding: string, callback: Function): void; 1745 | write(chunk: any, cb?: Function): boolean; 1746 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1747 | end(): void; 1748 | end(chunk: any, cb?: Function): void; 1749 | end(chunk: any, encoding?: string, cb?: Function): void; 1750 | } 1751 | 1752 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1753 | allowHalfOpen?: boolean; 1754 | } 1755 | 1756 | // Note: Duplex extends both Readable and Writable. 1757 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1758 | writable: boolean; 1759 | constructor(opts?: DuplexOptions); 1760 | _write(chunk: any, encoding: string, callback: Function): void; 1761 | write(chunk: any, cb?: Function): boolean; 1762 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1763 | end(): void; 1764 | end(chunk: any, cb?: Function): void; 1765 | end(chunk: any, encoding?: string, cb?: Function): void; 1766 | } 1767 | 1768 | export interface TransformOptions extends ReadableOptions, WritableOptions {} 1769 | 1770 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1771 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1772 | readable: boolean; 1773 | writable: boolean; 1774 | constructor(opts?: TransformOptions); 1775 | _transform(chunk: any, encoding: string, callback: Function): void; 1776 | _flush(callback: Function): void; 1777 | read(size?: number): any; 1778 | setEncoding(encoding: string): void; 1779 | pause(): void; 1780 | resume(): void; 1781 | pipe(destination: T, options?: { end?: boolean; }): T; 1782 | unpipe(destination?: T): void; 1783 | unshift(chunk: any): void; 1784 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1785 | push(chunk: any, encoding?: string): boolean; 1786 | write(chunk: any, cb?: Function): boolean; 1787 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1788 | end(): void; 1789 | end(chunk: any, cb?: Function): void; 1790 | end(chunk: any, encoding?: string, cb?: Function): void; 1791 | } 1792 | 1793 | export class PassThrough extends Transform {} 1794 | } 1795 | 1796 | declare module "util" { 1797 | export interface InspectOptions { 1798 | showHidden?: boolean; 1799 | depth?: number; 1800 | colors?: boolean; 1801 | customInspect?: boolean; 1802 | } 1803 | 1804 | export function format(format: any, ...param: any[]): string; 1805 | export function debug(string: string): void; 1806 | export function error(...param: any[]): void; 1807 | export function puts(...param: any[]): void; 1808 | export function print(...param: any[]): void; 1809 | export function log(string: string): void; 1810 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 1811 | export function inspect(object: any, options: InspectOptions): string; 1812 | export function isArray(object: any): boolean; 1813 | export function isRegExp(object: any): boolean; 1814 | export function isDate(object: any): boolean; 1815 | export function isError(object: any): boolean; 1816 | export function inherits(constructor: any, superConstructor: any): void; 1817 | export function debuglog(key:string): (msg:string,...param: any[])=>void; 1818 | } 1819 | 1820 | declare module "assert" { 1821 | function internal (value: any, message?: string): void; 1822 | module internal { 1823 | export class AssertionError implements Error { 1824 | name: string; 1825 | message: string; 1826 | actual: any; 1827 | expected: any; 1828 | operator: string; 1829 | generatedMessage: boolean; 1830 | 1831 | constructor(options?: {message?: string; actual?: any; expected?: any; 1832 | operator?: string; stackStartFunction?: Function}); 1833 | } 1834 | 1835 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 1836 | export function ok(value: any, message?: string): void; 1837 | export function equal(actual: any, expected: any, message?: string): void; 1838 | export function notEqual(actual: any, expected: any, message?: string): void; 1839 | export function deepEqual(actual: any, expected: any, message?: string): void; 1840 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 1841 | export function strictEqual(actual: any, expected: any, message?: string): void; 1842 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 1843 | export function deepStrictEqual(actual: any, expected: any, message?: string): void; 1844 | export function notDeepStrictEqual(actual: any, expected: any, message?: string): void; 1845 | export var throws: { 1846 | (block: Function, message?: string): void; 1847 | (block: Function, error: Function, message?: string): void; 1848 | (block: Function, error: RegExp, message?: string): void; 1849 | (block: Function, error: (err: any) => boolean, message?: string): void; 1850 | }; 1851 | 1852 | export var doesNotThrow: { 1853 | (block: Function, message?: string): void; 1854 | (block: Function, error: Function, message?: string): void; 1855 | (block: Function, error: RegExp, message?: string): void; 1856 | (block: Function, error: (err: any) => boolean, message?: string): void; 1857 | }; 1858 | 1859 | export function ifError(value: any): void; 1860 | } 1861 | 1862 | export = internal; 1863 | } 1864 | 1865 | declare module "tty" { 1866 | import * as net from "net"; 1867 | 1868 | export function isatty(fd: number): boolean; 1869 | export interface ReadStream extends net.Socket { 1870 | isRaw: boolean; 1871 | setRawMode(mode: boolean): void; 1872 | } 1873 | export interface WriteStream extends net.Socket { 1874 | columns: number; 1875 | rows: number; 1876 | } 1877 | } 1878 | 1879 | declare module "domain" { 1880 | import * as events from "events"; 1881 | 1882 | export class Domain extends events.EventEmitter { 1883 | run(fn: Function): void; 1884 | add(emitter: events.EventEmitter): void; 1885 | remove(emitter: events.EventEmitter): void; 1886 | bind(cb: (err: Error, data: any) => any): any; 1887 | intercept(cb: (data: any) => any): any; 1888 | dispose(): void; 1889 | 1890 | addListener(event: string, listener: Function): Domain; 1891 | on(event: string, listener: Function): Domain; 1892 | once(event: string, listener: Function): Domain; 1893 | removeListener(event: string, listener: Function): Domain; 1894 | removeAllListeners(event?: string): Domain; 1895 | } 1896 | 1897 | export function create(): Domain; 1898 | } 1899 | 1900 | declare module "constants" { 1901 | export var E2BIG: number; 1902 | export var EACCES: number; 1903 | export var EADDRINUSE: number; 1904 | export var EADDRNOTAVAIL: number; 1905 | export var EAFNOSUPPORT: number; 1906 | export var EAGAIN: number; 1907 | export var EALREADY: number; 1908 | export var EBADF: number; 1909 | export var EBADMSG: number; 1910 | export var EBUSY: number; 1911 | export var ECANCELED: number; 1912 | export var ECHILD: number; 1913 | export var ECONNABORTED: number; 1914 | export var ECONNREFUSED: number; 1915 | export var ECONNRESET: number; 1916 | export var EDEADLK: number; 1917 | export var EDESTADDRREQ: number; 1918 | export var EDOM: number; 1919 | export var EEXIST: number; 1920 | export var EFAULT: number; 1921 | export var EFBIG: number; 1922 | export var EHOSTUNREACH: number; 1923 | export var EIDRM: number; 1924 | export var EILSEQ: number; 1925 | export var EINPROGRESS: number; 1926 | export var EINTR: number; 1927 | export var EINVAL: number; 1928 | export var EIO: number; 1929 | export var EISCONN: number; 1930 | export var EISDIR: number; 1931 | export var ELOOP: number; 1932 | export var EMFILE: number; 1933 | export var EMLINK: number; 1934 | export var EMSGSIZE: number; 1935 | export var ENAMETOOLONG: number; 1936 | export var ENETDOWN: number; 1937 | export var ENETRESET: number; 1938 | export var ENETUNREACH: number; 1939 | export var ENFILE: number; 1940 | export var ENOBUFS: number; 1941 | export var ENODATA: number; 1942 | export var ENODEV: number; 1943 | export var ENOENT: number; 1944 | export var ENOEXEC: number; 1945 | export var ENOLCK: number; 1946 | export var ENOLINK: number; 1947 | export var ENOMEM: number; 1948 | export var ENOMSG: number; 1949 | export var ENOPROTOOPT: number; 1950 | export var ENOSPC: number; 1951 | export var ENOSR: number; 1952 | export var ENOSTR: number; 1953 | export var ENOSYS: number; 1954 | export var ENOTCONN: number; 1955 | export var ENOTDIR: number; 1956 | export var ENOTEMPTY: number; 1957 | export var ENOTSOCK: number; 1958 | export var ENOTSUP: number; 1959 | export var ENOTTY: number; 1960 | export var ENXIO: number; 1961 | export var EOPNOTSUPP: number; 1962 | export var EOVERFLOW: number; 1963 | export var EPERM: number; 1964 | export var EPIPE: number; 1965 | export var EPROTO: number; 1966 | export var EPROTONOSUPPORT: number; 1967 | export var EPROTOTYPE: number; 1968 | export var ERANGE: number; 1969 | export var EROFS: number; 1970 | export var ESPIPE: number; 1971 | export var ESRCH: number; 1972 | export var ETIME: number; 1973 | export var ETIMEDOUT: number; 1974 | export var ETXTBSY: number; 1975 | export var EWOULDBLOCK: number; 1976 | export var EXDEV: number; 1977 | export var WSAEINTR: number; 1978 | export var WSAEBADF: number; 1979 | export var WSAEACCES: number; 1980 | export var WSAEFAULT: number; 1981 | export var WSAEINVAL: number; 1982 | export var WSAEMFILE: number; 1983 | export var WSAEWOULDBLOCK: number; 1984 | export var WSAEINPROGRESS: number; 1985 | export var WSAEALREADY: number; 1986 | export var WSAENOTSOCK: number; 1987 | export var WSAEDESTADDRREQ: number; 1988 | export var WSAEMSGSIZE: number; 1989 | export var WSAEPROTOTYPE: number; 1990 | export var WSAENOPROTOOPT: number; 1991 | export var WSAEPROTONOSUPPORT: number; 1992 | export var WSAESOCKTNOSUPPORT: number; 1993 | export var WSAEOPNOTSUPP: number; 1994 | export var WSAEPFNOSUPPORT: number; 1995 | export var WSAEAFNOSUPPORT: number; 1996 | export var WSAEADDRINUSE: number; 1997 | export var WSAEADDRNOTAVAIL: number; 1998 | export var WSAENETDOWN: number; 1999 | export var WSAENETUNREACH: number; 2000 | export var WSAENETRESET: number; 2001 | export var WSAECONNABORTED: number; 2002 | export var WSAECONNRESET: number; 2003 | export var WSAENOBUFS: number; 2004 | export var WSAEISCONN: number; 2005 | export var WSAENOTCONN: number; 2006 | export var WSAESHUTDOWN: number; 2007 | export var WSAETOOMANYREFS: number; 2008 | export var WSAETIMEDOUT: number; 2009 | export var WSAECONNREFUSED: number; 2010 | export var WSAELOOP: number; 2011 | export var WSAENAMETOOLONG: number; 2012 | export var WSAEHOSTDOWN: number; 2013 | export var WSAEHOSTUNREACH: number; 2014 | export var WSAENOTEMPTY: number; 2015 | export var WSAEPROCLIM: number; 2016 | export var WSAEUSERS: number; 2017 | export var WSAEDQUOT: number; 2018 | export var WSAESTALE: number; 2019 | export var WSAEREMOTE: number; 2020 | export var WSASYSNOTREADY: number; 2021 | export var WSAVERNOTSUPPORTED: number; 2022 | export var WSANOTINITIALISED: number; 2023 | export var WSAEDISCON: number; 2024 | export var WSAENOMORE: number; 2025 | export var WSAECANCELLED: number; 2026 | export var WSAEINVALIDPROCTABLE: number; 2027 | export var WSAEINVALIDPROVIDER: number; 2028 | export var WSAEPROVIDERFAILEDINIT: number; 2029 | export var WSASYSCALLFAILURE: number; 2030 | export var WSASERVICE_NOT_FOUND: number; 2031 | export var WSATYPE_NOT_FOUND: number; 2032 | export var WSA_E_NO_MORE: number; 2033 | export var WSA_E_CANCELLED: number; 2034 | export var WSAEREFUSED: number; 2035 | export var SIGHUP: number; 2036 | export var SIGINT: number; 2037 | export var SIGILL: number; 2038 | export var SIGABRT: number; 2039 | export var SIGFPE: number; 2040 | export var SIGKILL: number; 2041 | export var SIGSEGV: number; 2042 | export var SIGTERM: number; 2043 | export var SIGBREAK: number; 2044 | export var SIGWINCH: number; 2045 | export var SSL_OP_ALL: number; 2046 | export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; 2047 | export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; 2048 | export var SSL_OP_CISCO_ANYCONNECT: number; 2049 | export var SSL_OP_COOKIE_EXCHANGE: number; 2050 | export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; 2051 | export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; 2052 | export var SSL_OP_EPHEMERAL_RSA: number; 2053 | export var SSL_OP_LEGACY_SERVER_CONNECT: number; 2054 | export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; 2055 | export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; 2056 | export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; 2057 | export var SSL_OP_NETSCAPE_CA_DN_BUG: number; 2058 | export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; 2059 | export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; 2060 | export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; 2061 | export var SSL_OP_NO_COMPRESSION: number; 2062 | export var SSL_OP_NO_QUERY_MTU: number; 2063 | export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; 2064 | export var SSL_OP_NO_SSLv2: number; 2065 | export var SSL_OP_NO_SSLv3: number; 2066 | export var SSL_OP_NO_TICKET: number; 2067 | export var SSL_OP_NO_TLSv1: number; 2068 | export var SSL_OP_NO_TLSv1_1: number; 2069 | export var SSL_OP_NO_TLSv1_2: number; 2070 | export var SSL_OP_PKCS1_CHECK_1: number; 2071 | export var SSL_OP_PKCS1_CHECK_2: number; 2072 | export var SSL_OP_SINGLE_DH_USE: number; 2073 | export var SSL_OP_SINGLE_ECDH_USE: number; 2074 | export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; 2075 | export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; 2076 | export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; 2077 | export var SSL_OP_TLS_D5_BUG: number; 2078 | export var SSL_OP_TLS_ROLLBACK_BUG: number; 2079 | export var ENGINE_METHOD_DSA: number; 2080 | export var ENGINE_METHOD_DH: number; 2081 | export var ENGINE_METHOD_RAND: number; 2082 | export var ENGINE_METHOD_ECDH: number; 2083 | export var ENGINE_METHOD_ECDSA: number; 2084 | export var ENGINE_METHOD_CIPHERS: number; 2085 | export var ENGINE_METHOD_DIGESTS: number; 2086 | export var ENGINE_METHOD_STORE: number; 2087 | export var ENGINE_METHOD_PKEY_METHS: number; 2088 | export var ENGINE_METHOD_PKEY_ASN1_METHS: number; 2089 | export var ENGINE_METHOD_ALL: number; 2090 | export var ENGINE_METHOD_NONE: number; 2091 | export var DH_CHECK_P_NOT_SAFE_PRIME: number; 2092 | export var DH_CHECK_P_NOT_PRIME: number; 2093 | export var DH_UNABLE_TO_CHECK_GENERATOR: number; 2094 | export var DH_NOT_SUITABLE_GENERATOR: number; 2095 | export var NPN_ENABLED: number; 2096 | export var RSA_PKCS1_PADDING: number; 2097 | export var RSA_SSLV23_PADDING: number; 2098 | export var RSA_NO_PADDING: number; 2099 | export var RSA_PKCS1_OAEP_PADDING: number; 2100 | export var RSA_X931_PADDING: number; 2101 | export var RSA_PKCS1_PSS_PADDING: number; 2102 | export var POINT_CONVERSION_COMPRESSED: number; 2103 | export var POINT_CONVERSION_UNCOMPRESSED: number; 2104 | export var POINT_CONVERSION_HYBRID: number; 2105 | export var O_RDONLY: number; 2106 | export var O_WRONLY: number; 2107 | export var O_RDWR: number; 2108 | export var S_IFMT: number; 2109 | export var S_IFREG: number; 2110 | export var S_IFDIR: number; 2111 | export var S_IFCHR: number; 2112 | export var S_IFLNK: number; 2113 | export var O_CREAT: number; 2114 | export var O_EXCL: number; 2115 | export var O_TRUNC: number; 2116 | export var O_APPEND: number; 2117 | export var F_OK: number; 2118 | export var R_OK: number; 2119 | export var W_OK: number; 2120 | export var X_OK: number; 2121 | export var UV_UDP_REUSEADDR: number; 2122 | } 2123 | -------------------------------------------------------------------------------- /generators/app/templates/typings/q/Q.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Q 2 | // Project: https://github.com/kriskowal/q 3 | // Definitions by: Barrie Nemetchek , Andrew Gaspar , John Reilly 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /** 7 | * If value is a Q promise, returns the promise. 8 | * If value is a promise from another library it is coerced into a Q promise (where possible). 9 | */ 10 | declare function Q(promise: Q.IPromise): Q.Promise; 11 | /** 12 | * If value is not a promise, returns a promise that is fulfilled with value. 13 | */ 14 | declare function Q(value: T): Q.Promise; 15 | 16 | declare module Q { 17 | interface IPromise { 18 | then(onFulfill?: (value: T) => U | IPromise, onReject?: (error: any) => U | IPromise): IPromise; 19 | } 20 | 21 | interface Deferred { 22 | promise: Promise; 23 | resolve(value?: T): void; 24 | reject(reason: any): void; 25 | notify(value: any): void; 26 | makeNodeResolver(): (reason: any, value: T) => void; 27 | } 28 | 29 | interface Promise { 30 | /** 31 | * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object. 32 | 33 | * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished. 34 | */ 35 | fin(finallyCallback: () => any): Promise; 36 | /** 37 | * Like a finally clause, allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful for collecting resources regardless of whether a job succeeded, like closing a database connection, shutting a server down, or deleting an unneeded key from an object. 38 | 39 | * finally returns a promise, which will become resolved with the same fulfillment value or rejection reason as promise. However, if callback returns a promise, the resolution of the returned promise will be delayed until the promise returned from callback is finished. 40 | */ 41 | finally(finallyCallback: () => any): Promise; 42 | 43 | /** 44 | * The then method from the Promises/A+ specification, with an additional progress handler. 45 | */ 46 | then(onFulfill?: (value: T) => U | IPromise, onReject?: (error: any) => U | IPromise, onProgress?: Function): Promise; 47 | 48 | /** 49 | * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason. 50 | * 51 | * This is especially useful in conjunction with all 52 | */ 53 | spread(onFulfill: (...args: any[]) => IPromise | U, onReject?: (reason: any) => IPromise | U): Promise; 54 | 55 | fail(onRejected: (reason: any) => U | IPromise): Promise; 56 | 57 | /** 58 | * A sugar method, equivalent to promise.then(undefined, onRejected). 59 | */ 60 | catch(onRejected: (reason: any) => U | IPromise): Promise; 61 | 62 | /** 63 | * A sugar method, equivalent to promise.then(undefined, undefined, onProgress). 64 | */ 65 | progress(onProgress: (progress: any) => any): Promise; 66 | 67 | /** 68 | * Much like then, but with different behavior around unhandled rejection. If there is an unhandled rejection, either because promise is rejected and no onRejected callback was provided, or because onFulfilled or onRejected threw an error or returned a rejected promise, the resulting rejection reason is thrown as an exception in a future turn of the event loop. 69 | * 70 | * This method should be used to terminate chains of promises that will not be passed elsewhere. Since exceptions thrown in then callbacks are consumed and transformed into rejections, exceptions at the end of the chain are easy to accidentally, silently ignore. By arranging for the exception to be thrown in a future turn of the event loop, so that it won't be caught, it causes an onerror event on the browser window, or an uncaughtException event on Node.js's process object. 71 | * 72 | * Exceptions thrown by done will have long stack traces, if Q.longStackSupport is set to true. If Q.onerror is set, exceptions will be delivered there instead of thrown in a future turn. 73 | * 74 | * The Golden Rule of done vs. then usage is: either return your promise to someone else, or if the chain ends with you, call done to terminate it. 75 | */ 76 | done(onFulfilled?: (value: T) => any, onRejected?: (reason: any) => any, onProgress?: (progress: any) => any): void; 77 | 78 | /** 79 | * If callback is a function, assumes it's a Node.js-style callback, and calls it as either callback(rejectionReason) when/if promise becomes rejected, or as callback(null, fulfillmentValue) when/if promise becomes fulfilled. If callback is not a function, simply returns promise. 80 | */ 81 | nodeify(callback: (reason: any, value: any) => void): Promise; 82 | 83 | /** 84 | * Returns a promise to get the named property of an object. Essentially equivalent to 85 | * 86 | * promise.then(function (o) { 87 | * return o[propertyName]; 88 | * }); 89 | */ 90 | get(propertyName: String): Promise; 91 | set(propertyName: String, value: any): Promise; 92 | delete(propertyName: String): Promise; 93 | /** 94 | * Returns a promise for the result of calling the named method of an object with the given array of arguments. The object itself is this in the function, just like a synchronous method call. Essentially equivalent to 95 | * 96 | * promise.then(function (o) { 97 | * return o[methodName].apply(o, args); 98 | * }); 99 | */ 100 | post(methodName: String, args: any[]): Promise; 101 | /** 102 | * Returns a promise for the result of calling the named method of an object with the given variadic arguments. The object itself is this in the function, just like a synchronous method call. 103 | */ 104 | invoke(methodName: String, ...args: any[]): Promise; 105 | fapply(args: any[]): Promise; 106 | fcall(...args: any[]): Promise; 107 | 108 | /** 109 | * Returns a promise for an array of the property names of an object. Essentially equivalent to 110 | * 111 | * promise.then(function (o) { 112 | * return Object.keys(o); 113 | * }); 114 | */ 115 | keys(): Promise; 116 | 117 | /** 118 | * A sugar method, equivalent to promise.then(function () { return value; }). 119 | */ 120 | thenResolve(value: U): Promise; 121 | /** 122 | * A sugar method, equivalent to promise.then(function () { throw reason; }). 123 | */ 124 | thenReject(reason: any): Promise; 125 | 126 | /** 127 | * Attaches a handler that will observe the value of the promise when it becomes fulfilled, returning a promise for that same value, perhaps deferred but not replaced by the promise returned by the onFulfilled handler. 128 | */ 129 | tap(onFulfilled: (value: T) => any): Promise; 130 | 131 | timeout(ms: number, message?: string): Promise; 132 | /** 133 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 134 | */ 135 | delay(ms: number): Promise; 136 | 137 | /** 138 | * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true. 139 | */ 140 | isFulfilled(): boolean; 141 | /** 142 | * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false. 143 | */ 144 | isRejected(): boolean; 145 | /** 146 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 147 | */ 148 | isPending(): boolean; 149 | 150 | valueOf(): any; 151 | 152 | /** 153 | * Returns a "state snapshot" object, which will be in one of three forms: 154 | * 155 | * - { state: "pending" } 156 | * - { state: "fulfilled", value: } 157 | * - { state: "rejected", reason: } 158 | */ 159 | inspect(): PromiseState; 160 | } 161 | 162 | interface PromiseState { 163 | /** 164 | * "fulfilled", "rejected", "pending" 165 | */ 166 | state: string; 167 | value?: T; 168 | reason?: any; 169 | } 170 | 171 | // If no value provided, returned promise will be of void type 172 | export function when(): Promise; 173 | 174 | // if no fulfill, reject, or progress provided, returned promise will be of same type 175 | export function when(value: T | IPromise): Promise; 176 | 177 | // If a non-promise value is provided, it will not reject or progress 178 | export function when(value: T | IPromise, onFulfilled: (val: T) => U | IPromise, onRejected?: (reason: any) => U | IPromise, onProgress?: (progress: any) => any): Promise; 179 | 180 | /** 181 | * Currently "impossible" (and I use the term loosely) to implement due to TypeScript limitations as it is now. 182 | * See: https://github.com/Microsoft/TypeScript/issues/1784 for discussion on it. 183 | */ 184 | // export function try(method: Function, ...args: any[]): Promise; 185 | 186 | export function fbind(method: (...args: any[]) => T | IPromise, ...args: any[]): (...args: any[]) => Promise; 187 | 188 | export function fcall(method: (...args: any[]) => T, ...args: any[]): Promise; 189 | 190 | export function send(obj: any, functionName: string, ...args: any[]): Promise; 191 | export function invoke(obj: any, functionName: string, ...args: any[]): Promise; 192 | export function mcall(obj: any, functionName: string, ...args: any[]): Promise; 193 | 194 | export function denodeify(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; 195 | export function nbind(nodeFunction: Function, thisArg: any, ...args: any[]): (...args: any[]) => Promise; 196 | export function nfbind(nodeFunction: Function, ...args: any[]): (...args: any[]) => Promise; 197 | export function nfcall(nodeFunction: Function, ...args: any[]): Promise; 198 | export function nfapply(nodeFunction: Function, args: any[]): Promise; 199 | 200 | export function ninvoke(nodeModule: any, functionName: string, ...args: any[]): Promise; 201 | export function npost(nodeModule: any, functionName: string, args: any[]): Promise; 202 | export function nsend(nodeModule: any, functionName: string, ...args: any[]): Promise; 203 | export function nmcall(nodeModule: any, functionName: string, ...args: any[]): Promise; 204 | 205 | /** 206 | * Returns a promise that is fulfilled with an array containing the fulfillment value of each promise, or is rejected with the same rejection reason as the first promise to be rejected. 207 | */ 208 | export function all(promises: IPromise[]): Promise; 209 | 210 | /** 211 | * Returns a promise for the first of an array of promises to become settled. 212 | */ 213 | export function race(promises: IPromise[]): Promise; 214 | 215 | /** 216 | * Returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected. 217 | */ 218 | export function allSettled(promises: IPromise[]): Promise[]>; 219 | 220 | export function allResolved(promises: IPromise[]): Promise[]>; 221 | 222 | /** 223 | * Like then, but "spreads" the array into a variadic fulfillment handler. If any of the promises in the array are rejected, instead calls onRejected with the first rejected promise's rejection reason. 224 | * This is especially useful in conjunction with all. 225 | */ 226 | export function spread(promises: IPromise[], onFulfilled: (...args: T[]) => U | IPromise, onRejected?: (reason: any) => U | IPromise): Promise; 227 | 228 | /** 229 | * Returns a promise that will have the same result as promise, except that if promise is not fulfilled or rejected before ms milliseconds, the returned promise will be rejected with an Error with the given message. If message is not supplied, the message will be "Timed out after " + ms + " ms". 230 | */ 231 | export function timeout(promise: Promise, ms: number, message?: string): Promise; 232 | 233 | /** 234 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 235 | */ 236 | export function delay(promise: Promise, ms: number): Promise; 237 | /** 238 | * Returns a promise that will have the same result as promise, but will only be fulfilled or rejected after at least ms milliseconds have passed. 239 | */ 240 | export function delay(value: T, ms: number): Promise; 241 | /** 242 | * Returns a promise that will be fulfilled with undefined after at least ms milliseconds have passed. 243 | */ 244 | export function delay(ms: number): Promise ; 245 | /** 246 | * Returns whether a given promise is in the fulfilled state. When the static version is used on non-promises, the result is always true. 247 | */ 248 | export function isFulfilled(promise: Promise): boolean; 249 | /** 250 | * Returns whether a given promise is in the rejected state. When the static version is used on non-promises, the result is always false. 251 | */ 252 | export function isRejected(promise: Promise): boolean; 253 | /** 254 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 255 | */ 256 | export function isPending(promise: Promise): boolean; 257 | 258 | /** 259 | * Returns a "deferred" object with a: 260 | * promise property 261 | * resolve(value) method 262 | * reject(reason) method 263 | * notify(value) method 264 | * makeNodeResolver() method 265 | */ 266 | export function defer(): Deferred; 267 | 268 | /** 269 | * Returns a promise that is rejected with reason. 270 | */ 271 | export function reject(reason?: any): Promise; 272 | 273 | export function Promise(resolver: (resolve: (val: T | IPromise) => void , reject: (reason: any) => void , notify: (progress: any) => void ) => void ): Promise; 274 | 275 | /** 276 | * Creates a new version of func that accepts any combination of promise and non-promise values, converting them to their fulfillment values before calling the original func. The returned version also always returns a promise: if func does a return or throw, then Q.promised(func) will return fulfilled or rejected promise, respectively. 277 | * 278 | * This can be useful for creating functions that accept either promises or non-promise values, and for ensuring that the function always returns a promise even in the face of unintentional thrown exceptions. 279 | */ 280 | export function promised(callback: (...args: any[]) => T): (...args: any[]) => Promise; 281 | 282 | /** 283 | * Returns whether the given value is a Q promise. 284 | */ 285 | export function isPromise(object: any): boolean; 286 | /** 287 | * Returns whether the given value is a promise (i.e. it's an object with a then function). 288 | */ 289 | export function isPromiseAlike(object: any): boolean; 290 | /** 291 | * Returns whether a given promise is in the pending state. When the static version is used on non-promises, the result is always false. 292 | */ 293 | export function isPending(object: any): boolean; 294 | 295 | /** 296 | * This is an experimental tool for converting a generator function into a deferred function. This has the potential of reducing nested callbacks in engines that support yield. 297 | */ 298 | export function async(generatorFunction: any): (...args: any[]) => Promise; 299 | export function nextTick(callback: Function): void; 300 | 301 | /** 302 | * A settable property that will intercept any uncaught errors that would otherwise be thrown in the next tick of the event loop, usually as a result of done. Can be useful for getting the full stack trace of an error in browsers, which is not usually possible with window.onerror. 303 | */ 304 | export var onerror: (reason: any) => void; 305 | /** 306 | * A settable property that lets you turn on long stack trace support. If turned on, "stack jumps" will be tracked across asynchronous promise operations, so that if an uncaught error is thrown by done or a rejection reason's stack property is inspected in a rejection callback, a long stack trace is produced. 307 | */ 308 | export var longStackSupport: boolean; 309 | 310 | /** 311 | * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). 312 | * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. 313 | * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. 314 | * Calling resolve with a non-promise value causes promise to be fulfilled with that value. 315 | */ 316 | export function resolve(object: IPromise): Promise; 317 | /** 318 | * Calling resolve with a pending promise causes promise to wait on the passed promise, becoming fulfilled with its fulfillment value or rejected with its rejection reason (or staying pending forever, if the passed promise does). 319 | * Calling resolve with a rejected promise causes promise to be rejected with the passed promise's rejection reason. 320 | * Calling resolve with a fulfilled promise causes promise to be fulfilled with the passed promise's fulfillment value. 321 | * Calling resolve with a non-promise value causes promise to be fulfilled with that value. 322 | */ 323 | export function resolve(object: T): Promise; 324 | 325 | /** 326 | * Resets the global "Q" variable to the value it has before Q was loaded. 327 | * This will either be undefined if there was no version or the version of Q which was already loaded before. 328 | * @returns { The last version of Q. } 329 | */ 330 | export function noConflict(): typeof Q; 331 | } 332 | 333 | declare module "q" { 334 | export = Q; 335 | } 336 | -------------------------------------------------------------------------------- /generators/app/templates/typings/serve-static/serve-static.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for serve-static 1.7.1 2 | // Project: https://github.com/expressjs/serve-static 3 | // Definitions by: Uros Smolnik 4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped 5 | 6 | /* =================== USAGE =================== 7 | 8 | import * as serveStatic from "serve-static"; 9 | app.use(serveStatic("public/ftp", {"index": ["default.html", "default.htm"]})) 10 | 11 | =============================================== */ 12 | 13 | /// 14 | /// 15 | 16 | declare module "serve-static" { 17 | import * as express from "express"; 18 | 19 | /** 20 | * Create a new middleware function to serve files from within a given root directory. 21 | * The file to serve will be determined by combining req.url with the provided root directory. 22 | * When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs. 23 | */ 24 | function serveStatic(root: string, options?: { 25 | /** 26 | * Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). 27 | * Note this check is done on the path itself without checking if the path actually exists on the disk. 28 | * If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny"). 29 | * The default value is 'ignore'. 30 | * 'allow' No special treatment for dotfiles 31 | * 'deny' Send a 403 for any request for a dotfile 32 | * 'ignore' Pretend like the dotfile does not exist and call next() 33 | */ 34 | dotfiles?: string; 35 | 36 | /** 37 | * Enable or disable etag generation, defaults to true. 38 | */ 39 | etag?: boolean; 40 | 41 | /** 42 | * Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for. 43 | * The first that exists will be served. Example: ['html', 'htm']. 44 | * The default value is false. 45 | */ 46 | extensions?: string[]; 47 | 48 | /** 49 | * By default this module will send "index.html" files in response to a request on a directory. 50 | * To disable this set false or to supply a new index pass a string or an array in preferred order. 51 | */ 52 | index?: boolean|string|string[]; 53 | 54 | /** 55 | * Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value. 56 | */ 57 | lastModified?: boolean; 58 | 59 | /** 60 | * Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module. 61 | */ 62 | maxAge?: number|string; 63 | 64 | /** 65 | * Redirect to trailing "/" when the pathname is a dir. Defaults to true. 66 | */ 67 | redirect?: boolean; 68 | 69 | /** 70 | * Function to set custom headers on response. Alterations to the headers need to occur synchronously. 71 | * The function is called as fn(res, path, stat), where the arguments are: 72 | * res the response object 73 | * path the file path that is being sent 74 | * stat the stat object of the file that is being sent 75 | */ 76 | setHeaders?: (res: express.Response, path: string, stat: any) => any; 77 | }): express.Handler; 78 | 79 | import * as m from "mime"; 80 | 81 | module serveStatic { 82 | var mime: typeof m; 83 | } 84 | 85 | export = serveStatic; 86 | } 87 | -------------------------------------------------------------------------------- /generators/app/templates/typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | -------------------------------------------------------------------------------- /generators/app/templates/views/error.hbs: -------------------------------------------------------------------------------- 1 |

{{message}}

2 |

{{error.status}}

3 |
{{error.stack}}
4 | -------------------------------------------------------------------------------- /generators/app/templates/views/index.hbs: -------------------------------------------------------------------------------- 1 |

{{title}}

2 |

Welcome to {{title}}

3 | -------------------------------------------------------------------------------- /generators/app/templates/views/layout.hbs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{title}} 5 | 6 | 7 | 8 | {{{body}}} 9 | 10 | 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-express-typescript", 3 | "version": "0.1.4", 4 | "description": "Yeoman generator for Express.js running on Typescript", 5 | "main": "app/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/koroandr/generator-express-typescript.git" 12 | }, 13 | "files": [ 14 | "generators" 15 | ], 16 | "keywords": [ 17 | "yeoman-generator", 18 | "typescript", 19 | "nodejs", 20 | "express", 21 | "docker" 22 | ], 23 | "author": "ak@koroandr.me", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/koroandr/generator-express-typescript/issues" 27 | }, 28 | "homepage": "https://github.com/koroandr/generator-express-typescript#readme", 29 | "dependencies": { 30 | "lodash": "^3.10.1", 31 | "yeoman-generator": "^0.22.3" 32 | } 33 | } 34 | --------------------------------------------------------------------------------