├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── gulpfile.js
├── package.json
├── src
└── index.ts
├── test
├── index.ts
└── swaggers
│ └── minimal.json
├── tsconfig.json
└── typings
├── form-data
└── form-data.d.ts
├── gulp
└── gulp.d.ts
├── lodash
└── lodash.d.ts
├── mocha
└── mocha.d.ts
├── node
└── node.d.ts
├── request
└── request.d.ts
└── z-schema
└── z-schema.d.ts
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Linux
3 | ################################################################################
4 | *~
5 |
6 | # KDE directory preferences
7 | .directory
8 |
9 | # Linux trash folder which might appear on any partition or disk
10 | .Trash-*
11 |
12 | ################################################################################
13 | # OS X
14 | ################################################################################
15 | .DS_Store
16 | .AppleDouble
17 | .LSOverride
18 |
19 | # Icon must end with two \r
20 | Icon
21 |
22 |
23 | # Thumbnails
24 | ._*
25 |
26 | # Files that might appear in the root of a volume
27 | .DocumentRevisions-V100
28 | .fseventsd
29 | .Spotlight-V100
30 | .TemporaryItems
31 | .Trashes
32 | .VolumeIcon.icns
33 |
34 | # Directories potentially created on remote AFP share
35 | .AppleDB
36 | .AppleDesktop
37 | Network Trash Folder
38 | Temporary Items
39 | .apdisk
40 |
41 | ################################################################################
42 | # Node.js
43 | ################################################################################
44 | # Logs
45 | logs
46 | *.log
47 |
48 | # Runtime data
49 | pids
50 | *.pid
51 | *.seed
52 |
53 | # Directory for instrumented libs generated by jscoverage/JSCover
54 | lib-cov
55 |
56 | # Coverage directory used by tools like istanbul
57 | coverage
58 |
59 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
60 | .grunt
61 |
62 | # node-waf configuration
63 | .lock-wscript
64 |
65 | # Compiled binary addons (http://nodejs.org/api/addons.html)
66 | build/Release
67 |
68 | # Dependency directory
69 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
70 | node_modules
71 |
72 | ################################################################################
73 | # Swagger Testing (this project)
74 | ################################################################################
75 | build
76 | .idea
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | he MIT License (MIT)
2 |
3 | Copyright (c) 2015 Apigee Corporation
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swagger Testing
2 |
3 | > Automated RESTful API Testing Using [SwaggerAPI](http://swagger.io)
4 |
5 | ### Note: This project is under development and is not ready yet.
6 |
7 | ### Installation
8 | ```
9 | npm install swagger-testing
10 | ```
11 |
12 | ### Usage
13 |
14 | #### Independent
15 |
16 | ```js
17 | var SwaggerTesting = require('swagger-testing');
18 | var swaggerSpec = require('./swagger.json');
19 |
20 | var swagger = new SwaggerTesting(swaggerSpec);
21 |
22 | swagger.testOperation({path: '/pet', operation: 'GET'}, function (err) {
23 | if (!err) {
24 | console.log('Successfully tested GET /pet');
25 | }
26 | });
27 |
28 | swagger.testCRUD('/user', '/pet', function (err) {
29 | if (!err) {
30 | console.log('All CRUD operations for all objects in my API are tested successfully.');
31 | }
32 | });
33 | ```
34 |
35 | #### In Mocha/Jasmine tests
36 |
37 | Use `SwaggerTesting` in your [Mocha](https://github.com/mochajs/mocha) tests:
38 |
39 | ```js
40 | var SwaggerTesting = require('swagger-testing');
41 | var swaggerSpec = require('./swagger.json');
42 |
43 | var swagger = new SwaggerTesting(swaggerSpec);
44 |
45 | // Automatically test all models
46 | describe('My API', function() {
47 | it ('tests all objects CRUD operations', function(done){
48 | swagger.testCRUD('/user', '/pet', done);
49 | });
50 | });
51 |
52 | ```
53 |
54 | ### API
55 |
56 | ```js
57 | // Automatically test all models
58 | swagger.testCRUD('/user', '/pet');
59 | ```
60 |
61 | ```js
62 | // Automatically test CRUD resources
63 | swagger.testCRUD('/user');
64 | ```
65 |
66 | ```js
67 | // Test all non mutating paths
68 | swagger.testAllOperations('GET');
69 | ```
70 |
71 | ```js
72 | // Test a specific operation
73 | swagger.testOperation({
74 | path: '/pet',
75 | operation: 'PUT',
76 | data: pet
77 | });
78 | ```
79 |
80 | ### A complex flow
81 |
82 | ```js
83 | describe('CRUD Pet (Manual)', function() {
84 | var pet = null;
85 |
86 | it('Creates a Pet object', function(done) {
87 | swagger.testOperation({path: '/pet', operation: 'POST'}, function(err, result) {
88 | pet = result;
89 | done();
90 | });
91 | });
92 |
93 | it('Reads the created Pet object', function(done) {
94 | swagger.testOperation({path: '/pet/' + pet.id, operation: 'GET'}, done);
95 | });
96 |
97 | it('Updates the created Pet object', function(done) {
98 | pet.name = Math.random().toString(36);
99 |
100 | swagger.testOperation({
101 | path: '/pet',
102 | operation: 'PUT',
103 | data: pet
104 | }, done);
105 | });
106 |
107 | it('Deletes the created Pet object', function(done) {
108 | swagger.testOperation({path: '/pet/' + pet.id, operation: 'DELETE'}, done);
109 | });
110 | });
111 |
112 | ```
113 |
114 | ### Development
115 |
116 | To make a new build
117 |
118 | ```shell
119 | npm run build
120 | ```
121 |
122 | To run the test
123 |
124 | ```shell
125 | npm test
126 | ```
127 |
128 | ### License
129 |
130 | [MIT](./LICENSE)
131 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | var gulp = require('gulp');
5 | var tsc = require('gulp-tsc');
6 | var mocha = require('gulp-mocha');
7 | var typescriptCompilerOptions = require('./tsconfig.json').compilerOptions;
8 |
9 | gulp.task('test', ['default', 'copy'], function() {
10 | return gulp.src('build/test/index.js', {read: false})
11 | .pipe(mocha());
12 | });
13 |
14 | gulp.task('copy', function() {
15 | return gulp.src(['test/swaggers/*.json'])
16 | .pipe(gulp.dest('build/test/swaggers'));
17 | });
18 |
19 | gulp.task('default', function() {
20 | return gulp.src([
21 | 'src/**/*.ts',
22 | 'test/**/*.ts'
23 | ])
24 | .pipe(tsc(typescriptCompilerOptions))
25 | .pipe(gulp.dest('build/'));
26 | });
27 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "swagger-testing",
3 | "version": "0.0.0",
4 | "description": "Automated REST API Testing Using SwaggerAPI",
5 | "main": "build/index.js",
6 | "scripts": {
7 | "prebuild": "npm install",
8 | "pretest": "npm install",
9 | "build": "gulp",
10 | "test": "gulp test"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/apigee-127/swagger-testing.git"
15 | },
16 | "keywords": [
17 | "Swagger",
18 | "API",
19 | "SwaggerAPI",
20 | "Test"
21 | ],
22 | "author": "Mohsen Azimi ",
23 | "license": "MIT",
24 | "bugs": {
25 | "url": "https://github.com/apigee-127/swagger-testing/issues"
26 | },
27 | "homepage": "https://github.com/apigee-127/swagger-testing#readme",
28 | "devDependencies": {
29 | "chai": "^3.0.0",
30 | "gulp": "^3.9.0",
31 | "gulp-mocha": "^2.1.1",
32 | "gulp-tsc": "^0.10.1",
33 | "request": "^2.58.0",
34 | "rewire": "^2.3.4",
35 | "sinon": "^1.15.3",
36 | "sinon-chai": "^2.8.0",
37 | "swagger.d.ts": "0.0.2",
38 | "typescript": "1.4.1"
39 | },
40 | "dependencies": {
41 | "lodash": "^3.9.3",
42 | "swagger-core-api": "apigee-127/swagger-core-api",
43 | "z-schema": "^3.12.0"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 |
7 | // TODO: move to it's own file
8 | module SwaggerTestingModule {
9 | export declare class Error {
10 | public name: string;
11 | public message: string;
12 | public stack: string;
13 | constructor(message?: string);
14 | }
15 |
16 | export class SwaggerTestingError extends Error {
17 | constructor(public message: string) {
18 | super(message);
19 | this.name = 'SwaggerTestingError';
20 | this.message = message;
21 | this.stack = (new Error()).stack;
22 | }
23 |
24 | toString() {
25 | return `${this.name}: ${this.message}`;
26 | }
27 | }
28 | }
29 |
30 | module SwaggerTestingModule {
31 | var request = require('request');
32 | var _ = require('lodash');
33 | var ZSchema = require('z-schema');
34 |
35 | var JSONSchema = new ZSchema();
36 |
37 | type Callback = (error?: Error)=>void
38 |
39 | interface BasicAuthValue {
40 | username: string;
41 | password: string;
42 | }
43 |
44 | interface SwaggerTestingOptions {
45 | auth?: BasicAuthValue; /*| APIKeyAuthValue | OAuthAuthValue */
46 | baseUrl?: string; // to use a different host for testing
47 | }
48 |
49 | interface TestOperationConfig {
50 | operationPath: string;
51 | operationName: string;
52 | }
53 |
54 | var OPERAION_NAMES = ['get', 'post', 'put', 'patch', 'delete', 'head'];
55 |
56 | class SwaggerTesting {
57 | options: SwaggerTestingOptions;
58 | swagger: Swagger.Spec;
59 |
60 | constructor(swagger: Swagger.Spec, options: SwaggerTestingOptions = {}) {
61 | if (!swagger || !_.isObject(swagger)) {
62 | throw new TypeError('swagger must be an object.');
63 | }
64 | this.swagger = swagger;
65 | this.options = options;
66 | }
67 |
68 | private get baseUrl(): string {
69 | // TODO: complete me
70 | return this.options.baseUrl ||
71 | 'http://' + (this.swagger.host || 'localhost') + (this.swagger.basePath || '/');
72 | }
73 |
74 | /*
75 | *
76 | * @throws TypeError
77 | */
78 | testOperation(config: TestOperationConfig, cb: Callback = noop) {
79 |
80 | if (!config || !_.isObject(config)) {
81 | throw new TypeError('config should be an object.');
82 | }
83 |
84 | if (!_.isString(config.operationName)) {
85 | throw new TypeError('operationName should be a string.');
86 | }
87 |
88 | if (!_.isString(config.operationPath)) {
89 | throw new TypeError('operationPath should be a string.');
90 | }
91 |
92 | var operationName = config.operationName.toLowerCase();
93 |
94 | if (!_.contains(OPERAION_NAMES, operationName)) {
95 | throw new TypeError(`operationName should be one of ${OPERAION_NAMES.join(' ')}`);
96 | }
97 |
98 | request[operationName](this.baseUrl, (error, response, body) => {
99 | if (error) { return cb(error); }
100 |
101 | // TODO: guard against all sort of things that can go wrong here
102 | var schema = this.swagger.paths[config.operationPath][operationName]
103 | .responses[200].schema;
104 |
105 | var isValid = JSONSchema.validate(body, schema);
106 |
107 | if (!isValid) {
108 | cb(new SwaggerTestingError(`response is not conforming to schema.
109 | operation: ${config.operationName}
110 | path: ${config.operationPath}
111 | response: 200
112 | `));
113 | } else {
114 | cb(null);
115 | }
116 | });
117 | }
118 |
119 | /*
120 | *
121 | */
122 | testAllOperations(operationName: string, cb: Callback = noop) {
123 | throw new Error('Not implemented');
124 | }
125 | }
126 |
127 | function noop(): void {}
128 |
129 | module.exports = SwaggerTesting;
130 | }
131 |
--------------------------------------------------------------------------------
/test/index.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 |
5 | var rewire = require('rewire');
6 | var request = require('request');
7 | var sinon = require('sinon');
8 | var sinonChai = require("sinon-chai");
9 | var chai = require('chai');
10 |
11 | chai.use(sinonChai);
12 | var expect = chai.expect;
13 |
14 | var SwaggerTesting = rewire('../src/index.js');
15 |
16 | SwaggerTesting.__set__({
17 | request: {
18 | get: sinon.spy()
19 | }
20 | })
21 |
22 | type Callback = (err?: Error) => void;
23 |
24 | describe('SwaggerTesting constructor', ()=> {
25 | it('throws if swagger argument is not provided', ()=> {
26 | expect(SwaggerTesting).to.throw(TypeError);
27 | expect(SwaggerTesting.bind(null, 42)).to.throw(TypeError);
28 | });
29 |
30 | xit('TODO: throws if swagger is invalid', ()=> {
31 | expect(SwaggerTesting.bind(null, {})).to.throw(TypeError);
32 | });
33 | });
34 |
35 | describe('Specs', ()=> {
36 | describe('minimal', function() {
37 | var swaggerSpec = require('./swaggers/minimal.json');
38 |
39 | var swagger = new SwaggerTesting(swaggerSpec);
40 |
41 | describe('#testOperation', ()=> {
42 | describe('Makes a GET call to "/" path', ()=> {
43 | it('works when server reponds with correct response', ()=> {
44 | sinon.stub(request, 'get')
45 | .yields(null, null, 'Hello, World!');
46 | var callbackFn = sinon.spy();
47 |
48 | swagger.testOperation({operationPath: '/', operationName: 'GET'}, callbackFn);
49 |
50 | // we only care about the URL in this assertion
51 | expect(request.get).to.have.been.calledWithMatch('http://localhost/');
52 | expect(callbackFn).to.have.been.calledWith(null);
53 |
54 | request.get.restore();
55 | });
56 |
57 | it('fails when server responds with incorrect response', ()=> {
58 | sinon.stub(request, 'get')
59 | .yields(null, null, 42);
60 | var callbackFn = sinon.spy();
61 |
62 | swagger.testOperation({operationPath: '/', operationName: 'GET'}, callbackFn);
63 |
64 | // we only care about the URL in this assertion
65 | expect(request.get).to.have.been.calledWithMatch('http://localhost/');
66 | expect(callbackFn).to.have.been.calledWithMatch(Error);
67 |
68 | request.get.restore();
69 | });
70 | });
71 | });
72 |
73 | xdescribe('TODO: #testAllOperations', ()=> {
74 | it('throws for mutating operations', ()=> {
75 |
76 | });
77 |
78 | it('Makes a GET call to "/" path when testAllOperations("get") is called', ()=> {
79 |
80 | });
81 | });
82 | });
83 | });
84 |
--------------------------------------------------------------------------------
/test/swaggers/minimal.json:
--------------------------------------------------------------------------------
1 | {
2 | "swagger": "2.0",
3 | "info": {
4 | "version": "0.0.0",
5 | "title": "Simple API"
6 | },
7 | "paths": {
8 | "/": {
9 | "get": {
10 | "responses": {
11 | "200": {
12 | "description": "OK",
13 | "schema": {
14 | "type": "string"
15 | }
16 | }
17 | }
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "exclude": ["node_modules/**/*", "build"],
3 | "compilerOptions": {
4 | "module": "commonjs",
5 | "sourceRoot": "../..",
6 | "outDir": "build",
7 | "sourceRoot": "src",
8 | "sourceMap": true,
9 | "watch": true,
10 | "target": "es5"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/typings/form-data/form-data.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for form-data
2 | // Project: https://github.com/felixge/node-form-data
3 | // Definitions by: Carlos Ballesteros Velasco
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/form-data.d.ts
7 |
8 | declare module "form-data" {
9 | export class FormData {
10 | append(key: string, value: any): FormData;
11 | getHeaders(): Object;
12 | // TODO expand pipe
13 | pipe(to: any): any;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/typings/gulp/gulp.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for Gulp v3.8.x
2 | // Project: http://gulpjs.com
3 | // Definitions by: Drew Noakes
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | ///
7 |
8 | declare module gulp {
9 |
10 | /**
11 | * Options to pass to node-glob through glob-stream.
12 | * Specifies two options in addition to those used by node-glob:
13 | * https://github.com/isaacs/node-glob#options
14 | */
15 | interface ISrcOptions {
16 | /**
17 | * Setting this to false
will return file.contents
as null
18 | * and not read the file at all.
19 | * Default: true
.
20 | */
21 | read?: boolean;
22 |
23 | /**
24 | * Setting this to false will return file.contents
as a stream and not buffer files.
25 | * This is useful when working with large files.
26 | * Note: Plugins might not implement support for streams.
27 | * Default: true
.
28 | */
29 | buffer?: boolean;
30 |
31 | /**
32 | * The current working directory in which to search.
33 | * Defaults to process.cwd().
34 | */
35 | cwd?: string;
36 |
37 | /**
38 | * The place where patterns starting with / will be mounted onto.
39 | * Defaults to path.resolve(options.cwd, "/") (/ on Unix systems, and C:\ or some such on Windows.)
40 | */
41 | root?: string;
42 |
43 | /**
44 | * Include .dot files in normal matches and globstar matches.
45 | * Note that an explicit dot in a portion of the pattern will always match dot files.
46 | */
47 | dot?: boolean;
48 |
49 | /**
50 | * By default, a pattern starting with a forward-slash will be "mounted" onto the root setting, so that a valid
51 | * filesystem path is returned. Set this flag to disable that behavior.
52 | */
53 | nomount?: boolean;
54 |
55 | /**
56 | * Add a / character to directory matches. Note that this requires additional stat calls.
57 | */
58 | mark?: boolean;
59 |
60 | /**
61 | * Don't sort the results.
62 | */
63 | nosort?: boolean;
64 |
65 | /**
66 | * Set to true to stat all results. This reduces performance somewhat, and is completely unnecessary, unless
67 | * readdir is presumed to be an untrustworthy indicator of file existence. It will cause ELOOP to be triggered one
68 | * level sooner in the case of cyclical symbolic links.
69 | */
70 | stat?: boolean;
71 |
72 | /**
73 | * When an unusual error is encountered when attempting to read a directory, a warning will be printed to stderr.
74 | * Set the silent option to true to suppress these warnings.
75 | */
76 | silent?: boolean;
77 |
78 | /**
79 | * When an unusual error is encountered when attempting to read a directory, the process will just continue on in
80 | * search of other matches. Set the strict option to raise an error in these cases.
81 | */
82 | strict?: boolean;
83 |
84 | /**
85 | * See cache property above. Pass in a previously generated cache object to save some fs calls.
86 | */
87 | cache?: boolean;
88 |
89 | /**
90 | * A cache of results of filesystem information, to prevent unnecessary stat calls.
91 | * While it should not normally be necessary to set this, you may pass the statCache from one glob() call to the
92 | * options object of another, if you know that the filesystem will not change between calls.
93 | */
94 | statCache?: boolean;
95 |
96 | /**
97 | * Perform a synchronous glob search.
98 | */
99 | sync?: boolean;
100 |
101 | /**
102 | * In some cases, brace-expanded patterns can result in the same file showing up multiple times in the result set.
103 | * By default, this implementation prevents duplicates in the result set. Set this flag to disable that behavior.
104 | */
105 | nounique?: boolean;
106 |
107 | /**
108 | * Set to never return an empty set, instead returning a set containing the pattern itself.
109 | * This is the default in glob(3).
110 | */
111 | nonull?: boolean;
112 |
113 | /**
114 | * Perform a case-insensitive match. Note that case-insensitive filesystems will sometimes result in glob returning
115 | * results that are case-insensitively matched anyway, since readdir and stat will not raise an error.
116 | */
117 | nocase?: boolean;
118 |
119 | /**
120 | * Set to enable debug logging in minimatch and glob.
121 | */
122 | debug?: boolean;
123 |
124 | /**
125 | * Set to enable debug logging in glob, but not minimatch.
126 | */
127 | globDebug?: boolean;
128 | }
129 |
130 | interface IDestOptions {
131 | /**
132 | * The output folder. Only has an effect if provided output folder is relative.
133 | * Default: process.cwd()
134 | */
135 | cwd?: string;
136 |
137 | /**
138 | * Octal permission string specifying mode for any folders that need to be created for output folder.
139 | * Default: 0777.
140 | */
141 | mode?: string;
142 | }
143 |
144 | /**
145 | * Options that are passed to gaze
.
146 | * https://github.com/shama/gaze
147 | */
148 | interface IWatchOptions {
149 | /** Interval to pass to fs.watchFile. */
150 | interval?: number;
151 | /** Delay for events called in succession for the same file/event. */
152 | debounceDelay?: number;
153 | /** Force the watch mode. Either 'auto' (default), 'watch' (force native events), or 'poll' (force stat polling). */
154 | mode?: string;
155 | /** The current working directory to base file patterns from. Default is process.cwd().. */
156 | cwd?: string;
157 | }
158 |
159 | interface IWatchEvent {
160 | /** The type of change that occurred, either added, changed or deleted. */
161 | type: string;
162 | /** The path to the file that triggered the event. */
163 | path: string;
164 | }
165 |
166 | /**
167 | * Callback to be called on each watched file change.
168 | */
169 | interface IWatchCallback {
170 | (event:IWatchEvent): void;
171 | }
172 |
173 | interface ITaskCallback {
174 | /**
175 | * Defines a task.
176 | * Tasks may be made asynchronous if they are passing a callback or return a promise or a stream.
177 | * @param cb callback used to signal asynchronous completion. Caller includes err
in case of error.
178 | */
179 | (cb?:(err?:any)=>void): any;
180 | }
181 |
182 | interface EventEmitter {
183 | any: any;
184 | }
185 |
186 | interface Gulp {
187 | /**
188 | * Define a task.
189 | *
190 | * @param name the name of the task. Tasks that you want to run from the command line should not have spaces in them.
191 | * @param fn the function that performs the task's operations. Generally this takes the form of gulp.src().pipe(someplugin()).
192 | */
193 | task(name:string, fn:ITaskCallback): any;
194 |
195 | /**
196 | * Define a task.
197 | *
198 | * @param name the name of the task. Tasks that you want to run from the command line should not have spaces in them.
199 | * @param dep an array of tasks to be executed and completed before your task will run.
200 | * @param fn the function that performs the task's operations. Generally this takes the form of gulp.src().pipe(someplugin()).
201 | */
202 | task(name:string, dep:string[], fn?:ITaskCallback): any;
203 |
204 |
205 | /**
206 | * Takes a glob and represents a file structure. Can be piped to plugins.
207 | * @param glob a glob string, using node-glob syntax
208 | * @param opt an optional option object
209 | */
210 | src(glob:string, opt?:ISrcOptions): NodeJS.ReadWriteStream;
211 |
212 | /**
213 | * Takes a glob and represents a file structure. Can be piped to plugins.
214 | * @param glob an array of glob strings, using node-glob syntax
215 | * @param opt an optional option object
216 | */
217 | src(glob:string[], opt?:ISrcOptions): NodeJS.ReadWriteStream;
218 |
219 |
220 | /**
221 | * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
222 | * Folders that don't exist will be created.
223 | *
224 | * @param outFolder the path (output folder) to write files to.
225 | * @param opt
226 | */
227 | dest(outFolder:string, opt?:IDestOptions): NodeJS.ReadWriteStream;
228 |
229 | /**
230 | * Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.
231 | * Folders that don't exist will be created.
232 | *
233 | * @param outFolder a function that converts a vinyl File instance into an output path
234 | * @param opt
235 | */
236 | dest(outFolder:(file:string)=>string, opt?:IDestOptions): NodeJS.ReadWriteStream;
237 |
238 |
239 | /**
240 | * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
241 | *
242 | * @param glob a single glob or array of globs that indicate which files to watch for changes.
243 | * @param tasks names of task(s) to run when a file changes, added with gulp.task()
244 | */
245 | watch(glob:string, tasks:string[]): EventEmitter;
246 | watch(glob:string[], tasks:string[]): EventEmitter;
247 |
248 | /**
249 | * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
250 | *
251 | * @param glob a single glob or array of globs that indicate which files to watch for changes.
252 | * @param opt options, that are passed to the gaze library.
253 | * @param tasks names of task(s) to run when a file changes, added with gulp.task()
254 | */
255 | watch(glob:string, opt:IWatchOptions, tasks:string[]): EventEmitter;
256 | watch(glob:string[], opt:IWatchOptions, tasks:string[]): EventEmitter;
257 |
258 | /**
259 | * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
260 | *
261 | * @param glob a single glob or array of globs that indicate which files to watch for changes.
262 | * @param fn a callback or array of callbacks to be called on each change.
263 | */
264 | watch(glob:string, fn:IWatchCallback): EventEmitter;
265 | watch(glob:string[], fn:IWatchCallback): EventEmitter;
266 | watch(glob:string, fn:IWatchCallback[]): EventEmitter;
267 | watch(glob:string[], fn:IWatchCallback[]): EventEmitter;
268 |
269 | /**
270 | * Watch files and do something when a file changes. This always returns an EventEmitter that emits change events.
271 | *
272 | * @param glob a single glob or array of globs that indicate which files to watch for changes.
273 | * @param opt options, that are passed to the gaze library.
274 | * @param fn a callback or array of callbacks to be called on each change.
275 | */
276 | watch(glob:string, opt:IWatchOptions, fn:IWatchCallback): EventEmitter;
277 | watch(glob:string, opt:IWatchOptions, fn:IWatchCallback[]): EventEmitter;
278 | }
279 | }
280 |
281 | declare module "gulp" {
282 | var _tmp:gulp.Gulp;
283 | export = _tmp;
284 | }
285 |
286 | interface IGulpPlugin {
287 | (...args: any[]): NodeJS.ReadWriteStream;
288 | }
289 |
--------------------------------------------------------------------------------
/typings/mocha/mocha.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for mocha 2.0.1
2 | // Project: http://mochajs.org/
3 | // Definitions by: Kazi Manzur Rashid , otiai10 , jt000
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | interface Mocha {
7 | // Setup mocha with the given setting options.
8 | setup(options: MochaSetupOptions): Mocha;
9 |
10 | //Run tests and invoke `fn()` when complete.
11 | run(callback?: () => void): void;
12 |
13 | // Set reporter as function
14 | reporter(reporter: () => void): Mocha;
15 |
16 | // Set reporter, defaults to "dot"
17 | reporter(reporter: string): Mocha;
18 |
19 | // Enable growl support.
20 | growl(): Mocha
21 | }
22 |
23 | interface MochaSetupOptions {
24 | //milliseconds to wait before considering a test slow
25 | slow?: number;
26 |
27 | // timeout in milliseconds
28 | timeout?: number;
29 |
30 | // ui name "bdd", "tdd", "exports" etc
31 | ui?: string;
32 |
33 | //array of accepted globals
34 | globals?: any[];
35 |
36 | // reporter instance (function or string), defaults to `mocha.reporters.Dot`
37 | reporter?: any;
38 |
39 | // bail on the first test failure
40 | bail?: boolean;
41 |
42 | // ignore global leaks
43 | ignoreLeaks?: boolean;
44 |
45 | // grep string or regexp to filter tests with
46 | grep?: any;
47 | }
48 |
49 | interface MochaDone {
50 | (error?: Error): void;
51 | }
52 |
53 | declare var mocha: Mocha;
54 |
55 | declare var describe: {
56 | (description: string, spec: () => void): void;
57 | only(description: string, spec: () => void): void;
58 | skip(description: string, spec: () => void): void;
59 | timeout(ms: number): void;
60 | }
61 |
62 | declare var xdescribe: {
63 | (description: string, spec: () => void): void;
64 | only(description: string, spec: () => void): void;
65 | skip(description: string, spec: () => void): void;
66 | timeout(ms: number): void;
67 | }
68 |
69 |
70 | // alias for `describe`
71 | declare var context: {
72 | (contextTitle: string, spec: () => void): void;
73 | only(contextTitle: string, spec: () => void): void;
74 | skip(contextTitle: string, spec: () => void): void;
75 | timeout(ms: number): void;
76 | };
77 |
78 | // alias for `describe`
79 | declare var suite: {
80 | (suiteTitle: string, spec: () => void): void;
81 | only(suiteTitle: string, spec: () => void): void;
82 | skip(suiteTitle: string, spec: () => void): void;
83 | timeout(ms: number): void;
84 | };
85 |
86 | declare var it: {
87 | (expectation: string, assertion?: () => void): void;
88 | (expectation: string, assertion?: (done: MochaDone) => void): void;
89 | only(expectation: string, assertion?: () => void): void;
90 | only(expectation: string, assertion?: (done: MochaDone) => void): void;
91 | skip(expectation: string, assertion?: () => void): void;
92 | skip(expectation: string, assertion?: (done: MochaDone) => void): void;
93 | timeout(ms: number): void;
94 | };
95 |
96 | declare var xit: {
97 | (expectation: string, assertion?: () => void): void;
98 | (expectation: string, assertion?: (done: MochaDone) => void): void;
99 | only(expectation: string, assertion?: () => void): void;
100 | only(expectation: string, assertion?: (done: MochaDone) => void): void;
101 | skip(expectation: string, assertion?: () => void): void;
102 | skip(expectation: string, assertion?: (done: MochaDone) => void): void;
103 | timeout(ms: number): void;
104 | };
105 |
106 | // alias for `it`
107 | declare var test: {
108 | (expectation: string, assertion?: () => void): void;
109 | (expectation: string, assertion?: (done: MochaDone) => void): void;
110 | only(expectation: string, assertion?: () => void): void;
111 | only(expectation: string, assertion?: (done: MochaDone) => void): void;
112 | skip(expectation: string, assertion?: () => void): void;
113 | skip(expectation: string, assertion?: (done: MochaDone) => void): void;
114 | timeout(ms: number): void;
115 | };
116 |
117 | declare function before(action: () => void): void;
118 |
119 | declare function before(action: (done: MochaDone) => void): void;
120 |
121 | declare function setup(action: () => void): void;
122 |
123 | declare function setup(action: (done: MochaDone) => void): void;
124 |
125 | declare function after(action: () => void): void;
126 |
127 | declare function after(action: (done: MochaDone) => void): void;
128 |
129 | declare function teardown(action: () => void): void;
130 |
131 | declare function teardown(action: (done: MochaDone) => void): void;
132 |
133 | declare function beforeEach(action: () => void): void;
134 |
135 | declare function beforeEach(action: (done: MochaDone) => void): void;
136 |
137 | declare function suiteSetup(action: () => void): void;
138 |
139 | declare function suiteSetup(action: (done: MochaDone) => void): void;
140 |
141 | declare function afterEach(action: () => void): void;
142 |
143 | declare function afterEach(action: (done: MochaDone) => void): void;
144 |
145 | declare function suiteTeardown(action: () => void): void;
146 |
147 | declare function suiteTeardown(action: (done: MochaDone) => void): void;
148 |
149 | declare module "mocha" {
150 |
151 | class Mocha {
152 | constructor(options?: {
153 | grep?: RegExp;
154 | ui?: string;
155 | reporter?: string;
156 | timeout?: number;
157 | bail?: boolean;
158 | });
159 |
160 | bail(value?: boolean): Mocha;
161 | addFile(file: string): Mocha;
162 | reporter(value: string): Mocha;
163 | ui(value: string): Mocha;
164 | grep(value: string): Mocha;
165 | grep(value: RegExp): Mocha;
166 | invert(): Mocha;
167 | ignoreLeaks(value: boolean): Mocha;
168 | checkLeaks(): Mocha;
169 | growl(): Mocha;
170 | globals(value: string): Mocha;
171 | globals(values: string[]): Mocha;
172 | useColors(value: boolean): Mocha;
173 | useInlineDiffs(value: boolean): Mocha;
174 | timeout(value: number): Mocha;
175 | slow(value: number): Mocha;
176 | enableTimeouts(value: boolean): Mocha;
177 | asyncOnly(value: boolean): Mocha;
178 | noHighlighting(value: boolean): Mocha;
179 |
180 | run(onComplete?: (failures: number) => void): void;
181 | }
182 |
183 | export = Mocha;
184 | }
185 |
--------------------------------------------------------------------------------
/typings/node/node.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for Node.js v0.12.0
2 | // Project: http://nodejs.org/
3 | // Definitions by: Microsoft TypeScript , DefinitelyTyped
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | /************************************************
7 | * *
8 | * Node.js v0.12.0 API *
9 | * *
10 | ************************************************/
11 |
12 | /************************************************
13 | * *
14 | * GLOBAL *
15 | * *
16 | ************************************************/
17 | declare var process: NodeJS.Process;
18 | declare var global: NodeJS.Global;
19 |
20 | declare var __filename: string;
21 | declare var __dirname: string;
22 |
23 | declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer;
24 | declare function clearTimeout(timeoutId: NodeJS.Timer): void;
25 | declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer;
26 | declare function clearInterval(intervalId: NodeJS.Timer): void;
27 | declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any;
28 | declare function clearImmediate(immediateId: any): void;
29 |
30 | declare var require: {
31 | (id: string): any;
32 | resolve(id:string): string;
33 | cache: any;
34 | extensions: any;
35 | main: any;
36 | };
37 |
38 | declare var module: {
39 | exports: any;
40 | require(id: string): any;
41 | id: string;
42 | filename: string;
43 | loaded: boolean;
44 | parent: any;
45 | children: any[];
46 | };
47 |
48 | // Same as module.exports
49 | declare var exports: any;
50 | declare var SlowBuffer: {
51 | new (str: string, encoding?: string): Buffer;
52 | new (size: number): Buffer;
53 | new (size: Uint8Array): Buffer;
54 | new (array: any[]): Buffer;
55 | prototype: Buffer;
56 | isBuffer(obj: any): boolean;
57 | byteLength(string: string, encoding?: string): number;
58 | concat(list: Buffer[], totalLength?: number): Buffer;
59 | };
60 |
61 |
62 | // Buffer class
63 | interface Buffer extends NodeBuffer {}
64 |
65 | /**
66 | * Raw data is stored in instances of the Buffer class.
67 | * 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.
68 | * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
69 | */
70 | declare var Buffer: {
71 | /**
72 | * Allocates a new buffer containing the given {str}.
73 | *
74 | * @param str String to store in buffer.
75 | * @param encoding encoding to use, optional. Default is 'utf8'
76 | */
77 | new (str: string, encoding?: string): Buffer;
78 | /**
79 | * Allocates a new buffer of {size} octets.
80 | *
81 | * @param size count of octets to allocate.
82 | */
83 | new (size: number): Buffer;
84 | /**
85 | * Allocates a new buffer containing the given {array} of octets.
86 | *
87 | * @param array The octets to store.
88 | */
89 | new (array: Uint8Array): Buffer;
90 | /**
91 | * Allocates a new buffer containing the given {array} of octets.
92 | *
93 | * @param array The octets to store.
94 | */
95 | new (array: any[]): Buffer;
96 | prototype: Buffer;
97 | /**
98 | * Returns true if {obj} is a Buffer
99 | *
100 | * @param obj object to test.
101 | */
102 | isBuffer(obj: any): boolean;
103 | /**
104 | * Returns true if {encoding} is a valid encoding argument.
105 | * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
106 | *
107 | * @param encoding string to test.
108 | */
109 | isEncoding(encoding: string): boolean;
110 | /**
111 | * Gives the actual byte length of a string. encoding defaults to 'utf8'.
112 | * This is not the same as String.prototype.length since that returns the number of characters in a string.
113 | *
114 | * @param string string to test.
115 | * @param encoding encoding used to evaluate (defaults to 'utf8')
116 | */
117 | byteLength(string: string, encoding?: string): number;
118 | /**
119 | * Returns a buffer which is the result of concatenating all the buffers in the list together.
120 | *
121 | * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
122 | * If the list has exactly one item, then the first item of the list is returned.
123 | * If the list has more than one item, then a new Buffer is created.
124 | *
125 | * @param list An array of Buffer objects to concatenate
126 | * @param totalLength Total length of the buffers when concatenated.
127 | * 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.
128 | */
129 | concat(list: Buffer[], totalLength?: number): Buffer;
130 | };
131 |
132 | /************************************************
133 | * *
134 | * GLOBAL INTERFACES *
135 | * *
136 | ************************************************/
137 | declare module NodeJS {
138 | export interface ErrnoException extends Error {
139 | errno?: number;
140 | code?: string;
141 | path?: string;
142 | syscall?: string;
143 | }
144 |
145 | export interface EventEmitter {
146 | addListener(event: string, listener: Function): EventEmitter;
147 | on(event: string, listener: Function): EventEmitter;
148 | once(event: string, listener: Function): EventEmitter;
149 | removeListener(event: string, listener: Function): EventEmitter;
150 | removeAllListeners(event?: string): EventEmitter;
151 | setMaxListeners(n: number): void;
152 | listeners(event: string): Function[];
153 | emit(event: string, ...args: any[]): boolean;
154 | }
155 |
156 | export interface ReadableStream extends EventEmitter {
157 | readable: boolean;
158 | read(size?: number): string|Buffer;
159 | setEncoding(encoding: string): void;
160 | pause(): void;
161 | resume(): void;
162 | pipe(destination: T, options?: { end?: boolean; }): T;
163 | unpipe(destination?: T): void;
164 | unshift(chunk: string): void;
165 | unshift(chunk: Buffer): void;
166 | wrap(oldStream: ReadableStream): ReadableStream;
167 | }
168 |
169 | export interface WritableStream extends EventEmitter {
170 | writable: boolean;
171 | write(buffer: Buffer, cb?: Function): boolean;
172 | write(str: string, cb?: Function): boolean;
173 | write(str: string, encoding?: string, cb?: Function): boolean;
174 | end(): void;
175 | end(buffer: Buffer, cb?: Function): void;
176 | end(str: string, cb?: Function): void;
177 | end(str: string, encoding?: string, cb?: Function): void;
178 | }
179 |
180 | export interface ReadWriteStream extends ReadableStream, WritableStream {}
181 |
182 | export interface Process extends EventEmitter {
183 | stdout: WritableStream;
184 | stderr: WritableStream;
185 | stdin: ReadableStream;
186 | argv: string[];
187 | execPath: string;
188 | abort(): void;
189 | chdir(directory: string): void;
190 | cwd(): string;
191 | env: any;
192 | exit(code?: number): void;
193 | getgid(): number;
194 | setgid(id: number): void;
195 | setgid(id: string): void;
196 | getuid(): number;
197 | setuid(id: number): void;
198 | setuid(id: string): void;
199 | version: string;
200 | versions: {
201 | http_parser: string;
202 | node: string;
203 | v8: string;
204 | ares: string;
205 | uv: string;
206 | zlib: string;
207 | openssl: string;
208 | };
209 | config: {
210 | target_defaults: {
211 | cflags: any[];
212 | default_configuration: string;
213 | defines: string[];
214 | include_dirs: string[];
215 | libraries: string[];
216 | };
217 | variables: {
218 | clang: number;
219 | host_arch: string;
220 | node_install_npm: boolean;
221 | node_install_waf: boolean;
222 | node_prefix: string;
223 | node_shared_openssl: boolean;
224 | node_shared_v8: boolean;
225 | node_shared_zlib: boolean;
226 | node_use_dtrace: boolean;
227 | node_use_etw: boolean;
228 | node_use_openssl: boolean;
229 | target_arch: string;
230 | v8_no_strict_aliasing: number;
231 | v8_use_snapshot: boolean;
232 | visibility: string;
233 | };
234 | };
235 | kill(pid: number, signal?: string): void;
236 | pid: number;
237 | title: string;
238 | arch: string;
239 | platform: string;
240 | memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; };
241 | nextTick(callback: Function): void;
242 | umask(mask?: number): number;
243 | uptime(): number;
244 | hrtime(time?:number[]): number[];
245 |
246 | // Worker
247 | send?(message: any, sendHandle?: any): void;
248 | }
249 |
250 | export interface Global {
251 | Array: typeof Array;
252 | ArrayBuffer: typeof ArrayBuffer;
253 | Boolean: typeof Boolean;
254 | Buffer: typeof Buffer;
255 | DataView: typeof DataView;
256 | Date: typeof Date;
257 | Error: typeof Error;
258 | EvalError: typeof EvalError;
259 | Float32Array: typeof Float32Array;
260 | Float64Array: typeof Float64Array;
261 | Function: typeof Function;
262 | GLOBAL: Global;
263 | Infinity: typeof Infinity;
264 | Int16Array: typeof Int16Array;
265 | Int32Array: typeof Int32Array;
266 | Int8Array: typeof Int8Array;
267 | Intl: typeof Intl;
268 | JSON: typeof JSON;
269 | Map: typeof Map;
270 | Math: typeof Math;
271 | NaN: typeof NaN;
272 | Number: typeof Number;
273 | Object: typeof Object;
274 | Promise: Function;
275 | RangeError: typeof RangeError;
276 | ReferenceError: typeof ReferenceError;
277 | RegExp: typeof RegExp;
278 | Set: typeof Set;
279 | String: typeof String;
280 | Symbol: Function;
281 | SyntaxError: typeof SyntaxError;
282 | TypeError: typeof TypeError;
283 | URIError: typeof URIError;
284 | Uint16Array: typeof Uint16Array;
285 | Uint32Array: typeof Uint32Array;
286 | Uint8Array: typeof Uint8Array;
287 | Uint8ClampedArray: Function;
288 | WeakMap: typeof WeakMap;
289 | WeakSet: Function;
290 | clearImmediate: (immediateId: any) => void;
291 | clearInterval: (intervalId: NodeJS.Timer) => void;
292 | clearTimeout: (timeoutId: NodeJS.Timer) => void;
293 | console: typeof console;
294 | decodeURI: typeof decodeURI;
295 | decodeURIComponent: typeof decodeURIComponent;
296 | encodeURI: typeof encodeURI;
297 | encodeURIComponent: typeof encodeURIComponent;
298 | escape: (str: string) => string;
299 | eval: typeof eval;
300 | global: Global;
301 | isFinite: typeof isFinite;
302 | isNaN: typeof isNaN;
303 | parseFloat: typeof parseFloat;
304 | parseInt: typeof parseInt;
305 | process: Process;
306 | root: Global;
307 | setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any;
308 | setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer;
309 | setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer;
310 | undefined: typeof undefined;
311 | unescape: (str: string) => string;
312 | gc: () => void;
313 | }
314 |
315 | export interface Timer {
316 | ref() : void;
317 | unref() : void;
318 | }
319 | }
320 |
321 | /**
322 | * @deprecated
323 | */
324 | interface NodeBuffer {
325 | [index: number]: number;
326 | write(string: string, offset?: number, length?: number, encoding?: string): number;
327 | toString(encoding?: string, start?: number, end?: number): string;
328 | toJSON(): any;
329 | length: number;
330 | copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
331 | slice(start?: number, end?: number): Buffer;
332 | writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
333 | writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
334 | writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
335 | writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number;
336 | readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
337 | readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
338 | readIntLE(offset: number, byteLength: number, noAssert?: boolean): number;
339 | readIntBE(offset: number, byteLength: number, noAssert?: boolean): number;
340 | readUInt8(offset: number, noAsset?: boolean): number;
341 | readUInt16LE(offset: number, noAssert?: boolean): number;
342 | readUInt16BE(offset: number, noAssert?: boolean): number;
343 | readUInt32LE(offset: number, noAssert?: boolean): number;
344 | readUInt32BE(offset: number, noAssert?: boolean): number;
345 | readInt8(offset: number, noAssert?: boolean): number;
346 | readInt16LE(offset: number, noAssert?: boolean): number;
347 | readInt16BE(offset: number, noAssert?: boolean): number;
348 | readInt32LE(offset: number, noAssert?: boolean): number;
349 | readInt32BE(offset: number, noAssert?: boolean): number;
350 | readFloatLE(offset: number, noAssert?: boolean): number;
351 | readFloatBE(offset: number, noAssert?: boolean): number;
352 | readDoubleLE(offset: number, noAssert?: boolean): number;
353 | readDoubleBE(offset: number, noAssert?: boolean): number;
354 | writeUInt8(value: number, offset: number, noAssert?: boolean): void;
355 | writeUInt16LE(value: number, offset: number, noAssert?: boolean): void;
356 | writeUInt16BE(value: number, offset: number, noAssert?: boolean): void;
357 | writeUInt32LE(value: number, offset: number, noAssert?: boolean): void;
358 | writeUInt32BE(value: number, offset: number, noAssert?: boolean): void;
359 | writeInt8(value: number, offset: number, noAssert?: boolean): void;
360 | writeInt16LE(value: number, offset: number, noAssert?: boolean): void;
361 | writeInt16BE(value: number, offset: number, noAssert?: boolean): void;
362 | writeInt32LE(value: number, offset: number, noAssert?: boolean): void;
363 | writeInt32BE(value: number, offset: number, noAssert?: boolean): void;
364 | writeFloatLE(value: number, offset: number, noAssert?: boolean): void;
365 | writeFloatBE(value: number, offset: number, noAssert?: boolean): void;
366 | writeDoubleLE(value: number, offset: number, noAssert?: boolean): void;
367 | writeDoubleBE(value: number, offset: number, noAssert?: boolean): void;
368 | fill(value: any, offset?: number, end?: number): void;
369 | }
370 |
371 | /************************************************
372 | * *
373 | * MODULES *
374 | * *
375 | ************************************************/
376 | declare module "buffer" {
377 | export var INSPECT_MAX_BYTES: number;
378 | }
379 |
380 | declare module "querystring" {
381 | export function stringify(obj: any, sep?: string, eq?: string): string;
382 | export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any;
383 | export function escape(str: string): string;
384 | export function unescape(str: string): string;
385 | }
386 |
387 | declare module "events" {
388 | export class EventEmitter implements NodeJS.EventEmitter {
389 | static listenerCount(emitter: EventEmitter, event: string): number;
390 |
391 | addListener(event: string, listener: Function): EventEmitter;
392 | on(event: string, listener: Function): EventEmitter;
393 | once(event: string, listener: Function): EventEmitter;
394 | removeListener(event: string, listener: Function): EventEmitter;
395 | removeAllListeners(event?: string): EventEmitter;
396 | setMaxListeners(n: number): void;
397 | listeners(event: string): Function[];
398 | emit(event: string, ...args: any[]): boolean;
399 | }
400 | }
401 |
402 | declare module "http" {
403 | import events = require("events");
404 | import net = require("net");
405 | import stream = require("stream");
406 |
407 | export interface Server extends events.EventEmitter {
408 | listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server;
409 | listen(port: number, hostname?: string, callback?: Function): Server;
410 | listen(path: string, callback?: Function): Server;
411 | listen(handle: any, listeningListener?: Function): Server;
412 | close(cb?: any): Server;
413 | address(): { port: number; family: string; address: string; };
414 | maxHeadersCount: number;
415 | }
416 | /**
417 | * @deprecated Use IncomingMessage
418 | */
419 | export interface ServerRequest extends IncomingMessage {
420 | connection: net.Socket;
421 | }
422 | export interface ServerResponse extends events.EventEmitter, stream.Writable {
423 | // Extended base methods
424 | write(buffer: Buffer): boolean;
425 | write(buffer: Buffer, cb?: Function): boolean;
426 | write(str: string, cb?: Function): boolean;
427 | write(str: string, encoding?: string, cb?: Function): boolean;
428 | write(str: string, encoding?: string, fd?: string): boolean;
429 |
430 | writeContinue(): void;
431 | writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void;
432 | writeHead(statusCode: number, headers?: any): void;
433 | statusCode: number;
434 | setHeader(name: string, value: string): void;
435 | sendDate: boolean;
436 | getHeader(name: string): string;
437 | removeHeader(name: string): void;
438 | write(chunk: any, encoding?: string): any;
439 | addTrailers(headers: any): void;
440 |
441 | // Extended base methods
442 | end(): void;
443 | end(buffer: Buffer, cb?: Function): void;
444 | end(str: string, cb?: Function): void;
445 | end(str: string, encoding?: string, cb?: Function): void;
446 | end(data?: any, encoding?: string): void;
447 | }
448 | export interface ClientRequest extends events.EventEmitter, stream.Writable {
449 | // Extended base methods
450 | write(buffer: Buffer): boolean;
451 | write(buffer: Buffer, cb?: Function): boolean;
452 | write(str: string, cb?: Function): boolean;
453 | write(str: string, encoding?: string, cb?: Function): boolean;
454 | write(str: string, encoding?: string, fd?: string): boolean;
455 |
456 | write(chunk: any, encoding?: string): void;
457 | abort(): void;
458 | setTimeout(timeout: number, callback?: Function): void;
459 | setNoDelay(noDelay?: boolean): void;
460 | setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
461 |
462 | // Extended base methods
463 | end(): void;
464 | end(buffer: Buffer, cb?: Function): void;
465 | end(str: string, cb?: Function): void;
466 | end(str: string, encoding?: string, cb?: Function): void;
467 | end(data?: any, encoding?: string): void;
468 | }
469 | export interface IncomingMessage extends events.EventEmitter, stream.Readable {
470 | httpVersion: string;
471 | headers: any;
472 | rawHeaders: string[];
473 | trailers: any;
474 | rawTrailers: any;
475 | setTimeout(msecs: number, callback: Function): NodeJS.Timer;
476 | /**
477 | * Only valid for request obtained from http.Server.
478 | */
479 | method?: string;
480 | /**
481 | * Only valid for request obtained from http.Server.
482 | */
483 | url?: string;
484 | /**
485 | * Only valid for response obtained from http.ClientRequest.
486 | */
487 | statusCode?: number;
488 | /**
489 | * Only valid for response obtained from http.ClientRequest.
490 | */
491 | statusMessage?: string;
492 | socket: net.Socket;
493 | }
494 | /**
495 | * @deprecated Use IncomingMessage
496 | */
497 | export interface ClientResponse extends IncomingMessage { }
498 |
499 | export interface AgentOptions {
500 | /**
501 | * Keep sockets around in a pool to be used by other requests in the future. Default = false
502 | */
503 | keepAlive?: boolean;
504 | /**
505 | * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
506 | * Only relevant if keepAlive is set to true.
507 | */
508 | keepAliveMsecs?: number;
509 | /**
510 | * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
511 | */
512 | maxSockets?: number;
513 | /**
514 | * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
515 | */
516 | maxFreeSockets?: number;
517 | }
518 |
519 | export class Agent {
520 | maxSockets: number;
521 | sockets: any;
522 | requests: any;
523 |
524 | constructor(opts?: AgentOptions);
525 |
526 | /**
527 | * Destroy any sockets that are currently in use by the agent.
528 | * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled,
529 | * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise,
530 | * sockets may hang open for quite a long time before the server terminates them.
531 | */
532 | destroy(): void;
533 | }
534 |
535 | export var STATUS_CODES: {
536 | [errorCode: number]: string;
537 | [errorCode: string]: string;
538 | };
539 | export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server;
540 | export function createClient(port?: number, host?: string): any;
541 | export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest;
542 | export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest;
543 | export var globalAgent: Agent;
544 | }
545 |
546 | declare module "cluster" {
547 | import child = require("child_process");
548 | import events = require("events");
549 |
550 | export interface ClusterSettings {
551 | exec?: string;
552 | args?: string[];
553 | silent?: boolean;
554 | }
555 |
556 | export class Worker extends events.EventEmitter {
557 | id: string;
558 | process: child.ChildProcess;
559 | suicide: boolean;
560 | send(message: any, sendHandle?: any): void;
561 | kill(signal?: string): void;
562 | destroy(signal?: string): void;
563 | disconnect(): void;
564 | }
565 |
566 | export var settings: ClusterSettings;
567 | export var isMaster: boolean;
568 | export var isWorker: boolean;
569 | export function setupMaster(settings?: ClusterSettings): void;
570 | export function fork(env?: any): Worker;
571 | export function disconnect(callback?: Function): void;
572 | export var worker: Worker;
573 | export var workers: Worker[];
574 |
575 | // Event emitter
576 | export function addListener(event: string, listener: Function): void;
577 | export function on(event: string, listener: Function): any;
578 | export function once(event: string, listener: Function): void;
579 | export function removeListener(event: string, listener: Function): void;
580 | export function removeAllListeners(event?: string): void;
581 | export function setMaxListeners(n: number): void;
582 | export function listeners(event: string): Function[];
583 | export function emit(event: string, ...args: any[]): boolean;
584 | }
585 |
586 | declare module "zlib" {
587 | import stream = require("stream");
588 | export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; }
589 |
590 | export interface Gzip extends stream.Transform { }
591 | export interface Gunzip extends stream.Transform { }
592 | export interface Deflate extends stream.Transform { }
593 | export interface Inflate extends stream.Transform { }
594 | export interface DeflateRaw extends stream.Transform { }
595 | export interface InflateRaw extends stream.Transform { }
596 | export interface Unzip extends stream.Transform { }
597 |
598 | export function createGzip(options?: ZlibOptions): Gzip;
599 | export function createGunzip(options?: ZlibOptions): Gunzip;
600 | export function createDeflate(options?: ZlibOptions): Deflate;
601 | export function createInflate(options?: ZlibOptions): Inflate;
602 | export function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
603 | export function createInflateRaw(options?: ZlibOptions): InflateRaw;
604 | export function createUnzip(options?: ZlibOptions): Unzip;
605 |
606 | export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
607 | export function deflateSync(buf: Buffer, options?: ZlibOptions): any;
608 | export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
609 | export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any;
610 | export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
611 | export function gzipSync(buf: Buffer, options?: ZlibOptions): any;
612 | export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
613 | export function gunzipSync(buf: Buffer, options?: ZlibOptions): any;
614 | export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
615 | export function inflateSync(buf: Buffer, options?: ZlibOptions): any;
616 | export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
617 | export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any;
618 | export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void;
619 | export function unzipSync(buf: Buffer, options?: ZlibOptions): any;
620 |
621 | // Constants
622 | export var Z_NO_FLUSH: number;
623 | export var Z_PARTIAL_FLUSH: number;
624 | export var Z_SYNC_FLUSH: number;
625 | export var Z_FULL_FLUSH: number;
626 | export var Z_FINISH: number;
627 | export var Z_BLOCK: number;
628 | export var Z_TREES: number;
629 | export var Z_OK: number;
630 | export var Z_STREAM_END: number;
631 | export var Z_NEED_DICT: number;
632 | export var Z_ERRNO: number;
633 | export var Z_STREAM_ERROR: number;
634 | export var Z_DATA_ERROR: number;
635 | export var Z_MEM_ERROR: number;
636 | export var Z_BUF_ERROR: number;
637 | export var Z_VERSION_ERROR: number;
638 | export var Z_NO_COMPRESSION: number;
639 | export var Z_BEST_SPEED: number;
640 | export var Z_BEST_COMPRESSION: number;
641 | export var Z_DEFAULT_COMPRESSION: number;
642 | export var Z_FILTERED: number;
643 | export var Z_HUFFMAN_ONLY: number;
644 | export var Z_RLE: number;
645 | export var Z_FIXED: number;
646 | export var Z_DEFAULT_STRATEGY: number;
647 | export var Z_BINARY: number;
648 | export var Z_TEXT: number;
649 | export var Z_ASCII: number;
650 | export var Z_UNKNOWN: number;
651 | export var Z_DEFLATED: number;
652 | export var Z_NULL: number;
653 | }
654 |
655 | declare module "os" {
656 | export function tmpdir(): string;
657 | export function hostname(): string;
658 | export function type(): string;
659 | export function platform(): string;
660 | export function arch(): string;
661 | export function release(): string;
662 | export function uptime(): number;
663 | export function loadavg(): number[];
664 | export function totalmem(): number;
665 | export function freemem(): number;
666 | export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[];
667 | export function networkInterfaces(): any;
668 | export var EOL: string;
669 | }
670 |
671 | declare module "https" {
672 | import tls = require("tls");
673 | import events = require("events");
674 | import http = require("http");
675 |
676 | export interface ServerOptions {
677 | pfx?: any;
678 | key?: any;
679 | passphrase?: string;
680 | cert?: any;
681 | ca?: any;
682 | crl?: any;
683 | ciphers?: string;
684 | honorCipherOrder?: boolean;
685 | requestCert?: boolean;
686 | rejectUnauthorized?: boolean;
687 | NPNProtocols?: any;
688 | SNICallback?: (servername: string) => any;
689 | }
690 |
691 | export interface RequestOptions {
692 | host?: string;
693 | hostname?: string;
694 | port?: number;
695 | path?: string;
696 | method?: string;
697 | headers?: any;
698 | auth?: string;
699 | agent?: any;
700 | pfx?: any;
701 | key?: any;
702 | passphrase?: string;
703 | cert?: any;
704 | ca?: any;
705 | ciphers?: string;
706 | rejectUnauthorized?: boolean;
707 | }
708 |
709 | export interface Agent {
710 | maxSockets: number;
711 | sockets: any;
712 | requests: any;
713 | }
714 | export var Agent: {
715 | new (options?: RequestOptions): Agent;
716 | };
717 | export interface Server extends tls.Server { }
718 | export function createServer(options: ServerOptions, requestListener?: Function): Server;
719 | export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest;
720 | export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest;
721 | export var globalAgent: Agent;
722 | }
723 |
724 | declare module "punycode" {
725 | export function decode(string: string): string;
726 | export function encode(string: string): string;
727 | export function toUnicode(domain: string): string;
728 | export function toASCII(domain: string): string;
729 | export var ucs2: ucs2;
730 | interface ucs2 {
731 | decode(string: string): string;
732 | encode(codePoints: number[]): string;
733 | }
734 | export var version: any;
735 | }
736 |
737 | declare module "repl" {
738 | import stream = require("stream");
739 | import events = require("events");
740 |
741 | export interface ReplOptions {
742 | prompt?: string;
743 | input?: NodeJS.ReadableStream;
744 | output?: NodeJS.WritableStream;
745 | terminal?: boolean;
746 | eval?: Function;
747 | useColors?: boolean;
748 | useGlobal?: boolean;
749 | ignoreUndefined?: boolean;
750 | writer?: Function;
751 | }
752 | export function start(options: ReplOptions): events.EventEmitter;
753 | }
754 |
755 | declare module "readline" {
756 | import events = require("events");
757 | import stream = require("stream");
758 |
759 | export interface ReadLine extends events.EventEmitter {
760 | setPrompt(prompt: string, length: number): void;
761 | prompt(preserveCursor?: boolean): void;
762 | question(query: string, callback: Function): void;
763 | pause(): void;
764 | resume(): void;
765 | close(): void;
766 | write(data: any, key?: any): void;
767 | }
768 | export interface ReadLineOptions {
769 | input: NodeJS.ReadableStream;
770 | output: NodeJS.WritableStream;
771 | completer?: Function;
772 | terminal?: boolean;
773 | }
774 | export function createInterface(options: ReadLineOptions): ReadLine;
775 | }
776 |
777 | declare module "vm" {
778 | export interface Context { }
779 | export interface Script {
780 | runInThisContext(): void;
781 | runInNewContext(sandbox?: Context): void;
782 | }
783 | export function runInThisContext(code: string, filename?: string): void;
784 | export function runInNewContext(code: string, sandbox?: Context, filename?: string): void;
785 | export function runInContext(code: string, context: Context, filename?: string): void;
786 | export function createContext(initSandbox?: Context): Context;
787 | export function createScript(code: string, filename?: string): Script;
788 | }
789 |
790 | declare module "child_process" {
791 | import events = require("events");
792 | import stream = require("stream");
793 |
794 | export interface ChildProcess extends events.EventEmitter {
795 | stdin: stream.Writable;
796 | stdout: stream.Readable;
797 | stderr: stream.Readable;
798 | pid: number;
799 | kill(signal?: string): void;
800 | send(message: any, sendHandle?: any): void;
801 | disconnect(): void;
802 | }
803 |
804 | export function spawn(command: string, args?: string[], options?: {
805 | cwd?: string;
806 | stdio?: any;
807 | custom?: any;
808 | env?: any;
809 | detached?: boolean;
810 | }): ChildProcess;
811 | export function exec(command: string, options: {
812 | cwd?: string;
813 | stdio?: any;
814 | customFds?: any;
815 | env?: any;
816 | encoding?: string;
817 | timeout?: number;
818 | maxBuffer?: number;
819 | killSignal?: string;
820 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
821 | export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
822 | export function execFile(file: string,
823 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
824 | export function execFile(file: string, args?: string[],
825 | callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
826 | export function execFile(file: string, args?: string[], options?: {
827 | cwd?: string;
828 | stdio?: any;
829 | customFds?: any;
830 | env?: any;
831 | encoding?: string;
832 | timeout?: number;
833 | maxBuffer?: string;
834 | killSignal?: string;
835 | }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess;
836 | export function fork(modulePath: string, args?: string[], options?: {
837 | cwd?: string;
838 | env?: any;
839 | encoding?: string;
840 | }): ChildProcess;
841 | export function execSync(command: string, options?: {
842 | cwd?: string;
843 | input?: string|Buffer;
844 | stdio?: any;
845 | env?: any;
846 | uid?: number;
847 | gid?: number;
848 | timeout?: number;
849 | maxBuffer?: number;
850 | killSignal?: string;
851 | encoding?: string;
852 | }): ChildProcess;
853 | export function execFileSync(command: string, args?: string[], options?: {
854 | cwd?: string;
855 | input?: string|Buffer;
856 | stdio?: any;
857 | env?: any;
858 | uid?: number;
859 | gid?: number;
860 | timeout?: number;
861 | maxBuffer?: number;
862 | killSignal?: string;
863 | encoding?: string;
864 | }): ChildProcess;
865 | }
866 |
867 | declare module "url" {
868 | export interface Url {
869 | href: string;
870 | protocol: string;
871 | auth: string;
872 | hostname: string;
873 | port: string;
874 | host: string;
875 | pathname: string;
876 | search: string;
877 | query: any; // string | Object
878 | slashes: boolean;
879 | hash?: string;
880 | path?: string;
881 | }
882 |
883 | export interface UrlOptions {
884 | protocol?: string;
885 | auth?: string;
886 | hostname?: string;
887 | port?: string;
888 | host?: string;
889 | pathname?: string;
890 | search?: string;
891 | query?: any;
892 | hash?: string;
893 | path?: string;
894 | }
895 |
896 | export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url;
897 | export function format(url: UrlOptions): string;
898 | export function resolve(from: string, to: string): string;
899 | }
900 |
901 | declare module "dns" {
902 | export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string;
903 | export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string;
904 | export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[];
905 | export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
906 | export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
907 | export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
908 | export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
909 | export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
910 | export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
911 | export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
912 | export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[];
913 | export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[];
914 | }
915 |
916 | declare module "net" {
917 | import stream = require("stream");
918 |
919 | export interface Socket extends stream.Duplex {
920 | // Extended base methods
921 | write(buffer: Buffer): boolean;
922 | write(buffer: Buffer, cb?: Function): boolean;
923 | write(str: string, cb?: Function): boolean;
924 | write(str: string, encoding?: string, cb?: Function): boolean;
925 | write(str: string, encoding?: string, fd?: string): boolean;
926 |
927 | connect(port: number, host?: string, connectionListener?: Function): void;
928 | connect(path: string, connectionListener?: Function): void;
929 | bufferSize: number;
930 | setEncoding(encoding?: string): void;
931 | write(data: any, encoding?: string, callback?: Function): void;
932 | destroy(): void;
933 | pause(): void;
934 | resume(): void;
935 | setTimeout(timeout: number, callback?: Function): void;
936 | setNoDelay(noDelay?: boolean): void;
937 | setKeepAlive(enable?: boolean, initialDelay?: number): void;
938 | address(): { port: number; family: string; address: string; };
939 | unref(): void;
940 | ref(): void;
941 |
942 | remoteAddress: string;
943 | remoteFamily: string;
944 | remotePort: number;
945 | localAddress: string;
946 | localPort: number;
947 | bytesRead: number;
948 | bytesWritten: number;
949 |
950 | // Extended base methods
951 | end(): void;
952 | end(buffer: Buffer, cb?: Function): void;
953 | end(str: string, cb?: Function): void;
954 | end(str: string, encoding?: string, cb?: Function): void;
955 | end(data?: any, encoding?: string): void;
956 | }
957 |
958 | export var Socket: {
959 | new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket;
960 | };
961 |
962 | export interface Server extends Socket {
963 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server;
964 | listen(path: string, listeningListener?: Function): Server;
965 | listen(handle: any, listeningListener?: Function): Server;
966 | close(callback?: Function): Server;
967 | address(): { port: number; family: string; address: string; };
968 | maxConnections: number;
969 | connections: number;
970 | }
971 | export function createServer(connectionListener?: (socket: Socket) =>void ): Server;
972 | export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server;
973 | export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;
974 | export function connect(port: number, host?: string, connectionListener?: Function): Socket;
975 | export function connect(path: string, connectionListener?: Function): Socket;
976 | export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;
977 | export function createConnection(port: number, host?: string, connectionListener?: Function): Socket;
978 | export function createConnection(path: string, connectionListener?: Function): Socket;
979 | export function isIP(input: string): number;
980 | export function isIPv4(input: string): boolean;
981 | export function isIPv6(input: string): boolean;
982 | }
983 |
984 | declare module "dgram" {
985 | import events = require("events");
986 |
987 | interface RemoteInfo {
988 | address: string;
989 | port: number;
990 | size: number;
991 | }
992 |
993 | interface AddressInfo {
994 | address: string;
995 | family: string;
996 | port: number;
997 | }
998 |
999 | export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
1000 |
1001 | interface Socket extends events.EventEmitter {
1002 | send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void;
1003 | bind(port: number, address?: string, callback?: () => void): void;
1004 | close(): void;
1005 | address(): AddressInfo;
1006 | setBroadcast(flag: boolean): void;
1007 | setMulticastTTL(ttl: number): void;
1008 | setMulticastLoopback(flag: boolean): void;
1009 | addMembership(multicastAddress: string, multicastInterface?: string): void;
1010 | dropMembership(multicastAddress: string, multicastInterface?: string): void;
1011 | }
1012 | }
1013 |
1014 | declare module "fs" {
1015 | import stream = require("stream");
1016 | import events = require("events");
1017 |
1018 | interface Stats {
1019 | isFile(): boolean;
1020 | isDirectory(): boolean;
1021 | isBlockDevice(): boolean;
1022 | isCharacterDevice(): boolean;
1023 | isSymbolicLink(): boolean;
1024 | isFIFO(): boolean;
1025 | isSocket(): boolean;
1026 | dev: number;
1027 | ino: number;
1028 | mode: number;
1029 | nlink: number;
1030 | uid: number;
1031 | gid: number;
1032 | rdev: number;
1033 | size: number;
1034 | blksize: number;
1035 | blocks: number;
1036 | atime: Date;
1037 | mtime: Date;
1038 | ctime: Date;
1039 | }
1040 |
1041 | interface FSWatcher extends events.EventEmitter {
1042 | close(): void;
1043 | }
1044 |
1045 | export interface ReadStream extends stream.Readable {
1046 | close(): void;
1047 | }
1048 | export interface WriteStream extends stream.Writable {
1049 | close(): void;
1050 | }
1051 |
1052 | /**
1053 | * Asynchronous rename.
1054 | * @param oldPath
1055 | * @param newPath
1056 | * @param callback No arguments other than a possible exception are given to the completion callback.
1057 | */
1058 | export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1059 | /**
1060 | * Synchronous rename
1061 | * @param oldPath
1062 | * @param newPath
1063 | */
1064 | export function renameSync(oldPath: string, newPath: string): void;
1065 | export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1066 | export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1067 | export function truncateSync(path: string, len?: number): void;
1068 | export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1069 | export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1070 | export function ftruncateSync(fd: number, len?: number): void;
1071 | export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1072 | export function chownSync(path: string, uid: number, gid: number): void;
1073 | export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1074 | export function fchownSync(fd: number, uid: number, gid: number): void;
1075 | export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1076 | export function lchownSync(path: string, uid: number, gid: number): void;
1077 | export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1078 | export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1079 | export function chmodSync(path: string, mode: number): void;
1080 | export function chmodSync(path: string, mode: string): void;
1081 | export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1082 | export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1083 | export function fchmodSync(fd: number, mode: number): void;
1084 | export function fchmodSync(fd: number, mode: string): void;
1085 | export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1086 | export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1087 | export function lchmodSync(path: string, mode: number): void;
1088 | export function lchmodSync(path: string, mode: string): void;
1089 | export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
1090 | export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
1091 | export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
1092 | export function statSync(path: string): Stats;
1093 | export function lstatSync(path: string): Stats;
1094 | export function fstatSync(fd: number): Stats;
1095 | export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1096 | export function linkSync(srcpath: string, dstpath: string): void;
1097 | export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1098 | export function symlinkSync(srcpath: string, dstpath: string, type?: string): void;
1099 | export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void;
1100 | export function readlinkSync(path: string): string;
1101 | export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
1102 | export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void;
1103 | export function realpathSync(path: string, cache?: { [path: string]: string }): string;
1104 | /*
1105 | * Asynchronous unlink - deletes the file specified in {path}
1106 | *
1107 | * @param path
1108 | * @param callback No arguments other than a possible exception are given to the completion callback.
1109 | */
1110 | export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1111 | /*
1112 | * Synchronous unlink - deletes the file specified in {path}
1113 | *
1114 | * @param path
1115 | */
1116 | export function unlinkSync(path: string): void;
1117 | /*
1118 | * Asynchronous rmdir - removes the directory specified in {path}
1119 | *
1120 | * @param path
1121 | * @param callback No arguments other than a possible exception are given to the completion callback.
1122 | */
1123 | export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1124 | /*
1125 | * Synchronous rmdir - removes the directory specified in {path}
1126 | *
1127 | * @param path
1128 | */
1129 | export function rmdirSync(path: string): void;
1130 | /*
1131 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
1132 | *
1133 | * @param path
1134 | * @param callback No arguments other than a possible exception are given to the completion callback.
1135 | */
1136 | export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1137 | /*
1138 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
1139 | *
1140 | * @param path
1141 | * @param mode
1142 | * @param callback No arguments other than a possible exception are given to the completion callback.
1143 | */
1144 | export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1145 | /*
1146 | * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
1147 | *
1148 | * @param path
1149 | * @param mode
1150 | * @param callback No arguments other than a possible exception are given to the completion callback.
1151 | */
1152 | export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
1153 | /*
1154 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
1155 | *
1156 | * @param path
1157 | * @param mode
1158 | * @param callback No arguments other than a possible exception are given to the completion callback.
1159 | */
1160 | export function mkdirSync(path: string, mode?: number): void;
1161 | /*
1162 | * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
1163 | *
1164 | * @param path
1165 | * @param mode
1166 | * @param callback No arguments other than a possible exception are given to the completion callback.
1167 | */
1168 | export function mkdirSync(path: string, mode?: string): void;
1169 | export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void;
1170 | export function readdirSync(path: string): string[];
1171 | export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1172 | export function closeSync(fd: number): void;
1173 | export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void;
1174 | export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void;
1175 | export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void;
1176 | export function openSync(path: string, flags: string, mode?: number): number;
1177 | export function openSync(path: string, flags: string, mode?: string): number;
1178 | export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1179 | export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void;
1180 | export function utimesSync(path: string, atime: number, mtime: number): void;
1181 | export function utimesSync(path: string, atime: Date, mtime: Date): void;
1182 | export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1183 | export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void;
1184 | export function futimesSync(fd: number, atime: number, mtime: number): void;
1185 | export function futimesSync(fd: number, atime: Date, mtime: Date): void;
1186 | export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
1187 | export function fsyncSync(fd: number): void;
1188 | export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
1189 | export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number;
1190 | export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void;
1191 | export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number;
1192 | /*
1193 | * Asynchronous readFile - Asynchronously reads the entire contents of a file.
1194 | *
1195 | * @param fileName
1196 | * @param encoding
1197 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
1198 | */
1199 | export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
1200 | /*
1201 | * Asynchronous readFile - Asynchronously reads the entire contents of a file.
1202 | *
1203 | * @param fileName
1204 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer.
1205 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
1206 | */
1207 | export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
1208 | /*
1209 | * Asynchronous readFile - Asynchronously reads the entire contents of a file.
1210 | *
1211 | * @param fileName
1212 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer.
1213 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
1214 | */
1215 | export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
1216 | /*
1217 | * Asynchronous readFile - Asynchronously reads the entire contents of a file.
1218 | *
1219 | * @param fileName
1220 | * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
1221 | */
1222 | export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
1223 | /*
1224 | * Synchronous readFile - Synchronously reads the entire contents of a file.
1225 | *
1226 | * @param fileName
1227 | * @param encoding
1228 | */
1229 | export function readFileSync(filename: string, encoding: string): string;
1230 | /*
1231 | * Synchronous readFile - Synchronously reads the entire contents of a file.
1232 | *
1233 | * @param fileName
1234 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer.
1235 | */
1236 | export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string;
1237 | /*
1238 | * Synchronous readFile - Synchronously reads the entire contents of a file.
1239 | *
1240 | * @param fileName
1241 | * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer.
1242 | */
1243 | export function readFileSync(filename: string, options?: { flag?: string; }): Buffer;
1244 | export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void;
1245 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
1246 | export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
1247 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
1248 | export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void;
1249 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
1250 | export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
1251 | export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void;
1252 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
1253 | export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void;
1254 | export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void;
1255 | export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void;
1256 | export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void;
1257 | export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher;
1258 | export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher;
1259 | export function exists(path: string, callback?: (exists: boolean) => void): void;
1260 | export function existsSync(path: string): boolean;
1261 | export function createReadStream(path: string, options?: {
1262 | flags?: string;
1263 | encoding?: string;
1264 | fd?: string;
1265 | mode?: number;
1266 | bufferSize?: number;
1267 | }): ReadStream;
1268 | export function createReadStream(path: string, options?: {
1269 | flags?: string;
1270 | encoding?: string;
1271 | fd?: string;
1272 | mode?: string;
1273 | bufferSize?: number;
1274 | }): ReadStream;
1275 | export function createWriteStream(path: string, options?: {
1276 | flags?: string;
1277 | encoding?: string;
1278 | string?: string;
1279 | }): WriteStream;
1280 | }
1281 |
1282 | declare module "path" {
1283 |
1284 | /**
1285 | * A parsed path object generated by path.parse() or consumed by path.format().
1286 | */
1287 | export interface ParsedPath {
1288 | /**
1289 | * The root of the path such as '/' or 'c:\'
1290 | */
1291 | root: string;
1292 | /**
1293 | * The full directory path such as '/home/user/dir' or 'c:\path\dir'
1294 | */
1295 | dir: string;
1296 | /**
1297 | * The file name including extension (if any) such as 'index.html'
1298 | */
1299 | base: string;
1300 | /**
1301 | * The file extension (if any) such as '.html'
1302 | */
1303 | ext: string;
1304 | /**
1305 | * The file name without extension (if any) such as 'index'
1306 | */
1307 | name: string;
1308 | }
1309 |
1310 | /**
1311 | * Normalize a string path, reducing '..' and '.' parts.
1312 | * 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.
1313 | *
1314 | * @param p string path to normalize.
1315 | */
1316 | export function normalize(p: string): string;
1317 | /**
1318 | * Join all arguments together and normalize the resulting path.
1319 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
1320 | *
1321 | * @param paths string paths to join.
1322 | */
1323 | export function join(...paths: any[]): string;
1324 | /**
1325 | * Join all arguments together and normalize the resulting path.
1326 | * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
1327 | *
1328 | * @param paths string paths to join.
1329 | */
1330 | export function join(...paths: string[]): string;
1331 | /**
1332 | * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
1333 | *
1334 | * Starting from leftmost {from} paramter, resolves {to} to an absolute path.
1335 | *
1336 | * 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.
1337 | *
1338 | * @param pathSegments string paths to join. Non-string arguments are ignored.
1339 | */
1340 | export function resolve(...pathSegments: any[]): string;
1341 | /**
1342 | * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
1343 | *
1344 | * @param path path to test.
1345 | */
1346 | export function isAbsolute(path: string): boolean;
1347 | /**
1348 | * Solve the relative path from {from} to {to}.
1349 | * 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.
1350 | *
1351 | * @param from
1352 | * @param to
1353 | */
1354 | export function relative(from: string, to: string): string;
1355 | /**
1356 | * Return the directory name of a path. Similar to the Unix dirname command.
1357 | *
1358 | * @param p the path to evaluate.
1359 | */
1360 | export function dirname(p: string): string;
1361 | /**
1362 | * Return the last portion of a path. Similar to the Unix basename command.
1363 | * Often used to extract the file name from a fully qualified path.
1364 | *
1365 | * @param p the path to evaluate.
1366 | * @param ext optionally, an extension to remove from the result.
1367 | */
1368 | export function basename(p: string, ext?: string): string;
1369 | /**
1370 | * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
1371 | * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
1372 | *
1373 | * @param p the path to evaluate.
1374 | */
1375 | export function extname(p: string): string;
1376 | /**
1377 | * The platform-specific file separator. '\\' or '/'.
1378 | */
1379 | export var sep: string;
1380 | /**
1381 | * The platform-specific file delimiter. ';' or ':'.
1382 | */
1383 | export var delimiter: string;
1384 | /**
1385 | * Returns an object from a path string - the opposite of format().
1386 | *
1387 | * @param pathString path to evaluate.
1388 | */
1389 | export function parse(pathString: string): ParsedPath;
1390 | /**
1391 | * Returns a path string from an object - the opposite of parse().
1392 | *
1393 | * @param pathString path to evaluate.
1394 | */
1395 | export function format(pathObject: ParsedPath): string;
1396 |
1397 | export module posix {
1398 | export function normalize(p: string): string;
1399 | export function join(...paths: any[]): string;
1400 | export function resolve(...pathSegments: any[]): string;
1401 | export function isAbsolute(p: string): boolean;
1402 | export function relative(from: string, to: string): string;
1403 | export function dirname(p: string): string;
1404 | export function basename(p: string, ext?: string): string;
1405 | export function extname(p: string): string;
1406 | export var sep: string;
1407 | export var delimiter: string;
1408 | export function parse(p: string): ParsedPath;
1409 | export function format(pP: ParsedPath): string;
1410 | }
1411 |
1412 | export module win32 {
1413 | export function normalize(p: string): string;
1414 | export function join(...paths: any[]): string;
1415 | export function resolve(...pathSegments: any[]): string;
1416 | export function isAbsolute(p: string): boolean;
1417 | export function relative(from: string, to: string): string;
1418 | export function dirname(p: string): string;
1419 | export function basename(p: string, ext?: string): string;
1420 | export function extname(p: string): string;
1421 | export var sep: string;
1422 | export var delimiter: string;
1423 | export function parse(p: string): ParsedPath;
1424 | export function format(pP: ParsedPath): string;
1425 | }
1426 | }
1427 |
1428 | declare module "string_decoder" {
1429 | export interface NodeStringDecoder {
1430 | write(buffer: Buffer): string;
1431 | detectIncompleteChar(buffer: Buffer): number;
1432 | }
1433 | export var StringDecoder: {
1434 | new (encoding: string): NodeStringDecoder;
1435 | };
1436 | }
1437 |
1438 | declare module "tls" {
1439 | import crypto = require("crypto");
1440 | import net = require("net");
1441 | import stream = require("stream");
1442 |
1443 | var CLIENT_RENEG_LIMIT: number;
1444 | var CLIENT_RENEG_WINDOW: number;
1445 |
1446 | export interface TlsOptions {
1447 | pfx?: any; //string or buffer
1448 | key?: any; //string or buffer
1449 | passphrase?: string;
1450 | cert?: any;
1451 | ca?: any; //string or buffer
1452 | crl?: any; //string or string array
1453 | ciphers?: string;
1454 | honorCipherOrder?: any;
1455 | requestCert?: boolean;
1456 | rejectUnauthorized?: boolean;
1457 | NPNProtocols?: any; //array or Buffer;
1458 | SNICallback?: (servername: string) => any;
1459 | }
1460 |
1461 | export interface ConnectionOptions {
1462 | host?: string;
1463 | port?: number;
1464 | socket?: net.Socket;
1465 | pfx?: any; //string | Buffer
1466 | key?: any; //string | Buffer
1467 | passphrase?: string;
1468 | cert?: any; //string | Buffer
1469 | ca?: any; //Array of string | Buffer
1470 | rejectUnauthorized?: boolean;
1471 | NPNProtocols?: any; //Array of string | Buffer
1472 | servername?: string;
1473 | }
1474 |
1475 | export interface Server extends net.Server {
1476 | // Extended base methods
1477 | listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server;
1478 | listen(path: string, listeningListener?: Function): Server;
1479 | listen(handle: any, listeningListener?: Function): Server;
1480 |
1481 | listen(port: number, host?: string, callback?: Function): Server;
1482 | close(): Server;
1483 | address(): { port: number; family: string; address: string; };
1484 | addContext(hostName: string, credentials: {
1485 | key: string;
1486 | cert: string;
1487 | ca: string;
1488 | }): void;
1489 | maxConnections: number;
1490 | connections: number;
1491 | }
1492 |
1493 | export interface ClearTextStream extends stream.Duplex {
1494 | authorized: boolean;
1495 | authorizationError: Error;
1496 | getPeerCertificate(): any;
1497 | getCipher: {
1498 | name: string;
1499 | version: string;
1500 | };
1501 | address: {
1502 | port: number;
1503 | family: string;
1504 | address: string;
1505 | };
1506 | remoteAddress: string;
1507 | remotePort: number;
1508 | }
1509 |
1510 | export interface SecurePair {
1511 | encrypted: any;
1512 | cleartext: any;
1513 | }
1514 |
1515 | export interface SecureContextOptions {
1516 | pfx?: any; //string | buffer
1517 | key?: any; //string | buffer
1518 | passphrase?: string;
1519 | cert?: any; // string | buffer
1520 | ca?: any; // string | buffer
1521 | crl?: any; // string | string[]
1522 | ciphers?: string;
1523 | honorCipherOrder?: boolean;
1524 | }
1525 |
1526 | export interface SecureContext {
1527 | context: any;
1528 | }
1529 |
1530 | export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server;
1531 | export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream;
1532 | export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream;
1533 | export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream;
1534 | export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair;
1535 | export function createSecureContext(details: SecureContextOptions): SecureContext;
1536 | }
1537 |
1538 | declare module "crypto" {
1539 | export interface CredentialDetails {
1540 | pfx: string;
1541 | key: string;
1542 | passphrase: string;
1543 | cert: string;
1544 | ca: any; //string | string array
1545 | crl: any; //string | string array
1546 | ciphers: string;
1547 | }
1548 | export interface Credentials { context?: any; }
1549 | export function createCredentials(details: CredentialDetails): Credentials;
1550 | export function createHash(algorithm: string): Hash;
1551 | export function createHmac(algorithm: string, key: string): Hmac;
1552 | export function createHmac(algorithm: string, key: Buffer): Hmac;
1553 | interface Hash {
1554 | update(data: any, input_encoding?: string): Hash;
1555 | digest(encoding: 'buffer'): Buffer;
1556 | digest(encoding: string): any;
1557 | digest(): Buffer;
1558 | }
1559 | interface Hmac {
1560 | update(data: any, input_encoding?: string): Hmac;
1561 | digest(encoding: 'buffer'): Buffer;
1562 | digest(encoding: string): any;
1563 | digest(): Buffer;
1564 | }
1565 | export function createCipher(algorithm: string, password: any): Cipher;
1566 | export function createCipheriv(algorithm: string, key: any, iv: any): Cipher;
1567 | interface Cipher {
1568 | update(data: Buffer): Buffer;
1569 | update(data: string, input_encoding?: string, output_encoding?: string): string;
1570 | final(): Buffer;
1571 | final(output_encoding: string): string;
1572 | setAutoPadding(auto_padding: boolean): void;
1573 | }
1574 | export function createDecipher(algorithm: string, password: any): Decipher;
1575 | export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher;
1576 | interface Decipher {
1577 | update(data: Buffer): Buffer;
1578 | update(data: string, input_encoding?: string, output_encoding?: string): string;
1579 | final(): Buffer;
1580 | final(output_encoding: string): string;
1581 | setAutoPadding(auto_padding: boolean): void;
1582 | }
1583 | export function createSign(algorithm: string): Signer;
1584 | interface Signer {
1585 | update(data: any): void;
1586 | sign(private_key: string, output_format: string): string;
1587 | }
1588 | export function createVerify(algorith: string): Verify;
1589 | interface Verify {
1590 | update(data: any): void;
1591 | verify(object: string, signature: string, signature_format?: string): boolean;
1592 | }
1593 | export function createDiffieHellman(prime_length: number): DiffieHellman;
1594 | export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman;
1595 | interface DiffieHellman {
1596 | generateKeys(encoding?: string): string;
1597 | computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string;
1598 | getPrime(encoding?: string): string;
1599 | getGenerator(encoding: string): string;
1600 | getPublicKey(encoding?: string): string;
1601 | getPrivateKey(encoding?: string): string;
1602 | setPublicKey(public_key: string, encoding?: string): void;
1603 | setPrivateKey(public_key: string, encoding?: string): void;
1604 | }
1605 | export function getDiffieHellman(group_name: string): DiffieHellman;
1606 | export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void;
1607 | export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer;
1608 | export function randomBytes(size: number): Buffer;
1609 | export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void;
1610 | export function pseudoRandomBytes(size: number): Buffer;
1611 | export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void;
1612 | }
1613 |
1614 | declare module "stream" {
1615 | import events = require("events");
1616 |
1617 | export interface Stream extends events.EventEmitter {
1618 | pipe(destination: T, options?: { end?: boolean; }): T;
1619 | }
1620 |
1621 | export interface ReadableOptions {
1622 | highWaterMark?: number;
1623 | encoding?: string;
1624 | objectMode?: boolean;
1625 | }
1626 |
1627 | export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
1628 | readable: boolean;
1629 | constructor(opts?: ReadableOptions);
1630 | _read(size: number): void;
1631 | read(size?: number): string|Buffer;
1632 | setEncoding(encoding: string): void;
1633 | pause(): void;
1634 | resume(): void;
1635 | pipe(destination: T, options?: { end?: boolean; }): T;
1636 | unpipe(destination?: T): void;
1637 | unshift(chunk: string): void;
1638 | unshift(chunk: Buffer): void;
1639 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
1640 | push(chunk: any, encoding?: string): boolean;
1641 | }
1642 |
1643 | export interface WritableOptions {
1644 | highWaterMark?: number;
1645 | decodeStrings?: boolean;
1646 | }
1647 |
1648 | export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
1649 | writable: boolean;
1650 | constructor(opts?: WritableOptions);
1651 | _write(data: Buffer, encoding: string, callback: Function): void;
1652 | _write(data: string, encoding: string, callback: Function): void;
1653 | write(buffer: Buffer, cb?: Function): boolean;
1654 | write(str: string, cb?: Function): boolean;
1655 | write(str: string, encoding?: string, cb?: Function): boolean;
1656 | end(): void;
1657 | end(buffer: Buffer, cb?: Function): void;
1658 | end(str: string, cb?: Function): void;
1659 | end(str: string, encoding?: string, cb?: Function): void;
1660 | }
1661 |
1662 | export interface DuplexOptions extends ReadableOptions, WritableOptions {
1663 | allowHalfOpen?: boolean;
1664 | }
1665 |
1666 | // Note: Duplex extends both Readable and Writable.
1667 | export class Duplex extends Readable implements NodeJS.ReadWriteStream {
1668 | writable: boolean;
1669 | constructor(opts?: DuplexOptions);
1670 | _write(data: Buffer, encoding: string, callback: Function): void;
1671 | _write(data: string, encoding: string, callback: Function): void;
1672 | write(buffer: Buffer, cb?: Function): boolean;
1673 | write(str: string, cb?: Function): boolean;
1674 | write(str: string, encoding?: string, cb?: Function): boolean;
1675 | end(): void;
1676 | end(buffer: Buffer, cb?: Function): void;
1677 | end(str: string, cb?: Function): void;
1678 | end(str: string, encoding?: string, cb?: Function): void;
1679 | }
1680 |
1681 | export interface TransformOptions extends ReadableOptions, WritableOptions {}
1682 |
1683 | // Note: Transform lacks the _read and _write methods of Readable/Writable.
1684 | export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
1685 | readable: boolean;
1686 | writable: boolean;
1687 | constructor(opts?: TransformOptions);
1688 | _transform(chunk: Buffer, encoding: string, callback: Function): void;
1689 | _transform(chunk: string, encoding: string, callback: Function): void;
1690 | _flush(callback: Function): void;
1691 | read(size?: number): any;
1692 | setEncoding(encoding: string): void;
1693 | pause(): void;
1694 | resume(): void;
1695 | pipe(destination: T, options?: { end?: boolean; }): T;
1696 | unpipe(destination?: T): void;
1697 | unshift(chunk: string): void;
1698 | unshift(chunk: Buffer): void;
1699 | wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
1700 | push(chunk: any, encoding?: string): boolean;
1701 | write(buffer: Buffer, cb?: Function): boolean;
1702 | write(str: string, cb?: Function): boolean;
1703 | write(str: string, encoding?: string, cb?: Function): boolean;
1704 | end(): void;
1705 | end(buffer: Buffer, cb?: Function): void;
1706 | end(str: string, cb?: Function): void;
1707 | end(str: string, encoding?: string, cb?: Function): void;
1708 | }
1709 |
1710 | export class PassThrough extends Transform {}
1711 | }
1712 |
1713 | declare module "util" {
1714 | export interface InspectOptions {
1715 | showHidden?: boolean;
1716 | depth?: number;
1717 | colors?: boolean;
1718 | customInspect?: boolean;
1719 | }
1720 |
1721 | export function format(format: any, ...param: any[]): string;
1722 | export function debug(string: string): void;
1723 | export function error(...param: any[]): void;
1724 | export function puts(...param: any[]): void;
1725 | export function print(...param: any[]): void;
1726 | export function log(string: string): void;
1727 | export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string;
1728 | export function inspect(object: any, options: InspectOptions): string;
1729 | export function isArray(object: any): boolean;
1730 | export function isRegExp(object: any): boolean;
1731 | export function isDate(object: any): boolean;
1732 | export function isError(object: any): boolean;
1733 | export function inherits(constructor: any, superConstructor: any): void;
1734 | }
1735 |
1736 | declare module "assert" {
1737 | function internal (value: any, message?: string): void;
1738 | module internal {
1739 | export class AssertionError implements Error {
1740 | name: string;
1741 | message: string;
1742 | actual: any;
1743 | expected: any;
1744 | operator: string;
1745 | generatedMessage: boolean;
1746 |
1747 | constructor(options?: {message?: string; actual?: any; expected?: any;
1748 | operator?: string; stackStartFunction?: Function});
1749 | }
1750 |
1751 | export function fail(actual?: any, expected?: any, message?: string, operator?: string): void;
1752 | export function ok(value: any, message?: string): void;
1753 | export function equal(actual: any, expected: any, message?: string): void;
1754 | export function notEqual(actual: any, expected: any, message?: string): void;
1755 | export function deepEqual(actual: any, expected: any, message?: string): void;
1756 | export function notDeepEqual(acutal: any, expected: any, message?: string): void;
1757 | export function strictEqual(actual: any, expected: any, message?: string): void;
1758 | export function notStrictEqual(actual: any, expected: any, message?: string): void;
1759 | export var throws: {
1760 | (block: Function, message?: string): void;
1761 | (block: Function, error: Function, message?: string): void;
1762 | (block: Function, error: RegExp, message?: string): void;
1763 | (block: Function, error: (err: any) => boolean, message?: string): void;
1764 | };
1765 |
1766 | export var doesNotThrow: {
1767 | (block: Function, message?: string): void;
1768 | (block: Function, error: Function, message?: string): void;
1769 | (block: Function, error: RegExp, message?: string): void;
1770 | (block: Function, error: (err: any) => boolean, message?: string): void;
1771 | };
1772 |
1773 | export function ifError(value: any): void;
1774 | }
1775 |
1776 | export = internal;
1777 | }
1778 |
1779 | declare module "tty" {
1780 | import net = require("net");
1781 |
1782 | export function isatty(fd: number): boolean;
1783 | export interface ReadStream extends net.Socket {
1784 | isRaw: boolean;
1785 | setRawMode(mode: boolean): void;
1786 | }
1787 | export interface WriteStream extends net.Socket {
1788 | columns: number;
1789 | rows: number;
1790 | }
1791 | }
1792 |
1793 | declare module "domain" {
1794 | import events = require("events");
1795 |
1796 | export class Domain extends events.EventEmitter {
1797 | run(fn: Function): void;
1798 | add(emitter: events.EventEmitter): void;
1799 | remove(emitter: events.EventEmitter): void;
1800 | bind(cb: (err: Error, data: any) => any): any;
1801 | intercept(cb: (data: any) => any): any;
1802 | dispose(): void;
1803 |
1804 | addListener(event: string, listener: Function): Domain;
1805 | on(event: string, listener: Function): Domain;
1806 | once(event: string, listener: Function): Domain;
1807 | removeListener(event: string, listener: Function): Domain;
1808 | removeAllListeners(event?: string): Domain;
1809 | }
1810 |
1811 | export function create(): Domain;
1812 | }
1813 |
--------------------------------------------------------------------------------
/typings/request/request.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for request
2 | // Project: https://github.com/mikeal/request
3 | // Definitions by: Carlos Ballesteros Velasco , bonnici , Bart van der Schoor
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts
7 |
8 | ///
9 | ///
10 |
11 | declare module 'request' {
12 | import stream = require('stream');
13 | import http = require('http');
14 | import FormData = require('form-data');
15 |
16 | export = RequestAPI;
17 |
18 | function RequestAPI(uri: string, options?: RequestAPI.Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request;
19 | function RequestAPI(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request;
20 | function RequestAPI(options: RequestAPI.Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): RequestAPI.Request;
21 |
22 | module RequestAPI {
23 | export function defaults(options: Options): typeof RequestAPI;
24 |
25 | export function request(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
26 | export function request(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
27 | export function request(options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
28 |
29 | export function get(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
30 | export function get(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
31 | export function get(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
32 |
33 | export function post(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
34 | export function post(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
35 | export function post(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
36 |
37 | export function put(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
38 | export function put(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
39 | export function put(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
40 |
41 | export function head(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
42 | export function head(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
43 | export function head(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
44 |
45 | export function patch(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
46 | export function patch(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
47 | export function patch(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
48 |
49 | export function del(uri: string, options?: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
50 | export function del(uri: string, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
51 | export function del(options: Options, callback?: (error: any, response: http.IncomingMessage, body: any) => void): Request;
52 |
53 | export function forever(agentOptions: any, optionsArg: any): Request;
54 | export function jar(): CookieJar;
55 | export function cookie(str: string): Cookie;
56 |
57 | export var initParams: any;
58 |
59 | export interface Options {
60 | url?: string;
61 | uri?: string;
62 | callback?: (error: any, response: http.IncomingMessage, body: any) => void;
63 | jar?: any; // CookieJar
64 | form?: any; // Object or string
65 | auth?: AuthOptions;
66 | oauth?: OAuthOptions;
67 | aws?: AWSOptions;
68 | hawk ?: HawkOptions;
69 | qs?: Object;
70 | json?: any;
71 | multipart?: RequestPart[];
72 | agentOptions?: any;
73 | agentClass?: any;
74 | forever?: any;
75 | host?: string;
76 | port?: number;
77 | method?: string;
78 | headers?: Headers;
79 | body?: any;
80 | followRedirect?: boolean;
81 | followAllRedirects?: boolean;
82 | maxRedirects?: number;
83 | encoding?: string;
84 | pool?: any;
85 | timeout?: number;
86 | proxy?: any;
87 | strictSSL?: boolean;
88 | }
89 |
90 | export interface RequestPart {
91 | headers?: Headers;
92 | body: any;
93 | }
94 |
95 | export interface Request extends stream.Stream {
96 | readable: boolean;
97 | writable: boolean;
98 |
99 | getAgent(): http.Agent;
100 | //start(): void;
101 | //abort(): void;
102 | pipeDest(dest: any): void;
103 | setHeader(name: string, value: string, clobber?: boolean): Request;
104 | setHeaders(headers: Headers): Request;
105 | qs(q: Object, clobber?: boolean): Request;
106 | form(): FormData.FormData;
107 | form(form: any): Request;
108 | multipart(multipart: RequestPart[]): Request;
109 | json(val: any): Request;
110 | aws(opts: AWSOptions, now?: boolean): Request;
111 | auth(username: string, password: string, sendInmediately?: boolean, bearer?: string): Request;
112 | oauth(oauth: OAuthOptions): Request;
113 | jar(jar: CookieJar): Request;
114 |
115 | on(event: string, listener: Function): Request;
116 |
117 | write(buffer: Buffer, cb?: Function): boolean;
118 | write(str: string, cb?: Function): boolean;
119 | write(str: string, encoding: string, cb?: Function): boolean;
120 | write(str: string, encoding?: string, fd?: string): boolean;
121 | end(): void;
122 | end(chunk: Buffer, cb?: Function): void;
123 | end(chunk: string, cb?: Function): void;
124 | end(chunk: string, encoding: string, cb?: Function): void;
125 | pause(): void;
126 | resume(): void;
127 | abort(): void;
128 | destroy(): void;
129 | toJSON(): string;
130 | }
131 |
132 | export interface Headers {
133 | [key: string]: any;
134 | }
135 |
136 | export interface AuthOptions {
137 | user?: string;
138 | username?: string;
139 | pass?: string;
140 | password?: string;
141 | sendImmediately?: boolean;
142 | }
143 |
144 | export interface OAuthOptions {
145 | callback?: string;
146 | consumer_key?: string;
147 | consumer_secret?: string;
148 | token?: string;
149 | token_secret?: string;
150 | verifier?: string;
151 | }
152 |
153 | export interface HawkOptions {
154 | credentials: any;
155 | }
156 |
157 | export interface AWSOptions {
158 | secret: string;
159 | bucket?: string;
160 | }
161 |
162 | export interface CookieJar {
163 | add(cookie: Cookie): void;
164 | get(req: Request): Cookie;
165 | cookieString(req: Request): string;
166 | }
167 |
168 | export interface CookieValue {
169 | name: string;
170 | value: any;
171 | httpOnly: boolean;
172 | }
173 |
174 | export interface Cookie extends Array {
175 | constructor(name: string, req: Request): void;
176 | str: string;
177 | expires: Date;
178 | path: string;
179 | toString(): string;
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/typings/z-schema/z-schema.d.ts:
--------------------------------------------------------------------------------
1 |
2 | declare module 'z-schema' {
3 | }
4 |
--------------------------------------------------------------------------------