├── node-server ├── app │ └── .gitkeep ├── log │ ├── .gitkeep │ ├── access │ │ └── .gitkeep │ └── yog │ │ └── .gitkeep ├── views │ └── .gitkeep ├── plugins │ └── .gitkeep ├── static │ └── .gitkeep ├── README.md ├── .jshintrc ├── conf │ ├── ral │ │ └── demo.js │ └── plugins │ │ ├── recv-reload.default.js │ │ ├── ral.js │ │ ├── views.js │ │ ├── dispatcher.js │ │ ├── log.js │ │ └── http.js ├── app.js ├── .npmignore ├── package.json ├── .gitignore └── LICENSE ├── my-app ├── client │ ├── config.tsx │ ├── index.scss │ ├── reducer.tsx │ ├── routes │ │ ├── home │ │ │ ├── index.scss │ │ │ └── index.tsx │ │ ├── page-a │ │ │ └── index.tsx │ │ ├── page-b │ │ │ └── index.tsx │ │ └── layout │ │ │ └── index.tsx │ ├── routes.tsx │ ├── index.tsx │ ├── stores │ │ └── user │ │ │ ├── reducer.tsx │ │ │ └── action.tsx │ ├── index.html │ └── static │ │ └── mod.js ├── typings-replacement.d.ts ├── server │ ├── router.ts │ ├── service │ │ └── index.ts │ └── action │ │ └── index.ts ├── tsconfig.json ├── fis-conf.js ├── typings │ ├── tsd.d.ts │ ├── redux-thunk │ │ └── redux-thunk.d.ts │ ├── redux │ │ └── redux.d.ts │ ├── react-router-redux │ │ └── react-router-redux.d.ts │ ├── react │ │ └── react-dom.d.ts │ ├── react-redux │ │ └── react-redux.d.ts │ ├── react-router │ │ ├── history.d.ts │ │ └── react-router.d.ts │ └── node │ │ └── node.d.ts ├── tsd.json └── package.json ├── .gitignore ├── .travis.yml ├── package.json └── README.md /node-server/app/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /node-server/log/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /node-server/views/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /node-server/log/access/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /node-server/log/yog/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /node-server/plugins/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /node-server/static/.gitkeep: -------------------------------------------------------------------------------- 1 | // keep -------------------------------------------------------------------------------- /my-app/client/config.tsx: -------------------------------------------------------------------------------- 1 | export const basename:string = '/my-app' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | lib 4 | .DS_Store 5 | dist 6 | .idea -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5.7" 4 | - "5.0" 5 | - "4.0" 6 | - "iojs" -------------------------------------------------------------------------------- /my-app/client/index.scss: -------------------------------------------------------------------------------- 1 | ._global { 2 | html, body { 3 | margin: 0; 4 | padding: 0; 5 | } 6 | } -------------------------------------------------------------------------------- /node-server/README.md: -------------------------------------------------------------------------------- 1 | YOG2 框架基础运行时模板 2 | 3 | ============================== 4 | 5 | ``` 6 | npm i -g yog2 7 | yog2 init project 8 | ``` 9 | -------------------------------------------------------------------------------- /my-app/typings-replacement.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'redux-immutablejs' { 2 | export const createReducer:any 3 | } 4 | 5 | declare module 'es6-promise'{ 6 | export const polyfill:any 7 | } -------------------------------------------------------------------------------- /node-server/.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "curly": false, 5 | "smarttabs": true, 6 | "indent": 2, 7 | "quotmark": "single", 8 | "expr": "true", 9 | "globals": { 10 | "yog": true 11 | } 12 | } -------------------------------------------------------------------------------- /my-app/server/router.ts: -------------------------------------------------------------------------------- 1 | import initService from './service' 2 | 3 | export default (router: any) => { 4 | router.use(function (req:any, res:any, next:any) { 5 | /^\/api\//.test(req.path) ? next() : router.action('index')(req, res, next) 6 | }) 7 | 8 | initService(router) 9 | } -------------------------------------------------------------------------------- /my-app/client/reducer.tsx: -------------------------------------------------------------------------------- 1 | import {combineReducers} from 'redux' 2 | import {routerReducer} from 'react-router-redux' 3 | 4 | import layout from './stores/user/reducer' 5 | 6 | // 聚合各 reducer 7 | // 将路由也加入 reducer 8 | const rootReducer = combineReducers({ 9 | routing: routerReducer, 10 | user: layout 11 | }) 12 | 13 | export default rootReducer -------------------------------------------------------------------------------- /my-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "noImplicitAny": true, 5 | "target": "es6", 6 | "removeComments": true, 7 | "preserveConstEnums": true, 8 | "experimentalDecorators": true, 9 | "jsx": "react" 10 | }, 11 | "exclude": [ 12 | "node_modules", 13 | "output", 14 | "typings" 15 | ] 16 | } -------------------------------------------------------------------------------- /my-app/client/routes/home/index.scss: -------------------------------------------------------------------------------- 1 | & { 2 | display: flex; 3 | flex-direction: column; 4 | justify-content: center; 5 | align-items: center; 6 | background-image: linear-gradient(225deg, #3e5673, #1b2530 86%, #1a242e 0); 7 | color: hsla(0, 0%, 100%, .8); 8 | height: 500px; 9 | } 10 | 11 | .title { 12 | font-size: 30px; 13 | } 14 | 15 | a { 16 | color: #cccccc; 17 | &:hover { 18 | color: white; 19 | } 20 | } -------------------------------------------------------------------------------- /node-server/conf/ral/demo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 后端服务配置DEMO 3 | * @author fis@baidu.com 4 | */ 5 | 6 | module.exports = { 7 | // 'DEMO_SERVICE': { 8 | // unpack: 'json', 9 | // pack: 'form', 10 | // method: 'POST', 11 | // encoding: 'gbk', 12 | // balance: 'random', 13 | // protocol: 'http', 14 | // retry: 2, 15 | // timeout: 500, 16 | // server: [ 17 | // { host: '127.0.0.1', port: 8080} 18 | // ] 19 | // } 20 | }; 21 | -------------------------------------------------------------------------------- /my-app/server/service/index.ts: -------------------------------------------------------------------------------- 1 | import {initService, routerDecorator} from 'fit-isomorphic-redux-tools/lib/service' 2 | export default initService 3 | 4 | class Service { 5 | @routerDecorator('/api/simple-get-function', 'get') 6 | simpleGet(options:any) { 7 | return `got get: ${options.name}` 8 | } 9 | 10 | @routerDecorator('/api/simple-post-function', 'post') 11 | simplePost(options:any) { 12 | return `got post: ${options.name}` 13 | } 14 | } 15 | 16 | new Service() -------------------------------------------------------------------------------- /my-app/fis-conf.js: -------------------------------------------------------------------------------- 1 | module.exports = conf 2 | 3 | var conf = { 4 | // 项目名 5 | modName: 'my-app', 6 | 7 | // 可选: gbk 、utf8 8 | charset: 'utf8', 9 | 10 | // 远程开发机地址 11 | host: '', 12 | 13 | // 开发机端口 14 | port: 8080, 15 | 16 | // yog2 监听端口(上传文件) 17 | receiverStaticPort: 8080 18 | } 19 | 20 | /************ 启用 tb fis3 预设配置 ************/ 21 | fis.require.prefixes.unshift('fit') 22 | fis.require('isomorphic-build')(fis, conf) 23 | 24 | /************ 自定义配置部分 ************/ 25 | -------------------------------------------------------------------------------- /my-app/client/routes/page-a/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import {Link} from 'react-router' 3 | 4 | export default class PageA extends React.Component { 5 | state = {} 6 | 7 | constructor(props:any) { 8 | super(props) 9 | } 10 | 11 | componentDidMount() { 12 | document.title = 'page A' 13 | } 14 | 15 | render() { 16 | return ( 17 |
18 | back 19 |
20 | ) 21 | } 22 | } -------------------------------------------------------------------------------- /my-app/client/routes/page-b/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import {Link} from 'react-router' 3 | 4 | export default class PageB extends React.Component { 5 | state = {} 6 | 7 | constructor(props:any) { 8 | super(props) 9 | } 10 | 11 | componentDidMount() { 12 | document.title = 'page B' 13 | } 14 | 15 | render() { 16 | return ( 17 |
18 | back 19 |
20 | ) 21 | } 22 | } -------------------------------------------------------------------------------- /my-app/client/routes.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import {Route, IndexRoute} from 'react-router' 3 | import Layout from './routes/layout/index' 4 | import Home from './routes/home/index' 5 | import PageA from './routes/page-a/index' 6 | import PageB from './routes/page-b/index' 7 | 8 | export default ( 9 | 11 | 12 | 14 | 16 | 17 | ) -------------------------------------------------------------------------------- /my-app/client/index.tsx: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import es6Promise = require('es6-promise') 5 | es6Promise.polyfill() 6 | 7 | import * as React from 'react' 8 | import * as ReactDOM from 'react-dom' 9 | import {router} from 'fit-isomorphic-redux-tools' 10 | import routes from './routes' 11 | import {basename} from './config' 12 | import reducer from './reducer' 13 | import './index.scss' 14 | 15 | const routerElement = router(routes, basename, reducer) 16 | 17 | ReactDOM.render(routerElement, document.getElementById('react-dom')) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "isomorphic-react-redux-app", 3 | "version": "1.0.0", 4 | "description": "react react-hot-loader redux redux-devtools react-router-redux immutable isomorphic fis3 yog2 webpack", 5 | "scripts": { 6 | "build": "npm run clean && NODE_ENV=production webpack -p --progress --colors --profile", 7 | "test": "NODE_ENV=test mocha --compilers js:babel-core/register --recursive" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/caljrimmer/isomorphic-redux-app.git" 12 | }, 13 | "license": "MIT" 14 | } 15 | -------------------------------------------------------------------------------- /my-app/typings/tsd.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | /// 12 | -------------------------------------------------------------------------------- /node-server/conf/plugins/recv-reload.default.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 热加载配置 3 | * @author fis@baidu.com 4 | */ 5 | 6 | module.exports['recv-reload'] = { 7 | 8 | /** 9 | * 重载APP URL 10 | * 11 | * @type {String} 12 | */ 13 | cleanCacheUrl: '/yog/reload', 14 | 15 | /** 16 | * fis receiver URL 17 | * 18 | * @type {String} 19 | */ 20 | receiverUrl: '/yog/upload', 21 | 22 | /** 23 | * fis release 上传超时 (秒) 24 | * @type {Number} 25 | */ 26 | uploadTimeout: 30, 27 | 28 | /** 29 | * 缓存清理回调,可以在这里添加自定义的缓存清理操作 30 | */ 31 | onCacheClean: function () {} 32 | }; 33 | -------------------------------------------------------------------------------- /my-app/typings/redux-thunk/redux-thunk.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for redux-thunk v2.0.1 2 | // Project: https://github.com/gaearon/redux-thunk 3 | // Definitions by: Qubo 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare namespace ReduxThunk { 9 | export interface Thunk extends Redux.Middleware {} 10 | export interface ThunkInterface { 11 | (dispatch: Redux.Dispatch, getState?: () => T): any; 12 | } 13 | } 14 | 15 | declare module "redux-thunk" { 16 | var thunk: ReduxThunk.Thunk; 17 | export default thunk; 18 | } 19 | -------------------------------------------------------------------------------- /my-app/client/stores/user/reducer.tsx: -------------------------------------------------------------------------------- 1 | import * as action from './action' 2 | import {createReducer} from 'redux-immutablejs' 3 | import * as Immutable from 'immutable' 4 | 5 | const initialState:Immutable.Map = Immutable.Map({ 6 | 7 | }) 8 | 9 | export default createReducer(initialState, { 10 | [action.SIMPLE_GET_FUNCTION + '_SUCCESS']: (state:Immutable.Map, action:any) => { 11 | return state.merge({ 12 | simpleGet: action.data 13 | }) 14 | }, 15 | [action.SIMPLE_POST_FUNCTION + '_SUCCESS']: (state:Immutable.Map, action:any) => { 16 | return state.merge({ 17 | simplePost: action.data 18 | }) 19 | } 20 | }) -------------------------------------------------------------------------------- /node-server/app.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 框架启动入口 3 | * @author fis@baidu.com 4 | */ 5 | 6 | 'use strict'; 7 | 8 | var yog = require('yog2-kernel'); 9 | 10 | var app = yog.bootstrap({ 11 | rootPath: __dirname 12 | }, function () { 13 | console.log('plugins load completed'); 14 | }); 15 | 16 | app.set('port', process.env.PORT || 8080); 17 | app.disable('x-powered-by'); 18 | 19 | var server = yog.server = app.listen(app.get('port'), function () { 20 | console.log('Yog server listening on port ' + server.address().port); 21 | }); 22 | 23 | server.on('connection', function (socket) { 24 | // disable nagle 25 | socket.setNoDelay(true); 26 | // keep-alive timeout 27 | socket.setTimeout(60 * 1000); 28 | }); 29 | -------------------------------------------------------------------------------- /my-app/client/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 10 | 12 | React & nodejs 13 | 14 | 15 | 16 |
17 | 18 | 19 | 22 | 24 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /my-app/client/stores/user/action.tsx: -------------------------------------------------------------------------------- 1 | import {fetch} from 'fit-isomorphic-redux-tools' 2 | 3 | export const SIMPLE_GET_FUNCTION = 'SIMPLE_GET_FUNCTION' 4 | export const SIMPLE_POST_FUNCTION = 'SIMPLE_POST_FUNCTION' 5 | 6 | export const simpleGet = ()=> { 7 | return fetch({ 8 | type: SIMPLE_GET_FUNCTION, 9 | url: '/api/simple-get-function', 10 | params: { 11 | name: 'huangziyi' 12 | }, 13 | method: 'get' 14 | }) 15 | } 16 | 17 | export const simplePost = ()=> { 18 | return fetch({ 19 | type: SIMPLE_POST_FUNCTION, 20 | url: '/api/simple-post-function', 21 | data: { 22 | name: 'who are you?' 23 | }, 24 | method: 'post' 25 | }) 26 | } -------------------------------------------------------------------------------- /my-app/server/action/index.ts: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import routes from '../../client/routes' 3 | import {basename} from '../../client/config' 4 | import rootReducer from '../../client/reducer' 5 | import {serverRender} from 'fit-isomorphic-redux-tools' 6 | import * as fs from 'fs' 7 | import * as path from 'path' 8 | import {RequestOptions, ClientResponse} from 'http' 9 | 10 | const htmlText = fs.readFileSync(path.join(__dirname, '../../client/index.html'), 'utf-8') 11 | 12 | export default async (req: RequestOptions, res: ClientResponse) => { 13 | serverRender({ 14 | req, 15 | res, 16 | routes, 17 | basename, 18 | rootReducer, 19 | htmlText, 20 | enableServerRender: true 21 | }) 22 | } -------------------------------------------------------------------------------- /node-server/.npmignore: -------------------------------------------------------------------------------- 1 | # Webstorm 2 | .idea 3 | 4 | # Logs 5 | /logs 6 | /log 7 | /test/log 8 | *.log 9 | 10 | # Tmp 11 | /test/tmp 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 25 | .grunt 26 | 27 | # Compiled binary addons (http://nodejs.org/api/addons.html) 28 | build/Release 29 | 30 | # Dependency directory 31 | # Commenting this out is preferred by some people, see 32 | # https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 33 | node_modules 34 | 35 | # Users Environment Variables 36 | .lock-wscript 37 | 38 | # test 39 | test 40 | 41 | # benchmark 42 | benchmark -------------------------------------------------------------------------------- /node-server/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-server", 3 | "version": "0.8.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "debug-win": "set NODE_DEBUG=yog/dispatcher,yog/loader,yog/plugins,yog/recv-reload&set YOG_DEBUG=true&node app.js", 8 | "debug": "env NODE_DEBUG=yog/dispatcher,yog/loader,yog/plugins,yog/recv-reload YOG_DEBUG=true node app.js", 9 | "start": "yog2 run -e dev", 10 | "start-clean": "rm -rf views/* && rm -rf app/* && rm -rf static/* && rm -rf npm-debug.* && rm -rf log/access/* && rm -rf log/yog/* && rm -rf conf/fis/* && npm start" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/fex-team/yog2.git" 15 | }, 16 | "author": "fis@baidu.com", 17 | "license": "BSD", 18 | "dependencies": { 19 | "lodash": "2.4.1", 20 | "debuglog": "1.0.1", 21 | "yog2-kernel": "^0.8.0" 22 | } 23 | } -------------------------------------------------------------------------------- /my-app/client/routes/layout/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import {connect} from 'fit-isomorphic-redux-tools' 3 | import * as userActions from '../../stores/user/action' 4 | import {basename} from '../../config' 5 | 6 | @connect( 7 | (state: any) => { 8 | return { 9 | userStore: state.user.toJS() 10 | } 11 | }, 12 | userActions 13 | ) 14 | export default class LayoutComponent extends React.Component { 15 | state: any = {} 16 | props: any 17 | 18 | constructor(props: any) { 19 | super(props) 20 | } 21 | 22 | componentWillMount() { 23 | this.props.userStore.simpleGet || this.props.simpleGet() 24 | this.props.userStore.simplePost || this.props.simplePost() 25 | } 26 | 27 | componentDidMount() { 28 | 29 | } 30 | 31 | render(): any { 32 | return this.props.children 33 | } 34 | } -------------------------------------------------------------------------------- /node-server/.gitignore: -------------------------------------------------------------------------------- 1 | # Deploy 2 | /conf/app/** 3 | /conf/fis/** 4 | /static/** 5 | /views/** 6 | /app/** 7 | 8 | # Webstorm 9 | .idea 10 | 11 | # Logs 12 | /logs 13 | /log 14 | /test/log 15 | *.log 16 | 17 | # Tmp 18 | /test/tmp 19 | /tmp 20 | 21 | # Runtime data 22 | pids 23 | *.pid 24 | *.seed 25 | 26 | # Directory for instrumented libs generated by jscoverage/JSCover 27 | lib-cov 28 | 29 | # Coverage directory used by tools like istanbul 30 | coverage 31 | 32 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Compiled binary addons (http://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directory 39 | # Commenting this out is preferred by some people, see 40 | # https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 41 | node_modules 42 | 43 | # Users Environment Variables 44 | .lock-wscript 45 | 46 | # headdump 47 | *.heapsnapshot -------------------------------------------------------------------------------- /node-server/conf/plugins/ral.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 RAL配置 3 | * @author fis@baidu.com 4 | * 5 | * RAL是一个后端资源统一请求层,最常见的场景是封装HTTP请求 6 | * 7 | * 它的特色在于实现了请求协议与数据打包协议的解耦,并且提供了负载均衡与超时、异常重试机制。 8 | * 9 | * 更多的文档可以参考 https://github.com/fex-team/node-ral 10 | */ 11 | 12 | /* global yog */ 13 | 14 | module.exports.ral = { 15 | /*************************************************************************** 16 | * 17 | * 配置目录 18 | * 19 | * 20 | * RAL会自动加载配置目录中的所有配置 21 | * 22 | ***************************************************************************/ 23 | 24 | confDir: yog.ROOT_PATH + '/conf/ral', 25 | 26 | /*************************************************************************** 27 | * 28 | * Log配置 29 | * 30 | * 31 | * RAL使用yog-log进行日志处理,默认我们直接使用log的配置即可 32 | * 33 | ***************************************************************************/ 34 | 35 | logger: require('./log').log 36 | }; 37 | -------------------------------------------------------------------------------- /my-app/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 | "react-router/history.d.ts": { 9 | "commit": "6052959591c9bc6f8463c58220965c7030ba934d" 10 | }, 11 | "react/react.d.ts": { 12 | "commit": "6052959591c9bc6f8463c58220965c7030ba934d" 13 | }, 14 | "react/react-dom.d.ts": { 15 | "commit": "ec9eb4b28c74665a602c22db3457f0a76fa0fa23" 16 | }, 17 | "redux/redux.d.ts": { 18 | "commit": "8d44da84eb10cdcd2f7ea133f289caef817cb2b9" 19 | }, 20 | "react-redux/react-redux.d.ts": { 21 | "commit": "8d44da84eb10cdcd2f7ea133f289caef817cb2b9" 22 | }, 23 | "react-router-redux/react-router-redux.d.ts": { 24 | "commit": "8d44da84eb10cdcd2f7ea133f289caef817cb2b9" 25 | }, 26 | "redux-thunk/redux-thunk.d.ts": { 27 | "commit": "8d44da84eb10cdcd2f7ea133f289caef817cb2b9" 28 | }, 29 | "node/node.d.ts": { 30 | "commit": "310c247694d7f31bd2e3198f71c55221f7c3a3c7" 31 | }, 32 | "react-router/react-router.d.ts": { 33 | "commit": "6052959591c9bc6f8463c58220965c7030ba934d" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /my-app/client/routes/home/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react' 2 | import {Link} from 'react-router' 3 | import {connect} from 'fit-isomorphic-redux-tools' 4 | import './index.scss' 5 | 6 | @connect( 7 | (state: any) => { 8 | return { 9 | userStore: state.user.toJS() 10 | } 11 | }, {} 12 | ) 13 | export default class Home extends React.Component { 14 | state = {} 15 | 16 | constructor(props: any) { 17 | super(props) 18 | } 19 | 20 | componentWillMount() { 21 | 22 | } 23 | 24 | componentDidMount() { 25 | document.title = 'React & nodejs' 26 | } 27 | 28 | render() { 29 | const {userStore} = this.props 30 | return ( 31 |
32 |
React run well V15.0.1
33 |

访问 chrome 商店,下载 Redux DevTools 插件,随时查看页面状态树 35 |

36 |

37 | html5路由一 38 | html5路由二 40 |

41 |
42 | ) 43 | } 44 | } -------------------------------------------------------------------------------- /node-server/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Baidu FEX team 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of yog2 nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /my-app/typings/redux/redux.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for Redux v3.3.1 2 | // Project: https://github.com/rackt/redux 3 | // Definitions by: William Buchwalter , Vincent Prouillet 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | declare namespace Redux { 7 | 8 | interface ActionCreator extends Function { 9 | (...args: any[]): any; 10 | } 11 | 12 | interface Reducer extends Function { 13 | (state: any, action: any): any; 14 | } 15 | 16 | interface Dispatch extends Function { 17 | (action: any): any; 18 | } 19 | 20 | interface StoreMethods { 21 | dispatch: Dispatch; 22 | getState(): any; 23 | } 24 | 25 | 26 | interface MiddlewareArg { 27 | dispatch: Dispatch; 28 | getState: Function; 29 | } 30 | 31 | interface Middleware extends Function { 32 | (obj: MiddlewareArg): Function; 33 | } 34 | 35 | class Store { 36 | getReducer(): Reducer; 37 | replaceReducer(nextReducer: Reducer): void; 38 | dispatch(action: any): any; 39 | getState(): any; 40 | subscribe(listener: Function): Function; 41 | } 42 | 43 | function createStore(reducer: Reducer, initialState?: any, enhancer?: Function): Store; 44 | function bindActionCreators(actionCreators: T, dispatch: Dispatch): T; 45 | function combineReducers(reducers: any): Reducer; 46 | function applyMiddleware(...middlewares: Middleware[]): Function; 47 | function compose(...functions: Function[]): T; 48 | } 49 | 50 | declare module "redux" { 51 | export = Redux; 52 | } 53 | -------------------------------------------------------------------------------- /node-server/conf/plugins/views.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 模板层与静态资源管理配置 3 | * @author fis@baidu.com 4 | * 5 | * Yog默认使用swig作为后端模板引擎, 6 | * 7 | * 此处包括 8 | * 9 | * 1. 后端模板的缓存配置 10 | * 2. FIS后端静态资源管理 11 | * 3. Bigpipe配置 12 | * 13 | */ 14 | 15 | /*global yog*/ 16 | 17 | module.exports.views = { 18 | 19 | /*************************************************************************** 20 | * 21 | * confDir配置 22 | * 23 | * 后端静态资源配置存放目录,由yog2编译生成 24 | * 25 | * 默认存储与'memory'。设置 false 会关闭预编译缓存,可以设置一个拥有get, set function的对象自定义缓存 26 | * 27 | ***************************************************************************/ 28 | 29 | confDir: yog.ROOT_PATH + '/conf/fis', 30 | 31 | /*************************************************************************** 32 | * 33 | * bigpipe配置 34 | * 35 | * 开启Bigpipe功能 36 | * 37 | ***************************************************************************/ 38 | 39 | bigpipe: false, 40 | 41 | /*************************************************************************** 42 | * 43 | * chunkErrorHandler配置 44 | * 45 | * 开启BigPipe后如果Bigpipe组件获取数据时出现了异常,可以在此处自定义异常处理 46 | * 47 | * 此阶段无法使用类似res.redirect等命令,因为头信息已经发送完毕了 48 | * 49 | ***************************************************************************/ 50 | 51 | // chunkErrorHandler: function(error, res){}, 52 | 53 | /*************************************************************************** 54 | * 55 | * TPL渲染引擎配置 56 | * 57 | * 更详细的配置可以参考 http://paularmstrong.github.io/swig/ 58 | * 59 | ***************************************************************************/ 60 | 61 | tpl: { 62 | /*************************************************************************** 63 | * 64 | * cache配置 65 | * 66 | * 模板预编译缓存 67 | * 68 | * 默认存储与'memory'。设置 false 会关闭预编译缓存,可以设置一个拥有get, set function的对象自定义缓存 69 | * 70 | ***************************************************************************/ 71 | cache: 'memory' 72 | } 73 | }; 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://img.shields.io/travis/ascoders/isomorphic-react-redux-app/master.svg?style=flat)](https://travis-ci.org/ascoders/isomorphic-react-redux-app) 2 | [![Coverage Status](https://img.shields.io/coveralls/ascoders/isomorphic-react-redux-app/master.svg?style=flat)](https://coveralls.io/github/ascoders/isomorphic-react-redux-app?branch=master) 3 | 4 | # Isomorphic React Redux App 5 | 6 | simple but full front end technology stack, using React and Redux 7 | 8 | support **HotLoader** and server auto reload 9 | 10 | # Features 11 | - Async server-side rendering 12 | - Async server-side services request 13 | - Hot reloading middleware 14 | - Server auto reload 15 | - Redux DevTools and Logging 16 | - Redux Routing 17 | 18 | # Stack 19 | 20 | - React.js 21 | - Immutable 22 | - Webpack 23 | - Babel 24 | - Fis3 25 | - Yog2 26 | - Express 27 | - Redux 28 | - Redux-DevTools 29 | 30 | # Development Installation 31 | 32 | ## Environment 33 | 34 | - nodejs ^4.1.0 35 | - cnpm ^3.4.0 36 | - fis3 ^3.3.21 37 | - yog2 ^0.6.1 38 | 39 | ## Start Node Service 40 | 41 | In `node-server` directory, run the following commands: 42 | 43 | ```bash 44 | cnpm install 45 | npm start 46 | ``` 47 | 48 | ## Start App Building 49 | 50 | In `my-app` directory, run the following commands: 51 | 52 | ```bash 53 | cnpm install 54 | npm start 55 | ``` 56 | 57 | This command is executed with Webpack, and you can create other app's folder such like `second-app` `sell-system`... 58 | 59 | Then visit `http://localhost:8080/my-app` 60 | 61 | > Warning: You might see the TS error, we're trying to fix it, it does not prevent development 62 | 63 | ## Start App Preview Production Building 64 | 65 | In `my-app` directory, run the following commands: 66 | 67 | ```bash 68 | npm run preview 69 | ``` 70 | 71 | This command is executed with Fis3, use production setting 72 | 73 | ## Sandbox Development Building 74 | 75 | ```bash 76 | npm run remote 77 | ``` 78 | 79 | In `my-app` directory, change `host` in `fis-conf.js`, your code will be pushed to remote machine 80 | 81 | ## Production Building 82 | 83 | In `my-app` directory, run the following commands: 84 | 85 | ```bash 86 | npm run production 87 | ``` 88 | 89 | Then you can find `static-my-app.tar` `my-app.tar` in output dictionary 90 | 91 | # Author 92 | 93 | 2016 By FEX -------------------------------------------------------------------------------- /my-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-app", 3 | "version": "1.0.0", 4 | "description": "demo-app", 5 | "scripts": { 6 | "test": "echo \"Error: no test specified\" && exit 1", 7 | "start": "yog2 release dev -cwd --fis3 --watch & npm run webpack", 8 | "preview": "yog2 release preview -cd --fis3", 9 | "remote": "yog2 release remote -cd --fis3", 10 | "production": "yog2 release production -cd output --fis3", 11 | "webpack": "node ./node_modules/fit-isomorphic-build/lib/webpack/server.js" 12 | }, 13 | "repository": { 14 | "type": "git" 15 | }, 16 | "keywords": [ 17 | "fis3" 18 | ], 19 | "author": "fex@baidu.com", 20 | "license": "ISC", 21 | "dependencies": { 22 | "axios": "^0.9.1", 23 | "buffer": "^4.5.0", 24 | "es6-promise": "^3.1.2", 25 | "fit-isomorphic-redux-tools": "^0.0.95", 26 | "history": "^2.0.0", 27 | "immutable": "^3.7.6", 28 | "inversify": "^1.2.2", 29 | "is-buffer": "^1.1.2", 30 | "lodash": "^3.10.1", 31 | "process": "^0.11.2", 32 | "react": "^15.0.1", 33 | "react-dom": "^15.0.1", 34 | "react-immutable-render-mixin": "^0.9.6", 35 | "react-redux": "^4.4.2", 36 | "react-router": "^2.0.0", 37 | "react-router-redux": "^4.0.2", 38 | "redux": "^3.4.0", 39 | "redux-immutablejs": "0.0.8", 40 | "redux-thunk": "^2.0.1" 41 | }, 42 | "devDependencies": { 43 | "autoprefixer": "^6.2.2", 44 | "autoprefixer-loader": "^3.1.0", 45 | "babel-core": "^6.3.26", 46 | "babel-loader": "^6.2.0", 47 | "babel-plugin-transform-object-assign": "^6.3.13", 48 | "babel-preset-es2015": "^6.3.13", 49 | "babel-preset-react": "^6.3.13", 50 | "babel-preset-stage-0": "^6.5.0", 51 | "css-loader": "^0.23.1", 52 | "css-path-loader": "^0.2.14", 53 | "file-loader": "^0.8.5", 54 | "fis3-hook-commonjs": "^0.1.15", 55 | "fit-isomorphic-build": "0.0.9", 56 | "html-path-loader": "^0.1.10", 57 | "json-loader": "^0.5.4", 58 | "node-sass": "^3.7.0", 59 | "postcss-loader": "^0.8.0", 60 | "react-hot-loader": "^1.3.0", 61 | "sass-loader": "^3.1.2", 62 | "style-loader": "^0.13.0", 63 | "ts-loader": "^0.8.1", 64 | "typescript": "^1.8.10", 65 | "url-loader": "^0.5.7", 66 | "webpack": "^1.13.0", 67 | "webpack-dev-server": "^1.14.1" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /my-app/typings/react-router-redux/react-router-redux.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for react-router-redux v4.0.0 2 | // Project: https://github.com/rackt/react-router-redux 3 | // Definitions by: Isman Usoh , Noah Shipley , Dimitri Rosenberg 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | /// 7 | /// 8 | 9 | declare namespace ReactRouterRedux { 10 | import R = Redux; 11 | import H = HistoryModule; 12 | 13 | const CALL_HISTORY_METHOD: string; 14 | const LOCATION_CHANGE: string; 15 | 16 | const push: PushAction; 17 | const replace: ReplaceAction; 18 | const go: GoAction; 19 | const goBack: GoForwardAction; 20 | const goForward: GoBackAction; 21 | const routerActions: RouteActions; 22 | 23 | type LocationDescriptor = H.Location | H.Path; 24 | type PushAction = (nextLocation: LocationDescriptor) => RouterAction; 25 | type ReplaceAction = (nextLocation: LocationDescriptor) => RouterAction; 26 | type GoAction = (n: number) => RouterAction; 27 | type GoForwardAction = () => RouterAction; 28 | type GoBackAction = () => RouterAction; 29 | 30 | type RouterAction = { 31 | type: string 32 | payload?: any 33 | } 34 | 35 | interface RouteActions { 36 | push: PushAction; 37 | replace: ReplaceAction; 38 | go: GoAction; 39 | goForward: GoForwardAction; 40 | goBack: GoBackAction; 41 | } 42 | interface ReactRouterReduxHistory extends H.History { 43 | unsubscribe(): void; 44 | } 45 | 46 | interface DefaultSelectLocationState extends Function { 47 | (state: any): any; 48 | } 49 | 50 | interface SyncHistoryWithStoreOptions { 51 | selectLocationState?: DefaultSelectLocationState; 52 | adjustUrlOnReplay?: boolean; 53 | } 54 | 55 | function routerReducer(state?: any, options?: any): R.Reducer; 56 | function syncHistoryWithStore(history: H.History, store: R.Store, options?: SyncHistoryWithStoreOptions): ReactRouterReduxHistory; 57 | function routerMiddleware(history: H.History): R.Middleware; 58 | } 59 | 60 | declare module "react-router-redux" { 61 | export = ReactRouterRedux; 62 | } 63 | -------------------------------------------------------------------------------- /node-server/conf/plugins/dispatcher.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 系统路由配置 3 | * @author fis@baidu.com 4 | * 5 | * 用于管理URL与action之间的映射关系,默认的路由规则为 6 | * 7 | * http://www.example.com/home/index => app/home/action/index.js 8 | * http://www.example.com/home/doc/detail => app/home/action/doc/detail.js 9 | * 10 | * 如果上述规则没有匹配成功,会尝试匹配同名文件夹下的index.js,即 11 | * 12 | * http://www.example.com/home/index => app/home/action/index/index.js 13 | * http://www.example.com/home/doc/detail => app/home/action/doc/detail/index.js 14 | */ 15 | 16 | /*global yog*/ 17 | 18 | module.exports.dispatcher = { 19 | 20 | /*************************************************************************** 21 | * 22 | * 系统根路由 23 | * 24 | * 25 | * 系统根路由可以在自动路由生效前干预转发规则 26 | * 27 | * 你可以为一个app设置一个别名 28 | * router.use('/custom', yog.dispatcher.router('home')) 29 | * 30 | * http://www.example.com/custom => app/home/action/index/index.js 31 | * 32 | * 你可以直接建立一个特殊的URL 33 | * router.get('/somespecial', yog.dispatcher.action('home/doc/detail')) 34 | * 35 | * http://www.example.com/somespecial => app/home/action/doc/detail.js 36 | * 37 | * 你也可以在此处将router当成app使用,加载任意中间件 38 | * 39 | ***************************************************************************/ 40 | /** 41 | * rootRouter 42 | * @param {Router} router 43 | */ 44 | rootRouter: function (router) { 45 | 46 | }, 47 | /*************************************************************************** 48 | * 49 | * 默认路由配置 50 | * 51 | * 52 | * 当显式声明的Router无法找到时,Router会设置为默认路由 53 | * 54 | * 显式声明的Router会作为Action去查找 55 | * 56 | * http://www.example.com/doc/detail => app/home/action/doc/detail.js 57 | ***************************************************************************/ 58 | 59 | defaultRouter: 'home', 60 | 61 | /*************************************************************************** 62 | * 63 | * 默认Action配置 64 | * 65 | * 66 | * 当没有制定Action时,会使用默认Action 67 | * 68 | * http://www.example.com/home => app/home/action/index.js 69 | ***************************************************************************/ 70 | 71 | defaultAction: 'index', 72 | 73 | /*************************************************************************** 74 | * 75 | * appPath配置 76 | * 77 | * 78 | * 指定Yog项目的App路径 79 | * 80 | ***************************************************************************/ 81 | 82 | appPath: yog.ROOT_PATH + '/app' 83 | }; 84 | -------------------------------------------------------------------------------- /my-app/typings/react/react-dom.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for React v0.14 (react-dom) 2 | // Project: http://facebook.github.io/react/ 3 | // Definitions by: Asana , AssureSign , Microsoft 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | /// 7 | 8 | declare namespace __React { 9 | namespace __DOM { 10 | function findDOMNode(instance: ReactInstance): E; 11 | function findDOMNode(instance: ReactInstance): Element; 12 | 13 | function render

( 14 | element: DOMElement, 15 | container: Element, 16 | callback?: (element: T) => any): T; 17 | function render

( 18 | element: SFCElement

, 19 | container: Element, 20 | callback?: () => any): void; 21 | function render>( 22 | element: CElement, 23 | container: Element, 24 | callback?: (component: T) => any): T; 25 | function render

( 26 | element: ReactElement

, 27 | container: Element, 28 | callback?: (component?: Component | Element) => any): Component | Element | void; 29 | 30 | function unmountComponentAtNode(container: Element): boolean; 31 | 32 | var version: string; 33 | 34 | function unstable_batchedUpdates(callback: (a: A, b: B) => any, a: A, b: B): void; 35 | function unstable_batchedUpdates(callback: (a: A) => any, a: A): void; 36 | function unstable_batchedUpdates(callback: () => any): void; 37 | 38 | function unstable_renderSubtreeIntoContainer

( 39 | parentComponent: Component, 40 | element: DOMElement, 41 | container: Element, 42 | callback?: (element: T) => any): T; 43 | function unstable_renderSubtreeIntoContainer>( 44 | parentComponent: Component, 45 | element: CElement, 46 | container: Element, 47 | callback?: (component: T) => any): T; 48 | function render

( 49 | parentComponent: Component, 50 | element: SFCElement

, 51 | container: Element, 52 | callback?: () => any): void; 53 | function unstable_renderSubtreeIntoContainer

( 54 | parentComponent: Component, 55 | element: ReactElement

, 56 | container: Element, 57 | callback?: (component?: Component | Element) => any): Component | Element | void; 58 | } 59 | 60 | namespace __DOMServer { 61 | function renderToString(element: ReactElement): string; 62 | function renderToStaticMarkup(element: ReactElement): string; 63 | var version: string; 64 | } 65 | } 66 | 67 | declare module "react-dom" { 68 | import DOM = __React.__DOM; 69 | export = DOM; 70 | } 71 | 72 | declare module "react-dom/server" { 73 | import DOMServer = __React.__DOMServer; 74 | export = DOMServer; 75 | } 76 | -------------------------------------------------------------------------------- /node-server/conf/plugins/log.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 日志配置 3 | * @author fis@baidu.com 4 | * 更多的配置可以参考 https://github.com/fex-team/yog-log 5 | */ 6 | 7 | /*global yog*/ 8 | 9 | /*eslint-disable fecs-camelcase, camelcase */ 10 | 11 | module.exports.log = { 12 | /*************************************************************************** 13 | * 14 | * app配置 15 | * 16 | * 17 | * Log的归属App名称,日志将会保存在log/{app}目录中,即使使用autoAppName也需要提供默认的app名称 18 | ***************************************************************************/ 19 | app: 'yog', 20 | 21 | /*************************************************************************** 22 | * 23 | * autoAppName配置 24 | * 25 | * 26 | * 自动判断当前请求所在的app 27 | ***************************************************************************/ 28 | autoAppName: false, 29 | 30 | /*************************************************************************** 31 | * 32 | * intLevel配置 33 | * 34 | * 35 | * 控制Log输出的日志级别 36 | * 37 | * FATAL 1 打印FATAL 38 | * WARNING 2 打印FATAL和WARNING 39 | * NOTICE 4 打印FATAL、WARNING、NOTICE (线上程序正常运行时的配置) 40 | * TRACE 8 打印FATAL、WARNING、NOTICE、TRACE (线上程序异常时使用该配置) 41 | * DEBUG 16 打印FATAL、WARNING、NOTICE、TRACE、DEBUG (测试环境配置) 42 | ***************************************************************************/ 43 | 44 | intLevel: 16, 45 | 46 | /*************************************************************************** 47 | * 48 | * IS_OMP配置 49 | * 50 | * 51 | * 控制是否输出omp格式的日志,不适用omp设置为2即可 52 | ***************************************************************************/ 53 | 54 | IS_OMP: 2, 55 | 56 | /*************************************************************************** 57 | * 58 | * auto_rotate配置 59 | * 60 | * 61 | * 控制是否自动将日志根据小时切分 62 | ***************************************************************************/ 63 | 64 | auto_rotate: 1, 65 | 66 | /*************************************************************************** 67 | * 68 | * debug配置 69 | * 70 | * 71 | * 开启debug后,日志将在控制台输出而不是文件中输出 72 | ***************************************************************************/ 73 | 74 | debug: 0, 75 | 76 | /*************************************************************************** 77 | * 78 | * format配置 79 | * 80 | * 81 | * 常规日志输出格式,具体参数请参考 https://github.com/fex-team/yog-log 82 | ***************************************************************************/ 83 | 84 | // format: '%L: %t [%f:%N] errno[%E] logId[%l] uri[%U] user[%u] refer[%{referer}i] cookie[%{cookie}i] %S %M', 85 | 86 | /*************************************************************************** 87 | * 88 | * format_wf配置 89 | * 90 | * 91 | * 警告与错误日志输出格式,具体参数请参考 https://github.com/fex-team/yog-log 92 | ***************************************************************************/ 93 | 94 | // format_wf: '%L: %t [%f:%N] errno[%E] logId[%l] uri[%U] user[%u] refer[%{referer}i] cookie[%{cookie}i] %S %M', 95 | 96 | /*************************************************************************** 97 | * 98 | * data_path配置 99 | * 100 | * 101 | * 一般情况使用默认值即可,存放一些临时文件 102 | ***************************************************************************/ 103 | 104 | data_path: yog.ROOT_PATH + '/tmp', 105 | 106 | /*************************************************************************** 107 | * 108 | * log_path配置 109 | * 110 | * 111 | * Log的存放目录 112 | ***************************************************************************/ 113 | 114 | log_path: yog.ROOT_PATH + '/log', 115 | 116 | /*************************************************************************** 117 | * 118 | * use_sub_dir 119 | * 120 | * 121 | * Log是否分App存放 122 | ***************************************************************************/ 123 | 124 | use_sub_dir: 1 125 | }; 126 | -------------------------------------------------------------------------------- /my-app/typings/react-redux/react-redux.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for react-redux 4.4.0 2 | // Project: https://github.com/rackt/react-redux 3 | // Definitions by: Qubo , Sean Kelley 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | /// 7 | /// 8 | 9 | declare module "react-redux" { 10 | import { ComponentClass, Component, StatelessComponent, ReactNode } from 'react'; 11 | import { Store, Dispatch, ActionCreator } from 'redux'; 12 | 13 | interface ComponentDecorator { 14 | (component: ComponentClass|StatelessComponent): ComponentClass; 15 | } 16 | 17 | /** 18 | * Decorator that infers the type from the original component 19 | * 20 | * Can't use the above decorator because it would default the type to {} 21 | */ 22 | export interface InferableComponentDecorator { 23 | |StatelessComponent

)>(component: TComponentConstruct): TComponentConstruct; 24 | } 25 | 26 | /** 27 | * Connects a React component to a Redux store. 28 | * 29 | * - Without arguments, just wraps the component, without changing the behavior / props 30 | * 31 | * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior 32 | * is to override ownProps (as stated in the docs), so what remains is everything that's 33 | * not a state or dispatch prop 34 | * 35 | * - When 3rd param is passed, we don't know if ownProps propagate and whether they 36 | * should be valid component props, because it depends on mergeProps implementation. 37 | * As such, it is the user's responsibility to extend ownProps interface from state or 38 | * dispatch props or both when applicable 39 | * 40 | * @param mapStateToProps 41 | * @param mapDispatchToProps 42 | * @param mergeProps 43 | * @param options 44 | */ 45 | export function connect(): InferableComponentDecorator; 46 | 47 | export function connect( 48 | mapStateToProps: MapStateToProps, 49 | mapDispatchToProps?: MapDispatchToPropsFunction|MapDispatchToPropsObject 50 | ): ComponentDecorator; 51 | 52 | export function connect( 53 | mapStateToProps: MapStateToProps, 54 | mapDispatchToProps: MapDispatchToPropsFunction|MapDispatchToPropsObject, 55 | mergeProps: MergeProps, 56 | options?: Options 57 | ): ComponentDecorator; 58 | 59 | interface MapStateToProps { 60 | (state: any, ownProps?: TOwnProps): TStateProps; 61 | } 62 | 63 | interface MapDispatchToPropsFunction { 64 | (dispatch: Dispatch, ownProps?: TOwnProps): TDispatchProps; 65 | } 66 | 67 | interface MapDispatchToPropsObject { 68 | [name: string]: ActionCreator; 69 | } 70 | 71 | interface MergeProps { 72 | (stateProps: TStateProps, dispatchProps: TDispatchProps, ownProps: TOwnProps): TStateProps & TDispatchProps; 73 | } 74 | 75 | interface Options { 76 | /** 77 | * If true, implements shouldComponentUpdate and shallowly compares the result of mergeProps, 78 | * preventing unnecessary updates, assuming that the component is a “pure” component 79 | * and does not rely on any input or state other than its props and the selected Redux store’s state. 80 | * Defaults to true. 81 | * @default true 82 | */ 83 | pure: boolean; 84 | } 85 | 86 | export interface ProviderProps { 87 | /** 88 | * The single Redux store in your application. 89 | */ 90 | store?: Store; 91 | children?: ReactNode; 92 | } 93 | 94 | /** 95 | * Makes the Redux store available to the connect() calls in the component hierarchy below. 96 | */ 97 | export class Provider extends Component { } 98 | } 99 | -------------------------------------------------------------------------------- /node-server/conf/plugins/http.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file YOG2 中间件配置 3 | * @author fis@baidu.com 4 | */ 5 | 6 | /*global yog*/ 7 | 8 | module.exports.http = { 9 | /*************************************************************************** 10 | * 11 | * Middleware配置 12 | * 13 | * 用于管理加载哪些中间件,以及这些中间件的加载顺序 14 | * 15 | * 配置中可以通过字符串引用中间件插件,默认配置中均是Yog2的默认中间件 16 | * 17 | * 配置中也可以通过function(req, res, next){}的形式加载中间件而无需使用插件管理 18 | * 19 | ***************************************************************************/ 20 | // middleware: [ 21 | // 'favicon', 22 | // 'compression', 23 | // 'static', 24 | // 'responseTime', 25 | // 'cookieParser', 26 | // 'bodyParser', 27 | // 'log', 28 | // 'ral', 29 | // 'views', 30 | // 'methodOverride', 31 | // 'dispatcher', 32 | // 'notFound', 33 | // 'error', 34 | // function(req, res, next){ 35 | // next(); 36 | // } 37 | // ] 38 | }; 39 | 40 | 41 | /*************************************************************************** 42 | * 43 | * notFound配置 44 | * 45 | * 配置自定义的服务器404异常 46 | * 47 | ***************************************************************************/ 48 | 49 | module.exports.notFound = { 50 | 51 | /*************************************************************************** 52 | * 53 | * handler配置 54 | * 55 | * 设置请求未找到处理器后的处理函数,仅在YOG_DEBUG不为true时有效 56 | * 57 | ***************************************************************************/ 58 | 59 | // handler: function (req, res, next) { 60 | // res.status(404); 61 | // res.send('404: Page not Found'); 62 | // } 63 | }; 64 | 65 | 66 | /*************************************************************************** 67 | * 68 | * error配置 69 | * 70 | ***************************************************************************/ 71 | 72 | module.exports.error = { 73 | 74 | /*************************************************************************** 75 | * 76 | * handler配置 77 | * 78 | * 设置请求处理返回异常后的处理函数,仅在YOG_DEBUG不为true时有效 79 | * 80 | ***************************************************************************/ 81 | 82 | // handler: function (error, req, res, next) { 83 | // yog.log.fatal(error); 84 | // res.status(500); 85 | // res.send('500: Internal Server Error'); 86 | // } 87 | }; 88 | 89 | module.exports.favicon = { 90 | 91 | /*************************************************************************** 92 | * 93 | * favicon.path配置 94 | * 95 | * 设置favicon地址 96 | * 97 | ***************************************************************************/ 98 | 99 | path: yog.ROOT_PATH + '/static/favicon.ico' 100 | }; 101 | 102 | 103 | /*************************************************************************** 104 | * 105 | * compression配置 106 | * 107 | * 具体配置请参考 https://github.com/expressjs/compression 108 | * 109 | ***************************************************************************/ 110 | 111 | module.exports.compression = { 112 | 113 | }; 114 | 115 | /*************************************************************************** 116 | * 117 | * static配置 118 | * 119 | ***************************************************************************/ 120 | 121 | module.exports.static = { 122 | 123 | /*************************************************************************** 124 | * 125 | * staticPath配置 126 | * 127 | * 设置静态资源的根目录 128 | * 129 | ***************************************************************************/ 130 | 131 | staticPath: yog.ROOT_PATH + '/static', 132 | 133 | /*************************************************************************** 134 | * 135 | * urlPattern配置 136 | * 137 | * 设置静态资源访问的URL前缀 138 | * 139 | ***************************************************************************/ 140 | 141 | urlPattern: '/static', 142 | 143 | 144 | /*************************************************************************** 145 | * 146 | * options配置 147 | * 148 | * 参考 https://github.com/expressjs/serve-static#options 149 | * 150 | ***************************************************************************/ 151 | options: { 152 | maxAge: 0 153 | }, 154 | 155 | /*************************************************************************** 156 | * 157 | * notFound配置 158 | * 159 | * 设置静态资源未找到时的返回信息 160 | * 161 | ***************************************************************************/ 162 | 163 | notFound: function (req, res) { 164 | res.status(404); 165 | res.send('404: Resource not Found'); 166 | } 167 | }; 168 | 169 | 170 | /*************************************************************************** 171 | * 172 | * cookieParser 配置 173 | * 174 | * 配置可以参考 https://github.com/expressjs/cookie-parser 175 | * 176 | ***************************************************************************/ 177 | 178 | module.exports.cookieParser = { 179 | secret: 'yog', 180 | options: {} 181 | }; 182 | 183 | 184 | /*************************************************************************** 185 | * 186 | * bodyParser 配置 187 | * 188 | * 默认开启urlencoded与json的parser,额外的parser可以自行覆盖bodyParser插件实现 189 | * 190 | * 配置可以参考 https://github.com/expressjs/body-parser 191 | * 192 | ***************************************************************************/ 193 | 194 | module.exports.bodyParser = { 195 | urlencoded: { 196 | 197 | /*************************************************************************** 198 | * 199 | * exclude配置 200 | * 201 | * 可以指定特定的req.path不通过bodyparser.urlencoded处理 202 | * 203 | ***************************************************************************/ 204 | 205 | // exclude: [/\//,/\/index/, /\/home\/index/], 206 | 207 | extended: false 208 | } 209 | }; 210 | 211 | /*************************************************************************** 212 | * 213 | * methodOverride 配置 214 | * 215 | * 用于提供HTTP PUT DELETE的兼容 216 | * 217 | * 可以参考 https://github.com/expressjs/method-override 218 | * 219 | ***************************************************************************/ 220 | 221 | module.exports.methodOverride = [ 222 | 'X-HTTP-Method', 223 | 'X-HTTP-Method-Override', 224 | 'X-Method-Override', 225 | '_method' 226 | ]; 227 | -------------------------------------------------------------------------------- /my-app/client/static/mod.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file: mod.js 3 | * @author fis 4 | * ver: 1.0.13 5 | * update: 2016/01/27 6 | * https://github.com/fex-team/mod 7 | */ 8 | var require; 9 | 10 | /* eslint-disable no-unused-vars */ 11 | var define; 12 | 13 | (function (global) { 14 | 15 | // 避免重复加载而导致已定义模块丢失 16 | if (require) { 17 | return; 18 | } 19 | 20 | var head = document.getElementsByTagName('head')[0]; 21 | var loadingMap = {}; 22 | var factoryMap = {}; 23 | var modulesMap = {}; 24 | var scriptsMap = {}; 25 | var resMap = {}; 26 | var pkgMap = {}; 27 | 28 | var createScripts = function(queues, onerror){ 29 | 30 | var docFrag = document.createDocumentFragment(); 31 | 32 | for(var i = 0, len = queues.length; i < len; i++){ 33 | var id = queues[i].id; 34 | var url = queues[i].url; 35 | 36 | if (url in scriptsMap) { 37 | continue; 38 | } 39 | 40 | scriptsMap[url] = true; 41 | 42 | var script = document.createElement('script'); 43 | if (onerror) { 44 | (function(script, id){ 45 | var tid = setTimeout(function(){ 46 | onerror(id); 47 | }, require.timeout); 48 | 49 | script.onerror = function () { 50 | clearTimeout(tid); 51 | onerror(id); 52 | }; 53 | 54 | var onload = function () { 55 | clearTimeout(tid); 56 | }; 57 | 58 | if ('onload' in script) { 59 | script.onload = onload; 60 | } 61 | else { 62 | script.onreadystatechange = function () { 63 | if (this.readyState === 'loaded' || this.readyState === 'complete') { 64 | onload(); 65 | } 66 | }; 67 | } 68 | })(script, id); 69 | } 70 | script.type = 'text/javascript'; 71 | script.src = url; 72 | 73 | docFrag.appendChild(script); 74 | } 75 | 76 | head.appendChild(docFrag); 77 | }; 78 | 79 | var loadScripts = function(ids, callback, onerror){ 80 | var queues = []; 81 | for(var i = 0, len = ids.length; i < len; i++){ 82 | var id = ids[i]; 83 | var queue = loadingMap[id] || (loadingMap[id] = []); 84 | queue.push(callback); 85 | 86 | // 87 | // resource map query 88 | // 89 | var res = resMap[id] || resMap[id + '.js'] || {}; 90 | var pkg = res.pkg; 91 | var url; 92 | 93 | if (pkg) { 94 | url = pkgMap[pkg].url || pkgMap[pkg].uri; 95 | } 96 | else { 97 | url = res.url || res.uri || id; 98 | } 99 | 100 | queues.push({ 101 | id: id, 102 | url: url 103 | }); 104 | } 105 | 106 | createScripts(queues, onerror); 107 | }; 108 | 109 | define = function (id, factory) { 110 | id = id.replace(/\.js$/i, ''); 111 | factoryMap[id] = factory; 112 | 113 | var queue = loadingMap[id]; 114 | if (queue) { 115 | for (var i = 0, n = queue.length; i < n; i++) { 116 | queue[i](); 117 | } 118 | delete loadingMap[id]; 119 | } 120 | }; 121 | 122 | require = function (id) { 123 | 124 | // compatible with require([dep, dep2...]) syntax. 125 | if (id && id.splice) { 126 | return require.async.apply(this, arguments); 127 | } 128 | 129 | id = require.alias(id); 130 | 131 | var mod = modulesMap[id]; 132 | if (mod) { 133 | return mod.exports; 134 | } 135 | 136 | // 137 | // init module 138 | // 139 | var factory = factoryMap[id]; 140 | if (!factory) { 141 | throw '[ModJS] Cannot find module `' + id + '`'; 142 | } 143 | 144 | mod = modulesMap[id] = { 145 | exports: {} 146 | }; 147 | 148 | // 149 | // factory: function OR value 150 | // 151 | var ret = (typeof factory === 'function') ? factory.apply(mod, [require, mod.exports, mod]) : factory; 152 | 153 | if (ret) { 154 | mod.exports = ret; 155 | } 156 | 157 | return mod.exports; 158 | }; 159 | 160 | require.async = function (names, onload, onerror) { 161 | if (typeof names === 'string') { 162 | names = [names]; 163 | } 164 | 165 | var needMap = {}; 166 | var needNum = 0; 167 | var needLoad = []; 168 | 169 | function findNeed(depArr) { 170 | var child; 171 | 172 | for (var i = 0, n = depArr.length; i < n; i++) { 173 | // 174 | // skip loading or loaded 175 | // 176 | var dep = require.alias(depArr[i]); 177 | 178 | if (dep in needMap) { 179 | continue; 180 | } 181 | 182 | needMap[dep] = true; 183 | 184 | if (dep in factoryMap) { 185 | // check whether loaded resource's deps is loaded or not 186 | child = resMap[dep] || resMap[dep + '.js']; 187 | if (child && 'deps' in child) { 188 | findNeed(child.deps); 189 | } 190 | continue; 191 | } 192 | 193 | needLoad.push(dep); 194 | needNum++; 195 | 196 | child = resMap[dep] || resMap[dep + '.js']; 197 | if (child && 'deps' in child) { 198 | findNeed(child.deps); 199 | } 200 | } 201 | } 202 | 203 | function updateNeed() { 204 | if (0 === needNum--) { 205 | var args = []; 206 | for (var i = 0, n = names.length; i < n; i++) { 207 | args[i] = require(names[i]); 208 | } 209 | 210 | onload && onload.apply(global, args); 211 | } 212 | } 213 | 214 | findNeed(names); 215 | loadScripts(needLoad, updateNeed, onerror); 216 | updateNeed(); 217 | }; 218 | 219 | require.ensure = function(names, callback) { 220 | require.async(names, function() { 221 | callback && callback.call(this, require); 222 | }); 223 | }; 224 | 225 | require.resourceMap = function (obj) { 226 | var k; 227 | var col; 228 | 229 | // merge `res` & `pkg` fields 230 | col = obj.res; 231 | for (k in col) { 232 | if (col.hasOwnProperty(k)) { 233 | resMap[k] = col[k]; 234 | } 235 | } 236 | 237 | col = obj.pkg; 238 | for (k in col) { 239 | if (col.hasOwnProperty(k)) { 240 | pkgMap[k] = col[k]; 241 | } 242 | } 243 | }; 244 | 245 | require.loadJs = function (url) { 246 | if (url in scriptsMap) { 247 | return; 248 | } 249 | 250 | scriptsMap[url] = true; 251 | 252 | var script = document.createElement('script'); 253 | script.type = 'text/javascript'; 254 | script.src = url; 255 | head.appendChild(script); 256 | }; 257 | 258 | require.loadCss = function (cfg) { 259 | if (cfg.content) { 260 | var sty = document.createElement('style'); 261 | sty.type = 'text/css'; 262 | 263 | if (sty.styleSheet) { // IE 264 | sty.styleSheet.cssText = cfg.content; 265 | } 266 | else { 267 | sty.innerHTML = cfg.content; 268 | } 269 | head.appendChild(sty); 270 | } 271 | else if (cfg.url) { 272 | var link = document.createElement('link'); 273 | link.href = cfg.url; 274 | link.rel = 'stylesheet'; 275 | link.type = 'text/css'; 276 | head.appendChild(link); 277 | } 278 | }; 279 | 280 | 281 | require.alias = function (id) { 282 | return id.replace(/\.js$/i, ''); 283 | }; 284 | 285 | require.timeout = 5000; 286 | 287 | })(this); -------------------------------------------------------------------------------- /my-app/typings/react-router/history.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for history v2.0.0 2 | // Project: https://github.com/rackt/history 3 | // Definitions by: Sergey Buturlakin , Nathan Brown 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | 7 | declare namespace HistoryModule { 8 | 9 | // types based on https://github.com/rackt/history/blob/master/docs/Terms.md 10 | 11 | type Action = string 12 | 13 | type BeforeUnloadHook = () => string | boolean 14 | 15 | type CreateHistory = (options?: HistoryOptions) => T 16 | 17 | type CreateHistoryEnhancer = (createHistory: CreateHistory) => CreateHistory 18 | 19 | interface History { 20 | listenBefore(hook: TransitionHook): () => void 21 | listen(listener: LocationListener): () => void 22 | transitionTo(location: Location): void 23 | push(path: LocationDescriptor): void 24 | replace(path: LocationDescriptor): void 25 | go(n: number): void 26 | goBack(): void 27 | goForward(): void 28 | createKey(): LocationKey 29 | createPath(path: LocationDescriptor): Path 30 | createHref(path: LocationDescriptor): Href 31 | createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location 32 | 33 | /** @deprecated use a location descriptor instead */ 34 | createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location 35 | /** @deprecated use location.key to save state instead */ 36 | pushState(state: LocationState, path: Path): void 37 | /** @deprecated use location.key to save state instead */ 38 | replaceState(state: LocationState, path: Path): void 39 | /** @deprecated use location.key to save state instead */ 40 | setState(state: LocationState): void 41 | /** @deprecated use listenBefore instead */ 42 | registerTransitionHook(hook: TransitionHook): void 43 | /** @deprecated use the callback returned from listenBefore instead */ 44 | unregisterTransitionHook(hook: TransitionHook): void 45 | } 46 | 47 | type HistoryOptions = { 48 | getCurrentLocation?: () => Location 49 | finishTransition?: (nextLocation: Location) => boolean 50 | saveState?: (key: LocationKey, state: LocationState) => void 51 | go?: (n: number) => void 52 | getUserConfirmation?: (message: string, callback: (result: boolean) => void) => void 53 | keyLength?: number 54 | queryKey?: string | boolean 55 | stringifyQuery?: (obj: any) => string 56 | parseQueryString?: (str: string) => any 57 | basename?: string 58 | entries?: string | [any] 59 | current?: number 60 | } 61 | 62 | type Href = string 63 | 64 | type Location = { 65 | pathname: Pathname 66 | search: Search 67 | query: Query 68 | state: LocationState 69 | action: Action 70 | key: LocationKey 71 | basename?: string 72 | } 73 | 74 | type LocationDescriptorObject = { 75 | pathname?: Pathname 76 | search?: Search 77 | query?: Query 78 | state?: LocationState 79 | } 80 | 81 | type LocationDescriptor = LocationDescriptorObject | Path 82 | 83 | type LocationKey = string 84 | 85 | type LocationListener = (location: Location) => void 86 | 87 | type LocationState = Object 88 | 89 | type Path = string // Pathname + QueryString 90 | 91 | type Pathname = string 92 | 93 | type Query = Object 94 | 95 | type QueryString = string 96 | 97 | type Search = string 98 | 99 | type TransitionHook = (location: Location, callback: (result: any) => void) => any 100 | 101 | 102 | interface HistoryBeforeUnload { 103 | listenBeforeUnload(hook: BeforeUnloadHook): () => void 104 | } 105 | 106 | interface HistoryQueries { 107 | pushState(state: LocationState, pathname: Pathname | Path, query?: Query): void 108 | replaceState(state: LocationState, pathname: Pathname | Path, query?: Query): void 109 | createPath(path: Path, query?: Query): Path 110 | createHref(path: Path, query?: Query): Href 111 | } 112 | 113 | 114 | // Global usage, without modules, needs the small trick, because lib.d.ts 115 | // already has `history` and `History` global definitions: 116 | // var createHistory = ((window as any).History as HistoryModule.Module).createHistory; 117 | interface Module { 118 | createHistory: CreateHistory 119 | createHashHistory: CreateHistory 120 | createMemoryHistory: CreateHistory 121 | createLocation(path?: Path, state?: LocationState, action?: Action, key?: LocationKey): Location 122 | useBasename(createHistory: CreateHistory): CreateHistory 123 | useBeforeUnload(createHistory: CreateHistory): CreateHistory 124 | useQueries(createHistory: CreateHistory): CreateHistory 125 | actions: { 126 | PUSH: string 127 | REPLACE: string 128 | POP: string 129 | } 130 | } 131 | 132 | } 133 | 134 | 135 | declare module "history/lib/createBrowserHistory" { 136 | 137 | export default function createBrowserHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History 138 | 139 | } 140 | 141 | 142 | declare module "history/lib/createHashHistory" { 143 | 144 | export default function createHashHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History 145 | 146 | } 147 | 148 | 149 | declare module "history/lib/createMemoryHistory" { 150 | 151 | export default function createMemoryHistory(options?: HistoryModule.HistoryOptions): HistoryModule.History 152 | 153 | } 154 | 155 | 156 | declare module "history/lib/createLocation" { 157 | 158 | export default function createLocation(path?: HistoryModule.Path, state?: HistoryModule.LocationState, action?: HistoryModule.Action, key?: HistoryModule.LocationKey): HistoryModule.Location 159 | 160 | } 161 | 162 | 163 | declare module "history/lib/useBasename" { 164 | 165 | export default function useBasename(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory 166 | 167 | } 168 | 169 | 170 | declare module "history/lib/useBeforeUnload" { 171 | 172 | export default function useBeforeUnload(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory 173 | 174 | } 175 | 176 | 177 | declare module "history/lib/useQueries" { 178 | 179 | export default function useQueries(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory 180 | 181 | } 182 | 183 | 184 | declare module "history/lib/actions" { 185 | 186 | export const PUSH: string 187 | 188 | export const REPLACE: string 189 | 190 | export const POP: string 191 | 192 | export default { 193 | PUSH, 194 | REPLACE, 195 | POP 196 | } 197 | 198 | } 199 | 200 | declare module "history/lib/DOMUtils" { 201 | export function addEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; 202 | export function removeEventListener(node: EventTarget, event: string, listener: EventListenerOrEventListenerObject): void; 203 | export function getHashPath(): string; 204 | export function replaceHashPath(path: string): void; 205 | export function getWindowPath(): string; 206 | export function go(n: number): void; 207 | export function getUserConfirmation(message: string, callback: (result: boolean) => void): void; 208 | export function supportsHistory(): boolean; 209 | export function supportsGoWithoutReloadUsingHash(): boolean; 210 | } 211 | 212 | 213 | declare module "history" { 214 | 215 | export { default as createHistory } from "history/lib/createBrowserHistory" 216 | 217 | export { default as createHashHistory } from "history/lib/createHashHistory" 218 | 219 | export { default as createMemoryHistory } from "history/lib/createMemoryHistory" 220 | 221 | export { default as createLocation } from "history/lib/createLocation" 222 | 223 | export { default as useBasename } from "history/lib/useBasename" 224 | 225 | export { default as useBeforeUnload } from "history/lib/useBeforeUnload" 226 | 227 | export { default as useQueries } from "history/lib/useQueries" 228 | 229 | import * as Actions from "history/lib/actions" 230 | 231 | export { Actions } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /my-app/typings/react-router/react-router.d.ts: -------------------------------------------------------------------------------- 1 | // Type definitions for react-router v2.0.0 2 | // Project: https://github.com/rackt/react-router 3 | // Definitions by: Sergey Buturlakin , Yuichi Murata , Václav Ostrožlík , Nathan Brown 4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 5 | 6 | 7 | /// 8 | /// 9 | 10 | 11 | declare namespace ReactRouter { 12 | 13 | import React = __React 14 | 15 | import H = HistoryModule 16 | 17 | // types based on https://github.com/rackt/react-router/blob/master/docs/Glossary.md 18 | 19 | type Component = React.ReactType 20 | 21 | type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => void 22 | 23 | type LeaveHook = () => void 24 | 25 | type ChangeHook = (prevState: RouterState, nextState: RouterState, replace: RedirectFunction, callback: Function) => void; 26 | 27 | type Params = { [param: string]: string } 28 | 29 | type ParseQueryString = (queryString: H.QueryString) => H.Query 30 | 31 | interface RedirectFunction { 32 | (location: H.LocationDescriptor): void; 33 | /** 34 | * @deprecated `replaceState(state, pathname, query) is deprecated; Use `replace(location)` with a location descriptor instead. http://tiny.cc/router-isActivedeprecated 35 | */ 36 | (state: H.LocationState, pathname: H.Pathname | H.Path, query?: H.Query): void; 37 | } 38 | 39 | type RouteComponent = Component 40 | 41 | // use the following interface in an app code to get access to route param values, history, location... 42 | // interface MyComponentProps extends ReactRouter.RouteComponentProps<{}, { id: number }> {} 43 | // somewhere in MyComponent 44 | // ... 45 | // let id = this.props.routeParams.id 46 | // ... 47 | // this.props.history. ... 48 | // ... 49 | interface RouteComponentProps { 50 | history?: History 51 | location?: H.Location 52 | params?: P 53 | route?: PlainRoute 54 | routeParams?: R 55 | routes?: PlainRoute[] 56 | children?: React.ReactElement 57 | } 58 | 59 | type RouteComponents = { [key: string]: RouteComponent } 60 | 61 | type RouteConfig = React.ReactNode | PlainRoute | PlainRoute[] 62 | 63 | type RouteHook = (nextLocation?: H.Location) => any 64 | 65 | type RoutePattern = string 66 | 67 | type StringifyQuery = (queryObject: H.Query) => H.QueryString 68 | 69 | type RouterListener = (error: Error, nextState: RouterState) => void 70 | 71 | interface RouterState { 72 | location: H.Location 73 | routes: PlainRoute[] 74 | params: Params 75 | components: RouteComponent[] 76 | } 77 | 78 | 79 | interface HistoryBase extends H.History { 80 | routes: PlainRoute[] 81 | parseQueryString?: ParseQueryString 82 | stringifyQuery?: StringifyQuery 83 | } 84 | 85 | type History = HistoryBase & H.HistoryQueries & HistoryRoutes 86 | const browserHistory: History; 87 | const hashHistory: History; 88 | 89 | function createMemoryHistory(options?: H.HistoryOptions): H.History 90 | 91 | /* components */ 92 | 93 | interface RouterProps extends React.Props { 94 | history?: H.History 95 | routes?: RouteConfig // alias for children 96 | createElement?: (component: RouteComponent, props: Object) => any 97 | onError?: (error: any) => any 98 | onUpdate?: () => any 99 | parseQueryString?: ParseQueryString 100 | stringifyQuery?: StringifyQuery 101 | } 102 | interface Router extends React.ComponentClass {} 103 | interface RouterElement extends React.ReactElement {} 104 | const Router: Router 105 | 106 | 107 | interface LinkProps extends React.HTMLAttributes, React.Props { 108 | activeStyle?: React.CSSProperties 109 | activeClassName?: string 110 | onlyActiveOnIndex?: boolean 111 | to: RoutePattern | H.LocationDescriptor 112 | query?: H.Query 113 | state?: H.LocationState 114 | } 115 | interface Link extends React.ComponentClass {} 116 | interface LinkElement extends React.ReactElement {} 117 | const Link: Link 118 | 119 | 120 | const IndexLink: Link 121 | 122 | 123 | interface RouterContextProps extends React.Props { 124 | history?: H.History 125 | router: Router 126 | createElement: (component: RouteComponent, props: Object) => any 127 | location: H.Location 128 | routes: RouteConfig 129 | params: Params 130 | components?: RouteComponent[] 131 | } 132 | interface RouterContext extends React.ComponentClass {} 133 | interface RouterContextElement extends React.ReactElement { 134 | history?: H.History 135 | location: H.Location 136 | router?: Router 137 | } 138 | const RouterContext: RouterContext 139 | 140 | 141 | /* components (configuration) */ 142 | 143 | interface RouteProps extends React.Props { 144 | path?: RoutePattern 145 | component?: RouteComponent 146 | components?: RouteComponents 147 | getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void 148 | getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void 149 | onEnter?: EnterHook 150 | onLeave?: LeaveHook 151 | onChange?: ChangeHook 152 | getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void 153 | getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void 154 | } 155 | interface Route extends React.ComponentClass {} 156 | interface RouteElement extends React.ReactElement {} 157 | const Route: Route 158 | 159 | 160 | interface PlainRoute { 161 | path?: RoutePattern 162 | component?: RouteComponent 163 | components?: RouteComponents 164 | getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void 165 | getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void 166 | onEnter?: EnterHook 167 | onLeave?: LeaveHook 168 | indexRoute?: PlainRoute 169 | getIndexRoute?: (location: H.Location, cb: (error: any, indexRoute: RouteConfig) => void) => void 170 | childRoutes?: PlainRoute[] 171 | getChildRoutes?: (location: H.Location, cb: (error: any, childRoutes: RouteConfig) => void) => void 172 | } 173 | 174 | 175 | interface RedirectProps extends React.Props { 176 | path?: RoutePattern 177 | from?: RoutePattern // alias for path 178 | to: RoutePattern 179 | query?: H.Query 180 | state?: H.LocationState 181 | } 182 | interface Redirect extends React.ComponentClass {} 183 | interface RedirectElement extends React.ReactElement {} 184 | const Redirect: Redirect 185 | 186 | 187 | interface IndexRouteProps extends React.Props { 188 | component?: RouteComponent 189 | components?: RouteComponents 190 | getComponent?: (location: H.Location, cb: (error: any, component?: RouteComponent) => void) => void 191 | getComponents?: (location: H.Location, cb: (error: any, components?: RouteComponents) => void) => void 192 | onEnter?: EnterHook 193 | onLeave?: LeaveHook 194 | } 195 | interface IndexRoute extends React.ComponentClass {} 196 | interface IndexRouteElement extends React.ReactElement {} 197 | const IndexRoute: IndexRoute 198 | 199 | 200 | interface IndexRedirectProps extends React.Props { 201 | to: RoutePattern 202 | query?: H.Query 203 | state?: H.LocationState 204 | } 205 | interface IndexRedirect extends React.ComponentClass {} 206 | interface IndexRedirectElement extends React.ReactElement {} 207 | const IndexRedirect: IndexRedirect 208 | 209 | interface RouterOnContext extends H.History { 210 | setRouteLeaveHook(route: PlainRoute, hook?: RouteHook): () => void; 211 | isActive(pathOrLoc: H.LocationDescriptor, indexOnly?: boolean): boolean; 212 | } 213 | 214 | /* mixins */ 215 | 216 | interface HistoryMixin { 217 | history: History 218 | } 219 | const History: React.Mixin 220 | 221 | 222 | interface LifecycleMixin { 223 | routerWillLeave(nextLocation: H.Location): string | boolean 224 | } 225 | const Lifecycle: React.Mixin 226 | 227 | 228 | const RouteContext: React.Mixin 229 | 230 | 231 | /* utils */ 232 | 233 | interface HistoryRoutes { 234 | listen(listener: RouterListener): Function 235 | listenBeforeLeavingRoute(route: PlainRoute, hook: RouteHook): void 236 | match(location: H.Location, callback: (error: any, nextState: RouterState, nextLocation: H.Location) => void): void 237 | isActive(pathname: H.Pathname, query?: H.Query, indexOnly?: boolean): boolean 238 | setRouteLeaveHook(route: PlainRoute, callback: RouteHook): void 239 | } 240 | 241 | function useRoutes(createHistory: HistoryModule.CreateHistory): HistoryModule.CreateHistory 242 | 243 | 244 | function createRoutes(routes: RouteConfig): PlainRoute[] 245 | 246 | 247 | interface MatchArgs { 248 | routes?: RouteConfig 249 | history?: H.History 250 | location?: H.Location | string 251 | parseQueryString?: ParseQueryString 252 | stringifyQuery?: StringifyQuery 253 | basename?: string 254 | } 255 | interface MatchState extends RouterState { 256 | history: History 257 | } 258 | function match(args: MatchArgs, cb: (error: any, nextLocation: H.Location, nextState: MatchState) => void): void 259 | 260 | } 261 | 262 | 263 | declare module "react-router/lib/Router" { 264 | 265 | export default ReactRouter.Router 266 | 267 | } 268 | 269 | 270 | declare module "react-router/lib/Link" { 271 | 272 | export default ReactRouter.Link 273 | 274 | } 275 | 276 | 277 | declare module "react-router/lib/IndexLink" { 278 | 279 | export default ReactRouter.IndexLink 280 | 281 | } 282 | 283 | 284 | declare module "react-router/lib/IndexRedirect" { 285 | 286 | export default ReactRouter.IndexRedirect 287 | 288 | } 289 | 290 | 291 | declare module "react-router/lib/IndexRoute" { 292 | 293 | export default ReactRouter.IndexRoute 294 | 295 | } 296 | 297 | 298 | declare module "react-router/lib/Redirect" { 299 | 300 | export default ReactRouter.Redirect 301 | 302 | } 303 | 304 | 305 | declare module "react-router/lib/Route" { 306 | 307 | export default ReactRouter.Route 308 | 309 | } 310 | 311 | 312 | declare module "react-router/lib/History" { 313 | 314 | export default ReactRouter.History 315 | 316 | } 317 | 318 | 319 | declare module "react-router/lib/Lifecycle" { 320 | 321 | export default ReactRouter.Lifecycle 322 | 323 | } 324 | 325 | 326 | declare module "react-router/lib/RouteContext" { 327 | 328 | export default ReactRouter.RouteContext 329 | 330 | } 331 | 332 | 333 | declare module "react-router/lib/useRoutes" { 334 | 335 | export default ReactRouter.useRoutes 336 | 337 | } 338 | 339 | declare module "react-router/lib/PatternUtils" { 340 | 341 | export function formatPattern(pattern: string, params: {}): string; 342 | 343 | } 344 | 345 | declare module "react-router/lib/RouteUtils" { 346 | 347 | type E = __React.ReactElement 348 | 349 | export function isReactChildren(object: E | E[]): boolean 350 | 351 | export function createRouteFromReactElement(element: E): ReactRouter.PlainRoute 352 | 353 | export function createRoutesFromReactChildren(children: E | E[], parentRoute: ReactRouter.PlainRoute): ReactRouter.PlainRoute[] 354 | 355 | export import createRoutes = ReactRouter.createRoutes 356 | 357 | } 358 | 359 | 360 | declare module "react-router/lib/RouterContext" { 361 | 362 | export default ReactRouter.RouterContext 363 | 364 | } 365 | 366 | 367 | declare module "react-router/lib/PropTypes" { 368 | 369 | import React = __React 370 | 371 | export function falsy(props: any, propName: string, componentName: string): Error; 372 | 373 | export const history: React.Requireable 374 | 375 | export const location: React.Requireable 376 | 377 | export const component: React.Requireable 378 | 379 | export const components: React.Requireable 380 | 381 | export const route: React.Requireable 382 | 383 | export const routes: React.Requireable 384 | 385 | export default { 386 | falsy, 387 | history, 388 | location, 389 | component, 390 | components, 391 | route 392 | } 393 | 394 | } 395 | 396 | declare module "react-router/lib/browserHistory" { 397 | export default ReactRouter.browserHistory; 398 | } 399 | 400 | declare module "react-router/lib/hashHistory" { 401 | export default ReactRouter.hashHistory; 402 | } 403 | 404 | declare module "react-router/lib/match" { 405 | 406 | export default ReactRouter.match 407 | 408 | } 409 | 410 | declare module "react-router/lib/useRouterHistory" { 411 | interface CreateRouterHistory { 412 | (options?: HistoryModule.HistoryOptions): HistoryModule.History & HistoryModule.HistoryQueries; 413 | } 414 | 415 | export default function useRouterHistory(createHistory: HistoryModule.CreateHistory): CreateRouterHistory; 416 | } 417 | 418 | declare module "react-router/lib/createMemoryHistory" { 419 | export default ReactRouter.createMemoryHistory; 420 | } 421 | 422 | declare module "react-router" { 423 | 424 | import Router from "react-router/lib/Router" 425 | 426 | import Link from "react-router/lib/Link" 427 | 428 | import IndexLink from "react-router/lib/IndexLink" 429 | 430 | import IndexRedirect from "react-router/lib/IndexRedirect" 431 | 432 | import IndexRoute from "react-router/lib/IndexRoute" 433 | 434 | import Redirect from "react-router/lib/Redirect" 435 | 436 | import Route from "react-router/lib/Route" 437 | 438 | import History from "react-router/lib/History" 439 | 440 | import Lifecycle from "react-router/lib/Lifecycle" 441 | 442 | import RouteContext from "react-router/lib/RouteContext" 443 | 444 | import browserHistory from "react-router/lib/browserHistory" 445 | 446 | import hashHistory from "react-router/lib/hashHistory" 447 | 448 | import useRoutes from "react-router/lib/useRoutes" 449 | 450 | import { createRoutes } from "react-router/lib/RouteUtils" 451 | 452 | import { formatPattern } from "react-router/lib/PatternUtils" 453 | 454 | import RouterContext from "react-router/lib/RouterContext" 455 | 456 | import PropTypes from "react-router/lib/PropTypes" 457 | 458 | import match from "react-router/lib/match" 459 | 460 | import useRouterHistory from "react-router/lib/useRouterHistory"; 461 | 462 | import createMemoryHistory from "react-router/lib/createMemoryHistory"; 463 | 464 | // PlainRoute is defined in the API documented at: 465 | // https://github.com/rackt/react-router/blob/master/docs/API.md 466 | // but not included in any of the .../lib modules above. 467 | export type PlainRoute = ReactRouter.PlainRoute 468 | 469 | // The following definitions are also very useful to export 470 | // because by using these types lots of potential type errors 471 | // can be exposed: 472 | export type EnterHook = ReactRouter.EnterHook 473 | export type LeaveHook = ReactRouter.LeaveHook 474 | export type ParseQueryString = ReactRouter.ParseQueryString 475 | export type RedirectFunction = ReactRouter.RedirectFunction 476 | export type RouteComponentProps = ReactRouter.RouteComponentProps; 477 | export type RouteHook = ReactRouter.RouteHook 478 | export type StringifyQuery = ReactRouter.StringifyQuery 479 | export type RouterListener = ReactRouter.RouterListener 480 | export type RouterState = ReactRouter.RouterState 481 | export type HistoryBase = ReactRouter.HistoryBase 482 | export type RouterOnContext = ReactRouter.RouterOnContext 483 | 484 | export { 485 | Router, 486 | Link, 487 | IndexLink, 488 | IndexRedirect, 489 | IndexRoute, 490 | Redirect, 491 | Route, 492 | History, 493 | browserHistory, 494 | hashHistory, 495 | Lifecycle, 496 | RouteContext, 497 | useRoutes, 498 | createRoutes, 499 | formatPattern, 500 | RouterContext, 501 | PropTypes, 502 | match, 503 | useRouterHistory, 504 | createMemoryHistory 505 | } 506 | 507 | export default Router 508 | 509 | } 510 | -------------------------------------------------------------------------------- /my-app/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/DefinitelyTyped/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.8 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.8. 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 | type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex"; 84 | interface Buffer extends NodeBuffer {} 85 | 86 | /** 87 | * Raw data is stored in instances of the Buffer class. 88 | * 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. 89 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 90 | */ 91 | declare var Buffer: { 92 | /** 93 | * Allocates a new buffer containing the given {str}. 94 | * 95 | * @param str String to store in buffer. 96 | * @param encoding encoding to use, optional. Default is 'utf8' 97 | */ 98 | new (str: string, encoding?: string): Buffer; 99 | /** 100 | * Allocates a new buffer of {size} octets. 101 | * 102 | * @param size count of octets to allocate. 103 | */ 104 | new (size: number): Buffer; 105 | /** 106 | * Allocates a new buffer containing the given {array} of octets. 107 | * 108 | * @param array The octets to store. 109 | */ 110 | new (array: Uint8Array): Buffer; 111 | /** 112 | * Produces a Buffer backed by the same allocated memory as 113 | * the given {ArrayBuffer}. 114 | * 115 | * 116 | * @param arrayBuffer The ArrayBuffer with which to share memory. 117 | */ 118 | new (arrayBuffer: ArrayBuffer): Buffer; 119 | /** 120 | * Allocates a new buffer containing the given {array} of octets. 121 | * 122 | * @param array The octets to store. 123 | */ 124 | new (array: any[]): Buffer; 125 | /** 126 | * Copies the passed {buffer} data onto a new {Buffer} instance. 127 | * 128 | * @param buffer The buffer to copy. 129 | */ 130 | new (buffer: Buffer): Buffer; 131 | prototype: Buffer; 132 | /** 133 | * Returns true if {obj} is a Buffer 134 | * 135 | * @param obj object to test. 136 | */ 137 | isBuffer(obj: any): obj is Buffer; 138 | /** 139 | * Returns true if {encoding} is a valid encoding argument. 140 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' 141 | * 142 | * @param encoding string to test. 143 | */ 144 | isEncoding(encoding: string): boolean; 145 | /** 146 | * Gives the actual byte length of a string. encoding defaults to 'utf8'. 147 | * This is not the same as String.prototype.length since that returns the number of characters in a string. 148 | * 149 | * @param string string to test. 150 | * @param encoding encoding used to evaluate (defaults to 'utf8') 151 | */ 152 | byteLength(string: string, encoding?: string): number; 153 | /** 154 | * Returns a buffer which is the result of concatenating all the buffers in the list together. 155 | * 156 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. 157 | * If the list has exactly one item, then the first item of the list is returned. 158 | * If the list has more than one item, then a new Buffer is created. 159 | * 160 | * @param list An array of Buffer objects to concatenate 161 | * @param totalLength Total length of the buffers when concatenated. 162 | * 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. 163 | */ 164 | concat(list: Buffer[], totalLength?: number): Buffer; 165 | /** 166 | * The same as buf1.compare(buf2). 167 | */ 168 | compare(buf1: Buffer, buf2: Buffer): number; 169 | }; 170 | 171 | /************************************************ 172 | * * 173 | * GLOBAL INTERFACES * 174 | * * 175 | ************************************************/ 176 | declare namespace NodeJS { 177 | export interface ErrnoException extends Error { 178 | errno?: number; 179 | code?: string; 180 | path?: string; 181 | syscall?: string; 182 | stack?: string; 183 | } 184 | 185 | export interface EventEmitter { 186 | addListener(event: string, listener: Function): this; 187 | on(event: string, listener: Function): this; 188 | once(event: string, listener: Function): this; 189 | removeListener(event: string, listener: Function): this; 190 | removeAllListeners(event?: string): this; 191 | setMaxListeners(n: number): this; 192 | getMaxListeners(): number; 193 | listeners(event: string): Function[]; 194 | emit(event: string, ...args: any[]): boolean; 195 | listenerCount(type: string): number; 196 | } 197 | 198 | export interface ReadableStream extends EventEmitter { 199 | readable: boolean; 200 | read(size?: number): string|Buffer; 201 | setEncoding(encoding: string): void; 202 | pause(): void; 203 | resume(): void; 204 | pipe(destination: T, options?: { end?: boolean; }): T; 205 | unpipe(destination?: T): void; 206 | unshift(chunk: string): void; 207 | unshift(chunk: Buffer): void; 208 | wrap(oldStream: ReadableStream): ReadableStream; 209 | } 210 | 211 | export interface WritableStream extends EventEmitter { 212 | writable: boolean; 213 | write(buffer: Buffer|string, cb?: Function): boolean; 214 | write(str: string, encoding?: string, cb?: Function): boolean; 215 | end(): void; 216 | end(buffer: Buffer, cb?: Function): void; 217 | end(str: string, cb?: Function): void; 218 | end(str: string, encoding?: string, cb?: Function): void; 219 | } 220 | 221 | export interface ReadWriteStream extends ReadableStream, WritableStream {} 222 | 223 | export interface Events extends EventEmitter { } 224 | 225 | export interface Domain extends Events { 226 | run(fn: Function): void; 227 | add(emitter: Events): void; 228 | remove(emitter: Events): void; 229 | bind(cb: (err: Error, data: any) => any): any; 230 | intercept(cb: (data: any) => any): any; 231 | dispose(): void; 232 | 233 | addListener(event: string, listener: Function): this; 234 | on(event: string, listener: Function): this; 235 | once(event: string, listener: Function): this; 236 | removeListener(event: string, listener: Function): this; 237 | removeAllListeners(event?: string): this; 238 | } 239 | 240 | export interface MemoryUsage { 241 | rss: number; 242 | heapTotal: number; 243 | heapUsed: number; 244 | } 245 | 246 | export interface Process extends EventEmitter { 247 | stdout: WritableStream; 248 | stderr: WritableStream; 249 | stdin: ReadableStream; 250 | argv: string[]; 251 | execArgv: string[]; 252 | execPath: string; 253 | abort(): void; 254 | chdir(directory: string): void; 255 | cwd(): string; 256 | env: any; 257 | exit(code?: number): void; 258 | getgid(): number; 259 | setgid(id: number): void; 260 | setgid(id: string): void; 261 | getuid(): number; 262 | setuid(id: number): void; 263 | setuid(id: string): void; 264 | version: string; 265 | versions: { 266 | http_parser: string; 267 | node: string; 268 | v8: string; 269 | ares: string; 270 | uv: string; 271 | zlib: string; 272 | openssl: string; 273 | }; 274 | config: { 275 | target_defaults: { 276 | cflags: any[]; 277 | default_configuration: string; 278 | defines: string[]; 279 | include_dirs: string[]; 280 | libraries: string[]; 281 | }; 282 | variables: { 283 | clang: number; 284 | host_arch: string; 285 | node_install_npm: boolean; 286 | node_install_waf: boolean; 287 | node_prefix: string; 288 | node_shared_openssl: boolean; 289 | node_shared_v8: boolean; 290 | node_shared_zlib: boolean; 291 | node_use_dtrace: boolean; 292 | node_use_etw: boolean; 293 | node_use_openssl: boolean; 294 | target_arch: string; 295 | v8_no_strict_aliasing: number; 296 | v8_use_snapshot: boolean; 297 | visibility: string; 298 | }; 299 | }; 300 | kill(pid:number, signal?: string|number): void; 301 | pid: number; 302 | title: string; 303 | arch: string; 304 | platform: string; 305 | memoryUsage(): MemoryUsage; 306 | nextTick(callback: Function): void; 307 | umask(mask?: number): number; 308 | uptime(): number; 309 | hrtime(time?:number[]): number[]; 310 | domain: Domain; 311 | 312 | // Worker 313 | send?(message: any, sendHandle?: any): void; 314 | disconnect(): void; 315 | connected: boolean; 316 | } 317 | 318 | export interface Global { 319 | Array: typeof Array; 320 | ArrayBuffer: typeof ArrayBuffer; 321 | Boolean: typeof Boolean; 322 | Buffer: typeof Buffer; 323 | DataView: typeof DataView; 324 | Date: typeof Date; 325 | Error: typeof Error; 326 | EvalError: typeof EvalError; 327 | Float32Array: typeof Float32Array; 328 | Float64Array: typeof Float64Array; 329 | Function: typeof Function; 330 | GLOBAL: Global; 331 | Infinity: typeof Infinity; 332 | Int16Array: typeof Int16Array; 333 | Int32Array: typeof Int32Array; 334 | Int8Array: typeof Int8Array; 335 | Intl: typeof Intl; 336 | JSON: typeof JSON; 337 | Map: MapConstructor; 338 | Math: typeof Math; 339 | NaN: typeof NaN; 340 | Number: typeof Number; 341 | Object: typeof Object; 342 | Promise: Function; 343 | RangeError: typeof RangeError; 344 | ReferenceError: typeof ReferenceError; 345 | RegExp: typeof RegExp; 346 | Set: SetConstructor; 347 | String: typeof String; 348 | Symbol: Function; 349 | SyntaxError: typeof SyntaxError; 350 | TypeError: typeof TypeError; 351 | URIError: typeof URIError; 352 | Uint16Array: typeof Uint16Array; 353 | Uint32Array: typeof Uint32Array; 354 | Uint8Array: typeof Uint8Array; 355 | Uint8ClampedArray: Function; 356 | WeakMap: WeakMapConstructor; 357 | WeakSet: WeakSetConstructor; 358 | clearImmediate: (immediateId: any) => void; 359 | clearInterval: (intervalId: NodeJS.Timer) => void; 360 | clearTimeout: (timeoutId: NodeJS.Timer) => void; 361 | console: typeof console; 362 | decodeURI: typeof decodeURI; 363 | decodeURIComponent: typeof decodeURIComponent; 364 | encodeURI: typeof encodeURI; 365 | encodeURIComponent: typeof encodeURIComponent; 366 | escape: (str: string) => string; 367 | eval: typeof eval; 368 | global: Global; 369 | isFinite: typeof isFinite; 370 | isNaN: typeof isNaN; 371 | parseFloat: typeof parseFloat; 372 | parseInt: typeof parseInt; 373 | process: Process; 374 | root: Global; 375 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; 376 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 377 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; 378 | undefined: typeof undefined; 379 | unescape: (str: string) => string; 380 | gc: () => void; 381 | v8debug?: any; 382 | } 383 | 384 | export interface Timer { 385 | ref() : void; 386 | unref() : void; 387 | } 388 | } 389 | 390 | /** 391 | * @deprecated 392 | */ 393 | interface NodeBuffer extends Uint8Array { 394 | write(string: string, offset?: number, length?: number, encoding?: string): number; 395 | toString(encoding?: string, start?: number, end?: number): string; 396 | toJSON(): any; 397 | equals(otherBuffer: Buffer): boolean; 398 | compare(otherBuffer: Buffer): number; 399 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 400 | slice(start?: number, end?: number): Buffer; 401 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 402 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 403 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 404 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; 405 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 406 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 407 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; 408 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; 409 | readUInt8(offset: number, noAssert?: boolean): number; 410 | readUInt16LE(offset: number, noAssert?: boolean): number; 411 | readUInt16BE(offset: number, noAssert?: boolean): number; 412 | readUInt32LE(offset: number, noAssert?: boolean): number; 413 | readUInt32BE(offset: number, noAssert?: boolean): number; 414 | readInt8(offset: number, noAssert?: boolean): number; 415 | readInt16LE(offset: number, noAssert?: boolean): number; 416 | readInt16BE(offset: number, noAssert?: boolean): number; 417 | readInt32LE(offset: number, noAssert?: boolean): number; 418 | readInt32BE(offset: number, noAssert?: boolean): number; 419 | readFloatLE(offset: number, noAssert?: boolean): number; 420 | readFloatBE(offset: number, noAssert?: boolean): number; 421 | readDoubleLE(offset: number, noAssert?: boolean): number; 422 | readDoubleBE(offset: number, noAssert?: boolean): number; 423 | writeUInt8(value: number, offset: number, noAssert?: boolean): number; 424 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; 425 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; 426 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; 427 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; 428 | writeInt8(value: number, offset: number, noAssert?: boolean): number; 429 | writeInt16LE(value: number, offset: number, noAssert?: boolean): number; 430 | writeInt16BE(value: number, offset: number, noAssert?: boolean): number; 431 | writeInt32LE(value: number, offset: number, noAssert?: boolean): number; 432 | writeInt32BE(value: number, offset: number, noAssert?: boolean): number; 433 | writeFloatLE(value: number, offset: number, noAssert?: boolean): number; 434 | writeFloatBE(value: number, offset: number, noAssert?: boolean): number; 435 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; 436 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; 437 | fill(value: any, offset?: number, end?: number): Buffer; 438 | // TODO: encoding param 439 | indexOf(value: string | number | Buffer, byteOffset?: number): number; 440 | // TODO: entries 441 | // TODO: includes 442 | // TODO: keys 443 | // TODO: values 444 | } 445 | 446 | /************************************************ 447 | * * 448 | * MODULES * 449 | * * 450 | ************************************************/ 451 | declare module "buffer" { 452 | export var INSPECT_MAX_BYTES: number; 453 | var BuffType: typeof Buffer; 454 | var SlowBuffType: typeof SlowBuffer; 455 | export { BuffType as Buffer, SlowBuffType as SlowBuffer }; 456 | } 457 | 458 | declare module "querystring" { 459 | export interface StringifyOptions { 460 | encodeURIComponent?: Function; 461 | } 462 | 463 | export interface ParseOptions { 464 | maxKeys?: number; 465 | decodeURIComponent?: Function; 466 | } 467 | 468 | export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; 469 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; 470 | export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; 471 | export function escape(str: string): string; 472 | export function unescape(str: string): string; 473 | } 474 | 475 | declare module "events" { 476 | export class EventEmitter implements NodeJS.EventEmitter { 477 | static EventEmitter: EventEmitter; 478 | static listenerCount(emitter: EventEmitter, event: string): number; // deprecated 479 | static defaultMaxListeners: number; 480 | 481 | addListener(event: string, listener: Function): this; 482 | on(event: string, listener: Function): this; 483 | once(event: string, listener: Function): this; 484 | removeListener(event: string, listener: Function): this; 485 | removeAllListeners(event?: string): this; 486 | setMaxListeners(n: number): this; 487 | getMaxListeners(): number; 488 | listeners(event: string): Function[]; 489 | emit(event: string, ...args: any[]): boolean; 490 | listenerCount(type: string): number; 491 | } 492 | } 493 | 494 | declare module "http" { 495 | import * as events from "events"; 496 | import * as net from "net"; 497 | import * as stream from "stream"; 498 | 499 | export interface RequestOptions { 500 | protocol?: string; 501 | host?: string; 502 | hostname?: string; 503 | family?: number; 504 | port?: number; 505 | localAddress?: string; 506 | socketPath?: string; 507 | method?: string; 508 | path?: string; 509 | headers?: { [key: string]: any }; 510 | auth?: string; 511 | agent?: Agent|boolean; 512 | } 513 | 514 | export interface Server extends events.EventEmitter, net.Server { 515 | setTimeout(msecs: number, callback: Function): void; 516 | maxHeadersCount: number; 517 | timeout: number; 518 | } 519 | /** 520 | * @deprecated Use IncomingMessage 521 | */ 522 | export interface ServerRequest extends IncomingMessage { 523 | connection: net.Socket; 524 | } 525 | export interface ServerResponse extends events.EventEmitter, stream.Writable { 526 | // Extended base methods 527 | write(buffer: Buffer): boolean; 528 | write(buffer: Buffer, cb?: Function): boolean; 529 | write(str: string, cb?: Function): boolean; 530 | write(str: string, encoding?: string, cb?: Function): boolean; 531 | write(str: string, encoding?: string, fd?: string): boolean; 532 | 533 | writeContinue(): void; 534 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; 535 | writeHead(statusCode: number, headers?: any): void; 536 | statusCode: number; 537 | statusMessage: string; 538 | headersSent: boolean; 539 | setHeader(name: string, value: string | string[]): void; 540 | sendDate: boolean; 541 | getHeader(name: string): string; 542 | removeHeader(name: string): void; 543 | write(chunk: any, encoding?: string): any; 544 | addTrailers(headers: any): void; 545 | 546 | // Extended base methods 547 | end(): void; 548 | end(buffer: Buffer, cb?: Function): void; 549 | end(str: string, cb?: Function): void; 550 | end(str: string, encoding?: string, cb?: Function): void; 551 | end(data?: any, encoding?: string): void; 552 | } 553 | export interface ClientRequest extends events.EventEmitter, stream.Writable { 554 | // Extended base methods 555 | write(buffer: Buffer): boolean; 556 | write(buffer: Buffer, cb?: Function): boolean; 557 | write(str: string, cb?: Function): boolean; 558 | write(str: string, encoding?: string, cb?: Function): boolean; 559 | write(str: string, encoding?: string, fd?: string): boolean; 560 | 561 | write(chunk: any, encoding?: string): void; 562 | abort(): void; 563 | setTimeout(timeout: number, callback?: Function): void; 564 | setNoDelay(noDelay?: boolean): void; 565 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; 566 | 567 | setHeader(name: string, value: string | string[]): void; 568 | getHeader(name: string): string; 569 | removeHeader(name: string): void; 570 | addTrailers(headers: any): void; 571 | 572 | // Extended base methods 573 | end(): void; 574 | end(buffer: Buffer, cb?: Function): void; 575 | end(str: string, cb?: Function): void; 576 | end(str: string, encoding?: string, cb?: Function): void; 577 | end(data?: any, encoding?: string): void; 578 | } 579 | export interface IncomingMessage extends events.EventEmitter, stream.Readable { 580 | httpVersion: string; 581 | headers: any; 582 | rawHeaders: string[]; 583 | trailers: any; 584 | rawTrailers: any; 585 | setTimeout(msecs: number, callback: Function): NodeJS.Timer; 586 | /** 587 | * Only valid for request obtained from http.Server. 588 | */ 589 | method?: string; 590 | /** 591 | * Only valid for request obtained from http.Server. 592 | */ 593 | url?: string; 594 | /** 595 | * Only valid for response obtained from http.ClientRequest. 596 | */ 597 | statusCode?: number; 598 | /** 599 | * Only valid for response obtained from http.ClientRequest. 600 | */ 601 | statusMessage?: string; 602 | socket: net.Socket; 603 | } 604 | /** 605 | * @deprecated Use IncomingMessage 606 | */ 607 | export interface ClientResponse extends IncomingMessage { } 608 | 609 | export interface AgentOptions { 610 | /** 611 | * Keep sockets around in a pool to be used by other requests in the future. Default = false 612 | */ 613 | keepAlive?: boolean; 614 | /** 615 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. 616 | * Only relevant if keepAlive is set to true. 617 | */ 618 | keepAliveMsecs?: number; 619 | /** 620 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity 621 | */ 622 | maxSockets?: number; 623 | /** 624 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. 625 | */ 626 | maxFreeSockets?: number; 627 | } 628 | 629 | export class Agent { 630 | maxSockets: number; 631 | sockets: any; 632 | requests: any; 633 | 634 | constructor(opts?: AgentOptions); 635 | 636 | /** 637 | * Destroy any sockets that are currently in use by the agent. 638 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, 639 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, 640 | * sockets may hang open for quite a long time before the server terminates them. 641 | */ 642 | destroy(): void; 643 | } 644 | 645 | export var METHODS: string[]; 646 | 647 | export var STATUS_CODES: { 648 | [errorCode: number]: string; 649 | [errorCode: string]: string; 650 | }; 651 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; 652 | export function createClient(port?: number, host?: string): any; 653 | export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; 654 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; 655 | export var globalAgent: Agent; 656 | } 657 | 658 | declare module "cluster" { 659 | import * as child from "child_process"; 660 | import * as events from "events"; 661 | 662 | export interface ClusterSettings { 663 | exec?: string; 664 | args?: string[]; 665 | silent?: boolean; 666 | } 667 | 668 | export interface Address { 669 | address: string; 670 | port: number; 671 | addressType: string; 672 | } 673 | 674 | export class Worker extends events.EventEmitter { 675 | id: string; 676 | process: child.ChildProcess; 677 | suicide: boolean; 678 | send(message: any, sendHandle?: any): void; 679 | kill(signal?: string): void; 680 | destroy(signal?: string): void; 681 | disconnect(): void; 682 | isConnected(): boolean; 683 | isDead(): boolean; 684 | } 685 | 686 | export var settings: ClusterSettings; 687 | export var isMaster: boolean; 688 | export var isWorker: boolean; 689 | export function setupMaster(settings?: ClusterSettings): void; 690 | export function fork(env?: any): Worker; 691 | export function disconnect(callback?: Function): void; 692 | export var worker: Worker; 693 | export var workers: { 694 | [index: string]: Worker 695 | }; 696 | 697 | // Event emitter 698 | export function addListener(event: string, listener: Function): void; 699 | export function on(event: "disconnect", listener: (worker: Worker) => void): void; 700 | export function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): void; 701 | export function on(event: "fork", listener: (worker: Worker) => void): void; 702 | export function on(event: "listening", listener: (worker: Worker, address: any) => void): void; 703 | export function on(event: "message", listener: (worker: Worker, message: any) => void): void; 704 | export function on(event: "online", listener: (worker: Worker) => void): void; 705 | export function on(event: "setup", listener: (settings: any) => void): void; 706 | export function on(event: string, listener: Function): any; 707 | export function once(event: string, listener: Function): void; 708 | export function removeListener(event: string, listener: Function): void; 709 | export function removeAllListeners(event?: string): void; 710 | export function setMaxListeners(n: number): void; 711 | export function listeners(event: string): Function[]; 712 | export function emit(event: string, ...args: any[]): boolean; 713 | } 714 | 715 | declare module "zlib" { 716 | import * as stream from "stream"; 717 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } 718 | 719 | export interface Gzip extends stream.Transform { } 720 | export interface Gunzip extends stream.Transform { } 721 | export interface Deflate extends stream.Transform { } 722 | export interface Inflate extends stream.Transform { } 723 | export interface DeflateRaw extends stream.Transform { } 724 | export interface InflateRaw extends stream.Transform { } 725 | export interface Unzip extends stream.Transform { } 726 | 727 | export function createGzip(options?: ZlibOptions): Gzip; 728 | export function createGunzip(options?: ZlibOptions): Gunzip; 729 | export function createDeflate(options?: ZlibOptions): Deflate; 730 | export function createInflate(options?: ZlibOptions): Inflate; 731 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; 732 | export function createInflateRaw(options?: ZlibOptions): InflateRaw; 733 | export function createUnzip(options?: ZlibOptions): Unzip; 734 | 735 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 736 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any; 737 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 738 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; 739 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 740 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any; 741 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 742 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; 743 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 744 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any; 745 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 746 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; 747 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; 748 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any; 749 | 750 | // Constants 751 | export var Z_NO_FLUSH: number; 752 | export var Z_PARTIAL_FLUSH: number; 753 | export var Z_SYNC_FLUSH: number; 754 | export var Z_FULL_FLUSH: number; 755 | export var Z_FINISH: number; 756 | export var Z_BLOCK: number; 757 | export var Z_TREES: number; 758 | export var Z_OK: number; 759 | export var Z_STREAM_END: number; 760 | export var Z_NEED_DICT: number; 761 | export var Z_ERRNO: number; 762 | export var Z_STREAM_ERROR: number; 763 | export var Z_DATA_ERROR: number; 764 | export var Z_MEM_ERROR: number; 765 | export var Z_BUF_ERROR: number; 766 | export var Z_VERSION_ERROR: number; 767 | export var Z_NO_COMPRESSION: number; 768 | export var Z_BEST_SPEED: number; 769 | export var Z_BEST_COMPRESSION: number; 770 | export var Z_DEFAULT_COMPRESSION: number; 771 | export var Z_FILTERED: number; 772 | export var Z_HUFFMAN_ONLY: number; 773 | export var Z_RLE: number; 774 | export var Z_FIXED: number; 775 | export var Z_DEFAULT_STRATEGY: number; 776 | export var Z_BINARY: number; 777 | export var Z_TEXT: number; 778 | export var Z_ASCII: number; 779 | export var Z_UNKNOWN: number; 780 | export var Z_DEFLATED: number; 781 | export var Z_NULL: number; 782 | } 783 | 784 | declare module "os" { 785 | export interface CpuInfo { 786 | model: string; 787 | speed: number; 788 | times: { 789 | user: number; 790 | nice: number; 791 | sys: number; 792 | idle: number; 793 | irq: number; 794 | }; 795 | } 796 | 797 | export interface NetworkInterfaceInfo { 798 | address: string; 799 | netmask: string; 800 | family: string; 801 | mac: string; 802 | internal: boolean; 803 | } 804 | 805 | export function tmpdir(): string; 806 | export function homedir(): string; 807 | export function endianness(): string; 808 | export function hostname(): string; 809 | export function type(): string; 810 | export function platform(): string; 811 | export function arch(): string; 812 | export function release(): string; 813 | export function uptime(): number; 814 | export function loadavg(): number[]; 815 | export function totalmem(): number; 816 | export function freemem(): number; 817 | export function cpus(): CpuInfo[]; 818 | export function networkInterfaces(): {[index: string]: NetworkInterfaceInfo[]}; 819 | export var EOL: string; 820 | } 821 | 822 | declare module "https" { 823 | import * as tls from "tls"; 824 | import * as events from "events"; 825 | import * as http from "http"; 826 | 827 | export interface ServerOptions { 828 | pfx?: any; 829 | key?: any; 830 | passphrase?: string; 831 | cert?: any; 832 | ca?: any; 833 | crl?: any; 834 | ciphers?: string; 835 | honorCipherOrder?: boolean; 836 | requestCert?: boolean; 837 | rejectUnauthorized?: boolean; 838 | NPNProtocols?: any; 839 | SNICallback?: (servername: string) => any; 840 | } 841 | 842 | export interface RequestOptions extends http.RequestOptions{ 843 | pfx?: any; 844 | key?: any; 845 | passphrase?: string; 846 | cert?: any; 847 | ca?: any; 848 | ciphers?: string; 849 | rejectUnauthorized?: boolean; 850 | secureProtocol?: string; 851 | } 852 | 853 | export interface Agent { 854 | maxSockets: number; 855 | sockets: any; 856 | requests: any; 857 | } 858 | export var Agent: { 859 | new (options?: RequestOptions): Agent; 860 | }; 861 | export interface Server extends tls.Server { } 862 | export function createServer(options: ServerOptions, requestListener?: Function): Server; 863 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 864 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; 865 | export var globalAgent: Agent; 866 | } 867 | 868 | declare module "punycode" { 869 | export function decode(string: string): string; 870 | export function encode(string: string): string; 871 | export function toUnicode(domain: string): string; 872 | export function toASCII(domain: string): string; 873 | export var ucs2: ucs2; 874 | interface ucs2 { 875 | decode(string: string): number[]; 876 | encode(codePoints: number[]): string; 877 | } 878 | export var version: any; 879 | } 880 | 881 | declare module "repl" { 882 | import * as stream from "stream"; 883 | import * as events from "events"; 884 | 885 | export interface ReplOptions { 886 | prompt?: string; 887 | input?: NodeJS.ReadableStream; 888 | output?: NodeJS.WritableStream; 889 | terminal?: boolean; 890 | eval?: Function; 891 | useColors?: boolean; 892 | useGlobal?: boolean; 893 | ignoreUndefined?: boolean; 894 | writer?: Function; 895 | } 896 | export function start(options: ReplOptions): events.EventEmitter; 897 | } 898 | 899 | declare module "readline" { 900 | import * as events from "events"; 901 | import * as stream from "stream"; 902 | 903 | export interface Key { 904 | sequence?: string; 905 | name?: string; 906 | ctrl?: boolean; 907 | meta?: boolean; 908 | shift?: boolean; 909 | } 910 | 911 | export interface ReadLine extends events.EventEmitter { 912 | setPrompt(prompt: string): void; 913 | prompt(preserveCursor?: boolean): void; 914 | question(query: string, callback: (answer: string) => void): void; 915 | pause(): ReadLine; 916 | resume(): ReadLine; 917 | close(): void; 918 | write(data: string|Buffer, key?: Key): void; 919 | } 920 | 921 | export interface Completer { 922 | (line: string): CompleterResult; 923 | (line: string, callback: (err: any, result: CompleterResult) => void): any; 924 | } 925 | 926 | export interface CompleterResult { 927 | completions: string[]; 928 | line: string; 929 | } 930 | 931 | export interface ReadLineOptions { 932 | input: NodeJS.ReadableStream; 933 | output?: NodeJS.WritableStream; 934 | completer?: Completer; 935 | terminal?: boolean; 936 | historySize?: number; 937 | } 938 | 939 | export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine; 940 | export function createInterface(options: ReadLineOptions): ReadLine; 941 | 942 | export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void; 943 | export function moveCursor(stream: NodeJS.WritableStream, dx: number|string, dy: number|string): void; 944 | export function clearLine(stream: NodeJS.WritableStream, dir: number): void; 945 | export function clearScreenDown(stream: NodeJS.WritableStream): void; 946 | } 947 | 948 | declare module "vm" { 949 | export interface Context { } 950 | export interface ScriptOptions { 951 | filename?: string; 952 | lineOffset?: number; 953 | columnOffset?: number; 954 | displayErrors?: boolean; 955 | timeout?: number; 956 | cachedData?: Buffer; 957 | produceCachedData?: boolean; 958 | } 959 | export interface RunningScriptOptions { 960 | filename?: string; 961 | lineOffset?: number; 962 | columnOffset?: number; 963 | displayErrors?: boolean; 964 | timeout?: number; 965 | } 966 | export class Script { 967 | constructor(code: string, options?: ScriptOptions); 968 | runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any; 969 | runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any; 970 | runInThisContext(options?: RunningScriptOptions): any; 971 | } 972 | export function createContext(sandbox?: Context): Context; 973 | export function isContext(sandbox: Context): boolean; 974 | export function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions): any; 975 | export function runInDebugContext(code: string): any; 976 | export function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions): any; 977 | export function runInThisContext(code: string, options?: RunningScriptOptions): any; 978 | } 979 | 980 | declare module "child_process" { 981 | import * as events from "events"; 982 | import * as stream from "stream"; 983 | 984 | export interface ChildProcess extends events.EventEmitter { 985 | stdin: stream.Writable; 986 | stdout: stream.Readable; 987 | stderr: stream.Readable; 988 | stdio: [stream.Writable, stream.Readable, stream.Readable]; 989 | pid: number; 990 | kill(signal?: string): void; 991 | send(message: any, sendHandle?: any): void; 992 | disconnect(): void; 993 | unref(): void; 994 | } 995 | 996 | export interface SpawnOptions { 997 | cwd?: string; 998 | env?: any; 999 | stdio?: any; 1000 | detached?: boolean; 1001 | uid?: number; 1002 | gid?: number; 1003 | shell?: boolean | string; 1004 | } 1005 | export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; 1006 | 1007 | export interface ExecOptions { 1008 | cwd?: string; 1009 | env?: any; 1010 | shell?: string; 1011 | timeout?: number; 1012 | maxBuffer?: number; 1013 | killSignal?: string; 1014 | uid?: number; 1015 | gid?: number; 1016 | } 1017 | export interface ExecOptionsWithStringEncoding extends ExecOptions { 1018 | encoding: BufferEncoding; 1019 | } 1020 | export interface ExecOptionsWithBufferEncoding extends ExecOptions { 1021 | encoding: string; // specify `null`. 1022 | } 1023 | export function exec(command: string, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1024 | export function exec(command: string, options: ExecOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1025 | // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {}); 1026 | export function exec(command: string, options: ExecOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 1027 | export function exec(command: string, options: ExecOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1028 | 1029 | export interface ExecFileOptions { 1030 | cwd?: string; 1031 | env?: any; 1032 | timeout?: number; 1033 | maxBuffer?: number; 1034 | killSignal?: string; 1035 | uid?: number; 1036 | gid?: number; 1037 | } 1038 | export interface ExecFileOptionsWithStringEncoding extends ExecFileOptions { 1039 | encoding: BufferEncoding; 1040 | } 1041 | export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions { 1042 | encoding: string; // specify `null`. 1043 | } 1044 | export function execFile(file: string, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1045 | export function execFile(file: string, options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1046 | // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {}); 1047 | export function execFile(file: string, options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 1048 | export function execFile(file: string, options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1049 | export function execFile(file: string, args?: string[], callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1050 | export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1051 | // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {}); 1052 | export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; 1053 | export function execFile(file: string, args?: string[], options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) =>void ): ChildProcess; 1054 | 1055 | export interface ForkOptions { 1056 | cwd?: string; 1057 | env?: any; 1058 | execPath?: string; 1059 | execArgv?: string[]; 1060 | silent?: boolean; 1061 | uid?: number; 1062 | gid?: number; 1063 | } 1064 | export function fork(modulePath: string, args?: string[], options?: ForkOptions): ChildProcess; 1065 | 1066 | export interface SpawnSyncOptions { 1067 | cwd?: string; 1068 | input?: string | Buffer; 1069 | stdio?: any; 1070 | env?: any; 1071 | uid?: number; 1072 | gid?: number; 1073 | timeout?: number; 1074 | killSignal?: string; 1075 | maxBuffer?: number; 1076 | encoding?: string; 1077 | shell?: boolean | string; 1078 | } 1079 | export interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions { 1080 | encoding: BufferEncoding; 1081 | } 1082 | export interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions { 1083 | encoding: string; // specify `null`. 1084 | } 1085 | export interface SpawnSyncReturns { 1086 | pid: number; 1087 | output: string[]; 1088 | stdout: T; 1089 | stderr: T; 1090 | status: number; 1091 | signal: string; 1092 | error: Error; 1093 | } 1094 | export function spawnSync(command: string): SpawnSyncReturns; 1095 | export function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; 1096 | export function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; 1097 | export function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; 1098 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; 1099 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; 1100 | export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptions): SpawnSyncReturns; 1101 | 1102 | export interface ExecSyncOptions { 1103 | cwd?: string; 1104 | input?: string | Buffer; 1105 | stdio?: any; 1106 | env?: any; 1107 | shell?: string; 1108 | uid?: number; 1109 | gid?: number; 1110 | timeout?: number; 1111 | killSignal?: string; 1112 | maxBuffer?: number; 1113 | encoding?: string; 1114 | } 1115 | export interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions { 1116 | encoding: BufferEncoding; 1117 | } 1118 | export interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions { 1119 | encoding: string; // specify `null`. 1120 | } 1121 | export function execSync(command: string): Buffer; 1122 | export function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string; 1123 | export function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer; 1124 | export function execSync(command: string, options?: ExecSyncOptions): Buffer; 1125 | 1126 | export interface ExecFileSyncOptions { 1127 | cwd?: string; 1128 | input?: string | Buffer; 1129 | stdio?: any; 1130 | env?: any; 1131 | uid?: number; 1132 | gid?: number; 1133 | timeout?: number; 1134 | killSignal?: string; 1135 | maxBuffer?: number; 1136 | encoding?: string; 1137 | } 1138 | export interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions { 1139 | encoding: BufferEncoding; 1140 | } 1141 | export interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions { 1142 | encoding: string; // specify `null`. 1143 | } 1144 | export function execFileSync(command: string): Buffer; 1145 | export function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string; 1146 | export function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; 1147 | export function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer; 1148 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithStringEncoding): string; 1149 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; 1150 | export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptions): Buffer; 1151 | } 1152 | 1153 | declare module "url" { 1154 | export interface Url { 1155 | href?: string; 1156 | protocol?: string; 1157 | auth?: string; 1158 | hostname?: string; 1159 | port?: string; 1160 | host?: string; 1161 | pathname?: string; 1162 | search?: string; 1163 | query?: any; // string | Object 1164 | slashes?: boolean; 1165 | hash?: string; 1166 | path?: string; 1167 | } 1168 | 1169 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; 1170 | export function format(url: Url): string; 1171 | export function resolve(from: string, to: string): string; 1172 | } 1173 | 1174 | declare module "dns" { 1175 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; 1176 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; 1177 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1178 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1179 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1180 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1181 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1182 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1183 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1184 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1185 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; 1186 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; 1187 | } 1188 | 1189 | declare module "net" { 1190 | import * as stream from "stream"; 1191 | 1192 | export interface Socket extends stream.Duplex { 1193 | // Extended base methods 1194 | write(buffer: Buffer): boolean; 1195 | write(buffer: Buffer, cb?: Function): boolean; 1196 | write(str: string, cb?: Function): boolean; 1197 | write(str: string, encoding?: string, cb?: Function): boolean; 1198 | write(str: string, encoding?: string, fd?: string): boolean; 1199 | 1200 | connect(port: number, host?: string, connectionListener?: Function): void; 1201 | connect(path: string, connectionListener?: Function): void; 1202 | bufferSize: number; 1203 | setEncoding(encoding?: string): void; 1204 | write(data: any, encoding?: string, callback?: Function): void; 1205 | destroy(): void; 1206 | pause(): void; 1207 | resume(): void; 1208 | setTimeout(timeout: number, callback?: Function): void; 1209 | setNoDelay(noDelay?: boolean): void; 1210 | setKeepAlive(enable?: boolean, initialDelay?: number): void; 1211 | address(): { port: number; family: string; address: string; }; 1212 | unref(): void; 1213 | ref(): void; 1214 | 1215 | remoteAddress: string; 1216 | remoteFamily: string; 1217 | remotePort: number; 1218 | localAddress: string; 1219 | localPort: number; 1220 | bytesRead: number; 1221 | bytesWritten: number; 1222 | 1223 | // Extended base methods 1224 | end(): void; 1225 | end(buffer: Buffer, cb?: Function): void; 1226 | end(str: string, cb?: Function): void; 1227 | end(str: string, encoding?: string, cb?: Function): void; 1228 | end(data?: any, encoding?: string): void; 1229 | } 1230 | 1231 | export var Socket: { 1232 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; 1233 | }; 1234 | 1235 | export interface ListenOptions { 1236 | port?: number; 1237 | host?: string; 1238 | backlog?: number; 1239 | path?: string; 1240 | exclusive?: boolean; 1241 | } 1242 | 1243 | export interface Server extends Socket { 1244 | listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Server; 1245 | listen(port: number, hostname?: string, listeningListener?: Function): Server; 1246 | listen(port: number, backlog?: number, listeningListener?: Function): Server; 1247 | listen(port: number, listeningListener?: Function): Server; 1248 | listen(path: string, backlog?: number, listeningListener?: Function): Server; 1249 | listen(path: string, listeningListener?: Function): Server; 1250 | listen(handle: any, backlog?: number, listeningListener?: Function): Server; 1251 | listen(handle: any, listeningListener?: Function): Server; 1252 | listen(options: ListenOptions, listeningListener?: Function): Server; 1253 | close(callback?: Function): Server; 1254 | address(): { port: number; family: string; address: string; }; 1255 | getConnections(cb: (error: Error, count: number) => void): void; 1256 | ref(): Server; 1257 | unref(): Server; 1258 | maxConnections: number; 1259 | connections: number; 1260 | } 1261 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server; 1262 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; 1263 | export function connect(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1264 | export function connect(port: number, host?: string, connectionListener?: Function): Socket; 1265 | export function connect(path: string, connectionListener?: Function): Socket; 1266 | export function createConnection(options: { port: number, host?: string, localAddress? : string, localPort? : string, family? : number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; 1267 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; 1268 | export function createConnection(path: string, connectionListener?: Function): Socket; 1269 | export function isIP(input: string): number; 1270 | export function isIPv4(input: string): boolean; 1271 | export function isIPv6(input: string): boolean; 1272 | } 1273 | 1274 | declare module "dgram" { 1275 | import * as events from "events"; 1276 | 1277 | interface RemoteInfo { 1278 | address: string; 1279 | port: number; 1280 | size: number; 1281 | } 1282 | 1283 | interface AddressInfo { 1284 | address: string; 1285 | family: string; 1286 | port: number; 1287 | } 1288 | 1289 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; 1290 | 1291 | interface Socket extends events.EventEmitter { 1292 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; 1293 | bind(port: number, address?: string, callback?: () => void): void; 1294 | close(): void; 1295 | address(): AddressInfo; 1296 | setBroadcast(flag: boolean): void; 1297 | setMulticastTTL(ttl: number): void; 1298 | setMulticastLoopback(flag: boolean): void; 1299 | addMembership(multicastAddress: string, multicastInterface?: string): void; 1300 | dropMembership(multicastAddress: string, multicastInterface?: string): void; 1301 | } 1302 | } 1303 | 1304 | declare module "fs" { 1305 | import * as stream from "stream"; 1306 | import * as events from "events"; 1307 | 1308 | interface Stats { 1309 | isFile(): boolean; 1310 | isDirectory(): boolean; 1311 | isBlockDevice(): boolean; 1312 | isCharacterDevice(): boolean; 1313 | isSymbolicLink(): boolean; 1314 | isFIFO(): boolean; 1315 | isSocket(): boolean; 1316 | dev: number; 1317 | ino: number; 1318 | mode: number; 1319 | nlink: number; 1320 | uid: number; 1321 | gid: number; 1322 | rdev: number; 1323 | size: number; 1324 | blksize: number; 1325 | blocks: number; 1326 | atime: Date; 1327 | mtime: Date; 1328 | ctime: Date; 1329 | birthtime: Date; 1330 | } 1331 | 1332 | interface FSWatcher extends events.EventEmitter { 1333 | close(): void; 1334 | } 1335 | 1336 | export interface ReadStream extends stream.Readable { 1337 | close(): void; 1338 | } 1339 | export interface WriteStream extends stream.Writable { 1340 | close(): void; 1341 | bytesWritten: number; 1342 | } 1343 | 1344 | /** 1345 | * Asynchronous rename. 1346 | * @param oldPath 1347 | * @param newPath 1348 | * @param callback No arguments other than a possible exception are given to the completion callback. 1349 | */ 1350 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1351 | /** 1352 | * Synchronous rename 1353 | * @param oldPath 1354 | * @param newPath 1355 | */ 1356 | export function renameSync(oldPath: string, newPath: string): void; 1357 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1358 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1359 | export function truncateSync(path: string, len?: number): void; 1360 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1361 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1362 | export function ftruncateSync(fd: number, len?: number): void; 1363 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1364 | export function chownSync(path: string, uid: number, gid: number): void; 1365 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1366 | export function fchownSync(fd: number, uid: number, gid: number): void; 1367 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1368 | export function lchownSync(path: string, uid: number, gid: number): void; 1369 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1370 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1371 | export function chmodSync(path: string, mode: number): void; 1372 | export function chmodSync(path: string, mode: string): void; 1373 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1374 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1375 | export function fchmodSync(fd: number, mode: number): void; 1376 | export function fchmodSync(fd: number, mode: string): void; 1377 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1378 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1379 | export function lchmodSync(path: string, mode: number): void; 1380 | export function lchmodSync(path: string, mode: string): void; 1381 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1382 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1383 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; 1384 | export function statSync(path: string): Stats; 1385 | export function lstatSync(path: string): Stats; 1386 | export function fstatSync(fd: number): Stats; 1387 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1388 | export function linkSync(srcpath: string, dstpath: string): void; 1389 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1390 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; 1391 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; 1392 | export function readlinkSync(path: string): string; 1393 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; 1394 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; 1395 | export function realpathSync(path: string, cache?: { [path: string]: string }): string; 1396 | /* 1397 | * Asynchronous unlink - deletes the file specified in {path} 1398 | * 1399 | * @param path 1400 | * @param callback No arguments other than a possible exception are given to the completion callback. 1401 | */ 1402 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1403 | /* 1404 | * Synchronous unlink - deletes the file specified in {path} 1405 | * 1406 | * @param path 1407 | */ 1408 | export function unlinkSync(path: string): void; 1409 | /* 1410 | * Asynchronous rmdir - removes the directory specified in {path} 1411 | * 1412 | * @param path 1413 | * @param callback No arguments other than a possible exception are given to the completion callback. 1414 | */ 1415 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1416 | /* 1417 | * Synchronous rmdir - removes the directory specified in {path} 1418 | * 1419 | * @param path 1420 | */ 1421 | export function rmdirSync(path: string): void; 1422 | /* 1423 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1424 | * 1425 | * @param path 1426 | * @param callback No arguments other than a possible exception are given to the completion callback. 1427 | */ 1428 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1429 | /* 1430 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1431 | * 1432 | * @param path 1433 | * @param mode 1434 | * @param callback No arguments other than a possible exception are given to the completion callback. 1435 | */ 1436 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1437 | /* 1438 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1439 | * 1440 | * @param path 1441 | * @param mode 1442 | * @param callback No arguments other than a possible exception are given to the completion callback. 1443 | */ 1444 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; 1445 | /* 1446 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1447 | * 1448 | * @param path 1449 | * @param mode 1450 | * @param callback No arguments other than a possible exception are given to the completion callback. 1451 | */ 1452 | export function mkdirSync(path: string, mode?: number): void; 1453 | /* 1454 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. 1455 | * 1456 | * @param path 1457 | * @param mode 1458 | * @param callback No arguments other than a possible exception are given to the completion callback. 1459 | */ 1460 | export function mkdirSync(path: string, mode?: string): void; 1461 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; 1462 | export function readdirSync(path: string): string[]; 1463 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1464 | export function closeSync(fd: number): void; 1465 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1466 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1467 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; 1468 | export function openSync(path: string, flags: string, mode?: number): number; 1469 | export function openSync(path: string, flags: string, mode?: string): number; 1470 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1471 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1472 | export function utimesSync(path: string, atime: number, mtime: number): void; 1473 | export function utimesSync(path: string, atime: Date, mtime: Date): void; 1474 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1475 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; 1476 | export function futimesSync(fd: number, atime: number, mtime: number): void; 1477 | export function futimesSync(fd: number, atime: Date, mtime: Date): void; 1478 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; 1479 | export function fsyncSync(fd: number): void; 1480 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1481 | export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; 1482 | export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1483 | export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1484 | export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; 1485 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number; 1486 | export function writeSync(fd: number, data: any, position?: number, enconding?: string): number; 1487 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; 1488 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; 1489 | /* 1490 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1491 | * 1492 | * @param fileName 1493 | * @param encoding 1494 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1495 | */ 1496 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1497 | /* 1498 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1499 | * 1500 | * @param fileName 1501 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1502 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1503 | */ 1504 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; 1505 | /* 1506 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1507 | * 1508 | * @param fileName 1509 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. 1510 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1511 | */ 1512 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1513 | /* 1514 | * Asynchronous readFile - Asynchronously reads the entire contents of a file. 1515 | * 1516 | * @param fileName 1517 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. 1518 | */ 1519 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; 1520 | /* 1521 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1522 | * 1523 | * @param fileName 1524 | * @param encoding 1525 | */ 1526 | export function readFileSync(filename: string, encoding: string): string; 1527 | /* 1528 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1529 | * 1530 | * @param fileName 1531 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1532 | */ 1533 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; 1534 | /* 1535 | * Synchronous readFile - Synchronously reads the entire contents of a file. 1536 | * 1537 | * @param fileName 1538 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. 1539 | */ 1540 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; 1541 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1542 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1543 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1544 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1545 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1546 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1547 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; 1548 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; 1549 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; 1550 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; 1551 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; 1552 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; 1553 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; 1554 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; 1555 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; 1556 | export function exists(path: string, callback?: (exists: boolean) => void): void; 1557 | export function existsSync(path: string): boolean; 1558 | /** Constant for fs.access(). File is visible to the calling process. */ 1559 | export var F_OK: number; 1560 | /** Constant for fs.access(). File can be read by the calling process. */ 1561 | export var R_OK: number; 1562 | /** Constant for fs.access(). File can be written by the calling process. */ 1563 | export var W_OK: number; 1564 | /** Constant for fs.access(). File can be executed by the calling process. */ 1565 | export var X_OK: number; 1566 | /** Tests a user's permissions for the file specified by path. */ 1567 | export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; 1568 | export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; 1569 | /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ 1570 | export function accessSync(path: string, mode ?: number): void; 1571 | export function createReadStream(path: string, options?: { 1572 | flags?: string; 1573 | encoding?: string; 1574 | fd?: number; 1575 | mode?: number; 1576 | autoClose?: boolean; 1577 | }): ReadStream; 1578 | export function createWriteStream(path: string, options?: { 1579 | flags?: string; 1580 | encoding?: string; 1581 | fd?: number; 1582 | mode?: number; 1583 | }): WriteStream; 1584 | } 1585 | 1586 | declare module "path" { 1587 | 1588 | /** 1589 | * A parsed path object generated by path.parse() or consumed by path.format(). 1590 | */ 1591 | export interface ParsedPath { 1592 | /** 1593 | * The root of the path such as '/' or 'c:\' 1594 | */ 1595 | root: string; 1596 | /** 1597 | * The full directory path such as '/home/user/dir' or 'c:\path\dir' 1598 | */ 1599 | dir: string; 1600 | /** 1601 | * The file name including extension (if any) such as 'index.html' 1602 | */ 1603 | base: string; 1604 | /** 1605 | * The file extension (if any) such as '.html' 1606 | */ 1607 | ext: string; 1608 | /** 1609 | * The file name without extension (if any) such as 'index' 1610 | */ 1611 | name: string; 1612 | } 1613 | 1614 | /** 1615 | * Normalize a string path, reducing '..' and '.' parts. 1616 | * 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. 1617 | * 1618 | * @param p string path to normalize. 1619 | */ 1620 | export function normalize(p: string): string; 1621 | /** 1622 | * Join all arguments together and normalize the resulting path. 1623 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1624 | * 1625 | * @param paths string paths to join. 1626 | */ 1627 | export function join(...paths: any[]): string; 1628 | /** 1629 | * Join all arguments together and normalize the resulting path. 1630 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. 1631 | * 1632 | * @param paths string paths to join. 1633 | */ 1634 | export function join(...paths: string[]): string; 1635 | /** 1636 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. 1637 | * 1638 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path. 1639 | * 1640 | * 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. 1641 | * 1642 | * @param pathSegments string paths to join. Non-string arguments are ignored. 1643 | */ 1644 | export function resolve(...pathSegments: any[]): string; 1645 | /** 1646 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. 1647 | * 1648 | * @param path path to test. 1649 | */ 1650 | export function isAbsolute(path: string): boolean; 1651 | /** 1652 | * Solve the relative path from {from} to {to}. 1653 | * 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. 1654 | * 1655 | * @param from 1656 | * @param to 1657 | */ 1658 | export function relative(from: string, to: string): string; 1659 | /** 1660 | * Return the directory name of a path. Similar to the Unix dirname command. 1661 | * 1662 | * @param p the path to evaluate. 1663 | */ 1664 | export function dirname(p: string): string; 1665 | /** 1666 | * Return the last portion of a path. Similar to the Unix basename command. 1667 | * Often used to extract the file name from a fully qualified path. 1668 | * 1669 | * @param p the path to evaluate. 1670 | * @param ext optionally, an extension to remove from the result. 1671 | */ 1672 | export function basename(p: string, ext?: string): string; 1673 | /** 1674 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path. 1675 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string 1676 | * 1677 | * @param p the path to evaluate. 1678 | */ 1679 | export function extname(p: string): string; 1680 | /** 1681 | * The platform-specific file separator. '\\' or '/'. 1682 | */ 1683 | export var sep: string; 1684 | /** 1685 | * The platform-specific file delimiter. ';' or ':'. 1686 | */ 1687 | export var delimiter: string; 1688 | /** 1689 | * Returns an object from a path string - the opposite of format(). 1690 | * 1691 | * @param pathString path to evaluate. 1692 | */ 1693 | export function parse(pathString: string): ParsedPath; 1694 | /** 1695 | * Returns a path string from an object - the opposite of parse(). 1696 | * 1697 | * @param pathString path to evaluate. 1698 | */ 1699 | export function format(pathObject: ParsedPath): string; 1700 | 1701 | export module posix { 1702 | export function normalize(p: string): string; 1703 | export function join(...paths: any[]): string; 1704 | export function resolve(...pathSegments: any[]): string; 1705 | export function isAbsolute(p: string): boolean; 1706 | export function relative(from: string, to: string): string; 1707 | export function dirname(p: string): string; 1708 | export function basename(p: string, ext?: string): string; 1709 | export function extname(p: string): string; 1710 | export var sep: string; 1711 | export var delimiter: string; 1712 | export function parse(p: string): ParsedPath; 1713 | export function format(pP: ParsedPath): string; 1714 | } 1715 | 1716 | export module win32 { 1717 | export function normalize(p: string): string; 1718 | export function join(...paths: any[]): string; 1719 | export function resolve(...pathSegments: any[]): string; 1720 | export function isAbsolute(p: string): boolean; 1721 | export function relative(from: string, to: string): string; 1722 | export function dirname(p: string): string; 1723 | export function basename(p: string, ext?: string): string; 1724 | export function extname(p: string): string; 1725 | export var sep: string; 1726 | export var delimiter: string; 1727 | export function parse(p: string): ParsedPath; 1728 | export function format(pP: ParsedPath): string; 1729 | } 1730 | } 1731 | 1732 | declare module "string_decoder" { 1733 | export interface NodeStringDecoder { 1734 | write(buffer: Buffer): string; 1735 | detectIncompleteChar(buffer: Buffer): number; 1736 | } 1737 | export var StringDecoder: { 1738 | new (encoding: string): NodeStringDecoder; 1739 | }; 1740 | } 1741 | 1742 | declare module "tls" { 1743 | import * as crypto from "crypto"; 1744 | import * as net from "net"; 1745 | import * as stream from "stream"; 1746 | 1747 | var CLIENT_RENEG_LIMIT: number; 1748 | var CLIENT_RENEG_WINDOW: number; 1749 | 1750 | export interface TlsOptions { 1751 | host?: string; 1752 | port?: number; 1753 | pfx?: any; //string or buffer 1754 | key?: any; //string or buffer 1755 | passphrase?: string; 1756 | cert?: any; 1757 | ca?: any; //string or buffer 1758 | crl?: any; //string or string array 1759 | ciphers?: string; 1760 | honorCipherOrder?: any; 1761 | requestCert?: boolean; 1762 | rejectUnauthorized?: boolean; 1763 | NPNProtocols?: any; //array or Buffer; 1764 | SNICallback?: (servername: string) => any; 1765 | } 1766 | 1767 | export interface ConnectionOptions { 1768 | host?: string; 1769 | port?: number; 1770 | socket?: net.Socket; 1771 | pfx?: any; //string | Buffer 1772 | key?: any; //string | Buffer 1773 | passphrase?: string; 1774 | cert?: any; //string | Buffer 1775 | ca?: any; //Array of string | Buffer 1776 | rejectUnauthorized?: boolean; 1777 | NPNProtocols?: any; //Array of string | Buffer 1778 | servername?: string; 1779 | } 1780 | 1781 | export interface Server extends net.Server { 1782 | close(): Server; 1783 | address(): { port: number; family: string; address: string; }; 1784 | addContext(hostName: string, credentials: { 1785 | key: string; 1786 | cert: string; 1787 | ca: string; 1788 | }): void; 1789 | maxConnections: number; 1790 | connections: number; 1791 | } 1792 | 1793 | export interface ClearTextStream extends stream.Duplex { 1794 | authorized: boolean; 1795 | authorizationError: Error; 1796 | getPeerCertificate(): any; 1797 | getCipher: { 1798 | name: string; 1799 | version: string; 1800 | }; 1801 | address: { 1802 | port: number; 1803 | family: string; 1804 | address: string; 1805 | }; 1806 | remoteAddress: string; 1807 | remotePort: number; 1808 | } 1809 | 1810 | export interface SecurePair { 1811 | encrypted: any; 1812 | cleartext: any; 1813 | } 1814 | 1815 | export interface SecureContextOptions { 1816 | pfx?: any; //string | buffer 1817 | key?: any; //string | buffer 1818 | passphrase?: string; 1819 | cert?: any; // string | buffer 1820 | ca?: any; // string | buffer 1821 | crl?: any; // string | string[] 1822 | ciphers?: string; 1823 | honorCipherOrder?: boolean; 1824 | } 1825 | 1826 | export interface SecureContext { 1827 | context: any; 1828 | } 1829 | 1830 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; 1831 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; 1832 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1833 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; 1834 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; 1835 | export function createSecureContext(details: SecureContextOptions): SecureContext; 1836 | } 1837 | 1838 | declare module "crypto" { 1839 | export interface CredentialDetails { 1840 | pfx: string; 1841 | key: string; 1842 | passphrase: string; 1843 | cert: string; 1844 | ca: any; //string | string array 1845 | crl: any; //string | string array 1846 | ciphers: string; 1847 | } 1848 | export interface Credentials { context?: any; } 1849 | export function createCredentials(details: CredentialDetails): Credentials; 1850 | export function createHash(algorithm: string): Hash; 1851 | export function createHmac(algorithm: string, key: string): Hmac; 1852 | export function createHmac(algorithm: string, key: Buffer): Hmac; 1853 | export interface Hash { 1854 | update(data: any, input_encoding?: string): Hash; 1855 | digest(encoding: 'buffer'): Buffer; 1856 | digest(encoding: string): any; 1857 | digest(): Buffer; 1858 | } 1859 | export interface Hmac extends NodeJS.ReadWriteStream { 1860 | update(data: any, input_encoding?: string): Hmac; 1861 | digest(encoding: 'buffer'): Buffer; 1862 | digest(encoding: string): any; 1863 | digest(): Buffer; 1864 | } 1865 | export function createCipher(algorithm: string, password: any): Cipher; 1866 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; 1867 | export interface Cipher extends NodeJS.ReadWriteStream { 1868 | update(data: Buffer): Buffer; 1869 | update(data: string, input_encoding: "utf8"|"ascii"|"binary"): Buffer; 1870 | update(data: Buffer, input_encoding: any, output_encoding: "binary"|"base64"|"hex"): string; 1871 | update(data: string, input_encoding: "utf8"|"ascii"|"binary", output_encoding: "binary"|"base64"|"hex"): string; 1872 | final(): Buffer; 1873 | final(output_encoding: string): string; 1874 | setAutoPadding(auto_padding: boolean): void; 1875 | getAuthTag(): Buffer; 1876 | } 1877 | export function createDecipher(algorithm: string, password: any): Decipher; 1878 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; 1879 | export interface Decipher extends NodeJS.ReadWriteStream { 1880 | update(data: Buffer): Buffer; 1881 | update(data: string, input_encoding: "binary"|"base64"|"hex"): Buffer; 1882 | update(data: Buffer, input_encoding: any, output_encoding: "utf8"|"ascii"|"binary"): string; 1883 | update(data: string, input_encoding: "binary"|"base64"|"hex", output_encoding: "utf8"|"ascii"|"binary"): string; 1884 | final(): Buffer; 1885 | final(output_encoding: string): string; 1886 | setAutoPadding(auto_padding: boolean): void; 1887 | setAuthTag(tag: Buffer): void; 1888 | } 1889 | export function createSign(algorithm: string): Signer; 1890 | export interface Signer extends NodeJS.WritableStream { 1891 | update(data: any): void; 1892 | sign(private_key: string, output_format: string): string; 1893 | } 1894 | export function createVerify(algorith: string): Verify; 1895 | export interface Verify extends NodeJS.WritableStream { 1896 | update(data: any): void; 1897 | verify(object: string, signature: string, signature_format?: string): boolean; 1898 | } 1899 | export function createDiffieHellman(prime_length: number): DiffieHellman; 1900 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; 1901 | export interface DiffieHellman { 1902 | generateKeys(encoding?: string): string; 1903 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; 1904 | getPrime(encoding?: string): string; 1905 | getGenerator(encoding: string): string; 1906 | getPublicKey(encoding?: string): string; 1907 | getPrivateKey(encoding?: string): string; 1908 | setPublicKey(public_key: string, encoding?: string): void; 1909 | setPrivateKey(public_key: string, encoding?: string): void; 1910 | } 1911 | export function getDiffieHellman(group_name: string): DiffieHellman; 1912 | export function pbkdf2(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; 1913 | export function pbkdf2(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; 1914 | export function pbkdf2Sync(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number) : Buffer; 1915 | export function pbkdf2Sync(password: string|Buffer, salt: string|Buffer, iterations: number, keylen: number, digest: string) : Buffer; 1916 | export function randomBytes(size: number): Buffer; 1917 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1918 | export function pseudoRandomBytes(size: number): Buffer; 1919 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; 1920 | export interface RsaPublicKey { 1921 | key: string; 1922 | padding?: any; 1923 | } 1924 | export interface RsaPrivateKey { 1925 | key: string; 1926 | passphrase?: string, 1927 | padding?: any; 1928 | } 1929 | export function publicEncrypt(public_key: string|RsaPublicKey, buffer: Buffer): Buffer 1930 | export function privateDecrypt(private_key: string|RsaPrivateKey, buffer: Buffer): Buffer 1931 | } 1932 | 1933 | declare module "stream" { 1934 | import * as events from "events"; 1935 | 1936 | export class Stream extends events.EventEmitter { 1937 | pipe(destination: T, options?: { end?: boolean; }): T; 1938 | } 1939 | 1940 | export interface ReadableOptions { 1941 | highWaterMark?: number; 1942 | encoding?: string; 1943 | objectMode?: boolean; 1944 | } 1945 | 1946 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { 1947 | readable: boolean; 1948 | constructor(opts?: ReadableOptions); 1949 | _read(size: number): void; 1950 | read(size?: number): any; 1951 | setEncoding(encoding: string): void; 1952 | pause(): void; 1953 | resume(): void; 1954 | pipe(destination: T, options?: { end?: boolean; }): T; 1955 | unpipe(destination?: T): void; 1956 | unshift(chunk: any): void; 1957 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 1958 | push(chunk: any, encoding?: string): boolean; 1959 | } 1960 | 1961 | export interface WritableOptions { 1962 | highWaterMark?: number; 1963 | decodeStrings?: boolean; 1964 | objectMode?: boolean; 1965 | } 1966 | 1967 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream { 1968 | writable: boolean; 1969 | constructor(opts?: WritableOptions); 1970 | _write(chunk: any, encoding: string, callback: Function): void; 1971 | write(chunk: any, cb?: Function): boolean; 1972 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1973 | end(): void; 1974 | end(chunk: any, cb?: Function): void; 1975 | end(chunk: any, encoding?: string, cb?: Function): void; 1976 | } 1977 | 1978 | export interface DuplexOptions extends ReadableOptions, WritableOptions { 1979 | allowHalfOpen?: boolean; 1980 | } 1981 | 1982 | // Note: Duplex extends both Readable and Writable. 1983 | export class Duplex extends Readable implements NodeJS.ReadWriteStream { 1984 | writable: boolean; 1985 | constructor(opts?: DuplexOptions); 1986 | _write(chunk: any, encoding: string, callback: Function): void; 1987 | write(chunk: any, cb?: Function): boolean; 1988 | write(chunk: any, encoding?: string, cb?: Function): boolean; 1989 | end(): void; 1990 | end(chunk: any, cb?: Function): void; 1991 | end(chunk: any, encoding?: string, cb?: Function): void; 1992 | } 1993 | 1994 | export interface TransformOptions extends ReadableOptions, WritableOptions {} 1995 | 1996 | // Note: Transform lacks the _read and _write methods of Readable/Writable. 1997 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { 1998 | readable: boolean; 1999 | writable: boolean; 2000 | constructor(opts?: TransformOptions); 2001 | _transform(chunk: any, encoding: string, callback: Function): void; 2002 | _flush(callback: Function): void; 2003 | read(size?: number): any; 2004 | setEncoding(encoding: string): void; 2005 | pause(): void; 2006 | resume(): void; 2007 | pipe(destination: T, options?: { end?: boolean; }): T; 2008 | unpipe(destination?: T): void; 2009 | unshift(chunk: any): void; 2010 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; 2011 | push(chunk: any, encoding?: string): boolean; 2012 | write(chunk: any, cb?: Function): boolean; 2013 | write(chunk: any, encoding?: string, cb?: Function): boolean; 2014 | end(): void; 2015 | end(chunk: any, cb?: Function): void; 2016 | end(chunk: any, encoding?: string, cb?: Function): void; 2017 | } 2018 | 2019 | export class PassThrough extends Transform {} 2020 | } 2021 | 2022 | declare module "util" { 2023 | export interface InspectOptions { 2024 | showHidden?: boolean; 2025 | depth?: number; 2026 | colors?: boolean; 2027 | customInspect?: boolean; 2028 | } 2029 | 2030 | export function format(format: any, ...param: any[]): string; 2031 | export function debug(string: string): void; 2032 | export function error(...param: any[]): void; 2033 | export function puts(...param: any[]): void; 2034 | export function print(...param: any[]): void; 2035 | export function log(string: string): void; 2036 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; 2037 | export function inspect(object: any, options: InspectOptions): string; 2038 | export function isArray(object: any): boolean; 2039 | export function isRegExp(object: any): boolean; 2040 | export function isDate(object: any): boolean; 2041 | export function isError(object: any): boolean; 2042 | export function inherits(constructor: any, superConstructor: any): void; 2043 | export function debuglog(key:string): (msg:string,...param: any[])=>void; 2044 | } 2045 | 2046 | declare module "assert" { 2047 | function internal (value: any, message?: string): void; 2048 | namespace internal { 2049 | export class AssertionError implements Error { 2050 | name: string; 2051 | message: string; 2052 | actual: any; 2053 | expected: any; 2054 | operator: string; 2055 | generatedMessage: boolean; 2056 | 2057 | constructor(options?: {message?: string; actual?: any; expected?: any; 2058 | operator?: string; stackStartFunction?: Function}); 2059 | } 2060 | 2061 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; 2062 | export function ok(value: any, message?: string): void; 2063 | export function equal(actual: any, expected: any, message?: string): void; 2064 | export function notEqual(actual: any, expected: any, message?: string): void; 2065 | export function deepEqual(actual: any, expected: any, message?: string): void; 2066 | export function notDeepEqual(acutal: any, expected: any, message?: string): void; 2067 | export function strictEqual(actual: any, expected: any, message?: string): void; 2068 | export function notStrictEqual(actual: any, expected: any, message?: string): void; 2069 | export function deepStrictEqual(actual: any, expected: any, message?: string): void; 2070 | export function notDeepStrictEqual(actual: any, expected: any, message?: string): void; 2071 | export var throws: { 2072 | (block: Function, message?: string): void; 2073 | (block: Function, error: Function, message?: string): void; 2074 | (block: Function, error: RegExp, message?: string): void; 2075 | (block: Function, error: (err: any) => boolean, message?: string): void; 2076 | }; 2077 | 2078 | export var doesNotThrow: { 2079 | (block: Function, message?: string): void; 2080 | (block: Function, error: Function, message?: string): void; 2081 | (block: Function, error: RegExp, message?: string): void; 2082 | (block: Function, error: (err: any) => boolean, message?: string): void; 2083 | }; 2084 | 2085 | export function ifError(value: any): void; 2086 | } 2087 | 2088 | export = internal; 2089 | } 2090 | 2091 | declare module "tty" { 2092 | import * as net from "net"; 2093 | 2094 | export function isatty(fd: number): boolean; 2095 | export interface ReadStream extends net.Socket { 2096 | isRaw: boolean; 2097 | setRawMode(mode: boolean): void; 2098 | isTTY: boolean; 2099 | } 2100 | export interface WriteStream extends net.Socket { 2101 | columns: number; 2102 | rows: number; 2103 | isTTY: boolean; 2104 | } 2105 | } 2106 | 2107 | declare module "domain" { 2108 | import * as events from "events"; 2109 | 2110 | export class Domain extends events.EventEmitter implements NodeJS.Domain { 2111 | run(fn: Function): void; 2112 | add(emitter: events.EventEmitter): void; 2113 | remove(emitter: events.EventEmitter): void; 2114 | bind(cb: (err: Error, data: any) => any): any; 2115 | intercept(cb: (data: any) => any): any; 2116 | dispose(): void; 2117 | } 2118 | 2119 | export function create(): Domain; 2120 | } 2121 | 2122 | declare module "constants" { 2123 | export var E2BIG: number; 2124 | export var EACCES: number; 2125 | export var EADDRINUSE: number; 2126 | export var EADDRNOTAVAIL: number; 2127 | export var EAFNOSUPPORT: number; 2128 | export var EAGAIN: number; 2129 | export var EALREADY: number; 2130 | export var EBADF: number; 2131 | export var EBADMSG: number; 2132 | export var EBUSY: number; 2133 | export var ECANCELED: number; 2134 | export var ECHILD: number; 2135 | export var ECONNABORTED: number; 2136 | export var ECONNREFUSED: number; 2137 | export var ECONNRESET: number; 2138 | export var EDEADLK: number; 2139 | export var EDESTADDRREQ: number; 2140 | export var EDOM: number; 2141 | export var EEXIST: number; 2142 | export var EFAULT: number; 2143 | export var EFBIG: number; 2144 | export var EHOSTUNREACH: number; 2145 | export var EIDRM: number; 2146 | export var EILSEQ: number; 2147 | export var EINPROGRESS: number; 2148 | export var EINTR: number; 2149 | export var EINVAL: number; 2150 | export var EIO: number; 2151 | export var EISCONN: number; 2152 | export var EISDIR: number; 2153 | export var ELOOP: number; 2154 | export var EMFILE: number; 2155 | export var EMLINK: number; 2156 | export var EMSGSIZE: number; 2157 | export var ENAMETOOLONG: number; 2158 | export var ENETDOWN: number; 2159 | export var ENETRESET: number; 2160 | export var ENETUNREACH: number; 2161 | export var ENFILE: number; 2162 | export var ENOBUFS: number; 2163 | export var ENODATA: number; 2164 | export var ENODEV: number; 2165 | export var ENOENT: number; 2166 | export var ENOEXEC: number; 2167 | export var ENOLCK: number; 2168 | export var ENOLINK: number; 2169 | export var ENOMEM: number; 2170 | export var ENOMSG: number; 2171 | export var ENOPROTOOPT: number; 2172 | export var ENOSPC: number; 2173 | export var ENOSR: number; 2174 | export var ENOSTR: number; 2175 | export var ENOSYS: number; 2176 | export var ENOTCONN: number; 2177 | export var ENOTDIR: number; 2178 | export var ENOTEMPTY: number; 2179 | export var ENOTSOCK: number; 2180 | export var ENOTSUP: number; 2181 | export var ENOTTY: number; 2182 | export var ENXIO: number; 2183 | export var EOPNOTSUPP: number; 2184 | export var EOVERFLOW: number; 2185 | export var EPERM: number; 2186 | export var EPIPE: number; 2187 | export var EPROTO: number; 2188 | export var EPROTONOSUPPORT: number; 2189 | export var EPROTOTYPE: number; 2190 | export var ERANGE: number; 2191 | export var EROFS: number; 2192 | export var ESPIPE: number; 2193 | export var ESRCH: number; 2194 | export var ETIME: number; 2195 | export var ETIMEDOUT: number; 2196 | export var ETXTBSY: number; 2197 | export var EWOULDBLOCK: number; 2198 | export var EXDEV: number; 2199 | export var WSAEINTR: number; 2200 | export var WSAEBADF: number; 2201 | export var WSAEACCES: number; 2202 | export var WSAEFAULT: number; 2203 | export var WSAEINVAL: number; 2204 | export var WSAEMFILE: number; 2205 | export var WSAEWOULDBLOCK: number; 2206 | export var WSAEINPROGRESS: number; 2207 | export var WSAEALREADY: number; 2208 | export var WSAENOTSOCK: number; 2209 | export var WSAEDESTADDRREQ: number; 2210 | export var WSAEMSGSIZE: number; 2211 | export var WSAEPROTOTYPE: number; 2212 | export var WSAENOPROTOOPT: number; 2213 | export var WSAEPROTONOSUPPORT: number; 2214 | export var WSAESOCKTNOSUPPORT: number; 2215 | export var WSAEOPNOTSUPP: number; 2216 | export var WSAEPFNOSUPPORT: number; 2217 | export var WSAEAFNOSUPPORT: number; 2218 | export var WSAEADDRINUSE: number; 2219 | export var WSAEADDRNOTAVAIL: number; 2220 | export var WSAENETDOWN: number; 2221 | export var WSAENETUNREACH: number; 2222 | export var WSAENETRESET: number; 2223 | export var WSAECONNABORTED: number; 2224 | export var WSAECONNRESET: number; 2225 | export var WSAENOBUFS: number; 2226 | export var WSAEISCONN: number; 2227 | export var WSAENOTCONN: number; 2228 | export var WSAESHUTDOWN: number; 2229 | export var WSAETOOMANYREFS: number; 2230 | export var WSAETIMEDOUT: number; 2231 | export var WSAECONNREFUSED: number; 2232 | export var WSAELOOP: number; 2233 | export var WSAENAMETOOLONG: number; 2234 | export var WSAEHOSTDOWN: number; 2235 | export var WSAEHOSTUNREACH: number; 2236 | export var WSAENOTEMPTY: number; 2237 | export var WSAEPROCLIM: number; 2238 | export var WSAEUSERS: number; 2239 | export var WSAEDQUOT: number; 2240 | export var WSAESTALE: number; 2241 | export var WSAEREMOTE: number; 2242 | export var WSASYSNOTREADY: number; 2243 | export var WSAVERNOTSUPPORTED: number; 2244 | export var WSANOTINITIALISED: number; 2245 | export var WSAEDISCON: number; 2246 | export var WSAENOMORE: number; 2247 | export var WSAECANCELLED: number; 2248 | export var WSAEINVALIDPROCTABLE: number; 2249 | export var WSAEINVALIDPROVIDER: number; 2250 | export var WSAEPROVIDERFAILEDINIT: number; 2251 | export var WSASYSCALLFAILURE: number; 2252 | export var WSASERVICE_NOT_FOUND: number; 2253 | export var WSATYPE_NOT_FOUND: number; 2254 | export var WSA_E_NO_MORE: number; 2255 | export var WSA_E_CANCELLED: number; 2256 | export var WSAEREFUSED: number; 2257 | export var SIGHUP: number; 2258 | export var SIGINT: number; 2259 | export var SIGILL: number; 2260 | export var SIGABRT: number; 2261 | export var SIGFPE: number; 2262 | export var SIGKILL: number; 2263 | export var SIGSEGV: number; 2264 | export var SIGTERM: number; 2265 | export var SIGBREAK: number; 2266 | export var SIGWINCH: number; 2267 | export var SSL_OP_ALL: number; 2268 | export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; 2269 | export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; 2270 | export var SSL_OP_CISCO_ANYCONNECT: number; 2271 | export var SSL_OP_COOKIE_EXCHANGE: number; 2272 | export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; 2273 | export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; 2274 | export var SSL_OP_EPHEMERAL_RSA: number; 2275 | export var SSL_OP_LEGACY_SERVER_CONNECT: number; 2276 | export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; 2277 | export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; 2278 | export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; 2279 | export var SSL_OP_NETSCAPE_CA_DN_BUG: number; 2280 | export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; 2281 | export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; 2282 | export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; 2283 | export var SSL_OP_NO_COMPRESSION: number; 2284 | export var SSL_OP_NO_QUERY_MTU: number; 2285 | export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; 2286 | export var SSL_OP_NO_SSLv2: number; 2287 | export var SSL_OP_NO_SSLv3: number; 2288 | export var SSL_OP_NO_TICKET: number; 2289 | export var SSL_OP_NO_TLSv1: number; 2290 | export var SSL_OP_NO_TLSv1_1: number; 2291 | export var SSL_OP_NO_TLSv1_2: number; 2292 | export var SSL_OP_PKCS1_CHECK_1: number; 2293 | export var SSL_OP_PKCS1_CHECK_2: number; 2294 | export var SSL_OP_SINGLE_DH_USE: number; 2295 | export var SSL_OP_SINGLE_ECDH_USE: number; 2296 | export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; 2297 | export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; 2298 | export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; 2299 | export var SSL_OP_TLS_D5_BUG: number; 2300 | export var SSL_OP_TLS_ROLLBACK_BUG: number; 2301 | export var ENGINE_METHOD_DSA: number; 2302 | export var ENGINE_METHOD_DH: number; 2303 | export var ENGINE_METHOD_RAND: number; 2304 | export var ENGINE_METHOD_ECDH: number; 2305 | export var ENGINE_METHOD_ECDSA: number; 2306 | export var ENGINE_METHOD_CIPHERS: number; 2307 | export var ENGINE_METHOD_DIGESTS: number; 2308 | export var ENGINE_METHOD_STORE: number; 2309 | export var ENGINE_METHOD_PKEY_METHS: number; 2310 | export var ENGINE_METHOD_PKEY_ASN1_METHS: number; 2311 | export var ENGINE_METHOD_ALL: number; 2312 | export var ENGINE_METHOD_NONE: number; 2313 | export var DH_CHECK_P_NOT_SAFE_PRIME: number; 2314 | export var DH_CHECK_P_NOT_PRIME: number; 2315 | export var DH_UNABLE_TO_CHECK_GENERATOR: number; 2316 | export var DH_NOT_SUITABLE_GENERATOR: number; 2317 | export var NPN_ENABLED: number; 2318 | export var RSA_PKCS1_PADDING: number; 2319 | export var RSA_SSLV23_PADDING: number; 2320 | export var RSA_NO_PADDING: number; 2321 | export var RSA_PKCS1_OAEP_PADDING: number; 2322 | export var RSA_X931_PADDING: number; 2323 | export var RSA_PKCS1_PSS_PADDING: number; 2324 | export var POINT_CONVERSION_COMPRESSED: number; 2325 | export var POINT_CONVERSION_UNCOMPRESSED: number; 2326 | export var POINT_CONVERSION_HYBRID: number; 2327 | export var O_RDONLY: number; 2328 | export var O_WRONLY: number; 2329 | export var O_RDWR: number; 2330 | export var S_IFMT: number; 2331 | export var S_IFREG: number; 2332 | export var S_IFDIR: number; 2333 | export var S_IFCHR: number; 2334 | export var S_IFLNK: number; 2335 | export var O_CREAT: number; 2336 | export var O_EXCL: number; 2337 | export var O_TRUNC: number; 2338 | export var O_APPEND: number; 2339 | export var F_OK: number; 2340 | export var R_OK: number; 2341 | export var W_OK: number; 2342 | export var X_OK: number; 2343 | export var UV_UDP_REUSEADDR: number; 2344 | } 2345 | --------------------------------------------------------------------------------